geoip 1.3.5 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/geoip.gemspec +5 -5
- data/lib/geoip.rb +32 -13
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTNjMGMyYjJlNmYzY2JmZTFlZTI2ZDMwYmJiMWZjODVjZjA1ZTI4NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTIwNDVkMzA2NWI3YjNjODA2ODY5ZDkzZTY3MDI0NDljYjMwNTYxNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NThlNDBhZGYwOGFlODY3ODQ1NzBlZDQ1OGI3NzVkYzAzY2ZmOTg5OTEwYTFm
|
10
|
+
NmVkNzY2YmVhOTc1ZTIyNWEyNDlhNjhjYWNhNmZhZTAyYWVhNWIyMWFlYzdm
|
11
|
+
MjAxNjY0NzI4ODkyZmE3MmNiMjIzMWY3YmQwNjc0ZTQxYzYxMTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODBjOWM0ODA1NWUyNDRlYTQ0NmJkY2ViZTI3MGQwNjI5N2JiODRhZTY3YTIx
|
14
|
+
NzdkN2EzZGZkYWZkM2JlZDA0MmFiMTk4MzRmNTU3NTVmMWMxYmYyN2JmNTAx
|
15
|
+
YmUzYWZkMGE4OTE5NmFkOTM1YmVmMjAwMTczODQ2Yzg0ZTJkMzc=
|
data/geoip.gemspec
CHANGED
@@ -2,15 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: geoip 1.
|
5
|
+
# stub: geoip 1.4.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "geoip"
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.4.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
12
13
|
s.authors = ["Clifford Heath", "Roland Moriz"]
|
13
|
-
s.date = "
|
14
|
+
s.date = "2014-03-26"
|
14
15
|
s.description = "GeoIP searches a GeoIP database for a given host or IP address, and\nreturns information about the country where the IP address is allocated,\nand the city, ISP and other information, if you have that database version."
|
15
16
|
s.email = ["clifford.heath@gmail.com", "rmoriz@gmail.com"]
|
16
17
|
s.executables = ["geoip"]
|
@@ -40,8 +41,7 @@ Gem::Specification.new do |s|
|
|
40
41
|
]
|
41
42
|
s.homepage = "http://github.com/cjheath/geoip"
|
42
43
|
s.licenses = ["LGPL"]
|
43
|
-
s.
|
44
|
-
s.rubygems_version = "2.1.10"
|
44
|
+
s.rubygems_version = "2.2.2"
|
45
45
|
s.summary = "GeoIP searches a GeoIP database for a given host or IP address, and returns information about the country where the IP address is allocated, and the city, ISP and other information, if you have that database version."
|
46
46
|
end
|
47
47
|
|
data/lib/geoip.rb
CHANGED
@@ -58,7 +58,7 @@ require 'yaml'
|
|
58
58
|
class GeoIP
|
59
59
|
|
60
60
|
# The GeoIP GEM version number
|
61
|
-
VERSION = "1.
|
61
|
+
VERSION = "1.4.0"
|
62
62
|
|
63
63
|
# The +data/+ directory for geoip
|
64
64
|
DATA_DIR = File.expand_path(File.join(File.dirname(__FILE__),'..','data','geoip'))
|
@@ -171,19 +171,23 @@ class GeoIP
|
|
171
171
|
# Open the GeoIP database and determine the file format version.
|
172
172
|
#
|
173
173
|
# +filename+ is a String holding the path to the GeoIP.dat file
|
174
|
-
# +options+ is
|
174
|
+
# +options+ is a Hash allowing you to specify the caching options
|
175
175
|
#
|
176
|
-
def initialize(filename,
|
177
|
-
|
178
|
-
|
179
|
-
|
176
|
+
def initialize(filename, options = {})
|
177
|
+
if options[:preload] || !IO.respond_to?(:pread)
|
178
|
+
@mutex = Mutex.new
|
179
|
+
end
|
180
|
+
|
181
|
+
@use_pread = IO.respond_to?(:pread) && !options[:preload]
|
180
182
|
|
181
|
-
@
|
183
|
+
@options = options
|
182
184
|
@database_type = GEOIP_COUNTRY_EDITION
|
183
185
|
@record_length = STANDARD_RECORD_LENGTH
|
184
186
|
@file = File.open(filename, 'rb')
|
185
187
|
|
186
188
|
detect_database_type!
|
189
|
+
|
190
|
+
preload_data if options[:preload]
|
187
191
|
end
|
188
192
|
|
189
193
|
# Search the GeoIP database for the specified host, returning country
|
@@ -420,6 +424,13 @@ class GeoIP
|
|
420
424
|
|
421
425
|
private
|
422
426
|
|
427
|
+
# Loads data into a StringIO which is Copy-on-write friendly
|
428
|
+
def preload_data
|
429
|
+
@file.seek(0)
|
430
|
+
@contents = StringIO.new(@file.read)
|
431
|
+
@file.close
|
432
|
+
end
|
433
|
+
|
423
434
|
# Detects the type of the database.
|
424
435
|
def detect_database_type! # :nodoc:
|
425
436
|
@file.seek(-3, IO::SEEK_END)
|
@@ -708,18 +719,26 @@ class GeoIP
|
|
708
719
|
|
709
720
|
# reads +length+ bytes from +offset+ as atomically as possible
|
710
721
|
# if IO.pread is available, it'll use that (making it both multithread
|
711
|
-
# and multiprocess-safe).
|
722
|
+
# and multiprocess-safe). Otherwise we'll use a mutex to synchronize
|
712
723
|
# access (only providing protection against multiple threads, but not
|
713
724
|
# file descriptors shared across multiple processes).
|
725
|
+
# If the contents of the database have been preloaded it'll work with
|
726
|
+
# the StringIO object directly.
|
714
727
|
def atomic_read(length, offset) #:nodoc:
|
715
728
|
if @mutex
|
716
|
-
@mutex.synchronize
|
717
|
-
@file.seek(offset)
|
718
|
-
@file.read(length)
|
719
|
-
end
|
729
|
+
@mutex.synchronize { atomic_read_unguarded(length, offset) }
|
720
730
|
else
|
721
|
-
|
731
|
+
atomic_read_unguarded(length, offset)
|
722
732
|
end
|
723
733
|
end
|
724
734
|
|
735
|
+
def atomic_read_unguarded(length, offset)
|
736
|
+
if @use_pread
|
737
|
+
IO.pread(@file.fileno, length, offset)
|
738
|
+
else
|
739
|
+
io = @contents || @file
|
740
|
+
io.seek(offset)
|
741
|
+
io.read(length)
|
742
|
+
end
|
743
|
+
end
|
725
744
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geoip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clifford Heath
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'GeoIP searches a GeoIP database for a given host or IP address, and
|
15
15
|
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
66
|
rubyforge_project:
|
67
|
-
rubygems_version: 2.
|
67
|
+
rubygems_version: 2.2.2
|
68
68
|
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: GeoIP searches a GeoIP database for a given host or IP address, and returns
|