]> mj.ucw.cz Git - libucw.git/blob - lib/url.h
install sorter-globals.h header
[libucw.git] / lib / 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 #define NCC_SEMICOLON 1
19 #define NCC_SLASH 2
20 #define NCC_QUEST 3
21 #define NCC_COLON 4
22 #define NCC_AT 5
23 #define NCC_EQUAL 6
24 #define NCC_AND 7
25 #define NCC_HASH 8
26 #define NCC_MAX 9
27
28 #define NCC_CHARS " ;/?:@=&#"
29
30 /* Remove/Introduce '%' escapes */
31
32 int url_deescape(byte *s, byte *d);
33 int url_enescape(byte *s, byte *d);
34 int url_enescape_friendly(byte *src, byte *dest);       // for cards.c only
35
36 /* URL splitting and normalization */
37
38 struct url {
39   byte *protocol;
40   uns protoid;
41   byte *user;
42   byte *pass;
43   byte *host;
44   uns port;                             /* ~0 if unspec */
45   byte *rest;
46   byte *buf, *bufend;
47 };
48
49 int url_split(byte *s, struct url *u, byte *d);
50 int url_normalize(struct url *u, struct url *b);
51 int url_canonicalize(struct url *u);
52 int url_pack(struct url *u, byte *d);
53 int url_canon_split_rel(byte *url, byte *buf1, byte *buf2, struct url *u, struct url *base);
54 int url_auto_canonicalize_rel(byte *src, byte *dst, struct url *base);
55 uns identify_protocol(byte *p);
56 int url_has_repeated_component(byte *url);
57
58 static inline int url_canon_split(byte *url, byte *buf1, byte *buf2, struct url *u)
59 { return url_canon_split_rel(url, buf1, buf2, u, NULL); }
60
61 static inline int url_auto_canonicalize(byte *src, byte *dst)
62 { return url_auto_canonicalize_rel(src, dst, NULL); }
63
64 /* Error codes */
65
66 char *url_error(uns);
67
68 #define URL_ERR_TOO_LONG 1
69 #define URL_ERR_INVALID_CHAR 2
70 #define URL_ERR_INVALID_ESCAPE 3
71 #define URL_ERR_INVALID_ESCAPED_CHAR 4
72 #define URL_ERR_INVALID_PORT 5
73 #define URL_ERR_REL_NOTHING 6
74 #define URL_ERR_UNKNOWN_PROTOCOL 7
75 #define URL_SYNTAX_ERROR 8
76 #define URL_PATH_UNDERFLOW 9
77
78 #define URL_PROTO_UNKNOWN 0
79 #define URL_PROTO_HTTP 1
80 #define URL_PROTO_FTP 2
81 #define URL_PROTO_FILE 3
82 #define URL_PROTO_MAX 4
83
84 #define URL_PNAMES { "unknown", "http", "ftp", "file" }
85 #define URL_DEFPORTS { ~0, 80, 21, 0 }
86 #define URL_PATH_FLAGS { 0, 1, 1, 1 }
87
88 extern byte *url_proto_names[];
89
90 #endif