subdomainz 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ *.bundle
3
+ tmp/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem "rspec"
4
+ gem "rake-compiler"
5
+ gem "woof_util"
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ excon (0.16.10)
6
+ highline (1.6.15)
7
+ rake (10.0.2)
8
+ rake-compiler (0.8.1)
9
+ rake
10
+ rspec (2.12.0)
11
+ rspec-core (~> 2.12.0)
12
+ rspec-expectations (~> 2.12.0)
13
+ rspec-mocks (~> 2.12.0)
14
+ rspec-core (2.12.1)
15
+ rspec-expectations (2.12.0)
16
+ diff-lcs (~> 1.1.3)
17
+ rspec-mocks (2.12.0)
18
+ woof_util (0.0.16)
19
+ excon (~> 0.16.10)
20
+ highline (~> 1.6.15)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ rake-compiler
27
+ rspec
28
+ woof_util
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require "bundler/setup"
2
+ require "rake/extensiontask"
3
+ require "rspec/core/rake_task"
4
+ require "woof_util/gem_rake_tasks"
5
+
6
+ Rake::ExtensionTask.new("subdomainz")
7
+ WoofUtil::GemRakeTasks.create_tasks
8
+
9
+ RSpec::Core::RakeTask.new "spec"
10
+ task :build do
11
+ Dir.chdir('ext') do
12
+ output = `ruby extconf.rb`
13
+ raise output unless $? == 0
14
+ output = `make`
15
+ raise output unless $? == 0
16
+ end
17
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,5 @@
1
+ *.o
2
+ *.bundle
3
+ *.a
4
+ *.so
5
+ Makefile
@@ -0,0 +1,5 @@
1
+ require 'mkmf'
2
+
3
+ extension_name = 'subdomainz/subdomainz'
4
+ dir_config extension_name
5
+ create_makefile extension_name
@@ -0,0 +1,65 @@
1
+ #include <stdlib.h>
2
+ #include <string.h>
3
+
4
+ #include "ruby.h"
5
+
6
+ /* RFC 2181 */
7
+ #define MAXDNSLENGTH 253
8
+
9
+ VALUE Subdomainz = Qnil;
10
+
11
+ void Init_subdomainz();
12
+
13
+ VALUE method_common_subdomain(VALUE self, VALUE rb_a, VALUE rb_b);
14
+
15
+ void Init_subdomainz(){
16
+ Subdomainz = rb_define_module("Subdomainz");
17
+ // Subdomainz = rb_define_module("Subdomainz");
18
+ rb_define_singleton_method(Subdomainz, "common_subdomain", method_common_subdomain, 2);
19
+ }
20
+
21
+ VALUE method_common_subdomain(VALUE self, VALUE rb_a, VALUE rb_b){
22
+ char *a = StringValuePtr(rb_a);
23
+ char *b = StringValuePtr(rb_b);
24
+
25
+ long alen = strnlen(a, MAXDNSLENGTH),
26
+ blen = strnlen(b, MAXDNSLENGTH);
27
+ char *aptr = alen + a,
28
+ *bptr = blen + b,
29
+ *candidate = NULL;
30
+ char emptystring = '\0';
31
+
32
+ while((aptr >= a) && (bptr >= b)){
33
+ if(*aptr != *bptr) break;
34
+
35
+ /* a=alpha.foo.com, b=beta.foo.com */
36
+ if(*aptr == '.') candidate = aptr;
37
+
38
+ /* a=foo.com, b=beta.foo.com */
39
+ if((aptr == a) && (alen < blen) && bptr[-1] == '.') candidate = aptr;
40
+
41
+ /* a=alpha.foo.com, b=foo.com */
42
+ if((bptr == b) && (blen < alen) && aptr[-1]== '.') candidate = aptr;
43
+
44
+ /* a=foo.com, b=foo.com */
45
+ if((aptr == a) && (bptr = b)) candidate = aptr;
46
+
47
+ aptr -= 1 ; bptr -= 1;
48
+ }
49
+ if(candidate == NULL) return rb_str_new(&emptystring, 0);
50
+
51
+ if(candidate[0] == '.') candidate += 1;
52
+ return rb_str_new(candidate, strnlen(candidate, MAXDNSLENGTH));
53
+ }
54
+
55
+ #if 0
56
+ int main(int argc, char **argv){
57
+ char *common;
58
+ if(argc != 3) return 1;
59
+
60
+ common = find_common_subdomain(argv[1], argv[2]);
61
+ printf("common: %s\n", common);
62
+ free(common);
63
+ return 0;
64
+ }
65
+ #endif
data/spec/helpers.rb ADDED
@@ -0,0 +1 @@
1
+ $: << File.dirname(__FILE__) + '/../lib'
@@ -0,0 +1,15 @@
1
+ require_relative './helpers'
2
+ require 'subdomainz'
3
+
4
+ describe Subdomainz, ".common_subdomain" do
5
+ it "returns the common parts of the domains, starting from the end" do
6
+ Subdomainz.common_subdomain("x.a.b", "y.a.b").should eq "a.b"
7
+ Subdomainz.common_subdomain("x.z.a", "y.a").should eq "a"
8
+ Subdomainz.common_subdomain("x.z.a.b", "y.z.a.b").should eq "z.a.b"
9
+ end
10
+
11
+ it "returns an empty string if there's nothing in common" do
12
+ Subdomainz.common_subdomain("a.b.c", "d.e.f").should eq ""
13
+ Subdomainz.common_subdomain("a.b", "a.b.x").should eq ""
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'subdomainz'
3
+ s.version = File.read("VERSION").chomp
4
+ s.authors = ['Tom Maher']
5
+ s.email = 'tmaher@tursom.org'
6
+ s.homepage = 'http://github.com/tmaher/subdomainz'
7
+ s.summary = 'Ruby SUBDOMAINZ'
8
+ s.description = 'Ruby SUBDOMAINZ library'
9
+ s.files = `git ls-files`.split("\n")
10
+ s.extensions << 'ext/subdomainz/extconf.rb'
11
+ s.has_rdoc = false
12
+ s.required_ruby_version = '>= 1.8.7'
13
+ s.add_development_dependency 'rake'
14
+ s.add_development_dependency 'rake-compiler', '>=0.6.0'
15
+ s.add_development_dependency 'rspec'
16
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: subdomainz
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tom Maher
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake-compiler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.6.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.6.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Ruby SUBDOMAINZ library
63
+ email: tmaher@tursom.org
64
+ executables: []
65
+ extensions:
66
+ - ext/subdomainz/extconf.rb
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - Gemfile.lock
72
+ - Rakefile
73
+ - VERSION
74
+ - ext/subdomainz/.gitignore
75
+ - ext/subdomainz/extconf.rb
76
+ - ext/subdomainz/subdomainz.c
77
+ - spec/helpers.rb
78
+ - spec/subdomainz_spec.rb
79
+ - subdomainz.gemspec
80
+ homepage: http://github.com/tmaher/subdomainz
81
+ licenses: []
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: 1.8.7
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.23
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Ruby SUBDOMAINZ
104
+ test_files: []