Class | Dnsruby::RRSet |
In: |
lib/Dnsruby/resource/resource.rb
|
Parent: | Object |
num_sigs | [R] | The number of RRSIGs stored in this RRSet |
# File lib/Dnsruby/resource/resource.rb, line 29 29: def initialize(rrs = []) 30: if (!rrs.instance_of?Array) 31: rrs = [rrs] 32: end 33: @rrs = [] 34: @num_sigs = 0 35: rrs.each {|rr| add(rr)} 36: end
# File lib/Dnsruby/resource/resource.rb, line 105 105: def <=>(other) 106: # return 1 if ((!other) || !(other.name) || !(other.type)) 107: # return -1 if (!@name) 108: if (@name.canonical == other.name.canonical) 109: return @type.code <=> other.type.code 110: else 111: return @name <=> other.name 112: end 113: end
# File lib/Dnsruby/resource/resource.rb, line 133 133: def ==(other) 134: return false unless other.instance_of?RRSet 135: return false if (other.sigs.length != self.sigs.length) 136: return false if (other.rrs.length != self.rrs.length) 137: return false if (other.ttl != self.ttl) 138: otherrrs = other.rrs 139: self.rrs.each {|rr| 140: return false if (!otherrrs.include?rr) 141: } 142: othersigs= other.sigs 143: self.sigs.each {|sig| 144: return false if (!othersigs.include?sig) 145: } 146: return true 147: end
# File lib/Dnsruby/resource/resource.rb, line 157 157: def [](index) 158: return @rrs[index] 159: end
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 66 66: def add(rin, do_clone = true) 67: if (rin.instance_of?RRSet) 68: ret = false 69: [rin.rrs, rin.sigs].each {|rr| ret = add(rr)} 70: return ret 71: end 72: # r = RR.create(r.to_s) # clone the record 73: r = nil 74: if do_clone 75: r = rin.clone 76: else 77: r = rin 78: end 79: if (@rrs.size() == 0) # && !(r.type == Types.RRSIG)) 80: return privateAdd(r) 81: end 82: # Check the type, klass and ttl are correct 83: first = @rrs[0] 84: if (!r.sameRRset(first)) 85: return false 86: # raise ArgumentError.new("record does not match rrset") 87: end 88: 89: if (!(r.type == Types::RRSIG) && (!(first.type == Types::RRSIG))) 90: if (r.ttl != first.ttl) # RFC2181, section 5.2 91: if (r.ttl > first.ttl) 92: r.ttl=(first.ttl) 93: else 94: @rrs.each do |rr| 95: rr.ttl = r.ttl 96: end 97: end 98: end 99: end 100: 101: return privateAdd(r) 102: # return true 103: end
# File lib/Dnsruby/resource/resource.rb, line 152 152: def each 153: @rrs.each do |rr| 154: yield rr 155: end 156: end
# File lib/Dnsruby/resource/resource.rb, line 182 182: def name 183: if (@rrs[0]) 184: return @rrs[0].name 185: else 186: return nil 187: end 188: end
# File lib/Dnsruby/resource/resource.rb, line 115 115: def sort_canonical 116: #Make a list, for all the RRs, where each RR contributes 117: #the canonical RDATA encoding 118: canonical_rrs = {} 119: self.rrs.each do |rr| 120: data = MessageEncoder.new {|msg| 121: rr.encode_rdata(msg, true) 122: }.to_s 123: canonical_rrs[data] = rr 124: end 125: 126: return_rrs = RRSet.new 127: canonical_rrs.keys.sort.each { |rdata| 128: return_rrs.add(canonical_rrs[rdata], false) 129: } 130: return return_rrs 131: end
# File lib/Dnsruby/resource/resource.rb, line 189 189: def to_s 190: ret = "" 191: each {|rec| 192: ret += rec.to_s + "\n" 193: } 194: return ret 195: end