diff options
-rw-r--r-- | src/include/taler_util.h | 5 | ||||
-rw-r--r-- | src/util/url.c | 67 |
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); } |