]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add Ragel based DNS Label parser next to the DNS TXT parser
authorBert Hubert <bert.hubert@netherlabs.nl>
Thu, 10 Feb 2011 14:35:54 +0000 (14:35 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Thu, 10 Feb 2011 14:35:54 +0000 (14:35 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2003 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/dnslabeltext.rl
pdns/pdnssec.cc
pdns/rcpgenerator.hh

index 65f5bee1609b54f5d0691ea4a7664c5a6ed386eb..dc4cbf0b539a340883fed94964ad9fa7a621aab3 100644 (file)
@@ -5,10 +5,6 @@
 #include <string>
 #include "namespaces.hh"
 
-%%{
-        machine dnstext;
-        write data;
-}%%
 
 namespace {
 void appendSplit(vector<string>& ret, string& segment, char c)
@@ -23,6 +19,11 @@ void appendSplit(vector<string>& ret, string& segment, char c)
 
 vector<string> 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<string> 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<string> 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()
 {
index 0ccc9dcd89ddb80c2347de51ff25f65b7a653903..1c4ae8e4dfe039f21c48850954f69300159ada91 100644 (file)
@@ -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<vector<string> >();
 
-  
-
   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";
index f39e6aeebc6b7f0f00c2d16c6f17b9f5e2b4a847..174b70a675ccaf55bc1b909f6ebb76c5e15f900e 100644 (file)
@@ -89,5 +89,5 @@ private:
   string& d_string;
 };
 
-
+string segmentDNSLabel(const string& input );
 #endif