Add quotes to the parsing engine.

Support:
TXT
NAPTR

And other record that we may use.
This commit is contained in:
Miek Gieben 2012-02-13 13:19:37 +01:00
parent 42efa912b5
commit 2f64868d3c
5 changed files with 35 additions and 35 deletions

View File

@ -1,4 +1,4 @@
.PHONY: ex .PHONY: ex clean
EXAMPLES=mx \ EXAMPLES=mx \
chaos \ chaos \
@ -10,3 +10,6 @@ EXAMPLES=mx \
ex: ex:
for i in $(EXAMPLES); do go build dns/ex/$$i; done for i in $(EXAMPLES); do go build dns/ex/$$i; done
clean:
rm -f $(EXAMPLES)

View File

@ -215,6 +215,11 @@ func IsDomainName(s string) (uint8, uint8, bool) { // copied from net package.
l++ l++
longer = 1 longer = 1
} }
// Preloop check for root label
if s == "." {
return 0, 1, true
}
last := byte('.') last := byte('.')
ok := false // ok once we've seen a letter ok := false // ok once we've seen a letter
partlen := 0 partlen := 0

View File

@ -199,24 +199,24 @@ func TestParseNSEC(t *testing.T) {
func TestQuotes(t *testing.T) { func TestQuotes(t *testing.T) {
tests := map[string]string{ tests := map[string]string{
// `t.example.com. IN TXT "a bc"`: "t.example.com.\t3600\tIN\tTXT\t\"a bc\"", `t.example.com. IN TXT "a bc"`: "t.example.com.\t3600\tIN\tTXT\t\"a bc\"",
// `t.example.com. IN TXT "a `t.example.com. IN TXT "a
// bc"`: "t.example.com.\t3600\tIN\tTXT\t\"a\n bc\"", bc"`: "t.example.com.\t3600\tIN\tTXT\t\"a\n bc\"",
// `t.example.com. IN TXT "aaa" ;`: "t.example.com.\t3600\tIN\tTXT\t\"aaa\"", `t.example.com. IN TXT "aaa" ;`: "t.example.com.\t3600\tIN\tTXT\t\"aaa\"",
// `t.example.com. IN TXT "abc" "DEF"`: "t.example.com.\t3600\tIN\tTXT\t\"abc\" \"DEF\"", `t.example.com. IN TXT "abc" "DEF"`: "t.example.com.\t3600\tIN\tTXT\t\"abc\" \"DEF\"",
// `t.example.com. IN TXT "abc" ( "DEF" )`: "t.example.com.\t3600\tIN\tTXT\t\"abc\" \"DEF\"", `t.example.com. IN TXT "abc" ( "DEF" )`: "t.example.com.\t3600\tIN\tTXT\t\"abc\" \"DEF\"",
// `t.example.com. IN TXT aaa ;`: "t.example.com.\t3600\tIN\tTXT\t\"aaa \"", `t.example.com. IN TXT aaa ;`: "t.example.com.\t3600\tIN\tTXT\t\"aaa \"",
// `t.example.com. IN TXT aaa aaa;`: "t.example.com.\t3600\tIN\tTXT\t\"aaa aaa\"", `t.example.com. IN TXT aaa aaa;`: "t.example.com.\t3600\tIN\tTXT\t\"aaa aaa\"",
// `t.example.com. IN TXT aaa aaa`: "t.example.com.\t3600\tIN\tTXT\t\"aaa aaa\"", `t.example.com. IN TXT aaa aaa`: "t.example.com.\t3600\tIN\tTXT\t\"aaa aaa\"",
// `t.example.com. IN TXT aaa`: "t.example.com.\t3600\tIN\tTXT\t\"aaa\"", `t.example.com. IN TXT aaa`: "t.example.com.\t3600\tIN\tTXT\t\"aaa\"",
"cid.urn.arpa. NAPTR 100 50 \"s\" \"z3950+I2L+I2C\" \"\" _z3950._tcp.gatech.edu.": "cid.urn.arpa. NAPTR 100 50 \"s\" \"z3950+I2L+I2C\" \"\" _z3950._tcp.gatech.edu.":
"cid.urn.arpa.\t3600\tIN\tNAPTR\t100 50 \"s\" \"z3950+I2L+I2C\" \"\" _z3950._tcp.gatech.edu.", "cid.urn.arpa.\t3600\tIN\tNAPTR\t100 50 \"s\" \"z3950+I2L+I2C\" \"\" _z3950._tcp.gatech.edu.",
// "cid.urn.arpa. NAPTR 100 50 \"s\" \"rcds+I2C\" \"\" _rcds._udp.gatech.edu.": "cid.urn.arpa. NAPTR 100 50 \"s\" \"rcds+I2C\" \"\" _rcds._udp.gatech.edu.":
// "cid.urn.arpa.\t3600\tIN\tNAPTR\t100 50 \"s\" \"rcds+I2C\" \"\" _rcds._udp.gatech.edu.", "cid.urn.arpa.\t3600\tIN\tNAPTR\t100 50 \"s\" \"rcds+I2C\" \"\" _rcds._udp.gatech.edu.",
// "cid.urn.arpa. NAPTR 100 50 \"s\" \"http+I2L+I2C+I2R\" \"\" _http._tcp.gatech.edu.": "cid.urn.arpa. NAPTR 100 50 \"s\" \"http+I2L+I2C+I2R\" \"\" _http._tcp.gatech.edu.":
// "cid.urn.arpa.\t3600\tN\tNAPTR\t100 50 \"s\" \"http+I2L+I2C+I2R\" \"\" _http._tcp.gatech.edu.", "cid.urn.arpa.\t3600\tIN\tNAPTR\t100 50 \"s\" \"http+I2L+I2C+I2R\" \"\" _http._tcp.gatech.edu.",
// "cid.urn.arpa. NAPTR 100 10 \"\" \"\" \"/urn:cid:.+@([^\\.]+\\.)(.*)$/\\2/i\" .": "cid.urn.arpa. NAPTR 100 10 \"\" \"\" \"/urn:cid:.+@([^\\.]+\\.)(.*)$/\\2/i\" .":
// "cid.urn.arpa.\t3600\tIN\tNAPTR\t100 10 \"\" \"\" \"/urn:cid:.+@([^\\.]+\\.)(.*)$/\\2/i\" .", "cid.urn.arpa.\t3600\tIN\tNAPTR\t100 10 \"\" \"\" \"/urn:cid:.+@([^\\.]+\\.)(.*)$/\\2/i\" .",
} }
for i, o := range tests { for i, o := range tests {
rr, e := NewRR(i) rr, e := NewRR(i)

View File

@ -350,7 +350,7 @@ func (l lex) String() string {
case _QUOTE: case _QUOTE:
return "\"" return "\""
case _NEWLINE: case _NEWLINE:
return "|\n" return "|"
case _RRTYPE: case _RRTYPE:
return "R:" + l.token + "$" return "R:" + l.token + "$"
case _OWNER: case _OWNER:
@ -360,7 +360,7 @@ func (l lex) String() string {
case _DIRTTL: case _DIRTTL:
return "T:" + l.token + "$" return "T:" + l.token + "$"
} }
return "" return "**"
} }
// zlexer scans the sourcefile and returns tokens on the channel c. // zlexer scans the sourcefile and returns tokens on the channel c.
@ -429,11 +429,11 @@ func zlexer(s scanner.Scanner, c chan lex) {
l.value = _CLASS l.value = _CLASS
} }
} }
// Space ALSO? // Space ALSO?
c <- l c <- l
} }
stri = 0 stri = 0
// I reverse space stuff here // I reverse space stuff here
if !space && !commt { if !space && !commt {
l.value = _BLANK l.value = _BLANK
l.token = " " l.token = " "
@ -456,9 +456,9 @@ func zlexer(s scanner.Scanner, c chan lex) {
} }
if stri > 0 { if stri > 0 {
l.value = _STRING l.value = _STRING
l.token = string(str[:stri]) l.token = string(str[:stri])
c <- l c <- l
stri = 0 stri = 0
} }
commt = true commt = true
case '\n': case '\n':
@ -486,9 +486,6 @@ func zlexer(s scanner.Scanner, c chan lex) {
break break
} }
if stri != 0 { if stri != 0 {
l.value = _BLANK
l.token = " "
c <- l
l.value = _STRING l.value = _STRING
l.token = string(str[:stri]) l.token = string(str[:stri])
if !rrtype { if !rrtype {
@ -497,8 +494,6 @@ func zlexer(s scanner.Scanner, c chan lex) {
rrtype = true rrtype = true
} }
} }
// I don't send a BLANK here
println("WAT HEB IK HIER", l.token, l.value)
c <- l c <- l
} }
if brace > 0 { if brace > 0 {
@ -544,8 +539,11 @@ func zlexer(s scanner.Scanner, c chan lex) {
escape = false escape = false
break break
} }
space = false
// send previous gathered text and the quote // send previous gathered text and the quote
if stri != 0 { if stri != 0 {
//komt best vaak langs
//println("DEBUG: SENDING PREV TEXT", string(str[:stri]))
l.value = _STRING l.value = _STRING
l.token = string(str[:stri]) l.token = string(str[:stri])
c <- l c <- l

View File

@ -327,7 +327,6 @@ func setNAPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
} else { } else {
rr.Preference = uint16(i) rr.Preference = uint16(i)
} }
// Following three are put between quotes
// Flags // Flags
<-c // _BLANK <-c // _BLANK
l = <-c // _QUOTE l = <-c // _QUOTE
@ -365,7 +364,6 @@ func setNAPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
} else { } else {
return nil, &ParseError{f, "bad NAPTR Service", l} return nil, &ParseError{f, "bad NAPTR Service", l}
} }
println("SERVICE", rr.Service)
// Regexp // Regexp
<-c // _BLANK <-c // _BLANK
@ -381,18 +379,14 @@ func setNAPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
return nil, &ParseError{f, "bad NAPTR Regexp", l} return nil, &ParseError{f, "bad NAPTR Regexp", l}
} }
} else if l.value == _QUOTE { } else if l.value == _QUOTE {
println("SETTING HERE")
rr.Regexp = "" rr.Regexp = ""
} else { } else {
return nil, &ParseError{f, "bad NAPTR Regexp", l} return nil, &ParseError{f, "bad NAPTR Regexp", l}
} }
println("REGEXP", rr.Regexp) // After quote no space??
<-c // _BLANK <-c // _BLANK
l = <-c // _STRING l = <-c // _STRING
rr.Replacement = l.token rr.Replacement = l.token
println("Replacement", l.token, "A")
println("Replacement", l.value, "A")
_, ld, ok := IsDomainName(l.token) _, ld, ok := IsDomainName(l.token)
if !ok { if !ok {
return nil, &ParseError{f, "bad NAPTR Replacement", l} return nil, &ParseError{f, "bad NAPTR Replacement", l}