Get started for the LOC record

This commit is contained in:
Miek Gieben 2012-02-18 19:24:53 +01:00
parent 8ff38fb8c1
commit c2e99e8b41
2 changed files with 40 additions and 28 deletions

View File

@ -148,15 +148,15 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
if origin == "" {
origin = "."
}
if !IsFqdn(origin) {
t <- Token{Error: &ParseError{f, "bad initial origin name", lex{}}}
return
}
if !IsFqdn(origin) {
t <- Token{Error: &ParseError{f, "bad initial origin name", lex{}}}
return
}
if _, _, ok := IsDomainName(origin); !ok {
t <- Token{Error: &ParseError{f, "bad initial origin name", lex{}}}
return
}
st := _EXPECT_OWNER_DIR // initial state
st := _EXPECT_OWNER_DIR // initial state
var h RR_Header
var ok bool
var defttl uint32 = DefaultTtl
@ -321,7 +321,7 @@ 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); !ok {
t <- Token{Error: &ParseError{f, "not a TTL", l}}
t <- Token{Error: &ParseError{f, "not a TTL", l}}
return
} else {
h.Ttl = ttl
@ -369,7 +369,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
switch l.value {
case _STRING: // TTL
if ttl, ok := stringToTtl(l, f); !ok {
t <- Token{Error: &ParseError{f, "not a TTL", l}}
t <- Token{Error: &ParseError{f, "not a TTL", l}}
return
} else {
h.Ttl = ttl
@ -752,3 +752,22 @@ func appendOrigin(name, origin string) string {
}
return name + "." + origin
}
func slurpRemainder(c chan lex, f string) *ParseError {
l := <-c
switch l.value {
case _BLANK:
l = <-c
if l.value != _NEWLINE && l.value != _EOF {
return &ParseError{f, "garbage after rdata", l}
}
// Ok
case _NEWLINE:
// Ok
case _EOF:
// Ok
default:
return &ParseError{f, "garbage after rdata", l}
}
return nil
}

View File

@ -6,14 +6,13 @@ import (
"strings"
)
// TODO: SPF, TKEY, RR_URI, DHCID, TLSA
// TODO: TKEY, RR_URI, DHCID
// Parse the rdata of each rrtype.
// All data from the channel c is either _STRING or _BLANK.
// After the rdata there may come 1 _BLANK and then a _NEWLINE
// or immediately a _NEWLINE. If this is not the case we flag
// an *ParseError: garbage after rdata.
func setRR(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
var r RR
e := new(ParseError)
@ -51,6 +50,9 @@ func setRR(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
case TypeNAPTR:
r, e = setNAPTR(h, c, o, f)
goto Slurp
case TypeLOC:
r, e = setLOC(h, c, 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.
@ -88,25 +90,6 @@ Slurp:
return r, e
}
func slurpRemainder(c chan lex, f string) *ParseError {
l := <-c
switch l.value {
case _BLANK:
l = <-c
if l.value != _NEWLINE && l.value != _EOF {
return &ParseError{f, "garbage after rdata", l}
}
// Ok
case _NEWLINE:
// Ok
case _EOF:
// Ok
default:
return &ParseError{f, "garbage after rdata", l}
}
return nil
}
func setA(h RR_Header, c chan lex, f string) (RR, *ParseError) {
rr := new(RR_A)
rr.Hdr = h
@ -949,3 +932,13 @@ func setIPSECKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
rr.PublicKey = s
return rr, nil
}
func setLOC(h RR_Header, c chan lex, f string) (RR, *ParseError) {
rr := new(RR_LOC)
rr.Hdr = h
// TODO
rr.Version = 0
return rr, nil
}