1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-21 00:42:43 +03:00

OK, folks, here is the pgindent output.

This commit is contained in:
Bruce Momjian
1998-09-01 04:40:42 +00:00
parent af74855a60
commit fa1a8d6a97
574 changed files with 26509 additions and 24033 deletions

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.23 1998/09/01 03:28:50 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.24 1998/09/01 04:40:01 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -42,7 +42,7 @@
#include <unistd.h>
#endif
#include <pwd.h>
#endif /* WIN32 */
#endif /* WIN32 */
#ifdef HAVE_CRYPT_H
#include <crypt.h>
@@ -56,7 +56,8 @@
struct authsvc
{
char name[NAMEDATALEN]; /* service nickname (for command line) */
char name[NAMEDATALEN]; /* service nickname (for command
* line) */
MsgType msgtype; /* startup packet header type */
int allowed; /* initially allowed (before command line
* option parsing)? */
@@ -76,17 +77,17 @@ static struct authsvc authsvcs[] = {
#ifdef KRB4
{"krb4", STARTUP_KRB4_MSG, 1},
{"kerberos", STARTUP_KRB4_MSG, 1},
#endif /* KRB4 */
#endif /* KRB4 */
#ifdef KRB5
{"krb5", STARTUP_KRB5_MSG, 1},
{"kerberos", STARTUP_KRB5_MSG, 1},
#endif /* KRB5 */
#endif /* KRB5 */
{UNAUTHNAME, STARTUP_MSG,
#if defined(KRB4) || defined(KRB5)
0
#else /* !(KRB4 || KRB5) */
1
#endif /* !(KRB4 || KRB5) */
#endif /* !(KRB4 || KRB5) */
},
{"password", STARTUP_PASSWORD_MSG, 0}
};
@@ -223,7 +224,7 @@ pg_krb4_sendauth(const char *PQerrormsg, int sock,
return STATUS_OK;
}
#endif /* KRB4 */
#endif /* KRB4 */
#ifdef KRB5
/*----------------------------------------------------------------
@@ -457,7 +458,7 @@ pg_krb5_sendauth(const char *PQerrormsg, int sock,
return code ? STATUS_ERROR : STATUS_OK;
}
#endif /* KRB5 */
#endif /* KRB5 */
static int
pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
@@ -521,7 +522,7 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
if (password == NULL || *password == '\0')
{
(void) sprintf(PQerrormsg,
"fe_sendauth: no password supplied\n");
"fe_sendauth: no password supplied\n");
return STATUS_ERROR;
}
if (pg_password_sendauth(conn, password, areq) != STATUS_OK)
@@ -607,10 +608,10 @@ fe_getauthname(char *PQerrormsg)
case STARTUP_MSG:
{
#ifdef WIN32
char username[128];
DWORD namesize = sizeof(username) - 1;
char username[128];
DWORD namesize = sizeof(username) - 1;
if (GetUserName(username,&namesize))
if (GetUserName(username, &namesize))
name = username;
#else
struct passwd *pw = getpwuid(geteuid());

View File

@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: fe-auth.h,v 1.9 1998/08/17 03:50:33 scrappy Exp $
* $Id: fe-auth.h,v 1.10 1998/09/01 04:40:03 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -30,10 +30,9 @@
#define DEFAULT_CLIENT_AUTHSVC UNAUTHNAME
#else /* KRB4 || KRB5 */
#define DEFAULT_CLIENT_AUTHSVC "kerberos"
#endif /* KRB4 || KRB5 */
#endif /* KRB4 || KRB5 */
extern int
fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
extern int fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
const char *password, char *PQerrormsg);
extern MsgType fe_getauthsvc(char *PQerrormsg);
extern void fe_setauthsvc(const char *name, char *PQerrormsg);
@@ -42,4 +41,4 @@ extern char *fe_getauthname(char *PQerrormsg);
#define PG_KRB4_VERSION "PGVER4.1" /* at most KRB_SENDAUTH_VLEN chars */
#define PG_KRB5_VERSION "PGVER5.1"
#endif /* FE_AUTH_H */
#endif /* FE_AUTH_H */

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.79 1998/08/17 03:50:34 scrappy Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.80 1998/09/01 04:40:04 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -50,7 +50,8 @@ static void closePGconn(PGconn *conn);
static int conninfo_parse(const char *conninfo, char *errorMessage);
static char *conninfo_getval(char *keyword);
static void conninfo_free(void);
static void defaultNoticeProcessor(void * arg, const char * message);
static void defaultNoticeProcessor(void *arg, const char *message);
/* XXX Why is this not static? */
void PQsetenv(PGconn *conn);
@@ -282,8 +283,10 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, cons
{
PGconn *conn;
char *tmp;
/* An error message from some service we call. */
bool error = FALSE;
/* We encountered an error that prevents successful completion */
int i;
@@ -359,9 +362,10 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, cons
if (conn->dbName)
{
/*
* if the database name is surrounded by double-quotes, then
* don't convert case
* if the database name is surrounded by double-quotes, then don't
* convert case
*/
if (*conn->dbName == '"')
{
@@ -370,8 +374,8 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, cons
}
else
for (i = 0; conn->dbName[i]; i++)
if (isascii((unsigned char)conn->dbName[i]) &&
isupper(conn->dbName[i]))
if (isascii((unsigned char) conn->dbName[i]) &&
isupper(conn->dbName[i]))
conn->dbName[i] = tolower(conn->dbName[i]);
}
@@ -392,57 +396,63 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, cons
static int
update_db_info(PGconn *conn)
{
char *tmp, *old = conn->dbName;
char *tmp,
*old = conn->dbName;
if (strchr(conn->dbName, '@') != NULL)
{
/* old style: dbname[@server][:port] */
tmp = strrchr(conn->dbName, ':');
if (tmp != NULL) /* port number given */
if (tmp != NULL) /* port number given */
{
conn->pgport = strdup(tmp + 1);
conn->pgport = strdup(tmp + 1);
*tmp = '\0';
}
tmp = strrchr(conn->dbName, '@');
if (tmp != NULL) /* host name given */
if (tmp != NULL) /* host name given */
{
conn->pghost = strdup(tmp + 1);
conn->pghost = strdup(tmp + 1);
*tmp = '\0';
}
conn->dbName = strdup(old);
free(old);
}
else
{
int offset;
int offset;
/*
* only allow protocols tcp and unix
*/
* only allow protocols tcp and unix
*/
if (strncmp(conn->dbName, "tcp:", 4) == 0)
offset = 4;
else if (strncmp(conn->dbName, "unix:", 5) == 0)
offset = 5;
else return 0;
else
return 0;
if (strncmp(conn->dbName + offset, "postgresql://", strlen("postgresql://")) == 0)
{
/* new style: <tcp|unix>:postgresql://server[:port][/dbname][?options] */
/*
* new style:
* <tcp|unix>:postgresql://server[:port][/dbname][?options]
*/
offset += strlen("postgresql://");
tmp = strrchr(conn->dbName + offset, '?');
if (tmp != NULL) /* options given */
if (tmp != NULL) /* options given */
{
conn->pgoptions = strdup(tmp + 1);
conn->pgoptions = strdup(tmp + 1);
*tmp = '\0';
}
tmp = strrchr(conn->dbName + offset, '/');
if (tmp != NULL) /* database name given */
if (tmp != NULL) /* database name given */
{
conn->dbName = strdup(tmp + 1);
conn->dbName = strdup(tmp + 1);
*tmp = '\0';
}
else
@@ -452,30 +462,31 @@ update_db_info(PGconn *conn)
else if (conn->pguser)
conn->dbName = strdup(conn->pguser);
}
tmp = strrchr(old + offset, ':');
if (tmp != NULL) /* port number given */
if (tmp != NULL) /* port number given */
{
conn->pgport = strdup(tmp + 1);
conn->pgport = strdup(tmp + 1);
*tmp = '\0';
}
if (strncmp(old, "unix:", 5) == 0)
{
conn->pghost = NULL;
if (strcmp(old + offset, "localhost") != 0)
{
(void) sprintf(conn->errorMessage,
"connectDB() -- non-tcp access only possible on localhost\n");
return 1;
"connectDB() -- non-tcp access only possible on localhost\n");
return 1;
}
}
else conn->pghost = strdup(old + offset);
else
conn->pghost = strdup(old + offset);
free(old);
}
}
return 0;
}
@@ -498,12 +509,12 @@ connectDB(PGconn *conn)
char beresp;
int on = 1;
/*
* parse dbName to get all additional info in it, if any
*/
/*
* parse dbName to get all additional info in it, if any
*/
if (update_db_info(conn) != 0)
goto connect_errReturn;
/*
* Initialize the startup packet.
*/
@@ -535,7 +546,8 @@ connectDB(PGconn *conn)
}
family = AF_INET;
}
else {
else
{
hp = NULL;
family = AF_UNIX;
}
@@ -556,7 +568,7 @@ connectDB(PGconn *conn)
else
conn->raddr_len = UNIXSOCK_PATH(conn->raddr.un, portno);
#endif
/* Connect to the server */
if ((conn->sock = socket(family, SOCK_STREAM, 0)) < 0)
@@ -577,14 +589,14 @@ connectDB(PGconn *conn)
}
/*
* Set the right options.
* We need nonblocking I/O, and we don't want delay of outgoing data.
* Set the right options. We need nonblocking I/O, and we don't want
* delay of outgoing data.
*/
#ifndef WIN32
if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0)
#else
if (ioctlsocket(conn->sock,FIONBIO, &on) != 0)
if (ioctlsocket(conn->sock, FIONBIO, &on) != 0)
#endif
{
(void) sprintf(conn->errorMessage,
@@ -606,16 +618,16 @@ connectDB(PGconn *conn)
}
if (setsockopt(conn->sock, pe->p_proto, TCP_NODELAY,
#ifdef WIN32
(char *)
(char *)
#endif
&on,
&on,
sizeof(on)) < 0)
{
(void) sprintf(conn->errorMessage,
"connectDB() -- setsockopt failed: errno=%d\n%s\n",
"connectDB() -- setsockopt failed: errno=%d\n%s\n",
errno, strerror(errno));
#ifdef WIN32
printf("Winsock error: %i\n",WSAGetLastError());
printf("Winsock error: %i\n", WSAGetLastError());
#endif
goto connect_errReturn;
}
@@ -626,7 +638,7 @@ connectDB(PGconn *conn)
if (getsockname(conn->sock, &conn->laddr.sa, &laddrlen) < 0)
{
(void) sprintf(conn->errorMessage,
"connectDB() -- getsockname() failed: errno=%d\n%s\n",
"connectDB() -- getsockname() failed: errno=%d\n%s\n",
errno, strerror(errno));
goto connect_errReturn;
}
@@ -640,15 +652,15 @@ connectDB(PGconn *conn)
if (pqPacketSend(conn, (char *) &sp, sizeof(StartupPacket)) != STATUS_OK)
{
sprintf(conn->errorMessage,
"connectDB() -- couldn't send startup packet: errno=%d\n%s\n",
"connectDB() -- couldn't send startup packet: errno=%d\n%s\n",
errno, strerror(errno));
goto connect_errReturn;
}
/*
* Perform the authentication exchange:
* wait for backend messages and respond as necessary.
* We fall out of this loop when done talking to the postmaster.
* Perform the authentication exchange: wait for backend messages and
* respond as necessary. We fall out of this loop when done talking to
* the postmaster.
*/
for (;;)
@@ -659,8 +671,10 @@ connectDB(PGconn *conn)
/* Load data, or detect EOF */
if (pqReadData(conn) < 0)
goto connect_errReturn;
/* Scan the message.
* If we run out of data, loop around to try again.
/*
* Scan the message. If we run out of data, loop around to try
* again.
*/
conn->inCursor = conn->inStart;
@@ -679,7 +693,7 @@ connectDB(PGconn *conn)
if (beresp != 'R')
{
(void) sprintf(conn->errorMessage,
"connectDB() -- expected authentication request\n");
"connectDB() -- expected authentication request\n");
goto connect_errReturn;
}
@@ -710,20 +724,21 @@ connectDB(PGconn *conn)
}
/*
* Now we expect to hear from the backend.
* A ReadyForQuery message indicates that startup is successful,
* but we might also get an Error message indicating failure.
* (Notice messages indicating nonfatal warnings are also allowed
* by the protocol, as is a BackendKeyData message.)
* Easiest way to handle this is to let PQgetResult() read the messages.
* We just have to fake it out about the state of the connection.
* Now we expect to hear from the backend. A ReadyForQuery message
* indicates that startup is successful, but we might also get an
* Error message indicating failure. (Notice messages indicating
* nonfatal warnings are also allowed by the protocol, as is a
* BackendKeyData message.) Easiest way to handle this is to let
* PQgetResult() read the messages. We just have to fake it out about
* the state of the connection.
*/
conn->status = CONNECTION_OK;
conn->asyncStatus = PGASYNC_BUSY;
res = PQgetResult(conn);
/* NULL return indicating we have gone to IDLE state is expected */
if (res) {
if (res)
{
if (res->resultStatus != PGRES_FATAL_ERROR)
sprintf(conn->errorMessage,
"connectDB() -- unexpected message during startup\n");
@@ -731,16 +746,17 @@ connectDB(PGconn *conn)
goto connect_errReturn;
}
/* Given the new protocol that sends a ReadyForQuery message
* after successful backend startup, it should no longer be
* necessary to send an empty query to test for startup.
/*
* Given the new protocol that sends a ReadyForQuery message after
* successful backend startup, it should no longer be necessary to
* send an empty query to test for startup.
*/
#if 0
/*
* Send a blank query to make sure everything works; in
* particular, that the database exists.
* Send a blank query to make sure everything works; in particular,
* that the database exists.
*/
res = PQexec(conn, " ");
if (res == NULL || res->resultStatus != PGRES_EMPTY_QUERY)
@@ -754,8 +770,8 @@ connectDB(PGconn *conn)
#endif
/* Post-connection housekeeping.
* Send environment variables to server
/*
* Post-connection housekeeping. Send environment variables to server
*/
PQsetenv(conn);
@@ -781,32 +797,38 @@ PQsetenv(PGconn *conn)
{
struct EnvironmentOptions *eo;
char setQuery[80]; /* mjl: size okay? XXX */
#ifdef MULTIBYTE
char *envname = "PGCLIENTENCODING";
static char envbuf[64]; /* big enough? */
char *env;
char *encoding = 0;
char *envname = "PGCLIENTENCODING";
static char envbuf[64]; /* big enough? */
char *env;
char *encoding = 0;
PGresult *rtn;
#endif
#ifdef MULTIBYTE
/* query server encoding */
env = getenv(envname);
if (!env) {
rtn = PQexec(conn, "select getdatabaseencoding()");
if (rtn && PQresultStatus(rtn) == PGRES_TUPLES_OK) {
encoding = PQgetvalue(rtn,0,0);
if (encoding) {
/* set client encoding */
sprintf(envbuf,"%s=%s",envname,encoding);
putenv(envbuf);
}
PQclear(rtn);
}
if (!encoding) { /* this should not happen */
sprintf(envbuf,"%s=%s",envname,pg_encoding_to_char(MULTIBYTE));
putenv(envbuf);
}
if (!env)
{
rtn = PQexec(conn, "select getdatabaseencoding()");
if (rtn && PQresultStatus(rtn) == PGRES_TUPLES_OK)
{
encoding = PQgetvalue(rtn, 0, 0);
if (encoding)
{
/* set client encoding */
sprintf(envbuf, "%s=%s", envname, encoding);
putenv(envbuf);
}
PQclear(rtn);
}
if (!encoding)
{ /* this should not happen */
sprintf(envbuf, "%s=%s", envname, pg_encoding_to_char(MULTIBYTE));
putenv(envbuf);
}
}
#endif
@@ -833,12 +855,13 @@ PQsetenv(PGconn *conn)
/*
* makeEmptyPGconn
* - create a PGconn data structure with (as yet) no interesting data
* - create a PGconn data structure with (as yet) no interesting data
*/
static PGconn *
makeEmptyPGconn(void)
{
PGconn *conn = (PGconn *) malloc(sizeof(PGconn));
PGconn *conn = (PGconn *) malloc(sizeof(PGconn));
if (conn == NULL)
return conn;
@@ -914,11 +937,11 @@ closePGconn(PGconn *conn)
{
if (conn->sock >= 0)
{
/*
* Try to send "close connection" message to backend.
* Ignore any error.
* Note: this routine used to go to substantial lengths to avoid
* getting SIGPIPE'd if the connection were already closed.
* Try to send "close connection" message to backend. Ignore any
* error. Note: this routine used to go to substantial lengths to
* avoid getting SIGPIPE'd if the connection were already closed.
* Now we rely on pqFlush to avoid the signal.
*/
(void) pqPuts("X", conn);
@@ -998,9 +1021,10 @@ int
PQrequestCancel(PGconn *conn)
{
int tmpsock = -1;
struct {
uint32 packetlen;
CancelRequestPacket cp;
struct
{
uint32 packetlen;
CancelRequestPacket cp;
} crp;
/* Check we have an open connection */
@@ -1015,9 +1039,8 @@ PQrequestCancel(PGconn *conn)
}
/*
* We need to open a temporary connection to the postmaster.
* Use the information saved by connectDB to do this with
* only kernel calls.
* We need to open a temporary connection to the postmaster. Use the
* information saved by connectDB to do this with only kernel calls.
*/
if ((tmpsock = socket(conn->raddr.sa.sa_family, SOCK_STREAM, 0)) < 0)
{
@@ -1029,6 +1052,7 @@ PQrequestCancel(PGconn *conn)
strcpy(conn->errorMessage, "PQrequestCancel() -- connect() failed: ");
goto cancel_errReturn;
}
/*
* We needn't set nonblocking I/O or NODELAY options here.
*/
@@ -1040,7 +1064,7 @@ PQrequestCancel(PGconn *conn)
crp.cp.backendPID = htonl(conn->be_pid);
crp.cp.cancelAuthCode = htonl(conn->be_key);
if (send(tmpsock, (char*) &crp, sizeof(crp), 0) != (int) sizeof(crp))
if (send(tmpsock, (char *) &crp, sizeof(crp), 0) != (int) sizeof(crp))
{
strcpy(conn->errorMessage, "PQrequestCancel() -- send() failed: ");
goto cancel_errReturn;
@@ -1404,6 +1428,7 @@ char *
PQerrorMessage(PGconn *conn)
{
static char noConn[] = "PQerrorMessage: conn pointer is NULL\n";
if (!conn)
return noConn;
return conn->errorMessage;
@@ -1441,7 +1466,7 @@ PQuntrace(PGconn *conn)
}
void
PQsetNoticeProcessor (PGconn *conn, PQnoticeProcessor proc, void *arg)
PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
{
if (conn == NULL)
return;
@@ -1457,7 +1482,7 @@ PQsetNoticeProcessor (PGconn *conn, PQnoticeProcessor proc, void *arg)
*/
static void
defaultNoticeProcessor(void * arg, const char * message)
defaultNoticeProcessor(void *arg, const char *message)
{
/* Note: we expect the supplied string to end with a newline already. */
fprintf(stderr, "%s", message);

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.64 1998/09/01 03:28:51 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.65 1998/09/01 04:40:05 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -33,11 +33,11 @@
#define TUPARR_GROW_BY 100
/* keep this in same order as ExecStatusType in libpq-fe.h */
const char * const pgresStatus[] = {
const char *const pgresStatus[] = {
"PGRES_EMPTY_QUERY",
"PGRES_COMMAND_OK",
"PGRES_TUPLES_OK",
"PGRES_COPY_OUT",
"PGRES_COPY_OUT",
"PGRES_COPY_IN",
"PGRES_BAD_RESPONSE",
"PGRES_NONFATAL_ERROR",
@@ -53,10 +53,10 @@ static PGresult *makeEmptyPGresult(PGconn *conn, ExecStatusType status);
static void freeTuple(PGresAttValue *tuple, int numAttributes);
static void addTuple(PGresult *res, PGresAttValue *tup);
static void parseInput(PGconn *conn);
static int getRowDescriptions(PGconn *conn);
static int getAnotherTuple(PGconn *conn, int binary);
static int getNotify(PGconn *conn);
static int getNotice(PGconn *conn);
static int getRowDescriptions(PGconn *conn);
static int getAnotherTuple(PGconn *conn, int binary);
static int getNotify(PGconn *conn);
static int getNotice(PGconn *conn);
/*
@@ -127,7 +127,7 @@ PQclear(PGresult *res)
static void
freeTuple(PGresAttValue *tuple, int numAttributes)
{
int i;
int i;
if (tuple)
{
@@ -170,12 +170,13 @@ addTuple(PGresult *res, PGresAttValue *tup)
{
/* grow the array */
res->tupArrSize += TUPARR_GROW_BY;
/*
* we can use realloc because shallow copying of the structure
* is okay. Note that the first time through, res->tuples is NULL.
* realloc is supposed to do the right thing in that case.
* Also note that the positions beyond res->ntups are garbage,
* not necessarily NULL.
* we can use realloc because shallow copying of the structure is
* okay. Note that the first time through, res->tuples is NULL.
* realloc is supposed to do the right thing in that case. Also
* note that the positions beyond res->ntups are garbage, not
* necessarily NULL.
*/
res->tuples = (PGresAttValue **)
realloc(res->tuples, res->tupArrSize * sizeof(PGresAttValue *));
@@ -187,10 +188,10 @@ addTuple(PGresult *res, PGresAttValue *tup)
/*
* PQsendQuery
* Submit a query, but don't wait for it to finish
* Submit a query, but don't wait for it to finish
*
* Returns: 1 if successfully submitted
* 0 if error (conn->errorMessage is set)
* 0 if error (conn->errorMessage is set)
*/
int
@@ -204,7 +205,7 @@ PQsendQuery(PGconn *conn, const char *query)
return 0;
}
/* check to see if the query string is too long */
if (strlen(query) > MAX_MESSAGE_LEN-2)
if (strlen(query) > MAX_MESSAGE_LEN - 2)
{
sprintf(conn->errorMessage, "PQsendQuery() -- query is too long. "
"Maximum length is %d\n", MAX_MESSAGE_LEN - 2);
@@ -259,11 +260,11 @@ PQconsumeInput(PGconn *conn)
if (!conn)
return;
/* Load more data, if available.
* We do this no matter what state we are in, since we are probably
* getting called because the application wants to get rid
* of a read-select condition.
* Note that we will NOT block waiting for more input.
/*
* Load more data, if available. We do this no matter what state we
* are in, since we are probably getting called because the
* application wants to get rid of a read-select condition. Note that
* we will NOT block waiting for more input.
*/
if (pqReadData(conn) < 0)
strcpy(conn->asyncErrorMessage, conn->errorMessage);
@@ -280,30 +281,34 @@ PQconsumeInput(PGconn *conn)
static void
parseInput(PGconn *conn)
{
char id;
char id;
/*
/*
* Loop to parse successive complete messages available in the buffer.
*/
for (;;)
{
/*
* Quit if in COPY_OUT state: we expect raw data from the server until
* PQendcopy is called. Don't try to parse it according to the normal
* protocol. (This is bogus. The data lines ought to be part of the
* protocol and have identifying leading characters.)
/*
* Quit if in COPY_OUT state: we expect raw data from the server
* until PQendcopy is called. Don't try to parse it according to
* the normal protocol. (This is bogus. The data lines ought to
* be part of the protocol and have identifying leading
* characters.)
*/
if (conn->asyncStatus == PGASYNC_COPY_OUT)
return;
/*
* OK to try to read a message type code.
*/
conn->inCursor = conn->inStart;
if (pqGetc(&id, conn))
return;
/*
* NOTIFY and NOTICE messages can happen in any state besides COPY OUT;
* always process them right away.
* NOTIFY and NOTICE messages can happen in any state besides COPY
* OUT; always process them right away.
*/
if (id == 'A')
{
@@ -317,18 +322,19 @@ parseInput(PGconn *conn)
}
else
{
/*
* Other messages should only be processed while in BUSY state.
* (In particular, in READY state we hold off further parsing
* until the application collects the current PGresult.)
* If the state is IDLE then we got trouble.
* Other messages should only be processed while in BUSY
* state. (In particular, in READY state we hold off further
* parsing until the application collects the current
* PGresult.) If the state is IDLE then we got trouble.
*/
if (conn->asyncStatus != PGASYNC_BUSY)
{
if (conn->asyncStatus == PGASYNC_IDLE)
{
sprintf(conn->errorMessage,
"Backend message type 0x%02x arrived while idle\n",
"Backend message type 0x%02x arrived while idle\n",
id);
DONOTICE(conn, conn->errorMessage);
/* Discard the unexpected message; good idea?? */
@@ -341,18 +347,21 @@ parseInput(PGconn *conn)
case 'C': /* command complete */
if (conn->result == NULL)
conn->result = makeEmptyPGresult(conn,
PGRES_COMMAND_OK);
PGRES_COMMAND_OK);
if (pqGets(conn->result->cmdStatus, CMDSTATUS_LEN, conn))
return;
conn->asyncStatus = PGASYNC_READY;
break;
case 'E': /* error return */
if (pqGets(conn->asyncErrorMessage,ERROR_MSG_LENGTH,conn))
if (pqGets(conn->asyncErrorMessage, ERROR_MSG_LENGTH, conn))
return;
/* delete any partially constructed result */
pqClearAsyncResult(conn);
/* we leave result NULL while setting asyncStatus=READY;
* this signals an error condition to PQgetResult.
/*
* we leave result NULL while setting
* asyncStatus=READY; this signals an error condition
* to PQgetResult.
*/
conn->asyncStatus = PGASYNC_READY;
break;
@@ -366,18 +375,20 @@ parseInput(PGconn *conn)
if (id != '\0')
{
sprintf(conn->errorMessage,
"unexpected character %c following 'I'\n", id);
"unexpected character %c following 'I'\n", id);
DONOTICE(conn, conn->errorMessage);
}
if (conn->result == NULL)
conn->result = makeEmptyPGresult(conn,
PGRES_EMPTY_QUERY);
PGRES_EMPTY_QUERY);
conn->asyncStatus = PGASYNC_READY;
break;
case 'K': /* secret key data from the backend */
/* This is expected only during backend startup,
* but it's just as easy to handle it as part of the
* main loop. Save the data and continue processing.
/*
* This is expected only during backend startup, but
* it's just as easy to handle it as part of the main
* loop. Save the data and continue processing.
*/
if (pqGetInt(&(conn->be_pid), 4, conn))
return;
@@ -389,7 +400,8 @@ parseInput(PGconn *conn)
return;
/* We pretty much ignore this message type... */
break;
case 'T': /* row descriptions (start of query results) */
case 'T': /* row descriptions (start of query
* results) */
if (conn->result == NULL)
{
/* First 'T' in a query sequence */
@@ -398,7 +410,9 @@ parseInput(PGconn *conn)
}
else
{
/* A new 'T' message is treated as the start of
/*
* A new 'T' message is treated as the start of
* another PGresult. (It is not clear that this
* is really possible with the current backend.)
* We stop parsing until the application accepts
@@ -418,7 +432,7 @@ parseInput(PGconn *conn)
else
{
sprintf(conn->errorMessage,
"Backend sent D message without prior T\n");
"Backend sent D message without prior T\n");
DONOTICE(conn, conn->errorMessage);
/* Discard the unexpected message; good idea?? */
conn->inStart = conn->inEnd;
@@ -435,7 +449,7 @@ parseInput(PGconn *conn)
else
{
sprintf(conn->errorMessage,
"Backend sent B message without prior T\n");
"Backend sent B message without prior T\n");
DONOTICE(conn, conn->errorMessage);
/* Discard the unexpected message; good idea?? */
conn->inStart = conn->inEnd;
@@ -450,8 +464,8 @@ parseInput(PGconn *conn)
break;
default:
sprintf(conn->asyncErrorMessage,
"unknown protocol character '%c' read from backend. "
"(The protocol character is the first character the "
"unknown protocol character '%c' read from backend. "
"(The protocol character is the first character the "
"backend sends in response to a query it receives).\n",
id);
/* Discard the unexpected message; good idea?? */
@@ -567,7 +581,7 @@ getAnotherTuple(PGconn *conn, int binary)
tup = conn->curTuple;
/* Get the null-value bitmap */
nbytes = (nfields + BYTELEN-1) / BYTELEN;
nbytes = (nfields + BYTELEN - 1) / BYTELEN;
if (nbytes >= MAX_FIELDS)
{
sprintf(conn->asyncErrorMessage,
@@ -637,7 +651,7 @@ getAnotherTuple(PGconn *conn, int binary)
/*
* PQisBusy
* Return TRUE if PQgetResult would block waiting for input.
* Return TRUE if PQgetResult would block waiting for input.
*/
int
@@ -656,14 +670,14 @@ PQisBusy(PGconn *conn)
/*
* PQgetResult
* Get the next PGresult produced by a query.
* Returns NULL if and only if no query work remains.
* Get the next PGresult produced by a query.
* Returns NULL if and only if no query work remains.
*/
PGresult *
PGresult *
PQgetResult(PGconn *conn)
{
PGresult *res;
PGresult *res;
if (!conn)
return NULL;
@@ -694,16 +708,16 @@ PQgetResult(PGconn *conn)
res = NULL; /* query is complete */
break;
case PGASYNC_READY:
/*
* conn->result is the PGresult to return, or possibly NULL
* indicating an error.
* conn->asyncErrorMessage holds the errorMessage to return.
* (We keep it stashed there so that other user calls can't
* overwrite it prematurely.)
* indicating an error. conn->asyncErrorMessage holds the
* errorMessage to return. (We keep it stashed there so that
* other user calls can't overwrite it prematurely.)
*/
res = conn->result;
conn->result = NULL; /* handing over ownership to caller */
conn->curTuple = NULL; /* just in case */
conn->result = NULL;/* handing over ownership to caller */
conn->curTuple = NULL; /* just in case */
if (!res)
res = makeEmptyPGresult(conn, PGRES_FATAL_ERROR);
strcpy(conn->errorMessage, conn->asyncErrorMessage);
@@ -742,11 +756,13 @@ PQgetResult(PGconn *conn)
PGresult *
PQexec(PGconn *conn, const char *query)
{
PGresult *result;
PGresult *lastResult;
PGresult *result;
PGresult *lastResult;
/* Silently discard any prior query result that application didn't eat.
* This is probably poor design, but it's here for backward compatibility.
/*
* Silently discard any prior query result that application didn't
* eat. This is probably poor design, but it's here for backward
* compatibility.
*/
while ((result = PQgetResult(conn)) != NULL)
{
@@ -755,19 +771,20 @@ PQexec(PGconn *conn, const char *query)
{
PQclear(result);
sprintf(conn->errorMessage,
"PQexec: you gotta get out of a COPY state yourself.\n");
"PQexec: you gotta get out of a COPY state yourself.\n");
return NULL;
}
PQclear(result);
}
/* OK to send the message */
if (! PQsendQuery(conn, query))
if (!PQsendQuery(conn, query))
return NULL;
/* For backwards compatibility, return the last result if there are
* more than one. We have to stop if we see copy in/out, however.
* We will resume parsing when application calls PQendcopy.
/*
* For backwards compatibility, return the last result if there are
* more than one. We have to stop if we see copy in/out, however. We
* will resume parsing when application calls PQendcopy.
*/
lastResult = NULL;
while ((result = PQgetResult(conn)) != NULL)
@@ -788,7 +805,7 @@ PQexec(PGconn *conn, const char *query)
* This is possible in several places, so we break it out as a subroutine.
* Entry: 'N' flag character has already been consumed.
* Exit: returns 0 if successfully consumed Notice message.
* returns EOF if not enough data.
* returns EOF if not enough data.
*/
static int
getNotice(PGconn *conn)
@@ -804,12 +821,12 @@ getNotice(PGconn *conn)
* This is possible in several places, so we break it out as a subroutine.
* Entry: 'A' flag character has already been consumed.
* Exit: returns 0 if successfully consumed Notify message.
* returns EOF if not enough data.
* returns EOF if not enough data.
*/
static int
getNotify(PGconn *conn)
{
PGnotify tempNotify;
PGnotify tempNotify;
PGnotify *newNotify;
if (pqGetInt(&(tempNotify.be_pid), 4, conn))
@@ -885,14 +902,16 @@ PQgetline(PGconn *conn, char *s, int maxlen)
return EOF;
}
/* Since this is a purely synchronous routine, we don't bother to
/*
* Since this is a purely synchronous routine, we don't bother to
* maintain conn->inCursor; there is no need to back up.
*/
while (maxlen > 1)
{
if (conn->inStart < conn->inEnd)
{
char c = conn->inBuffer[conn->inStart++];
char c = conn->inBuffer[conn->inStart++];
if (c == '\n')
{
result = 0; /* success exit */
@@ -951,7 +970,7 @@ PQputnbytes(PGconn *conn, const char *buffer, int nbytes)
int
PQendcopy(PGconn *conn)
{
PGresult *result;
PGresult *result;
if (!conn)
return 0;
@@ -960,7 +979,7 @@ PQendcopy(PGconn *conn)
conn->asyncStatus != PGASYNC_COPY_OUT)
{
sprintf(conn->errorMessage,
"PQendcopy() -- I don't think there's a copy in progress.");
"PQendcopy() -- I don't think there's a copy in progress.");
return 1;
}
@@ -980,10 +999,10 @@ PQendcopy(PGconn *conn)
return 0;
}
/* Trouble.
* The worst case is that we've lost sync with the backend entirely
* due to application screwup of the copy in/out protocol.
* To recover, reset the connection (talk about using a sledgehammer...)
/*
* Trouble. The worst case is that we've lost sync with the backend
* entirely due to application screwup of the copy in/out protocol. To
* recover, reset the connection (talk about using a sledgehammer...)
*/
PQclear(result);
@@ -1014,9 +1033,9 @@ PQendcopy(PGconn *conn)
* nargs : # of arguments in args array.
*
* RETURNS
* PGresult with status = PGRES_COMMAND_OK if successful.
* PGresult with status = PGRES_COMMAND_OK if successful.
* *actual_result_len is > 0 if there is a return value, 0 if not.
* PGresult with status = PGRES_FATAL_ERROR if backend returns an error.
* PGresult with status = PGRES_FATAL_ERROR if backend returns an error.
* NULL on communications failure. conn->errorMessage will be set.
* ----------------
*/
@@ -1031,7 +1050,7 @@ PQfn(PGconn *conn,
int nargs)
{
bool needInput = false;
ExecStatusType status = PGRES_FATAL_ERROR;
ExecStatusType status = PGRES_FATAL_ERROR;
char id;
int i;
@@ -1051,9 +1070,9 @@ PQfn(PGconn *conn,
if (pqPuts("F ", conn)) /* function */
return NULL;
if (pqPutInt(fnid, 4, conn)) /* function id */
if (pqPutInt(fnid, 4, conn))/* function id */
return NULL;
if (pqPutInt(nargs, 4, conn)) /* # of args */
if (pqPutInt(nargs, 4, conn)) /* # of args */
return NULL;
for (i = 0; i < nargs; ++i)
@@ -1084,8 +1103,10 @@ PQfn(PGconn *conn,
pqReadData(conn) < 0)
break;
}
/* Scan the message.
* If we run out of data, loop around to try again.
/*
* Scan the message. If we run out of data, loop around to try
* again.
*/
conn->inCursor = conn->inStart;
needInput = true;
@@ -1093,9 +1114,10 @@ PQfn(PGconn *conn,
if (pqGetc(&id, conn))
continue;
/* We should see V or E response to the command,
* but might get N and/or A notices first.
* We also need to swallow the final Z before returning.
/*
* We should see V or E response to the command, but might get N
* and/or A notices first. We also need to swallow the final Z
* before returning.
*/
switch (id)
{
@@ -1119,7 +1141,7 @@ PQfn(PGconn *conn,
conn))
continue;
}
if (pqGetc(&id, conn)) /* get the last '0' */
if (pqGetc(&id, conn)) /* get the last '0' */
continue;
}
if (id == '0')
@@ -1127,7 +1149,8 @@ PQfn(PGconn *conn,
/* correctly finished function result message */
status = PGRES_COMMAND_OK;
}
else {
else
{
/* The backend violates the protocol. */
sprintf(conn->errorMessage,
"FATAL: PQfn: protocol error: id=%x\n", id);
@@ -1249,7 +1272,7 @@ check_tuple_field_number(const char *routineName, PGresult *res,
char *
PQfname(PGresult *res, int field_num)
{
if (! check_field_number("PQfname", res, field_num))
if (!check_field_number("PQfname", res, field_num))
return NULL;
if (res->attDescs)
return res->attDescs[field_num].name;
@@ -1282,8 +1305,8 @@ PQfnumber(PGresult *res, const char *field_name)
}
else
for (i = 0; field_case[i]; i++)
if (isascii((unsigned char)field_case[i]) &&
isupper(field_case[i]))
if (isascii((unsigned char) field_case[i]) &&
isupper(field_case[i]))
field_case[i] = tolower(field_case[i]);
for (i = 0; i < res->numAttributes; i++)
@@ -1301,7 +1324,7 @@ PQfnumber(PGresult *res, const char *field_name)
Oid
PQftype(PGresult *res, int field_num)
{
if (! check_field_number("PQftype", res, field_num))
if (!check_field_number("PQftype", res, field_num))
return InvalidOid;
if (res->attDescs)
return res->attDescs[field_num].typid;
@@ -1312,7 +1335,7 @@ PQftype(PGresult *res, int field_num)
short
PQfsize(PGresult *res, int field_num)
{
if (! check_field_number("PQfsize", res, field_num))
if (!check_field_number("PQfsize", res, field_num))
return 0;
if (res->attDescs)
return res->attDescs[field_num].typlen;
@@ -1323,7 +1346,7 @@ PQfsize(PGresult *res, int field_num)
int
PQfmod(PGresult *res, int field_num)
{
if (! check_field_number("PQfmod", res, field_num))
if (!check_field_number("PQfmod", res, field_num))
return 0;
if (res->attDescs)
return res->attDescs[field_num].atttypmod;
@@ -1347,8 +1370,11 @@ PQcmdStatus(PGresult *res)
const char *
PQoidStatus(PGresult *res)
{
char *p, *e, *scan;
int slen, olen;
char *p,
*e,
*scan;
int slen,
olen;
if (!res)
return "";
@@ -1356,22 +1382,20 @@ PQoidStatus(PGresult *res)
if (strncmp(res->cmdStatus, "INSERT ", 7) != 0)
return "";
/* The cmdStatus string looks like
* INSERT oid count\0
* In order to be able to return an ordinary C string without
* damaging the result for PQcmdStatus or PQcmdTuples, we copy
* the oid part of the string to just after the null, so that
* cmdStatus looks like
* INSERT oid count\0oid\0
* ^ our return value points here
* Pretty klugy eh? This routine should've just returned an Oid value.
/*
* The cmdStatus string looks like INSERT oid count\0 In order to be
* able to return an ordinary C string without damaging the result for
* PQcmdStatus or PQcmdTuples, we copy the oid part of the string to
* just after the null, so that cmdStatus looks like INSERT oid
* count\0oid\0 ^ our return value points here Pretty klugy eh? This
* routine should've just returned an Oid value.
*/
slen = strlen(res->cmdStatus);
p = res->cmdStatus + 7; /* where oid is now */
e = res->cmdStatus + slen + 1; /* where to put the oid string */
p = res->cmdStatus + 7; /* where oid is now */
e = res->cmdStatus + slen + 1; /* where to put the oid string */
for (scan = p; *scan && *scan != ' '; )
for (scan = p; *scan && *scan != ' ';)
scan++;
olen = scan - p;
if (slen + olen + 2 > sizeof(res->cmdStatus))
@@ -1439,7 +1463,7 @@ PQcmdTuples(PGresult *res)
char *
PQgetvalue(PGresult *res, int tup_num, int field_num)
{
if (! check_tuple_field_number("PQgetvalue", res, tup_num, field_num))
if (!check_tuple_field_number("PQgetvalue", res, tup_num, field_num))
return NULL;
return res->tuples[tup_num][field_num].value;
}
@@ -1452,7 +1476,7 @@ PQgetvalue(PGresult *res, int tup_num, int field_num)
int
PQgetlength(PGresult *res, int tup_num, int field_num)
{
if (! check_tuple_field_number("PQgetlength", res, tup_num, field_num))
if (!check_tuple_field_number("PQgetlength", res, tup_num, field_num))
return 0;
if (res->tuples[tup_num][field_num].len != NULL_LEN)
return res->tuples[tup_num][field_num].len;
@@ -1466,7 +1490,7 @@ PQgetlength(PGresult *res, int tup_num, int field_num)
int
PQgetisnull(PGresult *res, int tup_num, int field_num)
{
if (! check_tuple_field_number("PQgetisnull", res, tup_num, field_num))
if (!check_tuple_field_number("PQgetisnull", res, tup_num, field_num))
return 1; /* pretend it is null */
if (res->tuples[tup_num][field_num].len == NULL_LEN)
return 1;

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.15 1998/08/17 03:50:37 scrappy Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.16 1998/09/01 04:40:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -28,7 +28,7 @@
#include <fcntl.h>
#include <sys/stat.h>
#include "libpq/libpq-fs.h" /* must come after sys/stat.h */
#include "libpq/libpq-fs.h" /* must come after sys/stat.h */
#define LO_BUFSIZE 1024

View File

@@ -24,7 +24,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.19 1998/08/29 02:09:25 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.20 1998/09/01 04:40:08 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -46,7 +46,7 @@
#if !defined(NO_UNISTD_H)
#include <unistd.h>
#endif
#endif /* WIN32 */
#endif /* WIN32 */
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
@@ -87,7 +87,7 @@ pqGetc(char *result, PGconn *conn)
static int
pqPutBytes(const char *s, int nbytes, PGconn *conn)
{
int avail = conn->outBufSize - conn->outCount;
int avail = conn->outBufSize - conn->outCount;
while (nbytes > avail)
{
@@ -117,10 +117,10 @@ int
pqGets(char *s, int maxlen, PGconn *conn)
{
/* Copy conn data to locals for faster search loop */
char *inBuffer = conn->inBuffer;
int inCursor = conn->inCursor;
int inEnd = conn->inEnd;
int slen;
char *inBuffer = conn->inBuffer;
int inCursor = conn->inCursor;
int inEnd = conn->inEnd;
int slen;
while (inCursor < inEnd && inBuffer[inCursor])
inCursor++;
@@ -133,8 +133,8 @@ pqGets(char *s, int maxlen, PGconn *conn)
strcpy(s, inBuffer + conn->inCursor);
else
{
strncpy(s, inBuffer + conn->inCursor, maxlen-1);
s[maxlen-1] = '\0';
strncpy(s, inBuffer + conn->inCursor, maxlen - 1);
s[maxlen - 1] = '\0';
}
conn->inCursor = ++inCursor;
@@ -149,7 +149,7 @@ pqGets(char *s, int maxlen, PGconn *conn)
int
pqPuts(const char *s, PGconn *conn)
{
if (pqPutBytes(s, strlen(s)+1, conn))
if (pqPutBytes(s, strlen(s) + 1, conn))
return EOF;
if (conn->Pfdebug)
@@ -170,7 +170,7 @@ pqGetnchar(char *s, int len, PGconn *conn)
memcpy(s, conn->inBuffer + conn->inCursor, len);
/* no terminating null */
conn->inCursor += len;
if (conn->Pfdebug)
@@ -204,8 +204,8 @@ pqPutnchar(const char *s, int len, PGconn *conn)
int
pqGetInt(int *result, int bytes, PGconn *conn)
{
uint16 tmp2;
uint32 tmp4;
uint16 tmp2;
uint32 tmp4;
switch (bytes)
{
@@ -244,19 +244,19 @@ pqGetInt(int *result, int bytes, PGconn *conn)
int
pqPutInt(int value, int bytes, PGconn *conn)
{
uint16 tmp2;
uint32 tmp4;
uint16 tmp2;
uint32 tmp4;
switch (bytes)
{
case 2:
tmp2 = htons((uint16) value);
if (pqPutBytes((const char*) &tmp2, 2, conn))
if (pqPutBytes((const char *) &tmp2, 2, conn))
return EOF;
break;
case 4:
tmp4 = htonl((uint32) value);
if (pqPutBytes((const char*) &tmp4, 4, conn))
if (pqPutBytes((const char *) &tmp4, 4, conn))
return EOF;
break;
default:
@@ -278,8 +278,8 @@ pqPutInt(int value, int bytes, PGconn *conn)
static int
pqReadReady(PGconn *conn)
{
fd_set input_mask;
struct timeval timeout;
fd_set input_mask;
struct timeval timeout;
if (conn->sock < 0)
return 0;
@@ -288,7 +288,7 @@ pqReadReady(PGconn *conn)
FD_SET(conn->sock, &input_mask);
timeout.tv_sec = 0;
timeout.tv_usec = 0;
if (select(conn->sock+1, &input_mask, (fd_set *) NULL, (fd_set *) NULL,
if (select(conn->sock + 1, &input_mask, (fd_set *) NULL, (fd_set *) NULL,
&timeout) < 0)
{
sprintf(conn->errorMessage,
@@ -302,17 +302,17 @@ pqReadReady(PGconn *conn)
/* --------------------------------------------------------------------- */
/* pqReadData: read more data, if any is available
* Possible return values:
* 1: successfully loaded at least one more byte
* 0: no data is presently available, but no error detected
* -1: error detected (including EOF = connection closure);
* conn->errorMessage set
* 1: successfully loaded at least one more byte
* 0: no data is presently available, but no error detected
* -1: error detected (including EOF = connection closure);
* conn->errorMessage set
* NOTE: callers must not assume that pointers or indexes into conn->inBuffer
* remain valid across this call!
*/
int
pqReadData(PGconn *conn)
{
int nread;
int nread;
if (conn->sock < 0)
{
@@ -331,16 +331,19 @@ pqReadData(PGconn *conn)
}
else
conn->inStart = conn->inCursor = conn->inEnd = 0;
/* If the buffer is fairly full, enlarge it.
* We need to be able to enlarge the buffer in case a single message
* exceeds the initial buffer size. We enlarge before filling the
* buffer entirely so as to avoid asking the kernel for a partial packet.
* The magic constant here should be at least one TCP packet.
/*
* If the buffer is fairly full, enlarge it. We need to be able to
* enlarge the buffer in case a single message exceeds the initial
* buffer size. We enlarge before filling the buffer entirely so as
* to avoid asking the kernel for a partial packet. The magic constant
* here should be at least one TCP packet.
*/
if (conn->inBufSize - conn->inEnd < 2000)
{
int newSize = conn->inBufSize * 2;
char * newBuf = (char *) realloc(conn->inBuffer, newSize);
int newSize = conn->inBufSize * 2;
char *newBuf = (char *) realloc(conn->inBuffer, newSize);
if (newBuf)
{
conn->inBuffer = newBuf;
@@ -350,7 +353,7 @@ pqReadData(PGconn *conn)
/* OK, try to read some data */
tryAgain:
nread = recv(conn->sock, conn->inBuffer + conn->inEnd,
nread = recv(conn->sock, conn->inBuffer + conn->inEnd,
conn->inBufSize - conn->inEnd, 0);
if (nread < 0)
{
@@ -376,22 +379,24 @@ tryAgain:
return 1;
}
/* A return value of 0 could mean just that no data is now available,
* or it could mean EOF --- that is, the server has closed the connection.
* Since we have the socket in nonblock mode, the only way to tell the
* difference is to see if select() is saying that the file is ready.
* Grumble. Fortunately, we don't expect this path to be taken much,
* since in normal practice we should not be trying to read data unless
* the file selected for reading already.
/*
* A return value of 0 could mean just that no data is now available,
* or it could mean EOF --- that is, the server has closed the
* connection. Since we have the socket in nonblock mode, the only way
* to tell the difference is to see if select() is saying that the
* file is ready. Grumble. Fortunately, we don't expect this path to
* be taken much, since in normal practice we should not be trying to
* read data unless the file selected for reading already.
*/
if (! pqReadReady(conn))
if (!pqReadReady(conn))
return 0; /* definitely no data available */
/* Still not sure that it's EOF,
* because some data could have just arrived.
/*
* Still not sure that it's EOF, because some data could have just
* arrived.
*/
tryAgain2:
nread = recv(conn->sock, conn->inBuffer + conn->inEnd,
nread = recv(conn->sock, conn->inBuffer + conn->inEnd,
conn->inBufSize - conn->inEnd, 0);
if (nread < 0)
{
@@ -417,22 +422,22 @@ tryAgain2:
return 1;
}
/* OK, we are getting a zero read even though select() says ready.
/*
* OK, we are getting a zero read even though select() says ready.
* This means the connection has been closed. Cope.
*/
sprintf(conn->errorMessage,
"pqReadData() -- backend closed the channel unexpectedly.\n"
"\tThis probably means the backend terminated abnormally"
" before or while processing the request.\n");
conn->status = CONNECTION_BAD; /* No more connection to
* backend */
conn->status = CONNECTION_BAD; /* No more connection to backend */
#ifdef WIN32
closesocket(conn->sock);
#else
close(conn->sock);
#endif
conn->sock = -1;
return -1;
}
@@ -442,8 +447,8 @@ tryAgain2:
int
pqFlush(PGconn *conn)
{
char * ptr = conn->outBuffer;
int len = conn->outCount;
char *ptr = conn->outBuffer;
int len = conn->outCount;
if (conn->sock < 0)
{
@@ -455,10 +460,11 @@ pqFlush(PGconn *conn)
{
/* Prevent being SIGPIPEd if backend has closed the connection. */
#ifndef WIN32
pqsigfunc oldsighandler = pqsignal(SIGPIPE, SIG_IGN);
pqsigfunc oldsighandler = pqsignal(SIGPIPE, SIG_IGN);
#endif
int sent = send(conn->sock, ptr, len, 0);
int sent = send(conn->sock, ptr, len, 0);
#ifndef WIN32
pqsignal(SIGPIPE, oldsighandler);
@@ -479,7 +485,7 @@ pqFlush(PGconn *conn)
#endif
default:
sprintf(conn->errorMessage,
"pqFlush() -- couldn't send data: errno=%d\n%s\n",
"pqFlush() -- couldn't send data: errno=%d\n%s\n",
errno, strerror(errno));
return EOF;
}
@@ -511,8 +517,8 @@ pqFlush(PGconn *conn)
int
pqWait(int forRead, int forWrite, PGconn *conn)
{
fd_set input_mask;
fd_set output_mask;
fd_set input_mask;
fd_set output_mask;
if (conn->sock < 0)
{
@@ -521,14 +527,15 @@ pqWait(int forRead, int forWrite, PGconn *conn)
}
/* loop in case select returns EINTR */
for (;;) {
for (;;)
{
FD_ZERO(&input_mask);
FD_ZERO(&output_mask);
if (forRead)
FD_SET(conn->sock, &input_mask);
if (forWrite)
FD_SET(conn->sock, &output_mask);
if (select(conn->sock+1, &input_mask, &output_mask, (fd_set *) NULL,
if (select(conn->sock + 1, &input_mask, &output_mask, (fd_set *) NULL,
(struct timeval *) NULL) < 0)
{
if (errno == EINTR)

View File

@@ -9,7 +9,7 @@
* didn't really belong there.
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.11 1998/09/01 03:28:54 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.12 1998/09/01 04:40:09 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -30,7 +30,7 @@
#else
#include <termios.h>
#endif
#endif /* WIN32 */
#endif /* WIN32 */
#include <stdlib.h>
#include <signal.h>
#include <string.h>
@@ -52,19 +52,16 @@ static struct winsize
#endif
static void
do_field(PQprintOpt *po, PGresult *res,
static void do_field(PQprintOpt *po, PGresult *res,
const int i, const int j, char *buf, const int fs_len,
char **fields,
const int nFields, char **fieldNames,
unsigned char *fieldNotNum, int *fieldMax,
const int fieldMaxLen, FILE *fout);
static char *
do_header(FILE *fout, PQprintOpt *po, const int nFields,
static char *do_header(FILE *fout, PQprintOpt *po, const int nFields,
int *fieldMax, char **fieldNames, unsigned char *fieldNotNum,
const int fs_len, PGresult *res);
static void
output_row(FILE *fout, PQprintOpt *po, const int nFields, char **fields,
static void output_row(FILE *fout, PQprintOpt *po, const int nFields, char **fields,
unsigned char *fieldNotNum, int *fieldMax, char *border,
const int row_index);
static void fill(int length, int max, char filler, FILE *fp);
@@ -150,7 +147,7 @@ PQprint(FILE *fout,
if (fout == NULL)
fout = stdout;
if (po->pager && fout == stdout
if (po->pager && fout == stdout
#ifndef WIN32
&&
isatty(fileno(stdin)) &&
@@ -502,20 +499,20 @@ PQprintTuples(PGresult *res,
* if this variable is not defined, the same encoding as
* the backend is assumed.
*/
int PQmblen(unsigned char *s)
int
PQmblen(unsigned char *s)
{
char *str;
int encoding = -1;
char *str;
int encoding = -1;
str = getenv("PGCLIENTENCODING");
if (str) {
encoding = pg_char_to_encoding(str);
}
if (encoding < 0) {
encoding = MULTIBYTE;
}
return(pg_encoding_mblen(encoding, s));
str = getenv("PGCLIENTENCODING");
if (str)
encoding = pg_char_to_encoding(str);
if (encoding < 0)
encoding = MULTIBYTE;
return (pg_encoding_mblen(encoding, s));
}
#endif
static void
@@ -552,11 +549,11 @@ do_field(PQprintOpt *po, PGresult *res,
if (!skipit)
{
#ifdef MULTIBYTE
int len;
int len;
for (p = pval, o = buf; *p;
len = PQmblen(p),memcpy(o,p,len),
o+=len, p+=len)
for (p = pval, o = buf; *p;
len = PQmblen(p), memcpy(o, p, len),
o += len, p += len)
#else
for (p = pval, o = buf; *p; *(o++) = *(p++))
#endif

View File

@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: libpq-fe.h,v 1.39 1998/08/29 04:05:45 momjian Exp $
* $Id: libpq-fe.h,v 1.40 1998/09/01 04:40:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -60,7 +60,7 @@ extern "C"
} ExecStatusType;
/* string descriptions of the ExecStatusTypes */
extern const char * const pgresStatus[];
extern const char *const pgresStatus[];
/*
* POSTGRES backend dependent Constants.
@@ -127,7 +127,7 @@ extern "C"
} PGnotify;
/* PQnoticeProcessor is a typedef for a callback function type */
typedef void (*PQnoticeProcessor) (void * arg, const char * message);
typedef void (*PQnoticeProcessor) (void *arg, const char *message);
/* PGAsyncStatusType is private to libpq, really shouldn't be seen by users */
typedef enum
@@ -137,7 +137,7 @@ extern "C"
PGASYNC_READY, /* result ready for PQgetResult */
PGASYNC_COPY_IN, /* Copy In data transfer in progress */
PGASYNC_COPY_OUT /* Copy Out data transfer in progress */
} PGAsyncStatusType;
} PGAsyncStatusType;
/* generic socket address type for PGconn connection information.
* Really shouldn't be visible to users */
@@ -148,7 +148,7 @@ extern "C"
#ifndef WIN32
struct sockaddr_un un;
#endif
} PGSockAddr;
} PGSockAddr;
/* large-object-access data ... allocated only if large-object code is used.
* Really shouldn't be visible to users */
@@ -187,13 +187,14 @@ extern "C"
FILE *Pfdebug;
/* Callback procedure for notice/error message processing */
PQnoticeProcessor noticeHook;
PQnoticeProcessor noticeHook;
void *noticeArg;
/* Status indicators */
ConnStatusType status;
PGAsyncStatusType asyncStatus;
Dllist *notifyList; /* Notify msgs not yet handed to application */
ConnStatusType status;
PGAsyncStatusType asyncStatus;
Dllist *notifyList; /* Notify msgs not yet handed to
* application */
/* Connection data */
int sock; /* Unix FD for socket, -1 if not connected */
@@ -205,28 +206,33 @@ extern "C"
int be_pid; /* PID of backend --- needed for cancels */
int be_key; /* key of backend --- needed for cancels */
char salt[2]; /* password salt received from backend */
PGlobjfuncs *lobjfuncs; /* private state for large-object access fns */
PGlobjfuncs *lobjfuncs; /* private state for large-object access
* fns */
/* Buffer for data received from backend and not yet processed */
char *inBuffer; /* currently allocated buffer */
char *inBuffer; /* currently allocated buffer */
int inBufSize; /* allocated size of buffer */
int inStart; /* offset to first unconsumed data in buffer */
int inStart; /* offset to first unconsumed data in
* buffer */
int inCursor; /* next byte to tentatively consume */
int inEnd; /* offset to first position after avail data */
int inEnd; /* offset to first position after avail
* data */
/* Buffer for data not yet sent to backend */
char *outBuffer; /* currently allocated buffer */
int outBufSize; /* allocated size of buffer */
char *outBuffer; /* currently allocated buffer */
int outBufSize; /* allocated size of buffer */
int outCount; /* number of chars waiting in buffer */
/* Status for asynchronous result construction */
PGresult *result; /* result being constructed */
PGresAttValue *curTuple; /* tuple currently being read */
PGresult *result; /* result being constructed */
PGresAttValue *curTuple;/* tuple currently being read */
/* Message space. Placed last for code-size reasons.
* errorMessage is the message last returned to the application.
* When asyncStatus=READY, asyncErrorMessage is the pending message
* that will be put in errorMessage by PQgetResult. */
/*
* Message space. Placed last for code-size reasons. errorMessage
* is the message last returned to the application. When
* asyncStatus=READY, asyncErrorMessage is the pending message
* that will be put in errorMessage by PQgetResult.
*/
char errorMessage[ERROR_MSG_LENGTH];
char asyncErrorMessage[ERROR_MSG_LENGTH];
} PGconn;
@@ -303,8 +309,8 @@ extern "C"
extern PGconn *PQconnectdb(const char *conninfo);
extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport,
const char *pgoptions, const char *pgtty,
const char *dbName,
const char *login, const char *pwd);
const char *dbName,
const char *login, const char *pwd);
#define PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME) \
PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, NULL, NULL)
@@ -313,6 +319,7 @@ extern "C"
/* close the current connection and free the PGconn data structure */
extern void PQfinish(PGconn *conn);
/*
* close the current connection and restablish a new one with the same
* parameters
@@ -331,16 +338,16 @@ extern "C"
extern char *PQtty(PGconn *conn);
extern ConnStatusType PQstatus(PGconn *conn);
extern char *PQerrorMessage(PGconn *conn);
extern int PQsocket(PGconn *conn);
extern int PQsocket(PGconn *conn);
/* Enable/disable tracing */
extern void PQtrace(PGconn *conn, FILE *debug_port);
extern void PQuntrace(PGconn *conn);
/* Override default notice processor */
extern void PQsetNoticeProcessor (PGconn *conn,
PQnoticeProcessor proc,
void *arg);
extern void PQsetNoticeProcessor(PGconn *conn,
PQnoticeProcessor proc,
void *arg);
/* === in fe-exec.c === */
@@ -349,7 +356,7 @@ extern "C"
extern PGnotify *PQnotifies(PGconn *conn);
/* Interface for multiple-result or asynchronous queries */
extern int PQsendQuery(PGconn *conn, const char *query);
extern int PQsendQuery(PGconn *conn, const char *query);
extern PGresult *PQgetResult(PGconn *conn);
/* Routines for managing an asychronous query */
@@ -362,14 +369,17 @@ extern "C"
extern void PQputnbytes(PGconn *conn, const char *buffer, int nbytes);
extern int PQendcopy(PGconn *conn);
/* "Fast path" interface --- not really recommended for application use */
/*
* "Fast path" interface --- not really recommended for application
* use
*/
extern PGresult *PQfn(PGconn *conn,
int fnid,
int *result_buf,
int *result_len,
int result_is_int,
PQArgBlock *args,
int nargs);
int fnid,
int *result_buf,
int *result_len,
int result_is_int,
PQArgBlock *args,
int nargs);
/* Accessor functions for PGresult objects */
extern ExecStatusType PQresultStatus(PGresult *res);
@@ -393,31 +403,32 @@ extern "C"
/* === in fe-print.c === */
extern void PQprint(FILE *fout, /* output stream */
PGresult *res,
PQprintOpt *ps); /* option structure */
PGresult *res,
PQprintOpt *ps); /* option structure */
/* PQdisplayTuples() is a better version of PQprintTuples(),
* but both are obsoleted by PQprint().
/*
* PQdisplayTuples() is a better version of PQprintTuples(), but both
* are obsoleted by PQprint().
*/
extern void PQdisplayTuples(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);
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(PGresult *res,
FILE *fout, /* output stream */
int printAttName, /* print attribute names
* or not */
int terseOutput, /* delimiter bars or
* not? */
int width); /* width of column, if
* 0, use variable width */
FILE *fout, /* output stream */
int printAttName, /* print attribute names
* or not */
int terseOutput, /* delimiter bars or
* not? */
int width); /* width of column, if
* 0, use variable width */
#ifdef MULTIBYTE
extern int PQmblen(unsigned char *s);
extern int PQmblen(unsigned char *s);
#endif
/* === in fe-lobj.c === */
@@ -436,6 +447,7 @@ extern "C"
#ifdef __cplusplus
};
#endif
#endif /* LIBPQ_FE_H */
#endif /* LIBPQ_FE_H */

View File

@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: libpq-int.h,v 1.1 1998/08/17 03:52:36 scrappy Exp $
* $Id: libpq-int.h,v 1.2 1998/09/01 04:40:12 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -27,7 +27,7 @@
* NB: we used to use PG_PROTOCOL_LATEST from the backend pqcomm.h file,
* but that's not really the right thing: just recompiling libpq
* against a more recent backend isn't going to magically update it
* for most sorts of protocol changes. So, when you change libpq
* for most sorts of protocol changes. So, when you change libpq
* to support a different protocol revision, you have to change this
* constant too. PG_PROTOCOL_EARLIEST and PG_PROTOCOL_LATEST in
* pqcomm.h describe what the backend knows, not what libpq knows.
@@ -46,28 +46,29 @@
/* === in fe-connect.c === */
extern int pqPacketSend(PGconn *conn, const char *buf, size_t len);
extern int pqPacketSend(PGconn *conn, const char *buf, size_t len);
/* === in fe-exec.c === */
extern void pqClearAsyncResult(PGconn *conn);
extern void pqClearAsyncResult(PGconn *conn);
/* === in fe-misc.c === */
/* "Get" and "Put" routines return 0 if successful, EOF if not.
* Note that for Get, EOF merely means the buffer is exhausted,
* not that there is necessarily any error.
*/
extern int pqGetc(char *result, PGconn *conn);
extern int pqGets(char *s, int maxlen, PGconn *conn);
extern int pqPuts(const char *s, PGconn *conn);
extern int pqGetnchar(char *s, int len, PGconn *conn);
extern int pqPutnchar(const char *s, int len, PGconn *conn);
extern int pqGetInt(int *result, int bytes, PGconn *conn);
extern int pqPutInt(int value, int bytes, PGconn *conn);
extern int pqReadData(PGconn *conn);
extern int pqFlush(PGconn *conn);
extern int pqWait(int forRead, int forWrite, PGconn *conn);
/*
* "Get" and "Put" routines return 0 if successful, EOF if not. Note that
* for Get, EOF merely means the buffer is exhausted, not that there is
* necessarily any error.
*/
extern int pqGetc(char *result, PGconn *conn);
extern int pqGets(char *s, int maxlen, PGconn *conn);
extern int pqPuts(const char *s, PGconn *conn);
extern int pqGetnchar(char *s, int len, PGconn *conn);
extern int pqPutnchar(const char *s, int len, PGconn *conn);
extern int pqGetInt(int *result, int bytes, PGconn *conn);
extern int pqPutInt(int value, int bytes, PGconn *conn);
extern int pqReadData(PGconn *conn);
extern int pqFlush(PGconn *conn);
extern int pqWait(int forRead, int forWrite, PGconn *conn);
/* max length of message to send */
#define MAX_MESSAGE_LEN 8193
@@ -90,8 +91,9 @@
#ifndef strerror
#if defined(sun) && defined(sparc) && !defined(__SVR4)
extern char *sys_errlist[];
#define strerror(A) (sys_errlist[(A)])
#endif /* sunos4 */
#endif /* !strerror */
#endif /* LIBPQ_INT_H */
#define strerror(A) (sys_errlist[(A)])
#endif /* sunos4 */
#endif /* !strerror */
#endif /* LIBPQ_INT_H */

View File

@@ -1,6 +1,8 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason,
LPVOID lpReserved ){
BOOL WINAPI
DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
LPVOID lpReserved)
{
return TRUE;
}

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/pqsignal.c,v 1.8 1998/09/01 03:28:56 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/pqsignal.c,v 1.9 1998/09/01 04:40:14 momjian Exp $
*
* NOTES
* This shouldn't be in libpq, but the monitor and some other
@@ -38,5 +38,5 @@ pqsignal(int signo, pqsigfunc func)
if (sigaction(signo, &act, &oact) < 0)
return SIG_ERR;
return oact.sa_handler;
#endif /* !USE_POSIX_SIGNALS */
#endif /* !USE_POSIX_SIGNALS */
}

View File

@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pqsignal.h,v 1.4 1997/09/08 02:40:38 momjian Exp $
* $Id: pqsignal.h,v 1.5 1998/09/01 04:40:15 momjian Exp $
*
* NOTES
* This shouldn't be in libpq, but the monitor and some other
@@ -23,4 +23,4 @@ typedef void (*pqsigfunc) (int);
extern pqsigfunc pqsignal(int signo, pqsigfunc func);
#endif /* PQSIGNAL_H */
#endif /* PQSIGNAL_H */

View File

@@ -11,7 +11,7 @@
/*
* Some compat functions
* Some compat functions
*/
#define open(a,b,c) _open(a,b,c)
#define read(a,b,c) _read(a,b,c)