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 geoipcache.h 00013 ** \version $Id: geoipcache.h 2362 2008-02-29 04:30:11Z edmanm $ 00014 ** \brief Caches the results of previous GeoIP requests 00015 */ 00016 00017 #ifndef _GEOIPCACHE_H 00018 #define _GEOIPCACHE_H 00019 00020 #include <QString> 00021 #include <QHash> 00022 #include <QHostAddress> 00023 00024 #include "geoipcacheitem.h" 00025 00026 00027 class GeoIpCache 00028 { 00029 public: 00030 /** Default constructor. */ 00031 GeoIpCache(); 00032 00033 /** Writes the current cache to disk. */ 00034 bool saveToDisk(QString *errmsg = 0); 00035 /** Reads the cache in from disk. */ 00036 bool loadFromDisk(QString *errmsg = 0); 00037 00038 /** Returns the location currently used for the cache file. */ 00039 QString cacheFilename(); 00040 /** Caches the given IP and geographic information to disk. */ 00041 void cache(GeoIp geoip); 00042 /** Returns a GeoIp object for the given IP from cache. */ 00043 GeoIp geoip(QHostAddress ip); 00044 /** Returns true if the given IP address is cached. */ 00045 bool contains(QHostAddress ip); 00046 00047 private: 00048 QHash<quint32, GeoIpCacheItem> _cache; /**< List of cached GeoIp objects. */ 00049 }; 00050 00051 #endif 00052