]> mj.ucw.cz Git - libucw.git/blob - ucw/url.h
tableprinter: update of tests
[libucw.git] / ucw / url.h
1 /*
2  *      UCW Library -- URL Functions
3  *
4  *      (c) 1997--2004 Martin Mares <mj@ucw.cz>
5  *      (c) 2001 Robert Spalek <robert@ucw.cz>
6  *
7  *      This software may be freely distributed and used according to the terms
8  *      of the GNU Lesser General Public License.
9  */
10
11 #ifndef _UCW_URL_H
12 #define _UCW_URL_H
13
14 #ifdef CONFIG_UCW_CLEAN_ABI
15 #define url_auto_canonicalize_rel ucw_url_auto_canonicalize_rel
16 #define url_canon_split_rel ucw_url_canon_split_rel
17 #define url_canonicalize ucw_url_canonicalize
18 #define url_deescape ucw_url_deescape
19 #define url_enescape ucw_url_enescape
20 #define url_enescape_friendly ucw_url_enescape_friendly
21 #define url_error ucw_url_error
22 #define url_has_repeated_component ucw_url_has_repeated_component
23 #define url_identify_protocol ucw_url_identify_protocol
24 #define url_normalize ucw_url_normalize
25 #define url_pack ucw_url_pack
26 #define url_proto_names ucw_url_proto_names
27 #define url_split ucw_url_split
28 #endif
29
30 #define MAX_URL_SIZE 1024
31
32 /* Non-control meanings of control characters */
33
34 enum {
35   NCC_SEMICOLON = 1,
36   NCC_SLASH = 2,
37   NCC_QUEST = 3,
38   NCC_COLON = 4,
39   NCC_AT = 5,
40   NCC_EQUAL = 6,
41   NCC_AND = 7,
42   NCC_HASH = 8,
43   // Avoid 9 (\t) and 10 (\n)
44   NCC_DOLLAR = 11,
45   NCC_PLUS = 12,
46   // Avoid 13 (\r)
47   NCC_COMMA = 14,
48   NCC_MAX = 15
49 };
50
51 #define NCC_CHARS " ;/?:@=&#\t\n$+\r,"
52
53 /* Remove/Introduce '%' escapes */
54
55 int url_deescape(const char *s, char *d);
56 int url_enescape(const char *s, char *d);
57 int url_enescape_friendly(const char *src, char *dest);
58
59 /* URL splitting and normalization */
60
61 struct url {
62   char *protocol;
63   uint protoid;
64   char *user;
65   char *pass;
66   char *host;
67   uint port;                            /* ~0 if unspec */
68   char *rest;
69   char *buf, *bufend;
70 };
71
72 int url_split(char *s, struct url *u, char *d);
73 int url_normalize(struct url *u, struct url *b);
74 int url_canonicalize(struct url *u);
75 int url_pack(struct url *u, char *d);
76 int url_canon_split_rel(const char *url, char *buf1, char *buf2, struct url *u, struct url *base);
77 int url_auto_canonicalize_rel(const char *src, char *dst, struct url *base);
78 uint url_identify_protocol(const char *p);
79 int url_has_repeated_component(const char *url);
80
81 static inline int url_canon_split(const char *url, char *buf1, char *buf2, struct url *u)
82 { return url_canon_split_rel(url, buf1, buf2, u, NULL); }
83
84 static inline int url_auto_canonicalize(const char *src, char *dst)
85 { return url_auto_canonicalize_rel(src, dst, NULL); }
86
87 /* Error codes */
88
89 char *url_error(uint);
90
91 #define URL_ERR_TOO_LONG 1
92 #define URL_ERR_INVALID_CHAR 2
93 #define URL_ERR_INVALID_ESCAPE 3
94 #define URL_ERR_INVALID_ESCAPED_CHAR 4
95 #define URL_ERR_INVALID_PORT 5
96 #define URL_ERR_REL_NOTHING 6
97 #define URL_ERR_UNKNOWN_PROTOCOL 7
98 #define URL_SYNTAX_ERROR 8
99 #define URL_PATH_UNDERFLOW 9
100
101 #define URL_PROTO_UNKNOWN 0
102 #define URL_PROTO_HTTP 1
103 #define URL_PROTO_FTP 2
104 #define URL_PROTO_FILE 3
105 #define URL_PROTO_MAX 4
106
107 #define URL_PNAMES { "unknown", "http", "ftp", "file" }
108 #define URL_DEFPORTS { ~0, 80, 21, 0 }
109 #define URL_PATH_FLAGS { 0, 1, 1, 1 }
110
111 extern char *url_proto_names[];
112
113 #endif