]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Move soa-calculation to seperate function.
authorRuben d'Arco <cyclops@prof-x.net>
Fri, 4 Jan 2013 22:13:49 +0000 (23:13 +0100)
committerRuben d'Arco <cyclops@prof-x.net>
Wed, 15 May 2013 06:06:39 +0000 (08:06 +0200)
Conflicts:

pdns/serialtweaker.cc

pdns/dnsseckeeper.hh
pdns/serialtweaker.cc

index 2d81a71bc1d48c4babc22d0fc5d3d778069e9efe..9dcc4f41811c125e7e26dee0eef023482f587032 100644 (file)
@@ -164,4 +164,5 @@ private:
 
 class DNSPacket;
 bool editSOA(DNSSECKeeper& dk, const string& qname, DNSPacket* dp);
+uint32_t calculateEditSoa(SOAData sd, const string& kind);
 #endif
index d1dff57cb5b3b4f1add7090248855b8fd72fb6a9..7330c7d2d1a294acdbd6bb8c7ec0e5cbf2c63f01 100644 (file)
@@ -43,44 +43,46 @@ bool editSOA(DNSSECKeeper& dk, const string& qname, DNSPacket* dp)
         return false;
       SOAData sd;
       fillSOAData(rr.content, sd);
-      if(pdns_iequals(kind,"INCEPTION")) {
-        time_t inception = getStartOfWeek();
-        sd.serial = localtime_format_YYYYMMDDSS(inception, 1);
-      }
-      else if(pdns_iequals(kind,"INCEPTION-INCREMENT")) {
-        time_t inception = getStartOfWeek();
-
-        uint32_t inception_serial = localtime_format_YYYYMMDDSS(inception, 1);
-        uint32_t dont_increment_after = localtime_format_YYYYMMDDSS(inception + 2*86400, 99);
-
-        if(sd.serial <= dont_increment_after) {
-          /* "day00" and "day01" are reserved for inception increasing, so increment sd.serial by two */
-          sd.serial += 2;
-        }
-        else if(sd.serial < inception_serial) {
-          sd.serial = inception_serial;
-        }
-      }
-      else if(pdns_iequals(kind,"INCEPTION-WEEK")) {
-        time_t inception = getStartOfWeek();
-        sd.serial = inception / (7*86400);
-      }
-      else if(pdns_iequals(kind,"INCREMENT-WEEKS")) {
-        time_t inception = getStartOfWeek();
-        sd.serial += inception / (7*86400);
-      }
-      else if(pdns_iequals(kind,"EPOCH")) {
-        sd.serial = time(0);
-      }
-      else if(pdns_iequals(kind,"INCEPTION-EPOCH")) {
-        time_t inception = getStartOfWeek();
-        if (sd.serial < inception) {
-          sd.serial = inception;
-        }
-      }
-      rr.content = serializeSOAData(sd);
+      sd.serial = calculateEditSoa(sd, kind);
+      rr.content = serializeSOAData(sd);      
       return true;
     }
   }
   return false;
 }
+
+
+uint32_t calculateEditSoa(SOAData sd, const string& kind) {
+  if(pdns_iequals(kind,"INCEPTION")) {
+    time_t inception = getStartOfWeek();
+    return localtime_format_YYYYMMDDSS(inception, 1);
+  }
+  else if(pdns_iequals(kind,"INCEPTION-INCREMENT")) {
+    time_t inception = getStartOfWeek();
+    uint32_t inception_serial = localtime_format_YYYYMMDDSS(inception, 1);
+    uint32_t dont_increment_after = localtime_format_YYYYMMDDSS(inception + 2*86400, 99);
+
+    if(sd.serial <= dont_increment_after)
+      return (sd.serial + 2); /* "day00" and "day01" are reserved for inception increasing, so increment sd.serial by two */
+    else if(sd.serial < inception_serial) 
+      return inception_serial;
+  }
+  else if(pdns_iequals(kind,"INCEPTION-WEEK")) {
+    time_t inception = getStartOfWeek();
+    return ( inception / (7*86400) );
+  }
+  else if(pdns_iequals(kind,"INCREMENT-WEEKS")) {
+    time_t inception = getStartOfWeek();
+    return (sd.serial + (inception / (7*86400)));
+  }
+  else if(pdns_iequals(kind,"EPOCH")) {
+    return time(0);
+  }
+  else if(pdns_iequals(kind,"INCEPTION-EPOCH")) {
+    time_t inception = getStartOfWeek();
+    if (sd.serial < inception)
+      return inception;
+  }
+  else
+    return (sd.serial + 1);
+}