Removed class ApiRouter.

This commit is contained in:
XMRig 2019-07-19 04:41:48 +07:00
parent 1d78e7d60d
commit ca7fb33848
7 changed files with 37 additions and 146 deletions

View file

@ -235,8 +235,6 @@ if (WITH_HTTP)
src/api/requests/ApiRequest.h
src/api/requests/HttpApiRequest.cpp
src/api/requests/HttpApiRequest.h
src/api/v1/ApiRouter.cpp
src/api/v1/ApiRouter.h
)
else()
set(HTTP_SOURCES "")

View file

@ -35,7 +35,6 @@
#include "api/Api.h"
#include "api/interfaces/IApiListener.h"
#include "api/requests/HttpApiRequest.h"
#include "api/v1/ApiRouter.h"
#include "base/kernel/Base.h"
#include "base/tools/Buffer.h"
#include "base/tools/Chrono.h"
@ -61,16 +60,11 @@ xmrig::Api::Api(Base *base) :
base->addListener(this);
genId(base->config()->apiId());
m_v1 = new ApiRouter(base);
addListener(m_v1);
}
xmrig::Api::~Api()
{
delete m_v1;
# ifdef XMRIG_FEATURE_HTTP
delete m_httpd;
# endif

View file

@ -36,7 +36,6 @@
namespace xmrig {
class ApiRouter;
class Base;
class Httpd;
class HttpData;
@ -67,7 +66,6 @@ private:
void genId(const String &id);
void genWorkerId(const String &id);
ApiRouter *m_v1;
Base *m_base;
char m_id[32];
char m_workerId[128];

View file

@ -1,75 +0,0 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include <cmath>
#include <string.h>
#include <uv.h>
#include "api/interfaces/IApiRequest.h"
#include "api/v1/ApiRouter.h"
#include "backend/common/interfaces/IThread.h"
#include "backend/cpu/Cpu.h"
#include "base/kernel/Base.h"
#include "base/kernel/Platform.h"
#include "core/config/Config.h"
#include "rapidjson/document.h"
#include "version.h"
xmrig::ApiRouter::ApiRouter(Base *base) :
m_base(base)
{
}
xmrig::ApiRouter::~ApiRouter()
{
}
void xmrig::ApiRouter::onRequest(IApiRequest &request)
{
if (request.method() == IApiRequest::METHOD_GET) {
if (request.url() == "/1/config") {
if (request.isRestricted()) {
return request.done(403);
}
request.accept();
m_base->config()->getJSON(request.doc());
}
}
else if (request.method() == IApiRequest::METHOD_PUT || request.method() == IApiRequest::METHOD_POST) {
if (request.url() == "/1/config") {
request.accept();
if (!m_base->reload(request.json())) {
return request.done(400);
}
request.done(204);
}
}
}

View file

@ -1,59 +0,0 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_APIROUTER_H
#define XMRIG_APIROUTER_H
#include "api/interfaces/IApiListener.h"
#include "rapidjson/fwd.h"
class Hashrate;
namespace xmrig {
class Base;
class ApiRouter : public IApiListener
{
public:
ApiRouter(Base *base);
~ApiRouter() override;
protected:
void onRequest(IApiRequest &request) override;
private:
Base *m_base;
};
} // namespace xmrig
#endif /* XMRIG_APIROUTER_H */

View file

@ -48,6 +48,7 @@
#ifdef XMRIG_FEATURE_API
# include "api/Api.h"
# include "api/interfaces/IApiRequest.h"
#endif
@ -167,6 +168,7 @@ int xmrig::Base::init()
# ifdef XMRIG_FEATURE_API
d_ptr->api = new Api(this);
d_ptr->api->addListener(this);
# endif
Platform::init(config()->userAgent());
@ -288,3 +290,31 @@ void xmrig::Base::onFileChanged(const String &fileName)
d_ptr->replace(config);
}
#ifdef XMRIG_FEATURE_API
void xmrig::Base::onRequest(IApiRequest &request)
{
if (request.method() == IApiRequest::METHOD_GET) {
if (request.url() == "/1/config") {
if (request.isRestricted()) {
return request.done(403);
}
request.accept();
config()->getJSON(request.doc());
}
}
else if (request.method() == IApiRequest::METHOD_PUT || request.method() == IApiRequest::METHOD_POST) {
if (request.url() == "/1/config") {
request.accept();
if (!reload(request.json())) {
return request.done(400);
}
request.done(204);
}
}
}
#endif

View file

@ -26,6 +26,7 @@
#define XMRIG_BASE_H
#include "api/interfaces/IApiListener.h"
#include "base/kernel/interfaces/IConfigListener.h"
#include "base/kernel/interfaces/IWatcherListener.h"
#include "rapidjson/fwd.h"
@ -35,13 +36,13 @@ namespace xmrig {
class Api;
class Config;
class BasePrivate;
class Config;
class IBaseListener;
class Process;
class Base : public IWatcherListener
class Base : public IWatcherListener, public IApiListener
{
public:
Base(Process *process);
@ -60,6 +61,10 @@ public:
protected:
void onFileChanged(const String &fileName) override;
# ifdef XMRIG_FEATURE_API
void onRequest(IApiRequest &request) override;
# endif
private:
BasePrivate *d_ptr;
};