/usr/include/BALL/SYSTEM/simpleDownloader.h is in libball1.4-dev 1.4.3~beta1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | #ifndef BALL_SYSTEM_SIMPLEDOWNLOADER_H
#define BALL_SYSTEM_SIMPLEDOWNLOADER_H
#ifndef BALL_DATATYPE_STRING_H
#include <BALL/DATATYPE/string.h>
#endif
#include <QtCore/QThread>
#include <QtCore/QFile>
#include <QtNetwork/QFtp>
#include <QtNetwork/QNetworkReply>
class QByteArray;
namespace BALL
{
namespace SimpleDownloaderHelper
{
class HelperThread;
}
/**
* This class provides an interface for synchronous downloads.
* It currently relies on QNetworkAccessManager and thus on the existence of
* a QCoreApplication object. If no global instance is existing a local application
* object is created. For this reason you must not use this class in any thread but
* the main thread if you did not create a QCoreApplication object yourself.
*
* REMARK: this class is considered experimental and its interface
* can be a subject to redesign.
*/
class BALL_EXPORT SimpleDownloader
: public QObject
{
Q_OBJECT
public:
/*
* Default Constructor.
*
* @param url The URL to download.
* @param timeout The maximum number of milliseconds the download is allowed to take.
* default: infinite
*/
SimpleDownloader(const String& url, unsigned int timeout = UINT_MAX);
/*
* Default Constructor.
*
* @param url The URL to download.
* @param timeout The maximum number of milliseconds the download is allowed to take.
* default: infinite
*/
SimpleDownloader(const QUrl& url, unsigned int timeout = UINT_MAX);
/**
* If the content of the download should be kept in memory you can use this function
* that stores the received bytes in the provides vector. Any previous content is overwritten.
*
* @param buffer The buffer vector to use.
* @return Non-zero if an error occurred while downloading
*/
int downloadToBuffer(std::vector<char>& buffer);
/**
* Download the url and store the contents to a file.
*
* @param path The path to the file the content is stored in.
* @return Non-zero if an error occurred while downloading
*/
int downloadToFile(const String& path);
/**
* Upload the passed string to the specified URL and save the response
* to the specified buffer
*
* @param data the string which is uploaded
* @param response the response of the server
* @return Non-zero if an error occured while uploading
*/
int uploadStringToBuffer(const String& data, std::vector<char>& response);
/**
* Upload the passed string to the specified URL and save the response
* to the specified file
*
* @param data the string which is uploaded
* @param response the file the response is saved to
* @return Non-zero if an error occured while uploading
*/
int uploadStringToFile(const String& data, const String& response);
/**
* Upload the passed string to the specified URL and save the response
* to the specified file
*
* @param path the path of the file to upload
* @param response the response of the server
* @return Non-zero if an error occured while uploading
*/
int uploadFileToBuffer(const String& path, std::vector<char>& response);
/**
* Upload the passed string to the specified URL and save the response
* to the specified file
*
* @param path the path of the file to upload
* @param response the file the response is saved to
* @return Non-zero if an error occured while uploading
*/
int uploadFileToFile(const String& path, const String& response);
/**
* Sets the maximum amount of time a download my take. The time is specified in
* milliseconds.
*
* @param timeout The time in milliseconds.
*/
void setTimeout(unsigned int timeout);
/**
* Sets the url of the download.
*
* @param url The URL to download
*/
void setURL(const String& url);
/**
* Sets the url of the download.
*
* @param url The URL to download
*/
void setURL(const QUrl& url);
/**
* Returns the current URL.
*
* @return The currently set URL
*/
const QUrl& getURL() const;
private:
int download_(SimpleDownloaderHelper::HelperThread& thread);
int qftpDownloadHack_(QIODevice* iodev);
QUrl url_;
unsigned int timeout_;
};
namespace SimpleDownloaderHelper
{
class HelperThread : public QThread
{
public:
HelperThread(const QUrl& url, QByteArray* result, SimpleDownloader* parent);
HelperThread(const QUrl& url, const String& path, SimpleDownloader* parent);
int getStatus();
protected:
virtual QNetworkReply* getReply_(QNetworkAccessManager* man) = 0;
void run();
int err_;
QUrl url_;
QByteArray* result_;
String path_;
SimpleDownloader* parent_;
};
class DLThread : public HelperThread
{
public:
DLThread(const QUrl& url, QByteArray* result, SimpleDownloader* parent);
DLThread(const QUrl& url, const String& path, SimpleDownloader* parent);
protected:
virtual QNetworkReply* getReply_(QNetworkAccessManager* man);
};
class UPThread : public HelperThread
{
public:
UPThread(const QUrl& url, const QByteArray* data, QByteArray* result, SimpleDownloader* parent);
UPThread(const QUrl& url, const QByteArray* data, const String& path, SimpleDownloader* parent);
UPThread(const QUrl& url, QIODevice* file, QByteArray* result, SimpleDownloader* parent);
UPThread(const QUrl& url, QIODevice* file, const String& path, SimpleDownloader* parent);
protected:
virtual QNetworkReply* getReply_(QNetworkAccessManager* man);
const QByteArray* data_;
QIODevice* file_;
};
class BasicHelper : public QObject
{
Q_OBJECT
public:
BasicHelper(HelperThread* caller, QNetworkReply* reply);
virtual ~BasicHelper(){}
public slots:
void error(QNetworkReply::NetworkError error);
#ifndef QT_NO_OPENSSL
void sslErrors(const QList<QSslError>& errors);
#endif
virtual void finished() = 0;
protected:
HelperThread* caller_;
QNetworkReply* reply_;
};
class DLArrayHelper : public BasicHelper
{
Q_OBJECT
public:
DLArrayHelper(HelperThread* caller, QNetworkReply* reply, QByteArray* result);
public slots:
void finished();
private:
QByteArray* result_;
};
class DLHelper : public BasicHelper
{
Q_OBJECT
public:
DLHelper(HelperThread* caller, QNetworkReply* reply, const String& path);
public slots:
void finished();
void receivedData();
private:
QFile file_;
};
// We need this due to a bug in QNetworkAccessManager that basically
// screws up the FTP download code. This should be fixed upstream with
// the advent of Qt5
class QFtpHackHelper;
class QFtpHackThread : public QThread
{
Q_OBJECT
public:
QFtpHackThread(const QUrl& url, QIODevice* iodev, SimpleDownloader* parent);
~QFtpHackThread();
protected:
void run();
private:
QFtp* ftp_;
QFtpHackHelper* helper_;
QUrl url_;
QIODevice* iodev_;
SimpleDownloader* parent_;
};
class QFtpHackHelper : public QObject
{
Q_OBJECT
public:
QFtpHackHelper(QFtpHackThread* th);
public slots:
void done(bool error);
private:
QFtpHackThread* th_;
};
}
}
#endif //BALL_SYSTEM_SIMPLEDOWNLOADER_H
|