14#ifndef OPENVPN_COMMON_ENVIRON_H
15#define OPENVPN_COMMON_ENVIRON_H
28class Environ :
public std::vector<std::string>
33 for (
char **e =
::environ; *e != NULL; ++e)
35 const char *eq = ::strchr(*e,
'=');
38 const size_t namelen = eq - *e;
39 if (name.length() == namelen && ::strncmp(name.c_str(), *e, namelen) == 0)
40 return std::string(eq + 1);
49 for (
char **e =
::environ; *e != NULL; ++e)
57 for (
const auto &s : *
this)
67 for (size_type i = 0; i < size(); ++i)
69 const std::string &s = (*this)[i];
70 const size_t pos = s.find_first_of(
'=');
71 if (pos != std::string::npos)
73 if (name == s.substr(0, pos))
74 return static_cast<int>(i);
79 return static_cast<int>(i);
85 std::string
find(
const std::string &name)
const
94 std::string
value(
const size_t idx)
const
96 const std::string &s = (*this)[idx];
97 const size_t pos = s.find_first_of(
'=');
98 if (pos != std::string::npos)
99 return s.substr(pos + 1);
106 std::string nv = name +
'=' +
value;
109 (*this)[i] = std::move(nv);
std::string value(const size_t idx) const
int find_index(const std::string &name) const
static std::string find_static(const std::string &name)
std::string to_string() const
std::string find(const std::string &name) const
void assign(const std::string &name, const std::string &value)
server addresses push_back({address, port})