lib/net/dns/rr/hinfo.rb in net-dns-0.6.1 vs lib/net/dns/rr/hinfo.rb in net-dns-0.7.0
- old
+ new
@@ -1,68 +1,108 @@
-module Net
+module Net # :nodoc:
module DNS
class RR
-
- #------------------------------------------------------------
- # RR type HINFO
- #------------------------------------------------------------
+
+ #
+ # = System Information Record (HINFO)
+ #
+ # Class for DNS HINFO resource records.
+ #
+ # Allows definition of the Hardware type and Operating System (OS) in use at a host.
+ # For security reasons these records are rarely used on public servers.
+ # If a space exists in the field it must be enclosed in quotes.
+ # Single space between CPU and OS parameters.
+ #
class HINFO < RR
- attr_reader :cpu, :os
- private
-
- def check_hinfo(str)
- if str.strip =~ /^["'](.*?)["']\s+["'](.*?)["']$/
- return $1,$2
- else
- raise ArgumentError, "HINFO section not valid: #{str.inspect}"
- end
+ # Gets the CPU value.
+ #
+ # Returns a String.
+ def cpu
+ @cpu
end
-
- def build_pack
- @hinfo_pack = [@cpu.size].pack("C") + @cpu
- @hinfo_pack += [@os.size].pack("C") + @os
- @rdlength = @hinfo_pack.size
- end
- def get_data
- @hinfo_pack
+ # Gets the OS value.
+ #
+ # Returns a String.
+ def os
+ @os
end
- def get_inspect
- "#@cpu #@os"
+ # Gets the standardized value for this record,
+ # represented by the value of <tt>cpu</tt> and <tt>os</tt>.
+ #
+ # Returns a String.
+ def value
+ %Q{"#{cpu}" "#{os}"}
end
- def subclass_new_from_hash(args)
- if args.has_key? :cpu and args.has_key? :os
- @cpu = args[:cpu]
- @os = args[:os]
- else
- raise ArgumentError, ":cpu and :os fields are mandatory but missing"
- end
- end
- def subclass_new_from_string(str)
- @cpu,@os = check_hinfo(str)
+ # Gets a list of all the attributes for this record.
+ #
+ # Returns an Array of values.
+ def to_a
+ [nil, nil, cls.to_s, type.to_s, value]
end
- def subclass_new_from_binary(data,offset)
- len = data.unpack("@#{offset} C")[0]
- @cpu = data[offset+1..offset+1+len]
- offset += len+1
- len = @data.unpack("@#{offset} C")[0]
- @os = data[offset+1..offset+1+len]
- return offset += len+1
- end
-
+
private
-
+
+ def subclass_new_from_hash(options)
+ if options.has_key?(:cpu) && options.has_key?(:os)
+ @cpu = options[:cpu]
+ @os = options[:os]
+ else
+ raise ArgumentError, ":cpu and :os fields are mandatory"
+ end
+ end
+
+ def subclass_new_from_string(str)
+ @cpu, @os = check_hinfo(str)
+ end
+
+ def subclass_new_from_binary(data, offset)
+ len = data.unpack("@#{offset} C").first
+ offset += 1
+ @cpu = data[offset..(offset + len)]
+ offset += len
+
+ len = data.unpack("@#{offset} C").first
+ offset += 1
+ @os = data[offset..(offset + len)]
+ offset += len
+ end
+
+
def set_type
@type = Net::DNS::RR::Types.new("HINFO")
end
-
- end # class HINFO
-
- end # class RR
- end # module DNS
-end # module Net
+ def get_inspect
+ value
+ end
+
+
+ def check_hinfo(input)
+ if input.to_s.strip =~ /^(?:["']?(.*?)["']?)\s+(?:["']?(.*?)["']?)$/
+ [$1, $2]
+ else
+ raise ArgumentError, "Invalid HINFO Section `#{input}'"
+ end
+ end
+
+ def build_pack
+ @hinfo_pack = ""
+ @hinfo_pack += [cpu.size].pack("C") + cpu
+ @hinfo_pack += [os.size ].pack("C") + os
+ @rdlength = @hinfo_pack.size
+ end
+
+ def get_data
+ @hinfo_pack
+ end
+
+ end
+
+ end
+ end
+end