PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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-2026, 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
22
23/* avoid including waiteventset.h */
25
26
27/*
28 * Callers of pq_getmessage() must supply a maximum expected message size.
29 * By convention, if there's not any specific reason to use another value,
30 * use PQ_SMALL_MESSAGE_LIMIT for messages that shouldn't be too long, and
31 * PQ_LARGE_MESSAGE_LIMIT for messages that can be long.
32 */
33#define PQ_SMALL_MESSAGE_LIMIT 10000
34#define PQ_LARGE_MESSAGE_LIMIT (MaxAllocSize - 1)
35
36typedef struct
37{
38 void (*comm_reset) (void);
39 int (*flush) (void);
40 int (*flush_if_writable) (void);
41 bool (*is_send_pending) (void);
42 int (*putmessage) (char msgtype, const char *s, size_t len);
43 void (*putmessage_noblock) (char msgtype, const char *s, size_t len);
45
47
48#define pq_comm_reset() (PqCommMethods->comm_reset())
49#define pq_flush() (PqCommMethods->flush())
50#define pq_flush_if_writable() (PqCommMethods->flush_if_writable())
51#define pq_is_send_pending() (PqCommMethods->is_send_pending())
52#define pq_putmessage(msgtype, s, len) \
53 (PqCommMethods->putmessage(msgtype, s, len))
54#define pq_putmessage_noblock(msgtype, s, len) \
55 (PqCommMethods->putmessage_noblock(msgtype, s, len))
56
57/*
58 * External functions.
59 */
60
61/*
62 * prototypes for functions in pqcomm.c
63 */
65
66#define FeBeWaitSetSocketPos 0
67#define FeBeWaitSetLatchPos 1
68#define FeBeWaitSetNEvents 3
69
70extern int ListenServerPort(int family, const char *hostName,
71 unsigned short portNumber, const char *unixSocketDir,
74extern void TouchSocketFiles(void);
75extern void RemoveSocketFiles(void);
77extern int pq_getbytes(void *b, size_t len);
78extern void pq_startmsgread(void);
79extern void pq_endmsgread(void);
80extern bool pq_is_reading_msg(void);
81extern int pq_getmessage(StringInfo s, int maxlen);
82extern int pq_getbyte(void);
83extern int pq_peekbyte(void);
84extern int pq_getbyte_if_available(unsigned char *c);
86extern int pq_putmessage_v2(char msgtype, const char *s, size_t len);
87extern bool pq_check_connection(void);
88
89/*
90 * prototypes for functions in be-secure.c
91 */
92extern int secure_initialize(bool isServerStart);
93extern bool secure_loaded_verify_locations(void);
94extern void secure_destroy(void);
95extern int secure_open_server(Port *port);
96extern void secure_close(Port *port);
97extern ssize_t secure_read(Port *port, void *ptr, size_t len);
98extern ssize_t secure_write(Port *port, const void *ptr, size_t len);
99extern ssize_t secure_raw_read(Port *port, void *ptr, size_t len);
100extern ssize_t secure_raw_write(Port *port, const void *ptr, size_t len);
101
102/*
103 * declarations for variables defined in be-secure.c
104 */
105extern PGDLLIMPORT char *ssl_library;
106extern PGDLLIMPORT char *ssl_ca_file;
107extern PGDLLIMPORT char *ssl_cert_file;
108extern PGDLLIMPORT char *ssl_crl_file;
109extern PGDLLIMPORT char *ssl_crl_dir;
110extern PGDLLIMPORT char *ssl_key_file;
116extern PGDLLIMPORT char *SSLCipherSuites;
117extern PGDLLIMPORT char *SSLCipherList;
118extern PGDLLIMPORT char *SSLECDHCurve;
120#ifdef USE_SSL
122#endif
123
124#ifdef USE_SSL
125#define SSL_LIBRARY "OpenSSL"
126#else
127#define SSL_LIBRARY ""
128#endif
129
130#ifdef USE_OPENSSL
131#define DEFAULT_SSL_CIPHERS "HIGH:MEDIUM:+3DES:!aNULL"
132#else
133#define DEFAULT_SSL_CIPHERS "none"
134#endif
135
136#ifdef USE_SSL
137#define DEFAULT_SSL_GROUPS "X25519:prime256v1"
138#else
139#define DEFAULT_SSL_GROUPS "none"
140#endif
141
142/*
143 * prototypes for functions in be-secure-gssapi.c
144 */
145#ifdef ENABLE_GSS
147#endif
148
157
158/*
159 * prototypes for functions in be-secure-common.c
160 */
161extern int run_ssl_passphrase_command(const char *prompt, bool is_server_start,
162 char *buf, int size);
163extern bool check_ssl_key_file_permissions(const char *ssl_key_file,
164 bool isServerStart);
165
166#endif /* LIBPQ_H */
ssize_t secure_open_gssapi(Port *port)
#define PGDLLIMPORT
Definition c.h:1356
int b
Definition isn.c:74
Port * pq_init(ClientSocket *client_sock)
Definition pqcomm.c:175
PGDLLIMPORT char * ssl_ca_file
Definition be-secure.c:40
PGDLLIMPORT char * SSLCipherSuites
Definition be-secure.c:52
void secure_destroy(void)
Definition be-secure.c:89
bool check_ssl_key_file_permissions(const char *ssl_key_file, bool isServerStart)
PGDLLIMPORT char * ssl_dh_params_file
Definition be-secure.c:43
PGDLLIMPORT char * SSLECDHCurve
Definition be-secure.c:56
PGDLLIMPORT int ssl_max_protocol_version
Definition be-secure.c:62
PGDLLIMPORT char * ssl_library
Definition be-secure.c:37
int pq_peekbyte(void)
Definition pqcomm.c:983
int pq_getbyte_if_available(unsigned char *c)
Definition pqcomm.c:1004
ssize_t secure_raw_read(Port *port, void *ptr, size_t len)
Definition be-secure.c:269
PGDLLIMPORT WaitEventSet * FeBeWaitSet
Definition pqcomm.c:167
int secure_initialize(bool isServerStart)
Definition be-secure.c:76
ssl_protocol_versions
Definition libpq.h:150
@ PG_TLS1_VERSION
Definition libpq.h:152
@ PG_TLS1_3_VERSION
Definition libpq.h:155
@ PG_TLS1_1_VERSION
Definition libpq.h:153
@ PG_TLS1_2_VERSION
Definition libpq.h:154
@ PG_TLS_ANY
Definition libpq.h:151
PGDLLIMPORT char * ssl_key_file
Definition be-secure.c:39
int pq_getmessage(StringInfo s, int maxlen)
Definition pqcomm.c:1204
ssize_t pq_buffer_remaining_data(void)
Definition pqcomm.c:1128
int run_ssl_passphrase_command(const char *prompt, bool is_server_start, char *buf, int size)
ssize_t secure_write(Port *port, const void *ptr, size_t len)
Definition be-secure.c:306
PGDLLIMPORT char * SSLCipherList
Definition be-secure.c:53
int pq_getbytes(void *b, size_t len)
Definition pqcomm.c:1063
int ListenServerPort(int family, const char *hostName, unsigned short portNumber, const char *unixSocketDir, pgsocket ListenSockets[], int *NumListenSockets, int MaxListen)
Definition pqcomm.c:419
int secure_open_server(Port *port)
Definition be-secure.c:113
void pq_endmsgread(void)
Definition pqcomm.c:1166
bool secure_loaded_verify_locations(void)
Definition be-secure.c:100
int AcceptConnection(pgsocket server_fd, ClientSocket *client_sock)
Definition pqcomm.c:795
void TouchSocketFiles(void)
Definition pqcomm.c:831
int pq_getbyte(void)
Definition pqcomm.c:964
PGDLLIMPORT int ssl_min_protocol_version
Definition be-secure.c:61
void secure_close(Port *port)
Definition be-secure.c:168
ssize_t secure_read(Port *port, void *ptr, size_t len)
Definition be-secure.c:180
PGDLLIMPORT char * ssl_crl_dir
Definition be-secure.c:42
PGDLLIMPORT char * ssl_cert_file
Definition be-secure.c:38
const PGDLLIMPORT PQcommMethods * PqCommMethods
Definition pqcomm.c:165
int pq_putmessage_v2(char msgtype, const char *s, size_t len)
Definition pqcomm.c:1562
PGDLLIMPORT char * ssl_crl_file
Definition be-secure.c:41
PGDLLIMPORT bool ssl_passphrase_command_supports_reload
Definition be-secure.c:45
ssize_t secure_raw_write(Port *port, const void *ptr, size_t len)
Definition be-secure.c:378
bool pq_is_reading_msg(void)
Definition pqcomm.c:1182
void RemoveSocketFiles(void)
Definition pqcomm.c:849
bool pq_check_connection(void)
Definition pqcomm.c:2057
PGDLLIMPORT bool SSLPreferServerCiphers
Definition be-secure.c:59
void pq_startmsgread(void)
Definition pqcomm.c:1142
PGDLLIMPORT char * ssl_passphrase_command
Definition be-secure.c:44
const void size_t len
static int port
Definition pg_regress.c:115
static char buf[DEFAULT_XLOG_SEG_SIZE]
int pgsocket
Definition port.h:29
static pgsocket * ListenSockets
Definition postmaster.c:235
static int NumListenSockets
Definition postmaster.c:234
char * c
static int fb(int x)