Add features to soa parsing
This commit is contained in:
parent
697d67ea96
commit
ef524d882a
|
@ -152,11 +152,18 @@ func TestDomainName(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestParseDirective(t *testing.T) {
|
||||
func TestParseDirectiveMisc(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.",
|
||||
`name. IN SOA a6.nstld.com. hostmaster.nic.name. (
|
||||
203362132 ; serial
|
||||
5m ; refresh (5 minutes)
|
||||
5m ; retry (5 minutes)
|
||||
2w ; expire (2 weeks)
|
||||
300 ; minimum (5 minutes)
|
||||
)`: "name.\t3600\tIN\tSOA\ta6.nstld.com. hostmaster.nic.name. 203362132 300 300 1209600 300",
|
||||
}
|
||||
for i, o := range tests {
|
||||
rr, e := NewRR(i)
|
||||
|
|
11
zscan.go
11
zscan.go
|
@ -256,7 +256,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
|
|||
t <- Token{Error: e}
|
||||
return
|
||||
}
|
||||
if ttl, ok := stringToTtl(l, f, t); !ok {
|
||||
if ttl, ok := stringToTtl(l, f); !ok {
|
||||
t <- Token{Error: &ParseError{f, "Expecting $TTL value, not this...", l}}
|
||||
return
|
||||
} else {
|
||||
|
@ -314,7 +314,8 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
|
|||
}
|
||||
st = _EXPECT_ANY_NOCLASS_BL
|
||||
case _STRING: // TTL is this case
|
||||
if ttl, ok := stringToTtl(l, f, t); !ok {
|
||||
if ttl, ok := stringToTtl(l, f); !ok {
|
||||
t <- Token{Error: &ParseError{f, "Not a TTL", l}}
|
||||
return
|
||||
} else {
|
||||
h.Ttl = ttl
|
||||
|
@ -361,7 +362,8 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
|
|||
case _EXPECT_ANY_NOCLASS:
|
||||
switch l.value {
|
||||
case _STRING: // TTL
|
||||
if ttl, ok := stringToTtl(l, f, t); !ok {
|
||||
if ttl, ok := stringToTtl(l, f); !ok {
|
||||
t <- Token{Error: &ParseError{f, "Not a TTL", l}}
|
||||
return
|
||||
} else {
|
||||
h.Ttl = ttl
|
||||
|
@ -707,7 +709,7 @@ func typeToInt(token string) (uint16, bool) {
|
|||
return uint16(typ), true
|
||||
}
|
||||
|
||||
func stringToTtl(l lex, f string, t chan Token) (uint32, bool) {
|
||||
func stringToTtl(l lex, f string) (uint32, bool) {
|
||||
s := uint32(0)
|
||||
i := uint32(0)
|
||||
for _, c := range l.token {
|
||||
|
@ -731,7 +733,6 @@ func stringToTtl(l lex, f string, t chan Token) (uint32, bool) {
|
|||
i *= 10
|
||||
i += uint32(c) - '0'
|
||||
default:
|
||||
t <- Token{Error: &ParseError{f, "Not a TTL", l}}
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
|
24
zscan_rr.go
24
zscan_rr.go
|
@ -238,28 +238,36 @@ func setSOA(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
|
|||
}
|
||||
<-c // _BLANK
|
||||
|
||||
var j int
|
||||
var e error
|
||||
var v uint32
|
||||
for i := 0; i < 5; i++ {
|
||||
l = <-c
|
||||
if j, e = strconv.Atoi(l.token); e != nil {
|
||||
if j, e := strconv.Atoi(l.token); e != nil {
|
||||
if i == 0 {
|
||||
// Serial should be a number
|
||||
return nil, &ParseError{f, "bad SOA zone parameter", l}
|
||||
}
|
||||
if v, ok = stringToTtl(l, f); !ok {
|
||||
return nil, &ParseError{f, "bad SOA zone parameter", l}
|
||||
|
||||
}
|
||||
} else {
|
||||
v = uint32(j)
|
||||
}
|
||||
switch i {
|
||||
case 0:
|
||||
rr.Serial = uint32(j)
|
||||
rr.Serial = v
|
||||
<-c // _BLANK
|
||||
case 1:
|
||||
rr.Refresh = uint32(j)
|
||||
rr.Refresh = v
|
||||
<-c // _BLANK
|
||||
case 2:
|
||||
rr.Retry = uint32(j)
|
||||
rr.Retry = v
|
||||
<-c // _BLANK
|
||||
case 3:
|
||||
rr.Expire = uint32(j)
|
||||
rr.Expire = v
|
||||
<-c // _BLANK
|
||||
case 4:
|
||||
rr.Minttl = uint32(j)
|
||||
rr.Minttl = v
|
||||
}
|
||||
}
|
||||
return rr, nil
|
||||
|
|
Loading…
Reference in New Issue