16#ifndef OPENVPN_SSL_PEERINFO_H
17#define OPENVPN_SSL_PEERINFO_H
39 KeyValue(
const std::string &key_arg,
const std::string &value_arg)
54struct Set :
public std::vector<KeyValue>,
public RCCopyable<thread_unsafe_refcount>
58 template <
typename SET>
62 for (
const auto &kv : other)
63 sp->emplace_back(kv.key, kv.value);
67 template <
typename SET>
71 for (
const auto &kv : *other)
72 emplace_back(kv.key, kv.value);
75 template <
typename SET>
78 for (
const auto &kv : other)
79 emplace_back(kv.key, kv.value);
85 {
return kv.
key == key; })
91 return new Set(*
this);
96 template <
typename SET>
99 if (src.length() >= 1 && src[0] ==
'@')
101 const std::string fn = src.substr(1);
102#ifdef OPENVPN_JSON_INTERNAL
104 parse_json(root, dest, fn);
106 OPENVPN_THROW(peer_info_error, fn <<
": JSON library not available");
114 template <
typename SET>
115 static void parse_csv(
const std::string &src, SET &dest)
122 for (
const auto &kvstr : list)
126 dest.emplace_back(kv[0], kv[1]);
133#ifdef OPENVPN_JSON_INTERNAL
134 template <
typename SET>
135 static void parse_json(
const Json::Value &src, SET &dest,
const std::string &title)
138 OPENVPN_THROW(peer_info_error, title <<
": top level JSON object must be a dictionary");
139 auto m = src.asObject();
142 if (e.second.isString())
143 dest.emplace_back(e.first, e.second.asStringRef());
145 dest.emplace_back(e.first, e.second.toCompactString());
154 for (
const auto &kv : *
this)
156 ret += kv.to_string();
Reference count base class for objects tracked by RCPtr. Allows copying and assignment.
#define OPENVPN_EXCEPTION(C)
#define OPENVPN_THROW(exc, stuff)
STRING utf8_printable(const STRING &str, size_t max_len_flags)
Json::Value parse_from_file(const std::string &fn)
bool is_multiline(const std::string &str)
bool is_empty(const std::string &str)
std::string to_string() const
KeyValue(const std::string &key_arg, const std::string &value_arg)
static void parse_csv(const std::string &src, SET &dest)
std::string to_string() const
bool contains_key(const std::string &key)
static Ptr new_from_foreign_set(const SET &other)
static void parse_flexible(const std::string &src, SET &dest)
void append_foreign_set_ptr(const SET *other)
void append_foreign_set_ref(const SET &other)