geoipdb 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/ext/geoipdb/Makefile +57 -87
- data/ext/geoipdb/geoipdb.c +33 -33
- data/ext/geoipdb/ipdb.c +94 -94
- data/ext/geoipdb/ipdb.h +18 -18
- data/geoipdb.gemspec +8 -8
- data/sample_data/ip_ranges_corrupt.csv +2 -2
- metadata +13 -15
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.1
|
data/ext/geoipdb/Makefile
CHANGED
@@ -4,84 +4,67 @@ SHELL = /bin/sh
|
|
4
4
|
#### Start of system configuration section. ####
|
5
5
|
|
6
6
|
srcdir = .
|
7
|
-
topdir = /Users/eugen/.rvm/rubies/
|
8
|
-
hdrdir =
|
9
|
-
|
10
|
-
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
|
11
|
-
prefix = $(DESTDIR)/Users/eugen/.rvm/rubies/ruby-1.9.2-p180
|
12
|
-
rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
|
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)
|
13
10
|
exec_prefix = $(prefix)
|
14
|
-
|
15
|
-
|
16
|
-
rubyhdrdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version)
|
17
|
-
vendordir = $(rubylibprefix)/vendor_ruby
|
18
|
-
sitedir = $(rubylibprefix)/site_ruby
|
19
|
-
ridir = $(datarootdir)/$(RI_BASE_NAME)
|
11
|
+
prefix = $(DESTDIR)/Users/eugen/.rvm/rubies/ree-1.8.7-2011.03
|
12
|
+
sharedstatedir = $(prefix)/com
|
20
13
|
mandir = $(datarootdir)/man
|
21
|
-
localedir = $(datarootdir)/locale
|
22
|
-
libdir = $(exec_prefix)/lib
|
23
14
|
psdir = $(docdir)
|
24
|
-
pdfdir = $(docdir)
|
25
|
-
dvidir = $(docdir)
|
26
|
-
htmldir = $(docdir)
|
27
|
-
infodir = $(datarootdir)/info
|
28
|
-
docdir = $(datarootdir)/doc/$(PACKAGE)
|
29
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)
|
30
22
|
includedir = $(prefix)/include
|
31
|
-
|
32
|
-
|
23
|
+
infodir = $(datarootdir)/info
|
24
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
33
25
|
sysconfdir = $(prefix)/etc
|
34
|
-
|
35
|
-
datarootdir = $(prefix)/share
|
36
|
-
libexecdir = $(exec_prefix)/libexec
|
26
|
+
libdir = $(exec_prefix)/lib
|
37
27
|
sbindir = $(exec_prefix)/sbin
|
38
|
-
|
39
|
-
|
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)
|
40
34
|
archdir = $(rubylibdir)/$(arch)
|
41
|
-
sitelibdir = $(sitedir)/$(ruby_version)
|
42
35
|
sitearchdir = $(sitelibdir)/$(sitearch)
|
43
|
-
|
44
|
-
|
36
|
+
datadir = $(datarootdir)
|
37
|
+
localstatedir = $(prefix)/var
|
38
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
45
39
|
|
46
40
|
CC = gcc
|
47
|
-
|
48
|
-
LIBRUBY = $(LIBRUBY_SO)
|
41
|
+
LIBRUBY = $(LIBRUBY_A)
|
49
42
|
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
50
|
-
LIBRUBYARG_SHARED =
|
43
|
+
LIBRUBYARG_SHARED =
|
51
44
|
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
52
|
-
OUTFLAG = -o
|
53
|
-
COUTFLAG = -o
|
54
45
|
|
55
46
|
RUBY_EXTCONF_H =
|
56
|
-
|
57
|
-
|
58
|
-
debugflags = -ggdb
|
59
|
-
warnflags = -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long
|
60
|
-
CFLAGS = -fno-common $(cflags) -fno-common -pipe
|
61
|
-
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
|
47
|
+
CFLAGS = -fno-common -g -O2 -pipe -fno-common $(cflags)
|
48
|
+
INCFLAGS = $(PREINCFLAGS) -I. -I/opt/local/include -I$(topdir) -I$(hdrdir) -I$(srcdir)
|
62
49
|
DEFS =
|
63
|
-
CPPFLAGS =
|
64
|
-
CXXFLAGS = $(CFLAGS)
|
65
|
-
ldflags = -L.
|
66
|
-
dldflags =
|
67
|
-
|
68
|
-
DLDFLAGS = $(ldflags) $(dldflags)
|
69
|
-
LDSHARED =
|
70
|
-
LDSHAREDXX = $(CXX) -dynamic -bundle
|
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
|
71
57
|
AR = ar
|
72
58
|
EXEEXT =
|
73
59
|
|
74
|
-
RUBY_BASE_NAME = ruby
|
75
60
|
RUBY_INSTALL_NAME = ruby
|
76
|
-
RUBY_SO_NAME = ruby
|
77
|
-
arch =
|
78
|
-
sitearch =
|
79
|
-
ruby_version = 1.
|
80
|
-
ruby = /Users/eugen/.rvm/rubies/
|
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
|
81
66
|
RUBY = $(ruby)
|
82
67
|
RM = rm -f
|
83
|
-
RM_RF = $(RUBY) -run -e rm -- -rf
|
84
|
-
RMDIRS = $(RUBY) -run -e rmdir -- -p
|
85
68
|
MAKEDIRS = mkdir -p
|
86
69
|
INSTALL = /usr/bin/install -c
|
87
70
|
INSTALL_PROG = $(INSTALL) -m 0755
|
@@ -98,13 +81,12 @@ DEFFILE =
|
|
98
81
|
|
99
82
|
CLEANFILES = mkmf.log
|
100
83
|
DISTCLEANFILES =
|
101
|
-
DISTCLEANDIRS =
|
102
84
|
|
103
85
|
extout =
|
104
86
|
extout_prefix =
|
105
87
|
target_prefix = /geoipdb
|
106
88
|
LOCAL_LIBS =
|
107
|
-
LIBS =
|
89
|
+
LIBS = -L/opt/local/lib -ldl -lobjc
|
108
90
|
SRCS = geoipdb.c ipdb.c
|
109
91
|
OBJS = geoipdb.o ipdb.o
|
110
92
|
TARGET = geoipdb
|
@@ -116,40 +98,28 @@ BINDIR = $(bindir)
|
|
116
98
|
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
117
99
|
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
118
100
|
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
119
|
-
HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
|
120
|
-
ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
|
121
101
|
|
122
102
|
TARGET_SO = $(DLLIB)
|
123
|
-
CLEANLIBS = $(TARGET).bundle
|
124
|
-
CLEANOBJS = *.o
|
125
|
-
|
126
|
-
all:
|
127
|
-
static:
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
clean-rb-default::
|
132
|
-
clean-rb::
|
133
|
-
clean-so::
|
134
|
-
clean: clean-so clean-rb-default clean-rb
|
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:
|
135
110
|
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
136
111
|
|
137
|
-
distclean
|
138
|
-
distclean-rb::
|
139
|
-
distclean-so::
|
140
|
-
distclean: clean distclean-so distclean-rb-default distclean-rb
|
112
|
+
distclean: clean
|
141
113
|
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
142
114
|
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
143
|
-
@-$(RMDIRS) $(DISTCLEANDIRS)
|
144
115
|
|
145
|
-
realclean:
|
116
|
+
realclean: distclean
|
146
117
|
install: install-so install-rb
|
147
118
|
|
148
119
|
install-so: $(RUBYARCHDIR)
|
149
120
|
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
150
121
|
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
151
|
-
|
152
|
-
$(INSTALL_PROG) $(DLLIB) $(@D)
|
122
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
153
123
|
install-rb: pre-install-rb install-rb-default
|
154
124
|
install-rb-default: pre-install-rb-default
|
155
125
|
pre-install-rb: Makefile
|
@@ -164,24 +134,24 @@ site-install-rb: install-rb
|
|
164
134
|
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
165
135
|
|
166
136
|
.cc.o:
|
167
|
-
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS)
|
137
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
168
138
|
|
169
139
|
.cxx.o:
|
170
|
-
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS)
|
140
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
171
141
|
|
172
142
|
.cpp.o:
|
173
|
-
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS)
|
143
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
174
144
|
|
175
145
|
.C.o:
|
176
|
-
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS)
|
146
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
177
147
|
|
178
148
|
.c.o:
|
179
|
-
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS)
|
149
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
180
150
|
|
181
151
|
$(DLLIB): $(OBJS) Makefile
|
182
|
-
@-$(RM)
|
152
|
+
@-$(RM) $@
|
183
153
|
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
184
154
|
|
185
155
|
|
186
156
|
|
187
|
-
$(OBJS):
|
157
|
+
$(OBJS): ruby.h defines.h
|
data/ext/geoipdb/geoipdb.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
+
#include "ruby.h"
|
1
2
|
#include "ipdb.h"
|
2
3
|
|
3
|
-
|
4
|
-
/**
|
4
|
+
/**
|
5
5
|
Ruby Wrapper
|
6
6
|
*/
|
7
7
|
|
@@ -28,8 +28,8 @@ void geoipdb_free(geoipdb *gi) {
|
|
28
28
|
gi->db->ranges = NULL;
|
29
29
|
}
|
30
30
|
if(gi->db != NULL){
|
31
|
-
printf("..freeing ipdb \n");
|
32
|
-
free(gi->db);
|
31
|
+
printf("..freeing ipdb \n");
|
32
|
+
free(gi->db);
|
33
33
|
}
|
34
34
|
}
|
35
35
|
}
|
@@ -37,20 +37,20 @@ void geoipdb_free(geoipdb *gi) {
|
|
37
37
|
|
38
38
|
VALUE ipdb_init(VALUE self, VALUE cities_file_name, VALUE ranges_file_name, VALUE cache_file_name) {
|
39
39
|
geoipdb *gi;
|
40
|
-
|
40
|
+
|
41
41
|
Check_Type(cities_file_name, T_STRING);
|
42
42
|
Check_Type(ranges_file_name, T_STRING);
|
43
43
|
Check_Type(cache_file_name, T_STRING);
|
44
|
-
|
44
|
+
|
45
45
|
char *cities_csv_file = RSTRING_PTR(cities_file_name);
|
46
46
|
char *ranges_csv_file = RSTRING_PTR(ranges_file_name);
|
47
|
-
char *cache_file = RSTRING_PTR(cache_file_name);
|
48
|
-
|
47
|
+
char *cache_file = RSTRING_PTR(cache_file_name);
|
48
|
+
|
49
49
|
gi = ALLOC(geoipdb);
|
50
|
-
|
51
|
-
gi->db= init_db(cities_csv_file, ranges_csv_file, cache_file);
|
52
|
-
|
53
|
-
|
50
|
+
|
51
|
+
gi->db= init_db(cities_csv_file, ranges_csv_file, cache_file);
|
52
|
+
|
53
|
+
|
54
54
|
if(gi->db == NULL)
|
55
55
|
{
|
56
56
|
if(DEBUG)
|
@@ -62,51 +62,51 @@ VALUE ipdb_init(VALUE self, VALUE cities_file_name, VALUE ranges_file_name, VALU
|
|
62
62
|
}else{
|
63
63
|
if(DEBUG)
|
64
64
|
printf("\nDB Init completed!\n");
|
65
|
-
return(Data_Wrap_Struct(cIpDb, 0, geoipdb_free, gi));
|
65
|
+
return(Data_Wrap_Struct(cIpDb, 0, geoipdb_free, gi));
|
66
66
|
}
|
67
67
|
}
|
68
68
|
|
69
|
-
|
69
|
+
|
70
70
|
VALUE build_ip_information_object(IpRange *range, City *city, char* isp) {
|
71
71
|
VALUE CIpInformation;
|
72
|
-
|
72
|
+
|
73
73
|
CIpInformation = rb_const_get(rb_cObject, rb_intern("IpInformation"));
|
74
|
-
|
74
|
+
|
75
75
|
VALUE ip_information = rb_funcall(CIpInformation, rb_intern("new"), 0);
|
76
76
|
rb_ivar_set(ip_information, rb_intern("@country_iso_code"), rb_str_new2(city->country_iso2) );
|
77
|
-
rb_ivar_set(ip_information, rb_intern("@city_name"), rb_str_new2(city->name) );
|
78
|
-
rb_ivar_set(ip_information, rb_intern("@city_code"), INT2FIX(city->city_code) );
|
77
|
+
rb_ivar_set(ip_information, rb_intern("@city_name"), rb_str_new2(city->name) );
|
78
|
+
rb_ivar_set(ip_information, rb_intern("@city_code"), INT2FIX(city->city_code) );
|
79
79
|
rb_ivar_set(ip_information, rb_intern("@lng"), rb_float_new(city->lng) );
|
80
80
|
rb_ivar_set(ip_information, rb_intern("@lat"), rb_float_new(city->lat) );
|
81
81
|
rb_ivar_set(ip_information, rb_intern("@is_mobile"), range->is_mobile == 1 ? Qtrue : Qfalse );
|
82
|
-
rb_ivar_set(ip_information, rb_intern("@isp_name"), isp == NULL ? Qnil : ID2SYM( rb_intern(isp) ) );
|
82
|
+
rb_ivar_set(ip_information, rb_intern("@isp_name"), isp == NULL ? Qnil : ID2SYM( rb_intern(isp) ) );
|
83
83
|
|
84
84
|
return ip_information;
|
85
|
-
}
|
85
|
+
}
|
86
86
|
|
87
87
|
VALUE ipdb_information_for_ip(VALUE self, VALUE ip_string){
|
88
88
|
char *ip = RSTRING_PTR(ip_string);
|
89
|
-
geoipdb *gi;
|
90
|
-
|
89
|
+
geoipdb *gi;
|
90
|
+
|
91
91
|
Data_Get_Struct(self, geoipdb, gi);
|
92
|
-
|
93
|
-
IpRange* ip_range = find_range_for_ip(gi->db, ip);
|
94
|
-
|
92
|
+
|
93
|
+
IpRange* ip_range = find_range_for_ip(gi->db, ip);
|
94
|
+
|
95
95
|
if(!ip_range)
|
96
|
-
return Qnil;
|
97
|
-
|
96
|
+
return Qnil;
|
97
|
+
|
98
98
|
City * city = find_city_for_ip_range(gi->db, ip_range);
|
99
99
|
if(!city)
|
100
|
-
return Qnil;
|
101
|
-
|
100
|
+
return Qnil;
|
101
|
+
|
102
102
|
char* isp = find_isp_for_ip_range(gi->db, ip_range);
|
103
|
-
|
103
|
+
|
104
104
|
return build_ip_information_object(ip_range, city, isp);
|
105
105
|
}
|
106
106
|
|
107
107
|
void Init_geoipdb(void)
|
108
|
-
{
|
108
|
+
{
|
109
109
|
cIpDb = rb_define_class( "GeoIpDb", rb_cObject);
|
110
|
-
rb_define_singleton_method( cIpDb, "init", ipdb_init, 3);
|
111
|
-
rb_define_method( cIpDb, "information_for_ip", ipdb_information_for_ip, 1);
|
110
|
+
rb_define_singleton_method( cIpDb, "init", ipdb_init, 3);
|
111
|
+
rb_define_method( cIpDb, "information_for_ip", ipdb_information_for_ip, 1);
|
112
112
|
}
|
data/ext/geoipdb/ipdb.c
CHANGED
@@ -63,12 +63,12 @@ const char country_iso3_codes[253][4] = { "--","ap","eu","and","are","afg","atg"
|
|
63
63
|
"blm","maf"};
|
64
64
|
|
65
65
|
|
66
|
-
void
|
66
|
+
void
|
67
67
|
print_range(const IpRange* e){
|
68
|
-
printf( "from: %lu, to:%lu ->City-idx: %i \n",e->from, e->to,e->city_index );
|
68
|
+
printf( "from: %lu, to:%lu ->City-idx: %i \n",e->from, e->to,e->city_index );
|
69
69
|
}
|
70
70
|
|
71
|
-
void
|
71
|
+
void
|
72
72
|
print_ranges(IPDB * db){
|
73
73
|
int i;
|
74
74
|
for(i = 0; i < db->ranges_count; ++i)
|
@@ -77,16 +77,16 @@ print_ranges(IPDB * db){
|
|
77
77
|
}
|
78
78
|
}
|
79
79
|
|
80
|
-
void
|
80
|
+
void
|
81
81
|
print_city(const City * e){
|
82
82
|
if(e == NULL)
|
83
83
|
{
|
84
84
|
return;
|
85
85
|
}
|
86
|
-
printf( "City: code:%i, name:%s, country: %s, lat: %10.7f, lng: %10.7f \n",e->city_code, e->name, e->country_iso3, e->lat, e->lng );
|
86
|
+
printf( "City: code:%i, name:%s, country: %s, lat: %10.7f, lng: %10.7f \n",e->city_code, e->name, e->country_iso3, e->lat, e->lng );
|
87
87
|
}
|
88
88
|
|
89
|
-
void
|
89
|
+
void
|
90
90
|
print_cities(IPDB * db){
|
91
91
|
int i;
|
92
92
|
for(i = 0; i < db->cities_count; ++i)
|
@@ -100,10 +100,10 @@ print_cities(IPDB * db){
|
|
100
100
|
void print_stats(IPDB * db){
|
101
101
|
printf("DB STATS: \n");
|
102
102
|
printf("\tCities: %i\n", db->cities_count);
|
103
|
-
printf("\tRanges: %i\n", db->ranges_count);
|
103
|
+
printf("\tRanges: %i\n", db->ranges_count);
|
104
104
|
}
|
105
105
|
|
106
|
-
double
|
106
|
+
double
|
107
107
|
get_time(struct timeval *tim){
|
108
108
|
gettimeofday(tim, NULL);
|
109
109
|
return tim->tv_sec+(tim->tv_usec/1000000.0);
|
@@ -141,7 +141,7 @@ ip_to_int(const char *addr){
|
|
141
141
|
ipnum <<= 8;
|
142
142
|
return ipnum + octet;
|
143
143
|
}
|
144
|
-
|
144
|
+
|
145
145
|
|
146
146
|
unsigned char con_type_to_int(char* con_type) {
|
147
147
|
// possible values
|
@@ -156,13 +156,13 @@ unsigned char con_type_to_int(char* con_type) {
|
|
156
156
|
// oc3
|
157
157
|
// oc12
|
158
158
|
// satellite
|
159
|
-
// wireless
|
159
|
+
// wireless
|
160
160
|
if(strlen(con_type) > 0 && (con_type[0] == 'm'))
|
161
161
|
return 1;
|
162
162
|
return 0;
|
163
163
|
}
|
164
164
|
|
165
|
-
// Function to compare
|
165
|
+
// Function to compare
|
166
166
|
// - either two ip-ranges: i.e.: a(from...to) <=> b(from...to)
|
167
167
|
// - or a ip(i.e. range without to) and an ip-range: i.e. a(from...NULL) <=> b(from...to); a(from...to) <=> b(from ... NULL)
|
168
168
|
int compare_ranges(const void *fa, const void *fb) {
|
@@ -179,7 +179,7 @@ int compare_ranges(const void *fa, const void *fb) {
|
|
179
179
|
|
180
180
|
|
181
181
|
const IpRange *a = (IpRange *) fa;
|
182
|
-
const IpRange *b = (IpRange *) fb;
|
182
|
+
const IpRange *b = (IpRange *) fb;
|
183
183
|
|
184
184
|
// printf("\tComparing: a:");
|
185
185
|
// print_range(a);
|
@@ -218,7 +218,7 @@ int compare_ranges(const void *fa, const void *fb) {
|
|
218
218
|
}
|
219
219
|
|
220
220
|
|
221
|
-
int
|
221
|
+
int
|
222
222
|
compare_cities(const void *a, const void *b){
|
223
223
|
const City city_a = *(City*)a;
|
224
224
|
const City city_b = * (City*) b;
|
@@ -230,26 +230,26 @@ void
|
|
230
230
|
sort_cities(IPDB * db){
|
231
231
|
if(DEBUG)
|
232
232
|
printf("Sorting %i Cities in db...\n", db->cities_count);
|
233
|
-
|
233
|
+
|
234
234
|
struct timeval tim;
|
235
|
-
double t1 = get_time(&tim);
|
236
|
-
|
237
|
-
qsort(db->cities,db->cities_count,sizeof(City), compare_cities);
|
235
|
+
double t1 = get_time(&tim);
|
236
|
+
|
237
|
+
qsort(db->cities,db->cities_count,sizeof(City), compare_cities);
|
238
238
|
if(DEBUG)
|
239
|
-
printf("\n Sorting cities needed %.6lf seconds\n", get_time(&tim)-t1);
|
239
|
+
printf("\n Sorting cities needed %.6lf seconds\n", get_time(&tim)-t1);
|
240
240
|
}
|
241
241
|
|
242
242
|
|
243
|
-
int // returns a city-
|
244
|
-
city_index_by_code(IPDB * db,
|
243
|
+
int // returns a city-index
|
244
|
+
city_index_by_code(IPDB * db, int city_code){
|
245
245
|
City *search, *result;
|
246
246
|
search = malloc(sizeof(City));
|
247
247
|
search->city_code = city_code;
|
248
248
|
result = (City*) bsearch(search, db->cities, db->cities_count, sizeof(City), compare_cities);
|
249
|
-
|
249
|
+
|
250
250
|
if(search != NULL)
|
251
251
|
free(search);
|
252
|
-
|
252
|
+
|
253
253
|
if(result == NULL)
|
254
254
|
{
|
255
255
|
if(DEBUG)
|
@@ -270,19 +270,19 @@ IpRange* find_range_for_ip(IPDB *db, char *ip) {
|
|
270
270
|
IpRange* search;
|
271
271
|
IpRange* result;
|
272
272
|
search = (IpRange *)malloc(sizeof(IpRange));
|
273
|
-
|
273
|
+
|
274
274
|
if(db == NULL)
|
275
275
|
{
|
276
276
|
printf("ERROR: DB ist NULL! ");
|
277
277
|
return NULL;
|
278
278
|
}
|
279
|
-
|
279
|
+
|
280
280
|
if(db->ranges_count == 0)
|
281
281
|
{
|
282
282
|
printf("ERROR: DB has no Ranges Data. Can not search!\n");
|
283
283
|
return NULL;
|
284
284
|
}
|
285
|
-
|
285
|
+
|
286
286
|
search->from = ip_to_int(ip);
|
287
287
|
search->to=0;
|
288
288
|
search->city_index = 0;
|
@@ -291,45 +291,45 @@ IpRange* find_range_for_ip(IPDB *db, char *ip) {
|
|
291
291
|
result = (IpRange*)bsearch(search, db->ranges, db->ranges_count, sizeof(IpRange), compare_ranges);
|
292
292
|
if(search != NULL)
|
293
293
|
free(search);
|
294
|
-
|
294
|
+
|
295
295
|
if(result == NULL)
|
296
|
-
{
|
296
|
+
{
|
297
297
|
if(DEBUG)
|
298
298
|
printf("ERROR: Could not find the IP: %s! THIS SHOULD NOT HAPPEN!\n", ip);
|
299
299
|
return NULL;
|
300
300
|
} else {
|
301
301
|
if(DEBUG) {
|
302
|
-
printf("Found Range: \t");
|
303
|
-
print_range(result);
|
304
|
-
}
|
305
|
-
return (IpRange*)result;
|
302
|
+
printf("Found Range: \t");
|
303
|
+
print_range(result);
|
304
|
+
}
|
305
|
+
return (IpRange*)result;
|
306
306
|
}
|
307
307
|
}
|
308
308
|
|
309
|
-
City * find_city_for_ip_range(IPDB * db, IpRange* range)
|
309
|
+
City * find_city_for_ip_range(IPDB * db, IpRange* range)
|
310
310
|
{
|
311
311
|
if(!db || !range)
|
312
|
-
return NULL;
|
313
|
-
|
312
|
+
return NULL;
|
313
|
+
|
314
314
|
if(db->cities_count == 0)
|
315
315
|
{
|
316
316
|
if(DEBUG)
|
317
317
|
printf("ERROR: DB has no City Data. Can not search!\n");
|
318
318
|
return NULL;
|
319
319
|
}
|
320
|
-
|
321
|
-
if( range->city_index <= 0 || range->city_index >= db->cities_count )
|
320
|
+
|
321
|
+
if( range->city_index <= 0 || range->city_index >= db->cities_count )
|
322
322
|
{
|
323
323
|
if(DEBUG)
|
324
324
|
printf("ERROR: Could not find city with index: %i - THIS SHOULD NOT HAPPEN!\n", range->city_index);
|
325
|
-
}
|
326
|
-
|
325
|
+
}
|
326
|
+
|
327
327
|
return &(db->cities[range->city_index]);
|
328
328
|
}
|
329
329
|
|
330
330
|
char* find_isp_for_ip_range(IPDB * db, IpRange* range)
|
331
331
|
{
|
332
|
-
if( range == NULL || range->isp_index < 0
|
332
|
+
if( range == NULL || range->isp_index < 0){
|
333
333
|
printf("Could not find isp for isp_index=%i", range->isp_index);
|
334
334
|
return NULL;
|
335
335
|
}
|
@@ -367,13 +367,13 @@ isp_index_by_name(IPDB * db, char* isp_name){
|
|
367
367
|
|
368
368
|
// read ip-ranges from csv file, of format:
|
369
369
|
// from_ip|to_ip|contype|city_code
|
370
|
-
void
|
371
|
-
read_ranges_csv(IPDB * db){
|
370
|
+
void
|
371
|
+
read_ranges_csv(IPDB * db){
|
372
372
|
struct timeval tim;
|
373
373
|
double t1 = get_time(&tim);
|
374
374
|
|
375
375
|
db->ranges = malloc(sizeof(IpRange) * db->max_ranges_count);
|
376
|
-
|
376
|
+
|
377
377
|
if(DEBUG)
|
378
378
|
printf("Parsing RANGES-CSV-file: %s\n", db->ranges_csv_file);
|
379
379
|
FILE * f = fopen(db->ranges_csv_file, "rt");
|
@@ -386,7 +386,7 @@ read_ranges_csv(IPDB * db){
|
|
386
386
|
char line[256];
|
387
387
|
char* from;
|
388
388
|
char* to;
|
389
|
-
char* city_code;
|
389
|
+
char* city_code;
|
390
390
|
int city_index;
|
391
391
|
|
392
392
|
char* con_type;
|
@@ -394,7 +394,7 @@ read_ranges_csv(IPDB * db){
|
|
394
394
|
uint16 isp_index;
|
395
395
|
|
396
396
|
int invalid_cities_count = 0;
|
397
|
-
|
397
|
+
|
398
398
|
IpRange* entry;
|
399
399
|
db->ranges_count = 0;
|
400
400
|
while (fgets(line, sizeof(line) ,f) && db->ranges_count < db->max_ranges_count){
|
@@ -428,27 +428,27 @@ read_ranges_csv(IPDB * db){
|
|
428
428
|
}else{
|
429
429
|
entry = &(db->ranges[db->ranges_count]);
|
430
430
|
entry->from = ip_to_int(from);
|
431
|
-
entry->to = ip_to_int(to);
|
431
|
+
entry->to = ip_to_int(to);
|
432
432
|
entry->is_mobile = con_type_to_int(con_type);
|
433
433
|
entry->city_index = city_index;
|
434
434
|
entry->isp_index = isp_index;
|
435
|
-
|
435
|
+
|
436
436
|
// printf("from: %u,to: %u, city_code:%s, city_index: %i\n",entry->from,entry->to,city_code, entry->city_index);
|
437
437
|
// printf("working record nr: %li\n", db->ranges_count);
|
438
438
|
db->ranges_count++;
|
439
439
|
}
|
440
|
-
}
|
440
|
+
}
|
441
441
|
if(invalid_cities_count)
|
442
442
|
{
|
443
443
|
printf("Found invalid cities: %i", invalid_cities_count);
|
444
444
|
}
|
445
|
-
printf("\n Parsing of %i records needed %.6lf seconds\n", db->ranges_count, get_time(&tim)-t1);
|
445
|
+
printf("\n Parsing of %i records needed %.6lf seconds\n", db->ranges_count, get_time(&tim)-t1);
|
446
446
|
}
|
447
447
|
|
448
448
|
|
449
449
|
|
450
450
|
//translate country iso3 to iso2
|
451
|
-
char *
|
451
|
+
char *
|
452
452
|
iso2_code(char* iso3){
|
453
453
|
int i = 0;
|
454
454
|
for( i = 0; i < num_countries; i++)
|
@@ -472,7 +472,7 @@ read_cities_csv(IPDB * db){
|
|
472
472
|
|
473
473
|
db->cities_count = 0;
|
474
474
|
db->cities = malloc(sizeof(City) * db->max_cities_count);
|
475
|
-
|
475
|
+
|
476
476
|
if(DEBUG)
|
477
477
|
printf("Parsing Cities-CSV-file: %s\n", db->cities_csv_file);
|
478
478
|
FILE * f = fopen(db->cities_csv_file, "rt");
|
@@ -497,23 +497,23 @@ read_cities_csv(IPDB * db){
|
|
497
497
|
printf("Worked lines: %i\n", i);
|
498
498
|
}
|
499
499
|
// printf("Line: %s", line);
|
500
|
-
// COUNTRY,REGION,CITY-NAME,METRO-CODE,CITY-CODE,LATITUDE,LONGITUDE
|
500
|
+
// COUNTRY,REGION,CITY-NAME,METRO-CODE,CITY-CODE,LATITUDE,LONGITUDE
|
501
501
|
country = strtok(line, CITIES_DELIM);
|
502
502
|
region = strtok(NULL, CITIES_DELIM);
|
503
503
|
name = strtok(NULL, CITIES_DELIM);
|
504
|
-
metro_code = strtok(NULL, CITIES_DELIM);
|
504
|
+
metro_code = strtok(NULL, CITIES_DELIM);
|
505
505
|
city_code = strtok(NULL, CITIES_DELIM);
|
506
506
|
lat = strtok(NULL, CITIES_DELIM);
|
507
|
-
lng = strtok(NULL, CITIES_DELIM);
|
508
|
-
|
507
|
+
lng = strtok(NULL, CITIES_DELIM);
|
508
|
+
|
509
509
|
entry = &(db->cities[db->cities_count]);
|
510
|
-
|
510
|
+
|
511
511
|
strncpy(entry->country_iso3, country, strlen(country));
|
512
512
|
|
513
|
-
// entry->country_iso2 = iso2_code(entry->country_iso3);
|
513
|
+
// entry->country_iso2 = iso2_code(entry->country_iso3);
|
514
514
|
strncpy(entry->country_iso2, iso2_code(country), 2);
|
515
515
|
strncpy(entry->name, name, strlen(name));
|
516
|
-
|
516
|
+
|
517
517
|
entry->city_code = atoi(city_code);
|
518
518
|
entry->lat = atof(lat);
|
519
519
|
entry->lng = atof(lng);
|
@@ -534,12 +534,12 @@ the layout goes like this:
|
|
534
534
|
db->cities [sizeof(City)=24 x db->ranges_count Bytes]
|
535
535
|
db->ranges [sizeof(IpRange)=24 x db->ranges_count Bytes]
|
536
536
|
*/
|
537
|
-
void
|
537
|
+
void
|
538
538
|
write_cache_file(IPDB * db){
|
539
539
|
struct timeval tim;
|
540
540
|
double t1 = get_time(&tim);
|
541
541
|
int objects_written;
|
542
|
-
|
542
|
+
|
543
543
|
FILE * f;
|
544
544
|
f = fopen(db->cache_file_name, "w");
|
545
545
|
if(f==NULL){
|
@@ -549,43 +549,43 @@ write_cache_file(IPDB * db){
|
|
549
549
|
}
|
550
550
|
if(DEBUG){
|
551
551
|
printf("Dumping %i records to cache-file: %s\n\n", db->ranges_count, db->cache_file_name);
|
552
|
-
|
552
|
+
|
553
553
|
//write the record length at file header
|
554
554
|
printf("Writing DB-Header of length: %li\n",sizeof(db->ranges_count));
|
555
|
-
|
556
|
-
printf("RecordLength: %li\n",sizeof(IpRange));
|
557
|
-
printf("FieldLength: %li\n",sizeof(db->ranges[0].from));
|
555
|
+
|
556
|
+
printf("RecordLength: %li\n",sizeof(IpRange));
|
557
|
+
printf("FieldLength: %li\n",sizeof(db->ranges[0].from));
|
558
558
|
}
|
559
559
|
//write the header: i.e.: numbers of records
|
560
560
|
fwrite(&(db->cities_count), sizeof(db->cities_count),1,f);
|
561
|
-
fwrite(&(db->isps_count), sizeof(db->isps_count),1,f);
|
561
|
+
fwrite(&(db->isps_count), sizeof(db->isps_count),1,f);
|
562
562
|
fwrite(&(db->ranges_count), sizeof(db->ranges_count),1,f);
|
563
|
-
|
563
|
+
|
564
564
|
if(DEBUG)
|
565
|
-
printf("Writing Contents with %i cities, a %li bytes each, should = %li \n", db->cities_count, sizeof(City), db->cities_count * sizeof(City));
|
565
|
+
printf("Writing Contents with %i cities, a %li bytes each, should = %li \n", db->cities_count, sizeof(City), db->cities_count * sizeof(City));
|
566
566
|
//write the actual data: all the ranges-array-buffer:
|
567
567
|
objects_written = fwrite(db->cities, sizeof(City), db->cities_count, f);
|
568
|
-
|
568
|
+
|
569
569
|
if(DEBUG)
|
570
|
-
printf("Writing Contents with %i isps, a %
|
570
|
+
printf("Writing Contents with %i isps, a %i bytes each, should = %i \n", db->isps_count, MAX_ISP_NAME_LENGTH, db->isps_count * MAX_ISP_NAME_LENGTH);
|
571
571
|
//write the actual data: all the ranges-array-buffer:
|
572
572
|
objects_written += fwrite(db->isps, MAX_ISP_NAME_LENGTH, db->isps_count, f);
|
573
|
-
|
573
|
+
|
574
574
|
if(DEBUG)
|
575
|
-
printf("Writing Contents with %i ranges, a %li bytes each, should = %li \n", db->ranges_count, sizeof(IpRange), db->ranges_count * sizeof(IpRange));
|
575
|
+
printf("Writing Contents with %i ranges, a %li bytes each, should = %li \n", db->ranges_count, sizeof(IpRange), db->ranges_count * sizeof(IpRange));
|
576
576
|
//write the actual data: all the ranges-array-buffer:
|
577
577
|
objects_written += fwrite(db->ranges, sizeof(IpRange), db->ranges_count, f);
|
578
|
-
|
578
|
+
|
579
579
|
|
580
580
|
fclose(f);
|
581
|
-
if(DEBUG)
|
582
|
-
printf("\n Writing CacheFile of %i objects needed %.6lf seconds\n", objects_written, get_time(&tim)-t1);
|
581
|
+
if(DEBUG)
|
582
|
+
printf("\n Writing CacheFile of %i objects needed %.6lf seconds\n", objects_written, get_time(&tim)-t1);
|
583
583
|
}
|
584
584
|
|
585
|
-
int
|
586
|
-
read_cache_file(IPDB * db){
|
585
|
+
int
|
586
|
+
read_cache_file(IPDB * db){
|
587
587
|
struct timeval tim;
|
588
|
-
double t1 = get_time(&tim);
|
588
|
+
double t1 = get_time(&tim);
|
589
589
|
FILE * f;
|
590
590
|
f = fopen(db->cache_file_name, "r");
|
591
591
|
if(f==NULL){
|
@@ -594,17 +594,17 @@ read_cache_file(IPDB * db){
|
|
594
594
|
return 0;
|
595
595
|
}
|
596
596
|
int cities_header_read = fread(&(db->cities_count), sizeof(db->cities_count),1,f);
|
597
|
-
int isps_header_read = fread(&(db->isps_count), sizeof(db->isps_count),1,f);
|
597
|
+
int isps_header_read = fread(&(db->isps_count), sizeof(db->isps_count),1,f);
|
598
598
|
int ranges_header_read = fread(&(db->ranges_count), sizeof(db->ranges_count),1,f);
|
599
599
|
|
600
|
-
|
600
|
+
|
601
601
|
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)
|
602
602
|
{
|
603
603
|
printf("Could not read Cities-Header from Cache-File: %s", db->cache_file_name);
|
604
604
|
return 0;
|
605
605
|
}
|
606
|
-
if(DEBUG)
|
607
|
-
printf("Reading DB-Header from Cache-File: %s, with %i cities, %iisps and %i ranges\n",db->cache_file_name, db->cities_count, db->isps_count, db->ranges_count);
|
606
|
+
if(DEBUG)
|
607
|
+
printf("Reading DB-Header from Cache-File: %s, with %i cities, %iisps and %i ranges\n",db->cache_file_name, db->cities_count, db->isps_count, db->ranges_count);
|
608
608
|
|
609
609
|
int objects_read = 0;
|
610
610
|
if(DEBUG)
|
@@ -620,29 +620,29 @@ read_cache_file(IPDB * db){
|
|
620
620
|
printf("Allocating: %lu for ranges-array \n", sizeof(IpRange)*(db->ranges_count));
|
621
621
|
db->ranges = malloc(sizeof(IpRange) * db->ranges_count);
|
622
622
|
objects_read += fread(db->ranges, sizeof(IpRange),db->ranges_count,f);
|
623
|
-
|
623
|
+
|
624
624
|
|
625
625
|
fclose(f);
|
626
|
-
if(DEBUG)
|
627
|
-
printf("Reading cacheFile of %i objects needed %.6lf seconds\n", objects_read, get_time(&tim)-t1);
|
626
|
+
if(DEBUG)
|
627
|
+
printf("Reading cacheFile of %i objects needed %.6lf seconds\n", objects_read, get_time(&tim)-t1);
|
628
628
|
return objects_read;
|
629
629
|
}
|
630
630
|
|
631
|
-
void
|
631
|
+
void
|
632
632
|
benchmark_search(IPDB * db,int count){
|
633
633
|
printf("(Naiv) benchmark of the City-Search-Function with %i counts \n", count);
|
634
|
-
struct timeval tim;
|
634
|
+
struct timeval tim;
|
635
635
|
double t1 = get_time(&tim);
|
636
636
|
int i;
|
637
637
|
City * city;
|
638
638
|
|
639
|
-
for(i=0;i<count; i++){
|
639
|
+
for(i=0;i<count; i++){
|
640
640
|
IpRange* range = find_range_for_ip(db,"278.50.47.0");
|
641
641
|
City* city = find_city_for_ip_range(db,range);
|
642
642
|
}
|
643
643
|
double delta = get_time(&tim)-t1;
|
644
|
-
|
645
|
-
printf("\n\nSearch: %.6lf seconds elapsed, i.e. %.6lf Ops/Second \n", delta, count / delta);
|
644
|
+
|
645
|
+
printf("\n\nSearch: %.6lf seconds elapsed, i.e. %.6lf Ops/Second \n", delta, count / delta);
|
646
646
|
}
|
647
647
|
|
648
648
|
IPDB * init_db(char * cities_csv_file, char * ranges_csv_file, char * cache_file_name){
|
@@ -660,18 +660,18 @@ IPDB * init_db(char * cities_csv_file, char * ranges_csv_file, char * cache_file
|
|
660
660
|
db->max_cities_count = MAX_CITIES_COUNT;
|
661
661
|
db->ranges_csv_file = ranges_csv_file;
|
662
662
|
db->max_ranges_count = MAX_RANGES_COUNT;
|
663
|
-
|
663
|
+
|
664
664
|
// db->isps = NULL;
|
665
|
-
// db->isps = malloc(MAX_ISP_NAME_LENGTH * MAX_ISPS_COUNT);
|
665
|
+
// db->isps = malloc(MAX_ISP_NAME_LENGTH * MAX_ISPS_COUNT);
|
666
666
|
db->isps_count = 0;
|
667
|
-
|
667
|
+
|
668
668
|
|
669
669
|
if(USE_CACHE && read_cache_file(db) > 0){
|
670
670
|
if(DEBUG)
|
671
671
|
printf("Loaded DB from Cache-File with %i records \n", db->ranges_count);
|
672
672
|
}else{
|
673
673
|
if(DEBUG)
|
674
|
-
printf("Initializing IPDB from CSV-file: %s \n", db->ranges_csv_file);
|
674
|
+
printf("Initializing IPDB from CSV-file: %s \n", db->ranges_csv_file);
|
675
675
|
read_cities_csv(db);
|
676
676
|
// print_cities(db);
|
677
677
|
if(db->cities_count == 0)
|
@@ -684,10 +684,10 @@ IPDB * init_db(char * cities_csv_file, char * ranges_csv_file, char * cache_file
|
|
684
684
|
if(db!=NULL && db->ranges_count > 0 && USE_CACHE)
|
685
685
|
{
|
686
686
|
if(DEBUG)
|
687
|
-
printf("Got %i records from CSV-file, writing to cache...\n", db->ranges_count);
|
687
|
+
printf("Got %i records from CSV-file, writing to cache...\n", db->ranges_count);
|
688
688
|
write_cache_file(db);
|
689
689
|
}
|
690
690
|
}
|
691
|
-
return db;
|
691
|
+
return db;
|
692
692
|
}
|
693
693
|
|
data/ext/geoipdb/ipdb.h
CHANGED
@@ -13,18 +13,18 @@ typedef int int32;
|
|
13
13
|
|
14
14
|
#ifdef RSTRING_PTR
|
15
15
|
#else
|
16
|
-
# define RSTRING_LEN(x) (RSTRING(x)->len)
|
17
|
-
# define RSTRING_PTR(x) (RSTRING(x)->ptr)
|
16
|
+
# define RSTRING_LEN(x) (RSTRING(x)->len)
|
17
|
+
# define RSTRING_PTR(x) (RSTRING(x)->ptr)
|
18
18
|
#endif
|
19
19
|
|
20
20
|
|
21
21
|
#define RANGES_DELIM ",\n"
|
22
22
|
#define CITIES_DELIM ",\n"
|
23
23
|
|
24
|
-
#define MAX_CITIES_COUNT
|
25
|
-
#define MAX_RANGES_COUNT 10000000 //Usually we have about 6 Mio IP-Ranges
|
24
|
+
#define MAX_CITIES_COUNT 1000000 //Usually we have about 120 000 Cities
|
25
|
+
#define MAX_RANGES_COUNT 10000000 //Usually we have about 6 Mio IP-Ranges
|
26
26
|
|
27
|
-
#define MAX_ISPS_COUNT
|
27
|
+
#define MAX_ISPS_COUNT 65535
|
28
28
|
#define MAX_ISP_NAME_LENGTH 100
|
29
29
|
|
30
30
|
#define USE_CACHE 1
|
@@ -32,20 +32,20 @@ typedef int int32;
|
|
32
32
|
|
33
33
|
typedef struct{
|
34
34
|
unsigned long from;
|
35
|
-
unsigned long to;
|
35
|
+
unsigned long to;
|
36
36
|
unsigned char is_mobile;
|
37
|
-
|
38
|
-
int16 isp_index; //index of the isp in the isps-array
|
37
|
+
int city_index; //index of the city in the cities-array
|
38
|
+
int16 isp_index; //index of the isp in the isps-array
|
39
39
|
} IpRange;
|
40
40
|
|
41
41
|
typedef struct{
|
42
|
-
|
42
|
+
int city_code;
|
43
43
|
char name[32];
|
44
44
|
double lat;
|
45
45
|
double lng;
|
46
|
-
|
46
|
+
|
47
47
|
char country_iso3[4];
|
48
|
-
char country_iso2[3];
|
48
|
+
char country_iso2[3];
|
49
49
|
} City;
|
50
50
|
|
51
51
|
typedef struct{
|
@@ -54,7 +54,7 @@ typedef struct{
|
|
54
54
|
unsigned int ranges_count;
|
55
55
|
|
56
56
|
char *cities_csv_file;
|
57
|
-
unsigned int cities_count;
|
57
|
+
unsigned int cities_count;
|
58
58
|
unsigned int max_cities_count;
|
59
59
|
|
60
60
|
char *cache_file_name; // a binary file to store the whole db.....
|
@@ -62,27 +62,27 @@ typedef struct{
|
|
62
62
|
City * cities;
|
63
63
|
|
64
64
|
char isps[MAX_ISPS_COUNT][MAX_ISP_NAME_LENGTH]; // a fixed size array of strings should be enough here...do not expect the isps to grow dramatically..
|
65
|
-
uint16 isps_count;
|
65
|
+
uint16 isps_count;
|
66
66
|
|
67
67
|
|
68
68
|
} IPDB;
|
69
69
|
|
70
70
|
|
71
71
|
// "publicly" visible functions
|
72
|
-
IPDB *
|
72
|
+
IPDB *
|
73
73
|
init_db(char * cities_csv_file, char * ranges_csv_file, char * cache_file_name);
|
74
74
|
|
75
75
|
|
76
|
-
void
|
76
|
+
void
|
77
77
|
print_city(const City * e);
|
78
78
|
|
79
|
-
void
|
80
|
-
benchmark_search(IPDB * db,int count);
|
79
|
+
void
|
80
|
+
benchmark_search(IPDB * db,int count);
|
81
81
|
|
82
82
|
IpRange*
|
83
83
|
find_range_for_ip(IPDB *db, char *ip);
|
84
84
|
|
85
|
-
City*
|
85
|
+
City*
|
86
86
|
find_city_for_ip_range(IPDB * db, IpRange* range);
|
87
87
|
|
88
88
|
char*
|
data/geoipdb.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
7
|
+
s.name = "geoipdb"
|
8
|
+
s.version = "0.4.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Eugen Martin", "Martin Karlsch"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2011-11-25"
|
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
15
|
s.extensions = ["ext/geoipdb/extconf.rb"]
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE.txt",
|
@@ -41,11 +41,11 @@ Gem::Specification.new do |s|
|
|
41
41
|
"spec/spec_helper.rb",
|
42
42
|
"test.rb"
|
43
43
|
]
|
44
|
-
s.homepage =
|
44
|
+
s.homepage = "http://github.com/madvertise/geoipdb"
|
45
45
|
s.licenses = ["MIT"]
|
46
46
|
s.require_paths = ["lib", "ext"]
|
47
|
-
s.rubygems_version =
|
48
|
-
s.summary =
|
47
|
+
s.rubygems_version = "1.8.10"
|
48
|
+
s.summary = "Fast (>3 Mio queries/sec!!!) GeoIpDb implementation for Ruby using C-Extensions."
|
49
49
|
s.test_files = [
|
50
50
|
"spec/geoipdb_spec.rb",
|
51
51
|
"spec/spec_helper.rb"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
asdf,as,dsa,g,asdf,g,as,d,ga,sd,f,as,dg,
|
2
2
|
|
3
3
|
|
4
4
|
start_ip,end_ip,field 13,
|
@@ -12,7 +12,7 @@ start_ip,end_ip,field 13,
|
|
12
12
|
|
13
13
|
asfdasdf asdf asfasdfasdf§$%&/
|
14
14
|
|
15
|
-
1, , , 7 ,.1.1.0,1.1.1.255,4,
|
15
|
+
1, , , 7 ,.1.1.0,1.1.1.255,4,,asdf,f,as,df,ag,as,df,asd,
|
16
16
|
1.1.2.0,1.2.2.255,5,
|
17
17
|
1.2.3.0,1.2.3.255,5,
|
18
18
|
1.2.4.0,1.3.255.255,2,
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geoipdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 1
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eugen Martin
|
@@ -16,11 +16,9 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
20
|
-
default_executable:
|
19
|
+
date: 2011-11-25 00:00:00 Z
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
23
|
-
name: rspec
|
24
22
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
23
|
none: false
|
26
24
|
requirements:
|
@@ -32,11 +30,11 @@ dependencies:
|
|
32
30
|
- 1
|
33
31
|
- 0
|
34
32
|
version: 2.1.0
|
33
|
+
requirement: *id001
|
35
34
|
prerelease: false
|
35
|
+
name: rspec
|
36
36
|
type: :development
|
37
|
-
requirement: *id001
|
38
37
|
- !ruby/object:Gem::Dependency
|
39
|
-
name: bundler
|
40
38
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
40
|
requirements:
|
@@ -48,11 +46,11 @@ dependencies:
|
|
48
46
|
- 0
|
49
47
|
- 0
|
50
48
|
version: 1.0.0
|
49
|
+
requirement: *id002
|
51
50
|
prerelease: false
|
51
|
+
name: bundler
|
52
52
|
type: :development
|
53
|
-
requirement: *id002
|
54
53
|
- !ruby/object:Gem::Dependency
|
55
|
-
name: jeweler
|
56
54
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
57
55
|
none: false
|
58
56
|
requirements:
|
@@ -64,11 +62,11 @@ dependencies:
|
|
64
62
|
- 5
|
65
63
|
- 1
|
66
64
|
version: 1.5.1
|
65
|
+
requirement: *id003
|
67
66
|
prerelease: false
|
67
|
+
name: jeweler
|
68
68
|
type: :development
|
69
|
-
requirement: *id003
|
70
69
|
- !ruby/object:Gem::Dependency
|
71
|
-
name: rcov
|
72
70
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
73
71
|
none: false
|
74
72
|
requirements:
|
@@ -78,9 +76,10 @@ dependencies:
|
|
78
76
|
segments:
|
79
77
|
- 0
|
80
78
|
version: "0"
|
79
|
+
requirement: *id004
|
81
80
|
prerelease: false
|
81
|
+
name: rcov
|
82
82
|
type: :development
|
83
|
-
requirement: *id004
|
84
83
|
description: Returns a GeoLocation and additional information for given IP. Reads Data from CSV-Files and uses internal binary caching.
|
85
84
|
email: eugeniusmartinus@googlemail.com
|
86
85
|
executables: []
|
@@ -113,7 +112,6 @@ files:
|
|
113
112
|
- spec/geoipdb_spec.rb
|
114
113
|
- spec/spec_helper.rb
|
115
114
|
- test.rb
|
116
|
-
has_rdoc: true
|
117
115
|
homepage: http://github.com/madvertise/geoipdb
|
118
116
|
licenses:
|
119
117
|
- MIT
|
@@ -144,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
142
|
requirements: []
|
145
143
|
|
146
144
|
rubyforge_project:
|
147
|
-
rubygems_version: 1.
|
145
|
+
rubygems_version: 1.8.10
|
148
146
|
signing_key:
|
149
147
|
specification_version: 3
|
150
148
|
summary: Fast (>3 Mio queries/sec!!!) GeoIpDb implementation for Ruby using C-Extensions.
|