v8-0003-libpq-Add-PQunsupportedProtocolExtensionParameter.patch

application/octet-stream

Filename: v8-0003-libpq-Add-PQunsupportedProtocolExtensionParameter.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 v8-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 b42df84860f710d25cf029244583c6c62a6aa3f5 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 v8 03/13] 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 173ab779a08..a143eec77ce 100644
--- a/doc/src/sgml/libpq.sgml
+++ b/doc/src/sgml/libpq.sgml
@@ -2576,6 +2576,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 088592deb16..b46c387f6f7 100644
--- a/src/interfaces/libpq/exports.txt
+++ b/src/interfaces/libpq/exports.txt
@@ -193,3 +193,4 @@ PQsendClosePrepared       190
 PQsendClosePortal         191
 PQchangePassword          192
 PQsendPipelineSync        193
+PQunsupportedProtocolExtensions 194
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 08b15c55526..a32d813f3c3 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://";
@@ -7264,6 +7266,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 defc415fa3f..d538f702b99 100644
--- a/src/interfaces/libpq/libpq-fe.h
+++ b/src/interfaces/libpq/libpq-fe.h
@@ -347,6 +347,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