1 | /*------------------------------------------------------------------------- |
2 | * |
3 | * libpq.h |
4 | * POSTGRES LIBPQ buffer structure definitions. |
5 | * |
6 | * |
7 | * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group |
8 | * Portions Copyright (c) 1994, Regents of the University of California |
9 | * |
10 | * src/include/libpq/libpq.h |
11 | * |
12 | *------------------------------------------------------------------------- |
13 | */ |
14 | #ifndef LIBPQ_H |
15 | #define LIBPQ_H |
16 | |
17 | #include <netinet/in.h> |
18 | |
19 | #include "lib/stringinfo.h" |
20 | #include "libpq/libpq-be.h" |
21 | #include "storage/latch.h" |
22 | |
23 | |
24 | typedef struct |
25 | { |
26 | void (*comm_reset) (void); |
27 | int (*flush) (void); |
28 | int (*flush_if_writable) (void); |
29 | bool (*is_send_pending) (void); |
30 | int (*putmessage) (char msgtype, const char *s, size_t len); |
31 | void (*putmessage_noblock) (char msgtype, const char *s, size_t len); |
32 | void (*startcopyout) (void); |
33 | void (*endcopyout) (bool errorAbort); |
34 | } PQcommMethods; |
35 | |
36 | extern const PGDLLIMPORT PQcommMethods *PqCommMethods; |
37 | |
38 | #define pq_comm_reset() (PqCommMethods->comm_reset()) |
39 | #define pq_flush() (PqCommMethods->flush()) |
40 | #define pq_flush_if_writable() (PqCommMethods->flush_if_writable()) |
41 | #define pq_is_send_pending() (PqCommMethods->is_send_pending()) |
42 | #define pq_putmessage(msgtype, s, len) \ |
43 | (PqCommMethods->putmessage(msgtype, s, len)) |
44 | #define pq_putmessage_noblock(msgtype, s, len) \ |
45 | (PqCommMethods->putmessage_noblock(msgtype, s, len)) |
46 | #define pq_startcopyout() (PqCommMethods->startcopyout()) |
47 | #define pq_endcopyout(errorAbort) (PqCommMethods->endcopyout(errorAbort)) |
48 | |
49 | /* |
50 | * External functions. |
51 | */ |
52 | |
53 | /* |
54 | * prototypes for functions in pqcomm.c |
55 | */ |
56 | extern WaitEventSet *FeBeWaitSet; |
57 | |
58 | extern int StreamServerPort(int family, char *hostName, |
59 | unsigned short portNumber, char *unixSocketDir, |
60 | pgsocket ListenSocket[], int MaxListen); |
61 | extern int StreamConnection(pgsocket server_fd, Port *port); |
62 | extern void StreamClose(pgsocket sock); |
63 | extern void TouchSocketFiles(void); |
64 | extern void RemoveSocketFiles(void); |
65 | extern void pq_init(void); |
66 | extern int pq_getbytes(char *s, size_t len); |
67 | extern int pq_getstring(StringInfo s); |
68 | extern void pq_startmsgread(void); |
69 | extern void pq_endmsgread(void); |
70 | extern bool pq_is_reading_msg(void); |
71 | extern int pq_getmessage(StringInfo s, int maxlen); |
72 | extern int pq_getbyte(void); |
73 | extern int pq_peekbyte(void); |
74 | extern int pq_getbyte_if_available(unsigned char *c); |
75 | extern int pq_putbytes(const char *s, size_t len); |
76 | |
77 | /* |
78 | * prototypes for functions in be-secure.c |
79 | */ |
80 | extern char *ssl_library; |
81 | extern char *ssl_cert_file; |
82 | extern char *ssl_key_file; |
83 | extern char *ssl_ca_file; |
84 | extern char *ssl_crl_file; |
85 | extern char *ssl_dh_params_file; |
86 | extern char *ssl_passphrase_command; |
87 | extern bool ssl_passphrase_command_supports_reload; |
88 | #ifdef USE_SSL |
89 | extern bool ssl_loaded_verify_locations; |
90 | #endif |
91 | |
92 | extern int secure_initialize(bool isServerStart); |
93 | extern bool secure_loaded_verify_locations(void); |
94 | extern void secure_destroy(void); |
95 | extern int secure_open_server(Port *port); |
96 | extern void secure_close(Port *port); |
97 | extern ssize_t secure_read(Port *port, void *ptr, size_t len); |
98 | extern ssize_t secure_write(Port *port, void *ptr, size_t len); |
99 | extern ssize_t secure_raw_read(Port *port, void *ptr, size_t len); |
100 | extern ssize_t secure_raw_write(Port *port, const void *ptr, size_t len); |
101 | |
102 | /* |
103 | * prototypes for functions in be-secure-gssapi.c |
104 | */ |
105 | #ifdef ENABLE_GSS |
106 | extern ssize_t secure_open_gssapi(Port *port); |
107 | #endif |
108 | |
109 | /* GUCs */ |
110 | extern char *SSLCipherSuites; |
111 | extern char *SSLECDHCurve; |
112 | extern bool SSLPreferServerCiphers; |
113 | extern int ssl_min_protocol_version; |
114 | extern int ssl_max_protocol_version; |
115 | |
116 | enum ssl_protocol_versions |
117 | { |
118 | PG_TLS_ANY = 0, |
119 | PG_TLS1_VERSION, |
120 | PG_TLS1_1_VERSION, |
121 | PG_TLS1_2_VERSION, |
122 | PG_TLS1_3_VERSION, |
123 | }; |
124 | |
125 | /* |
126 | * prototypes for functions in be-secure-common.c |
127 | */ |
128 | extern int run_ssl_passphrase_command(const char *prompt, bool is_server_start, |
129 | char *buf, int size); |
130 | extern bool check_ssl_key_file_permissions(const char *ssl_key_file, |
131 | bool isServerStart); |
132 | |
133 | #endif /* LIBPQ_H */ |
134 | |