aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/libpq')
-rw-r--r--src/interfaces/libpq/fe-connect.c41
-rw-r--r--src/interfaces/libpq/fe-exec.c69
-rw-r--r--src/interfaces/libpq/fe-lobj.c8
-rw-r--r--src/interfaces/libpq/fe-misc.c21
-rw-r--r--src/interfaces/libpq/fe-print.c3
-rw-r--r--src/interfaces/libpq/fe-protocol2.c16
-rw-r--r--src/interfaces/libpq/fe-protocol3.c10
-rw-r--r--src/interfaces/libpq/fe-secure.c147
-rw-r--r--src/interfaces/libpq/libpq-fe.h55
-rw-r--r--src/interfaces/libpq/libpq-int.h6
-rw-r--r--src/interfaces/libpq/pqexpbuffer.c4
-rw-r--r--src/interfaces/libpq/pqsignal.c10
-rw-r--r--src/interfaces/libpq/pthread-win32.c32
-rw-r--r--src/interfaces/libpq/win32.c2
14 files changed, 231 insertions, 193 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index a72f71de932..625de2a5331 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.283 2004/08/29 04:13:12 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.284 2004/08/29 05:07:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -449,7 +449,7 @@ connectOptions2(PGconn *conn)
{
conn->status = CONNECTION_BAD;
printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext("invalid sslmode value: \"%s\"\n"),
+ libpq_gettext("invalid sslmode value: \"%s\"\n"),
conn->sslmode);
return false;
}
@@ -881,6 +881,7 @@ connectDBStart(PGconn *conn)
struct addrinfo hint;
const char *node = NULL;
int ret;
+
#ifdef ENABLE_THREAD_SAFETY
#ifndef WIN32
static pthread_once_t check_sigpipe_once = PTHREAD_ONCE_INIT;
@@ -2283,11 +2284,12 @@ retry4:
}
/*
- * Wait for the postmaster to close the connection, which indicates that
- * it's processed the request. Without this delay, we might issue another
- * command only to find that our cancel zaps that command instead of the
- * one we thought we were canceling. Note we don't actually expect this
- * read to obtain any data, we are just waiting for EOF to be signaled.
+ * Wait for the postmaster to close the connection, which indicates
+ * that it's processed the request. Without this delay, we might
+ * issue another command only to find that our cancel zaps that
+ * command instead of the one we thought we were canceling. Note we
+ * don't actually expect this read to obtain any data, we are just
+ * waiting for EOF to be signaled.
*/
retry5:
if (recv(tmpsock, (char *) &crp, 1, 0) < 0)
@@ -2385,11 +2387,11 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
service = getenv("PGSERVICE");
/*
- * This could be used by any application so we can't use the binary
- * location to find our config files.
- */
+ * This could be used by any application so we can't use the binary
+ * location to find our config files.
+ */
snprintf(serviceFile, MAXPGPATH, "%s/pg_service.conf",
- getenv("PGSYSCONFDIR") ? getenv("PGSYSCONFDIR") : SYSCONFDIR);
+ getenv("PGSYSCONFDIR") ? getenv("PGSYSCONFDIR") : SYSCONFDIR);
if (service != NULL)
{
@@ -3112,12 +3114,12 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
port = DEF_PGPORT_STR;
/*
- * Look for it in the home dir.
- * We don't use get_home_path() so we don't pull path.c into our library.
+ * Look for it in the home dir. We don't use get_home_path() so we
+ * don't pull path.c into our library.
*/
if (!(home = getenv(HOMEDIR)))
return NULL;
-
+
pgpassfile = malloc(strlen(home) + 1 + strlen(PGPASSFILE) + 1);
if (!pgpassfile)
{
@@ -3208,16 +3210,18 @@ default_threadlock(int acquire)
#ifdef ENABLE_THREAD_SAFETY
#ifndef WIN32
static pthread_mutex_t singlethread_lock = PTHREAD_MUTEX_INITIALIZER;
+
#else
static pthread_mutex_t singlethread_lock = NULL;
static long mutex_initlock = 0;
- if (singlethread_lock == NULL) {
- while(InterlockedExchange(&mutex_initlock, 1) == 1)
- /* loop, another thread own the lock */ ;
+ if (singlethread_lock == NULL)
+ {
+ while (InterlockedExchange(&mutex_initlock, 1) == 1)
+ /* loop, another thread own the lock */ ;
if (singlethread_lock == NULL)
pthread_mutex_init(&singlethread_lock, NULL);
- InterlockedExchange(&mutex_initlock,0);
+ InterlockedExchange(&mutex_initlock, 0);
}
#endif
if (acquire)
@@ -3241,4 +3245,3 @@ PQregisterThreadLock(pgthreadlock_t *newhandler)
g_threadlock = default_threadlock;
return prev;
}
-
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index 1168eec8646..7b8b607e575 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.160 2004/08/29 04:13:12 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.161 2004/08/29 05:07:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -45,14 +45,14 @@ char *const pgresStatus[] = {
static bool PQsendQueryStart(PGconn *conn);
static int PQsendQueryGuts(PGconn *conn,
- const char *command,
- const char *stmtName,
- int nParams,
- const Oid *paramTypes,
- const char *const * paramValues,
- const int *paramLengths,
- const int *paramFormats,
- int resultFormat);
+ const char *command,
+ const char *stmtName,
+ int nParams,
+ const Oid *paramTypes,
+ const char *const * paramValues,
+ const int *paramLengths,
+ const int *paramFormats,
+ int resultFormat);
static void parseInput(PGconn *conn);
static bool PQexecStart(PGconn *conn);
static PGresult *PQexecFinish(PGconn *conn);
@@ -623,7 +623,7 @@ pqSaveParameterStatus(PGconn *conn, const char *name, const char *value)
cnt = sscanf(value, "%d.%d.%d", &vmaj, &vmin, &vrev);
if (cnt < 2)
- conn->sversion = 0; /* unknown */
+ conn->sversion = 0; /* unknown */
else
{
if (cnt == 2)
@@ -737,15 +737,15 @@ PQsendQueryPrepared(PGconn *conn,
if (!stmtName)
{
printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext("statement name is a null pointer\n"));
+ libpq_gettext("statement name is a null pointer\n"));
return 0;
}
return PQsendQueryGuts(conn,
- NULL, /* no command to parse */
+ NULL, /* no command to parse */
stmtName,
nParams,
- NULL, /* no param types */
+ NULL, /* no param types */
paramValues,
paramLengths,
paramFormats,
@@ -811,13 +811,13 @@ PQsendQueryGuts(PGconn *conn,
if (PG_PROTOCOL_MAJOR(conn->pversion) < 3)
{
printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext("function requires at least protocol version 3.0\n"));
+ libpq_gettext("function requires at least protocol version 3.0\n"));
return 0;
}
/*
- * We will send Parse (if needed), Bind, Describe Portal, Execute, Sync,
- * using specified statement name and the unnamed portal.
+ * We will send Parse (if needed), Bind, Describe Portal, Execute,
+ * Sync, using specified statement name and the unnamed portal.
*/
if (command)
@@ -1445,6 +1445,7 @@ PQputCopyEnd(PGconn *conn, const char *errormsg)
pqPutMsgEnd(conn) < 0)
return -1;
}
+
/*
* If we sent the COPY command in extended-query mode, we must
* issue a Sync as well.
@@ -1462,7 +1463,7 @@ PQputCopyEnd(PGconn *conn, const char *errormsg)
{
/* Ooops, no way to do this in 2.0 */
printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext("function requires at least protocol version 3.0\n"));
+ libpq_gettext("function requires at least protocol version 3.0\n"));
return -1;
}
else
@@ -1843,7 +1844,7 @@ PQfname(const PGresult *res, int field_num)
* downcasing in the frontend might follow different locale rules than
* downcasing in the backend...
*
- * Returns -1 if no match. In the present backend it is also possible
+ * Returns -1 if no match. In the present backend it is also possible
* to have multiple matches, in which case the first one is found.
*/
int
@@ -1859,8 +1860,8 @@ PQfnumber(const PGresult *res, const char *field_name)
return -1;
/*
- * Note: it is correct to reject a zero-length input string; the proper
- * input to match a zero-length field name would be "".
+ * Note: it is correct to reject a zero-length input string; the
+ * proper input to match a zero-length field name would be "".
*/
if (field_name == NULL ||
field_name[0] == '\0' ||
@@ -1869,8 +1870,8 @@ PQfnumber(const PGresult *res, const char *field_name)
/*
* Note: this code will not reject partially quoted strings, eg
- * foo"BAR"foo will become fooBARfoo when it probably ought to be
- * an error condition.
+ * foo"BAR"foo will become fooBARfoo when it probably ought to be an
+ * error condition.
*/
field_case = strdup(field_name);
if (field_case == NULL)
@@ -1880,7 +1881,7 @@ PQfnumber(const PGresult *res, const char *field_name)
optr = field_case;
for (iptr = field_case; *iptr; iptr++)
{
- char c = *iptr;
+ char c = *iptr;
if (in_quotes)
{
@@ -1899,9 +1900,7 @@ PQfnumber(const PGresult *res, const char *field_name)
*optr++ = c;
}
else if (c == '"')
- {
in_quotes = true;
- }
else
{
c = pg_tolower((unsigned char) c);
@@ -2148,7 +2147,7 @@ PQgetisnull(const PGresult *res, int tup_num, int field_num)
int
PQsetnonblocking(PGconn *conn, int arg)
{
- bool barg;
+ bool barg;
if (!conn || conn->status == CONNECTION_BAD)
return -1;
@@ -2283,7 +2282,7 @@ PQescapeString(char *to, const char *from, size_t length)
* '\'' == ASCII 39 == \'
* '\\' == ASCII 92 == \\\\
* anything < 0x20, or > 0x7e ---> \\ooo
- * (where ooo is an octal expression)
+ * (where ooo is an octal expression)
*/
unsigned char *
PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen)
@@ -2378,6 +2377,7 @@ PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen)
return NULL;
strtextlen = strlen(strtext);
+
/*
* Length of input is max length of output, but add one to avoid
* unportable malloc(0) if input is zero-length.
@@ -2386,7 +2386,7 @@ PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen)
if (buffer == NULL)
return NULL;
- for (i = j = 0; i < strtextlen; )
+ for (i = j = 0; i < strtextlen;)
{
switch (strtext[i])
{
@@ -2400,7 +2400,7 @@ PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen)
(ISOCTDIGIT(strtext[i + 1])) &&
(ISOCTDIGIT(strtext[i + 2])))
{
- int byte;
+ int byte;
byte = OCTVAL(strtext[i++]);
byte = (byte << 3) + OCTVAL(strtext[i++]);
@@ -2408,12 +2408,13 @@ PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen)
buffer[j++] = byte;
}
}
+
/*
- * Note: if we see '\' followed by something that isn't
- * a recognized escape sequence, we loop around having
- * done nothing except advance i. Therefore the something
- * will be emitted as ordinary data on the next cycle.
- * Corner case: '\' at end of string will just be discarded.
+ * Note: if we see '\' followed by something that isn't a
+ * recognized escape sequence, we loop around having done
+ * nothing except advance i. Therefore the something will
+ * be emitted as ordinary data on the next cycle. Corner
+ * case: '\' at end of string will just be discarded.
*/
break;
diff --git a/src/interfaces/libpq/fe-lobj.c b/src/interfaces/libpq/fe-lobj.c
index 8138d0dae91..2c70fc09241 100644
--- a/src/interfaces/libpq/fe-lobj.c
+++ b/src/interfaces/libpq/fe-lobj.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.50 2004/08/29 04:13:12 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.51 2004/08/29 05:07:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -520,7 +520,7 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
if (close(fd))
{
printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext("error while writing to file \"%s\"\n"),
+ libpq_gettext("error while writing to file \"%s\"\n"),
filename);
return -1;
}
@@ -559,8 +559,8 @@ lo_initialize(PGconn *conn)
MemSet((char *) lobjfuncs, 0, sizeof(PGlobjfuncs));
/*
- * Execute the query to get all the functions at once. In 7.3 and later
- * we need to be schema-safe.
+ * Execute the query to get all the functions at once. In 7.3 and
+ * later we need to be schema-safe.
*/
if (conn->sversion >= 70300)
query = "select proname, oid from pg_catalog.pg_proc "
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index a1c69ebdb76..212f7a63cd4 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -23,7 +23,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.109 2004/08/29 04:13:12 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.110 2004/08/29 05:07:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -830,15 +830,16 @@ pqSendSome(PGconn *conn, int len)
/*
* There are scenarios in which we can't send data because the
- * communications channel is full, but we cannot expect the server
- * to clear the channel eventually because it's blocked trying to
- * send data to us. (This can happen when we are sending a large
- * amount of COPY data, and the server has generated lots of
- * NOTICE responses.) To avoid a deadlock situation, we must be
- * prepared to accept and buffer incoming data before we try
- * again. Furthermore, it is possible that such incoming data
- * might not arrive until after we've gone to sleep. Therefore,
- * we wait for either read ready or write ready.
+ * communications channel is full, but we cannot expect the
+ * server to clear the channel eventually because it's blocked
+ * trying to send data to us. (This can happen when we are
+ * sending a large amount of COPY data, and the server has
+ * generated lots of NOTICE responses.) To avoid a deadlock
+ * situation, we must be prepared to accept and buffer
+ * incoming data before we try again. Furthermore, it is
+ * possible that such incoming data might not arrive until
+ * after we've gone to sleep. Therefore, we wait for either
+ * read ready or write ready.
*/
if (pqReadData(conn) < 0)
{
diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c
index 992af524450..bd89e825c77 100644
--- a/src/interfaces/libpq/fe-print.c
+++ b/src/interfaces/libpq/fe-print.c
@@ -10,7 +10,7 @@
* didn't really belong there.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-print.c,v 1.53 2004/08/29 04:13:12 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-print.c,v 1.54 2004/08/29 05:07:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -91,6 +91,7 @@ PQprint(FILE *fout,
int total_line_length = 0;
int usePipe = 0;
char *pagerenv;
+
#if !defined(ENABLE_THREAD_SAFETY) && !defined(WIN32)
pqsigfunc oldsigpipehandler = NULL;
#endif
diff --git a/src/interfaces/libpq/fe-protocol2.c b/src/interfaces/libpq/fe-protocol2.c
index a69c115a740..9fe877841c0 100644
--- a/src/interfaces/libpq/fe-protocol2.c
+++ b/src/interfaces/libpq/fe-protocol2.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.12 2004/08/29 04:13:12 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.13 2004/08/29 05:07:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -177,10 +177,10 @@ pqSetenvPoll(PGconn *conn)
* must use begin/commit in case autocommit is off by
* default in a 7.3 server.
*
- * Note: version() exists in all
- * protocol-2.0-supporting backends. In 7.3 it would
- * be safer to write pg_catalog.version(), but we can't
- * do that without causing problems on older versions.
+ * Note: version() exists in all protocol-2.0-supporting
+ * backends. In 7.3 it would be safer to write
+ * pg_catalog.version(), but we can't do that without
+ * causing problems on older versions.
*/
if (!PQsendQuery(conn, "begin; select version(); end"))
goto error_return;
@@ -303,9 +303,9 @@ pqSetenvPoll(PGconn *conn)
else
{
/*
- * Error: presumably function not
- * available, so use PGCLIENTENCODING or
- * SQL_ASCII as the fallback.
+ * Error: presumably function not available,
+ * so use PGCLIENTENCODING or SQL_ASCII as the
+ * fallback.
*/
val = getenv("PGCLIENTENCODING");
if (val && *val)
diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c
index 23281bd423c..68789067d2b 100644
--- a/src/interfaces/libpq/fe-protocol3.c
+++ b/src/interfaces/libpq/fe-protocol3.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.14 2004/08/29 04:13:12 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.15 2004/08/29 05:07:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -261,15 +261,16 @@ pqParseInput3(PGconn *conn)
}
break;
case 'n': /* No Data */
+
/*
* NoData indicates that we will not be seeing a
* RowDescription message because the statement or
- * portal inquired about doesn't return rows.
- * Set up a COMMAND_OK result, instead of TUPLES_OK.
+ * portal inquired about doesn't return rows. Set up a
+ * COMMAND_OK result, instead of TUPLES_OK.
*/
if (conn->result == NULL)
conn->result = PQmakeEmptyPGresult(conn,
- PGRES_COMMAND_OK);
+ PGRES_COMMAND_OK);
break;
case 'D': /* Data Row */
if (conn->result != NULL &&
@@ -1107,6 +1108,7 @@ pqEndcopy3(PGconn *conn)
if (pqPutMsgStart('c', false, conn) < 0 ||
pqPutMsgEnd(conn) < 0)
return 1;
+
/*
* If we sent the COPY command in extended-query mode, we must
* issue a Sync as well.
diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
index 6a54ba09bef..db254e52c27 100644
--- a/src/interfaces/libpq/fe-secure.c
+++ b/src/interfaces/libpq/fe-secure.c
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.48 2004/08/29 04:13:12 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.49 2004/08/29 05:07:00 momjian Exp $
*
* NOTES
* The client *requires* a valid server certificate. Since
@@ -145,7 +145,7 @@ static void SSLerrfree(char *buf);
#endif
#ifdef USE_SSL
-bool pq_initssllib = true;
+bool pq_initssllib = true;
static SSL_CTX *SSL_context = NULL;
#endif
@@ -256,7 +256,8 @@ pqsecure_open_client(PGconn *conn)
!SSL_set_app_data(conn->ssl, conn) ||
!SSL_set_fd(conn->ssl, conn->sock))
{
- char *err = SSLerrmessage();
+ char *err = SSLerrmessage();
+
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not establish SSL connection: %s\n"),
err);
@@ -335,9 +336,10 @@ rloop:
}
case SSL_ERROR_SSL:
{
- char *err = SSLerrmessage();
+ char *err = SSLerrmessage();
+
printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext("SSL error: %s\n"), err);
+ libpq_gettext("SSL error: %s\n"), err);
SSLerrfree(err);
}
/* fall through */
@@ -347,7 +349,7 @@ rloop:
break;
default:
printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext("unrecognized SSL error code\n"));
+ libpq_gettext("unrecognized SSL error code\n"));
n = -1;
break;
}
@@ -414,9 +416,10 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
}
case SSL_ERROR_SSL:
{
- char *err = SSLerrmessage();
+ char *err = SSLerrmessage();
+
printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext("SSL error: %s\n"), err);
+ libpq_gettext("SSL error: %s\n"), err);
SSLerrfree(err);
}
/* fall through */
@@ -426,7 +429,7 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
break;
default:
printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext("unrecognized SSL error code\n"));
+ libpq_gettext("unrecognized SSL error code\n"));
n = -1;
break;
}
@@ -501,12 +504,12 @@ verify_peer(PGconn *conn)
struct hostent hpstr;
char buf[BUFSIZ];
int herrno = 0;
-
+
/*
- * Currently, pqGethostbyname() is used only on platforms that
- * don't have getaddrinfo(). If you enable this function,
- * you should convert the pqGethostbyname() function call to
- * use getaddrinfo().
+ * Currently, pqGethostbyname() is used only on platforms that
+ * don't have getaddrinfo(). If you enable this function, you
+ * should convert the pqGethostbyname() function call to use
+ * getaddrinfo().
*/
pqGethostbyname(conn->peer_cn, &hpstr, buf, sizeof(buf),
&h, &herrno);
@@ -583,7 +586,7 @@ static DH *
load_dh_file(int keylength)
{
#ifdef WIN32
- return NULL;
+ return NULL;
#else
char pwdbuf[BUFSIZ];
struct passwd pwdstr;
@@ -730,7 +733,7 @@ static int
client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
{
#ifdef WIN32
- return 0;
+ return 0;
#else
char pwdbuf[BUFSIZ];
struct passwd pwdstr;
@@ -765,7 +768,8 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
}
if (PEM_read_X509(fp, x509, NULL, NULL) == NULL)
{
- char *err = SSLerrmessage();
+ char *err = SSLerrmessage();
+
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not read certificate (%s): %s\n"),
fnbuf, err);
@@ -812,7 +816,8 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
}
if (PEM_read_PrivateKey(fp, pkey, cb, NULL) == NULL)
{
- char *err = SSLerrmessage();
+ char *err = SSLerrmessage();
+
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not read private key (%s): %s\n"),
fnbuf, err);
@@ -826,7 +831,8 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
/* verify that the cert and key go together */
if (!X509_check_private_key(*x509, *pkey))
{
- char *err = SSLerrmessage();
+ char *err = SSLerrmessage();
+
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("certificate/private key mismatch (%s): %s\n"),
fnbuf, err);
@@ -845,52 +851,55 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
static unsigned long
pq_threadidcallback(void)
{
- return (unsigned long)pthread_self();
+ return (unsigned long) pthread_self();
}
static pthread_mutex_t *pq_lockarray;
static void
pq_lockingcallback(int mode, int n, const char *file, int line)
{
- if (mode & CRYPTO_LOCK) {
+ if (mode & CRYPTO_LOCK)
pthread_mutex_lock(&pq_lockarray[n]);
- } else {
+ else
pthread_mutex_unlock(&pq_lockarray[n]);
- }
}
-
-#endif /* ENABLE_THREAD_SAFETY */
+#endif /* ENABLE_THREAD_SAFETY */
static int
init_ssl_system(PGconn *conn)
{
#ifdef ENABLE_THREAD_SAFETY
#ifndef WIN32
- static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER;
+ static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER;
+
#else
static pthread_mutex_t init_mutex = NULL;
static long mutex_initlock = 0;
- if (init_mutex == NULL) {
- while(InterlockedExchange(&mutex_initlock, 1) == 1)
- /* loop, another thread own the lock */ ;
+ if (init_mutex == NULL)
+ {
+ while (InterlockedExchange(&mutex_initlock, 1) == 1)
+ /* loop, another thread own the lock */ ;
if (init_mutex == NULL)
pthread_mutex_init(&init_mutex, NULL);
- InterlockedExchange(&mutex_initlock,0);
+ InterlockedExchange(&mutex_initlock, 0);
}
#endif
pthread_mutex_lock(&init_mutex);
-
- if (pq_initssllib && pq_lockarray == NULL) {
- int i;
+
+ if (pq_initssllib && pq_lockarray == NULL)
+ {
+ int i;
+
CRYPTO_set_id_callback(pq_threadidcallback);
- pq_lockarray = malloc(sizeof(pthread_mutex_t)*CRYPTO_num_locks());
- if (!pq_lockarray) {
+ pq_lockarray = malloc(sizeof(pthread_mutex_t) * CRYPTO_num_locks());
+ if (!pq_lockarray)
+ {
pthread_mutex_unlock(&init_mutex);
return -1;
}
- for (i=0;i<CRYPTO_num_locks();i++)
+ for (i = 0; i < CRYPTO_num_locks(); i++)
pthread_mutex_init(&pq_lockarray[i], NULL);
CRYPTO_set_locking_callback(pq_lockingcallback);
@@ -898,14 +907,16 @@ init_ssl_system(PGconn *conn)
#endif
if (!SSL_context)
{
- if (pq_initssllib) {
+ if (pq_initssllib)
+ {
SSL_library_init();
SSL_load_error_strings();
}
SSL_context = SSL_CTX_new(TLSv1_method());
if (!SSL_context)
{
- char *err = SSLerrmessage();
+ char *err = SSLerrmessage();
+
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not create SSL context: %s\n"),
err);
@@ -921,6 +932,7 @@ init_ssl_system(PGconn *conn)
#endif
return 0;
}
+
/*
* Initialize global SSL context.
*/
@@ -935,7 +947,7 @@ initialize_SSL(PGconn *conn)
char fnbuf[2048];
#endif
- if(init_ssl_system(conn))
+ if (init_ssl_system(conn))
return -1;
#ifndef WIN32
@@ -958,7 +970,8 @@ initialize_SSL(PGconn *conn)
}
if (!SSL_CTX_load_verify_locations(SSL_context, fnbuf, 0))
{
- char *err = SSLerrmessage();
+ char *err = SSLerrmessage();
+
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not read root certificate list (%s): %s\n"),
fnbuf, err);
@@ -1030,9 +1043,10 @@ open_client_SSL(PGconn *conn)
}
case SSL_ERROR_SSL:
{
- char *err = SSLerrmessage();
+ char *err = SSLerrmessage();
+
printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext("SSL error: %s\n"), err);
+ libpq_gettext("SSL error: %s\n"), err);
SSLerrfree(err);
close_SSL(conn);
return PGRES_POLLING_FAILED;
@@ -1040,7 +1054,7 @@ open_client_SSL(PGconn *conn)
default:
printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext("unrecognized SSL error code\n"));
+ libpq_gettext("unrecognized SSL error code\n"));
close_SSL(conn);
return PGRES_POLLING_FAILED;
}
@@ -1070,7 +1084,8 @@ open_client_SSL(PGconn *conn)
conn->peer = SSL_get_peer_certificate(conn->ssl);
if (conn->peer == NULL)
{
- char *err = SSLerrmessage();
+ char *err = SSLerrmessage();
+
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("certificate could not be obtained: %s\n"),
err);
@@ -1136,27 +1151,30 @@ close_SSL(PGconn *conn)
* want to return NULL ever.
*/
static char ssl_nomem[] = "Out of memory allocating error description";
-#define SSL_ERR_LEN 128
+
+#define SSL_ERR_LEN 128
static char *
SSLerrmessage(void)
{
unsigned long errcode;
const char *errreason;
- char *errbuf;
+ char *errbuf;
errbuf = malloc(SSL_ERR_LEN);
if (!errbuf)
return ssl_nomem;
errcode = ERR_get_error();
- if (errcode == 0) {
+ if (errcode == 0)
+ {
strcpy(errbuf, "No SSL error reported");
return errbuf;
}
errreason = ERR_reason_error_string(errcode);
- if (errreason != NULL) {
- strncpy(errbuf, errreason, SSL_ERR_LEN-1);
- errbuf[SSL_ERR_LEN-1] = '\0';
+ if (errreason != NULL)
+ {
+ strncpy(errbuf, errreason, SSL_ERR_LEN - 1);
+ errbuf[SSL_ERR_LEN - 1] = '\0';
return errbuf;
}
snprintf(errbuf, SSL_ERR_LEN, "SSL error code %lu", errcode);
@@ -1169,6 +1187,7 @@ SSLerrfree(char *buf)
if (buf != ssl_nomem)
free(buf);
}
+
/*
* Return pointer to SSL object.
*/
@@ -1179,7 +1198,6 @@ PQgetssl(PGconn *conn)
return NULL;
return conn->ssl;
}
-
#endif /* USE_SSL */
@@ -1192,8 +1210,9 @@ void
pq_check_sigpipe_handler(void)
{
pthread_key_create(&pq_thread_in_send, NULL);
+
/*
- * Find current pipe handler and chain on to it.
+ * Find current pipe handler and chain on to it.
*/
pq_pipe_handler = pqsignalinquire(SIGPIPE);
pqsignal(SIGPIPE, sigpipe_handler_ignore_send);
@@ -1206,22 +1225,21 @@ void
sigpipe_handler_ignore_send(int signo)
{
/*
- * If we have gotten a SIGPIPE outside send(), chain or
- * exit if we are at the end of the chain.
- * Synchronous signals are delivered to the thread that
- * caused the signal.
+ * If we have gotten a SIGPIPE outside send(), chain or exit if we are
+ * at the end of the chain. Synchronous signals are delivered to the
+ * thread that caused the signal.
*/
if (!PQinSend())
{
- if (pq_pipe_handler == SIG_DFL) /* not set by application */
+ if (pq_pipe_handler == SIG_DFL) /* not set by application */
exit(128 + SIGPIPE); /* typical return value for SIG_DFL */
else
- (*pq_pipe_handler)(signo); /* call original handler */
+ (*pq_pipe_handler) (signo); /* call original handler */
}
}
#endif
#endif
-
+
/*
* Indicates whether the current thread is in send()
* For use by SIGPIPE signal handlers; they should
@@ -1233,13 +1251,14 @@ PQinSend(void)
{
#ifdef ENABLE_THREAD_SAFETY
return (pthread_getspecific(pq_thread_in_send) /* has it been set? */ &&
- *(char *)pthread_getspecific(pq_thread_in_send) == 't') ? true : false;
+ *(char *) pthread_getspecific(pq_thread_in_send) == 't') ? true : false;
#else
+
/*
- * No threading: our code ignores SIGPIPE around send().
- * Therefore, we can't be in send() if we are checking
- * from a SIGPIPE signal handler.
+ * No threading: our code ignores SIGPIPE around send(). Therefore, we
+ * can't be in send() if we are checking from a SIGPIPE signal
+ * handler.
*/
- return false;
+ return false;
#endif
}
diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h
index 60ab1d0d564..ff1a2c1ad69 100644
--- a/src/interfaces/libpq/libpq-fe.h
+++ b/src/interfaces/libpq/libpq-fe.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.107 2004/08/29 04:13:12 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.108 2004/08/29 05:07:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -248,7 +248,7 @@ extern PGTransactionStatusType PQtransactionStatus(const PGconn *conn);
extern const char *PQparameterStatus(const PGconn *conn,
const char *paramName);
extern int PQprotocolVersion(const PGconn *conn);
-extern int PQserverVersion(const PGconn *conn);
+extern int PQserverVersion(const PGconn *conn);
extern char *PQerrorMessage(const PGconn *conn);
extern int PQsocket(const PGconn *conn);
extern int PQbackendPID(const PGconn *conn);
@@ -276,15 +276,15 @@ extern PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn,
void *arg);
/*
- * Used to set callback that prevents concurrent access to
- * non-thread safe functions that libpq needs.
- * The default implementation uses a libpq internal mutex.
- * Only required for multithreaded apps that use kerberos
- * both within their app and for postgresql connections.
+ * Used to set callback that prevents concurrent access to
+ * non-thread safe functions that libpq needs.
+ * The default implementation uses a libpq internal mutex.
+ * Only required for multithreaded apps that use kerberos
+ * both within their app and for postgresql connections.
*/
-typedef void (pgthreadlock_t)(int acquire);
+typedef void (pgthreadlock_t) (int acquire);
-extern pgthreadlock_t * PQregisterThreadLock(pgthreadlock_t *newhandler);
+extern pgthreadlock_t *PQregisterThreadLock(pgthreadlock_t *newhandler);
extern void PQinitSSL(int do_init);
@@ -301,12 +301,12 @@ extern PGresult *PQexecParams(PGconn *conn,
const int *paramFormats,
int resultFormat);
extern PGresult *PQexecPrepared(PGconn *conn,
- const char *stmtName,
- int nParams,
- const char *const * paramValues,
- const int *paramLengths,
- const int *paramFormats,
- int resultFormat);
+ const char *stmtName,
+ int nParams,
+ const char *const * paramValues,
+ const int *paramLengths,
+ const int *paramFormats,
+ int resultFormat);
/* Interface for multiple-result or asynchronous queries */
extern int PQsendQuery(PGconn *conn, const char *query);
@@ -319,12 +319,12 @@ extern int PQsendQueryParams(PGconn *conn,
const int *paramFormats,
int resultFormat);
extern int PQsendQueryPrepared(PGconn *conn,
- const char *stmtName,
- int nParams,
- const char *const * paramValues,
- const int *paramLengths,
- const int *paramFormats,
- int resultFormat);
+ const char *stmtName,
+ int nParams,
+ const char *const * paramValues,
+ const int *paramLengths,
+ const int *paramFormats,
+ int resultFormat);
extern PGresult *PQgetResult(PGconn *conn);
/* Routines for managing an asynchronous query */
@@ -417,21 +417,24 @@ extern unsigned char *PQunescapeBytea(const unsigned char *strtext,
/* === in fe-print.c === */
-extern void PQprint(FILE *fout, /* output stream */
- const PGresult *res,
- const PQprintOpt *ps); /* option structure */
+extern void
+PQprint(FILE *fout, /* output stream */
+ const PGresult *res,
+ const PQprintOpt *ps); /* option structure */
/*
* really old printing routines
*/
-extern void PQdisplayTuples(const PGresult *res,
+extern void
+PQdisplayTuples(const PGresult *res,
FILE *fp, /* where to send the output */
int fillAlign, /* pad the fields with spaces */
const char *fieldSep, /* field separator */
int printHeader, /* display headers? */
int quiet);
-extern void PQprintTuples(const PGresult *res,
+extern void
+PQprintTuples(const PGresult *res,
FILE *fout, /* output stream */
int printAttName, /* print attribute names */
int terseOutput, /* delimiter bars */
diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h
index ecf8fab50a9..3037b0d2669 100644
--- a/src/interfaces/libpq/libpq-int.h
+++ b/src/interfaces/libpq/libpq-int.h
@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.90 2004/08/29 04:13:12 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.91 2004/08/29 05:07:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -361,13 +361,14 @@ extern int pqPacketSend(PGconn *conn, char pack_type,
#ifdef ENABLE_THREAD_SAFETY
extern pgthreadlock_t *g_threadlock;
+
#define pglock_thread() g_threadlock(true);
#define pgunlock_thread() g_threadlock(false);
#else
#define pglock_thread() ((void)0)
#define pgunlock_thread() ((void)0)
#endif
-
+
/* === in fe-exec.c === */
@@ -455,6 +456,7 @@ extern PostgresPollingStatusType pqsecure_open_client(PGconn *);
extern void pqsecure_close(PGconn *);
extern ssize_t pqsecure_read(PGconn *, void *ptr, size_t len);
extern ssize_t pqsecure_write(PGconn *, const void *ptr, size_t len);
+
#ifdef ENABLE_THREAD_SAFETY
extern void pq_check_sigpipe_handler(void);
extern pthread_key_t pq_thread_in_send;
diff --git a/src/interfaces/libpq/pqexpbuffer.c b/src/interfaces/libpq/pqexpbuffer.c
index 58a2cc01ab9..0afb8e714cb 100644
--- a/src/interfaces/libpq/pqexpbuffer.c
+++ b/src/interfaces/libpq/pqexpbuffer.c
@@ -17,7 +17,7 @@
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/interfaces/libpq/pqexpbuffer.c,v 1.18 2004/08/29 04:13:12 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/pqexpbuffer.c,v 1.19 2004/08/29 05:07:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -136,7 +136,7 @@ enlargePQExpBuffer(PQExpBuffer str, size_t needed)
/*
* Guard against ridiculous "needed" values, which can occur if we're
- * fed bogus data. Without this, we can get an overflow or infinite
+ * fed bogus data. Without this, we can get an overflow or infinite
* loop in the following.
*/
if (needed >= ((size_t) INT_MAX - str->len))
diff --git a/src/interfaces/libpq/pqsignal.c b/src/interfaces/libpq/pqsignal.c
index 226f90771cd..4bd24b78eb4 100644
--- a/src/interfaces/libpq/pqsignal.c
+++ b/src/interfaces/libpq/pqsignal.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/pqsignal.c,v 1.22 2004/08/29 04:13:12 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/pqsignal.c,v 1.23 2004/08/29 05:07:00 momjian Exp $
*
* NOTES
* This shouldn't be in libpq, but the monitor and some other
@@ -50,12 +50,12 @@ pqsignalinquire(int signo)
{
#ifndef WIN32
#if !defined(HAVE_POSIX_SIGNALS)
- pqsigfunc old_sigfunc;
- int old_sigmask;
+ pqsigfunc old_sigfunc;
+ int old_sigmask;
/* Prevent signal handler calls during test */
old_sigmask = sigblock(sigmask(signo));
- old_sigfunc = signal(signo, SIG_DFL);
+ old_sigfunc = signal(signo, SIG_DFL);
signal(signo, old_sigfunc);
sigblock(old_sigmask);
return old_sigfunc;
@@ -63,7 +63,7 @@ pqsignalinquire(int signo)
struct sigaction oact;
if (sigaction(signo, NULL, &oact) < 0)
- return SIG_ERR;
+ return SIG_ERR;
return oact.sa_handler;
#endif /* !HAVE_POSIX_SIGNALS */
#else
diff --git a/src/interfaces/libpq/pthread-win32.c b/src/interfaces/libpq/pthread-win32.c
index 87546424df0..24bdca29185 100644
--- a/src/interfaces/libpq/pthread-win32.c
+++ b/src/interfaces/libpq/pthread-win32.c
@@ -1,11 +1,11 @@
/*-------------------------------------------------------------------------
*
* pthread-win32.c
-* partial pthread implementation for win32
+* partial pthread implementation for win32
*
* Copyright (c) 2004, PostgreSQL Global Development Group
* IDENTIFICATION
-* $PostgreSQL: pgsql/src/interfaces/libpq/pthread-win32.c,v 1.1 2004/06/19 04:22:17 momjian Exp $
+* $PostgreSQL: pgsql/src/interfaces/libpq/pthread-win32.c,v 1.2 2004/08/29 05:07:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -14,31 +14,37 @@
#include "windows.h"
#include "pthread.h"
-HANDLE pthread_self()
+HANDLE
+pthread_self()
{
- return GetCurrentThread();
+ return GetCurrentThread();
}
-void pthread_setspecific(pthread_key_t key, void *val)
+void
+pthread_setspecific(pthread_key_t key, void *val)
{
}
-void *pthread_getspecific(pthread_key_t key)
+void *
+pthread_getspecific(pthread_key_t key)
{
- return NULL;
+ return NULL;
}
-void pthread_mutex_init(pthread_mutex_t *mp, void *attr)
+void
+pthread_mutex_init(pthread_mutex_t *mp, void *attr)
{
- *mp = CreateMutex(0, 0, 0);
+ *mp = CreateMutex(0, 0, 0);
}
-void pthread_mutex_lock(pthread_mutex_t *mp)
+void
+pthread_mutex_lock(pthread_mutex_t *mp)
{
- WaitForSingleObject(*mp, INFINITE);
+ WaitForSingleObject(*mp, INFINITE);
}
-void pthread_mutex_unlock(pthread_mutex_t *mp)
+void
+pthread_mutex_unlock(pthread_mutex_t *mp)
{
- ReleaseMutex(*mp);
+ ReleaseMutex(*mp);
}
diff --git a/src/interfaces/libpq/win32.c b/src/interfaces/libpq/win32.c
index 4e5820ec260..b2c77063e1f 100644
--- a/src/interfaces/libpq/win32.c
+++ b/src/interfaces/libpq/win32.c
@@ -314,7 +314,7 @@ winsock_strerror(int err, char *strerrbuf, size_t buflen)
{
strerrbuf[buflen - 1] = '\0';
offs = strlen(strerrbuf);
- if (offs > (int)buflen - 64)
+ if (offs > (int) buflen - 64)
offs = buflen - 64;
sprintf(strerrbuf + offs, " (0x%08X/%i)", err, err);
}