]> granicus.if.org Git - pdns/commitdiff
Use proper integer conversions in remotebackend
authorAki Tuomi <cmouse@desteem.org>
Fri, 11 Dec 2015 15:43:08 +0000 (17:43 +0200)
committerAki Tuomi <cmouse@desteem.org>
Mon, 21 Dec 2015 12:52:49 +0000 (14:52 +0200)
13 files changed:
modules/remotebackend/httpconnector.cc
modules/remotebackend/pipeconnector.cc
modules/remotebackend/remotebackend.cc
modules/remotebackend/remotebackend.hh
modules/remotebackend/test-remotebackend-http.cc
modules/remotebackend/test-remotebackend-json.cc
modules/remotebackend/test-remotebackend-pipe.cc
modules/remotebackend/test-remotebackend-post.cc
modules/remotebackend/test-remotebackend-unix.cc
modules/remotebackend/test-remotebackend-zeromq.cc
modules/remotebackend/test-remotebackend.cc
modules/remotebackend/unixconnector.cc
modules/remotebackend/zmqconnector.cc

index 94cf24656028d445163a062a9e3d041f5bea872e..eedaf0315ae59c8ddee05c1be344b0ced29407b1 100644 (file)
@@ -28,7 +28,7 @@ HTTPConnector::HTTPConnector(std::map<std::string,std::string> options) {
     this->d_socket = NULL;
 
     if (options.find("timeout") != options.end()) {
-      this->timeout = boost::lexical_cast<int>(options.find("timeout")->second)/1000;
+      this->timeout = std::stoi(options.find("timeout")->second)/1000;
     }
     if (options.find("post") != options.end()) {
       std::string val = options.find("post")->second;
@@ -53,10 +53,10 @@ HTTPConnector::~HTTPConnector() {
 bool HTTPConnector::json2string(const rapidjson::Value &input, std::string &output) {
    if (input.IsString()) output = input.GetString();
    else if (input.IsNull()) output = "";
-   else if (input.IsUint64()) output = lexical_cast<std::string>(input.GetUint64());
-   else if (input.IsInt64()) output = lexical_cast<std::string>(input.GetInt64());
-   else if (input.IsUint()) output = lexical_cast<std::string>(input.GetUint());
-   else if (input.IsInt()) output = lexical_cast<std::string>(input.GetInt());
+   else if (input.IsUint64()) output = std::to_string(input.GetUint64());
+   else if (input.IsInt64()) output = std::to_string(input.GetInt64());
+   else if (input.IsUint()) output = std::to_string(input.GetUint());
+   else if (input.IsInt()) output = std::to_string(input.GetInt());
    else return false;
    return true;
 }
@@ -152,11 +152,11 @@ void HTTPConnector::restful_requestbuilder(const std::string &method, const rapi
         size_t index = 0;
         for(rapidjson::Value::ConstValueIterator itr = parameters["nsset"].Begin(); itr != parameters["nsset"].End(); itr++) {
             index++;
-            ss2 << buildMemberListArgs("nsset[" + boost::lexical_cast<std::string>(index) + "]", itr) << "&";
+            ss2 << buildMemberListArgs("nsset[" + std::to_string(index) + "]", itr) << "&";
         }
         req.body = ss2.str().substr(0, ss2.str().size()-1);
         req.headers["content-type"] = "application/x-www-form-urlencoded; charset=utf-8";
-        req.headers["content-length"] = boost::lexical_cast<std::string>(req.body.size());
+        req.headers["content-length"] = std::to_string(req.body.size());
         verb = "POST";
     } else if (method == "createSlaveDomain") {
         addUrlComponent(parameters, "ip", ss);
@@ -171,17 +171,17 @@ void HTTPConnector::restful_requestbuilder(const std::string &method, const rapi
         size_t index = 0;
         for(rapidjson::Value::ConstValueIterator itr = parameters["rrset"].Begin(); itr != parameters["rrset"].End(); itr++) {
             index++;
-            ss2 << buildMemberListArgs("rrset[" + boost::lexical_cast<std::string>(index) + "]", itr);
+            ss2 << buildMemberListArgs("rrset[" + std::to_string(index) + "]", itr);
         }
         req.body = ss2.str();
         req.headers["content-type"] = "application/x-www-form-urlencoded; charset=utf-8";
-        req.headers["content-length"] = boost::lexical_cast<std::string>(req.body.size());
+        req.headers["content-length"] = std::to_string(req.body.size());
         verb = "PATCH";
     } else if (method == "feedRecord") {
         addUrlComponent(parameters, "trxid", ss);
         req.body = buildMemberListArgs("rr", &parameters["rr"]);
         req.headers["content-type"] = "application/x-www-form-urlencoded; charset=utf-8";
-        req.headers["content-length"] = boost::lexical_cast<std::string>(req.body.size());
+        req.headers["content-length"] = std::to_string(req.body.size());
         verb = "PATCH";
     } else if (method == "feedEnts") {
         std::stringstream ss2;
@@ -191,7 +191,7 @@ void HTTPConnector::restful_requestbuilder(const std::string &method, const rapi
         }
         req.body = ss2.str().substr(0, ss2.str().size()-1);
         req.headers["content-type"] = "application/x-www-form-urlencoded; charset=utf-8";
-        req.headers["content-length"] = boost::lexical_cast<std::string>(req.body.size());
+        req.headers["content-length"] = std::to_string(req.body.size());
         verb = "PATCH";
     } else if (method == "feedEnts3") {
         std::stringstream ss2;
@@ -203,7 +203,7 @@ void HTTPConnector::restful_requestbuilder(const std::string &method, const rapi
         }
         req.body = ss2.str().substr(0, ss2.str().size()-1);
         req.headers["content-type"] = "application/x-www-form-urlencoded; charset=utf-8";
-        req.headers["content-length"] = boost::lexical_cast<std::string>(req.body.size());
+        req.headers["content-length"] = std::to_string(req.body.size());
         verb = "PATCH";
     } else if (method == "startTransaction") {
         addUrlComponent(parameters, "domain", ss);
@@ -216,7 +216,7 @@ void HTTPConnector::restful_requestbuilder(const std::string &method, const rapi
         addUrlComponent(parameters, "domain", ss);
         req.body = buildMemberListArgs("sd", &parameters["sd"]);
         req.headers["content-type"] = "application/x-www-form-urlencoded; charset=utf-8";
-        req.headers["content-length"] = boost::lexical_cast<std::string>(req.body.size());
+        req.headers["content-length"] = std::to_string(req.body.size());
         verb = "POST";
     } else if (method == "setDomainMetadata") {
         // copy all metadata values into post
@@ -230,7 +230,7 @@ void HTTPConnector::restful_requestbuilder(const std::string &method, const rapi
         }
         req.body = ss2.str().substr(0, ss2.str().size()-1);
         req.headers["content-type"] = "application/x-www-form-urlencoded; charset=utf-8";
-        req.headers["content-length"] = boost::lexical_cast<std::string>(req.body.size());
+        req.headers["content-length"] = std::to_string(req.body.size());
         verb = "PATCH";
     } else if (method == "removeDomainKey") {
         // this one is delete
@@ -248,7 +248,7 @@ void HTTPConnector::restful_requestbuilder(const std::string &method, const rapi
     } else if (method == "searchRecords" || method == "searchComments") {
         json2string(parameters["pattern"],sparam);
         req.GET()["pattern"] = sparam;
-        req.GET()["maxResults"] = boost::lexical_cast<std::string>(parameters["maxResults"].GetInt());
+        req.GET()["maxResults"] = std::to_string(parameters["maxResults"].GetInt());
         verb = "GET";
     } else {
         // perform normal get
@@ -284,7 +284,7 @@ void HTTPConnector::post_requestbuilder(const rapidjson::Document &input, YaHTTP
         // simple case, POST JSON into url. nothing fancy.
         std::string out = makeStringFromDocument(input);
         req.headers["Content-Type"] = "text/javascript; charset=utf-8";
-        req.headers["Content-Length"] = boost::lexical_cast<std::string>(out.size());
+        req.headers["Content-Length"] = std::to_string(out.size());
         req.headers["accept"] = "application/json";
         req.body = out;
     } else {
@@ -348,7 +348,7 @@ int HTTPConnector::send_message(const rapidjson::Document &input) {
     } else {
       // connect using tcp
       struct addrinfo *gAddr, *gAddrPtr, hints;
-      std::string sPort = boost::lexical_cast<std::string>(req.url.port);
+      std::string sPort = std::to_string(req.url.port);
       memset(&hints,0,sizeof hints);
       hints.ai_family = AF_UNSPEC;
       hints.ai_flags = AI_ADDRCONFIG; 
index fef490217cb86b25332a4ee8ceac196984ab424c..016d98f800d6c43d7b806b852e35958d850b78a2 100644 (file)
@@ -15,7 +15,7 @@ PipeConnector::PipeConnector(std::map<std::string,std::string> options) {
   d_timeout=2000;
 
   if (options.find("timeout") != options.end()) {
-     d_timeout = boost::lexical_cast<int>(options.find("timeout")->second);
+     d_timeout = std::stoi(options.find("timeout")->second);
   }
 
   d_pid = -1;
index 6c8be5bcd0578afe83f610cb14a9912f7a27d135..bd5ea1bfd817156b25d22b8e59a2e86a30fcddd2 100644 (file)
@@ -1036,9 +1036,9 @@ bool Connector::getBool(rapidjson::Value &value) {
 std::string Connector::getString(rapidjson::Value &value) {
    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());
+   if (value.IsInt64()) return std::to_string(value.GetInt64());
+   if (value.IsInt()) return std::to_string(value.GetInt());
+   if (value.IsDouble()) return std::to_string(value.GetDouble());
    return "(unpresentable value)"; // cannot convert into presentation format
 }
 
@@ -1049,7 +1049,7 @@ int RemoteBackend::getInt(rapidjson::Value &value) {
    if (value.IsDouble()) return static_cast<int>(value.GetDouble());
    if (value.IsString()) {  // accepts 0, 1, false, true
      std::string tmp = value.GetString();
-     return boost::lexical_cast<int>(tmp);
+     return std::stoi(tmp);
    }
    throw PDNSException("Cannot convert rapidjson value into integer");
 }
@@ -1061,7 +1061,7 @@ unsigned int RemoteBackend::getUInt(rapidjson::Value &value) {
    if (value.IsDouble()) return static_cast<unsigned int>(value.GetDouble());
    if (value.IsString()) {  // accepts 0, 1, false, true
      std::string tmp = value.GetString();
-     return boost::lexical_cast<unsigned int>(tmp);
+     return pdns_stou(tmp);
    }
    throw PDNSException("Cannot convert rapidjson value into integer");
 }
@@ -1073,7 +1073,7 @@ int64_t RemoteBackend::getInt64(rapidjson::Value &value) {
    if (value.IsDouble()) return static_cast<int64_t>(value.GetDouble());
    if (value.IsString()) {  // accepts 0, 1, false, true
      std::string tmp = value.GetString();
-     return boost::lexical_cast<int64_t>(tmp);
+     return std::stoll(tmp);
    }
    throw PDNSException("Cannot convert rapidjson value into integer");
 }
@@ -1082,9 +1082,9 @@ 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());
+   if (value.IsInt64()) return std::to_string(value.GetInt64());
+   if (value.IsInt()) return std::to_string(value.GetInt());
+   if (value.IsDouble()) return std::to_string(value.GetDouble());
    throw PDNSException("Cannot convert rapidjson value into std::string");
 }
 
@@ -1095,7 +1095,7 @@ double RemoteBackend::getDouble(rapidjson::Value &value) {
    if (value.IsInt()) return static_cast<double>(value.GetInt());
    if (value.IsString()) {  // accepts 0, 1, false, true
      std::string tmp = value.GetString();
-     return boost::lexical_cast<double>(tmp);
+     return std::stod(tmp);
    }
    throw PDNSException("Cannot convert rapidjson value into double");
 }
index b0720879b9f686d99b4323464a448bce8ed4ae84..15e5c11c7faae6dd94d9fe84dd0d09f87e8efadd 100644 (file)
@@ -12,7 +12,6 @@
 #include "pdns/pdnsexception.hh"
 #include "pdns/sstuff.hh"
 #include "pdns/ueberbackend.hh"
-#include <boost/lexical_cast.hpp>
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
 #include "yahttp/yahttp.hpp"
index 05f36cd9b9467dee397473e9bd2ad5612c99f494..e90f1203c10a0410170da8b792bc7f99842667b2 100644 (file)
@@ -9,7 +9,6 @@
 #include "pdns/pdnsexception.hh"
 #include "pdns/logger.hh"
 #include "pdns/arguments.hh"
-#include <boost/lexical_cast.hpp>
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
 #include "pdns/json.hh"
index a020b9242770ea8c6512ff3ce6cf5616d3a809fc..46ea56815f6bbfd860e42304a6bc1d935ccb7a66 100644 (file)
@@ -9,7 +9,6 @@
 #include "pdns/pdnsexception.hh"
 #include "pdns/logger.hh"
 #include "pdns/arguments.hh"
-#include <boost/lexical_cast.hpp>
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
 #include "pdns/json.hh"
index fd1527b192282a515b6ce8f0616413acf1006cc3..3e800f0c63056fbb9e05a98c824b91273520a7d4 100644 (file)
@@ -18,7 +18,6 @@
 #include "pdns/logger.hh"
 #include "pdns/arguments.hh"
 #include "pdns/dnsrecords.hh"
-#include <boost/lexical_cast.hpp>
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
 #include "pdns/json.hh"
index f525887deac39e2bb02bf7d32b8e63101442c319..32339a7950bbf4a73076e27930fc423dd7d7d1d7 100644 (file)
@@ -9,7 +9,6 @@
 #include "pdns/pdnsexception.hh"
 #include "pdns/logger.hh"
 #include "pdns/arguments.hh"
-#include <boost/lexical_cast.hpp>
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
 #include "pdns/json.hh"
index dc8e3112d869e38594f693499a27d2df7206d308..cd06238343a85b0bf9bdeeb5a0b1016ad114bedb 100644 (file)
@@ -18,7 +18,6 @@
 #include "pdns/logger.hh"
 #include "pdns/arguments.hh"
 #include "pdns/dnsrecords.hh"
-#include <boost/lexical_cast.hpp>
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
 #include "pdns/json.hh"
index dd7de59cdd492d0eb7908b178cae0f078c40e996..e7b629944db8d270bc5ca45c44908b293a331ee6 100644 (file)
@@ -17,7 +17,6 @@
 #include "pdns/logger.hh"
 #include "pdns/arguments.hh"
 #include "pdns/dnsrecords.hh"
-#include <boost/lexical_cast.hpp>
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
 #include "pdns/json.hh"
index 4815d0f77a9d8627fcb521503cd03673d2414dc5..935cb770fdd38991f9080cce6ba5b484e47f4309 100644 (file)
@@ -16,7 +16,6 @@
 #include "pdns/pdnsexception.hh"
 #include "pdns/logger.hh"
 #include "pdns/arguments.hh"
-#include <boost/lexical_cast.hpp>
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
 #include "pdns/json.hh"
index 858311a46e4de1a46dbd10b3489b06cbff92677c..df5ee747c98ff1f06f449b3bd0491d2b1190f8f7 100644 (file)
@@ -17,7 +17,7 @@ UnixsocketConnector::UnixsocketConnector(std::map<std::string,std::string> optio
   } 
   this->timeout = 2000;
   if (options.find("timeout") != options.end()) { 
-    this->timeout = boost::lexical_cast<int>(options.find("timeout")->second);
+    this->timeout = std::stoi(options.find("timeout")->second);
   }
   this->path = options.find("path")->second;
   this->options = options;
index 4ec00b07ded7e1939b58e5e5063b402dc4f824e9..025f1e5ce42b963f599326f1015c1d46747e6983 100644 (file)
@@ -27,7 +27,7 @@ ZeroMQConnector::ZeroMQConnector(std::map<std::string,std::string> options) {
   this->d_timeout=2000;
 
   if (options.find("timeout") != options.end()) {
-     this->d_timeout = boost::lexical_cast<int>(options.find("timeout")->second);
+     this->d_timeout = std::stoi(options.find("timeout")->second);
   }
 
   d_ctx = zmq_init(2);