]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/web-util.c
Merge pull request #7376 from keszybz/simplify-root-options
[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 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #include <stdbool.h>
22
23 #include "string-util.h"
24 #include "utf8.h"
25 #include "web-util.h"
26
27 bool http_etag_is_valid(const char *etag) {
28 if (isempty(etag))
29 return false;
30
31 if (!endswith(etag, "\""))
32 return false;
33
34 if (!startswith(etag, "\"") && !startswith(etag, "W/\""))
35 return false;
36
37 return true;
38 }
39
40 bool http_url_is_valid(const char *url) {
41 const char *p;
42
43 if (isempty(url))
44 return false;
45
46 p = startswith(url, "http://");
47 if (!p)
48 p = startswith(url, "https://");
49 if (!p)
50 return false;
51
52 if (isempty(p))
53 return false;
54
55 return ascii_is_valid(p);
56 }
57
58 bool documentation_url_is_valid(const char *url) {
59 const char *p;
60
61 if (isempty(url))
62 return false;
63
64 if (http_url_is_valid(url))
65 return true;
66
67 p = startswith(url, "file:/");
68 if (!p)
69 p = startswith(url, "info:");
70 if (!p)
71 p = startswith(url, "man:");
72
73 if (isempty(p))
74 return false;
75
76 return ascii_is_valid(p);
77 }