PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/src/interfaces/libpq/libpq-int.h

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