]> granicus.if.org Git - pdns/commitdiff
move SOA serialization code away from dnspacket into generic dns.cc file, to break...
authorBert Hubert <bert.hubert@netherlabs.nl>
Sun, 2 Jan 2011 18:31:38 +0000 (18:31 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Sun, 2 Jan 2011 18:31:38 +0000 (18:31 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1789 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/dns.cc
pdns/dns.hh
pdns/dnspacket.cc
pdns/dnspacket.hh

index f930fac6132962dfd9be2595b897302cfcef6f5d..74c60cac41419e412329c9dac454e7265b92b844 100644 (file)
@@ -1,5 +1,6 @@
 #include "dns.hh"
 #include "misc.hh"
+#include "arguments.hh"
 #include <stdexcept>
 #include <iostream>
 #include <boost/algorithm/string.hpp>
@@ -123,3 +124,73 @@ string questionExpand(const char* packet, uint16_t len, uint16_t& type)
   // cerr << "returning: '"<<ret<<"'"<<endl;
   return ret;
 }
+
+void fillSOAData(const string &content, SOAData &data)
+{
+  // content consists of fields separated by spaces:
+  //  nameservername hostmaster serial-number [refresh [retry [expire [ minimum] ] ] ]
+
+  // fill out data with some plausible defaults:
+  // 10800 3600 604800 3600
+  data.serial=0;
+  data.refresh=::arg().asNum("soa-refresh-default");
+  data.retry=::arg().asNum("soa-retry-default");
+  data.expire=::arg().asNum("soa-expire-default");
+  data.default_ttl=::arg().asNum("soa-minimum-ttl");
+
+  vector<string>parts;
+  stringtok(parts,content);
+  int pleft=parts.size();
+
+  //  cout<<"'"<<content<<"'"<<endl;
+
+  if(pleft)
+    data.nameserver=parts[0];
+
+  if(pleft>1) 
+    data.hostmaster=attodot(parts[1]); // ahu@ds9a.nl -> ahu.ds9a.nl, piet.puk@ds9a.nl -> piet\.puk.ds9a.nl
+
+  if(pleft>2)
+    data.serial=strtoul(parts[2].c_str(), NULL, 10);
+
+  if(pleft>3)
+    data.refresh=atoi(parts[3].c_str());
+
+  if(pleft>4)
+    data.retry=atoi(parts[4].c_str());
+
+  if(pleft>5)
+    data.expire=atoi(parts[5].c_str());
+
+  if(pleft>6)
+    data.default_ttl=atoi(parts[6].c_str());
+
+}
+
+string serializeSOAData(const SOAData &d)
+{
+  ostringstream o;
+  //  nameservername hostmaster serial-number [refresh [retry [expire [ minimum] ] ] ]
+  o<<d.nameserver<<" "<< d.hostmaster <<" "<< d.serial <<" "<< d.refresh << " "<< d.retry << " "<< d.expire << " "<< d.default_ttl;
+
+  return o.str();
+}
+// the functions below update the 'arcount' and 'ancount', plus they serialize themselves to the stringbuffer
+
+string& attodot(string &str)
+{
+   if(str.find_first_of("@")==string::npos)
+      return str;
+
+   for (unsigned int i = 0; i < str.length(); i++)
+   {
+      if (str[i] == '@') {
+         str[i] = '.';
+         break;
+      } else if (str[i] == '.') {
+         str.insert(i++, "\\");
+      }
+   }
+   return str;
+}
+
index 107f328545c53200aa01d9a1b021a361cc8123cd..3c80a92b18edffc66671272344ef5ff280644dca 100644 (file)
@@ -1,6 +1,6 @@
 /*
     PowerDNS Versatile Database Driven Nameserver
-    Copyright (C) 2002  PowerDNS.COM BV
+    Copyright (C) 2002 - 2011 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
@@ -253,4 +253,12 @@ struct dnsheader {
 extern time_t s_starttime;
 std::string questionExpand(const char* packet, uint16_t len, uint16_t& type);
 bool dnspacketLessThan(const std::string& a, const std::string& b);
+
+/** helper function for both DNSPacket and addSOARecord() - converts a line into a struct, for easier parsing */
+void fillSOAData(const string &content, SOAData &data);
+
+/** for use by DNSPacket, converts a SOAData class to a ascii line again */
+string serializeSOAData(const SOAData &data);
+string &attodot(string &str);  //!< for when you need to insert an email address in the SOA
+
 #endif
index 10afcc0c0462d96ff3dd4e9986c5a7fb264c669e..4bd01b0055fe8dd3d81a60835787e063d874c86c 100644 (file)
@@ -1,6 +1,6 @@
 /*
     PowerDNS Versatile Database Driven Nameserver
-    Copyright (C) 2001 - 2010  PowerDNS.COM BV
+    Copyright (C) 2001 - 2011  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 as 
@@ -166,76 +166,6 @@ void DNSPacket::addRecord(const DNSResourceRecord &rr)
   d_rrs.push_back(rr);
 }
 
-// the functions below update the 'arcount' and 'ancount', plus they serialize themselves to the stringbuffer
-
-string& attodot(string &str)
-{
-   if(str.find_first_of("@")==string::npos)
-      return str;
-
-   for (unsigned int i = 0; i < str.length(); i++)
-   {
-      if (str[i] == '@') {
-         str[i] = '.';
-         break;
-      } else if (str[i] == '.') {
-         str.insert(i++, "\\");
-      }
-   }
-
-   return str;
-}
-
-void fillSOAData(const string &content, SOAData &data)
-{
-  // content consists of fields separated by spaces:
-  //  nameservername hostmaster serial-number [refresh [retry [expire [ minimum] ] ] ]
-
-  // fill out data with some plausible defaults:
-  // 10800 3600 604800 3600
-  data.serial=0;
-  data.refresh=::arg().asNum("soa-refresh-default");
-  data.retry=::arg().asNum("soa-retry-default");
-  data.expire=::arg().asNum("soa-expire-default");
-  data.default_ttl=::arg().asNum("soa-minimum-ttl");
-
-  vector<string>parts;
-  stringtok(parts,content);
-  int pleft=parts.size();
-
-  //  cout<<"'"<<content<<"'"<<endl;
-
-  if(pleft)
-    data.nameserver=parts[0];
-
-  if(pleft>1) 
-    data.hostmaster=attodot(parts[1]); // ahu@ds9a.nl -> ahu.ds9a.nl, piet.puk@ds9a.nl -> piet\.puk.ds9a.nl
-
-  if(pleft>2)
-    data.serial=strtoul(parts[2].c_str(), NULL, 10);
-
-  if(pleft>3)
-    data.refresh=atoi(parts[3].c_str());
-
-  if(pleft>4)
-    data.retry=atoi(parts[4].c_str());
-
-  if(pleft>5)
-    data.expire=atoi(parts[5].c_str());
-
-  if(pleft>6)
-    data.default_ttl=atoi(parts[6].c_str());
-
-}
-
-string serializeSOAData(const SOAData &d)
-{
-  ostringstream o;
-  //  nameservername hostmaster serial-number [refresh [retry [expire [ minimum] ] ] ]
-  o<<d.nameserver<<" "<< d.hostmaster <<" "<< d.serial <<" "<< d.refresh << " "<< d.retry << " "<< d.expire << " "<< d.default_ttl;
-
-  return o.str();
-}
 
 
 static int rrcomp(const DNSResourceRecord &A, const DNSResourceRecord &B)
@@ -366,7 +296,7 @@ void DNSPacket::wrapup(void)
 
        if(d_dnssecOk) {
          if(pos != d_rrs.begin() && (signQType != pos->qtype.getCode()  || signQName != pos->qname)) {
-           addSignature(::arg()["key-repository"], signQName, wildcardQName, signQType, signTTL, signPlace, toSign, pw);
+           addSignature(signQName, wildcardQName, signQType, signTTL, signPlace, toSign, pw);
          }
          signQName= pos->qname;
          wildcardQName = pos->wildcardname;
@@ -396,7 +326,7 @@ void DNSPacket::wrapup(void)
       // I assume this is some dirty hack to prevent us from signing the last SOA record in an AXFR.. XXX FIXME
       if(d_dnssecOk && !(d_tcp && d_rrs.rbegin()->qtype.getCode() == QType::SOA && d_rrs.rbegin()->priority == 1234)) {
        // cerr<<"Last signature.. "<<d_tcp<<", "<<d_rrs.rbegin()->priority<<", "<<d_rrs.rbegin()->qtype.getCode()<<", "<< d_rrs.size()<<endl;
-       addSignature(::arg()["key-repository"], signQName, wildcardQName, signQType, signTTL, signPlace, toSign, pw);
+       addSignature(signQName, wildcardQName, signQType, signTTL, signPlace, toSign, pw);
       }
 
       if(!opts.empty() || d_dnssecOk)
index 662809195dc158921e342c5b7341246dba99e88a..c187e1f576487845f540f8e0a874049d9abbcea6 100644 (file)
@@ -1,6 +1,6 @@
 /*
     PowerDNS Versatile Database Driven Nameserver
-    Copyright (C) 2002 - 2005  PowerDNS.COM BV
+    Copyright (C) 2002 - 2011  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 as published
 
 class DNSBackend;
 
-/** helper function for both DNSPacket and addSOARecord() - converts a line into a struct, for easier parsing */
-void fillSOAData(const string &content, SOAData &data);
 
-/** for use by DNSPacket, converts a SOAData class to a ascii line again */
-string serializeSOAData(const SOAData &data);
 
-string &attodot(string &str);  //!< for when you need to insert an email address in the SOA
 
 //! This class represents DNS packets, either received or to be sent.
 class DNSPacket