Skip to content

Commit

Permalink
* lib/resolv.rb: don't complete domains for absolute FQNs.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2185 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
akr committed Mar 12, 2002
1 parent 9651a9d commit 230034b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Tue Mar 12 17:12:06 2002 Tanaka Akira <[email protected]>

* lib/resolv.rb: don't complete domains for absolute FQNs.

Mon Mar 11 23:08:48 2002 Tanaka Akira <[email protected]>

* lib/tsort.rb: new file.
Expand Down
61 changes: 31 additions & 30 deletions lib/resolv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
== example
Resolv.getaddress("www.ruby-lang.org")
Resolv.getname("210.251.121.214").to_s
Resolv.getname("210.251.121.214")
Resolv::DNS.new.getresources("www.ruby-lang.org", Resolv::DNS::Resource::IN::A).collect {|r| r.address}
Resolv::DNS.new.getresources("ruby-lang.org", Resolv::DNS::Resource::IN::MX).collect {|r| [r.exchange.to_s, r.preference]}
Expand Down Expand Up @@ -168,8 +168,9 @@
regular expression for IPv6 address.
== Bugs
NIS is not supported.
/etc/nsswitch.conf is not supported.
* NIS is not supported.
* /etc/nsswitch.conf is not supported.
* IPv6 is not supported.
=end

Expand Down Expand Up @@ -690,9 +691,9 @@ def lazy_initialize
when 'nameserver'
@nameserver += args
when 'domain'
@search = [args[0]]
@search = [Label.split(args[0])]
when 'search'
@search = args
@search = args.map {|arg| Label.split(arg)}
end
}
}
Expand All @@ -703,9 +704,9 @@ def lazy_initialize
unless @search
hostname = Socket.gethostname
if /\./ =~ hostname
@search = [$']
@search = [Label.split($')]
else
@search = ['']
@search = [[]]
end
end
@initialized = true
Expand All @@ -724,20 +725,17 @@ def single?

def generate_candidates(name)
candidates = nil
name = name.to_s if Name === name
if /\.\z/ =~ name
name = Name.create(name)
if name.absolute?
candidates = [name]
elsif @ndots <= name.tr('^.', '').length
candidates = [name, *@search.collect {|domain| name + '.' + domain}]
else
candidates = [*@search.collect {|domain| name + '.' + domain}]
end
candidates.collect! {|c|
c = c.dup
c.gsub!(/\.\.+/, '.')
c.chomp!('.')
c
}
else
if @ndots <= name.length - 1
candidates = [Name.new(name.to_a)]
else
candidates = []
end
candidates.concat(@search.map {|domain| Name.new(name.to_a + domain)})
end
return candidates
end

Expand Down Expand Up @@ -859,26 +857,28 @@ def self.create(arg)
when Name
return arg
when String
return Name.new(Label.split(arg))
return Name.new(Label.split(arg), /\.\z/ =~ arg ? true : false)
else
raise ArgumentError.new("cannot interprete as DNS name: #{arg.inspect}")
raise ArgumentError.new("cannot interpret as DNS name: #{arg.inspect}")
end
end

def initialize(labels)
def initialize(labels, absolute=true)
@labels = labels
@absolute = absolute
end

def ==(other)
return @labels == other.to_a
def absolute?
return @absolute
end

def eql?(other)
return self == other
def ==(other)
return @labels == other.to_a && @absolute == other.absolute?
end
alias eql? ==

def hash
return @labels.hash
return @labels.hash ^ @absolute.hash
end

def to_a
Expand Down Expand Up @@ -1532,8 +1532,8 @@ def inspect
end

def to_name
return DNS::Name.new(
@address.unpack("CCCC").reverse + ['in-addr', 'arpa'])
return DNS::Name.create(
'%d.%d.%d.%d.in-addr.arpa.' % @address.unpack('CCCC').reverse)
end

def ==(other)
Expand Down Expand Up @@ -1644,6 +1644,7 @@ def inspect
end

def to_name
# ip6.arpa should be searched too. [RFC3152]
return DNS::Name.new(
@address.unpack("H32")[0].split(//).reverse + ['ip6', 'int'])
end
Expand Down

0 comments on commit 230034b

Please sign in to comment.