summaryrefslogtreecommitdiff
path: root/src/util/url.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/url.c')
-rw-r--r--src/util/url.c85
1 files changed, 52 insertions, 33 deletions
diff --git a/src/util/url.c b/src/util/url.c
index a140a3a2e..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);
}
@@ -322,7 +325,7 @@ TALER_url_valid_charset (const char *url)
for (unsigned int i = 0; '\0' != url[i]; i++)
{
#define ALLOWED_CHARACTERS \
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/:;&?-.,=_~%+"
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/:;&?-.,=_~%+#"
if (NULL == strchr (ALLOWED_CHARACTERS,
(int) url[i]))
return false;
@@ -332,4 +335,20 @@ TALER_url_valid_charset (const char *url)
}
+bool
+TALER_is_web_url (const char *url)
+{
+ if ( (0 != strncasecmp (url,
+ "https://",
+ strlen ("https://"))) &&
+ (0 != strncasecmp (url,
+ "http://",
+ strlen ("http://"))) )
+ return false;
+ if (! TALER_url_valid_charset (url) )
+ return false;
+ return true;
+}
+
+
/* end of url.c */