PostgreSQL Source Code git master
oauth-utils.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * oauth-utils.h
4 *
5 * Definitions providing missing libpq internal APIs
6 *
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * src/interfaces/libpq-oauth/oauth-utils.h
11 *
12 *-------------------------------------------------------------------------
13 */
14
15#ifndef OAUTH_UTILS_H
16#define OAUTH_UTILS_H
17
18#include "fe-auth-oauth.h"
19#include "libpq-fe.h"
20#include "pqexpbuffer.h"
21
22/*
23 * A bank of callbacks to safely access members of PGconn, which are all passed
24 * to libpq_oauth_init() by libpq.
25 *
26 * Keep these aligned with the definitions in fe-auth-oauth.c as well as the
27 * static declarations in oauth-curl.c.
28 */
29#define DECLARE_GETTER(TYPE, MEMBER) \
30 typedef TYPE (*conn_ ## MEMBER ## _func) (PGconn *conn); \
31 extern conn_ ## MEMBER ## _func conn_ ## MEMBER;
32
33#define DECLARE_SETTER(TYPE, MEMBER) \
34 typedef void (*set_conn_ ## MEMBER ## _func) (PGconn *conn, TYPE val); \
35 extern set_conn_ ## MEMBER ## _func set_conn_ ## MEMBER;
36
38DECLARE_GETTER(char *, oauth_client_id);
39DECLARE_GETTER(char *, oauth_client_secret);
40DECLARE_GETTER(char *, oauth_discovery_uri);
41DECLARE_GETTER(char *, oauth_issuer_id);
42DECLARE_GETTER(char *, oauth_scope);
44
46DECLARE_SETTER(char *, oauth_token);
47
48#undef DECLARE_GETTER
49#undef DECLARE_SETTER
50
51typedef char *(*libpq_gettext_func) (const char *msgid);
52
53/* Initializes libpq-oauth. */
54extern PGDLLEXPORT void libpq_oauth_init(pgthreadlock_t threadlock,
55 libpq_gettext_func gettext_impl,
56 conn_errorMessage_func errmsg_impl,
57 conn_oauth_client_id_func clientid_impl,
58 conn_oauth_client_secret_func clientsecret_impl,
59 conn_oauth_discovery_uri_func discoveryuri_impl,
60 conn_oauth_issuer_id_func issuerid_impl,
61 conn_oauth_scope_func scope_impl,
62 conn_sasl_state_func saslstate_impl,
63 set_conn_altsock_func setaltsock_impl,
64 set_conn_oauth_token_func settoken_impl);
65
66/*
67 * Duplicated APIs, copied from libpq (primarily libpq-int.h, which we cannot
68 * depend on here).
69 */
70
71typedef enum
72{
73 PG_BOOL_UNKNOWN = 0, /* Currently unknown */
74 PG_BOOL_YES, /* Yes (true) */
75 PG_BOOL_NO /* No (false) */
77
78extern void libpq_append_conn_error(PGconn *conn, const char *fmt,...) pg_attribute_printf(2, 3);
79extern bool oauth_unsafe_debugging_enabled(void);
80extern int pq_block_sigpipe(sigset_t *osigset, bool *sigpipe_pending);
81extern void pq_reset_sigpipe(sigset_t *osigset, bool sigpipe_pending, bool got_epipe);
82
83#ifdef ENABLE_NLS
84extern char *libpq_gettext(const char *msgid) pg_attribute_format_arg(1);
85#else
86#define libpq_gettext(x) (x)
87#endif
88
90
91#define pglock_thread() pg_g_threadlock(true)
92#define pgunlock_thread() pg_g_threadlock(false)
93
94#endif /* OAUTH_UTILS_H */
#define pg_attribute_format_arg(a)
Definition: c.h:232
#define pg_attribute_printf(f, a)
Definition: c.h:233
#define PGDLLEXPORT
Definition: c.h:1306
void(* pgthreadlock_t)(int acquire)
Definition: libpq-fe.h:472
void pq_reset_sigpipe(sigset_t *osigset, bool sigpipe_pending, bool got_epipe)
Definition: oauth-utils.c:208
#define libpq_gettext(x)
Definition: oauth-utils.h:86
void bool oauth_unsafe_debugging_enabled(void)
Definition: oauth-utils.c:149
int pq_block_sigpipe(sigset_t *osigset, bool *sigpipe_pending)
Definition: oauth-utils.c:172
pgthreadlock_t pg_g_threadlock
Definition: oauth-utils.c:35
PGTernaryBool
Definition: oauth-utils.h:72
@ PG_BOOL_YES
Definition: oauth-utils.h:74
@ PG_BOOL_NO
Definition: oauth-utils.h:75
@ PG_BOOL_UNKNOWN
Definition: oauth-utils.h:73
#define DECLARE_GETTER(TYPE, MEMBER)
Definition: oauth-utils.h:29
void libpq_append_conn_error(PGconn *conn, const char *fmt,...) pg_attribute_printf(2
PGDLLEXPORT void libpq_oauth_init(pgthreadlock_t threadlock, libpq_gettext_func gettext_impl, conn_errorMessage_func errmsg_impl, conn_oauth_client_id_func clientid_impl, conn_oauth_client_secret_func clientsecret_impl, conn_oauth_discovery_uri_func discoveryuri_impl, conn_oauth_issuer_id_func issuerid_impl, conn_oauth_scope_func scope_impl, conn_sasl_state_func saslstate_impl, set_conn_altsock_func setaltsock_impl, set_conn_oauth_token_func settoken_impl)
Definition: oauth-utils.c:65
char *(* libpq_gettext_func)(const char *msgid)
Definition: oauth-utils.h:51
#define DECLARE_SETTER(TYPE, MEMBER)
Definition: oauth-utils.h:33
int pgsocket
Definition: port.h:29
PGconn * conn
Definition: streamutil.c:52