|
|
@ -387,15 +387,10 @@ static const char uri_designator[] = "postgresql://"; |
|
|
|
static const char short_uri_designator[] = "postgres://"; |
|
|
|
static const char short_uri_designator[] = "postgres://"; |
|
|
|
|
|
|
|
|
|
|
|
static bool connectOptions1(PGconn *conn, const char *conninfo); |
|
|
|
static bool connectOptions1(PGconn *conn, const char *conninfo); |
|
|
|
static bool connectOptions2(PGconn *conn); |
|
|
|
|
|
|
|
static int connectDBStart(PGconn *conn); |
|
|
|
|
|
|
|
static int connectDBComplete(PGconn *conn); |
|
|
|
|
|
|
|
static PGPing internal_ping(PGconn *conn); |
|
|
|
static PGPing internal_ping(PGconn *conn); |
|
|
|
static PGconn *makeEmptyPGconn(void); |
|
|
|
|
|
|
|
static void pqFreeCommandQueue(PGcmdQueueEntry *queue); |
|
|
|
static void pqFreeCommandQueue(PGcmdQueueEntry *queue); |
|
|
|
static bool fillPGconn(PGconn *conn, PQconninfoOption *connOptions); |
|
|
|
static bool fillPGconn(PGconn *conn, PQconninfoOption *connOptions); |
|
|
|
static void freePGconn(PGconn *conn); |
|
|
|
static void freePGconn(PGconn *conn); |
|
|
|
static void closePGconn(PGconn *conn); |
|
|
|
|
|
|
|
static void release_conn_addrinfo(PGconn *conn); |
|
|
|
static void release_conn_addrinfo(PGconn *conn); |
|
|
|
static int store_conn_addrinfo(PGconn *conn, struct addrinfo *addrlist); |
|
|
|
static int store_conn_addrinfo(PGconn *conn, struct addrinfo *addrlist); |
|
|
|
static void sendTerminateConn(PGconn *conn); |
|
|
|
static void sendTerminateConn(PGconn *conn); |
|
|
@ -644,8 +639,8 @@ pqDropServerData(PGconn *conn) |
|
|
|
* PQconnectStart or PQconnectStartParams (which differ in the same way as |
|
|
|
* PQconnectStart or PQconnectStartParams (which differ in the same way as |
|
|
|
* PQconnectdb and PQconnectdbParams) and PQconnectPoll. |
|
|
|
* PQconnectdb and PQconnectdbParams) and PQconnectPoll. |
|
|
|
* |
|
|
|
* |
|
|
|
* Internally, the static functions connectDBStart, connectDBComplete |
|
|
|
* The non-exported functions pqConnectDBStart, pqConnectDBComplete are |
|
|
|
* are part of the connection procedure. |
|
|
|
* part of the connection procedure implementation. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -678,7 +673,7 @@ PQconnectdbParams(const char *const *keywords, |
|
|
|
PGconn *conn = PQconnectStartParams(keywords, values, expand_dbname); |
|
|
|
PGconn *conn = PQconnectStartParams(keywords, values, expand_dbname); |
|
|
|
|
|
|
|
|
|
|
|
if (conn && conn->status != CONNECTION_BAD) |
|
|
|
if (conn && conn->status != CONNECTION_BAD) |
|
|
|
(void) connectDBComplete(conn); |
|
|
|
(void) pqConnectDBComplete(conn); |
|
|
|
|
|
|
|
|
|
|
|
return conn; |
|
|
|
return conn; |
|
|
|
} |
|
|
|
} |
|
|
@ -731,7 +726,7 @@ PQconnectdb(const char *conninfo) |
|
|
|
PGconn *conn = PQconnectStart(conninfo); |
|
|
|
PGconn *conn = PQconnectStart(conninfo); |
|
|
|
|
|
|
|
|
|
|
|
if (conn && conn->status != CONNECTION_BAD) |
|
|
|
if (conn && conn->status != CONNECTION_BAD) |
|
|
|
(void) connectDBComplete(conn); |
|
|
|
(void) pqConnectDBComplete(conn); |
|
|
|
|
|
|
|
|
|
|
|
return conn; |
|
|
|
return conn; |
|
|
|
} |
|
|
|
} |
|
|
@ -785,7 +780,7 @@ PQconnectStartParams(const char *const *keywords, |
|
|
|
* to initialize conn->errorMessage to empty. All subsequent steps during |
|
|
|
* to initialize conn->errorMessage to empty. All subsequent steps during |
|
|
|
* connection initialization will only append to that buffer. |
|
|
|
* connection initialization will only append to that buffer. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
conn = makeEmptyPGconn(); |
|
|
|
conn = pqMakeEmptyPGconn(); |
|
|
|
if (conn == NULL) |
|
|
|
if (conn == NULL) |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
|
|
|
|
|
|
|
@ -819,15 +814,15 @@ PQconnectStartParams(const char *const *keywords, |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Compute derived options |
|
|
|
* Compute derived options |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
if (!connectOptions2(conn)) |
|
|
|
if (!pqConnectOptions2(conn)) |
|
|
|
return conn; |
|
|
|
return conn; |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Connect to the database |
|
|
|
* Connect to the database |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
if (!connectDBStart(conn)) |
|
|
|
if (!pqConnectDBStart(conn)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
/* Just in case we failed to set it in connectDBStart */ |
|
|
|
/* Just in case we failed to set it in pqConnectDBStart */ |
|
|
|
conn->status = CONNECTION_BAD; |
|
|
|
conn->status = CONNECTION_BAD; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -863,7 +858,7 @@ PQconnectStart(const char *conninfo) |
|
|
|
* to initialize conn->errorMessage to empty. All subsequent steps during |
|
|
|
* to initialize conn->errorMessage to empty. All subsequent steps during |
|
|
|
* connection initialization will only append to that buffer. |
|
|
|
* connection initialization will only append to that buffer. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
conn = makeEmptyPGconn(); |
|
|
|
conn = pqMakeEmptyPGconn(); |
|
|
|
if (conn == NULL) |
|
|
|
if (conn == NULL) |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
|
|
|
|
|
|
|
@ -876,15 +871,15 @@ PQconnectStart(const char *conninfo) |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Compute derived options |
|
|
|
* Compute derived options |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
if (!connectOptions2(conn)) |
|
|
|
if (!pqConnectOptions2(conn)) |
|
|
|
return conn; |
|
|
|
return conn; |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Connect to the database |
|
|
|
* Connect to the database |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
if (!connectDBStart(conn)) |
|
|
|
if (!pqConnectDBStart(conn)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
/* Just in case we failed to set it in connectDBStart */ |
|
|
|
/* Just in case we failed to set it in pqConnectDBStart */ |
|
|
|
conn->status = CONNECTION_BAD; |
|
|
|
conn->status = CONNECTION_BAD; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -895,7 +890,7 @@ PQconnectStart(const char *conninfo) |
|
|
|
* Move option values into conn structure |
|
|
|
* Move option values into conn structure |
|
|
|
* |
|
|
|
* |
|
|
|
* Don't put anything cute here --- intelligence should be in |
|
|
|
* Don't put anything cute here --- intelligence should be in |
|
|
|
* connectOptions2 ... |
|
|
|
* pqConnectOptions2 ... |
|
|
|
* |
|
|
|
* |
|
|
|
* Returns true on success. On failure, returns false and sets error message. |
|
|
|
* Returns true on success. On failure, returns false and sets error message. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -933,7 +928,7 @@ fillPGconn(PGconn *conn, PQconninfoOption *connOptions) |
|
|
|
* |
|
|
|
* |
|
|
|
* Internal subroutine to set up connection parameters given an already- |
|
|
|
* Internal subroutine to set up connection parameters given an already- |
|
|
|
* created PGconn and a conninfo string. Derived settings should be |
|
|
|
* created PGconn and a conninfo string. Derived settings should be |
|
|
|
* processed by calling connectOptions2 next. (We split them because |
|
|
|
* processed by calling pqConnectOptions2 next. (We split them because |
|
|
|
* PQsetdbLogin overrides defaults in between.) |
|
|
|
* PQsetdbLogin overrides defaults in between.) |
|
|
|
* |
|
|
|
* |
|
|
|
* Returns true if OK, false if trouble (in which case errorMessage is set |
|
|
|
* Returns true if OK, false if trouble (in which case errorMessage is set |
|
|
@ -1055,15 +1050,15 @@ libpq_prng_init(PGconn *conn) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* connectOptions2 |
|
|
|
* pqConnectOptions2 |
|
|
|
* |
|
|
|
* |
|
|
|
* Compute derived connection options after absorbing all user-supplied info. |
|
|
|
* Compute derived connection options after absorbing all user-supplied info. |
|
|
|
* |
|
|
|
* |
|
|
|
* Returns true if OK, false if trouble (in which case errorMessage is set |
|
|
|
* Returns true if OK, false if trouble (in which case errorMessage is set |
|
|
|
* and so is conn->status). |
|
|
|
* and so is conn->status). |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static bool |
|
|
|
bool |
|
|
|
connectOptions2(PGconn *conn) |
|
|
|
pqConnectOptions2(PGconn *conn) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
@ -1822,7 +1817,7 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, |
|
|
|
* to initialize conn->errorMessage to empty. All subsequent steps during |
|
|
|
* to initialize conn->errorMessage to empty. All subsequent steps during |
|
|
|
* connection initialization will only append to that buffer. |
|
|
|
* connection initialization will only append to that buffer. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
conn = makeEmptyPGconn(); |
|
|
|
conn = pqMakeEmptyPGconn(); |
|
|
|
if (conn == NULL) |
|
|
|
if (conn == NULL) |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
|
|
|
|
|
|
|
@ -1901,14 +1896,14 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Compute derived options |
|
|
|
* Compute derived options |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
if (!connectOptions2(conn)) |
|
|
|
if (!pqConnectOptions2(conn)) |
|
|
|
return conn; |
|
|
|
return conn; |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Connect to the database |
|
|
|
* Connect to the database |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
if (connectDBStart(conn)) |
|
|
|
if (pqConnectDBStart(conn)) |
|
|
|
(void) connectDBComplete(conn); |
|
|
|
(void) pqConnectDBComplete(conn); |
|
|
|
|
|
|
|
|
|
|
|
return conn; |
|
|
|
return conn; |
|
|
|
|
|
|
|
|
|
|
@ -2277,14 +2272,14 @@ setTCPUserTimeout(PGconn *conn) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* ----------
|
|
|
|
/* ----------
|
|
|
|
* connectDBStart - |
|
|
|
* pqConnectDBStart - |
|
|
|
* Begin the process of making a connection to the backend. |
|
|
|
* Begin the process of making a connection to the backend. |
|
|
|
* |
|
|
|
* |
|
|
|
* Returns 1 if successful, 0 if not. |
|
|
|
* Returns 1 if successful, 0 if not. |
|
|
|
* ---------- |
|
|
|
* ---------- |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static int |
|
|
|
int |
|
|
|
connectDBStart(PGconn *conn) |
|
|
|
pqConnectDBStart(PGconn *conn) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!conn) |
|
|
|
if (!conn) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
@ -2347,14 +2342,14 @@ connect_errReturn: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* connectDBComplete |
|
|
|
* pqConnectDBComplete |
|
|
|
* |
|
|
|
* |
|
|
|
* Block and complete a connection. |
|
|
|
* Block and complete a connection. |
|
|
|
* |
|
|
|
* |
|
|
|
* Returns 1 on success, 0 on failure. |
|
|
|
* Returns 1 on success, 0 on failure. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static int |
|
|
|
int |
|
|
|
connectDBComplete(PGconn *conn) |
|
|
|
pqConnectDBComplete(PGconn *conn) |
|
|
|
{ |
|
|
|
{ |
|
|
|
PostgresPollingStatusType flag = PGRES_POLLING_WRITING; |
|
|
|
PostgresPollingStatusType flag = PGRES_POLLING_WRITING; |
|
|
|
time_t finish_time = ((time_t) -1); |
|
|
|
time_t finish_time = ((time_t) -1); |
|
|
@ -2704,7 +2699,7 @@ keep_going: /* We will come back to here until there is |
|
|
|
* combining it with the insertion. |
|
|
|
* combining it with the insertion. |
|
|
|
* |
|
|
|
* |
|
|
|
* We don't need to initialize conn->prng_state here, because that |
|
|
|
* We don't need to initialize conn->prng_state here, because that |
|
|
|
* already happened in connectOptions2. |
|
|
|
* already happened in pqConnectOptions2. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
for (int i = 1; i < conn->naddr; i++) |
|
|
|
for (int i = 1; i < conn->naddr; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -4181,7 +4176,7 @@ internal_ping(PGconn *conn) |
|
|
|
|
|
|
|
|
|
|
|
/* Attempt to complete the connection */ |
|
|
|
/* Attempt to complete the connection */ |
|
|
|
if (conn->status != CONNECTION_BAD) |
|
|
|
if (conn->status != CONNECTION_BAD) |
|
|
|
(void) connectDBComplete(conn); |
|
|
|
(void) pqConnectDBComplete(conn); |
|
|
|
|
|
|
|
|
|
|
|
/* Definitely OK if we succeeded */ |
|
|
|
/* Definitely OK if we succeeded */ |
|
|
|
if (conn->status != CONNECTION_BAD) |
|
|
|
if (conn->status != CONNECTION_BAD) |
|
|
@ -4233,11 +4228,11 @@ internal_ping(PGconn *conn) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* makeEmptyPGconn |
|
|
|
* pqMakeEmptyPGconn |
|
|
|
* - create a PGconn data structure with (as yet) no interesting data |
|
|
|
* - create a PGconn data structure with (as yet) no interesting data |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static PGconn * |
|
|
|
PGconn * |
|
|
|
makeEmptyPGconn(void) |
|
|
|
pqMakeEmptyPGconn(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
PGconn *conn; |
|
|
|
PGconn *conn; |
|
|
|
|
|
|
|
|
|
|
@ -4330,7 +4325,7 @@ makeEmptyPGconn(void) |
|
|
|
* freePGconn |
|
|
|
* freePGconn |
|
|
|
* - free an idle (closed) PGconn data structure |
|
|
|
* - free an idle (closed) PGconn data structure |
|
|
|
* |
|
|
|
* |
|
|
|
* NOTE: this should not overlap any functionality with closePGconn(). |
|
|
|
* NOTE: this should not overlap any functionality with pqClosePGconn(). |
|
|
|
* Clearing/resetting of transient state belongs there; what we do here is |
|
|
|
* Clearing/resetting of transient state belongs there; what we do here is |
|
|
|
* release data that is to be held for the life of the PGconn structure. |
|
|
|
* release data that is to be held for the life of the PGconn structure. |
|
|
|
* If a value ought to be cleared/freed during PQreset(), do it there not here. |
|
|
|
* If a value ought to be cleared/freed during PQreset(), do it there not here. |
|
|
@ -4517,15 +4512,15 @@ sendTerminateConn(PGconn *conn) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* closePGconn |
|
|
|
* pqClosePGconn |
|
|
|
* - properly close a connection to the backend |
|
|
|
* - properly close a connection to the backend |
|
|
|
* |
|
|
|
* |
|
|
|
* This should reset or release all transient state, but NOT the connection |
|
|
|
* This should reset or release all transient state, but NOT the connection |
|
|
|
* parameters. On exit, the PGconn should be in condition to start a fresh |
|
|
|
* parameters. On exit, the PGconn should be in condition to start a fresh |
|
|
|
* connection with the same parameters (see PQreset()). |
|
|
|
* connection with the same parameters (see PQreset()). |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void |
|
|
|
void |
|
|
|
closePGconn(PGconn *conn) |
|
|
|
pqClosePGconn(PGconn *conn) |
|
|
|
{ |
|
|
|
{ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* If possible, send Terminate message to close the connection politely. |
|
|
|
* If possible, send Terminate message to close the connection politely. |
|
|
@ -4568,7 +4563,7 @@ PQfinish(PGconn *conn) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (conn) |
|
|
|
if (conn) |
|
|
|
{ |
|
|
|
{ |
|
|
|
closePGconn(conn); |
|
|
|
pqClosePGconn(conn); |
|
|
|
freePGconn(conn); |
|
|
|
freePGconn(conn); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -4582,9 +4577,9 @@ PQreset(PGconn *conn) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (conn) |
|
|
|
if (conn) |
|
|
|
{ |
|
|
|
{ |
|
|
|
closePGconn(conn); |
|
|
|
pqClosePGconn(conn); |
|
|
|
|
|
|
|
|
|
|
|
if (connectDBStart(conn) && connectDBComplete(conn)) |
|
|
|
if (pqConnectDBStart(conn) && pqConnectDBComplete(conn)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Notify event procs of successful reset. |
|
|
|
* Notify event procs of successful reset. |
|
|
@ -4615,9 +4610,9 @@ PQresetStart(PGconn *conn) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (conn) |
|
|
|
if (conn) |
|
|
|
{ |
|
|
|
{ |
|
|
|
closePGconn(conn); |
|
|
|
pqClosePGconn(conn); |
|
|
|
|
|
|
|
|
|
|
|
return connectDBStart(conn); |
|
|
|
return pqConnectDBStart(conn); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|