00001 /**************************************************************** 00002 * Vidalia is distributed under the following license: 00003 * 00004 * Copyright (C) 2006, Matt Edman, Justin Hipple 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 ****************************************************************/ 00021 00022 /** 00023 * \file geoipcache.h 00024 * \version $Id: geoipcache.h 1563 2006-12-26 06:06:04Z edmanm $ 00025 * \brief Caches the results of previous GeoIP requests 00026 */ 00027 00028 #ifndef _GEOIPCACHE_H 00029 #define _GEOIPCACHE_H 00030 00031 #include <QString> 00032 #include <QHash> 00033 #include <QHostAddress> 00034 00035 #include "geoipcacheitem.h" 00036 00037 00038 class GeoIpCache 00039 { 00040 public: 00041 /** Default constructor. */ 00042 GeoIpCache(); 00043 00044 /** Writes the current cache to disk. */ 00045 bool saveToDisk(QString *errmsg = 0); 00046 /** Reads the cache in from disk. */ 00047 bool loadFromDisk(QString *errmsg = 0); 00048 00049 /** Returns the location currently used for the cache file. */ 00050 QString cacheFilename(); 00051 /** Caches the given IP and geographic information to disk. */ 00052 void cache(GeoIp geoip); 00053 /** Returns a GeoIp object for the given IP from cache. */ 00054 GeoIp geoip(QHostAddress ip); 00055 /** Returns true if the given IP address is cached. */ 00056 bool contains(QHostAddress ip); 00057 00058 private: 00059 QHash<quint32, GeoIpCacheItem> _cache; /**< List of cached GeoIp objects. */ 00060 }; 00061 00062 #endif 00063