]> granicus.if.org Git - pdns/commitdiff
API: port recursor /jsonstat to json11
authorChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Mon, 28 Dec 2015 11:44:20 +0000 (12:44 +0100)
committerChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Tue, 29 Dec 2015 22:29:18 +0000 (23:29 +0100)
pdns/ws-recursor.cc

index 2f89e0521edf1af3304124007a6793ac746894c2..1b0af9a8bce600be7e2491ed3200384d44febf42 100644 (file)
@@ -439,33 +439,22 @@ void RecursorWebServer::jsonstat(HttpRequest* req, HttpResponse *resp)
     for(counts_t::const_iterator i=counts.begin(); i != counts.end(); ++i)
       rcounts.insert(make_pair(-i->second, i->first));
 
-    Document doc;
-    doc.SetObject();
-    Value entries;
-    entries.SetArray();
+    Json::array entries;
     unsigned int tot=0, totIncluded=0;
     for(const rcounts_t::value_type& q :  rcounts) {
-      Value arr;
-
-      arr.SetArray();
       totIncluded-=q.first;
-      arr.PushBack(-q.first, doc.GetAllocator());
-      arr.PushBack(q.second.first.toString().c_str(), doc.GetAllocator());
-      arr.PushBack(DNSRecordContent::NumberToType(q.second.second).c_str(), doc.GetAllocator());
-      entries.PushBack(arr, doc.GetAllocator());
+      entries.push_back(Json::array {
+        -q.first, q.second.first.toString(), DNSRecordContent::NumberToType(q.second.second)
+      });
       if(tot++>=100)
        break;
     }
     if(queries.size() != totIncluded) {
-      Value arr;
-      arr.SetArray();
-      arr.PushBack((unsigned int)(queries.size()-totIncluded), doc.GetAllocator());
-      arr.PushBack("", doc.GetAllocator());
-      arr.PushBack("", doc.GetAllocator());
-      entries.PushBack(arr, doc.GetAllocator());
+      entries.push_back(Json::array {
+        (int)(queries.size() - totIncluded), "", ""
+      });
     }
-    doc.AddMember("entries", entries, doc.GetAllocator());
-    resp->setBody(doc);
+    resp->setBody(Json::object { { "entries", entries } });
     return;
   }
   else if(command == "get-remote-ring") {
@@ -491,34 +480,23 @@ void RecursorWebServer::jsonstat(HttpRequest* req, HttpResponse *resp)
     for(counts_t::const_iterator i=counts.begin(); i != counts.end(); ++i)
       rcounts.insert(make_pair(-i->second, i->first));
 
-
-    Document doc;
-    doc.SetObject();
-    Value entries;
-    entries.SetArray();
+    Json::array entries;
     unsigned int tot=0, totIncluded=0;
     for(const rcounts_t::value_type& q :  rcounts) {
       totIncluded-=q.first;
-      Value arr;
-
-      arr.SetArray();
-      arr.PushBack(-q.first, doc.GetAllocator());
-      Value jname(q.second.toString().c_str(), doc.GetAllocator()); // copy
-      arr.PushBack(jname, doc.GetAllocator());
-      entries.PushBack(arr, doc.GetAllocator());
+      entries.push_back(Json::array {
+        -q.first, q.second.toString()
+      });
       if(tot++>=100)
        break;
     }
     if(queries.size() != totIncluded) {
-      Value arr;
-      arr.SetArray();
-      arr.PushBack((unsigned int)(queries.size()-totIncluded), doc.GetAllocator());
-      arr.PushBack("", doc.GetAllocator());
-      entries.PushBack(arr, doc.GetAllocator());
+      entries.push_back(Json::array {
+        (int)(queries.size() - totIncluded), "", ""
+      });
     }
 
-    doc.AddMember("entries", entries, doc.GetAllocator());
-    resp->setBody(doc);
+    resp->setBody(Json::object { { "entries", entries } });
     return;
   } else {
     resp->status = 404;