class Dnsruby::Config

Description

The Config class determines the system configuration for DNS.
In particular, it determines the nameserver to target queries to.

It also specifies whether and how the search list and default 
domain should be applied to queries, according to the following
algorithm :
The Config class has now been modified for lazy loading. Previously, the config
was loaded when a Resolver was instantiated. Now, the config is only loaded if
a query is performed (or a config parameter requested on) a Resolver which has
not yet been configured.

Attributes

apply_domain[RW]

Should the default domain be applied?

apply_search_list[RW]

Should the search list be applied?

Public Class Methods

new() click to toggle source

Create a new Config with system default values

# File lib/Dnsruby/Config.rb, line 84
def initialize()
  @mutex = Mutex.new
  @configured = false
  #      parse_config

end
reset() click to toggle source

Reset the config to default values

# File lib/Dnsruby/Config.rb, line 90
def Config.reset
  c = Config.new
  @configured = false
  #      c.parse_config

end

Public Instance Methods

add_nameserver(ns) click to toggle source

Add a nameserver to the list of nameservers.

Can take either a single String or an array of Strings. The new nameservers are added at a higher priority.

# File lib/Dnsruby/Config.rb, line 217
def add_nameserver(ns)
  @configured = true
  if (ns.kind_of?String) 
    ns=[ns]
  end
  check_ns(ns)
  ns.reverse_each do |n|
    if (!@nameserver.include?(n))
      self.nameserver=[n]+@nameserver
    end
  end
end
domain() click to toggle source

Return the default domain

# File lib/Dnsruby/Config.rb, line 402
def domain
  if (!@configured)
    parse_config
  end
  if (@domain==nil)
    return nil
  end
  return Name.create(@domain).to_s
end
domain=(dom) click to toggle source

Set the default domain

# File lib/Dnsruby/Config.rb, line 141
def domain=(dom)
  #      @configured = true

  if (dom)
    if !dom.kind_of?(String)
      raise ArgumentError.new("invalid domain config: #{@domain.inspect}")
    end
    @domain = Name::split(dom)
  else
    @domain=nil
  end
end
get_ready() click to toggle source
# File lib/Dnsruby/Config.rb, line 420
def get_ready
  if (!@configured)
    parse_config
  end
end
nameserver() click to toggle source

The list of nameservers to query

# File lib/Dnsruby/Config.rb, line 49
def nameserver
  if (!@configured)
    parse_config
  end
  return @nameserver
end
nameserver=(ns) click to toggle source

Set the config to point to a single nameserver

# File lib/Dnsruby/Config.rb, line 231
def nameserver=(ns)
  @configured = true
  check_ns(ns)
  #      @nameserver = ['0.0.0.0'] if (@nameserver.class != Array || @nameserver.empty?)

  # Now go through and ensure that all ns point to IP addresses, not domain names

  @nameserver=ns
  Dnsruby.log.debug{"Nameservers = #{@nameserver.join(", ")}"}
end
ndots() click to toggle source

The minimum number of labels in the query name (if it is not absolute) before it is considered complete

# File lib/Dnsruby/Config.rb, line 60
def ndots
  if (!@configured)
    parse_config
  end
  return @ndots
end
ndots=(nd) click to toggle source

Set ndots

# File lib/Dnsruby/Config.rb, line 154
def ndots=(nd)
  @configured = true
  @ndots=nd
  if !@ndots.kind_of?(Integer)
    raise ArgumentError.new("invalid ndots config: #{@ndots.inspect}")
  end
end
search=(s) click to toggle source

Set the default search path

# File lib/Dnsruby/Config.rb, line 163
def search=(s)
  @configured = true
  @search=s
  if @search
    if @search.class == Array
      @search = @search.map {|arg| Name::split(arg) }
    else
      raise ArgumentError.new("invalid search config: search must be an array!")
    end
  else
    hostname = Socket.gethostname
    if /\./ =~ hostname
      @search = [Name.split($')]
    else
      @search = [[]]
    end
  end
  
  if !@search.kind_of?(Array) ||
      #              !@search.all? {|ls| ls.all? {|l| Label::Str === l } }

    !@search.all? {|ls| ls.all? {|l| Name::Label === l } }
    raise ArgumentError.new("invalid search config: #{@search.inspect}")
  end
end
set_config_info(config_info) click to toggle source

Set the config. Parameter can be :

  • A String containing the name of the config file to load

    e.g. /etc/resolv.conf
  • A hash with the following elements :

    nameserver (String)
    domain (String)
    search (String)
    ndots (Fixnum)

This method should not normally be called by client code.

# File lib/Dnsruby/Config.rb, line 79
def set_config_info(config_info)
  parse_config(config_info)
end
to_s() click to toggle source
# File lib/Dnsruby/Config.rb, line 347
def to_s
  if (!@configured)
    parse_config
  end
  ret = "Config - nameservers : "
  @nameserver.each {|n| ret += n.to_s + ", "}
  domain_string="empty"
  if (@domain!=nil)
    domain_string=@domain.to_s
  end
  ret += " domain : #{domain_string}, search : "
  search.each {|s| ret += s + ", " }
  ret += " ndots : #{@ndots}"
  return ret
end