28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/dns_one/zone_search.rb', line 28
def query dom_name, res_class, ip_address
return unless dom_name =~ Util::DOM_REGEX
dom_name = dom_name.dup
res_class_short = Util.last_mod res_class Global.logger.debug "request #{ dom_name }/#{res_class_short} from #{ip_address}..."
records = []
rec_set_name, from_cache = find_record_set dom_name
Global.logger.debug "domain #{ rec_set_name ? "found, rec_set_name = '#{rec_set_name}'" : 'not found' }"
return unless rec_set_name
rec_set_name = @conf.record_sets.to_h.keys.first if rec_set_name == ''
rec_set = @conf.record_sets[rec_set_name]
Global.logger.debug "record set #{ rec_set ? 'found' : 'not found' }"
return records unless rec_set
recs = rec_set[res_class_short.to_sym]
Global.logger.debug "record(s) #{ recs ? 'found' : 'not found' }"
recs = [recs]
recs.flatten! unless res_class == IN::SOA
recs.compact.each do |val_raw|
val = if res_class == IN::NS
Name.create val_raw
elsif res_class == IN::SOA
[0, 1].each{|i| val_raw[i] = Name.create val_raw[i] }
val_raw
else
val_raw
end
records << OpenStruct.new(val: val, res_class: res_class, section: 'answer')
end
[records, from_cache]
end
|