From a2e9e5a5891f74ce4f15fa79395085915f449340 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Tue, 22 Apr 2014 13:22:03 +0200 Subject: [PATCH] appears to do something --- pdns/Makefile.am | 2 +- pdns/zone2sql.cc | 46 +++++++++++++++++++++++++++++++++--------- pdns/zoneparser-tng.cc | 12 +++++++---- pdns/zoneparser-tng.hh | 5 +++-- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 5acc3b6f2..0bf2fd040 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -113,7 +113,7 @@ zone2sql_SOURCES=bindparser.yy bindlexer.l bind-dnssec.schema.sqlite3.sql.h \ zoneparser-tng.cc dnsrecords.cc sillyrecords.cc \ dnswriter.cc dnslabeltext.cc rcpgenerator.cc dnsparser.cc base64.cc \ nsecrecords.cc dnssecinfra.cc base32.cc bindparserclasses.hh \ - dns_random.cc + dns_random.cc json.cc json.hh zone2sql_LDFLAGS=@THREADFLAGS@ zone2sql_LDADD= $(POLARSSL_LIBS) diff --git a/pdns/zone2sql.cc b/pdns/zone2sql.cc index 250c31ec0..15d183210 100644 --- a/pdns/zone2sql.cc +++ b/pdns/zone2sql.cc @@ -1,6 +1,6 @@ /* PowerDNS Versatile Database Driven Nameserver - Copyright (C) 2002 - 2011 PowerDNS.COM BV + Copyright (C) 2002 - 2014 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 @@ -24,7 +24,7 @@ #include #include #include - +#include "json.hh" #include #include #include "namespaces.hh" @@ -142,8 +142,23 @@ static void emitDomain(const string& domain, const vector *masters = 0) } } -static void emitRecord(const string& zoneName, const string &qname, const string &qtype, const string &ocontent, int ttl, int prio) +static void emitRecord(const string& zoneName, const string &qname, const string &qtype, const string &ocontent, int ttl, int prio, const string& comment="") { + int disabled=0; + string recordcomment; + + if(!comment.empty()) { + string::size_type pos = comment.find("json={"); + if(pos!=string::npos) { + string json = comment.substr(pos+5); + rapidjson::Document document; + if(document.Parse<0>(json.c_str()).HasParseError()) + throw runtime_error("Could not parse JSON '"+json+"'"); + + disabled=boolFromJson(document, "disabled", false); + recordcomment=stringFromJson(document, "comment", ""); + } + } g_numRecords++; string content(ocontent); @@ -169,15 +184,22 @@ static void emitRecord(const string& zoneName, const string &qname, const string cout<<"insert into records (domain_id, name, type,content,ttl,prio,disabled) select id ,"<< sqlstr(toLower(stripDot(qname)))<<", "<< sqlstr(qtype)<<", "<< - sqlstr(stripDotContent(content))<<", "<clear(); + if(comment && d_line.find(';') != string::npos) + *comment = d_line.substr(d_line.find(';')); parts_t parts; vstringtok(parts, d_line); @@ -314,8 +317,9 @@ bool ZoneParserTNG::get(DNSResourceRecord& rr) if(nextpart.empty()) break; - if(nextpart.find(';')!=string::npos) + if(nextpart.find(';')!=string::npos) { break; + } // cout<<"Next part: '"< > parts_t; private: @@ -54,6 +54,7 @@ private: uint32_t d_templatecounter, d_templatestop, d_templatestep; string d_templateline; parts_t d_templateparts; + bool d_doPassComments; struct filestate { filestate(FILE* fp, string filename) : d_fp(fp), d_filename(filename), d_lineno(0){} -- 2.40.0