From b42df84860f710d25cf029244583c6c62a6aa3f5 Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio 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); + + PQunsupportedProtocolExtensionParametersPQunsupportedProtocolExtensionParameters + + + + Returns a null-terminated array of protocol extensions that were + requested by the client but are not supported by the server. + +int PQunsupportedProtocolExtensionParameters(const PGconn *conn); + + 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. + + + + PQserverVersionPQserverVersion 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