summaryrefslogtreecommitdiff
path: root/src/interfaces/libpq-oauth/oauth-curl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/libpq-oauth/oauth-curl.c')
-rw-r--r--src/interfaces/libpq-oauth/oauth-curl.c120
1 files changed, 63 insertions, 57 deletions
diff --git a/src/interfaces/libpq-oauth/oauth-curl.c b/src/interfaces/libpq-oauth/oauth-curl.c
index bd0a656a166..92a7f1cd383 100644
--- a/src/interfaces/libpq-oauth/oauth-curl.c
+++ b/src/interfaces/libpq-oauth/oauth-curl.c
@@ -247,7 +247,8 @@ struct async_ctx
* our entry point, errors have three parts:
*
* - errctx: an optional static string, describing the global operation
- * currently in progress. It'll be translated for you.
+ * currently in progress. Should be translated with
+ * libpq_gettext().
*
* - errbuf: contains the actual error message. Generally speaking, use
* actx_error[_str] to manipulate this. This must be filled
@@ -367,13 +368,16 @@ pg_fe_cleanup_oauth_flow(PGconn *conn)
/*
* Macros for manipulating actx->errbuf. actx_error() translates and formats a
- * string for you; actx_error_str() appends a string directly without
- * translation.
+ * string for you, actx_error_internal() is the untranslated equivalent, and
+ * actx_error_str() appends a string directly (also without translation).
*/
#define actx_error(ACTX, FMT, ...) \
appendPQExpBuffer(&(ACTX)->errbuf, libpq_gettext(FMT), ##__VA_ARGS__)
+#define actx_error_internal(ACTX, FMT, ...) \
+ appendPQExpBuffer(&(ACTX)->errbuf, FMT, ##__VA_ARGS__)
+
#define actx_error_str(ACTX, S) \
appendPQExpBufferStr(&(ACTX)->errbuf, S)
@@ -461,6 +465,9 @@ struct oauth_parse
#define oauth_parse_set_error(ctx, fmt, ...) \
appendPQExpBuffer((ctx)->errbuf, libpq_gettext(fmt), ##__VA_ARGS__)
+#define oauth_parse_set_error_internal(ctx, fmt, ...) \
+ appendPQExpBuffer((ctx)->errbuf, fmt, ##__VA_ARGS__)
+
static void
report_type_mismatch(struct oauth_parse *ctx)
{
@@ -475,20 +482,20 @@ report_type_mismatch(struct oauth_parse *ctx)
switch (ctx->active->type)
{
case JSON_TOKEN_STRING:
- msgfmt = "field \"%s\" must be a string";
+ msgfmt = gettext_noop("field \"%s\" must be a string");
break;
case JSON_TOKEN_NUMBER:
- msgfmt = "field \"%s\" must be a number";
+ msgfmt = gettext_noop("field \"%s\" must be a number");
break;
case JSON_TOKEN_ARRAY_START:
- msgfmt = "field \"%s\" must be an array of strings";
+ msgfmt = gettext_noop("field \"%s\" must be an array of strings");
break;
default:
Assert(false);
- msgfmt = "field \"%s\" has unexpected type";
+ msgfmt = gettext_noop("field \"%s\" has unexpected type");
}
oauth_parse_set_error(ctx, msgfmt, ctx->active->name);
@@ -536,9 +543,9 @@ oauth_json_object_field_start(void *state, char *name, bool isnull)
if (ctx->active)
{
Assert(false);
- oauth_parse_set_error(ctx,
- "internal error: started field '%s' before field '%s' was finished",
- name, ctx->active->name);
+ oauth_parse_set_error_internal(ctx,
+ "internal error: started field \"%s\" before field \"%s\" was finished",
+ name, ctx->active->name);
return JSON_SEM_ACTION_FAILED;
}
@@ -588,9 +595,9 @@ oauth_json_object_end(void *state)
if (!ctx->nested && ctx->active)
{
Assert(false);
- oauth_parse_set_error(ctx,
- "internal error: field '%s' still active at end of object",
- ctx->active->name);
+ oauth_parse_set_error_internal(ctx,
+ "internal error: field \"%s\" still active at end of object",
+ ctx->active->name);
return JSON_SEM_ACTION_FAILED;
}
@@ -644,9 +651,9 @@ oauth_json_array_end(void *state)
if (ctx->nested != 2 || ctx->active->type != JSON_TOKEN_ARRAY_START)
{
Assert(false);
- oauth_parse_set_error(ctx,
- "internal error: found unexpected array end while parsing field '%s'",
- ctx->active->name);
+ oauth_parse_set_error_internal(ctx,
+ "internal error: found unexpected array end while parsing field \"%s\"",
+ ctx->active->name);
return JSON_SEM_ACTION_FAILED;
}
@@ -699,9 +706,9 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
if (ctx->nested != 1)
{
Assert(false);
- oauth_parse_set_error(ctx,
- "internal error: scalar target found at nesting level %d",
- ctx->nested);
+ oauth_parse_set_error_internal(ctx,
+ "internal error: scalar target found at nesting level %d",
+ ctx->nested);
return JSON_SEM_ACTION_FAILED;
}
@@ -709,9 +716,9 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
if (*field->scalar)
{
Assert(false);
- oauth_parse_set_error(ctx,
- "internal error: scalar field '%s' would be assigned twice",
- ctx->active->name);
+ oauth_parse_set_error_internal(ctx,
+ "internal error: scalar field \"%s\" would be assigned twice",
+ ctx->active->name);
return JSON_SEM_ACTION_FAILED;
}
@@ -731,9 +738,9 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
if (ctx->nested != 2)
{
Assert(false);
- oauth_parse_set_error(ctx,
- "internal error: array member found at nesting level %d",
- ctx->nested);
+ oauth_parse_set_error_internal(ctx,
+ "internal error: array member found at nesting level %d",
+ ctx->nested);
return JSON_SEM_ACTION_FAILED;
}
@@ -1087,7 +1094,7 @@ parse_token_error(struct async_ctx *actx, struct token_error *err)
* override the errctx if parsing explicitly fails.
*/
if (!result)
- actx->errctx = "failed to parse token error response";
+ actx->errctx = libpq_gettext("failed to parse token error response");
return result;
}
@@ -1115,8 +1122,8 @@ record_token_error(struct async_ctx *actx, const struct token_error *err)
if (response_code == 401)
{
actx_error(actx, actx->used_basic_auth
- ? "provider rejected the oauth_client_secret"
- : "provider requires client authentication, and no oauth_client_secret is set");
+ ? gettext_noop("provider rejected the oauth_client_secret")
+ : gettext_noop("provider requires client authentication, and no oauth_client_secret is set"));
actx_error_str(actx, " ");
}
}
@@ -1179,20 +1186,20 @@ setup_multiplexer(struct async_ctx *actx)
actx->mux = epoll_create1(EPOLL_CLOEXEC);
if (actx->mux < 0)
{
- actx_error(actx, "failed to create epoll set: %m");
+ actx_error_internal(actx, "failed to create epoll set: %m");
return false;
}
actx->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
if (actx->timerfd < 0)
{
- actx_error(actx, "failed to create timerfd: %m");
+ actx_error_internal(actx, "failed to create timerfd: %m");
return false;
}
if (epoll_ctl(actx->mux, EPOLL_CTL_ADD, actx->timerfd, &ev) < 0)
{
- actx_error(actx, "failed to add timerfd to epoll set: %m");
+ actx_error_internal(actx, "failed to add timerfd to epoll set: %m");
return false;
}
@@ -1201,8 +1208,7 @@ setup_multiplexer(struct async_ctx *actx)
actx->mux = kqueue();
if (actx->mux < 0)
{
- /*- translator: the term "kqueue" (kernel queue) should not be translated */
- actx_error(actx, "failed to create kqueue: %m");
+ actx_error_internal(actx, "failed to create kqueue: %m");
return false;
}
@@ -1215,7 +1221,7 @@ setup_multiplexer(struct async_ctx *actx)
actx->timerfd = kqueue();
if (actx->timerfd < 0)
{
- actx_error(actx, "failed to create timer kqueue: %m");
+ actx_error_internal(actx, "failed to create timer kqueue: %m");
return false;
}
@@ -1259,7 +1265,7 @@ register_socket(CURL *curl, curl_socket_t socket, int what, void *ctx,
break;
default:
- actx_error(actx, "unknown libcurl socket operation: %d", what);
+ actx_error_internal(actx, "unknown libcurl socket operation: %d", what);
return -1;
}
@@ -1276,15 +1282,15 @@ register_socket(CURL *curl, curl_socket_t socket, int what, void *ctx,
switch (op)
{
case EPOLL_CTL_ADD:
- actx_error(actx, "could not add to epoll set: %m");
+ actx_error_internal(actx, "could not add to epoll set: %m");
break;
case EPOLL_CTL_DEL:
- actx_error(actx, "could not delete from epoll set: %m");
+ actx_error_internal(actx, "could not delete from epoll set: %m");
break;
default:
- actx_error(actx, "could not update epoll set: %m");
+ actx_error_internal(actx, "could not update epoll set: %m");
}
return -1;
@@ -1334,7 +1340,7 @@ register_socket(CURL *curl, curl_socket_t socket, int what, void *ctx,
break;
default:
- actx_error(actx, "unknown libcurl socket operation: %d", what);
+ actx_error_internal(actx, "unknown libcurl socket operation: %d", what);
return -1;
}
@@ -1344,7 +1350,7 @@ register_socket(CURL *curl, curl_socket_t socket, int what, void *ctx,
res = kevent(actx->mux, ev, nev, ev_out, nev, &timeout);
if (res < 0)
{
- actx_error(actx, "could not modify kqueue: %m");
+ actx_error_internal(actx, "could not modify kqueue: %m");
return -1;
}
@@ -1368,10 +1374,10 @@ register_socket(CURL *curl, curl_socket_t socket, int what, void *ctx,
switch (what)
{
case CURL_POLL_REMOVE:
- actx_error(actx, "could not delete from kqueue: %m");
+ actx_error_internal(actx, "could not delete from kqueue: %m");
break;
default:
- actx_error(actx, "could not add to kqueue: %m");
+ actx_error_internal(actx, "could not add to kqueue: %m");
}
return -1;
}
@@ -1420,7 +1426,7 @@ comb_multiplexer(struct async_ctx *actx)
*/
if (kevent(actx->mux, NULL, 0, &ev, 1, &timeout) < 0)
{
- actx_error(actx, "could not comb kqueue: %m");
+ actx_error_internal(actx, "could not comb kqueue: %m");
return false;
}
@@ -1470,7 +1476,7 @@ set_timer(struct async_ctx *actx, long timeout)
if (timerfd_settime(actx->timerfd, 0 /* no flags */ , &spec, NULL) < 0)
{
- actx_error(actx, "setting timerfd to %ld: %m", timeout);
+ actx_error_internal(actx, "setting timerfd to %ld: %m", timeout);
return false;
}
@@ -1500,14 +1506,14 @@ set_timer(struct async_ctx *actx, long timeout)
EV_SET(&ev, 1, EVFILT_TIMER, EV_DELETE, 0, 0, 0);
if (kevent(actx->timerfd, &ev, 1, NULL, 0, NULL) < 0 && errno != ENOENT)
{
- actx_error(actx, "deleting kqueue timer: %m");
+ actx_error_internal(actx, "deleting kqueue timer: %m");
return false;
}
EV_SET(&ev, actx->timerfd, EVFILT_READ, EV_DELETE, 0, 0, 0);
if (kevent(actx->mux, &ev, 1, NULL, 0, NULL) < 0 && errno != ENOENT)
{
- actx_error(actx, "removing kqueue timer from multiplexer: %m");
+ actx_error_internal(actx, "removing kqueue timer from multiplexer: %m");
return false;
}
@@ -1518,14 +1524,14 @@ set_timer(struct async_ctx *actx, long timeout)
EV_SET(&ev, 1, EVFILT_TIMER, (EV_ADD | EV_ONESHOT), 0, timeout, 0);
if (kevent(actx->timerfd, &ev, 1, NULL, 0, NULL) < 0)
{
- actx_error(actx, "setting kqueue timer to %ld: %m", timeout);
+ actx_error_internal(actx, "setting kqueue timer to %ld: %m", timeout);
return false;
}
EV_SET(&ev, actx->timerfd, EVFILT_READ, EV_ADD, 0, 0, 0);
if (kevent(actx->mux, &ev, 1, NULL, 0, NULL) < 0)
{
- actx_error(actx, "adding kqueue timer to multiplexer: %m");
+ actx_error_internal(actx, "adding kqueue timer to multiplexer: %m");
return false;
}
@@ -2153,7 +2159,7 @@ finish_discovery(struct async_ctx *actx)
/*
* Pull the fields we care about from the document.
*/
- actx->errctx = "failed to parse OpenID discovery document";
+ actx->errctx = libpq_gettext("failed to parse OpenID discovery document");
if (!parse_provider(actx, &actx->provider))
return false; /* error message already set */
@@ -2421,7 +2427,7 @@ finish_device_authz(struct async_ctx *actx)
*/
if (response_code == 200)
{
- actx->errctx = "failed to parse device authorization";
+ actx->errctx = libpq_gettext("failed to parse device authorization");
if (!parse_device_authz(actx, &actx->authz))
return false; /* error message already set */
@@ -2509,7 +2515,7 @@ finish_token_request(struct async_ctx *actx, struct token *tok)
*/
if (response_code == 200)
{
- actx->errctx = "failed to parse access token response";
+ actx->errctx = libpq_gettext("failed to parse access token response");
if (!parse_access_token(actx, tok))
return false; /* error message already set */
@@ -2888,7 +2894,7 @@ pg_fe_run_oauth_flow_impl(PGconn *conn)
switch (actx->step)
{
case OAUTH_STEP_INIT:
- actx->errctx = "failed to fetch OpenID discovery document";
+ actx->errctx = libpq_gettext("failed to fetch OpenID discovery document");
if (!start_discovery(actx, conn_oauth_discovery_uri(conn)))
goto error_return;
@@ -2902,11 +2908,11 @@ pg_fe_run_oauth_flow_impl(PGconn *conn)
if (!check_issuer(actx, conn))
goto error_return;
- actx->errctx = "cannot run OAuth device authorization";
+ actx->errctx = libpq_gettext("cannot run OAuth device authorization");
if (!check_for_device_flow(actx))
goto error_return;
- actx->errctx = "failed to obtain device authorization";
+ actx->errctx = libpq_gettext("failed to obtain device authorization");
if (!start_device_authz(actx, conn))
goto error_return;
@@ -2917,7 +2923,7 @@ pg_fe_run_oauth_flow_impl(PGconn *conn)
if (!finish_device_authz(actx))
goto error_return;
- actx->errctx = "failed to obtain access token";
+ actx->errctx = libpq_gettext("failed to obtain access token");
if (!start_token_request(actx, conn))
goto error_return;
@@ -2968,7 +2974,7 @@ pg_fe_run_oauth_flow_impl(PGconn *conn)
break;
case OAUTH_STEP_WAIT_INTERVAL:
- actx->errctx = "failed to obtain access token";
+ actx->errctx = libpq_gettext("failed to obtain access token");
if (!start_token_request(actx, conn))
goto error_return;
@@ -2994,7 +3000,7 @@ error_return:
* also the documentation for struct async_ctx.
*/
if (actx->errctx)
- appendPQExpBuffer(errbuf, "%s: ", libpq_gettext(actx->errctx));
+ appendPQExpBuffer(errbuf, "%s: ", actx->errctx);
if (PQExpBufferDataBroken(actx->errbuf))
appendPQExpBufferStr(errbuf, libpq_gettext("out of memory"));