geoip2_c 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/ext/geoip2/libmaxminddb/.gitignore +35 -0
  3. data/ext/geoip2/libmaxminddb/.gitmodules +9 -0
  4. data/ext/geoip2/libmaxminddb/.perltidyrc +11 -0
  5. data/ext/geoip2/libmaxminddb/.travis.yml +48 -0
  6. data/ext/geoip2/libmaxminddb/.uncrustify.cfg +78 -0
  7. data/ext/geoip2/libmaxminddb/AUTHORS +0 -0
  8. data/ext/geoip2/libmaxminddb/Changes.md +238 -0
  9. data/ext/geoip2/libmaxminddb/LICENSE +202 -0
  10. data/ext/geoip2/libmaxminddb/Makefile.am +41 -0
  11. data/ext/geoip2/libmaxminddb/NOTICE +13 -0
  12. data/ext/geoip2/libmaxminddb/README.dev.md +58 -0
  13. data/ext/geoip2/libmaxminddb/README.md +122 -0
  14. data/ext/geoip2/libmaxminddb/appveyor.yml +33 -0
  15. data/ext/geoip2/libmaxminddb/bin/Makefile.am +5 -0
  16. data/ext/geoip2/libmaxminddb/bin/mmdblookup.c +397 -0
  17. data/ext/geoip2/libmaxminddb/bootstrap +21 -0
  18. data/ext/geoip2/libmaxminddb/common.mk +7 -0
  19. data/ext/geoip2/libmaxminddb/configure.ac +132 -0
  20. data/ext/geoip2/libmaxminddb/dev-bin/make-man-pages.pl +76 -0
  21. data/ext/geoip2/libmaxminddb/dev-bin/ppa-release.sh +50 -0
  22. data/ext/geoip2/libmaxminddb/dev-bin/regen-prototypes.pl +136 -0
  23. data/ext/geoip2/libmaxminddb/dev-bin/regen-win32-test-projs.pl +54 -0
  24. data/ext/geoip2/libmaxminddb/dev-bin/release.sh +106 -0
  25. data/ext/geoip2/libmaxminddb/dev-bin/uncrustify-all.sh +21 -0
  26. data/ext/geoip2/libmaxminddb/dev-bin/valgrind-all.pl +46 -0
  27. data/ext/geoip2/libmaxminddb/doc/libmaxminddb.md +889 -0
  28. data/ext/geoip2/libmaxminddb/doc/mmdblookup.md +103 -0
  29. data/ext/geoip2/libmaxminddb/include/maxminddb.h +232 -0
  30. data/ext/geoip2/libmaxminddb/include/maxminddb_config.h.in +14 -0
  31. data/ext/geoip2/libmaxminddb/projects/VS12/README.md +59 -0
  32. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb-release.props +32 -0
  33. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb-x64.props +14 -0
  34. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.props +32 -0
  35. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.sln +150 -0
  36. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj +141 -0
  37. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj.filters +26 -0
  38. data/ext/geoip2/libmaxminddb/projects/VS12/maxminddb_config.h +14 -0
  39. data/ext/geoip2/libmaxminddb/projects/VS12-tests/bad_pointers.vcxproj +105 -0
  40. data/ext/geoip2/libmaxminddb/projects/VS12-tests/basic_lookup.vcxproj +105 -0
  41. data/ext/geoip2/libmaxminddb/projects/VS12-tests/data_entry_list.vcxproj +105 -0
  42. data/ext/geoip2/libmaxminddb/projects/VS12-tests/data_types.vcxproj +105 -0
  43. data/ext/geoip2/libmaxminddb/projects/VS12-tests/dump.vcxproj +105 -0
  44. data/ext/geoip2/libmaxminddb/projects/VS12-tests/get_value.vcxproj +105 -0
  45. data/ext/geoip2/libmaxminddb/projects/VS12-tests/get_value_pointer_bug.vcxproj +105 -0
  46. data/ext/geoip2/libmaxminddb/projects/VS12-tests/ipv4_start_cache.vcxproj +105 -0
  47. data/ext/geoip2/libmaxminddb/projects/VS12-tests/ipv6_lookup_in_ipv4.vcxproj +105 -0
  48. data/ext/geoip2/libmaxminddb/projects/VS12-tests/libtap.vcxproj +85 -0
  49. data/ext/geoip2/libmaxminddb/projects/VS12-tests/maxminddb_test_helper.vcxproj +107 -0
  50. data/ext/geoip2/libmaxminddb/projects/VS12-tests/metadata.vcxproj +105 -0
  51. data/ext/geoip2/libmaxminddb/projects/VS12-tests/metadata_pointers.vcxproj +105 -0
  52. data/ext/geoip2/libmaxminddb/projects/VS12-tests/no_map_get_value.vcxproj +105 -0
  53. data/ext/geoip2/libmaxminddb/projects/VS12-tests/read_node.vcxproj +105 -0
  54. data/ext/geoip2/libmaxminddb/projects/VS12-tests/shared.vcxproj +104 -0
  55. data/ext/geoip2/libmaxminddb/projects/VS12-tests/threads.vcxproj +103 -0
  56. data/ext/geoip2/libmaxminddb/projects/VS12-tests/version.vcxproj +105 -0
  57. data/ext/geoip2/libmaxminddb/projects/test.vcxproj.template +105 -0
  58. data/ext/geoip2/libmaxminddb/src/Makefile.am +9 -0
  59. data/ext/geoip2/libmaxminddb/src/libmaxminddb.pc.in +11 -0
  60. data/ext/geoip2/libmaxminddb/src/maxminddb-compat-util.h +167 -0
  61. data/ext/geoip2/libmaxminddb/src/maxminddb.c +2171 -0
  62. data/ext/geoip2/libmaxminddb/t/Makefile.am +23 -0
  63. data/ext/geoip2/libmaxminddb/t/bad_databases_t.c +66 -0
  64. data/ext/geoip2/libmaxminddb/t/bad_pointers_t.c +53 -0
  65. data/ext/geoip2/libmaxminddb/t/basic_lookup_t.c +172 -0
  66. data/ext/geoip2/libmaxminddb/t/compile_c++_t.pl +107 -0
  67. data/ext/geoip2/libmaxminddb/t/data_entry_list_t.c +353 -0
  68. data/ext/geoip2/libmaxminddb/t/data_types_t.c +439 -0
  69. data/ext/geoip2/libmaxminddb/t/dump_t.c +103 -0
  70. data/ext/geoip2/libmaxminddb/t/get_value_pointer_bug_t.c +66 -0
  71. data/ext/geoip2/libmaxminddb/t/get_value_t.c +249 -0
  72. data/ext/geoip2/libmaxminddb/t/ipv4_start_cache_t.c +36 -0
  73. data/ext/geoip2/libmaxminddb/t/ipv6_lookup_in_ipv4_t.c +48 -0
  74. data/ext/geoip2/libmaxminddb/t/maxminddb_test_helper.c +255 -0
  75. data/ext/geoip2/libmaxminddb/t/maxminddb_test_helper.h +69 -0
  76. data/ext/geoip2/libmaxminddb/t/metadata_pointers_t.c +32 -0
  77. data/ext/geoip2/libmaxminddb/t/metadata_t.c +226 -0
  78. data/ext/geoip2/libmaxminddb/t/mmdblookup_t.pl +158 -0
  79. data/ext/geoip2/libmaxminddb/t/no_map_get_value_t.c +32 -0
  80. data/ext/geoip2/libmaxminddb/t/read_node_t.c +157 -0
  81. data/ext/geoip2/libmaxminddb/t/threads_t.c +196 -0
  82. data/ext/geoip2/libmaxminddb/t/version_t.c +10 -0
  83. data/geoip2_c.gemspec +1 -1
  84. data/lib/geoip2/version.rb +1 -1
  85. metadata +82 -1
