Fix LOC parsing

This commit is contained in:
Miek Gieben 2012-05-01 22:21:44 +02:00
parent d30dcf93e0
commit 79ea0f8e31
3 changed files with 15 additions and 9 deletions

View File

@ -255,8 +255,8 @@ func TestParseLOC(t *testing.T) {
lt := map[string]string{
"SW1A2AA.find.me.uk. LOC 51 30 12.748 N 00 07 39.611 W 0.00m 0.00m 0.00m 0.00m":
"SW1A2AA.find.me.uk.\t3600\tIN\tLOC\t51 30 12.748 N 00 07 39.611 W 0.00m 0.00m 0.00m 0.00m",
// "SW1A2AA.find.me.uk. LOC 51 0 0.0 N 00 07 39.611 W 0.00m 0.00m 0.00m 0.00m":
// "SW1A2AA.find.me.uk.\t3600\tIN\tLOC\t51 0 0.0 N 00 07 39.611 W 0.00m 0.00m 0.00m 0.00m",
"SW1A2AA.find.me.uk. LOC 51 0 0.0 N 00 07 39.611 W 0.00m 0.00m 0.00m 0.00m":
"SW1A2AA.find.me.uk.\t3600\tIN\tLOC\t51 0 0.0 N 00 07 39.611 W 0.00m 0.00m 0.00m 0.00m",
}
for i, o := range lt {
rr, e := NewRR(i)

View File

@ -739,15 +739,18 @@ func stringToCm(token string) (e, m uint8, ok bool) {
var meters, cmeters, val int
var err error
switch len(s) {
case 1:
case 2:
if cmeters, err = strconv.Atoi(s[1]); err != nil {
return
}
fallthrough
case 0:
case 1:
if meters, err = strconv.Atoi(s[0]); err != nil {
return
}
case 0:
// huh?
return 0, 0, false
}
ok = true
if meters > 0 {

View File

@ -422,16 +422,19 @@ func setTALINK(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
}
func setLOC(h RR_Header, c chan lex, f string) (RR, *ParseError) {
// Defaults TODO(mg)
rr := new(RR_LOC)
rr.Hdr = h
// Non zero defaults for LOC record, see RFC 1876, Section 3.
rr.HorizPre = 165 // 10000
rr.VertPre = 162 // 10
rr.Size = 18 // 1
ok := false
// North
l := <-c
if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{f, "bad LOC Latitude", l}
} else {
rr.Latitude = 1000 * uint32(i)
rr.Latitude = 1000 * 60 * 60 * uint32(i)
}
<-c // _BLANK
// Either number, 'N' or 'S'
@ -449,7 +452,7 @@ func setLOC(h RR_Header, c chan lex, f string) (RR, *ParseError) {
if i, e := strconv.ParseFloat(l.token, 32); e != nil {
return nil, &ParseError{f, "bad LOC Latitude seconds", l}
} else {
rr.Latitude += uint32(1000 * 60 * 60 * i)
rr.Latitude += uint32(1000 * i)
}
<-c // _BLANK
// Either number, 'N' or 'S'
@ -467,7 +470,7 @@ East:
if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{f, "bad LOC Longitude", l}
} else {
rr.Longitude = uint32(1000.0 * i) // +0.0005 in ldns?
rr.Longitude = 1000 * 60 * 60 * uint32(i)
}
<-c // _BLANK
// Either number, 'E' or 'W'
@ -485,7 +488,7 @@ East:
if i, e := strconv.ParseFloat(l.token, 32); e != nil {
return nil, &ParseError{f, "bad LOC Longitude seconds", l}
} else {
rr.Longitude += uint32(1000 * 60 * 60 * i)
rr.Longitude += uint32(1000 * i)
}
<-c // _BLANK
// Either number, 'E' or 'W'