/src/dovecot/src/lib-http/http-url.h
Line | Count | Source |
1 | | #ifndef HTTP_URL_H |
2 | | #define HTTP_URL_H |
3 | | |
4 | | #include "net.h" |
5 | | #include "uri-util.h" |
6 | | |
7 | | #include "http-common.h" |
8 | | |
9 | | struct http_request_target; |
10 | | |
11 | | struct http_url { |
12 | | /* server */ |
13 | | struct uri_host host; |
14 | | in_port_t port; |
15 | | |
16 | | /* userinfo (not parsed by default) */ |
17 | | const char *user; |
18 | | const char *password; |
19 | | |
20 | | /* path */ |
21 | | const char *enc_path; /* encoded */ |
22 | | const char *path; |
23 | | |
24 | | /* ?query (still encoded) */ |
25 | | const char *enc_query; |
26 | | |
27 | | /* #fragment (still encoded) */ |
28 | | const char *enc_fragment; |
29 | | |
30 | | bool have_ssl:1; |
31 | | }; |
32 | | |
33 | | /* |
34 | | * HTTP URL parsing |
35 | | */ |
36 | | |
37 | | enum http_url_parse_flags { |
38 | | /* Scheme part 'http:' is already parsed externally. This implies that |
39 | | this is an absolute HTTP URL. */ |
40 | | HTTP_URL_PARSE_SCHEME_EXTERNAL = 0x01, |
41 | | /* Allow '#fragment' part in HTTP URL */ |
42 | | HTTP_URL_ALLOW_FRAGMENT_PART = 0x02, |
43 | | /* Allow 'user:password@' part in HTTP URL */ |
44 | | HTTP_URL_ALLOW_USERINFO_PART = 0x04, |
45 | | /* Allow URL to contain %00 */ |
46 | | HTTP_URL_ALLOW_PCT_NUL = 0x08, |
47 | | }; |
48 | | |
49 | | int http_url_parse(const char *url, struct http_url *base, |
50 | | enum http_url_parse_flags flags, pool_t pool, |
51 | | struct http_url **url_r, const char **error_r); |
52 | | |
53 | | int http_url_request_target_parse(const char *request_target, |
54 | | const char *host_header, |
55 | | const struct http_url *default_base, |
56 | | pool_t pool, |
57 | | struct http_request_target *target, |
58 | | const char **error_r) ATTR_NULL(3); |
59 | | |
60 | | /* |
61 | | * HTTP URL evaluation |
62 | | */ |
63 | | |
64 | | static inline in_port_t |
65 | | http_url_get_port_default(const struct http_url *url, in_port_t default_port) |
66 | 0 | { |
67 | 0 | return (url->port != 0 ? url->port : default_port); |
68 | 0 | } |
69 | | |
70 | | static inline in_port_t http_url_get_port(const struct http_url *url) |
71 | 0 | { |
72 | 0 | return http_url_get_port_default( |
73 | 0 | url, (url->have_ssl ? HTTPS_DEFAULT_PORT : HTTP_DEFAULT_PORT)); |
74 | 0 | } |
75 | | |
76 | | /* |
77 | | * HTTP URL manipulation |
78 | | */ |
79 | | |
80 | | void http_url_init_authority_from(struct http_url *dest, |
81 | | const struct http_url *src); |
82 | | void http_url_copy_authority(pool_t pool, struct http_url *dest, |
83 | | const struct http_url *src); |
84 | | struct http_url * |
85 | | http_url_clone_authority(pool_t pool, const struct http_url *src); |
86 | | |
87 | | void http_url_copy(pool_t pool, struct http_url *dest, |
88 | | const struct http_url *src); |
89 | | void http_url_copy_with_userinfo(pool_t pool, struct http_url *dest, |
90 | | const struct http_url *src); |
91 | | |
92 | | struct http_url *http_url_clone(pool_t pool,const struct http_url *src); |
93 | | struct http_url * |
94 | | http_url_clone_with_userinfo(pool_t pool, const struct http_url *src); |
95 | | |
96 | | /* |
97 | | * HTTP URL construction |
98 | | */ |
99 | | |
100 | | const char *http_url_create(const struct http_url *url); |
101 | | |
102 | | const char *http_url_create_host(const struct http_url *url); |
103 | | const char *http_url_create_authority(const struct http_url *url); |
104 | | const char *http_url_create_target(const struct http_url *url); |
105 | | |
106 | | void http_url_escape_path(string_t *out, const char *data); |
107 | | void http_url_escape_param(string_t *out, const char *data); |
108 | | |
109 | | #endif |