geoip2_c 0.3.3 → 0.4.0

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.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ubuntu.yml +33 -0
  3. data/.github/workflows/windows.yml +52 -0
  4. data/.gitmodules +0 -3
  5. data/README.md +3 -9
  6. data/docker-compose.yml +7 -0
  7. data/dockerfiles/Dockerfile-ruby2.7 +8 -0
  8. data/ext/geoip2/extconf.rb +9 -18
  9. data/ext/geoip2/geoip2.c +58 -15
  10. data/geoip2_c.gemspec +3 -3
  11. data/lib/geoip2/database.rb +4 -0
  12. data/lib/geoip2/version.rb +1 -1
  13. metadata +28 -103
  14. data/.travis.yml +0 -30
  15. data/Appraisals +0 -7
  16. data/ext/geoip2/libmaxminddb/.gitignore +0 -38
  17. data/ext/geoip2/libmaxminddb/.gitmodules +0 -9
  18. data/ext/geoip2/libmaxminddb/.perltidyrc +0 -11
  19. data/ext/geoip2/libmaxminddb/.travis.yml +0 -70
  20. data/ext/geoip2/libmaxminddb/.uncrustify.cfg +0 -78
  21. data/ext/geoip2/libmaxminddb/AUTHORS +0 -0
  22. data/ext/geoip2/libmaxminddb/Changes.md +0 -277
  23. data/ext/geoip2/libmaxminddb/LICENSE +0 -202
  24. data/ext/geoip2/libmaxminddb/Makefile.am +0 -41
  25. data/ext/geoip2/libmaxminddb/NOTICE +0 -13
  26. data/ext/geoip2/libmaxminddb/README.dev.md +0 -69
  27. data/ext/geoip2/libmaxminddb/README.md +0 -122
  28. data/ext/geoip2/libmaxminddb/appveyor.yml +0 -33
  29. data/ext/geoip2/libmaxminddb/bin/Makefile.am +0 -10
  30. data/ext/geoip2/libmaxminddb/bin/mmdblookup.c +0 -715
  31. data/ext/geoip2/libmaxminddb/bootstrap +0 -21
  32. data/ext/geoip2/libmaxminddb/common.mk +0 -7
  33. data/ext/geoip2/libmaxminddb/configure.ac +0 -132
  34. data/ext/geoip2/libmaxminddb/dev-bin/make-man-pages.pl +0 -76
  35. data/ext/geoip2/libmaxminddb/dev-bin/ppa-release.sh +0 -53
  36. data/ext/geoip2/libmaxminddb/dev-bin/regen-prototypes.pl +0 -136
  37. data/ext/geoip2/libmaxminddb/dev-bin/regen-win32-test-projs.pl +0 -54
  38. data/ext/geoip2/libmaxminddb/dev-bin/release.sh +0 -113
  39. data/ext/geoip2/libmaxminddb/dev-bin/uncrustify-all.sh +0 -21
  40. data/ext/geoip2/libmaxminddb/dev-bin/valgrind-all.pl +0 -53
  41. data/ext/geoip2/libmaxminddb/doc/libmaxminddb.md +0 -889
  42. data/ext/geoip2/libmaxminddb/doc/mmdblookup.md +0 -103
  43. data/ext/geoip2/libmaxminddb/include/maxminddb.h +0 -241
  44. data/ext/geoip2/libmaxminddb/include/maxminddb_config.h.in +0 -14
  45. data/ext/geoip2/libmaxminddb/projects/VS12/README.md +0 -59
  46. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb-release.props +0 -32
  47. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb-x64.props +0 -14
  48. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.props +0 -32
  49. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.sln +0 -150
  50. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj +0 -143
  51. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj.filters +0 -32
  52. data/ext/geoip2/libmaxminddb/projects/VS12/maxminddb_config.h +0 -14
  53. data/ext/geoip2/libmaxminddb/projects/VS12-tests/bad_pointers.vcxproj +0 -105
  54. data/ext/geoip2/libmaxminddb/projects/VS12-tests/basic_lookup.vcxproj +0 -105
  55. data/ext/geoip2/libmaxminddb/projects/VS12-tests/data_entry_list.vcxproj +0 -105
  56. data/ext/geoip2/libmaxminddb/projects/VS12-tests/data_types.vcxproj +0 -105
  57. data/ext/geoip2/libmaxminddb/projects/VS12-tests/dump.vcxproj +0 -105
  58. data/ext/geoip2/libmaxminddb/projects/VS12-tests/get_value.vcxproj +0 -105
  59. data/ext/geoip2/libmaxminddb/projects/VS12-tests/get_value_pointer_bug.vcxproj +0 -105
  60. data/ext/geoip2/libmaxminddb/projects/VS12-tests/ipv4_start_cache.vcxproj +0 -105
  61. data/ext/geoip2/libmaxminddb/projects/VS12-tests/ipv6_lookup_in_ipv4.vcxproj +0 -105
  62. data/ext/geoip2/libmaxminddb/projects/VS12-tests/libtap.vcxproj +0 -85
  63. data/ext/geoip2/libmaxminddb/projects/VS12-tests/maxminddb_test_helper.vcxproj +0 -107
  64. data/ext/geoip2/libmaxminddb/projects/VS12-tests/metadata.vcxproj +0 -105
  65. data/ext/geoip2/libmaxminddb/projects/VS12-tests/metadata_pointers.vcxproj +0 -105
  66. data/ext/geoip2/libmaxminddb/projects/VS12-tests/no_map_get_value.vcxproj +0 -105
  67. data/ext/geoip2/libmaxminddb/projects/VS12-tests/read_node.vcxproj +0 -105
  68. data/ext/geoip2/libmaxminddb/projects/VS12-tests/shared.vcxproj +0 -104
  69. data/ext/geoip2/libmaxminddb/projects/VS12-tests/threads.vcxproj +0 -103
  70. data/ext/geoip2/libmaxminddb/projects/VS12-tests/version.vcxproj +0 -105
  71. data/ext/geoip2/libmaxminddb/projects/test.vcxproj.template +0 -105
  72. data/ext/geoip2/libmaxminddb/src/Makefile.am +0 -25
  73. data/ext/geoip2/libmaxminddb/src/data-pool.c +0 -180
  74. data/ext/geoip2/libmaxminddb/src/data-pool.h +0 -52
  75. data/ext/geoip2/libmaxminddb/src/libmaxminddb.pc.in +0 -11
  76. data/ext/geoip2/libmaxminddb/src/maxminddb-compat-util.h +0 -167
  77. data/ext/geoip2/libmaxminddb/src/maxminddb.c +0 -2181
  78. data/ext/geoip2/libmaxminddb/t/Makefile.am +0 -27
  79. data/ext/geoip2/libmaxminddb/t/bad_databases_t.c +0 -67
  80. data/ext/geoip2/libmaxminddb/t/bad_pointers_t.c +0 -53
  81. data/ext/geoip2/libmaxminddb/t/basic_lookup_t.c +0 -207
  82. data/ext/geoip2/libmaxminddb/t/compile_c++_t.pl +0 -107
  83. data/ext/geoip2/libmaxminddb/t/data-pool-t.c +0 -374
  84. data/ext/geoip2/libmaxminddb/t/data_entry_list_t.c +0 -353
  85. data/ext/geoip2/libmaxminddb/t/data_types_t.c +0 -439
  86. data/ext/geoip2/libmaxminddb/t/dump_t.c +0 -103
  87. data/ext/geoip2/libmaxminddb/t/external_symbols_t.pl +0 -106
  88. data/ext/geoip2/libmaxminddb/t/get_value_pointer_bug_t.c +0 -66
  89. data/ext/geoip2/libmaxminddb/t/get_value_t.c +0 -249
  90. data/ext/geoip2/libmaxminddb/t/ipv4_start_cache_t.c +0 -36
  91. data/ext/geoip2/libmaxminddb/t/ipv6_lookup_in_ipv4_t.c +0 -48
  92. data/ext/geoip2/libmaxminddb/t/maxminddb_test_helper.c +0 -255
  93. data/ext/geoip2/libmaxminddb/t/maxminddb_test_helper.h +0 -69
  94. data/ext/geoip2/libmaxminddb/t/metadata_pointers_t.c +0 -32
  95. data/ext/geoip2/libmaxminddb/t/metadata_t.c +0 -226
  96. data/ext/geoip2/libmaxminddb/t/mmdblookup_t.pl +0 -158
  97. data/ext/geoip2/libmaxminddb/t/no_map_get_value_t.c +0 -32
  98. data/ext/geoip2/libmaxminddb/t/read_node_t.c +0 -157
  99. data/ext/geoip2/libmaxminddb/t/threads_t.c +0 -196
  100. data/ext/geoip2/libmaxminddb/t/version_t.c +0 -10
  101. data/gemfiles/ruby_2.1.gemfile +0 -7
  102. data/gemfiles/ruby_2.2.gemfile +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa4074dbeab86f3881d576390460438107cd9d3d156d1a3da9813b2f5dc1f890
