1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-31 17:02:12 +03:00

Retire escapeConnectionParameter().

It is redundant with appendConnStrVal(), which became an extern function
in commit 41f18f021a.  This changes the
handling of out-of-memory and of certain inputs for which quoting is
optional, but pg_basebackup has no need for unusual treatment thereof.
This commit is contained in:
Noah Misch
2016-08-21 22:05:57 -04:00
parent 04164deb7c
commit 9132c01429
2 changed files with 4 additions and 66 deletions

View File

@@ -17,6 +17,7 @@ top_builddir = ../../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS) override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
LDFLAGS += -L$(top_builddir)/src/fe_utils -lpgfeutils -lpq
OBJS=receivelog.o streamutil.o $(WIN32RES) OBJS=receivelog.o streamutil.o $(WIN32RES)

View File

@@ -26,6 +26,7 @@
#endif #endif
#include "common/string.h" #include "common/string.h"
#include "fe_utils/string_utils.h"
#include "getopt_long.h" #include "getopt_long.h"
#include "libpq-fe.h" #include "libpq-fe.h"
#include "pqexpbuffer.h" #include "pqexpbuffer.h"
@@ -1392,69 +1393,6 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
WriteRecoveryConf(); WriteRecoveryConf();
} }
/*
* Escape a parameter value so that it can be used as part of a libpq
* connection string, e.g. in:
*
* application_name=<value>
*
* The returned string is malloc'd. Return NULL on out-of-memory.
*/
static char *
escapeConnectionParameter(const char *src)
{
bool need_quotes = false;
bool need_escaping = false;
const char *p;
char *dstbuf;
char *dst;
/*
* First check if quoting is needed. Any quote (') or backslash (\)
* characters need to be escaped. Parameters are separated by whitespace,
* so any string containing whitespace characters need to be quoted. An
* empty string is represented by ''.
*/
if (strchr(src, '\'') != NULL || strchr(src, '\\') != NULL)
need_escaping = true;
for (p = src; *p; p++)
{
if (isspace((unsigned char) *p))
{
need_quotes = true;
break;
}
}
if (*src == '\0')
return pg_strdup("''");
if (!need_quotes && !need_escaping)
return pg_strdup(src); /* no quoting or escaping needed */
/*
* Allocate a buffer large enough for the worst case that all the source
* characters need to be escaped, plus quotes.
*/
dstbuf = pg_malloc(strlen(src) * 2 + 2 + 1);
dst = dstbuf;
if (need_quotes)
*(dst++) = '\'';
for (; *src; src++)
{
if (*src == '\'' || *src == '\\')
*(dst++) = '\\';
*(dst++) = *src;
}
if (need_quotes)
*(dst++) = '\'';
*dst = '\0';
return dstbuf;
}
/* /*
* Escape a string so that it can be used as a value in a key-value pair * Escape a string so that it can be used as a value in a key-value pair
* a configuration file. * a configuration file.
@@ -1523,9 +1461,8 @@ GenerateRecoveryConf(PGconn *conn)
* Write "keyword=value" pieces, the value string is escaped and/or * Write "keyword=value" pieces, the value string is escaped and/or
* quoted if necessary. * quoted if necessary.
*/ */
escaped = escapeConnectionParameter(option->val); appendPQExpBuffer(&conninfo_buf, "%s=", option->keyword);
appendPQExpBuffer(&conninfo_buf, "%s=%s", option->keyword, escaped); appendConnStrVal(&conninfo_buf, option->val);
free(escaped);
} }
/* /*