spf2 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +20 -0
- data/ext/spf2/extconf.rb +4 -0
- data/ext/spf2/spf2.c +113 -0
- data/lib/spf2.rb +2 -0
- data/lib/spf2/version.rb +3 -0
- data/spf2.gemspec +25 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YmQ3ZGM0ZTY5ZDQ2MjUzOGQwMjNjZGRkZjNkYzBjODBkZWZhNDY5MA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NWYyMDIwNjYzMTZjNTI2OTkzYjFkN2MzOGFlZGNiMWZlM2QwZjMzNw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
M2VmODRhZTZlOTZlMzFjZDg4OGU1MDU0MTA2MjgyMThlOGFlNTdhNGVlZjRk
|
10
|
+
NDJmODYyNThmY2QwMzQ0NjE1ZjZjZTA1NmYzNDIzMDg1ZWViZDVkNTc3YzE4
|
11
|
+
ZWNmODVhYTk0OGY4NjU2ZmI0MThmMDliNWJiODVlM2UzNzBkMTA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTNhNmY0YTU3MTdmZWY5MjgzNjlkODIzODdiODA5OWE2YTUwNWZhZDdjMzEx
|
14
|
+
MmVlZDNhZTMxYTlhYWYzNzIzOGUyNGZmYzFmODIxMmRjYzRmZjc3YzIwMGZj
|
15
|
+
OGIwNDk0NTE5N2U0NDQwMDU4NDIxNzA0N2MzZTY4NjIwOWNmZGE=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Romeu Fonseca
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Spf2
|
2
|
+
|
3
|
+
Simple native wrapper over the C lib SPF2.
|
4
|
+
At the moment it just have a query method that returns three strings with result, reason and error:
|
5
|
+
|
6
|
+
["pass", "mechanism", "No errors"]
|
7
|
+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'spf2'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install spf2
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
```
|
25
|
+
require 'spf2'
|
26
|
+
|
27
|
+
s = Spf2.new(debug=false)
|
28
|
+
s.debug = true
|
29
|
+
s.query("173.194.65.27", "gmail.com")
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
40
|
+
|
41
|
+
|
42
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
|
4
|
+
require 'rake/extensiontask'
|
5
|
+
|
6
|
+
##
|
7
|
+
# Rake::ExtensionTask comes from the rake-compiler and understands how to
|
8
|
+
# build and cross-compile extensions.
|
9
|
+
#
|
10
|
+
# See https://github.com/luislavena/rake-compiler for details
|
11
|
+
|
12
|
+
Rake::ExtensionTask.new 'spf2' do |ext|
|
13
|
+
ext.lib_dir = 'lib/spf2'
|
14
|
+
end
|
15
|
+
|
16
|
+
task test: %w[compile] do
|
17
|
+
ruby '-Ilib', '-rspf2', '-e', 's = Spf2.new(false); s.debug=(true); s.debug=(false); p s.query("186.224.205.179", "cmacomunicacao.com.br")'
|
18
|
+
end
|
19
|
+
|
20
|
+
task default: :test
|
data/ext/spf2/extconf.rb
ADDED
data/ext/spf2/spf2.c
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <netinet/in.h>
|
3
|
+
#include <spf2/spf.h>
|
4
|
+
#include <spf2/spf_server.h>
|
5
|
+
/*
|
6
|
+
SPF_server_t *spf_server = SPF_server_new(SPF_DNS_CACHE, 0);
|
7
|
+
Create a request, and set the relevant fields in it. Each setter method returns an SPF_errcode_t, which will inform you of error conditions, such as out-of-memory or invalid argument.
|
8
|
+
|
9
|
+
SPF_request_t *spf_request = SPF_request_new(spf_server);
|
10
|
+
SPF_request_set_ipv4_str(spf_request, "123.45.6.7");
|
11
|
+
SPF_request_set_env_from(spf_request, "clientdomain.com");
|
12
|
+
Now that we have built a query, we may execute it. It will use the SPF_server_t which was passed to the query constructor. As usual, the SPF_request_query_mailfrom method returns an error code, although much richer errors are returned inside the SPF_response_t - see spf_response.h for more details of that API.
|
13
|
+
|
14
|
+
SPF_response_t *spf_response = NULL;
|
15
|
+
SPF_request_query_mailfrom(spf_request, &spf_response);
|
16
|
+
printf("Result is %s\n",
|
17
|
+
SPF_strresult(SPF_response_result(spf_response)));
|
18
|
+
When we have finished with the response, we must free it and the request.
|
19
|
+
|
20
|
+
SPF_response_free(spf_response);
|
21
|
+
SPF_request_free(spf_request);
|
22
|
+
We can execute many requests in parallel threads on the same server, but before the program exits, we must free the server.
|
23
|
+
|
24
|
+
SPF_server_free(spf_server);
|
25
|
+
*/
|
26
|
+
|
27
|
+
/*
|
28
|
+
*/
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
static VALUE
|
33
|
+
spf2_set_debug(VALUE self, VALUE bDebug){
|
34
|
+
SPF_server_t *spf_server ;
|
35
|
+
|
36
|
+
Data_Get_Struct(self, SPF_server_t, spf_server);
|
37
|
+
spf_server->debug = RTEST(bDebug);
|
38
|
+
|
39
|
+
|
40
|
+
return self;
|
41
|
+
}
|
42
|
+
|
43
|
+
static VALUE
|
44
|
+
spf2_query(VALUE self, VALUE ipfrom, VALUE domain) {
|
45
|
+
|
46
|
+
SPF_server_t *spf_server = NULL ;
|
47
|
+
SPF_response_t *spf_response = NULL;
|
48
|
+
SPF_request_t *spf_request = NULL;
|
49
|
+
|
50
|
+
VALUE ret , str_result , str_reason, str_error;
|
51
|
+
|
52
|
+
Data_Get_Struct(self, SPF_server_t, spf_server);
|
53
|
+
|
54
|
+
spf_request = SPF_request_new(spf_server);
|
55
|
+
|
56
|
+
SPF_request_set_ipv4_str(spf_request,StringValueCStr(ipfrom));
|
57
|
+
SPF_request_set_env_from(spf_request,StringValueCStr(domain));
|
58
|
+
SPF_request_query_mailfrom(spf_request, &spf_response);
|
59
|
+
|
60
|
+
str_result = rb_str_new2(SPF_strresult(SPF_response_result(spf_response)));
|
61
|
+
str_reason = rb_str_new2(SPF_strreason(SPF_response_reason(spf_response)));
|
62
|
+
str_error = rb_str_new2(SPF_strerror(SPF_response_errcode(spf_response)));
|
63
|
+
ret = rb_ary_new2(4);
|
64
|
+
rb_ary_push(ret, str_result);
|
65
|
+
rb_ary_push(ret, str_reason);
|
66
|
+
rb_ary_push(ret, str_error);
|
67
|
+
|
68
|
+
|
69
|
+
SPF_response_free(spf_response);
|
70
|
+
SPF_request_free(spf_request);
|
71
|
+
return ret;
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
static void spf2_free(void * p){
|
76
|
+
SPF_server_free(p);
|
77
|
+
}
|
78
|
+
|
79
|
+
static VALUE
|
80
|
+
spf2_init(VALUE self, VALUE bDebug) {
|
81
|
+
spf2_set_debug(self, bDebug);
|
82
|
+
return self;
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
/*
|
88
|
+
* This defines the C functions as extensions.
|
89
|
+
*
|
90
|
+
* The name of the Init_ function is important. What follows Init_ must match
|
91
|
+
* the file name (including case) so ruby knows what method to call to define
|
92
|
+
* the extensions.
|
93
|
+
*/
|
94
|
+
static VALUE spf2_alloc(VALUE klass){
|
95
|
+
SPF_server_t *spf_server = NULL;
|
96
|
+
VALUE obj;
|
97
|
+
spf_server = SPF_server_new(SPF_DNS_CACHE,0);
|
98
|
+
obj = Data_Wrap_Struct(klass, 0, spf2_free, spf_server);
|
99
|
+
return obj;
|
100
|
+
|
101
|
+
}
|
102
|
+
void
|
103
|
+
Init_spf2(void) {
|
104
|
+
VALUE cSpf2;
|
105
|
+
|
106
|
+
cSpf2 = rb_const_get(rb_cObject, rb_intern("Spf2"));
|
107
|
+
|
108
|
+
rb_define_alloc_func(cSpf2, spf2_alloc);
|
109
|
+
rb_define_method(cSpf2, "initialize", spf2_init, 1);
|
110
|
+
rb_define_method(cSpf2, "debug=", spf2_set_debug, 1);
|
111
|
+
rb_define_method(cSpf2, "query", spf2_query, 2);
|
112
|
+
}
|
113
|
+
|
data/lib/spf2.rb
ADDED
data/lib/spf2/version.rb
ADDED
data/spf2.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'spf2/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "spf2"
|
8
|
+
spec.version = Spf2::VERSION
|
9
|
+
spec.authors = ["Romeu Fonseca"]
|
10
|
+
spec.email = ["romeu.hcf@gmail.com"]
|
11
|
+
spec.description = %q{Native libspf2 basic wrapper}
|
12
|
+
spec.summary = %q{Simple query interface to native libspf2. Will be more complete later.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.extensions = %w[ext/spf2/extconf.rb]
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rake-compiler"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spf2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Romeu Fonseca
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Native libspf2 basic wrapper
|
56
|
+
email:
|
57
|
+
- romeu.hcf@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions:
|
60
|
+
- ext/spf2/extconf.rb
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- ext/spf2/extconf.rb
|
69
|
+
- ext/spf2/spf2.c
|
70
|
+
- lib/spf2.rb
|
71
|
+
- lib/spf2/version.rb
|
72
|
+
- spf2.gemspec
|
73
|
+
homepage: ''
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.1.11
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Simple query interface to native libspf2. Will be more complete later.
|
97
|
+
test_files: []
|