88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.238 2003/04/28 04:29:12 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.239 2003/04/28 04:52:13 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -107,7 +107,7 @@ static const PQconninfoOption PQconninfoOptions[] = {
107107{"user" ,"PGUSER" ,NULL ,NULL ,
108108"Database-User" ,"" ,20 },
109109
110- {"password" ,"PGPASSWORD" ,DefaultPassword ,NULL ,
110+ {"password" ,"PGPASSWORD" ,NULL ,NULL ,
111111"Database-Password" ,"*" ,20 },
112112
113113{"connect_timeout" ,"PGCONNECT_TIMEOUT" ,NULL ,NULL ,
@@ -1976,6 +1976,14 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
19761976int linenr = 0 ,
19771977i ;
19781978
1979+ /*
1980+ * We have to special-case the environment variable PGSERVICE here,
1981+ * since this is and should be called before inserting environment
1982+ * defaults for other connection options.
1983+ */
1984+ if (service == NULL )
1985+ service = getenv ("PGSERVICE" );
1986+
19791987if (service != NULL )
19801988{
19811989FILE * f ;
@@ -2060,21 +2068,30 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
20602068 *name of the service
20612069 */
20622070for (i = 0 ;options [i ].keyword ;i ++ )
2071+ {
20632072if (strcmp (options [i ].keyword ,"dbname" )== 0 )
2073+ {
20642074if (options [i ].val == NULL )
20652075options [i ].val = strdup (service );
2076+ break ;
2077+ }
2078+ }
20662079
20672080val = line + strlen (line )+ 1 ;
20682081
2082+ /*
2083+ * Set the parameter --- but don't override any
2084+ * previous explicit setting.
2085+ */
20692086found_keyword = 0 ;
20702087for (i = 0 ;options [i ].keyword ;i ++ )
20712088{
20722089if (strcmp (options [i ].keyword ,key )== 0 )
20732090{
2074- if (options [i ].val != NULL )
2075- free (options [i ].val );
2076- options [i ].val = strdup (val );
2091+ if (options [i ].val == NULL )
2092+ options [i ].val = strdup (val );
20772093found_keyword = 1 ;
2094+ break ;
20782095}
20792096}
20802097
@@ -2273,7 +2290,10 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage)
22732290/* Done with the modifiable input string */
22742291free (buf );
22752292
2276- /* Now check for service info */
2293+ /*
2294+ * If there's a service spec, use it to obtain any not-explicitly-given
2295+ * parameters.
2296+ */
22772297if (parseServiceInfo (options ,errorMessage ))
22782298{
22792299PQconninfoFree (options );
@@ -2282,12 +2302,12 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage)
22822302
22832303/*
22842304 * Get the fallback resources for parameters not specified in the
2285- * conninfo string.
2305+ * conninfo string nor the service .
22862306 */
22872307for (option = options ;option -> keyword != NULL ;option ++ )
22882308{
22892309if (option -> val != NULL )
2290- continue ;/* Value was in conninfo */
2310+ continue ;/* Value was in conninfoor service */
22912311
22922312/*
22932313 * Try to get the environment variable fallback
@@ -2322,15 +2342,9 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage)
23222342}
23232343
23242344/*
2325- * Special handling for dbname
2345+ * We used to special-case dbname too, but it's easier to let the
2346+ * backend handle the fallback for that.
23262347 */
2327- if (strcmp (option -> keyword ,"dbname" )== 0 )
2328- {
2329- tmp = conninfo_getval (options ,"user" );
2330- if (tmp )
2331- option -> val = strdup (tmp );
2332- continue ;
2333- }
23342348}
23352349
23362350return options ;