]> mj.ucw.cz Git - libucw.git/blob - ucw/url.h
Logging: Introduce LS_NUM_TYPES and use it.
[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 #define MAX_URL_SIZE 1024
15
16 /* Non-control meanings of control characters */
17
18 enum {
19   NCC_SEMICOLON = 1,
20   NCC_SLASH = 2,
21   NCC_QUEST = 3,
22   NCC_COLON = 4,
23   NCC_AT = 5,
24   NCC_EQUAL = 6,
25   NCC_AND = 7,
26   NCC_HASH = 8,
27 #ifdef CONFIG_URL_ESCAPE_COMPAT
28   NCC_MAX = 9
29 #else
30   // Avoid 9 (\t) and 10 (\n)
31   NCC_DOLLAR = 11,
32   NCC_PLUS = 12,
33   // Avoid 13 (\r)
34   NCC_COMMA = 14,
35   NCC_MAX = 15
36 #endif
37 };
38
39 #ifdef CONFIG_URL_ESCAPE_COMPAT
40 #define NCC_CHARS " ;/?:@=&#"
41 #else
42 #define NCC_CHARS " ;/?:@=&#\t\n$+\r,"
43 #endif
44
45 /* Remove/Introduce '%' escapes */
46
47 int url_deescape(const char *s, char *d);
48 int url_enescape(const char *s, char *d);
49 int url_enescape_friendly(const char *src, char *dest);
50
51 /* URL splitting and normalization */
52
53 struct url {
54   char *protocol;
55   uns protoid;
56   char *user;
57   char *pass;
58   char *host;
59   uns port;                             /* ~0 if unspec */
60   char *rest;
61   char *buf, *bufend;
62 };
63
64 int url_split(char *s, struct url *u, char *d);
65 int url_normalize(struct url *u, struct url *b);
66 int url_canonicalize(struct url *u);
67 int url_pack(struct url *u, char *d);
68 int url_canon_split_rel(const char *url, char *buf1, char *buf2, struct url *u, struct url *base);
69 int url_auto_canonicalize_rel(const char *src, char *dst, struct url *base);
70 uns url_identify_protocol(const char *p);
71 int url_has_repeated_component(const char *url);
72
73 static inline int url_canon_split(const char *url, char *buf1, char *buf2, struct url *u)
74 { return url_canon_split_rel(url, buf1, buf2, u, NULL); }
75
76 static inline int url_auto_canonicalize(const char *src, char *dst)
77 { return url_auto_canonicalize_rel(src, dst, NULL); }
78
79 /* Error codes */
80
81 char *url_error(uns);
82
83 #define URL_ERR_TOO_LONG 1
84 #define URL_ERR_INVALID_CHAR 2
85 #define URL_ERR_INVALID_ESCAPE 3
86 #define URL_ERR_INVALID_ESCAPED_CHAR 4
87 #define URL_ERR_INVALID_PORT 5
88 #define URL_ERR_REL_NOTHING 6
89 #define URL_ERR_UNKNOWN_PROTOCOL 7
90 #define URL_SYNTAX_ERROR 8
91 #define URL_PATH_UNDERFLOW 9
92
93 #define URL_PROTO_UNKNOWN 0
94 #define URL_PROTO_HTTP 1
95 #define URL_PROTO_FTP 2
96 #define URL_PROTO_FILE 3
97 #define URL_PROTO_MAX 4
98
99 #define URL_PNAMES { "unknown", "http", "ftp", "file" }
100 #define URL_DEFPORTS { ~0, 80, 21, 0 }
101 #define URL_PATH_FLAGS { 0, 1, 1, 1 }
102
103 extern char *url_proto_names[];
104
105 #endif