4
- data.tar.gz: 94a44a7f48e4b69742c659b473b60baad893df2cf938db6e49d7ee7388a6fbe4
3
+ metadata.gz: '08ccfe015bb26a4af300f07f11c20ff027b4de7ee76413755df7d8a7c1e74822'
4
+ data.tar.gz: 282c25e8603af880c2bd7dc081c7792c1337a09d6421c4738bc78f02b005b158
5
5
  SHA512:
6
- metadata.gz: 2a338f192553f75914d5c5bfe72c26be5aea555df7c6416406751521f35445d36c06c99c0ea3aa58f11b9f635dc8f4e8f85a5ac2b03f402be8c9295d655ff41b
7
- data.tar.gz: 758c468308389d460bdf3633afb824079188ce3ecc4cc05e2f76365c3adcbd3cbf158d6129cade3627177dda6f238b2e29d5b77bed044f2493b6587fcb577941
6
+ metadata.gz: 8bdd737733f0dff3b8691c5b33fcb823b03111af2c09c0fac3c59e12430c55a5b1c46fd9fd19d3fd1a5caa26559f280ad291031d05af76383e67f69450260ff7
7
+ data.tar.gz: 773ce3df6dbf835c00267c24c45588efdfc81a2934b839741d80445f401fa0dba56025863745fec01939b4f1fbba3b755e80130697e584a78eff7f3ed023a1c2
@@ -0,0 +1,33 @@
1
+ name: ubuntu
2
+
3
+ on:
4
+ - push
5
+ - pull_request
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+ strategy:
11
+ matrix:
12
+ ruby:
13
+ - "3.2"
14
+ - "3.1"
15
+ - "3.0"
16
+ steps:
17
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
18
+ with:
19
+ submodules: true
20
+ - name: Setup ruby
21
+ uses: ruby/setup-ruby@09a7688d3b55cf0e976497ff046b70949eeaccfd # v1.288.0
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler: latest
25
+ bundler-cache: true
26
+ - name: Install dependencies
27
+ run: |
28
+ sudo apt-get update
29
+ sudo apt-get install -y -qq build-essential automake autoconf libtool
30
+ - name: Build
31
+ run: bundle exec rake compile
32
+ - name: Run test
33
+ run: bundle exec rake test
@@ -0,0 +1,52 @@
1
+ name: windows
2
+
3
+ on:
4
+ - push
5
+ - pull_request
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: windows-latest
10
+ strategy:
11
+ matrix:
12
+ ruby:
13
+ - "3.2"
14
+ - "3.1"
15
+ include:
16
+ - ruby: "3.0.3"
17
+ # On Ruby 3.0, we need to use fiddle 1.0.8 or later to retrieve correct
18
+ # error code. In addition, we have to specify the path of fiddle by RUBYLIB
19
+ # because RubyInstaller loads Ruby's bundled fiddle before initializing gem.
20
+ # See also:
21
+ # * https://github.com/ruby/fiddle/issues/72
22
+ # * https://bugs.ruby-lang.org/issues/17813
23
+ # * https://github.com/oneclick/rubyinstaller2/blob/8225034c22152d8195bc0aabc42a956c79d6c712/lib/ruby_installer/build/dll_directory.rb
24
+ ruby-lib-opt: RUBYLIB=%RUNNER_TOOL_CACHE%/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/fiddle-1.1.0/lib
25
+ steps:
26
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
27
+ with:
28
+ submodules: true
29
+ - name: Install dependencies
30
+ run: |
31
+ ridk enable
32
+ pacman -Sy --noconfirm mingw-w64-x86_64-libmaxminddb
33
+ - name: Setup ruby
34
+ uses: ruby/setup-ruby@09a7688d3b55cf0e976497ff046b70949eeaccfd # v1.288.0
35
+ with:
36
+ ruby-version: ${{ matrix.ruby }}
37
+ bundler: latest
38
+ bundler-cache: true
39
+ - name: Check Ruby version
40
+ run: |
41
+ ruby -v
42
+ - name: Add Fiddle 1.1.0
43
+ if: ${{ matrix.ruby == '3.0.3' }}
44
+ run: gem install fiddle --version 1.1.0
45
+ - name: Build
46
+ run: |
47
+ ridk enable
48
+ bundle exec rake compile
49
+ - name: Run test
50
+ run: |
51
+ ridk enable
52
+ bundle exec rake test
data/.gitmodules CHANGED
@@ -1,6 +1,3 @@
1
1
  [submodule "test/MaxMind-DB"]
