http-url.h revision e641c9f656f1788ca6226ef0d60b2d592e2ca6d1
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen#ifndef HTTP_URL_H
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen#define HTTP_URL_H
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen
46552a931924c2d743f045e95b08c3ce6beda91aTimo Sirainen#include "net.h"
ce1a6c9b82117d253df9acd77e54ac84dd8a247eTimo Sirainen
c5f932968281763df360b9c97cef60f5f80d5e3dTimo Sirainenstruct http_request_target;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstruct http_url {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* server */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen const char *host_name;
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen struct ip_addr host_ip;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen in_port_t port;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
de754cb78f75e8b3b994cddafe41c9ed1467c33dTimo Sirainen /* path */
f29756821a4c6b12b73e4a2a3e1c230117a43773Timo Sirainen const char *path;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* ?query (still encoded) */
53dfcefa9440a49d703e49193819a79be99c9ba6Timo Sirainen const char *enc_query;
f0d93763f210ecdb85a115fdd0210a16cfc5ff5cTimo Sirainen
53dfcefa9440a49d703e49193819a79be99c9ba6Timo Sirainen /* #fragment (still encoded) */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen const char *enc_fragment;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen unsigned int have_host_ip:1; /* URL uses IP address */
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen unsigned int have_port:1;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen unsigned int have_ssl:1;
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch};
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch/*
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch * HTTP URL parsing
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch */
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Boschenum http_url_parse_flags {
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch /* Scheme part 'http:' is already parsed externally. This implies that
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch this is an absolute HTTP URL. */
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch HTTP_URL_PARSE_SCHEME_EXTERNAL = 0x01,
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch /* Allow '#fragment' part in URL */
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch HTTP_URL_ALLOW_FRAGMENT_PART = 0x02
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch};
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Boschint http_url_parse(const char *url, struct http_url *base,
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch enum http_url_parse_flags flags, pool_t pool,
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch struct http_url **url_r, const char **error_r);
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Boschint http_url_request_target_parse(const char *request_target,
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch const char *host_header, pool_t pool,
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch struct http_request_target *target, const char **error_r);
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch/*
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch * HTTP URL construction
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch */
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Boschconst char *http_url_create(const struct http_url *url);
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Boschconst char *http_url_create_target(const struct http_url *url);
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Bosch
36b072d84a9076c3c483bf710444a716e987ccc3Stephan Boschvoid http_url_escape_param(string_t *out, const char *data);
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen#endif
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen