Vidalia 0.2.10
|
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 BridgeDownloader.h 00013 ** \version $Id: BridgeDownloader.h 3735 2009-04-28 20:28:01Z edmanm $ 00014 ** \brief Downloads a list of new bridge addresses via HTTPS 00015 */ 00016 00017 #ifndef _BRIDGEDOWNLOADER_H 00018 #define _BRIDGEDOWNLOADER_H 00019 00020 #include <QHttp> 00021 #include <QSslError> 00022 #include <QStringList> 00023 00024 00025 class BridgeDownloader : public QObject 00026 { 00027 Q_OBJECT 00028 00029 public: 00030 /** Available bridge download methods. */ 00031 enum BridgeDownloadMethod { 00032 DownloadMethodHttps, /** Download via an HTTPS connection. */ 00033 }; 00034 00035 /** Default constructor. 00036 */ 00037 BridgeDownloader(QObject *parent = 0); 00038 00039 /** Initiates a request for a set of bridges using the specified 00040 * download <b>method</b>. Returns true if the request was initiated 00041 * successfully, or false on error. 00042 */ 00043 bool downloadBridges(BridgeDownloadMethod method); 00044 00045 /** Enables HTTPS proxy support, using the proxy server <b>host</b> on 00046 * port <b>port</b>. A <b>username</b> and <b>password</b> can also 00047 * optionally be supplied, if required by the proxy. 00048 */ 00049 void setProxy(const QString &host, int port, 00050 const QString &username = QString(), 00051 const QString &password = QString()); 00052 00053 /** Returns true if <b>method</b> is supported by the currently 00054 * available Qt libraries. 00055 */ 00056 static bool isMethodSupported(BridgeDownloadMethod method); 00057 00058 public slots: 00059 /** Cancels any pending bridge download requests. 00060 */ 00061 void cancelBridgeRequest(); 00062 00063 signals: 00064 /** Emitted when the underlying QHttp object reads data from an HTTPS 00065 * response. <b>done</b> indicates how many bytes out of <b>total</b> 00066 * have been read so far. Note that <b>total</b> may be 0 if the expected 00067 * total size of the response is not known. 00068 */ 00069 void downloadProgress(int done, int total); 00070 00071 /** Emitted when the status of the bridge request changes. <b>status</b> 00072 * describes the new current state of the request. 00073 */ 00074 void statusChanged(const QString &status); 00075 00076 /** Emitted when the previous request for bridge addresses completes 00077 * successfully. The QStringList <b>bridges</b> contains a (possibly empty) 00078 * list of bridge addresses parsed from the received response. 00079 */ 00080 void bridgeRequestFinished(const QStringList &bridges); 00081 00082 /** Emitted when the previous request for bridge addresses fails. The 00083 * QString <b>error</b> is a human-readable string describing the error 00084 * encountered. 00085 */ 00086 void bridgeRequestFailed(const QString &error); 00087 00088 private slots: 00089 /** Called when the state of the underlying QHttp object changes. A 00090 * statusChanged() signal is emitted with the appropriate text 00091 * describing the new state of the request. 00092 */ 00093 void httpsStateChanged(int state); 00094 00095 /** Called when the underlying QHttp object used to make the bridge 00096 * request completes. <b>error</b> is set to false if the request was 00097 * successful, or true if the request failed. If <b>id</b> does not 00098 * match the request ID previously returned by QHttp::get(), then the 00099 * signal is ignored since it is the result of a close() or abort() 00100 * request. 00101 */ 00102 void httpsRequestFinished(int id, bool error); 00103 00104 /** Called when the HTTPS connection encounters one or more 00105 * <b>sslErrors</b>. Currently the errors are just logged and 00106 * bridgeRequestFailed() is <i>not</i> emitted, since QHttp will also 00107 * emit 00108 */ 00109 void sslErrors(const QList<QSslError> &sslErrors); 00110 00111 private: 00112 /** Initiates an HTTPS connection to bridges.torproject.org to start 00113 * downloading a set of bridges. 00114 */ 00115 void startHttpsDownload(); 00116 00117 /** Used to connect to the bridge database, send an HTTPS request for 00118 * new bridge addresses and then read the response. */ 00119 QHttp* _https; 00120 00121 /** Unique numeric identifier of the current bridge request. */ 00122 int _requestId; 00123 }; 00124 00125 #endif 00126