summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/taler_util.h9
-rw-r--r--src/util/url.c16
2 files changed, 25 insertions, 0 deletions
diff --git a/src/include/taler_util.h b/src/include/taler_util.h
index 33c126cbc..59824a521 100644
--- a/src/include/taler_util.h
+++ b/src/include/taler_util.h
@@ -183,6 +183,15 @@ TALER_project_data_default (void);
char *
TALER_urlencode (const char *s);
+/**
+ * Test if all characters in @a url are valid for
+ * a URL.
+ *
+ * @param url URL to sanity-check
+ * @return true if @a url only contains valid characters
+ */
+bool
+TALER_url_valid_charset (const char *url);
/**
* Check if @a lang matches the @a language_pattern, and if so with
diff --git a/src/util/url.c b/src/util/url.c
index 5962a18b2..3fbc4a048 100644
--- a/src/util/url.c
+++ b/src/util/url.c
@@ -365,4 +365,20 @@ TALER_url_absolute_raw (const char *proto,
}
+bool
+TALER_url_valid_charset (const char *url)
+{
+ for (unsigned int i = 0; '\0' != url[i]; i++)
+ {
+#define ALLOWED_CHARACTERS \
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/:&?-.,=_~%"
+ if (NULL == strchr (ALLOWED_CHARACTERS,
+ (int) url[i]))
+ return false;
+#undef ALLOWED_CHARACTERS
+ }
+ return true;
+}
+
+
/* end of url.c */