Class: Latte::Response::RecordParser
Instance Method Summary collapse
- #encode_name(name) ⇒ Object
- #encoded_qclass ⇒ Object
- #encoded_qname ⇒ Object
- #encoded_qtype ⇒ Object
- #encoded_rdata ⇒ Object
- #execute ⇒ Object
- #parts ⇒ Object
- #qclass ⇒ Object
-
#qname ⇒ Object
QTYPE codes: A 1 a host address NS 2 an authoritative name server MD 3 a mail destination (Obsolete - use MX) MF 4 a mail forwarder (Obsolete - use MX) CNAME 5 the canonical name for an alias SOA 6 marks the start of a zone of authority MB 7 a mailbox domain name (EXPERIMENTAL) MG 8 a mail group member (EXPERIMENTAL) MR 9 a mail rename domain name (EXPERIMENTAL) NULL 10 a null RR (EXPERIMENTAL) WKS 11 a well known service description PTR 12 a domain name pointer HINFO 13 host information MINFO 14 mailbox or mail list information MX 15 mail exchange TXT 16 text strings.
- #qtype ⇒ Object
- #rdata ⇒ Object
- #ttl ⇒ Object
Instance Method Details
#encode_name(name) ⇒ Object
134 135 136 137 138 139 |
# File 'lib/latte/response.rb', line 134 def encode_name name parts = name.split /\./ parts.map! { |p| BinData::Uint8.new(p.length).to_binary_s + p } parts << BinData::Uint8.new(0).to_binary_s parts.join '' end |
#encoded_qclass ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/latte/response.rb', line 100 def encoded_qclass { 'IN' => 1, 'CH' => 3, 'HS' => 4 }[qclass] end |
#encoded_qname ⇒ Object
141 142 143 |
# File 'lib/latte/response.rb', line 141 def encoded_qname encode_name qname end |
#encoded_qtype ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/latte/response.rb', line 112 def encoded_qtype { 'A' => 1, 'NS' => 2, 'CNAME' => 5, 'SOA' => 6, 'PTR' => 12, 'HINFO' => 13, 'MINFO' => 14, 'MX' => 15, 'TXT' => 16 }[qtype] end |
#encoded_rdata ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/latte/response.rb', line 145 def encoded_rdata # FIXME: Extract this case statment into separate encoders case qtype when 'A', 'PTR' parts = rdata.split /\./ parts.map! { |o| BinData::Uint8.new(o.to_i).to_binary_s } parts.join '' when 'NS', 'CNAME' encode_name rdata else raise "I don't know how to encode QTYPE #{qtype.inspect}" end end |
#execute ⇒ Object
167 168 169 170 171 172 173 174 175 |
# File 'lib/latte/response.rb', line 167 def execute self.record = Answer.new.tap { |a| a.qname = encoded_qname a.qtype = encoded_qtype a.qclass = encoded_qclass a.ttl = ttl a.rdata = encoded_rdata } end |
#parts ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/latte/response.rb', line 159 def parts string = record_string.dup string.strip! parts = string.split /\s+/, 5 parts.map! { |p| p.strip } parts end |
#qclass ⇒ Object
96 97 98 |
# File 'lib/latte/response.rb', line 96 def qclass parts[1] end |
#qname ⇒ Object
QTYPE codes: A 1 a host address NS 2 an authoritative name server MD 3 a mail destination (Obsolete - use MX) MF 4 a mail forwarder (Obsolete - use MX) CNAME 5 the canonical name for an alias SOA 6 marks the start of a zone of authority MB 7 a mailbox domain name (EXPERIMENTAL) MG 8 a mail group member (EXPERIMENTAL) MR 9 a mail rename domain name (EXPERIMENTAL) NULL 10 a null RR (EXPERIMENTAL) WKS 11 a well known service description PTR 12 a domain name pointer HINFO 13 host information MINFO 14 mailbox or mail list information MX 15 mail exchange TXT 16 text strings
92 93 94 |
# File 'lib/latte/response.rb', line 92 def qname parts[0] end |
#qtype ⇒ Object
108 109 110 |
# File 'lib/latte/response.rb', line 108 def qtype parts[2] end |
#rdata ⇒ Object
130 131 132 |
# File 'lib/latte/response.rb', line 130 def rdata parts[4] end |
#ttl ⇒ Object
126 127 128 |
# File 'lib/latte/response.rb', line 126 def ttl parts[3].to_i end |