]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/web-util.c
ci: re-enable uefi secure boot
[thirdparty/systemd.git] / src / shared / web-util.c
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
49cf4170 2
49cf4170 3#include "string-util.h"
49fe5c09 4#include "strv.h"
49cf4170
LP
5#include "utf8.h"
6#include "web-util.h"
7
8bool http_etag_is_valid(const char *etag) {
9 if (isempty(etag))
10 return false;
11
12 if (!endswith(etag, "\""))
13 return false;
14
49fe5c09 15 if (!STARTSWITH_SET(etag, "\"", "W/\""))
49cf4170
LP
16 return false;
17
18 return true;
19}
20
21bool http_url_is_valid(const char *url) {
22 const char *p;
23
24 if (isempty(url))
25 return false;
26
49fe5c09 27 p = STARTSWITH_SET(url, "http://", "https://");
49cf4170
LP
28 if (!p)
29 return false;
30
31 if (isempty(p))
32 return false;
33
34 return ascii_is_valid(p);
35}
36
c456862f
LP
37bool 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
49cf4170
LP
50bool documentation_url_is_valid(const char *url) {
51 const char *p;
52
53 if (isempty(url))
54 return false;
55
c456862f 56 if (http_url_is_valid(url) || file_url_is_valid(url))
49cf4170
LP
57 return true;
58
c456862f 59 p = STARTSWITH_SET(url, "info:", "man:");
49cf4170
LP
60 if (isempty(p))
61 return false;
62
63 return ascii_is_valid(p);
64}