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 355 of file oauth-curl.c.

356{
358
359 if (state->async_ctx)
360 {
361 free_async_ctx(conn, state->async_ctx);
362 state->async_ctx = NULL;
363 }
364
366}
#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:288
#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 3027 of file oauth-curl.c.

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

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().