diff --git a/AUTHORS b/AUTHORS index ea1d6fb95..3c64ea125 100644 --- a/AUTHORS +++ b/AUTHORS @@ -12,11 +12,6 @@ Code from other projects: copyright: Malte Starostik license: LGPL -GeoIP database author: -* files: src/geoip/GeoIP.dat - copyright: MaxMind, Inc (http://maxmind.com/) - license: Open Data License (see src/geoip/LICENSE.txt) - Images Authors: * files: src/Icons/*.png copyright: Gnome Icon Theme diff --git a/configure b/configure index c855b34bd..82630eabf 100755 --- a/configure +++ b/configure @@ -18,8 +18,12 @@ Main options: --help This help text. Dependency options: - --with-libboost-inc=[path] Path to libboost include files - --disable-libnotify Disable use of libnotify + --with-libboost-inc=[path] Path to libboost include files + --disable-libnotify Disable use of libnotify + --disable-geoip-database Disable use of geoip-database + --with-geoip-database-embedded Geoip Database will be embedded in + qBittorrent executable (please follow + instructions in src/geoip/README) EOT } @@ -146,6 +150,16 @@ while [ $# -gt 0 ]; do shift ;; + --disable-geoip-database) + QC_DISABLE_geoip_database="Y" + shift + ;; + + --with-geoip-database-embedded) + QC_WITH_GEOIP_DATABASE_EMBEDDED="Y" + shift + ;; + --verbose) QC_VERBOSE="Y" shift @@ -169,6 +183,8 @@ echo DATADIR=$DATADIR echo EX_QTDIR=$EX_QTDIR echo QC_WITH_LIBBOOST_INC=$QC_WITH_LIBBOOST_INC echo QC_DISABLE_libnotify=$QC_DISABLE_libnotify +echo QC_DISABLE_geoip_database=$QC_DISABLE_geoip_database +echo QC_WITH_GEOIP_DATABASE_EMBEDDED=$QC_WITH_GEOIP_DATABASE_EMBEDDED echo fi @@ -422,6 +438,36 @@ public: return true; } }; +#line 1 "geoip-database.qcm" +/* +-----BEGIN QCMOD----- +name: geoip-database +arg: with-geoip-database-embedded, Geoip Database will be embedded in qBittorrent executable (please follow instructions in src/geoip/README) +-----END QCMOD----- +*/ +// see Conf::findPkgConfig +class qc_geoip_database : public ConfObj +{ +public: + qc_geoip_database(Conf *c) : ConfObj(c) {} + QString name() const { return "GeoIP Database (optional)"; } + QString shortname() const { return "GeoIP Database"; } + bool exec() { +#ifdef Q_WS_X11 + if(!conf->getenv("QC_WITH_GEOIP_DATABASE_EMBEDDED").isEmpty()) { +#endif + conf->addDefine("WITH_GEOIP_EMBEDDED"); + printf(" embedded and"); + return true; +#ifdef Q_WS_X11 + } + if(QFile::exists("/usr/share/GeoIP/GeoIP.dat") || QFile::exists("/usr/local/share/GeoIP/GeoIP.dat")) + return true; + printf("\nWarning: GeoIP database was not found at /usr/share/GeoIP/GeoIP.dat\nCountry resolution will be slow."); + return false; +#endif + } +}; EOT cat >$1/modules_new.cpp <$1/modules_new.cpp <required = false; o->disabled = false; + o = new qc_geoip_database(conf); + o->required = false; + o->disabled = false; EOT cat >$1/conf4.h < + + diff --git a/qcm/geoip-database.qcm b/qcm/geoip-database.qcm new file mode 100644 index 000000000..30c43e63c --- /dev/null +++ b/qcm/geoip-database.qcm @@ -0,0 +1,29 @@ +/* +-----BEGIN QCMOD----- +name: geoip-database +arg: with-geoip-database-embedded, Geoip Database will be embedded in qBittorrent executable (please follow instructions in src/geoip/README) +-----END QCMOD----- +*/ +// see Conf::findPkgConfig +class qc_geoip_database : public ConfObj +{ +public: + qc_geoip_database(Conf *c) : ConfObj(c) {} + QString name() const { return "GeoIP Database (optional)"; } + QString shortname() const { return "GeoIP Database"; } + bool exec() { +#ifdef Q_WS_X11 + if(!conf->getenv("QC_WITH_GEOIP_DATABASE_EMBEDDED").isEmpty()) { +#endif + conf->addDefine("WITH_GEOIP_EMBEDDED"); + printf(" embedded and"); + return true; +#ifdef Q_WS_X11 + } + if(QFile::exists("/usr/share/GeoIP/GeoIP.dat") || QFile::exists("/usr/local/share/GeoIP/GeoIP.dat")) + return true; + printf("\nWarning: GeoIP database was not found at /usr/share/GeoIP/GeoIP.dat\nCountry resolution will be slow."); + return false; +#endif + } +}; diff --git a/src/geoip.h b/src/geoip.h index 4a22b9823..4c2712d26 100644 --- a/src/geoip.h +++ b/src/geoip.h @@ -40,43 +40,27 @@ using namespace libtorrent; -// TODO: Update from Internet class GeoIP { protected: static QString geoipFolder(bool embedded=false) { +#ifdef WITH_GEOIP_EMBEDDED if(embedded) return ":/geoip/"; return misc::qBittorrentPath()+"geoip"+QDir::separator(); +#else + if(QFile::exists("/usr/local/share/GeoIP/GeoIP.dat")) + return "/usr/local/share/GeoIP/"; + return "/usr/share/GeoIP/"; +#endif } static QString geoipDBpath(bool embedded=false) { return geoipFolder(embedded)+"GeoIP.dat"; } - static QString geoipVersionPath(bool embedded=false) { - return geoipFolder(embedded)+"VERSION"; - } - - static int getDBVersion(bool embedded = false) { - QFile vFile(geoipVersionPath(embedded)); - qDebug("Reading file at %s", geoipVersionPath(embedded).toLocal8Bit().data()); - if(vFile.exists() && vFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - qDebug("File exists and was opened"); - QByteArray v = vFile.readAll().trimmed(); - /*while(!v.isEmpty() && v[0] == '0') { - v = v.mid(1); - }*/ - qDebug("Read version: %s", v.data()); - bool ok = false; - int version = v.toInt(&ok); - qDebug("Read version %d (Error? %d)", version, (int) !ok); - if(ok) return version; - } - return 0; - } - - static void updateLocalDb() { - if(getDBVersion(true) > getDBVersion(false)) { // Update required +#ifdef WITH_GEOIP_EMBEDDED + static void exportEmbeddedDb() { + if(!QFile::exists(geoipDBpath(false)) || QFile(geoipDBpath(false)).size() != QFile(geoipDBpath(true)).size()) { // Export is required qDebug("A local Geoip database update is required, proceeding..."); // Create geoip folder is necessary QDir gfolder(geoipFolder(false)); @@ -86,18 +70,18 @@ protected: // Remove destination files if(QFile::exists(geoipDBpath(false))) QFile::remove(geoipDBpath(false)); - if(QFile::exists(geoipVersionPath(false))) - QFile::remove(geoipVersionPath(false)); // Copy from executable to hard disk QFile::copy(geoipDBpath(true), geoipDBpath(false)); - QFile::copy(geoipVersionPath(true), geoipVersionPath(false)); qDebug("Local Geoip database was updated"); } } +#endif public: static void loadDatabase(session *s) { - updateLocalDb(); + #ifdef WITH_GEOIP_EMBEDDED + exportEmbeddedDb(); +#endif if(QFile::exists(geoipDBpath(false))) { qDebug("Loading GeoIP database from %s...", geoipDBpath(false).toLocal8Bit().data()); if(!s->load_country_db(geoipDBpath(false).toLocal8Bit().data())) { diff --git a/src/geoip.qrc b/src/geoip.qrc index ddee2d064..50758c4f9 100644 --- a/src/geoip.qrc +++ b/src/geoip.qrc @@ -1,7 +1,5 @@ - - - geoip/GeoIP.dat - geoip/VERSION - + + + geoip/GeoIP.dat + - diff --git a/src/geoip/GeoIP.dat b/src/geoip/GeoIP.dat deleted file mode 100644 index f7d043ed8..000000000 Binary files a/src/geoip/GeoIP.dat and /dev/null differ diff --git a/src/geoip/LICENSE.txt b/src/geoip/LICENSE.txt deleted file mode 100644 index 01c2910fe..000000000 --- a/src/geoip/LICENSE.txt +++ /dev/null @@ -1,39 +0,0 @@ -There are two licenses, one for the C library software, and one for -the database. - -SOFTWARE LICENSE (C library) - -The GeoIP C Library is licensed under the LGPL. For details see -the COPYING file. - -OPEN DATA LICENSE (GeoLite Country and GeoLite City databases) - -Copyright (c) 2008 MaxMind, Inc. All Rights Reserved. - -All advertising materials and documentation mentioning features or use of -this database must display the following acknowledgment: -"This product includes GeoLite data created by MaxMind, available from -http://maxmind.com/" - -Redistribution and use with or without modification, are permitted provided -that the following conditions are met: -1. Redistributions must retain the above copyright notice, this list of -conditions and the following disclaimer in the documentation and/or other -materials provided with the distribution. -2. All advertising materials and documentation mentioning features or use of -this database must display the following acknowledgement: -"This product includes GeoLite data created by MaxMind, available from -http://maxmind.com/" -3. "MaxMind" may not be used to endorse or promote products derived from this -database without specific prior written permission. - -THIS DATABASE IS PROVIDED BY MAXMIND, INC ``AS IS'' AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL MAXMIND BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -DATABASE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/geoip/README b/src/geoip/README new file mode 100644 index 000000000..9d001dca3 --- /dev/null +++ b/src/geoip/README @@ -0,0 +1,12 @@ +If you wish to embed GeoIP database into qBittorrent executable, please download put GeoIP.dat in this folder. + +GeoIP Database can be downloaded from here: +* http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz +Note that the database should be uncompressed. + +Embedding GeoIP database into qBittorrent executable is advised for: +* Windows +* Mac OS X +* Linux distributions that don't provide GeoIP database in a separate package + +On Linux operating system, since this is not the default behavior, you also need to pass --with-geoip-database-embedded parameter to the configure file. diff --git a/src/geoip/VERSION b/src/geoip/VERSION deleted file mode 100644 index bbf25ef50..000000000 --- a/src/geoip/VERSION +++ /dev/null @@ -1 +0,0 @@ -0911 diff --git a/src/src.pro b/src/src.pro index de7bbbbb1..b0967f9c9 100644 --- a/src/src.pro +++ b/src/src.pro @@ -9,12 +9,10 @@ DEBUG_MODE = 0 TEMPLATE = app TARGET = qbittorrent CONFIG += qt \ - thread \ - x11 \ - network + thread # Update this VERSION for each release -DEFINES += VERSION=\\\"v2.0.0rc5\\\" +DEFINES += VERSION=\\\"v2.0.0rc6\\\" DEFINES += VERSION_MAJOR=2 DEFINES += VERSION_MINOR=0 DEFINES += VERSION_BUGFIX=0 @@ -105,11 +103,41 @@ win32:LIBS += -lssl32 \ -lwsock32 \ -ladvapi32 \ -lwinmm + +win32 { + DEFINES += WITH_GEOIP_EMBEDDED + message("On Windows, GeoIP database must be embedded.") +} + +macx { + DEFINES += WITH_GEOIP_EMBEDDED + message("On Mac OS X, GeoIP database must be embedded.") +} + +unix:!macx { + contains(DEFINES, WITH_GEOIP_EMBEDDED) { + message("You chose to embed GeoIP database in qBittorrent executable.") + } +} + RESOURCES = icons.qrc \ lang.qrc \ search.qrc \ - webui.qrc \ - geoip.qrc + webui.qrc + +# Add GeoIP resource file if the GeoIP database +# should be embedded in qBittorrent executable +contains(DEFINES, WITH_GEOIP_EMBEDDED) { + exists("geoip/GeoIP.dat") { + message("GeoIP.dat was found in src/geoip/.") + RESOURCES += geoip.qrc + } else { + DEFINES -= WITH_GEOIP_EMBEDDED + error("GeoIP.dat was not found in src/geoip/ folder, please follow instructions in src/geoip/README.") + } +} else { + message("GeoIP database will not be embedded in qBittorrent executable.") +} # Translations TRANSLATIONS = $$LANG_PATH/qbittorrent_fr.ts \