geoip-c 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (9) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -0
  3. data/Changelog.md +5 -0
  4. data/Gemfile +2 -0
  5. data/Rakefile +3 -33
  6. data/geoip-c.gemspec +21 -0
  7. data/geoip.c +26 -2
  8. data/test.rb +44 -40
  9. metadata +59 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91eed9251f7822fa17eb0cea5ebab05b6e51f57c
4
- data.tar.gz: c7aa1ea30ea0f17ae49df12ae3bf6b54fec8f17d
3
+ metadata.gz: ae090a902a2c6012eef837411743d23201d98c3a
4
+ data.tar.gz: e057da0aa1d34651f91a26fa0c3c586529cc493f
5
5
  SHA512:
6
- metadata.gz: 14e5521793aabd18dc0fa7c1a4b19a2b6b73a99060b2d23f5fc3c0dd6ab1ad68405a9dd02f552338aae3b49033f4cce4100ad19c81e374f7ac4056a90b7b277d
7
- data.tar.gz: b0e6944f68b08ad9556692eb149a75c5386964e0f359442fbb799b5db240e8382cf64289d291584ede42aa0ec78f1e2acd1b528142001b7f65f1c324cf1cc5ac
6
+ metadata.gz: 19193af7ae5b8bfb762ab8d4b8a7eecde9c00d776f1c96a2ee3029a05845db26a2525eba3a365f478f2b591cd0ade6ae24c1e49d6942a502b7df2a8ee923c508
7
+ data.tar.gz: e77e7cb91f5e4775a35f8db2962850b9d85141c38ef4ede81a73261d66a7e1468b72e222074056534f73a6b3740361176a27e9ca153e676250fe4a6724b15473
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ pkg/
2
+ doc/
3
+ mkmf.log
4
+ Makefile
5
+ conftest.dSYM/
6
+ geoip.bundle
7
+ geoip.so
8
+ geoip.o
9
+ Gemfile.lock
data/Changelog.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 0.9.0 (21 August 2013)
2
+
3
+ * Returns UTF-8 encoded strings in Ruby 1.9. (Andy Lindeman)
4
+ * Adds license (WTFPL) to gemspec. (Andy Lindeman)
5
+ * Fixes crash if region name cannot be found. (Andy Lindeman)
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'rake'
2
+ require 'bundler/gem_tasks'
2
3
  require 'rake/clean'
3
4
  require 'rake/testtask'
4
5
  require 'rdoc/task'
5
- require 'rubygems/package_task'
6
6
 
7
7
  task :default => [:compile, :test]
8
8
 
@@ -10,8 +10,8 @@ CLEAN.add "geoip.{o,bundle,so,obj,pdb,lib,def,exp}"
10
10
  CLOBBER.add ['Makefile', 'mkmf.log','doc']
11
11
 
12
12
  Rake::RDocTask.new do |rdoc|
13
- rdoc.rdoc_files.add ['README', 'geoip.c']
14
- rdoc.main = "README" # page to start on
13
+ rdoc.rdoc_files.add ['README.md', 'geoip.c']
14
+ rdoc.main = "README.md" # page to start on
15
15
  rdoc.rdoc_dir = 'doc/' # rdoc output folder
16
16
  end
17
17
 
@@ -20,36 +20,6 @@ Rake::TestTask.new do |t|
20
20
  t.verbose = true
21
21
  end
22
22
 
23
- spec = Gem::Specification.new do |s|
24
- s.name = 'geoip-c'
25
- s.version = "0.8.2"
26
-
27
- s.authors = ['Ryah Dahl', 'Matt Todd', 'Andy Lindeman']
28
- s.email = ['alindeman@gmail.com', 'mtodd@highgroove.com']
29
-
30
- s.summary = "A Binding to the GeoIP C library"
31
- s.description = 'Generic GeoIP lookup tool. Based on the geoip_city RubyGem by Ryah Dahl'
32
- s.homepage = "http://github.com/mtodd/geoip"
33
-
34
- s.files = ["Rakefile", "extconf.rb", "test.rb", "geoip.c", "README.md"]
35
- s.test_files = ['test.rb']
36
- s.extensions = ['extconf.rb']
37
- s.require_path = '.'
38
- end
39
-
40
- Gem::PackageTask.new(spec) do |p|
41
- p.need_tar = true
42
- p.gem_spec = spec
43
- end
44
-
45
23
  desc 'compile the extension'
