From: Christian Hofstaedtler Date: Wed, 28 Aug 2013 14:11:03 +0000 (+0200) Subject: jsonstat: accept ints as strings or ints X-Git-Tag: rec-3.6.0-rc1~462^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=12a82d650b58bf7e17e16b66c6ba247114099f44;p=pdns jsonstat: accept ints as strings or ints --- diff --git a/pdns/ws.cc b/pdns/ws.cc index 5ba85bcbd..f4cea02a3 100644 --- a/pdns/ws.cc +++ b/pdns/ws.cc @@ -33,6 +33,7 @@ #include "rapidjson/stringbuffer.h" #include "rapidjson/writer.h" #include "version.hh" +#include "session.hh" using namespace rapidjson; @@ -247,6 +248,15 @@ string StatWebServer::indexfunction(const string& method, const string& post, co return ret.str(); } +static int int_from_json(const Value& val) { + if (val.IsInt()) { + return val.GetInt(); + } else if (val.IsString()) { + return atoi(val.GetString()); + } else { + throw Exception("Value not an Integer"); + } +} string StatWebServer::jsonstat(const string& method, const string& post, const map &varmap, void *ptr, bool *custom) { @@ -460,8 +470,8 @@ string StatWebServer::jsonstat(const string& method, const string& post, const m rr.qtype=record["type"].GetString(); rr.domain_id = sd.domain_id; rr.auth=0; - rr.ttl=atoi(record["ttl"].GetString()); - rr.priority=atoi(record["priority"].GetString()); + rr.ttl=int_from_json(record["ttl"]); + rr.priority=int_from_json(record["priority"]); rrset.push_back(rr);