geoipdb 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -13,22 +13,18 @@ static VALUE cIpDb;
13
13
 
14
14
  // free the memory used by the db, called by the Ruby-GC
15
15
  void geoipdb_free(geoipdb *gi) {
16
- printf("Freeing memory for the GeoIpDb.. \n");
17
16
  if(gi == NULL)
18
17
  return;
19
18
  if (gi->db != NULL){
20
19
  if(gi->db->cities != NULL ){
21
- printf("..freeing cities \n");
22
20
  free(gi->db->cities);
23
21
  gi->db->cities = NULL;
24
22
  }
25
23
  if(gi->db->ranges != NULL ){
26
- printf("..freeing ranges \n");
27
24
  free(gi->db->ranges);
28
25
  gi->db->ranges = NULL;
29
26
  }
30
27
  if(gi->db != NULL){
31
- printf("..freeing ipdb \n");
32
28
  free(gi->db);
33
29
  }
34
30
  }
@@ -50,7 +46,6 @@ VALUE ipdb_init(VALUE self, VALUE cities_file_name, VALUE ranges_file_name, VALU
50
46
 
51
47
  gi->db= init_db(cities_csv_file, ranges_csv_file, cache_file);
52
48
 
53
-
54
49
  if(gi->db == NULL)
55
50
  {
56
51
  if(DEBUG)
@@ -109,4 +104,4 @@ void Init_geoipdb(void)
109
104
  cIpDb = rb_define_class( "GeoIpDb", rb_cObject);
110
105
  rb_define_singleton_method( cIpDb, "init", ipdb_init, 3);
111
106
  rb_define_method( cIpDb, "information_for_ip", ipdb_information_for_ip, 1);
112
- }
107
+ }
@@ -95,8 +95,6 @@ print_cities(IPDB * db){
95
95
  }
96
96
  }
97
97
 
