12#ifndef OPENVPN_HTTP_URLPARM_H
13#define OPENVPN_HTTP_URLPARM_H
33 Parm(
const std::string &name_arg,
const std::string &value_arg)
40 std::ostringstream
out;
56 const std::vector<std::string> req_parms =
string::split(uri,
'?', 1);
58 if (req_parms.size() == 2)
60 const std::vector<std::string> kv_list =
string::split(req_parms[1],
'&');
61 for (
auto &kvstr : kv_list)
63 const std::vector<std::string> kv =
string::split(kvstr,
'=', 1);
72 catch (
const std::exception &e)
78 const Parm *
get(
const std::string &key)
const
103 throw url_parameter_error(key +
" : not found");
106 template <
typename T>
107 T
get_num(
const std::string &name,
const std::string &short_name,
const T default_value)
const
110 if (!p && !short_name.empty())
113 return parse_number_throw<T>(p->
value, name);
115 return default_value;
118 template <
typename T>
122 if (!p && !short_name.empty())
125 throw url_parameter_error(name +
" : not found");
126 return parse_number_throw<T>(p->
value, name);
129 bool get_bool(
const std::string &name,
const std::string &short_name,
const bool default_value)
const
132 if (!p && !short_name.empty())
138 else if (p->
value ==
"1")
141 throw url_parameter_error(name +
": parameter must be 0 or 1");
144 return default_value;
147 std::string
get_string(
const std::string &name,
const std::string &short_name)
const
150 if (!p && !short_name.empty())
161 if (!p && !short_name.empty())
164 throw url_parameter_error(name +
" : not found");
170 std::ostringstream
out;
171 for (
size_t i = 0; i < size(); ++i)
172 out <<
'[' << i <<
"] " << (*
this)[i].to_string() << std::endl;
176 std::string
request(
const bool remove_leading_slash)
const
179 if (remove_leading_slash)
181 if (
ret.length() > 0 &&
ret[0] ==
'/')
std::string get_string(const std::string &name, const std::string &short_name) const
std::string get_value(const std::string &key) const
const std::string & request() const
const std::string & get_value_required(const std::string &key) const
const Parm * get(const std::string &key) const
T get_num(const std::string &name, const std::string &short_name, const T default_value) const
ParmList(const std::string &uri)
std::string to_string() const
std::string get_string_required(const std::string &name, const std::string &short_name) const
T get_num_required(const std::string &name, const std::string &short_name) const
bool get_bool(const std::string &name, const std::string &short_name, const bool default_value) const
std::string request(const bool remove_leading_slash) const
#define OPENVPN_EXCEPTION(C)
std::string decode(const std::string &encoded)
std::vector< T > split(const T &str, const typename T::value_type sep, const int maxsplit=-1)
std::string to_string() const
Parm(const std::string &name_arg, const std::string &value_arg)
server addresses push_back({address, port})
static std::stringstream out