geoipresolver.h

Go to the documentation of this file.
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 geoipresolver.h
00024  * \version $Id: geoipresolver.h 1238 2006-09-25 17:50:57Z edmanm $
00025  * \brief Requests GeoIP information and caches the result
00026  */
00027 
00028 #ifndef _GEOIPRESOLVER_H
00029 #define _GEOIPRESOLVER_H
00030 
00031 #include <QObject>
00032 #include <QList>
00033 #include <QHash>
00034 #include <QString>
00035 #include <QHostAddress>
00036 #include <util/torsocket.h>
00037 
00038 #include "geoip.h"
00039 #include "geoipcache.h"
00040 #include "geoiprequest.h"
00041 #include "geoipresponse.h"
00042 
00043 
00044 class GeoIpResolver : public QObject
00045 {
00046   Q_OBJECT
00047 
00048 public:
00049   /** Default constructor. */
00050   GeoIpResolver() {}
00051 
00052   /** Resolves a single IP to a geographic location. */
00053   int resolve(QHostAddress ip);
00054   /** Resolves a list of IPs to a geographic location. */
00055   int resolve(QList<QHostAddress> ips);
00056   /** Resolves a list of IPs to a geographic location, but only those which
00057    * are cached. Returns a list of which IPs were not cached. */
00058   QList<QHostAddress> resolveFromCache(QList<QHostAddress> ips);
00059 
00060 signals:
00061   /** Emitted when a list of IPs have been resolved to lat/long. */
00062   void resolved(int id, QList<GeoIp> geoips);
00063   /** Emitted when a resolve has failed. */
00064   void resolveFailed(int id, QString errorString);
00065 
00066 private slots:
00067   /** Called when the socket has connected to the Geo IP host. */
00068   void connected();
00069   /** Called when the socket has disconnected from the Geo IP host. */
00070   void disconnected();
00071   /** Called when an error has occurred getting the Geo IP information. */
00072   void socketError(QString errorString);
00073 
00074 private:
00075   /** Creates an HTTP request for Geo IP information. */
00076   GeoIpRequest* createRequest(QList<QHostAddress> ips);
00077   /** Creates a socket used to request Geo IP information over Tor. */
00078   TorSocket* createRequestSocket();
00079   
00080   /**< Cached GeoIp objects. */
00081   GeoIpCache  _cache;
00082   /**< List of sockets used for requests. */
00083   QHash<TorSocket *,GeoIpRequest*> _requestList;
00084 };
00085 
00086 #endif
00087 

Generated on Mon Oct 23 20:08:15 2006 for Vidalia by  doxygen 1.5.0