hive_geoip2 0.1.3 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b348c2c8f75bccacdd82a1b16721519d8b96d39c395b44fb8ff90df15c9b1f0
4
- data.tar.gz: 21ad1005e09d5b6e14f1c30e0ba7f03a57dce167fc472501132be2e3a5f45a6c
3
+ metadata.gz: 209e8f8c9e603be8bde6f15e6c09ae9e2665c63fb427c0b3af48920e1a6b2179
4
+ data.tar.gz: 903ca36a7999f737f31407badf8a70abcd2284a371850ad636c5e0acbc964fec
5
5
  SHA512:
6
- metadata.gz: 25a0c7587f29c6b083175fe1af32ef95bccf371d84b768ffeb3e6700f8beb22e3e2b889b513bf1f822110b4ed342cd7a757a08c83907f4119567debc51d60663
7
- data.tar.gz: 2512935d151ee581c91604695b78c3229386e5ad5cb7a8794bd399b1b4b5b155f8ea889115e974b2e31ad840ba8a0661d4490a9a3a1f3fd8e4dfbe0fd0e831f4
6
+ metadata.gz: 66dee7bd11266d7481e3d01127c3232aa31336ac0a2aa020bd81308c471511d5e549f059fc8b7c90991fc881b553b518cc6b08fef43c3aab35eee6af903183a9
7
+ data.tar.gz: 1465bc69a609a0f3ba147e37a4241a53c5e1f9f880aa87b5f7f0a93466838cde8202c730f2fc2379089badd993cc1c5a9c64ef5ee88b73bc5ff8a127c03a663d
@@ -19,6 +19,8 @@ static VALUE mmdb_lookup(MMDB_s *mmdb, char *ip_addr, bool cleanup);
19
19
 
20
20
  static VALUE rb_hive_geo_lookup(VALUE self, VALUE ip_arg);
21
21
  static VALUE rb_hive_geo_lookup2(VALUE self, VALUE ip_arg, VALUE db_arg);
22
+ static VALUE rb_hive_geo_lookup_with_prefix_length(VALUE self, VALUE ip_arg);
23
+ static VALUE rb_hive_geo_lookup_with_prefix_length2(VALUE self, VALUE ip_arg, VALUE db_arg);
22
24
  static VALUE rb_hive_geo_is_closed(VALUE self);
23
25
  static VALUE rb_hive_geo_close(VALUE self);
24
26
  static void rb_hive_geo_free(MMDB_s *mmdb);
@@ -320,11 +322,22 @@ static VALUE mmdb_lookup(MMDB_s *mmdb, char *ip_addr, bool cleanup) {
320
322
  if (exception) {
321
323
  rb_jump_tag(exception);
322
324
  }
323
-
324
- return ret_obj;
325
+
326
+ // Return [data, prefix_length] tuple
327
+ VALUE result_array = rb_ary_new2(2);
328
+ rb_ary_push(result_array, ret_obj);
329
+ rb_ary_push(result_array, INT2NUM(result.netmask));
330
+ return result_array;
325
331
  }
326
332
  else {
327
- return Qnil;
333
+ if (cleanup) {
334
+ mmdb_close(mmdb);
335
+ }
336
+ // Return [nil, 0] for not found
337
+ VALUE result_array = rb_ary_new2(2);
338
+ rb_ary_push(result_array, Qnil);
339
+ rb_ary_push(result_array, INT2NUM(0));
340
+ return result_array;
328
341
  }
329
342
  }
330
343
 
@@ -340,8 +353,8 @@ static VALUE rb_hive_geo_lookup(VALUE self, VALUE ip_arg) {
340
353
  if (mmdb_is_closed(mmdb)) {
341
354
  rb_raise(rb_eIOError, "GeoIP2 - closed database");
342
355
  }
343
-
344
- return mmdb_lookup(mmdb, ip_addr, false);
356
+ VALUE result_tuple = mmdb_lookup(mmdb, ip_addr, false);
357
+ return rb_ary_entry(result_tuple, 0); // Extract just the data part
345
358
  }
346
359
 
347
360
  static VALUE rb_hive_geo_lookup2(VALUE self, VALUE ip_arg, VALUE db_arg) {
@@ -354,8 +367,29 @@ static VALUE rb_hive_geo_lookup2(VALUE self, VALUE ip_arg, VALUE db_arg) {
354
367
  MMDB_s mmdb;
355
368
 
356
369
  mmdb_try_open(db_path, &mmdb);
357
-
358
- return mmdb_lookup(&mmdb, ip_addr, true);
370
+ VALUE result_tuple = mmdb_lookup(&mmdb, ip_addr, true);
371
+ return rb_ary_entry(result_tuple, 0); // Extract just the data part
372
+ }
373
+
374
+ static VALUE rb_hive_geo_lookup_with_prefix_length(VALUE self, VALUE ip_arg) {
375
+ Check_Type(ip_arg, T_STRING);
376
+ char *ip_addr = StringValuePtr(ip_arg);
377
+ MMDB_s *mmdb;
378
+ Data_Get_Struct(self, MMDB_s, mmdb);
379
+ if (mmdb_is_closed(mmdb)) {
380
+ rb_raise(rb_eIOError, "GeoIP2 - closed database");
381
+ }
382
+ return mmdb_lookup(mmdb, ip_addr, false); // Return full tuple with prefix length
383
+ }
384
+
385
+ static VALUE rb_hive_geo_lookup_with_prefix_length2(VALUE self, VALUE ip_arg, VALUE db_arg) {
386
+ Check_Type(ip_arg, T_STRING);
387
+ Check_Type(db_arg, T_STRING);
388
+ char *ip_addr = StringValuePtr(ip_arg);
389
+ char *db_path = StringValuePtr(db_arg);
390
+ MMDB_s mmdb;
391
+ mmdb_try_open(db_path, &mmdb);
392
+ return mmdb_lookup(&mmdb, ip_addr, true); // Return full tuple with prefix length
359
393
  }
360
394
 
361
395
  static VALUE rb_hive_geo_is_closed(VALUE self) {
@@ -413,9 +447,11 @@ void Init_hive_geoip2() {
413
447
  rb_define_alloc_func(rb_cGeoIP2, rb_hive_geo_alloc);
414
448
 
415
449
  rb_define_singleton_method(rb_cGeoIP2, "lookup", rb_hive_geo_lookup2, 2);
416
-
450
+ rb_define_singleton_method(rb_cGeoIP2, "lookup_with_prefix_length", rb_hive_geo_lookup_with_prefix_length2, 2);
451
+
417
452
  rb_define_method(rb_cGeoIP2, "initialize", rb_hive_geo_init, 1);
418
453
  rb_define_method(rb_cGeoIP2, "close", rb_hive_geo_close, 0);
419
454
  rb_define_method(rb_cGeoIP2, "closed?", rb_hive_geo_is_closed, 0);
420
455
  rb_define_method(rb_cGeoIP2, "lookup", rb_hive_geo_lookup, 1);
456
+ rb_define_method(rb_cGeoIP2, "lookup_with_prefix_length", rb_hive_geo_lookup_with_prefix_length, 1);
421
457
  }
data/hive_geoip2.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'hive_geoip2'
3
- s.version = '0.1.3'
3
+ s.version = '0.1.4'
4
4
  s.summary = 'libmaxminddb GeoIP2 Ruby bindings'
5
5
  s.author = 'Maxime Youdine'
6
6
  s.license = 'MIT'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hive_geoip2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxime Youdine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-09 00:00:00.000000000 Z
11
+ date: 2025-08-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: