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

Generated on Wed Nov 26 21:03:58 2008 for Vidalia by  doxygen 1.5.6