/*
PowerDNS Versatile Database Driven Nameserver
- Copyright (C) 2002-2010 PowerDNS.COM BV
+ Copyright (C) 2002-2012 PowerDNS.COM BV
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
}
}while(!line.empty());
-
if(!d_password.empty() && !authOK) {
client->putLine("HTTP/1.1 401 OK\n");
client->putLine("WWW-Authenticate: Basic realm=\"PowerDNS\"\n");
string StatWebServer::indexfunction(const map<string,string> &varmap, void *ptr, bool *custom)
{
-
StatWebServer *sws=static_cast<StatWebServer *>(ptr);
map<string,string>rvarmap=varmap;
if(!rvarmap["resetring"].empty()){
return ret.str();
}
+string StatWebServer::jsonstat(const map<string,string> &varmap, void *ptr, bool *custom)
+{
+ *custom=1;
+ string ret="HTTP/1.1 200 OK\r\n"
+ "Date: Wed, 30 Nov 2011 22:01:15 GMT\r\n" // XXX FIXME real date!
+ "Server: PowerDNS/"VERSION"\r\n"
+ "Connection: Keep-Alive\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "Access-Control-Allow-Origin: *\r\n"
+ "Content-Type: application/json\r\n"
+ "\r\n" ;
+
+ typedef map<string,string> varmap_t;
+ string variable, value;
+ ret="{";
+ for(varmap_t::const_iterator iter = varmap.begin(); iter != varmap.end() ; ++iter) {
+ if(iter != varmap.begin())
+ ret += ",";
+
+ variable = iter->first;
+ if(variable == "version")
+ value = '"'+string(VERSION)+'"';
+ else
+ value = lexical_cast<string>(S.read(variable));
+
+ ret += '"'+ variable +"\": "+ value;
+ }
+ ret+="}";
+ return ret;
+}
+
void StatWebServer::launch()
{
try {
d_ws->setCaller(this);
d_ws->registerHandler("",&indexfunction);
+ d_ws->registerHandler("jsonstat", &jsonstat);
d_ws->go();
}
catch(...) {
static void *threadHelper(void *);
static void *statThreadHelper(void *p);
static string indexfunction(const map<string,string> &varmap, void *ptr, bool *custom);
-
+ static string jsonstat(const map<string,string> &varmap, void *ptr, bool *custom);
void printvars(ostringstream &ret);
void printargs(ostringstream &ret);
void launch();