gone
This commit is contained in:
parent
e863e86e65
commit
5fe15bc754
3
Makefile
3
Makefile
|
@ -23,7 +23,6 @@ GOFILES=\
|
||||||
xfr.go\
|
xfr.go\
|
||||||
zone.go\
|
zone.go\
|
||||||
zparse.go\
|
zparse.go\
|
||||||
# test.go\
|
|
||||||
|
|
||||||
|
|
||||||
include $(GOROOT)/src/Make.pkg
|
include $(GOROOT)/src/Make.pkg
|
||||||
|
@ -35,7 +34,7 @@ examples:
|
||||||
gomake -C _examples
|
gomake -C _examples
|
||||||
|
|
||||||
# yes, hardcoded path, yes ugly, yes, deal with it
|
# yes, hardcoded path, yes ugly, yes, deal with it
|
||||||
zparse.go: zparse.rl types.rl
|
zparse.go: zparse.rl
|
||||||
/home/miekg/svn/ragel/ragel/ragel -Z -G2 -o $@ $<
|
/home/miekg/svn/ragel/ragel/ragel -Z -G2 -o $@ $<
|
||||||
|
|
||||||
kparse.go: kparse.rl
|
kparse.go: kparse.rl
|
||||||
|
|
157
types.rl
157
types.rl
|
@ -1,88 +1,69 @@
|
||||||
%%{
|
func rdata_a(hdr RR_Header, tok *token) RR {
|
||||||
machine z;
|
rr := new(RR_A)
|
||||||
|
rr.Hdr = hdr
|
||||||
action rdata_a {
|
rr.Hdr.Rrtype = TypeA
|
||||||
rr = new(RR_A)
|
rr.A = net.ParseIP(tok.T[0])
|
||||||
x := rr.(*RR_A)
|
}
|
||||||
x.Hdr = *hdr
|
func rdata_ns(hdr RR_Header, tok *token) RR {
|
||||||
x.Hdr.Rrtype = TypeA
|
rr := new(RR_NS)
|
||||||
x.A = net.ParseIP(tok.T[0])
|
rr.Hdr = hdr
|
||||||
}
|
rr.Hdr.Rrtype = TypeNS
|
||||||
action rdata_aaaa {
|
rr.Ns = tok.T[0]
|
||||||
rr = new(RR_AAAA)
|
}
|
||||||
x := rr.(*RR_AAAA)
|
func rdata_cname(hdr RR_Header, tok *token) RR {
|
||||||
x.Hdr = *hdr
|
rr := new(RR_CNAME)
|
||||||
x.Hdr.Rrtype = TypeAAAA
|
rr.Hdr = hdr
|
||||||
x.AAAA = net.ParseIP(tok.T[0])
|
rr.Hdr.Rrtype = TypeCNAME
|
||||||
}
|
rr.Cname = tok.T[0]
|
||||||
action rdata_ns {
|
}
|
||||||
rr = new(RR_NS)
|
func rdata_soa(hdr RR_Header, tok *token) RR {
|
||||||
x := rr.(*RR_NS)
|
rr := new(RR_SOA)
|
||||||
x.Hdr = *hdr
|
rr.Hdr = hdr
|
||||||
x.Hdr.Rrtype = TypeNS
|
rr.Hdr.Rrtype = TypeSOA
|
||||||
x.Ns = tok.T[0]
|
rr.Ns = tok.T[0]
|
||||||
}
|
rr.Mbox = tok.T[1]
|
||||||
action rdata_cname {
|
rr.Serial = uint32(tok.N[0])
|
||||||
rr = new(RR_CNAME)
|
rr.Refresh = uint32(tok.N[1])
|
||||||
x := rr.(*RR_CNAME)
|
rr.Retry = uint32(tok.N[2])
|
||||||
x.Hdr = *hdr
|
rr.Expire = uint32(tok.N[3])
|
||||||
x.Hdr.Rrtype = TypeCNAME
|
rr.Minttl = uint32(tok.N[4])
|
||||||
x.Cname = tok.T[0]
|
}
|
||||||
}
|
func rdata_mx(hdr RR_Header, tok *token) RR {
|
||||||
action rdata_soa {
|
rr := new(RR_MX)
|
||||||
rr = new(RR_SOA)
|
rr.Hdr = hdr;
|
||||||
x := rr.(*RR_SOA)
|
rr.Hdr.Rrtype = TypeMX
|
||||||
x.Hdr = *hdr
|
rr.Pref = uint16(tok.N[0])
|
||||||
x.Hdr.Rrtype = TypeSOA
|
rr.Mx = tok.T[0]
|
||||||
x.Ns = tok.T[0]
|
}
|
||||||
x.Mbox = tok.T[1]
|
func rdata_ds(hdr RR_Header, tok *token) RR {
|
||||||
x.Serial = uint32(tok.N[0])
|
rr := new(RR_DS)
|
||||||
x.Refresh = uint32(tok.N[1])
|
rr.Hdr = hdr;
|
||||||
x.Retry = uint32(tok.N[2])
|
rr.Hdr.Rrtype = TypeDS
|
||||||
x.Expire = uint32(tok.N[3])
|
rr.KeyTag = uint16(tok.N[0])
|
||||||
x.Minttl = uint32(tok.N[4])
|
rr.Algorithm = uint8(tok.N[1])
|
||||||
}
|
rr.DigestType = uint8(tok.N[2])
|
||||||
action rdata_mx {
|
rr.Digest = tok.T[0]
|
||||||
rr = new(RR_MX)
|
}
|
||||||
x := rr.(*RR_MX)
|
func rdata_dnskey(hdr RR_Header, tok *token) RR {
|
||||||
x.Hdr = *hdr;
|
rr := new(RR_DNSKEY)
|
||||||
x.Hdr.Rrtype = TypeMX
|
rr.Hdr = hdr;
|
||||||
x.Pref = uint16(tok.N[0])
|
rr.Hdr.Rrtype = TypeDNSKEY
|
||||||
x.Mx = tok.T[0]
|
rr.Flags = uint16(tok.N[0])
|
||||||
}
|
rr.Protocol = uint8(tok.N[1])
|
||||||
action rdata_ds {
|
rr.Algorithm = uint8(tok.N[2])
|
||||||
rr = new(RR_DS)
|
rr.PublicKey = tok.T[0]
|
||||||
x := rr.(*RR_DS)
|
}
|
||||||
x.Hdr = *hdr;
|
func rdata_rrsig(hdr RR_Header, tok *token) RR {
|
||||||
x.Hdr.Rrtype = TypeDS
|
rr := new(RR_RRSIG)
|
||||||
x.KeyTag = uint16(tok.N[0])
|
rr.Hdr = hdr;
|
||||||
x.Algorithm = uint8(tok.N[1])
|
rr.Hdr.Rrtype = TypeRRSIG
|
||||||
x.DigestType = uint8(tok.N[2])
|
rr.TypeCovered = uint16(tok.N[0])
|
||||||
x.Digest = tok.T[0]
|
rr.Algorithm = uint8(tok.N[1])
|
||||||
}
|
rr.Labels = uint8(tok.N[2])
|
||||||
action rdata_dnskey {
|
rr.OrigTtl = uint32(tok.N[3])
|
||||||
rr = new(RR_DNSKEY)
|
rr.Expiration = uint32(tok.N[4])
|
||||||
x := rr.(*RR_DNSKEY)
|
rr.Inception = uint32(tok.N[5])
|
||||||
x.Hdr = *hdr;
|
rr.KeyTag = uint16(tok.N[6])
|
||||||
x.Hdr.Rrtype = TypeDNSKEY
|
rr.SignerName = tok.T[0]
|
||||||
x.Flags = uint16(tok.N[0])
|
rr.Signature = tok.T[1]
|
||||||
x.Protocol = uint8(tok.N[1])
|
}
|
||||||
x.Algorithm = uint8(tok.N[2])
|
|
||||||
x.PublicKey = tok.T[0]
|
|
||||||
}
|
|
||||||
action rdata_rrsig {
|
|
||||||
rr = new(RR_RRSIG)
|
|
||||||
x := rr.(*RR_RRSIG)
|
|
||||||
x.Hdr = *hdr;
|
|
||||||
x.Hdr.Rrtype = TypeRRSIG
|
|
||||||
x.TypeCovered = uint16(tok.N[0])
|
|
||||||
x.Algorithm = uint8(tok.N[1])
|
|
||||||
x.Labels = uint8(tok.N[2])
|
|
||||||
x.OrigTtl = uint32(tok.N[3])
|
|
||||||
x.Expiration = uint32(tok.N[4])
|
|
||||||
x.Inception = uint32(tok.N[5])
|
|
||||||
x.KeyTag = uint16(tok.N[6])
|
|
||||||
x.SignerName = tok.T[0]
|
|
||||||
x.Signature = tok.T[1]
|
|
||||||
}
|
|
||||||
}%%
|
|
||||||
|
|
169
zparse.rl
169
zparse.rl
|
@ -1,169 +0,0 @@
|
||||||
package dns
|
|
||||||
|
|
||||||
// Parse RRs
|
|
||||||
// With the thankful help of gdnsd and the Go examples for Ragel.
|
|
||||||
//
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"io"
|
|
||||||
"net"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
const _RDATAMAX = 7
|
|
||||||
const _IOBUF = 65365
|
|
||||||
|
|
||||||
// Save up tokens, after we've seen the entire rdata
|
|
||||||
// we can use this.
|
|
||||||
type token struct {
|
|
||||||
T []string // text
|
|
||||||
N []int // number
|
|
||||||
ti int // text counter
|
|
||||||
ni int // number counter
|
|
||||||
}
|
|
||||||
|
|
||||||
func newToken() *token {
|
|
||||||
to := new(token)
|
|
||||||
to.T = make([]string, _RDATAMAX)
|
|
||||||
to.N = make([]int, _RDATAMAX)
|
|
||||||
to.ni, to.ti = 0, 0
|
|
||||||
return to
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only push functions are provided. Reading is done, by directly
|
|
||||||
// accessing the members (T and N). See types.rl.
|
|
||||||
func (to *token) pushInt(s string) {
|
|
||||||
i, err := strconv.Atoi(s)
|
|
||||||
if err != nil {
|
|
||||||
panic("Failure to parse to int: " + s)
|
|
||||||
}
|
|
||||||
to.N[to.ni] = i
|
|
||||||
to.ni++
|
|
||||||
if to.ni > _RDATAMAX {
|
|
||||||
panic("Too much rdata (int)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (to *token) pushString(s string) {
|
|
||||||
to.T[to.ti] = s
|
|
||||||
to.ti++
|
|
||||||
if to.ti > _RDATAMAX {
|
|
||||||
panic("Too much rdata (string)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (to *token) reset() {
|
|
||||||
to.ni, to.ti = 0, 0
|
|
||||||
}
|
|
||||||
|
|
||||||
%%{
|
|
||||||
machine z;
|
|
||||||
write data;
|
|
||||||
}%%
|
|
||||||
|
|
||||||
// SetString
|
|
||||||
// All the NewReader stuff is expensive...
|
|
||||||
// only works for short io.Readers as we put the whole thing
|
|
||||||
// in a string -- needs to be extended for large files (sliding window).
|
|
||||||
func Zparse(q io.Reader) (z *Zone, err os.Error) {
|
|
||||||
buf := make([]byte, _IOBUF)
|
|
||||||
n, err := q.Read(buf)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
buf = buf[:n]
|
|
||||||
z = new(Zone)
|
|
||||||
|
|
||||||
data := string(buf)
|
|
||||||
cs, p, pe := 0, 0, len(data)
|
|
||||||
ts, te, act := 0, 0, 0
|
|
||||||
// top := 0
|
|
||||||
// stack := make([]int, 100)
|
|
||||||
eof := len(data)
|
|
||||||
// keep Go happy
|
|
||||||
ts = ts; te = te; act = act
|
|
||||||
|
|
||||||
brace := false
|
|
||||||
lines := 0
|
|
||||||
mark := 0
|
|
||||||
hdr := new(RR_Header)
|
|
||||||
tok := newToken()
|
|
||||||
var rr RR
|
|
||||||
|
|
||||||
%%{
|
|
||||||
action mark { mark = p }
|
|
||||||
action qname { hdr.Name = data[mark:p] }
|
|
||||||
action qclass { hdr.Class = Str_class[data[mark:p]] }
|
|
||||||
action defTtl { /* ... */ }
|
|
||||||
action setTtl { ttl, _ := strconv.Atoi(data[mark:p]); hdr.Ttl = uint32(ttl) }
|
|
||||||
action number { tok.pushInt(data[mark:p]) }
|
|
||||||
action text { tok.pushString(data[mark:p]) }
|
|
||||||
action set { z.Push(rr); tok.reset(); println("Setting") }
|
|
||||||
action openBrace { if brace { println("Brace already open")} ; brace = true }
|
|
||||||
action closeBrace { if !brace { println("Brace already closed")}; brace = false }
|
|
||||||
action brace { brace }
|
|
||||||
action linecount { lines++ }
|
|
||||||
|
|
||||||
# Newlines
|
|
||||||
nl = [\n]+ $linecount;
|
|
||||||
|
|
||||||
# Comments, entire line. Shorter comments are handled in the
|
|
||||||
# 'bl' definition below.
|
|
||||||
comment = ';' [^\n]*;
|
|
||||||
|
|
||||||
bl = (
|
|
||||||
[ \t]+
|
|
||||||
| '(' $openBrace
|
|
||||||
| ')' $closeBrace
|
|
||||||
| (comment? nl)+ when brace
|
|
||||||
)+ %mark;
|
|
||||||
|
|
||||||
qclass = ('IN'i|'CS'i|'CH'i|'HS'i|'ANY'i|'NONE'i) %qclass;
|
|
||||||
chars = [^; \t"\n\\)(];
|
|
||||||
ttl = digit+ >mark;
|
|
||||||
qname = chars+ %qname;
|
|
||||||
tb = (chars | ' ')+ $1 %0 %text;
|
|
||||||
t = chars+ $1 %0 %text;
|
|
||||||
n = [0-9]+ $1 %0 %number;
|
|
||||||
|
|
||||||
lhs = qname? bl %defTtl (
|
|
||||||
(ttl %setTtl bl (qclass bl)?)
|
|
||||||
| (qclass bl (ttl %setTtl bl)?)
|
|
||||||
)?;
|
|
||||||
|
|
||||||
# RDATA definitions.
|
|
||||||
include "types.rl";
|
|
||||||
|
|
||||||
# RR definitions.
|
|
||||||
rhs = (
|
|
||||||
('AAAA'i bl t) %rdata_aaaa
|
|
||||||
| ('A'i bl t) %rdata_a
|
|
||||||
| ('NS'i bl t) %rdata_ns
|
|
||||||
| ('CNAME'i bl t) %rdata_cname
|
|
||||||
| ('MX'i bl n bl t) %rdata_mx
|
|
||||||
);
|
|
||||||
# 'SOA'i; bl; t; bl; t; bl; n; bl; n; bl; n; bl; n; bl; n => rdata_soa; { fret; };
|
|
||||||
# *|;
|
|
||||||
|
|
||||||
rr = lhs rhs %set;
|
|
||||||
main := (rr? bl? ((comment? nl) when !brace))*;
|
|
||||||
|
|
||||||
write init;
|
|
||||||
write exec;
|
|
||||||
}%%
|
|
||||||
|
|
||||||
if eof > -1 {
|
|
||||||
if cs < z_first_final {
|
|
||||||
// No clue what I'm doing what so ever
|
|
||||||
if p == pe {
|
|
||||||
println("unexpected eof")
|
|
||||||
return z, nil
|
|
||||||
} else {
|
|
||||||
println("error at position ", p, "\"",data[mark:p],"\"")
|
|
||||||
return z, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return z, nil
|
|
||||||
}
|
|
Loading…
Reference in New Issue