@@ -0,0 +1,196 @@
1
+ #include "maxminddb_test_helper.h"
2
+ #include <pthread.h>
3
+
4
+ typedef struct thread_arg {
5
+ int thread_id;
6
+ MMDB_s *mmdb;
7
+ const char *ip_to_lookup;
8
+ } thread_arg_s;
9
+
10
+ typedef struct test_result {
11
+ const char *ip_looked_up;
12
+ int lookup_string_gai_error;
13
+ int lookup_string_mmdb_error;
14
+ int found_entry;
15
+ int get_value_status;
16
+ int data_type_ok;
17
+ char *data_value;
18
+ } test_result_s;
19
+
20
+ void test_one_ip(MMDB_s *mmdb, const char *ip, test_result_s *test_result)
21
+ {
22
+
23
+ test_result->ip_looked_up = ip;
24
+
25
+ int gai_error = 0;
26
+ int mmdb_error = 0;
27
+ MMDB_lookup_result_s result =
28
+ MMDB_lookup_string(mmdb, ip, &gai_error, &mmdb_error);
29
+
30
+ test_result->lookup_string_gai_error = gai_error;
31
+ if (gai_error) {
32
+ return;
33
+ }
34
+
35
+ test_result->lookup_string_mmdb_error = mmdb_error;
36
+ if (mmdb_error) {
37
+ return;
38
+ }
39
+
40
+ test_result->found_entry = result.found_entry;
41
+ if (!result.found_entry) {
42
+ return;
43
+ }
44
+
45
+ MMDB_entry_data_s data;
46
+ int status = MMDB_get_value(&result.entry, &data, "ip", NULL);
47
+
48
+ test_result->get_value_status = status;
49
+ if (status) {
50
+ return;
51
+ }
52
+
53
+ test_result->data_type_ok = data.type == MMDB_DATA_TYPE_UTF8_STRING;
54
+ if (!test_result->data_type_ok) {
55
+ return;
56
+ }
57
+
58
+ test_result->data_value = strndup(data.utf8_string, data.data_size);
59
+
60
+ return;
61
+ }
62
+
63
+ void *run_one_thread(void *arg)
64
+ {
65
+ thread_arg_s *thread_arg = (thread_arg_s *)arg;
66
+
67
+ MMDB_s *mmdb = thread_arg->mmdb;
68
+ const char *ip = thread_arg->ip_to_lookup;
69
+
70
+ test_result_s *result = malloc(sizeof(test_result_s));
71
+ test_one_ip(mmdb, ip, result);
72
+
73
+ pthread_exit((void *)result);
74
+ }
75
+
76
+ void process_result(test_result_s *result, const char *expect,
77
+ const char *mode_desc)
78
+ {
79
+ int is_ok;
80
+ is_ok =
81
+ ok(!result->lookup_string_gai_error, "no getaddrinfo error for %s - %s",
82
+ result->ip_looked_up, mode_desc);
83
+ if (!is_ok) {
84
+ return;
85
+ }
86
+
87
+ is_ok = ok(!result->lookup_string_mmdb_error, "no mmdb error for %s - %s",
88
+ result->ip_looked_up, mode_desc);
89
+ if (!is_ok) {
90
+ return;
91
+ }
92
+
93
+ is_ok = ok(result->found_entry, "got a result for %s in the database - %s",
94
+ result->ip_looked_up, mode_desc);
95
+ if (!is_ok) {
96
+ return;
97
+ }
98
+
99
+ is_ok =
100
+ ok(!result->get_value_status,
101
+ "no error from MMDB_get_value for %s - %s",
102
+ result->ip_looked_up,
103
+ mode_desc);
104
+ if (!is_ok) {
105
+ return;
106
+ }
107
+
108
+ is_ok = ok(result->data_type_ok,
109
+ "MMDB_get_value found a utf8_string at 'ip' key for %s - %s",
110
+ result->ip_looked_up, mode_desc);
111
+ if (!is_ok) {
112
+ return;
113
+ }
114
+
115
+ is(result->data_value, expect,
116
+ "found expected result for 'ip' key for %s - %s",
117
+ result->ip_looked_up, mode_desc);
118
+ }
119
+
120
+ void run_ipX_tests(MMDB_s *mmdb, const char *pairs[][2], int pairs_rows,
121
+ int mode, const char *mode_desc)
122
+ {
123
+ pthread_t threads[pairs_rows];
124
+ struct thread_arg thread_args[pairs_rows];
125
+
126
+ for (int i = 0; i < pairs_rows; i += 1) {
127
+ thread_args[i].thread_id = i;
128
+ thread_args[i].mmdb = mmdb;
129
+ thread_args[i].ip_to_lookup = pairs[i][0];
130
+
131
+ int error = pthread_create(&threads[i], NULL, run_one_thread,
132
+ &thread_args[i]);
133
+ if (error) {
134
+ BAIL_OUT("pthread_create failed");
135
+ }
136
+ }
137
+
138
+ for (int i = 0; i < pairs_rows; i += 1) {
139
+ void *thread_return;
140
+ int error = pthread_join(threads[i], &thread_return);
141
+ if (error) {
142
+ BAIL_OUT("pthread_join failed");
143
+ }
144
+
145
+ test_result_s *test_result = (test_result_s *)thread_return;
146
+ if (NULL != test_result) {
147
+ process_result(test_result, pairs[i][1], mode_desc);
148
+ if (test_result->data_type_ok) {
149
+ free(test_result->data_value);
150
+ }
151
+ free(test_result);
152
+ }
153
+ }
154
+ }
155
+
156
+ void run_tests(int mode, const char *mode_desc)
157
+ {
158
+ const char *filename = "MaxMind-DB-test-mixed-32.mmdb";
159
+ const char *path = test_database_path(filename);
160
+ MMDB_s *mmdb = open_ok(path, mode, mode_desc);
161
+ free((void *)path);
162
+
163
+ const char *pairs[18][2] = {
164
+ { "1.1.1.1", "::1.1.1.1" },
165
+ { "1.1.1.2", "::1.1.1.2" },
166
+ { "1.1.1.3", "::1.1.1.2" },
167
+ { "1.1.1.7", "::1.1.1.4" },
168
+ { "1.1.1.9", "::1.1.1.8" },
169
+ { "1.1.1.15", "::1.1.1.8" },
170
+ { "1.1.1.17", "::1.1.1.16" },
171
+ { "1.1.1.31", "::1.1.1.16" },
172
+ { "1.1.1.32", "::1.1.1.32" },
173
+ { "::1:ffff:ffff", "::1:ffff:ffff" },
174
+ { "::2:0:0", "::2:0:0" },
175
+ { "::2:0:1a", "::2:0:0" },
176
+ { "::2:0:40", "::2:0:40" },
177
+ { "::2:0:4f", "::2:0:40" },
178
+ { "::2:0:50", "::2:0:50" },
179
+ { "::2:0:52", "::2:0:50" },
180
+ { "::2:0:58", "::2:0:58" },
181
+ { "::2:0:59", "::2:0:58" },
182
+ };
183
+
184
+ run_ipX_tests(mmdb, pairs, 18, mode, mode_desc);
185
+
186
+ MMDB_close(mmdb);
187
+ free(mmdb);
188
+ }
189
+
190
+ int main(void)
191
+ {
192
+ plan(NO_PLAN);
193
+ for_all_modes(&run_tests);
194
+ done_testing();
195
+ pthread_exit(NULL);
196
+ }
@@ -0,0 +1,10 @@
1
+ #include "maxminddb_test_helper.h"
2
+
3
+ int main(void)
4
+ {
5
+ const char *version = MMDB_lib_version();
6
+ if (ok((version != NULL), "MMDB_lib_version exists")) {
7
+ is(version, PACKAGE_VERSION, "version is " PACKAGE_VERSION);
8
+ }
9
+ done_testing();
10
+ }
data/geoip2_c.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = ""
15
15
  spec.license = "Apache-2.0"
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ spec.files = `git ls-files -z --recurse-submodules`.split("\x0").reject do |f|
18
18
  f.match(%r{^(test|spec|features|benchmark)/})
