geoip2_c 0.3.3 → 0.3.4
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.
- checksums.yaml +4 -4
- data/.github/workflows/ubuntu.yml +33 -0
- data/.github/workflows/windows.yml +52 -0
- data/README.md +3 -9
- data/docker-compose.yml +7 -0
- data/dockerfiles/Dockerfile-ruby2.7 +8 -0
- data/ext/geoip2/extconf.rb +11 -4
- data/ext/geoip2/geoip2.c +58 -15
- data/ext/geoip2/libmaxminddb/t/libtap/.gitignore +13 -0
- data/ext/geoip2/libmaxminddb/t/libtap/.travis.yml +13 -0
- data/ext/geoip2/libmaxminddb/t/libtap/COPYING +165 -0
- data/ext/geoip2/libmaxminddb/t/libtap/INSTALL +41 -0
- data/ext/geoip2/libmaxminddb/t/libtap/Makefile +72 -0
- data/ext/geoip2/libmaxminddb/t/libtap/Makefile.win +37 -0
- data/ext/geoip2/libmaxminddb/t/libtap/README.md +268 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/cmp_mem.c +20 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/cmp_mem.expected +28 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/cmpok.c +16 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/cmpok.expected +37 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/diag.c +10 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/diag.expected +2 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/diesok.c +14 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/diesok.expected +6 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/is.c +24 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/is.expected +58 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/like.c +10 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/like.expected +4 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/simple.c +31 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/simple.expected +32 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/skip.c +23 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/skip.expected +9 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/synopsis.c +13 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/synopsis.expected +9 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/test.c +28 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/todo.c +17 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/todo.expected +11 -0
- data/ext/geoip2/libmaxminddb/t/libtap/tap.c +354 -0
- data/ext/geoip2/libmaxminddb/t/libtap/tap.h +115 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/.gitattributes +1 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/.gitconfig +2 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/.gitignore +2 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/.perltidyallrc +11 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/.tidyallrc +7 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/LICENSE +4 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/MaxMind-DB-spec.md +558 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/README.md +4 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/README.md +7 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/libmaxminddb/libmaxminddb-offset-integer-overflow.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/cyclic-data-structure.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-bytes-length.mmdb +1 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-data-record-offset.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-map-key-length.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-string-length.mmdb +1 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/metadata-is-an-uint128.mmdb +1 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/unexpected-bytes.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/perltidyrc +12 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Anonymous-IP-Test.json +32 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-City-Test.json +12616 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Connection-Type-Test.json +102 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Country-Test.json +10975 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-DensityIncome-Test.json +14 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Domain-Test.json +452 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Enterprise-Test.json +666 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-ISP-Test.json +12585 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Precision-Enterprise-Test.json +1035 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoLite2-ASN-Test.json +37 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/README +13 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Anonymous-IP-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-City-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Connection-Type-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Country-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-DensityIncome-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Domain-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Enterprise-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-ISP-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Precision-Enterprise-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoLite2-ASN-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-string-value-entries.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-broken-pointers-24.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-decoder.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv4-24.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv4-28.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv4-32.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv6-24.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv6-28.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv6-32.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-metadata-pointers.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-mixed-24.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-mixed-28.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-mixed-32.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-nested.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/README.md +26 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/maps-with-pointers.raw +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/write-test-data.pl +614 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/tidyall.ini +5 -0
- data/geoip2_c.gemspec +2 -3
- data/lib/geoip2/database.rb +4 -0
- data/lib/geoip2/version.rb +1 -1
- metadata +108 -18
- data/.travis.yml +0 -30
- data/Appraisals +0 -7
- data/gemfiles/ruby_2.1.gemfile +0 -7
- data/gemfiles/ruby_2.2.gemfile +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: abed5426ff2b76c33f8fbfd79a591b86fe2dc5a6aeea1a73723e37763537271f
|
|
4
|
+
data.tar.gz: e77eb5aa947623d9be2fa2f2161081145d50e57f75f516cb775b0757965aff83
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 36b58ccb36e05a271a2806ec0ab53f9a4445175cb24a39916f2e674b2373f0f82275946a327b925567e63de06c64ddfd462376a3dec056649c6559b95d50faa7
|
|
7
|
+
data.tar.gz: f3deafdd7c89751ee468d950506dee5395381ef810cbe7683d4043973e1a7ad547e24e04f61925a51ff99526d116908da790b708c41a5c1f8378b200f1f82608
|
|
@@ -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@v3
|
|
18
|
+
with:
|
|
19
|
+
submodules: true
|
|
20
|
+
- name: Setup ruby
|
|
21
|
+
uses: ruby/setup-ruby@v1
|
|
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@v3
|
|
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@v1
|
|
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/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
|
-
##
|
|
8
|
+
## Supported Ruby versions
|
|
9
9
|
|
|
10
|
-
|
|
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/
|
|
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
data/ext/geoip2/extconf.rb
CHANGED
|
@@ -5,12 +5,19 @@ libdir = RbConfig::CONFIG["libdir"]
|
|
|
5
5
|
includedir = RbConfig::CONFIG["includedir"]
|
|
6
6
|
|
|
7
7
|
maxminddb_dir = File.expand_path(File.join(__dir__, "libmaxminddb"))
|
|
8
|
+
gem_root = File.expand_path('..', __dir__)
|
|
9
|
+
|
|
10
|
+
if !File.directory?(maxminddb_dir) ||
|
|
11
|
+
# '.', '..', and possibly '.git' from a failed checkout:
|
|
12
|
+
Dir.entries(maxminddb_dir).size <= 3
|
|
13
|
+
Dir.chdir(gem_root) { system('git submodule update --init') } or fail 'Could not fetch maxminddb'
|
|
14
|
+
end
|
|
8
15
|
|
|
9
16
|
Dir.chdir(maxminddb_dir) do
|
|
10
|
-
system("./bootstrap")
|
|
11
|
-
system({ "CFLAGS" => "-fPIC" }, "./configure", "--disable-shared", "--disable-tests")
|
|
12
|
-
system("make", "clean")
|
|
13
|
-
system("make")
|
|
17
|
+
system("./bootstrap") or fail "Couldn't run maxminddb `bootstrap`"
|
|
18
|
+
system({ "CFLAGS" => "-fPIC" }, "./configure", "--disable-shared", "--disable-tests") or fail "Couldn't run maxminddb `configure`"
|
|
19
|
+
system("make", "clean") or fail "Couldn't run maxminddb `make clean`"
|
|
20
|
+
system("make") or fail "Couldn't run maxminddb `make`"
|
|
14
21
|
end
|
|
15
22
|
|
|
16
23
|
header_dirs = [includedir, "#{maxminddb_dir}/include"]
|
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
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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",
|
|
441
|
-
rb_cGeoIP2LookupResult = rb_define_class_under(rb_mGeoIP2, "LookupResult",
|
|
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, "
|
|
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
|
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
To install libtap on a Unix-like system:
|
|
2
|
+
|
|
3
|
+
$ make
|
|
4
|
+
$ make check
|
|
5
|
+
$ make install
|
|
6
|
+
|
|
7
|
+
To compile with gcc -ansi, run:
|
|
8
|
+
|
|
9
|
+
$ ANSI=1 make
|
|
10
|
+
|
|
11
|
+
To install to a different directory than /usr/local, supply the
|
|
12
|
+
PREFIX variable to make:
|
|
13
|
+
|
|
14
|
+
$ PREFIX=/usr make install
|
|
15
|
+
|
|
16
|
+
On Windows, the library can be created by first setting up the
|
|
17
|
+
correct development environment variables. Usually this is done by
|
|
18
|
+
running vcvars32.bat included in the Visual Studio distribution.
|
|
19
|
+
You should also install gnu make which can be found at
|
|
20
|
+
http://gnuwin32.sourceforge.net/packages/make.htm. Once this is
|
|
21
|
+
done, you should be able to run the following:
|
|
22
|
+
|
|
23
|
+
> make -f Makefile.win
|
|
24
|
+
|
|
25
|
+
If you want to use it directly in another project, you can copy tap.c
|
|
26
|
+
and tap.h there and it shouldn't have a problem compiling.
|
|
27
|
+
|
|
28
|
+
$ ls
|
|
29
|
+
tap.c tap.h test.c
|
|
30
|
+
$ cat test.c
|
|
31
|
+
#include "tap.h"
|
|
32
|
+
int main () {
|
|
33
|
+
plan(1);
|
|
34
|
+
ok(50 + 5, "foo %s", "bar");
|
|
35
|
+
done_testing();
|
|
36
|
+
}
|
|
37
|
+
$ gcc test.c tap.c
|
|
38
|
+
$ a.out
|
|
39
|
+
1..1
|
|
40
|
+
ok 1 - foo bar
|
|
41
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
CC ?= gcc
|
|
2
|
+
CFLAGS += -Wall -I. -fPIC
|
|
3
|
+
PREFIX ?= $(DESTDIR)/usr/local
|
|
4
|
+
TESTS = $(patsubst %.c, %, $(wildcard t/*.c))
|
|
5
|
+
|
|
6
|
+
ifdef ANSI
|
|
7
|
+
# -D_BSD_SOURCE for MAP_ANONYMOUS
|
|
8
|
+
CFLAGS += -ansi -D_BSD_SOURCE
|
|
9
|
+
LDLIBS += -lbsd-compat
|
|
10
|
+
endif
|
|
11
|
+
|
|
12
|
+
%:
|
|
13
|
+
$(CC) $(LDFLAGS) $(TARGET_ARCH) $(filter %.o %.a %.so, $^) $(LDLIBS) -o $@
|
|
14
|
+
|
|
15
|
+
%.o:
|
|
16
|
+
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $(filter %.c, $^) $(LDLIBS) -o $@
|
|
17
|
+
|
|
18
|
+
%.a:
|
|
19
|
+
$(AR) rcs $@ $(filter %.o, $^)
|
|
20
|
+
|
|
21
|
+
%.so:
|
|
22
|
+
$(CC) -shared $(LDFLAGS) $(TARGET_ARCH) $(filter %.o, $^) $(LDLIBS) -o $@
|
|
23
|
+
|
|
24
|
+
all: libtap.a libtap.so tap.pc tests
|
|
25
|
+
|
|
26
|
+
tap.pc:
|
|
27
|
+
@echo generating tap.pc
|
|
28
|
+
@echo 'prefix='$(PREFIX) > tap.pc
|
|
29
|
+
@echo 'exec_prefix=$${prefix}' >> tap.pc
|
|
30
|
+
@echo 'libdir=$${prefix}/lib' >> tap.pc
|
|
31
|
+
@echo 'includedir=$${prefix}/include' >> tap.pc
|
|
32
|
+
@echo '' >> tap.pc
|
|
33
|
+
@echo 'Name: libtap' >> tap.pc
|
|
34
|
+
@echo 'Description: Write tests in C' >> tap.pc
|
|
35
|
+
@echo 'Version: 0.1.0' >> tap.pc
|
|
36
|
+
@echo 'URL: https://github.com/zorgnax/libtap' >> tap.pc
|
|
37
|
+
@echo 'Libs: -L$${libdir} -ltap' >> tap.pc
|
|
38
|
+
@echo 'Cflags: -I$${includedir}' >> tap.pc
|
|
39
|
+
|
|
40
|
+
libtap.a: tap.o
|
|
41
|
+
|
|
42
|
+
libtap.so: tap.o
|
|
43
|
+
|
|
44
|
+
tap.o: tap.c tap.h
|
|
45
|
+
|
|
46
|
+
tests: $(TESTS)
|
|
47
|
+
|
|
48
|
+
$(TESTS): %: %.o libtap.a
|
|
49
|
+
|
|
50
|
+
$(patsubst %, %.o, $(TESTS)): %.o: %.c tap.h
|
|
51
|
+
|
|
52
|
+
clean:
|
|
53
|
+
rm -rf *.o t/*.o tap.pc libtap.a libtap.so $(TESTS)
|
|
54
|
+
|
|
55
|
+
install: libtap.a tap.h libtap.so tap.pc
|
|
56
|
+
mkdir -p $(PREFIX)/lib $(PREFIX)/include $(PREFIX)/lib/pkgconfig
|
|
57
|
+
install -c libtap.a $(PREFIX)/lib
|
|
58
|
+
install -c libtap.so $(PREFIX)/lib
|
|
59
|
+
install -c tap.pc $(PREFIX)/lib/pkgconfig
|
|
60
|
+
install -c tap.h $(PREFIX)/include
|
|
61
|
+
|
|
62
|
+
uninstall:
|
|
63
|
+
rm $(PREFIX)/lib/libtap.a $(PREFIX)/lib/libtap.so $(PREFIX)/include/tap.h
|
|
64
|
+
|
|
65
|
+
dist:
|
|
66
|
+
rm libtap.zip
|
|
67
|
+
zip -r libtap *
|
|
68
|
+
|
|
69
|
+
check test: all
|
|
70
|
+
./t/test
|
|
71
|
+
|
|
72
|
+
.PHONY: all clean install uninstall dist check test tests
|