diff options
Diffstat (limited to 'src/interfaces/libpq')
-rw-r--r-- | src/interfaces/libpq/fe-auth.c | 70 | ||||
-rw-r--r-- | src/interfaces/libpq/fe-connect.c | 382 | ||||
-rw-r--r-- | src/interfaces/libpq/fe-misc.c | 22 | ||||
-rw-r--r-- | src/interfaces/libpq/fe-print.c | 10 | ||||
-rw-r--r-- | src/interfaces/libpq/libpq-fe.h | 4 | ||||
-rw-r--r-- | src/interfaces/libpq/libpq-int.h | 9 |
6 files changed, 277 insertions, 220 deletions
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index dce3b5c90b9..0e158d984f4 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -10,7 +10,7 @@ * exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes). * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.46 2001/02/10 02:31:30 tgl Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.47 2001/03/22 04:01:25 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -118,7 +118,7 @@ static void pg_krb4_init() { char *realm; - static int init_done = 0; + static int init_done = 0; if (init_done) return; @@ -265,7 +265,7 @@ pg_an_to_ln(char *aname) * Various krb5 state which is not connection specfic, and a flag to * indicate whether we have initialised it yet. */ -static int pg_krb5_initialised; +static int pg_krb5_initialised; static krb5_context pg_krb5_context; static krb5_ccache pg_krb5_ccache; static krb5_principal pg_krb5_client; @@ -281,7 +281,8 @@ pg_krb5_init(char *PQerrormsg) return STATUS_OK; retval = krb5_init_context(&pg_krb5_context); - if (retval) { + if (retval) + { snprintf(PQerrormsg, PQERRORMSG_LENGTH, "pg_krb5_init: krb5_init_context: %s", error_message(retval)); @@ -289,27 +290,30 @@ pg_krb5_init(char *PQerrormsg) } retval = krb5_cc_default(pg_krb5_context, &pg_krb5_ccache); - if (retval) { + if (retval) + { snprintf(PQerrormsg, PQERRORMSG_LENGTH, "pg_krb5_init: krb5_cc_default: %s", error_message(retval)); krb5_free_context(pg_krb5_context); return STATUS_ERROR; - } + } - retval = krb5_cc_get_principal(pg_krb5_context, pg_krb5_ccache, + retval = krb5_cc_get_principal(pg_krb5_context, pg_krb5_ccache, &pg_krb5_client); - if (retval) { + if (retval) + { snprintf(PQerrormsg, PQERRORMSG_LENGTH, "pg_krb5_init: krb5_cc_get_principal: %s", error_message(retval)); krb5_cc_close(pg_krb5_context, pg_krb5_ccache); krb5_free_context(pg_krb5_context); return STATUS_ERROR; - } + } - retval = krb5_unparse_name(pg_krb5_context, pg_krb5_client, &pg_krb5_name); - if (retval) { + retval = krb5_unparse_name(pg_krb5_context, pg_krb5_client, &pg_krb5_name); + if (retval) + { snprintf(PQerrormsg, PQERRORMSG_LENGTH, "pg_krb5_init: krb5_unparse_name: %s", error_message(retval)); @@ -317,7 +321,7 @@ pg_krb5_init(char *PQerrormsg) krb5_cc_close(pg_krb5_context, pg_krb5_ccache); krb5_free_context(pg_krb5_context); return STATUS_ERROR; - } + } pg_krb5_name = pg_an_to_ln(pg_krb5_name); @@ -351,32 +355,34 @@ pg_krb5_sendauth(char *PQerrormsg, int sock, const char *hostname) { krb5_error_code retval; - int ret; + int ret; krb5_principal server; krb5_auth_context auth_context = NULL; - krb5_error *err_ret = NULL; - int flags; + krb5_error *err_ret = NULL; + int flags; ret = pg_krb5_init(PQerrormsg); if (ret != STATUS_OK) return ret; - retval = krb5_sname_to_principal(pg_krb5_context, hostname, PG_KRB_SRVNAM, + retval = krb5_sname_to_principal(pg_krb5_context, hostname, PG_KRB_SRVNAM, KRB5_NT_SRV_HST, &server); - if (retval) { + if (retval) + { snprintf(PQerrormsg, PQERRORMSG_LENGTH, "pg_krb5_sendauth: krb5_sname_to_principal: %s", error_message(retval)); return STATUS_ERROR; } - /* + /* * libpq uses a non-blocking socket. But kerberos needs a blocking * socket, and we have to block somehow to do mutual authentication * anyway. So we temporarily make it blocking. */ flags = fcntl(sock, F_GETFL); - if (flags < 0 || fcntl(sock, F_SETFL, (long)(flags & ~O_NONBLOCK))) { + if (flags < 0 || fcntl(sock, F_SETFL, (long) (flags & ~O_NONBLOCK))) + { snprintf(PQerrormsg, PQERRORMSG_LENGTH, "pg_krb5_sendauth: fcntl: %s", strerror(errno)); krb5_free_principal(pg_krb5_context, server); @@ -384,32 +390,36 @@ pg_krb5_sendauth(char *PQerrormsg, int sock, } retval = krb5_sendauth(pg_krb5_context, &auth_context, - (krb5_pointer) &sock, PG_KRB_SRVNAM, + (krb5_pointer) & sock, PG_KRB_SRVNAM, pg_krb5_client, server, AP_OPTS_MUTUAL_REQUIRED, NULL, 0, /* no creds, use ccache instead */ pg_krb5_ccache, &err_ret, NULL, NULL); - if (retval) { - if (retval == KRB5_SENDAUTH_REJECTED && err_ret) { + if (retval) + { + if (retval == KRB5_SENDAUTH_REJECTED && err_ret) + { snprintf(PQerrormsg, PQERRORMSG_LENGTH, "pg_krb5_sendauth: authentication rejected: \"%*s\"", err_ret->text.length, err_ret->text.data); } - else { + else + { snprintf(PQerrormsg, PQERRORMSG_LENGTH, "pg_krb5_sendauth: krb5_sendauth: %s", error_message(retval)); } - + if (err_ret) krb5_free_error(pg_krb5_context, err_ret); - + ret = STATUS_ERROR; } krb5_free_principal(pg_krb5_context, server); - - if (fcntl(sock, F_SETFL, (long)flags)) { + + if (fcntl(sock, F_SETFL, (long) flags)) + { snprintf(PQerrormsg, PQERRORMSG_LENGTH, "pg_krb5_sendauth: fcntl: %s", strerror(errno)); ret = STATUS_ERROR; @@ -575,8 +585,8 @@ fe_getauthname(char *PQerrormsg) #endif if (authsvc == STARTUP_MSG - || (authsvc == STARTUP_KRB4_MSG && !name) - || (authsvc == STARTUP_KRB5_MSG && !name)) + || (authsvc == STARTUP_KRB4_MSG && !name) + || (authsvc == STARTUP_KRB5_MSG && !name)) { #ifdef WIN32 char username[128]; @@ -593,7 +603,7 @@ fe_getauthname(char *PQerrormsg) } if (authsvc != STARTUP_MSG && authsvc != STARTUP_KRB4_MSG && authsvc != STARTUP_KRB5_MSG) - sprintf(PQerrormsg,"fe_getauthname: invalid authentication system: %d\n", authsvc); + sprintf(PQerrormsg, "fe_getauthname: invalid authentication system: %d\n", authsvc); if (name && (authn = (char *) malloc(strlen(name) + 1))) strcpy(authn, name); diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 4486e3cf72a..891e0752b42 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.160 2001/02/10 02:31:30 tgl Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.161 2001/03/22 04:01:25 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -32,7 +32,7 @@ #include <netdb.h> #include <netinet/in.h> #ifdef HAVE_NETINET_TCP_H -# include <netinet/tcp.h> +#include <netinet/tcp.h> #endif #include <arpa/inet.h> #endif @@ -65,6 +65,7 @@ inet_aton(const char *cp, struct in_addr * inp) #ifdef USE_SSL static SSL_CTX *SSL_context = NULL; + #endif #define NOTIFYLIST_INITIAL_SIZE 10 @@ -108,7 +109,7 @@ static const PQconninfoOption PQconninfoOptions[] = { "Database-Authtype", "D", 20}, {"service", "PGSERVICE", NULL, NULL, - "Database-Service", "", 20}, + "Database-Service", "", 20}, {"user", "PGUSER", NULL, NULL, "Database-User", "", 20}, @@ -137,7 +138,7 @@ static const PQconninfoOption PQconninfoOptions[] = { #ifdef USE_SSL {"requiressl", "PGREQUIRESSL", "0", NULL, - "Require-SSL", "", 1 }, + "Require-SSL", "", 1}, #endif /* Terminating entry --- MUST BE LAST */ @@ -186,8 +187,8 @@ static PQconninfoOption *conninfo_parse(const char *conninfo, static char *conninfo_getval(PQconninfoOption *connOptions, const char *keyword); static void defaultNoticeProcessor(void *arg, const char *message); -static int parseServiceInfo(PQconninfoOption *options, - PQExpBuffer errorMessage); +static int parseServiceInfo(PQconninfoOption *options, + PQExpBuffer errorMessage); /* ---------------- @@ -316,7 +317,7 @@ PQconnectStart(const char *conninfo) conn->pgpass = tmp ? strdup(tmp) : NULL; #ifdef USE_SSL tmp = conninfo_getval(connOptions, "requiressl"); - conn->require_ssl = tmp ? (tmp[0]=='1'?true:false) : false; + conn->require_ssl = tmp ? (tmp[0] == '1' ? true : false) : false; #endif /* ---------- @@ -516,7 +517,7 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, #ifdef USE_SSL if ((tmp = getenv("PGREQUIRESSL")) != NULL) - conn->require_ssl = (tmp[0]=='1')?true:false; + conn->require_ssl = (tmp[0] == '1') ? true : false; else conn->require_ssl = 0; #endif @@ -533,7 +534,7 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, } -#ifdef NOT_USED /* because it's broken */ +#ifdef NOT_USED /* because it's broken */ /* * update_db_info - * get all additional info out of dbName @@ -542,7 +543,8 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, static int update_db_info(PGconn *conn) { - char *tmp, *tmp2, + char *tmp, + *tmp2, *old = conn->dbName; if (strchr(conn->dbName, '@') != NULL) @@ -588,7 +590,8 @@ update_db_info(PGconn *conn) /* * new style: - * <tcp|unix>:postgresql://server[:port|:/unixsocket/path:][/dbname][?options] + * <tcp|unix>:postgresql://server[:port|:/unixsocket/path:][/db + * name][?options] */ offset += strlen("postgresql://"); @@ -611,7 +614,11 @@ update_db_info(PGconn *conn) } else { - /* Why do we default only this value from the environment again? */ + + /* + * Why do we default only this value from the environment + * again? + */ if ((tmp = getenv("PGDATABASE")) != NULL) { if (conn->dbName) @@ -635,10 +642,10 @@ update_db_info(PGconn *conn) if (strncmp(old, "unix:", 5) != 0) { printfPQExpBuffer(&conn->errorMessage, - "connectDBStart() -- " - "socket name can only be specified with " - "non-TCP\n"); - return 1; + "connectDBStart() -- " + "socket name can only be specified with " + "non-TCP\n"); + return 1; } *tmp2 = '\0'; if (conn->pgunixsocket) @@ -682,7 +689,8 @@ update_db_info(PGconn *conn) return 0; } -#endif /* NOT_USED */ + +#endif /* NOT_USED */ /* ---------- @@ -696,12 +704,14 @@ connectMakeNonblocking(PGconn *conn) { #ifdef WIN32 int on = 1; + if (ioctlsocket(conn->sock, FIONBIO, &on) != 0) #elif defined(__BEOS__) - int on = 1; - if (ioctl(conn->sock, FIONBIO, &on) != 0) + int on = 1; + + if (ioctl(conn->sock, FIONBIO, &on) != 0) #else - if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0) + if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0) #endif { printfPQExpBuffer(&conn->errorMessage, @@ -754,7 +764,7 @@ connectFailureMessage(PGconn *conn, const char *caller, int errorno) printfPQExpBuffer(&conn->errorMessage, "%s -- connect() failed: %s\n" "\tIs the postmaster running locally\n" - "\tand accepting connections on Unix socket '%s'?\n", + "\tand accepting connections on Unix socket '%s'?\n", caller, strerror(errorno), conn->raddr.un.sun_path); @@ -762,8 +772,8 @@ connectFailureMessage(PGconn *conn, const char *caller, int errorno) #endif printfPQExpBuffer(&conn->errorMessage, "%s -- connect() failed: %s\n" - "\tIs the postmaster running (with -i) at '%s'\n" - "\tand accepting connections on TCP/IP port %s?\n", + "\tIs the postmaster running (with -i) at '%s'\n" + "\tand accepting connections on TCP/IP port %s?\n", caller, strerror(errorno), conn->pghost ? conn->pghost : "localhost", @@ -794,6 +804,7 @@ connectDBStart(PGconn *conn) return 0; #ifdef NOT_USED + /* * parse dbName to get all additional info in it, if any */ @@ -822,7 +833,7 @@ connectDBStart(PGconn *conn) { printfPQExpBuffer(&conn->errorMessage, "connectDBStart() -- " - "invalid host address: %s\n", conn->pghostaddr); + "invalid host address: %s\n", conn->pghostaddr); goto connect_errReturn; } @@ -963,15 +974,15 @@ connectDBStart(PGconn *conn) if (pqPacketSend(conn, (char *) &np, sizeof(StartupPacket)) != STATUS_OK) { printfPQExpBuffer(&conn->errorMessage, - "connectDB() -- couldn't send SSL negotiation packet: errno=%d\n%s\n", - errno, strerror(errno)); + "connectDB() -- couldn't send SSL negotiation packet: errno=%d\n%s\n", + errno, strerror(errno)); goto connect_errReturn; } /* Now receive the postmasters response */ if (recv(conn->sock, &SSLok, 1, 0) != 1) { printfPQExpBuffer(&conn->errorMessage, "PQconnectDB() -- couldn't read postmaster response: errno=%d\n%s\n", - errno, strerror(errno)); + errno, strerror(errno)); goto connect_errReturn; } if (SSLok == 'S') @@ -985,7 +996,7 @@ connectDBStart(PGconn *conn) { printfPQExpBuffer(&conn->errorMessage, "connectDB() -- couldn't create SSL context: %s\n", - ERR_reason_error_string(ERR_get_error())); + ERR_reason_error_string(ERR_get_error())); goto connect_errReturn; } } @@ -995,7 +1006,7 @@ connectDBStart(PGconn *conn) { printfPQExpBuffer(&conn->errorMessage, "connectDB() -- couldn't establish SSL connection: %s\n", - ERR_reason_error_string(ERR_get_error())); + ERR_reason_error_string(ERR_get_error())); goto connect_errReturn; } /* SSL connection finished. Continue to send startup packet */ @@ -1012,15 +1023,15 @@ connectDBStart(PGconn *conn) else if (SSLok != 'N') { printfPQExpBuffer(&conn->errorMessage, - "Received invalid negotiation response.\n"); + "Received invalid negotiation response.\n"); goto connect_errReturn; } } - if (conn->require_ssl && !conn->ssl) + if (conn->require_ssl && !conn->ssl) { /* Require SSL, but server does not support/want it */ printfPQExpBuffer(&conn->errorMessage, - "Server does not support SSL when SSL was required.\n"); + "Server does not support SSL when SSL was required.\n"); goto connect_errReturn; } #endif @@ -1065,6 +1076,7 @@ static int connectDBComplete(PGconn *conn) { PostgresPollingStatusType flag = PGRES_POLLING_WRITING; + if (conn == NULL || conn->status == CONNECTION_BAD) return 0; @@ -1144,6 +1156,7 @@ PostgresPollingStatusType PQconnectPoll(PGconn *conn) { PGresult *res; + if (conn == NULL) return PGRES_POLLING_FAILED; @@ -1621,8 +1634,11 @@ keep_going: /* We will come back to here until there env = getenv(envname); if (!env || *env == '\0') { - /* query server encoding if PGCLIENTENCODING - is not specified */ + + /* + * query server encoding if PGCLIENTENCODING is not + * specified + */ if (!PQsendQuery(conn, "select getdatabaseencoding()")) goto error_return; @@ -1633,16 +1649,17 @@ keep_going: /* We will come back to here until there else { /* otherwise set client encoding in pg_conn struct */ - int encoding = pg_char_to_encoding(env); + int encoding = pg_char_to_encoding(env); + if (encoding < 0) { strcpy(conn->errorMessage.data, - "PGCLIENTENCODING has no valid encoding name.\n"); + "PGCLIENTENCODING has no valid encoding name.\n"); goto error_return; } conn->client_encoding = encoding; } - + } case SETENV_STATE_ENCODINGS_WAIT: @@ -2209,7 +2226,7 @@ pqPacketSend(PGconn *conn, const char *buf, size_t len) #ifndef SYSCONFDIR -# error "You must compile this file with SYSCONFDIR defined." +#error "You must compile this file with SYSCONFDIR defined." #endif #define MAXBUFSIZE 256 @@ -2217,111 +2234,131 @@ pqPacketSend(PGconn *conn, const char *buf, size_t len) static int parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage) { - char *service = conninfo_getval(options, "service"); - char *serviceFile = SYSCONFDIR "/pg_service.conf"; - int group_found = 0; - int linenr=0, i; - - if(service != NULL) { - FILE *f; - char buf[MAXBUFSIZE], *line; - - f = fopen(serviceFile, "r"); - if(f == NULL) { - printfPQExpBuffer(errorMessage, "ERROR: Service file '%s' not found\n", - serviceFile); - return 1; - } - - /* As default, set the database name to the name of the service */ - for(i = 0; options[i].keyword; i++) - if(strcmp(options[i].keyword, "dbname") == 0) { - if(options[i].val != NULL) - free(options[i].val); - options[i].val = strdup(service); - } - - while((line = fgets(buf, MAXBUFSIZE-1, f)) != NULL) { - linenr++; - - if(strlen(line) >= MAXBUFSIZE - 2) { - fclose(f); - printfPQExpBuffer(errorMessage, - "ERROR: line %d too long in service file '%s'\n", - linenr, - serviceFile); - return 2; - } - - /* ignore EOL at end of line */ - if(strlen(line) && line[strlen(line)-1] == '\n') - line[strlen(line)-1] = 0; - - /* ignore leading blanks */ - while(*line && isspace((unsigned char) line[0])) - line++; - - /* ignore comments and empty lines */ - if(strlen(line) == 0 || line[0] == '#') - continue; - - /* Check for right groupname */ - if(line[0] == '[') - { - if(group_found) { - /* group info already read */ - fclose(f); - return 0; - } - - if(strncmp(line+1, service, strlen(service)) == 0 && - line[strlen(service)+1] == ']') - group_found = 1; - else - group_found = 0; - } else { - if(group_found) { - /* Finally, we are in the right group and can parse the line */ - char *key, *val; - int found_keyword; - - key = strtok(line, "="); - if(key == NULL) { - printfPQExpBuffer(errorMessage, - "ERROR: syntax error in service file '%s', line %d\n", - serviceFile, - linenr); - fclose(f); - return 3; - } - val = line + strlen(line) + 1; - - found_keyword = 0; - for(i = 0; options[i].keyword; i++) { - if(strcmp(options[i].keyword, key) == 0) { - if(options[i].val != NULL) - free(options[i].val); - options[i].val = strdup(val); - found_keyword = 1; - } - } - - if(!found_keyword) { - printfPQExpBuffer(errorMessage, - "ERROR: syntax error in service file '%s', line %d\n", - serviceFile, - linenr); - fclose(f); - return 3; - } - } - } - } + char *service = conninfo_getval(options, "service"); + char *serviceFile = SYSCONFDIR "/pg_service.conf"; + int group_found = 0; + int linenr = 0, + i; + + if (service != NULL) + { + FILE *f; + char buf[MAXBUFSIZE], + *line; + + f = fopen(serviceFile, "r"); + if (f == NULL) + { + printfPQExpBuffer(errorMessage, "ERROR: Service file '%s' not found\n", + serviceFile); + return 1; + } + + /* As default, set the database name to the name of the service */ + for (i = 0; options[i].keyword; i++) + if (strcmp(options[i].keyword, "dbname") == 0) + { + if (options[i].val != NULL) + free(options[i].val); + options[i].val = strdup(service); + } + + while ((line = fgets(buf, MAXBUFSIZE - 1, f)) != NULL) + { + linenr++; + + if (strlen(line) >= MAXBUFSIZE - 2) + { + fclose(f); + printfPQExpBuffer(errorMessage, + "ERROR: line %d too long in service file '%s'\n", + linenr, + serviceFile); + return 2; + } + + /* ignore EOL at end of line */ + if (strlen(line) && line[strlen(line) - 1] == '\n') + line[strlen(line) - 1] = 0; + + /* ignore leading blanks */ + while (*line && isspace((unsigned char) line[0])) + line++; + + /* ignore comments and empty lines */ + if (strlen(line) == 0 || line[0] == '#') + continue; + + /* Check for right groupname */ + if (line[0] == '[') + { + if (group_found) + { + /* group info already read */ + fclose(f); + return 0; + } + + if (strncmp(line + 1, service, strlen(service)) == 0 && + line[strlen(service) + 1] == ']') + group_found = 1; + else + group_found = 0; + } + else + { + if (group_found) + { - fclose(f); - } + /* + * Finally, we are in the right group and can parse + * the line + */ + char *key, + *val; + int found_keyword; - return 0; + key = strtok(line, "="); + if (key == NULL) + { + printfPQExpBuffer(errorMessage, + "ERROR: syntax error in service file '%s', line %d\n", + serviceFile, + linenr); + fclose(f); + return 3; + } + val = line + strlen(line) + 1; + + found_keyword = 0; + for (i = 0; options[i].keyword; i++) + { + if (strcmp(options[i].keyword, key) == 0) + { + if (options[i].val != NULL) + free(options[i].val); + options[i].val = strdup(val); + found_keyword = 1; + } + } + + if (!found_keyword) + { + printfPQExpBuffer(errorMessage, + "ERROR: syntax error in service file '%s', line %d\n", + serviceFile, + linenr); + fclose(f); + return 3; + } + } + } + } + + fclose(f); + } + + return 0; } @@ -2500,11 +2537,12 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage) } - /* Now check for service info */ - if(parseServiceInfo(options, errorMessage)) { - PQconninfoFree(options); - free(buf); - return NULL; + /* Now check for service info */ + if (parseServiceInfo(options, errorMessage)) + { + PQconninfoFree(options); + free(buf); + return NULL; } /* Done with the modifiable input string */ @@ -2749,12 +2787,14 @@ PQsetClientEncoding(PGconn *conn, const char *encoding) #endif #ifdef USE_SSL -SSL *PQgetssl(PGconn *conn) +SSL * +PQgetssl(PGconn *conn) { if (!conn) return NULL; return conn->ssl; } + #endif void @@ -2819,31 +2859,32 @@ defaultNoticeProcessor(void *arg, const char *message) * if there's no valid encoding, returns -1 */ -typedef struct { - int encoding; /* encoding symbol value */ - char *name; /* encoding string */ -} PQ_encoding_conv_tbl; +typedef struct +{ + int encoding; /* encoding symbol value */ + char *name; /* encoding string */ +} PQ_encoding_conv_tbl; static PQ_encoding_conv_tbl pq_conv_tbl[] = { - {SQL_ASCII, "SQL_ASCII"}, - {EUC_JP, "EUC_JP"}, - {EUC_CN, "EUC_CN"}, - {EUC_KR, "EUC_KR"}, - {EUC_TW, "EUC_TW"}, - {UNICODE, "UNICODE"}, - {MULE_INTERNAL, "MULE_INTERNAL"}, - {LATIN1, "LATIN1"}, - {LATIN2, "LATIN2"}, - {LATIN3, "LATIN3"}, - {LATIN4, "LATIN4"}, - {LATIN5, "LATIN5"}, - {KOI8, "KOI8"}, - {WIN, "WIN"}, - {ALT, "ALT"}, - {SJIS, "SJIS"}, - {BIG5, "BIG5"}, - {WIN1250, "WIN1250"}, - {-1, ""} + {SQL_ASCII, "SQL_ASCII"}, + {EUC_JP, "EUC_JP"}, + {EUC_CN, "EUC_CN"}, + {EUC_KR, "EUC_KR"}, + {EUC_TW, "EUC_TW"}, + {UNICODE, "UNICODE"}, + {MULE_INTERNAL, "MULE_INTERNAL"}, + {LATIN1, "LATIN1"}, + {LATIN2, "LATIN2"}, + {LATIN3, "LATIN3"}, + {LATIN4, "LATIN4"}, + {LATIN5, "LATIN5"}, + {KOI8, "KOI8"}, + {WIN, "WIN"}, + {ALT, "ALT"}, + {SJIS, "SJIS"}, + {BIG5, "BIG5"}, + {WIN1250, "WIN1250"}, + {-1, ""} }; int @@ -2878,4 +2919,5 @@ pg_encoding_to_char(int encoding) } return (""); } + #endif diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c index b7acb044674..697128cb828 100644 --- a/src/interfaces/libpq/fe-misc.c +++ b/src/interfaces/libpq/fe-misc.c @@ -25,7 +25,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.46 2001/02/17 03:37:22 tgl Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.47 2001/03/22 04:01:26 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -208,7 +208,7 @@ pqGetnchar(char *s, size_t len, PGconn *conn) conn->inCursor += len; if (conn->Pfdebug) - fprintf(conn->Pfdebug, "From backend (%lu)> %.*s\n", (unsigned long)len, (int) len, s); + fprintf(conn->Pfdebug, "From backend (%lu)> %.*s\n", (unsigned long) len, (int) len, s); return 0; } @@ -259,13 +259,13 @@ pqGetInt(int *result, size_t bytes, PGconn *conn) break; default: sprintf(noticeBuf, - "pqGetInt: int size %lu not supported\n", (unsigned long)bytes); + "pqGetInt: int size %lu not supported\n", (unsigned long) bytes); DONOTICE(conn, noticeBuf); return EOF; } if (conn->Pfdebug) - fprintf(conn->Pfdebug, "From backend (#%lu)> %d\n", (unsigned long)bytes, *result); + fprintf(conn->Pfdebug, "From backend (#%lu)> %d\n", (unsigned long) bytes, *result); return 0; } @@ -296,13 +296,13 @@ pqPutInt(int value, size_t bytes, PGconn *conn) break; default: sprintf(noticeBuf, - "pqPutInt: int size %lu not supported\n", (unsigned long)bytes); + "pqPutInt: int size %lu not supported\n", (unsigned long) bytes); DONOTICE(conn, noticeBuf); return EOF; } if (conn->Pfdebug) - fprintf(conn->Pfdebug, "To backend (%lu#)> %d\n", (unsigned long)bytes, value); + fprintf(conn->Pfdebug, "To backend (%lu#)> %d\n", (unsigned long) bytes, value); return 0; } @@ -645,9 +645,9 @@ pqFlush(PGconn *conn) case ECONNRESET: #endif printfPQExpBuffer(&conn->errorMessage, - "pqFlush() -- backend closed the channel unexpectedly.\n" - "\tThis probably means the backend terminated abnormally" - " before or while processing the request.\n"); + "pqFlush() -- backend closed the channel unexpectedly.\n" + "\tThis probably means the backend terminated abnormally" + " before or while processing the request.\n"); /* * We used to close the socket here, but that's a bad @@ -661,8 +661,8 @@ pqFlush(PGconn *conn) default: printfPQExpBuffer(&conn->errorMessage, - "pqFlush() -- couldn't send data: errno=%d\n%s\n", - errno, strerror(errno)); + "pqFlush() -- couldn't send data: errno=%d\n%s\n", + errno, strerror(errno)); /* We don't assume it's a fatal error... */ return EOF; } diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c index bd5e4e29a12..f581260de03 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 - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.41 2001/02/10 02:31:30 tgl Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.42 2001/03/22 04:01:27 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -92,14 +92,17 @@ PQprint(FILE *fout, int usePipe = 0; pqsigfunc oldsigpipehandler = NULL; char *pagerenv; + #ifdef TIOCGWINSZ struct winsize screen_size; + #else struct winsize { int ws_row; int ws_col; } screen_size; + #endif nTups = PQntuples(res); @@ -149,9 +152,10 @@ PQprint(FILE *fout, #endif ) { + /* - * If we think there'll be more than one screen of output, - * try to pipe to the pager program. + * If we think there'll be more than one screen of output, try + * to pipe to the pager program. */ #ifdef TIOCGWINSZ if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) == -1 || diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h index 1f201857e3e..95279a133a9 100644 --- a/src/interfaces/libpq/libpq-fe.h +++ b/src/interfaces/libpq/libpq-fe.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: libpq-fe.h,v 1.70 2001/01/24 19:43:31 momjian Exp $ + * $Id: libpq-fe.h,v 1.71 2001/03/22 04:01:27 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -227,7 +227,7 @@ extern "C" extern int PQsetClientEncoding(PGconn *conn, const char *encoding); #ifdef USE_SSL /* Get the SSL structure associated with a connection */ - extern SSL *PQgetssl(PGconn *conn); + extern SSL *PQgetssl(PGconn *conn); #endif diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h index 09ffcb137ad..2c652bd767a 100644 --- a/src/interfaces/libpq/libpq-int.h +++ b/src/interfaces/libpq/libpq-int.h @@ -12,7 +12,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: libpq-int.h,v 1.32 2001/02/10 02:31:30 tgl Exp $ + * $Id: libpq-int.h,v 1.33 2001/03/22 04:01:27 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -204,8 +204,9 @@ struct pg_conn * numbers-and-dots notation. Takes * precedence over above. */ char *pgport; /* the server's communication port */ - char *pgunixsocket; /* the Unix-domain socket that the server is listening on; - * if NULL, uses a default constructed from pgport */ + char *pgunixsocket; /* the Unix-domain socket that the server + * is listening on; if NULL, uses a + * default constructed from pgport */ char *pgtty; /* tty on which the backend messages is * displayed (NOT ACTUALLY USED???) */ char *pgoptions; /* options to start the backend with */ @@ -266,7 +267,7 @@ struct pg_conn #ifdef USE_SSL bool allow_ssl_try; /* Allowed to try SSL negotiation */ - bool require_ssl; /* Require SSL to make connection */ + bool require_ssl; /* Require SSL to make connection */ SSL *ssl; /* SSL status, if have SSL connection */ #endif |