Header And Logo

PostgreSQL
| The world's most advanced open source database.

libpq-int.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * libpq-int.h
00004  *    This file contains internal definitions meant to be used only by
00005  *    the frontend libpq library, not by applications that call it.
00006  *
00007  *    An application can include this file if it wants to bypass the
00008  *    official API defined by libpq-fe.h, but code that does so is much
00009  *    more likely to break across PostgreSQL releases than code that uses
00010  *    only the official API.
00011  *
00012  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00013  * Portions Copyright (c) 1994, Regents of the University of California
00014  *
00015  * src/interfaces/libpq/libpq-int.h
00016  *
00017  *-------------------------------------------------------------------------
00018  */
00019 
00020 #ifndef LIBPQ_INT_H
00021 #define LIBPQ_INT_H
00022 
00023 /* We assume libpq-fe.h has already been included. */
00024 #include "postgres_fe.h"
00025 #include "libpq-events.h"
00026 
00027 #include <time.h>
00028 #include <sys/types.h>
00029 #ifndef WIN32
00030 #include <sys/time.h>
00031 #endif
00032 
00033 #ifdef ENABLE_THREAD_SAFETY
00034 #ifdef WIN32
00035 #include "pthread-win32.h"
00036 #else
00037 #include <pthread.h>
00038 #endif
00039 #include <signal.h>
00040 #endif
00041 
00042 /* include stuff common to fe and be */
00043 #include "getaddrinfo.h"
00044 #include "libpq/pqcomm.h"
00045 /* include stuff found in fe only */
00046 #include "pqexpbuffer.h"
00047 
00048 #ifdef ENABLE_GSS
00049 #if defined(HAVE_GSSAPI_H)
00050 #include <gssapi.h>
00051 #else
00052 #include <gssapi/gssapi.h>
00053 #endif
00054 #endif
00055 
00056 #ifdef ENABLE_SSPI
00057 #define SECURITY_WIN32
00058 #if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
00059 #include <ntsecapi.h>
00060 #endif
00061 #include <security.h>
00062 #undef SECURITY_WIN32
00063 
00064 #ifndef ENABLE_GSS
00065 /*
00066  * Define a fake structure compatible with GSSAPI on Unix.
00067  */
00068 typedef struct
00069 {
00070     void       *value;
00071     int         length;
00072 } gss_buffer_desc;
00073 #endif
00074 #endif   /* ENABLE_SSPI */
00075 
00076 #ifdef USE_SSL
00077 #include <openssl/ssl.h>
00078 #include <openssl/err.h>
00079 
00080 #if (SSLEAY_VERSION_NUMBER >= 0x00907000L) && !defined(OPENSSL_NO_ENGINE)
00081 #define USE_SSL_ENGINE
00082 #endif
00083 #endif   /* USE_SSL */
00084 
00085 /*
00086  * POSTGRES backend dependent Constants.
00087  */
00088 #define CMDSTATUS_LEN 64        /* should match COMPLETION_TAG_BUFSIZE */
00089 
00090 /*
00091  * PGresult and the subsidiary types PGresAttDesc, PGresAttValue
00092  * represent the result of a query (or more precisely, of a single SQL
00093  * command --- a query string given to PQexec can contain multiple commands).
00094  * Note we assume that a single command can return at most one tuple group,
00095  * hence there is no need for multiple descriptor sets.
00096  */
00097 
00098 /* Subsidiary-storage management structure for PGresult.
00099  * See space management routines in fe-exec.c for details.
00100  * Note that space[k] refers to the k'th byte starting from the physical
00101  * head of the block --- it's a union, not a struct!
00102  */
00103 typedef union pgresult_data PGresult_data;
00104 
00105 union pgresult_data
00106 {
00107     PGresult_data *next;        /* link to next block, or NULL */
00108     char        space[1];       /* dummy for accessing block as bytes */
00109 };
00110 
00111 /* Data about a single parameter of a prepared statement */
00112 typedef struct pgresParamDesc
00113 {
00114     Oid         typid;          /* type id */
00115 } PGresParamDesc;
00116 
00117 /*
00118  * Data for a single attribute of a single tuple
00119  *
00120  * We use char* for Attribute values.
00121  *
00122  * The value pointer always points to a null-terminated area; we add a
00123  * null (zero) byte after whatever the backend sends us.  This is only
00124  * particularly useful for text values ... with a binary value, the
00125  * value might have embedded nulls, so the application can't use C string
00126  * operators on it.  But we add a null anyway for consistency.
00127  * Note that the value itself does not contain a length word.
00128  *
00129  * A NULL attribute is a special case in two ways: its len field is NULL_LEN
00130  * and its value field points to null_field in the owning PGresult.  All the
00131  * NULL attributes in a query result point to the same place (there's no need
00132  * to store a null string separately for each one).
00133  */
00134 
00135 #define NULL_LEN        (-1)    /* pg_result len for NULL value */
00136 
00137 typedef struct pgresAttValue
00138 {
00139     int         len;            /* length in bytes of the value */
00140     char       *value;          /* actual value, plus terminating zero byte */
00141 } PGresAttValue;
00142 
00143 /* Typedef for message-field list entries */
00144 typedef struct pgMessageField
00145 {
00146     struct pgMessageField *next;    /* list link */
00147     char        code;           /* field code */
00148     char        contents[1];    /* field value (VARIABLE LENGTH) */
00149 } PGMessageField;
00150 
00151 /* Fields needed for notice handling */
00152 typedef struct
00153 {
00154     PQnoticeReceiver noticeRec; /* notice message receiver */
00155     void       *noticeRecArg;
00156     PQnoticeProcessor noticeProc;       /* notice message processor */
00157     void       *noticeProcArg;
00158 } PGNoticeHooks;
00159 
00160 typedef struct PGEvent
00161 {
00162     PGEventProc proc;           /* the function to call on events */
00163     char       *name;           /* used only for error messages */
00164     void       *passThrough;    /* pointer supplied at registration time */
00165     void       *data;           /* optional state (instance) data */
00166     bool        resultInitialized;      /* T if RESULTCREATE/COPY succeeded */
00167 } PGEvent;
00168 
00169 struct pg_result
00170 {
00171     int         ntups;
00172     int         numAttributes;
00173     PGresAttDesc *attDescs;
00174     PGresAttValue **tuples;     /* each PGresTuple is an array of
00175                                  * PGresAttValue's */
00176     int         tupArrSize;     /* allocated size of tuples array */
00177     int         numParameters;
00178     PGresParamDesc *paramDescs;
00179     ExecStatusType resultStatus;
00180     char        cmdStatus[CMDSTATUS_LEN];       /* cmd status from the query */
00181     int         binary;         /* binary tuple values if binary == 1,
00182                                  * otherwise text */
00183 
00184     /*
00185      * These fields are copied from the originating PGconn, so that operations
00186      * on the PGresult don't have to reference the PGconn.
00187      */
00188     PGNoticeHooks noticeHooks;
00189     PGEvent    *events;
00190     int         nEvents;
00191     int         client_encoding;    /* encoding id */
00192 
00193     /*
00194      * Error information (all NULL if not an error result).  errMsg is the
00195      * "overall" error message returned by PQresultErrorMessage.  If we have
00196      * per-field info then it is stored in a linked list.
00197      */
00198     char       *errMsg;         /* error message, or NULL if no error */
00199     PGMessageField *errFields;  /* message broken into fields */
00200 
00201     /* All NULL attributes in the query result point to this null string */
00202     char        null_field[1];
00203 
00204     /*
00205      * Space management information.  Note that attDescs and error stuff, if
00206      * not null, point into allocated blocks.  But tuples points to a
00207      * separately malloc'd block, so that we can realloc it.
00208      */
00209     PGresult_data *curBlock;    /* most recently allocated block */
00210     int         curOffset;      /* start offset of free space in block */
00211     int         spaceLeft;      /* number of free bytes remaining in block */
00212 };
00213 
00214 /* PGAsyncStatusType defines the state of the query-execution state machine */
00215 typedef enum
00216 {
00217     PGASYNC_IDLE,               /* nothing's happening, dude */
00218     PGASYNC_BUSY,               /* query in progress */
00219     PGASYNC_READY,              /* result ready for PQgetResult */
00220     PGASYNC_COPY_IN,            /* Copy In data transfer in progress */
00221     PGASYNC_COPY_OUT,           /* Copy Out data transfer in progress */
00222     PGASYNC_COPY_BOTH           /* Copy In/Out data transfer in progress */
00223 } PGAsyncStatusType;
00224 
00225 /* PGQueryClass tracks which query protocol we are now executing */
00226 typedef enum
00227 {
00228     PGQUERY_SIMPLE,             /* simple Query protocol (PQexec) */
00229     PGQUERY_EXTENDED,           /* full Extended protocol (PQexecParams) */
00230     PGQUERY_PREPARE,            /* Parse only (PQprepare) */
00231     PGQUERY_DESCRIBE            /* Describe Statement or Portal */
00232 } PGQueryClass;
00233 
00234 /* PGSetenvStatusType defines the state of the PQSetenv state machine */
00235 /* (this is used only for 2.0-protocol connections) */
00236 typedef enum
00237 {
00238     SETENV_STATE_CLIENT_ENCODING_SEND,  /* About to send an Environment Option */
00239     SETENV_STATE_CLIENT_ENCODING_WAIT,  /* Waiting for above send to complete */
00240     SETENV_STATE_OPTION_SEND,   /* About to send an Environment Option */
00241     SETENV_STATE_OPTION_WAIT,   /* Waiting for above send to complete */
00242     SETENV_STATE_QUERY1_SEND,   /* About to send a status query */
00243     SETENV_STATE_QUERY1_WAIT,   /* Waiting for query to complete */
00244     SETENV_STATE_QUERY2_SEND,   /* About to send a status query */
00245     SETENV_STATE_QUERY2_WAIT,   /* Waiting for query to complete */
00246     SETENV_STATE_IDLE
00247 } PGSetenvStatusType;
00248 
00249 /* Typedef for the EnvironmentOptions[] array */
00250 typedef struct PQEnvironmentOption
00251 {
00252     const char *envName,        /* name of an environment variable */
00253                *pgName;         /* name of corresponding SET variable */
00254 } PQEnvironmentOption;
00255 
00256 /* Typedef for parameter-status list entries */
00257 typedef struct pgParameterStatus
00258 {
00259     struct pgParameterStatus *next;     /* list link */
00260     char       *name;           /* parameter name */
00261     char       *value;          /* parameter value */
00262     /* Note: name and value are stored in same malloc block as struct is */
00263 } pgParameterStatus;
00264 
00265 /* large-object-access data ... allocated only if large-object code is used. */
00266 typedef struct pgLobjfuncs
00267 {
00268     Oid         fn_lo_open;     /* OID of backend function lo_open      */
00269     Oid         fn_lo_close;    /* OID of backend function lo_close     */
00270     Oid         fn_lo_creat;    /* OID of backend function lo_creat     */
00271     Oid         fn_lo_create;   /* OID of backend function lo_create    */
00272     Oid         fn_lo_unlink;   /* OID of backend function lo_unlink    */
00273     Oid         fn_lo_lseek;    /* OID of backend function lo_lseek     */
00274     Oid         fn_lo_lseek64;  /* OID of backend function lo_lseek64   */
00275     Oid         fn_lo_tell;     /* OID of backend function lo_tell      */
00276     Oid         fn_lo_tell64;   /* OID of backend function lo_tell64    */
00277     Oid         fn_lo_truncate; /* OID of backend function lo_truncate  */
00278     Oid         fn_lo_truncate64;       /* OID of function lo_truncate64 */
00279     Oid         fn_lo_read;     /* OID of backend function LOread       */
00280     Oid         fn_lo_write;    /* OID of backend function LOwrite      */
00281 } PGlobjfuncs;
00282 
00283 /* PGdataValue represents a data field value being passed to a row processor.
00284  * It could be either text or binary data; text data is not zero-terminated.
00285  * A SQL NULL is represented by len < 0; then value is still valid but there
00286  * are no data bytes there.
00287  */
00288 typedef struct pgDataValue
00289 {
00290     int         len;            /* data length in bytes, or <0 if NULL */
00291     const char *value;          /* data value, without zero-termination */
00292 } PGdataValue;
00293 
00294 /*
00295  * PGconn stores all the state data associated with a single connection
00296  * to a backend.
00297  */
00298 struct pg_conn
00299 {
00300     /* Saved values of connection options */
00301     char       *pghost;         /* the machine on which the server is running */
00302     char       *pghostaddr;     /* the numeric IP address of the machine on
00303                                  * which the server is running.  Takes
00304                                  * precedence over above. */
00305     char       *pgport;         /* the server's communication port */
00306     char       *pgunixsocket;   /* the Unix-domain socket that the server is
00307                                  * listening on; if NULL, uses a default
00308                                  * constructed from pgport */
00309     char       *pgtty;          /* tty on which the backend messages is
00310                                  * displayed (OBSOLETE, NOT USED) */
00311     char       *connect_timeout;    /* connection timeout (numeric string) */
00312     char       *client_encoding_initial;        /* encoding to use */
00313     char       *pgoptions;      /* options to start the backend with */
00314     char       *appname;        /* application name */
00315     char       *fbappname;      /* fallback application name */
00316     char       *dbName;         /* database name */
00317     char       *replication;    /* connect as the replication standby? */
00318     char       *pguser;         /* Postgres username and password, if any */
00319     char       *pgpass;
00320     char       *keepalives;     /* use TCP keepalives? */
00321     char       *keepalives_idle;    /* time between TCP keepalives */
00322     char       *keepalives_interval;    /* time between TCP keepalive
00323                                          * retransmits */
00324     char       *keepalives_count;       /* maximum number of TCP keepalive
00325                                          * retransmits */
00326     char       *sslmode;        /* SSL mode (require,prefer,allow,disable) */
00327     char       *sslcompression; /* SSL compression (0 or 1) */
00328     char       *sslkey;         /* client key filename */
00329     char       *sslcert;        /* client certificate filename */
00330     char       *sslrootcert;    /* root certificate filename */
00331     char       *sslcrl;         /* certificate revocation list filename */
00332     char       *requirepeer;    /* required peer credentials for local sockets */
00333 
00334 #if defined(KRB5) || defined(ENABLE_GSS) || defined(ENABLE_SSPI)
00335     char       *krbsrvname;     /* Kerberos service name */
00336 #endif
00337 
00338     /* Optional file to write trace info to */
00339     FILE       *Pfdebug;
00340 
00341     /* Callback procedures for notice message processing */
00342     PGNoticeHooks noticeHooks;
00343 
00344     /* Event procs registered via PQregisterEventProc */
00345     PGEvent    *events;         /* expandable array of event data */
00346     int         nEvents;        /* number of active events */
00347     int         eventArraySize; /* allocated array size */
00348 
00349     /* Status indicators */
00350     ConnStatusType status;
00351     PGAsyncStatusType asyncStatus;
00352     PGTransactionStatusType xactStatus; /* never changes to ACTIVE */
00353     PGQueryClass queryclass;
00354     char       *last_query;     /* last SQL command, or NULL if unknown */
00355     char        last_sqlstate[6];       /* last reported SQLSTATE */
00356     bool        options_valid;  /* true if OK to attempt connection */
00357     bool        nonblocking;    /* whether this connection is using nonblock
00358                                  * sending semantics */
00359     bool        singleRowMode;  /* return current query result row-by-row? */
00360     char        copy_is_binary; /* 1 = copy binary, 0 = copy text */
00361     int         copy_already_done;      /* # bytes already returned in COPY
00362                                          * OUT */
00363     PGnotify   *notifyHead;     /* oldest unreported Notify msg */
00364     PGnotify   *notifyTail;     /* newest unreported Notify msg */
00365 
00366     /* Connection data */
00367     int         sock;           /* Unix FD for socket, -1 if not connected */
00368     SockAddr    laddr;          /* Local address */
00369     SockAddr    raddr;          /* Remote address */
00370     ProtocolVersion pversion;   /* FE/BE protocol version in use */
00371     int         sversion;       /* server version, e.g. 70401 for 7.4.1 */
00372     bool        auth_req_received;      /* true if any type of auth req
00373                                          * received */
00374     bool        password_needed;    /* true if server demanded a password */
00375     bool        dot_pgpass_used;    /* true if used .pgpass */
00376     bool        sigpipe_so;     /* have we masked SIGPIPE via SO_NOSIGPIPE? */
00377     bool        sigpipe_flag;   /* can we mask SIGPIPE via MSG_NOSIGNAL? */
00378 
00379     /* Transient state needed while establishing connection */
00380     struct addrinfo *addrlist;  /* list of possible backend addresses */
00381     struct addrinfo *addr_cur;  /* the one currently being tried */
00382     int         addrlist_family;    /* needed to know how to free addrlist */
00383     PGSetenvStatusType setenv_state;    /* for 2.0 protocol only */
00384     const PQEnvironmentOption *next_eo;
00385     bool        send_appname;   /* okay to send application_name? */
00386 
00387     /* Miscellaneous stuff */
00388     int         be_pid;         /* PID of backend --- needed for cancels */
00389     int         be_key;         /* key of backend --- needed for cancels */
00390     char        md5Salt[4];     /* password salt received from backend */
00391     pgParameterStatus *pstatus; /* ParameterStatus data */
00392     int         client_encoding;    /* encoding id */
00393     bool        std_strings;    /* standard_conforming_strings */
00394     PGVerbosity verbosity;      /* error/notice message verbosity */
00395     PGlobjfuncs *lobjfuncs;     /* private state for large-object access fns */
00396 
00397     /* Buffer for data received from backend and not yet processed */
00398     char       *inBuffer;       /* currently allocated buffer */
00399     int         inBufSize;      /* allocated size of buffer */
00400     int         inStart;        /* offset to first unconsumed data in buffer */
00401     int         inCursor;       /* next byte to tentatively consume */
00402     int         inEnd;          /* offset to first position after avail data */
00403 
00404     /* Buffer for data not yet sent to backend */
00405     char       *outBuffer;      /* currently allocated buffer */
00406     int         outBufSize;     /* allocated size of buffer */
00407     int         outCount;       /* number of chars waiting in buffer */
00408 
00409     /* State for constructing messages in outBuffer */
00410     int         outMsgStart;    /* offset to msg start (length word); if -1,
00411                                  * msg has no length word */
00412     int         outMsgEnd;      /* offset to msg end (so far) */
00413 
00414     /* Row processor interface workspace */
00415     PGdataValue *rowBuf;        /* array for passing values to rowProcessor */
00416     int         rowBufLen;      /* number of entries allocated in rowBuf */
00417 
00418     /* Status for asynchronous result construction */
00419     PGresult   *result;         /* result being constructed */
00420     PGresult   *next_result;    /* next result (used in single-row mode) */
00421 
00422     /* Assorted state for SSL, GSS, etc */
00423 
00424 #ifdef USE_SSL
00425     bool        allow_ssl_try;  /* Allowed to try SSL negotiation */
00426     bool        wait_ssl_try;   /* Delay SSL negotiation until after
00427                                  * attempting normal connection */
00428     SSL        *ssl;            /* SSL status, if have SSL connection */
00429     X509       *peer;           /* X509 cert of server */
00430 #ifdef USE_SSL_ENGINE
00431     ENGINE     *engine;         /* SSL engine, if any */
00432 #else
00433     void       *engine;         /* dummy field to keep struct the same if
00434                                  * OpenSSL version changes */
00435 #endif
00436 #endif   /* USE_SSL */
00437 
00438 #ifdef ENABLE_GSS
00439     gss_ctx_id_t gctx;          /* GSS context */
00440     gss_name_t  gtarg_nam;      /* GSS target name */
00441     gss_buffer_desc ginbuf;     /* GSS input token */
00442     gss_buffer_desc goutbuf;    /* GSS output token */
00443 #endif
00444 
00445 #ifdef ENABLE_SSPI
00446 #ifndef ENABLE_GSS
00447     gss_buffer_desc ginbuf;     /* GSS input token */
00448 #else
00449     char       *gsslib;         /* What GSS librart to use ("gssapi" or
00450                                  * "sspi") */
00451 #endif
00452     CredHandle *sspicred;       /* SSPI credentials handle */
00453     CtxtHandle *sspictx;        /* SSPI context */
00454     char       *sspitarget;     /* SSPI target name */
00455     int         usesspi;        /* Indicate if SSPI is in use on the
00456                                  * connection */
00457 #endif
00458 
00459     /* Buffer for current error message */
00460     PQExpBufferData errorMessage;       /* expansible string */
00461 
00462     /* Buffer for receiving various parts of messages */
00463     PQExpBufferData workBuffer; /* expansible string */
00464 };
00465 
00466 /* PGcancel stores all data necessary to cancel a connection. A copy of this
00467  * data is required to safely cancel a connection running on a different
00468  * thread.
00469  */
00470 struct pg_cancel
00471 {
00472     SockAddr    raddr;          /* Remote address */
00473     int         be_pid;         /* PID of backend --- needed for cancels */
00474     int         be_key;         /* key of backend --- needed for cancels */
00475 };
00476 
00477 
00478 /* String descriptions of the ExecStatusTypes.
00479  * direct use of this array is deprecated; call PQresStatus() instead.
00480  */
00481 extern char *const pgresStatus[];
00482 
00483 /* ----------------
00484  * Internal functions of libpq
00485  * Functions declared here need to be visible across files of libpq,
00486  * but are not intended to be called by applications.  We use the
00487  * convention "pqXXX" for internal functions, vs. the "PQxxx" names
00488  * used for application-visible routines.
00489  * ----------------
00490  */
00491 
00492 /* === in fe-connect.c === */
00493 
00494 extern void pqDropConnection(PGconn *conn);
00495 extern int pqPacketSend(PGconn *conn, char pack_type,
00496              const void *buf, size_t buf_len);
00497 extern bool pqGetHomeDirectory(char *buf, int bufsize);
00498 
00499 #ifdef ENABLE_THREAD_SAFETY
00500 extern pgthreadlock_t pg_g_threadlock;
00501 
00502 #define PGTHREAD_ERROR(msg) \
00503     do { \
00504         fprintf(stderr, "%s\n", msg); \
00505         abort(); \
00506     } while (0)
00507 
00508 
00509 #define pglock_thread()     pg_g_threadlock(true)
00510 #define pgunlock_thread()   pg_g_threadlock(false)
00511 #else
00512 #define pglock_thread()     ((void) 0)
00513 #define pgunlock_thread()   ((void) 0)
00514 #endif
00515 
00516 /* === in fe-exec.c === */
00517 
00518 extern void pqSetResultError(PGresult *res, const char *msg);
00519 extern void pqCatenateResultError(PGresult *res, const char *msg);
00520 extern void *pqResultAlloc(PGresult *res, size_t nBytes, bool isBinary);
00521 extern char *pqResultStrdup(PGresult *res, const char *str);
00522 extern void pqClearAsyncResult(PGconn *conn);
00523 extern void pqSaveErrorResult(PGconn *conn);
00524 extern PGresult *pqPrepareAsyncResult(PGconn *conn);
00525 extern void
00526 pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...)
00527 /* This lets gcc check the format string for consistency. */
00528 __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
00529 extern void pqSaveMessageField(PGresult *res, char code,
00530                    const char *value);
00531 extern void pqSaveParameterStatus(PGconn *conn, const char *name,
00532                       const char *value);
00533 extern int  pqRowProcessor(PGconn *conn, const char **errmsgp);
00534 extern void pqHandleSendFailure(PGconn *conn);
00535 
00536 /* === in fe-protocol2.c === */
00537 
00538 extern PostgresPollingStatusType pqSetenvPoll(PGconn *conn);
00539 
00540 extern char *pqBuildStartupPacket2(PGconn *conn, int *packetlen,
00541                       const PQEnvironmentOption *options);
00542 extern void pqParseInput2(PGconn *conn);
00543 extern int  pqGetCopyData2(PGconn *conn, char **buffer, int async);
00544 extern int  pqGetline2(PGconn *conn, char *s, int maxlen);
00545 extern int  pqGetlineAsync2(PGconn *conn, char *buffer, int bufsize);
00546 extern int  pqEndcopy2(PGconn *conn);
00547 extern PGresult *pqFunctionCall2(PGconn *conn, Oid fnid,
00548                 int *result_buf, int *actual_result_len,
00549                 int result_is_int,
00550                 const PQArgBlock *args, int nargs);
00551 
00552 /* === in fe-protocol3.c === */
00553 
00554 extern char *pqBuildStartupPacket3(PGconn *conn, int *packetlen,
00555                       const PQEnvironmentOption *options);
00556 extern void pqParseInput3(PGconn *conn);
00557 extern int  pqGetErrorNotice3(PGconn *conn, bool isError);
00558 extern int  pqGetCopyData3(PGconn *conn, char **buffer, int async);
00559 extern int  pqGetline3(PGconn *conn, char *s, int maxlen);
00560 extern int  pqGetlineAsync3(PGconn *conn, char *buffer, int bufsize);
00561 extern int  pqEndcopy3(PGconn *conn);
00562 extern PGresult *pqFunctionCall3(PGconn *conn, Oid fnid,
00563                 int *result_buf, int *actual_result_len,
00564                 int result_is_int,
00565                 const PQArgBlock *args, int nargs);
00566 
00567 /* === in fe-misc.c === */
00568 
00569  /*
00570   * "Get" and "Put" routines return 0 if successful, EOF if not. Note that for
00571   * Get, EOF merely means the buffer is exhausted, not that there is
00572   * necessarily any error.
00573   */
00574 extern int  pqCheckOutBufferSpace(size_t bytes_needed, PGconn *conn);
00575 extern int  pqCheckInBufferSpace(size_t bytes_needed, PGconn *conn);
00576 extern int  pqGetc(char *result, PGconn *conn);
00577 extern int  pqPutc(char c, PGconn *conn);
00578 extern int  pqGets(PQExpBuffer buf, PGconn *conn);
00579 extern int  pqGets_append(PQExpBuffer buf, PGconn *conn);
00580 extern int  pqPuts(const char *s, PGconn *conn);
00581 extern int  pqGetnchar(char *s, size_t len, PGconn *conn);
00582 extern int  pqSkipnchar(size_t len, PGconn *conn);
00583 extern int  pqPutnchar(const char *s, size_t len, PGconn *conn);
00584 extern int  pqGetInt(int *result, size_t bytes, PGconn *conn);
00585 extern int  pqPutInt(int value, size_t bytes, PGconn *conn);
00586 extern int  pqPutMsgStart(char msg_type, bool force_len, PGconn *conn);
00587 extern int  pqPutMsgEnd(PGconn *conn);
00588 extern int  pqReadData(PGconn *conn);
00589 extern int  pqFlush(PGconn *conn);
00590 extern int  pqWait(int forRead, int forWrite, PGconn *conn);
00591 extern int pqWaitTimed(int forRead, int forWrite, PGconn *conn,
00592             time_t finish_time);
00593 extern int  pqReadReady(PGconn *conn);
00594 extern int  pqWriteReady(PGconn *conn);
00595 
00596 /* === in fe-secure.c === */
00597 
00598 extern int  pqsecure_initialize(PGconn *);
00599 extern void pqsecure_destroy(void);
00600 extern PostgresPollingStatusType pqsecure_open_client(PGconn *);
00601 extern void pqsecure_close(PGconn *);
00602 extern ssize_t pqsecure_read(PGconn *, void *ptr, size_t len);
00603 extern ssize_t pqsecure_write(PGconn *, const void *ptr, size_t len);
00604 
00605 #if defined(ENABLE_THREAD_SAFETY) && !defined(WIN32)
00606 extern int  pq_block_sigpipe(sigset_t *osigset, bool *sigpipe_pending);
00607 extern void pq_reset_sigpipe(sigset_t *osigset, bool sigpipe_pending,
00608                  bool got_epipe);
00609 #endif
00610 
00611 /*
00612  * this is so that we can check if a connection is non-blocking internally
00613  * without the overhead of a function call
00614  */
00615 #define pqIsnonblocking(conn)   ((conn)->nonblocking)
00616 
00617 #ifdef ENABLE_NLS
00618 extern char *
00619 libpq_gettext(const char *msgid)
00620 __attribute__((format_arg(1)));
00621 #else
00622 #define libpq_gettext(x) (x)
00623 #endif
00624 
00625 /*
00626  * These macros are needed to let error-handling code be portable between
00627  * Unix and Windows.  (ugh)
00628  */
00629 #ifdef WIN32
00630 #define SOCK_ERRNO (WSAGetLastError())
00631 #define SOCK_STRERROR winsock_strerror
00632 #define SOCK_ERRNO_SET(e) WSASetLastError(e)
00633 #else
00634 #define SOCK_ERRNO errno
00635 #define SOCK_STRERROR pqStrerror
00636 #define SOCK_ERRNO_SET(e) (errno = (e))
00637 #endif
00638 
00639 #endif   /* LIBPQ_INT_H */