37static const char *login_filename(
void)
48static void init_login(LOGIN *
login)
56static void add_login(LOGIN *
login,
const char *
dr,
const char *
db,
57 const char *
usr,
const char *
pwd,
const char *host,
58 const char *port,
int idx)
64 "add_login(): drv='%s' db='%s' usr='%s' pwd='%s' host='%s', port='%s'",
66 port ? port :
"null");
93static int read_file(LOGIN *
login)
102 file = login_filename();
104 G_debug(3,
"read_file(): DB login file = <%s>",
file);
107 G_debug(3,
"login file does not exist");
117 while (
G_getl2(buf, 2000, fd)) {
149static int write_file(LOGIN *
login)
155 file = login_filename();
157 G_debug(3,
"write_file(): DB login file = <%s>",
file);
170 for (i = 0; i <
login->n; i++) {
172 if (
login->data[i].user) {
175 if (
login->data[i].password)
178 if (
login->data[i].host)
180 if (
login->data[i].port)
191static int set_login(
const char *
driver,
const char *database,
const char *user,
192 const char *password,
const char *host,
const char *port,
199 "db_set_login(): drv=[%s] db=[%s] usr=[%s] pwd=[%s] host=[%s] "
201 driver, database, user, password, host, port);
205 if (read_file(&
login) == -1)
209 for (i = 0; i <
login.n; i++) {
229 G_warning(
_(
"DB connection <%s/%s> already exists and will be "
231 driver, database ? database :
"");
234 "Re-run '%s' with '--%s' flag to overwrite "
235 "existing settings."),
241 add_login(&
login,
driver, database, user, password, host, port, -1);
243 add_login(&
login,
driver, database, user, password, host, port, i);
245 if (write_file(&
login) == -1)
266 const char *password,
const char *host,
const char *port,
288 const char *password,
const char *host,
const char *port,
291 return set_login(
driver, database, user, password, host, port, overwrite);
294static int get_login(
const char *
driver,
const char *database,
295 const char **user,
const char **password,
296 const char **host,
const char **port)
301 G_debug(3,
"db_get_login(): drv=[%s] db=[%s]",
driver, database);
310 if (read_file(&
login) == -1)
313 for (i = 0; i <
login.n; i++) {
315 (!database ||
strcmp(
login.data[i].database, database) == 0)) {
359 const char **password,
const char **host,
const char **port)
380 const char **password,
const char **host,
const char **port)
382 return get_login(
driver, database, user, password, host, port);
398 G_debug(3,
"db_get_login_dump()");
401 if (read_file(&
login) == -1)
404 for (i = 0; i <
login.n; i++) {
405 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.