🪰 Fixes payload offset bug

This commit is contained in:
Rune Harlyk
2024-06-28 02:16:39 +02:00
committed by Rune Harlyk
parent adf71187c6
commit e8f48f7427
+7 -7
View File
@@ -29,14 +29,11 @@ const char* getEventName(const char* msg) {
}
const char* getEventPayload(const char* msg) {
const char* start = strchr(msg + 4, '\"') - 1;
const char* start = strchr(msg + 2, '[');
const char* end = msg + strlen(msg) - 1;
if (*start == '\"') {
if (*start == '[') {
start++;
}
if (*(end - 1) == '\"') {
end--;
}
int len = end - start;
if (len < 0) return nullptr;
char* payload = new char[len + 1];
@@ -83,8 +80,12 @@ esp_err_t EventSocket::onFrame(PsychicWebSocketRequest *request, httpd_ws_frame
ESP_LOGV("EventSocket", "ws[%s][%u] opcode[%d]", request->client()->remoteIP().toString().c_str(),
request->client()->socket(), frame->type);
if (frame->type == HTTPD_WS_TYPE_TEXT)
if (frame->type != HTTPD_WS_TYPE_TEXT)
{
ESP_LOGE("EventSocket", "Unsupported frame type");
return ESP_OK;
}
ESP_LOGV("EventSocket", "Received message: %s", (char *)frame->payload);
char* msg = (char *)frame->payload;
@@ -129,7 +130,6 @@ esp_err_t EventSocket::onFrame(PsychicWebSocketRequest *request, httpd_ws_frame
handleEventCallbacks(event, jsonObject, request->client()->socket());
return ESP_OK;
}
}
return ESP_OK;
}