mmdb 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/mmdb/mmdb.c +21 -19
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddbd3f739b7ffac9b3e61811c4aa3edf5e8a55f7
|
4
|
+
data.tar.gz: bd71b111bd50ac7c88fad053377120c027f4a2c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6fe7e623f94fec0f4e45e0a7078cf7e3329b57826d46fddae0c1d939412f6a023e96affa116e93bb585b3e302032ca331ab3bff73161637630bb706cd230558
|
7
|
+
data.tar.gz: 1fac584cfb105ae76f5379414d87b7fd1cc3fd29f016e5132261b46e4cba9d58a3c265a66d83d1f384c6e35161fca175d3512edf42379d34c2c341da5f611aa7
|
data/ext/mmdb/mmdb.c
CHANGED
@@ -17,20 +17,20 @@ static VALUE rb_sym_longitude;
|
|
17
17
|
static VALUE rb_sym_postcode;
|
18
18
|
static VALUE rb_sym_subdivisions;
|
19
19
|
|
20
|
-
const
|
21
|
-
const
|
22
|
-
const
|
23
|
-
const
|
24
|
-
const
|
25
|
-
const
|
26
|
-
const
|
27
|
-
const
|
28
|
-
const
|
29
|
-
const
|
30
|
-
const
|
31
|
-
const
|
32
|
-
const
|
33
|
-
const
|
20
|
+
static const char *en = "en";
|
21
|
+
static const char *names = "names";
|
22
|
+
static const char *city = "city";
|
23
|
+
static const char *country = "country";
|
24
|
+
static const char *country_code = "country_code";
|
25
|
+
static const char *continent = "continent";
|
26
|
+
static const char *location = "location";
|
27
|
+
static const char *latitude = "latitude";
|
28
|
+
static const char *longitude = "longitude";
|
29
|
+
static const char *postal = "postal";
|
30
|
+
static const char *code = "code";
|
31
|
+
static const char *iso_code = "iso_code";
|
32
|
+
static const char *postcode = "postcode";
|
33
|
+
static const char *subdivisions = "subdivisions";
|
34
34
|
|
35
35
|
struct MaxMindDB {
|
36
36
|
MMDB_s *mmdb;
|
@@ -145,13 +145,15 @@ maxminddb_lookup(VALUE self, VALUE ip) {
|
|
145
145
|
VALUE ret;
|
146
146
|
int gai_error, mmdb_error;
|
147
147
|
struct MaxMindDB *ptr = MaxMindDB(self);
|
148
|
-
|
148
|
+
MMDB_lookup_result_s lookuped;
|
149
|
+
MMDB_entry_data_s data;
|
150
|
+
MMDB_entry_s *entry;
|
149
151
|
|
150
152
|
if (NIL_P(ip)) {
|
151
153
|
return Qnil;
|
152
154
|
}
|
153
155
|
|
154
|
-
|
156
|
+
lookuped = MMDB_lookup_string(ptr->mmdb, StringValuePtr(ip), &gai_error, &mmdb_error);
|
155
157
|
if (gai_error) {
|
156
158
|
rb_sys_fail(gai_strerror(gai_error));
|
157
159
|
}
|
@@ -161,8 +163,7 @@ maxminddb_lookup(VALUE self, VALUE ip) {
|
|
161
163
|
|
162
164
|
if (lookuped.found_entry) {
|
163
165
|
ret = rb_hash_new();
|
164
|
-
|
165
|
-
MMDB_entry_s *entry = &lookuped.entry;
|
166
|
+
entry = &lookuped.entry;
|
166
167
|
|
167
168
|
MMDB_get_value(entry, &data, city, names, en, NULL);
|
168
169
|
maxminddb_set_result(ret, rb_sym_city, &data);
|
@@ -190,13 +191,14 @@ maxminddb_lookup(VALUE self, VALUE ip) {
|
|
190
191
|
// subdivisions fields is basically array
|
191
192
|
if (data.type == MMDB_DATA_TYPE_ARRAY) {
|
192
193
|
VALUE ary = rb_ary_new();
|
194
|
+
int i;
|
193
195
|
int n, data_size;
|
194
196
|
int count = 0;
|
195
197
|
n = data_size = data.data_size;
|
196
198
|
number_of_digits(n, count);
|
197
199
|
char index[count+1];
|
198
200
|
|
199
|
-
for (
|
201
|
+
for (i = 0; i < data_size; i++) {
|
200
202
|
sprintf(index, "%d", i);
|
201
203
|
MMDB_get_value(entry, &data, subdivisions, index, names, en, NULL);
|
202
204
|
if (data.has_data) {
|