2
2
  path = test/MaxMind-DB
3
3
  url = https://github.com/maxmind/MaxMind-DB.git
4
- [submodule "ext/geoip2/libmaxminddb"]
5
- path = ext/geoip2/libmaxminddb
6
- url = https://github.com/maxmind/libmaxminddb.git
data/README.md CHANGED
@@ -5,15 +5,9 @@ This gem provides binding of [libmaxminddb](http://maxmind.github.io/libmaxmindd
5
5
  This binding does not traverse all elements in lookup result by default.
6
6
  So you can get the element you want fast such as city name, country name or etc.
7
7
 
8
- ## Requirements
8
+ ## Supported Ruby versions
9
9
 
10
- * Ruby 2.3 or later
11
-
12
- NOTE:
13
-
14
- This library uses `Hash#dig` and `Array#dig`.
15
- If you want to use this library with Ruby2.1 or Ruby2.2, you can install a gem which adds support `#dig` method.
16
- But I don't want to add extra dependency to this library, so I decided not to add extra dependency to support old Ruby versions.
10
+ See [workflows](https://github.com/fluent-plugins-nursery/geoip2_c/blob/master/.github/workflows/ubuntu.yml)
17
11
 
18
12
  ## Build requirements
19
13
 
@@ -68,7 +62,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
68
62
 
69
63
  ## Contributing
70
64
 
71
- Bug reports and pull requests are welcome on GitHub at https://github.com/okkez/geoip2_c.
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fluent-plugins-nursery/geoip2_c.
72
66
 
73
67
  ## License
74
68
 
data/docker-compose.yml CHANGED
@@ -1,5 +1,12 @@
1
1
  version: "3"
2
2
  services:
3
+ test-ruby2.7:
4
+ build:
5
+ context: .
6
+ dockerfile: dockerfiles/Dockerfile-ruby2.7
7
+ command: tail -f /dev/null
8
+ environment:
9
+ - BUNDLE_GEMFILE=Gemfile
3
10
  test-ruby2.6:
4
11
  build:
5
12
  context: .
@@ -0,0 +1,8 @@
1
+ FROM ruby:2.7-alpine
2
+
3
+ ENV BUNDLE_GEMFILE=$BUNDLE_GEMFILE
4
+
5
+ RUN apk --no-cache --update add build-base autoconf automake libtool ruby-dev libc6-compat git
6
+
7
+ WORKDIR /app
8
+ COPY . .
@@ -1,26 +1,17 @@
1
1
  require "mkmf"
2
- require "rbconfig"
2
+ require "mini_portile2"
3
3
 
4
- libdir = RbConfig::CONFIG["libdir"]
5
- includedir = RbConfig::CONFIG["includedir"]
4
+ maxminddb_version = "1.13.3"
6
5
 
7
- maxminddb_dir = File.expand_path(File.join(__dir__, "libmaxminddb"))
6
+ recipe = MiniPortile.new("libmaxminddb", maxminddb_version)
7
+ recipe.files = ["https://github.com/maxmind/libmaxminddb/releases/download/#{maxminddb_version}/libmaxminddb-#{maxminddb_version}.tar.gz"]
8
+ recipe.cook
9
+ recipe.activate
8
10
 
9
- Dir.chdir(maxminddb_dir) do
10
- system("./bootstrap")
11
- system({ "CFLAGS" => "-fPIC" }, "./configure", "--disable-shared", "--disable-tests")
12
- system("make", "clean")
13
- system("make")
14
- end
11
+ $INCFLAGS = "-I#{File.join(recipe.path, 'include')} " + $INCFLAGS
12
+ $LDFLAGS << " -L#{File.join(recipe.path, 'lib')} -lmaxminddb"
13
+ $CFLAGS << " -std=c99 -fPIC -fms-extensions -I#{File.join(recipe.path, 'include')}"
15
14
 
16
- header_dirs = [includedir, "#{maxminddb_dir}/include"]
17
- lib_dirs = [libdir, "#{maxminddb_dir}/src/.libs"]
18
-
19
- dir_config("maxminddb", header_dirs, lib_dirs)
20
15
  have_func("rb_sym2str", "ruby.h")
21
16
 
22
- $LDFLAGS << " -L#{maxminddb_dir}/src/.libs -lmaxminddb"
23
- $CFLAGS << " -std=c99 -fPIC -fms-extensions -I#{maxminddb_dir}/src/.libs"
24
- # $CFLAGS << " -g -O0"
25
-
26
17
  create_makefile("geoip2/geoip2")
data/ext/geoip2/geoip2.c CHANGED
@@ -15,10 +15,11 @@ static void mmdb_free(void *mmdb);
15
15
  static MMDB_lookup_result_s mmdb_lookup(MMDB_s *mmdb, const char *ip_str, bool cleanup);
16
16
  static VALUE mmdb_entry_data_decode(MMDB_entry_data_s *entry_data);
17
17
  static VALUE mmdb_guard_parse_entry_data_list(VALUE ptr);
18
- static MMDB_entry_data_list_s *mmdb_parse_entry_data_list(MMDB_entry_data_list_s *data_list, VALUE *obj);
18
+ static MMDB_entry_data_list_s *mmdb_parse_entry_data_list(MMDB_entry_data_list_s *data_list, bool symbolize_keys, VALUE *obj);
19
19
 
20
20
  static VALUE rb_geoip2_db_alloc(VALUE klass);
21
- static VALUE rb_geoip2_db_initialize(VALUE self, VALUE path);
21
+ static VALUE rb_geoip2_db_initialize(int argc, VALUE* argv, VALUE self);
22
+
22
23
  static VALUE rb_geoip2_db_close(VALUE self);
23
24
  static VALUE rb_geoip2_db_lookup(VALUE self, VALUE ip);
24
25
 
@@ -27,6 +28,11 @@ static VALUE rb_geoip2_lr_initialize(VALUE self);
27
28
  static VALUE rb_geoip2_lr_get_value(int argc, VALUE *argv, VALUE self);
28
29
  static VALUE rb_geoip2_lr_to_h(VALUE self);
29
30
 
31
+ typedef struct {
32
+ struct MMDB_entry_data_list_s* data_list;
33
+ bool symbolize_keys;
34
+ } ParseRequest;
35
+
30
36
  static const rb_data_type_t rb_mmdb_type = {
31
37
  "geoip2/mmdb", {
32
38
  0, mmdb_free, 0,
@@ -157,19 +163,36 @@ mmdb_entry_data_decode(MMDB_entry_data_s *entry_data)
157
163
  }
158
164
  }
159
165
 
166
+ static VALUE
167
+ mmdb_entry_data_decode_key(MMDB_entry_data_s *entry_data, bool symbolize_strings)
168
+ {
169
+ if (entry_data->type != MMDB_DATA_TYPE_UTF8_STRING) {
170
+ rb_raise(rb_eGeoIP2Error, "Unexpected key type: %d", entry_data->type);
171
+ }
172
+ if (symbolize_strings) {
173
+ return ID2SYM(rb_intern3(entry_data->utf8_string,
174
+ entry_data->data_size,
175
+ rb_utf8_encoding()));
176
+ } else {
177
+ return rb_enc_str_new(entry_data->utf8_string,
178
+ entry_data->data_size,
179
+ rb_utf8_encoding());
180
+ }
181
+ }
182
+
160
183
  static VALUE
161
184
  mmdb_guard_parse_entry_data_list(VALUE ptr)
162
185
  {
163
- MMDB_entry_data_list_s *data_list =
164
- (struct MMDB_entry_data_list_s *)ptr;
186
+ MMDB_entry_data_list_s *data_list = ((ParseRequest *)ptr)->data_list;
187
+ bool symbolize_keys = ((ParseRequest *)ptr)->symbolize_keys;
165
188
  VALUE obj;
166
189
 
167
- mmdb_parse_entry_data_list(data_list, &obj);
190
+ mmdb_parse_entry_data_list(data_list, symbolize_keys, &obj);
168
191
  return obj;
169
192
  }
170
193
 
171
194
  static MMDB_entry_data_list_s *
172
- mmdb_parse_entry_data_list(MMDB_entry_data_list_s *data_list, VALUE *obj)
195
+ mmdb_parse_entry_data_list(MMDB_entry_data_list_s *data_list, bool symbolize_keys, VALUE *obj)
173
196
  {
174
197
  switch (data_list->entry_data.type) {
175
198
  case MMDB_DATA_TYPE_MAP:
@@ -179,9 +202,9 @@ mmdb_parse_entry_data_list(MMDB_entry_data_list_s *data_list, VALUE *obj)
179
202
  for (data_list = data_list->next; data_size && data_list; data_size--) {
180
203
  VALUE key;
181
204
  VALUE val;
182
- key = mmdb_entry_data_decode(&data_list->entry_data);
205
+ key = mmdb_entry_data_decode_key(&data_list->entry_data, symbolize_keys);
183
206
  data_list = data_list->next;
184
- data_list = mmdb_parse_entry_data_list(data_list, &val);
207
+ data_list = mmdb_parse_entry_data_list(data_list, symbolize_keys, &val);
185
208
  rb_hash_aset(hash, key, val);
186
209
  }
187
210
  *obj = hash;
@@ -193,7 +216,7 @@ mmdb_parse_entry_data_list(MMDB_entry_data_list_s *data_list, VALUE *obj)
193
216
  VALUE array = rb_ary_new();
194
217
  for (data_list = data_list->next; data_size && data_list; data_size--) {
195
218
  VALUE val;
196
- data_list = mmdb_parse_entry_data_list(data_list, &val);
219
+ data_list = mmdb_parse_entry_data_list(data_list, symbolize_keys, &val);
197
220
  rb_ary_push(array, val);
198
221
  }
199
222
  *obj = array;
@@ -233,7 +256,7 @@ rb_geoip2_db_alloc(VALUE klass)
233
256
  }
234
257
 
235
258
  static VALUE
236
- rb_geoip2_db_initialize(VALUE self, VALUE path)
259
+ rb_geoip2_db_open_mmdb(VALUE self, VALUE path)
237
260
  {
238
261
  char *db_path;
239
262
  MMDB_s *mmdb;
@@ -288,6 +311,9 @@ rb_geoip2_db_lookup(VALUE self, VALUE ip)
288
311
  result_ptr->found_entry = result.found_entry;
289
312
  result_ptr->entry = result.entry;
290
313
  result_ptr->netmask = result.netmask;
314
+
315
+ rb_iv_set(obj, "@symbolize_keys", rb_iv_get(self, "@symbolize_keys"));
316
+
291
317
  return obj;
292
318
  }
293
319
 
@@ -382,8 +408,9 @@ rb_geoip2_lr_get_value(int argc, VALUE *argv, VALUE self)
382
408
  VALUE array = rb_ary_new();
383
409
  VALUE hash;
384
410
  VALUE val;
411
+ bool symbolize_keys = RTEST(rb_iv_get(self, "@symbolize_keys"));
385
412
  for (int j = 0; path[j] != NULL; j++) {
386
- rb_ary_push(array, rb_str_new_cstr(path[j]));
413
+ rb_ary_push(array, symbolize_keys ? ID2SYM(rb_intern(path[j])) : rb_str_new_cstr(path[j]));
387
414
  }
388
415
  hash = rb_funcall(self, rb_intern("to_h"), 0);
389
416
  val = rb_apply(hash, rb_intern("dig"), array);
@@ -395,6 +422,19 @@ rb_geoip2_lr_get_value(int argc, VALUE *argv, VALUE self)
395
422
  return mmdb_entry_data_decode(&entry_data);
396
423
  }
397
424
 
425
+ static VALUE
426
+ rb_geoip2_lr_netmask(VALUE self)
427
+ {
428
+ MMDB_lookup_result_s *result = NULL;
429
+
430
+ TypedData_Get_Struct(self,
431
+ struct MMDB_lookup_result_s,
432
+ &rb_lookup_result_type,
433
+ result);
434
+
435
+ return UINT2NUM(result->netmask);
436
+ }
437
+
398
438
  static VALUE
399
439
  rb_geoip2_lr_to_h(VALUE self)
400
440
  {
@@ -421,7 +461,9 @@ rb_geoip2_lr_to_h(VALUE self)
421
461
  rb_raise(rb_eGeoIP2Error, "%s", MMDB_strerror(status));
422
462
  }
423
463
 
424
- hash = rb_protect(mmdb_guard_parse_entry_data_list, (VALUE)entry_data_list, &exception);
464
+ ParseRequest parse_request = { entry_data_list, RTEST(rb_iv_get(self, "@symbolize_keys")) };
465
+
466
+ hash = rb_protect(mmdb_guard_parse_entry_data_list, (VALUE)&parse_request, &exception);
425
467
  MMDB_free_entry_data_list(entry_data_list);
426
468
 
427
469
  if (exception != 0) {
@@ -437,17 +479,18 @@ void
437
479
  Init_geoip2(void)
438
480
  {
439
481
  rb_mGeoIP2 = rb_define_module("GeoIP2");
440
- rb_cGeoIP2Database = rb_define_class_under(rb_mGeoIP2, "Database", rb_cData);
441
- rb_cGeoIP2LookupResult = rb_define_class_under(rb_mGeoIP2, "LookupResult", rb_cData);
482
+ rb_cGeoIP2Database = rb_define_class_under(rb_mGeoIP2, "Database", rb_cObject);
483
+ rb_cGeoIP2LookupResult = rb_define_class_under(rb_mGeoIP2, "LookupResult", rb_cObject);
442
484
  rb_eGeoIP2Error = rb_define_class_under(rb_mGeoIP2, "Error", rb_eStandardError);
443
485
 
444
486
  rb_define_alloc_func(rb_cGeoIP2Database, rb_geoip2_db_alloc);
445
- rb_define_method(rb_cGeoIP2Database, "initialize", rb_geoip2_db_initialize, 1);
487
+ rb_define_method(rb_cGeoIP2Database, "open_mmdb", rb_geoip2_db_open_mmdb, 1);
446
488
  rb_define_method(rb_cGeoIP2Database, "close", rb_geoip2_db_close, 0);
447
489
  rb_define_method(rb_cGeoIP2Database, "lookup", rb_geoip2_db_lookup, 1);
448
490
 
449
491
  rb_define_alloc_func(rb_cGeoIP2LookupResult, rb_geoip2_lr_alloc);
450
492
  rb_define_method(rb_cGeoIP2LookupResult, "initialize", rb_geoip2_lr_initialize, 0);
451
493
  rb_define_method(rb_cGeoIP2LookupResult, "get_value", rb_geoip2_lr_get_value, -1);
494
+ rb_define_method(rb_cGeoIP2LookupResult, "netmask", rb_geoip2_lr_netmask, 0);
452
495
  rb_define_method(rb_cGeoIP2LookupResult, "to_h", rb_geoip2_lr_to_h, 0);
453
496
  }
data/geoip2_c.gemspec CHANGED
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'geoip2/version'
@@ -22,9 +21,10 @@ Gem::Specification.new do |spec|
22
21
  spec.require_paths = ["lib"]
23
22
  spec.extensions = ["ext/geoip2/extconf.rb"]
24
23
 
24
+ spec.add_dependency('mini_portile2', '~> 2.8')
25
25
  spec.add_development_dependency "appraisal"
26
- spec.add_development_dependency "bundler", "~> 1.13"
27
- spec.add_development_dependency "rake", "~> 11.0"
26
+ spec.add_development_dependency "bundler"
27
+ spec.add_development_dependency "rake"
28
28
  spec.add_development_dependency "rake-compiler"
29
29
  spec.add_development_dependency "test-unit", "~> 3.2"
30
30
  end
@@ -1,4 +1,8 @@
1
1
  module GeoIP2
2
2
  class Database
3
+ def initialize(path, symbolize_keys: false)
4
+ @symbolize_keys = !!symbolize_keys
5
+ open_mmdb(path)
6
+ end
3
7
  end
4
8
  end
@@ -1,3 +1,3 @@
1
1
  module GeoIP2
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,15 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoip2_c
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - okkez
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2019-04-05 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: mini_portile2
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.8'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.8'
13
26
  - !ruby/object:Gem::Dependency
14
27
  name: appraisal
15
28
  requirement: !ruby/object:Gem::Requirement
@@ -28,30 +41,30 @@ dependencies:
28
41
  name: bundler
29
42
  requirement: !ruby/object:Gem::Requirement
30
43
  requirements:
31
- - - "~>"
44
+ - - ">="
32
45
  - !ruby/object:Gem::Version
33
- version: '1.13'
46
+ version: '0'
34
47
  type: :development
35
48
  prerelease: false
36
49
  version_requirements: !ruby/object:Gem::Requirement
37
50
  requirements:
38
- - - "~>"
51
+ - - ">="
39
52
  - !ruby/object:Gem::Version
40
- version: '1.13'
53
+ version: '0'
41
54
  - !ruby/object:Gem::Dependency
42
55
  name: rake
43
56
  requirement: !ruby/object:Gem::Requirement
44
57
  requirements:
45
- - - "~>"
58
+ - - ">="
46
59
  - !ruby/object:Gem::Version
47
- version: '11.0'
60
+ version: '0'
48
61
  type: :development
49
62
  prerelease: false
50
63
  version_requirements: !ruby/object:Gem::Requirement
51
64
  requirements:
52
- - - "~>"
65
+ - - ">="
53
66
  - !ruby/object:Gem::Version
54
- version: '11.0'
67
+ version: '0'
55
68
  - !ruby/object:Gem::Dependency
56
69
  name: rake-compiler
57
70
  requirement: !ruby/object:Gem::Requirement
@@ -88,10 +101,10 @@ extensions:
88
101
  - ext/geoip2/extconf.rb
89
102
  extra_rdoc_files: []
90
103
  files:
104
+ - ".github/workflows/ubuntu.yml"
105
+ - ".github/workflows/windows.yml"
91
106
  - ".gitignore"
92
107
  - ".gitmodules"
93
- - ".travis.yml"
94
- - Appraisals
95
108
  - COPYING.txt
96
109
  - Gemfile
97
110
  - LICENSE.txt
@@ -101,96 +114,10 @@ files:
101
114
  - dockerfiles/Dockerfile-ruby2.4
102
115
  - dockerfiles/Dockerfile-ruby2.5
103
116
  - dockerfiles/Dockerfile-ruby2.6
117
+ - dockerfiles/Dockerfile-ruby2.7
104
118
  - ext/geoip2/extconf.rb
105
119
  - ext/geoip2/geoip2.c
106
- - ext/geoip2/libmaxminddb/.gitignore
107
- - ext/geoip2/libmaxminddb/.gitmodules
108
- - ext/geoip2/libmaxminddb/.perltidyrc
109
- - ext/geoip2/libmaxminddb/.travis.yml
110
- - ext/geoip2/libmaxminddb/.uncrustify.cfg
111
- - ext/geoip2/libmaxminddb/AUTHORS
112
- - ext/geoip2/libmaxminddb/Changes.md
113
- - ext/geoip2/libmaxminddb/LICENSE
114
- - ext/geoip2/libmaxminddb/Makefile.am
115
- - ext/geoip2/libmaxminddb/NOTICE
116
- - ext/geoip2/libmaxminddb/README.dev.md
117
- - ext/geoip2/libmaxminddb/README.md
118
- - ext/geoip2/libmaxminddb/appveyor.yml
119
- - ext/geoip2/libmaxminddb/bin/Makefile.am
120
- - ext/geoip2/libmaxminddb/bin/mmdblookup.c
121
- - ext/geoip2/libmaxminddb/bootstrap
122
- - ext/geoip2/libmaxminddb/common.mk
123
- - ext/geoip2/libmaxminddb/configure.ac
124
- - ext/geoip2/libmaxminddb/dev-bin/make-man-pages.pl
125
- - ext/geoip2/libmaxminddb/dev-bin/ppa-release.sh
126
- - ext/geoip2/libmaxminddb/dev-bin/regen-prototypes.pl
127
- - ext/geoip2/libmaxminddb/dev-bin/regen-win32-test-projs.pl
128
- - ext/geoip2/libmaxminddb/dev-bin/release.sh
129
- - ext/geoip2/libmaxminddb/dev-bin/uncrustify-all.sh
130
- - ext/geoip2/libmaxminddb/dev-bin/valgrind-all.pl
131
- - ext/geoip2/libmaxminddb/doc/libmaxminddb.md
132
- - ext/geoip2/libmaxminddb/doc/mmdblookup.md
133
- - ext/geoip2/libmaxminddb/include/maxminddb.h
134
- - ext/geoip2/libmaxminddb/include/maxminddb_config.h.in
135
- - ext/geoip2/libmaxminddb/projects/VS12-tests/bad_pointers.vcxproj
136
- - ext/geoip2/libmaxminddb/projects/VS12-tests/basic_lookup.vcxproj
137
- - ext/geoip2/libmaxminddb/projects/VS12-tests/data_entry_list.vcxproj
138
- - ext/geoip2/libmaxminddb/projects/VS12-tests/data_types.vcxproj
139
- - ext/geoip2/libmaxminddb/projects/VS12-tests/dump.vcxproj
140
- - ext/geoip2/libmaxminddb/projects/VS12-tests/get_value.vcxproj
141
- - ext/geoip2/libmaxminddb/projects/VS12-tests/get_value_pointer_bug.vcxproj
142
- - ext/geoip2/libmaxminddb/projects/VS12-tests/ipv4_start_cache.vcxproj
143
- - ext/geoip2/libmaxminddb/projects/VS12-tests/ipv6_lookup_in_ipv4.vcxproj
144
- - ext/geoip2/libmaxminddb/projects/VS12-tests/libtap.vcxproj
145
- - ext/geoip2/libmaxminddb/projects/VS12-tests/maxminddb_test_helper.vcxproj
146
- - ext/geoip2/libmaxminddb/projects/VS12-tests/metadata.vcxproj
147
- - ext/geoip2/libmaxminddb/projects/VS12-tests/metadata_pointers.vcxproj
148
- - ext/geoip2/libmaxminddb/projects/VS12-tests/no_map_get_value.vcxproj
149
- - ext/geoip2/libmaxminddb/projects/VS12-tests/read_node.vcxproj
150
- - ext/geoip2/libmaxminddb/projects/VS12-tests/shared.vcxproj
151
- - ext/geoip2/libmaxminddb/projects/VS12-tests/threads.vcxproj
152
- - ext/geoip2/libmaxminddb/projects/VS12-tests/version.vcxproj
153
- - ext/geoip2/libmaxminddb/projects/VS12/README.md
154
- - ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb-release.props
155
- - ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb-x64.props
156
- - ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.props
157
- - ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.sln
158
- - ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj
159
- - ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj.filters
160
- - ext/geoip2/libmaxminddb/projects/VS12/maxminddb_config.h
161
- - ext/geoip2/libmaxminddb/projects/test.vcxproj.template
162
- - ext/geoip2/libmaxminddb/src/Makefile.am
163
- - ext/geoip2/libmaxminddb/src/data-pool.c
164
- - ext/geoip2/libmaxminddb/src/data-pool.h
165
- - ext/geoip2/libmaxminddb/src/libmaxminddb.pc.in
166
- - ext/geoip2/libmaxminddb/src/maxminddb-compat-util.h
167
- - ext/geoip2/libmaxminddb/src/maxminddb.c
168
- - ext/geoip2/libmaxminddb/t/Makefile.am
169
- - ext/geoip2/libmaxminddb/t/bad_databases_t.c
170
- - ext/geoip2/libmaxminddb/t/bad_pointers_t.c
171
- - ext/geoip2/libmaxminddb/t/basic_lookup_t.c
172
- - ext/geoip2/libmaxminddb/t/compile_c++_t.pl
173
- - ext/geoip2/libmaxminddb/t/data-pool-t.c
174
- - ext/geoip2/libmaxminddb/t/data_entry_list_t.c
175
- - ext/geoip2/libmaxminddb/t/data_types_t.c
176
- - ext/geoip2/libmaxminddb/t/dump_t.c
177
- - ext/geoip2/libmaxminddb/t/external_symbols_t.pl
178
- - ext/geoip2/libmaxminddb/t/get_value_pointer_bug_t.c
179
- - ext/geoip2/libmaxminddb/t/get_value_t.c
180
- - ext/geoip2/libmaxminddb/t/ipv4_start_cache_t.c
181
- - ext/geoip2/libmaxminddb/t/ipv6_lookup_in_ipv4_t.c
182
- - ext/geoip2/libmaxminddb/t/maxminddb_test_helper.c
183
- - ext/geoip2/libmaxminddb/t/maxminddb_test_helper.h
184
- - ext/geoip2/libmaxminddb/t/metadata_pointers_t.c
185
- - ext/geoip2/libmaxminddb/t/metadata_t.c
186
- - ext/geoip2/libmaxminddb/t/mmdblookup_t.pl
187
- - ext/geoip2/libmaxminddb/t/no_map_get_value_t.c
188
- - ext/geoip2/libmaxminddb/t/read_node_t.c
189
- - ext/geoip2/libmaxminddb/t/threads_t.c
190
- - ext/geoip2/libmaxminddb/t/version_t.c
191
120
  - ext/geoip2/rb_compat.h
192
- - gemfiles/ruby_2.1.gemfile
193
- - gemfiles/ruby_2.2.gemfile
194
121
  - geoip2_c.gemspec
195
122
  - lib/geoip2.rb
196
123
  - lib/geoip2/database.rb
@@ -200,7 +127,6 @@ homepage: ''
200
127
  licenses:
201
128
  - Apache-2.0
202
129
  metadata: {}
203
- post_install_message:
204
130
  rdoc_options: []
205
131
  require_paths:
206
132
  - lib
@@ -215,8 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
141
  - !ruby/object:Gem::Version
216
142
  version: '0'
217
143
  requirements: []
218
- rubygems_version: 3.0.3
219
- signing_key:
144
+ rubygems_version: 4.0.4
220
145
  specification_version: 4
221
146
  summary: Write a short summary, because Rubygems requires one.
222
147
  test_files: []
data/.travis.yml DELETED
@@ -1,30 +0,0 @@
1
- sudo: required
2
- services:
3
- - docker
4
-
5
- env:
6
- global:
7
- DOCKER_COMPOSE_VERSION: 1.18.0
8
- matrix:
9
- - TARGET_RUBY_VERSION=2.4
10
- - TARGET_RUBY_VERSION=2.5
11
- - TARGET_RUBY_VERSION=2.6
12
-
13
- before_install:
14
- #- sudo apt-get update
15
- #- sudo apt-get install -y docker-engine
16
- - sudo rm /usr/local/bin/docker-compose
17
- - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m) > docker-compose
18
- - chmod +x docker-compose
19
- - sudo mv docker-compose /usr/local/bin/
20
-
21
- before_script:
22
- - docker-compose build test-ruby${TARGET_RUBY_VERSION}
23
- - docker-compose ps
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
27
-
28
- script:
29
- - docker-compose exec test-ruby${TARGET_RUBY_VERSION} bundle exec rake test
30
-
data/Appraisals DELETED
@@ -1,7 +0,0 @@
1
- appraise "ruby 2.2" do
2
- gem "dig_rb"
3
- end
4
-
5
- appraise "ruby 2.1" do
6
- gem "dig_rb"
7
- end
@@ -1,38 +0,0 @@
1
- *.la
2
- *.lo
3
- *.o
4
- *.so
5
- *.swp
6
- */.deps
7
- */.libs
8
- *~
9
- .\#*
10
- .gh-pages
11
- /INSTALL
12
- /autom4te.cache
13
- /bin/country_lookup
14
- /bin/mmdbdump
15
- /bin/mmdblookup
16
- /compile
17
- /config.*
18
- /configure
19
- /depcomp
20
- /include/maxminddb_config.h
21
- /install-sh
22
- /libmaxminddb-*
23
- /libtool
24
- /ltmain.sh
25
- /man
26
- /missing
27
- /src/libmaxminddb.pc
28
- /src/test-data-pool
29
- /t/*.log
30
- /t/*.trs
31
- /t/*_t
32
- /t/*-t
33
- /test-driver
34
- Makefile
35
- Makefile.in
36
- \#*\#
37
- aclocal.m4
38
- stamp-h*