98
-
99
-
100
98
  void print_stats(IPDB * db){
101
99
  printf("DB STATS: \n");
102
100
  printf("\tCities: %i\n", db->cities_count);
@@ -181,12 +179,6 @@ int compare_ranges(const void *fa, const void *fb) {
181
179
  const IpRange *a = (IpRange *) fa;
182
180
  const IpRange *b = (IpRange *) fb;
183
181
 
184
- // printf("\tComparing: a:");
185
- // print_range(a);
186
- // printf(" with b:");
187
- // print_range(b);
188
- // printf("\n");
189
-
190
182
  if(a->from>0 && a->to>0 && b->from>0 && b->to>0){ //regular case: both entries are ranges
191
183
  if(a->to < b->from) {
192
184
  return -1;
@@ -256,11 +248,8 @@ city_index_by_code(IPDB * db, int city_code){
256
248
  printf("Could not find searched city with code: %i \n", city_code);
257
249
  return -1;
258
250
  }else{
259
- // printf("Found result: \t");
260
- // print_city(result);
261
251
  int index;
262
252
  index = (result - db->cities);
263
- // printf("Found index: %i\n", index);
264
253
  return index;
265
254
  }
266
255
  }
@@ -350,7 +339,6 @@ isp_index_by_name(IPDB * db, char* isp_name){
350
339
  }
351
340
  }
352
341
  }
353
- // TODO: malloc more space if needed
354
342
  // add new isp
355
343
  if(db->isps_count < MAX_ISPS_COUNT){
356
344
  int16 new_index = db->isps_count;
@@ -433,8 +421,6 @@ read_ranges_csv(IPDB * db){
433
421
  entry->city_index = city_index;
434
422
  entry->isp_index = isp_index;
435
423
 
436
- // printf("from: %u,to: %u, city_code:%s, city_index: %i\n",entry->from,entry->to,city_code, entry->city_index);
437
- // printf("working record nr: %li\n", db->ranges_count);
438
424
  db->ranges_count++;
439
425
  }
440
426
  }
@@ -453,13 +439,11 @@ iso2_code(char* iso3){
453
439
  int i = 0;
454
440
  for( i = 0; i < num_countries; i++)
455
441
  {
456
- // printf("Trying cmp of %s and %s...", iso3, country_iso3_codes[i]);
457
442
  if( strcmp(country_iso3_codes[i],iso3)==0)
458
443
  {
459
444
  return (char*) country_iso2_codes[i];
460
445
  }
461
446
  }
462
- // printf("Could not find iso2 code for iso3: %s, using: '%s' \n", iso3, country_iso2_codes[0]);
463
447
  return (char*) country_iso2_codes[0];
464
448
  }
465
449
 
@@ -496,7 +480,6 @@ read_cities_csv(IPDB * db){
496
480
  {
497
481
  printf("Worked lines: %i\n", i);
498
482
  }
499
- // printf("Line: %s", line);
500
483
  // COUNTRY,REGION,CITY-NAME,METRO-CODE,CITY-CODE,LATITUDE,LONGITUDE
501
484
  country = strtok(line, CITIES_DELIM);
502
485
  region = strtok(NULL, CITIES_DELIM);
@@ -510,7 +493,6 @@ read_cities_csv(IPDB * db){
510
493
 
511
494
  strncpy(entry->country_iso3, country, strlen(country));
512
495
 
513
- // entry->country_iso2 = iso2_code(entry->country_iso3);
514
496
  strncpy(entry->country_iso2, iso2_code(country), 2);
515
497
  strncpy(entry->name, name, strlen(name));
516
498
 
@@ -523,8 +505,6 @@ read_cities_csv(IPDB * db){
523
505
  printf("\n Parsing of %i records needed %.6lf seconds\n", db->cities_count, get_time(&tim)-t1);
524
506
  }
525
507
 
526
-
527
-
528
508
  /**
529
509
  cache-file is an exact binary copy of the ranges+cities-arrays from memory,
530
510
  the layout goes like this:
@@ -661,11 +641,8 @@ IPDB * init_db(char * cities_csv_file, char * ranges_csv_file, char * cache_file
661
641
  db->ranges_csv_file = ranges_csv_file;
662
642
  db->max_ranges_count = MAX_RANGES_COUNT;
663
643
 
664
- // db->isps = NULL;
665
- // db->isps = malloc(MAX_ISP_NAME_LENGTH * MAX_ISPS_COUNT);
666
644
  db->isps_count = 0;
667
645
 
668
-
669
646
  if(USE_CACHE && read_cache_file(db) > 0){
670
647
  if(DEBUG)
671
648
  printf("Loaded DB from Cache-File with %i records \n", db->ranges_count);
@@ -673,14 +650,12 @@ IPDB * init_db(char * cities_csv_file, char * ranges_csv_file, char * cache_file
673
650
  if(DEBUG)
674
651
  printf("Initializing IPDB from CSV-file: %s \n", db->ranges_csv_file);
675
652
  read_cities_csv(db);
676
- // print_cities(db);
677
653
  if(db->cities_count == 0)
678
654
  {
679
655
  return NULL;
680
656
  }
681
657
  sort_cities(db);
682
658
  read_ranges_csv(db);
683
- // //TODO: sort ranges
684
659
  if(db!=NULL && db->ranges_count > 0 && USE_CACHE)
685
660
  {
686
661
  if(DEBUG)
@@ -1,4 +1,3 @@
1
-
2
1
  #ifdef INT_2_BYTES
3
2
  typedef char int8;
4
3
  typedef int int16;
@@ -17,7 +16,6 @@ typedef int int32;
17
16
  # define RSTRING_PTR(x) (RSTRING(x)->ptr)
18
17
  #endif
19
18
 
20
-
21
19
  #define RANGES_DELIM ",\n"
22
20
  #define CITIES_DELIM ",\n"
23
21
 
@@ -67,12 +65,9 @@ typedef struct{
67
65
 
68
66
  } IPDB;
69
67
 
70
-
71
- // "publicly" visible functions
72
68
  IPDB *
73
69
  init_db(char * cities_csv_file, char * ranges_csv_file, char * cache_file_name);
74
70
 
75
-
76
71
  void
77
72
  print_city(const City * e);
78
73
 
@@ -86,4 +81,4 @@ City*
86
81
  find_city_for_ip_range(IPDB * db, IpRange* range);
87
82
 
88
83
  char*
89
- find_isp_for_ip_range(IPDB * db, IpRange* range);
84
+ find_isp_for_ip_range(IPDB * db, IpRange* range);
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "geoipdb"
8
- s.version = "0.4.1"
8
+ s.version = "0.4.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Eugen Martin", "Martin Karlsch"]
12
- s.date = "2011-11-25"
12
+ s.date = "2012-05-11"
13
13
  s.description = "Returns a GeoLocation and additional information for given IP. Reads Data from CSV-Files and uses internal binary caching."
14
14
  s.email = "eugeniusmartinus@googlemail.com"
15
15
  s.extensions = ["ext/geoipdb/extconf.rb"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoipdb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 1
10
- version: 0.4.1
9
+ - 2
10
+ version: 0.4.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eugen Martin
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-11-25 00:00:00 Z
19
+ date: 2012-05-11 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  version_requirements: &id001 !ruby/object:Gem::Requirement