geoip2_c 0.3.2 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ubuntu.yml +33 -0
- data/.github/workflows/windows.yml +52 -0
- data/README.md +22 -10
- data/docker-compose.yml +22 -1
- data/dockerfiles/{Dockerfile-ruby2.3 → Dockerfile-ruby2.5} +1 -1
- data/dockerfiles/{Dockerfile-ruby2.1 → Dockerfile-ruby2.6} +1 -1
- data/dockerfiles/{Dockerfile-ruby2.2 → Dockerfile-ruby2.7} +1 -1
- data/ext/geoip2/extconf.rb +11 -4
- data/ext/geoip2/geoip2.c +63 -18
- data/ext/geoip2/libmaxminddb/.gitignore +3 -0
- data/ext/geoip2/libmaxminddb/.travis.yml +24 -2
- data/ext/geoip2/libmaxminddb/Changes.md +39 -0
- data/ext/geoip2/libmaxminddb/README.dev.md +41 -30
- data/ext/geoip2/libmaxminddb/README.md +3 -3
- data/ext/geoip2/libmaxminddb/bin/Makefile.am +5 -0
- data/ext/geoip2/libmaxminddb/bin/mmdblookup.c +333 -15
- data/ext/geoip2/libmaxminddb/configure.ac +5 -5
- data/ext/geoip2/libmaxminddb/dev-bin/ppa-release.sh +8 -5
- data/ext/geoip2/libmaxminddb/dev-bin/release.sh +7 -0
- data/ext/geoip2/libmaxminddb/dev-bin/valgrind-all.pl +10 -3
- data/ext/geoip2/libmaxminddb/include/maxminddb.h +11 -2
- data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj +3 -1
- data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj.filters +7 -1
- data/ext/geoip2/libmaxminddb/src/Makefile.am +18 -2
- data/ext/geoip2/libmaxminddb/src/data-pool.c +180 -0
- data/ext/geoip2/libmaxminddb/src/data-pool.h +52 -0
- data/ext/geoip2/libmaxminddb/src/maxminddb.c +58 -48
- data/ext/geoip2/libmaxminddb/t/Makefile.am +6 -2
- data/ext/geoip2/libmaxminddb/t/bad_databases_t.c +1 -0
- data/ext/geoip2/libmaxminddb/t/basic_lookup_t.c +35 -0
- data/ext/geoip2/libmaxminddb/t/data-pool-t.c +374 -0
- data/ext/geoip2/libmaxminddb/t/external_symbols_t.pl +106 -0
- 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 +114 -22
- data/.travis.yml +0 -31
- 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
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
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,27 @@ 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
|
-
|
10
|
+
See [workflows](https://github.com/fluent-plugins-nursery/geoip2_c/blob/master/.github/workflows/ubuntu.yml)
|
11
11
|
|
12
|
-
|
12
|
+
## Build requirements
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
Need ruby.h to build this extension, so you must install it before build this extension.
|
15
|
+
|
16
|
+
Debian GNU Linux / Ubuntu:
|
17
|
+
|
18
|
+
```
|
19
|
+
$ sudo apt install -y build-essential automake autoconf libtool
|
20
|
+
```
|
21
|
+
|
22
|
+
CentOS:
|
23
|
+
|
24
|
+
```
|
25
|
+
$ sudo yum groupinstall -y "Development Tools"
|
26
|
+
```
|
27
|
+
|
28
|
+
**NOTE**: If you want to use libmaxminddb provided as a deb/rpm package, you can install libmaxminddb-dev or libmaxminddb-devel at your own risk.
|
17
29
|
|
18
30
|
## Installation
|
19
31
|
|
@@ -36,10 +48,10 @@ Or install it yourself as:
|
|
36
48
|
```ruby
|
37
49
|
require "geoip2"
|
38
50
|
|
39
|
-
db = GeoIP2::
|
51
|
+
db = GeoIP2::Database.new("GeoLite2-City.mmdb")
|
40
52
|
result = db.lookup("66.102.9.80")
|
41
|
-
|
42
|
-
|
53
|
+
result.get_value("city", "names", "en") # => "Mountain View"
|
54
|
+
result.dig("city", "names", "en") # => "Mountain View"
|
43
55
|
```
|
44
56
|
|
45
57
|
## Development
|
@@ -50,7 +62,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
50
62
|
|
51
63
|
## Contributing
|
52
64
|
|
53
|
-
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.
|
54
66
|
|
55
67
|
## License
|
56
68
|
|
data/docker-compose.yml
CHANGED
@@ -1,5 +1,26 @@
|
|
1
|
-
version: "
|
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
|
10
|
+
test-ruby2.6:
|
11
|
+
build:
|
12
|
+
context: .
|
13
|
+
dockerfile: dockerfiles/Dockerfile-ruby2.6
|
14
|
+
command: tail -f /dev/null
|
15
|
+
environment:
|
16
|
+
- BUNDLE_GEMFILE=Gemfile
|
17
|
+
test-ruby2.5:
|
18
|
+
build:
|
19
|
+
context: .
|
20
|
+
dockerfile: dockerfiles/Dockerfile-ruby2.5
|
21
|
+
command: tail -f /dev/null
|
22
|
+
environment:
|
23
|
+
- BUNDLE_GEMFILE=Gemfile
|
3
24
|
test-ruby2.4:
|
4
25
|
build:
|
5
26
|
context: .
|
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,16 +28,23 @@ 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,
|
33
|
-
}, NULL, NULL
|
39
|
+
}, NULL, NULL,
|
40
|
+
RUBY_TYPED_FREE_IMMEDIATELY
|
34
41
|
};
|
35
42
|
|
36
43
|
static const rb_data_type_t rb_lookup_result_type = {
|
37
44
|
"geoip2/lookup_result", {
|
38
|
-
0,
|
39
|
-
}, NULL, NULL
|
45
|
+
0, RUBY_DEFAULT_FREE, 0,
|
46
|
+
}, NULL, NULL,
|
47
|
+
RUBY_TYPED_FREE_IMMEDIATELY
|
40
48
|
};
|
41
49
|
|
42
50
|
static void
|
@@ -155,19 +163,36 @@ mmdb_entry_data_decode(MMDB_entry_data_s *entry_data)
|
|
155
163
|
}
|
156
164
|
}
|
157
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
|
+
|
158
183
|
static VALUE
|
159
184
|
mmdb_guard_parse_entry_data_list(VALUE ptr)
|
160
185
|
{
|
161
|
-
MMDB_entry_data_list_s *data_list =
|
162
|
-
|
186
|
+
MMDB_entry_data_list_s *data_list = ((ParseRequest *)ptr)->data_list;
|
187
|
+
bool symbolize_keys = ((ParseRequest *)ptr)->symbolize_keys;
|
163
188
|
VALUE obj;
|
164
189
|
|
165
|
-
mmdb_parse_entry_data_list(data_list, &obj);
|
190
|
+
mmdb_parse_entry_data_list(data_list, symbolize_keys, &obj);
|
166
191
|
return obj;
|
167
192
|
}
|
168
193
|
|
169
194
|
static MMDB_entry_data_list_s *
|
170
|
-
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)
|
171
196
|
{
|
172
197
|
switch (data_list->entry_data.type) {
|
173
198
|
case MMDB_DATA_TYPE_MAP:
|
@@ -177,9 +202,9 @@ mmdb_parse_entry_data_list(MMDB_entry_data_list_s *data_list, VALUE *obj)
|
|
177
202
|
for (data_list = data_list->next; data_size && data_list; data_size--) {
|
178
203
|
VALUE key;
|
179
204
|
VALUE val;
|
180
|
-
key =
|
205
|
+
key = mmdb_entry_data_decode_key(&data_list->entry_data, symbolize_keys);
|
181
206
|
data_list = data_list->next;
|
182
|
-
data_list = mmdb_parse_entry_data_list(data_list, &val);
|
207
|
+
data_list = mmdb_parse_entry_data_list(data_list, symbolize_keys, &val);
|
183
208
|
rb_hash_aset(hash, key, val);
|
184
209
|
}
|
185
210
|
*obj = hash;
|
@@ -191,7 +216,7 @@ mmdb_parse_entry_data_list(MMDB_entry_data_list_s *data_list, VALUE *obj)
|
|
191
216
|
VALUE array = rb_ary_new();
|
192
217
|
for (data_list = data_list->next; data_size && data_list; data_size--) {
|
193
218
|
VALUE val;
|
194
|
-
data_list = mmdb_parse_entry_data_list(data_list, &val);
|
219
|
+
data_list = mmdb_parse_entry_data_list(data_list, symbolize_keys, &val);
|
195
220
|
rb_ary_push(array, val);
|
196
221
|
}
|
197
222
|
*obj = array;
|
@@ -231,7 +256,7 @@ rb_geoip2_db_alloc(VALUE klass)
|
|
231
256
|
}
|
232
257
|
|
233
258
|
static VALUE
|
234
|
-
|
259
|
+
rb_geoip2_db_open_mmdb(VALUE self, VALUE path)
|
235
260
|
{
|
236
261
|
char *db_path;
|
237
262
|
MMDB_s *mmdb;
|
@@ -286,6 +311,9 @@ rb_geoip2_db_lookup(VALUE self, VALUE ip)
|
|
286
311
|
result_ptr->found_entry = result.found_entry;
|
287
312
|
result_ptr->entry = result.entry;
|
288
313
|
result_ptr->netmask = result.netmask;
|
314
|
+
|
315
|
+
rb_iv_set(obj, "@symbolize_keys", rb_iv_get(self, "@symbolize_keys"));
|
316
|
+
|
289
317
|
return obj;
|
290
318
|
}
|
291
319
|
|
@@ -380,8 +408,9 @@ rb_geoip2_lr_get_value(int argc, VALUE *argv, VALUE self)
|
|
380
408
|
VALUE array = rb_ary_new();
|
381
409
|
VALUE hash;
|
382
410
|
VALUE val;
|
411
|
+
bool symbolize_keys = RTEST(rb_iv_get(self, "@symbolize_keys"));
|
383
412
|
for (int j = 0; path[j] != NULL; j++) {
|
384
|
-
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]));
|
385
414
|
}
|
386
415
|
hash = rb_funcall(self, rb_intern("to_h"), 0);
|
387
416
|
val = rb_apply(hash, rb_intern("dig"), array);
|
@@ -393,6 +422,19 @@ rb_geoip2_lr_get_value(int argc, VALUE *argv, VALUE self)
|
|
393
422
|
return mmdb_entry_data_decode(&entry_data);
|
394
423
|
}
|
395
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
|
+
|
396
438
|
static VALUE
|
397
439
|
rb_geoip2_lr_to_h(VALUE self)
|
398
440
|
{
|
@@ -419,7 +461,9 @@ rb_geoip2_lr_to_h(VALUE self)
|
|
419
461
|
rb_raise(rb_eGeoIP2Error, "%s", MMDB_strerror(status));
|
420
462
|
}
|
421
463
|
|
422
|
-
|
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);
|
423
467
|
MMDB_free_entry_data_list(entry_data_list);
|
424
468
|
|
425
469
|
if (exception != 0) {
|
@@ -435,17 +479,18 @@ void
|
|
435
479
|
Init_geoip2(void)
|
436
480
|
{
|
437
481
|
rb_mGeoIP2 = rb_define_module("GeoIP2");
|
438
|
-
rb_cGeoIP2Database = rb_define_class_under(rb_mGeoIP2, "Database",
|
439
|
-
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);
|
440
484
|
rb_eGeoIP2Error = rb_define_class_under(rb_mGeoIP2, "Error", rb_eStandardError);
|
441
485
|
|
442
486
|
rb_define_alloc_func(rb_cGeoIP2Database, rb_geoip2_db_alloc);
|
443
|
-
rb_define_method(rb_cGeoIP2Database, "
|
487
|
+
rb_define_method(rb_cGeoIP2Database, "open_mmdb", rb_geoip2_db_open_mmdb, 1);
|
444
488
|
rb_define_method(rb_cGeoIP2Database, "close", rb_geoip2_db_close, 0);
|
445
489
|
rb_define_method(rb_cGeoIP2Database, "lookup", rb_geoip2_db_lookup, 1);
|
446
490
|
|
447
491
|
rb_define_alloc_func(rb_cGeoIP2LookupResult, rb_geoip2_lr_alloc);
|
448
492
|
rb_define_method(rb_cGeoIP2LookupResult, "initialize", rb_geoip2_lr_initialize, 0);
|
449
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);
|
450
495
|
rb_define_method(rb_cGeoIP2LookupResult, "to_h", rb_geoip2_lr_to_h, 0);
|
451
496
|
}
|
@@ -15,18 +15,40 @@ addons:
|
|
15
15
|
language: c
|
16
16
|
matrix:
|
17
17
|
include:
|
18
|
+
# Why do we have -Wno-unused-parameter? Because libtap has unused
|
19
|
+
# parameters unfortunately.
|
20
|
+
#
|
21
|
+
# Why -Wno-unused-command-line-argument? Because Clang on OSX does not like
|
22
|
+
# -pthread to be given during linking (while gcc says it should be). We
|
23
|
+
# could alternatively work around this via conditionals in automake, but
|
24
|
+
# that seems uglier. Note we specify this for gcc on OSX as well as gcc
|
25
|
+
# there is a frontend for Clang.
|
18
26
|
- os: linux
|
19
27
|
compiler: gcc
|
20
28
|
env: MMCFLAGS="-std=c99 -Wall -Wextra -Werror -Wno-unused-parameter"
|
21
29
|
- os: osx
|
22
30
|
compiler: gcc
|
23
|
-
env: MMCFLAGS="-std=c99 -Wall -Wextra -Wno-unused-parameter"
|
31
|
+
env: MMCFLAGS="-std=c99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-command-line-argument"
|
24
32
|
- os: linux
|
25
33
|
compiler: clang
|
26
34
|
env: MMCFLAGS="-std=c99 -Wall -Wextra -Werror -Wno-unused-parameter"
|
27
35
|
- os: osx
|
28
36
|
compiler: clang
|
29
|
-
env: MMCFLAGS="-std=c99 -Wall -Wextra -Wno-unused-parameter"
|
37
|
+
env: MMCFLAGS="-std=c99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-command-line-argument"
|
38
|
+
# The same, but POSIX.1-2001. We default to POSIX.1-2008 but want to remain
|
39
|
+
# compatible with POSIX.1-2001.
|
40
|
+
- os: linux
|
41
|
+
compiler: gcc
|
42
|
+
env: MMCFLAGS="-std=c99 -Wall -Wextra -Werror -Wno-unused-parameter -D_POSIX_C_SOURCE=200112L"
|
43
|
+
- os: osx
|
44
|
+
compiler: gcc
|
45
|
+
env: MMCFLAGS="-std=c99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-command-line-argument -D_POSIX_C_SOURCE=200112L"
|
46
|
+
- os: linux
|
47
|
+
compiler: clang
|
48
|
+
env: MMCFLAGS="-std=c99 -Wall -Wextra -Werror -Wno-unused-parameter -D_POSIX_C_SOURCE=200112L"
|
49
|
+
- os: osx
|
50
|
+
compiler: clang
|
51
|
+
env: MMCFLAGS="-std=c99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-command-line-argument -D_POSIX_C_SOURCE=200112L"
|
30
52
|
env:
|
31
53
|
global:
|
32
54
|
- secure: a2pXNVW/lGrMdJTal+pzH0J5N69RdBErwe2dHU2xDnOeNcDYmiSxmU4Fw52KPYXFzdlR9GuEyZtHtesRQthSHpylcIvfJJCih7EvwbNQ5pfplpT5ri2PKPFWB11ebr6vG23Ucgc5lrqHdgIgv+QtqVmW1IDf0hq62itMpu4MwcQ=
|
@@ -1,3 +1,42 @@
|
|
1
|
+
## 1.3.2 - 2018-01-17
|
2
|
+
|
3
|
+
* Allocate memory for `MMDB_entry_data_list_s` structs in separate chunks
|
4
|
+
rather than one large chunk. This simplifies accessing memory in
|
5
|
+
`MMDB_get_entry_data_list()` and increases performance. It builds on the
|
6
|
+
changes in 1.3.0 and 1.3.1.
|
7
|
+
* We no longer export `data_pool_*` symbols. These are internal functions
|
8
|
+
but we were previously exporting them. Pull request by Faidon Liambotis.
|
9
|
+
GitHub #162.
|
10
|
+
* Build with POSIX.1-2008 by default if the system supports it. This allows
|
11
|
+
use of `open()` with `O_CLOEXEC`. We retain support for systems that
|
12
|
+
provide only POSIX.1-2001.
|
13
|
+
* Open the database with the `O_CLOEXEC` flag if the system provides it.
|
14
|
+
This avoids cases where we could leak fds when called in multi-threaded
|
15
|
+
programs that `fork()` and `exec()`. Original report and PR by Brandon L
|
16
|
+
Black.
|
17
|
+
* Added a test to ensure we export only intended symbols (e.g. MMDB_*).
|
18
|
+
|
19
|
+
|
20
|
+
## 1.3.1 - 2017-11-24
|
21
|
+
|
22
|
+
* Fix build problems related to `rpl_malloc()`. Pull request by Rainer
|
23
|
+
Gerhards. GitHub #152.
|
24
|
+
* Fix a race to set and read data in a field on the `MMDB_s` struct
|
25
|
+
(`ipv4_start_node`). GitHub #153.
|
26
|
+
* Fix cases of invalid memory access when using
|
27
|
+
`MMDB_get_entry_data_list()`. This was introduced in 1.3.0 and occurred
|
28
|
+
when performing large lookups. GitHub #153.
|
29
|
+
|
30
|
+
|
31
|
+
## 1.3.0 - 2017-11-10
|
32
|
+
|
33
|
+
* Perform fewer memory allocations in `MMDB_get_entry_data_list()`. This
|
34
|
+
significantly improves its performance. GitHub #147.
|
35
|
+
* Fix `mmdblookup`'s build epoch reporting on some systems. Big endian
|
36
|
+
systems with a 32-bit `time_t` no longer show a database build date of
|
37
|
+
1970-01-01 00:00:00. Pull request by Rainer Jung. GitHub #143.
|
38
|
+
|
39
|
+
|
1
40
|
## 1.2.1 - 2017-05-15
|
2
41
|
|
3
42
|
* Use autoconf to check the system's endianness rather than trying to do this
|
@@ -4,23 +4,14 @@ We release by uploading the tarball to GitHub, uploading Ubuntu PPAs, and by
|
|
4
4
|
updating the Homebrew recipe for this library.
|
5
5
|
|
6
6
|
## Creating the release tarball
|
7
|
+
You may want to refer to the section about prerequisites.
|
7
8
|
|
9
|
+
* Check whether there are any open issues to fix while you're doing this.
|
8
10
|
* Update `Changes.md` to include specify the new version, today's date, and
|
9
|
-
list relevant changes.
|
10
|
-
* Run `./dev-bin/
|
11
|
-
GitHub pages,
|
12
|
-
*
|
13
|
-
|
14
|
-
## GitHub
|
15
|
-
|
16
|
-
* Go to https://github.com/maxmind/libmaxminddb/releases
|
17
|
-
* GitHub will already have a release for the tag you just created.
|
18
|
-
* Click on the new tag new.
|
19
|
-
* Click on "Edit tag".
|
20
|
-
* Give the release a title summarizing the changes.
|
21
|
-
* Paste in the changes from the `Changes.md` file as the body.
|
22
|
-
* Attach the release tarball you just created.
|
23
|
-
* Click "Update release"
|
11
|
+
list relevant changes. Commit this.
|
12
|
+
* Run `./dev-bin/release.sh` to update various files in the distro, our
|
13
|
+
GitHub pages, and creates a GitHub release with the tarball.
|
14
|
+
* Check the release looks good on both GitHub and launchpad.net.
|
24
15
|
|
25
16
|
## PPA
|
26
17
|
|
@@ -33,26 +24,46 @@ The PPA release script is at `dev-bin/ppa-release.sh`. Running it should
|
|
33
24
|
guide you though the release, although it may require some changes to run on
|
34
25
|
configurations different than Greg's machine.
|
35
26
|
|
36
|
-
|
27
|
+
Check whether any new Ubuntu versions need to be listed in this script
|
28
|
+
before running it.
|
37
29
|
|
38
|
-
|
39
|
-
2. git merge `<TAG>`
|
40
|
-
3. dch -i
|
41
|
-
* Add new entry for wily (or whatever the most recent Ubuntu release
|
42
|
-
is. Follow existing PPA versioning style.
|
43
|
-
4. git commit to add the debian changelog
|
44
|
-
5. gbp buildpackage -S
|
45
|
-
6. dput ppa:maxmind/ppa ../libmaxminddb_`<TAG>`-`<DEB VERSION>`_source.changes
|
46
|
-
7. git push
|
47
|
-
|
48
|
-
If 5 was successful, modify debian/changelog and repeat 5 & 6 for trusty and
|
49
|
-
precise. Note that you can skip step #4 for subsequent uploads by adding
|
50
|
-
`--git-ignore-new` when you call `gbp`.
|
30
|
+
You should run it from `master`.
|
51
31
|
|
52
32
|
## Homebrew
|
53
33
|
|
54
|
-
* Go to https://github.com/Homebrew/homebrew/
|
34
|
+
* Go to https://github.com/Homebrew/homebrew-core/edit/master/Formula/libmaxminddb.rb
|
55
35
|
* Edit the file to update the url and sha256. You can get the sha256 for the
|
56
36
|
tarball with the `sha256sum` command line utility.
|
57
37
|
* Make a commit with the summary `libmaxminddb <VERSION>`
|
58
38
|
* Submit a PR with the changes you just made.
|
39
|
+
|
40
|
+
# Prerequisites for releasing
|
41
|
+
|
42
|
+
* Required packages (Ubuntu Artful): vim git-core dput build-essential
|
43
|
+
autoconf automake libtool git-buildpackage libfile-slurp-perl pandoc
|
44
|
+
dirmngr libfile-slurp-tiny-perl libdatetime-perl debhelper dh-autoreconf
|
45
|
+
libipc-run3-perl libtest-output-perl devscripts
|
46
|
+
* Install [hub](https://github.com/github/hub/releases). (Using `./install`
|
47
|
+
from the tarball is fine)
|
48
|
+
* GitHub ssh key (e.g. in `~/.ssh/id_rsa`)
|
49
|
+
* Git config (e.g. `~/.gitconfig`)
|
50
|
+
* Import your GPG secret key (or create one if you don't have a suitable
|
51
|
+
one)
|
52
|
+
* `gpg --import /path/to/key`
|
53
|
+
* `gpg --edit-key KEYID` and trust it ultimately
|
54
|
+
* Ensure it shows with `gpg --list-secret-keys`
|
55
|
+
* You need to be invited to the launchpad.net MaxMind organization on your
|
56
|
+
launchpad.net account.
|
57
|
+
* You need your GPG key listed on your launchpad.net account
|
58
|
+
* You can add it in the web interface. It wants the output of
|
59
|
+
`gpg --fingerprint`.
|
60
|
+
* Part of the instructions involve having your key published on the
|
61
|
+
Ubuntu keyserver:
|
62
|
+
`gpg --keyserver keyserver.ubuntu.com --send-keys KEYID`
|
63
|
+
* You'll get an email with an encrypted payload that you need to decrypt
|
64
|
+
and follow the link to confirm it.
|
65
|
+
* Ensure `dch` knows your name and email. Refer to its man page for how to
|
66
|
+
tell it this. One way is to set the `DEBFULLNAME` and `DEBEMAIL`
|
67
|
+
environment variables. These should match your GPG key's name and email
|
68
|
+
exactly. This is what gets used in the Debian changelog as well as
|
69
|
+
defines what GPG key to use.
|
@@ -20,7 +20,7 @@ This library is licensed under the Apache License, Version 2.
|
|
20
20
|
## From a Tarball
|
21
21
|
|
22
22
|
This code is known to work with GCC 4.4+ and clang 3.2+. It should also work
|
23
|
-
on other compilers that supports C99, POSIX
|
23
|
+
on other compilers that supports C99, POSIX.1-2001, and the `-fms-extensions
|
24
24
|
flag` (or equivalent). The latter is needed to allow an anonymous union in a
|
25
25
|
structure.
|
26
26
|
|
@@ -76,8 +76,8 @@ APT sources, run:
|
|
76
76
|
|
77
77
|
Then install the packages by running:
|
78
78
|
|
79
|
-
$ sudo
|
80
|
-
$ sudo
|
79
|
+
$ sudo apt update
|
80
|
+
$ sudo apt install libmaxminddb0 libmaxminddb-dev mmdb-bin
|
81
81
|
|
82
82
|
## On OS X via Homebrew
|
83
83
|
|