12#ifndef OPENVPN_HTTP_URLPARSE_H
13#define OPENVPN_HTTP_URLPARSE_H
36 const bool set_default_port =
false,
37 const bool loose_validation =
false)
60 state = PostSchemeSlash1;
64 throw url_parse_error(
"bad scheme char");
66 case PostSchemeSlash1:
68 state = PostSchemeSlash2;
70 throw url_parse_error(
"expected '://' after scheme");
72 case PostSchemeSlash2:
76 throw url_parse_error(
"expected '://' after scheme");
80 state = BracketedHost;
100 state = PostBracketedHost;
104 case PostBracketedHost:
127 throw url_parse_error(
"bad URI char");
132 if (set_default_port)
144 const std::string &
host,
145 const std::string &
port,
146 const std::string &
uri)
149 p.
scheme = https ?
"https" :
"http";
162 throw url_parse_error(
"undefined scheme");
164 throw url_parse_error(
"undefined host");
166 throw url_parse_error(
"undefined uri");
169 throw url_parse_error(
"bad port");
171 throw url_parse_error(
"bad host");
180 else if (
scheme ==
"https")
192 return host.find_first_of(
":/\\") != std::string::npos;
197 return '[' +
host +
']';
236#ifdef OPENVPN_PLATFORM_WIN
246 throw url_parse_error(
"unknown scheme");
257 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)