46
24
  task(:compile => 'Makefile') { sh 'make' }
47
25
  file('Makefile' => "geoip.c") { ruby 'extconf.rb' }
48
-
49
- task :install => [:gem] do
50
- `env ARCHFLAGS="-arch i386" gem install pkg/geoip-c-0.8.2.gem -- --with-geoip-dir=/usr/local/GeoIP`
51
- end
52
-
53
- task(:webpage) do
54
- sh 'scp -r doc/* rydahl@rubyforge.org:/var/www/gforge-projects/geoip-city/'
55
- end
data/geoip-c.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'geoip-c'
3
+ s.version = "0.9.0"
4
+ s.licenses = ['WTFPL']
5
+
6
+ s.authors = ['Ryan Dahl', 'Matt Todd', 'Charles Brian Quinn', 'Michael Sheakoski', 'Silvio Quadri', 'Andy Lindeman']
7
+ s.email = ['andy@andylindeman.com', 'mtodd@highgroove.com']
8
+
9
+ s.summary = "A Binding to the GeoIP C library"
10
+ s.description = 'Generic GeoIP lookup tool. Based on the geoip_city RubyGem by Ryan Dahl'
11
+ s.homepage = "http://github.com/mtodd/geoip"
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = ['test.rb']
15
+ s.extensions = ['extconf.rb']
16
+ s.require_path = '.'
17
+
18
+ s.add_development_dependency 'minitest', '~>5.0'
19
+ s.add_development_dependency 'rake', '~>10.0'
20
+ s.add_development_dependency 'rdoc', '~>4.0'
21
+ end
data/geoip.c CHANGED
@@ -10,6 +10,26 @@
10
10
  #include <GeoIPCity.h>
11
11
  #include "iconv.h"
12
12
 
13
+ // String encoding support for 1.9 while maintaining 1.8 compatibility
14
+ // <http://tenderlovemaking.com/2009/06/26/string-encoding-in-ruby-1-9-c-extensions.html>
15
+ #ifdef HAVE_RUBY_ENCODING_H
16
+
17
+ #include <ruby/encoding.h>
18
+ #define ENCODED_STR_NEW2(str, encoding) \
19
+ ({ \
20
+ VALUE _string = rb_str_new2((const char *)str); \
21
+ int _enc = rb_enc_find_index(encoding); \
22
+ rb_enc_associate_index(_string, _enc); \
23
+ _string; \
24
+ })
25
+
26
+ #else
27
+
28
+ #define ENCODED_STR_NEW2(str, encoding) \
29
+ rb_str_new2((const char *)str)
30
+
31
+ #endif
32
+
13
33
  static VALUE mGeoIP;
14
34
  static VALUE mGeoIP_City;
15
35
  static VALUE mGeoIP_Country;
@@ -56,7 +76,7 @@ static VALUE encode_to_utf8_and_return_rb_str(char *value) {
56
76
 
57
77
  *(pOut++) = 0; /* ensure we null terminate */
58
78
 
59
- return rb_str_new2(dst);
79
+ return ENCODED_STR_NEW2(dst, "UTF-8");
60
80
  }
61
81
 
