From c2e99e8b4173f357551353f03331fdf71a927e80 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sat, 18 Feb 2012 19:24:53 +0100 Subject: [PATCH] Get started for the LOC record --- zscan.go | 33 ++++++++++++++++++++++++++------- zscan_rr.go | 35 ++++++++++++++--------------------- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/zscan.go b/zscan.go index a5ac430a..70002fe0 100644 --- a/zscan.go +++ b/zscan.go @@ -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 +} diff --git a/zscan_rr.go b/zscan_rr.go index 21d38320..33870a65 100644 --- a/zscan_rr.go +++ b/zscan_rr.go @@ -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 +}