[GRASS-SVN] r39879 - in grass/trunk: db/db.login include
lib/db/dbmi_base
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Dec 3 06:08:18 EST 2009
Author: martinl
Date: 2009-12-03 06:08:18 -0500 (Thu, 03 Dec 2009)
New Revision: 39879
Modified:
grass/trunk/db/db.login/main.c
grass/trunk/include/gis.h
grass/trunk/lib/db/dbmi_base/login.c
Log:
libgis: define CONFIG_DIR
db.login: updated & interactive mode removed
dbmi/login.c updated
Modified: grass/trunk/db/db.login/main.c
===================================================================
--- grass/trunk/db/db.login/main.c 2009-12-03 10:45:46 UTC (rev 39878)
+++ grass/trunk/db/db.login/main.c 2009-12-03 11:08:18 UTC (rev 39879)
@@ -4,12 +4,12 @@
* MODULE: db.login
* AUTHOR(S): Radim Blazek <radim.blazek gmail.com> (original contributor)
* Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>
- * PURPOSE:
- * COPYRIGHT: (C) 2004-2006 by the GRASS Development Team
+ * PURPOSE: Store db login settings
+ * COPYRIGHT: (C) 2004-2009 by the GRASS Development Team
*
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
+ * This program is free software under the GNU General
+ * Public License (>=v2). Read the file COPYING that
+ * comes with GRASS for details.
*
*****************************************************************************/
#include <stdio.h>
@@ -30,28 +30,23 @@
{
struct Option *driver, *database, *user, *password;
struct GModule *module;
-
-#ifdef HAVE_TERMIOS_H
- struct termios tios, tios2;
-#endif
- char answer[200];
-
+
/* Initialize the GIS calls */
G_gisinit(argv[0]);
module = G_define_module();
G_add_keyword(_("database"));
- G_add_keyword(_("SQL"));
+ G_add_keyword(_("connection"));
module->description = _("Sets user/password for driver/database.");
driver = G_define_standard_option(G_OPT_DB_DRIVER);
driver->options = db_list_drivers();
driver->required = YES;
- driver->answer = db_get_default_driver_name();
+ driver->answer = (char *) db_get_default_driver_name();
database = G_define_standard_option(G_OPT_DB_DATABASE);
database->required = YES;
- database->answer = db_get_default_database_name();
+ database->answer = (char *) db_get_default_database_name();
user = G_define_option();
user->key = "user";
@@ -70,47 +65,13 @@
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
- /* set connection */
- if (!password->answer && isatty(fileno(stdin))) {
- for (;;) {
-#ifdef HAVE_TERMIOS_H
- tcgetattr(STDIN_FILENO, &tios);
- tios2 = tios;
- tios2.c_lflag &= ~ECHO;
- tcsetattr(STDIN_FILENO, TCSAFLUSH, &tios2);
-#endif
- do {
- fprintf(stderr,
- _("\nEnter database password for connection\n<%s:%s:user=%s>\n"),
- driver->answer, database->answer, user->answer);
- fprintf(stderr, _("Hit RETURN to cancel request\n"));
- fprintf(stderr, ">");
- *answer = '\0';
- G_getl(answer, sizeof(answer), stdin);
- } while (0);
-#ifdef HAVE_TERMIOS_H
- tcsetattr(STDIN_FILENO, TCSANOW, &tios);
-#endif
- G_strip(answer);
- if (strlen(answer) == 0) {
- G_message(_("Exiting. Not changing current settings"));
- return -1;
- }
- else {
- G_message(_("New password set"));
- password->answer = G_store(answer);
- break;
- }
- }
- }
- if (db_set_login
- (driver->answer, database->answer, user->answer,
- password->answer) == DB_FAILED) {
+ if (db_set_login(driver->answer, database->answer, user->answer,
+ password->answer) == DB_FAILED) {
G_fatal_error(_("Unable to set user/password"));
}
-
+
if (password->answer)
- G_warning(_("The password was stored in file"));
-
+ G_important_message(_("The password was stored in file (%s/dblogin)"), CONFIG_DIR);
+
exit(EXIT_SUCCESS);
}
Modified: grass/trunk/include/gis.h
===================================================================
--- grass/trunk/include/gis.h 2009-12-03 10:45:46 UTC (rev 39878)
+++ grass/trunk/include/gis.h 2009-12-03 11:08:18 UTC (rev 39879)
@@ -72,8 +72,10 @@
#define PROJECTION_OTHER 99
#define PROJECTION_FILE "PROJ_INFO"
-#define UNIT_FILE "PROJ_UNITS"
+#define UNIT_FILE "PROJ_UNITS"
+#define CONFIG_DIR ".grass7"
+
/* define PI and friends */
#undef M_PI
#define M_PI 3.14159265358979323846 /* pi */
Modified: grass/trunk/lib/db/dbmi_base/login.c
===================================================================
--- grass/trunk/lib/db/dbmi_base/login.c 2009-12-03 10:45:46 UTC (rev 39878)
+++ grass/trunk/lib/db/dbmi_base/login.c 2009-12-03 11:08:18 UTC (rev 39879)
@@ -1,3 +1,17 @@
+/*!
+ \file db/dbmi_base/login.c
+
+ \brief DBMI Library (base) - login settings
+
+ (C) 1999-2009 by the GRASS Development Team
+
+ This program is free software under the GNU General Public
+ License (>=v2). Read the file COPYING that comes with GRASS
+ for details.
+
+ \author Joel Jones (CERL/UIUC), Radim Blazek
+*/
+
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -4,8 +18,10 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+
#include <grass/gis.h>
#include <grass/dbmi.h>
+#include <grass/glocale.h>
typedef struct
{
@@ -27,12 +43,12 @@
if (!file) {
file = (char *)malloc(1000);
- sprintf(file, "%s/.grasslogin6", G_home());
+ sprintf(file, "%s/%s/dblogin", G_home(), CONFIG_DIR);
}
return file;
}
-void init_login(LOGIN * login)
+static void init_login(LOGIN * login)
{
login->n = 0;
login->a = 10;
@@ -40,9 +56,8 @@
login->data = (DATA *) malloc(login->a * sizeof(DATA));
}
-void
-add_login(LOGIN * login, const char *dr, const char *db, const char *usr,
- const char *pwd)
+static void add_login(LOGIN * login, const char *dr, const char *db, const char *usr,
+ const char *pwd)
{
if (login->n == login->a) {
login->a += 10;
@@ -62,7 +77,7 @@
return: -1 error (cannot read file)
number of items (0 also if file does not exist)
*/
-int read_file(LOGIN * login)
+static int read_file(LOGIN * login)
{
int ret;
const char *file;
@@ -93,7 +108,7 @@
G_debug(3, "ret = %d : %s %s %s %s", ret, dr, db, usr, pwd);
if (ret < 2) {
- G_warning("Login file corrupted");
+ G_warning(_("Login file corrupted"));
continue;
}
@@ -110,7 +125,7 @@
return: -1 error (cannot read file)
0 OK
*/
-int write_file(LOGIN * login)
+static int write_file(LOGIN * login)
{
int i;
const char *file;
@@ -146,12 +161,17 @@
/*!
\brief Set user/password for driver/database
+
+ \param driver driver name
+ \param database database name
+ \param user user name
+ \param password password string
+
\return DB_OK
\return DB_FAILED
*/
-int
-db_set_login(const char *driver, const char *database, const char *user,
- const char *password)
+int db_set_login(const char *driver, const char *database, const char *user,
+ const char *password)
{
int i, found;
LOGIN login;
@@ -193,14 +213,18 @@
}
/*!
- \brief Get user/password for driver/database
- if driver/database is not found, user/password are set to NULL
+ \brief Get user/password for driver/database if driver/database is not found, user/password are set to NULL
+
+ \param driver driver name
+ \param database database name
+ \param[out] user name
+ \param[out] password string
+
\return DB_OK
\return DB_FAILED
*/
-int
-db_get_login(const char *driver, const char *database, const char **user,
- const char **password)
+int db_get_login(const char *driver, const char *database, const char **user,
+ const char **password)
{
int i;
LOGIN login;
More information about the grass-commit
mailing list