lib/spf/model.rb in spf-0.0.22 vs lib/spf/model.rb in spf-0.0.23
- old
+ new
@@ -83,29 +83,30 @@
:: (?: #{HEXWORD_PATTERN} : ){0,5} #{TWO_HEXWORDS_OR_IPV4_ADDRESS_PATTERN} |
# :: | -
::
"
- attr_reader :errors, :ip_netblocks, :ip_address, :ip_network, :ipv4_prefix_length, :ipv6_prefix_length, :domain_spec
+ attr_reader :errors, :ip_netblocks, :ip_address, :ip_network, :ipv4_prefix_length, :ipv6_prefix_length, :domain_spec, :raw_params
def initialize(options = {})
@ip_address = nil
@ip_network = nil
@ipv4_prefix_length = nil
@ipv6_prefix_length = nil
+ @raw_params = nil
@errors = []
@ip_netblocks = []
+ @text = options[:text]
@raise_exceptions = options.has_key?(:raise_exceptions) ? options[:raise_exceptions] : true
end
def error(exception)
raise exception if @raise_exceptions
@errors << exception
end
def self.new_from_string(text, options = {})
- #term = SPF::Term.new(options, {:text => text})
options[:text] = text
term = self.new(options)
term.parse
return term
end
@@ -120,10 +121,11 @@
"Missing required domain-spec in '#{@text}'"))
end
end
def parse_ipv4_address(required = false)
+ @raw_params = @parse_text.dup
if @parse_text.sub!(/^(#{IPV4_ADDRESS_PATTERN})/x, '')
@ip_address = $1
elsif required
error(SPF::TermIPv4AddressExpectedError.new(
"Missing or invalid required IPv4 address in '#{@text}'"))
@@ -149,10 +151,11 @@
@ipv4_prefix_length = self.default_ipv4_prefix_length
end
end
def parse_ipv4_network(required = false)
+ @raw_params = @parse_text.dup
self.parse_ipv4_address(required)
self.parse_ipv4_prefix_length
begin
@ip_network = IP.new("#{@ip_address}/#{@ipv4_prefix_length}") if @ip_address and @ipv4_prefix_length
rescue ArgumentError
@@ -187,10 +190,11 @@
@ipv6_prefix_length = self.default_ipv6_prefix_length
end
end
def parse_ipv6_network(required = false)
+ @raw_params = @parse_text.dup
self.parse_ipv6_address(required)
self.parse_ipv6_prefix_length
begin
@ip_network = IP.new("#{@ip_address}/#{@ipv6_prefix_length}") if @ip_address and @ipv6_prefix_length
rescue ArgumentError
@@ -283,13 +287,15 @@
error(SPF::InvalidMechError.new("Unexpected mechanism encountered in '#{@text}'"))
end
end
def parse_params(required = true)
+ @raw_params = @parse_text.dup
# Parse generic string of parameters text (should be overridden in sub-classes):
if @parse_text.sub!(/^(.*)/, '')
@params_text = $1
+ @raw_params = @params_text.dup
end
end
def parse_end
unless @parse_text == ''
@@ -364,10 +370,11 @@
class SPF::Mech::A < SPF::Mech
NAME = 'a'
def parse_params(required = true)
+ @raw_params = @parse_text.dup
self.parse_domain_spec
self.parse_ipv4_ipv6_prefix_lengths
end
def params
@@ -408,10 +415,11 @@
class SPF::Mech::Exists < SPF::Mech
NAME = 'exists'
def parse_params(required = true)
+ @raw_params = @raw_text.dup
self.parse_domain_spec(required)
# Other method of denoting "potentially ~infinite" netblocks?
@ip_netblocks << nil
end
@@ -484,10 +492,12 @@
return nil unless @ip_network
return @ip_network if String === @ip_network
params = @ip_network.to_addr
params += '/' + @ip_network.pfxlen.to_s if
@ip_network.pfxlen != self.default_ipv6_prefix_length
+ puts "params: #{params}"
+ puts self.inspect
return params
end
def match(server, request, want_result = true)
return @ip_network.contains?(request.ip_address_v6)
@@ -503,10 +513,11 @@
super(options)
@nested_record = nil
end
def parse_params(required = true)
+ @raw_params = @parse_text.dup
self.parse_domain_spec(required)
end
def params
return @domain_spec ? @domain_spec.to_s : nil
@@ -555,10 +566,11 @@
class SPF::Mech::MX < SPF::Mech
NAME = 'mx'
def parse_params(required = true)
+ @raw_params = @parse_text.dup
self.parse_domain_spec
self.parse_ipv4_ipv6_prefix_lengths
end
def params
@@ -607,9 +619,10 @@
class SPF::Mech::PTR < SPF::Mech
NAME = 'ptr'
def parse_params(required = true)
+ @raw_params = @parse_text.dup
self.parse_domain_spec
end
def params
return @domain_spec ? @domain_spec : nil