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