From: Christian Hofstaedtler Date: Mon, 28 Dec 2015 10:28:11 +0000 (+0100) Subject: remotebackend: inline makeStringFromDocument, drop json.hh include X-Git-Tag: dnsdist-1.0.0-alpha2~123^2~19 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=50e2c25cfb0c95e5097a2e3038c49510515a4829;p=pdns remotebackend: inline makeStringFromDocument, drop json.hh include --- diff --git a/modules/remotebackend/Makefile.am b/modules/remotebackend/Makefile.am index 7dcd9bef4..8338e72d8 100644 --- a/modules/remotebackend/Makefile.am +++ b/modules/remotebackend/Makefile.am @@ -103,7 +103,6 @@ libtestremotebackend_la_SOURCES = \ ../../pdns/dnsrecords.cc \ ../../pdns/dnssecinfra.cc \ ../../pdns/ednssubnet.cc \ - ../../pdns/json.hh ../../pdns/json.cc \ ../../pdns/logger.cc \ ../../pdns/misc.cc \ ../../pdns/nsecrecords.cc \ diff --git a/modules/remotebackend/httpconnector.cc b/modules/remotebackend/httpconnector.cc index eedaf0315..3631a45cf 100644 --- a/modules/remotebackend/httpconnector.cc +++ b/modules/remotebackend/httpconnector.cc @@ -7,8 +7,8 @@ #include #include -#include "rapidjson/stringbuffer.h" -#include "rapidjson/writer.h" +#include +#include #include "pdns/lock.hh" #ifndef UNIX_PATH_MAX @@ -277,12 +277,14 @@ void HTTPConnector::restful_requestbuilder(const std::string &method, const rapi req.headers["accept"] = "application/json"; } - void HTTPConnector::post_requestbuilder(const rapidjson::Document &input, YaHTTP::Request& req) { + rapidjson::StringBuffer output; + rapidjson::Writer w(output); if (this->d_post_json) { req.setup("POST", d_url); // simple case, POST JSON into url. nothing fancy. - std::string out = makeStringFromDocument(input); + input.Accept(w); + std::string out(output.GetString(), output.Size()); req.headers["Content-Type"] = "text/javascript; charset=utf-8"; req.headers["Content-Length"] = std::to_string(out.size()); req.headers["accept"] = "application/json"; @@ -290,8 +292,6 @@ void HTTPConnector::post_requestbuilder(const rapidjson::Document &input, YaHTTP } else { std::stringstream url,content; // call url/method.suffix - rapidjson::StringBuffer output; - rapidjson::Writer w(output); input["parameters"].Accept(w); url << d_url << "/" << input["method"].GetString() << d_url_suffix; req.setup("POST", url.str()); diff --git a/modules/remotebackend/pipeconnector.cc b/modules/remotebackend/pipeconnector.cc index 016d98f80..26100134d 100644 --- a/modules/remotebackend/pipeconnector.cc +++ b/modules/remotebackend/pipeconnector.cc @@ -3,6 +3,9 @@ #endif #include #include +#include +#include +#include #include "remotebackend.hh" PipeConnector::PipeConnector(std::map options) { @@ -117,8 +120,10 @@ void PipeConnector::launch() { int PipeConnector::send_message(const rapidjson::Document &input) { - std::string line; - line = makeStringFromDocument(input); + rapidjson::StringBuffer output; + rapidjson::Writer w(output); + input.Accept(w); + auto line = std::string(output.GetString(), output.Size()); launch(); line.append(1,'\n'); diff --git a/modules/remotebackend/remotebackend.hh b/modules/remotebackend/remotebackend.hh index 15e5c11c7..5fd433123 100644 --- a/modules/remotebackend/remotebackend.hh +++ b/modules/remotebackend/remotebackend.hh @@ -6,7 +6,6 @@ #include "pdns/dns.hh" #include "pdns/dnsbackend.hh" #include "pdns/dnspacket.hh" -#include "pdns/json.hh" #include "pdns/logger.hh" #include "pdns/namespaces.hh" #include "pdns/pdnsexception.hh" diff --git a/modules/remotebackend/test-remotebackend-http.cc b/modules/remotebackend/test-remotebackend-http.cc index e90f1203c..296753882 100644 --- a/modules/remotebackend/test-remotebackend-http.cc +++ b/modules/remotebackend/test-remotebackend-http.cc @@ -11,7 +11,6 @@ #include "pdns/arguments.hh" #include #include -#include "pdns/json.hh" #include "pdns/statbag.hh" #include "pdns/packetcache.hh" diff --git a/modules/remotebackend/test-remotebackend-json.cc b/modules/remotebackend/test-remotebackend-json.cc index 46ea56815..10a7c97fc 100644 --- a/modules/remotebackend/test-remotebackend-json.cc +++ b/modules/remotebackend/test-remotebackend-json.cc @@ -11,7 +11,6 @@ #include "pdns/arguments.hh" #include #include -#include "pdns/json.hh" #include "pdns/statbag.hh" #include "pdns/packetcache.hh" diff --git a/modules/remotebackend/test-remotebackend-pipe.cc b/modules/remotebackend/test-remotebackend-pipe.cc index 3e800f0c6..e1e9a5894 100644 --- a/modules/remotebackend/test-remotebackend-pipe.cc +++ b/modules/remotebackend/test-remotebackend-pipe.cc @@ -20,7 +20,6 @@ #include "pdns/dnsrecords.hh" #include #include -#include "pdns/json.hh" #include "pdns/statbag.hh" #include "pdns/packetcache.hh" diff --git a/modules/remotebackend/test-remotebackend-post.cc b/modules/remotebackend/test-remotebackend-post.cc index 32339a795..a5d394085 100644 --- a/modules/remotebackend/test-remotebackend-post.cc +++ b/modules/remotebackend/test-remotebackend-post.cc @@ -11,7 +11,6 @@ #include "pdns/arguments.hh" #include #include -#include "pdns/json.hh" #include "pdns/statbag.hh" #include "pdns/packetcache.hh" diff --git a/modules/remotebackend/test-remotebackend-unix.cc b/modules/remotebackend/test-remotebackend-unix.cc index cd0623834..b5467337c 100644 --- a/modules/remotebackend/test-remotebackend-unix.cc +++ b/modules/remotebackend/test-remotebackend-unix.cc @@ -20,7 +20,6 @@ #include "pdns/dnsrecords.hh" #include #include -#include "pdns/json.hh" #include "pdns/statbag.hh" #include "pdns/packetcache.hh" diff --git a/modules/remotebackend/test-remotebackend-zeromq.cc b/modules/remotebackend/test-remotebackend-zeromq.cc index e7b629944..38ab1d8e4 100644 --- a/modules/remotebackend/test-remotebackend-zeromq.cc +++ b/modules/remotebackend/test-remotebackend-zeromq.cc @@ -19,7 +19,6 @@ #include "pdns/dnsrecords.hh" #include #include -#include "pdns/json.hh" #include "pdns/statbag.hh" #include "pdns/packetcache.hh" diff --git a/modules/remotebackend/test-remotebackend.cc b/modules/remotebackend/test-remotebackend.cc index 935cb770f..06efcd8d0 100644 --- a/modules/remotebackend/test-remotebackend.cc +++ b/modules/remotebackend/test-remotebackend.cc @@ -18,7 +18,6 @@ #include "pdns/arguments.hh" #include #include -#include "pdns/json.hh" #include "pdns/statbag.hh" #include "pdns/packetcache.hh" diff --git a/modules/remotebackend/unixconnector.cc b/modules/remotebackend/unixconnector.cc index df5ee747c..b10d5880c 100644 --- a/modules/remotebackend/unixconnector.cc +++ b/modules/remotebackend/unixconnector.cc @@ -3,6 +3,9 @@ #endif #include "remotebackend.hh" #include +#include +#include +#include #include "pdns/lock.hh" #include #include @@ -33,11 +36,11 @@ UnixsocketConnector::~UnixsocketConnector() { } int UnixsocketConnector::send_message(const rapidjson::Document &input) { - std::string data; - int rv; - data = makeStringFromDocument(input); - data = data + "\n"; - rv = this->write(data); + rapidjson::StringBuffer output; + rapidjson::Writer w(output); + input.Accept(w); + auto data = std::string(output.GetString(), output.Size()) + "\n"; + int rv = this->write(data); if (rv == -1) return -1; return rv; diff --git a/modules/remotebackend/zmqconnector.cc b/modules/remotebackend/zmqconnector.cc index 025f1e5ce..189802044 100644 --- a/modules/remotebackend/zmqconnector.cc +++ b/modules/remotebackend/zmqconnector.cc @@ -9,8 +9,8 @@ #include #include -#include "rapidjson/stringbuffer.h" -#include "rapidjson/writer.h" +#include +#include ZeroMQConnector::ZeroMQConnector(std::map options) { rapidjson::Value val; @@ -65,8 +65,10 @@ ZeroMQConnector::~ZeroMQConnector() { }; int ZeroMQConnector::send_message(const rapidjson::Document &input) { - std::string line; - line = makeStringFromDocument(input); + rapidjson::StringBuffer output; + rapidjson::Writer w(output); + input.Accept(w); + auto line = std::string(output.GetString(), output.Size()); zmq_msg_t message; zmq_msg_init_size(&message, line.size()+1);