Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
libpq: Change some static functions to extern
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Sun, 4 Feb 2024 15:35:16 +0000 (16:35 +0100)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Sun, 4 Feb 2024 15:35:16 +0000 (16:35 +0100)
This is in preparation of a follow up commit that starts using these
functions from fe-cancel.c.

Author: Jelte Fennema-Nio <jelte.fennema@microsoft.com>
Discussion: https://postgr.es/m/AM5PR83MB0178D3B31CA1B6EC4A8ECC42F7529@AM5PR83MB0178.EURPRD83.prod.outlook.com

src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/libpq-int.h

index 5add6f4ebb3b1ed0cb795f08287848a470005751..64c0b628b3c4af9fd8c2d3eb9ef486875e107d9a 100644 (file)
@@ -387,15 +387,10 @@ static const char uri_designator[] = "postgresql://";
 static const char short_uri_designator[] = "postgres://";
 
 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 PGconn *makeEmptyPGconn(void);
 static void pqFreeCommandQueue(PGcmdQueueEntry *queue);
 static bool fillPGconn(PGconn *conn, PQconninfoOption *connOptions);
 static void freePGconn(PGconn *conn);
-static void closePGconn(PGconn *conn);
 static void release_conn_addrinfo(PGconn *conn);
 static int store_conn_addrinfo(PGconn *conn, struct addrinfo *addrlist);
 static void sendTerminateConn(PGconn *conn);
@@ -644,8 +639,8 @@ pqDropServerData(PGconn *conn)
  * PQconnectStart or PQconnectStartParams (which differ in the same way as
  * PQconnectdb and PQconnectdbParams) and PQconnectPoll.
  *
- * Internally, the static functions connectDBStart, connectDBComplete
- * are part of the connection procedure.
+ * The non-exported functions pqConnectDBStart, pqConnectDBComplete are
+ * part of the connection procedure implementation.
  */
 
 /*
@@ -678,7 +673,7 @@ PQconnectdbParams(const char *const *keywords,
    PGconn     *conn = PQconnectStartParams(keywords, values, expand_dbname);
 
    if (conn && conn->status != CONNECTION_BAD)
-       (void) connectDBComplete(conn);
+       (void) pqConnectDBComplete(conn);
 
    return conn;
 }
@@ -731,7 +726,7 @@ PQconnectdb(const char *conninfo)
    PGconn     *conn = PQconnectStart(conninfo);
 
    if (conn && conn->status != CONNECTION_BAD)
-       (void) connectDBComplete(conn);
+       (void) pqConnectDBComplete(conn);
 
    return conn;
 }
@@ -785,7 +780,7 @@ PQconnectStartParams(const char *const *keywords,
     * to initialize conn->errorMessage to empty.  All subsequent steps during
     * connection initialization will only append to that buffer.
     */
-   conn = makeEmptyPGconn();
+   conn = pqMakeEmptyPGconn();
    if (conn == NULL)
        return NULL;
 
