http-url.h revision d82ad7143c057c565e1fd5f3580645556ed0bcc9
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainen#ifndef HTTP_URL_H
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainen#define HTTP_URL_H
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainen
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen#include "net.h"
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainen
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainenstruct http_request_target;
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainenstruct http_url {
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen /* server */
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen const char *host_name;
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen struct ip_addr host_ip;
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen in_port_t port;
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen /* userinfo (not parsed by default) */
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen const char *user;
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen const char *password;
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen /* path */
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen const char *path;
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen /* ?query (still encoded) */
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen const char *enc_query;
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen /* #fragment (still encoded) */
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen const char *enc_fragment;
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen unsigned int have_host_ip:1; /* URL uses IP address */
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen unsigned int have_port:1;
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen unsigned int have_ssl:1;
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen};
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen/*
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen * HTTP URL parsing
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen */
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainenenum http_url_parse_flags {
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen /* Scheme part 'http:' is already parsed externally. This implies that
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen this is an absolute HTTP URL. */
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen HTTP_URL_PARSE_SCHEME_EXTERNAL = 0x01,
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen /* Allow '#fragment' part in HTTP URL */
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen HTTP_URL_ALLOW_FRAGMENT_PART = 0x02,
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen /* Allow 'user:password@' part in HTTP URL */
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen HTTP_URL_ALLOW_USERINFO_PART = 0x04
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen};
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainenint http_url_parse(const char *url, struct http_url *base,
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen enum http_url_parse_flags flags, pool_t pool,
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen struct http_url **url_r, const char **error_r);
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainenint http_url_request_target_parse(const char *request_target,
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen const char *host_header, pool_t pool,
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen struct http_request_target *target, const char **error_r);
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen/*
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen * HTTP URL manipulation
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen */
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainenvoid http_url_copy_authority(pool_t pool, struct http_url *dest,
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen const struct http_url *src);
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainenvoid http_url_copy(pool_t pool, struct http_url *dest,
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen const struct http_url *src);
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainenstruct http_url *http_url_clone(pool_t pool,const struct http_url *src);
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen/*
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen * HTTP URL construction
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen */
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainenconst char *http_url_create(const struct http_url *url);
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainenconst char *http_url_create_host(const struct http_url *url);
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainenconst char *http_url_create_authority(const struct http_url *url);
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainenconst char *http_url_create_target(const struct http_url *url);
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainenvoid http_url_escape_param(string_t *out, const char *data);
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen#endif
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen