GeoIpResolver.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 G** \file GeoIpResolver.h
00013 ** \version $Id: GeoIpResolver.h 3768 2009-05-13 19:07:26Z edmanm $
00014 ** \brief Requests GeoIP information and caches the result
00015 */
00016 
00017 #ifndef _GEOIPRESOLVER_H
00018 #define _GEOIPRESOLVER_H
00019 
00020 #include "GeoIpCache.h"
00021 
00022 #include <QObject>
00023 #include <QList>
00024 #include <QHash>
00025 #include <QHostAddress>
00026 
00027 class GeoIp;
00028 class GeoIpRequest;
00029 class GeoIpResponse;
00030 class QString;
00031 class QAbstractSocket;
00032 
00033 
00034 class GeoIpResolver : public QObject
00035 {
00036   Q_OBJECT
00037 
00038 public:
00039   /** Default constructor. */
00040   GeoIpResolver(QObject *parent = 0);
00041   
00042   /** Sets the address and port of Tor, through which GeoIP requests will be
00043    * made. */
00044   void setSocksHost(const QHostAddress &addr, quint16 port);
00045   /** Resolves a single IP to a geographic location. */
00046   int resolve(const QHostAddress &ip);
00047   /** Resolves a list of IPs to a geographic location. */
00048   int resolve(const QList<QHostAddress> &ips);
00049   /** Resolves <b>ip</b> to geographic information only if it is cached. */
00050   bool resolveFromCache(const QHostAddress &ip);
00051   /** Resolves a list of IPs to a geographic location, but only those which
00052    * are cached. Returns a list of which IPs were not cached. */
00053   QList<QHostAddress> resolveFromCache(const QList<QHostAddress> &ips);
00054 
00055 signals:
00056   /** Emitted when a list of IPs have been resolved to lat/long. */
00057   void resolved(int id, const QList<GeoIp> &geoips);
00058   /** Emitted when a resolve has failed. */
00059   void resolveFailed(int id, const QString &errorString);
00060 
00061 private slots:
00062   /** Called when the socket has connected to the Geo IP host. */
00063   void connected();
00064   /** Called when the socket has disconnected from the Geo IP host. */
00065   void disconnected();
00066   /** Called when an error has occurred getting the Geo IP information. */
00067   void socketError(const QString &errorString);
00068 
00069 private:
00070   /** Creates an HTTP request for Geo IP information. */
00071   GeoIpRequest* createRequest(const QList<QHostAddress> &ips);
00072 
00073   void parseGeoIpResponse(const QByteArray &response, GeoIpRequest *request);
00074 
00075   /**< Cached GeoIp objects. */
00076   GeoIpCache*  _cache;
00077   /**< List of sockets used for requests. */
00078   QHash<QAbstractSocket *,GeoIpRequest*> _requestList;
00079   /** Tor's SocksListenAddress. */
00080   QHostAddress _socksAddr;
00081   /** Tor's SocksPort. */
00082   quint16 _socksPort;
00083 };
00084 
00085 #endif
00086 
Generated on Mon Aug 30 23:09:49 2010 for Vidalia by  doxygen 1.6.3