Class: Dnsruby::Config

### Home Classes Methods

### In Files

- lib/Dnsruby/Config.rb

### Parent

Object

### Methods

- ::new
- ::reset
- #add_nameserver
- #domain
- #domain=
- #get_ready
- #nameserver
- #nameserver=
- #ndots
- #ndots=
- #search
- #search=
- #set_config_info
- #to_s

### Files

- DNSSEC
- EVENTMACHINE
- EXAMPLES
- README

### Class/Module Index

Quicksearch

- Dnsruby
- Dnsruby::Algorithms
- Dnsruby::Classes
- Dnsruby::CodeMapper
- Dnsruby::Config
- Dnsruby::DNS
- Dnsruby::DecodeError
- Dnsruby::Dnssec
- Dnsruby::Dnssec::ValidationPolicy
- Dnsruby::EncodeError
- Dnsruby::ExtendedRCode
- Dnsruby::FormErr
- Dnsruby::Header
- Dnsruby::Hosts
- Dnsruby::IPv4
- Dnsruby::IPv6
- Dnsruby::Message
- Dnsruby::Message::Section
- Dnsruby::Message::SecurityLevel
- Dnsruby::MetaTypes
- Dnsruby::Modes
- Dnsruby::NXDomain
- Dnsruby::NXRRSet
- Dnsruby::Name
- Dnsruby::Name::Label
- Dnsruby::NotAuth
- Dnsruby::NotImp
- Dnsruby::NotZone
- Dnsruby::Nsec3HashAlgorithms
- Dnsruby::OpCode
- Dnsruby::OtherResolvError
- Dnsruby::QTypes
- Dnsruby::Question
- Dnsruby::RCode
- Dnsruby::RR
- Dnsruby::RR::ANY
- Dnsruby::RR::CERT
- Dnsruby::RR::CERT::CertificateTypes
- Dnsruby::RR::CNAME
- Dnsruby::RR::DHCID
- Dnsruby::RR::DLV
- Dnsruby::RR::DNAME
- Dnsruby::RR::DNSKEY
- Dnsruby::RR::DS
- Dnsruby::RR::DS::DigestTypes
- Dnsruby::RR::DomainName
- Dnsruby::RR::Generic
- Dnsruby::RR::HINFO
- Dnsruby::RR::HIP
- Dnsruby::RR::IN
- Dnsruby::RR::IN::A
- Dnsruby::RR::IN::AAAA
- Dnsruby::RR::IN::AFSDB
- Dnsruby::RR::IN::PX
- Dnsruby::RR::IN::SRV
- Dnsruby::RR::IN::WKS
- Dnsruby::RR::IPSECKEY
- Dnsruby::RR::ISDN
- Dnsruby::RR::KX
- Dnsruby::RR::LOC
- Dnsruby::RR::MB
- Dnsruby::RR::MG
- Dnsruby::RR::MINFO
- Dnsruby::RR::MR
- Dnsruby::RR::MX
- Dnsruby::RR::NAPTR
- Dnsruby::RR::NS
- Dnsruby::RR::NSAP
- Dnsruby::RR::NSEC
- Dnsruby::RR::NSEC3
- Dnsruby::RR::NSEC3PARAM
- Dnsruby::RR::OPT
- Dnsruby::RR::PTR
- Dnsruby::RR::RP
- Dnsruby::RR::RRSIG
- Dnsruby::RR::RT
- Dnsruby::RR::SOA
- Dnsruby::RR::SPF
- Dnsruby::RR::SSHFP
- Dnsruby::RR::SSHFP::Algorithms
- Dnsruby::RR::SSHFP::FpTypes
- Dnsruby::RR::TKEY
- Dnsruby::RR::TSIG
- Dnsruby::RR::TXT
- Dnsruby::RR::X25
- Dnsruby::RRSet
- Dnsruby::Recursor
- Dnsruby::Refused
- Dnsruby::Resolv
- Dnsruby::ResolvError
- Dnsruby::ResolvTimeout
- Dnsruby::Resolver
- Dnsruby::Resolver::EventType
- Dnsruby::SelectThread
- Dnsruby::ServFail
- Dnsruby::SingleResolver
- Dnsruby::TheLog
- Dnsruby::TsigError
- Dnsruby::TsigNotSignedResponseError
- Dnsruby::Types
- Dnsruby::Update
- Dnsruby::VerifyError
- Dnsruby::YXDomain
- Dnsruby::YXRRSet
- Dnsruby::ZoneReader
- Dnsruby::ZoneReader::ParseException
- Dnsruby::ZoneSerialError
- Dnsruby::ZoneTransfer
- Dnsruby::ZoneTransfer::Delta
- Base32

No matching classes.

# 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 :

- If the name is absolute, then it is used as is.

- If the name is not absolute, then :

      If apply_domain is true, and ndots is greater than the number
      of labels in the name, then the default domain is added to the name.

      If apply_search_list is true, then each member of the search list
      is appended to the name.

    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() click to toggle source

Return the search path

    # File lib/Dnsruby/Config.rb, line 390
    def search
      if (!@configured)
        parse_config
      end
      search = []
      @search.each do |s|
        search.push(Name.new(s).to_s)
      end
      return search
    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

[Validate]

Generated with the Darkfish Rdoc Generator 2.