@ -755,7 +755,9 @@ PQconnectStartParams(const char *const *keywords,
PQconninfoOption * connOptions ;
PQconninfoOption * connOptions ;
/*
/*
* Allocate memory for the conn structure
* Allocate memory for the conn structure . Note that we also expect this
* to initialize conn - > errorMessage to empty . All subsequent steps during
* connection initialization will only append to that buffer .
*/
*/
conn = makeEmptyPGconn ( ) ;
conn = makeEmptyPGconn ( ) ;
if ( conn = = NULL )
if ( conn = = NULL )
@ -831,7 +833,9 @@ PQconnectStart(const char *conninfo)
PGconn * conn ;
PGconn * conn ;
/*
/*
* Allocate memory for the conn structure
* Allocate memory for the conn structure . Note that we also expect this
* to initialize conn - > errorMessage to empty . All subsequent steps during
* connection initialization will only append to that buffer .
*/
*/
conn = makeEmptyPGconn ( ) ;
conn = makeEmptyPGconn ( ) ;
if ( conn = = NULL )
if ( conn = = NULL )
@ -889,7 +893,7 @@ fillPGconn(PGconn *conn, PQconninfoOption *connOptions)
* connmember = strdup ( tmp ) ;
* connmember = strdup ( tmp ) ;
if ( * connmember = = NULL )
if ( * connmember = = NULL )
{
{
printfPQExpBuffe r( & conn - > errorMessage ,
appendPQExpBufferSt r( & conn - > errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
return false ;
return false ;
}
}
@ -1072,7 +1076,7 @@ connectOptions2(PGconn *conn)
if ( more | | i ! = conn - > nconnhost )
if ( more | | i ! = conn - > nconnhost )
{
{
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
printf PQExpBuffer( & conn - > errorMessage ,
append PQExpBuffer( & conn - > errorMessage ,
libpq_gettext ( " could not match %d host names to %d hostaddr values \n " ) ,
libpq_gettext ( " could not match %d host names to %d hostaddr values \n " ) ,
count_comma_separated_elems ( conn - > pghost ) , conn - > nconnhost ) ;
count_comma_separated_elems ( conn - > pghost ) , conn - > nconnhost ) ;
return false ;
return false ;
@ -1153,7 +1157,7 @@ connectOptions2(PGconn *conn)
else if ( more | | i ! = conn - > nconnhost )
else if ( more | | i ! = conn - > nconnhost )
{
{
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
printf PQExpBuffer( & conn - > errorMessage ,
append PQExpBuffer( & conn - > errorMessage ,
libpq_gettext ( " could not match %d port numbers to %d hosts \n " ) ,
libpq_gettext ( " could not match %d port numbers to %d hosts \n " ) ,
count_comma_separated_elems ( conn - > pgport ) , conn - > nconnhost ) ;
count_comma_separated_elems ( conn - > pgport ) , conn - > nconnhost ) ;
return false ;
return false ;
@ -1246,7 +1250,7 @@ connectOptions2(PGconn *conn)
& & strcmp ( conn - > channel_binding , " require " ) ! = 0 )
& & strcmp ( conn - > channel_binding , " require " ) ! = 0 )
{
{
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
printf PQExpBuffer( & conn - > errorMessage ,
append PQExpBuffer( & conn - > errorMessage ,
libpq_gettext ( " invalid %s value: \" %s \" \n " ) ,
libpq_gettext ( " invalid %s value: \" %s \" \n " ) ,
" channel_binding " , conn - > channel_binding ) ;
" channel_binding " , conn - > channel_binding ) ;
return false ;
return false ;
@ -1272,7 +1276,7 @@ connectOptions2(PGconn *conn)
& & strcmp ( conn - > sslmode , " verify-full " ) ! = 0 )
& & strcmp ( conn - > sslmode , " verify-full " ) ! = 0 )
{
{
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
printf PQExpBuffer( & conn - > errorMessage ,
append PQExpBuffer( & conn - > errorMessage ,
libpq_gettext ( " invalid %s value: \" %s \" \n " ) ,
libpq_gettext ( " invalid %s value: \" %s \" \n " ) ,
" sslmode " , conn - > sslmode ) ;
" sslmode " , conn - > sslmode ) ;
return false ;
return false ;
@ -1293,7 +1297,7 @@ connectOptions2(PGconn *conn)
case ' r ' : /* "require" */
case ' r ' : /* "require" */
case ' v ' : /* "verify-ca" or "verify-full" */
case ' v ' : /* "verify-ca" or "verify-full" */
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
printf PQExpBuffer( & conn - > errorMessage ,
append PQExpBuffer( & conn - > errorMessage ,
libpq_gettext ( " sslmode value \" %s \" invalid when SSL support is not compiled in \n " ) ,
libpq_gettext ( " sslmode value \" %s \" invalid when SSL support is not compiled in \n " ) ,
conn - > sslmode ) ;
conn - > sslmode ) ;
return false ;
return false ;
@ -1314,7 +1318,7 @@ connectOptions2(PGconn *conn)
if ( ! sslVerifyProtocolVersion ( conn - > ssl_min_protocol_version ) )
if ( ! sslVerifyProtocolVersion ( conn - > ssl_min_protocol_version ) )
{
{
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
printf PQExpBuffer( & conn - > errorMessage ,
append PQExpBuffer( & conn - > errorMessage ,
libpq_gettext ( " invalid %s value: \" %s \" \n " ) ,
libpq_gettext ( " invalid %s value: \" %s \" \n " ) ,
" ssl_min_protocol_version " ,
" ssl_min_protocol_version " ,
conn - > ssl_min_protocol_version ) ;
conn - > ssl_min_protocol_version ) ;
@ -1323,7 +1327,7 @@ connectOptions2(PGconn *conn)
if ( ! sslVerifyProtocolVersion ( conn - > ssl_max_protocol_version ) )
if ( ! sslVerifyProtocolVersion ( conn - > ssl_max_protocol_version ) )
{
{
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
printf PQExpBuffer( & conn - > errorMessage ,
append PQExpBuffer( & conn - > errorMessage ,
libpq_gettext ( " invalid %s value: \" %s \" \n " ) ,
libpq_gettext ( " invalid %s value: \" %s \" \n " ) ,
" ssl_max_protocol_version " ,
" ssl_max_protocol_version " ,
conn - > ssl_max_protocol_version ) ;
conn - > ssl_max_protocol_version ) ;
@ -1341,7 +1345,7 @@ connectOptions2(PGconn *conn)
conn - > ssl_max_protocol_version ) )
conn - > ssl_max_protocol_version ) )
{
{
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
printfPQExpBuffe r( & conn - > errorMessage ,
appendPQExpBufferSt r( & conn - > errorMessage ,
libpq_gettext ( " invalid SSL protocol version range \n " ) ) ;
libpq_gettext ( " invalid SSL protocol version range \n " ) ) ;
return false ;
return false ;
}
}
@ -1356,7 +1360,7 @@ connectOptions2(PGconn *conn)
strcmp ( conn - > gssencmode , " require " ) ! = 0 )
strcmp ( conn - > gssencmode , " require " ) ! = 0 )
{
{
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
printf PQExpBuffer( & conn - > errorMessage ,
append PQExpBuffer( & conn - > errorMessage ,
libpq_gettext ( " invalid %s value: \" %s \" \n " ) ,
libpq_gettext ( " invalid %s value: \" %s \" \n " ) ,
" gssencmode " ,
" gssencmode " ,
conn - > gssencmode ) ;
conn - > gssencmode ) ;
@ -1366,7 +1370,7 @@ connectOptions2(PGconn *conn)
if ( strcmp ( conn - > gssencmode , " require " ) = = 0 )
if ( strcmp ( conn - > gssencmode , " require " ) = = 0 )
{
{
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
printf PQExpBuffer( & conn - > errorMessage ,
append PQExpBuffer( & conn - > errorMessage ,
libpq_gettext ( " gssencmode value \" %s \" invalid when GSSAPI support is not compiled in \n " ) ,
libpq_gettext ( " gssencmode value \" %s \" invalid when GSSAPI support is not compiled in \n " ) ,
conn - > gssencmode ) ;
conn - > gssencmode ) ;
return false ;
return false ;
@ -1401,7 +1405,7 @@ connectOptions2(PGconn *conn)
& & strcmp ( conn - > target_session_attrs , " read-write " ) ! = 0 )
& & strcmp ( conn - > target_session_attrs , " read-write " ) ! = 0 )
{
{
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
printf PQExpBuffer( & conn - > errorMessage ,
append PQExpBuffer( & conn - > errorMessage ,
libpq_gettext ( " invalid %s value: \" %s \" \n " ) ,
libpq_gettext ( " invalid %s value: \" %s \" \n " ) ,
" target_settion_attrs " ,
" target_settion_attrs " ,
conn - > target_session_attrs ) ;
conn - > target_session_attrs ) ;
@ -1420,7 +1424,7 @@ connectOptions2(PGconn *conn)
oom_error :
oom_error :
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
printfPQExpBuffe r( & conn - > errorMessage ,
appendPQExpBufferSt r( & conn - > errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
return false ;
return false ;
}
}
@ -1487,7 +1491,9 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
PGconn * conn ;
PGconn * conn ;
/*
/*
* Allocate memory for the conn structure
* Allocate memory for the conn structure . Note that we also expect this
* to initialize conn - > errorMessage to empty . All subsequent steps during
* connection initialization will only append to that buffer .
*/
*/
conn = makeEmptyPGconn ( ) ;
conn = makeEmptyPGconn ( ) ;
if ( conn = = NULL )
if ( conn = = NULL )
@ -1596,7 +1602,7 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
oom_error :
oom_error :
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
printfPQExpBuffe r( & conn - > errorMessage ,
appendPQExpBufferSt r( & conn - > errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
return conn ;
return conn ;
}
}
@ -2017,7 +2023,7 @@ connectDBStart(PGconn *conn)
*/
*/
if ( ! pg_link_canary_is_frontend ( ) )
if ( ! pg_link_canary_is_frontend ( ) )
{
{
printfPQExpBuffe r( & conn - > errorMessage ,
appendPQExpBufferSt r( & conn - > errorMessage ,
" libpq is incorrectly linked to backend functions \n " ) ;
" libpq is incorrectly linked to backend functions \n " ) ;
goto connect_errReturn ;
goto connect_errReturn ;
}
}
@ -2026,14 +2032,6 @@ connectDBStart(PGconn *conn)
conn - > inStart = conn - > inCursor = conn - > inEnd = 0 ;
conn - > inStart = conn - > inCursor = conn - > inEnd = 0 ;
conn - > outCount = 0 ;
conn - > outCount = 0 ;
/*
* Ensure errorMessage is empty , too . PQconnectPoll will append messages
* to it in the process of scanning for a working server . Thus , if we
* fail to connect to multiple hosts , the final error message will include
* details about each failure .
*/
resetPQExpBuffer ( & conn - > errorMessage ) ;
/*
/*
* Set up to try to connect to the first host . ( Setting whichhost = - 1 is
* Set up to try to connect to the first host . ( Setting whichhost = - 1 is
* a bit of a cheat , but PQconnectPoll will advance it to 0 before
* a bit of a cheat , but PQconnectPoll will advance it to 0 before
@ -2139,12 +2137,6 @@ connectDBComplete(PGconn *conn)
switch ( flag )
switch ( flag )
{
{
case PGRES_POLLING_OK :
case PGRES_POLLING_OK :
/*
* Reset stored error messages since we now have a working
* connection
*/
resetPQExpBuffer ( & conn - > errorMessage ) ;
return 1 ; /* success! */
return 1 ; /* success! */
case PGRES_POLLING_READING :
case PGRES_POLLING_READING :
@ -2189,46 +2181,6 @@ connectDBComplete(PGconn *conn)
}
}
}
}
/*
* This subroutine saves conn - > errorMessage , which will be restored back by
* restoreErrorMessage subroutine . Returns false on OOM failure .
*/
static bool
saveErrorMessage ( PGconn * conn , PQExpBuffer savedMessage )
{
initPQExpBuffer ( savedMessage ) ;
appendPQExpBufferStr ( savedMessage ,
conn - > errorMessage . data ) ;
if ( PQExpBufferBroken ( savedMessage ) )
{
printfPQExpBuffer ( & conn - > errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
return false ;
}
/* Clear whatever is in errorMessage now */
resetPQExpBuffer ( & conn - > errorMessage ) ;
return true ;
}
/*
* Restores saved error messages back to conn - > errorMessage , prepending them
* to whatever is in conn - > errorMessage already . ( This does the right thing
* if anything ' s been added to conn - > errorMessage since saveErrorMessage . )
*/
static void
restoreErrorMessage ( PGconn * conn , PQExpBuffer savedMessage )
{
appendPQExpBufferStr ( savedMessage , conn - > errorMessage . data ) ;
resetPQExpBuffer ( & conn - > errorMessage ) ;
appendPQExpBufferStr ( & conn - > errorMessage , savedMessage - > data ) ;
/* If any step above hit OOM, just report that */
if ( PQExpBufferBroken ( savedMessage ) | |
PQExpBufferBroken ( & conn - > errorMessage ) )
printfPQExpBuffer ( & conn - > errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
termPQExpBuffer ( savedMessage ) ;
}
/* ----------------
/* ----------------
* PQconnectPoll
* PQconnectPoll
*
*
@ -2264,7 +2216,6 @@ PQconnectPoll(PGconn *conn)
PGresult * res ;
PGresult * res ;
char sebuf [ PG_STRERROR_R_BUFLEN ] ;
char sebuf [ PG_STRERROR_R_BUFLEN ] ;
int optval ;
int optval ;
PQExpBufferData savedMessage ;
if ( conn = = NULL )
if ( conn = = NULL )
return PGRES_POLLING_FAILED ;
return PGRES_POLLING_FAILED ;
@ -2954,11 +2905,7 @@ keep_going: /* We will come back to here until there is
EnvironmentOptions ) ;
EnvironmentOptions ) ;
if ( ! startpacket )
if ( ! startpacket )
{
{
/*
appendPQExpBufferStr ( & conn - > errorMessage ,
* will not appendbuffer here , since it ' s likely to also
* run out of memory
*/
printfPQExpBuffer ( & conn - > errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
goto error_return ;
goto error_return ;
}
}
@ -3448,7 +3395,6 @@ keep_going: /* We will come back to here until there is
* avoid the Kerberos code doing a hostname look - up .
* avoid the Kerberos code doing a hostname look - up .
*/
*/
res = pg_fe_sendauth ( areq , msgLength , conn ) ;
res = pg_fe_sendauth ( areq , msgLength , conn ) ;
conn - > errorMessage . len = strlen ( conn - > errorMessage . data ) ;
/* OK, we have processed the message; mark data consumed */
/* OK, we have processed the message; mark data consumed */
conn - > inStart = conn - > inCursor ;
conn - > inStart = conn - > inCursor ;
@ -3576,24 +3522,16 @@ keep_going: /* We will come back to here until there is
strcmp ( conn - > target_session_attrs , " read-write " ) = = 0 )
strcmp ( conn - > target_session_attrs , " read-write " ) = = 0 )
{
{
/*
/*
* Save existing error messages across the PQsendQuery
* We use PQsendQueryContinue so that conn - > errorMessage
* attempt . This is necessary because PQsendQuery is
* does not get cleared . We need to preserve any error
* going to reset conn - > errorMessage , so we would lose
* messages related to previous hosts we have tried and
* error messages related to previous hosts we have tried
* failed to connect to .
* and failed to connect to .
*/
*/
if ( ! saveErrorMessage ( conn , & savedMessage ) )
goto error_return ;
conn - > status = CONNECTION_OK ;
conn - > status = CONNECTION_OK ;
if ( ! PQsendQuery ( conn ,
if ( ! PQsendQueryContinue ( conn ,
" SHOW transaction_read_only " ) )
" SHOW transaction_read_only " ) )
{
restoreErrorMessage ( conn , & savedMessage ) ;
goto error_return ;
goto error_return ;
}
conn - > status = CONNECTION_CHECK_WRITABLE ;
conn - > status = CONNECTION_CHECK_WRITABLE ;
restoreErrorMessage ( conn , & savedMessage ) ;
return PGRES_POLLING_READING ;
return PGRES_POLLING_READING ;
}
}
@ -3673,20 +3611,13 @@ keep_going: /* We will come back to here until there is
const char * displayed_host ;
const char * displayed_host ;
const char * displayed_port ;
const char * displayed_port ;
if ( ! saveErrorMessage ( conn , & savedMessage ) )
goto error_return ;
conn - > status = CONNECTION_OK ;
conn - > status = CONNECTION_OK ;
if ( ! PQconsumeInput ( conn ) )
if ( ! PQconsumeInput ( conn ) )
{
restoreErrorMessage ( conn , & savedMessage ) ;
goto error_return ;
goto error_return ;
}
if ( PQisBusy ( conn ) )
if ( PQisBusy ( conn ) )
{
{
conn - > status = CONNECTION_CHECK_WRITABLE ;
conn - > status = CONNECTION_CHECK_WRITABLE ;
restoreErrorMessage ( conn , & savedMessage ) ;
return PGRES_POLLING_READING ;
return PGRES_POLLING_READING ;
}
}
@ -3701,7 +3632,6 @@ keep_going: /* We will come back to here until there is
{
{
/* Not writable; fail this connection. */
/* Not writable; fail this connection. */
PQclear ( res ) ;
PQclear ( res ) ;
restoreErrorMessage ( conn , & savedMessage ) ;
/* Append error report to conn->errorMessage. */
/* Append error report to conn->errorMessage. */
if ( conn - > connhost [ conn - > whichhost ] . type = = CHT_HOST_ADDRESS )
if ( conn - > connhost [ conn - > whichhost ] . type = = CHT_HOST_ADDRESS )
@ -3732,7 +3662,6 @@ keep_going: /* We will come back to here until there is
/* Session is read-write, so we're good. */
/* Session is read-write, so we're good. */
PQclear ( res ) ;
PQclear ( res ) ;
termPQExpBuffer ( & savedMessage ) ;
/*
/*
* Finish reading any remaining messages before being
* Finish reading any remaining messages before being
@ -3748,7 +3677,6 @@ keep_going: /* We will come back to here until there is
*/
*/
if ( res )
if ( res )
PQclear ( res ) ;
PQclear ( res ) ;
restoreErrorMessage ( conn , & savedMessage ) ;
/* Append error report to conn->errorMessage. */
/* Append error report to conn->errorMessage. */
if ( conn - > connhost [ conn - > whichhost ] . type = = CHT_HOST_ADDRESS )
if ( conn - > connhost [ conn - > whichhost ] . type = = CHT_HOST_ADDRESS )
@ -4157,6 +4085,9 @@ closePGconn(PGconn *conn)
/*
/*
* Close the connection , reset all transient state , flush I / O buffers .
* Close the connection , reset all transient state , flush I / O buffers .
* Note that this includes clearing conn - > errorMessage ; we ' re no longer
* interested in any failures associated with the old connection , and we
* want a clean slate for any new connection attempt .
*/
*/
pqDropConnection ( conn , true ) ;
pqDropConnection ( conn , true ) ;
conn - > status = CONNECTION_BAD ; /* Well, not really _bad_ - just absent */
conn - > status = CONNECTION_BAD ; /* Well, not really _bad_ - just absent */
@ -4212,7 +4143,7 @@ PQreset(PGconn *conn)
conn - > events [ i ] . passThrough ) )
conn - > events [ i ] . passThrough ) )
{
{
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
printf PQExpBuffer( & conn - > errorMessage ,
append PQExpBuffer( & conn - > errorMessage ,
libpq_gettext ( " PGEventProc \" %s \" failed during PGEVT_CONNRESET event \n " ) ,
libpq_gettext ( " PGEventProc \" %s \" failed during PGEVT_CONNRESET event \n " ) ,
conn - > events [ i ] . name ) ;
conn - > events [ i ] . name ) ;
break ;
break ;
@ -4272,7 +4203,7 @@ PQresetPoll(PGconn *conn)
conn - > events [ i ] . passThrough ) )
conn - > events [ i ] . passThrough ) )
{
{
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
printf PQExpBuffer( & conn - > errorMessage ,
append PQExpBuffer( & conn - > errorMessage ,
libpq_gettext ( " PGEventProc \" %s \" failed during PGEVT_CONNRESET event \n " ) ,
libpq_gettext ( " PGEventProc \" %s \" failed during PGEVT_CONNRESET event \n " ) ,
conn - > events [ i ] . name ) ;
conn - > events [ i ] . name ) ;
return PGRES_POLLING_FAILED ;
return PGRES_POLLING_FAILED ;
@ -4569,7 +4500,7 @@ pqPacketSend(PGconn *conn, char pack_type,
* 2 if a connection could not be established , and
* 2 if a connection could not be established , and
* 3 if a fatal error occurred .
* 3 if a fatal error occurred .
*
*
* An error message is returned in the third argument for return codes 1 and 3.
* An error message is appended to * errorMessage for return codes 1 and 3.
*/
*/
static int
static int
ldapServiceLookup ( const char * purl , PQconninfoOption * options ,
ldapServiceLookup ( const char * purl , PQconninfoOption * options ,
@ -4607,7 +4538,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
if ( ( url = strdup ( purl ) ) = = NULL )
if ( ( url = strdup ( purl ) ) = = NULL )
{
{
printfPQExpBuffe r( errorMessage , libpq_gettext ( " out of memory \n " ) ) ;
appendPQExpBufferSt r( errorMessage , libpq_gettext ( " out of memory \n " ) ) ;
return 3 ;
return 3 ;
}
}
@ -4619,7 +4550,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
if ( pg_strncasecmp ( url , LDAP_URL , strlen ( LDAP_URL ) ) ! = 0 )
if ( pg_strncasecmp ( url , LDAP_URL , strlen ( LDAP_URL ) ) ! = 0 )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " invalid LDAP URL \" %s \" : scheme must be ldap:// \n " ) , purl ) ;
libpq_gettext ( " invalid LDAP URL \" %s \" : scheme must be ldap:// \n " ) , purl ) ;
free ( url ) ;
free ( url ) ;
return 3 ;
return 3 ;
@ -4634,7 +4565,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
p = strchr ( url + strlen ( LDAP_URL ) , ' / ' ) ;
p = strchr ( url + strlen ( LDAP_URL ) , ' / ' ) ;
if ( p = = NULL | | * ( p + 1 ) = = ' \0 ' | | * ( p + 1 ) = = ' ? ' )
if ( p = = NULL | | * ( p + 1 ) = = ' \0 ' | | * ( p + 1 ) = = ' ? ' )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " invalid LDAP URL \" %s \" : missing distinguished name \n " ) ,
libpq_gettext ( " invalid LDAP URL \" %s \" : missing distinguished name \n " ) ,
purl ) ;
purl ) ;
free ( url ) ;
free ( url ) ;
@ -4646,7 +4577,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
/* attribute */
/* attribute */
if ( ( p = strchr ( dn , ' ? ' ) ) = = NULL | | * ( p + 1 ) = = ' \0 ' | | * ( p + 1 ) = = ' ? ' )
if ( ( p = strchr ( dn , ' ? ' ) ) = = NULL | | * ( p + 1 ) = = ' \0 ' | | * ( p + 1 ) = = ' ? ' )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " invalid LDAP URL \" %s \" : must have exactly one attribute \n " ) ,
libpq_gettext ( " invalid LDAP URL \" %s \" : must have exactly one attribute \n " ) ,
purl ) ;
purl ) ;
free ( url ) ;
free ( url ) ;
@ -4658,7 +4589,9 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
/* scope */
/* scope */
if ( ( p = strchr ( attrs [ 0 ] , ' ? ' ) ) = = NULL | | * ( p + 1 ) = = ' \0 ' | | * ( p + 1 ) = = ' ? ' )
if ( ( p = strchr ( attrs [ 0 ] , ' ? ' ) ) = = NULL | | * ( p + 1 ) = = ' \0 ' | | * ( p + 1 ) = = ' ? ' )
{
{
printfPQExpBuffer ( errorMessage , libpq_gettext ( " invalid LDAP URL \" %s \" : must have search scope (base/one/sub) \n " ) , purl ) ;
appendPQExpBuffer ( errorMessage ,
libpq_gettext ( " invalid LDAP URL \" %s \" : must have search scope (base/one/sub) \n " ) ,
purl ) ;
free ( url ) ;
free ( url ) ;
return 3 ;
return 3 ;
}
}
@ -4668,8 +4601,9 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
/* filter */
/* filter */
if ( ( p = strchr ( scopestr , ' ? ' ) ) = = NULL | | * ( p + 1 ) = = ' \0 ' | | * ( p + 1 ) = = ' ? ' )
if ( ( p = strchr ( scopestr , ' ? ' ) ) = = NULL | | * ( p + 1 ) = = ' \0 ' | | * ( p + 1 ) = = ' ? ' )
{
{
printfPQExpBuffer ( errorMessage ,
appendPQExpBuffer ( errorMessage ,
libpq_gettext ( " invalid LDAP URL \" %s \" : no filter \n " ) , purl ) ;
libpq_gettext ( " invalid LDAP URL \" %s \" : no filter \n " ) ,
purl ) ;
free ( url ) ;
free ( url ) ;
return 3 ;
return 3 ;
}
}
@ -4689,7 +4623,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
lport = strtol ( portstr , & endptr , 10 ) ;
lport = strtol ( portstr , & endptr , 10 ) ;
if ( * portstr = = ' \0 ' | | * endptr ! = ' \0 ' | | errno | | lport < 0 | | lport > 65535 )
if ( * portstr = = ' \0 ' | | * endptr ! = ' \0 ' | | errno | | lport < 0 | | lport > 65535 )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " invalid LDAP URL \" %s \" : invalid port number \n " ) ,
libpq_gettext ( " invalid LDAP URL \" %s \" : invalid port number \n " ) ,
purl ) ;
purl ) ;
free ( url ) ;
free ( url ) ;
@ -4701,7 +4635,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
/* Allow only one attribute */
/* Allow only one attribute */
if ( strchr ( attrs [ 0 ] , ' , ' ) ! = NULL )
if ( strchr ( attrs [ 0 ] , ' , ' ) ! = NULL )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " invalid LDAP URL \" %s \" : must have exactly one attribute \n " ) ,
libpq_gettext ( " invalid LDAP URL \" %s \" : must have exactly one attribute \n " ) ,
purl ) ;
purl ) ;
free ( url ) ;
free ( url ) ;
@ -4717,7 +4651,9 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
scope = LDAP_SCOPE_SUBTREE ;
scope = LDAP_SCOPE_SUBTREE ;
else
else
{
{
printfPQExpBuffer ( errorMessage , libpq_gettext ( " invalid LDAP URL \" %s \" : must have search scope (base/one/sub) \n " ) , purl ) ;
appendPQExpBuffer ( errorMessage ,
libpq_gettext ( " invalid LDAP URL \" %s \" : must have search scope (base/one/sub) \n " ) ,
purl ) ;
free ( url ) ;
free ( url ) ;
return 3 ;
return 3 ;
}
}
@ -4725,7 +4661,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
/* initialize LDAP structure */
/* initialize LDAP structure */
if ( ( ld = ldap_init ( hostname , port ) ) = = NULL )
if ( ( ld = ldap_init ( hostname , port ) ) = = NULL )
{
{
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " could not create LDAP structure \n " ) ) ;
libpq_gettext ( " could not create LDAP structure \n " ) ) ;
free ( url ) ;
free ( url ) ;
return 3 ;
return 3 ;
@ -4801,7 +4737,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
{
{
if ( res ! = NULL )
if ( res ! = NULL )
ldap_msgfree ( res ) ;
ldap_msgfree ( res ) ;
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " lookup on LDAP server failed: %s \n " ) ,
libpq_gettext ( " lookup on LDAP server failed: %s \n " ) ,
ldap_err2string ( rc ) ) ;
ldap_err2string ( rc ) ) ;
ldap_unbind ( ld ) ;
ldap_unbind ( ld ) ;
@ -4812,7 +4748,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
/* complain if there was not exactly one result */
/* complain if there was not exactly one result */
if ( ( rc = ldap_count_entries ( ld , res ) ) ! = 1 )
if ( ( rc = ldap_count_entries ( ld , res ) ) ! = 1 )
{
{
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
rc ? libpq_gettext ( " more than one entry found on LDAP lookup \n " )
rc ? libpq_gettext ( " more than one entry found on LDAP lookup \n " )
: libpq_gettext ( " no entry found on LDAP lookup \n " ) ) ;
: libpq_gettext ( " no entry found on LDAP lookup \n " ) ) ;
ldap_msgfree ( res ) ;
ldap_msgfree ( res ) ;
@ -4825,7 +4761,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
if ( ( entry = ldap_first_entry ( ld , res ) ) = = NULL )
if ( ( entry = ldap_first_entry ( ld , res ) ) = = NULL )
{
{
/* should never happen */
/* should never happen */
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " no entry found on LDAP lookup \n " ) ) ;
libpq_gettext ( " no entry found on LDAP lookup \n " ) ) ;
ldap_msgfree ( res ) ;
ldap_msgfree ( res ) ;
ldap_unbind ( ld ) ;
ldap_unbind ( ld ) ;
@ -4836,7 +4772,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
/* get values */
/* get values */
if ( ( values = ldap_get_values_len ( ld , entry , attrs [ 0 ] ) ) = = NULL )
if ( ( values = ldap_get_values_len ( ld , entry , attrs [ 0 ] ) ) = = NULL )
{
{
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " attribute has no values on LDAP lookup \n " ) ) ;
libpq_gettext ( " attribute has no values on LDAP lookup \n " ) ) ;
ldap_msgfree ( res ) ;
ldap_msgfree ( res ) ;
ldap_unbind ( ld ) ;
ldap_unbind ( ld ) ;
@ -4849,7 +4785,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
if ( values [ 0 ] = = NULL )
if ( values [ 0 ] = = NULL )
{
{
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " attribute has no values on LDAP lookup \n " ) ) ;
libpq_gettext ( " attribute has no values on LDAP lookup \n " ) ) ;
ldap_value_free_len ( values ) ;
ldap_value_free_len ( values ) ;
ldap_unbind ( ld ) ;
ldap_unbind ( ld ) ;
@ -4862,7 +4798,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
size + = values [ i ] - > bv_len + 1 ;
size + = values [ i ] - > bv_len + 1 ;
if ( ( result = malloc ( size ) ) = = NULL )
if ( ( result = malloc ( size ) ) = = NULL )
{
{
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
ldap_value_free_len ( values ) ;
ldap_value_free_len ( values ) ;
ldap_unbind ( ld ) ;
ldap_unbind ( ld ) ;
@ -4901,7 +4837,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
}
}
else if ( ld_is_nl_cr ( * p ) )
else if ( ld_is_nl_cr ( * p ) )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " missing \" = \" after \" %s \" in connection info string \n " ) ,
libpq_gettext ( " missing \" = \" after \" %s \" in connection info string \n " ) ,
optname ) ;
optname ) ;
free ( result ) ;
free ( result ) ;
@ -4920,7 +4856,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
}
}
else if ( ! ld_is_sp_tab ( * p ) )
else if ( ! ld_is_sp_tab ( * p ) )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " missing \" = \" after \" %s \" in connection info string \n " ) ,
libpq_gettext ( " missing \" = \" after \" %s \" in connection info string \n " ) ,
optname ) ;
optname ) ;
free ( result ) ;
free ( result ) ;
@ -4981,7 +4917,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
options [ i ] . val = strdup ( optval ) ;
options [ i ] . val = strdup ( optval ) ;
if ( ! options [ i ] . val )
if ( ! options [ i ] . val )
{
{
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
free ( result ) ;
free ( result ) ;
return 3 ;
return 3 ;
@ -4993,7 +4929,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
}
}
if ( ! found_keyword )
if ( ! found_keyword )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " invalid connection option \" %s \" \n " ) ,
libpq_gettext ( " invalid connection option \" %s \" \n " ) ,
optname ) ;
optname ) ;
free ( result ) ;
free ( result ) ;
@ -5009,7 +4945,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
if ( state = = 5 | | state = = 6 )
if ( state = = 5 | | state = = 6 )
{
{
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " unterminated quoted string in connection info string \n " ) ) ;
libpq_gettext ( " unterminated quoted string in connection info string \n " ) ) ;
return 3 ;
return 3 ;
}
}
@ -5090,7 +5026,7 @@ next_file:
last_file :
last_file :
if ( ! group_found )
if ( ! group_found )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " definition of service \" %s \" not found \n " ) , service ) ;
libpq_gettext ( " definition of service \" %s \" not found \n " ) , service ) ;
return 3 ;
return 3 ;
}
}
@ -5117,7 +5053,7 @@ parseServiceFile(const char *serviceFile,
f = fopen ( serviceFile , " r " ) ;
f = fopen ( serviceFile , " r " ) ;
if ( f = = NULL )
if ( f = = NULL )
{
{
printf PQExpBuffer( errorMessage , libpq_gettext ( " service file \" %s \" not found \n " ) ,
append PQExpBuffer( errorMessage , libpq_gettext ( " service file \" %s \" not found \n " ) ,
serviceFile ) ;
serviceFile ) ;
return 1 ;
return 1 ;
}
}
@ -5193,7 +5129,7 @@ parseServiceFile(const char *serviceFile,
val = strchr ( line , ' = ' ) ;
val = strchr ( line , ' = ' ) ;
if ( val = = NULL )
if ( val = = NULL )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " syntax error in service file \" %s \" , line %d \n " ) ,
libpq_gettext ( " syntax error in service file \" %s \" , line %d \n " ) ,
serviceFile ,
serviceFile ,
linenr ) ;
linenr ) ;
@ -5204,7 +5140,7 @@ parseServiceFile(const char *serviceFile,
if ( strcmp ( key , " service " ) = = 0 )
if ( strcmp ( key , " service " ) = = 0 )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " nested service specifications not supported in service file \" %s \" , line %d \n " ) ,
libpq_gettext ( " nested service specifications not supported in service file \" %s \" , line %d \n " ) ,
serviceFile ,
serviceFile ,
linenr ) ;
linenr ) ;
@ -5225,7 +5161,7 @@ parseServiceFile(const char *serviceFile,
options [ i ] . val = strdup ( val ) ;
options [ i ] . val = strdup ( val ) ;
if ( ! options [ i ] . val )
if ( ! options [ i ] . val )
{
{
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
result = 3 ;
result = 3 ;
goto exit ;
goto exit ;
@ -5237,7 +5173,7 @@ parseServiceFile(const char *serviceFile,
if ( ! found_keyword )
if ( ! found_keyword )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " syntax error in service file \" %s \" , line %d \n " ) ,
libpq_gettext ( " syntax error in service file \" %s \" , line %d \n " ) ,
serviceFile ,
serviceFile ,
linenr ) ;
linenr ) ;
@ -5307,7 +5243,7 @@ conninfo_init(PQExpBuffer errorMessage)
options = ( PQconninfoOption * ) malloc ( sizeof ( PQconninfoOption ) * sizeof ( PQconninfoOptions ) / sizeof ( PQconninfoOptions [ 0 ] ) ) ;
options = ( PQconninfoOption * ) malloc ( sizeof ( PQconninfoOption ) * sizeof ( PQconninfoOptions ) / sizeof ( PQconninfoOptions [ 0 ] ) ) ;
if ( options = = NULL )
if ( options = = NULL )
{
{
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
return NULL ;
return NULL ;
}
}
@ -5328,7 +5264,7 @@ conninfo_init(PQExpBuffer errorMessage)
* Connection string parser
* Connection string parser
*
*
* Returns a malloc ' d PQconninfoOption array , if parsing is successful .
* Returns a malloc ' d PQconninfoOption array , if parsing is successful .
* Otherwise , NULL is returned and an error message is left in errorMessage .
* Otherwise , NULL is returned and an error message is added to errorMessage .
*
*
* If use_defaults is true , default values are filled in ( from a service file ,
* If use_defaults is true , default values are filled in ( from a service file ,
* environment variables , etc ) .
* environment variables , etc ) .
@ -5406,7 +5342,7 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage,
/* Need a modifiable copy of the input string */
/* Need a modifiable copy of the input string */
if ( ( buf = strdup ( conninfo ) ) = = NULL )
if ( ( buf = strdup ( conninfo ) ) = = NULL )
{
{
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
PQconninfoFree ( options ) ;
PQconninfoFree ( options ) ;
return NULL ;
return NULL ;
@ -5445,7 +5381,7 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage,
/* Check that there is a following '=' */
/* Check that there is a following '=' */
if ( * cp ! = ' = ' )
if ( * cp ! = ' = ' )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " missing \" = \" after \" %s \" in connection info string \n " ) ,
libpq_gettext ( " missing \" = \" after \" %s \" in connection info string \n " ) ,
pname ) ;
pname ) ;
PQconninfoFree ( options ) ;
PQconninfoFree ( options ) ;
@ -5494,7 +5430,7 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage,
{
{
if ( * cp = = ' \0 ' )
if ( * cp = = ' \0 ' )
{
{
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " unterminated quoted string in connection info string \n " ) ) ;
libpq_gettext ( " unterminated quoted string in connection info string \n " ) ) ;
PQconninfoFree ( options ) ;
PQconninfoFree ( options ) ;
free ( buf ) ;
free ( buf ) ;
@ -5551,7 +5487,7 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage,
*
*
* If successful , a malloc ' d PQconninfoOption array is returned .
* If successful , a malloc ' d PQconninfoOption array is returned .
* If not successful , NULL is returned and an error message is
* If not successful , NULL is returned and an error message is
* left in errorMessage .
* appended to errorMessage .
* Defaults are supplied ( from a service file , environment variables , etc )
* Defaults are supplied ( from a service file , environment variables , etc )
* for unspecified options , but only if use_defaults is true .
* for unspecified options , but only if use_defaults is true .
*
*
@ -5630,7 +5566,7 @@ conninfo_array_parse(const char *const *keywords, const char *const *values,
/* Check for invalid connection option */
/* Check for invalid connection option */
if ( option - > keyword = = NULL )
if ( option - > keyword = = NULL )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " invalid connection option \" %s \" \n " ) ,
libpq_gettext ( " invalid connection option \" %s \" \n " ) ,
pname ) ;
pname ) ;
PQconninfoFree ( options ) ;
PQconninfoFree ( options ) ;
@ -5662,7 +5598,7 @@ conninfo_array_parse(const char *const *keywords, const char *const *values,
options [ k ] . val = strdup ( str_option - > val ) ;
options [ k ] . val = strdup ( str_option - > val ) ;
if ( ! options [ k ] . val )
if ( ! options [ k ] . val )
{
{
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
PQconninfoFree ( options ) ;
PQconninfoFree ( options ) ;
PQconninfoFree ( dbname_options ) ;
PQconninfoFree ( dbname_options ) ;
@ -5691,7 +5627,7 @@ conninfo_array_parse(const char *const *keywords, const char *const *values,
option - > val = strdup ( pvalue ) ;
option - > val = strdup ( pvalue ) ;
if ( ! option - > val )
if ( ! option - > val )
{
{
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
PQconninfoFree ( options ) ;
PQconninfoFree ( options ) ;
PQconninfoFree ( dbname_options ) ;
PQconninfoFree ( dbname_options ) ;
@ -5763,7 +5699,7 @@ conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage)
if ( ! option - > val )
if ( ! option - > val )
{
{
if ( errorMessage )
if ( errorMessage )
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
return false ;
return false ;
}
}
@ -5787,7 +5723,7 @@ conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage)
if ( ! option - > val )
if ( ! option - > val )
{
{
if ( errorMessage )
if ( errorMessage )
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
return false ;
return false ;
}
}
@ -5805,7 +5741,7 @@ conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage)
if ( ! option - > val )
if ( ! option - > val )
{
{
if ( errorMessage )
if ( errorMessage )
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
return false ;
return false ;
}
}
@ -5906,7 +5842,7 @@ conninfo_uri_parse_options(PQconninfoOption *options, const char *uri,
initPQExpBuffer ( & portbuf ) ;
initPQExpBuffer ( & portbuf ) ;
if ( PQExpBufferDataBroken ( hostbuf ) | | PQExpBufferDataBroken ( portbuf ) )
if ( PQExpBufferDataBroken ( hostbuf ) | | PQExpBufferDataBroken ( portbuf ) )
{
{
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
goto cleanup ;
goto cleanup ;
}
}
@ -5915,7 +5851,7 @@ conninfo_uri_parse_options(PQconninfoOption *options, const char *uri,
buf = strdup ( uri ) ;
buf = strdup ( uri ) ;
if ( buf = = NULL )
if ( buf = = NULL )
{
{
printfPQExpBuffe r( errorMessage ,
appendPQExpBufferSt r( errorMessage ,
libpq_gettext ( " out of memory \n " ) ) ;
libpq_gettext ( " out of memory \n " ) ) ;
goto cleanup ;
goto cleanup ;
}
}
@ -5926,7 +5862,7 @@ conninfo_uri_parse_options(PQconninfoOption *options, const char *uri,
if ( prefix_len = = 0 )
if ( prefix_len = = 0 )
{
{
/* Should never happen */
/* Should never happen */
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " invalid URI propagated to internal parser routine: \" %s \" \n " ) ,
libpq_gettext ( " invalid URI propagated to internal parser routine: \" %s \" \n " ) ,
uri ) ;
uri ) ;
goto cleanup ;
goto cleanup ;
@ -6003,14 +5939,14 @@ conninfo_uri_parse_options(PQconninfoOption *options, const char *uri,
+ + p ;
+ + p ;
if ( ! * p )
if ( ! * p )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " end of string reached when looking for matching \" ] \" in IPv6 host address in URI: \" %s \" \n " ) ,
libpq_gettext ( " end of string reached when looking for matching \" ] \" in IPv6 host address in URI: \" %s \" \n " ) ,
uri ) ;
uri ) ;
goto cleanup ;
goto cleanup ;
}
}
if ( p = = host )
if ( p = = host )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " IPv6 host address may not be empty in URI: \" %s \" \n " ) ,
libpq_gettext ( " IPv6 host address may not be empty in URI: \" %s \" \n " ) ,
uri ) ;
uri ) ;
goto cleanup ;
goto cleanup ;
@ -6025,7 +5961,7 @@ conninfo_uri_parse_options(PQconninfoOption *options, const char *uri,
*/
*/
if ( * p & & * p ! = ' : ' & & * p ! = ' / ' & & * p ! = ' ? ' & & * p ! = ' , ' )
if ( * p & & * p ! = ' : ' & & * p ! = ' / ' & & * p ! = ' ? ' & & * p ! = ' , ' )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " unexpected character \" %c \" at position %d in URI (expected \" : \" or \" / \" ): \" %s \" \n " ) ,
libpq_gettext ( " unexpected character \" %c \" at position %d in URI (expected \" : \" or \" / \" ): \" %s \" \n " ) ,
* p , ( int ) ( p - buf + 1 ) , uri ) ;
* p , ( int ) ( p - buf + 1 ) , uri ) ;
goto cleanup ;
goto cleanup ;
@ -6142,6 +6078,7 @@ conninfo_uri_parse_params(char *params,
char * value = NULL ;
char * value = NULL ;
char * p = params ;
char * p = params ;
bool malloced = false ;
bool malloced = false ;
int oldmsglen ;
/*
/*
* Scan the params string for ' = ' and ' & ' , marking the end of keyword
* Scan the params string for ' = ' and ' & ' , marking the end of keyword
@ -6154,7 +6091,7 @@ conninfo_uri_parse_params(char *params,
/* Was there '=' already? */
/* Was there '=' already? */
if ( value ! = NULL )
if ( value ! = NULL )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " extra key/value separator \" = \" in URI query parameter: \" %s \" \n " ) ,
libpq_gettext ( " extra key/value separator \" = \" in URI query parameter: \" %s \" \n " ) ,
keyword ) ;
keyword ) ;
return false ;
return false ;
@ -6174,7 +6111,7 @@ conninfo_uri_parse_params(char *params,
/* Was there '=' at all? */
/* Was there '=' at all? */
if ( value = = NULL )
if ( value = = NULL )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " missing key/value separator \" = \" in URI query parameter: \" %s \" \n " ) ,
libpq_gettext ( " missing key/value separator \" = \" in URI query parameter: \" %s \" \n " ) ,
keyword ) ;
keyword ) ;
return false ;
return false ;
@ -6220,12 +6157,13 @@ conninfo_uri_parse_params(char *params,
* otherwise . At this point both keyword and value are not
* otherwise . At this point both keyword and value are not
* URI - encoded .
* URI - encoded .
*/
*/
oldmsglen = errorMessage - > len ;
if ( ! conninfo_storeval ( connOptions , keyword , value ,
if ( ! conninfo_storeval ( connOptions , keyword , value ,
errorMessage , true , false ) )
errorMessage , true , false ) )
{
{
/* Insert generic message if conninfo_storeval didn't give one. */
/* Insert generic message if conninfo_storeval didn't give one. */
if ( errorMessage - > len = = 0 )
if ( errorMessage - > len = = oldmsglen )
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " invalid URI query parameter: \" %s \" \n " ) ,
libpq_gettext ( " invalid URI query parameter: \" %s \" \n " ) ,
keyword ) ;
keyword ) ;
/* And fail. */
/* And fail. */
@ -6272,7 +6210,7 @@ conninfo_uri_decode(const char *str, PQExpBuffer errorMessage)
buf = malloc ( strlen ( str ) + 1 ) ;
buf = malloc ( strlen ( str ) + 1 ) ;
if ( buf = = NULL )
if ( buf = = NULL )
{
{
printfPQExpBuffe r( errorMessage , libpq_gettext ( " out of memory \n " ) ) ;
appendPQExpBufferSt r( errorMessage , libpq_gettext ( " out of memory \n " ) ) ;
return NULL ;
return NULL ;
}
}
p = buf ;
p = buf ;
@ -6299,7 +6237,7 @@ conninfo_uri_decode(const char *str, PQExpBuffer errorMessage)
*/
*/
if ( ! ( get_hexdigit ( * q + + , & hi ) & & get_hexdigit ( * q + + , & lo ) ) )
if ( ! ( get_hexdigit ( * q + + , & hi ) & & get_hexdigit ( * q + + , & lo ) ) )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " invalid percent-encoded token: \" %s \" \n " ) ,
libpq_gettext ( " invalid percent-encoded token: \" %s \" \n " ) ,
str ) ;
str ) ;
free ( buf ) ;
free ( buf ) ;
@ -6309,7 +6247,7 @@ conninfo_uri_decode(const char *str, PQExpBuffer errorMessage)
c = ( hi < < 4 ) | lo ;
c = ( hi < < 4 ) | lo ;
if ( c = = 0 )
if ( c = = 0 )
{
{
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " forbidden value %%00 in percent-encoded value: \" %s \" \n " ) ,
libpq_gettext ( " forbidden value %%00 in percent-encoded value: \" %s \" \n " ) ,
str ) ;
str ) ;
free ( buf ) ;
free ( buf ) ;
@ -6404,7 +6342,7 @@ conninfo_storeval(PQconninfoOption *connOptions,
if ( option = = NULL )
if ( option = = NULL )
{
{
if ( ! ignoreMissing )
if ( ! ignoreMissing )
printf PQExpBuffer( errorMessage ,
append PQExpBuffer( errorMessage ,
libpq_gettext ( " invalid connection option \" %s \" \n " ) ,
libpq_gettext ( " invalid connection option \" %s \" \n " ) ,
keyword ) ;
keyword ) ;
return NULL ;
return NULL ;
@ -6422,7 +6360,7 @@ conninfo_storeval(PQconninfoOption *connOptions,
value_copy = strdup ( value ) ;
value_copy = strdup ( value ) ;
if ( value_copy = = NULL )
if ( value_copy = = NULL )
{
{
printfPQExpBuffe r( errorMessage , libpq_gettext ( " out of memory \n " ) ) ;
appendPQExpBufferSt r( errorMessage , libpq_gettext ( " out of memory \n " ) ) ;
return NULL ;
return NULL ;
}
}
}
}
@ -6469,7 +6407,10 @@ PQconninfo(PGconn *conn)
if ( conn = = NULL )
if ( conn = = NULL )
return NULL ;
return NULL ;
/* We don't actually report any errors here, but callees want a buffer */
/*
* We don ' t actually report any errors here , but callees want a buffer ,
* and we prefer not to trash the conn ' s errorMessage .
*/
initPQExpBuffer ( & errorBuf ) ;
initPQExpBuffer ( & errorBuf ) ;
if ( PQExpBufferDataBroken ( errorBuf ) )
if ( PQExpBufferDataBroken ( errorBuf ) )
return NULL ; /* out of memory already :-( */
return NULL ; /* out of memory already :-( */