]> granicus.if.org Git - pdns/commitdiff
remotebackend: inline makeStringFromDocument, drop json.hh include
authorChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Mon, 28 Dec 2015 10:28:11 +0000 (11:28 +0100)
committerChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Tue, 29 Dec 2015 22:29:15 +0000 (23:29 +0100)
13 files changed:
modules/remotebackend/Makefile.am
modules/remotebackend/httpconnector.cc
modules/remotebackend/pipeconnector.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 7dcd9bef4ee60a317f1e488904b7aa95311f58a7..8338e72d834a835c893e543a64b8dd3b3d050305 100644 (file)
@@ -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 \
index eedaf0315ae59c8ddee05c1be344b0ced29407b1..3631a45cfc9c94eb991037686d7187f58d8befa3 100644 (file)
@@ -7,8 +7,8 @@
 #include <fcntl.h>
 
 #include <sstream>
-#include "rapidjson/stringbuffer.h"
-#include "rapidjson/writer.h"
+#include <rapidjson/stringbuffer.h>
+#include <rapidjson/writer.h>
 #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<rapidjson::StringBuffer> 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<rapidjson::StringBuffer> w(output);
         input["parameters"].Accept(w);
         url << d_url << "/" << input["method"].GetString() << d_url_suffix;
         req.setup("POST", url.str());
index 016d98f800d6c43d7b806b852e35958d850b78a2..26100134d59ecd9df68535529e3febb22a2aed30 100644 (file)
@@ -3,6 +3,9 @@
 #endif
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <sstream>
+#include <rapidjson/stringbuffer.h>
+#include <rapidjson/writer.h>
 #include "remotebackend.hh"
 
 PipeConnector::PipeConnector(std::map<std::string,std::string> 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<rapidjson::StringBuffer> w(output);
+   input.Accept(w);
+   auto line = std::string(output.GetString(), output.Size());
    launch();
 
    line.append(1,'\n');
index 15e5c11c7faae6dd94d9fe84dd0d09f87e8efadd..5fd433123b7ecd6f197c7fc5095d9f7bc1896f30 100644 (file)
@@ -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"
index e90f1203c10a0410170da8b792bc7f99842667b2..29675388244d6bfd9d15f55194e8dc45f616852b 100644 (file)
@@ -11,7 +11,6 @@
 #include "pdns/arguments.hh"
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
-#include "pdns/json.hh"
 #include "pdns/statbag.hh"
 #include "pdns/packetcache.hh"
 
index 46ea56815f6bbfd860e42304a6bc1d935ccb7a66..10a7c97fcd439cecf96bfbe171ecd0267ebb9ca5 100644 (file)
@@ -11,7 +11,6 @@
 #include "pdns/arguments.hh"
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
-#include "pdns/json.hh"
 #include "pdns/statbag.hh"
 #include "pdns/packetcache.hh"
 
index 3e800f0c63056fbb9e05a98c824b91273520a7d4..e1e9a58943b6aa699739c589dbf940fe13f03003 100644 (file)
@@ -20,7 +20,6 @@
 #include "pdns/dnsrecords.hh"
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
-#include "pdns/json.hh"
 #include "pdns/statbag.hh"
 #include "pdns/packetcache.hh"
 
index 32339a7950bbf4a73076e27930fc423dd7d7d1d7..a5d3940855f3f9d2594c693de37b87b22b1c10fe 100644 (file)
@@ -11,7 +11,6 @@
 #include "pdns/arguments.hh"
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
-#include "pdns/json.hh"
 #include "pdns/statbag.hh"
 #include "pdns/packetcache.hh"
 
index cd06238343a85b0bf9bdeeb5a0b1016ad114bedb..b5467337c343c2eeda1e46c1648c848cf7670abb 100644 (file)
@@ -20,7 +20,6 @@
 #include "pdns/dnsrecords.hh"
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
-#include "pdns/json.hh"
 #include "pdns/statbag.hh"
 #include "pdns/packetcache.hh"
 
index e7b629944db8d270bc5ca45c44908b293a331ee6..38ab1d8e447efbac47b5f1e3ef51e0032a97e06d 100644 (file)
@@ -19,7 +19,6 @@
 #include "pdns/dnsrecords.hh"
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
-#include "pdns/json.hh"
 #include "pdns/statbag.hh"
 #include "pdns/packetcache.hh"
 
index 935cb770fdd38991f9080cce6ba5b484e47f4309..06efcd8d0a717c0986a00fce10541f9458b59d7a 100644 (file)
@@ -18,7 +18,6 @@
 #include "pdns/arguments.hh"
 #include <rapidjson/rapidjson.h>
 #include <rapidjson/document.h>
-#include "pdns/json.hh"
 #include "pdns/statbag.hh"
 #include "pdns/packetcache.hh"
 
index df5ee747c98ff1f06f449b3bd0491d2b1190f8f7..b10d5880c64b01cf441f7dbc1115fbe63f8ef7e1 100644 (file)
@@ -3,6 +3,9 @@
 #endif
 #include "remotebackend.hh"
 #include <sys/socket.h>
+#include <sstream>
+#include <rapidjson/stringbuffer.h>
+#include <rapidjson/writer.h>
 #include "pdns/lock.hh" 
 #include <unistd.h>
 #include <fcntl.h>
@@ -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<rapidjson::StringBuffer> 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;
index 025f1e5ce42b963f599326f1015c1d46747e6983..18980204422db6781f3e75fea4b1436b37a09b02 100644 (file)
@@ -9,8 +9,8 @@
 #include <fcntl.h>
 
 #include <sstream>
-#include "rapidjson/stringbuffer.h"
-#include "rapidjson/writer.h"
+#include <rapidjson/stringbuffer.h>
+#include <rapidjson/writer.h>
 
 ZeroMQConnector::ZeroMQConnector(std::map<std::string,std::string> 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<rapidjson::StringBuffer> 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);