geoipdb 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.rvmrc +1 -0
- data/Gemfile +7 -10
- data/Rakefile +5 -46
- data/ext/geoipdb/ipdb.c +99 -99
- data/geoipdb.gemspec +15 -69
- data/spec/spec_helper.rb +7 -8
- data/tasks/rspec.rake +7 -0
- data/tasks/yard.rake +5 -0
- metadata +35 -106
- data/ext/geoipdb/Makefile +0 -157
- data/ext/geoipdb/build.sh +0 -1
- data/test.rb +0 -9
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create ruby-1.9.3-p286@geoipdb
|
data/Gemfile
CHANGED
@@ -1,13 +1,10 @@
|
|
1
|
-
source
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
1
|
+
source :rubygems
|
5
2
|
|
6
|
-
# Add dependencies to develop your gem here.
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
8
3
|
group :development do
|
9
|
-
gem
|
10
|
-
gem
|
11
|
-
gem
|
12
|
-
gem
|
4
|
+
gem 'bundler'
|
5
|
+
gem 'rake'
|
6
|
+
gem 'redcarpet'
|
7
|
+
gem 'rspec'
|
8
|
+
gem 'simplecov'
|
9
|
+
gem 'yard'
|
13
10
|
end
|
data/Rakefile
CHANGED
@@ -1,49 +1,8 @@
|
|
1
|
-
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'rake'
|
1
|
+
#!/usr/bin/env rake
|
11
2
|
|
12
|
-
require
|
13
|
-
|
14
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
-
gem.name = "geoipdb"
|
16
|
-
gem.homepage = "http://github.com/madvertise/geoipdb"
|
17
|
-
gem.license = "MIT"
|
18
|
-
gem.summary = %Q{Fast (>3 Mio queries/sec!!!) GeoIpDb implementation for Ruby using C-Extensions.}
|
19
|
-
gem.description = %Q{Returns a GeoLocation and additional information for given IP. Reads Data from CSV-Files and uses internal binary caching.}
|
20
|
-
gem.email = "eugeniusmartinus@googlemail.com"
|
21
|
-
gem.authors = ["Eugen Martin", "Martin Karlsch"]
|
22
|
-
gem.extensions = ['ext/geoipdb/extconf.rb']
|
23
|
-
gem.require_paths = ["lib","ext"]
|
24
|
-
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bundler/gem_tasks"
|
27
5
|
|
28
|
-
|
29
|
-
require 'rspec/core/rake_task'
|
30
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
-
end
|
6
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
33
7
|
|
34
|
-
|
35
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
-
spec.rcov = true
|
37
|
-
end
|
38
|
-
|
39
|
-
task :default => :spec
|
40
|
-
|
41
|
-
require 'rake/rdoctask'
|
42
|
-
Rake::RDocTask.new do |rdoc|
|
43
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
-
|
45
|
-
rdoc.rdoc_dir = 'rdoc'
|
46
|
-
rdoc.title = "geoipdb #{version}"
|
47
|
-
rdoc.rdoc_files.include('README*')
|
48
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
-
end
|
8
|
+
task :default => [:spec]
|
data/ext/geoipdb/ipdb.c
CHANGED
@@ -7,59 +7,59 @@
|
|
7
7
|
#include <sys/time.h>
|
8
8
|
|
9
9
|
const char country_iso2_codes[253][3] = { "--","ap","eu","ad","ae","af","ag","ai","al","am","an",
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
10
|
+
"ao","aq","ar","as","at","au","aw","az","ba","bb",
|
11
|
+
"bd","be","bf","bg","bh","bi","bj","bm","bn","bo",
|
12
|
+
"br","bs","bt","bv","bw","by","bz","ca","cc","cd",
|
13
|
+
"cf","cg","ch","ci","ck","cl","cm","cn","co","cr",
|
14
|
+
"cu","cv","cx","cy","cz","de","dj","dk","dm","do",
|
15
|
+
"dz","ec","ee","eg","eh","er","es","et","fi","fj",
|
16
|
+
"fk","fm","fo","fr","fx","ga","gb","gd","ge","gf",
|
17
|
+
"gh","gi","gl","gm","gn","gp","gq","gr","gs","gt",
|
18
|
+
"gu","gw","gy","hk","hm","hn","hr","ht","hu","id",
|
19
|
+
"ie","il","in","io","iq","ir","is","it","jm","jo",
|
20
|
+
"jp","ke","kg","kh","ki","km","kn","kp","kr","kw",
|
21
|
+
"ky","kz","la","lb","lc","li","lk","lr","ls","lt",
|
22
|
+
"lu","lv","ly","ma","mc","md","mg","mh","mk","ml",
|
23
|
+
"mm","mn","mo","mp","mq","mr","ms","mt","mu","mv",
|
24
|
+
"mw","mx","my","mz","na","nc","ne","nf","ng","ni",
|
25
|
+
"nl","no","np","nr","nu","nz","om","pa","pe","pf",
|
26
|
+
"pg","ph","pk","pl","pm","pn","pr","ps","pt","pw",
|
27
|
+
"py","qa","re","ro","ru","rw","sa","sb","sc","sd",
|
28
|
+
"se","sg","sh","si","sj","sk","sl","sm","sn","so",
|
29
|
+
"sr","st","sv","sy","sz","tc","td","tf","tg","th",
|
30
|
+
"tj","tk","tm","tn","to","tl","tr","tt","tv","tw",
|
31
|
+
"tz","ua","ug","um","us","uy","uz","va","vc","ve",
|
32
|
+
"vg","vi","vn","vu","wf","ws","ye","yt","rs","za",
|
33
|
+
"zm","me","zw","a1","a2","o1","ax","gg","im","je",
|
34
34
|
"bl","mf"};
|
35
35
|
|
36
36
|
static const unsigned num_countries = (unsigned)(sizeof(country_iso2_codes)/sizeof(country_iso2_codes[0]));
|
37
37
|
|
38
38
|
const char country_iso3_codes[253][4] = { "--","ap","eu","and","are","afg","atg","aia","alb","arm","ant",
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
39
|
+
"ago","aq","arg","asm","aut","aus","abw","aze","bih","brb",
|
40
|
+
"bgd","bel","bfa","bgr","bhr","bdi","ben","bmu","brn","bol",
|
41
|
+
"bra","bhs","btn","bv","bwa","blr","blz","can","cc","cod",
|
42
|
+
"caf","cog","che","civ","cok","chl","cmr","chn","col","cri",
|
43
|
+
"cub","cpv","cx","cyp","cze","deu","dji","dnk","dma","dom",
|
44
|
+
"dza","ecu","est","egy","esh","eri","esp","eth","fin","fji",
|
45
|
+
"flk","fsm","fro","fra","fx","gab","gbr","grd","geo","guf",
|
46
|
+
"gha","gib","grl","gmb","gin","glp","gnq","grc","gs","gtm",
|
47
|
+
"gum","gnb","guy","hkg","hm","hnd","hrv","hti","hun","idn",
|
48
|
+
"irl","isr","ind","io","irq","irn","isl","ita","jam","jor",
|
49
|
+
"jpn","ken","kgz","khm","kir","com","kna","prk","kor","kwt",
|
50
|
+
"cym","kaz","lao","lbn","lca","lie","lka","lbr","lso","ltu",
|
51
|
+
"lux","lva","lby","mar","mco","mda","mdg","mhl","mkd","mli",
|
52
|
+
"mmr","mng","mac","mnp","mtq","mrt","msr","mlt","mus","mdv",
|
53
|
+
"mwi","mex","mys","moz","nam","ncl","ner","nfk","nga","nic",
|
54
|
+
"nld","nor","npl","nru","niu","nzl","omn","pan","per","pyf",
|
55
|
+
"png","phl","pak","pol","spm","pcn","pri","pse","prt","plw",
|
56
|
+
"pry","qat","reu","rou","rus","rwa","sau","slb","syc","sdn",
|
57
|
+
"swe","sgp","shn","svn","sjm","svk","sle","smr","sen","som",
|
58
|
+
"sur","stp","slv","syr","swz","tca","tcd","tf","tgo","tha",
|
59
|
+
"tjk","tkl","tkm","tun","ton","tls","tur","tto","tuv","twn",
|
60
|
+
"tza","ukr","uga","um","usa","ury","uzb","vat","vct","ven",
|
61
|
+
"vgb","vir","vnm","vut","wlf","wsm","yem","yt","srb","zaf",
|
62
|
+
"zmb","mne","zwe","a1","a2","o1","ala","ggy","imn","jey",
|
63
63
|
"blm","maf"};
|
64
64
|
|
65
65
|
|
@@ -110,34 +110,34 @@ get_time(struct timeval *tim){
|
|
110
110
|
|
111
111
|
unsigned long
|
112
112
|
ip_to_int(const char *addr){
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
113
|
+
unsigned int c, octet, t;
|
114
|
+
unsigned long ipnum;
|
115
|
+
int i = 3;
|
116
|
+
|
117
|
+
octet = ipnum = 0;
|
118
|
+
while ((c = *addr++)) {
|
119
|
+
if (c == '.') {
|
120
|
+
if (octet > 255)
|
121
|
+
return 0;
|
122
|
+
ipnum <<= 8;
|
123
|
+
ipnum += octet;
|
124
|
+
i--;
|
125
|
+
octet = 0;
|
126
|
+
} else {
|
127
|
+
t = octet;
|
128
|
+
octet <<= 3;
|
129
|
+
octet += t;
|
130
|
+
octet += t;
|
131
|
+
c -= '0';
|
132
|
+
if (c > 9)
|
133
|
+
return 0;
|
134
|
+
octet += c;
|
135
|
+
}
|
136
|
+
}
|
137
|
+
if ((octet > 255) || (i != 0))
|
138
|
+
return 0;
|
139
|
+
ipnum <<= 8;
|
140
|
+
return ipnum + octet;
|
141
141
|
}
|
142
142
|
|
143
143
|
|
@@ -166,12 +166,12 @@ unsigned char con_type_to_int(char* con_type) {
|
|
166
166
|
int compare_ranges(const void *fa, const void *fb) {
|
167
167
|
if(fa == NULL)
|
168
168
|
{
|
169
|
-
printf("FA IS NULL!!!\n");
|
169
|
+
if(DEBUG){printf("FA IS NULL!!!\n");}
|
170
170
|
return 0;
|
171
171
|
}
|
172
172
|
if(fb == NULL)
|
173
173
|
{
|
174
|
-
printf("FB IS NULL!!!\n");
|
174
|
+
if(DEBUG){printf("FB IS NULL!!!\n");}
|
175
175
|
return 0;
|
176
176
|
}
|
177
177
|
|
@@ -262,13 +262,13 @@ IpRange* find_range_for_ip(IPDB *db, char *ip) {
|
|
262
262
|
|
263
263
|
if(db == NULL)
|
264
264
|
{
|
265
|
-
printf("ERROR: DB ist NULL! ");
|
265
|
+
if(DEBUG){printf("ERROR: DB ist NULL! \n");}
|
266
266
|
return NULL;
|
267
267
|
}
|
268
268
|
|
269
269
|
if(db->ranges_count == 0)
|
270
270
|
{
|
271
|
-
printf("ERROR: DB has no Ranges Data. Can not search!\n");
|
271
|
+
if(DEBUG){printf("ERROR: DB has no Ranges Data. Can not search!\n");}
|
272
272
|
return NULL;
|
273
273
|
}
|
274
274
|
|
@@ -319,7 +319,7 @@ City * find_city_for_ip_range(IPDB * db, IpRange* range)
|
|
319
319
|
char* find_isp_for_ip_range(IPDB * db, IpRange* range)
|
320
320
|
{
|
321
321
|
if( range == NULL || range->isp_index < 0){
|
322
|
-
printf("Could not find isp for isp_index=%i", range->isp_index);
|
322
|
+
if(DEBUG){printf("Could not find isp for isp_index=%i\n", range->isp_index);}
|
323
323
|
return NULL;
|
324
324
|
}
|
325
325
|
return db->isps[range->isp_index];
|
@@ -346,7 +346,7 @@ isp_index_by_name(IPDB * db, char* isp_name){
|
|
346
346
|
db->isps_count++;
|
347
347
|
return new_index;
|
348
348
|
}else{
|
349
|
-
printf("ERROR: MAX_ISPS_COUNT = %i limit reached - this should not happen
|
349
|
+
if(DEBUG){printf("ERROR: MAX_ISPS_COUNT = %i limit reached - this should not happen!\n", MAX_ISPS_COUNT);}
|
350
350
|
return -1;
|
351
351
|
}
|
352
352
|
}
|
@@ -368,7 +368,7 @@ read_ranges_csv(IPDB * db){
|
|
368
368
|
if(f == NULL)
|
369
369
|
{
|
370
370
|
if(DEBUG)
|
371
|
-
printf("Could not open the CSV-file: %s", db->ranges_csv_file);
|
371
|
+
printf("Could not open the CSV-file: %s\n", db->ranges_csv_file);
|
372
372
|
return;
|
373
373
|
}
|
374
374
|
char line[256];
|
@@ -378,7 +378,7 @@ read_ranges_csv(IPDB * db){
|
|
378
378
|
int city_index;
|
379
379
|
|
380
380
|
char* con_type;
|
381
|
-
|
381
|
+
char* isp_name;
|
382
382
|
uint16 isp_index;
|
383
383
|
|
384
384
|
int invalid_cities_count = 0;
|
@@ -392,7 +392,7 @@ read_ranges_csv(IPDB * db){
|
|
392
392
|
city_index = 0;
|
393
393
|
|
394
394
|
con_type = NULL;
|
395
|
-
|
395
|
+
isp_name = NULL;
|
396
396
|
int16 isp_index = -1;
|
397
397
|
|
398
398
|
if(DEBUG && db->ranges_count % 1000000 == 0)
|
@@ -410,7 +410,7 @@ read_ranges_csv(IPDB * db){
|
|
410
410
|
if(city_index < 0)
|
411
411
|
{
|
412
412
|
if(DEBUG)
|
413
|
-
printf("Could not find city for code: %i", atoi(city_code));
|
413
|
+
printf("Could not find city for code: %i\n", atoi(city_code));
|
414
414
|
invalid_cities_count ++;
|
415
415
|
continue;
|
416
416
|
}else{
|
@@ -424,11 +424,11 @@ read_ranges_csv(IPDB * db){
|
|
424
424
|
db->ranges_count++;
|
425
425
|
}
|
426
426
|
}
|
427
|
-
if(
|
427
|
+
if(DEBUG)
|
428
428
|
{
|
429
|
-
printf("Found invalid cities: %i", invalid_cities_count);
|
429
|
+
if(invalid_cities_count ){printf("Found invalid cities: %i\n", invalid_cities_count);}
|
430
|
+
printf("\n Parsing of %i records needed %.6lf seconds\n", db->ranges_count, get_time(&tim)-t1);
|
430
431
|
}
|
431
|
-
printf("\n Parsing of %i records needed %.6lf seconds\n", db->ranges_count, get_time(&tim)-t1);
|
432
432
|
}
|
433
433
|
|
434
434
|
|
@@ -463,7 +463,7 @@ read_cities_csv(IPDB * db){
|
|
463
463
|
if(f == NULL)
|
464
464
|
{
|
465
465
|
if(DEBUG)
|
466
|
-
printf("Could not open the Cities-CSV-file: %s", db->cities_csv_file);
|
466
|
+
printf("Could not open the Cities-CSV-file: %s\n", db->cities_csv_file);
|
467
467
|
return;
|
468
468
|
}
|
469
469
|
char line[256];
|
@@ -480,7 +480,7 @@ read_cities_csv(IPDB * db){
|
|
480
480
|
{
|
481
481
|
printf("Worked lines: %i\n", i);
|
482
482
|
}
|
483
|
-
|
483
|
+
// COUNTRY,REGION,CITY-NAME,METRO-CODE,CITY-CODE,LATITUDE,LONGITUDE
|
484
484
|
country = strtok(line, CITIES_DELIM);
|
485
485
|
region = strtok(NULL, CITIES_DELIM);
|
486
486
|
name = strtok(NULL, CITIES_DELIM);
|
@@ -506,14 +506,14 @@ read_cities_csv(IPDB * db){
|
|
506
506
|
}
|
507
507
|
|
508
508
|
/**
|
509
|
-
cache-file is an exact binary copy of the ranges+cities-arrays from memory,
|
510
|
-
the layout goes like this:
|
509
|
+
cache-file is an exact binary copy of the ranges+cities-arrays from memory,
|
510
|
+
the layout goes like this:
|
511
511
|
db->cities_count [4 Bytes]
|
512
512
|
db->ranges_count [4 Bytes]
|
513
513
|
|
514
514
|
db->cities [sizeof(City)=24 x db->ranges_count Bytes]
|
515
515
|
db->ranges [sizeof(IpRange)=24 x db->ranges_count Bytes]
|
516
|
-
*/
|
516
|
+
*/
|
517
517
|
void
|
518
518
|
write_cache_file(IPDB * db){
|
519
519
|
struct timeval tim;
|
@@ -524,7 +524,7 @@ write_cache_file(IPDB * db){
|
|
524
524
|
f = fopen(db->cache_file_name, "w");
|
525
525
|
if(f==NULL){
|
526
526
|
if(DEBUG)
|
527
|
-
printf("Could not open Cache-File: %s", db->cache_file_name);
|
527
|
+
printf("Could not open Cache-File: %s\n", db->cache_file_name);
|
528
528
|
return;
|
529
529
|
}
|
530
530
|
if(DEBUG){
|
@@ -570,7 +570,7 @@ read_cache_file(IPDB * db){
|
|
570
570
|
f = fopen(db->cache_file_name, "r");
|
571
571
|
if(f==NULL){
|
572
572
|
if(DEBUG)
|
573
|
-
printf("Could not open Cache-File: %s", db->cache_file_name);
|
573
|
+
printf("Could not open Cache-File: %s\n", db->cache_file_name);
|
574
574
|
return 0;
|
575
575
|
}
|
576
576
|
int cities_header_read = fread(&(db->cities_count), sizeof(db->cities_count),1,f);
|
@@ -580,7 +580,7 @@ read_cache_file(IPDB * db){
|
|
580
580
|
|
581
581
|
if(cities_header_read == 0 || isps_header_read == 0 || ranges_header_read == 0 || db->cities_count == 0 || db->isps_count ==0 || db->ranges_count ==0)
|
582
582
|
{
|
583
|
-
printf("Could not read Cities-Header from Cache-File: %s", db->cache_file_name);
|
583
|
+
if(DEBUG){printf("Could not read Cities-Header from Cache-File: %s\n", db->cache_file_name);}
|
584
584
|
return 0;
|
585
585
|
}
|
586
586
|
if(DEBUG)
|
@@ -593,7 +593,7 @@ read_cache_file(IPDB * db){
|
|
593
593
|
objects_read += fread(db->cities, sizeof(City),db->cities_count,f);
|
594
594
|
|
595
595
|
if(DEBUG)
|
596
|
-
printf("Reading in the isps into preallocated buffer of size: ", sizeof(db->isps));
|
596
|
+
printf("Reading in the isps into preallocated buffer of size: %lu\n", sizeof(db->isps));
|
597
597
|
objects_read += fread(db->isps, MAX_ISP_NAME_LENGTH, db->isps_count,f);
|
598
598
|
|
599
599
|
if(DEBUG)
|
@@ -627,7 +627,7 @@ benchmark_search(IPDB * db,int count){
|
|
627
627
|
|
628
628
|
IPDB * init_db(char * cities_csv_file, char * ranges_csv_file, char * cache_file_name){
|
629
629
|
if(DEBUG)
|
630
|
-
printf("Initializing db");
|
630
|
+
printf("Initializing db\n");
|
631
631
|
IPDB *db;
|
632
632
|
db = (IPDB*)malloc(sizeof(IPDB));
|
633
633
|
if (db == NULL) //no memory left
|
data/geoipdb.gemspec
CHANGED
@@ -1,75 +1,21 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
5
2
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "geoipdb"
|
5
|
+
gem.version = "0.4.3"
|
6
|
+
gem.licenses = ["MIT"]
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
s.date = "2012-05-11"
|
13
|
-
s.description = "Returns a GeoLocation and additional information for given IP. Reads Data from CSV-Files and uses internal binary caching."
|
14
|
-
s.email = "eugeniusmartinus@googlemail.com"
|
15
|
-
s.extensions = ["ext/geoipdb/extconf.rb"]
|
16
|
-
s.extra_rdoc_files = [
|
17
|
-
"LICENSE.txt",
|
18
|
-
"README.markdown"
|
19
|
-
]
|
20
|
-
s.files = [
|
21
|
-
".document",
|
22
|
-
".rspec",
|
23
|
-
"Gemfile",
|
24
|
-
"LICENSE.txt",
|
25
|
-
"README.markdown",
|
26
|
-
"Rakefile",
|
27
|
-
"VERSION",
|
28
|
-
"ext/geoipdb/Makefile",
|
29
|
-
"ext/geoipdb/build.sh",
|
30
|
-
"ext/geoipdb/extconf.rb",
|
31
|
-
"ext/geoipdb/geoipdb.c",
|
32
|
-
"ext/geoipdb/ipdb.c",
|
33
|
-
"ext/geoipdb/ipdb.h",
|
34
|
-
"geoipdb.gemspec",
|
35
|
-
"lib/geoipdb.rb",
|
36
|
-
"sample_data/cities.csv",
|
37
|
-
"sample_data/citiess_corrupt.csv",
|
38
|
-
"sample_data/ip_ranges.csv",
|
39
|
-
"sample_data/ip_ranges_corrupt.csv",
|
40
|
-
"spec/geoipdb_spec.rb",
|
41
|
-
"spec/spec_helper.rb",
|
42
|
-
"test.rb"
|
43
|
-
]
|
44
|
-
s.homepage = "http://github.com/madvertise/geoipdb"
|
45
|
-
s.licenses = ["MIT"]
|
46
|
-
s.require_paths = ["lib", "ext"]
|
47
|
-
s.rubygems_version = "1.8.10"
|
48
|
-
s.summary = "Fast (>3 Mio queries/sec!!!) GeoIpDb implementation for Ruby using C-Extensions."
|
49
|
-
s.test_files = [
|
50
|
-
"spec/geoipdb_spec.rb",
|
51
|
-
"spec/spec_helper.rb"
|
52
|
-
]
|
8
|
+
gem.authors = ["Eugen Martin", "Martin Karlsch"]
|
9
|
+
gem.email = ["eugeniusmartinus@googlemail.com", "martin.karlsch@madvertise.com"]
|
53
10
|
|
54
|
-
|
55
|
-
|
11
|
+
gem.description = "Returns a GeoLocation and additional information for given IP. Reads Data from CSV-Files and uses internal binary caching."
|
12
|
+
gem.summary = "Fast (>3 Mio queries/sec!!!) GeoIpDb implementation for Ruby using C-Extensions."
|
13
|
+
gem.homepage = "http://github.com/madvertise/geoipdb"
|
56
14
|
|
57
|
-
|
58
|
-
s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
|
59
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
61
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
62
|
-
else
|
63
|
-
s.add_dependency(%q<rspec>, ["~> 2.1.0"])
|
64
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
66
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
-
end
|
68
|
-
else
|
69
|
-
s.add_dependency(%q<rspec>, ["~> 2.1.0"])
|
70
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
71
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
72
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
73
|
-
end
|
74
|
-
end
|
15
|
+
gem.extensions = ["ext/geoipdb/extconf.rb"]
|
75
16
|
|
17
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
gem.files = `git ls-files`.split("\n")
|
19
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
gem.require_paths = ["lib", "ext"]
|
21
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
|
1
|
+
require 'rubygems'
|
4
2
|
require 'rspec'
|
5
|
-
require 'lib/geoipdb'
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start
|
6
|
+
|
7
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
8
|
+
$:.unshift(File.dirname(__FILE__) + '/../ext')
|
9
|
+
require 'geoipdb'
|
10
10
|
|
11
11
|
RSpec.configure do |config|
|
12
|
-
|
13
12
|
end
|
data/tasks/rspec.rake
ADDED
data/tasks/yard.rake
ADDED
metadata
CHANGED
@@ -1,104 +1,36 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: geoipdb
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.3
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 4
|
9
|
-
- 2
|
10
|
-
version: 0.4.2
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Eugen Martin
|
14
9
|
- Martin Karlsch
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
- - ~>
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
hash: 11
|
28
|
-
segments:
|
29
|
-
- 2
|
30
|
-
- 1
|
31
|
-
- 0
|
32
|
-
version: 2.1.0
|
33
|
-
requirement: *id001
|
34
|
-
prerelease: false
|
35
|
-
name: rspec
|
36
|
-
type: :development
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
hash: 23
|
44
|
-
segments:
|
45
|
-
- 1
|
46
|
-
- 0
|
47
|
-
- 0
|
48
|
-
version: 1.0.0
|
49
|
-
requirement: *id002
|
50
|
-
prerelease: false
|
51
|
-
name: bundler
|
52
|
-
type: :development
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
|
-
requirements:
|
57
|
-
- - ~>
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
hash: 1
|
60
|
-
segments:
|
61
|
-
- 1
|
62
|
-
- 5
|
63
|
-
- 1
|
64
|
-
version: 1.5.1
|
65
|
-
requirement: *id003
|
66
|
-
prerelease: false
|
67
|
-
name: jeweler
|
68
|
-
type: :development
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
hash: 3
|
76
|
-
segments:
|
77
|
-
- 0
|
78
|
-
version: "0"
|
79
|
-
requirement: *id004
|
80
|
-
prerelease: false
|
81
|
-
name: rcov
|
82
|
-
type: :development
|
83
|
-
description: Returns a GeoLocation and additional information for given IP. Reads Data from CSV-Files and uses internal binary caching.
|
84
|
-
email: eugeniusmartinus@googlemail.com
|
13
|
+
date: 2012-11-14 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: Returns a GeoLocation and additional information for given IP. Reads
|
16
|
+
Data from CSV-Files and uses internal binary caching.
|
17
|
+
email:
|
18
|
+
- eugeniusmartinus@googlemail.com
|
19
|
+
- martin.karlsch@madvertise.com
|
85
20
|
executables: []
|
86
|
-
|
87
|
-
extensions:
|
21
|
+
extensions:
|
88
22
|
- ext/geoipdb/extconf.rb
|
89
|
-
extra_rdoc_files:
|
90
|
-
|
91
|
-
- README.markdown
|
92
|
-
files:
|
23
|
+
extra_rdoc_files: []
|
24
|
+
files:
|
93
25
|
- .document
|
26
|
+
- .gitignore
|
94
27
|
- .rspec
|
28
|
+
- .rvmrc
|
95
29
|
- Gemfile
|
96
30
|
- LICENSE.txt
|
97
31
|
- README.markdown
|
98
32
|
- Rakefile
|
99
33
|
- VERSION
|
100
|
-
- ext/geoipdb/Makefile
|
101
|
-
- ext/geoipdb/build.sh
|
102
34
|
- ext/geoipdb/extconf.rb
|
103
35
|
- ext/geoipdb/geoipdb.c
|
104
36
|
- ext/geoipdb/ipdb.c
|
@@ -111,41 +43,38 @@ files:
|
|
111
43
|
- sample_data/ip_ranges_corrupt.csv
|
112
44
|
- spec/geoipdb_spec.rb
|
113
45
|
- spec/spec_helper.rb
|
114
|
-
-
|
46
|
+
- tasks/rspec.rake
|
47
|
+
- tasks/yard.rake
|
115
48
|
homepage: http://github.com/madvertise/geoipdb
|
116
|
-
licenses:
|
49
|
+
licenses:
|
117
50
|
- MIT
|
118
51
|
post_install_message:
|
119
52
|
rdoc_options: []
|
120
|
-
|
121
|
-
require_paths:
|
53
|
+
require_paths:
|
122
54
|
- lib
|
123
55
|
- ext
|
124
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
57
|
none: false
|
126
|
-
requirements:
|
127
|
-
- -
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
|
130
|
-
segments:
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
segments:
|
131
63
|
- 0
|
132
|
-
|
133
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
hash: 4023628714682434710
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
66
|
none: false
|
135
|
-
requirements:
|
136
|
-
- -
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
|
139
|
-
segments:
|
140
|
-
- 0
|
141
|
-
version: "0"
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
142
71
|
requirements: []
|
143
|
-
|
144
72
|
rubyforge_project:
|
145
|
-
rubygems_version: 1.8.
|
73
|
+
rubygems_version: 1.8.24
|
146
74
|
signing_key:
|
147
75
|
specification_version: 3
|
148
76
|
summary: Fast (>3 Mio queries/sec!!!) GeoIpDb implementation for Ruby using C-Extensions.
|
149
|
-
test_files:
|
77
|
+
test_files:
|
150
78
|
- spec/geoipdb_spec.rb
|
151
79
|
- spec/spec_helper.rb
|
80
|
+
has_rdoc:
|
data/ext/geoipdb/Makefile
DELETED
@@ -1,157 +0,0 @@
|
|
1
|
-
|
2
|
-
SHELL = /bin/sh
|
3
|
-
|
4
|
-
#### Start of system configuration section. ####
|
5
|
-
|
6
|
-
srcdir = .
|
7
|
-
topdir = /Users/eugen/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/i686-darwin10.7.0
|
8
|
-
hdrdir = $(topdir)
|
9
|
-
VPATH = $(srcdir):$(topdir):$(hdrdir)
|
10
|
-
exec_prefix = $(prefix)
|
11
|
-
prefix = $(DESTDIR)/Users/eugen/.rvm/rubies/ree-1.8.7-2011.03
|
12
|
-
sharedstatedir = $(prefix)/com
|
13
|
-
mandir = $(datarootdir)/man
|
14
|
-
psdir = $(docdir)
|
15
|
-
oldincludedir = $(DESTDIR)/usr/include
|
16
|
-
localedir = $(datarootdir)/locale
|
17
|
-
bindir = $(exec_prefix)/bin
|
18
|
-
libexecdir = $(exec_prefix)/libexec
|
19
|
-
sitedir = $(libdir)/ruby/site_ruby
|
20
|
-
htmldir = $(docdir)
|
21
|
-
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
22
|
-
includedir = $(prefix)/include
|
23
|
-
infodir = $(datarootdir)/info
|
24
|
-
vendorlibdir = $(vendordir)/$(ruby_version)
|
25
|
-
sysconfdir = $(prefix)/etc
|
26
|
-
libdir = $(exec_prefix)/lib
|
27
|
-
sbindir = $(exec_prefix)/sbin
|
28
|
-
rubylibdir = $(libdir)/ruby/$(ruby_version)
|
29
|
-
docdir = $(datarootdir)/doc/$(PACKAGE)
|
30
|
-
dvidir = $(docdir)
|
31
|
-
vendordir = $(libdir)/ruby/vendor_ruby
|
32
|
-
datarootdir = $(prefix)/share
|
33
|
-
pdfdir = $(docdir)
|
34
|
-
archdir = $(rubylibdir)/$(arch)
|
35
|
-
sitearchdir = $(sitelibdir)/$(sitearch)
|
36
|
-
datadir = $(datarootdir)
|
37
|
-
localstatedir = $(prefix)/var
|
38
|
-
sitelibdir = $(sitedir)/$(ruby_version)
|
39
|
-
|
40
|
-
CC = gcc
|
41
|
-
LIBRUBY = $(LIBRUBY_A)
|
42
|
-
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
43
|
-
LIBRUBYARG_SHARED =
|
44
|
-
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
45
|
-
|
46
|
-
RUBY_EXTCONF_H =
|
47
|
-
CFLAGS = -fno-common -g -O2 -pipe -fno-common $(cflags)
|
48
|
-
INCFLAGS = $(PREINCFLAGS) -I. -I/opt/local/include -I$(topdir) -I$(hdrdir) -I$(srcdir)
|
49
|
-
DEFS =
|
50
|
-
CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags)
|
51
|
-
CXXFLAGS = $(CFLAGS)
|
52
|
-
ldflags = -L.
|
53
|
-
dldflags =
|
54
|
-
archflag =
|
55
|
-
DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
|
56
|
-
LDSHARED = cc -dynamic -bundle -undefined suppress -flat_namespace
|
57
|
-
AR = ar
|
58
|
-
EXEEXT =
|
59
|
-
|
60
|
-
RUBY_INSTALL_NAME = ruby
|
61
|
-
RUBY_SO_NAME = ruby
|
62
|
-
arch = i686-darwin10.7.0
|
63
|
-
sitearch = i686-darwin10.7.0
|
64
|
-
ruby_version = 1.8
|
65
|
-
ruby = /Users/eugen/.rvm/rubies/ree-1.8.7-2011.03/bin/ruby
|
66
|
-
RUBY = $(ruby)
|
67
|
-
RM = rm -f
|
68
|
-
MAKEDIRS = mkdir -p
|
69
|
-
INSTALL = /usr/bin/install -c
|
70
|
-
INSTALL_PROG = $(INSTALL) -m 0755
|
71
|
-
INSTALL_DATA = $(INSTALL) -m 644
|
72
|
-
COPY = cp
|
73
|
-
|
74
|
-
#### End of system configuration section. ####
|
75
|
-
|
76
|
-
preload =
|
77
|
-
|
78
|
-
libpath = . $(libdir)
|
79
|
-
LIBPATH = -L. -L$(libdir)
|
80
|
-
DEFFILE =
|
81
|
-
|
82
|
-
CLEANFILES = mkmf.log
|
83
|
-
DISTCLEANFILES =
|
84
|
-
|
85
|
-
extout =
|
86
|
-
extout_prefix =
|
87
|
-
target_prefix = /geoipdb
|
88
|
-
LOCAL_LIBS =
|
89
|
-
LIBS = -L/opt/local/lib -ldl -lobjc
|
90
|
-
SRCS = geoipdb.c ipdb.c
|
91
|
-
OBJS = geoipdb.o ipdb.o
|
92
|
-
TARGET = geoipdb
|
93
|
-
DLLIB = $(TARGET).bundle
|
94
|
-
EXTSTATIC =
|
95
|
-
STATIC_LIB =
|
96
|
-
|
97
|
-
BINDIR = $(bindir)
|
98
|
-
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
99
|
-
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
100
|
-
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
101
|
-
|
102
|
-
TARGET_SO = $(DLLIB)
|
103
|
-
CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
|
104
|
-
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
105
|
-
|
106
|
-
all: $(DLLIB)
|
107
|
-
static: $(STATIC_LIB)
|
108
|
-
|
109
|
-
clean:
|
110
|
-
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
111
|
-
|
112
|
-
distclean: clean
|
113
|
-
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
114
|
-
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
115
|
-
|
116
|
-
realclean: distclean
|
117
|
-
install: install-so install-rb
|
118
|
-
|
119
|
-
install-so: $(RUBYARCHDIR)
|
120
|
-
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
121
|
-
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
122
|
-
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
123
|
-
install-rb: pre-install-rb install-rb-default
|
124
|
-
install-rb-default: pre-install-rb-default
|
125
|
-
pre-install-rb: Makefile
|
126
|
-
pre-install-rb-default: Makefile
|
127
|
-
$(RUBYARCHDIR):
|
128
|
-
$(MAKEDIRS) $@
|
129
|
-
|
130
|
-
site-install: site-install-so site-install-rb
|
131
|
-
site-install-so: install-so
|
132
|
-
site-install-rb: install-rb
|
133
|
-
|
134
|
-
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
135
|
-
|
136
|
-
.cc.o:
|
137
|
-
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
138
|
-
|
139
|
-
.cxx.o:
|
140
|
-
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
141
|
-
|
142
|
-
.cpp.o:
|
143
|
-
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
144
|
-
|
145
|
-
.C.o:
|
146
|
-
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
147
|
-
|
148
|
-
.c.o:
|
149
|
-
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
150
|
-
|
151
|
-
$(DLLIB): $(OBJS) Makefile
|
152
|
-
@-$(RM) $@
|
153
|
-
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
$(OBJS): ruby.h defines.h
|
data/ext/geoipdb/build.sh
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
gcc -Wall -o test test.c ipdb.c ipdb.h
|
data/test.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'ext'))
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
|
4
|
-
require 'lib/geoipdb'
|
5
|
-
|
6
|
-
|
7
|
-
db = GeoIpDb.init 'ext/data/cities.csv', 'ext/data/ip_ranges.csv', 'ext/data/ipdb.cache'
|
8
|
-
|
9
|
-
puts db.information_for_ip("165.193.245.54").inspect
|