Browse Source

Change indentation to 4 spaces. Issue #2192.

adaptive-webui-19844
Gabriele 10 years ago
parent
commit
1154ea3873
  1. 126
      src/webui/requesthandler.cpp

126
src/webui/requesthandler.cpp

@ -109,8 +109,8 @@ QMap<QString, QMap<QString, RequestHandler::Action> > RequestHandler::initialize @@ -109,8 +109,8 @@ QMap<QString, QMap<QString, RequestHandler::Action> > RequestHandler::initialize
void RequestHandler::action_public_index()
{
QString path;
if (!args_.isEmpty())
{
if (!args_.isEmpty()) {
if (args_.back() == "favicon.ico")
path = ":/Icons/skin/qbittorrent16.png";
else
@ -139,13 +139,11 @@ void RequestHandler::action_public_login() @@ -139,13 +139,11 @@ void RequestHandler::action_public_login()
bool equalUser = misc::slowEquals(request().posts["username"].toUtf8(), pref->getWebUiUsername().toUtf8());
bool equalPass = misc::slowEquals(pass.toUtf8(), pref->getWebUiPassword().toUtf8());
if (equalUser && equalPass)
{
if (equalUser && equalPass) {
sessionStart();
print(QByteArray("Ok."), CONTENT_TYPE_TXT);
}
else
{
else {
QString addr = env().clientAddress.toString();
increaseFailedAttempts();
qDebug("client IP: %s (%d failed attempts)", qPrintable(addr), failedAttempts());
@ -160,8 +158,7 @@ void RequestHandler::action_public_logout() @@ -160,8 +158,7 @@ void RequestHandler::action_public_logout()
void RequestHandler::action_public_theme()
{
if (args_.size() != 1)
{
if (args_.size() != 1) {
status(404, "Not Found");
return;
}
@ -227,22 +224,17 @@ void RequestHandler::action_command_download() @@ -227,22 +224,17 @@ void RequestHandler::action_command_download()
QString urls = request().posts["urls"];
QStringList list = urls.split('\n');
foreach (QString url, list)
{
foreach (QString url, list) {
url = url.trimmed();
if (!url.isEmpty())
{
if (url.startsWith("bc://bt/", Qt::CaseInsensitive))
{
if (!url.isEmpty()) {
if (url.startsWith("bc://bt/", Qt::CaseInsensitive)) {
qDebug("Converting bc link to magnet link");
url = misc::bcLinkToMagnet(url);
}
else if (url.startsWith("magnet:", Qt::CaseInsensitive))
{
else if (url.startsWith("magnet:", Qt::CaseInsensitive)) {
QBtSession::instance()->addMagnetSkipAddDlg(url);
}
else
{
else {
qDebug("Downloading url: %s", qPrintable(url));
QBtSession::instance()->downloadUrlAndSkipDialog(url);
}
@ -254,12 +246,10 @@ void RequestHandler::action_command_upload() @@ -254,12 +246,10 @@ void RequestHandler::action_command_upload()
{
qDebug() << Q_FUNC_INFO;
foreach(const UploadedFile& torrent, request().files)
{
foreach(const UploadedFile& torrent, request().files) {
QString filePath = saveTmpFile(torrent.data);
if (!filePath.isEmpty())
{
if (!filePath.isEmpty()) {
QTorrentHandle h = QBtSession::instance()->addTorrent(filePath);
if (!h.is_valid()) {
status(415, "Internal Server Error");
@ -268,8 +258,7 @@ void RequestHandler::action_command_upload() @@ -268,8 +258,7 @@ void RequestHandler::action_command_upload()
// Clean up
fsutils::forceRemove(filePath);
}
else
{
else {
qWarning() << "I/O Error: Could not create temporary file";
status(500, "Internal Server Error");
print(QObject::tr("I/O Error: Could not create temporary file."), CONTENT_TYPE_TXT);
@ -281,17 +270,14 @@ void RequestHandler::action_command_addTrackers() @@ -281,17 +270,14 @@ void RequestHandler::action_command_addTrackers()
{
QString hash = request().posts["hash"];
if (!hash.isEmpty())
{
if (!hash.isEmpty()) {
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (h.is_valid() && h.has_metadata())
{
if (h.is_valid() && h.has_metadata()) {
QString urls = request().posts["urls"];
QStringList list = urls.split('\n');
foreach (const QString& url, list)
{
foreach (const QString& url, list) {
announce_entry e(url.toStdString());
h.add_tracker(e);
}
@ -332,9 +318,7 @@ void RequestHandler::action_command_setFilePrio() @@ -332,9 +318,7 @@ void RequestHandler::action_command_setFilePrio()
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (h.is_valid() && h.has_metadata())
{
h.file_priority(file_id, priority);
}
}
void RequestHandler::action_command_getGlobalUpLimit()
@ -353,7 +337,7 @@ void RequestHandler::action_command_setGlobalUpLimit() @@ -353,7 +337,7 @@ void RequestHandler::action_command_setGlobalUpLimit()
if (limit == 0) limit = -1;
QBtSession::instance()->setUploadRateLimit(limit);
Preferences::instance()->setGlobalUploadLimit(limit/1024.);
Preferences::instance()->setGlobalUploadLimit(limit / 1024.);
}
void RequestHandler::action_command_setGlobalDlLimit()
@ -362,7 +346,7 @@ void RequestHandler::action_command_setGlobalDlLimit() @@ -362,7 +346,7 @@ void RequestHandler::action_command_setGlobalDlLimit()
if (limit == 0) limit = -1;
QBtSession::instance()->setDownloadRateLimit(limit);
Preferences::instance()->setGlobalDownloadLimit(limit/1024.);
Preferences::instance()->setGlobalDownloadLimit(limit / 1024.);
}
void RequestHandler::action_command_getTorrentUpLimit()
@ -371,9 +355,7 @@ void RequestHandler::action_command_getTorrentUpLimit() @@ -371,9 +355,7 @@ void RequestHandler::action_command_getTorrentUpLimit()
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (h.is_valid())
{
print(QByteArray::number(h.upload_limit()));
}
}
void RequestHandler::action_command_getTorrentDlLimit()
@ -382,9 +364,7 @@ void RequestHandler::action_command_getTorrentDlLimit() @@ -382,9 +364,7 @@ void RequestHandler::action_command_getTorrentDlLimit()
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (h.is_valid())
{
print(QByteArray::number(h.download_limit()));
}
}
void RequestHandler::action_command_setTorrentUpLimit()
@ -395,9 +375,7 @@ void RequestHandler::action_command_setTorrentUpLimit() @@ -395,9 +375,7 @@ void RequestHandler::action_command_setTorrentUpLimit()
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (h.is_valid())
{
h.set_upload_limit(limit);
}
}
void RequestHandler::action_command_setTorrentDlLimit()
@ -408,59 +386,46 @@ void RequestHandler::action_command_setTorrentDlLimit() @@ -408,59 +386,46 @@ void RequestHandler::action_command_setTorrentDlLimit()
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (h.is_valid())
{
h.set_download_limit(limit);
}
}
void RequestHandler::action_command_delete()
{
QStringList hashes = request().posts["hashes"].split("|");
foreach (const QString &hash, hashes)
{
QBtSession::instance()->deleteTorrent(hash, false);
}
}
void RequestHandler::action_command_deletePerm()
{
QStringList hashes = request().posts["hashes"].split("|");
foreach (const QString &hash, hashes)
{
QBtSession::instance()->deleteTorrent(hash, true);
}
}
void RequestHandler::action_command_increasePrio()
{
QStringList hashes = request().posts["hashes"].split("|");
std::priority_queue<QPair<int, QTorrentHandle>,
std::vector<QPair<int, QTorrentHandle> >,
std::greater<QPair<int, QTorrentHandle> > > torrent_queue;
// Sort torrents by priority
foreach (const QString &hash, hashes)
{
try
{
foreach (const QString &hash, hashes) {
try {
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (!h.is_seed())
{
torrent_queue.push(qMakePair(h.queue_position(), h));
}
}
catch(invalid_handle&) {}
}
// Increase torrents priority (starting with the ones with highest priority)
while(!torrent_queue.empty())
{
while(!torrent_queue.empty()) {
QTorrentHandle h = torrent_queue.top().second;
try
{
try {
h.queue_position_up();
}
catch(invalid_handle&) {}
@ -472,32 +437,27 @@ void RequestHandler::action_command_increasePrio() @@ -472,32 +437,27 @@ void RequestHandler::action_command_increasePrio()
void RequestHandler::action_command_decreasePrio()
{
QStringList hashes = request().posts["hashes"].split("|");
std::priority_queue<QPair<int, QTorrentHandle>,
std::vector<QPair<int, QTorrentHandle> >,
std::less<QPair<int, QTorrentHandle> > > torrent_queue;
// Sort torrents by priority
foreach (const QString &hash, hashes)
{
try
{
foreach (const QString &hash, hashes) {
try {
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (!h.is_seed())
{
torrent_queue.push(qMakePair(h.queue_position(), h));
}
}
catch(invalid_handle&) {}
}
// Decrease torrents priority (starting with the ones with lowest priority)
while(!torrent_queue.empty())
{
while(!torrent_queue.empty()) {
QTorrentHandle h = torrent_queue.top().second;
try
{
try {
h.queue_position_down();
}
catch(invalid_handle&) {}
@ -508,8 +468,7 @@ void RequestHandler::action_command_decreasePrio() @@ -508,8 +468,7 @@ void RequestHandler::action_command_decreasePrio()
void RequestHandler::action_command_topPrio()
{
foreach (const QString &hash, request().posts["hashes"].split("|"))
{
foreach (const QString &hash, request().posts["hashes"].split("|")) {
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (h.is_valid()) h.queue_position_top();
}
@ -517,8 +476,7 @@ void RequestHandler::action_command_topPrio() @@ -517,8 +476,7 @@ void RequestHandler::action_command_topPrio()
void RequestHandler::action_command_bottomPrio()
{
foreach (const QString &hash, request().posts["hashes"].split("|"))
{
foreach (const QString &hash, request().posts["hashes"].split("|")) {
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (h.is_valid()) h.queue_position_bottom();
}
@ -536,25 +494,21 @@ bool RequestHandler::isPublicScope() @@ -536,25 +494,21 @@ bool RequestHandler::isPublicScope()
void RequestHandler::processRequest()
{
if (args_.contains(".") || args_.contains(".."))
{
if (args_.contains(".") || args_.contains("..")) {
qDebug() << Q_FUNC_INFO << "Invalid path:" << request().path;
status(404, "Not Found");
return;
}
if (!isPublicScope() && !sessionActive())
{
if (!isPublicScope() && !sessionActive()) {
status(403, "Forbidden");
return;
}
if (actions_.value(scope_).value(action_) != 0)
{
if (actions_.value(scope_).value(action_) != 0) {
(this->*(actions_[scope_][action_]))();
}
else
{
else {
status(404, "Not Found");
qDebug() << Q_FUNC_INFO << "Resource not found:" << request().path;
}
@ -566,19 +520,15 @@ void RequestHandler::parsePath() @@ -566,19 +520,15 @@ void RequestHandler::parsePath()
// check action for requested path
QStringList pathItems = request().path.split('/', QString::SkipEmptyParts);
if (!pathItems.empty())
{
if (actions_.contains(pathItems.front()))
{
if (!pathItems.empty()) {
if (actions_.contains(pathItems.front())) {
scope_ = pathItems.front();
pathItems.pop_front();
}
}
if (!pathItems.empty())
{
if (actions_[scope_].contains(pathItems.front()))
{
if (!pathItems.empty()) {
if (actions_[scope_].contains(pathItems.front())) {
action_ = pathItems.front();
pathItems.pop_front();
}

Loading…
Cancel
Save