equal
deleted
inserted
replaced
|
1 #ifndef LIB_URL_H |
|
2 #define LIB_URL_H |
|
3 |
|
4 /* |
|
5 * A trivial parser for simple URLs |
|
6 * |
|
7 * [ <scheme> [ "+" <scheme> [ ... ] ] "://" ] [ <username> [ ":" <password> ] "@" ] <hostname> [ ":" <service> ] [ "/" <path> ] [ "?" [ <key> [ "=" <value> ] ] [ "&" [ <key> [ "=" <value> ] ] [ ... ] ] |
|
8 * |
|
9 * example.com |
|
10 * tcp://example.com:7348/ |
|
11 * psql://postgres@localhost/test_db?charset=utf8 |
|
12 * |
|
13 */ |
|
14 |
|
15 /* |
|
16 * The schema |
|
17 */ |
|
18 struct url_schema { |
|
19 size_t count; |
|
20 const char **list; |
|
21 }; |
|
22 |
|
23 /* |
|
24 * The options at the end |
|
25 */ |
|
26 struct url_opts { |
|
27 size_t count; |
|
28 struct url_opt { |
|
29 const char *key; |
|
30 const char *value; |
|
31 } *list; |
|
32 }; |
|
33 |
|
34 /* |
|
35 * A parsed URL |
|
36 */ |
|
37 struct url { |
|
38 struct url_schema *schema; |
|
39 const char *username; |
|
40 const char *password; |
|
41 const char *hostname; |
|
42 const char *service; |
|
43 const char *path; |
|
44 struct url_opts *opts; |
|
45 }; |
|
46 |
|
47 /* |
|
48 * Parse the given `text` as an URL, returning the result in `url`. Optional fields that are missing in the text will |
|
49 * cause those values to be returned unmodified. |
|
50 */ |
|
51 int url_parse (struct url *url, const char *text); |
|
52 |
|
53 #endif /* LIB_URL_H */ |