More fixes, but doesnt compile yet

This commit is contained in:
Miek Gieben 2011-12-14 11:56:12 +01:00
parent 8bfa46dec7
commit 5836f0f8f6
1 changed files with 213 additions and 226 deletions

View File

@ -15,13 +15,13 @@ func slurpRemainder(c chan Lex) error {
case _BLANK:
l = <-c
if l.value != _NEWLINE {
return &ParseError{err: "garbage after rdata", lex: l}
return &ParseError{"garbage after rdata", l}
}
// Ok
case _NEWLINE:
// Ok
default:
return &ParseError{err: "garbage after rdata", lex: l}
return &ParseError{"garbage after rdata", l}
}
return nil
}
@ -34,12 +34,15 @@ func setRR(h RR_Header, c chan Lex) (RR, error) {
switch h.Rrtype {
case TypeA:
r, e = setA(h, c)
if se := slurpRemainder(c); se != nil {
return nil, se
}
case TypeRRSIG:
r, e = setRRSIG(h, c)
// Remain slurped in function
default:
println("RR not supported")
}
if se := slurpRemainder(c); se != nil {
return nil, se
}
return r, e
}
@ -50,7 +53,7 @@ func setA(h RR_Header, c chan Lex) (RR, error) {
l := <-c
rr.A = net.ParseIP(l.token)
if rr.A == nil {
return nil, &ParseError{err: "bad a", lex: l}
return nil, &ParseError{"bad a", l}
}
return rr, nil
}
@ -62,7 +65,7 @@ func setAAAA(h RR_Header, c chan Lex) (RR, error) {
l := <-c
rr.AAAA = net.ParseIP(l.token)
if rr.AAAA == nil {
return nil, &ParseError{err: "bad AAAA", lex: l}
return nil, &ParseError{"bad AAAA", l}
}
return rr, nil
}
@ -74,7 +77,7 @@ func setNS(h RR_Header, c chan Lex) (RR, error) {
l := <-c
rr.Ns = l.token
if ! IsDomainName(l.token) {
return nil, &ParseError{err: "bad NS", lex: l}
return nil, &ParseError{"bad NS", l}
}
return rr, nil
}
@ -85,12 +88,15 @@ func setMX(h RR_Header, c chan Lex) (RR, error) {
l := <-c
i, e := strconv.Atoui(l.token)
if e != nil {
return nil, &ParseError{"bad MX", l}
}
rr.Pref = uint16(i)
l = <-c // _BLANK
<-c // _BLANK
l = <-c // _STRING
rr.Mx = l.token
if e != nil {
return nil, &ParseError{err: "bad MX", lex: l}
if ! IsDomainName(l.token) {
return nil, &ParseError{"bad CNAME", l}
}
return rr, nil
}
@ -99,61 +105,220 @@ func setCNAME(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_CNAME)
rr.Hdr = h
action setCNAME {
rdf := fields(data[mark:p], 1)
rr := new(RR_CNAME)
rr.Hdr = hdr
rr.Hdr.Rrtype = TypeCNAME
rr.Cname = rdf[0]
if ! IsDomainName(rdf[0]) {
zp.Err <- &ParseError{Error: "bad CNAME", name: rdf[0], line: l}
return
l := <-c
rr.Cname = l.token
if ! IsDomainName(l.token) {
return nil, &ParseError{"bad CNAME", l}
}
zp.RR <- rr
}
return rr, nil
}
func setCNAME(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_CNAME)
func setSOA(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_SOA)
rr.Hdr = h
action setSOA {
l := <-c
var (
i uint
err os.Error
)
rdf := fields(data[mark:p], 7)
rr := new(RR_SOA)
rr.Hdr = hdr
rr.Hdr.Rrtype = TypeSOA
rr.Ns = rdf[0]
rr.Mbox = rdf[1]
if ! IsDomainName(rdf[0]) {
zp.Err <- &ParseError{Error: "bad SOA", name: rdf[0], line: l}
return
rr.Ns = l.token
<-c // _BLANK
if ! IsDomainName(l.token) {
return nil, &ParseError{"bad SOA", l}
}
if ! IsDomainName(rdf[1]) {
zp.Err <- &ParseError{Error: "bad SOA", name: rdf[1], line: l}
return
l = <-c
rr.Mbox = l.token
if ! IsDomainName(l.token) {
return nil, &ParseError{Error: "bad SOA", name: rdf[1], line: l}
}
for j, s := range rdf[2:7] {
if i, err = strconv.Atoui(s); err != nil {
zp.Err <- &ParseError{Error: "bad SOA", name: s, line: l}
return
<-c // _BLANK
for i := 0; i < 5; i++ {
l = <-c
if j, e = strconv.Atoui(s); e != nil {
return nil, &ParseError{"bad SOA", l}
}
switch j {
case 0: rr.Serial = uint32(i)
case 1: rr.Refresh = uint32(i)
case 2: rr.Retry = uint32(i)
case 3: rr.Expire = uint32(i)
case 4: rr.Minttl = uint32(i)
switch i {
case 0: rr.Serial = uint32(j)
case 1: rr.Refresh = uint32(j)
case 2: rr.Retry = uint32(j)
case 3: rr.Expire = uint32(j)
case 4: rr.Minttl = uint32(j)
}
<-c // _BLANK
}
z.PushRR(rr)
return rr, nil
}
func setRRSIG(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_RRSIG)
rr.Hdr = h
l := <-c
if t, ok := str_rr[strings.ToUpper(l.token]; !ok {
return nil, &ParseError{"bad RRSIG", l}
} else {
rr.TypeCovered = t
}
<-c // _BLANK
l = <-c
if i, err := strconv.Atoui(l.token); err != nil {
return nil, &ParseError{"bad RRSIG", l}
} else {
rr.Algorithm = uint8(i)
}
<-c // _BLANK
l = <-c
if i, err := strconv.Atoui(l.token); err != nil {
return nil, &ParseError{"bad RRSIG", l}
} else {
rr.Labels = uint8(i)
}
<-c // _BLANK
l = <-c
if i, err := strconv.Atoui(l.token); err != nil {
return nil, &ParseError{"bad RRSIG", l}
} else {
rr.OrigTtl = uint32(i)
}
<-c // _BLANK
l = <-c
if i, err := dateToTime(l.token); err != nil {
return nil, &ParseError{"bad RRSIG", l}
} else {
rr.Expiration = i
}
<-c // _BLANK
l = <-c
if i, err := dateToTime(l.token); err != nil {
return nil, &ParseError{"bad RRSIG", l}
} else {
rr.Inception = i
}
<-c // _BLANK
l = <-c
if i, err := strconv.Atoui(l.token); err != nil {
return nil, &ParseError{"bad RRSIG", l}
} else {
rr.KeyTag = uint16(i)
}
<-c // _BLANK
l = <-c
if ! IsDomainName(l.token) {
return nil, &ParseError{"bad RRSIG", l}
} else {
rr.SignerName = l.token
}
// Get the remaining data until we see a NEWLINE
// Check base64 TODO
rr.Signature = rdf[8]
zp.RR <- rr
}
func setNSEC(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_NSEC)
rr.Hdr = h
l := <-c
if ! IsDomainName(l.token) {
return nil, &ParseError{"bad RRSIG", l}
} else {
rr.NextDomain = l.token
}
rr.TypeBitMap = make([]uint16, len(rdf)-1)
// Fill the Type Bit Map
for i := 1; i < len(rdf); i++ {
// Check if its there in the map TODO
rr.TypeBitMap[i-1] = str_rr[strings.ToUpper(rdf[i])]
}
zp.RR <- rr
}
func setNSEC3(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_NSEC3)
rr.Hdr = h
rdf := fields(data[mark:p], 0)
if i, e = strconv.Atoui(rdf[0]); e != nil {
zp.Err <- &ParseError{Error: "bad NSEC3", name: rdf[0], line: l}
return
}
rr.Hash = uint8(i)
if i, e = strconv.Atoui(rdf[1]); e != nil {
zp.Err <- &ParseError{Error: "bad NSEC3", name: rdf[1], line: l}
return
}
rr.Flags = uint8(i)
if i, e = strconv.Atoui(rdf[2]); e != nil {
zp.Err <- &ParseError{Error: "bad NSEC3", name: rdf[2], line: l}
return
}
rr.Iterations = uint16(i)
rr.SaltLength = uint8(len(rdf[3]))
rr.Salt = rdf[3]
rr.HashLength = uint8(len(rdf[4]))
rr.NextDomain = rdf[4]
rr.TypeBitMap = make([]uint16, len(rdf)-5)
// Fill the Type Bit Map
for i := 5; i < len(rdf); i++ {
// Check if its there in the map TODO
rr.TypeBitMap[i-5] = str_rr[strings.ToUpper(rdf[i])]
}
zp.RR <- rr
}
func setNSEC3PARAM(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_NSEC3PARAM)
rr.Hdr = h
rdf := fields(data[mark:p], 4)
if i, e = strconv.Atoi(rdf[0]); e != nil {
zp.Err <- &ParseError{Error: "bad NSEC3PARAM", name: rdf[0], line: l}
return
}
rr.Hash = uint8(i)
if i, e = strconv.Atoi(rdf[1]); e != nil {
zp.Err <- &ParseError{Error: "bad NSEC3PARAM", name: rdf[1], line: l}
return
}
rr.Flags = uint8(i)
if i, e = strconv.Atoi(rdf[2]); e != nil {
zp.Err <- &ParseError{Error: "bad NSEC3PARAM", name: rdf[2], line: l}
return
}
rr.Iterations = uint16(i)
rr.Salt = rdf[3]
rr.SaltLength = uint8(len(rr.Salt))
zp.RR <- rr
}
func setTXT(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_TXT)
rr.Hdr = h
rr.Txt = rdf[0]
zp.RR <- rr
}
/*
func setCNAME(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_CNAME)
rr.Hdr = h
action setSRV {
}
func setCNAME(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_CNAME)
rr.Hdr = h
action setCERT {
}
func setDS(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_DS)
rr.Hdr = h
action setDS {
var (
i uint
@ -276,184 +441,6 @@ func setCNAME(h RR_Header, c chan Lex) (RR, error) {
zp.RR <- rr
}
func setCNAME(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_CNAME)
rr.Hdr = h
action setRRSIG {
var (
i uint
j uint32
err os.Error
)
rdf := fields(data[mark:p], 9)
rr := new(RR_RRSIG)
rr.Hdr = hdr
rr.Hdr.Rrtype = TypeRRSIG
if _, ok := str_rr[strings.ToUpper(rdf[0])]; !ok {
zp.Err <- &ParseError{Error: "bad RRSIG", name: rdf[0], line: l}
return
}
rr.TypeCovered = str_rr[strings.ToUpper(rdf[0])]
if i, err = strconv.Atoui(rdf[1]); err != nil {
zp.Err <- &ParseError{Error: "bad RRSIG", name: rdf[1], line: l}
return
}
rr.Algorithm = uint8(i)
if i, err = strconv.Atoui(rdf[2]); err != nil {
zp.Err <- &ParseError{Error: "bad RRSIG", name: rdf[2], line: l}
return
}
rr.Labels = uint8(i)
if i, err = strconv.Atoui(rdf[3]); err != nil {
zp.Err <- &ParseError{Error: "bad RRSIG", name: rdf[3], line: l}
return
}
rr.OrigTtl = uint32(i)
if j, err = dateToTime(rdf[4]); err != nil {
zp.Err <- &ParseError{Error: "bad RRSIG", name: rdf[4], line: l}
return
}
rr.Expiration = j
if j, err = dateToTime(rdf[5]); err != nil {
zp.Err <- &ParseError{Error: "bad RRSIG", name: rdf[5], line: l}
return
}
rr.Inception = j
if i, err = strconv.Atoui(rdf[6]); err != nil {
zp.Err <- &ParseError{Error: "bad RRSIG", name: rdf[3], line: l}
return
}
rr.KeyTag = uint16(i)
rr.SignerName = rdf[7]
if ! IsDomainName(rdf[7]) {
zp.Err <- &ParseError{Error: "bad RRSIG", name: rdf[7], line: l}
return
}
// Check base64 TODO
rr.Signature = rdf[8]
zp.RR <- rr
}
func setCNAME(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_CNAME)
rr.Hdr = h
action setNSEC {
rdf := fields(data[mark:p], 0)
rr := new(RR_NSEC)
rr.Hdr = hdr
rr.Hdr.Rrtype = TypeNSEC
rr.NextDomain = rdf[0]
rr.TypeBitMap = make([]uint16, len(rdf)-1)
// Fill the Type Bit Map
for i := 1; i < len(rdf); i++ {
// Check if its there in the map TODO
rr.TypeBitMap[i-1] = str_rr[strings.ToUpper(rdf[i])]
}
zp.RR <- rr
}
func setCNAME(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_CNAME)
rr.Hdr = h
action setNSEC3 {
var (
i uint
e os.Error
)
rdf := fields(data[mark:p], 0)
rr := new(RR_NSEC3)
rr.Hdr = hdr
rr.Hdr.Rrtype = TypeNSEC3
if i, e = strconv.Atoui(rdf[0]); e != nil {
zp.Err <- &ParseError{Error: "bad NSEC3", name: rdf[0], line: l}
return
}
rr.Hash = uint8(i)
if i, e = strconv.Atoui(rdf[1]); e != nil {
zp.Err <- &ParseError{Error: "bad NSEC3", name: rdf[1], line: l}
return
}
rr.Flags = uint8(i)
if i, e = strconv.Atoui(rdf[2]); e != nil {
zp.Err <- &ParseError{Error: "bad NSEC3", name: rdf[2], line: l}
return
}
rr.Iterations = uint16(i)
rr.SaltLength = uint8(len(rdf[3]))
rr.Salt = rdf[3]
rr.HashLength = uint8(len(rdf[4]))
rr.NextDomain = rdf[4]
rr.TypeBitMap = make([]uint16, len(rdf)-5)
// Fill the Type Bit Map
for i := 5; i < len(rdf); i++ {
// Check if its there in the map TODO
rr.TypeBitMap[i-5] = str_rr[strings.ToUpper(rdf[i])]
}
zp.RR <- rr
}
func setCNAME(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_CNAME)
rr.Hdr = h
action setNSEC3PARAM {
var (
i int
e os.Error
)
rdf := fields(data[mark:p], 4)
rr := new(RR_NSEC3PARAM)
rr.Hdr = hdr
rr.Hdr.Rrtype = TypeNSEC3PARAM
if i, e = strconv.Atoi(rdf[0]); e != nil {
zp.Err <- &ParseError{Error: "bad NSEC3PARAM", name: rdf[0], line: l}
return
}
rr.Hash = uint8(i)
if i, e = strconv.Atoi(rdf[1]); e != nil {
zp.Err <- &ParseError{Error: "bad NSEC3PARAM", name: rdf[1], line: l}
return
}
rr.Flags = uint8(i)
if i, e = strconv.Atoi(rdf[2]); e != nil {
zp.Err <- &ParseError{Error: "bad NSEC3PARAM", name: rdf[2], line: l}
return
}
rr.Iterations = uint16(i)
rr.Salt = rdf[3]
rr.SaltLength = uint8(len(rr.Salt))
zp.RR <- rr
}
func setCNAME(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_CNAME)
rr.Hdr = h
action setTXT {
rdf := fields(data[mark:p], 1)
rr := new(RR_TXT)
rr.Hdr = hdr
rr.Hdr.Rrtype = TypeTXT
rr.Txt = rdf[0]
zp.RR <- rr
}
func setCNAME(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_CNAME)
rr.Hdr = h
action setSRV {
}
func setCNAME(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_CNAME)
rr.Hdr = h
action setCERT {
}
func setCNAME(h RR_Header, c chan Lex) (RR, error) {
rr := new(RR_CNAME)