1 #ifndef URI_H
 2 #define URI_H
 3 
 4 #include "rh_buffer.h"
 5 #include "http_host.h"
 6 
 7 typedef struct uri      uri_t;
 8 
 9 enum {
10         URI_SCHEME_UNSET,
11         URI_SCHEME_HTTP,
12         URI_SCHEME_HTTPS,
13         URI_SCHEME_FTP,
14 };
15         
16 enum {  /* order is importend for the parser */
17         URI_DECODE_STATE_USER           = 1,
18         URI_DECODE_STATE_PASS           = 2,
19         URI_DECODE_STATE_HOST           = 4,
20         URI_DECODE_STATE_PORT           = 8,
21         URI_DECODE_STATE_PATH           = 16,
22         URI_DECODE_STATE_QUERY          = 32,
23         URI_DECODE_STATE_FRAGMENT       = 64,
24 };
25 
26 #define URI_HAVE(_uri,_what)                                    \
27         ( (_uri)->decode_state & URI_DECODE_STATE_ ## _what )
28 
29 #define URI_HAVE_USER(_uri)     URI_HAVE(_uri,USER)
30 #define URI_HAVE_PASS(_uri)     URI_HAVE(_uri,PASS)
31 #define URI_HAVE_HOST(_uri)     URI_HAVE(_uri,HOST)
32 #define URI_HAVE_PORT(_uri)     URI_HAVE(_uri,PORT)
33 #define URI_HAVE_PATH(_uri)     URI_HAVE(_uri,PATH)
34 #define URI_HAVE_QUERY(_uri)    URI_HAVE(_uri,QUERY)
35 #define URI_HAVE_FRAGMENT(_uri) URI_HAVE(_uri,FRAGMENT)
36 
37 /* 
38  * the buffers in this structure (expect filename) are mostly
39  * constant to the decoded buffer, dont try to append data to it.
40  *
41  *
42  */
43 struct uri {
44         /* raw undecoded/parsed uri, may contain illegal characters */
45         rh_buffer_t     raw;
46         
47         /* the decoded uri, may contain illegal characters */
48         rh_buffer_t     decoded;
49 
50         /* uri to use for logging, all illegal characters are escaped */
51         rh_buffer_t     log;
52 
53         /* uri components, all in a valid state */
54         
55         rh_buffer_t     user;
56         rh_buffer_t     pass;
57 
58         http_host_t     host;
59         
60         rh_buffer_t     path;
61         
62         /* query may contain "strange" (but hex encoded) characters 
63          * like: %00 */
64         rh_buffer_t     query;
65 
66         rh_buffer_t     fragment;
67         
68         /* physical filename */
69         
70         rh_buffer_t     filename;
71 
72         /* may asked what fields are filled */
73         int             decode_state;
74 };
75 
76 void uri_init    (uri_t *);
77 void uri_destroy (uri_t *);
78 void uri_reset   (uri_t *);
79 
80 void uri_dump    (uri_t *uri);
81 
82 
83 int uri_parse (uri_t *uri, const char *src, size_t nsrc);
84 
85 #endif /* URI_H */


syntax highlighted by Code2HTML, v. 0.9.1