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