From 8b698b4f6b99f278ac6c52237ea660e7ffd15b4b Mon Sep 17 00:00:00 2001 From: zhuhaow Date: Sat, 4 Jan 2020 14:50:14 +0800 Subject: [PATCH] Remove bundled Geolite2 db due to license change Due to license change, https://dev.maxmind.com/geoip/geoip2/geolite2/ we are no longer able to download Geolite2 db without manual setting up. 1. Removed db update script 2. Removed bundled db binary from `MMDB` target, `MMDB` now must be inited with a path to the db binary 3. Moved bundled db to test target for only testing purpose. The binary can be released since it was obtained under old license. But there is no way to update it now. --- MMDB-Swift.podspec | 5 +- MMDB.xcodeproj/project.pbxproj | 47 ++---------------- README.md | 6 ++- Sources/MMDB.swift | 7 +-- .../MMDBTests}/GeoLite2-Country.mmdb | Bin Tests/MMDBTests/MMDBTests.swift | 2 +- update_database.sh | 21 -------- 7 files changed, 13 insertions(+), 75 deletions(-) rename {Sources/libmaxminddb => Tests/MMDBTests}/GeoLite2-Country.mmdb (100%) delete mode 100755 update_database.sh diff --git a/MMDB-Swift.podspec b/MMDB-Swift.podspec index e77151a..5dfe8a3 100644 --- a/MMDB-Swift.podspec +++ b/MMDB-Swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "MMDB-Swift" - s.version = "0.4.0" + s.version = "0.5.0" s.summary = "A wrapper for MaxMind DB" s.description = <<-DESC A tiny wrapper for libmaxminddb which allows you to lookup @@ -27,9 +27,6 @@ Pod::Spec.new do |s| s.ios.public_header_files = "Sources/libmaxminddb/*.h", "Sources/MMDB.h" s.osx.public_header_files = "Sources/libmaxminddb/*.h", "Sources/MMDB.h" - s.prepare_command = "./update_database.sh" - s.resource = "Sources/libmaxminddb/GeoLite2-Country.mmdb" - s.framework = "Foundation" s.requires_arc = true end diff --git a/MMDB.xcodeproj/project.pbxproj b/MMDB.xcodeproj/project.pbxproj index 2b2188d..8f38256 100644 --- a/MMDB.xcodeproj/project.pbxproj +++ b/MMDB.xcodeproj/project.pbxproj @@ -11,14 +11,14 @@ 366F5FE91F052F7F00DE3883 /* MMDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D716CB471C23A58700D89B5C /* MMDB.framework */; }; 366F5FF81F05301400DE3883 /* MMDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D716CB541C23A5DC00D89B5C /* MMDB.framework */; }; 366F5FFE1F05302300DE3883 /* MMDBTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 366F5FE61F052F7F00DE3883 /* MMDBTests.swift */; }; + 36D1827B23C0688C002E42A5 /* GeoLite2-Country.mmdb in Resources */ = {isa = PBXBuildFile; fileRef = D73CAED01C21AA9A000C2132 /* GeoLite2-Country.mmdb */; }; + 36D1827C23C0688D002E42A5 /* GeoLite2-Country.mmdb in Resources */ = {isa = PBXBuildFile; fileRef = D73CAED01C21AA9A000C2132 /* GeoLite2-Country.mmdb */; }; D716CB5C1C23A65200D89B5C /* maxminddb.c in Sources */ = {isa = PBXBuildFile; fileRef = D73CAECC1C21A7A2000C2132 /* maxminddb.c */; }; D716CB5D1C23A65200D89B5C /* maxminddb_unions.c in Sources */ = {isa = PBXBuildFile; fileRef = D716CB3F1C2269D200D89B5C /* maxminddb_unions.c */; }; D716CB5E1C23A65D00D89B5C /* MMDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = D716CB321C21432C00D89B5C /* MMDB.swift */; }; D716CB5F1C23A66C00D89B5C /* MMDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = D716CB321C21432C00D89B5C /* MMDB.swift */; }; D716CB601C23A66C00D89B5C /* maxminddb.c in Sources */ = {isa = PBXBuildFile; fileRef = D73CAECC1C21A7A2000C2132 /* maxminddb.c */; }; D716CB611C23A66C00D89B5C /* maxminddb_unions.c in Sources */ = {isa = PBXBuildFile; fileRef = D716CB3F1C2269D200D89B5C /* maxminddb_unions.c */; }; - D736A97E1C23B59D0070EAA3 /* GeoLite2-Country.mmdb in Resources */ = {isa = PBXBuildFile; fileRef = D73CAED01C21AA9A000C2132 /* GeoLite2-Country.mmdb */; }; - D736A97F1C23B59F0070EAA3 /* GeoLite2-Country.mmdb in Resources */ = {isa = PBXBuildFile; fileRef = D73CAED01C21AA9A000C2132 /* GeoLite2-Country.mmdb */; }; D736A9811C23B7D40070EAA3 /* maxminddb_config.h in Headers */ = {isa = PBXBuildFile; fileRef = D73CAECE1C21A7B0000C2132 /* maxminddb_config.h */; settings = {ATTRIBUTES = (Public, ); }; }; D736A9821C23B7D40070EAA3 /* maxminddb-compat-util.h in Headers */ = {isa = PBXBuildFile; fileRef = D73CAED11C21AAEA000C2132 /* maxminddb-compat-util.h */; settings = {ATTRIBUTES = (Public, ); }; }; D736A9831C23B7D40070EAA3 /* maxminddb.h in Headers */ = {isa = PBXBuildFile; fileRef = D73CAECF1C21A7B0000C2132 /* maxminddb.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -71,9 +71,6 @@ D73CAECF1C21A7B0000C2132 /* maxminddb.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = maxminddb.h; sourceTree = ""; }; D73CAED01C21AA9A000C2132 /* GeoLite2-Country.mmdb */ = {isa = PBXFileReference; lastKnownFileType = file; path = "GeoLite2-Country.mmdb"; sourceTree = ""; }; D73CAED11C21AAEA000C2132 /* maxminddb-compat-util.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "maxminddb-compat-util.h"; sourceTree = ""; }; - D77179AE1EF800B300E25F23 /* MMDB-Swift.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = "MMDB-Swift.podspec"; sourceTree = ""; }; - D77179AF1EF800B300E25F23 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; - D77179B01EF800B300E25F23 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; D7999FEC2307B8B4003EB8CC /* data-pool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "data-pool.h"; sourceTree = ""; }; D7999FED2307B8B4003EB8CC /* data-pool.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "data-pool.c"; sourceTree = ""; }; D7999FF22307B9D7003EB8CC /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; @@ -118,6 +115,7 @@ 366F5FE51F052F7F00DE3883 /* MMDBTests */ = { isa = PBXGroup; children = ( + D73CAED01C21AA9A000C2132 /* GeoLite2-Country.mmdb */, 366F5FF71F05301400DE3883 /* Info-OSX.plist */, 366F5FE81F052F7F00DE3883 /* Info-iOS.plist */, 366F5FE61F052F7F00DE3883 /* MMDBTests.swift */, @@ -136,9 +134,6 @@ D716CB311C21432C00D89B5C /* libmaxminddb */, 366F5FE51F052F7F00DE3883 /* MMDBTests */, D716CB301C21432C00D89B5C /* Products */, - D77179AE1EF800B300E25F23 /* MMDB-Swift.podspec */, - D77179AF1EF800B300E25F23 /* Package.swift */, - D77179B01EF800B300E25F23 /* README.md */, ); sourceTree = ""; }; @@ -156,7 +151,6 @@ D716CB311C21432C00D89B5C /* libmaxminddb */ = { isa = PBXGroup; children = ( - D73CAED01C21AA9A000C2132 /* GeoLite2-Country.mmdb */, D73CAED11C21AAEA000C2132 /* maxminddb-compat-util.h */, D73CAECC1C21A7A2000C2132 /* maxminddb.c */, D73CAECF1C21A7B0000C2132 /* maxminddb.h */, @@ -254,7 +248,6 @@ isa = PBXNativeTarget; buildConfigurationList = D716CB4C1C23A58700D89B5C /* Build configuration list for PBXNativeTarget "MMDB-iOS" */; buildPhases = ( - 366F5FDD1F05152C00DE3883 /* ShellScript */, D716CB421C23A58700D89B5C /* Sources */, D716CB431C23A58700D89B5C /* Frameworks */, D716CB441C23A58700D89B5C /* Headers */, @@ -273,7 +266,6 @@ isa = PBXNativeTarget; buildConfigurationList = D716CB591C23A5DC00D89B5C /* Build configuration list for PBXNativeTarget "MMDB-OSX" */; buildPhases = ( - 366F5FDE1F0515CD00DE3883 /* ShellScript */, D716CB4F1C23A5DC00D89B5C /* Sources */, D716CB501C23A5DC00D89B5C /* Frameworks */, D716CB511C23A5DC00D89B5C /* Headers */, @@ -343,6 +335,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 36D1827B23C0688C002E42A5 /* GeoLite2-Country.mmdb in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -350,6 +343,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 36D1827C23C0688D002E42A5 /* GeoLite2-Country.mmdb in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -357,7 +351,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - D736A97E1C23B59D0070EAA3 /* GeoLite2-Country.mmdb in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -365,41 +358,11 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - D736A97F1C23B59F0070EAA3 /* GeoLite2-Country.mmdb in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ -/* Begin PBXShellScriptBuildPhase section */ - 366F5FDD1F05152C00DE3883 /* ShellScript */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 12; - files = ( - ); - inputPaths = ( - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "if [ ! -f $SRCROOT/Sources/libmaxminddb/GeoLite2-Country.mmdb ] || [ $CONFIGURATION == \"Release\" ]; then\n $SRCROOT/update_database.sh\nfi"; - }; - 366F5FDE1F0515CD00DE3883 /* ShellScript */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 12; - files = ( - ); - inputPaths = ( - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "if [ ! -f $SRCROOT/MMDB/GeoLite2-Country.mmdb ] || [ $CONFIGURATION == \"Release\" ]; then\n $SRCROOT/update_database.sh\nfi"; - }; -/* End PBXShellScriptBuildPhase section */ - /* Begin PBXSourcesBuildPhase section */ 366F5FE01F052F7F00DE3883 /* Sources */ = { isa = PBXSourcesBuildPhase; diff --git a/README.md b/README.md index 77d065d..cc65113 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,9 @@ A tiny wrapper for [libmaxminddb](https://github.com/maxmind/libmaxminddb) which allows you to lookup Geo data by IP address. -This product includes [GeoLite2 data](http://dev.maxmind.com/geoip/geoip2/geolite2/) created by MaxMind, available from [http://www.maxmind.com](http://www.maxmind.com). +--- + +**NOTE** From `v0.5.0`, MMDB-Swift no longer bundles [GeoLite2 database](http://dev.maxmind.com/geoip/geoip2/geolite2/) due to the license change. Developers should download the binary version from the [Maxmind website](http://dev.maxmind.com/geoip/geoip2/geolite2/). ## CocoaPods @@ -60,7 +62,7 @@ let package = Package( ## Usage ``` swift -guard let db = MMDB() else { +guard let db = MMDB("PATH_TO_THE_DATABASE") else { print("Failed to open DB.") return } diff --git a/Sources/MMDB.swift b/Sources/MMDB.swift index 4bf6a21..29ae6b9 100644 --- a/Sources/MMDB.swift +++ b/Sources/MMDB.swift @@ -74,11 +74,8 @@ final public class MMDB { fileprivate typealias ListPtr = UnsafeMutablePointer fileprivate typealias StringPtr = UnsafeMutablePointer - public init?(_ filename: String? = nil) { - if let filename = filename, openDB(atPath: filename) { return } - - let path = Bundle(for: MMDB.self).path(forResource: "GeoLite2-Country", ofType: "mmdb") - if let path = path, openDB(atPath: path) { return } + public init?(_ filename: String) { + if openDB(atPath: filename) { return } return nil } diff --git a/Sources/libmaxminddb/GeoLite2-Country.mmdb b/Tests/MMDBTests/GeoLite2-Country.mmdb similarity index 100% rename from Sources/libmaxminddb/GeoLite2-Country.mmdb rename to Tests/MMDBTests/GeoLite2-Country.mmdb diff --git a/Tests/MMDBTests/MMDBTests.swift b/Tests/MMDBTests/MMDBTests.swift index ff8ecd4..4aec221 100644 --- a/Tests/MMDBTests/MMDBTests.swift +++ b/Tests/MMDBTests/MMDBTests.swift @@ -6,7 +6,7 @@ class MMDBTests: XCTestCase { override func setUp() { super.setUp() - database = MMDB() + database = MMDB(Bundle(for: MMDBTests.self).path(forResource: "GeoLite2-Country", ofType: "mmdb")!) } func testExample() { diff --git a/update_database.sh b/update_database.sh deleted file mode 100755 index 72a2ddd..0000000 --- a/update_database.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env sh - -set -e - -echo "Updating GeoIP database." - -tmpfile=$(mktemp) -tmpdir=$(mktemp -d) - -curl -L -o $tmpfile http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz - -tar -xzf $tmpfile -C $tmpdir - -find $tmpdir -type f -exec mv {} $tmpdir \; - -mv $tmpdir/GeoLite2-Country.mmdb $(dirname $0)/Sources/libmaxminddb/ - -echo "Updated GeoIP database." - - -