Replace all uses of BOOST_THROW_EXCEPTION with NDN_THROW
Refs: #4834
Change-Id: I6c536cd321fba62d397bf8520f51d2dbba73d908
diff --git a/src/mgmt/management-tool.cpp b/src/mgmt/management-tool.cpp
index 9f363dc..6d34997 100644
--- a/src/mgmt/management-tool.cpp
+++ b/src/mgmt/management-tool.cpp
@@ -23,8 +23,8 @@
#include "ndns-tlv.hpp"
#include "util/cert-helper.hpp"
-#include <string>
#include <iomanip>
+#include <iostream>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
@@ -72,31 +72,31 @@
//check preconditions
Zone zone(zoneName, cacheTtl);
if (m_dbMgr.find(zone)) {
- BOOST_THROW_EXCEPTION(Error(zoneName.toUri() + " is already presented in the NDNS db"));
+ NDN_THROW(Error(zoneName.toUri() + " is already present in the NDNS db"));
}
if (!isRoot && parentZoneName.equals(zoneName)) {
- BOOST_THROW_EXCEPTION(Error("Parent zone name can not be the zone itself"));
+ NDN_THROW(Error("Parent zone name can not be the zone itself"));
}
if (!isRoot && !parentZoneName.isPrefixOf(zoneName)) {
- BOOST_THROW_EXCEPTION(Error(parentZoneName.toUri() + " is not a prefix of " + zoneName.toUri()));
+ NDN_THROW(Error(parentZoneName.toUri() + " is not a prefix of " + zoneName.toUri()));
}
// if dsk is provided, there is no need to check ksk
if (dskCertName != DEFAULT_CERT) {
if (!matchCertificate(dskCertName, zoneIdentityName)) {
- BOOST_THROW_EXCEPTION(Error("Cannot verify DSK certificate"));
+ NDN_THROW(Error("Cannot verify DSK certificate"));
}
}
else if (kskCertName != DEFAULT_CERT) {
if (!matchCertificate(kskCertName, zoneIdentityName)) {
- BOOST_THROW_EXCEPTION(Error("Cannot verify KSK certificate"));
+ NDN_THROW(Error("Cannot verify KSK certificate"));
}
}
if (dkeyCertName == DEFAULT_CERT && isRoot) {
- BOOST_THROW_EXCEPTION(Error("Cannot generate dkey for root zone"));
+ NDN_THROW(Error("Cannot generate dkey for root zone"));
}
// Generate a parentZone's identity to generate a D-Key.
@@ -196,7 +196,7 @@
//check pre-conditions
Zone zone(zoneName);
if (!m_dbMgr.find(zone)) {
- BOOST_THROW_EXCEPTION(Error(zoneName.toUri() + " is not presented in the NDNS db"));
+ NDN_THROW(Error(zoneName.toUri() + " is not present in the NDNS db"));
}
//first remove all rrsets of this zone from local ndns database
@@ -216,7 +216,7 @@
security::Certificate cert;
shared_ptr<Regex> regex = make_shared<Regex>("(<>*)<NDNS>(<>+)<CERT><>");
if (!regex->match(certName)) {
- BOOST_THROW_EXCEPTION(Error("Certificate name is illegal"));
+ NDN_THROW(Error("Certificate name is illegal"));
return;
}
@@ -232,7 +232,7 @@
cert = security::Certificate(rrset.getData());
}
else {
- BOOST_THROW_EXCEPTION(Error("Cannot find the cert: " + certName.toUri()));
+ NDN_THROW(Error("Cannot find the cert: " + certName.toUri()));
}
if (outFile == DEFAULT_IO) {
@@ -260,7 +260,7 @@
if (m_dbMgr.find(prefixNsRr)) {
Data data(prefixNsRr.getData());
if (data.getContentType() == NDNS_LINK) {
- BOOST_THROW_EXCEPTION(Error("Cannot override " + boost::lexical_cast<std::string>(prefixNsRr) + " (NDNS_LINK)"));
+ NDN_THROW(Error("Cannot override " + boost::lexical_cast<std::string>(prefixNsRr) + " (NDNS_LINK)"));
}
}
}
@@ -270,7 +270,7 @@
Rrset rrsetCopy = rrset;
if (m_dbMgr.find(rrsetCopy)) {
if (Data(rrsetCopy.getData()).getContentType() == NDNS_AUTH) {
- BOOST_THROW_EXCEPTION(Error("Cannot override " + boost::lexical_cast<std::string>(rrsetCopy) + " (NDNS_AUTH)"));
+ NDN_THROW(Error("Cannot override " + boost::lexical_cast<std::string>(rrsetCopy) + " (NDNS_AUTH)"));
}
}
}
@@ -305,7 +305,7 @@
rrsetCopy.setType(label::NS_RR_TYPE);
if (m_dbMgr.find(rrsetCopy)) {
if (Data(rrsetCopy.getData()).getContentType() == NDNS_AUTH) {
- BOOST_THROW_EXCEPTION(Error("Can not add this Rrset: it overrides a NDNS_AUTH record"));
+ NDN_THROW(Error("Can not add this Rrset: it overrides a NDNS_AUTH record"));
}
}
@@ -327,7 +327,7 @@
Zone zone(zoneName);
Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY);
if (!m_dbMgr.find(zone)) {
- BOOST_THROW_EXCEPTION(Error(zoneName.toUri() + " is not presented in the NDNS db"));
+ NDN_THROW(Error(zoneName.toUri() + " is not present in the NDNS db"));
}
Name dskName;
@@ -338,14 +338,14 @@
}
else {
if (!matchCertificate(dskCertName, zoneIdentityName)) {
- BOOST_THROW_EXCEPTION(Error("Cannot verify certificate"));
+ NDN_THROW(Error("Cannot verify certificate"));
}
}
if (inFile != DEFAULT_IO) {
boost::filesystem::path dir = boost::filesystem::path(inFile);
if (!boost::filesystem::exists(dir) || boost::filesystem::is_directory(dir)) {
- BOOST_THROW_EXCEPTION(Error("Data: " + inFile + " does not exist"));
+ NDN_THROW(Error("Data: " + inFile + " does not exist"));
}
}
@@ -357,7 +357,7 @@
data = ndn::io::load<ndn::Data>(inFile, encoding);
if (data == nullptr) {
- BOOST_THROW_EXCEPTION(Error("input does not contain a valid Data packet"));
+ NDN_THROW(Error("input does not contain a valid Data packet"));
}
if (needResign) {
@@ -402,7 +402,7 @@
{
Zone zone(zoneName);
if (!m_dbMgr.find(zone)) {
- BOOST_THROW_EXCEPTION(Error("Zone " + zoneName.toUri() + " is not found in the database"));
+ NDN_THROW(Error("Zone " + zoneName.toUri() + " is not found in the database"));
}
//first output the zone name
@@ -593,8 +593,8 @@
rrsetKey.setData(cert.wireEncode());
if (m_dbMgr.find(rrsetKey)) {
- BOOST_THROW_EXCEPTION(Error("CERT with label=" + label.toUri() +
- " is already presented in local NDNS databse"));
+ NDN_THROW(Error("CERT with label=" + label.toUri() +
+ " is already present in local NDNS database"));
}
m_dbMgr.insert(rrsetKey);
@@ -606,8 +606,8 @@
ManagementTool::addZone(Zone& zone)
{
if (m_dbMgr.find(zone)) {
- BOOST_THROW_EXCEPTION(Error("Zone with Name=" + zone.getName().toUri() +
- " is already presented in local NDNS databse"));
+ NDN_THROW(Error("Zone with Name=" + zone.getName().toUri() +
+ " is already present in local NDNS database"));
}
NDNS_LOG_INFO("Add zone with Name: " << zone.getName().toUri());
m_dbMgr.insert(zone);
@@ -644,12 +644,10 @@
if (m_dbMgr.find(originalRrset)) {
// update only if rrset has a newer version
if (originalRrset.getVersion() == rrset.getVersion()) {
- BOOST_THROW_EXCEPTION(Error("Duplicate: "
- + boost::lexical_cast<std::string>(originalRrset)));
+ NDN_THROW(Error("Duplicate: " + boost::lexical_cast<std::string>(originalRrset)));
}
else if (originalRrset.getVersion() > rrset.getVersion()) {
- BOOST_THROW_EXCEPTION(Error("Newer version exists: "
- + boost::lexical_cast<std::string>(originalRrset)));
+ NDN_THROW(Error("Newer version exists: " + boost::lexical_cast<std::string>(originalRrset)));
}
m_dbMgr.remove(originalRrset);
@@ -661,7 +659,7 @@
{
// check zone existence
if (!m_dbMgr.find(zone)) {
- BOOST_THROW_EXCEPTION(Error(zone.getName().toUri() + " is not presented in the NDNS db"));
+ NDN_THROW(Error(zone.getName().toUri() + " is not present in the NDNS db"));
}
// remove all the Doe records
diff --git a/src/mgmt/management-tool.hpp b/src/mgmt/management-tool.hpp
index 5b9b51e..ba00458 100644
--- a/src/mgmt/management-tool.hpp
+++ b/src/mgmt/management-tool.hpp
@@ -20,7 +20,6 @@
#ifndef NDNS_MGMT_MANAGEMENT_TOOL_HPP
#define NDNS_MGMT_MANAGEMENT_TOOL_HPP
-#include "config.hpp"
#include "ndns-enum.hpp"
#include "clients/response.hpp"
#include "daemon/db-mgr.hpp"
@@ -49,7 +48,7 @@
* @brief provides management tools to the NDNS system, such as zone creation, zone delegation, DSK
* generation and root zone creation.
*/
-class ManagementTool : noncopyable
+class ManagementTool : boost::noncopyable
{
public:
/** @brief Represents an error might be thrown during runtime
@@ -57,10 +56,7 @@
class Error : public std::runtime_error
{
public:
- explicit
- Error(const std::string& what) : std::runtime_error(what)
- {
- }
+ using std::runtime_error::runtime_error;
};
/**