Vidalia  0.3.1
GeoIpDatabase.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 ** \file GeoIpDatabase.h
13 ** \brief Interface to a local MaxMind GeoIP database.
14 */
15 
16 #ifndef _GEOIPDATABASE_H
17 #define _GEOIPDATABASE_H
18 
19 #include <GeoIP.h>
20 #include <GeoIPCity.h>
21 
22 #include <QObject>
23 
24 class QString;
25 class QHostAddress;
26 class GeoIpRecord;
27 
28 
29 class GeoIpDatabase : public QObject
30 {
31  Q_OBJECT
32 
33 public:
34  enum DatabaseType {
45  };
46 
47  /** Default constructor.
48  */
49  GeoIpDatabase(QObject *parent = 0);
50 
51  /** Virtual destructor. Closes the database if it is currently open.
52  */
53  virtual ~GeoIpDatabase();
54 
55  /** Open the GeoIP database file <b>fname</b> and return true if
56  * successful. Otherwise, return false. If a different database file is
57  * already open, the open database will be closed before the new one is
58  * opened.
59  * \sa close()
60  * \sa isOpen()
61  */
62  bool open(const QString &fname);
63 
64  /** Closes an open dataase, or does nothing if no database file is
65  * currently open.
66  * \sa open()
67  * \sa isOpen()
68  */
69  void close();
70 
71  /** Return true if this object has a currently open GeoIP database.
72  * \sa open()
73  */
74  bool isOpen() const;
75 
76  /** Returns the DatabaseType enum value corresponding to the current
77  * database type. If no database is open, this will simply return
78  * UnknownDatabase.
79  */
81 
82  /** Resolves the IP address <b>ip</b> to its two-letter ISO-3166 country
83  * code and returns the result on success. On failure, this returns a
84  * default-constructed QString.
85  */
86  QString countryCodeByAddr(const QHostAddress &ip);
87 
88  /** Resolves the IP address <b>ip</b> to an approximate geographic
89  * location and returns the result on success. On failure, this returns
90  * a default-constructed QString.
91  */
92  GeoIpRecord recordByAddr(const QHostAddress &ip);
93 
94 private:
95  GeoIP *_db; /**< Pointer to the local GeoIP database object. */
96 };
97 
98 #endif
99 
GeoIpRecord
Definition: GeoIpRecord.h:24
GeoIpDatabase::DomainDatabase
@ DomainDatabase
Definition: GeoIpDatabase.h:44
GeoIpDatabase::CountryDatabase
@ CountryDatabase
Definition: GeoIpDatabase.h:36
GeoIpDatabase::UnknownDatabase
@ UnknownDatabase
Definition: GeoIpDatabase.h:35
GeoIpDatabase::open
bool open(const QString &fname)
Definition: GeoIpDatabase.cpp:36
GeoIpDatabase::OrganizationDatabase
@ OrganizationDatabase
Definition: GeoIpDatabase.h:39
GeoIpDatabase::~GeoIpDatabase
virtual ~GeoIpDatabase()
Definition: GeoIpDatabase.cpp:30
GeoIpDatabase::IspDatabase
@ IspDatabase
Definition: GeoIpDatabase.h:40
GeoIpDatabase::NetSpeedDatabase
@ NetSpeedDatabase
Definition: GeoIpDatabase.h:43
GeoIpDatabase::isOpen
bool isOpen() const
Definition: GeoIpDatabase.cpp:60
GeoIpDatabase
Definition: GeoIpDatabase.h:29
GeoIpDatabase::_db
GeoIP * _db
Definition: GeoIpDatabase.h:95
GeoIpDatabase::DatabaseType
DatabaseType
Definition: GeoIpDatabase.h:34
GeoIpDatabase::AsnDatabase
@ AsnDatabase
Definition: GeoIpDatabase.h:42
GeoIpDatabase::ProxyDatabase
@ ProxyDatabase
Definition: GeoIpDatabase.h:41
GeoIpDatabase::type
GeoIpDatabase::DatabaseType type() const
Definition: GeoIpDatabase.cpp:66
GeoIpDatabase::close
void close()
Definition: GeoIpDatabase.cpp:51
GeoIpDatabase::RegionDatabase
@ RegionDatabase
Definition: GeoIpDatabase.h:38
GeoIpDatabase::recordByAddr
GeoIpRecord recordByAddr(const QHostAddress &ip)
Definition: GeoIpDatabase.cpp:120
GeoIpDatabase::GeoIpDatabase
GeoIpDatabase(QObject *parent=0)
Definition: GeoIpDatabase.cpp:25
GeoIpDatabase::countryCodeByAddr
QString countryCodeByAddr(const QHostAddress &ip)
Definition: GeoIpDatabase.cpp:108
GeoIpDatabase::CityDatabase
@ CityDatabase
Definition: GeoIpDatabase.h:37