12#ifndef OPENVPN_HTTP_URLPARM_H
13#define OPENVPN_HTTP_URLPARM_H
31 Parm(
const std::string &name_arg,
const std::string &value_arg)
38 std::ostringstream
out;
54 const std::vector<std::string> req_parms =
string::split(uri,
'?', 1);
56 if (req_parms.size() == 2)
58 const std::vector<std::string> kv_list =
string::split(req_parms[1],
'&');
59 for (
auto &kvstr : kv_list)
61 const std::vector<std::string> kv =
string::split(kvstr,
'=', 1);
70 catch (
const std::exception &e)
76 const Parm *
get(
const std::string &key)
const
101 throw url_parameter_error(key +
" : not found");
104 template <
typename T>
105 T
get_num(
const std::string &name,
const std::string &short_name,
const T default_value)
const
108 if (!p && !short_name.empty())
111 return parse_number_throw<T>(p->
value, name);
113 return default_value;
116 template <
typename T>
120 if (!p && !short_name.empty())
123 throw url_parameter_error(name +
" : not found");
124 return parse_number_throw<T>(p->
value, name);
127 bool get_bool(
const std::string &name,
const std::string &short_name,
const bool default_value)
const
130 if (!p && !short_name.empty())
136 else if (p->
value ==
"1")
139 throw url_parameter_error(name +
": parameter must be 0 or 1");
142 return default_value;
145 std::string
get_string(
const std::string &name,
const std::string &short_name)
const
148 if (!p && !short_name.empty())
159 if (!p && !short_name.empty())
162 throw url_parameter_error(name +
" : not found");
168 std::ostringstream
out;
169 for (
size_t i = 0; i < size(); ++i)
170 out <<
'[' << i <<
"] " << (*
this)[i].to_string() <<
"\n";
174 std::string
request(
const bool remove_leading_slash)
const
177 if (remove_leading_slash)
179 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)
static std::stringstream out