PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
libpq-int.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * libpq-int.h
4  * This file contains internal definitions meant to be used only by
5  * the frontend libpq library, not by applications that call it.
6  *
7  * An application can include this file if it wants to bypass the
8  * official API defined by libpq-fe.h, but code that does so is much
9  * more likely to break across PostgreSQL releases than code that uses
10  * only the official API.
11  *
12  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
13  * Portions Copyright (c) 1994, Regents of the University of California
14  *
15  * src/interfaces/libpq/libpq-int.h
16  *
17  *-------------------------------------------------------------------------
18  */
19 
20 #ifndef LIBPQ_INT_H
21 #define LIBPQ_INT_H
22 
23 /* We assume libpq-fe.h has already been included. */
24 #include "postgres_fe.h"
25 #include "libpq-events.h"
26 
27 #include <time.h>
28 #include <sys/types.h>
29 #ifndef WIN32
30 #include <sys/time.h>
31 #endif
32 
33 #ifdef ENABLE_THREAD_SAFETY
34 #ifdef WIN32
35 #include "pthread-win32.h"
36 #else
37 #include <pthread.h>
38 #endif
39 #include <signal.h>
40 #endif
41 
42 /* include stuff common to fe and be */
43 #include "getaddrinfo.h"
44 #include "libpq/pqcomm.h"
45 /* include stuff found in fe only */
46 #include "pqexpbuffer.h"
47 
48 #ifdef ENABLE_GSS
49 #if defined(HAVE_GSSAPI_H)
50 #include <gssapi.h>
51 #else
52 #include <gssapi/gssapi.h>
53 #endif
54 #endif
55 
56 #ifdef ENABLE_SSPI
57 #define SECURITY_WIN32
58 #if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
59 #include <ntsecapi.h>
60 #endif
61 #include <security.h>
62 #undef SECURITY_WIN32
63 
64 #ifndef ENABLE_GSS
65 /*
66  * Define a fake structure compatible with GSSAPI on Unix.
67  */
68 typedef struct
69 {
70  void *value;
71  int length;
72 } gss_buffer_desc;
73 #endif
74 #endif /* ENABLE_SSPI */
75 
76 #ifdef USE_OPENSSL
77 #include <openssl/ssl.h>
78 #include <openssl/err.h>
79 
80 #ifndef OPENSSL_NO_ENGINE
81 #define USE_SSL_ENGINE
82 #endif
83 #endif /* USE_OPENSSL */
84 
85 /*
86  * POSTGRES backend dependent Constants.
87  */
88 #define CMDSTATUS_LEN 64 /* should match COMPLETION_TAG_BUFSIZE */
89 
90 /*
91  * PGresult and the subsidiary types PGresAttDesc, PGresAttValue
92  * represent the result of a query (or more precisely, of a single SQL
93  * command --- a query string given to PQexec can contain multiple commands).
94  * Note we assume that a single command can return at most one tuple group,
95  * hence there is no need for multiple descriptor sets.
96  */
97 
98 /* Subsidiary-storage management structure for PGresult.
99  * See space management routines in fe-exec.c for details.
100  * Note that space[k] refers to the k'th byte starting from the physical
101  * head of the block --- it's a union, not a struct!
102  */
104 
106 {
107  PGresult_data *next; /* link to next block, or NULL */
108  char space[1]; /* dummy for accessing block as bytes */
109 };
110 
111 /* Data about a single parameter of a prepared statement */
112 typedef struct pgresParamDesc
113 {
114  Oid typid; /* type id */
116 
117 /*
118  * Data for a single attribute of a single tuple
119  *
120  * We use char* for Attribute values.
121  *
122  * The value pointer always points to a null-terminated area; we add a
123  * null (zero) byte after whatever the backend sends us. This is only
124  * particularly useful for text values ... with a binary value, the
125  * value might have embedded nulls, so the application can't use C string
126  * operators on it. But we add a null anyway for consistency.
127  * Note that the value itself does not contain a length word.
128  *
129  * A NULL attribute is a special case in two ways: its len field is NULL_LEN
130  * and its value field points to null_field in the owning PGresult. All the
131  * NULL attributes in a query result point to the same place (there's no need
132  * to store a null string separately for each one).
133  */
134 
135 #define NULL_LEN (-1) /* pg_result len for NULL value */
136 
137 typedef struct pgresAttValue
138 {
139  int len; /* length in bytes of the value */
140  char *value; /* actual value, plus terminating zero byte */
141 } PGresAttValue;
142 
143 /* Typedef for message-field list entries */
144 typedef struct pgMessageField
145 {
146  struct pgMessageField *next; /* list link */
147  char code; /* field code */
148  char contents[FLEXIBLE_ARRAY_MEMBER]; /* value, nul-terminated */
150 
151 /* Fields needed for notice handling */
152 typedef struct
153 {
154  PQnoticeReceiver noticeRec; /* notice message receiver */
156  PQnoticeProcessor noticeProc; /* notice message processor */
158 } PGNoticeHooks;
159 
160 typedef struct PGEvent
161 {
162  PGEventProc proc; /* the function to call on events */
163  char *name; /* used only for error messages */
164  void *passThrough; /* pointer supplied at registration time */
165  void *data; /* optional state (instance) data */
166  bool resultInitialized; /* T if RESULTCREATE/COPY succeeded */
167 } PGEvent;
168 
169 struct pg_result
170 {
171  int ntups;
174  PGresAttValue **tuples; /* each PGresTuple is an array of
175  * PGresAttValue's */
176  int tupArrSize; /* allocated size of tuples array */
180  char cmdStatus[CMDSTATUS_LEN]; /* cmd status from the query */
181  int binary; /* binary tuple values if binary == 1,
182  * otherwise text */
183 
184  /*
185  * These fields are copied from the originating PGconn, so that operations
186  * on the PGresult don't have to reference the PGconn.
187  */
190  int nEvents;
191  int client_encoding; /* encoding id */
192 
193  /*
194  * Error information (all NULL if not an error result). errMsg is the
195  * "overall" error message returned by PQresultErrorMessage. If we have
196  * per-field info then it is stored in a linked list.
197  */
198  char *errMsg; /* error message, or NULL if no error */
199  PGMessageField *errFields; /* message broken into fields */
200  char *errQuery; /* text of triggering query, if available */
201 
202  /* All NULL attributes in the query result point to this null string */
203  char null_field[1];
204 
205  /*
206  * Space management information. Note that attDescs and error stuff, if
207  * not null, point into allocated blocks. But tuples points to a
208  * separately malloc'd block, so that we can realloc it.
209  */
210  PGresult_data *curBlock; /* most recently allocated block */
211  int curOffset; /* start offset of free space in block */
212  int spaceLeft; /* number of free bytes remaining in block */
213 };
214 
215 /* PGAsyncStatusType defines the state of the query-execution state machine */
216 typedef enum
217 {
218  PGASYNC_IDLE, /* nothing's happening, dude */
219  PGASYNC_BUSY, /* query in progress */
220  PGASYNC_READY, /* result ready for PQgetResult */
221  PGASYNC_COPY_IN, /* Copy In data transfer in progress */
222  PGASYNC_COPY_OUT, /* Copy Out data transfer in progress */
223  PGASYNC_COPY_BOTH /* Copy In/Out data transfer in progress */
225 
226 /* PGQueryClass tracks which query protocol we are now executing */
227 typedef enum
228 {
229  PGQUERY_SIMPLE, /* simple Query protocol (PQexec) */
230  PGQUERY_EXTENDED, /* full Extended protocol (PQexecParams) */
231  PGQUERY_PREPARE, /* Parse only (PQprepare) */
232  PGQUERY_DESCRIBE /* Describe Statement or Portal */
233 } PGQueryClass;
234 
235 /* PGSetenvStatusType defines the state of the PQSetenv state machine */
236 /* (this is used only for 2.0-protocol connections) */
237 typedef enum
238 {
239  SETENV_STATE_CLIENT_ENCODING_SEND, /* About to send an Environment Option */
240  SETENV_STATE_CLIENT_ENCODING_WAIT, /* Waiting for above send to complete */
241  SETENV_STATE_OPTION_SEND, /* About to send an Environment Option */
242  SETENV_STATE_OPTION_WAIT, /* Waiting for above send to complete */
243  SETENV_STATE_QUERY1_SEND, /* About to send a status query */
244  SETENV_STATE_QUERY1_WAIT, /* Waiting for query to complete */
245  SETENV_STATE_QUERY2_SEND, /* About to send a status query */
246  SETENV_STATE_QUERY2_WAIT, /* Waiting for query to complete */
249 
250 /* Typedef for the EnvironmentOptions[] array */
251 typedef struct PQEnvironmentOption
252 {
253  const char *envName, /* name of an environment variable */
254  *pgName; /* name of corresponding SET variable */
256 
257 /* Typedef for parameter-status list entries */
258 typedef struct pgParameterStatus
259 {
260  struct pgParameterStatus *next; /* list link */
261  char *name; /* parameter name */
262  char *value; /* parameter value */
263  /* Note: name and value are stored in same malloc block as struct is */
265 
266 /* large-object-access data ... allocated only if large-object code is used. */
267 typedef struct pgLobjfuncs
268 {
269  Oid fn_lo_open; /* OID of backend function lo_open */
270  Oid fn_lo_close; /* OID of backend function lo_close */
271  Oid fn_lo_creat; /* OID of backend function lo_creat */
272  Oid fn_lo_create; /* OID of backend function lo_create */
273  Oid fn_lo_unlink; /* OID of backend function lo_unlink */
274  Oid fn_lo_lseek; /* OID of backend function lo_lseek */
275  Oid fn_lo_lseek64; /* OID of backend function lo_lseek64 */
276  Oid fn_lo_tell; /* OID of backend function lo_tell */
277  Oid fn_lo_tell64; /* OID of backend function lo_tell64 */
278  Oid fn_lo_truncate; /* OID of backend function lo_truncate */
279  Oid fn_lo_truncate64; /* OID of function lo_truncate64 */
280  Oid fn_lo_read; /* OID of backend function LOread */
281  Oid fn_lo_write; /* OID of backend function LOwrite */
282 } PGlobjfuncs;
283 
284 /* PGdataValue represents a data field value being passed to a row processor.
285  * It could be either text or binary data; text data is not zero-terminated.
286  * A SQL NULL is represented by len < 0; then value is still valid but there
287  * are no data bytes there.
288  */
289 typedef struct pgDataValue
290 {
291  int len; /* data length in bytes, or <0 if NULL */
292  const char *value; /* data value, without zero-termination */
293 } PGdataValue;
294 
295 typedef enum pg_conn_host_type
296 {
301 
302 /*
303  * pg_conn_host stores all information about one of possibly several hosts
304  * mentioned in the connection string. Derived by splitting the pghost
305  * on the comma character and then parsing each segment.
306  */
307 typedef struct pg_conn_host
308 {
309  char *host; /* host name or address, or socket path */
310  pg_conn_host_type type; /* type of host */
311  char *port; /* port number for this host; if not NULL,
312  * overrides the PGConn's pgport */
313  char *password; /* password for this host, read from the
314  * password file. only set if the PGconn's
315  * pgpass field is NULL. */
316  struct addrinfo *addrlist; /* list of possible backend addresses */
317 } pg_conn_host;
318 
319 /*
320  * PGconn stores all the state data associated with a single connection
321  * to a backend.
322  */
323 struct pg_conn
324 {
325  /* Saved values of connection options */
326  char *pghost; /* the machine on which the server is running,
327  * or a path to a UNIX-domain socket, or a
328  * comma-separated list of machines and/or
329  * paths, optionally with port suffixes; if
330  * NULL, use DEFAULT_PGSOCKET_DIR */
331  char *pghostaddr; /* the numeric IP address of the machine on
332  * which the server is running. Takes
333  * precedence over above. */
334  char *pgport; /* the server's communication port number */
335  char *pgtty; /* tty on which the backend messages is
336  * displayed (OBSOLETE, NOT USED) */
337  char *connect_timeout; /* connection timeout (numeric string) */
338  char *client_encoding_initial; /* encoding to use */
339  char *pgoptions; /* options to start the backend with */
340  char *appname; /* application name */
341  char *fbappname; /* fallback application name */
342  char *dbName; /* database name */
343  char *replication; /* connect as the replication standby? */
344  char *pguser; /* Postgres username and password, if any */
345  char *pgpass;
346  char *pgpassfile; /* path to a file containing password(s) */
347  char *keepalives; /* use TCP keepalives? */
348  char *keepalives_idle; /* time between TCP keepalives */
349  char *keepalives_interval; /* time between TCP keepalive
350  * retransmits */
351  char *keepalives_count; /* maximum number of TCP keepalive
352  * retransmits */
353  char *sslmode; /* SSL mode (require,prefer,allow,disable) */
354  char *sslcompression; /* SSL compression (0 or 1) */
355  char *sslkey; /* client key filename */
356  char *sslcert; /* client certificate filename */
357  char *sslrootcert; /* root certificate filename */
358  char *sslcrl; /* certificate revocation list filename */
359  char *requirepeer; /* required peer credentials for local sockets */
360 
361 #if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
362  char *krbsrvname; /* Kerberos service name */
363 #endif
364 
365  char *target_session_attrs; /* Type of connection to make
366  * Possible values any, read-write. */
367 
368  /* Optional file to write trace info to */
369  FILE *Pfdebug;
370 
371  /* Callback procedures for notice message processing */
373 
374  /* Event procs registered via PQregisterEventProc */
375  PGEvent *events; /* expandable array of event data */
376  int nEvents; /* number of active events */
377  int eventArraySize; /* allocated array size */
378 
379  /* Status indicators */
382  PGTransactionStatusType xactStatus; /* never changes to ACTIVE */
384  char *last_query; /* last SQL command, or NULL if unknown */
385  char last_sqlstate[6]; /* last reported SQLSTATE */
386  bool options_valid; /* true if OK to attempt connection */
387  bool nonblocking; /* whether this connection is using nonblock
388  * sending semantics */
389  bool singleRowMode; /* return current query result row-by-row? */
390  char copy_is_binary; /* 1 = copy binary, 0 = copy text */
391  int copy_already_done; /* # bytes already returned in COPY
392  * OUT */
393  PGnotify *notifyHead; /* oldest unreported Notify msg */
394  PGnotify *notifyTail; /* newest unreported Notify msg */
395 
396  /* Support for multiple hosts in connection string */
397  int nconnhost; /* # of possible hosts */
398  int whichhost; /* host we're currently considering */
399  pg_conn_host *connhost; /* details about each possible host */
400 
401  /* Connection data */
402  pgsocket sock; /* FD for socket, PGINVALID_SOCKET if
403  * unconnected */
404  SockAddr laddr; /* Local address */
405  SockAddr raddr; /* Remote address */
406  ProtocolVersion pversion; /* FE/BE protocol version in use */
407  int sversion; /* server version, e.g. 70401 for 7.4.1 */
408  bool auth_req_received; /* true if any type of auth req
409  * received */
410  bool password_needed; /* true if server demanded a password */
411  bool pgpassfile_used; /* true if password is from pgpassfile */
412  bool sigpipe_so; /* have we masked SIGPIPE via SO_NOSIGPIPE? */
413  bool sigpipe_flag; /* can we mask SIGPIPE via MSG_NOSIGNAL? */
414 
415  /* Transient state needed while establishing connection */
416  struct addrinfo *addr_cur; /* backend address currently being tried */
417  PGSetenvStatusType setenv_state; /* for 2.0 protocol only */
419  bool send_appname; /* okay to send application_name? */
420 
421  /* Miscellaneous stuff */
422  int be_pid; /* PID of backend --- needed for cancels */
423  int be_key; /* key of backend --- needed for cancels */
424  char md5Salt[4]; /* password salt received from backend */
425  pgParameterStatus *pstatus; /* ParameterStatus data */
426  int client_encoding; /* encoding id */
427  bool std_strings; /* standard_conforming_strings */
428  PGVerbosity verbosity; /* error/notice message verbosity */
429  PGContextVisibility show_context; /* whether to show CONTEXT field */
430  PGlobjfuncs *lobjfuncs; /* private state for large-object access fns */
431 
432  /* Buffer for data received from backend and not yet processed */
433  char *inBuffer; /* currently allocated buffer */
434  int inBufSize; /* allocated size of buffer */
435  int inStart; /* offset to first unconsumed data in buffer */
436  int inCursor; /* next byte to tentatively consume */
437  int inEnd; /* offset to first position after avail data */
438 
439  /* Buffer for data not yet sent to backend */
440  char *outBuffer; /* currently allocated buffer */
441  int outBufSize; /* allocated size of buffer */
442  int outCount; /* number of chars waiting in buffer */
443 
444  /* State for constructing messages in outBuffer */
445  int outMsgStart; /* offset to msg start (length word); if -1,
446  * msg has no length word */
447  int outMsgEnd; /* offset to msg end (so far) */
448 
449  /* Row processor interface workspace */
450  PGdataValue *rowBuf; /* array for passing values to rowProcessor */
451  int rowBufLen; /* number of entries allocated in rowBuf */
452 
453  /* Status for asynchronous result construction */
454  PGresult *result; /* result being constructed */
455  PGresult *next_result; /* next result (used in single-row mode) */
456 
457  /* Assorted state for SSL, GSS, etc */
458 
459 #ifdef USE_SSL
460  bool allow_ssl_try; /* Allowed to try SSL negotiation */
461  bool wait_ssl_try; /* Delay SSL negotiation until after
462  * attempting normal connection */
463  bool ssl_in_use;
464 #ifdef USE_OPENSSL
465  SSL *ssl; /* SSL status, if have SSL connection */
466  X509 *peer; /* X509 cert of server */
467 #ifdef USE_SSL_ENGINE
468  ENGINE *engine; /* SSL engine, if any */
469 #else
470  void *engine; /* dummy field to keep struct the same if
471  * OpenSSL version changes */
472 #endif
473 #endif /* USE_OPENSSL */
474 #endif /* USE_SSL */
475 
476 #ifdef ENABLE_GSS
477  gss_ctx_id_t gctx; /* GSS context */
478  gss_name_t gtarg_nam; /* GSS target name */
479  gss_buffer_desc ginbuf; /* GSS input token */
480  gss_buffer_desc goutbuf; /* GSS output token */
481 #endif
482 
483 #ifdef ENABLE_SSPI
484 #ifndef ENABLE_GSS
485  gss_buffer_desc ginbuf; /* GSS input token */
486 #else
487  char *gsslib; /* What GSS library to use ("gssapi" or
488  * "sspi") */
489 #endif
490  CredHandle *sspicred; /* SSPI credentials handle */
491  CtxtHandle *sspictx; /* SSPI context */
492  char *sspitarget; /* SSPI target name */
493  int usesspi; /* Indicate if SSPI is in use on the
494  * connection */
495 #endif
496 
497  /* Buffer for current error message */
498  PQExpBufferData errorMessage; /* expansible string */
499 
500  /* Buffer for receiving various parts of messages */
501  PQExpBufferData workBuffer; /* expansible string */
502 };
503 
504 /* PGcancel stores all data necessary to cancel a connection. A copy of this
505  * data is required to safely cancel a connection running on a different
506  * thread.
507  */
508 struct pg_cancel
509 {
510  SockAddr raddr; /* Remote address */
511  int be_pid; /* PID of backend --- needed for cancels */
512  int be_key; /* key of backend --- needed for cancels */
513 };
514 
515 
516 /* String descriptions of the ExecStatusTypes.
517  * direct use of this array is deprecated; call PQresStatus() instead.
518  */
519 extern char *const pgresStatus[];
520 
521 
522 #ifdef USE_SSL
523 
524 #ifndef WIN32
525 #define USER_CERT_FILE ".postgresql/postgresql.crt"
526 #define USER_KEY_FILE ".postgresql/postgresql.key"
527 #define ROOT_CERT_FILE ".postgresql/root.crt"
528 #define ROOT_CRL_FILE ".postgresql/root.crl"
529 #else
530 /* On Windows, the "home" directory is already PostgreSQL-specific */
531 #define USER_CERT_FILE "postgresql.crt"
532 #define USER_KEY_FILE "postgresql.key"
533 #define ROOT_CERT_FILE "root.crt"
534 #define ROOT_CRL_FILE "root.crl"
535 #endif
536 
537 #endif /* USE_SSL */
538 
539 /* ----------------
540  * Internal functions of libpq
541  * Functions declared here need to be visible across files of libpq,
542  * but are not intended to be called by applications. We use the
543  * convention "pqXXX" for internal functions, vs. the "PQxxx" names
544  * used for application-visible routines.
545  * ----------------
546  */
547 
548 /* === in fe-connect.c === */
549 
550 extern void pqDropConnection(PGconn *conn, bool flushInput);
551 extern int pqPacketSend(PGconn *conn, char pack_type,
552  const void *buf, size_t buf_len);
553 extern bool pqGetHomeDirectory(char *buf, int bufsize);
554 
555 #ifdef ENABLE_THREAD_SAFETY
557 
558 #define PGTHREAD_ERROR(msg) \
559  do { \
560  fprintf(stderr, "%s\n", msg); \
561  abort(); \
562  } while (0)
563 
564 
565 #define pglock_thread() pg_g_threadlock(true)
566 #define pgunlock_thread() pg_g_threadlock(false)
567 #else
568 #define pglock_thread() ((void) 0)
569 #define pgunlock_thread() ((void) 0)
570 #endif
571 
572 /* === in fe-exec.c === */
573 
574 extern void pqSetResultError(PGresult *res, const char *msg);
575 extern void pqCatenateResultError(PGresult *res, const char *msg);
576 extern void *pqResultAlloc(PGresult *res, size_t nBytes, bool isBinary);
577 extern char *pqResultStrdup(PGresult *res, const char *str);
578 extern void pqClearAsyncResult(PGconn *conn);
579 extern void pqSaveErrorResult(PGconn *conn);
581 extern void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...) pg_attribute_printf(2, 3);
582 extern void pqSaveMessageField(PGresult *res, char code,
583  const char *value);
584 extern void pqSaveParameterStatus(PGconn *conn, const char *name,
585  const char *value);
586 extern int pqRowProcessor(PGconn *conn, const char **errmsgp);
587 extern void pqHandleSendFailure(PGconn *conn);
588 
589 /* === in fe-protocol2.c === */
590 
592 
593 extern char *pqBuildStartupPacket2(PGconn *conn, int *packetlen,
595 extern void pqParseInput2(PGconn *conn);
596 extern int pqGetCopyData2(PGconn *conn, char **buffer, int async);
597 extern int pqGetline2(PGconn *conn, char *s, int maxlen);
598 extern int pqGetlineAsync2(PGconn *conn, char *buffer, int bufsize);
599 extern int pqEndcopy2(PGconn *conn);
600 extern PGresult *pqFunctionCall2(PGconn *conn, Oid fnid,
601  int *result_buf, int *actual_result_len,
602  int result_is_int,
603  const PQArgBlock *args, int nargs);
604 
605 /* === in fe-protocol3.c === */
606 
607 extern char *pqBuildStartupPacket3(PGconn *conn, int *packetlen,
608  const PQEnvironmentOption *options);
609 extern void pqParseInput3(PGconn *conn);
610 extern int pqGetErrorNotice3(PGconn *conn, bool isError);
611 extern void pqBuildErrorMessage3(PQExpBuffer msg, const PGresult *res,
612  PGVerbosity verbosity, PGContextVisibility show_context);
613 extern int pqGetCopyData3(PGconn *conn, char **buffer, int async);
614 extern int pqGetline3(PGconn *conn, char *s, int maxlen);
615 extern int pqGetlineAsync3(PGconn *conn, char *buffer, int bufsize);
616 extern int pqEndcopy3(PGconn *conn);
617 extern PGresult *pqFunctionCall3(PGconn *conn, Oid fnid,
618  int *result_buf, int *actual_result_len,
619  int result_is_int,
620  const PQArgBlock *args, int nargs);
621 
622 /* === in fe-misc.c === */
623 
624  /*
625  * "Get" and "Put" routines return 0 if successful, EOF if not. Note that for
626  * Get, EOF merely means the buffer is exhausted, not that there is
627  * necessarily any error.
628  */
629 extern int pqCheckOutBufferSpace(size_t bytes_needed, PGconn *conn);
630 extern int pqCheckInBufferSpace(size_t bytes_needed, PGconn *conn);
631 extern int pqGetc(char *result, PGconn *conn);
632 extern int pqPutc(char c, PGconn *conn);
633 extern int pqGets(PQExpBuffer buf, PGconn *conn);
634 extern int pqGets_append(PQExpBuffer buf, PGconn *conn);
635 extern int pqPuts(const char *s, PGconn *conn);
636 extern int pqGetnchar(char *s, size_t len, PGconn *conn);
637 extern int pqSkipnchar(size_t len, PGconn *conn);
638 extern int pqPutnchar(const char *s, size_t len, PGconn *conn);
639 extern int pqGetInt(int *result, size_t bytes, PGconn *conn);
640 extern int pqPutInt(int value, size_t bytes, PGconn *conn);
641 extern int pqPutMsgStart(char msg_type, bool force_len, PGconn *conn);
642 extern int pqPutMsgEnd(PGconn *conn);
643 extern int pqReadData(PGconn *conn);
644 extern int pqFlush(PGconn *conn);
645 extern int pqWait(int forRead, int forWrite, PGconn *conn);
646 extern int pqWaitTimed(int forRead, int forWrite, PGconn *conn,
647  time_t finish_time);
648 extern int pqReadReady(PGconn *conn);
649 extern int pqWriteReady(PGconn *conn);
650 
651 /* === in fe-secure.c === */
652 
653 extern int pqsecure_initialize(PGconn *);
654 extern void pqsecure_destroy(void);
656 extern void pqsecure_close(PGconn *);
657 extern ssize_t pqsecure_read(PGconn *, void *ptr, size_t len);
658 extern ssize_t pqsecure_write(PGconn *, const void *ptr, size_t len);
659 extern ssize_t pqsecure_raw_read(PGconn *, void *ptr, size_t len);
660 extern ssize_t pqsecure_raw_write(PGconn *, const void *ptr, size_t len);
661 
662 #if defined(ENABLE_THREAD_SAFETY) && !defined(WIN32)
663 extern int pq_block_sigpipe(sigset_t *osigset, bool *sigpipe_pending);
664 extern void pq_reset_sigpipe(sigset_t *osigset, bool sigpipe_pending,
665  bool got_epipe);
666 #endif
667 
668 /*
669  * The SSL implementation provides these functions (fe-secure-openssl.c)
670  */
671 extern void pgtls_init_library(bool do_ssl, int do_crypto);
672 extern int pgtls_init(PGconn *conn);
673 extern PostgresPollingStatusType pgtls_open_client(PGconn *conn);
674 extern void pgtls_close(PGconn *conn);
675 extern ssize_t pgtls_read(PGconn *conn, void *ptr, size_t len);
676 extern bool pgtls_read_pending(PGconn *conn);
677 extern ssize_t pgtls_write(PGconn *conn, const void *ptr, size_t len);
678 
679 /*
680  * this is so that we can check if a connection is non-blocking internally
681  * without the overhead of a function call
682  */
683 #define pqIsnonblocking(conn) ((conn)->nonblocking)
684 
685 #ifdef ENABLE_NLS
686 extern char *libpq_gettext(const char *msgid) pg_attribute_format_arg(1);
687 extern char *libpq_ngettext(const char *msgid, const char *msgid_plural, unsigned long n) pg_attribute_format_arg(1) pg_attribute_format_arg(2);
688 #else
689 #define libpq_gettext(x) (x)
690 #define libpq_ngettext(s, p, n) ((n) == 1 ? (s) : (p))
691 #endif
692 
693 /*
694  * These macros are needed to let error-handling code be portable between
695  * Unix and Windows. (ugh)
696  */
697 #ifdef WIN32
698 #define SOCK_ERRNO (WSAGetLastError())
699 #define SOCK_STRERROR winsock_strerror
700 #define SOCK_ERRNO_SET(e) WSASetLastError(e)
701 #else
702 #define SOCK_ERRNO errno
703 #define SOCK_STRERROR pqStrerror
704 #define SOCK_ERRNO_SET(e) (errno = (e))
705 #endif
706 
707 #endif /* LIBPQ_INT_H */
struct PGEvent PGEvent
struct pgDataValue PGdataValue
int pqPutInt(int value, size_t bytes, PGconn *conn)
Definition: fe-misc.c:312
PGContextVisibility show_context
Definition: libpq-int.h:429
bool sigpipe_flag
Definition: libpq-int.h:413
ConnStatusType
Definition: libpq-fe.h:47
int length(const List *list)
Definition: list.c:1271
static struct @76 value
void pgtls_close(PGconn *conn)
void(* PQnoticeProcessor)(void *arg, const char *message)
Definition: libpq-fe.h:172
int inEnd
Definition: libpq-int.h:437
int pqWait(int forRead, int forWrite, PGconn *conn)
Definition: fe-misc.c:989
PGMessageField * errFields
Definition: libpq-int.h:199
bool pgtls_read_pending(PGconn *conn)
int pqPacketSend(PGconn *conn, char pack_type, const void *buf, size_t buf_len)
Definition: fe-connect.c:3862
int inStart
Definition: libpq-int.h:435
ssize_t pgtls_read(PGconn *conn, void *ptr, size_t len)
char space[1]
Definition: libpq-int.h:108
int pqReadData(PGconn *conn)
Definition: fe-misc.c:634
char * pqBuildStartupPacket3(PGconn *conn, int *packetlen, const PQEnvironmentOption *options)
int be_pid
Definition: libpq-int.h:511
struct addrinfo * addr_cur
Definition: libpq-int.h:416
const char * envName
Definition: libpq-int.h:253
PGEvent * events
Definition: libpq-int.h:375
ssize_t pqsecure_write(PGconn *, const void *ptr, size_t len)
Definition: fe-secure.c:282
void pqSaveErrorResult(PGconn *conn)
Definition: fe-exec.c:728
bool singleRowMode
Definition: libpq-int.h:389
bool resultInitialized
Definition: libpq-int.h:166
int rowBufLen
Definition: libpq-int.h:451
Oid fn_lo_write
Definition: libpq-int.h:281
int eventArraySize
Definition: libpq-int.h:377
int pqGetline2(PGconn *conn, char *s, int maxlen)
char * replication
Definition: libpq-int.h:343
char * pgpassfile
Definition: libpq-int.h:346
bool sigpipe_so
Definition: libpq-int.h:412
int pqPutMsgEnd(PGconn *conn)
Definition: fe-misc.c:592
int pqRowProcessor(PGconn *conn, const char **errmsgp)
Definition: fe-exec.c:1030
bool password_needed
Definition: libpq-int.h:410
ssize_t pgtls_write(PGconn *conn, const void *ptr, size_t len)
char * pqResultStrdup(PGresult *res, const char *str)
Definition: fe-exec.c:602
PGQueryClass
Definition: libpq-int.h:227
int outCount
Definition: libpq-int.h:442
PQExpBufferData workBuffer
Definition: libpq-int.h:501
Oid fn_lo_create
Definition: libpq-int.h:272
int pqPutMsgStart(char msg_type, bool force_len, PGconn *conn)
Definition: fe-misc.c:524
PGAsyncStatusType
Definition: libpq-int.h:216
int tupArrSize
Definition: libpq-int.h:176
char * requirepeer
Definition: libpq-int.h:359
char * host
Definition: libpq-int.h:309
PGresult * pqFunctionCall2(PGconn *conn, Oid fnid, int *result_buf, int *actual_result_len, int result_is_int, const PQArgBlock *args, int nargs)
const char * value
Definition: libpq-int.h:292
PGresult_data * next
Definition: libpq-int.h:107
PGQueryClass queryclass
Definition: libpq-int.h:383
char copy_is_binary
Definition: libpq-int.h:390
PGnotify * notifyHead
Definition: libpq-int.h:393
Oid fn_lo_lseek
Definition: libpq-int.h:274
char * dbName
Definition: libpq-int.h:342
struct pgMessageField * next
Definition: libpq-int.h:146
int outMsgEnd
Definition: libpq-int.h:447
ExecStatusType
Definition: libpq-fe.h:82
int spaceLeft
Definition: libpq-int.h:212
void pqClearAsyncResult(PGconn *conn)
Definition: fe-exec.c:705
void pqsecure_close(PGconn *)
Definition: fe-secure.c:189
char * keepalives
Definition: libpq-int.h:347
void pgtls_init_library(bool do_ssl, int do_crypto)
bool pgpassfile_used
Definition: libpq-int.h:411
void(* pgthreadlock_t)(int acquire)
Definition: libpq-fe.h:374
void pqBuildErrorMessage3(PQExpBuffer msg, const PGresult *res, PGVerbosity verbosity, PGContextVisibility show_context)
Definition: fe-protocol3.c:982
int nEvents
Definition: libpq-int.h:190
unsigned int Oid
Definition: postgres_ext.h:31
PGresult * pqPrepareAsyncResult(PGconn *conn)
Definition: fe-exec.c:756
char * errMsg
Definition: libpq-int.h:198
#define CMDSTATUS_LEN
Definition: libpq-int.h:88
char * keepalives_idle
Definition: libpq-int.h:348
int pqGets_append(PQExpBuffer buf, PGconn *conn)
Definition: fe-misc.c:174
pg_conn_host_type type
Definition: libpq-int.h:310
char null_field[1]
Definition: libpq-int.h:203
PGresAttDesc * attDescs
Definition: libpq-int.h:173
FILE * Pfdebug
Definition: libpq-int.h:369
void pqParseInput3(PGconn *conn)
Definition: fe-protocol3.c:66
void * pqResultAlloc(PGresult *res, size_t nBytes, bool isBinary)
Definition: fe-exec.c:506
PGresult * result
Definition: libpq-int.h:454
#define pg_attribute_printf(f, a)
Definition: c.h:634
void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...) pg_attribute_printf(2
PGresAttValue ** tuples
Definition: libpq-int.h:174
PGresult * pqFunctionCall3(PGconn *conn, Oid fnid, int *result_buf, int *actual_result_len, int result_is_int, const PQArgBlock *args, int nargs)
char * client_encoding_initial
Definition: libpq-int.h:338
ssize_t pqsecure_read(PGconn *, void *ptr, size_t len)
Definition: fe-secure.c:205
int(* PGEventProc)(PGEventId evtId, void *evtInfo, void *passThrough)
Definition: libpq-events.h:69
int sversion
Definition: libpq-int.h:407
char * sslkey
Definition: libpq-int.h:355
void pqsecure_destroy(void)
PGresult * next_result
Definition: libpq-int.h:455
char * sslcompression
Definition: libpq-int.h:354
PGAsyncStatusType asyncStatus
Definition: libpq-int.h:381
int pqPutnchar(const char *s, size_t len, PGconn *conn)
Definition: fe-misc.c:251
char md5Salt[4]
Definition: libpq-int.h:424
int pqCheckInBufferSpace(size_t bytes_needed, PGconn *conn)
Definition: fe-misc.c:413
PGSetenvStatusType setenv_state
Definition: libpq-int.h:417
void pqSaveParameterStatus(PGconn *conn, const char *name, const char *value)
Definition: fe-exec.c:912
void(* PQnoticeReceiver)(void *arg, const PGresult *res)
Definition: libpq-fe.h:171
PGNoticeHooks noticeHooks
Definition: libpq-int.h:188
void * data
Definition: libpq-int.h:165
int pqsecure_initialize(PGconn *)
Definition: fe-secure.c:160
PGconn * conn
Definition: streamutil.c:45
Oid fn_lo_read
Definition: libpq-int.h:280
int inBufSize
Definition: libpq-int.h:434
Oid fn_lo_truncate
Definition: libpq-int.h:278
struct pgParameterStatus pgParameterStatus
PostgresPollingStatusType pgtls_open_client(PGconn *conn)
PGNoticeHooks noticeHooks
Definition: libpq-int.h:372
int curOffset
Definition: libpq-int.h:211
char * connect_timeout
Definition: libpq-int.h:337
pg_conn_host * connhost
Definition: libpq-int.h:399
void * noticeProcArg
Definition: libpq-int.h:157
char * keepalives_interval
Definition: libpq-int.h:349
#define libpq_ngettext(s, p, n)
Definition: libpq-int.h:690
char * c
PGVerbosity verbosity
Definition: libpq-int.h:428
const PQEnvironmentOption * next_eo
Definition: libpq-int.h:418
static char * buf
Definition: pg_test_fsync.c:65
Oid fn_lo_open
Definition: libpq-int.h:269
PQnoticeReceiver noticeRec
Definition: libpq-int.h:154
int pqGetInt(int *result, size_t bytes, PGconn *conn)
Definition: fe-misc.c:272
char * appname
Definition: libpq-int.h:340
PGresult_data * curBlock
Definition: libpq-int.h:210
int numParameters
Definition: libpq-int.h:177
int pgsocket
Definition: port.h:22
int pqGetlineAsync3(PGconn *conn, char *buffer, int bufsize)
char * target_session_attrs
Definition: libpq-int.h:365
char * last_query
Definition: libpq-int.h:384
Oid fn_lo_tell64
Definition: libpq-int.h:277
pgthreadlock_t pg_g_threadlock
Definition: fe-connect.c:395
PGdataValue * rowBuf
Definition: libpq-int.h:450
void pqHandleSendFailure(PGconn *conn)
Definition: fe-exec.c:1582
void void pqSaveMessageField(PGresult *res, char code, const char *value)
Definition: fe-exec.c:891
int binary
Definition: libpq-int.h:181
char * pguser
Definition: libpq-int.h:344
const char * pgName
Definition: libpq-int.h:253
#define pg_attribute_format_arg(a)
Definition: c.h:633
Oid fn_lo_truncate64
Definition: libpq-int.h:279
PGSetenvStatusType
Definition: libpq-int.h:237
int pqReadReady(PGconn *conn)
Definition: fe-misc.c:1028
pgsocket sock
Definition: libpq-int.h:402
int be_key
Definition: libpq-int.h:512
char * errQuery
Definition: libpq-int.h:200
void pqDropConnection(PGconn *conn, bool flushInput)
Definition: fe-connect.c:410
int numAttributes
Definition: libpq-int.h:172
uint32 ProtocolVersion
Definition: pqcomm.h:113
struct PQEnvironmentOption PQEnvironmentOption
struct pgresParamDesc PGresParamDesc
int pqGets(PQExpBuffer buf, PGconn *conn)
Definition: fe-misc.c:168
pg_conn_host_type
Definition: libpq-int.h:295
PostgresPollingStatusType pqSetenvPoll(PGconn *conn)
Definition: fe-protocol2.c:50
SockAddr raddr
Definition: libpq-int.h:405
ssize_t pqsecure_raw_read(PGconn *, void *ptr, size_t len)
Definition: fe-secure.c:224
pgParameterStatus * pstatus
Definition: libpq-int.h:425
PGContextVisibility
Definition: libpq-fe.h:117
char * inBuffer
Definition: libpq-int.h:433
int pqGetCopyData3(PGconn *conn, char **buffer, int async)
int pqPuts(const char *s, PGconn *conn)
Definition: fe-misc.c:184
char *const pgresStatus[]
Definition: fe-exec.c:32
char * sslmode
Definition: libpq-int.h:353
struct pgresAttValue PGresAttValue
int pqWriteReady(PGconn *conn)
Definition: fe-misc.c:1038
PGVerbosity
Definition: libpq-fe.h:110
PQnoticeProcessor noticeProc
Definition: libpq-int.h:156
int outMsgStart
Definition: libpq-int.h:445
PQExpBufferData errorMessage
Definition: libpq-int.h:498
void pqParseInput2(PGconn *conn)
Definition: fe-protocol2.c:411
bool std_strings
Definition: libpq-int.h:427
Oid fn_lo_tell
Definition: libpq-int.h:276
int pqGetnchar(char *s, size_t len, PGconn *conn)
Definition: fe-misc.c:200
char * sslcert
Definition: libpq-int.h:356
int pqWaitTimed(int forRead, int forWrite, PGconn *conn, time_t finish_time)
Definition: fe-misc.c:1004
bool options_valid
Definition: libpq-int.h:386
PGTransactionStatusType
Definition: libpq-fe.h:101
int outBufSize
Definition: libpq-int.h:441
PGresParamDesc * paramDescs
Definition: libpq-int.h:178
struct pg_conn_host pg_conn_host
int ntups
Definition: libpq-int.h:171
char * pgoptions
Definition: libpq-int.h:339
struct addrinfo * addrlist
Definition: libpq-int.h:316
int pqPutc(char c, PGconn *conn)
Definition: fe-misc.c:117
ssize_t pqsecure_raw_write(PGconn *, const void *ptr, size_t len)
Definition: fe-secure.c:301
struct pgParameterStatus * next
Definition: libpq-int.h:260
int pqCheckOutBufferSpace(size_t bytes_needed, PGconn *conn)
Definition: fe-misc.c:349
char contents[FLEXIBLE_ARRAY_MEMBER]
Definition: libpq-int.h:148
char * pgpass
Definition: libpq-int.h:345
ProtocolVersion pversion
Definition: libpq-int.h:406
char * sslrootcert
Definition: libpq-int.h:357
char cmdStatus[CMDSTATUS_LEN]
Definition: libpq-int.h:180
PGEventProc proc
Definition: libpq-int.h:162
ConnStatusType status
Definition: libpq-int.h:380
bool auth_req_received
Definition: libpq-int.h:408
int be_key
Definition: libpq-int.h:423
Oid fn_lo_creat
Definition: libpq-int.h:271
PGnotify * notifyTail
Definition: libpq-int.h:394
int copy_already_done
Definition: libpq-int.h:391
Oid fn_lo_close
Definition: libpq-int.h:270
const char * name
Definition: encode.c:521
int pqFlush(PGconn *conn)
Definition: fe-misc.c:966
char * pqBuildStartupPacket2(PGconn *conn, int *packetlen, const PQEnvironmentOption *options)
SockAddr laddr
Definition: libpq-int.h:404
char * outBuffer
Definition: libpq-int.h:440
bool nonblocking
Definition: libpq-int.h:387
PostgresPollingStatusType
Definition: libpq-fe.h:72
PostgresPollingStatusType pqsecure_open_client(PGconn *)
Definition: fe-secure.c:175
char * pghostaddr
Definition: libpq-int.h:331
Oid fn_lo_lseek64
Definition: libpq-int.h:275
struct pgLobjfuncs PGlobjfuncs
int pqGetCopyData2(PGconn *conn, char **buffer, int async)
int pqEndcopy2(PGconn *conn)
int pqGetlineAsync2(PGconn *conn, char *buffer, int bufsize)
int nEvents
Definition: libpq-int.h:376
int pqGetc(char *result, PGconn *conn)
Definition: fe-misc.c:99
void * passThrough
Definition: libpq-int.h:164
char * fbappname
Definition: libpq-int.h:341
int client_encoding
Definition: libpq-int.h:426
Oid fn_lo_unlink
Definition: libpq-int.h:273
char * value
Definition: libpq-int.h:140
void pqCatenateResultError(PGresult *res, const char *msg)
Definition: fe-exec.c:631
SockAddr raddr
Definition: libpq-int.h:510
bool pqGetHomeDirectory(char *buf, int bufsize)
Definition: fe-connect.c:6379
PGEvent * events
Definition: libpq-int.h:189
int inCursor
Definition: libpq-int.h:436
int pqSkipnchar(size_t len, PGconn *conn)
Definition: fe-misc.c:229
char * port
Definition: libpq-int.h:311
char * pgport
Definition: libpq-int.h:334
int pqEndcopy3(PGconn *conn)
int pqGetErrorNotice3(PGconn *conn, bool isError)
Definition: fe-protocol3.c:876
int be_pid
Definition: libpq-int.h:422
int nconnhost
Definition: libpq-int.h:397
char * name
Definition: libpq-int.h:163
ExecStatusType resultStatus
Definition: libpq-int.h:179
PGlobjfuncs * lobjfuncs
Definition: libpq-int.h:430
int pgtls_init(PGconn *conn)
char * sslcrl
Definition: libpq-int.h:358
void pqSetResultError(PGresult *res, const char *msg)
Definition: fe-exec.c:616
int whichhost
Definition: libpq-int.h:398
struct pgMessageField PGMessageField
#define libpq_gettext(x)
Definition: libpq-int.h:689
int pqGetline3(PGconn *conn, char *s, int maxlen)
bool send_appname
Definition: libpq-int.h:419
PGTransactionStatusType xactStatus
Definition: libpq-int.h:382
char * keepalives_count
Definition: libpq-int.h:351
char * pghost
Definition: libpq-int.h:326
char * pgtty
Definition: libpq-int.h:335
void * noticeRecArg
Definition: libpq-int.h:155
int client_encoding
Definition: libpq-int.h:191
char last_sqlstate[6]
Definition: libpq-int.h:385
char * password
Definition: libpq-int.h:313