From 2fa33bce0c7ec984671ac827d1fff0f2ae68629d Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Thu, 10 Feb 2011 14:35:54 +0000 Subject: [PATCH] add Ragel based DNS Label parser next to the DNS TXT parser git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2003 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- pdns/dnslabeltext.rl | 78 +++++++++++++++++++++++++++++++++++++++----- pdns/pdnssec.cc | 4 +-- pdns/rcpgenerator.hh | 2 +- 3 files changed, 72 insertions(+), 12 deletions(-) diff --git a/pdns/dnslabeltext.rl b/pdns/dnslabeltext.rl index 65f5bee160..dc4cbf0b53 100644 --- a/pdns/dnslabeltext.rl +++ b/pdns/dnslabeltext.rl @@ -5,10 +5,6 @@ #include #include "namespaces.hh" -%%{ - machine dnstext; - write data; -}%% namespace { void appendSplit(vector& ret, string& segment, char c) @@ -23,6 +19,11 @@ void appendSplit(vector& ret, string& segment, char c) vector segmentDNSText(const string& input ) { +%%{ + machine dnstext; + write data; +}%% + const char *p = input.c_str(), *pe = input.c_str() + input.length(); const char* eof = pe; int cs; @@ -61,10 +62,9 @@ vector segmentDNSText(const string& input ) escaped = '\\' ((["\\]@reportEscaped) | ([0-9]{3}$reportEscapedNumber%doneEscapedNumber)); plain = (print-'\\'-'"') $ reportPlain; - labelElement = escaped | plain; - - - main := (('"' labelElement* '"' space?) >segmentBegin %segmentEnd)+; + txtElement = escaped | plain; + + main := (('"' txtElement* '"' space?) >segmentBegin %segmentEnd)+; # Initialize and execute. write init; @@ -77,7 +77,69 @@ vector segmentDNSText(const string& input ) return ret; }; +string segmentDNSLabel(const string& input ) +{ +%%{ + machine dnslabel; + write data; +}%% + + const char *p = input.c_str(), *pe = input.c_str() + input.length(); + //const char* eof = pe; + int cs; + char val = 0; + + string ret; + string segment; + + %%{ + action segmentEnd { + printf("Segment end, segment = '%s'\n", segment.c_str()); + ret.append(1, (unsigned char)segment.size()); + ret.append(segment); + segment.clear(); + } + action reportEscaped { + printf("'\\%c' ", *fpc); + segment.append(1, *fpc); + } + action reportEscapedNumber { + char c = *fpc; + val *= 10; + val += c-'0'; + + } + action doneEscapedNumber { + printf("_%c_ ", val); + segment.append(1, val); + val=0; + } + + action reportPlain { + printf("'%c' ", *fpc); + segment.append(1, *fpc); + } + + escaped = '\\' (([\\.]@reportEscaped) | ([0-9]{3}$reportEscapedNumber%doneEscapedNumber)); + plain = (print-'\\'-'.') $ reportPlain; + labelElement = escaped | plain; + + + main := ((labelElement)* %segmentEnd '.')+; + + # Initialize and execute. + write init; + write exec; + }%% + + if ( cs < dnslabel_first_final ) { + throw runtime_error("Unable to parse DNS Label '"+input+"'"); + } + if(ret.empty() || ret[0] != 0) + ret.append(1, 0); + return ret; +}; #if 0 int main() { diff --git a/pdns/pdnssec.cc b/pdns/pdnssec.cc index 0ccc9dcd89..1c4ae8e4df 100644 --- a/pdns/pdnssec.cc +++ b/pdns/pdnssec.cc @@ -370,7 +370,7 @@ void showZone(DNSSECKeeper& dk, const std::string& zone) int main(int argc, char** argv) try -{ +{ po::options_description desc("Allowed options"); desc.add_options() ("help,h", "produce help message") @@ -390,8 +390,6 @@ try if(g_vm.count("commands")) cmds = g_vm["commands"].as >(); - - if(cmds.empty() || g_vm.count("help")) { cerr<<"Usage: \npdnssec [options] [show-zone] [secure-zone] [rectify-zone] [add-zone-key] [deactivate-zone-key] [remove-zone-key] [activate-zone-key]\n"; cerr<<" [import-zone-key] [export-zone-key] [set-nsec3] [set-presigned] [unset-nsec3] [unset-presigned] [export-zone-dnskey]\n\n"; diff --git a/pdns/rcpgenerator.hh b/pdns/rcpgenerator.hh index f39e6aeebc..174b70a675 100644 --- a/pdns/rcpgenerator.hh +++ b/pdns/rcpgenerator.hh @@ -89,5 +89,5 @@ private: string& d_string; }; - +string segmentDNSLabel(const string& input ); #endif -- 2.47.3