aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-08-05 14:28:55 +0700
committerShulhan <ms@kilabit.info>2023-08-05 14:28:55 +0700
commitbd2ae82e254e203a021c9907e41b41ec0643ad49 (patch)
tree4acf0ad705ed44b36da1a240b0bd83d51a8a8adc /lib
parent75d59dff238b78076ca8c7f12fc660e6e75da288 (diff)
downloadpakakeh.go-bd2ae82e254e203a021c9907e41b41ec0643ad49.tar.xz
lib/dns: directly use the map RecordClasses and RecordTypes
Previously, to check if string value is valid record class or type, we use a function that iterate each map key and return a boolean. This changes simplify it by getting the map RecordClasses and RecordTypes value directly.
Diffstat (limited to 'lib')
-rw-r--r--lib/dns/zone_parser.go48
1 files changed, 8 insertions, 40 deletions
diff --git a/lib/dns/zone_parser.go b/lib/dns/zone_parser.go
index adab37b0..bd40a328 100644
--- a/lib/dns/zone_parser.go
+++ b/lib/dns/zone_parser.go
@@ -452,7 +452,7 @@ func (m *zoneParser) parseRR(prevRR *ResourceRecord, tok []byte) (rr *ResourceRe
fallthrough // If its not digit maybe type.
case flagRRTtl | flagRRClass:
- ok = m.parseRRType(rr, stok)
+ rr.Type, ok = RecordTypes[stok]
if !ok {
return nil, fmt.Errorf(`%s: line %d: unknown class or type '%s'`, logp, m.lineno, stok)
}
@@ -474,56 +474,24 @@ func (m *zoneParser) parseRR(prevRR *ResourceRecord, tok []byte) (rr *ResourceRe
func (m *zoneParser) parseRRClassOrType(rr *ResourceRecord, stok string, flag int) (int, bool) {
var ok bool
- ok = m.parseRRClass(rr, stok)
+ rr.Class, ok = RecordClasses[stok]
if ok {
flag |= flagRRClass
- return flag, true
+ return flag, ok
}
- ok = m.parseRRType(rr, stok)
+ // Set back to default class.
+ rr.Class = RecordClassIN
+
+ rr.Type, ok = RecordTypes[stok]
if ok {
flag = flagRRType
- return flag, true
+ return flag, ok
}
return flag, false
}
-// parseRRClass check if token is known class.
-// It will set the rr.Class and return true if stok is one of known class;
-// otherwise it will return false.
-func (m *zoneParser) parseRRClass(rr *ResourceRecord, stok string) bool {
- var (
- k string
- v RecordClass
- )
-
- for k, v = range RecordClasses {
- if stok == k {
- rr.Class = v
- return true
- }
- }
- return false
-}
-
-// parseRRType check if token is one of known query type.
-// It will set rr.Type and return true if token found, otherwise it will
-// return false.
-func (m *zoneParser) parseRRType(rr *ResourceRecord, stok string) bool {
- var (
- k string
- v RecordType
- )
- for k, v = range RecordTypes {
- if stok == k {
- rr.Type = v
- return true
- }
- }
- return false
-}
-
func (m *zoneParser) parseRRData(rr *ResourceRecord, tok []byte, c byte) (err error) {
switch rr.Type {
case RecordTypeA, RecordTypeAAAA: