OSDN Git Service

Set psql client encoding from locale by default
[pg-rex/syncrep.git] / src / interfaces / libpq / libpq-int.h
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-2011, 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_SSL
77 #include <openssl/ssl.h>
78 #include <openssl/err.h>
79
80 #if (SSLEAY_VERSION_NUMBER >= 0x00907000L) && !defined(OPENSSL_NO_ENGINE)
81 #define USE_SSL_ENGINE
82 #endif
83 #endif   /* USE_SSL */
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  */
103 typedef union pgresult_data PGresult_data;
104
105 union pgresult_data
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 */
115 } PGresParamDesc;
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[1];    /* field value (VARIABLE LENGTH) */
149 } PGMessageField;
150
151 /* Fields needed for notice handling */
152 typedef struct
153 {
154         PQnoticeReceiver noticeRec; /* notice message receiver */
155         void       *noticeRecArg;
156         PQnoticeProcessor noticeProc;           /* notice message processor */
157         void       *noticeProcArg;
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;
172         int                     numAttributes;
173         PGresAttDesc *attDescs;
174         PGresAttValue **tuples;         /* each PGresTuple is an array of
175                                                                  * PGresAttValue's */
176         int                     tupArrSize;             /* allocated size of tuples array */
177         int                     numParameters;
178         PGresParamDesc *paramDescs;
179         ExecStatusType resultStatus;
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          */
188         PGNoticeHooks noticeHooks;
189         PGEvent    *events;
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
201         /* All NULL attributes in the query result point to this null string */
202         char            null_field[1];
203
204         /*
205          * Space management information.  Note that attDescs and error stuff, if
206          * not null, point into allocated blocks.  But tuples points to a
207          * separately malloc'd block, so that we can realloc it.
208          */
209         PGresult_data *curBlock;        /* most recently allocated block */
210         int                     curOffset;              /* start offset of free space in block */
211         int                     spaceLeft;              /* number of free bytes remaining in block */
212 };
213
214 /* PGAsyncStatusType defines the state of the query-execution state machine */
215 typedef enum
216 {
217         PGASYNC_IDLE,                           /* nothing's happening, dude */
218         PGASYNC_BUSY,                           /* query in progress */
219         PGASYNC_READY,                          /* result ready for PQgetResult */
220         PGASYNC_COPY_IN,                        /* Copy In data transfer in progress */
221         PGASYNC_COPY_OUT,                       /* Copy Out data transfer in progress */
222         PGASYNC_COPY_BOTH                       /* Copy In/Out data transfer in progress */
223 } PGAsyncStatusType;
224
225 /* PGQueryClass tracks which query protocol we are now executing */
226 typedef enum
227 {
228         PGQUERY_SIMPLE,                         /* simple Query protocol (PQexec) */
229         PGQUERY_EXTENDED,                       /* full Extended protocol (PQexecParams) */
230         PGQUERY_PREPARE,                        /* Parse only (PQprepare) */
231         PGQUERY_DESCRIBE                        /* Describe Statement or Portal */
232 } PGQueryClass;
233
234 /* PGSetenvStatusType defines the state of the PQSetenv state machine */
235 /* (this is used only for 2.0-protocol connections) */
236 typedef enum
237 {
238         SETENV_STATE_CLIENT_ENCODING_SEND,      /* About to send an Environment Option */
239         SETENV_STATE_CLIENT_ENCODING_WAIT,      /* Waiting for above send to complete */
240         SETENV_STATE_OPTION_SEND,       /* About to send an Environment Option */
241         SETENV_STATE_OPTION_WAIT,       /* Waiting for above send to complete */
242         SETENV_STATE_QUERY1_SEND,       /* About to send a status query */
243         SETENV_STATE_QUERY1_WAIT,       /* Waiting for query to complete */
244         SETENV_STATE_QUERY2_SEND,       /* About to send a status query */
245         SETENV_STATE_QUERY2_WAIT,       /* Waiting for query to complete */
246         SETENV_STATE_IDLE
247 } PGSetenvStatusType;
248
249 /* Typedef for the EnvironmentOptions[] array */
250 typedef struct PQEnvironmentOption
251 {
252         const char *envName,            /* name of an environment variable */
253                            *pgName;                     /* name of corresponding SET variable */
254 } PQEnvironmentOption;
255
256 /* Typedef for parameter-status list entries */
257 typedef struct pgParameterStatus
258 {
259         struct pgParameterStatus *next;         /* list link */
260         char       *name;                       /* parameter name */
261         char       *value;                      /* parameter value */
262         /* Note: name and value are stored in same malloc block as struct is */
263 } pgParameterStatus;
264
265 /* large-object-access data ... allocated only if large-object code is used. */
266 typedef struct pgLobjfuncs
267 {
268         Oid                     fn_lo_open;             /* OID of backend function lo_open              */
269         Oid                     fn_lo_close;    /* OID of backend function lo_close             */
270         Oid                     fn_lo_creat;    /* OID of backend function lo_creat             */
271         Oid                     fn_lo_create;   /* OID of backend function lo_create    */
272         Oid                     fn_lo_unlink;   /* OID of backend function lo_unlink    */
273         Oid                     fn_lo_lseek;    /* OID of backend function lo_lseek             */
274         Oid                     fn_lo_tell;             /* OID of backend function lo_tell              */
275         Oid                     fn_lo_truncate; /* OID of backend function lo_truncate  */
276         Oid                     fn_lo_read;             /* OID of backend function LOread               */
277         Oid                     fn_lo_write;    /* OID of backend function LOwrite              */
278 } PGlobjfuncs;
279
280 /*
281  * PGconn stores all the state data associated with a single connection
282  * to a backend.
283  */
284 struct pg_conn
285 {
286         /* Saved values of connection options */
287         char       *pghost;                     /* the machine on which the server is running */
288         char       *pghostaddr;         /* the numeric IP address of the machine on
289                                                                  * which the server is running.  Takes
290                                                                  * precedence over above. */
291         char       *pgport;                     /* the server's communication port */
292         char       *pgunixsocket;       /* the Unix-domain socket that the server is
293                                                                  * listening on; if NULL, uses a default
294                                                                  * constructed from pgport */
295         char       *pgtty;                      /* tty on which the backend messages is
296                                                                  * displayed (OBSOLETE, NOT USED) */
297         char       *connect_timeout;    /* connection timeout (numeric string) */
298         char       *client_encoding_initial; /* encoding to use */
299         char       *pgoptions;          /* options to start the backend with */
300         char       *appname;            /* application name */
301         char       *fbappname;          /* fallback application name */
302         char       *dbName;                     /* database name */
303         char       *replication;        /* connect as the replication standby? */
304         char       *pguser;                     /* Postgres username and password, if any */
305         char       *pgpass;
306         char       *keepalives;         /* use TCP keepalives? */
307         char       *keepalives_idle;    /* time between TCP keepalives */
308         char       *keepalives_interval;        /* time between TCP keepalive
309                                                                                  * retransmits */
310         char       *keepalives_count;           /* maximum number of TCP keepalive
311                                                                                  * retransmits */
312         char       *sslmode;            /* SSL mode (require,prefer,allow,disable) */
313         char       *sslkey;                     /* client key filename */
314         char       *sslcert;            /* client certificate filename */
315         char       *sslrootcert;        /* root certificate filename */
316         char       *sslcrl;                     /* certificate revocation list filename */
317         char       *requirepeer;        /* required peer credentials for local sockets */
318
319 #if defined(KRB5) || defined(ENABLE_GSS) || defined(ENABLE_SSPI)
320         char       *krbsrvname;         /* Kerberos service name */
321 #endif
322
323         /* Optional file to write trace info to */
324         FILE       *Pfdebug;
325
326         /* Callback procedures for notice message processing */
327         PGNoticeHooks noticeHooks;
328
329         /* Event procs registered via PQregisterEventProc */
330         PGEvent    *events;                     /* expandable array of event data */
331         int                     nEvents;                /* number of active events */
332         int                     eventArraySize; /* allocated array size */
333
334         /* Status indicators */
335         ConnStatusType status;
336         PGAsyncStatusType asyncStatus;
337         PGTransactionStatusType xactStatus; /* never changes to ACTIVE */
338         PGQueryClass queryclass;
339         char       *last_query;         /* last SQL command, or NULL if unknown */
340         char            last_sqlstate[6];       /* last reported SQLSTATE */
341         bool            options_valid;  /* true if OK to attempt connection */
342         bool            nonblocking;    /* whether this connection is using nonblock
343                                                                  * sending semantics */
344         char            copy_is_binary; /* 1 = copy binary, 0 = copy text */
345         int                     copy_already_done;              /* # bytes already returned in COPY
346                                                                                  * OUT */
347         PGnotify   *notifyHead;         /* oldest unreported Notify msg */
348         PGnotify   *notifyTail;         /* newest unreported Notify msg */
349
350         /* Connection data */
351         int                     sock;                   /* Unix FD for socket, -1 if not connected */
352         SockAddr        laddr;                  /* Local address */
353         SockAddr        raddr;                  /* Remote address */
354         ProtocolVersion pversion;       /* FE/BE protocol version in use */
355         int                     sversion;               /* server version, e.g. 70401 for 7.4.1 */
356         bool            auth_req_received;      /* true if any type of auth req received */
357         bool            password_needed;        /* true if server demanded a password */
358         bool            dot_pgpass_used;        /* true if used .pgpass */
359         bool            sigpipe_so;             /* have we masked SIGPIPE via SO_NOSIGPIPE? */
360         bool            sigpipe_flag;   /* can we mask SIGPIPE via MSG_NOSIGNAL? */
361
362         /* Transient state needed while establishing connection */
363         struct addrinfo *addrlist;      /* list of possible backend addresses */
364         struct addrinfo *addr_cur;      /* the one currently being tried */
365         int                     addrlist_family;        /* needed to know how to free addrlist */
366         PGSetenvStatusType setenv_state;        /* for 2.0 protocol only */
367         const PQEnvironmentOption *next_eo;
368         bool            send_appname;   /* okay to send application_name? */
369
370         /* Miscellaneous stuff */
371         int                     be_pid;                 /* PID of backend --- needed for cancels */
372         int                     be_key;                 /* key of backend --- needed for cancels */
373         char            md5Salt[4];             /* password salt received from backend */
374         pgParameterStatus *pstatus; /* ParameterStatus data */
375         int                     client_encoding;        /* encoding id */
376         bool            std_strings;    /* standard_conforming_strings */
377         PGVerbosity verbosity;          /* error/notice message verbosity */
378         PGlobjfuncs *lobjfuncs;         /* private state for large-object access fns */
379
380         /* Buffer for data received from backend and not yet processed */
381         char       *inBuffer;           /* currently allocated buffer */
382         int                     inBufSize;              /* allocated size of buffer */
383         int                     inStart;                /* offset to first unconsumed data in buffer */
384         int                     inCursor;               /* next byte to tentatively consume */
385         int                     inEnd;                  /* offset to first position after avail data */
386
387         /* Buffer for data not yet sent to backend */
388         char       *outBuffer;          /* currently allocated buffer */
389         int                     outBufSize;             /* allocated size of buffer */
390         int                     outCount;               /* number of chars waiting in buffer */
391
392         /* State for constructing messages in outBuffer */
393         int                     outMsgStart;    /* offset to msg start (length word); if -1,
394                                                                  * msg has no length word */
395         int                     outMsgEnd;              /* offset to msg end (so far) */
396
397         /* Status for asynchronous result construction */
398         PGresult   *result;                     /* result being constructed */
399         PGresAttValue *curTuple;        /* tuple currently being read */
400
401 #ifdef USE_SSL
402         bool            allow_ssl_try;  /* Allowed to try SSL negotiation */
403         bool            wait_ssl_try;   /* Delay SSL negotiation until after
404                                                                  * attempting normal connection */
405         SSL                *ssl;                        /* SSL status, if have SSL connection */
406         X509       *peer;                       /* X509 cert of server */
407         char            peer_dn[256 + 1];               /* peer distinguished name */
408         char            peer_cn[SM_USER + 1];   /* peer common name */
409 #ifdef USE_SSL_ENGINE
410         ENGINE     *engine;                     /* SSL engine, if any */
411 #else
412         void       *engine;                     /* dummy field to keep struct the same if
413                                                                  * OpenSSL version changes */
414 #endif
415 #endif   /* USE_SSL */
416
417 #ifdef ENABLE_GSS
418         gss_ctx_id_t gctx;                      /* GSS context */
419         gss_name_t      gtarg_nam;              /* GSS target name */
420         gss_buffer_desc ginbuf;         /* GSS input token */
421         gss_buffer_desc goutbuf;        /* GSS output token */
422 #endif
423
424 #ifdef ENABLE_SSPI
425 #ifndef ENABLE_GSS
426         gss_buffer_desc ginbuf;         /* GSS input token */
427 #else
428         char       *gsslib;                     /* What GSS librart to use ("gssapi" or
429                                                                  * "sspi") */
430 #endif
431         CredHandle *sspicred;           /* SSPI credentials handle */
432         CtxtHandle *sspictx;            /* SSPI context */
433         char       *sspitarget;         /* SSPI target name */
434         int                     usesspi;                /* Indicate if SSPI is in use on the
435                                                                  * connection */
436 #endif
437
438
439         /* Buffer for current error message */
440         PQExpBufferData errorMessage;           /* expansible string */
441
442         /* Buffer for receiving various parts of messages */
443         PQExpBufferData workBuffer; /* expansible string */
444 };
445
446 /* PGcancel stores all data necessary to cancel a connection. A copy of this
447  * data is required to safely cancel a connection running on a different
448  * thread.
449  */
450 struct pg_cancel
451 {
452         SockAddr        raddr;                  /* Remote address */
453         int                     be_pid;                 /* PID of backend --- needed for cancels */
454         int                     be_key;                 /* key of backend --- needed for cancels */
455 };
456
457
458 /* String descriptions of the ExecStatusTypes.
459  * direct use of this array is deprecated; call PQresStatus() instead.
460  */
461 extern char *const pgresStatus[];
462
463 /* ----------------
464  * Internal functions of libpq
465  * Functions declared here need to be visible across files of libpq,
466  * but are not intended to be called by applications.  We use the
467  * convention "pqXXX" for internal functions, vs. the "PQxxx" names
468  * used for application-visible routines.
469  * ----------------
470  */
471
472 /* === in fe-connect.c === */
473
474 extern int pqPacketSend(PGconn *conn, char pack_type,
475                          const void *buf, size_t buf_len);
476 extern bool pqGetHomeDirectory(char *buf, int bufsize);
477
478 #ifdef ENABLE_THREAD_SAFETY
479 extern pgthreadlock_t pg_g_threadlock;
480
481 #define PGTHREAD_ERROR(msg) \
482         do { \
483                 fprintf(stderr, "%s\n", msg); \
484                 exit(1); \
485         } while (0)
486
487
488 #define pglock_thread()         pg_g_threadlock(true)
489 #define pgunlock_thread()       pg_g_threadlock(false)
490 #else
491 #define pglock_thread()         ((void) 0)
492 #define pgunlock_thread()       ((void) 0)
493 #endif
494
495 /* === in fe-exec.c === */
496
497 extern void pqSetResultError(PGresult *res, const char *msg);
498 extern void pqCatenateResultError(PGresult *res, const char *msg);
499 extern void *pqResultAlloc(PGresult *res, size_t nBytes, bool isBinary);
500 extern char *pqResultStrdup(PGresult *res, const char *str);
501 extern void pqClearAsyncResult(PGconn *conn);
502 extern void pqSaveErrorResult(PGconn *conn);
503 extern PGresult *pqPrepareAsyncResult(PGconn *conn);
504 extern void
505 pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...)
506 /* This lets gcc check the format string for consistency. */
507 __attribute__((format(printf, 2, 3)));
508 extern int      pqAddTuple(PGresult *res, PGresAttValue *tup);
509 extern void pqSaveMessageField(PGresult *res, char code,
510                                    const char *value);
511 extern void pqSaveParameterStatus(PGconn *conn, const char *name,
512                                           const char *value);
513 extern void pqHandleSendFailure(PGconn *conn);
514
515 /* === in fe-protocol2.c === */
516
517 extern PostgresPollingStatusType pqSetenvPoll(PGconn *conn);
518
519 extern char *pqBuildStartupPacket2(PGconn *conn, int *packetlen,
520                                           const PQEnvironmentOption *options);
521 extern void pqParseInput2(PGconn *conn);
522 extern int      pqGetCopyData2(PGconn *conn, char **buffer, int async);
523 extern int      pqGetline2(PGconn *conn, char *s, int maxlen);
524 extern int      pqGetlineAsync2(PGconn *conn, char *buffer, int bufsize);
525 extern int      pqEndcopy2(PGconn *conn);
526 extern PGresult *pqFunctionCall2(PGconn *conn, Oid fnid,
527                                 int *result_buf, int *actual_result_len,
528                                 int result_is_int,
529                                 const PQArgBlock *args, int nargs);
530
531 /* === in fe-protocol3.c === */
532
533 extern char *pqBuildStartupPacket3(PGconn *conn, int *packetlen,
534                                           const PQEnvironmentOption *options);
535 extern void pqParseInput3(PGconn *conn);
536 extern int      pqGetErrorNotice3(PGconn *conn, bool isError);
537 extern int      pqGetCopyData3(PGconn *conn, char **buffer, int async);
538 extern int      pqGetline3(PGconn *conn, char *s, int maxlen);
539 extern int      pqGetlineAsync3(PGconn *conn, char *buffer, int bufsize);
540 extern int      pqEndcopy3(PGconn *conn);
541 extern PGresult *pqFunctionCall3(PGconn *conn, Oid fnid,
542                                 int *result_buf, int *actual_result_len,
543                                 int result_is_int,
544                                 const PQArgBlock *args, int nargs);
545
546 /* === in fe-misc.c === */
547
548  /*
549   * "Get" and "Put" routines return 0 if successful, EOF if not. Note that for
550   * Get, EOF merely means the buffer is exhausted, not that there is
551   * necessarily any error.
552   */
553 extern int      pqCheckOutBufferSpace(size_t bytes_needed, PGconn *conn);
554 extern int      pqCheckInBufferSpace(size_t bytes_needed, PGconn *conn);
555 extern int      pqGetc(char *result, PGconn *conn);
556 extern int      pqPutc(char c, PGconn *conn);
557 extern int      pqGets(PQExpBuffer buf, PGconn *conn);
558 extern int      pqGets_append(PQExpBuffer buf, PGconn *conn);
559 extern int      pqPuts(const char *s, PGconn *conn);
560 extern int      pqGetnchar(char *s, size_t len, PGconn *conn);
561 extern int      pqPutnchar(const char *s, size_t len, PGconn *conn);
562 extern int      pqGetInt(int *result, size_t bytes, PGconn *conn);
563 extern int      pqPutInt(int value, size_t bytes, PGconn *conn);
564 extern int      pqPutMsgStart(char msg_type, bool force_len, PGconn *conn);
565 extern int      pqPutMsgEnd(PGconn *conn);
566 extern int      pqReadData(PGconn *conn);
567 extern int      pqFlush(PGconn *conn);
568 extern int      pqWait(int forRead, int forWrite, PGconn *conn);
569 extern int pqWaitTimed(int forRead, int forWrite, PGconn *conn,
570                         time_t finish_time);
571 extern int      pqReadReady(PGconn *conn);
572 extern int      pqWriteReady(PGconn *conn);
573
574 /* === in fe-secure.c === */
575
576 extern int      pqsecure_initialize(PGconn *);
577 extern void pqsecure_destroy(void);
578 extern PostgresPollingStatusType pqsecure_open_client(PGconn *);
579 extern void pqsecure_close(PGconn *);
580 extern ssize_t pqsecure_read(PGconn *, void *ptr, size_t len);
581 extern ssize_t pqsecure_write(PGconn *, const void *ptr, size_t len);
582
583 #if defined(ENABLE_THREAD_SAFETY) && !defined(WIN32)
584 extern int      pq_block_sigpipe(sigset_t *osigset, bool *sigpipe_pending);
585 extern void pq_reset_sigpipe(sigset_t *osigset, bool sigpipe_pending,
586                                  bool got_epipe);
587 #endif
588
589 /*
590  * this is so that we can check if a connection is non-blocking internally
591  * without the overhead of a function call
592  */
593 #define pqIsnonblocking(conn)   ((conn)->nonblocking)
594
595 #ifdef ENABLE_NLS
596 extern char *
597 libpq_gettext(const char *msgid)
598 __attribute__((format_arg(1)));
599 #else
600 #define libpq_gettext(x) (x)
601 #endif
602
603 /*
604  * These macros are needed to let error-handling code be portable between
605  * Unix and Windows.  (ugh)
606  */
607 #ifdef WIN32
608 #define SOCK_ERRNO (WSAGetLastError())
609 #define SOCK_STRERROR winsock_strerror
610 #define SOCK_ERRNO_SET(e) WSASetLastError(e)
611 #else
612 #define SOCK_ERRNO errno
613 #define SOCK_STRERROR pqStrerror
614 #define SOCK_ERRNO_SET(e) (errno = (e))
615 #endif
616
617 #endif   /* LIBPQ_INT_H */