Debian Codegraph @

src/shared/web-util.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "string-util.h"
4 #include "strv.h"
5 #include "utf8.h"
6 #include "web-util.h"
7
8 bool http_url_is_valid(const char *url) {
9 const char *p;
10
11 if (isempty(url))
12 return false;
13
14 p = STARTSWITH_SET(url, "http://", "https://");
15 if (!p)
16 return false;
17
18 if (isempty(p))
19 return false;
20
21 return ascii_is_valid(p);
22 }
23
24 bool file_url_is_valid(const char *url) {
25 const char *p;
26
27 if (isempty(url))
28 return false;
29
30 p = startswith(url, "file:/");
31 if (isempty(p))
32 return false;
33
34 return ascii_is_valid(p);
35 }
36
37 bool documentation_url_is_valid(const char *url) {
38 const char *p;
39
40 if (isempty(url))
41 return false;
42
43 if (http_url_is_valid(url) || file_url_is_valid(url))
44 return true;
45
46 p = STARTSWITH_SET(url, "info:", "man:");
47 if (isempty(p))
48 return false;
49
50 return ascii_is_valid(p);
51 }
52
53 bool http_header_valid(const char *header) {
54 return header &&
55 ascii_is_valid(header) &&
56 !string_has_cc(header, /* ok= */ NULL) &&
57 strchr(header, ':');
58 }
59
60 bool http_etag_is_valid(const char *etag) {
61 if (isempty(etag))
62 return false;
63
64 if (!endswith(etag, "\""))
65 return false;
66
67 if (!STARTSWITH_SET(etag, "\"", "W/\""))
68 return false;
69
70 return true;
71 }