mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-09 17:12:31 -06:00
Redesign Web API
Normalize Web API method names. Allow to use alternative Web UI. Switch Web API version to standard form (i.e. "2.0"). Improve Web UI translation code. Retranslate changed files. Add Web API for RSS subsystem.
This commit is contained in:
@@ -19,6 +19,7 @@ bittorrent/torrentinfo.h
|
||||
bittorrent/tracker.h
|
||||
bittorrent/trackerentry.h
|
||||
http/connection.h
|
||||
http/httperror.h
|
||||
http/irequesthandler.h
|
||||
http/requestparser.h
|
||||
http/responsebuilder.h
|
||||
@@ -85,6 +86,7 @@ bittorrent/torrentinfo.cpp
|
||||
bittorrent/tracker.cpp
|
||||
bittorrent/trackerentry.cpp
|
||||
http/connection.cpp
|
||||
http/httperror.cpp
|
||||
http/requestparser.cpp
|
||||
http/responsebuilder.cpp
|
||||
http/responsegenerator.cpp
|
||||
|
||||
@@ -21,6 +21,7 @@ HEADERS += \
|
||||
$$PWD/filesystemwatcher.h \
|
||||
$$PWD/global.h \
|
||||
$$PWD/http/connection.h \
|
||||
$$PWD/http/httperror.h \
|
||||
$$PWD/http/irequesthandler.h \
|
||||
$$PWD/http/requestparser.h \
|
||||
$$PWD/http/responsebuilder.h \
|
||||
@@ -86,6 +87,7 @@ SOURCES += \
|
||||
$$PWD/exceptions.cpp \
|
||||
$$PWD/filesystemwatcher.cpp \
|
||||
$$PWD/http/connection.cpp \
|
||||
$$PWD/http/httperror.cpp \
|
||||
$$PWD/http/requestparser.cpp \
|
||||
$$PWD/http/responsebuilder.cpp \
|
||||
$$PWD/http/responsegenerator.cpp \
|
||||
|
||||
@@ -74,7 +74,7 @@ libtorrent::entry Peer::toEntry(bool noPeerId) const
|
||||
// Tracker
|
||||
|
||||
Tracker::Tracker(QObject *parent)
|
||||
: Http::ResponseBuilder(parent)
|
||||
: QObject(parent)
|
||||
, m_server(new Http::Server(this, this))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#define BITTORRENT_TRACKER_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
|
||||
#include "base/http/irequesthandler.h"
|
||||
#include "base/http/responsebuilder.h"
|
||||
@@ -75,7 +76,7 @@ namespace BitTorrent
|
||||
|
||||
/* Basic Bittorrent tracker implementation in Qt */
|
||||
/* Following http://wiki.theory.org/BitTorrent_Tracker_Protocol */
|
||||
class Tracker : public Http::ResponseBuilder, public Http::IRequestHandler
|
||||
class Tracker : public QObject, public Http::IRequestHandler, private Http::ResponseBuilder
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(Tracker)
|
||||
|
||||
81
src/base/http/httperror.cpp
Normal file
81
src/base/http/httperror.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2017 Vladimir Golovnev <glassez@yandex.ru>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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 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.
|
||||
*/
|
||||
|
||||
#include "httperror.h"
|
||||
|
||||
HTTPError::HTTPError(int statusCode, const QString &statusText, const QString &message)
|
||||
: RuntimeError {message}
|
||||
, m_statusCode {statusCode}
|
||||
, m_statusText {statusText}
|
||||
{
|
||||
}
|
||||
|
||||
int HTTPError::statusCode() const
|
||||
{
|
||||
return m_statusCode;
|
||||
}
|
||||
|
||||
QString HTTPError::statusText() const
|
||||
{
|
||||
return m_statusText;
|
||||
}
|
||||
|
||||
BadRequestHTTPError::BadRequestHTTPError(const QString &message)
|
||||
: HTTPError(400, QLatin1String("Bad Request"), message)
|
||||
{
|
||||
}
|
||||
|
||||
ConflictHTTPError::ConflictHTTPError(const QString &message)
|
||||
: HTTPError(409, QLatin1String("Conflict"), message)
|
||||
{
|
||||
}
|
||||
|
||||
ForbiddenHTTPError::ForbiddenHTTPError(const QString &message)
|
||||
: HTTPError(403, QLatin1String("Forbidden"), message)
|
||||
{
|
||||
}
|
||||
|
||||
NotFoundHTTPError::NotFoundHTTPError(const QString &message)
|
||||
: HTTPError(404, QLatin1String("Not Found"), message)
|
||||
{
|
||||
}
|
||||
|
||||
UnsupportedMediaTypeHTTPError::UnsupportedMediaTypeHTTPError(const QString &message)
|
||||
: HTTPError(415, QLatin1String("Unsupported Media Type"), message)
|
||||
{
|
||||
}
|
||||
|
||||
UnauthorizedHTTPError::UnauthorizedHTTPError(const QString &message)
|
||||
: HTTPError(401, QLatin1String("Unauthorized"), message)
|
||||
{
|
||||
}
|
||||
|
||||
InternalServerErrorHTTPError::InternalServerErrorHTTPError(const QString &message)
|
||||
: HTTPError(500, QLatin1String("Internal Server Error"), message)
|
||||
{
|
||||
}
|
||||
86
src/base/http/httperror.h
Normal file
86
src/base/http/httperror.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2017 Vladimir Golovnev <glassez@yandex.ru>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/exceptions.h"
|
||||
|
||||
class HTTPError : public RuntimeError
|
||||
{
|
||||
public:
|
||||
HTTPError(int statusCode, const QString &statusText, const QString &message = "");
|
||||
|
||||
int statusCode() const;
|
||||
QString statusText() const;
|
||||
|
||||
private:
|
||||
const int m_statusCode;
|
||||
const QString m_statusText;
|
||||
};
|
||||
|
||||
class BadRequestHTTPError : public HTTPError
|
||||
{
|
||||
public:
|
||||
explicit BadRequestHTTPError(const QString &message = "");
|
||||
};
|
||||
|
||||
class ForbiddenHTTPError : public HTTPError
|
||||
{
|
||||
public:
|
||||
explicit ForbiddenHTTPError(const QString &message = "");
|
||||
};
|
||||
|
||||
class NotFoundHTTPError : public HTTPError
|
||||
{
|
||||
public:
|
||||
explicit NotFoundHTTPError(const QString &message = "");
|
||||
};
|
||||
|
||||
class ConflictHTTPError : public HTTPError
|
||||
{
|
||||
public:
|
||||
explicit ConflictHTTPError(const QString &message = "");
|
||||
};
|
||||
|
||||
class UnsupportedMediaTypeHTTPError : public HTTPError
|
||||
{
|
||||
public:
|
||||
explicit UnsupportedMediaTypeHTTPError(const QString &message = "");
|
||||
};
|
||||
|
||||
class UnauthorizedHTTPError : public HTTPError
|
||||
{
|
||||
public:
|
||||
explicit UnauthorizedHTTPError(const QString &message = "");
|
||||
};
|
||||
|
||||
class InternalServerErrorHTTPError : public HTTPError
|
||||
{
|
||||
public:
|
||||
explicit InternalServerErrorHTTPError(const QString &message = "");
|
||||
};
|
||||
@@ -30,11 +30,6 @@
|
||||
|
||||
using namespace Http;
|
||||
|
||||
ResponseBuilder::ResponseBuilder(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void ResponseBuilder::status(uint code, const QString &text)
|
||||
{
|
||||
m_response.status = ResponseStatus(code, text);
|
||||
|
||||
@@ -29,17 +29,13 @@
|
||||
#ifndef HTTP_RESPONSEBUILDER_H
|
||||
#define HTTP_RESPONSEBUILDER_H
|
||||
|
||||
#include <QObject>
|
||||
#include "types.h"
|
||||
|
||||
namespace Http
|
||||
{
|
||||
class ResponseBuilder : public QObject
|
||||
class ResponseBuilder
|
||||
{
|
||||
public:
|
||||
explicit ResponseBuilder(QObject *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void status(uint code = 200, const QString &text = QLatin1String("OK"));
|
||||
void header(const QString &name, const QString &value);
|
||||
void print(const QString &text, const QString &type = CONTENT_TYPE_HTML);
|
||||
|
||||
@@ -609,6 +609,26 @@ void Preferences::setWebUiHttpsKey(const QByteArray &data)
|
||||
setValue("Preferences/WebUI/HTTPS/Key", data);
|
||||
}
|
||||
|
||||
bool Preferences::isAltWebUiEnabled() const
|
||||
{
|
||||
return value("Preferences/WebUI/AlternativeUIEnabled", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setAltWebUiEnabled(bool enabled)
|
||||
{
|
||||
setValue("Preferences/WebUI/AlternativeUIEnabled", enabled);
|
||||
}
|
||||
|
||||
QString Preferences::getWebUiRootFolder() const
|
||||
{
|
||||
return value("Preferences/WebUI/RootFolder").toString();
|
||||
}
|
||||
|
||||
void Preferences::setWebUiRootFolder(const QString &path)
|
||||
{
|
||||
setValue("Preferences/WebUI/RootFolder", path);
|
||||
}
|
||||
|
||||
bool Preferences::isDynDNSEnabled() const
|
||||
{
|
||||
return value("Preferences/DynDNS/Enabled", false).toBool();
|
||||
|
||||
@@ -204,6 +204,10 @@ public:
|
||||
void setWebUiHttpsCertificate(const QByteArray &data);
|
||||
QByteArray getWebUiHttpsKey() const;
|
||||
void setWebUiHttpsKey(const QByteArray &data);
|
||||
bool isAltWebUiEnabled() const;
|
||||
void setAltWebUiEnabled(bool enabled);
|
||||
QString getWebUiRootFolder() const;
|
||||
void setWebUiRootFolder(const QString &path);
|
||||
|
||||
// Dynamic DNS
|
||||
bool isDynDNSEnabled() const;
|
||||
|
||||
@@ -30,6 +30,10 @@
|
||||
|
||||
#include "fs.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
@@ -47,6 +51,7 @@
|
||||
#include <kernel/fs_info.h>
|
||||
#else
|
||||
#include <sys/vfs.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "base/bittorrent/torrenthandle.h"
|
||||
@@ -281,3 +286,17 @@ QString Utils::Fs::tempPath()
|
||||
QDir().mkdir(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
bool Utils::Fs::isRegularFile(const QString &path)
|
||||
{
|
||||
struct ::stat st;
|
||||
if (::stat(path.toUtf8().constData(), &st) != 0) {
|
||||
// analyse erno and log the error
|
||||
const auto err = errno;
|
||||
qDebug("Could not get file stats for path '%s'. Error: %s"
|
||||
, qUtf8Printable(path), qUtf8Printable(strerror(err)));
|
||||
return false;
|
||||
}
|
||||
|
||||
return (st.st_mode & S_IFMT) == S_IFREG;
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ namespace Utils
|
||||
bool sameFileNames(const QString &first, const QString &second);
|
||||
QString expandPath(const QString &path);
|
||||
QString expandPathAbs(const QString &path);
|
||||
bool isRegularFile(const QString &path);
|
||||
|
||||
bool smartRemoveEmptyFolderTree(const QString &path);
|
||||
bool forceRemove(const QString &filePath);
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
#include <QThreadStorage>
|
||||
#endif
|
||||
|
||||
#include "../tristatebool.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
class NaturalCompare
|
||||
@@ -184,3 +186,19 @@ QString Utils::String::wildcardToRegex(const QString &pattern)
|
||||
{
|
||||
return qt_regexp_toCanonical(pattern, QRegExp::Wildcard);
|
||||
}
|
||||
|
||||
bool Utils::String::parseBool(const QString &string, const bool defaultValue)
|
||||
{
|
||||
if (defaultValue)
|
||||
return (string.compare("false", Qt::CaseInsensitive) == 0) ? false : true;
|
||||
return (string.compare("true", Qt::CaseInsensitive) == 0) ? true : false;
|
||||
}
|
||||
|
||||
TriStateBool Utils::String::parseTriStateBool(const QString &string)
|
||||
{
|
||||
if (string.compare("true", Qt::CaseInsensitive) == 0)
|
||||
return TriStateBool::True;
|
||||
if (string.compare("false", Qt::CaseInsensitive) == 0)
|
||||
return TriStateBool::False;
|
||||
return TriStateBool::Undefined;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
class QByteArray;
|
||||
class QLatin1String;
|
||||
class TriStateBool;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
@@ -66,6 +67,9 @@ namespace Utils
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
bool parseBool(const QString &string, const bool defaultValue);
|
||||
TriStateBool parseTriStateBool(const QString &string);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user