/usr/include/fatrat/engines/CurlDownload.h is in fatrat-dev 1.2.0~beta2-0ubuntu8.
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 | /*
FatRat download manager
http://fatrat.dolezel.info
Copyright (C) 2006-2011 Lubos Dolezel <lubos a dolezel.info>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
In addition, as a special exemption, Luboš Doležel gives permission
to link the code of FatRat with the OpenSSL project's
"OpenSSL" library (or with modified versions of it that use the; same
license as the "OpenSSL" library), and distribute the linked
executables. You must obey the GNU General Public License in all
respects for all of the code used other than "OpenSSL".
*/
#ifndef CURLDOWNLOAD_H
#define CURLDOWNLOAD_H
#include <Transfer.h>
#include <fatrat.h>
#include "engines/CurlUser.h"
#include "engines/UrlClient.h"
#include <QHash>
#include <QUuid>
#include <QDir>
#include <QUrl>
#include <QTimer>
#include "StaticTransferMessage.h"
class CurlPollingMaster;
class CurlDownload : public StaticTransferMessage<Transfer>
{
Q_OBJECT
public:
CurlDownload();
~CurlDownload();
virtual void init(QString source, QString target);
virtual void changeActive(bool bActove);
virtual void setObject(QString object);
virtual QString object() const;
virtual QString myClass() const { return "GeneralDownload"; }
virtual QString name() const;
virtual void speeds(int& down, int& up) const;
virtual qulonglong total() const;
virtual qulonglong done() const;
virtual void load(const QDomNode& map);
virtual void save(QDomDocument& doc, QDomNode& map) const;
virtual void setSpeedLimits(int down, int up);
static int acceptable(QString uri, bool);
static QDialog* createMultipleOptionsWidget(QWidget* parent, QList<Transfer*>& transfers);
static Transfer* createInstance() { return new CurlDownload; }
static void globalInit();
static void globalExit();
virtual WidgetHostChild* createOptionsWidget(QWidget* w);
virtual void fillContextMenu(QMenu& menu);
virtual QString remoteURI() const;
virtual QObject* createDetailsWidget(QWidget* w);
protected:
QString filePath() const;
private slots:
//void switchMirror();
void computeHash();
void clientRenameTo(QString name);
void clientLogMessage(QString msg);
void clientDone(QString error);
void clientTotalSizeKnown(qlonglong bytes);
void clientFailure(QString err);
void clientRangesUnsupported();
void updateSegmentProgress();
private:
void generateName();
void init2(QString uri, QString dest);
void setTargetName(QString newFileName);
void processHeaders();
void checkFileContents();
static int seek_function(int file, curl_off_t offset, int origin);
static size_t process_header(const char* ptr, size_t size, size_t nmemb, CurlDownload* This);
static int curl_debug_callback(CURL*, curl_infotype, char* text, size_t bytes, CurlDownload* This);
protected:
// Represents a written segment, i.e. what's really been written to the on-disk file
struct Segment
{
// the start
qlonglong offset;
// how many bytes have already been transfered
qlonglong bytes;
// the last url object used for this segment
int urlIndex;
// pointer to a UrlClient instance, if the segment is active
UrlClient* client;
QColor color;
bool operator<(const Segment& s2) const;
operator QString() const
{
return QString("(struct Segment): offset: %1; bytes: %2; urlIndex: %3").arg(offset).arg(bytes).arg(urlIndex);
}
};
// Represents a blank spot in the file, i.e. a candidate for a new download thread
struct FreeSegment
{
FreeSegment(qlonglong _offset, qlonglong _bytes) : offset(_offset), bytes(_bytes), affectedClient(0) {}
qlonglong offset;
qlonglong bytes;
UrlClient* affectedClient;
bool operator<(const FreeSegment& s2) const;
static bool compareByOffset(const FreeSegment& s1, const FreeSegment& s2);
};
void autoCreateSegment();
static void simplifySegments(QList<Segment>& in);
void fixActiveSegmentsList();
QColor allocateSegmentColor();
void startSegment(Segment& seg, qlonglong bytes);
void startSegment(int urlIndex);
void stopSegment(int index, bool restarting = false);
protected:
QDir m_dir;
long long m_nTotal;
mutable long long m_nStart;
QString m_strFile;
bool m_bAutoName;
char m_errorBuffer[CURL_ERROR_SIZE];
QList<UrlClient::UrlObject> m_urls;
QList<Segment> m_segments;
mutable QReadWriteLock m_segmentsLock;
CurlPollingMaster* m_master;
QTimer m_timer;
UrlClient* m_nameChanger;
QList<int> m_listActiveSegments;
friend class HttpOptsWidget;
friend class HttpUrlOptsDlg;
friend class HttpDetailsBar;
friend class HttpDetails;
friend class MetalinkDownload;
};
#endif
|