lib/spf/model.rb in spf-0.0.50 vs lib/spf/model.rb in spf-0.0.51

- old
+ new

@@ -137,17 +137,17 @@ def parse_ipv4_prefix_length(required = false) if @parse_text.sub!(/^\/(\d+)/, '') bits = $1.to_i unless bits and bits >= 0 and bits <= 32 and $1 !~ /^0./ - error(SPF::TermIPv4PrefixLengthExpected.new( + error(SPF::TermIPv4PrefixLengthExpectedError.new( "Invalid IPv4 prefix length encountered in '#{@text}'")) return end @ipv4_prefix_length = bits elsif required - error(SPF::TermIPv4PrefixLengthExpected.new( + error(SPF::TermIPv4PrefixLengthExpectedError.new( "Missing required IPv4 prefix length in '#{@text}")) return else @ipv4_prefix_length = self.default_ipv4_prefix_length end @@ -166,11 +166,11 @@ def parse_ipv6_address(required = false) if @parse_text.sub!(/(#{IPV6_ADDRESS_PATTERN})(?=\/|$)/x, '') @ip_address = $1 elsif required - error(SPF::TermIPv6AddressExpected.new( + error(SPF::TermIPv6AddressExpectedError.new( "Missing or invalid required IPv6 address in '#{@text}'")) end @ip_address = @parse_text.dup unless @ip_address end @@ -182,11 +182,11 @@ "Invalid IPv6 prefix length encountered in '#{@text}'")) return end @ipv6_prefix_length = bits elsif required - error(SPF::TermIPv6PrefixLengthExpected.new( + error(SPF::TermIPv6PrefixLengthExpectedError.new( "Missing required IPv6 prefix length in '#{@text}'")) return else @ipv6_prefix_length = self.default_ipv6_prefix_length end @@ -212,11 +212,11 @@ end end def domain(server, request) if self.instance_variable_defined?(:@domain_spec) and @domain_spec - return @domain_spec + return SPF::MacroString.new({:server => server, :request => request, :text => @domain_spec.text}) end return request.authority_domain end def text @@ -444,17 +444,17 @@ def match(server, request, want_result = true) server.count_dns_interactive_term(request) domain = self.domain(server, request) - packet = server.dns_lookup(domain, 'A') - rrs = (packet.exchange or server.count_void_dns_lookup(request)) - rrs.each do |rr| - return true if rr.type == 'A' + begin + rrs = server.dns_lookup(domain, 'A') + return true if rrs.any? + rescue SPF::DNSNXDomainError => e + server.count_void_dns_lookup(request) + return false end - - return false end end class SPF::Mech::IP4 < SPF::Mech @@ -939,10 +939,10 @@ # Known modifier. term = mod = mod_class.new_from_string(mod_text, {:raise_exceptions => @raise_exceptions}) if SPF::GlobalMod === mod # Global modifier. if @global_mods[mod_name] - raise SPF::DuplicateGlobalMod.new("Duplicate global modifier '#{mod_name}' encountered") + raise SPF::DuplicateGlobalModError.new("Duplicate global modifier '#{mod_name}' encountered") end @global_mods[mod_name] = mod elsif SPF::PositionalMod === mod # Positional modifier, queue normally: @terms << mod