]> granicus.if.org Git - pdns/commitdiff
API: port log-search to json11
authorChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Mon, 28 Dec 2015 00:54:23 +0000 (01:54 +0100)
committerChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Tue, 29 Dec 2015 22:29:16 +0000 (23:29 +0100)
pdns/ws-api.cc

index 80a283c17c5604826e3110897d31b264109a66d8..780878a4a8dae435ec964651c5bbec7f9d37c796 100644 (file)
@@ -137,7 +137,7 @@ void apiServerConfig(HttpRequest* req, HttpResponse* resp) {
   resp->setBody(doc);
 }
 
-static string logGrep(const string& q, const string& fname, const string& prefix)
+static Json logGrep(const string& q, const string& fname, const string& prefix)
 {
   FILE* ptr = fopen(fname.c_str(), "r");
   if(!ptr) {
@@ -169,14 +169,11 @@ static string logGrep(const string& q, const string& fname, const string& prefix
     }
   }
 
-  Document doc;
-  doc.SetArray();
-  if(!lines.empty()) {
-    for(const string& line :  lines) {
-      doc.PushBack(line.c_str(), doc.GetAllocator());
-    }
+  Json::array items;
+  for(const string& line : lines) {
+    items.push_back(line);
   }
-  return makeStringFromDocument(doc);
+  return items;
 }
 
 void apiServerSearchLog(HttpRequest* req, HttpResponse* resp) {
@@ -184,7 +181,7 @@ void apiServerSearchLog(HttpRequest* req, HttpResponse* resp) {
     throw HttpMethodNotAllowedException();
 
   string prefix = " " + s_programname + "[";
-  resp->body = logGrep(req->getvars["q"], ::arg()["api-logfile"], prefix);
+  resp->setBody(logGrep(req->getvars["q"], ::arg()["api-logfile"], prefix));
 }
 
 void apiServerStatistics(HttpRequest* req, HttpResponse* resp) {