#include <iomanip>
extern string s_programname;
+using json11::Json;
#ifndef HAVE_STRCASESTR
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);
}
if(req->method != "GET")
throw HttpMethodNotAllowedException();
- Document doc;
- fillServerDetail(doc, doc.GetAllocator());
- resp->setBody(doc);
+ resp->setBody(getServerDetail());
}
void apiServerConfig(HttpRequest* req, HttpResponse* resp) {