]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
API: replace returnJsonObject with json11 code
authorChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Mon, 28 Dec 2015 11:56:17 +0000 (12:56 +0100)
committerChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Tue, 29 Dec 2015 22:29:18 +0000 (23:29 +0100)
pdns/json.cc
pdns/json.hh
pdns/ws-auth.cc
pdns/ws-recursor.cc

index b0bd9e51331ba292218d20cc87682625d6ea7792..0e58c0a86ffa60455902354b13d1f875a1c01f68 100644 (file)
@@ -180,17 +180,6 @@ string makeStringFromDocument(const Document& doc)
   return string(output.GetString(), output.Size());
 }
 
-string returnJsonObject(const map<string, string>& items)
-{
-  Document doc;
-  doc.SetObject();
-  typedef map<string, string> items_t;
-  for(const items_t::value_type& val :  items) {
-    doc.AddMember(val.first.c_str(), val.second.c_str(), doc.GetAllocator());
-  }
-  return makeStringFromDocument(doc);
-}
-
 string returnJsonError(const string& error)
 {
   Document doc;
index 726f8de4502663fba8a9d1f75be6fee9f77a8431..72df628412f2be1f9e69c1d74b58fed8e93dfee0 100644 (file)
@@ -27,7 +27,6 @@
 #include "rapidjson/document.h"
 #include "json11.hpp"
 
-std::string returnJsonObject(const std::map<std::string, std::string>& items);
 std::string returnJsonError(const std::string& error);
 std::string returnJsonMessage(const std::string& message);
 std::string makeStringFromDocument(const rapidjson::Document& doc);
index b0cd581dea3bcb932a069aa920d948885a94e0db..b9781aefa7a7d13e7f9fef02cfba758274c5afd7 100644 (file)
@@ -1086,11 +1086,10 @@ void apiServerCacheFlush(HttpRequest* req, HttpResponse* resp) {
 
   extern PacketCache PC;
   int count = PC.purgeExact(canon);
-
-  map<string, string> object;
-  object["count"] = std::to_string(count);
-  object["result"] = "Flushed cache.";
-  resp->body = returnJsonObject(object);
+  resp->setBody(Json::object {
+    { "count", count },
+    { "result", "Flushed cache." }
+  });
 }
 
 void AuthWebServer::cssfunction(HttpRequest* req, HttpResponse* resp)
index 1b0af9a8bce600be7e2491ed3200384d44febf42..c5665031c3798fe335e178c8e1115a36575f2d1c 100644 (file)
@@ -373,10 +373,10 @@ static void apiServerCacheFlush(HttpRequest* req, HttpResponse* resp) {
   int count = broadcastAccFunction<uint64_t>(boost::bind(pleaseWipeCache, canon, false));
   count += broadcastAccFunction<uint64_t>(boost::bind(pleaseWipePacketCache, canon, false));
   count += broadcastAccFunction<uint64_t>(boost::bind(pleaseWipeAndCountNegCache, canon, false));
-  map<string, string> object;
-  object["count"] = std::to_string(count);
-  object["result"] = "Flushed cache.";
-  resp->body = returnJsonObject(object);
+  resp->setBody(Json::object {
+    { "count", count },
+    { "result", "Flushed cache." }
+  });
 }
 
 RecursorWebServer::RecursorWebServer(FDMultiplexer* fdm)