diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d205f55..e0290778 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 "") diff --git a/src/api/Api.cpp b/src/api/Api.cpp index 11fc2a69..9151aa7e 100644 --- a/src/api/Api.cpp +++ b/src/api/Api.cpp @@ -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 diff --git a/src/api/Api.h b/src/api/Api.h index eef57c3a..f2ed3926 100644 --- a/src/api/Api.h +++ b/src/api/Api.h @@ -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]; diff --git a/src/api/v1/ApiRouter.cpp b/src/api/v1/ApiRouter.cpp deleted file mode 100644 index 21e69f2d..00000000 --- a/src/api/v1/ApiRouter.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , - * - * 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 . - */ - -#include -#include -#include - - -#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); - } - } -} diff --git a/src/api/v1/ApiRouter.h b/src/api/v1/ApiRouter.h deleted file mode 100644 index 008f5bc0..00000000 --- a/src/api/v1/ApiRouter.h +++ /dev/null @@ -1,59 +0,0 @@ -/* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , - * - * 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 . - */ - -#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 */ diff --git a/src/base/kernel/Base.cpp b/src/base/kernel/Base.cpp index 46f32684..d290e7f4 100644 --- a/src/base/kernel/Base.cpp +++ b/src/base/kernel/Base.cpp @@ -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 diff --git a/src/base/kernel/Base.h b/src/base/kernel/Base.h index 592d3a37..6a33a802 100644 --- a/src/base/kernel/Base.h +++ b/src/base/kernel/Base.h @@ -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; };