PostgreSQL Source Code git master
oauth-curl.h File Reference
#include "libpq-fe.h"
Include dependency graph for oauth-curl.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

PGDLLEXPORT PostgresPollingStatusType pg_fe_run_oauth_flow (PGconn *conn)
 
PGDLLEXPORT void pg_fe_cleanup_oauth_flow (PGconn *conn)
 

Function Documentation

◆ pg_fe_cleanup_oauth_flow()

PGDLLEXPORT void pg_fe_cleanup_oauth_flow ( PGconn conn)

Definition at line 356 of file oauth-curl.c.

357{
359
360 if (state->async_ctx)
361 {
362 free_async_ctx(conn, state->async_ctx);
363 state->async_ctx = NULL;
364 }
365
367}
#define set_conn_altsock(CONN, VAL)
Definition: oauth-curl.c:61
static void free_async_ctx(PGconn *conn, struct async_ctx *actx)
Definition: oauth-curl.c:289
#define conn_sasl_state(CONN)
Definition: oauth-curl.c:59
#define PGINVALID_SOCKET
Definition: port.h:31
PGconn * conn
Definition: streamutil.c:52
Definition: regguts.h:323

References conn, conn_sasl_state, free_async_ctx(), PGINVALID_SOCKET, and set_conn_altsock.

◆ pg_fe_run_oauth_flow()

PGDLLEXPORT PostgresPollingStatusType pg_fe_run_oauth_flow ( PGconn conn)

Definition at line 3033 of file oauth-curl.c.

3034{
3037 struct async_ctx *actx;
3038#ifndef WIN32
3039 sigset_t osigset;
3040 bool sigpipe_pending;
3041 bool masked;
3042
3043 /*---
3044 * Ignore SIGPIPE on this thread during all Curl processing.
3045 *
3046 * Because we support multiple threads, we have to set up libcurl with
3047 * CURLOPT_NOSIGNAL, which disables its default global handling of
3048 * SIGPIPE. From the Curl docs:
3049 *
3050 * libcurl makes an effort to never cause such SIGPIPE signals to
3051 * trigger, but some operating systems have no way to avoid them and
3052 * even on those that have there are some corner cases when they may
3053 * still happen, contrary to our desire.
3054 *
3055 * Note that libcurl is also at the mercy of its DNS resolution and SSL
3056 * libraries; if any of them forget a MSG_NOSIGNAL then we're in trouble.
3057 * Modern platforms and libraries seem to get it right, so this is a
3058 * difficult corner case to exercise in practice, and unfortunately it's
3059 * not really clear whether it's necessary in all cases.
3060 */
3061 masked = (pq_block_sigpipe(&osigset, &sigpipe_pending) == 0);
3062#endif
3063
3065
3066 /*
3067 * To assist with finding bugs in comb_multiplexer() and
3068 * drain_timer_events(), when we're in debug mode, track the total number
3069 * of calls to this function and print that at the end of the flow.
3070 *
3071 * Be careful that state->async_ctx could be NULL if early initialization
3072 * fails during the first call.
3073 */
3074 actx = state->async_ctx;
3075 Assert(actx || result == PGRES_POLLING_FAILED);
3076
3077 if (actx && actx->debugging)
3078 {
3079 actx->dbg_num_calls++;
3080 if (result == PGRES_POLLING_OK || result == PGRES_POLLING_FAILED)
3081 fprintf(stderr, "[libpq] total number of polls: %d\n",
3082 actx->dbg_num_calls);
3083 }
3084
3085#ifndef WIN32
3086 if (masked)
3087 {
3088 /*
3089 * Undo the SIGPIPE mask. Assume we may have gotten EPIPE (we have no
3090 * way of knowing at this level).
3091 */
3092 pq_reset_sigpipe(&osigset, sigpipe_pending, true /* EPIPE, maybe */ );
3093 }
3094#endif
3095
3096 return result;
3097}
#define fprintf(file, fmt, msg)
Definition: cubescan.l:21
Assert(PointerIsAligned(start, uint64))
PostgresPollingStatusType
Definition: libpq-fe.h:114
@ PGRES_POLLING_OK
Definition: libpq-fe.h:118
@ PGRES_POLLING_FAILED
Definition: libpq-fe.h:115
static PostgresPollingStatusType pg_fe_run_oauth_flow_impl(PGconn *conn)
Definition: oauth-curl.c:2769
void pq_reset_sigpipe(sigset_t *osigset, bool sigpipe_pending, bool got_epipe)
Definition: oauth-utils.c:208
int pq_block_sigpipe(sigset_t *osigset, bool *sigpipe_pending)
Definition: oauth-utils.c:172
bool debugging
Definition: oauth-curl.c:281
int dbg_num_calls
Definition: oauth-curl.c:282

References Assert(), conn, conn_sasl_state, async_ctx::dbg_num_calls, async_ctx::debugging, fprintf, pg_fe_run_oauth_flow_impl(), PGRES_POLLING_FAILED, PGRES_POLLING_OK, pq_block_sigpipe(), and pq_reset_sigpipe().