Parent

Namespace

Included Modules

Class Index [+]

Quicksearch

Dnsruby::Name

Dnsruby::Name class

A representation of a DNS name (RFC1035, section 3.1)

methods

Constants

MaxNameLength

Attributes

labels[RW]

Public Class Methods

create(arg) click to toggle source

Creates a new Dnsruby::Name from arg. arg can be :

  • Name

    returns arg

  • String

    returns a new Name

    # File lib/Dnsruby/name.rb, line 43
43:     def self.create(arg)
44:       case arg
45:       when Name
46:         return Name.new(arg.labels, arg.absolute?)
47:       when String
48:         #        arg.gsub!(/\.$/o, "")
49:         if (arg==".")
50:           return Name.new([],true)
51:         end
52:         if (arg=="")
53:           return Name.new([],false)
54:         end
55:         return Name.new(split_escaped(arg), /\.\z/ =~ arg ? true : false)
56:         #        return Name.new(Label.split(arg), /\.\z/ =~ arg ? true : false)
57:       when Array
58:         return Name.new(arg, /\.\z/ =~ (arg.last ? ((arg.last.kind_of?String)?arg.last : arg.last.string) : arg.last) ? true : false)
59:       else        
60:         raise ArgumentError.new("cannot interpret as DNS name: #{arg.inspect}")
61:       end
62:     end
split(name) click to toggle source
    # File lib/Dnsruby/name.rb, line 69
69:     def self.split(name)
70:       encodedlabels = name2encodedlabels(name)
71:       labels = encodedlabels.each  {|el| Name.decode(el.to_s)}
72:       return labels
73:     end

Public Instance Methods

<=>(other) click to toggle source
     # File lib/Dnsruby/name.rb, line 135
135:     def <=>(other)
136:       # return -1 if other less than us, +1 if greater than us
137:       return 0 if (canonical == other.canonical)
138:       if (canonically_before(other))
139:         return 1
140:       end
141:       return 1
142:     end
absolute?() click to toggle source

Returns true if this Name is absolute

     # File lib/Dnsruby/name.rb, line 105
105:     def absolute?
106:       return @absolute
107:     end
canonical() click to toggle source

Return the canonical form of this name (RFC 4034 section 6.2)

     # File lib/Dnsruby/name.rb, line 127
127:     def canonical
128:       #
129:       return MessageEncoder.new {|msg|
130:         msg.put_name(self, true)
131:       }.to_s
132: 
133:     end
canonically_before(n) click to toggle source
     # File lib/Dnsruby/name.rb, line 144
144:     def canonically_before(n)
145:       if (!(Name === n))
146:         n = Name.create(n)
147:       end
148:       # Work out whether this name is canonically before the passed Name
149:       # RFC 4034 section 6.1
150:       # For the purposes of DNS security, owner names are ordered by treating
151:       #individual labels as unsigned left-justified octet strings.  The
152:       #absence of a octet sorts before a zero value octet, and uppercase
153:       #US-ASCII letters are treated as if they were lowercase US-ASCII
154:       #letters.
155:       #To compute the canonical ordering of a set of DNS names, start by
156:       #sorting the names according to their most significant (rightmost)
157:       #labels.  For names in which the most significant label is identical,
158:       #continue sorting according to their next most significant label, and
159:       #so forth.
160: 
161:       # Get the list of labels for both names, and then swap them
162:       my_labels = @labels.reverse
163:       other_labels = n.labels.reverse
164:       my_labels.each_index {|i|
165:         if (!other_labels[i])
166:           return false
167:         end
168:         next if (other_labels[i].downcase == my_labels[i].downcase)
169:         return (my_labels[i].downcase < other_labels[i].downcase)
170:       }
171:       return true
172:     end
downcase() click to toggle source
    # File lib/Dnsruby/name.rb, line 94
94:     def downcase
95:       labels = []
96:       @labels.each do |label| labels << Label.new(label.downcase) end
97:       return Name.new(labels)
98:     end
subdomain_of?(other) click to toggle source

Tests subdomain-of relation : returns true if this name is a subdomain of other.

  domain = Resolv::Name.create("y.z")
  p Resolv::Name.create("w.x.y.z").subdomain_of?(domain) #=> true
  p Resolv::Name.create("x.y.z").subdomain_of?(domain) #=> true
  p Resolv::Name.create("y.z").subdomain_of?(domain) #=> false
  p Resolv::Name.create("z").subdomain_of?(domain) #=> false
  p Resolv::Name.create("x.y.z.").subdomain_of?(domain) #=> false
  p Resolv::Name.create("w.z").subdomain_of?(domain) #=> false
     # File lib/Dnsruby/name.rb, line 190
190:     def subdomain_of?(other)
191:       raise ArgumentError, "not a domain name: #{other.inspect}" unless Name === other
192:       return false if @absolute != other.absolute?
193:       other_len = other.length
194:       return false if @labels.length <= other_len
195:       return @labels[-other_len, other_len] == other.to_a
196:     end
to_s(include_absolute=false) click to toggle source

returns the domain name as a string.

The domain name doesn’t have a trailing dot even if the name object is absolute.

Example :

  p Resolv::Name.create("x.y.z.").to_s #=> "x.y.z"
  p Resolv::Name.create("x.y.z").to_s #=> "x.y.z"
     # File lib/Dnsruby/name.rb, line 224
224:     def to_s(include_absolute=false)
225:       ret = to_str(@labels)
226:       if (@absolute && include_absolute)
227:         ret += "."
228:       end
229:       return ret
230:     end
wild?() click to toggle source

Is this name a wildcard?

     # File lib/Dnsruby/name.rb, line 119
119:     def wild?
120:       if (labels.length == 0)
121:         return false
122:       end
123:       return (labels[0].string == '*')
124:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.