geoip2_c 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +11 -6
- data/Appraisals +7 -0
- data/Rakefile +1 -0
- data/docker-compose.yml +20 -2
- data/{Dockerfile → dockerfiles/Dockerfile-ruby2.1} +3 -1
- data/dockerfiles/Dockerfile-ruby2.2 +8 -0
- data/dockerfiles/Dockerfile-ruby2.3 +8 -0
- data/ext/geoip2/extconf.rb +1 -0
- data/ext/geoip2/geoip2.c +36 -8
- data/ext/geoip2/rb_compat.h +10 -0
- data/gemfiles/ruby_2.1.gemfile +7 -0
- data/gemfiles/ruby_2.2.gemfile +7 -0
- data/geoip2_c.gemspec +2 -1
- data/lib/geoip2/version.rb +1 -1
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c4c6ed6506390f217b61759fe77b1523f159b7b
|
4
|
+
data.tar.gz: 4ea870d8984e94dd182827b07e5ebce843527ce4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f051648f8cc6144c5d952d455c70684246ee929c2db8d016c0a8b6ac802cd0638ff3f935c455b0205081aa3767c09b14a0bdb946d6fd58c60c0c0d542400133
|
7
|
+
data.tar.gz: 79e2869114777969696d0dcd0f5aeea37dc3245faf734a1595f72cb30543bd7d5e3d1876af313da9f1ba7992ae6377075b8025d2251fa0ef44fb0fba34d13046
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -3,7 +3,12 @@ services:
|
|
3
3
|
- docker
|
4
4
|
|
5
5
|
env:
|
6
|
-
|
6
|
+
global:
|
7
|
+
DOCKER_COMPOSE_VERSION: 1.8.1
|
8
|
+
matrix:
|
9
|
+
- TARGET_RUBY_VERSION=2.1
|
10
|
+
- TARGET_RUBY_VERSION=2.2
|
11
|
+
- TARGET_RUBY_VERSION=2.3
|
7
12
|
|
8
13
|
before_install:
|
9
14
|
#- sudo apt-get update
|
@@ -14,12 +19,12 @@ before_install:
|
|
14
19
|
- sudo mv docker-compose /usr/local/bin/
|
15
20
|
|
16
21
|
before_script:
|
17
|
-
- docker-compose build
|
22
|
+
- docker-compose build test-ruby${TARGET_RUBY_VERSION}
|
18
23
|
- docker-compose ps
|
19
|
-
- docker-compose up -d
|
20
|
-
- docker-compose exec test bundle install
|
21
|
-
- docker-compose exec test bundle exec rake compile
|
24
|
+
- docker-compose up -d test-ruby${TARGET_RUBY_VERSION}
|
25
|
+
- docker-compose exec test-ruby${TARGET_RUBY_VERSION} bundle install
|
26
|
+
- docker-compose exec test-ruby${TARGET_RUBY_VERSION} bundle exec rake compile
|
22
27
|
|
23
28
|
script:
|
24
|
-
- docker-compose exec test bundle exec rake test
|
29
|
+
- docker-compose exec test-ruby${TARGET_RUBY_VERSION} bundle exec rake test
|
25
30
|
|
data/Appraisals
ADDED
data/Rakefile
CHANGED
data/docker-compose.yml
CHANGED
@@ -1,6 +1,24 @@
|
|
1
1
|
version: "2"
|
2
2
|
services:
|
3
|
-
test:
|
3
|
+
test-ruby2.3:
|
4
4
|
build:
|
5
5
|
context: .
|
6
|
-
|
6
|
+
dockerfile: dockerfiles/Dockerfile-ruby2.3
|
7
|
+
command: ruby -run -e httpd .
|
8
|
+
environment:
|
9
|
+
- BUNDLE_GEMFILE=Gemfile
|
10
|
+
test-ruby2.2:
|
11
|
+
build:
|
12
|
+
context: .
|
13
|
+
dockerfile: dockerfiles/Dockerfile-ruby2.2
|
14
|
+
command: ruby -run -e httpd .
|
15
|
+
environment:
|
16
|
+
- BUNDLE_GEMFILE=gemfiles/ruby_2.2.gemfile
|
17
|
+
test-ruby2.1:
|
18
|
+
build:
|
19
|
+
context: .
|
20
|
+
dockerfile: dockerfiles/Dockerfile-ruby2.1
|
21
|
+
command: ruby -run -e httpd .
|
22
|
+
environment:
|
23
|
+
- BUNDLE_GEMFILE=gemfiles/ruby_2.1.gemfile
|
24
|
+
|
data/ext/geoip2/extconf.rb
CHANGED
data/ext/geoip2/geoip2.c
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
#include <ruby/encoding.h>
|
3
3
|
#include <maxminddb.h>
|
4
|
+
#include "rb_compat.h"
|
4
5
|
|
5
6
|
VALUE rb_mGeoIP2;
|
6
7
|
VALUE rb_cGeoIP2Database;
|
@@ -26,9 +27,6 @@ static VALUE rb_geoip2_lr_initialize(VALUE self);
|
|
26
27
|
static VALUE rb_geoip2_lr_get_value(int argc, VALUE *argv, VALUE self);
|
27
28
|
static VALUE rb_geoip2_lr_to_h(VALUE self);
|
28
29
|
|
29
|
-
// static void lookup_result_free(void *pointer);
|
30
|
-
// static size_t lookup_result_size(void *pointer);
|
31
|
-
|
32
30
|
static const rb_data_type_t rb_mmdb_type = {
|
33
31
|
"geoip2/mmdb", {
|
34
32
|
0, mmdb_free, 0,
|
@@ -135,8 +133,11 @@ mmdb_entry_data_decode(MMDB_entry_data_s *entry_data)
|
|
135
133
|
case MMDB_DATA_TYPE_UINT64:
|
136
134
|
return UINT2NUM(entry_data->uint64);
|
137
135
|
case MMDB_DATA_TYPE_UINT128:
|
138
|
-
|
136
|
+
#if !(MMDB_UINT128_IS_BYTE_ARRAY)
|
139
137
|
return UINT2NUM(entry_data->uint128);
|
138
|
+
#else
|
139
|
+
rb_raise(rb_eNotImpError, "TODO: unit8_t[16] -> Integer");
|
140
|
+
#endif
|
140
141
|
case MMDB_DATA_TYPE_ARRAY:
|
141
142
|
/* TODO: not implemented */
|
142
143
|
return Qnil;
|
@@ -306,6 +307,16 @@ rb_geoip2_lr_initialize(VALUE self)
|
|
306
307
|
return Qnil;
|
307
308
|
}
|
308
309
|
|
310
|
+
static inline char*
|
311
|
+
rb_geoip2_lr_arg_convert_to_cstring(VALUE sym_or_str)
|
312
|
+
{
|
313
|
+
if (TYPE(sym_or_str) == T_SYMBOL) {
|
314
|
+
return RSTRING_PTR(rb_sym2str(sym_or_str));
|
315
|
+
} else {
|
316
|
+
return StringValueCStr(sym_or_str);
|
317
|
+
}
|
318
|
+
}
|
319
|
+
|
309
320
|
static VALUE
|
310
321
|
rb_geoip2_lr_get_value(int argc, VALUE *argv, VALUE self)
|
311
322
|
{
|
@@ -321,7 +332,16 @@ rb_geoip2_lr_get_value(int argc, VALUE *argv, VALUE self)
|
|
321
332
|
int status;
|
322
333
|
|
323
334
|
rb_scan_args(argc, argv, "1*", &arg, &rest);
|
324
|
-
|
335
|
+
switch(TYPE(arg)) {
|
336
|
+
case T_STRING:
|
337
|
+
case T_SYMBOL:
|
338
|
+
{
|
339
|
+
break;
|
340
|
+
}
|
341
|
+
default:
|
342
|
+
rb_raise(rb_eArgError, "Expected a String or a Symbol");
|
343
|
+
break;
|
344
|
+
}
|
325
345
|
path = malloc(sizeof(char *) * (RARRAY_LEN(rest) + 2));
|
326
346
|
|
327
347
|
TypedData_Get_Struct(self,
|
@@ -329,11 +349,11 @@ rb_geoip2_lr_get_value(int argc, VALUE *argv, VALUE self)
|
|
329
349
|
&rb_lookup_result_type,
|
330
350
|
result);
|
331
351
|
|
332
|
-
path[i] =
|
352
|
+
path[i] = rb_geoip2_lr_arg_convert_to_cstring(arg);
|
333
353
|
while (RARRAY_LEN(rest) != 0) {
|
334
354
|
++i;
|
335
355
|
e = rb_ary_shift(rest);
|
336
|
-
tmp =
|
356
|
+
tmp = rb_geoip2_lr_arg_convert_to_cstring(e);
|
337
357
|
path[i] = tmp;
|
338
358
|
}
|
339
359
|
|
@@ -345,7 +365,7 @@ rb_geoip2_lr_get_value(int argc, VALUE *argv, VALUE self)
|
|
345
365
|
|
346
366
|
if (status != MMDB_SUCCESS) {
|
347
367
|
free(path);
|
348
|
-
fprintf(stderr, "%s\n", MMDB_strerror(status));
|
368
|
+
/* fprintf(stderr, "%s:%s\n", __FUNCTION__, MMDB_strerror(status)); */
|
349
369
|
return Qnil;
|
350
370
|
}
|
351
371
|
|
@@ -379,9 +399,15 @@ rb_geoip2_lr_to_h(VALUE self)
|
|
379
399
|
MMDB_lookup_result_s *result = NULL;
|
380
400
|
MMDB_entry_data_list_s *entry_data_list = NULL;
|
381
401
|
VALUE hash;
|
402
|
+
VALUE cache;
|
382
403
|
int status = 0;
|
383
404
|
int exception = 0;
|
384
405
|
|
406
|
+
cache = rb_ivar_get(self, rb_intern("rb_hash"));
|
407
|
+
if (!NIL_P(cache)) {
|
408
|
+
return cache;
|
409
|
+
}
|
410
|
+
|
385
411
|
TypedData_Get_Struct(self,
|
386
412
|
struct MMDB_lookup_result_s,
|
387
413
|
&rb_lookup_result_type,
|
@@ -398,6 +424,8 @@ rb_geoip2_lr_to_h(VALUE self)
|
|
398
424
|
rb_jump_tag(exception);
|
399
425
|
}
|
400
426
|
|
427
|
+
rb_ivar_set(self, rb_intern("rb_hash"), hash);
|
428
|
+
|
401
429
|
return hash;
|
402
430
|
}
|
403
431
|
|
data/geoip2_c.gemspec
CHANGED
@@ -15,13 +15,14 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.license = "Apache-2.0"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
-
f.match(%r{^(test|spec|features)/})
|
18
|
+
f.match(%r{^(test|spec|features|benchmark)/})
|
19
19
|
end
|
20
20
|
spec.bindir = "bin"
|
21
21
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
spec.extensions = ["ext/geoip2/extconf.rb"]
|
24
24
|
|
25
|
+
spec.add_development_dependency "appraisal"
|
25
26
|
spec.add_development_dependency "bundler", "~> 1.13"
|
26
27
|
spec.add_development_dependency "rake", "~> 11.0"
|
27
28
|
spec.add_development_dependency "rake-compiler"
|
data/lib/geoip2/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geoip2_c
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- okkez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: appraisal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,14 +91,20 @@ files:
|
|
77
91
|
- ".gitignore"
|
78
92
|
- ".gitmodules"
|
79
93
|
- ".travis.yml"
|
80
|
-
-
|
94
|
+
- Appraisals
|
81
95
|
- Gemfile
|
82
96
|
- LICENSE.txt
|
83
97
|
- README.md
|
84
98
|
- Rakefile
|
85
99
|
- docker-compose.yml
|
100
|
+
- dockerfiles/Dockerfile-ruby2.1
|
101
|
+
- dockerfiles/Dockerfile-ruby2.2
|
102
|
+
- dockerfiles/Dockerfile-ruby2.3
|
86
103
|
- ext/geoip2/extconf.rb
|
87
104
|
- ext/geoip2/geoip2.c
|
105
|
+
- ext/geoip2/rb_compat.h
|
106
|
+
- gemfiles/ruby_2.1.gemfile
|
107
|
+
- gemfiles/ruby_2.2.gemfile
|
88
108
|
- geoip2_c.gemspec
|
89
109
|
- lib/geoip2.rb
|
90
110
|
- lib/geoip2/database.rb
|