PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 3022 of file oauth-curl.c.

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