]> granicus.if.org Git - pdns/commitdiff
Fix exception handling and use "" for NULL
authorAki Tuomi <cmouse@desteem.org>
Tue, 15 Jul 2014 18:20:44 +0000 (21:20 +0300)
committerAki Tuomi <cmouse@desteem.org>
Wed, 16 Jul 2014 07:05:47 +0000 (10:05 +0300)
modules/remotebackend/pipeconnector.cc
modules/remotebackend/remotebackend.cc
modules/remotebackend/unixconnector.cc
modules/remotebackend/zmqconnector.cc

index 33c58897ba80733ba28579d6c4a7116ab6918cf1..140132a20159ee289e940781f3acf01d10604e5a 100644 (file)
@@ -5,7 +5,7 @@
 PipeConnector::PipeConnector(std::map<std::string,std::string> options) {
   if (options.count("command") == 0) {
     L<<Logger::Error<<"Cannot find 'command' option in connection string"<<endl;
-    throw new PDNSException();
+    throw PDNSException();
   }
   this->command = options.find("command")->second;
   this->options = options;
index b494ca40112bf3fcd506de4e716990cc7124bd13..2e40846359c772eb65c2c9d7895ac1115e166125 100644 (file)
@@ -933,7 +933,7 @@ bool RemoteBackend::getBool(rapidjson::Value &value) {
      if (boost::iequals(tmp, "0") || boost::iequals(tmp, "false")) return false;
    }
    std::cerr << value.GetType() << endl;
-   throw new PDNSException("Cannot convert rapidjson value into boolean");
+   throw PDNSException("Cannot convert rapidjson value into boolean");
 }
 
 bool Connector::getBool(rapidjson::Value &value) {
@@ -969,7 +969,7 @@ int RemoteBackend::getInt(rapidjson::Value &value) {
      std::string tmp = value.GetString();
      return boost::lexical_cast<int>(tmp);
    }
-   throw new PDNSException("Cannot convert rapidjson value into integer");
+   throw PDNSException("Cannot convert rapidjson value into integer");
 }
 
 unsigned int RemoteBackend::getUInt(rapidjson::Value &value) {
@@ -981,7 +981,7 @@ unsigned int RemoteBackend::getUInt(rapidjson::Value &value) {
      std::string tmp = value.GetString();
      return boost::lexical_cast<unsigned int>(tmp);
    }
-   throw new PDNSException("Cannot convert rapidjson value into integer");
+   throw PDNSException("Cannot convert rapidjson value into integer");
 }
 
 int64_t RemoteBackend::getInt64(rapidjson::Value &value) {
@@ -993,16 +993,17 @@ int64_t RemoteBackend::getInt64(rapidjson::Value &value) {
      std::string tmp = value.GetString();
      return boost::lexical_cast<int64_t>(tmp);
    }
-   throw new PDNSException("Cannot convert rapidjson value into integer");
+   throw PDNSException("Cannot convert rapidjson value into integer");
 }
 
 std::string RemoteBackend::getString(rapidjson::Value &value) {
+   if (value.IsNull()) return "";
    if (value.IsString()) return value.GetString();
    if (value.IsBool()) return (value.GetBool() ? "true" : "false");
    if (value.IsInt64()) return boost::lexical_cast<std::string>(value.GetInt64());
    if (value.IsInt()) return boost::lexical_cast<std::string>(value.GetInt());
    if (value.IsDouble()) return boost::lexical_cast<std::string>(value.GetDouble());
-   throw new PDNSException("Cannot convert rapidjson value into std::string");
+   throw PDNSException("Cannot convert rapidjson value into std::string");
 }
 
 double RemoteBackend::getDouble(rapidjson::Value &value) {
@@ -1014,7 +1015,7 @@ double RemoteBackend::getDouble(rapidjson::Value &value) {
      std::string tmp = value.GetString();
      return boost::lexical_cast<double>(tmp);
    }
-   throw new PDNSException("Cannot convert rapidjson value into double");
+   throw PDNSException("Cannot convert rapidjson value into double");
 }
 
 DNSBackend *RemoteBackend::maker()
index 1b68353703e5308c49d153ff850a94f2f28c6fa1..f744462b23cffbc0289e2e00f5f07c58c7886802 100644 (file)
@@ -10,7 +10,7 @@
 UnixsocketConnector::UnixsocketConnector(std::map<std::string,std::string> options) {
    if (options.count("path") == 0) {
      L<<Logger::Error<<"Cannot find 'path' option in connection string"<<endl;
-     throw new PDNSException();
+     throw PDNSException();
    } 
    this->timeout = 2000;
    if (options.find("timeout") != options.end()) { 
index 3e96589ab26ab836737283472bb5cb50a5ad4e21..5f863d2e8c7194ce95a73726d6f3b00e86bbe518 100644 (file)
@@ -16,7 +16,7 @@ ZeroMQConnector::ZeroMQConnector(std::map<std::string,std::string> options) : d_
   // lookup timeout, target and stuff
   if (options.count("endpoint") == 0) {
     L<<Logger::Error<<"Cannot find 'endpoint' option in connection string"<<endl;
-    throw new PDNSException("Cannot find 'endpoint' option in connection string");
+    throw PDNSException("Cannot find 'endpoint' option in connection string");
   }
   this->d_endpoint = options.find("endpoint")->second;
   this->d_options = options;
@@ -74,7 +74,7 @@ int ZeroMQConnector::send_message(const rapidjson::Document &input) {
      }
    } catch (std::exception &ex) {
      L<<Logger::Error<<"Cannot send to " << this->d_endpoint << ": " << ex.what();
-     throw new PDNSException(ex.what());
+     throw PDNSException(ex.what());
    }
 
    return 0;
@@ -122,7 +122,7 @@ int ZeroMQConnector::recv_message(rapidjson::Document &output) {
      }
    } catch (std::exception &ex) {
      L<<Logger::Error<<"Cannot receive from " << this->d_endpoint << ": " << ex.what();
-     throw new PDNSException(ex.what());
+     throw PDNSException(ex.what());
    }
 
    return rv;