diff --git a/src/base/api/interfaces/IApiRequest.h b/src/base/api/interfaces/IApiRequest.h index 35fb27d5f..fb55c2807 100644 --- a/src/base/api/interfaces/IApiRequest.h +++ b/src/base/api/interfaces/IApiRequest.h @@ -52,6 +52,8 @@ public: enum RequestType { REQ_UNKNOWN, REQ_SUMMARY, + REQ_BACKENDS, + REQ_CONFIG, REQ_JSON_RPC }; diff --git a/src/base/api/requests/ApiRequest.h b/src/base/api/requests/ApiRequest.h index c87e822c0..4bfb1637c 100644 --- a/src/base/api/requests/ApiRequest.h +++ b/src/base/api/requests/ApiRequest.h @@ -60,7 +60,7 @@ protected: inline Source source() const override { return m_source; } inline void done(int) override { m_state = STATE_DONE; } - int m_version = 1; + int m_version = 0; RequestType m_type = REQ_UNKNOWN; State m_state = STATE_NEW; String m_rpcMethod; diff --git a/src/base/api/requests/HttpApiRequest.cpp b/src/base/api/requests/HttpApiRequest.cpp index de43f752e..c9f56b075 100644 --- a/src/base/api/requests/HttpApiRequest.cpp +++ b/src/base/api/requests/HttpApiRequest.cpp @@ -67,10 +67,33 @@ xmrig::HttpApiRequest::HttpApiRequest(const HttpData &req, bool restricted) : m_res(req.id()), m_url(req.url.c_str()) { - if (method() == METHOD_GET) { - if (url() == "/1/summary" || url() == "/2/summary" || url() == "/api.json") { - m_type = REQ_SUMMARY; + if (url().size() > 4 && memcmp(url().data(), "/", 1) == 0 && memcmp(url().data()+2, "/", 1) == 0) { + if (memcmp(url().data(), "/2/", 3) == 0) { + m_version = 2; + } else if (memcmp(url().data(), "/1/", 3) == 0) { + m_version = 1; } + switch (url().size()) { + case 9: + if (memcmp(url().data()+3, "config", 6) == 0) { + m_type = REQ_CONFIG; + } + break; + case 10: + if (memcmp(url().data()+3, "summary", 7) == 0) { + m_type = REQ_SUMMARY; + } + break; + case 11: + if (memcmp(url().data()+3, "backends", 8) == 0) { + m_type = REQ_BACKENDS; + } + break; + } + } + + if (url() == "/api.json") { + m_type = REQ_SUMMARY; } if (method() == METHOD_POST && url() == "/json_rpc") { @@ -94,12 +117,6 @@ xmrig::HttpApiRequest::HttpApiRequest(const HttpData &req, bool restricted) : return; } - - if (url().size() > 4) { - if (memcmp(url().data(), "/2/", 3) == 0) { - m_version = 2; - } - } } diff --git a/src/base/kernel/Base.cpp b/src/base/kernel/Base.cpp index 4aa2e466e..b5d30af3e 100644 --- a/src/base/kernel/Base.cpp +++ b/src/base/kernel/Base.cpp @@ -45,13 +45,6 @@ #ifdef XMRIG_FEATURE_API # include "base/api/Api.h" # include "base/api/interfaces/IApiRequest.h" - -namespace xmrig { - -static const char *kConfigPathV1 = "/1/config"; -static const char *kConfigPathV2 = "/2/config"; - -} // namespace xmrig #endif @@ -317,7 +310,7 @@ void xmrig::Base::onFileChanged(const String &fileName) void xmrig::Base::onRequest(IApiRequest &request) { if (request.method() == IApiRequest::METHOD_GET) { - if (request.url() == kConfigPathV1 || request.url() == kConfigPathV2) { + if (request.type() == IApiRequest::REQ_CONFIG) { if (request.isRestricted()) { return request.done(403); } @@ -327,7 +320,7 @@ void xmrig::Base::onRequest(IApiRequest &request) } } else if (request.method() == IApiRequest::METHOD_PUT || request.method() == IApiRequest::METHOD_POST) { - if (request.url() == kConfigPathV1 || request.url() == kConfigPathV2) { + if (request.type() == IApiRequest::REQ_CONFIG) { request.accept(); if (!reload(request.json())) { diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 9cc9092b3..71f73ea42 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -689,7 +689,7 @@ void xmrig::Miner::onRequest(IApiRequest &request) d_ptr->getMiner(request.reply(), request.doc(), request.version()); d_ptr->getHashrate(request.reply(), request.doc(), request.version()); } - else if (request.url() == "/2/backends") { + else if (request.type() == IApiRequest::REQ_BACKENDS && request.version() == 2) { request.accept(); d_ptr->getBackends(request.reply(), request.doc()); @@ -711,6 +711,12 @@ void xmrig::Miner::onRequest(IApiRequest &request) stop(); } + else if (request.rpcMethod() == "start") { + request.accept(); + + const auto config = d_ptr->controller->config(); + onConfigChanged(config, config); + } } for (IBackend *backend : d_ptr->backends) {