From 2f64868d3cf88168a48b5163d366f3ee1d6c4faa Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 13 Feb 2012 13:19:37 +0100 Subject: [PATCH] Add quotes to the parsing engine. Support: TXT NAPTR And other record that we may use. --- Makefile | 5 ++++- defaults.go | 5 +++++ parse_test.go | 32 ++++++++++++++++---------------- zscan.go | 20 +++++++++----------- zscan_rr.go | 8 +------- 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index b6158c2e..b41a865c 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/defaults.go b/defaults.go index 916afbb5..8015f5f3 100644 --- a/defaults.go +++ b/defaults.go @@ -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 diff --git a/parse_test.go b/parse_test.go index cd6c8ef1..2b59c861 100644 --- a/parse_test.go +++ b/parse_test.go @@ -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) diff --git a/zscan.go b/zscan.go index fb470ccf..10b4590b 100644 --- a/zscan.go +++ b/zscan.go @@ -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 diff --git a/zscan_rr.go b/zscan_rr.go index 6e423fd0..f02d6f09 100644 --- a/zscan_rr.go +++ b/zscan_rr.go @@ -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}