summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-02-18 11:35:24 +0100
committerChristian Grothoff <christian@grothoff.org>2024-02-18 11:35:24 +0100
commit99228c467a935c8e91a73d2b6c9d6acd593c05f5 (patch)
tree8188a52d4a11ec0a6dcc85c45eda787fd377998f
parent81b54516af8595e024e54d5cef883c852239988c (diff)
downloadexchange-99228c467a935c8e91a73d2b6c9d6acd593c05f5.tar.gz
exchange-99228c467a935c8e91a73d2b6c9d6acd593c05f5.tar.bz2
exchange-99228c467a935c8e91a73d2b6c9d6acd593c05f5.zip
allow using URL builder to just add query parameters
-rw-r--r--src/include/taler_util.h5
-rw-r--r--src/util/url.c67
2 files changed, 38 insertions, 34 deletions
diff --git a/src/include/taler_util.h b/src/include/taler_util.h
index d2ff78715..d8d1a5638 100644
--- a/src/include/taler_util.h
+++ b/src/include/taler_util.h
@@ -416,8 +416,9 @@ TALER_mhd_is_https (struct MHD_Connection *connection);
* that a NULL value does not terminate the list, only a NULL key signals the
* end of the list of arguments.
*
- * @param base_url absolute base URL to use
- * @param path path of the url
+ * @param base_url absolute base URL to use, must either
+ * end with '/' *or* @a path must be the empty string
+ * @param path path of the url to append to the @a base_url
* @param ... NULL-terminated key-value pairs (char *) for query parameters,
* only the value will be url-encoded
* @returns the URL, must be freed with #GNUNET_free
diff --git a/src/util/url.c b/src/util/url.c
index 73f61dee8..bf59ba6ec 100644
--- a/src/util/url.c
+++ b/src/util/url.c
@@ -212,8 +212,6 @@ TALER_url_join (const char *base_url,
...)
{
struct GNUNET_Buffer buf = { 0 };
- va_list args;
- size_t len;
GNUNET_assert (NULL != base_url);
GNUNET_assert (NULL != path);
@@ -224,40 +222,45 @@ TALER_url_join (const char *base_url,
"Empty base URL specified\n");
return NULL;
}
- if ('/' != base_url[strlen (base_url) - 1])
+ if ('\0' != path[0])
{
- /* Must be an actual base URL! */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Base URL `%s' does not end with '/', cannot join with `%s'\n",
- base_url,
- path);
- return NULL;
+ if ('/' != base_url[strlen (base_url) - 1])
+ {
+ /* Must be an actual base URL! */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Base URL `%s' does not end with '/', cannot join with `%s'\n",
+ base_url,
+ path);
+ return NULL;
+ }
+ if ('/' == path[0])
+ {
+ /* The path must be relative. */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Path `%s' is not relative\n",
+ path);
+ return NULL;
+ }
}
- if ('/' == path[0])
+
{
- /* The path must be relative. */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Path `%s' is not relative\n",
- path);
- return NULL;
+ va_list args;
+ size_t len;
+
+ va_start (args,
+ path);
+ len = strlen (base_url) + strlen (path) + 1;
+ len += calculate_argument_length (args);
+ GNUNET_buffer_prealloc (&buf,
+ len);
+ GNUNET_buffer_write_str (&buf,
+ base_url);
+ GNUNET_buffer_write_str (&buf,
+ path);
+ serialize_arguments (&buf,
+ args);
+ va_end (args);
}
-
- va_start (args,
- path);
-
- len = strlen (base_url) + strlen (path) + 1;
- len += calculate_argument_length (args);
-
- GNUNET_buffer_prealloc (&buf,
- len);
- GNUNET_buffer_write_str (&buf,
- base_url);
- GNUNET_buffer_write_str (&buf,
- path);
- serialize_arguments (&buf,
- args);
- va_end (args);
-
return GNUNET_buffer_reap_str (&buf);
}