PostgreSQL Source Code  git master
libpq.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * libpq.h
4  * POSTGRES LIBPQ buffer structure definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2021, 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 /*
25  * Callers of pq_getmessage() must supply a maximum expected message size.
26  * By convention, if there's not any specific reason to use another value,
27  * use PQ_SMALL_MESSAGE_LIMIT for messages that shouldn't be too long, and
28  * PQ_LARGE_MESSAGE_LIMIT for messages that can be long.
29  */
30 #define PQ_SMALL_MESSAGE_LIMIT 10000
31 #define PQ_LARGE_MESSAGE_LIMIT (MaxAllocSize - 1)
32 
33 typedef struct
34 {
35  void (*comm_reset) (void);
36  int (*flush) (void);
37  int (*flush_if_writable) (void);
38  bool (*is_send_pending) (void);
39  int (*putmessage) (char msgtype, const char *s, size_t len);
40  void (*putmessage_noblock) (char msgtype, const char *s, size_t len);
42 
44 
45 #define pq_comm_reset() (PqCommMethods->comm_reset())
46 #define pq_flush() (PqCommMethods->flush())
47 #define pq_flush_if_writable() (PqCommMethods->flush_if_writable())
48 #define pq_is_send_pending() (PqCommMethods->is_send_pending())
49 #define pq_putmessage(msgtype, s, len) \
50  (PqCommMethods->putmessage(msgtype, s, len))
51 #define pq_putmessage_noblock(msgtype, s, len) \
52  (PqCommMethods->putmessage_noblock(msgtype, s, len))
53 
54 /*
55  * External functions.
56  */
57 
58 /*
59  * prototypes for functions in pqcomm.c
60  */
62 
63 #define FeBeWaitSetSocketPos 0
64 #define FeBeWaitSetLatchPos 1
65 
66 extern int StreamServerPort(int family, const char *hostName,
67  unsigned short portNumber, const char *unixSocketDir,
68  pgsocket ListenSocket[], int MaxListen);
69 extern int StreamConnection(pgsocket server_fd, Port *port);
70 extern void StreamClose(pgsocket sock);
71 extern void TouchSocketFiles(void);
72 extern void RemoveSocketFiles(void);
73 extern void pq_init(void);
74 extern int pq_getbytes(char *s, size_t len);
75 extern void pq_startmsgread(void);
76 extern void pq_endmsgread(void);
77 extern bool pq_is_reading_msg(void);
78 extern int pq_getmessage(StringInfo s, int maxlen);
79 extern int pq_getbyte(void);
80 extern int pq_peekbyte(void);
81 extern int pq_getbyte_if_available(unsigned char *c);
82 extern int pq_putmessage_v2(char msgtype, const char *s, size_t len);
83 extern bool pq_check_connection(void);
84 
85 /*
86  * prototypes for functions in be-secure.c
87  */
88 extern char *ssl_library;
89 extern char *ssl_cert_file;
90 extern char *ssl_key_file;
91 extern char *ssl_ca_file;
92 extern char *ssl_crl_file;
93 extern char *ssl_crl_dir;
94 extern char *ssl_dh_params_file;
97 #ifdef USE_SSL
98 extern bool ssl_loaded_verify_locations;
99 #endif
100 
101 extern int secure_initialize(bool isServerStart);
102 extern bool secure_loaded_verify_locations(void);
103 extern void secure_destroy(void);
104 extern int secure_open_server(Port *port);
105 extern void secure_close(Port *port);
106 extern ssize_t secure_read(Port *port, void *ptr, size_t len);
107 extern ssize_t secure_write(Port *port, void *ptr, size_t len);
108 extern ssize_t secure_raw_read(Port *port, void *ptr, size_t len);
109 extern ssize_t secure_raw_write(Port *port, const void *ptr, size_t len);
110 
111 /*
112  * prototypes for functions in be-secure-gssapi.c
113  */
114 #ifdef ENABLE_GSS
115 extern ssize_t secure_open_gssapi(Port *port);
116 #endif
117 
118 /* GUCs */
119 extern char *SSLCipherSuites;
120 extern char *SSLECDHCurve;
121 extern bool SSLPreferServerCiphers;
122 extern int ssl_min_protocol_version;
123 extern int ssl_max_protocol_version;
124 
126 {
132 };
133 
134 /*
135  * prototypes for functions in be-secure-common.c
136  */
137 extern int run_ssl_passphrase_command(const char *prompt, bool is_server_start,
138  char *buf, int size);
139 extern bool check_ssl_key_file_permissions(const char *ssl_key_file,
140  bool isServerStart);
141 
142 #endif /* LIBPQ_H */
char * SSLCipherSuites
Definition: be-secure.c:55
ssl_protocol_versions
Definition: libpq.h:125
void StreamClose(pgsocket sock)
Definition: pqcomm.c:850
ssize_t secure_raw_write(Port *port, const void *ptr, size_t len)
Definition: be-secure.c:332
char * ssl_ca_file
Definition: be-secure.c:43
WaitEventSet * FeBeWaitSet
Definition: pqcomm.c:168
char * ssl_library
Definition: be-secure.c:40
bool pq_is_reading_msg(void)
Definition: pqcomm.c:1192
bool pq_check_connection(void)
Definition: pqcomm.c:1933
Definition: libpq-be.h:125
int StreamServerPort(int family, const char *hostName, unsigned short portNumber, const char *unixSocketDir, pgsocket ListenSocket[], int MaxListen)
Definition: pqcomm.c:318
void pq_endmsgread(void)
Definition: pqcomm.c:1176
int secure_initialize(bool isServerStart)
Definition: be-secure.c:78
char * ssl_cert_file
Definition: be-secure.c:41
PGDLLIMPORT char * ssl_passphrase_command
Definition: be-secure.c:47
ssize_t secure_read(Port *port, void *ptr, size_t len)
Definition: be-secure.c:147
void pq_startmsgread(void)
Definition: pqcomm.c:1152
#define PGDLLIMPORT
Definition: c.h:1317
PGDLLIMPORT bool ssl_passphrase_command_supports_reload
Definition: be-secure.c:48
int pq_putmessage_v2(char msgtype, const char *s, size_t len)
Definition: pqcomm.c:1540
bool SSLPreferServerCiphers
Definition: be-secure.c:61
char * c
static char * buf
Definition: pg_test_fsync.c:68
bool secure_loaded_verify_locations(void)
Definition: be-secure.c:102
int pgsocket
Definition: port.h:31
int StreamConnection(pgsocket server_fd, Port *port)
Definition: pqcomm.c:716
static int port
Definition: pg_regress.c:92
int pq_getbyte_if_available(unsigned char *c)
Definition: pqcomm.c:1034
int run_ssl_passphrase_command(const char *prompt, bool is_server_start, char *buf, int size)
static pgsocket ListenSocket[MAXLISTEN]
Definition: postmaster.c:221
int pq_peekbyte(void)
Definition: pqcomm.c:1013
char * ssl_crl_dir
Definition: be-secure.c:45
ssize_t secure_open_gssapi(Port *port)
void secure_close(Port *port)
Definition: be-secure.c:135
char * ssl_dh_params_file
Definition: be-secure.c:46
char * ssl_key_file
Definition: be-secure.c:42
void RemoveSocketFiles(void)
Definition: pqcomm.c:883
const PGDLLIMPORT PQcommMethods * PqCommMethods
Definition: pqcomm.c:166
bool check_ssl_key_file_permissions(const char *ssl_key_file, bool isServerStart)
ssize_t secure_write(Port *port, void *ptr, size_t len)
Definition: be-secure.c:260
void TouchSocketFiles(void)
Definition: pqcomm.c:865
int ssl_min_protocol_version
Definition: be-secure.c:63
void pq_init(void)
Definition: pqcomm.c:176
void secure_destroy(void)
Definition: be-secure.c:91
ssize_t secure_raw_read(Port *port, void *ptr, size_t len)
Definition: be-secure.c:236
int ssl_max_protocol_version
Definition: be-secure.c:64
int pq_getbyte(void)
Definition: pqcomm.c:994
int pq_getbytes(char *s, size_t len)
Definition: pqcomm.c:1088
char * ssl_crl_file
Definition: be-secure.c:44
int pq_getmessage(StringInfo s, int maxlen)
Definition: pqcomm.c:1214
char * SSLECDHCurve
Definition: be-secure.c:58
unsigned char bool
Definition: c.h:391
int secure_open_server(Port *port)
Definition: be-secure.c:115