From: Aki Tuomi Date: Wed, 17 Jun 2015 18:08:45 +0000 (+0300) Subject: Use json11 zone2json X-Git-Tag: dnsdist-1.0.0-alpha1~248^2~58^2~21^2~5^2~23 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bf6dc7473bd973fb833e118c003c4e6fd3c731d1;p=pdns Use json11 zone2json --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index c9f2ce8b6..49acfc014 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -1,4 +1,5 @@ AM_CPPFLAGS += \ + -I$(top_srcdir)/ext/json11 \ -I$(top_srcdir)/ext/rapidjson/include \ $(YAHTTP_CFLAGS) \ $(POLARSSL_CFLAGS) @@ -401,7 +402,7 @@ zone2json_SOURCES = \ zone2json.cc \ zoneparser-tng.cc -zone2json_LDADD = $(POLARSSL_LIBS) +zone2json_LDADD = $(POLARSSL_LIBS) -L$(top_srcdir)/ext/json11 -ljson11 # pkglib_LTLIBRARIES = iputils.la # iputils_la_SOURCES = lua-iputils.cc diff --git a/pdns/zone2json.cc b/pdns/zone2json.cc index 17cad46f4..09bed5a6e 100644 --- a/pdns/zone2json.cc +++ b/pdns/zone2json.cc @@ -45,33 +45,14 @@ #include #include #include +#include "json11.hpp" +using namespace json11; StatBag S; static int g_numRecords; -static void quoteValue(string &value) -{ - string tmp; - size_t opos,pos; - - // no point doing it if there isn't anything to do - if (value.find_first_of("\\\\\"") == string::npos) return; - - pos = opos = 0; - while((pos = value.find_first_of("\\\\\"", opos)) != string::npos) - { - tmp += value.substr(opos, pos - opos); - tmp += "\\"; - tmp += value[pos]; - opos = pos+1; - } - - value = tmp; -} - - -static string emitRecord(const string& zoneName, const DNSName &DNSqname, const string &qtype, const string &ocontent, int ttl) +static Json::object emitRecord(const string& zoneName, const DNSName &DNSqname, const string &qtype, const string &ocontent, int ttl) { int prio=0; string retval; @@ -86,35 +67,15 @@ static string emitRecord(const string& zoneName, const DNSName &DNSqname, const trim_left(content); } - quoteValue(content); - - retval = "{"; - retval += "\"name\":\""; - retval += DNSqname.toString(); - retval += "\","; - retval += "\"type\":\""; - retval += qtype; - retval += "\","; - retval += "\"ttl\":"; - retval += lexical_cast(ttl); - retval += ","; - retval += "\"prio\":"; - retval += lexical_cast(prio); - retval += ","; - retval += "\"content\":\""; - retval += content; - retval += "\"}"; + Json::object dict; - return retval; -} + dict["name"] = DNSqname.toStringNoDot(); + dict["type"] = qtype; + dict["ttl"] = ttl; + dict["prio"] = prio; + dict["content"] = content; -static void emitJson(vector &data) -{ - size_t l = data.size(); - cout << "["; - for(size_t i=0;i::const_iterator i=domains.begin(); i!=domains.end(); ++i) @@ -205,15 +166,20 @@ try } lines.clear(); try { + Json::object obj; + Json::array recs; ZoneParserTNG zpt(i->filename, i->name, BP.getDirectory()); DNSResourceRecord rr; + obj["name"] = i->name.toStringNoDot(); + while(zpt.get(rr)) - lines.push_back(emitRecord(i->name.toStringNoDot(), rr.qname.toStringNoDot(), rr.qtype.getName(), rr.content, rr.ttl)); - cout << "{\"name\":\"" << i->name.toStringNoDot() << "\",\"records\": "; - emitJson(lines); - cout << "},"; + recs.push_back(emitRecord(i->name.toStringNoDot(), rr.qname.toStringNoDot(), rr.qtype.getName(), rr.content, rr.ttl)); + obj["records"] = recs; + Json tmp = obj; + cout<filename<<")\033\133\113"; } - cout << "]\n"; + cout << "]" << endl; cerr<<"\r100% done\033\133\113"<