Fix URI record

When the URI record became an RFC they slightly changed the format.
Make the needed changes.
This commit is contained in:
Miek Gieben 2015-07-21 07:47:38 +01:00
parent 3825eda935
commit a34cf6798a
4 changed files with 31 additions and 29 deletions

View File

@ -125,7 +125,7 @@ Example programs can be found in the `github.com/miekg/exdns` repository.
* 6975 - Algorithm Understanding in DNSSEC
* 7043 - EUI48/EUI64 records
* 7314 - DNS (EDNS) EXPIRE Option
* xxxx - URI record (draft)
* 7553 - URI record
* xxxx - EDNS0 DNS Update Lease (draft)
## Loosely based upon
@ -138,7 +138,7 @@ Example programs can be found in the `github.com/miekg/exdns` repository.
## TODO
* privatekey.Precompute() when signing?
* Last remaining RRs: APL, ATMA, A6 and NXT and IPSECKEY;
* Missing in parsing: ISDN, UNSPEC, ATMA;
* NSEC(3) cover/match/closest enclose;
* Replies with TC bit are not parsed to the end;
* Last remaining RRs: APL, ATMA, A6 and NXT.
* Missing in parsing: ISDN, UNSPEC, ATMA.
* NSEC(3) cover/match/closest enclose.
* Replies with TC bit are not parsed to the end.

View File

@ -1477,3 +1477,21 @@ func TestParseCAA(t *testing.T) {
}
}
}
func TestParseURI(t *testing.T) {
lt := map[string]string{
"_http._tcp IN URI 10 1 \"http://www.example.com/path\"": "_http._tcp\t3600\tIN\tURI\t10 1 \"http://www.example.com/path\"",
}
for i, o := range lt {
rr, err := NewRR(i)
if err != nil {
t.Error("failed to parse RR: ", err)
continue
}
if rr.String() != o {
t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
} else {
t.Logf("RR is OK: `%s'", rr.String())
}
}
}

View File

@ -503,7 +503,7 @@ func sprintName(s string) string {
return string(dst)
}
func sprintCAAValue(s string) string {
func sprintTxtOctet(s string) string {
src := []byte(s)
dst := make([]byte, 0, len(src))
dst = append(dst, '"')
@ -1329,27 +1329,15 @@ type URI struct {
Hdr RR_Header
Priority uint16
Weight uint16
Target []string `dns:"txt"`
Target string `dns:"octet"`
}
func (rr *URI) Header() *RR_Header { return &rr.Hdr }
func (rr *URI) copy() RR {
cp := make([]string, len(rr.Target), cap(rr.Target))
copy(cp, rr.Target)
return &URI{*rr.Hdr.copyHeader(), rr.Weight, rr.Priority, cp}
}
func (rr *URI) copy() RR { return &URI{*rr.Hdr.copyHeader(), rr.Weight, rr.Priority, rr.Target} }
func (rr *URI) len() int { return rr.Hdr.len() + 4 + len(rr.Target) }
func (rr *URI) String() string {
return rr.Hdr.String() + strconv.Itoa(int(rr.Priority)) +
" " + strconv.Itoa(int(rr.Weight)) + sprintTxt(rr.Target)
}
func (rr *URI) len() int {
l := rr.Hdr.len() + 4
for _, t := range rr.Target {
l += len(t) + 1
}
return l
" " + strconv.Itoa(int(rr.Weight)) + sprintTxtOctet(rr.Target)
}
type DHCID struct {
@ -1571,7 +1559,7 @@ func (rr *CAA) Header() *RR_Header { return &rr.Hdr }
func (rr *CAA) copy() RR { return &CAA{*rr.Hdr.copyHeader(), rr.Flag, rr.Tag, rr.Value} }
func (rr *CAA) len() int { return rr.Hdr.len() + 1 + len(rr.Tag) + len(rr.Value)/2 }
func (rr *CAA) String() string {
return rr.Hdr.String() + strconv.Itoa(int(rr.Flag)) + " " + rr.Tag + " " + sprintCAAValue(rr.Value)
return rr.Hdr.String() + strconv.Itoa(int(rr.Flag)) + " " + rr.Tag + " " + sprintTxtOctet(rr.Value)
}
type UID struct {

View File

@ -1876,9 +1876,6 @@ func setURI(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
rr.Hdr = h
l := <-c
if l.length == 0 {
return rr, nil, l.comment
}
i, e := strconv.Atoi(l.token)
if e != nil {
return nil, &ParseError{f, "bad URI Priority", l}, ""
@ -1897,7 +1894,7 @@ func setURI(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
if e != nil {
return nil, e.(*ParseError), ""
}
rr.Target = s
rr.Target = s[0]
return rr, nil, c1
}
@ -2197,9 +2194,8 @@ func setCAA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
}
if len(s) > 1 {
return nil, &ParseError{f, "bad CAA Value", l}, ""
} else {
rr.Value = s[0]
}
rr.Value = s[0]
return rr, nil, c1
}