Some work about adaptive color scheme for Web UI (PR #19901)
http://[316:c51a:62a3:8b9::4]/d4708/qBittorrent/src/branch/adaptive-webui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
542 lines
18 KiB
542 lines
18 KiB
17 years ago
|
/*
|
||
16 years ago
|
* Bittorrent Client using Qt4 and libtorrent.
|
||
|
* Copyright (C) 2006 Ishan Arora and Christophe Dumez
|
||
17 years ago
|
*
|
||
16 years ago
|
* This program is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU General Public License
|
||
|
* as published by the Free Software Foundation; either version 2
|
||
|
* of the License, or (at your option) any later version.
|
||
17 years ago
|
*
|
||
16 years ago
|
* 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.
|
||
17 years ago
|
*
|
||
16 years ago
|
* 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 exception, the copyright holders give permission to
|
||
|
* link this program 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". If you
|
||
|
* modify file(s), you may extend this exception to your version of the file(s),
|
||
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||
|
* exception statement from your version.
|
||
|
*
|
||
|
* Contact : chris@qbittorrent.org
|
||
17 years ago
|
*/
|
||
|
|
||
|
|
||
|
#include "httpconnection.h"
|
||
|
#include "httpserver.h"
|
||
|
#include "eventmanager.h"
|
||
15 years ago
|
#include "preferences.h"
|
||
17 years ago
|
#include "json.h"
|
||
14 years ago
|
#include "qbtsession.h"
|
||
15 years ago
|
#include "misc.h"
|
||
17 years ago
|
#include <QTcpSocket>
|
||
|
#include <QDateTime>
|
||
|
#include <QStringList>
|
||
|
#include <QHttpRequestHeader>
|
||
|
#include <QHttpResponseHeader>
|
||
|
#include <QFile>
|
||
|
#include <QDebug>
|
||
15 years ago
|
#include <QRegExp>
|
||
17 years ago
|
#include <QTemporaryFile>
|
||
17 years ago
|
|
||
15 years ago
|
HttpConnection::HttpConnection(QTcpSocket *socket, Bittorrent *BTSession, HttpServer *parent)
|
||
14 years ago
|
: QObject(parent), socket(socket), parent(parent), BTSession(BTSession)
|
||
17 years ago
|
{
|
||
15 years ago
|
socket->setParent(this);
|
||
|
connect(socket, SIGNAL(readyRead()), this, SLOT(read()));
|
||
|
connect(socket, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
||
17 years ago
|
}
|
||
|
|
||
|
HttpConnection::~HttpConnection()
|
||
|
{
|
||
16 years ago
|
delete socket;
|
||
17 years ago
|
}
|
||
|
|
||
16 years ago
|
void HttpConnection::processDownloadedFile(QString url, QString file_path) {
|
||
16 years ago
|
qDebug("URL %s successfully downloaded !", (const char*)url.toLocal8Bit());
|
||
15 years ago
|
emit torrentReadyToBeDownloaded(file_path, false, url, false);
|
||
16 years ago
|
}
|
||
|
|
||
|
void HttpConnection::handleDownloadFailure(QString url, QString reason) {
|
||
16 years ago
|
std::cerr << "Could not download " << (const char*)url.toLocal8Bit() << ", reason: " << (const char*)reason.toLocal8Bit() << "\n";
|
||
16 years ago
|
}
|
||
|
|
||
17 years ago
|
void HttpConnection::read()
|
||
|
{
|
||
15 years ago
|
QByteArray input = socket->readAll();
|
||
|
/*qDebug(" -------");
|
||
|
qDebug("|REQUEST|");
|
||
|
qDebug(" -------"); */
|
||
|
//qDebug("%s", input.toAscii().constData());
|
||
|
if(input.size() > 100000) {
|
||
|
qDebug("Request too big");
|
||
|
generator.setStatusLine(400, "Bad Request");
|
||
|
write();
|
||
|
return;
|
||
|
}
|
||
|
parser.write(input);
|
||
|
if(parser.isError())
|
||
|
{
|
||
|
generator.setStatusLine(400, "Bad Request");
|
||
|
write();
|
||
|
}
|
||
|
else
|
||
|
if (parser.isParsable())
|
||
|
respond();
|
||
17 years ago
|
}
|
||
|
|
||
|
void HttpConnection::write()
|
||
|
{
|
||
15 years ago
|
QByteArray output = generator.toByteArray();
|
||
|
/*qDebug(" --------");
|
||
|
qDebug("|RESPONSE|");
|
||
|
qDebug(" --------");
|
||
|
qDebug()<<output;*/
|
||
|
socket->write(output);
|
||
|
socket->disconnectFromHost();
|
||
17 years ago
|
}
|
||
|
|
||
15 years ago
|
QString HttpConnection::translateDocument(QString data) {
|
||
15 years ago
|
std::string contexts[] = {"TransferListFiltersWidget", "TransferListWidget", "PropertiesWidget", "GUI", "MainWindow", "HttpServer", "confirmDeletionDlg", "TrackerList", "TorrentFilesModel", "options_imp", "Preferences", "TrackersAdditionDlg", "ScanFoldersModel"};
|
||
15 years ago
|
int i=0;
|
||
|
bool found = false;
|
||
|
do {
|
||
|
found = false;
|
||
14 years ago
|
QRegExp regex(QString::fromUtf8("_\\(([\\w\\s?!:\\/\\(\\),%µ&\\-\\.]+)\\)"));
|
||
15 years ago
|
i = regex.indexIn(data, i);
|
||
|
if(i >= 0) {
|
||
15 years ago
|
//qDebug("Found translatable string: %s", regex.cap(1).toUtf8().data());
|
||
15 years ago
|
QString word = regex.cap(1);
|
||
|
QString translation = word;
|
||
|
int context_index= 0;
|
||
|
do {
|
||
15 years ago
|
translation = qApp->translate(contexts[context_index].c_str(), word.toLocal8Bit().constData(), 0, QCoreApplication::UnicodeUTF8, 1);
|
||
15 years ago
|
++context_index;
|
||
15 years ago
|
}while(translation == word && context_index < 13);
|
||
15 years ago
|
// Remove keyboard shortcuts
|
||
|
translation = translation.replace("&", "");
|
||
15 years ago
|
//qDebug("Translation is %s", translation.toUtf8().data());
|
||
15 years ago
|
data = data.replace(i, regex.matchedLength(), translation);
|
||
|
i += translation.length();
|
||
|
found = true;
|
||
|
}
|
||
|
}while(found && i < data.size());
|
||
|
return data;
|
||
|
}
|
||
|
|
||
15 years ago
|
void HttpConnection::respond() {
|
||
15 years ago
|
//qDebug("Respond called");
|
||
15 years ago
|
const QString peer_ip = socket->peerAddress().toString();
|
||
15 years ago
|
const int nb_fail = parent->NbFailedAttemptsForIp(peer_ip);
|
||
|
if(nb_fail >= MAX_AUTH_FAILED_ATTEMPTS) {
|
||
15 years ago
|
generator.setStatusLine(403, "Forbidden");
|
||
|
generator.setMessage(tr("Your IP address has been banned after too many failed authentication attempts."));
|
||
|
write();
|
||
|
return;
|
||
|
}
|
||
15 years ago
|
QString auth = parser.value("Authorization");
|
||
15 years ago
|
if(auth.isEmpty()) {
|
||
|
// Return unauthorized header
|
||
|
qDebug("Auth is Empty...");
|
||
|
generator.setStatusLine(401, "Unauthorized");
|
||
|
generator.setValue("WWW-Authenticate", "Digest realm=\""+QString(QBT_REALM)+"\", nonce=\""+parent->generateNonce()+"\", opaque=\""+parent->generateNonce()+"\", stale=\"false\", algorithm=\"MD5\", qop=\"auth\"");
|
||
|
write();
|
||
|
return;
|
||
|
}
|
||
15 years ago
|
//qDebug("Auth: %s", qPrintable(auth.split(" ").first()));
|
||
15 years ago
|
if (QString::compare(auth.split(" ").first(), "Digest", Qt::CaseInsensitive) != 0 || !parent->isAuthorized(auth.toLocal8Bit(), parser.method())) {
|
||
15 years ago
|
// Update failed attempt counter
|
||
15 years ago
|
parent->increaseNbFailedAttemptsForIp(peer_ip);
|
||
|
qDebug("client IP: %s (%d failed attempts)", qPrintable(peer_ip), nb_fail+1);
|
||
15 years ago
|
// Return unauthorized header
|
||
15 years ago
|
generator.setStatusLine(401, "Unauthorized");
|
||
15 years ago
|
generator.setValue("WWW-Authenticate", "Digest realm=\""+QString(QBT_REALM)+"\", nonce=\""+parent->generateNonce()+"\", opaque=\""+parent->generateNonce()+"\", stale=\"false\", algorithm=\"MD5\", qop=\"auth\"");
|
||
15 years ago
|
write();
|
||
|
return;
|
||
|
}
|
||
14 years ago
|
// Client successfully authenticated, reset number of failed attempts
|
||
15 years ago
|
parent->resetNbFailedAttemptsForIp(peer_ip);
|
||
15 years ago
|
QString url = parser.url();
|
||
15 years ago
|
// Favicon
|
||
|
if(url.endsWith("favicon.ico")) {
|
||
|
qDebug("Returning favicon");
|
||
|
QFile favicon(":/Icons/skin/qbittorrent16.png");
|
||
|
if(favicon.open(QIODevice::ReadOnly)) {
|
||
|
QByteArray data = favicon.readAll();
|
||
|
generator.setStatusLine(200, "OK");
|
||
|
generator.setContentTypeByExt("png");
|
||
|
generator.setMessage(data);
|
||
|
write();
|
||
|
} else {
|
||
|
respondNotFound();
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
15 years ago
|
QStringList list = url.split('/', QString::SkipEmptyParts);
|
||
|
if (list.contains(".") || list.contains(".."))
|
||
|
{
|
||
|
respondNotFound();
|
||
|
return;
|
||
|
}
|
||
|
if (list.size() == 0)
|
||
|
list.append("index.html");
|
||
15 years ago
|
if (list.size() >= 2)
|
||
15 years ago
|
{
|
||
|
if (list[0] == "json")
|
||
|
{
|
||
|
if (list[1] == "events")
|
||
|
{
|
||
|
respondJson();
|
||
|
return;
|
||
|
}
|
||
15 years ago
|
if(list.size() > 2) {
|
||
|
if(list[1] == "propertiesGeneral") {
|
||
|
QString hash = list[2];
|
||
|
respondGenPropertiesJson(hash);
|
||
|
return;
|
||
|
}
|
||
15 years ago
|
if(list[1] == "propertiesTrackers") {
|
||
|
QString hash = list[2];
|
||
|
respondTrackersPropertiesJson(hash);
|
||
|
return;
|
||
|
}
|
||
15 years ago
|
if(list[1] == "propertiesFiles") {
|
||
|
QString hash = list[2];
|
||
|
respondFilesPropertiesJson(hash);
|
||
|
return;
|
||
|
}
|
||
15 years ago
|
} else {
|
||
|
if(list[1] == "preferences") {
|
||
|
respondPreferencesJson();
|
||
15 years ago
|
} else {
|
||
|
if(list[1] == "transferInfo") {
|
||
|
respondGlobalTransferInfoJson();
|
||
|
}
|
||
15 years ago
|
}
|
||
15 years ago
|
}
|
||
15 years ago
|
}
|
||
|
if (list[0] == "command")
|
||
|
{
|
||
|
QString command = list[1];
|
||
|
respondCommand(command);
|
||
|
generator.setStatusLine(200, "OK");
|
||
|
write();
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
14 years ago
|
if (list[0] == "images") {
|
||
15 years ago
|
list[0] = "Icons";
|
||
14 years ago
|
} else {
|
||
|
if(list.last().endsWith(".html"))
|
||
|
list.prepend("html");
|
||
15 years ago
|
list.prepend("webui");
|
||
14 years ago
|
}
|
||
15 years ago
|
url = ":/" + list.join("/");
|
||
|
QFile file(url);
|
||
|
if(!file.open(QIODevice::ReadOnly))
|
||
|
{
|
||
15 years ago
|
qDebug("File %s was not found!", qPrintable(url));
|
||
15 years ago
|
respondNotFound();
|
||
|
return;
|
||
|
}
|
||
|
QString ext = list.last();
|
||
|
int index = ext.lastIndexOf('.') + 1;
|
||
|
if (index > 0)
|
||
|
ext.remove(0, index);
|
||
|
else
|
||
|
ext.clear();
|
||
|
QByteArray data = file.readAll();
|
||
15 years ago
|
// Translate the page
|
||
15 years ago
|
if(ext == "html" || (ext == "js" && !list.last().startsWith("excanvas"))) {
|
||
15 years ago
|
data = translateDocument(QString::fromUtf8(data.data())).toUtf8();
|
||
|
}
|
||
15 years ago
|
generator.setStatusLine(200, "OK");
|
||
|
generator.setContentTypeByExt(ext);
|
||
|
generator.setMessage(data);
|
||
|
write();
|
||
17 years ago
|
}
|
||
|
|
||
|
void HttpConnection::respondNotFound()
|
||
|
{
|
||
15 years ago
|
generator.setStatusLine(404, "File not found");
|
||
|
write();
|
||
17 years ago
|
}
|
||
|
|
||
|
void HttpConnection::respondJson()
|
||
|
{
|
||
15 years ago
|
EventManager* manager = parent->eventManager();
|
||
|
QString string = json::toJson(manager->getEventList());
|
||
|
generator.setStatusLine(200, "OK");
|
||
|
generator.setContentTypeByExt("js");
|
||
|
generator.setMessage(string);
|
||
|
write();
|
||
17 years ago
|
}
|
||
|
|
||
15 years ago
|
void HttpConnection::respondGenPropertiesJson(QString hash) {
|
||
|
EventManager* manager = parent->eventManager();
|
||
|
QString string = json::toJson(manager->getPropGeneralInfo(hash));
|
||
|
generator.setStatusLine(200, "OK");
|
||
|
generator.setContentTypeByExt("js");
|
||
|
generator.setMessage(string);
|
||
|
write();
|
||
|
}
|
||
|
|
||
15 years ago
|
void HttpConnection::respondTrackersPropertiesJson(QString hash) {
|
||
|
EventManager* manager = parent->eventManager();
|
||
|
QString string = json::toJson(manager->getPropTrackersInfo(hash));
|
||
|
generator.setStatusLine(200, "OK");
|
||
|
generator.setContentTypeByExt("js");
|
||
|
generator.setMessage(string);
|
||
|
write();
|
||
|
}
|
||
|
|
||
15 years ago
|
void HttpConnection::respondFilesPropertiesJson(QString hash) {
|
||
|
EventManager* manager = parent->eventManager();
|
||
|
QString string = json::toJson(manager->getPropFilesInfo(hash));
|
||
|
generator.setStatusLine(200, "OK");
|
||
|
generator.setContentTypeByExt("js");
|
||
|
generator.setMessage(string);
|
||
|
write();
|
||
|
}
|
||
|
|
||
15 years ago
|
void HttpConnection::respondPreferencesJson() {
|
||
|
EventManager* manager = parent->eventManager();
|
||
|
QString string = json::toJson(manager->getGlobalPreferences());
|
||
|
generator.setStatusLine(200, "OK");
|
||
|
generator.setContentTypeByExt("js");
|
||
|
generator.setMessage(string);
|
||
|
write();
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
void HttpConnection::respondGlobalTransferInfoJson() {
|
||
|
QVariantMap info;
|
||
15 years ago
|
session_status sessionStatus = BTSession->getSessionStatus();
|
||
15 years ago
|
info["DlInfos"] = tr("D: %1/s - T: %2", "Download speed: x KiB/s - Transferred: x MiB").arg(misc::friendlyUnit(sessionStatus.payload_download_rate)).arg(misc::friendlyUnit(sessionStatus.total_payload_download));
|
||
|
info["UpInfos"] = tr("U: %1/s - T: %2", "Upload speed: x KiB/s - Transferred: x MiB").arg(misc::friendlyUnit(sessionStatus.payload_upload_rate)).arg(misc::friendlyUnit(sessionStatus.total_payload_upload));
|
||
|
QString string = json::toJson(info);
|
||
|
generator.setStatusLine(200, "OK");
|
||
|
generator.setContentTypeByExt("js");
|
||
|
generator.setMessage(string);
|
||
|
write();
|
||
|
}
|
||
|
|
||
17 years ago
|
void HttpConnection::respondCommand(QString command)
|
||
|
{
|
||
15 years ago
|
if(command == "download")
|
||
|
{
|
||
|
QString urls = parser.post("urls");
|
||
|
QStringList list = urls.split('\n');
|
||
|
foreach(QString url, list){
|
||
|
url = url.trimmed();
|
||
|
if(!url.isEmpty()){
|
||
15 years ago
|
if(url.startsWith("bc://bt/", Qt::CaseInsensitive)) {
|
||
|
qDebug("Converting bc link to magnet link");
|
||
|
url = misc::bcLinkToMagnet(url);
|
||
|
}
|
||
15 years ago
|
if(url.startsWith("magnet:", Qt::CaseInsensitive)) {
|
||
|
emit MagnetReadyToBeDownloaded(url);
|
||
|
} else {
|
||
|
qDebug("Downloading url: %s", (const char*)url.toLocal8Bit());
|
||
|
emit UrlReadyToBeDownloaded(url);
|
||
16 years ago
|
}
|
||
15 years ago
|
}
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
15 years ago
|
if(command == "addTrackers") {
|
||
|
QString hash = parser.post("hash");
|
||
|
if(!hash.isEmpty()) {
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
|
if(h.is_valid() && h.has_metadata()) {
|
||
|
QString urls = parser.post("urls");
|
||
|
QStringList list = urls.split('\n');
|
||
|
foreach(QString url, list) {
|
||
|
announce_entry e(url.toStdString());
|
||
|
h.add_tracker(e);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
15 years ago
|
if(command == "upload")
|
||
|
{
|
||
|
QByteArray torrentfile = parser.torrent();
|
||
15 years ago
|
// Get a unique filename
|
||
15 years ago
|
QString filePath;
|
||
15 years ago
|
QTemporaryFile tmpfile;
|
||
|
tmpfile.setAutoRemove(false);
|
||
|
if (tmpfile.open()) {
|
||
|
filePath = tmpfile.fileName();
|
||
|
} else {
|
||
|
std::cerr << "I/O Error: Could not create temporary file" << std::endl;
|
||
|
return;
|
||
15 years ago
|
}
|
||
15 years ago
|
tmpfile.close();
|
||
|
// Now temporary file is created but closed so that it can be used.
|
||
|
// write torrent to temporary file
|
||
15 years ago
|
QFile torrent(filePath);
|
||
|
if(torrent.open(QIODevice::WriteOnly)) {
|
||
|
torrent.write(torrentfile);
|
||
|
torrent.close();
|
||
|
}
|
||
|
emit torrentReadyToBeDownloaded(filePath, false, QString(), false);
|
||
15 years ago
|
// Prepare response
|
||
|
generator.setStatusLine(200, "OK");
|
||
|
generator.setContentTypeByExt("html");
|
||
|
generator.setMessage(QString("<script type=\"text/javascript\">window.parent.hideAll();</script>"));
|
||
|
write();
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
if(command == "resumeall") {
|
||
|
emit resumeAllTorrents();
|
||
|
return;
|
||
|
}
|
||
|
if(command == "pauseall") {
|
||
|
emit pauseAllTorrents();
|
||
|
return;
|
||
|
}
|
||
15 years ago
|
if(command == "resume") {
|
||
15 years ago
|
emit resumeTorrent(parser.post("hash"));
|
||
|
return;
|
||
|
}
|
||
15 years ago
|
if(command == "setPreferences") {
|
||
15 years ago
|
QString json_str = parser.post("json");
|
||
|
EventManager* manager = parent->eventManager();
|
||
|
manager->setGlobalPreferences(json::fromJson(json_str));
|
||
15 years ago
|
}
|
||
15 years ago
|
if(command == "setFilePrio") {
|
||
|
QString hash = parser.post("hash");
|
||
|
int file_id = parser.post("id").toInt();
|
||
|
int priority = parser.post("priority").toInt();
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
15 years ago
|
if(h.is_valid() && h.has_metadata()) {
|
||
15 years ago
|
h.file_priority(file_id, priority);
|
||
|
}
|
||
|
}
|
||
15 years ago
|
if(command == "getGlobalUpLimit") {
|
||
|
generator.setStatusLine(200, "OK");
|
||
|
generator.setContentTypeByExt("html");
|
||
|
generator.setMessage(QString::number(BTSession->getSession()->upload_rate_limit()));
|
||
|
write();
|
||
|
}
|
||
|
if(command == "getGlobalDlLimit") {
|
||
|
generator.setStatusLine(200, "OK");
|
||
|
generator.setContentTypeByExt("html");
|
||
|
generator.setMessage(QString::number(BTSession->getSession()->download_rate_limit()));
|
||
|
write();
|
||
|
}
|
||
15 years ago
|
if(command == "getTorrentUpLimit") {
|
||
|
QString hash = parser.post("hash");
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
|
if(h.is_valid()) {
|
||
|
generator.setStatusLine(200, "OK");
|
||
|
generator.setContentTypeByExt("html");
|
||
|
generator.setMessage(QString::number(h.upload_limit()));
|
||
|
write();
|
||
|
}
|
||
|
}
|
||
|
if(command == "getTorrentDlLimit") {
|
||
|
QString hash = parser.post("hash");
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
|
if(h.is_valid()) {
|
||
|
generator.setStatusLine(200, "OK");
|
||
|
generator.setContentTypeByExt("html");
|
||
|
generator.setMessage(QString::number(h.download_limit()));
|
||
|
write();
|
||
|
}
|
||
|
}
|
||
|
if(command == "setTorrentUpLimit") {
|
||
|
QString hash = parser.post("hash");
|
||
|
qlonglong limit = parser.post("limit").toLongLong();
|
||
|
if(limit == 0) limit = -1;
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
|
if(h.is_valid()) {
|
||
|
h.set_upload_limit(limit);
|
||
|
}
|
||
|
}
|
||
|
if(command == "setTorrentDlLimit") {
|
||
|
QString hash = parser.post("hash");
|
||
|
qlonglong limit = parser.post("limit").toLongLong();
|
||
|
if(limit == 0) limit = -1;
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
|
if(h.is_valid()) {
|
||
|
h.set_download_limit(limit);
|
||
|
}
|
||
|
}
|
||
15 years ago
|
if(command == "setGlobalUpLimit") {
|
||
|
qlonglong limit = parser.post("limit").toLongLong();
|
||
|
if(limit == 0) limit = -1;
|
||
|
BTSession->getSession()->set_upload_rate_limit(limit);
|
||
|
Preferences::setGlobalUploadLimit(limit/1024.);
|
||
|
}
|
||
|
if(command == "setGlobalDlLimit") {
|
||
|
qlonglong limit = parser.post("limit").toLongLong();
|
||
|
if(limit == 0) limit = -1;
|
||
|
BTSession->getSession()->set_download_rate_limit(limit);
|
||
|
Preferences::setGlobalDownloadLimit(limit/1024.);
|
||
|
}
|
||
15 years ago
|
if(command == "pause") {
|
||
|
emit pauseTorrent(parser.post("hash"));
|
||
|
return;
|
||
|
}
|
||
|
if(command == "delete") {
|
||
|
emit deleteTorrent(parser.post("hash"), false);
|
||
|
return;
|
||
|
}
|
||
|
if(command == "deletePerm") {
|
||
|
emit deleteTorrent(parser.post("hash"), true);
|
||
|
return;
|
||
|
}
|
||
|
if(command == "increasePrio") {
|
||
15 years ago
|
QTorrentHandle h = BTSession->getTorrentHandle(parser.post("hash"));
|
||
|
if(h.is_valid()) h.queue_position_up();
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
if(command == "decreasePrio") {
|
||
15 years ago
|
QTorrentHandle h = BTSession->getTorrentHandle(parser.post("hash"));
|
||
|
if(h.is_valid()) h.queue_position_down();
|
||
15 years ago
|
return;
|
||
|
}
|
||
14 years ago
|
if(command == "topPrio") {
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(parser.post("hash"));
|
||
|
if(h.is_valid()) h.queue_position_top();
|
||
|
return;
|
||
|
}
|
||
|
if(command == "bottomPrio") {
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(parser.post("hash"));
|
||
|
if(h.is_valid()) h.queue_position_bottom();
|
||
|
return;
|
||
|
}
|
||
15 years ago
|
if(command == "recheck"){
|
||
|
recheckTorrent(parser.post("hash"));
|
||
|
return;
|
||
|
}
|
||
|
if(command == "recheckall"){
|
||
|
recheckAllTorrents();
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void HttpConnection::recheckTorrent(QString hash) {
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
15 years ago
|
if(h.is_valid()){
|
||
|
BTSession->recheckTorrent(h.hash());
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void HttpConnection::recheckAllTorrents() {
|
||
|
std::vector<torrent_handle> torrents = BTSession->getTorrents();
|
||
|
std::vector<torrent_handle>::iterator torrentIT;
|
||
|
for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
|
||
|
QTorrentHandle h = QTorrentHandle(*torrentIT);
|
||
15 years ago
|
if(h.is_valid())
|
||
|
BTSession->recheckTorrent(h.hash());
|
||
15 years ago
|
}
|
||
17 years ago
|
}
|