12#ifndef OPENVPN_HTTP_URLPARSE_H
13#define OPENVPN_HTTP_URLPARSE_H
34 const bool set_default_port =
false,
35 const bool loose_validation =
false)
58 state = PostSchemeSlash1;
62 throw url_parse_error(
"bad scheme char");
64 case PostSchemeSlash1:
66 state = PostSchemeSlash2;
68 throw url_parse_error(
"expected '://' after scheme");
70 case PostSchemeSlash2:
74 throw url_parse_error(
"expected '://' after scheme");
78 state = BracketedHost;
98 state = PostBracketedHost;
102 case PostBracketedHost:
125 throw url_parse_error(
"bad URI char");
130 if (set_default_port)
142 const std::string &
host,
143 const std::string &
port,
144 const std::string &
uri)
147 p.
scheme = https ?
"https" :
"http";
160 throw url_parse_error(
"undefined scheme");
162 throw url_parse_error(
"undefined host");
164 throw url_parse_error(
"undefined uri");
167 throw url_parse_error(
"bad port");
169 throw url_parse_error(
"bad host");
178 else if (
scheme ==
"https")
190 return host.find_first_of(
":/\\") != std::string::npos;
195 return '[' +
host +
']';
234#ifdef OPENVPN_PLATFORM_WIN
244 throw url_parse_error(
"unknown scheme");
255 return (c >=
'a' && c <=
'z') || c ==
'_';
bool is_valid_scheme_char(const char c)
bool is_bracketed_host() const
std::string to_string() const
static Parse from_components(const bool https, const std::string &host, const std::string &port, const std::string &uri)
std::string bracketed_host() const
std::string port_for_scheme() const
std::string format_components() const
Parse(const std::string &url, const bool set_default_port=false, const bool loose_validation=false)
bool port_implied() const
#define OPENVPN_EXCEPTION(C)
bool is_valid_uri_char(const unsigned char c)
bool is_valid_port(const unsigned int port)
bool is_valid_host(const std::string &host)
bool is_digit(const char c)
std::string printfmt(const std::string &fmt, Args... args)