From 664585ff9998db84b3b21bc5f23e286c7d0c2c14 Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:20:30 +0000 Subject: [PATCH 1/6] add security policies for public access to API --- CMakeLists.txt | 2 +- src/main.cpp | 19 ++++++++++++++++--- src/net_mongoose.cpp | 41 ++++++++++++++++++++++++++++++++++------- src/net_mongoose.h | 2 +- 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5632e24..31f02a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,7 +98,7 @@ else() mbedx509 ) target_compile_definitions(mo_simulator PUBLIC - MG_ENABLE_MBEDTLS=1 + MG_TLS=MG_TLS_MBED ) endif() diff --git a/src/main.cpp b/src/main.cpp index ac7d6b4..58d4f13 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include #include +#include #include "evse.h" #include "api.h" @@ -128,6 +129,10 @@ void app_loop() { #if MO_NETLIB == MO_NETLIB_MONGOOSE +#ifndef MO_SIM_ENDPOINT_URL +#define MO_SIM_ENDPOINT_URL "http://0.0.0.0:8000" //URL to forward to mg_http_listen(). Will be ignored if the URL field exists in api.jsn +#endif + int main() { #if MBEDTLS_PLATFORM_MEMORY @@ -143,12 +148,20 @@ int main() { mg_log_set(MG_LL_INFO); mg_mgr_init(&mgr); - mg_http_listen(&mgr, "0.0.0.0:8000", http_serve, NULL); // Create listening connection - auto filesystem = MicroOcpp::makeDefaultFilesystemAdapter(MicroOcpp::FilesystemOpt::Use_Mount_FormatOnFail); load_ocpp_version(filesystem); + auto api_settings_doc = MicroOcpp::FilesystemUtils::loadJson(filesystem, MO_FILENAME_PREFIX "api.jsn", "Simulator"); + if (!api_settings_doc) { + api_settings_doc = MicroOcpp::makeJsonDoc("Simulator", 0); + } + JsonObject api_settings = api_settings_doc->as(); + + const char *api_url = api_settings["url"] | MO_SIM_ENDPOINT_URL; + + mg_http_listen(&mgr, api_url, http_serve, (void*)api_url); // Create listening connection + osock = new MicroOcpp::MOcppMongooseClient(&mgr, "ws://echo.websocket.events", "charger-01", @@ -160,7 +173,7 @@ int main() { MicroOcpp::ProtocolVersion{1,6} ); - server_initialize(osock); + server_initialize(osock, api_settings["cert"] | "", api_settings["key"] | "", api_settings["user"] | "", api_settings["pass"] | ""); app_setup(*osock, filesystem); setOnResetExecute([] (bool isHard) { diff --git a/src/net_mongoose.cpp b/src/net_mongoose.cpp index 3bcd6c9..96789b2 100644 --- a/src/net_mongoose.cpp +++ b/src/net_mongoose.cpp @@ -16,22 +16,49 @@ #define CORS_HEADERS "Access-Control-Allow-Origin: *\r\nAccess-Control-Allow-Headers:Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers\r\nAccess-Control-Allow-Methods: GET,HEAD,OPTIONS,POST,PUT\r\n" MicroOcpp::MOcppMongooseClient *ao_sock = nullptr; +const char *api_cert = ""; +const char *api_key = ""; +const char *api_user = ""; +const char *api_pass = ""; -void server_initialize(MicroOcpp::MOcppMongooseClient *osock) { - ao_sock = osock; +void server_initialize(MicroOcpp::MOcppMongooseClient *osock, const char *cert, const char *key, const char *user, const char *pass) { + ao_sock = osock; + api_cert = cert; + api_key = key; + api_user = user; + api_pass = pass; } -char* toStringPtr(std::string cppString){ - char *cstr = new char[cppString.length() + 1]; - strcpy(cstr, cppString.c_str()); - return cstr; +bool api_check_basic_auth(const char *user, const char *pass) { + if (strcmp(api_user, user)) { + return false; + } + if (strcmp(api_pass, pass)) { + return false; + } + return true; } void http_serve(struct mg_connection *c, int ev, void *ev_data) { - if (ev == MG_EV_HTTP_MSG) { + if (ev == MG_EV_ACCEPT) { + if (mg_url_is_ssl((const char*)c->fn_data)) { // TLS listener! + struct mg_tls_opts opts = {0}; + opts.cert = mg_str(api_cert); + opts.key = mg_str(api_key); + mg_tls_init(c, &opts); + } + } else if (ev == MG_EV_HTTP_MSG) { //struct mg_http_message *message_data = (struct mg_http_message *) ev_data; struct mg_http_message *message_data = reinterpret_cast(ev_data); const char *final_headers = DEFAULT_HEADER CORS_HEADERS; + + char user[64], pass[64]; + mg_http_creds(message_data, user, sizeof(user), pass, sizeof(pass)); + if (!api_check_basic_auth(user, pass)) { + mg_http_reply(c, 403, final_headers, "Not Authorised\n"); + return; + } + struct mg_str json = message_data->body; MO_DBG_VERBOSE("%.*s", 20, message_data->uri.buf); diff --git a/src/net_mongoose.h b/src/net_mongoose.h index 46e0890..aa88717 100644 --- a/src/net_mongoose.h +++ b/src/net_mongoose.h @@ -13,7 +13,7 @@ namespace MicroOcpp { class MOcppMongooseClient; } -void server_initialize(MicroOcpp::MOcppMongooseClient *osock); +void server_initialize(MicroOcpp::MOcppMongooseClient *osock, const char *cert = "", const char *key = "", const char *user = "", const char *pass = ""); void http_serve(struct mg_connection *c, int ev, void *ev_data); From e4575fcc885d33f9359b8a0fab6a288f71f51700 Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Wed, 9 Oct 2024 09:56:53 +0000 Subject: [PATCH 2/6] load certificates from .pem files --- src/main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 58d4f13..0e945fd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -152,6 +152,9 @@ int main() { load_ocpp_version(filesystem); + struct mg_str api_cert = mg_file_read(&mg_fs_posix, MO_FILENAME_PREFIX "api_cert.pem"); + struct mg_str api_key = mg_file_read(&mg_fs_posix, MO_FILENAME_PREFIX "api_key.pem"); + auto api_settings_doc = MicroOcpp::FilesystemUtils::loadJson(filesystem, MO_FILENAME_PREFIX "api.jsn", "Simulator"); if (!api_settings_doc) { api_settings_doc = MicroOcpp::makeJsonDoc("Simulator", 0); @@ -173,7 +176,7 @@ int main() { MicroOcpp::ProtocolVersion{1,6} ); - server_initialize(osock, api_settings["cert"] | "", api_settings["key"] | "", api_settings["user"] | "", api_settings["pass"] | ""); + server_initialize(osock, api_cert.buf ? api_cert.buf : "", api_key.buf ? api_key.buf : "", api_settings["user"] | "", api_settings["pass"] | ""); app_setup(*osock, filesystem); setOnResetExecute([] (bool isHard) { @@ -204,6 +207,8 @@ int main() { delete osock; mg_mgr_free(&mgr); + free(api_cert.buf); + free(api_key.buf); return 0; } From a27cc2ffa83021cb7d98a02cdc7a634460f5f193 Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Thu, 10 Oct 2024 07:19:52 +0000 Subject: [PATCH 3/6] add HTTP API extension --- src/api.cpp | 142 ++++++++++++++++++++++++++++++++++++++++++- src/api.h | 2 + src/evse.cpp | 46 +++++++++----- src/evse.h | 5 ++ src/net_mongoose.cpp | 29 ++++++--- 5 files changed, 198 insertions(+), 26 deletions(-) diff --git a/src/api.cpp b/src/api.cpp index 955415f..f6696f7 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -3,8 +3,11 @@ // GPL-3.0 License #include "api.h" +#include "mongoose.h" #include +#include +#include #include "evse.h" @@ -12,8 +15,8 @@ bool str_match(const char *query, const char *pattern) { size_t qi = 0, pi = 0; - while (query[qi] && pattern[pi]) { - if (query[qi] == pattern[pi]) { + while (pattern[pi]) { + if (query[qi] && query[qi] == pattern[pi]) { qi++; pi++; } else if (pattern[pi] == '*') { @@ -155,3 +158,138 @@ int mocpp_api_call(const char *endpoint, MicroOcpp::Method method, const char *b return status; } + +int mocpp_api2_call(const char *uri_raw, size_t uri_raw_len, MicroOcpp::Method method, const char *query_raw, size_t query_raw_len, char *resp_body, size_t resp_body_size) { + + snprintf(resp_body, resp_body_size, "%s", ""); + + struct mg_str uri = mg_str_n(uri_raw, uri_raw_len); + struct mg_str query = mg_str_n(query_raw, query_raw_len); + + int evse_id = -1; + int connector_id = -1; + + unsigned int num; + struct mg_str evse_id_str = mg_http_var(query, mg_str("evse_id")); + if (evse_id_str.buf) { + if (!mg_str_to_num(evse_id_str, 10, &num, sizeof(num)) || num < 1 || num >= MO_NUM_EVSEID) { + snprintf(resp_body, resp_body_size, "invalid connector_id"); + return 400; + } + evse_id = (int)num; + } + + struct mg_str connector_id_str = mg_http_var(query, mg_str("connector_id")); + if (connector_id_str.buf) { + if (!mg_str_to_num(connector_id_str, 10, &num, sizeof(num)) || num != 1) { + snprintf(resp_body, resp_body_size, "invalid connector_id"); + return 400; + } + connector_id = (int)num; + } + + if (mg_match(uri, mg_str("/plugin"), NULL)) { + if (evse_id < 0) { + snprintf(resp_body, resp_body_size, "no action taken"); + return 200; + } else { + snprintf(resp_body, resp_body_size, "%s", connectors[evse_id-1].getEvPlugged() ? "EV already plugged" : "plugged in EV"); + connectors[evse_id-1].setEvPlugged(true); + connectors[evse_id-1].setEvReady(true); + connectors[evse_id-1].setEvseReady(true); + return 200; + } + } else if (mg_match(uri, mg_str("/plugout"), NULL)) { + if (evse_id < 0) { + snprintf(resp_body, resp_body_size, "no action taken"); + return 200; + } else { + snprintf(resp_body, resp_body_size, "%s", connectors[evse_id-1].getEvPlugged() ? "EV already unplugged" : "unplug EV"); + connectors[evse_id-1].setEvPlugged(false); + connectors[evse_id-1].setEvReady(false); + connectors[evse_id-1].setEvseReady(false); + return 200; + } + } else if (mg_match(uri, mg_str("/end"), NULL)) { + bool trackEvReady = false; + for (size_t i = 0; i < connectors.size(); i++) { + trackEvReady |= connectors[i].getEvReady(); + connectors[i].setEvReady(false); + } + snprintf(resp_body, resp_body_size, "%s", trackEvReady ? "suspended EV" : "EV already suspended"); + return 200; + } else if (mg_match(uri, mg_str("/state"), NULL)) { + struct mg_str ready_str = mg_http_var(query, mg_str("ready")); + bool ready = true; + if (ready_str.buf) { + if (mg_match(ready_str, mg_str("true"), NULL)) { + ready = true; + } else if (mg_match(ready_str, mg_str("false"), NULL)) { + ready = false; + } else { + snprintf(resp_body, resp_body_size, "invalid ready"); + return 400; + } + } + bool trackEvReady = false; + for (size_t i = 0; i < connectors.size(); i++) { + if (connectors[i].getEvPlugged()) { + bool trackEvReady = connectors[i].getEvReady(); + connectors[i].setEvReady(ready); + snprintf(resp_body, resp_body_size, "%s, %s", ready ? "EV suspended" : "EV not suspended", trackEvReady ? "suspended before" : "not suspended before"); + return 200; + } + } + snprintf(resp_body, resp_body_size, "no action taken - EV not plugged"); + return 200; + } else if (mg_match(uri, mg_str("/authorize"), NULL)) { + struct mg_str id = mg_http_var(query, mg_str("id")); + if (!id.buf) { + snprintf(resp_body, resp_body_size, "missing id"); + return 400; + } + struct mg_str type = mg_http_var(query, mg_str("type")); + if (!id.buf) { + snprintf(resp_body, resp_body_size, "missing type"); + return 400; + } + + int ret; + char id_buf [MO_IDTOKEN_LEN_MAX + 1]; + ret = snprintf(id_buf, sizeof(id_buf), "%.*s", (int)id.len, id.buf); + if (ret < 0 || ret >= sizeof(id_buf)) { + snprintf(resp_body, resp_body_size, "invalid id"); + return 400; + } + char type_buf [128]; + ret = snprintf(type_buf, sizeof(type_buf), "%.*s", (int)type.len, type.buf); + if (ret < 0 || ret >= sizeof(type_buf)) { + snprintf(resp_body, resp_body_size, "invalid type"); + return 400; + } + + if (evse_id <= 0) { + snprintf(resp_body, resp_body_size, "invalid evse_id"); + return 400; + } + + bool trackAuthActive = connectors[evse_id-1].getSessionIdTag(); + + if (!connectors[evse_id-1].presentNfcTag(id_buf, type_buf)) { + snprintf(resp_body, resp_body_size, "invalid id and / or type"); + return 400; + } + + bool authActive = connectors[evse_id-1].getSessionIdTag(); + + snprintf(resp_body, resp_body_size, "%s", + !trackAuthActive && authActive ? "authorize in progress" : + trackAuthActive && !authActive ? "unauthorize in progress" : + trackAuthActive && authActive ? "no action taken (EVSE still authorized)" : + "no action taken (EVSE not authorized)"); + + return 200; + } + + return 404; +} diff --git a/src/api.h b/src/api.h index fd25663..a2de1f8 100644 --- a/src/api.h +++ b/src/api.h @@ -19,4 +19,6 @@ enum class Method { int mocpp_api_call(const char *endpoint, MicroOcpp::Method method, const char *body, char *resp_body, size_t resp_body_size); +int mocpp_api2_call(const char *endpoint, size_t endpoint_len, MicroOcpp::Method method, const char *query, size_t query_len, char *resp_body, size_t resp_body_size); + #endif diff --git a/src/evse.cpp b/src/evse.cpp index b8b7d4a..a5f4275 100644 --- a/src/evse.cpp +++ b/src/evse.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -146,41 +147,54 @@ void Evse::loop() { } -void Evse::presentNfcTag(const char *uid_cstr) { - if (!uid_cstr) { +void Evse::presentNfcTag(const char *uid) { + if (!uid) { MO_DBG_ERR("invalid argument"); return; } - std::string uid = uid_cstr; #if MO_ENABLE_V201 if (auto context = getOcppContext()) { if (context->getVersion().major == 2) { - if (auto txService = context->getModel().getTransactionService()) { - if (auto evse = txService->getEvse(connectorId)) { - if (evse->getTransaction() && evse->getTransaction()->isAuthorizationActive) { - evse->endAuthorization(MicroOcpp::IdToken(uid_cstr, MicroOcpp::IdToken::Type::KeyCode)); - } else { - evse->beginAuthorization(MicroOcpp::IdToken(uid_cstr, MicroOcpp::IdToken::Type::KeyCode)); - } - return; - } - } + presentNfcTag(uid, "ISO14443"); + return; } } #endif if (isTransactionActive(connectorId)) { - if (!uid.compare(getTransactionIdTag(connectorId))) { - endTransaction(uid.c_str(), "Local", connectorId); + if (!strcmp(uid, getTransactionIdTag(connectorId))) { + endTransaction(uid, "Local", connectorId); } else { MO_DBG_INFO("RFID card denied"); } } else { - beginTransaction(uid.c_str(), connectorId); + beginTransaction(uid, connectorId); } } +#if MO_ENABLE_V201 +bool Evse::presentNfcTag(const char *uid, const char *type) { + + MicroOcpp::IdToken idToken {nullptr, MicroOcpp::IdToken::Type::UNDEFINED, "Simulator"}; + if (!idToken.parseCstr(uid, type)) { + return false; + } + + if (auto txService = getOcppContext()->getModel().getTransactionService()) { + if (auto evse = txService->getEvse(connectorId)) { + if (evse->getTransaction() && evse->getTransaction()->isAuthorizationActive) { + evse->endAuthorization(idToken); + } else { + evse->beginAuthorization(idToken); + } + return true; + } + } + return false; +} +#endif + void Evse::setEvPlugged(bool plugged) { if (!trackEvPluggedBool) return; trackEvPluggedBool->setBool(plugged); diff --git a/src/evse.h b/src/evse.h index 399652d..eaf37dc 100644 --- a/src/evse.h +++ b/src/evse.h @@ -8,6 +8,7 @@ #include #include #include +#include #define SIMULATOR_FN MO_FILENAME_PREFIX "simulator.jsn" @@ -41,6 +42,10 @@ class Evse { void presentNfcTag(const char *uid); +#if MO_ENABLE_V201 + bool presentNfcTag(const char *uid, const char *type); +#endif //MO_ENABLE_V201 + void setEvPlugged(bool plugged); bool getEvPlugged(); diff --git a/src/net_mongoose.cpp b/src/net_mongoose.cpp index 96789b2..6dae37c 100644 --- a/src/net_mongoose.cpp +++ b/src/net_mongoose.cpp @@ -42,6 +42,7 @@ bool api_check_basic_auth(const char *user, const char *pass) { void http_serve(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_ACCEPT) { if (mg_url_is_ssl((const char*)c->fn_data)) { // TLS listener! + MO_DBG_VERBOSE("API TLS setup"); struct mg_tls_opts opts = {0}; opts.cert = mg_str(api_cert); opts.key = mg_str(api_key); @@ -55,7 +56,7 @@ void http_serve(struct mg_connection *c, int ev, void *ev_data) { char user[64], pass[64]; mg_http_creds(message_data, user, sizeof(user), pass, sizeof(pass)); if (!api_check_basic_auth(user, pass)) { - mg_http_reply(c, 403, final_headers, "Not Authorised\n"); + mg_http_reply(c, 401, final_headers, "Unauthorized. Expect Basic Auth user and / or password\n"); return; } @@ -127,12 +128,24 @@ void http_serve(struct mg_connection *c, int ev, void *ev_data) { *c = '\0'; } - int status = mocpp_api_call( - message_data->uri.buf + strlen("/api"), - method, - message_data->body.buf, - resp_buf, RESP_BUF_SIZE); - + int status = 404; + if (status == 404) { + status = mocpp_api2_call( + message_data->uri.buf + strlen("/api"), + message_data->uri.len - strlen("/api"), + method, + message_data->query.buf, + message_data->query.len, + resp_buf, RESP_BUF_SIZE); + } + if (status == 404) { + status = mocpp_api_call( + message_data->uri.buf + strlen("/api"), + method, + message_data->body.buf, + resp_buf, RESP_BUF_SIZE); + } + mg_http_reply(c, status, final_headers, resp_buf); } else if (mg_match(message_data->uri, mg_str("/"), NULL)) { //if no specific path is given serve dashboard application file struct mg_http_serve_opts opts; @@ -141,7 +154,7 @@ void http_serve(struct mg_connection *c, int ev, void *ev_data) { opts.extra_headers = "Content-Type: text/html\r\nContent-Encoding: gzip\r\n"; mg_http_serve_file(c, message_data, "public/bundle.html.gz", &opts); } else { - mg_http_reply(c, 404, final_headers, "The required parameters are not given"); + mg_http_reply(c, 404, final_headers, "API endpoint not found"); } } } From 993382a3272f90e7fe2982a1c81759a3b9cf3c9e Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Thu, 10 Oct 2024 08:53:52 +0000 Subject: [PATCH 4/6] add memory endpoint --- lib/MicroOcpp | 2 +- src/api.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++ src/net_mongoose.cpp | 2 +- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/lib/MicroOcpp b/lib/MicroOcpp index 4ea7db2..56f7566 160000 --- a/lib/MicroOcpp +++ b/lib/MicroOcpp @@ -1 +1 @@ -Subproject commit 4ea7db2daeefb94bef42d4fa2d4ae4db9fab5646 +Subproject commit 56f7566409ae74b5cf4829fd6346e7e76a2d6835 diff --git a/src/api.cpp b/src/api.cpp index f6696f7..08bc18d 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -6,6 +6,7 @@ #include "mongoose.h" #include +#include #include #include @@ -189,6 +190,9 @@ int mocpp_api2_call(const char *uri_raw, size_t uri_raw_len, MicroOcpp::Method m } if (mg_match(uri, mg_str("/plugin"), NULL)) { + if (method != MicroOcpp::Method::POST) { + return 405; + } if (evse_id < 0) { snprintf(resp_body, resp_body_size, "no action taken"); return 200; @@ -200,6 +204,9 @@ int mocpp_api2_call(const char *uri_raw, size_t uri_raw_len, MicroOcpp::Method m return 200; } } else if (mg_match(uri, mg_str("/plugout"), NULL)) { + if (method != MicroOcpp::Method::POST) { + return 405; + } if (evse_id < 0) { snprintf(resp_body, resp_body_size, "no action taken"); return 200; @@ -211,6 +218,9 @@ int mocpp_api2_call(const char *uri_raw, size_t uri_raw_len, MicroOcpp::Method m return 200; } } else if (mg_match(uri, mg_str("/end"), NULL)) { + if (method != MicroOcpp::Method::POST) { + return 405; + } bool trackEvReady = false; for (size_t i = 0; i < connectors.size(); i++) { trackEvReady |= connectors[i].getEvReady(); @@ -219,6 +229,9 @@ int mocpp_api2_call(const char *uri_raw, size_t uri_raw_len, MicroOcpp::Method m snprintf(resp_body, resp_body_size, "%s", trackEvReady ? "suspended EV" : "EV already suspended"); return 200; } else if (mg_match(uri, mg_str("/state"), NULL)) { + if (method != MicroOcpp::Method::POST) { + return 405; + } struct mg_str ready_str = mg_http_var(query, mg_str("ready")); bool ready = true; if (ready_str.buf) { @@ -243,6 +256,9 @@ int mocpp_api2_call(const char *uri_raw, size_t uri_raw_len, MicroOcpp::Method m snprintf(resp_body, resp_body_size, "no action taken - EV not plugged"); return 200; } else if (mg_match(uri, mg_str("/authorize"), NULL)) { + if (method != MicroOcpp::Method::POST) { + return 405; + } struct mg_str id = mg_http_var(query, mg_str("id")); if (!id.buf) { snprintf(resp_body, resp_body_size, "missing id"); @@ -289,6 +305,43 @@ int mocpp_api2_call(const char *uri_raw, size_t uri_raw_len, MicroOcpp::Method m "no action taken (EVSE not authorized)"); return 200; + } else if (mg_match(uri, mg_str("/memory/info"), NULL)) { + #if MO_OVERRIDE_ALLOCATION && MO_ENABLE_HEAP_PROFILER + { + if (method != MicroOcpp::Method::GET) { + return 405; + } + + int ret = mo_mem_write_stats_json(resp_body, resp_body_size); + if (ret < 0 || ret >= resp_body_size) { + snprintf(resp_body, resp_body_size, "internal error"); + return 500; + } + + return 200; + } + #else + { + snprintf(resp_body, resp_body_size, "memory profiler disabled"); + return 404; + } + #endif + } else if (mg_match(uri, mg_str("/memory/reset"), NULL)) { + #if MO_OVERRIDE_ALLOCATION && MO_ENABLE_HEAP_PROFILER + { + if (method != MicroOcpp::Method::POST) { + return 405; + } + + MO_MEM_RESET(); + } + #else + { + snprintf(resp_body, resp_body_size, "memory profiler disabled"); + return 404; + } + #endif + } return 404; diff --git a/src/net_mongoose.cpp b/src/net_mongoose.cpp index 6dae37c..e203279 100644 --- a/src/net_mongoose.cpp +++ b/src/net_mongoose.cpp @@ -120,7 +120,7 @@ void http_serve(struct mg_connection *c, int ev, void *ev_data) { mg_http_reply(c, 200, final_headers, serialized.c_str()); return; } else if (strncmp(message_data->uri.buf, "/api", strlen("api")) == 0) { - #define RESP_BUF_SIZE 1024 + #define RESP_BUF_SIZE 8192 char resp_buf [RESP_BUF_SIZE]; //replace endpoint-body separator by null From 7a8cba2aa38bdc17e304831ac93c0df6d7c88d09 Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Sat, 12 Oct 2024 09:54:14 +0200 Subject: [PATCH 5/6] fix /memory/reset status code --- src/api.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api.cpp b/src/api.cpp index 08bc18d..054f37c 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -334,6 +334,7 @@ int mocpp_api2_call(const char *uri_raw, size_t uri_raw_len, MicroOcpp::Method m } MO_MEM_RESET(); + return 200; } #else { From f226cc72038a7d035e7cceeda9e7f1b3a90e3dfe Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Sun, 13 Oct 2024 07:07:30 +0200 Subject: [PATCH 6/6] update dependencies --- lib/MicroOcpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/MicroOcpp b/lib/MicroOcpp index 56f7566..942fb88 160000 --- a/lib/MicroOcpp +++ b/lib/MicroOcpp @@ -1 +1 @@ -Subproject commit 56f7566409ae74b5cf4829fd6346e7e76a2d6835 +Subproject commit 942fb88aa736a5f99d1a24c11fe657c49af2c7ea