lib/spf/model.rb in spf-0.0.9 vs lib/spf/model.rb in spf-0.0.10

- old
+ new

@@ -189,10 +189,17 @@ # Parse an IPv6 prefix length: self.parse_ipv6_prefix_length(true) end end + def domain(server, request) + if self.instance_variable_defined?(:@domain_spec) and @domain_spec + return @domain_spec + end + return request.authority_domain + end + def text if self.instance_variable_defined?(:@text) return @text else raise SPF::NoUnparsedTextError @@ -255,11 +262,11 @@ else raise SPF::InvalidMech.new("Unexpected mechanism encountered in '#{@text}'") end end - def parse_params + def parse_params(required = true) # Parse generic string of parameters text (should be overridden in sub-classes): if @parse_text.sub!(/^(.*)/, '') @params_text = $1 end end @@ -286,22 +293,15 @@ @name, @params ? @params : '' ) end - def domain(server, request) - if self.instance_variable_defined?(:@domain_spec) and @domain_spec - return @domain_spec - end - return request.authority_domain - end - def match_in_domain(server, request, domain) domain = self.domain(server, request) unless domain - ipv4_prefix_length = @ipv4_prefix_length - ipv6_prefix_length = @ipv6_prefix_length + ipv4_prefix_length = @ipv4_prefix_length || self.default_ipv4_prefix_length + ipv6_prefix_length = @ipv6_prefix_length || self.default_ipv6_prefix_length packet = server.dns_lookup(domain, 'ANY') server.count_void_dns_lookup(request) unless (rrs = packet) rrs.each do |rr| if Resolv::DNS::Resource::IN::A === rr @@ -343,11 +343,11 @@ class SPF::Mech::A < SPF::Mech NAME = 'a' - def parse_params + def parse_params(required = true) self.parse_domain_spec self.parse_ipv4_ipv6_prefix_lengths end def params @@ -373,11 +373,11 @@ class SPF::Mech::All < SPF::Mech NAME = 'all' - def parse_params + def parse_params(required = true) # No parameters. end def match(server, request, want_result = true) return true @@ -387,12 +387,12 @@ class SPF::Mech::Exists < SPF::Mech NAME = 'exists' - def parse_params - self.parse_domain_spec(true) + def parse_params(required = true) + self.parse_domain_spec(required) # Other method of denoting "potentially ~infinite" netblocks? @ip_netblocks << nil end def params @@ -416,12 +416,12 @@ class SPF::Mech::IP4 < SPF::Mech NAME = 'ip4' - def parse_params - self.parse_ipv4_network(true) + def parse_params(required = true) + self.parse_ipv4_network(required) @ip_netblocks << @ip_network end def params result = @ip_network.addr @@ -442,12 +442,12 @@ class SPF::Mech::IP6 < SPF::Mech NAME = 'ip6' - def parse_params - self.parse_ipv6_network(true) + def parse_params(required = true) + self.parse_ipv6_network(required) @ip_netblocks << @ip_network end def params params = ':' + @ip_network.short @@ -469,12 +469,12 @@ def intitialize(options = {}) super(options) @nested_record = nil end - def parse_params - self.parse_domain_spec(true) + def parse_params(required = true) + self.parse_domain_spec(required) end def params return @domain_spec ? ':' + @domain_spec : nil end @@ -520,11 +520,11 @@ class SPF::Mech::MX < SPF::Mech NAME = 'mx' - def parse_params + def parse_params(required = true) self.parse_domain_spec self.parse_ipv4_ipv6_prefix_lengths end def params @@ -572,11 +572,11 @@ end class SPF::Mech::PTR < SPF::Mech NAME = 'ptr' - def parse_params + def parse_params(required = true) self.parse_domain_spec end def params return @domain_spec ? ':' + @domain_spec : nil @@ -612,11 +612,11 @@ self.parse_params(true) self.parse_end end def parse_name - @parse_text.sub!(/^(#{NAME})=/i, '') + @parse_text.sub!(/^(#{self.class::NAME})=/i, '') if $1 @name = $1 else raise SPF::InvalidModError.new( "Unexpected modifier name encoutered in #{@text}") @@ -660,15 +660,15 @@ class SPF::Mod::Exp < SPF::Mod attr_reader :domain_spec - NAME = 'exp' - PRECEDENCE = 0.2 + NAME = 'exp' + PRECEDENCE = 0.2 - def parse_params - self.parse_domain_spec(true) + def parse_params(required = true) + self.parse_domain_spec(required) end def params return @domain_spec end @@ -710,12 +710,12 @@ def init(options = {}) super(options) @nested_record = nil end - def parse_params - self.parse_domain_spec(true) + def parse_params(required = true) + self.parse_domain_spec(required) end def params return @domain_spec end @@ -850,16 +850,16 @@ /x, '') and $& ) # Looks like a modifier: mod_text = $1 mod_name = $2.downcase - mod_class = self.class::MOD_CLASSES[mod_name] + mod_class = self.class::MOD_CLASSES[mod_name.to_sym] if mod_class # Known modifier. term = mod = mod_class.new_from_string(mod_text) if SPF::GlobalMod === mod # Global modifier. - unless @global_mods[mod_name] + if @global_mods[mod_name] raise SPF::DuplicateGlobalMod.new("Duplicate global modifier '#{mod_name}' encountered") end @global_mods[mod_name] = mod elsif SPF::PositionalMod === mod # Positional modifier, queue normally: