Parse SRV and PTR too

This commit is contained in:
Miek Gieben 2012-02-11 17:03:09 +01:00
parent 5d4e45d253
commit 19cef3f981
2 changed files with 62 additions and 1 deletions

View File

@ -161,6 +161,8 @@ func TestParseBrace(t *testing.T) {
3600 A 127.0.0.1)`: "miek.nl.\t3600\tIN\tA\t127.0.0.1",
"(miek.nl.) (A) (127.0.0.1)": "miek.nl.\t3600\tIN\tA\t127.0.0.1",
"miek.nl A 127.0.0.1": "miek.nl.\t3600\tIN\tA\t127.0.0.1",
"_ssh._tcp.local. 60 IN PTR stora._ssh._tcp.local.":
"_ssh._tcp.local.\t60\tIN\tPTR\tstora._ssh._tcp.local.",
"miek.nl. NS ns.miek.nl": "miek.nl.\t3600\tIN\tNS\tns.miek.nl.",
`(miek.nl.) (
(IN)

View File

@ -26,6 +26,9 @@ func setRR(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
case TypeNS:
r, e = setNS(h, c, o, f)
goto Slurp
case TypePTR:
r, e = setPTR(h, c, o, f)
goto Slurp
case TypeMX:
r, e = setMX(h, c, o, f)
goto Slurp
@ -35,9 +38,12 @@ func setRR(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
case TypeSOA:
r, e = setSOA(h, c, o, f)
goto Slurp
case TypeSSHFP:
r, e = setSSHFP(h, c, f)
goto Slurp
case TypeSRV:
r, e = setSRV(h, c, o, f)
goto Slurp
case TypeDNSKEY:
// These types have a variable ending either chunks of txt or chunks/base64 or hex.
// They need to search for the end of the RR themselves, hence they look for the ending
@ -133,6 +139,22 @@ func setNS(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
return rr, nil
}
func setPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
rr := new(RR_PTR)
rr.Hdr = h
l := <-c
rr.Ptr = l.token
_, ld, ok := IsDomainName(l.token)
if !ok {
return nil, &ParseError{f, "bad PTR Ptr", l}
}
if rr.Ptr[ld-1] != '.' {
rr.Ptr += o
}
return rr, nil
}
func setMX(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
rr := new(RR_MX)
rr.Hdr = h
@ -225,6 +247,43 @@ func setSOA(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
return rr, nil
}
func setSRV(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
rr := new(RR_SRV)
rr.Hdr = h
l := <-c
if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{f, "bad SRV Priority", l}
} else {
rr.Priority = uint16(i)
}
<-c // _BLANK
l = <-c // _STRING
if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{f, "bad SRV Weight", l}
} else {
rr.Weight = uint16(i)
}
<-c // _BLANK
l = <-c // _STRING
if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{f, "bad SRV Port", l}
} else {
rr.Port = uint16(i)
}
<-c // _BLANK
l = <-c // _STRING
rr.Target = l.token
_, ld, ok := IsDomainName(l.token)
if !ok {
return nil, &ParseError{f, "bad SRV Target", l}
}
if rr.Target[ld-1] != '.' {
rr.Target += o
}
return rr, nil
}
func setRRSIG(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
rr := new(RR_RRSIG)
rr.Hdr = h