]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/web-util.c
eaff736665798fa79751cfa81472a288afb74759
[thirdparty/systemd.git] / src / basic / web-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 This file is part of systemd.
4
5 Copyright 2010 Lennart Poettering
6 ***/
7
8 #include <stdbool.h>
9
10 #include "string-util.h"
11 #include "utf8.h"
12 #include "web-util.h"
13
14 bool http_etag_is_valid(const char *etag) {
15 if (isempty(etag))
16 return false;
17
18 if (!endswith(etag, "\""))
19 return false;
20
21 if (!startswith(etag, "\"") && !startswith(etag, "W/\""))
22 return false;
23
24 return true;
25 }
26
27 bool http_url_is_valid(const char *url) {
28 const char *p;
29
30 if (isempty(url))
31 return false;
32
33 p = startswith(url, "http://");
34 if (!p)
35 p = startswith(url, "https://");
36 if (!p)
37 return false;
38
39 if (isempty(p))
40 return false;
41
42 return ascii_is_valid(p);
43 }
44
45 bool documentation_url_is_valid(const char *url) {
46 const char *p;
47
48 if (isempty(url))
49 return false;
50
51 if (http_url_is_valid(url))
52 return true;
53
54 p = startswith(url, "file:/");
55 if (!p)
56 p = startswith(url, "info:");
57 if (!p)
58 p = startswith(url, "man:");
59
60 if (isempty(p))
61 return false;
62
63 return ascii_is_valid(p);
64 }