@@ -819,15 +814,15 @@ PQconnectStartParams(const char *const *keywords,
    /*
     * Compute derived options
     */
-   if (!connectOptions2(conn))
+   if (!pqConnectOptions2(conn))
        return conn;
 
    /*
     * 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;
    }
 
@@ -863,7 +858,7 @@ PQconnectStart(const char *conninfo)
     * to initialize conn->errorMessage to empty.  All subsequent steps during
     * connection initialization will only append to that buffer.
     */
-   conn = makeEmptyPGconn();
+   conn = pqMakeEmptyPGconn();
    if (conn == NULL)
        return NULL;
 
@@ -876,15 +871,15 @@ PQconnectStart(const char *conninfo)
    /*
     * Compute derived options
     */
-   if (!connectOptions2(conn))
+   if (!pqConnectOptions2(conn))
        return conn;
 
    /*
     * 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;
    }
 
@@ -895,7 +890,7 @@ PQconnectStart(const char *conninfo)
  * Move option values into conn structure
  *
  * Don't put anything cute here --- intelligence should be in
- * connectOptions2 ...
+ * pqConnectOptions2 ...
  *
  * 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-
  * 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.)
  *
  * 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.
  *
  * Returns true if OK, false if trouble (in which case errorMessage is set
  * and so is conn->status).
  */
-static bool
-connectOptions2(PGconn *conn)
+bool
+pqConnectOptions2(PGconn *conn)
 {
    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
     * connection initialization will only append to that buffer.
     */
-   conn = makeEmptyPGconn();
+   conn = pqMakeEmptyPGconn();
    if (conn == NULL)
        return NULL;
 
@@ -1901,14 +1896,14 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
    /*
     * Compute derived options
     */
-   if (!connectOptions2(conn))
+   if (!pqConnectOptions2(conn))
        return conn;
 
    /*
     * Connect to the database
     */
-   if (connectDBStart(conn))
-       (void) connectDBComplete(conn);
+   if (pqConnectDBStart(conn))
+       (void) pqConnectDBComplete(conn);
 
    return conn;
 
@@ -2277,14 +2272,14 @@ setTCPUserTimeout(PGconn *conn)
 }
 
 /* ----------
- * connectDBStart -
+ * pqConnectDBStart -
  *     Begin the process of making a connection to the backend.
  *
  * Returns 1 if successful, 0 if not.
  * ----------
  */
-static int
-connectDBStart(PGconn *conn)
+int
+pqConnectDBStart(PGconn *conn)
 {
    if (!conn)
        return 0;
@@ -2347,14 +2342,14 @@ connect_errReturn:
 
 
 /*
- *     connectDBComplete
+ *     pqConnectDBComplete
  *
  * Block and complete a connection.
  *
  * Returns 1 on success, 0 on failure.
  */
-static int
-connectDBComplete(PGconn *conn)
+int
+pqConnectDBComplete(PGconn *conn)
 {
    PostgresPollingStatusType flag = PGRES_POLLING_WRITING;
    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.
             *
             * 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++)
            {
@@ -4181,7 +4176,7 @@ internal_ping(PGconn *conn)
 
    /* Attempt to complete the connection */
    if (conn->status != CONNECTION_BAD)
-       (void) connectDBComplete(conn);
+       (void) pqConnectDBComplete(conn);
 
    /* Definitely OK if we succeeded */
    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
  */
-static PGconn *
-makeEmptyPGconn(void)
+PGconn *
+pqMakeEmptyPGconn(void)
 {
    PGconn     *conn;
 
@@ -4330,7 +4325,7 @@ makeEmptyPGconn(void)
  * freePGconn
  *  - 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
  * 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.
@@ -4517,15 +4512,15 @@ sendTerminateConn(PGconn *conn)
 }
 
 /*
- * closePGconn
+ * pqClosePGconn
  *  - properly close a connection to the backend
  *
  * 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
  * connection with the same parameters (see PQreset()).
  */
-static void
-closePGconn(PGconn *conn)
+void
+pqClosePGconn(PGconn *conn)
 {
    /*
     * If possible, send Terminate message to close the connection politely.
@@ -4568,7 +4563,7 @@ PQfinish(PGconn *conn)
 {
    if (conn)
    {
-       closePGconn(conn);
+       pqClosePGconn(conn);
        freePGconn(conn);
    }
 }
@@ -4582,9 +4577,9 @@ PQreset(PGconn *conn)
 {
    if (conn)
    {
-       closePGconn(conn);
+       pqClosePGconn(conn);
 
-       if (connectDBStart(conn) && connectDBComplete(conn))
+       if (pqConnectDBStart(conn) && pqConnectDBComplete(conn))
        {
            /*
             * Notify event procs of successful reset.
@@ -4615,9 +4610,9 @@ PQresetStart(PGconn *conn)
 {
    if (conn)
    {
-       closePGconn(conn);
+       pqClosePGconn(conn);
 
-       return connectDBStart(conn);
+       return pqConnectDBStart(conn);
    }
 
    return 0;
index 5ac50fe20cb52d9c259379af2012236305349f06..82c18f870d2adfd341e72950fe12f5d79574661d 100644 (file)
@@ -675,10 +675,15 @@ extern char *const pgresStatus[];
 /* === in fe-connect.c === */
 
 extern void pqDropConnection(PGconn *conn, bool flushInput);
+extern bool pqConnectOptions2(PGconn *conn);
 #if defined(WIN32) && defined(SIO_KEEPALIVE_VALS)
 extern int pqSetKeepalivesWin32(pgsocket sock, int idle, int interval);
 #endif
+extern int pqConnectDBStart(PGconn *conn);
+extern int pqConnectDBComplete(PGconn *conn);
+extern PGconn *pqMakeEmptyPGconn(void);
 extern void pqReleaseConnHosts(PGconn *conn);
+extern void pqClosePGconn(PGconn *conn);
 extern int pqPacketSend(PGconn *conn, char pack_type,
                         const void *buf, size_t buf_len);
 extern bool pqGetHomeDirectory(char *buf, int bufsize);