v47-0007-fixup-Add-OAUTHBEARER-SASL-mechanism.patch
application/octet-stream
Filename: v47-0007-fixup-Add-OAUTHBEARER-SASL-mechanism.patch
Type: application/octet-stream
Part: 7
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v47-0007
Subject: fixup! Add OAUTHBEARER SASL mechanism
| File | + | − |
|---|---|---|
| src/interfaces/libpq/fe-auth-oauth-curl.c | 37 | 11 |
From 298839b69f04d01ec5ba2e77c3b9f7d351384809 Mon Sep 17 00:00:00 2001
From: Jacob Champion <jacob.champion@enterprisedb.com>
Date: Thu, 6 Feb 2025 14:56:04 -0800
Subject: [PATCH v47 07/11] fixup! Add OAUTHBEARER SASL mechanism
---
src/interfaces/libpq/fe-auth-oauth-curl.c | 48 +++++++++++++++++------
1 file changed, 37 insertions(+), 11 deletions(-)
diff --git a/src/interfaces/libpq/fe-auth-oauth-curl.c b/src/interfaces/libpq/fe-auth-oauth-curl.c
index 6c8333789f1..993ca3bdab9 100644
--- a/src/interfaces/libpq/fe-auth-oauth-curl.c
+++ b/src/interfaces/libpq/fe-auth-oauth-curl.c
@@ -1329,8 +1329,9 @@ static int
debug_callback(CURL *handle, curl_infotype type, char *data, size_t size,
void *clientp)
{
- const char *const end = data + size;
const char *prefix;
+ bool printed_prefix = false;
+ PQExpBufferData buf;
/* Prefixes are modeled off of the default libcurl debug output. */
switch (type)
@@ -1353,25 +1354,50 @@ debug_callback(CURL *handle, curl_infotype type, char *data, size_t size,
return 0;
}
+ initPQExpBuffer(&buf);
+
/*
* Split the output into lines for readability; sometimes multiple headers
- * are included in a single call.
+ * are included in a single call. We also don't allow unprintable ASCII
+ * through without a basic <XX> escape.
*/
- while (data < end)
+ for (int i = 0; i < size; i++)
{
- size_t len = end - data;
- char *eol = memchr(data, '\n', len);
+ char c = data[i];
- if (eol)
- len = eol - data + 1;
+ if (!printed_prefix)
+ {
+ appendPQExpBuffer(&buf, "%s ", prefix);
+ printed_prefix = true;
+ }
- /* TODO: handle unprintables */
- fprintf(stderr, "%s %.*s%s", prefix, (int) len, data,
- eol ? "" : "\n");
+ if (c >= 0x20 && c <= 0x7E)
+ appendPQExpBufferChar(&buf, c);
+ else if ((type == CURLINFO_HEADER_IN
+ || type == CURLINFO_HEADER_OUT
+ || type == CURLINFO_TEXT)
+ && (c == '\r' || c == '\n'))
+ {
+ /*
+ * Don't bother emitting <0D><0A> for headers and text; it's not
+ * helpful noise.
+ */
+ }
+ else
+ appendPQExpBuffer(&buf, "<%02X>", c);
- data += len;
+ if (c == '\n')
+ {
+ appendPQExpBufferChar(&buf, c);
+ printed_prefix = false;
+ }
}
+ if (printed_prefix)
+ appendPQExpBufferChar(&buf, '\n'); /* finish the line */
+
+ fprintf(stderr, "%s", buf.data);
+ termPQExpBuffer(&buf);
return 0;
}
--
2.34.1