Implement TTLs in words
1H, 1M, 1W2D, etc. should now be parsed in TTLs
This commit is contained in:
parent
b3a58abd24
commit
63d8b1feb1
|
@ -155,6 +155,8 @@ func TestDomainName(t *testing.T) {
|
|||
func TestParseDirective(t *testing.T) {
|
||||
tests := map[string]string{
|
||||
"$ORIGIN miek.nl.\na IN NS b": "a.miek.nl.\t3600\tIN\tNS\tb.miek.nl.",
|
||||
"$TTL 2H\nmiek.nl. IN NS b.": "miek.nl.\t7200\tIN\tNS\tb.",
|
||||
"miek.nl. 1D IN NS b.": "miek.nl.\t86400\tIN\tNS\tb.",
|
||||
}
|
||||
for i, o := range tests {
|
||||
rr, e := NewRR(i)
|
||||
|
|
35
zscan.go
35
zscan.go
|
@ -679,11 +679,32 @@ func typeToInt(token string) (uint16, bool) {
|
|||
}
|
||||
|
||||
func stringToTtl(l lex, f string, t chan Token) (uint32, bool) {
|
||||
if ttl, ok := strconv.Atoi(l.token); ok != nil {
|
||||
t <- Token{Error: &ParseError{f, "Not a TTL", l}}
|
||||
return 0, false
|
||||
} else {
|
||||
return uint32(ttl), true
|
||||
}
|
||||
panic("not reached")
|
||||
s := uint32(0)
|
||||
i := uint32(0)
|
||||
for _, c := range l.token {
|
||||
switch c {
|
||||
case 's', 'S':
|
||||
s += i
|
||||
i = 0
|
||||
case 'm', 'M':
|
||||
s += i * 60
|
||||
i = 0
|
||||
case 'h', 'H':
|
||||
s += i * 60 * 60
|
||||
i = 0
|
||||
case 'd', 'D':
|
||||
s += i * 60 * 60 * 24
|
||||
i = 0
|
||||
case 'w', 'W':
|
||||
s += i * 60 * 60 * 24 * 7
|
||||
i = 0
|
||||
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||
i *= 10
|
||||
i += uint32(c) - '0'
|
||||
default:
|
||||
t <- Token{Error: &ParseError{f, "Not a TTL", l}}
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
return s+i, true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue