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 CrashReportUploader.h 00013 ** \version $Id$ 00014 ** \brief Uploads a minidump file and any extra information to a crash 00015 ** reporting server. 00016 */ 00017 00018 #ifndef _CRASHREPORTUPLOADER_H 00019 #define _CRASHREPORTUPLOADER_H 00020 00021 #include <QObject> 00022 #include <QHttp> 00023 #include <QMap> 00024 00025 class QUrl; 00026 class QString; 00027 class QByteArray; 00028 00029 00030 class CrashReportUploader : public QObject 00031 { 00032 Q_OBJECT 00033 00034 public: 00035 /** Default constructor. 00036 */ 00037 CrashReportUploader(QObject *parent = 0); 00038 00039 /** Starts uploading <b>minidump</b> to <b>serverUrl</b> and returns 00040 * immediately. <b>minidumpId</b> is the minidump GUID generated by 00041 * the exception handler and used for the minidump's filename. The 00042 * optional <b>parameters</b> can be used to pass additional form fields 00043 * to the crash reporting server. 00044 */ 00045 void uploadMinidump(const QUrl &serverUrl, 00046 const QString &minidumpId, 00047 const QByteArray &minidump, 00048 const QMap<QString,QString> ¶meters); 00049 00050 public slots: 00051 /** Cancels a pending minidump upload. 00052 */ 00053 void cancel(); 00054 00055 signals: 00056 /** Emitted when the underlying QHttp object posts data to the server. 00057 * <b>done</b> indicates how many bytes out of <b>total</b> 00058 * have been sent so far. 00059 */ 00060 void uploadProgress(int done, int total); 00061 00062 /** Emitted when the status of the POST request changes. <b>status</b> 00063 * describes the new current state of the request. 00064 */ 00065 void statusChanged(const QString &status); 00066 00067 /** Emitted when the previous minidump upload completes successfully. 00068 */ 00069 void uploadFinished(); 00070 00071 /** Emitted when the previous crash report upload fails. The QString 00072 * <b>error</b> is a human-readable string describing the error 00073 * encountered. 00074 */ 00075 void uploadFailed(const QString &error); 00076 00077 private slots: 00078 /** Called when the state of the underlying QHttp object changes. A 00079 * statusChanged() signal is emitted with the appropriate text 00080 * describing the new state of the POST request. 00081 */ 00082 void httpStateChanged(int state); 00083 00084 /** Called when the underlying QHttp object used to upload the minidump 00085 * completes. <b>error</b> is set to false if the upload was 00086 * successful, or true if the upload failed. If <b>id</b> does not 00087 * match the request ID previously returned by QHttp::get(), then the 00088 * signal is ignored since it is the result of a close() or abort() 00089 * request. 00090 */ 00091 void httpRequestFinished(int id, bool error); 00092 00093 private: 00094 /** Generates a "random" 8-byte multipart boundary marker encoded into 00095 * 16 hex characters. 00096 */ 00097 QString generateBoundaryMarker() const; 00098 00099 /** Unique numeric identifier of the current minidump upload POST request. 00100 */ 00101 int _requestId; 00102 00103 /** Object used to POST a minidump to the crash server and read the 00104 * response. 00105 */ 00106 QHttp *_http; 00107 }; 00108 00109 #endif 00110