add redirection to CA config

Change-Id: I945bf6ac7aaac89bc7328b69caf566f2477edaf1
diff --git a/src/configuration.cpp b/src/configuration.cpp
index c4f2c72..18b71a0 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -71,7 +71,7 @@
   }
   // anchor certificate
   m_cert = nullptr;
-  auto certificateStr = configJson.get("certificate", "");
+  auto certificateStr = configJson.get(CONFIG_CERTIFICATE, "");
   if (certificateStr != "") {
     std::istringstream ss(certificateStr);
     m_cert = io::load<security::v2::Certificate>(ss);
@@ -129,17 +129,24 @@
   if (m_caItem.m_supportedChallenges.size() == 0) {
     BOOST_THROW_EXCEPTION(std::runtime_error("At least one challenge should be specified."));
   }
-}
-
-void
-CaConfig::save(const std::string& fileName) const
-{
-  std::stringstream ss;
-  boost::property_tree::write_json(ss, m_caItem.toJson());
-  std::ofstream configFile;
-  configFile.open(fileName);
-  configFile << ss.str();
-  configFile.close();
+  // parse redirection section if appears
+  m_redirection = boost::none;
+  auto redirectionItems = configJson.get_child_optional(CONFIG_REDIRECTION);
+  if (redirectionItems) {
+    for (const auto item : *redirectionItems) {
+      auto caPrefixStr = item.second.get(CONFIG_CA_PREFIX, "");
+      auto caCertStr = item.second.get(CONFIG_CERTIFICATE, "");
+      if (caPrefixStr == "" || caCertStr == "") {
+        BOOST_THROW_EXCEPTION(std::runtime_error("Redirect-to item's ca-prefix or certificate cannot be empty."));
+      }
+      std::istringstream ss(caCertStr);
+      auto caCert = io::load<security::v2::Certificate>(ss);
+      if (!m_redirection) {
+        m_redirection = RedirectionItems();
+      }
+      m_redirection->push_back(std::make_tuple(Name(caPrefixStr), caCert));
+    }
+  }
 }
 
 void