Vidalia 0.2.12

GeoIpDatabase.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.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 ** \file GeoIpDatabase.h
00013 ** \brief Interface to a local MaxMind GeoIP database.
00014 */
00015 
00016 #ifndef _GEOIPDATABASE_H
00017 #define _GEOIPDATABASE_H
00018 
00019 #include <GeoIP.h>
00020 #include <GeoIPCity.h>
00021 
00022 #include <QObject>
00023 
00024 class QString;
00025 class QHostAddress;
00026 class GeoIpRecord;
00027 
00028 
00029 class GeoIpDatabase : public QObject
00030 {
00031   Q_OBJECT
00032 
00033 public:
00034   enum DatabaseType {
00035     UnknownDatabase = 0,
00036     CountryDatabase,
00037     CityDatabase,
00038     RegionDatabase,
00039     OrganizationDatabase,
00040     IspDatabase,
00041     ProxyDatabase,
00042     AsnDatabase,
00043     NetSpeedDatabase,
00044     DomainDatabase
00045   };
00046 
00047   /** Default constructor.
00048    */
00049   GeoIpDatabase(QObject *parent = 0);
00050 
00051   /** Virtual destructor. Closes the database if it is currently open.
00052    */
00053   virtual ~GeoIpDatabase();
00054 
00055   /** Open the GeoIP database file <b>fname</b> and return true if
00056    * successful. Otherwise, return false. If a different database file is
00057    * already open, the open database will be closed before the new one is
00058    * opened.
00059    * \sa close()
00060    * \sa isOpen()
00061    */
00062   bool open(const QString &fname);
00063 
00064   /** Closes an open dataase, or does nothing if no database file is
00065    * currently open.
00066    * \sa open()
00067    * \sa isOpen()
00068    */
00069   void close();
00070 
00071   /** Return true if this object has a currently open GeoIP database.
00072    * \sa open()
00073    */
00074   bool isOpen() const;
00075 
00076   /** Returns the DatabaseType enum value corresponding to the current
00077    * database type. If no database is open, this will simply return
00078    * UnknownDatabase.
00079    */
00080   GeoIpDatabase::DatabaseType type() const;
00081 
00082   /** Resolves the IP address <b>ip</b> to its two-letter ISO-3166 country
00083    * code and returns the result on success. On failure, this returns a
00084    * default-constructed QString.
00085    */
00086   QString countryCodeByAddr(const QHostAddress &ip);
00087 
00088   /** Resolves the IP address <b>ip</b> to an approximate geographic
00089    * location and returns the result on success. On failure, this returns
00090    * a default-constructed QString.
00091    */
00092   GeoIpRecord recordByAddr(const QHostAddress &ip);
00093 
00094 private:
00095   GeoIP *_db; /**< Pointer to the local GeoIP database object. */
00096 };
00097 
00098 #endif
00099