v11-0003-libpq-Add-PQunsupportedProtocolExtensionParamete.patch

application/octet-stream

Filename: v11-0003-libpq-Add-PQunsupportedProtocolExtensionParamete.patch
Type: application/octet-stream
Part: 2
Message: Re: Add new protocol message to change GUCs for usage with future protocol-only GUCs

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 v11-0003
Subject: libpq: Add PQunsupportedProtocolExtensionParameters
File+
doc/src/sgml/libpq.sgml 19 0
src/interfaces/libpq/exports.txt 1 0
src/interfaces/libpq/fe-connect.c 14 0
src/interfaces/libpq/libpq-fe.h 1 0
From 1da6d6e129f539745b7b0c7fcc52d71165ceba94 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <jelte.fennema@microsoft.com>
Date: Mon, 22 Jan 2024 09:54:28 +0100
Subject: [PATCH v11 03/14] libpq: Add PQunsupportedProtocolExtensionParameters

This patch adds a new PQunsupportedProtocolExtensionParamters API to
libpq. This can be used for feature detection of protocol extension
parameters by the client. Similar to how a client can feature detection
of the protocol and server version using PQprotocolVersion and
PQserverVersion respectively.
---
 doc/src/sgml/libpq.sgml           | 19 +++++++++++++++++++
 src/interfaces/libpq/exports.txt  |  1 +
 src/interfaces/libpq/fe-connect.c | 14 ++++++++++++++
 src/interfaces/libpq/libpq-fe.h   |  1 +
 4 files changed, 35 insertions(+)

diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml
index d3e87056f2c..f6ca29268c5 100644
--- a/doc/src/sgml/libpq.sgml
+++ b/doc/src/sgml/libpq.sgml
@@ -2582,6 +2582,25 @@ int PQprotocolVersion(const PGconn *conn);
      </listitem>
     </varlistentry>
 
+    <varlistentry id="libpq-PQunsupportedProtocolExtensionParameters">
+     <term><function>PQunsupportedProtocolExtensionParameters</function><indexterm><primary>PQunsupportedProtocolExtensionParameters</primary></indexterm></term>
+
+     <listitem>
+      <para>
+       Returns a null-terminated array of protocol extensions that were
+       requested by the client but are not supported by the server.
+<synopsis>
+int PQunsupportedProtocolExtensionParameters(const PGconn *conn);
+</synopsis>
+       Applications might wish to use this function to determine whether certain
+       protocol extensions they intended to use are supported. Even when some
+       extension is not supported the connection can still be used, only the
+       unsupported extensions cannot be used. Returns NULL if the connection is
+       bad.
+      </para>
+     </listitem>
+    </varlistentry>
+
     <varlistentry id="libpq-PQserverVersion">
      <term><function>PQserverVersion</function><indexterm><primary>PQserverVersion</primary></indexterm></term>
 
diff --git a/src/interfaces/libpq/exports.txt b/src/interfaces/libpq/exports.txt
index 9fbd3d34074..4ac8a75c419 100644
--- a/src/interfaces/libpq/exports.txt
+++ b/src/interfaces/libpq/exports.txt
@@ -202,3 +202,4 @@ PQcancelSocket            199
 PQcancelErrorMessage      200
 PQcancelReset             201
 PQcancelFinish            202
+PQunsupportedProtocolExtensionParameters 203
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 035f0fdd2c1..f0f646b11f3 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -382,6 +382,8 @@ static const PQEnvironmentOption EnvironmentOptions[] =
 	}
 };
 
+static const char *no_unsupported_protocol_extensions[1] = {NULL};
+
 /* The connection URI must start with either of the following designators: */
 static const char uri_designator[] = "postgresql://";
 static const char short_uri_designator[] = "postgres://";
@@ -6964,6 +6966,18 @@ PQprotocolVersion(const PGconn *conn)
 	return PG_PROTOCOL_MAJOR(conn->pversion);
 }
 
+const char **
+PQunsupportedProtocolExtensionParameters(const PGconn *conn)
+{
+	if (!conn)
+		return NULL;
+	if (conn->status == CONNECTION_BAD)
+		return NULL;
+	if (!conn->unsupported_pextension_params)
+		return no_unsupported_protocol_extensions;
+	return (const char **) conn->unsupported_pextension_params;
+}
+
 int
 PQserverVersion(const PGconn *conn)
 {
diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h
index 09b485bd2bc..4f2b075075c 100644
--- a/src/interfaces/libpq/libpq-fe.h
+++ b/src/interfaces/libpq/libpq-fe.h
@@ -373,6 +373,7 @@ extern PGTransactionStatusType PQtransactionStatus(const PGconn *conn);
 extern const char *PQparameterStatus(const PGconn *conn,
 									 const char *paramName);
 extern int	PQprotocolVersion(const PGconn *conn);
+extern const char **PQunsupportedProtocolExtensionParameters(const PGconn *conn);
 extern int	PQserverVersion(const PGconn *conn);
 extern char *PQerrorMessage(const PGconn *conn);
 extern int	PQsocket(const PGconn *conn);
-- 
2.34.1