PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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-2024, 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
33typedef 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#define FeBeWaitSetNEvents 3
66
67extern int ListenServerPort(int family, const char *hostName,
68 unsigned short portNumber, const char *unixSocketDir,
69 pgsocket ListenSockets[], int *NumListenSockets, int MaxListen);
70extern int AcceptConnection(pgsocket server_fd, ClientSocket *client_sock);
71extern void TouchSocketFiles(void);
72extern void RemoveSocketFiles(void);
73extern Port *pq_init(ClientSocket *client_sock);
74extern int pq_getbytes(char *s, size_t len);
75extern void pq_startmsgread(void);
76extern void pq_endmsgread(void);
77extern bool pq_is_reading_msg(void);
78extern int pq_getmessage(StringInfo s, int maxlen);
79extern int pq_getbyte(void);
80extern int pq_peekbyte(void);
81extern int pq_getbyte_if_available(unsigned char *c);
82extern ssize_t pq_buffer_remaining_data(void);
83extern int pq_putmessage_v2(char msgtype, const char *s, size_t len);
84extern bool pq_check_connection(void);
85
86/*
87 * prototypes for functions in be-secure.c
88 */
89extern int secure_initialize(bool isServerStart);
90extern bool secure_loaded_verify_locations(void);
91extern void secure_destroy(void);
92extern int secure_open_server(Port *port);
93extern void secure_close(Port *port);
94extern ssize_t secure_read(Port *port, void *ptr, size_t len);
95extern ssize_t secure_write(Port *port, void *ptr, size_t len);
96extern ssize_t secure_raw_read(Port *port, void *ptr, size_t len);
97extern ssize_t secure_raw_write(Port *port, const void *ptr, size_t len);
98
99/*
100 * declarations for variables defined in be-secure.c
101 */
102extern PGDLLIMPORT char *ssl_library;
103extern PGDLLIMPORT char *ssl_ca_file;
104extern PGDLLIMPORT char *ssl_cert_file;
105extern PGDLLIMPORT char *ssl_crl_file;
106extern PGDLLIMPORT char *ssl_crl_dir;
107extern PGDLLIMPORT char *ssl_key_file;
113extern PGDLLIMPORT char *SSLCipherSuites;
114extern PGDLLIMPORT char *SSLCipherList;
115extern PGDLLIMPORT char *SSLECDHCurve;
117#ifdef USE_SSL
118extern PGDLLIMPORT bool ssl_loaded_verify_locations;
119#endif
120
121/*
122 * prototypes for functions in be-secure-gssapi.c
123 */
124#ifdef ENABLE_GSS
125extern ssize_t secure_open_gssapi(Port *port);
126#endif
127
129{
135};
136
137/*
138 * prototypes for functions in be-secure-common.c
139 */
140extern int run_ssl_passphrase_command(const char *prompt, bool is_server_start,
141 char *buf, int size);
142extern bool check_ssl_key_file_permissions(const char *ssl_key_file,
143 bool isServerStart);
144
145#endif /* LIBPQ_H */
ssize_t secure_open_gssapi(Port *port)
#define PGDLLIMPORT
Definition: c.h:1274
Port * pq_init(ClientSocket *client_sock)
Definition: pqcomm.c:174
PGDLLIMPORT char * ssl_ca_file
Definition: be-secure.c:39
PGDLLIMPORT char * SSLCipherSuites
Definition: be-secure.c:51
void secure_destroy(void)
Definition: be-secure.c:88
bool check_ssl_key_file_permissions(const char *ssl_key_file, bool isServerStart)
PGDLLIMPORT char * ssl_dh_params_file
Definition: be-secure.c:42
PGDLLIMPORT char * SSLECDHCurve
Definition: be-secure.c:55
PGDLLIMPORT int ssl_max_protocol_version
Definition: be-secure.c:61
PGDLLIMPORT char * ssl_library
Definition: be-secure.c:36
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:268
PGDLLIMPORT WaitEventSet * FeBeWaitSet
Definition: pqcomm.c:166
int secure_initialize(bool isServerStart)
Definition: be-secure.c:75
ssl_protocol_versions
Definition: libpq.h:129
@ PG_TLS1_VERSION
Definition: libpq.h:131
@ PG_TLS1_3_VERSION
Definition: libpq.h:134
@ PG_TLS1_1_VERSION
Definition: libpq.h:132
@ PG_TLS1_2_VERSION
Definition: libpq.h:133
@ PG_TLS_ANY
Definition: libpq.h:130
PGDLLIMPORT char * ssl_key_file
Definition: be-secure.c:38
int pq_getmessage(StringInfo s, int maxlen)
Definition: pqcomm.c:1203
int pq_getbytes(char *s, size_t len)
Definition: pqcomm.c:1063
ssize_t pq_buffer_remaining_data(void)
Definition: pqcomm.c:1127
int run_ssl_passphrase_command(const char *prompt, bool is_server_start, char *buf, int size)
PGDLLIMPORT char * SSLCipherList
Definition: be-secure.c:52
int ListenServerPort(int family, const char *hostName, unsigned short portNumber, const char *unixSocketDir, pgsocket ListenSockets[], int *NumListenSockets, int MaxListen)
Definition: pqcomm.c:418
ssize_t secure_write(Port *port, void *ptr, size_t len)
Definition: be-secure.c:305
int secure_open_server(Port *port)
Definition: be-secure.c:112
void pq_endmsgread(void)
Definition: pqcomm.c:1165
bool secure_loaded_verify_locations(void)
Definition: be-secure.c:99
int AcceptConnection(pgsocket server_fd, ClientSocket *client_sock)
Definition: pqcomm.c:794
void TouchSocketFiles(void)
Definition: pqcomm.c:830
int pq_getbyte(void)
Definition: pqcomm.c:964
PGDLLIMPORT int ssl_min_protocol_version
Definition: be-secure.c:60
void secure_close(Port *port)
Definition: be-secure.c:167
ssize_t secure_read(Port *port, void *ptr, size_t len)
Definition: be-secure.c:179
PGDLLIMPORT char * ssl_crl_dir
Definition: be-secure.c:41
PGDLLIMPORT char * ssl_cert_file
Definition: be-secure.c:37
const PGDLLIMPORT PQcommMethods * PqCommMethods
Definition: pqcomm.c:164
int pq_putmessage_v2(char msgtype, const char *s, size_t len)
Definition: pqcomm.c:1559
PGDLLIMPORT char * ssl_crl_file
Definition: be-secure.c:40
PGDLLIMPORT bool ssl_passphrase_command_supports_reload
Definition: be-secure.c:44
ssize_t secure_raw_write(Port *port, const void *ptr, size_t len)
Definition: be-secure.c:377
bool pq_is_reading_msg(void)
Definition: pqcomm.c:1181
void RemoveSocketFiles(void)
Definition: pqcomm.c:848
bool pq_check_connection(void)
Definition: pqcomm.c:2054
PGDLLIMPORT bool SSLPreferServerCiphers
Definition: be-secure.c:58
void pq_startmsgread(void)
Definition: pqcomm.c:1141
PGDLLIMPORT char * ssl_passphrase_command
Definition: be-secure.c:43
const void size_t len
static int port
Definition: pg_regress.c:115
static char * buf
Definition: pg_test_fsync.c:72
int pgsocket
Definition: port.h:29
static pgsocket * ListenSockets
Definition: postmaster.c:227
static int NumListenSockets
Definition: postmaster.c:226
char * c
static pg_noinline void Size size
Definition: slab.c:607
Definition: libpq-be.h:133