From: Aki Tuomi Date: Fri, 11 Dec 2015 15:43:08 +0000 (+0200) Subject: Use proper integer conversions in remotebackend X-Git-Tag: dnsdist-1.0.0-alpha1~34^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d8ead9781e126a3e1577739417becb03ab6342d;p=thirdparty%2Fpdns.git Use proper integer conversions in remotebackend --- diff --git a/modules/remotebackend/httpconnector.cc b/modules/remotebackend/httpconnector.cc index 94cf246560..eedaf0315a 100644 --- a/modules/remotebackend/httpconnector.cc +++ b/modules/remotebackend/httpconnector.cc @@ -28,7 +28,7 @@ HTTPConnector::HTTPConnector(std::map options) { this->d_socket = NULL; if (options.find("timeout") != options.end()) { - this->timeout = boost::lexical_cast(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(input.GetUint64()); - else if (input.IsInt64()) output = lexical_cast(input.GetInt64()); - else if (input.IsUint()) output = lexical_cast(input.GetUint()); - else if (input.IsInt()) output = lexical_cast(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(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(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(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(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", ¶meters["rr"]); req.headers["content-type"] = "application/x-www-form-urlencoded; charset=utf-8"; - req.headers["content-length"] = boost::lexical_cast(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(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(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", ¶meters["sd"]); req.headers["content-type"] = "application/x-www-form-urlencoded; charset=utf-8"; - req.headers["content-length"] = boost::lexical_cast(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(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(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(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(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; diff --git a/modules/remotebackend/pipeconnector.cc b/modules/remotebackend/pipeconnector.cc index fef490217c..016d98f800 100644 --- a/modules/remotebackend/pipeconnector.cc +++ b/modules/remotebackend/pipeconnector.cc @@ -15,7 +15,7 @@ PipeConnector::PipeConnector(std::map options) { d_timeout=2000; if (options.find("timeout") != options.end()) { - d_timeout = boost::lexical_cast(options.find("timeout")->second); + d_timeout = std::stoi(options.find("timeout")->second); } d_pid = -1; diff --git a/modules/remotebackend/remotebackend.cc b/modules/remotebackend/remotebackend.cc index 6c8be5bcd0..bd5ea1bfd8 100644 --- a/modules/remotebackend/remotebackend.cc +++ b/modules/remotebackend/remotebackend.cc @@ -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(value.GetInt64()); - if (value.IsInt()) return boost::lexical_cast(value.GetInt()); - if (value.IsDouble()) return boost::lexical_cast(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(value.GetDouble()); if (value.IsString()) { // accepts 0, 1, false, true std::string tmp = value.GetString(); - return boost::lexical_cast(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(value.GetDouble()); if (value.IsString()) { // accepts 0, 1, false, true std::string tmp = value.GetString(); - return boost::lexical_cast(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(value.GetDouble()); if (value.IsString()) { // accepts 0, 1, false, true std::string tmp = value.GetString(); - return boost::lexical_cast(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(value.GetInt64()); - if (value.IsInt()) return boost::lexical_cast(value.GetInt()); - if (value.IsDouble()) return boost::lexical_cast(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(value.GetInt()); if (value.IsString()) { // accepts 0, 1, false, true std::string tmp = value.GetString(); - return boost::lexical_cast(tmp); + return std::stod(tmp); } throw PDNSException("Cannot convert rapidjson value into double"); } diff --git a/modules/remotebackend/remotebackend.hh b/modules/remotebackend/remotebackend.hh index b0720879b9..15e5c11c7f 100644 --- a/modules/remotebackend/remotebackend.hh +++ b/modules/remotebackend/remotebackend.hh @@ -12,7 +12,6 @@ #include "pdns/pdnsexception.hh" #include "pdns/sstuff.hh" #include "pdns/ueberbackend.hh" -#include #include #include #include "yahttp/yahttp.hpp" diff --git a/modules/remotebackend/test-remotebackend-http.cc b/modules/remotebackend/test-remotebackend-http.cc index 05f36cd9b9..e90f1203c1 100644 --- a/modules/remotebackend/test-remotebackend-http.cc +++ b/modules/remotebackend/test-remotebackend-http.cc @@ -9,7 +9,6 @@ #include "pdns/pdnsexception.hh" #include "pdns/logger.hh" #include "pdns/arguments.hh" -#include #include #include #include "pdns/json.hh" diff --git a/modules/remotebackend/test-remotebackend-json.cc b/modules/remotebackend/test-remotebackend-json.cc index a020b92427..46ea56815f 100644 --- a/modules/remotebackend/test-remotebackend-json.cc +++ b/modules/remotebackend/test-remotebackend-json.cc @@ -9,7 +9,6 @@ #include "pdns/pdnsexception.hh" #include "pdns/logger.hh" #include "pdns/arguments.hh" -#include #include #include #include "pdns/json.hh" diff --git a/modules/remotebackend/test-remotebackend-pipe.cc b/modules/remotebackend/test-remotebackend-pipe.cc index fd1527b192..3e800f0c63 100644 --- a/modules/remotebackend/test-remotebackend-pipe.cc +++ b/modules/remotebackend/test-remotebackend-pipe.cc @@ -18,7 +18,6 @@ #include "pdns/logger.hh" #include "pdns/arguments.hh" #include "pdns/dnsrecords.hh" -#include #include #include #include "pdns/json.hh" diff --git a/modules/remotebackend/test-remotebackend-post.cc b/modules/remotebackend/test-remotebackend-post.cc index f525887dea..32339a7950 100644 --- a/modules/remotebackend/test-remotebackend-post.cc +++ b/modules/remotebackend/test-remotebackend-post.cc @@ -9,7 +9,6 @@ #include "pdns/pdnsexception.hh" #include "pdns/logger.hh" #include "pdns/arguments.hh" -#include #include #include #include "pdns/json.hh" diff --git a/modules/remotebackend/test-remotebackend-unix.cc b/modules/remotebackend/test-remotebackend-unix.cc index dc8e3112d8..cd06238343 100644 --- a/modules/remotebackend/test-remotebackend-unix.cc +++ b/modules/remotebackend/test-remotebackend-unix.cc @@ -18,7 +18,6 @@ #include "pdns/logger.hh" #include "pdns/arguments.hh" #include "pdns/dnsrecords.hh" -#include #include #include #include "pdns/json.hh" diff --git a/modules/remotebackend/test-remotebackend-zeromq.cc b/modules/remotebackend/test-remotebackend-zeromq.cc index dd7de59cdd..e7b629944d 100644 --- a/modules/remotebackend/test-remotebackend-zeromq.cc +++ b/modules/remotebackend/test-remotebackend-zeromq.cc @@ -17,7 +17,6 @@ #include "pdns/logger.hh" #include "pdns/arguments.hh" #include "pdns/dnsrecords.hh" -#include #include #include #include "pdns/json.hh" diff --git a/modules/remotebackend/test-remotebackend.cc b/modules/remotebackend/test-remotebackend.cc index 4815d0f77a..935cb770fd 100644 --- a/modules/remotebackend/test-remotebackend.cc +++ b/modules/remotebackend/test-remotebackend.cc @@ -16,7 +16,6 @@ #include "pdns/pdnsexception.hh" #include "pdns/logger.hh" #include "pdns/arguments.hh" -#include #include #include #include "pdns/json.hh" diff --git a/modules/remotebackend/unixconnector.cc b/modules/remotebackend/unixconnector.cc index 858311a46e..df5ee747c9 100644 --- a/modules/remotebackend/unixconnector.cc +++ b/modules/remotebackend/unixconnector.cc @@ -17,7 +17,7 @@ UnixsocketConnector::UnixsocketConnector(std::map optio } this->timeout = 2000; if (options.find("timeout") != options.end()) { - this->timeout = boost::lexical_cast(options.find("timeout")->second); + this->timeout = std::stoi(options.find("timeout")->second); } this->path = options.find("path")->second; this->options = options; diff --git a/modules/remotebackend/zmqconnector.cc b/modules/remotebackend/zmqconnector.cc index 4ec00b07de..025f1e5ce4 100644 --- a/modules/remotebackend/zmqconnector.cc +++ b/modules/remotebackend/zmqconnector.cc @@ -27,7 +27,7 @@ ZeroMQConnector::ZeroMQConnector(std::map options) { this->d_timeout=2000; if (options.find("timeout") != options.end()) { - this->d_timeout = boost::lexical_cast(options.find("timeout")->second); + this->d_timeout = std::stoi(options.find("timeout")->second); } d_ctx = zmq_init(2);