Add NAPTR support

This commit is contained in:
Miek Gieben 2012-02-11 22:32:45 +01:00
parent 4e5ef3a0f0
commit 89a45fbc48
1 changed files with 45 additions and 0 deletions

View File

@ -44,6 +44,9 @@ func setRR(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
case TypeSRV:
r, e = setSRV(h, c, o, f)
goto Slurp
case TypeNAPTR:
r, e = setNAPTR(h, c, o, f)
goto Slurp
// 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
// newline. Thus there is no need to slurp the remainder, because there is none.
@ -284,6 +287,48 @@ func setSRV(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
return rr, nil
}
func setNAPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
rr := new(RR_NAPTR)
rr.Hdr = h
l := <-c
if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{f, "bad NAPTR Order", l}
} else {
rr.Order = uint16(i)
}
<-c // _BLANK
l = <-c // _STRING
if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{f, "bad NAPTR Preference", l}
} else {
rr.Preference = uint16(i)
}
<-c // _BLANK
l = <-c // _STRING
rr.Flags = l.token
<-c // _BLANK
l = <-c // _STRING
rr.Service = l.token
<-c // _BLANK
l = <-c // _STRING
rr.Regexp = l.token
<-c // _BLANK
l = <-c // _STRING
rr.Replacement = l.token
_, ld, ok := IsDomainName(l.token)
if !ok {
return nil, &ParseError{f, "bad NAPTR Replacement", l}
}
if rr.Replacement[ld-1] != '.' {
rr.Replacement += o
}
return rr, nil
}
func setRRSIG(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
rr := new(RR_RRSIG)
rr.Hdr = h