*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.238 2003/04/28 04:29:12 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.239 2003/04/28 04:52:13 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{"user", "PGUSER", NULL, NULL,
"Database-User", "", 20},
- {"password", "PGPASSWORD", DefaultPassword, NULL,
+ {"password", "PGPASSWORD", NULL, NULL,
"Database-Password", "*", 20},
{"connect_timeout", "PGCONNECT_TIMEOUT", NULL, NULL,
int linenr = 0,
i;
+ /*
+ * We have to special-case the environment variable PGSERVICE here,
+ * since this is and should be called before inserting environment
+ * defaults for other connection options.
+ */
+ if (service == NULL)
+ service = getenv("PGSERVICE");
+
if (service != NULL)
{
FILE *f;
* name of the service
*/
for (i = 0; options[i].keyword; i++)
+ {
if (strcmp(options[i].keyword, "dbname") == 0)
+ {
if (options[i].val == NULL)
options[i].val = strdup(service);
+ break;
+ }
+ }
val = line + strlen(line) + 1;
+ /*
+ * Set the parameter --- but don't override any
+ * previous explicit setting.
+ */
found_keyword = 0;
for (i = 0; options[i].keyword; i++)
{
if (strcmp(options[i].keyword, key) == 0)
{
- if (options[i].val != NULL)
- free(options[i].val);
- options[i].val = strdup(val);
+ if (options[i].val == NULL)
+ options[i].val = strdup(val);
found_keyword = 1;
+ break;
}
}
/* Done with the modifiable input string */
free(buf);
- /* Now check for service info */
+ /*
+ * If there's a service spec, use it to obtain any not-explicitly-given
+ * parameters.
+ */
if (parseServiceInfo(options, errorMessage))
{
PQconninfoFree(options);
/*
* Get the fallback resources for parameters not specified in the
- * conninfo string.
+ * conninfo string nor the service.
*/
for (option = options; option->keyword != NULL; option++)
{
if (option->val != NULL)
- continue; /* Value was in conninfo */
+ continue; /* Value was in conninfo or service */
/*
* Try to get the environment variable fallback
}
/*
- * Special handling for dbname
+ * We used to special-case dbname too, but it's easier to let the
+ * backend handle the fallback for that.
*/
- if (strcmp(option->keyword, "dbname") == 0)
- {
- tmp = conninfo_getval(options, "user");
- if (tmp)
- option->val = strdup(tmp);
- continue;
- }
}
return options;