First chunk in parsing LOC RRs
This commit is contained in:
parent
0940f549bf
commit
b50e3f690e
8
types.go
8
types.go
|
@ -618,9 +618,9 @@ func (rr *RR_LOC) String() string {
|
||||||
} else {
|
} else {
|
||||||
s += fmt.Sprintf("%.0fm ", float64(s1))
|
s += fmt.Sprintf("%.0fm ", float64(s1))
|
||||||
}
|
}
|
||||||
s += locCM((rr.Size&0xf0)>>4, rr.Size&0x0f) + "m "
|
s += cmToString((rr.Size&0xf0)>>4, rr.Size&0x0f) + "m "
|
||||||
s += locCM((rr.HorizPre&0xf0)>>4, rr.HorizPre&0x0f) + "m "
|
s += cmToString((rr.HorizPre&0xf0)>>4, rr.HorizPre&0x0f) + "m "
|
||||||
s += locCM((rr.VertPre&0xf0)>>4, rr.VertPre&0x0f) + "m"
|
s += cmToString((rr.VertPre&0xf0)>>4, rr.VertPre&0x0f) + "m"
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1109,7 +1109,7 @@ func saltString(s string) string {
|
||||||
return strings.ToUpper(s)
|
return strings.ToUpper(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func locCM(mantissa, exponent uint8) string {
|
func cmToString(mantissa, exponent uint8) string {
|
||||||
switch exponent {
|
switch exponent {
|
||||||
case 0, 1:
|
case 0, 1:
|
||||||
if exponent == 1 {
|
if exponent == 1 {
|
||||||
|
|
52
zscan.go
52
zscan.go
|
@ -210,7 +210,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
|
||||||
// Discard, can happen when there is nothing on the
|
// Discard, can happen when there is nothing on the
|
||||||
// line except the RR type
|
// line except the RR type
|
||||||
case _STRING: // First thing on the is the ttl
|
case _STRING: // First thing on the is the ttl
|
||||||
if ttl, ok := stringToTtl(l, f); !ok {
|
if ttl, ok := stringToTtl(l.token); !ok {
|
||||||
t <- Token{Error: &ParseError{f, "not a TTL", l}}
|
t <- Token{Error: &ParseError{f, "not a TTL", l}}
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
@ -264,7 +264,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
|
||||||
t <- Token{Error: e}
|
t <- Token{Error: e}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ttl, ok := stringToTtl(l, f); !ok {
|
if ttl, ok := stringToTtl(l.token); !ok {
|
||||||
t <- Token{Error: &ParseError{f, "expecting $TTL value, not this...", l}}
|
t <- Token{Error: &ParseError{f, "expecting $TTL value, not this...", l}}
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
@ -310,7 +310,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
|
||||||
h.Class = l.torc
|
h.Class = l.torc
|
||||||
st = _EXPECT_ANY_NOCLASS_BL
|
st = _EXPECT_ANY_NOCLASS_BL
|
||||||
case _STRING: // TTL is this case
|
case _STRING: // TTL is this case
|
||||||
if ttl, ok := stringToTtl(l, f); !ok {
|
if ttl, ok := stringToTtl(l.token); !ok {
|
||||||
t <- Token{Error: &ParseError{f, "not a TTL", l}}
|
t <- Token{Error: &ParseError{f, "not a TTL", l}}
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
@ -349,7 +349,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
|
||||||
case _EXPECT_ANY_NOCLASS:
|
case _EXPECT_ANY_NOCLASS:
|
||||||
switch l.value {
|
switch l.value {
|
||||||
case _STRING: // TTL
|
case _STRING: // TTL
|
||||||
if ttl, ok := stringToTtl(l, f); !ok {
|
if ttl, ok := stringToTtl(l.token); !ok {
|
||||||
t <- Token{Error: &ParseError{f, "not a TTL", l}}
|
t <- Token{Error: &ParseError{f, "not a TTL", l}}
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
@ -698,10 +698,10 @@ func typeToInt(token string) (uint16, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse things like 2w, 2m, etc, Return the time in seconds.
|
// Parse things like 2w, 2m, etc, Return the time in seconds.
|
||||||
func stringToTtl(l lex, f string) (uint32, bool) {
|
func stringToTtl(token string) (uint32, bool) {
|
||||||
s := uint32(0)
|
s := uint32(0)
|
||||||
i := uint32(0)
|
i := uint32(0)
|
||||||
for _, c := range l.token {
|
for _, c := range token {
|
||||||
switch c {
|
switch c {
|
||||||
case 's', 'S':
|
case 's', 'S':
|
||||||
s += i
|
s += i
|
||||||
|
@ -728,6 +728,46 @@ func stringToTtl(l lex, f string) (uint32, bool) {
|
||||||
return s + i, true
|
return s + i, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse LOC records' <digits>[.<digits>][mM] into a
|
||||||
|
// mantissa exponent format. Token should contain the entire
|
||||||
|
// string (i.e. no spaces allowed)
|
||||||
|
func stringToCm(token string) (e, m uint8, ok bool) {
|
||||||
|
if token[len(token)-1] == 'M' || token[len(token)-1] == 'm' {
|
||||||
|
token = token[0 : len(token)-1]
|
||||||
|
}
|
||||||
|
s := strings.SplitN(token, ".", 2)
|
||||||
|
var meters, cmeters, val int
|
||||||
|
var err error
|
||||||
|
switch len(s) {
|
||||||
|
case 1:
|
||||||
|
if cmeters, err = strconv.Atoi(s[1]); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fallthrough
|
||||||
|
case 0:
|
||||||
|
if meters, err = strconv.Atoi(s[0]); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ok = true
|
||||||
|
if meters > 0 {
|
||||||
|
e = 2
|
||||||
|
val = meters
|
||||||
|
} else {
|
||||||
|
e = 0
|
||||||
|
val = cmeters
|
||||||
|
}
|
||||||
|
for val > 10 {
|
||||||
|
e++
|
||||||
|
val /= 10
|
||||||
|
}
|
||||||
|
if e > 9 {
|
||||||
|
ok = false
|
||||||
|
}
|
||||||
|
m = uint8(val)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func appendOrigin(name, origin string) string {
|
func appendOrigin(name, origin string) string {
|
||||||
if origin == "." {
|
if origin == "." {
|
||||||
return name + origin
|
return name + origin
|
||||||
|
|
|
@ -245,7 +245,7 @@ func setSOA(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
|
||||||
// Serial should be a number
|
// Serial should be a number
|
||||||
return nil, &ParseError{f, "bad SOA zone parameter", l}
|
return nil, &ParseError{f, "bad SOA zone parameter", l}
|
||||||
}
|
}
|
||||||
if v, ok = stringToTtl(l, f); !ok {
|
if v, ok = stringToTtl(l.token); !ok {
|
||||||
return nil, &ParseError{f, "bad SOA zone parameter", l}
|
return nil, &ParseError{f, "bad SOA zone parameter", l}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue