]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
49cf4170 LP |
2 | |
3 | #include <stdbool.h> | |
4 | ||
5 | #include "string-util.h" | |
6 | #include "utf8.h" | |
7 | #include "web-util.h" | |
8 | ||
9 | bool http_etag_is_valid(const char *etag) { | |
10 | if (isempty(etag)) | |
11 | return false; | |
12 | ||
13 | if (!endswith(etag, "\"")) | |
14 | return false; | |
15 | ||
16 | if (!startswith(etag, "\"") && !startswith(etag, "W/\"")) | |
17 | return false; | |
18 | ||
19 | return true; | |
20 | } | |
21 | ||
22 | bool http_url_is_valid(const char *url) { | |
23 | const char *p; | |
24 | ||
25 | if (isempty(url)) | |
26 | return false; | |
27 | ||
28 | p = startswith(url, "http://"); | |
29 | if (!p) | |
30 | p = startswith(url, "https://"); | |
31 | if (!p) | |
32 | return false; | |
33 | ||
34 | if (isempty(p)) | |
35 | return false; | |
36 | ||
37 | return ascii_is_valid(p); | |
38 | } | |
39 | ||
40 | bool documentation_url_is_valid(const char *url) { | |
41 | const char *p; | |
42 | ||
43 | if (isempty(url)) | |
44 | return false; | |
45 | ||
46 | if (http_url_is_valid(url)) | |
47 | return true; | |
48 | ||
49 | p = startswith(url, "file:/"); | |
50 | if (!p) | |
51 | p = startswith(url, "info:"); | |
52 | if (!p) | |
53 | p = startswith(url, "man:"); | |
54 | ||
55 | if (isempty(p)) | |
56 | return false; | |
57 | ||
58 | return ascii_is_valid(p); | |
59 | } |