geoip2_c 0.3.4 → 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.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +23 -0
  3. data/.github/workflows/ubuntu.yml +17 -8
  4. data/.github/workflows/windows.yml +18 -8
  5. data/.gitmodules +0 -3
  6. data/ext/geoip2/extconf.rb +9 -25
  7. data/ext/geoip2/geoip2.c +82 -32
  8. data/geoip2_c.gemspec +1 -0
  9. data/lib/geoip2/version.rb +1 -1
  10. metadata +18 -182
  11. data/ext/geoip2/libmaxminddb/.gitignore +0 -38
  12. data/ext/geoip2/libmaxminddb/.gitmodules +0 -9
  13. data/ext/geoip2/libmaxminddb/.perltidyrc +0 -11
  14. data/ext/geoip2/libmaxminddb/.travis.yml +0 -70
  15. data/ext/geoip2/libmaxminddb/.uncrustify.cfg +0 -78
  16. data/ext/geoip2/libmaxminddb/AUTHORS +0 -0
  17. data/ext/geoip2/libmaxminddb/Changes.md +0 -277
  18. data/ext/geoip2/libmaxminddb/LICENSE +0 -202
  19. data/ext/geoip2/libmaxminddb/Makefile.am +0 -41
  20. data/ext/geoip2/libmaxminddb/NOTICE +0 -13
  21. data/ext/geoip2/libmaxminddb/README.dev.md +0 -69
  22. data/ext/geoip2/libmaxminddb/README.md +0 -122
  23. data/ext/geoip2/libmaxminddb/appveyor.yml +0 -33
  24. data/ext/geoip2/libmaxminddb/bin/Makefile.am +0 -10
  25. data/ext/geoip2/libmaxminddb/bin/mmdblookup.c +0 -715
  26. data/ext/geoip2/libmaxminddb/bootstrap +0 -21
  27. data/ext/geoip2/libmaxminddb/common.mk +0 -7
  28. data/ext/geoip2/libmaxminddb/configure.ac +0 -132
  29. data/ext/geoip2/libmaxminddb/dev-bin/make-man-pages.pl +0 -76
  30. data/ext/geoip2/libmaxminddb/dev-bin/ppa-release.sh +0 -53
  31. data/ext/geoip2/libmaxminddb/dev-bin/regen-prototypes.pl +0 -136
  32. data/ext/geoip2/libmaxminddb/dev-bin/regen-win32-test-projs.pl +0 -54
  33. data/ext/geoip2/libmaxminddb/dev-bin/release.sh +0 -113
  34. data/ext/geoip2/libmaxminddb/dev-bin/uncrustify-all.sh +0 -21
  35. data/ext/geoip2/libmaxminddb/dev-bin/valgrind-all.pl +0 -53
  36. data/ext/geoip2/libmaxminddb/doc/libmaxminddb.md +0 -889
  37. data/ext/geoip2/libmaxminddb/doc/mmdblookup.md +0 -103
  38. data/ext/geoip2/libmaxminddb/include/maxminddb.h +0 -241
  39. data/ext/geoip2/libmaxminddb/include/maxminddb_config.h.in +0 -14
  40. data/ext/geoip2/libmaxminddb/projects/VS12/README.md +0 -59
  41. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb-release.props +0 -32
  42. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb-x64.props +0 -14
  43. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.props +0 -32
  44. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.sln +0 -150
  45. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj +0 -143
  46. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj.filters +0 -32
  47. data/ext/geoip2/libmaxminddb/projects/VS12/maxminddb_config.h +0 -14
  48. data/ext/geoip2/libmaxminddb/projects/VS12-tests/bad_pointers.vcxproj +0 -105
  49. data/ext/geoip2/libmaxminddb/projects/VS12-tests/basic_lookup.vcxproj +0 -105
  50. data/ext/geoip2/libmaxminddb/projects/VS12-tests/data_entry_list.vcxproj +0 -105
  51. data/ext/geoip2/libmaxminddb/projects/VS12-tests/data_types.vcxproj +0 -105
  52. data/ext/geoip2/libmaxminddb/projects/VS12-tests/dump.vcxproj +0 -105
  53. data/ext/geoip2/libmaxminddb/projects/VS12-tests/get_value.vcxproj +0 -105
  54. data/ext/geoip2/libmaxminddb/projects/VS12-tests/get_value_pointer_bug.vcxproj +0 -105
  55. data/ext/geoip2/libmaxminddb/projects/VS12-tests/ipv4_start_cache.vcxproj +0 -105
  56. data/ext/geoip2/libmaxminddb/projects/VS12-tests/ipv6_lookup_in_ipv4.vcxproj +0 -105
  57. data/ext/geoip2/libmaxminddb/projects/VS12-tests/libtap.vcxproj +0 -85
  58. data/ext/geoip2/libmaxminddb/projects/VS12-tests/maxminddb_test_helper.vcxproj +0 -107
  59. data/ext/geoip2/libmaxminddb/projects/VS12-tests/metadata.vcxproj +0 -105
  60. data/ext/geoip2/libmaxminddb/projects/VS12-tests/metadata_pointers.vcxproj +0 -105
  61. data/ext/geoip2/libmaxminddb/projects/VS12-tests/no_map_get_value.vcxproj +0 -105
  62. data/ext/geoip2/libmaxminddb/projects/VS12-tests/read_node.vcxproj +0 -105
  63. data/ext/geoip2/libmaxminddb/projects/VS12-tests/shared.vcxproj +0 -104
  64. data/ext/geoip2/libmaxminddb/projects/VS12-tests/threads.vcxproj +0 -103
  65. data/ext/geoip2/libmaxminddb/projects/VS12-tests/version.vcxproj +0 -105
  66. data/ext/geoip2/libmaxminddb/projects/test.vcxproj.template +0 -105
  67. data/ext/geoip2/libmaxminddb/src/Makefile.am +0 -25
  68. data/ext/geoip2/libmaxminddb/src/data-pool.c +0 -180
  69. data/ext/geoip2/libmaxminddb/src/data-pool.h +0 -52
  70. data/ext/geoip2/libmaxminddb/src/libmaxminddb.pc.in +0 -11
  71. data/ext/geoip2/libmaxminddb/src/maxminddb-compat-util.h +0 -167
  72. data/ext/geoip2/libmaxminddb/src/maxminddb.c +0 -2181
  73. data/ext/geoip2/libmaxminddb/t/Makefile.am +0 -27
  74. data/ext/geoip2/libmaxminddb/t/bad_databases_t.c +0 -67
  75. data/ext/geoip2/libmaxminddb/t/bad_pointers_t.c +0 -53
  76. data/ext/geoip2/libmaxminddb/t/basic_lookup_t.c +0 -207
  77. data/ext/geoip2/libmaxminddb/t/compile_c++_t.pl +0 -107
  78. data/ext/geoip2/libmaxminddb/t/data-pool-t.c +0 -374
  79. data/ext/geoip2/libmaxminddb/t/data_entry_list_t.c +0 -353
  80. data/ext/geoip2/libmaxminddb/t/data_types_t.c +0 -439
  81. data/ext/geoip2/libmaxminddb/t/dump_t.c +0 -103
  82. data/ext/geoip2/libmaxminddb/t/external_symbols_t.pl +0 -106
  83. data/ext/geoip2/libmaxminddb/t/get_value_pointer_bug_t.c +0 -66
  84. data/ext/geoip2/libmaxminddb/t/get_value_t.c +0 -249
  85. data/ext/geoip2/libmaxminddb/t/ipv4_start_cache_t.c +0 -36
  86. data/ext/geoip2/libmaxminddb/t/ipv6_lookup_in_ipv4_t.c +0 -48
  87. data/ext/geoip2/libmaxminddb/t/libtap/.gitignore +0 -13
  88. data/ext/geoip2/libmaxminddb/t/libtap/.travis.yml +0 -13
  89. data/ext/geoip2/libmaxminddb/t/libtap/COPYING +0 -165
  90. data/ext/geoip2/libmaxminddb/t/libtap/INSTALL +0 -41
  91. data/ext/geoip2/libmaxminddb/t/libtap/Makefile +0 -72
  92. data/ext/geoip2/libmaxminddb/t/libtap/Makefile.win +0 -37
  93. data/ext/geoip2/libmaxminddb/t/libtap/README.md +0 -268
  94. data/ext/geoip2/libmaxminddb/t/libtap/t/cmp_mem.c +0 -20
  95. data/ext/geoip2/libmaxminddb/t/libtap/t/cmp_mem.expected +0 -28
  96. data/ext/geoip2/libmaxminddb/t/libtap/t/cmpok.c +0 -16
  97. data/ext/geoip2/libmaxminddb/t/libtap/t/cmpok.expected +0 -37
  98. data/ext/geoip2/libmaxminddb/t/libtap/t/diag.c +0 -10
  99. data/ext/geoip2/libmaxminddb/t/libtap/t/diag.expected +0 -2
  100. data/ext/geoip2/libmaxminddb/t/libtap/t/diesok.c +0 -14
  101. data/ext/geoip2/libmaxminddb/t/libtap/t/diesok.expected +0 -6
  102. data/ext/geoip2/libmaxminddb/t/libtap/t/is.c +0 -24
  103. data/ext/geoip2/libmaxminddb/t/libtap/t/is.expected +0 -58
  104. data/ext/geoip2/libmaxminddb/t/libtap/t/like.c +0 -10
  105. data/ext/geoip2/libmaxminddb/t/libtap/t/like.expected +0 -4
  106. data/ext/geoip2/libmaxminddb/t/libtap/t/simple.c +0 -31
  107. data/ext/geoip2/libmaxminddb/t/libtap/t/simple.expected +0 -32
  108. data/ext/geoip2/libmaxminddb/t/libtap/t/skip.c +0 -23
  109. data/ext/geoip2/libmaxminddb/t/libtap/t/skip.expected +0 -9
  110. data/ext/geoip2/libmaxminddb/t/libtap/t/synopsis.c +0 -13
  111. data/ext/geoip2/libmaxminddb/t/libtap/t/synopsis.expected +0 -9
  112. data/ext/geoip2/libmaxminddb/t/libtap/t/test.c +0 -28
  113. data/ext/geoip2/libmaxminddb/t/libtap/t/todo.c +0 -17
  114. data/ext/geoip2/libmaxminddb/t/libtap/t/todo.expected +0 -11
  115. data/ext/geoip2/libmaxminddb/t/libtap/tap.c +0 -354
  116. data/ext/geoip2/libmaxminddb/t/libtap/tap.h +0 -115
  117. data/ext/geoip2/libmaxminddb/t/maxmind-db/.gitattributes +0 -1
  118. data/ext/geoip2/libmaxminddb/t/maxmind-db/.gitconfig +0 -2
  119. data/ext/geoip2/libmaxminddb/t/maxmind-db/.gitignore +0 -2
  120. data/ext/geoip2/libmaxminddb/t/maxmind-db/.perltidyallrc +0 -11
  121. data/ext/geoip2/libmaxminddb/t/maxmind-db/.tidyallrc +0 -7
  122. data/ext/geoip2/libmaxminddb/t/maxmind-db/LICENSE +0 -4
  123. data/ext/geoip2/libmaxminddb/t/maxmind-db/MaxMind-DB-spec.md +0 -558
  124. data/ext/geoip2/libmaxminddb/t/maxmind-db/README.md +0 -4
  125. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/README.md +0 -7
  126. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/libmaxminddb/libmaxminddb-offset-integer-overflow.mmdb +0 -0
  127. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/cyclic-data-structure.mmdb +0 -0
  128. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-bytes-length.mmdb +0 -1
  129. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-data-record-offset.mmdb +0 -0
  130. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-map-key-length.mmdb +0 -0
  131. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-string-length.mmdb +0 -1
  132. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/metadata-is-an-uint128.mmdb +0 -1
  133. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/unexpected-bytes.mmdb +0 -0
  134. data/ext/geoip2/libmaxminddb/t/maxmind-db/perltidyrc +0 -12
  135. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Anonymous-IP-Test.json +0 -32
  136. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-City-Test.json +0 -12616
  137. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Connection-Type-Test.json +0 -102
  138. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Country-Test.json +0 -10975
  139. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-DensityIncome-Test.json +0 -14
  140. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Domain-Test.json +0 -452
  141. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Enterprise-Test.json +0 -666
  142. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-ISP-Test.json +0 -12585
  143. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Precision-Enterprise-Test.json +0 -1035
  144. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoLite2-ASN-Test.json +0 -37
  145. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/README +0 -13
  146. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Anonymous-IP-Test.mmdb +0 -0
  147. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb +0 -0
  148. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb +0 -0
  149. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-City-Test.mmdb +0 -0
  150. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Connection-Type-Test.mmdb +0 -0
  151. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Country-Test.mmdb +0 -0
  152. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-DensityIncome-Test.mmdb +0 -0
  153. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Domain-Test.mmdb +0 -0
  154. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Enterprise-Test.mmdb +0 -0
  155. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-ISP-Test.mmdb +0 -0
  156. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Precision-Enterprise-Test.mmdb +0 -0
  157. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoLite2-ASN-Test.mmdb +0 -0
  158. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb +0 -0
  159. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-string-value-entries.mmdb +0 -0
  160. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-broken-pointers-24.mmdb +0 -0
  161. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb +0 -0
  162. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-decoder.mmdb +0 -0
  163. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv4-24.mmdb +0 -0
  164. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv4-28.mmdb +0 -0
  165. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv4-32.mmdb +0 -0
  166. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv6-24.mmdb +0 -0
  167. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv6-28.mmdb +0 -0
  168. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv6-32.mmdb +0 -0
  169. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-metadata-pointers.mmdb +0 -0
  170. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-mixed-24.mmdb +0 -0
  171. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-mixed-28.mmdb +0 -0
  172. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-mixed-32.mmdb +0 -0
  173. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-nested.mmdb +0 -0
  174. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/README.md +0 -26
  175. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/maps-with-pointers.raw +0 -0
  176. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/write-test-data.pl +0 -614
  177. data/ext/geoip2/libmaxminddb/t/maxmind-db/tidyall.ini +0 -5
  178. data/ext/geoip2/libmaxminddb/t/maxminddb_test_helper.c +0 -255
  179. data/ext/geoip2/libmaxminddb/t/maxminddb_test_helper.h +0 -69
  180. data/ext/geoip2/libmaxminddb/t/metadata_pointers_t.c +0 -32
  181. data/ext/geoip2/libmaxminddb/t/metadata_t.c +0 -226
  182. data/ext/geoip2/libmaxminddb/t/mmdblookup_t.pl +0 -158
  183. data/ext/geoip2/libmaxminddb/t/no_map_get_value_t.c +0 -32
  184. data/ext/geoip2/libmaxminddb/t/read_node_t.c +0 -157
  185. data/ext/geoip2/libmaxminddb/t/threads_t.c +0 -196
  186. data/ext/geoip2/libmaxminddb/t/version_t.c +0 -10
