Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
pkg/
doc/
/.bundle
/pkg
/doc
mkmf.log
Makefile
conftest.dSYM/
geoip.bundle
geoip.so
geoip.o
Gemfile.lock
/tmp
36 changes: 26 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,39 @@ require 'bundler/gem_tasks'
require 'rake/clean'
require 'rake/testtask'
require 'rdoc/task'
require "rake/extensiontask"

task :default => [:compile, :test]
task :default => [:test]

CLEAN.add "geoip.{o,bundle,so,obj,pdb,lib,def,exp}"
CLOBBER.add ['Makefile', 'mkmf.log','doc']
CLOBBER.add 'doc', 'data'

Rake::RDocTask.new do |rdoc|
rdoc.rdoc_files.add ['README.md', 'geoip.c']
RDoc::Task.new do |rdoc|
rdoc.main = "README.md" # page to start on
rdoc.rdoc_dir = 'doc/' # rdoc output folder
rdoc.rdoc_files.add ["README.md", "ext/geoip/geoip.c"]
rdoc.rdoc_dir = 'doc' # rdoc output folder
end

Rake::TestTask.new do |t|
t.test_files = ['test.rb']
t.verbose = true
end

desc 'compile the extension'
task(:compile => 'Makefile') { sh 'make' }
file('Makefile' => "geoip.c") { ruby 'extconf.rb' }
spec = Gem::Specification.load "geoip-c.gemspec"

Rake::ExtensionTask.new("geoip", spec) do |ext|
end

directory "data"

file "data/GeoLiteCity.dat" => ["data"] do |f|
url = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz"

sh "curl #{url} -o data/GeoLiteCity.dat.gz"
sh "gunzip data/GeoLiteCity.dat.gz"
touch f.name
end

task :database => ["data/GeoLiteCity.dat"] do
ENV['CITY'] = File.expand_path("data/GeoLiteCity.dat")
end

task :test => [:compile, :database]
File renamed without changes.
6 changes: 3 additions & 3 deletions geoip.c → ext/geoip/geoip.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ static VALUE generic_single_value_lookup_response(char *key, char *value)
VALUE rb_city_record_to_hash(GeoIPRecord *record)
{
VALUE hash = rb_hash_new();
char *region_name;

if(record->country_code)
rb_hash_sset(hash, "country_code", encode_to_utf8_and_return_rb_str(record->country_code));
Expand All @@ -147,10 +148,9 @@ VALUE rb_city_record_to_hash(GeoIPRecord *record)
if(record->region) {
rb_hash_sset(hash, "region", encode_to_utf8_and_return_rb_str(record->region));

char *region_name = GeoIP_region_name_by_code(record->country_code, record->region);
if (region_name) {
region_name = GeoIP_region_name_by_code(record->country_code, record->region);
if (region_name)
rb_hash_sset(hash, "region_name", encode_to_utf8_and_return_rb_str(region_name));
}
}
if(record->city)
rb_hash_sset(hash, "city", encode_to_utf8_and_return_rb_str(record->city));
Expand Down
14 changes: 8 additions & 6 deletions geoip-c.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = 'geoip-c'
s.version = "0.9.0"
Expand All @@ -11,11 +13,11 @@ Gem::Specification.new do |s|
s.homepage = "http://github.com/mtodd/geoip"

s.files = `git ls-files`.split("\n")
s.test_files = ['test.rb']
s.extensions = ['extconf.rb']
s.require_path = '.'
s.test_files = ['test/test_geoip.rb']
s.extensions = ["ext/geoip/extconf.rb"]

s.add_development_dependency 'minitest', '~>5.0'
s.add_development_dependency 'rake', '~>10.0'
s.add_development_dependency 'rdoc', '~>4.0'
s.add_development_dependency 'minitest', '~> 5.0'
s.add_development_dependency 'rake', '~> 10.0'
s.add_development_dependency 'rdoc', '~> 4.0'
s.add_development_dependency "rake-compiler", "~> 0.9.1"
end
8 changes: 6 additions & 2 deletions test.rb → test/test_geoip.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# encoding: utf-8

require 'rubygems'
gem 'minitest'
require 'minitest/autorun'
require File.dirname(__FILE__) + '/geoip'
require 'geoip'

CITY_DB = ENV.fetch("CITY", '/usr/local/GeoIP/share/GeoIP/GeoLiteCity.dat')
ORG_DB = ENV.fetch("ORG", '/usr/local/GeoIP/share/GeoIP/GeoIPOrg.dat')
Expand Down Expand Up @@ -124,6 +125,10 @@ def test_empty_region_name_does_not_crash
assert_look_up(db, '119.236.232.169', :region_name, nil)
end

def test_hong_kong_segfault
db = GeoIP::City.new(@dbfile, :filesystem, true)
assert_look_up(db, "61.93.14.4", :country_name, "Hong Kong")
end
end

class GeoIPOrgTest < Minitest::Test
Expand Down Expand Up @@ -170,5 +175,4 @@ def test_bad_db_file
GeoIP::Organization.new('/supposed-to-fail')
end
end

end