Module: DNS::Zone::RR
- Defined in:
- lib/dns/zone/rr.rb
Overview
The module containes resource record types supported by this gem. The #RR.load method will convert RR string data into a Ruby class.
Defined Under Namespace
Classes: A, AAAA, CDNSKEY, CDS, CNAME, DLV, DNSKEY, DS, HINFO, MX, NAPTR, NS, NSEC, NSEC3, NSEC3PARAM, PTR, RRSIG, Record, SOA, SPF, SRV, SSHFP, TXT
Constant Summary collapse
- REGEX_TTL =
/\d+[wdmhs]?/i
- REGEX_KLASS =
/(?<klass>IN)?/i
- REGEX_TYPE =
/(?<type>A|AAAA|CDNSKEY|CDS|CNAME|DLV|DNSKEY|DS|HINFO|MX|NAPTR|NS|NSEC|NSEC3|NSEC3PARAM|RRSIG|SOA|SPF|SRV|SSHFP|TXT|PTR)\s{1}/i
- REGEX_RR =
/^(?<label>\S+|\s{1})\s*(?<ttl>#{REGEX_TTL})?\s*#{REGEX_KLASS}\s*#{REGEX_TYPE}\s*(?<rdata>[\s\S]*)$/i
- REGEX_DOMAINNAME =
/\S+\.?/i
- REGEX_STRING =
/((?:[^"\\]+|\\.)*)/
- REGEX_CHARACTER_STRING =
%r{ "#{DNS::Zone::RR::REGEX_STRING}"|#{DNS::Zone::RR::REGEX_STRING} }mx
Class Method Summary collapse
-
.load(string, options = {}) ⇒ Object
Load RR string data and return an instance representing the RR.
Class Method Details
.load(string, options = {}) ⇒ Object
Load RR string data and return an instance representing the RR.
24 25 26 27 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 |
# File 'lib/dns/zone/rr.rb', line 24 def self.load(string, = {}) # strip comments, unless its escaped. # skip semicolons within "quote segments" (TXT records) string.gsub!(/((?<!\\);)(?=(?:[^"]|"[^"]*")*$).*/o, "") captures = string.match(REGEX_RR) return nil unless captures case captures[:type] when 'A' then A.new.load(string, ) when 'AAAA' then AAAA.new.load(string, ) when 'CDNSKEY' then CDNSKEY.new.load(string, ) when 'CDS' then CDS.new.load(string, ) when 'CNAME' then CNAME.new.load(string, ) when 'DLV' then DLV.new.load(string, ) when 'DNSKEY' then DNSKEY.new.load(string, ) when 'DS' then DS.new.load(string, ) when 'HINFO' then HINFO.new.load(string, ) when 'MX' then MX.new.load(string, ) when 'NAPTR' then NAPTR.new.load(string, ) when 'NS' then NS.new.load(string, ) when 'NSEC' then NSEC.new.load(string, ) when 'NSEC3' then NSEC3.new.load(string, ) when 'NSEC3PARAM' then NSEC3PARAM.new.load(string, ) when 'PTR' then PTR.new.load(string, ) when 'RRSIG' then RRSIG.new.load(string, ) when 'SOA' then SOA.new.load(string, ) when 'SPF' then SPF.new.load(string, ) when 'SRV' then SRV.new.load(string, ) when 'SSHFP' then SSHFP.new.load(string, ) when 'TXT' then TXT.new.load(string, ) else raise 'Unknown or unsupported RR Type' end end |