19
19
  end
20
20
  spec.bindir = "bin"
@@ -1,3 +1,3 @@
1
1
  module GeoIP2
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoip2_c
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - okkez
@@ -104,6 +104,87 @@ files:
104
104
  - dockerfiles/Dockerfile-ruby2.4
105
105
  - ext/geoip2/extconf.rb
106
106
  - ext/geoip2/geoip2.c
107
+ - ext/geoip2/libmaxminddb/.gitignore
108
+ - ext/geoip2/libmaxminddb/.gitmodules
109
+ - ext/geoip2/libmaxminddb/.perltidyrc
110
+ - ext/geoip2/libmaxminddb/.travis.yml
111
+ - ext/geoip2/libmaxminddb/.uncrustify.cfg
112
+ - ext/geoip2/libmaxminddb/AUTHORS
113
+ - ext/geoip2/libmaxminddb/Changes.md
114
+ - ext/geoip2/libmaxminddb/LICENSE
115
+ - ext/geoip2/libmaxminddb/Makefile.am
116
+ - ext/geoip2/libmaxminddb/NOTICE
117
+ - ext/geoip2/libmaxminddb/README.dev.md
118
+ - ext/geoip2/libmaxminddb/README.md
119
+ - ext/geoip2/libmaxminddb/appveyor.yml
120
+ - ext/geoip2/libmaxminddb/bin/Makefile.am
121
+ - ext/geoip2/libmaxminddb/bin/mmdblookup.c
122
+ - ext/geoip2/libmaxminddb/bootstrap
123
+ - ext/geoip2/libmaxminddb/common.mk
124
+ - ext/geoip2/libmaxminddb/configure.ac
125
+ - ext/geoip2/libmaxminddb/dev-bin/make-man-pages.pl
126
+ - ext/geoip2/libmaxminddb/dev-bin/ppa-release.sh
127
+ - ext/geoip2/libmaxminddb/dev-bin/regen-prototypes.pl
128
+ - ext/geoip2/libmaxminddb/dev-bin/regen-win32-test-projs.pl
129
+ - ext/geoip2/libmaxminddb/dev-bin/release.sh
130
+ - ext/geoip2/libmaxminddb/dev-bin/uncrustify-all.sh
131
+ - ext/geoip2/libmaxminddb/dev-bin/valgrind-all.pl
132
+ - ext/geoip2/libmaxminddb/doc/libmaxminddb.md
133
+ - ext/geoip2/libmaxminddb/doc/mmdblookup.md
134
+ - ext/geoip2/libmaxminddb/include/maxminddb.h
135
+ - ext/geoip2/libmaxminddb/include/maxminddb_config.h.in
136
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/bad_pointers.vcxproj
137
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/basic_lookup.vcxproj
138
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/data_entry_list.vcxproj
139
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/data_types.vcxproj
140
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/dump.vcxproj
141
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/get_value.vcxproj
142
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/get_value_pointer_bug.vcxproj
143
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/ipv4_start_cache.vcxproj
144
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/ipv6_lookup_in_ipv4.vcxproj
145
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/libtap.vcxproj
146
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/maxminddb_test_helper.vcxproj
147
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/metadata.vcxproj
148
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/metadata_pointers.vcxproj
149
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/no_map_get_value.vcxproj
150
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/read_node.vcxproj
151
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/shared.vcxproj
152
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/threads.vcxproj
153
+ - ext/geoip2/libmaxminddb/projects/VS12-tests/version.vcxproj
154
+ - ext/geoip2/libmaxminddb/projects/VS12/README.md
155
+ - ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb-release.props
156
+ - ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb-x64.props
157
+ - ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.props
158
+ - ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.sln
159
+ - ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj
160
+ - ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj.filters
161
+ - ext/geoip2/libmaxminddb/projects/VS12/maxminddb_config.h
162
+ - ext/geoip2/libmaxminddb/projects/test.vcxproj.template
163
+ - ext/geoip2/libmaxminddb/src/Makefile.am
164
+ - ext/geoip2/libmaxminddb/src/libmaxminddb.pc.in
165
+ - ext/geoip2/libmaxminddb/src/maxminddb-compat-util.h
166
+ - ext/geoip2/libmaxminddb/src/maxminddb.c
167
+ - ext/geoip2/libmaxminddb/t/Makefile.am
168
+ - ext/geoip2/libmaxminddb/t/bad_databases_t.c
169
+ - ext/geoip2/libmaxminddb/t/bad_pointers_t.c
170
+ - ext/geoip2/libmaxminddb/t/basic_lookup_t.c
171
+ - ext/geoip2/libmaxminddb/t/compile_c++_t.pl
172
+ - ext/geoip2/libmaxminddb/t/data_entry_list_t.c
173
+ - ext/geoip2/libmaxminddb/t/data_types_t.c
174
+ - ext/geoip2/libmaxminddb/t/dump_t.c
175
+ - ext/geoip2/libmaxminddb/t/get_value_pointer_bug_t.c
176
+ - ext/geoip2/libmaxminddb/t/get_value_t.c
177
+ - ext/geoip2/libmaxminddb/t/ipv4_start_cache_t.c
178
+ - ext/geoip2/libmaxminddb/t/ipv6_lookup_in_ipv4_t.c
179
+ - ext/geoip2/libmaxminddb/t/maxminddb_test_helper.c
180
+ - ext/geoip2/libmaxminddb/t/maxminddb_test_helper.h
181
+ - ext/geoip2/libmaxminddb/t/metadata_pointers_t.c
182
+ - ext/geoip2/libmaxminddb/t/metadata_t.c
183
+ - ext/geoip2/libmaxminddb/t/mmdblookup_t.pl
184
+ - ext/geoip2/libmaxminddb/t/no_map_get_value_t.c
185
+ - ext/geoip2/libmaxminddb/t/read_node_t.c
186
+ - ext/geoip2/libmaxminddb/t/threads_t.c
187
+ - ext/geoip2/libmaxminddb/t/version_t.c
107
188
  - ext/geoip2/rb_compat.h
108
189
  - gemfiles/ruby_2.1.gemfile
109
190
  - gemfiles/ruby_2.2.gemfile