summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-01-19 20:45:27 +0100
committerLennart Poettering <lennart@poettering.net>2015-01-20 15:06:58 +0100
commita2e0337875addaf08225fbf9b231435ba12a88b5 (patch)
tree2d8db845ca71eef64593bc564931d9f21fc1fe9b /src/shared/util.c
parent6c8f2e7d78b1fe280588dc91beae90cdf36fcd49 (diff)
util: make http url validity checks more generic, and move them to util.c
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index fd54023660..5157b94a34 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5458,25 +5458,43 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value) {
return r;
}
-bool is_valid_documentation_url(const char *url) {
- assert(url);
+bool http_url_is_valid(const char *url) {
+ const char *p;
- if (startswith(url, "http://") && url[7])
- return true;
+ if (isempty(url))
+ return false;
- if (startswith(url, "https://") && url[8])
- return true;
+ p = startswith(url, "http://");
+ if (!p)
+ p = startswith(url, "https://");
+ if (!p)
+ return false;
- if (startswith(url, "file:") && url[5])
- return true;
+ if (isempty(p))
+ return false;
- if (startswith(url, "info:") && url[5])
- return true;
+ return ascii_is_valid(p);
+}
- if (startswith(url, "man:") && url[4])
+bool documentation_url_is_valid(const char *url) {
+ const char *p;
+
+ if (isempty(url))
+ return false;
+
+ if (http_url_is_valid(url))
return true;
- return false;
+ p = startswith(url, "file:/");
+ if (!p)
+ p = startswith(url, "info:");
+ if (!p)
+ p = startswith(url, "man:");
+
+ if (isempty(p))
+ return false;
+
+ return ascii_is_valid(p);
}
bool in_initrd(void) {