From: Christian Hofstaedtler Date: Mon, 28 Dec 2015 11:56:17 +0000 (+0100) Subject: API: replace returnJsonObject with json11 code X-Git-Tag: dnsdist-1.0.0-alpha2~123^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f682752ae50439cfa6c3d1a60abf85b62fba4190;p=thirdparty%2Fpdns.git API: replace returnJsonObject with json11 code --- diff --git a/pdns/json.cc b/pdns/json.cc index b0bd9e5133..0e58c0a86f 100644 --- a/pdns/json.cc +++ b/pdns/json.cc @@ -180,17 +180,6 @@ string makeStringFromDocument(const Document& doc) return string(output.GetString(), output.Size()); } -string returnJsonObject(const map& items) -{ - Document doc; - doc.SetObject(); - typedef map 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; diff --git a/pdns/json.hh b/pdns/json.hh index 726f8de450..72df628412 100644 --- a/pdns/json.hh +++ b/pdns/json.hh @@ -27,7 +27,6 @@ #include "rapidjson/document.h" #include "json11.hpp" -std::string returnJsonObject(const std::map& items); std::string returnJsonError(const std::string& error); std::string returnJsonMessage(const std::string& message); std::string makeStringFromDocument(const rapidjson::Document& doc); diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index b0cd581dea..b9781aefa7 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -1086,11 +1086,10 @@ void apiServerCacheFlush(HttpRequest* req, HttpResponse* resp) { extern PacketCache PC; int count = PC.purgeExact(canon); - - map 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) diff --git a/pdns/ws-recursor.cc b/pdns/ws-recursor.cc index 1b0af9a8bc..c5665031c3 100644 --- a/pdns/ws-recursor.cc +++ b/pdns/ws-recursor.cc @@ -373,10 +373,10 @@ static void apiServerCacheFlush(HttpRequest* req, HttpResponse* resp) { int count = broadcastAccFunction(boost::bind(pleaseWipeCache, canon, false)); count += broadcastAccFunction(boost::bind(pleaseWipePacketCache, canon, false)); count += broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, canon, false)); - map 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)