Vidalia 0.2.10
|
00001 /* 00002 ** This file is part of Vidalia, and is subject to the license terms in the 00003 ** LICENSE file, found in the top level directory of this distribution. If you 00004 ** did not receive the LICENSE file with this file, you may obtain it from the 00005 ** Vidalia source package distributed by the Vidalia Project at 00006 ** http://www.vidalia-project.net/. No part of Vidalia, including this file, 00007 ** may be copied, modified, propagated, or distributed except according to the 00008 ** terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 G** \file GeoIpResolver.h 00013 ** \version $Id: GeoIpResolver.h 4378 2010-08-05 20:28:54Z edmanm $ 00014 ** \brief Retrieves GeoIP information either from Tor or from a local 00015 ** database and returns the result. 00016 */ 00017 00018 #ifndef _GEOIPRESOLVER_H 00019 #define _GEOIPRESOLVER_H 00020 00021 #include "Vidalia.h" 00022 #ifdef USE_GEOIP 00023 #include "GeoIpDatabase.h" 00024 #endif 00025 #include "CountryInfo.h" 00026 00027 #include <QObject> 00028 #include <QList> 00029 #include <QHash> 00030 #include <QHostAddress> 00031 00032 class QString; 00033 class GeoIpRecord; 00034 00035 00036 class GeoIpResolver : public QObject 00037 { 00038 Q_OBJECT 00039 00040 public: 00041 /** Default constructor. 00042 */ 00043 GeoIpResolver(QObject *parent = 0); 00044 00045 /** Sets the local database file to <b>databaseFile</b>. Returns true if 00046 * <b>databaseFile</b> could be opened for reading. Otherwise, returns 00047 * false. 00048 * \sa setUseLocalDatabase() 00049 */ 00050 bool setLocalDatabase(const QString &databaseFile); 00051 00052 /** Enables or disables the use of a local GeoIP database, depending on 00053 * the value of <b>useLocalDatabase</b>. 00054 * \sa setLocalDatabase() 00055 */ 00056 void setUseLocalDatabase(bool useLocalDatabase); 00057 00058 /** Resolves a single IP to a geographic location and returns the 00059 * result on success. On failure, this returns a default-constructed 00060 * GeoIpRecord object. 00061 */ 00062 GeoIpRecord resolve(const QHostAddress &ip); 00063 00064 protected: 00065 /** Maps <b>ip</b> to a country code using Tor, and then maps the 00066 * country code to a geographic location using the built-in 00067 * country-to-coordinate database. 00068 */ 00069 GeoIpRecord resolveUsingTor(const QHostAddress &ip); 00070 00071 /** Maps <b>ip</b> to an approximate geographic location using a local 00072 * GeoIP database and returns the result on success. 00073 * \sa setLocalDatabase() 00074 * \sa setUseLocalDatabase() 00075 */ 00076 GeoIpRecord resolveUsingLocalDatabase(const QHostAddress &ip); 00077 00078 private: 00079 #ifdef USE_GEOIP 00080 /** Wrapper around a local database used for looking up GeoIP 00081 * information. 00082 */ 00083 GeoIpDatabase _database; 00084 #endif 00085 bool _useLocalDatabase; 00086 }; 00087 00088 #endif 00089