Browse Source

WebUI: Assign a version to the Web API and allow to get it

New GET methods:
 * version/api: current API version
 * version/api_min: min API version supported

The API version is an integer and it's returned as plain text.

Whenever the API is changed, the api version is increased.

Whenever the API is changed in a way that is not backward compatible,
api_min is increased.
adaptive-webui-19844
Gabriele 10 years ago
parent
commit
8b5512c244
  1. 18
      src/webui/requesthandler.cpp
  2. 2
      src/webui/requesthandler.h

18
src/webui/requesthandler.cpp

@ -51,6 +51,9 @@
using namespace libtorrent; using namespace libtorrent;
static const int API_VERSION = 2;
static const int API_VERSION_MIN = 2;
const QString WWW_FOLDER = ":/www/public/"; const QString WWW_FOLDER = ":/www/public/";
const QString PRIVATE_FOLDER = ":/www/private/"; const QString PRIVATE_FOLDER = ":/www/private/";
const QString DEFAULT_SCOPE = "public"; const QString DEFAULT_SCOPE = "public";
@ -58,6 +61,7 @@ const QString SCOPE_IMAGES = "images";
const QString SCOPE_THEME = "theme"; const QString SCOPE_THEME = "theme";
const QString DEFAULT_ACTION = "index"; const QString DEFAULT_ACTION = "index";
const QString WEBUI_ACTION = "webui"; const QString WEBUI_ACTION = "webui";
const QString VERSION_INFO = "version";
#define ADD_ACTION(scope, action) actions[#scope][#action] = &RequestHandler::action_##scope##_##action #define ADD_ACTION(scope, action) actions[#scope][#action] = &RequestHandler::action_##scope##_##action
@ -102,6 +106,8 @@ QMap<QString, QMap<QString, RequestHandler::Action> > RequestHandler::initialize
ADD_ACTION(command, topPrio); ADD_ACTION(command, topPrio);
ADD_ACTION(command, bottomPrio); ADD_ACTION(command, bottomPrio);
ADD_ACTION(command, recheck); ADD_ACTION(command, recheck);
ADD_ACTION(version, api);
ADD_ACTION(version, api_min);
return actions; return actions;
} }
@ -209,6 +215,16 @@ void RequestHandler::action_json_propertiesFiles()
print(btjson::getFilesForTorrent(args_.front()), CONTENT_TYPE_JS); print(btjson::getFilesForTorrent(args_.front()), CONTENT_TYPE_JS);
} }
void RequestHandler::action_version_api()
{
print(QString::number(API_VERSION), CONTENT_TYPE_TXT);
}
void RequestHandler::action_version_api_min()
{
print(QString::number(API_VERSION_MIN), CONTENT_TYPE_TXT);
}
void RequestHandler::action_command_shutdown() void RequestHandler::action_command_shutdown()
{ {
qDebug() << "Shutdown request from Web UI"; qDebug() << "Shutdown request from Web UI";
@ -489,7 +505,7 @@ void RequestHandler::action_command_recheck()
bool RequestHandler::isPublicScope() bool RequestHandler::isPublicScope()
{ {
return (scope_ == DEFAULT_SCOPE); return (scope_ == DEFAULT_SCOPE || scope_ == VERSION_INFO);
} }
void RequestHandler::processRequest() void RequestHandler::processRequest()

2
src/webui/requesthandler.h

@ -81,6 +81,8 @@ private:
void action_command_topPrio(); void action_command_topPrio();
void action_command_bottomPrio(); void action_command_bottomPrio();
void action_command_recheck(); void action_command_recheck();
void action_version_api();
void action_version_api_min();
typedef void (RequestHandler::*Action)(); typedef void (RequestHandler::*Action)();

Loading…
Cancel
Save