summaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-connect.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2015-02-21 13:27:12 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2015-02-21 13:27:12 -0500
commit3d9b6f31eec150b5a6000e0814e81e36d9eb069a (patch)
tree36ed0e369ae24d21773fe8b5c2d3beb575436440 /src/interfaces/libpq/fe-connect.c
parentb26e2081423cf1c70f83a11787351017c97cfd7c (diff)
downloadpostgresql-3d9b6f31eec150b5a6000e0814e81e36d9eb069a.tar.gz
Minor code beautification in conninfo_uri_parse_params().
Reading this made me itch, so clean the logic a bit.
Diffstat (limited to 'src/interfaces/libpq/fe-connect.c')
-rw-r--r--src/interfaces/libpq/fe-connect.c55
1 files changed, 19 insertions, 36 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 17f34cf8b5..e2a06b3d92 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -4934,36 +4934,30 @@ conninfo_uri_parse_params(char *params,
{
printfPQExpBuffer(errorMessage,
libpq_gettext("extra key/value separator \"=\" in URI query parameter: \"%s\"\n"),
- params);
+ keyword);
return false;
}
/* Cut off keyword, advance to value */
- *p = '\0';
- value = ++p;
+ *p++ = '\0';
+ value = p;
}
else if (*p == '&' || *p == '\0')
{
- char prevchar;
-
- /* Cut off value, remember old value */
- prevchar = *p;
- *p = '\0';
-
+ /*
+ * If not at the end, cut off value and advance; leave p
+ * pointing to start of the next parameter, if any.
+ */
+ if (*p != '\0')
+ *p++ = '\0';
/* Was there '=' at all? */
if (value == NULL)
{
printfPQExpBuffer(errorMessage,
libpq_gettext("missing key/value separator \"=\" in URI query parameter: \"%s\"\n"),
- params);
+ keyword);
return false;
}
-
- /*
- * If not at the end, advance; now pointing to start of the
- * next parameter, if any.
- */
- if (prevchar != '\0')
- ++p;
+ /* Got keyword and value, go process them. */
break;
}
else
@@ -5007,24 +5001,12 @@ conninfo_uri_parse_params(char *params,
if (!conninfo_storeval(connOptions, keyword, value,
errorMessage, true, false))
{
- /*
- * Check if there was a hard error when decoding or storing the
- * option.
- */
- if (errorMessage->len != 0)
- {
- if (malloced)
- {
- free(keyword);
- free(value);
- }
- return false;
- }
-
- printfPQExpBuffer(errorMessage,
- libpq_gettext(
- "invalid URI query parameter: \"%s\"\n"),
- keyword);
+ /* Insert generic message if conninfo_storeval didn't give one. */
+ if (errorMessage->len == 0)
+ printfPQExpBuffer(errorMessage,
+ libpq_gettext("invalid URI query parameter: \"%s\"\n"),
+ keyword);
+ /* And fail. */
if (malloced)
{
free(keyword);
@@ -5032,13 +5014,14 @@ conninfo_uri_parse_params(char *params,
}
return false;
}
+
if (malloced)
{
free(keyword);
free(value);
}
- /* Proceed to next key=value pair */
+ /* Proceed to next key=value pair, if any */
params = p;
}