Vidalia  0.2.15
GeoIpResolver.h
Go to the documentation of this file.
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.torproject.org/projects/vidalia.html. No part of Vidalia, 
00007 **  including this file, may be copied, modified, propagated, or distributed 
00008 **  except according to the terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 G** \file GeoIpResolver.h
00013 ** \brief Retrieves GeoIP information either from Tor or from a local
00014 ** database and returns the result.
00015 */
00016 
00017 #ifndef _GEOIPRESOLVER_H
00018 #define _GEOIPRESOLVER_H
00019 
00020 #include "Vidalia.h"
00021 #ifdef USE_GEOIP
00022 #include "GeoIpDatabase.h"
00023 #endif
00024 #include "CountryInfo.h"
00025 
00026 #include <QObject>
00027 #include <QList>
00028 #include <QHash>
00029 #include <QHostAddress>
00030 
00031 class QString;
00032 class GeoIpRecord;
00033 
00034 
00035 class GeoIpResolver : public QObject
00036 {
00037   Q_OBJECT
00038 
00039 public:
00040   /** Default constructor.
00041    */
00042   GeoIpResolver(QObject *parent = 0);
00043 
00044   /** Sets the local database file to <b>databaseFile</b>. Returns true if
00045    * <b>databaseFile</b> could be opened for reading. Otherwise, returns
00046    * false.
00047    * \sa setUseLocalDatabase()
00048    */
00049   bool setLocalDatabase(const QString &databaseFile);
00050 
00051   /** Enables or disables the use of a local GeoIP database, depending on
00052    * the value of <b>useLocalDatabase</b>.
00053    * \sa setLocalDatabase()
00054    */
00055   void setUseLocalDatabase(bool useLocalDatabase);
00056 
00057   /** Resolves a single IP to a geographic location and returns the
00058    * result on success. On failure, this returns a default-constructed
00059    * GeoIpRecord object.
00060    */
00061   GeoIpRecord resolve(const QHostAddress &ip);
00062 
00063 protected:
00064   /** Maps <b>ip</b> to a country code using Tor, and then maps the
00065    * country code to a geographic location using the built-in
00066    * country-to-coordinate database.
00067    */
00068   GeoIpRecord resolveUsingTor(const QHostAddress &ip);
00069 
00070   /** Maps <b>ip</b> to an approximate geographic location using a local
00071    * GeoIP database and returns the result on success.
00072    * \sa setLocalDatabase()
00073    * \sa setUseLocalDatabase()
00074    */
00075   GeoIpRecord resolveUsingLocalDatabase(const QHostAddress &ip);
00076 
00077 private:
00078 #ifdef USE_GEOIP
00079   /** Wrapper around a local database used for looking up GeoIP
00080    * information.
00081    */
00082   GeoIpDatabase _database;
00083 #endif
00084   bool _useLocalDatabase;
00085 };
00086 
00087 #endif
00088