1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#--
#Copyright 2007 Nominet UK
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
#++
module Dnsruby
class RR
#Class for DNS Naming Authority Pointer (NAPTR) resource records.
#RFC 2168
class NAPTR < RR
ClassValue = nil #:nodoc: all
TypeValue= Types::NAPTR #:nodoc: all
# The NAPTR RR order field
attr_accessor :order
# The NAPTR RR preference field
attr_accessor :preference
# The NAPTR RR flags field
attr_accessor :flags
# The NAPTR RR service field
attr_accessor :service
# The NAPTR RR regexp field
attr_accessor :regexp
# The NAPTR RR replacement field
attr_accessor :replacement
def from_hash(hash) #:nodoc: all
@order = hash[:order]
@preference = hash[:preference]
@flags = hash[:flags]
@service = hash[:service]
@regexp = hash[:regexp]
@replacement = Name.create(hash[:replacement])
end
def from_data(data) #:nodoc: all
@order, @preference, @flags, @service, @regexp, @replacement = data
end
def regexp=(s)
@regexp = TXT.parse(s)[0]
end
def from_string(input) #:nodoc: all
if (input.length > 0)
values = input.split(" ")
@order = values [0].to_i
@preference = values [1].to_i
@flags = values [2].gsub!("\"", "")
@service = values [3].gsub!("\"", "")
@regexp = TXT.parse(values[4])[0]
@replacement = Name.create(values[5])
end
end
def rdata_to_string #:nodoc: all
if (@order!=nil)
ret = "#{@order} #{@preference} \"#{@flags}\" \"#{@service}\" \""
ret += TXT.display(@regexp)
ret += "\" #{@replacement.to_s(true)}"
return ret
else
return ""
end
end
def encode_rdata(msg, canonical=false) #:nodoc: all
msg.put_pack('n', @order)
msg.put_pack('n', @preference)
msg.put_string(@flags)
msg.put_string(@service)
msg.put_string(@regexp)
msg.put_name(@replacement, true)
end
def self.decode_rdata(msg) #:nodoc: all
order, = msg.get_unpack('n')
preference, = msg.get_unpack('n')
flags = msg.get_string
service = msg.get_string
regexp = msg.get_string
replacement = msg.get_name
return self.new([order, preference, flags, service, regexp, replacement])
end
end
end
end
|