]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/web-util.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / shared / web-util.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
49cf4170
LP
2
3#include <stdbool.h>
4
5#include "string-util.h"
49fe5c09 6#include "strv.h"
49cf4170
LP
7#include "utf8.h"
8#include "web-util.h"
9
10bool http_etag_is_valid(const char *etag) {
11 if (isempty(etag))
12 return false;
13
14 if (!endswith(etag, "\""))
15 return false;
16
49fe5c09 17 if (!STARTSWITH_SET(etag, "\"", "W/\""))
49cf4170
LP
18 return false;
19
20 return true;
21}
22
23bool http_url_is_valid(const char *url) {
24 const char *p;
25
26 if (isempty(url))
27 return false;
28
49fe5c09 29 p = STARTSWITH_SET(url, "http://", "https://");
49cf4170
LP
30 if (!p)
31 return false;
32
33 if (isempty(p))
34 return false;
35
36 return ascii_is_valid(p);
37}
38
39bool 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
49fe5c09 48 p = STARTSWITH_SET(url, "file:/", "info:", "man:");
49cf4170
LP
49 if (isempty(p))
50 return false;
51
52 return ascii_is_valid(p);
53}