62
82
  int check_load_option(VALUE load_option) {
@@ -126,7 +146,11 @@ VALUE rb_city_record_to_hash(GeoIPRecord *record)
126
146
  rb_hash_sset(hash, "country_name", encode_to_utf8_and_return_rb_str(record->country_name));
127
147
  if(record->region) {
128
148
  rb_hash_sset(hash, "region", encode_to_utf8_and_return_rb_str(record->region));
129
- rb_hash_sset(hash, "region_name", encode_to_utf8_and_return_rb_str(GeoIP_region_name_by_code(record->country_code, record->region)));
149
+
150
+ char *region_name = GeoIP_region_name_by_code(record->country_code, record->region);
151
+ if (region_name) {
152
+ rb_hash_sset(hash, "region_name", encode_to_utf8_and_return_rb_str(region_name));
153
+ }
130
154
  }
131
155
  if(record->city)
132
156
  rb_hash_sset(hash, "city", encode_to_utf8_and_return_rb_str(record->city));
data/test.rb CHANGED
@@ -1,62 +1,60 @@
1
- require 'test/unit'
2
- require File.dirname(__FILE__) + '/geoip'
1
+ # encoding: utf-8
3
2
  require 'rubygems'
4
- # require 'ruby-debug'
5
- # Debugger.start
3
+ gem 'minitest'
4
+ require 'minitest/autorun'
5
+ require File.dirname(__FILE__) + '/geoip'
6
6
 
7
7
  CITY_DB = ENV.fetch("CITY", '/usr/local/GeoIP/share/GeoIP/GeoLiteCity.dat')
8
8
  ORG_DB = ENV.fetch("ORG", '/usr/local/GeoIP/share/GeoIP/GeoIPOrg.dat')
9
9
 
10
- class Test::Unit::TestCase
11
-
10
+ class Minitest::Test
12
11
  def assert_look_up(db, addr, field, value)
13
12
  h = db.look_up(addr)
14
13
  assert_equal value, h[field]
15
14
  h
16
15
  end
17
-
18
16
  end
19
17
 
20
- class GeoIPTest < Test::Unit::TestCase
21
-
18
+ class GeoIPTest < Minitest::Test
19
+
22
20
  def setup
23
21
  @ip = "24.24.24.24"
24
22
  @ipnum = 16777216*24 + 65536*24 + 256*24 + 24
25
-
23
+
26
24
  @large_ip = "245.245.245.245"
27
25
  @large_ipnum = 16777216*245 + 65536*245 + 256*245 + 245
28
26
  end
29
-
27
+
30
28
  # addr_to_num
31
-
29
+
32
30
  def test_addr_to_num_converts_an_ip_to_an_ipnum
33
31
  assert_equal @ipnum, GeoIP.addr_to_num(@ip)
34
32
  end
35
-
33
+
36
34
  def test_addr_to_num_converts_large_ips_to_an_ipnum_correctly
37
35
  assert_equal @large_ipnum, GeoIP.addr_to_num(@large_ip)
38
36
  end
39
-
37
+
40
38
  def test_addr_to_num_expects_an_ip_string
41
- assert_raises TypeError do
42
- GeoIP.addr_to_num(nil)
39
+ assert_raises TypeError do
40
+ GeoIP.addr_to_num(nil)
43
41
  end
44
42
  end
45
-
43
+
46
44
  def test_addr_to_num_returns_zero_for_an_illformed_ip_string
47
45
  assert_equal 0, GeoIP.addr_to_num("foo.bar")
48
46
  end
49
-
47
+
50
48
  # num_to_addr
51
-
49
+
52
50
  def test_num_to_addr_converts_an_ipnum_to_an_ip
53
51
  assert_equal @ip, GeoIP.num_to_addr(@ipnum)
54
52
  end
55
-
53
+
56
54
  def test_num_to_addr_converts_large_ipnums_to_an_ip_correctly
57
55
  assert_equal @large_ip, GeoIP.num_to_addr(@large_ipnum)
58
56
  end
59
-
57
+
60
58
  def test_num_to_addr_expects_a_numeric_ip
61
59
  assert_raises TypeError do
62
60
  GeoIP.num_to_addr(nil)
@@ -65,11 +63,11 @@ class GeoIPTest < Test::Unit::TestCase
65
63
  GeoIP.num_to_addr("foo.bar")
66
64
  end
67
65
  end
68
-
66
+
69
67
  end
70
68
 
71
- class GeoIPCityTest < Test::Unit::TestCase
72
-
69
+ class GeoIPCityTest < Minitest::Test
70
+
73
71
  def setup
74
72
  ## Change me!
75
73
  @dbfile = CITY_DB
@@ -77,36 +75,36 @@ class GeoIPCityTest < Test::Unit::TestCase
77
75
 
78
76
  def test_construction_default
79
77
  db = GeoIP::City.new(@dbfile)
80
-
81
- assert_raises TypeError do
82
- db.look_up(nil)
78
+
79
+ assert_raises TypeError do
80
+ db.look_up(nil)
83
81
  end
84
-
82
+
85
83
  h = db.look_up('24.24.24.24')
86
84
  #debugger
87
85
  assert_kind_of Hash, h
88
- assert_equal 'New York', h[:city]
86
+ assert_equal 'Deer Park', h[:city]
89
87
  assert_equal 'United States', h[:country_name]
90
88
  end
91
89
 
92
90
  def test_construction_index
93
91
  db = GeoIP::City.new(@dbfile, :index)
94
- assert_look_up(db, '24.24.24.24', :city, 'New York')
92
+ assert_look_up(db, '24.24.24.24', :city, 'Deer Park')
95
93
  end
96
94
 
97
95
  def test_construction_filesystem
98
96
  db = GeoIP::City.new(@dbfile, :filesystem)
99
- assert_look_up(db, '24.24.24.24', :city, 'New York')
97
+ assert_look_up(db, '24.24.24.24', :city, 'Deer Park')
100
98
  end
101
99
 
102
100
  def test_construction_memory
103
101
  db = GeoIP::City.new(@dbfile, :memory)
104
- assert_look_up(db, '24.24.24.24', :city, 'New York')
102
+ assert_look_up(db, '24.24.24.24', :city, 'Deer Park')
105
103
  end
106
104
 
107
105
  def test_construction_filesystem_check
108
106
  db = GeoIP::City.new(@dbfile, :filesystem, true)
109
- assert_look_up(db, '24.24.24.24', :city, 'New York')
107
+ assert_look_up(db, '24.24.24.24', :city, 'Deer Park')
110
108
  end
111
109
 
112
110
  def test_bad_db_file
@@ -117,13 +115,19 @@ class GeoIPCityTest < Test::Unit::TestCase
117
115
 
118
116
  def test_character_encoding_converted_to_utf8_first
119
117
  db = GeoIP::City.new(@dbfile, :filesystem, true)
120
- assert_look_up(db, '201.85.50.148', :city, 'São Paulo')
118
+ assert_look_up(db, '201.85.50.148', :city, "Jundiaí")
119
+ end
120
+
121
+ def test_empty_region_name_does_not_crash
122
+ db = GeoIP::City.new(@dbfile, :filesystem, true)
123
+ assert_look_up(db, '119.236.232.169', :region, "00")
124
+ assert_look_up(db, '119.236.232.169', :region_name, nil)
121
125
  end
122
126
 
123
127
  end
124
128
 
125
- class GeoIPOrgTest < Test::Unit::TestCase
126
-
129
+ class GeoIPOrgTest < Minitest::Test
130
+
127
131
  def setup
128
132
  ## Change me!
129
133
  @dbfile = ORG_DB
@@ -131,11 +135,11 @@ class GeoIPOrgTest < Test::Unit::TestCase
131
135
 
132
136
  def test_construction_default
133
137
  db = GeoIP::Organization.new(@dbfile)
134
-
135
- assert_raises TypeError do
136
- db.look_up(nil)
138
+
139
+ assert_raises TypeError do
140
+ db.look_up(nil)
137
141
  end
138
-
142
+
139
143
  h = db.look_up('24.24.24.24')
140
144
  assert_kind_of Hash, h
141
145
  assert_equal 'Road Runner', h[:name]
metadata CHANGED
@@ -1,33 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoip-c
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
- - Ryah Dahl
7
+ - Ryan Dahl
8
8
  - Matt Todd
9
+ - Charles Brian Quinn
10
+ - Michael Sheakoski
11
+ - Silvio Quadri
9
12
  - Andy Lindeman
10
13
  autorequire:
11
14
  bindir: bin
12
15
  cert_chain: []
13
- date: 2013-07-19 00:00:00.000000000 Z
14
- dependencies: []
15
- description: Generic GeoIP lookup tool. Based on the geoip_city RubyGem by Ryah Dahl
16
+ date: 2013-08-21 00:00:00.000000000 Z
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: minitest
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '5.0'
25
+ type: :development
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: '5.0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: rake
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '10.0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '10.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
52
+ version: '4.0'
53
+ type: :development
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: '4.0'
60
+ description: Generic GeoIP lookup tool. Based on the geoip_city RubyGem by Ryan Dahl
16
61
  email:
17
- - alindeman@gmail.com
62
+ - andy@andylindeman.com
18
63
  - mtodd@highgroove.com
19
64
  executables: []
20
65
  extensions:
21
66
  - extconf.rb
22
67
  extra_rdoc_files: []
23
68
  files:
69
+ - .gitignore
70
+ - Changelog.md
71
+ - Gemfile
72
+ - README.md
24
73
  - Rakefile
25
74
  - extconf.rb
26
- - test.rb
75
+ - geoip-c.gemspec
27
76
  - geoip.c
28
- - README.md
77
+ - test.rb
29
78
  homepage: http://github.com/mtodd/geoip
30
- licenses: []
79
+ licenses:
80
+ - WTFPL
31
81
  metadata: {}
32
82
  post_install_message:
33
83
  rdoc_options: []