5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch#ifndef HTTP_URL_H
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch#define HTTP_URL_H
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
9f8559a5ac7b53b83378c894de6578773dc1e392Timo Sirainen#include "net.h"
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch#include "uri-util.h"
9f8559a5ac7b53b83378c894de6578773dc1e392Timo Sirainen
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch#include "http-common.h"
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch
e641c9f656f1788ca6226ef0d60b2d592e2ca6d1Stephan Boschstruct http_request_target;
e641c9f656f1788ca6226ef0d60b2d592e2ca6d1Stephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschstruct http_url {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch /* server */
f74dbd3ff682fea040f60383e001620d1f1b09d3Stephan Bosch struct uri_host host;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch in_port_t port;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch /* userinfo (not parsed by default) */
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch const char *user;
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch const char *password;
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch /* path */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch const char *path;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch /* ?query (still encoded) */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch const char *enc_query;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch /* #fragment (still encoded) */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch const char *enc_fragment;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool have_ssl:1;
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch};
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch/*
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch * HTTP URL parsing
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschenum http_url_parse_flags {
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch /* Scheme part 'http:' is already parsed externally. This implies that
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch this is an absolute HTTP URL. */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch HTTP_URL_PARSE_SCHEME_EXTERNAL = 0x01,
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch /* Allow '#fragment' part in HTTP URL */
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch HTTP_URL_ALLOW_FRAGMENT_PART = 0x02,
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch /* Allow 'user:password@' part in HTTP URL */
89e040049336e69c43fec09dcbdfd0f2ae5efd51Martti Rannanjärvi HTTP_URL_ALLOW_USERINFO_PART = 0x04,
89e040049336e69c43fec09dcbdfd0f2ae5efd51Martti Rannanjärvi /* Allow URL to contain %00 */
89e040049336e69c43fec09dcbdfd0f2ae5efd51Martti Rannanjärvi HTTP_URL_ALLOW_PCT_NUL = 0x08,
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch};
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschint http_url_parse(const char *url, struct http_url *base,
d45ab3fff7c47f1719b9cd310228c0dac2bdd1b2Timo Sirainen enum http_url_parse_flags flags, pool_t pool,
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch struct http_url **url_r, const char **error_r);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
e641c9f656f1788ca6226ef0d60b2d592e2ca6d1Stephan Boschint http_url_request_target_parse(const char *request_target,
e641c9f656f1788ca6226ef0d60b2d592e2ca6d1Stephan Bosch const char *host_header, pool_t pool,
e641c9f656f1788ca6226ef0d60b2d592e2ca6d1Stephan Bosch struct http_request_target *target, const char **error_r);
e641c9f656f1788ca6226ef0d60b2d592e2ca6d1Stephan Bosch
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch/*
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch * HTTP URL evaluation
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch */
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch
777776de3515b6721381d2230c4182b6401cdce1Stephan Boschstatic inline in_port_t http_url_get_port_default(const struct http_url *url,
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch in_port_t default_port)
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch{
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch return (url->port != 0 ? url->port : default_port);
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch}
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch
777776de3515b6721381d2230c4182b6401cdce1Stephan Boschstatic inline in_port_t http_url_get_port(const struct http_url *url)
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch{
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch return http_url_get_port_default(url,
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch (url->have_ssl ? HTTPS_DEFAULT_PORT : HTTP_DEFAULT_PORT));
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch}
777776de3515b6721381d2230c4182b6401cdce1Stephan Bosch
d82ad7143c057c565e1fd5f3580645556ed0bcc9Stephan Bosch/*
d82ad7143c057c565e1fd5f3580645556ed0bcc9Stephan Bosch * HTTP URL manipulation
d82ad7143c057c565e1fd5f3580645556ed0bcc9Stephan Bosch */
d82ad7143c057c565e1fd5f3580645556ed0bcc9Stephan Bosch
d82ad7143c057c565e1fd5f3580645556ed0bcc9Stephan Boschvoid http_url_copy_authority(pool_t pool, struct http_url *dest,
d82ad7143c057c565e1fd5f3580645556ed0bcc9Stephan Bosch const struct http_url *src);
4356563bc3261a4043ec736cb1009373d37a617cStephan Boschstruct http_url *http_url_clone_authority(pool_t pool,
4356563bc3261a4043ec736cb1009373d37a617cStephan Bosch const struct http_url *src);
4356563bc3261a4043ec736cb1009373d37a617cStephan Bosch
d82ad7143c057c565e1fd5f3580645556ed0bcc9Stephan Boschvoid http_url_copy(pool_t pool, struct http_url *dest,
d82ad7143c057c565e1fd5f3580645556ed0bcc9Stephan Bosch const struct http_url *src);
92c2272787b74eb000f05a926e9103a25a6a0dc0Stephan Boschvoid http_url_copy_with_userinfo(pool_t pool, struct http_url *dest,
92c2272787b74eb000f05a926e9103a25a6a0dc0Stephan Bosch const struct http_url *src);
92c2272787b74eb000f05a926e9103a25a6a0dc0Stephan Bosch
d82ad7143c057c565e1fd5f3580645556ed0bcc9Stephan Boschstruct http_url *http_url_clone(pool_t pool,const struct http_url *src);
92c2272787b74eb000f05a926e9103a25a6a0dc0Stephan Boschstruct http_url *http_url_clone_with_userinfo(pool_t pool,
92c2272787b74eb000f05a926e9103a25a6a0dc0Stephan Bosch const struct http_url *src);
d82ad7143c057c565e1fd5f3580645556ed0bcc9Stephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch/*
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch * HTTP URL construction
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschconst char *http_url_create(const struct http_url *url);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch
d82ad7143c057c565e1fd5f3580645556ed0bcc9Stephan Boschconst char *http_url_create_host(const struct http_url *url);
d82ad7143c057c565e1fd5f3580645556ed0bcc9Stephan Boschconst char *http_url_create_authority(const struct http_url *url);
069def4dc35022852d569b7ab75a3b19d2cb0f1cTimo Sirainenconst char *http_url_create_target(const struct http_url *url);
069def4dc35022852d569b7ab75a3b19d2cb0f1cTimo Sirainen
a952a4444e46e107b15ab1bd0e8b63a29f94b123Timo Sirainenvoid http_url_escape_path(string_t *out, const char *data);
c911297407bdcc7c7936305eb8f791b450d6375cTimo Sirainenvoid http_url_escape_param(string_t *out, const char *data);
c911297407bdcc7c7936305eb8f791b450d6375cTimo Sirainen
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch#endif