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 \
chaos \
@ -10,3 +10,6 @@ EXAMPLES=mx \
ex:
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++
longer = 1
}
// Preloop check for root label
if s == "." {
return 0, 1, true
}
last := byte('.')
ok := false // ok once we've seen a letter
partlen := 0

View File

@ -199,24 +199,24 @@ func TestParseNSEC(t *testing.T) {
func TestQuotes(t *testing.T) {
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\n bc\"",
// `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 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`: "t.example.com.\t3600\tIN\tTXT\t\"aaa\"",
`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\n bc\"",
`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 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`: "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.\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.\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.\t3600\tN\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.\t3600\tIN\tNAPTR\t100 10 \"\" \"\" \"/urn:cid:.+@([^\\.]+\\.)(.*)$/\\2/i\" .",
"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. NAPTR 100 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.\t3600\tIN\tNAPTR\t100 10 \"\" \"\" \"/urn:cid:.+@([^\\.]+\\.)(.*)$/\\2/i\" .",
}
for i, o := range tests {
rr, e := NewRR(i)

View File

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

View File

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