Class: Dnsruby::RRSet

### Home Classes Methods

### In Files

- lib/Dnsruby/resource/resource.rb

### Parent

Object

### Methods

- ::new
- ::new_from_string
- #<=>
- #==
- #[]
- #add
- #delete
- #each
- #klass
- #length
- #name
- #rrs
- #sigs
- #sort_canonical
- #to_s
- #ttl
- #ttl=
- #type

### Included Modules

- Comparable

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

RFC2181, section 5 "It is however possible for most record types to exist with the same label, class and type, but with different data. Such a group of records is hereby defined to be a Resource Record Set (RRSet)." This class also stores the RRSIG records which cover the RRSet

### Attributes

num_sigs[R]

The number of RRSIGs stored in this RRSet

### Public Class Methods

new(rrs = []) click to toggle source

    # File lib/Dnsruby/resource/resource.rb, line 29
    def initialize(rrs = [])
      if (!rrs.instance_of?Array)
        rrs = [rrs]
      end
      @rrs = []
      @num_sigs = 0
      rrs.each {|rr| add(rr)}
    end

new_from_string(string) click to toggle source

    # File lib/Dnsruby/resource/resource.rb, line 37
    def self.new_from_string(string)
      rr_strings = string.split("\n")
      rrs = rr_strings.map { |s| Dnsruby::RR.new_from_string(s) }

      Dnsruby::RRSet.new(rrs)
    end

### Public Instance Methods

<=>(other) click to toggle source

    # File lib/Dnsruby/resource/resource.rb, line 111
    def <=>(other)
      #      return 1 if ((!other) || !(other.name) || !(other.type))
      #      return -1 if (!@name)
      if (name.canonical == other.name.canonical)
        return type.code <=> other.type.code
      else
        return name <=> other.name
      end
    end

==(other) click to toggle source

    # File lib/Dnsruby/resource/resource.rb, line 139
    def ==(other)
      return false unless other.instance_of?RRSet
      return false if (other.sigs.length != self.sigs.length)
      return false if (other.rrs.length != self.rrs.length)
      return false if (other.ttl != self.ttl)
      otherrrs = other.rrs
      self.rrs.each {|rr|
        return false if (!otherrrs.include?rr)
      }
      othersigs= other.sigs
      self.sigs.each {|sig|
        return false if (!othersigs.include?sig)
      }
      return true
    end

[](index) click to toggle source

    # File lib/Dnsruby/resource/resource.rb, line 163
    def [](index)
      return @rrs[index]
    end

add(rin, do_clone = true) click to toggle source

Add the RR to this RRSet Takes a copy of the RR by default. To suppress this, pass false as the second parameter.

    # File lib/Dnsruby/resource/resource.rb, line 72
    def add(rin, do_clone = true)
      if (rin.instance_of?RRSet)
        ret = false
        [rin.rrs, rin.sigs].each {|rr| ret = add(rr)}
        return ret
      end
      #      r = RR.create(r.to_s) # clone the record
      r = nil
      if do_clone
        r = rin.clone
      else
        r = rin
      end
      if (@rrs.size() == 0) #  && !(r.type == Types.RRSIG))
        return privateAdd(r)
      end
      # Check the type, klass and ttl are correct
      first = @rrs[0]
      if (!r.sameRRset(first))
        return false
        #        raise ArgumentError.new("record does not match rrset")
      end

      if (!(r.type == Types::RRSIG) && (!(first.type == Types::RRSIG)))
        if (r.ttl != first.ttl) # RFC2181, section 5.2
          if (r.ttl > first.ttl)
            r.ttl=(first.ttl)
          else
            @rrs.each do |rr|
              rr.ttl = r.ttl
            end
          end
        end
      end

      return privateAdd(r)
      #      return true
    end

delete(rr) click to toggle source

Delete the RR from this RRSet

    # File lib/Dnsruby/resource/resource.rb, line 155
    def delete(rr)
      @rrs.delete(rr)
    end

each() click to toggle source

    # File lib/Dnsruby/resource/resource.rb, line 158
    def each
      @rrs.each do |rr|
        yield rr
      end
    end

klass() click to toggle source

Return the klass of this RRSet

    # File lib/Dnsruby/resource/resource.rb, line 174
    def klass
      return @rrs[0].klass
    end

length() click to toggle source

    # File lib/Dnsruby/resource/resource.rb, line 202
    def length
      return @rrs.length
    end

name() click to toggle source

    # File lib/Dnsruby/resource/resource.rb, line 188
    def name
      if (@rrs[0])
        return @rrs[0].name
      else
        return nil
      end
    end

rrs() click to toggle source

The RRs (not RRSIGs) stored in this RRSet

    # File lib/Dnsruby/resource/resource.rb, line 47
    def rrs
      return @rrs[0, @rrs.length-@num_sigs]
    end

sigs() click to toggle source

    # File lib/Dnsruby/resource/resource.rb, line 43
    def sigs
      return @rrs[@rrs.length-@num_sigs, @num_sigs]
    end

sort_canonical() click to toggle source

    # File lib/Dnsruby/resource/resource.rb, line 121
    def sort_canonical
      #Make a list, for all the RRs, where each RR contributes
      #the canonical RDATA encoding
      canonical_rrs = {}
      self.rrs.each do |rr|
        data = MessageEncoder.new {|msg|
          rr.encode_rdata(msg, true)
        }.to_s
        canonical_rrs[data] = rr
      end

      return_rrs = RRSet.new
      canonical_rrs.keys.sort.each { |rdata|
        return_rrs.add(canonical_rrs[rdata], false)
      }
      return return_rrs
    end

to_s() click to toggle source

    # File lib/Dnsruby/resource/resource.rb, line 195
    def to_s
      ret = ""
      each {|rec|
        ret += rec.to_s + "\n"
      }
      return ret
    end

ttl() click to toggle source

Return the ttl of this RRSet

    # File lib/Dnsruby/resource/resource.rb, line 178
    def ttl
      return @rrs[0].ttl
    end

ttl=(ttl) click to toggle source

    # File lib/Dnsruby/resource/resource.rb, line 181
    def ttl=(ttl)
      [rrs, sigs].each {|rrs|
        rrs.each {|rr|
          rr.ttl = ttl
        }
      }
    end

type() click to toggle source

Return the type of this RRSet

    # File lib/Dnsruby/resource/resource.rb, line 167
    def type
      if (@rrs[0])
        return @rrs[0].type
      end
      return nil
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.