From: Ruben d'Arco Date: Fri, 4 Jan 2013 22:13:49 +0000 (+0100) Subject: Move soa-calculation to seperate function. X-Git-Tag: auth-3.3-rc1~29^2~10^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5ba9719b5e72e6132b6a481c3e90f0e4f196a6da;p=thirdparty%2Fpdns.git Move soa-calculation to seperate function. Conflicts: pdns/serialtweaker.cc --- diff --git a/pdns/dnsseckeeper.hh b/pdns/dnsseckeeper.hh index 2d81a71bc1..9dcc4f4181 100644 --- a/pdns/dnsseckeeper.hh +++ b/pdns/dnsseckeeper.hh @@ -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 diff --git a/pdns/serialtweaker.cc b/pdns/serialtweaker.cc index d1dff57cb5..7330c7d2d1 100644 --- a/pdns/serialtweaker.cc +++ b/pdns/serialtweaker.cc @@ -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); +}