| 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 |
|
| 37 |
DECLARE_GETTER(PQExpBuffer, errorMessage); |
| 38 |
DECLARE_GETTER(char *, oauth_client_id); |
| 39 |
DECLARE_GETTER(char *, oauth_client_secret); |
| 40 |
DECLARE_GETTER(char *, oauth_discovery_uri); |
| 41 |
DECLARE_GETTER(char *, oauth_issuer_id); |
| 42 |
DECLARE_GETTER(char *, oauth_scope); |
| 43 |
DECLARE_GETTER(fe_oauth_state *, sasl_state); |
| 44 |
|
| 45 |
DECLARE_SETTER(pgsocket, altsock); |
| 46 |
DECLARE_SETTER(char *, oauth_token); |
| 47 |
|
| 48 |
#undef DECLARE_GETTER |
| 49 |
#undef DECLARE_SETTER |
| 50 |
|
| 51 |
typedef char *(*libpq_gettext_func) (const char *msgid); |
| 52 |
|
| 53 |
/* Initializes libpq-oauth. */ |
| 54 |
extern 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 |
|
| 71 |
typedef enum |
| 72 |
{ |
| 73 |
PG_BOOL_UNKNOWN = 0, /* Currently unknown */ |
| 74 |
PG_BOOL_YES, /* Yes (true) */ |
| 75 |
PG_BOOL_NO /* No (false) */ |
| 76 |
} PGTernaryBool; |
| 77 |
|
| 78 |
extern void libpq_append_conn_error(PGconn *conn, const char *fmt,...) pg_attribute_printf(2, 3); |
| 79 |
extern bool oauth_unsafe_debugging_enabled(void); |
| 80 |
extern int pq_block_sigpipe(sigset_t *osigset, bool *sigpipe_pending); |
| 81 |
extern void pq_reset_sigpipe(sigset_t *osigset, bool sigpipe_pending, bool got_epipe); |
| 82 |
|
| 83 |
#ifdef ENABLE_NLS |
| 84 |
extern char *libpq_gettext(const char *msgid) pg_attribute_format_arg(1); |
| 85 |
#else |
| 86 |
#define libpq_gettext(x) (x) |
| 87 |
#endif |
| 88 |
|
| 89 |
extern pgthreadlock_t pg_g_threadlock; |
| 90 |
|
| 91 |
#define pglock_thread() pg_g_threadlock(true) |
| 92 |
#define pgunlock_thread() pg_g_threadlock(false) |
| 93 |
|
| 94 |
#endif /* OAUTH_UTILS_H */ |