From: Christian Hofstaedtler Date: Mon, 28 Dec 2015 00:54:19 +0000 (+0100) Subject: API: port /api/v1/servers{/localhost} to json11 X-Git-Tag: dnsdist-1.0.0-alpha2~123^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f461cf07b45aff63a48e5861b88991a07633c4b2;p=thirdparty%2Fpdns.git API: port /api/v1/servers{/localhost} to json11 --- diff --git a/pdns/ws-api.cc b/pdns/ws-api.cc index a24b7774e9..80a283c17c 100644 --- a/pdns/ws-api.cc +++ b/pdns/ws-api.cc @@ -36,6 +36,7 @@ #include extern string s_programname; +using json11::Json; #ifndef HAVE_STRCASESTR @@ -80,29 +81,23 @@ strcasestr(const char *s1, const char *s2) using namespace rapidjson; -static void fillServerDetail(Value& out, Value::AllocatorType& allocator) -{ - Value jdaemonType(productTypeApiType().c_str(), allocator); - out.SetObject(); - out.AddMember("type", "Server", allocator); - out.AddMember("id", "localhost", allocator); - out.AddMember("url", "/api/v1/servers/localhost", allocator); - out.AddMember("daemon_type", jdaemonType, allocator); - Value jversion(getPDNSVersion().c_str(), allocator); - out.AddMember("version", jversion, allocator); - out.AddMember("config_url", "/api/v1/servers/localhost/config{/config_setting}", allocator); - out.AddMember("zones_url", "/api/v1/servers/localhost/zones{/zone}", allocator); +static Json getServerDetail() { + return Json::object { + { "type", "Server" }, + { "id", "localhost" }, + { "url", "/api/v1/servers/localhost" }, + { "daemon_type", productTypeApiType() }, + { "version", getPDNSVersion() }, + { "config_url", "/api/v1/servers/localhost/config{/config_setting}" }, + { "zones_url", "/api/v1/servers/localhost/zones{/zone}" } + }; } void apiServer(HttpRequest* req, HttpResponse* resp) { if(req->method != "GET") throw HttpMethodNotAllowedException(); - Document doc; - doc.SetArray(); - Value server; - fillServerDetail(server, doc.GetAllocator()); - doc.PushBack(server, doc.GetAllocator()); + Json doc = Json::array {getServerDetail()}; resp->setBody(doc); } @@ -110,9 +105,7 @@ void apiServerDetail(HttpRequest* req, HttpResponse* resp) { if(req->method != "GET") throw HttpMethodNotAllowedException(); - Document doc; - fillServerDetail(doc, doc.GetAllocator()); - resp->setBody(doc); + resp->setBody(getServerDetail()); } void apiServerConfig(HttpRequest* req, HttpResponse* resp) {