]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/web-util.c
pkgconfig: define variables relative to ${prefix}/${rootprefix}/${sysconfdir}
[thirdparty/systemd.git] / src / shared / web-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <stdbool.h>
4
5 #include "string-util.h"
6 #include "strv.h"
7 #include "utf8.h"
8 #include "web-util.h"
9
10 bool http_etag_is_valid(const char *etag) {
11 if (isempty(etag))
12 return false;
13
14 if (!endswith(etag, "\""))
15 return false;
16
17 if (!STARTSWITH_SET(etag, "\"", "W/\""))
18 return false;
19
20 return true;
21 }
22
23 bool http_url_is_valid(const char *url) {
24 const char *p;
25
26 if (isempty(url))
27 return false;
28
29 p = STARTSWITH_SET(url, "http://", "https://");
30 if (!p)
31 return false;
32
33 if (isempty(p))
34 return false;
35
36 return ascii_is_valid(p);
37 }
38
39 bool documentation_url_is_valid(const char *url) {
40 const char *p;
41
42 if (isempty(url))
43 return false;
44
45 if (http_url_is_valid(url))
46 return true;
47
48 p = STARTSWITH_SET(url, "file:/", "info:", "man:");
49 if (isempty(p))
50 return false;
51
52 return ascii_is_valid(p);
53 }