Works, stop touching it
This commit is contained in:
parent
bd03eda9f4
commit
ff351f2cf7
61
zparse.rl
61
zparse.rl
|
@ -1,8 +1,13 @@
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
|
// Parse RRs
|
||||||
|
// With the thankful help of gdnsd and the Go examples for Ragel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
%%{
|
%%{
|
||||||
|
@ -10,22 +15,44 @@ import (
|
||||||
write data;
|
write data;
|
||||||
}%%
|
}%%
|
||||||
|
|
||||||
func zparse(data string) (res int, err os.Error) {
|
func zparse(data string) (rr RR, err os.Error) {
|
||||||
cs, p, pe, eof := 0, 0, len(data), len(data)
|
cs, p, pe := 0, 0, len(data)
|
||||||
|
mark := 0
|
||||||
|
eof := len(data)
|
||||||
|
hdr := new(RR_Header)
|
||||||
|
|
||||||
%%{
|
%%{
|
||||||
action out { fmt.Printf("%s\n", data[p:pe]) }
|
action mark { mark = p }
|
||||||
action defTtl { fmt.Printf("%s\n", data[p:pe]) }
|
action rdata_out { fmt.Printf("rdata {%s}\n", data[mark:p]) }
|
||||||
action setTtl { fmt.Printf("%s\n", data[p:pe]) }
|
action qname_out { fmt.Printf("qname {%s}\n", data[mark:p]); hdr.Name = data[mark:p] }
|
||||||
|
action qclass_out { fmt.Printf("qclass {%s}\n", data[mark:p]) }
|
||||||
|
action qtype_out {
|
||||||
|
fmt.Printf("qtype {%s}\n", data[mark:p])
|
||||||
|
}
|
||||||
|
|
||||||
qtype = ('IN'i|'CS'i|'CH'i|'HS'i|'ANY'i|'NONE'i);
|
action defTtl { fmt.Printf("defttl {%s}\n", data[mark:p]) }
|
||||||
ttl = digit+;
|
action setTtl {
|
||||||
blank = [ \t]+;
|
fmt.Printf("ttl {%s}\n", data[mark:p])
|
||||||
qname = any+;
|
ttl, _ := strconv.Atoi(data[mark:p])
|
||||||
|
hdr.Ttl = uint32(ttl)
|
||||||
|
}
|
||||||
|
|
||||||
# RDATA definition
|
action rdata_a {
|
||||||
rdata_a = any+;
|
r := new(RR_A)
|
||||||
rdata_dnskey = any+;
|
r.Hdr = *hdr
|
||||||
|
r.Hdr.Rrtype = TypeA
|
||||||
|
r.A = net.ParseIP(data[mark:p])
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
qtype = ('IN'i|'CS'i|'CH'i|'HS'i|'ANY'i|'NONE'i) %qtype_out;
|
||||||
|
ttl = digit+ >mark;
|
||||||
|
blank = [ \t]+ %mark;
|
||||||
|
qname = [a-zA-Z0-9.\\]+ %qname_out;
|
||||||
|
|
||||||
|
# RDATA definitions
|
||||||
|
rdata_a = any+ $1 %0 %rdata_a;
|
||||||
|
rdata_dnskey = [a-z0-9.\\]+;
|
||||||
|
|
||||||
lhs = qname? blank %defTtl (
|
lhs = qname? blank %defTtl (
|
||||||
(ttl %setTtl blank (qtype blank)?)
|
(ttl %setTtl blank (qtype blank)?)
|
||||||
|
@ -34,8 +61,8 @@ func zparse(data string) (res int, err os.Error) {
|
||||||
|
|
||||||
# RR definitions
|
# RR definitions
|
||||||
rhs = (
|
rhs = (
|
||||||
('A'i blank rdata_a) %out
|
('A'i %qtype_out blank rdata_a)
|
||||||
| ('DNSKEY'i blank rdata_dnskey) %out
|
| ('DNSKEY'i %qtype_out blank rdata_dnskey)
|
||||||
);
|
);
|
||||||
|
|
||||||
rr = lhs rhs;
|
rr = lhs rhs;
|
||||||
|
@ -49,10 +76,10 @@ func zparse(data string) (res int, err os.Error) {
|
||||||
if cs < z_first_final {
|
if cs < z_first_final {
|
||||||
// No clue what I'm doing what so ever
|
// No clue what I'm doing what so ever
|
||||||
if p == pe {
|
if p == pe {
|
||||||
return 0, os.ErrorString("unexpected eof")
|
return nil, os.ErrorString("unexpected eof")
|
||||||
} else {
|
} else {
|
||||||
return 0, os.ErrorString(fmt.Sprintf("error at position %d", p))
|
return nil, os.ErrorString(fmt.Sprintf("error at position %d", p))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0 ,nil
|
return rr ,nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue