Skip to content

Commit

Permalink
- No longer ships GeoIP database since most distributions provide it …
Browse files Browse the repository at this point in the history
…in a separate package

- GeoIP database is no longer embedded in qBittorrent executable unless --with-geoip-database-embedded parameter is passed to configure (see src/geoip/REAME)
- Dropped "CONFIG += x11 network" in project file since it does not seem to be required
- Updated configure file to reflect Geoip changes
  • Loading branch information
Christophe Dumez committed Dec 7, 2009
1 parent 8df1708 commit 968a5f3
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 88 deletions.
5 changes: 0 additions & 5 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ Code from other projects:
copyright: Malte Starostik <[email protected]>
license: LGPL

GeoIP database author:
* files: src/geoip/GeoIP.dat
copyright: MaxMind, Inc (http:https://maxmind.com/)
license: Open Data License (see src/geoip/LICENSE.txt)

Images Authors:
* files: src/Icons/*.png
copyright: Gnome Icon Theme
Expand Down
55 changes: 53 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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 <<EOT
Expand All @@ -437,6 +483,9 @@ cat >$1/modules_new.cpp <<EOT
o = new qc_libnotify(conf);
o->required = false;
o->disabled = false;
o = new qc_geoip_database(conf);
o->required = false;
o->disabled = false;
EOT
cat >$1/conf4.h <<EOT
Expand Down Expand Up @@ -1384,6 +1433,8 @@ export DATADIR
export EX_QTDIR
export QC_WITH_LIBBOOST_INC
export QC_DISABLE_libnotify
export QC_DISABLE_geoip_database
export QC_WITH_GEOIP_DATABASE_EMBEDDED
export QC_VERBOSE
rm -rf .qconftemp
(
Expand Down
2 changes: 2 additions & 0 deletions qbittorrent.qc
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
</dep>
<dep type='libnotify'>
</dep>
<dep type='geoip-database'>
</dep>
</qconf>
29 changes: 29 additions & 0 deletions qcm/geoip-database.qcm
Original file line number Diff line number Diff line change
@@ -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
}
};
42 changes: 13 additions & 29 deletions src/geoip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -86,18 +70,18 @@ class GeoIP {
// 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())) {
Expand Down
10 changes: 4 additions & 6 deletions src/geoip.qrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>geoip/GeoIP.dat</file>
<file>geoip/VERSION</file>
</qresource>
<RCC>
<qresource prefix="/" >
<file>geoip/GeoIP.dat</file>
</qresource>
</RCC>

Binary file removed src/geoip/GeoIP.dat
Binary file not shown.
39 changes: 0 additions & 39 deletions src/geoip/LICENSE.txt

This file was deleted.

12 changes: 12 additions & 0 deletions src/geoip/README
Original file line number Diff line number Diff line change
@@ -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:https://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.
1 change: 0 additions & 1 deletion src/geoip/VERSION

This file was deleted.

40 changes: 34 additions & 6 deletions src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down

0 comments on commit 968a5f3

Please sign in to comment.