40static const char *login_filename(
void)
51static void init_login(LOGIN *
login)
59static void add_login(LOGIN *
login,
const char *
dr,
const char *
db,
60 const char *
usr,
const char *
pwd,
const char *host,
61 const char *port,
int idx)
67 "add_login(): drv='%s' db='%s' usr='%s' pwd='%s' host='%s', port='%s'",
69 port ? port :
"null");
96static int read_file(LOGIN *
login)
105 file = login_filename();
107 G_debug(3,
"read_file(): DB login file = <%s>",
file);
110 G_debug(3,
"login file does not exist");
120 while (
G_getl2(buf, 2000, fd)) {
152static int write_file(LOGIN *
login)
158 file = login_filename();
160 G_debug(3,
"write_file(): DB login file = <%s>",
file);
173 for (i = 0; i <
login->n; i++) {
175 if (
login->data[i].user) {
178 if (
login->data[i].password)
181 if (
login->data[i].host)
183 if (
login->data[i].port)
194static int set_login(
const char *
driver,
const char *database,
const char *user,
195 const char *password,
const char *host,
const char *port,
202 "db_set_login(): drv=[%s] db=[%s] usr=[%s] pwd=[%s] host=[%s] "
204 driver, database, user, password, host, port);
208 if (read_file(&
login) == -1)
212 for (i = 0; i <
login.n; i++) {
232 G_warning(
_(
"DB connection <%s/%s> already exists and will be "
234 driver, database ? database :
"");
237 "Re-run '%s' with '--%s' flag to overwrite "
238 "existing settings."),
244 add_login(&
login,
driver, database, user, password, host, port, -1);
246 add_login(&
login,
driver, database, user, password, host, port, i);
248 if (write_file(&
login) == -1)
269 const char *password,
const char *host,
const char *port,
291 const char *password,
const char *host,
const char *port,
294 return set_login(
driver, database, user, password, host, port, overwrite);
297static int get_login(
const char *
driver,
const char *database,
298 const char **user,
const char **password,
299 const char **host,
const char **port)
304 G_debug(3,
"db_get_login(): drv=[%s] db=[%s]",
driver, database);
313 if (read_file(&
login) == -1)
316 for (i = 0; i <
login.n; i++) {
318 (!database ||
strcmp(
login.data[i].database, database) == 0)) {
362 const char **password,
const char **host,
const char **port)
383 const char **password,
const char **host,
const char **port)
385 return get_login(
driver, database, user, password, host, port);
401 G_debug(3,
"db_get_login_dump()");
404 if (read_file(&
login) == -1)
407 for (i = 0; i <
login.n; i++) {
408 fprintf(fd,
"%s|%s|%s|%s|%s|%s\n",
login.data[i].driver,
Main header of GRASS DataBase Management Interface.
void * db_malloc(int)
Allocate memory.
const char * G_program_name(void)
Return module name.
int G_getl2(char *, int, FILE *)
Gets a line of text from a file of any pedigree.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
char ** G_tokenize(const char *, const char *)
Tokenize string.
void G_free_tokens(char **)
Free memory allocated to tokens.
int G_number_of_tokens(char **)
Return number of tokens.
char * G_chop(char *)
Chop leading and trailing white spaces.
char * G_store(const char *)
Copy string to allocated memory.
int G_debug(int, const char *,...) __attribute__((format(printf
const char * G_config_path(void)
Get user's config path directory.
int db_get_login2(const char *driver, const char *database, const char **user, const char **password, const char **host, const char **port)
Get login parameters for driver/database.
int db_set_login(const char *driver, const char *database, const char *user, const char *password, const char *host, const char *port, int overwrite)
Set login parameters for driver/database.
int db_get_login_dump(FILE *fd)
Print all connection settings to file.
int db_get_login(const char *driver, const char *database, const char **user, const char **password, const char **host, const char **port)
Get login parameters for driver/database.
int db_set_login2(const char *driver, const char *database, const char *user, const char *password, const char *host, const char *port, int overwrite)
Set login parameters for driver/database.