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
24class QString;
25class QHostAddress;
26class GeoIpRecord;
27
28
29class GeoIpDatabase : public QObject
30{
31 Q_OBJECT
32
33public:
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
94private:
95 GeoIP *_db; /**< Pointer to the local GeoIP database object. */
96};
97
98#endif
99
GeoIpRecord recordByAddr(const QHostAddress &ip)
GeoIpDatabase(QObject *parent=0)
bool isOpen() const
GeoIpDatabase::DatabaseType type() const
bool open(const QString &fname)
QString countryCodeByAddr(const QHostAddress &ip)
virtual ~GeoIpDatabase()