list func: update client config format
Change-Id: I147444d4b57dc360d6994ca9fe4f844139db777c
diff --git a/src/client-config.cpp b/src/client-config.cpp
index 7fd5280..116e1d8 100644
--- a/src/client-config.cpp
+++ b/src/client-config.cpp
@@ -27,54 +27,42 @@
void
ClientConfig::load(const std::string& fileName)
{
+ JsonSection config;
try {
- boost::property_tree::read_json(fileName, m_config);
+ boost::property_tree::read_json(fileName, config);
}
catch (const boost::property_tree::info_parser_error& error) {
BOOST_THROW_EXCEPTION(Error("Failed to parse configuration file " + fileName +
" " + error.message() + " line " + std::to_string(error.line())));
}
- if (m_config.begin() == m_config.end()) {
+ if (config.begin() == config.end()) {
BOOST_THROW_EXCEPTION(Error("Error processing configuration file: " + fileName + " no data"));
}
- parse();
+ load(config);
}
void
-ClientConfig::parse()
+ClientConfig::load(const JsonSection& configSection)
{
m_caItems.clear();
- auto caList = m_config.get_child("ca-list");
+ auto caList = configSection.get_child("ca-list");
auto it = caList.begin();
for (; it != caList.end(); it++) {
ClientCaItem item;
item.m_caName = Name(it->second.get<std::string>("ca-prefix"));
item.m_caInfo = it->second.get<std::string>("ca-info");
item.m_probe = it->second.get("probe", "");
+ item.m_targetedList = it->second.get("target-list", "");
std::istringstream ss(it->second.get<std::string>("certificate"));
item.m_anchor = *(io::load<security::v2::Certificate>(ss));
- auto challengeList = it->second.get_child("supported-challenges");
- item.m_supportedChallenges = parseChallengeList(challengeList);
-
m_caItems.push_back(item);
}
}
-std::list<std::string>
-ClientConfig::parseChallengeList(const JsonSection& section)
-{
- std::list<std::string> result;
- auto it = section.begin();
- for (; it != section.end(); it++) {
- result.push_back(it->second.get<std::string>("type"));
- }
- return result;
-}
-
void
ClientConfig::addNewCaItem(const ClientCaItem& item)
{
diff --git a/src/client-config.hpp b/src/client-config.hpp
index 8234c01..e32eab3 100644
--- a/src/client-config.hpp
+++ b/src/client-config.hpp
@@ -27,16 +27,33 @@
namespace ndn {
namespace ndncert {
+/**
+ * @brief The configuration for a trusted CA from a requester's perspective
+ */
class ClientCaItem
{
public:
+ // The identity name of the CA. Extracted from config field "ca-prefix"
Name m_caName;
+
+ // TODO: remove the caInfo, probe, and targetedList. Put them into the cert
+ // A brief introduction to the CA. Extracted from config field "ca-info"
std::string m_caInfo;
+ // An instruction for requesters to use _PROBE. Extracted from config field "probe"
std::string m_probe;
- std::list<std::string> m_supportedChallenges;
+ // An instruction for requesters to get a recommended CA. Extracted from config field "target-list"
+ std::string m_targetedList;
+
+ // CA's certificate
security::v2::Certificate m_anchor;
};
+/**
+ * @brief Represents Client configuration
+ *
+ * For Client configuration format, please refer to:
+ * https://github.com/named-data/ndncert/wiki/Client-Configuration-Sample
+ */
class ClientConfig
{
public:
@@ -51,18 +68,14 @@
load(const std::string& fileName);
void
+ load(const JsonSection& configSection);
+
+ void
addNewCaItem(const ClientCaItem& item);
void
removeCaItem(const Name& caName);
-PUBLIC_WITH_TESTS_ELSE_PRIVATE:
- void
- parse();
-
- std::list<std::string>
- parseChallengeList(const JsonSection& section);
-
public:
std::list<ClientCaItem> m_caItems;