Vidalia 0.2.10

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