@@ -1,439 +0,0 @@
1
- #include "maxminddb_test_helper.h"
2
-
3
- void test_all_data_types(MMDB_lookup_result_s *result, const char *ip,
4
- const char *UNUSED(filename), const char *mode_desc)
5
- {
6
- {
7
- char description[500];
8
- snprintf(description, 500, "utf8_string field for %s - %s", ip,
9
- mode_desc);
10
-
11
- MMDB_entry_data_s data =
12
- data_ok(result, MMDB_DATA_TYPE_UTF8_STRING, description,
13
- "utf8_string", NULL);
14
- const char *string = strndup(data.utf8_string, data.data_size);
15
- // This is hex for "unicode! ☯ - ♫" as bytes
16
- char expect[19] =
17
- { 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x21, 0x20, 0xe2, 0x98,
18
- 0xaf, 0x20, 0x2d, 0x20, 0xe2, 0x99, 0xab, 0x00 };
19
- is(string, expect, "got expected utf8_string value");
20
-
21
- free((char *)string);
22
- }
23
-
24
- {
25
- char description[500];
26
- snprintf(description, 500, "double field for %s - %s", ip, mode_desc);
27
-
28
- MMDB_entry_data_s data =
29
- data_ok(result, MMDB_DATA_TYPE_DOUBLE, description, "double", NULL);
30
-
31
- compare_double(data.double_value, 42.123456);
32
- }
33
-
34
- {
35
- char description[500];
36
- snprintf(description, 500, "float field for %s - %s", ip, mode_desc);
37
-
38
- MMDB_entry_data_s data =
39
- data_ok(result, MMDB_DATA_TYPE_FLOAT, description, "float", NULL);
40
-
41
- compare_float(data.float_value, 1.1F);
42
- }
43
-
44
- {
45
- char description[500];
46
- snprintf(description, 500, "bytes field for %s - %s", ip, mode_desc);
47
-
48
- MMDB_entry_data_s data =
49
- data_ok(result, MMDB_DATA_TYPE_BYTES, description, "bytes", NULL);
50
- uint8_t expect[] = { 0x00, 0x00, 0x00, 0x2a };
51
- ok(memcmp((uint8_t *)data.bytes, expect, 4) == 0,
52
- "bytes field has expected value");
53
- }
54
-
55
- {
56
- char description[500];
57
- snprintf(description, 500, "uint16 field for %s - %s", ip, mode_desc);
58
-
59
- MMDB_entry_data_s data =
60
- data_ok(result, MMDB_DATA_TYPE_UINT16, description, "uint16", NULL);
61
- uint16_t expect = 100;
62
- ok(data.uint16 == expect, "uint16 field is 100");
63
- }
64
-
65
- {
66
- char description[500];
67
- snprintf(description, 500, "uint32 field for %s - %s", ip, mode_desc);
68
-
69
- MMDB_entry_data_s data =
70
- data_ok(result, MMDB_DATA_TYPE_UINT32, description, "uint32", NULL);
71
- uint32_t expect = 1 << 28;
72
- cmp_ok(data.uint32, "==", expect, "uint32 field is 2**28");
73
- }
74
-
75
- {
76
- char description[500];
77
- snprintf(description, 500, "int32 field for %s - %s", ip, mode_desc);
78
-
79
- MMDB_entry_data_s data =
80
- data_ok(result, MMDB_DATA_TYPE_INT32, description, "int32", NULL);
81
- int32_t expect = 1 << 28;
82
- expect *= -1;
83
- cmp_ok(data.int32, "==", expect, "int32 field is -(2**28)");
84
- }
85
-
86
- {
87
- char description[500];
88
- snprintf(description, 500, "uint64 field for %s - %s", ip, mode_desc);
89
-
90
- MMDB_entry_data_s data =
91
- data_ok(result, MMDB_DATA_TYPE_UINT64, description, "uint64", NULL);
92
- uint64_t expect = 1;
93
- expect <<= 60;
94
- cmp_ok(data.uint64, "==", expect, "uint64 field is 2**60");
95
- }
96
-
97
- {
98
- char description[500];
99
- snprintf(description, 500, "uint128 field for %s - %s", ip, mode_desc);
100
-
101
- MMDB_entry_data_s data =
102
- data_ok(result, MMDB_DATA_TYPE_UINT128, description, "uint128",
103
- NULL);
104
- #if MMDB_UINT128_IS_BYTE_ARRAY
105
- uint8_t expect[16] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
107
- ok(memcmp(data.uint128, expect, 16) == 0, "uint128 field is 2**120");
108
- #else
109
- mmdb_uint128_t expect = 1;
110
- expect <<= 120;
111
- cmp_ok(data.uint128, "==", expect, "uint128 field is 2**120");
112
- #endif
113
- }
114
-
115
- {
116
- char description[500];
117
- snprintf(description, 500, "boolean field for %s - %s", ip, mode_desc);
118
-
119
- MMDB_entry_data_s data =
120
- data_ok(result, MMDB_DATA_TYPE_BOOLEAN, description, "boolean",
121
- NULL);
122
- cmp_ok(data.boolean, "==", true, "boolean field is true");
123
- }
124
-
125
- {
126
- char description[500];
127
- snprintf(description, 500, "array field for %s - %s", ip, mode_desc);
128
-
129
- MMDB_entry_data_s data =
130
- data_ok(result, MMDB_DATA_TYPE_ARRAY, description, "array", NULL);
131
- ok(data.data_size == 3, "array field has 3 elements");
132
-
133
- snprintf(description, 500, "array[0] for %s - %s", ip, mode_desc);
134
- data =
135
- data_ok(result, MMDB_DATA_TYPE_UINT32, description, "array", "0",
136
- NULL);
137
- ok(data.uint32 == 1, "array[0] is 1");
138
-
139
- snprintf(description, 500, "array[1] for %s - %s", ip, mode_desc);
140
- data =
141
- data_ok(result, MMDB_DATA_TYPE_UINT32, description, "array", "1",
142
- NULL);
143
- ok(data.uint32 == 2, "array[1] is 1");
144
-
145
- snprintf(description, 500, "array[2] for %s - %s", ip, mode_desc);
146
- data =
147
- data_ok(result, MMDB_DATA_TYPE_UINT32, description, "array", "2",
148
- NULL);
149
- ok(data.uint32 == 3, "array[2] is 1");
150
- }
151
-
152
- {
153
- char description[500];
154
- snprintf(description, 500, "map field for %s - %s", ip, mode_desc);
155
-
156
- MMDB_entry_data_s data =
157
- data_ok(result, MMDB_DATA_TYPE_MAP, description, "map", NULL);
158
- ok(data.data_size == 1, "map field has 1 element");
159
-
160
- snprintf(description, 500, "map{mapX} for %s - %s", ip, mode_desc);
161
-
162
- data =
163
- data_ok(result, MMDB_DATA_TYPE_MAP, description, "map", "mapX",
164
- NULL);
165
- ok(data.data_size == 2, "map{mapX} field has 2 elements");
166
-
167
- snprintf(description, 500, "map{mapX}{utf8_stringX} for %s - %s", ip,
168
- mode_desc);
169
-
170
- data =
171
- data_ok(result, MMDB_DATA_TYPE_UTF8_STRING, description, "map",
172
- "mapX", "utf8_stringX", NULL);
173
- const char *string = strndup(data.utf8_string, data.data_size);
174
- is(string, "hello", "map{mapX}{utf8_stringX} is 'hello'");
175
- free((char *)string);
176
-
177
- snprintf(description, 500, "map{mapX}{arrayX} for %s - %s", ip,
178
- mode_desc);
179
- data =
180
- data_ok(result, MMDB_DATA_TYPE_ARRAY, description, "map", "mapX",
181
- "arrayX", NULL);
182
- ok(data.data_size == 3, "map{mapX}{arrayX} field has 3 elements");
183
-
184
- snprintf(description, 500, "map{mapX}{arrayX}[0] for %s - %s", ip,
185
- mode_desc);
186
- data =
187
- data_ok(result, MMDB_DATA_TYPE_UINT32, description, "map", "mapX",
188
- "arrayX", "0", NULL);
189
- ok(data.uint32 == 7, "map{mapX}{arrayX}[0] is 7");
190
-
191
- snprintf(description, 500, "map{mapX}{arrayX}[1] for %s - %s", ip,
192
- mode_desc);
193
- data =
194
- data_ok(result, MMDB_DATA_TYPE_UINT32, description, "map", "mapX",
195
- "arrayX", "1", NULL);
196
- ok(data.uint32 == 8, "map{mapX}{arrayX}[1] is 8");
197
-
198
- snprintf(description, 500, "map{mapX}{arrayX}[2] for %s - %s", ip,
199
- mode_desc);
200
- data =
201
- data_ok(result, MMDB_DATA_TYPE_UINT32, description, "map", "mapX",
202
- "arrayX", "2", NULL);
203
- ok(data.uint32 == 9, "map{mapX}{arrayX}[2] is 9");
204
- }
205
-
206
- }
207
-
208
- void test_all_data_types_as_zero(MMDB_lookup_result_s *result, const char *ip,
209
- const char *UNUSED(
210
- filename), const char *mode_desc)
211
- {
212
- {
213
- char description[500];
214
- snprintf(description, 500, "utf8_string field for %s - %s", ip,
215
- mode_desc);
216
-
217
- MMDB_entry_data_s data =
218
- data_ok(result, MMDB_DATA_TYPE_UTF8_STRING, description,
219
- "utf8_string", NULL);
220
- is(data.utf8_string, "", "got expected utf8_string value (NULL)");
221
- }
222
-
223
- {
224
- char description[500];
225
- snprintf(description, 500, "double field for %s - %s", ip, mode_desc);
226
-
227
- MMDB_entry_data_s data =
228
- data_ok(result, MMDB_DATA_TYPE_DOUBLE, description, "double", NULL);
229
-
230
- compare_double(data.double_value, 0.0);
231
- }
232
-
233
- {
234
- char description[500];
235
- snprintf(description, 500, "float field for %s - %s", ip, mode_desc);
236
-
237
- MMDB_entry_data_s data =
238
- data_ok(result, MMDB_DATA_TYPE_FLOAT, description, "float", NULL);
239
-
240
- compare_float(data.float_value, 0.0F);
241
- }
242
-
243
- {
244
- char description[500];
245
- snprintf(description, 500, "bytes field for %s - %s", ip, mode_desc);
246
-
247
- MMDB_entry_data_s data =
248
- data_ok(result, MMDB_DATA_TYPE_BYTES, description, "bytes", NULL);
249
- ok(data.data_size == 0, "bytes field data_size is 0");
250
- /* In C does it makes sense to write something like this?
251
- uint8_t expect[0] = {};
252
- ok(memcmp(data.bytes, expect, 0) == 0, "got expected bytes value (NULL)"); */
253
- }
254
-
255
- {
256
- char description[500];
257
- snprintf(description, 500, "uint16 field for %s - %s", ip, mode_desc);
258
-
259
- MMDB_entry_data_s data =
260
- data_ok(result, MMDB_DATA_TYPE_UINT16, description, "uint16", NULL);
261
- uint16_t expect = 0;
262
- ok(data.uint16 == expect, "uint16 field is 0");
263
- }
264
-
265
- {
266
- char description[500];
267
- snprintf(description, 500, "uint32 field for %s - %s", ip, mode_desc);
268
-
269
- MMDB_entry_data_s data =
270
- data_ok(result, MMDB_DATA_TYPE_UINT32, description, "uint32", NULL);
271
- uint32_t expect = 0;
272
- cmp_ok(data.uint32, "==", expect, "uint32 field is 0");
273
- }
274
-
275
- {
276
- char description[500];
277
- snprintf(description, 500, "int32 field for %s - %s", ip, mode_desc);
278
-
279
- MMDB_entry_data_s data =
280
- data_ok(result, MMDB_DATA_TYPE_INT32, description, "int32", NULL);
281
- int32_t expect = 0;
282
- expect *= -1;
283
- cmp_ok(data.int32, "==", expect, "int32 field is 0");
284
- }
285
-
286
- {
287
- char description[500];
288
- snprintf(description, 500, "uint64 field for %s - %s", ip, mode_desc);
289
-
290
- MMDB_entry_data_s data =
291
- data_ok(result, MMDB_DATA_TYPE_UINT64, description, "uint64", NULL);
292
- uint64_t expect = 0;
293
- cmp_ok(data.uint64, "==", expect, "uint64 field is 0");
294
- }
295
-
296
- {
297
- char description[500];
298
- snprintf(description, 500, "uint128 field for %s - %s", ip, mode_desc);
299
-
300
- MMDB_entry_data_s data =
301
- data_ok(result, MMDB_DATA_TYPE_UINT128, description, "uint128",
302
- NULL);
303
- #if MMDB_UINT128_IS_BYTE_ARRAY
304
- uint8_t expect[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
306
- ok(memcmp(data.uint128, expect, 16) == 0, "uint128 field is 0");
307
- #else
308
- mmdb_uint128_t expect = 0;
309
- cmp_ok(data.uint128, "==", expect, "uint128 field is 0");
310
- #endif
311
- }
312
-
313
- {
314
- char description[500];
315
- snprintf(description, 500, "boolean field for %s - %s", ip, mode_desc);
316
-
317
- MMDB_entry_data_s data =
318
- data_ok(result, MMDB_DATA_TYPE_BOOLEAN, description, "boolean",
319
- NULL);
320
- cmp_ok(data.boolean, "==", false, "boolean field is false");
321
- }
322
-
323
- {
324
- char description[500];
325
- snprintf(description, 500, "array field for %s - %s", ip, mode_desc);
326
-
327
- MMDB_entry_data_s data =
328
- data_ok(result, MMDB_DATA_TYPE_ARRAY, description, "array", NULL);
329
- ok(data.data_size == 0, "array field has 0 elements");
330
- }
331
-
332
- {
333
- char description[500];
334
- snprintf(description, 500, "map field for %s - %s", ip, mode_desc);
335
-
336
- MMDB_entry_data_s data =
337
- data_ok(result, MMDB_DATA_TYPE_MAP, description, "map", NULL);
338
- ok(data.data_size == 0, "map field has 0 elements");
339
- }
340
- }
341
-
342
- void run_tests(int mode, const char *mode_desc)
343
- {
344
- const char *filename = "MaxMind-DB-test-decoder.mmdb";
345
- const char *path = test_database_path(filename);
346
- MMDB_s *mmdb = open_ok(path, mode, mode_desc);
347
-
348
- // All of the remaining tests require an open mmdb
349
- if (NULL == mmdb) {
350
- diag("could not open %s - skipping remaining tests", path);
351
- return;
352
- }
353
-
354
- free((void *)path);
355
-
356
- {
357
- const char *ip = "not an ip";
358
-
359
- int gai_error, mmdb_error;
360
- MMDB_lookup_result_s result =
361
- MMDB_lookup_string(mmdb, ip, &gai_error, &mmdb_error);
362
-
363
- cmp_ok(gai_error, "==", EAI_NONAME,
364
- "MMDB_lookup populates getaddrinfo error properly - %s", ip);
365
-
366
- ok(!result.found_entry,
367
- "no result entry struct returned for invalid IP address '%s'", ip);
368
- }
369
-
370
- {
371
- const char *ip = "e900::";
372
- MMDB_lookup_result_s result =
373
- lookup_string_ok(mmdb, ip, filename, mode_desc);
374
-
375
- ok(
376
- !result.found_entry,
377
- "no result entry struct returned for IP address not in the database - %s - %s - %s",
378
- ip, filename, mode_desc);
379
- }
380
-
381
- {
382
- const char *ip = "::1.1.1.1";
383
- MMDB_lookup_result_s result =
384
- lookup_string_ok(mmdb, ip, filename, mode_desc);
385
-
386
- ok(
387
- result.found_entry,
388
- "got a result entry struct for IP address in the database - %s - %s - %s",
389
- ip, filename, mode_desc);
390
-
391
- cmp_ok(
392
- result.entry.offset, ">", 0,
393
- "result.entry.offset > 0 for address in the database - %s - %s - %s",
394
- ip, filename, mode_desc);
395
-
396
- test_all_data_types(&result, ip, filename, mode_desc);
397
- }
398
-
399
- {
400
- const char *ip = "::4.5.6.7";
401
- MMDB_lookup_result_s result =
402
- lookup_string_ok(mmdb, ip, filename, mode_desc);
403
-
404
- ok(
405
- result.found_entry,
406
- "got a result entry struct for IP address in the database - %s - %s - %s",
407
- ip, filename, mode_desc);
408
-
409
- cmp_ok(
410
- result.entry.offset, ">", 0,
411
- "result.entry.offset > 0 for address in the database - %s - %s - %s",
412
- ip, filename, mode_desc);
413
-
414
- test_all_data_types(&result, ip, filename, mode_desc);
415
- }
416
-
417
- {
418
- const char *ip = "::0.0.0.0";
419
- MMDB_lookup_result_s result =
420
- lookup_string_ok(mmdb, ip, filename, mode_desc);
421
-
422
- ok(
423
- result.found_entry,
424
- "got a result entry struct for IP address in the database - %s - %s - %s",
425
- ip, filename, mode_desc);
426
-
427
- test_all_data_types_as_zero(&result, ip, filename, mode_desc);
428
- }
429
-
430
- MMDB_close(mmdb);
431
- free(mmdb);
432
- }
433
-
434
- int main(void)
435
- {
436
- plan(NO_PLAN);
437
- for_all_modes(&run_tests);
438
- done_testing();
439
- }
@@ -1,103 +0,0 @@
1
- #define _GNU_SOURCE
2
- #include "maxminddb_test_helper.h"
3
-
4
- #ifdef HAVE_OPEN_MEMSTREAM
5
- void run_tests(int mode, const char *mode_desc)
6
- {
7
- const char *filename = "MaxMind-DB-test-decoder.mmdb";
8
- const char *path = test_database_path(filename);
9
- MMDB_s *mmdb = open_ok(path, mode, mode_desc);
10
- free((void *)path);
11
-
12
- const char *ip = "1.1.1.1";
13
- MMDB_lookup_result_s result =
14
- lookup_string_ok(mmdb, ip, filename, mode_desc);
15
-
16
- MMDB_entry_data_list_s *entry_data_list;
17
- int status = MMDB_get_entry_data_list(&result.entry, &entry_data_list);
18
-
19
- ok(MMDB_SUCCESS == status,
20
- "MMDB_get_entry_data_list is successful");
21
-
22
- char *dump_output;
23
- size_t dump_size;
24
- FILE *stream = open_memstream(&dump_output, &dump_size);
25
- status = MMDB_dump_entry_data_list(stream, entry_data_list, 0);
26
- fclose(stream);
27
- MMDB_free_entry_data_list(entry_data_list);
28
-
29
- ok(MMDB_SUCCESS == status,
30
- "MMDB_dump_entry_data_list is successful - %s",
31
- mode_desc);
32
-
33
- cmp_ok(dump_size, ">", 0, "MMDB_dump produced output - %s", mode_desc);
34
-
35
- char *expect[] = {
36
- "{",
37
- " \"array\": ",
38
- " [",
39
- " 1 <uint32>",
40
- " 2 <uint32>",
41
- " 3 <uint32>",
42
- " ]",
43
- " \"boolean\": ",
44
- " true <boolean>",
45
- " \"bytes\": ",
46
- " 0000002A <bytes>",
47
- " \"double\": ",
48
- " 42.123456 <double>",
49
- " \"float\": ",
50
- " 1.100000 <float>",
51
- " \"int32\": ",
52
- " -268435456 <int32>",
53
- " \"map\": ",
54
- " {",
55
- " \"mapX\": ",
56
- " {",
57
- " \"arrayX\": ",
58
- " [",
59
- " 7 <uint32>",
60
- " 8 <uint32>",
61
- " 9 <uint32>",
62
- " ]",
63
- " \"utf8_stringX\": ",
64
- " \"hello\" <utf8_string>",
65
- " }",
66
- " }",
67
- " \"uint128\": ",
68
- " 0x01000000000000000000000000000000 <uint128>",
69
- " \"uint16\": ",
70
- " 100 <uint16>",
71
- " \"uint32\": ",
72
- " 268435456 <uint32>",
73
- " \"uint64\": ",
74
- " 1152921504606846976 <uint64>",
75
- " \"utf8_string\": ",
76
- " \"unicode! ☯ - ♫\" <utf8_string>",
77
- "}"
78
- };
79
-
80
- for (int i = 0; i < 42; i++) {
81
- ok((strstr(dump_output, expect[i]) != NULL),
82
- "dump output contains expected line (%s) - %s", expect[i],
83
- mode_desc);
84
- }
85
-
86
- free(dump_output);
87
-
88
- MMDB_close(mmdb);
89
- free(mmdb);
90
- }
91
-
92
- int main(void)
93
- {
94
- plan(NO_PLAN);
95
- for_all_modes(&run_tests);
96
- done_testing();
97
- }
98
- #else
99
- int main(void)
100
- {
101
- plan(SKIP_ALL, "This test requires the open_memstream() function");
102
- }
103
- #endif
@@ -1,106 +0,0 @@
1
- #!/usr/bin/env perl
2
-
3
- use strict;
4
- use warnings;
5
-
6
- use FindBin qw( $Bin );
7
-
8
- _skip_tests_if_required_modules_are_not_present();
9
- _skip_tests_if_nm_is_not_present();
10
- _test_libs_external_symbols();
11
-
12
- done_testing();
13
-
14
- sub _skip_tests_if_required_modules_are_not_present {
15
- eval <<'EOF';
16
- use Test::More 0.88;
17
- use IPC::Run3 qw( run3 );
18
- EOF
19
-
20
- if ($@) {
21
- print
22
- "1..0 # skip all tests skipped - these tests need the Test::More 0.88, IPC::Run3 modules:\n";
23
- print "$@";
24
- exit 0;
25
- }
26
- }
27
-
28
- sub _skip_tests_if_nm_is_not_present {
29
- run3(
30
- [ 'nm', '-V' ],
31
- \undef,
32
- \undef,
33
- \undef,
34
- );
35
-
36
- my $exit_status = $? >> 8;
37
- if ($exit_status) {
38
- print
39
- "1..0 # skipp all tests skipped - this test requires the command line utility `nm`.\n";
40
- exit 0;
41
- }
42
- }
43
-
44
- sub _test_libs_external_symbols {
45
- my @libs = _libs_to_test();
46
-
47
- if (@libs) {
48
- for my $lib (@libs) {
49
- _test_lib_external_symbols($lib);
50
- }
51
- }
52
- else {
53
- fail('No libs were found to test');
54
- }
55
- }
56
-
57
- sub _libs_to_test {
58
- my $lib_dir = "$Bin/../src/.libs";
59
- opendir my $dh, $lib_dir
60
- or die "Failed to open the lib dir at $lib_dir for reading: $!\n";
61
- my @libs = map { $lib_dir . q{/} . $_ }
62
- grep { $_ =~ m/\.so$/ } readdir $dh;
63
- closedir $dh;
64
-
65
- return @libs;
66
- }
67
-
68
- sub _test_lib_external_symbols {
69
- my $lib = shift;
70
-
71
- my $stdout;
72
- my $stderr;
73
- run3(
74
- [ 'nm', '-g', '--defined-only', $lib ],
75
- \undef,
76
- \$stdout,
77
- \$stderr,
78
- );
79
-
80
- my $exit_status = $? >> 8;
81
- ok( !$exit_status, 'nm returned a non-error status' )
82
- or diag($stderr);
83
-
84
- my @external_symbols = _extract_external_symbols($stdout);
85
- is_deeply(
86
- [ grep { $_ !~ m/^MMDB_/ } @external_symbols ],
87
- [],
88
- "$lib exports only MMDB_ symbols"
89
- );
90
- }
91
-
92
- sub _extract_external_symbols {
93
- my $nm_output = shift;
94
-
95
- my @lines = split /\r\n|\r|\n/, $nm_output;
96
-
97
- my @external_symbols;
98
- for my $line (@lines) {
99
- my @fields = split /\s+/, $line;
100
- die "Unexpected nm output for line $line\n"
101
- if @fields != 3;
102
- push @external_symbols, $fields[2];
103
- }
104
-
105
- return @external_symbols;
106
- }