Vidalia  0.3.1
GeoIpResolver.h
Go to the documentation of this file.
1 /*
2 ** This file is part of Vidalia, and is subject to the license terms in the
3 ** LICENSE file, found in the top level directory of this distribution. If you
4 ** did not receive the LICENSE file with this file, you may obtain it from the
5 ** Vidalia source package distributed by the Vidalia Project at
6 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7 ** including this file, may be copied, modified, propagated, or distributed
8 ** except according to the terms described in the LICENSE file.
9 */
10 
11 /*
12 G** \file GeoIpResolver.h
13 ** \brief Retrieves GeoIP information either from Tor or from a local
14 ** database and returns the result.
15 */
16 
17 #ifndef _GEOIPRESOLVER_H
18 #define _GEOIPRESOLVER_H
19 
20 #include "Vidalia.h"
21 #ifdef USE_GEOIP
22 #include "GeoIpDatabase.h"
23 #endif
24 #include "CountryInfo.h"
25 
26 #include <QObject>
27 #include <QList>
28 #include <QHash>
29 #include <QHostAddress>
30 
31 class QString;
32 class GeoIpRecord;
33 
34 
35 class GeoIpResolver : public QObject
36 {
37  Q_OBJECT
38 
39 public:
40  /** Default constructor.
41  */
42  GeoIpResolver(QObject *parent = 0);
43 
44  /** Sets the local database file to <b>databaseFile</b>. Returns true if
45  * <b>databaseFile</b> could be opened for reading. Otherwise, returns
46  * false.
47  * \sa setUseLocalDatabase()
48  */
49  bool setLocalDatabase(const QString &databaseFile);
50 
51  /** Enables or disables the use of a local GeoIP database, depending on
52  * the value of <b>useLocalDatabase</b>.
53  * \sa setLocalDatabase()
54  */
55  void setUseLocalDatabase(bool useLocalDatabase);
56 
57  /** Resolves a single IP to a geographic location and returns the
58  * result on success. On failure, this returns a default-constructed
59  * GeoIpRecord object.
60  */
61  GeoIpRecord resolve(const QHostAddress &ip);
62 
63 protected:
64  /** Maps <b>ip</b> to a country code using Tor, and then maps the
65  * country code to a geographic location using the built-in
66  * country-to-coordinate database.
67  */
68  GeoIpRecord resolveUsingTor(const QHostAddress &ip);
69 
70  /** Maps <b>ip</b> to an approximate geographic location using a local
71  * GeoIP database and returns the result on success.
72  * \sa setLocalDatabase()
73  * \sa setUseLocalDatabase()
74  */
75  GeoIpRecord resolveUsingLocalDatabase(const QHostAddress &ip);
76 
77 private:
78 #ifdef USE_GEOIP
79  /** Wrapper around a local database used for looking up GeoIP
80  * information.
81  */
82  GeoIpDatabase _database;
83 #endif
85 };
86 
87 #endif
88 
GeoIpRecord
Definition: GeoIpRecord.h:24
GeoIpResolver::resolveUsingLocalDatabase
GeoIpRecord resolveUsingLocalDatabase(const QHostAddress &ip)
Definition: GeoIpResolver.cpp:58
GeoIpResolver::GeoIpResolver
GeoIpResolver(QObject *parent=0)
Definition: GeoIpResolver.cpp:23
Vidalia.h
GeoIpResolver
Definition: GeoIpResolver.h:35
GeoIpResolver::resolve
GeoIpRecord resolve(const QHostAddress &ip)
Definition: GeoIpResolver.cpp:78
GeoIpResolver::_useLocalDatabase
bool _useLocalDatabase
Definition: GeoIpResolver.h:84
GeoIpDatabase.h
GeoIpDatabase
Definition: GeoIpDatabase.h:29
GeoIpResolver::resolveUsingTor
GeoIpRecord resolveUsingTor(const QHostAddress &ip)
Definition: GeoIpResolver.cpp:45
GeoIpResolver::setUseLocalDatabase
void setUseLocalDatabase(bool useLocalDatabase)
Definition: GeoIpResolver.cpp:39
CountryInfo.h
GeoIpResolver::setLocalDatabase
bool setLocalDatabase(const QString &databaseFile)
Definition: GeoIpResolver.cpp:29