Parsing works

This commit is contained in:
Miek Gieben 2011-12-14 15:37:36 +01:00
parent 7c3a6087a5
commit 824cb459fb
2 changed files with 383 additions and 361 deletions

View File

@ -14,27 +14,27 @@ import (
// * Make each RR fit on one line (NEWLINE is send as last) // * Make each RR fit on one line (NEWLINE is send as last)
// * Handle comments: ; // * Handle comments: ;
const ( const (
_STRING = iota _EOF = iota // Don't let it start with zero
_STRING
_BLANK _BLANK
_NEWLINE _NEWLINE
_RRTYPE _RRTYPE
_OWNER _OWNER
_CLASS _CLASS
_EXPECT_OWNER // Ownername
_EXPECT_OWNER_BL // Whitespace after the ownername
_EXPECT_ANY // Expect rrtype, ttl or class
_EXPECT_ANY_NOCLASS // Expect rrtype or ttl
_EXPECT_ANY_NOCLASS_BL // The Whitespace after _EXPECT_ANY_NOCLASS
_EXPECT_ANY_NOTTL // Expect rrtype or class
_EXPECT_ANY_NOTTL_BL // Whitespace after _EXPECT_ANY_NOTTL
_EXPECT_RRTYPE // Expect rrtype
_EXPECT_RRTYPE_BL // Whitespace BEFORE rrtype
_EXPECT_RDATA // The first element of the rdata
) )
const ( var DEBUG = true
_EXPECT_OWNER = iota // Ownername
_EXPECT_OWNER_BL // Whitespace after the ownername
_EXPECT_ANY // Expect rrtype, ttl or class
_EXPECT_ANY_NOCLASS // Expect rrtype or ttl
_EXPECT_ANY_NOCLASS_BL // The Whitespace after _EXPECT_ANY_NOCLASS
_EXPECT_ANY_NOTTL // Expect rrtype or class
_EXPECT_ANY_NOTTL_BL // Whitespace after _EXPECT_ANY_NOTTL
_EXPECT_RRTYPE // Expect rrtype
_EXPECT_RRTYPE_BL // Whitespace BEFORE rrype
_EXPECT_RDATA // The first element of the rdata
_EXPECT_RDATA_BL // Whitespace BEFORE rdata starts
)
type ParseError struct { type ParseError struct {
err string err string
@ -43,7 +43,7 @@ type ParseError struct {
func (e *ParseError) Error() string { func (e *ParseError) Error() string {
s := e.err + ": `" + e.lex.token + "' at line: " + strconv.Itoa(e.lex.line) + s := e.err + ": `" + e.lex.token + "' at line: " + strconv.Itoa(e.lex.line) +
"and column: " + strconv.Itoa(e.lex.column) " and column: " + strconv.Itoa(e.lex.column)
return s return s
} }
@ -57,17 +57,17 @@ type Lex struct {
// ParseString parses a string and returns the RR contained in there. If they string // ParseString parses a string and returns the RR contained in there. If they string
// contains more than one RR, only the first is returned. // contains more than one RR, only the first is returned.
func NewRRString(s string) (RR, error) { func NewRRString(s string) (RR, error) {
cr := make(chan RR) cr := make(chan RR)
go ParseZone(strings.NewReader(s), cr) go ParseZone(strings.NewReader(s), cr)
r := <-cr // There are no error send as of yet r := <-cr // There are no error send as of yet
return r, nil // Todo: errors return r, nil // Todo: errors
} }
func newRRReader(q io.Reader) (RR, error) { func newRRReader(q io.Reader) (RR, error) {
cr := make(chan RR) cr := make(chan RR)
go ParseZone(q, cr) go ParseZone(q, cr)
r := <-cr r := <-cr
return r, nil return r, nil
} }
// ParseZone reads a RFC 1035 zone from r. It returns each parsed RR on the // ParseZone reads a RFC 1035 zone from r. It returns each parsed RR on the
@ -94,6 +94,9 @@ func ParseZone(r io.Reader, cr chan RR) {
var h RR_Header var h RR_Header
var ok bool var ok bool
for l := range c { for l := range c {
if DEBUG {
fmt.Printf("[%v]\n", l)
}
switch st { switch st {
case _EXPECT_OWNER: case _EXPECT_OWNER:
switch l.value { switch l.value {
@ -103,12 +106,12 @@ func ParseZone(r io.Reader, cr chan RR) {
h.Name = l.token h.Name = l.token
st = _EXPECT_OWNER_BL st = _EXPECT_OWNER_BL
default: default:
fmt.Printf("%s\n", &ParseError{"Error at the start", l}) fmt.Printf("%s\n", &ParseError{"Error at the start", l})
st = _EXPECT_OWNER st = _EXPECT_OWNER
} }
case _EXPECT_OWNER_BL: case _EXPECT_OWNER_BL:
if l.value != _BLANK { if l.value != _BLANK {
fmt.Printf("%s\n", &ParseError{"No blank after owner", l}) fmt.Printf("%s\n", &ParseError{"No blank after owner", l})
} }
st = _EXPECT_ANY st = _EXPECT_ANY
case _EXPECT_ANY: case _EXPECT_ANY:
@ -116,32 +119,32 @@ func ParseZone(r io.Reader, cr chan RR) {
case _RRTYPE: case _RRTYPE:
h.Rrtype, _ = Str_rr[strings.ToUpper(l.token)] h.Rrtype, _ = Str_rr[strings.ToUpper(l.token)]
h.Ttl = DefaultTtl h.Ttl = DefaultTtl
st = _EXPECT_RDATA_BL st = _EXPECT_RDATA
case _CLASS: case _CLASS:
h.Class, ok = Str_class[strings.ToUpper(l.token)] h.Class, ok = Str_class[strings.ToUpper(l.token)]
if !ok { if !ok {
fmt.Printf("%s\n", &ParseError{"Unknown class", l}) fmt.Printf("%s\n", &ParseError{"Unknown class", l})
} }
st = _EXPECT_ANY_NOCLASS_BL st = _EXPECT_ANY_NOCLASS_BL
case _STRING: // TTL is this case case _STRING: // TTL is this case
ttl, ok := strconv.Atoi(l.token) ttl, ok := strconv.Atoi(l.token)
if ok != nil { if ok != nil {
fmt.Printf("%s\n", &ParseError{"Not a TTL", l}) fmt.Printf("%s\n", &ParseError{"Not a TTL", l})
} else { } else {
h.Ttl = uint32(ttl) h.Ttl = uint32(ttl)
} }
st = _EXPECT_ANY_NOTTL_BL st = _EXPECT_ANY_NOTTL_BL
default: default:
fmt.Printf("%s\n", &ParseError{"Expecting RR type, TTL or class, not this...", l}) fmt.Printf("%s\n", &ParseError{"Expecting RR type, TTL or class, not this...", l})
} }
case _EXPECT_ANY_NOCLASS_BL: case _EXPECT_ANY_NOCLASS_BL:
if l.value != _BLANK { if l.value != _BLANK {
fmt.Printf("%s\n", &ParseError{"No blank before NOCLASS", l}) fmt.Printf("%s\n", &ParseError{"No blank before NOCLASS", l})
} }
st = _EXPECT_ANY_NOCLASS st = _EXPECT_ANY_NOCLASS
case _EXPECT_ANY_NOTTL_BL: case _EXPECT_ANY_NOTTL_BL:
if l.value != _BLANK { if l.value != _BLANK {
fmt.Printf("%s\n", &ParseError{"No blank before NOTTL", l}) fmt.Printf("%s\n", &ParseError{"No blank before NOTTL", l})
} }
st = _EXPECT_ANY_NOTTL st = _EXPECT_ANY_NOTTL
case _EXPECT_ANY_NOTTL: case _EXPECT_ANY_NOTTL:
@ -149,47 +152,42 @@ func ParseZone(r io.Reader, cr chan RR) {
case _CLASS: case _CLASS:
h.Class, ok = Str_class[strings.ToUpper(l.token)] h.Class, ok = Str_class[strings.ToUpper(l.token)]
if !ok { if !ok {
fmt.Printf("%s\n", &ParseError{"Unknown class", l}) fmt.Printf("%s\n", &ParseError{"Unknown class", l})
} }
st = _EXPECT_RRTYPE_BL st = _EXPECT_RRTYPE_BL
case _RRTYPE: case _RRTYPE:
h.Rrtype, _ = Str_rr[strings.ToUpper(l.token)] h.Rrtype, _ = Str_rr[strings.ToUpper(l.token)]
st = _EXPECT_RDATA_BL st = _EXPECT_RDATA
} }
case _EXPECT_ANY_NOCLASS: case _EXPECT_ANY_NOCLASS:
switch l.value { switch l.value {
case _STRING: // TTL case _STRING: // TTL
ttl, ok := strconv.Atoi(l.token) ttl, ok := strconv.Atoi(l.token)
if ok != nil { if ok != nil {
fmt.Printf("%s\n", &ParseError{"Not a TTL", l}) fmt.Printf("%s\n", &ParseError{"Not a TTL", l})
} else { } else {
h.Ttl = uint32(ttl) h.Ttl = uint32(ttl)
} }
st = _EXPECT_RDATA_BL st = _EXPECT_RDATA
case _RRTYPE: case _RRTYPE:
h.Rrtype, _ = Str_rr[strings.ToUpper(l.token)] h.Rrtype, _ = Str_rr[strings.ToUpper(l.token)]
st = _EXPECT_RDATA_BL st = _EXPECT_RDATA
default: default:
fmt.Printf("%s\n", &ParseError{"Expecting RR type or TTL, not this...", l}) fmt.Printf("%s\n", &ParseError{"Expecting RR type or TTL, not this...", l})
} }
case _EXPECT_RRTYPE_BL: case _EXPECT_RRTYPE_BL:
if l.value != _BLANK { if l.value != _BLANK {
fmt.Printf("%s\n", &ParseError{"No blank after", l}) fmt.Printf("%s\n", &ParseError{"No blank after", l})
} }
st = _EXPECT_RRTYPE st = _EXPECT_RRTYPE
case _EXPECT_RRTYPE: case _EXPECT_RRTYPE:
if l.value != _RRTYPE { if l.value != _RRTYPE {
fmt.Printf("%s\n", &ParseError{"Unknown RR type", l}) fmt.Printf("%s\n", &ParseError{"Unknown RR type", l})
} }
h.Rrtype, _ = Str_rr[strings.ToUpper(l.token)] h.Rrtype, _ = Str_rr[strings.ToUpper(l.token)]
st = _EXPECT_RDATA_BL
case _EXPECT_RDATA_BL:
if l.value != _BLANK {
println("No blank after error")
}
st = _EXPECT_RDATA st = _EXPECT_RDATA
case _EXPECT_RDATA: case _EXPECT_RDATA:
r, e := setRR(h, c, l) r, e := setRR(h, c, l)
if e != nil { if e != nil {
fmt.Printf("%v\n", e) fmt.Printf("%v\n", e)
} }

View File

@ -1,9 +1,9 @@
package dns package dns
import ( import (
"net" "net"
"strconv" "strconv"
"strings" "strings"
) )
// All data from c is either _STRING or _BLANK // All data from c is either _STRING or _BLANK
@ -12,341 +12,364 @@ import (
// an error: garbage after rdata. // an error: garbage after rdata.
func slurpRemainder(c chan Lex) error { func slurpRemainder(c chan Lex) error {
l := <-c l := <-c
switch l.value { switch l.value {
case _BLANK: case _BLANK:
l = <-c l = <-c
if l.value != _NEWLINE { if l.value != _NEWLINE && l.value != _EOF {
return &ParseError{"garbage after rdata", l} return &ParseError{"garbage after rdata", l}
} }
// Ok // Ok
case _NEWLINE: case _NEWLINE:
// Ok // Ok
default: case _EOF:
return &ParseError{"garbage after rdata", l} // Ok
} default:
return nil return &ParseError{"garbage after rdata", l}
}
return nil
} }
func setRR(h RR_Header, c chan Lex, currenttok Lex) (RR, error) { func setRR(h RR_Header, c chan Lex, currenttok Lex) (RR, error) {
var ( var (
r RR r RR
e error e error
) )
switch h.Rrtype { switch h.Rrtype {
case TypeA: case TypeA:
r, e = setA(h, c) r, e = setA(h, c)
if se := slurpRemainder(c); se != nil { if e != nil {
return nil, se return nil, e
} }
case TypeAAAA: if se := slurpRemainder(c); se != nil {
r, e = setAAAA(h, c) return nil, se
if se := slurpRemainder(c); se != nil { }
return nil, se case TypeAAAA:
} r, e = setAAAA(h, c)
case TypeNS: if e != nil {
r, e = setNS(h, c) return nil, e
if se := slurpRemainder(c); se != nil { }
return nil, se if se := slurpRemainder(c); se != nil {
} return nil, se
case TypeMX: }
r, e = setMX(h, c) case TypeNS:
if se := slurpRemainder(c); se != nil { r, e = setNS(h, c)
return nil, se if e != nil {
} return nil, e
case TypeCNAME: }
r, e = setCNAME(h, c) if se := slurpRemainder(c); se != nil {
if se := slurpRemainder(c); se != nil { return nil, se
return nil, se }
} case TypeMX:
case TypeSOA: r, e = setMX(h, c)
r, e = setSOA(h, c) if e != nil {
if se := slurpRemainder(c); se != nil { return nil, e
return nil, se }
} if se := slurpRemainder(c); se != nil {
// These types have a variable ending either chunks of txt or chunks/base64 or hex. return nil, se
// 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 case TypeCNAME:
case TypeRRSIG: r, e = setCNAME(h, c)
r, e = setRRSIG(h, c) if e != nil {
case TypeNSEC: return nil, e
r, e = setNSEC(h, c) }
case TypeNSEC3: if se := slurpRemainder(c); se != nil {
r, e = setNSEC3(h, c) return nil, se
case TypeTXT: }
r, e = setTXT(h, c) case TypeSOA:
default: r, e = setSOA(h, c)
return nil, &ParseError{"Unknown RR type", currenttok} if e != nil {
} return nil, e
return r, e }
if se := slurpRemainder(c); se != nil {
return nil, se
}
// 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
case TypeRRSIG:
r, e = setRRSIG(h, c)
case TypeNSEC:
r, e = setNSEC(h, c)
case TypeNSEC3:
r, e = setNSEC3(h, c)
case TypeTXT:
r, e = setTXT(h, c)
default:
return nil, &ParseError{"Unknown RR type", currenttok}
}
return r, e
} }
func setA(h RR_Header, c chan Lex) (RR, error) { func setA(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_A) rr := new(RR_A)
rr.Hdr = h rr.Hdr = h
l := <-c l := <-c
rr.A = net.ParseIP(l.token) rr.A = net.ParseIP(l.token)
if rr.A == nil { if rr.A == nil {
return nil, &ParseError{"bad a", l} return nil, &ParseError{"bad a", l}
} }
return rr, nil return rr, nil
} }
func setAAAA(h RR_Header, c chan Lex) (RR, error) { func setAAAA(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_AAAA) rr := new(RR_AAAA)
rr.Hdr = h rr.Hdr = h
l := <-c l := <-c
rr.AAAA = net.ParseIP(l.token) rr.AAAA = net.ParseIP(l.token)
if rr.AAAA == nil { if rr.AAAA == nil {
return nil, &ParseError{"bad AAAA", l} return nil, &ParseError{"bad AAAA", l}
} }
return rr, nil return rr, nil
} }
func setNS(h RR_Header, c chan Lex) (RR, error) { func setNS(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_NS) rr := new(RR_NS)
rr.Hdr = h rr.Hdr = h
l := <-c l := <-c
rr.Ns = l.token rr.Ns = l.token
if ! IsDomainName(l.token) { if !IsDomainName(l.token) {
return nil, &ParseError{"bad NS", l} return nil, &ParseError{"bad NS", l}
} }
return rr, nil return rr, nil
} }
func setMX(h RR_Header, c chan Lex) (RR, error) { func setMX(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_MX) rr := new(RR_MX)
rr.Hdr = h rr.Hdr = h
l := <-c l := <-c
if i, e := strconv.Atoi(l.token); e != nil { if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{"bad MX", l} return nil, &ParseError{"bad MX", l}
} else { } else {
rr.Pref = uint16(i) rr.Pref = uint16(i)
} }
<-c // _BLANK <-c // _BLANK
l = <-c // _STRING l = <-c // _STRING
rr.Mx = l.token rr.Mx = l.token
if ! IsDomainName(l.token) { if !IsDomainName(l.token) {
return nil, &ParseError{"bad CNAME", l} return nil, &ParseError{"bad CNAME", l}
} }
return rr, nil return rr, nil
} }
func setCNAME(h RR_Header, c chan Lex) (RR, error) { func setCNAME(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_CNAME) rr := new(RR_CNAME)
rr.Hdr = h rr.Hdr = h
l := <-c l := <-c
rr.Cname = l.token rr.Cname = l.token
if ! IsDomainName(l.token) { if !IsDomainName(l.token) {
return nil, &ParseError{"bad CNAME", l} return nil, &ParseError{"bad CNAME", l}
} }
return rr, nil return rr, nil
} }
func setSOA(h RR_Header, c chan Lex) (RR, error) { func setSOA(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_SOA) rr := new(RR_SOA)
rr.Hdr = h rr.Hdr = h
l := <-c l := <-c
rr.Ns = l.token rr.Ns = l.token
<-c // _BLANK <-c // _BLANK
if ! IsDomainName(l.token) { if !IsDomainName(l.token) {
return nil, &ParseError{"bad SOA", l} return nil, &ParseError{"bad SOA mname", l}
} }
l = <-c l = <-c
rr.Mbox = l.token rr.Mbox = l.token
if ! IsDomainName(l.token) { if !IsDomainName(l.token) {
return nil, &ParseError{"bad SOA", l} return nil, &ParseError{"bad SOA rname", l}
} }
<-c // _BLANK <-c // _BLANK
var ( var j int
j int var e error
e error for i := 0; i < 5; i++ {
) l = <-c
for i := 0; i < 5; i++ { if j, e = strconv.Atoi(l.token); e != nil {
l = <-c return nil, &ParseError{"bad SOA zone parameter", l}
if j, e = strconv.Atoi(l.token); e != nil { }
return nil, &ParseError{"bad SOA", l} switch i {
} case 0:
switch i { rr.Serial = uint32(j)
case 0: rr.Serial = uint32(j) case 1:
case 1: rr.Refresh = uint32(j) rr.Refresh = uint32(j)
case 2: rr.Retry = uint32(j) case 2:
case 3: rr.Expire = uint32(j) rr.Retry = uint32(j)
case 4: rr.Minttl = uint32(j) case 3:
} rr.Expire = uint32(j)
<-c // _BLANK case 4:
} rr.Minttl = uint32(j)
return rr, nil }
<-c // _BLANK
}
return rr, nil
} }
func setRRSIG(h RR_Header, c chan Lex) (RR, error) { func setRRSIG(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_RRSIG) rr := new(RR_RRSIG)
rr.Hdr = h rr.Hdr = h
l := <-c l := <-c
if t, ok := Str_rr[strings.ToUpper(l.token)]; !ok { if t, ok := Str_rr[strings.ToUpper(l.token)]; !ok {
return nil, &ParseError{"bad RRSIG", l} return nil, &ParseError{"bad RRSIG", l}
} else { } else {
rr.TypeCovered = t rr.TypeCovered = t
} }
<-c // _BLANK <-c // _BLANK
l = <-c l = <-c
if i, err := strconv.Atoi(l.token); err != nil { if i, err := strconv.Atoi(l.token); err != nil {
return nil, &ParseError{"bad RRSIG", l} return nil, &ParseError{"bad RRSIG", l}
} else { } else {
rr.Algorithm = uint8(i) rr.Algorithm = uint8(i)
} }
<-c // _BLANK <-c // _BLANK
l = <-c l = <-c
if i, err := strconv.Atoi(l.token); err != nil { if i, err := strconv.Atoi(l.token); err != nil {
return nil, &ParseError{"bad RRSIG", l} return nil, &ParseError{"bad RRSIG", l}
} else { } else {
rr.Labels = uint8(i) rr.Labels = uint8(i)
} }
<-c // _BLANK <-c // _BLANK
l = <-c l = <-c
if i, err := strconv.Atoi(l.token); err != nil { if i, err := strconv.Atoi(l.token); err != nil {
return nil, &ParseError{"bad RRSIG", l} return nil, &ParseError{"bad RRSIG", l}
} else { } else {
rr.OrigTtl = uint32(i) rr.OrigTtl = uint32(i)
} }
<-c // _BLANK <-c // _BLANK
l = <-c l = <-c
if i, err := dateToTime(l.token); err != nil { if i, err := dateToTime(l.token); err != nil {
return nil, &ParseError{"bad RRSIG", l} return nil, &ParseError{"bad RRSIG", l}
} else { } else {
rr.Expiration = i rr.Expiration = i
} }
<-c // _BLANK <-c // _BLANK
l = <-c l = <-c
if i, err := dateToTime(l.token); err != nil { if i, err := dateToTime(l.token); err != nil {
return nil, &ParseError{"bad RRSIG", l} return nil, &ParseError{"bad RRSIG", l}
} else { } else {
rr.Inception = i rr.Inception = i
} }
<-c // _BLANK <-c // _BLANK
l = <-c l = <-c
if i, err := strconv.Atoi(l.token); err != nil { if i, err := strconv.Atoi(l.token); err != nil {
return nil, &ParseError{"bad RRSIG", l} return nil, &ParseError{"bad RRSIG", l}
} else { } else {
rr.KeyTag = uint16(i) rr.KeyTag = uint16(i)
} }
<-c // _BLANK <-c // _BLANK
l = <-c l = <-c
if ! IsDomainName(l.token) { if !IsDomainName(l.token) {
return nil, &ParseError{"bad RRSIG", l} return nil, &ParseError{"bad RRSIG", l}
} else { } else {
rr.SignerName = l.token rr.SignerName = l.token
} }
// Get the remaining data until we see a NEWLINE // Get the remaining data until we see a NEWLINE
l = <-c l = <-c
var s string var s string
for l.value != _NEWLINE { for l.value != _NEWLINE && l.value != _EOF {
switch l.value { switch l.value {
case _STRING: case _STRING:
s += l.token s += l.token
case _BLANK: case _BLANK:
// Ok // Ok
default: default:
return nil, &ParseError{"bad RRSIG", l} return nil, &ParseError{"bad RRSIG", l}
} }
l = <-c l = <-c
} }
rr.Signature = s rr.Signature = s
return rr, nil return rr, nil
} }
func setNSEC(h RR_Header, c chan Lex) (RR, error) { func setNSEC(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_NSEC) rr := new(RR_NSEC)
rr.Hdr = h rr.Hdr = h
l := <-c l := <-c
if ! IsDomainName(l.token) { if !IsDomainName(l.token) {
return nil, &ParseError{"bad NSEC", l} return nil, &ParseError{"bad NSEC", l}
} else { } else {
rr.NextDomain = l.token rr.NextDomain = l.token
} }
rr.TypeBitMap = make([]uint16, 0) rr.TypeBitMap = make([]uint16, 0)
l = <-c l = <-c
for l.value != _NEWLINE { for l.value != _NEWLINE && l.value != _EOF {
switch l.value { switch l.value {
case _BLANK: case _BLANK:
// Ok // Ok
case _STRING: case _STRING:
if k, ok := Str_rr[strings.ToUpper(l.token)]; !ok { if k, ok := Str_rr[strings.ToUpper(l.token)]; !ok {
return nil, &ParseError{"bad NSEC", l} return nil, &ParseError{"bad NSEC", l}
} else { } else {
rr.TypeBitMap = append(rr.TypeBitMap, k) rr.TypeBitMap = append(rr.TypeBitMap, k)
} }
default: default:
return nil, &ParseError{"bad NSEC", l} return nil, &ParseError{"bad NSEC", l}
} }
l = <-c l = <-c
} }
return rr, nil return rr, nil
} }
func setNSEC3(h RR_Header, c chan Lex) (RR, error) { func setNSEC3(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_NSEC3) rr := new(RR_NSEC3)
rr.Hdr = h rr.Hdr = h
l := <-c l := <-c
if i, e := strconv.Atoi(l.token); e != nil { if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{"bad NSEC3", l} return nil, &ParseError{"bad NSEC3", l}
} else { } else {
rr.Hash = uint8(i) rr.Hash = uint8(i)
} }
<-c // _BLANK <-c // _BLANK
l = <-c l = <-c
if i, e := strconv.Atoi(l.token); e != nil { if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{"bad NSEC3", l} return nil, &ParseError{"bad NSEC3", l}
} else { } else {
rr.Flags = uint8(i) rr.Flags = uint8(i)
} }
<-c // _BLANK <-c // _BLANK
l = <-c l = <-c
if i, e := strconv.Atoi(l.token); e != nil { if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{"bad NSEC3", l} return nil, &ParseError{"bad NSEC3", l}
} else { } else {
rr.Iterations = uint16(i) rr.Iterations = uint16(i)
} }
<-c <-c
l = <-c l = <-c
rr.SaltLength = uint8(len(l.token)) rr.SaltLength = uint8(len(l.token))
rr.Salt = l.token // CHECK? rr.Salt = l.token // CHECK?
<-c <-c
l = <-c l = <-c
rr.HashLength = uint8(len(l.token)) rr.HashLength = uint8(len(l.token))
rr.NextDomain = l.token rr.NextDomain = l.token
rr.TypeBitMap = make([]uint16, 0) rr.TypeBitMap = make([]uint16, 0)
l = <-c l = <-c
for l.value != _NEWLINE { for l.value != _NEWLINE && l.value != _EOF {
switch l.value { switch l.value {
case _BLANK: case _BLANK:
// Ok // Ok
case _STRING: case _STRING:
if k, ok := Str_rr[strings.ToUpper(l.token)]; !ok { if k, ok := Str_rr[strings.ToUpper(l.token)]; !ok {
return nil, &ParseError{"bad NSEC3", l} return nil, &ParseError{"bad NSEC3", l}
} else { } else {
rr.TypeBitMap = append(rr.TypeBitMap, k) rr.TypeBitMap = append(rr.TypeBitMap, k)
} }
default: default:
return nil, &ParseError{"bad NSEC3", l} return nil, &ParseError{"bad NSEC3", l}
} }
l = <-c l = <-c
} }
return rr, nil return rr, nil
} }
/* /*
func setNSEC3PARAM(h RR_Header, c chan Lex) (RR, error) { func setNSEC3PARAM(h RR_Header, c chan Lex) (RR, error) {
@ -375,28 +398,29 @@ func setNSEC3PARAM(h RR_Header, c chan Lex) (RR, error) {
*/ */
func setTXT(h RR_Header, c chan Lex) (RR, error) { func setTXT(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_TXT) rr := new(RR_TXT)
rr.Hdr = h rr.Hdr = h
// Get the remaining data until we see a NEWLINE // Get the remaining data until we see a NEWLINE
l := <-c l := <-c
var s string var s string
for l.value != _NEWLINE { for l.value != _NEWLINE && l.value != _EOF {
switch l.value { println("tok", l.token, l.value)
case _STRING: switch l.value {
s += l.token case _STRING:
case _BLANK: s += l.token
// Ok case _BLANK:
default: s += l.token
return nil, &ParseError{"bad TXT", l} default:
} return nil, &ParseError{"bad TXT", l}
l = <-c }
} l = <-c
rr.Txt = s }
return rr, nil rr.Txt = s
return rr, nil
} }
/* /*
func setDS(h RR_Header, c chan Lex) (RR, error) { func setDS(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_DS) rr := new(RR_DS)
rr.Hdr = h rr.Hdr = h