]> mj.ucw.cz Git - libucw.git/blob - lib/url.h
Removed xprintf() -- it was very ugly and its only raison d'etre was
[libucw.git] / lib / url.h
1 /*
2  *      Sherlock Library -- URL Functions
3  *
4  *      (c) 1997--2002 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 _SHERLOCK_URL_H
12 #define _SHERLOCK_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 *, byte *);
33 int url_enescape(byte *, byte *);
34
35 /* URL splitting and normalization */
36
37 struct url {
38   byte *protocol;
39   uns protoid;
40   byte *user;
41   byte *pass;
42   byte *host;
43   uns port;                             /* ~0 if unspec */
44   byte *rest;
45   byte *buf, *bufend;
46 };
47
48 int url_split(byte *, struct url *, byte *);
49 int url_normalize(struct url *, struct url *);
50 int url_canonicalize(struct url *);
51 int url_pack(struct url *, byte *);
52 int url_canon_split(byte *, byte *, byte *, struct url *);
53 int url_auto_canonicalize(byte *, byte *);
54 uns identify_protocol(byte *);
55 int url_has_repeated_component(byte *url);
56
57 /* Error codes */
58
59 char *url_error(uns);
60
61 #define URL_ERR_TOO_LONG 1
62 #define URL_ERR_INVALID_CHAR 2
63 #define URL_ERR_INVALID_ESCAPE 3
64 #define URL_ERR_INVALID_ESCAPED_CHAR 4
65 #define URL_ERR_INVALID_PORT 5
66 #define URL_ERR_REL_NOTHING 6
67 #define URL_ERR_UNKNOWN_PROTOCOL 7
68 #define URL_SYNTAX_ERROR 8
69 #define URL_PATH_UNDERFLOW 9
70
71 #define URL_PROTO_UNKNOWN 0
72 #define URL_PROTO_HTTP 1
73 #define URL_PROTO_FTP 2
74 #define URL_PROTO_FILE 3
75 #define URL_PROTO_MAX 4
76
77 #define URL_PNAMES { "unknown", "http", "ftp", "file" }
78 #define URL_DEFPORTS { ~0, 80, 21, 0 }
79 #define URL_PATH_FLAGS { 0, 1, 1, 1 }
80
81 extern byte *url_proto_names[];
82
83 #endif