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