Class: Dnsruby::Message::Section
- Inherits:
-
Array
- Object
- Array
- Dnsruby::Message::Section
- Defined in:
- lib/Dnsruby/message.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(msg = nil) ⇒ Section
constructor
A new instance of Section.
- #remove_rrset(name, type) ⇒ Object
-
#rrset(name, type = Types.A, klass = Classes::IN) ⇒ Object
Return the rrset of the specified type in this section.
-
#rrsets(type = nil, include_opt = false) ⇒ Object
Return an array of all the rrsets in the section.
Constructor Details
#initialize(msg = nil) ⇒ Section
Returns a new instance of Section.
91 92 93 94 |
# File 'lib/Dnsruby/message.rb', line 91 def initialize(msg = nil) @msg = msg super(0) end |
Instance Method Details
#==(other) ⇒ Object
152 153 154 155 156 157 158 159 160 |
# File 'lib/Dnsruby/message.rb', line 152 def ==(other) return false unless (other.instance_of?Message::Section) return false if (other.rrsets(nil, true).length != self.rrsets(nil, true).length) otherrrsets = other.rrsets(nil, true) self.rrsets(nil, true).each {|rrset| return false unless otherrrsets.include?rrset } return true end |
#remove_rrset(name, type) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/Dnsruby/message.rb', line 162 def remove_rrset(name, type) # Remove all RRs with the name and type from the section. # Need to worry about header counts here - can we get Message to # update the counts itself, rather than the section worrying about it? rrs_to_delete = [] each do |rr| next if rr.rr_type == Types::OPT if ((rr.name.to_s.downcase == name.to_s.downcase) && ((rr.type == type) || ((rr.type == Types::RRSIG) && (rr.type_covered == type)) )) rrs_to_delete.push(rr) end end rrs_to_delete.each {|rr| delete(rr) } @msg.update_counts if @msg end |
#rrset(name, type = Types.A, klass = Classes::IN) ⇒ Object
Return the rrset of the specified type in this section
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/Dnsruby/message.rb', line 96 def rrset(name, type=Types.A, klass=Classes::IN) rrs = select{|rr| type_ok = (rr.type==type) if (rr.type == Types::RRSIG) type_ok = (rr.type_covered == type) end if (!(/\.\z/ =~ name.to_s)) name = name.to_s + "." end type_ok && (rr.klass == klass) && (rr.name.to_s(true).downcase == name.to_s().downcase) } rrset = RRSet.new() rrs.each do |rr| rrset.add(rr) end return rrset end |
#rrsets(type = nil, include_opt = false) ⇒ Object
Return an array of all the rrsets in the section
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/Dnsruby/message.rb', line 115 def rrsets(type = nil, include_opt = false) if (type && !(Types === type)) type = Types.new(type) end ret = [] each do |rr| next if (!include_opt && (rr.type == Types::OPT)) # if (type) # next if ((rr.type == Types.RRSIG) && (type != Types.RRSIG) && (rr.type_covered != type)) # next if (rr.type != type) # end if (type) # if this is an rrsig type, then : # only include it if the type_covered is the type requested, # OR if the type requested is an RRSIG if (rr.type == Types::RRSIG) if ((rr.type_covered == type) || (type == Types::RRSIG)) else next end # next if ((rr.type_covered != type) || (type != Types.RRSIG)) elsif (rr.type != type) next end end found_rrset = false ret.each do |rrset| found_rrset = rrset.add(rr) break if found_rrset end if (!found_rrset) ret.push(RRSet.new(rr)) end end return ret end |