Rename handleSet to handleHttpApi

Clarify what this function does: it implements the legacy HTTP
API parser.
This commit is contained in:
Will Miles 2024-11-10 18:18:24 -05:00
parent 223b97b884
commit e570460cd9
9 changed files with 11 additions and 11 deletions

View File

@ -235,7 +235,7 @@ void handleRemote(uint8_t *data, size_t len);
//set.cpp //set.cpp
bool isAsterisksOnly(const char* str, byte maxLen); bool isAsterisksOnly(const char* str, byte maxLen);
void handleSettingsSet(AsyncWebServerRequest *request, byte subPage); void handleSettingsSet(AsyncWebServerRequest *request, byte subPage);
bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply=true); bool handleHttpApi(AsyncWebServerRequest *request, const String& req, bool apply=true);
//udp.cpp //udp.cpp
void notify(byte callMode, bool followUp=false); void notify(byte callMode, bool followUp=false);

View File

@ -608,7 +608,7 @@ static void decodeIRJson(uint32_t code)
cmdStr += tmp; cmdStr += tmp;
} }
fdo.clear(); // clear JSON buffer (it is no longer needed) fdo.clear(); // clear JSON buffer (it is no longer needed)
handleSet(nullptr, cmdStr, false); // no stateUpdated() call here handleHttpApi(nullptr, cmdStr, false); // no stateUpdated() call here
} }
} else { } else {
// command is JSON object (TODO: currently will not handle irApplyToAllSelected correctly) // command is JSON object (TODO: currently will not handle irApplyToAllSelected correctly)

View File

@ -451,7 +451,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
if (httpwin) { if (httpwin) {
String apireq = "win"; apireq += '&'; // reduce flash string usage String apireq = "win"; apireq += '&'; // reduce flash string usage
apireq += httpwin; apireq += httpwin;
handleSet(nullptr, apireq, false); // may set stateChanged handleHttpApi(nullptr, apireq, false); // may set stateChanged
} }
// Applying preset from JSON API has 2 cases: a) "pd" AKA "preset direct" and b) "ps" AKA "preset select" // Applying preset from JSON API has 2 cases: a) "pd" AKA "preset direct" and b) "ps" AKA "preset select"
@ -462,7 +462,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
if (!root[F("pd")].isNull() && stateChanged) { if (!root[F("pd")].isNull() && stateChanged) {
// a) already applied preset content (requires "seg" or "win" but will ignore the rest) // a) already applied preset content (requires "seg" or "win" but will ignore the rest)
currentPreset = root[F("pd")] | currentPreset; currentPreset = root[F("pd")] | currentPreset;
if (root["win"].isNull()) presetCycCurr = currentPreset; // otherwise presetCycCurr was set in handleSet() [set.cpp] if (root["win"].isNull()) presetCycCurr = currentPreset; // otherwise presetCycCurr was set in handleHttpApi() [set.cpp]
presetToRestore = currentPreset; // stateUpdated() will clear the preset, so we need to restore it after presetToRestore = currentPreset; // stateUpdated() will clear the preset, so we need to restore it after
DEBUG_PRINTF_P(PSTR("Preset direct: %d\n"), currentPreset); DEBUG_PRINTF_P(PSTR("Preset direct: %d\n"), currentPreset);
} else if (!root["ps"].isNull()) { } else if (!root["ps"].isNull()) {

View File

@ -109,7 +109,7 @@ static void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProp
} else { //HTTP API } else { //HTTP API
String apireq = "win"; apireq += '&'; // reduce flash string usage String apireq = "win"; apireq += '&'; // reduce flash string usage
apireq += payloadStr; apireq += payloadStr;
handleSet(nullptr, apireq); handleHttpApi(nullptr, apireq);
} }
releaseJSONBufferLock(); releaseJSONBufferLock();
} }

View File

@ -183,7 +183,7 @@ void handlePresets()
String apireq = "win"; // reduce flash string usage String apireq = "win"; // reduce flash string usage
apireq += F("&IN&"); // internal call apireq += F("&IN&"); // internal call
apireq += httpwin; apireq += httpwin;
handleSet(nullptr, apireq, false); // may call applyPreset() via PL= handleHttpApi(nullptr, apireq, false); // may call applyPreset() via PL=
setValuesFromFirstSelectedSeg(); // fills legacy values setValuesFromFirstSelectedSeg(); // fills legacy values
changePreset = true; changePreset = true;
} else { } else {
@ -208,7 +208,7 @@ void handlePresets()
updateInterfaces(tmpMode); updateInterfaces(tmpMode);
} }
//called from handleSet(PS=) [network callback (sObj is empty), IR (irrational), deserializeState, UDP] and deserializeState() [network callback (filedoc!=nullptr)] //called from handleHttpApi(PS=) [network callback (sObj is empty), IR (irrational), deserializeState, UDP] and deserializeState() [network callback (filedoc!=nullptr)]
void savePreset(byte index, const char* pname, JsonObject sObj) void savePreset(byte index, const char* pname, JsonObject sObj)
{ {
if (!saveName) saveName = new char[33]; if (!saveName) saveName = new char[33];

View File

@ -162,7 +162,7 @@ static bool remoteJson(int button)
cmdStr += tmp; cmdStr += tmp;
} }
fdo.clear(); // clear JSON buffer (it is no longer needed) fdo.clear(); // clear JSON buffer (it is no longer needed)
handleSet(nullptr, cmdStr, false); // no stateUpdated() call here handleHttpApi(nullptr, cmdStr, false); // no stateUpdated() call here
stateUpdated(CALL_MODE_BUTTON); stateUpdated(CALL_MODE_BUTTON);
parsed = true; parsed = true;
} }

View File

@ -803,7 +803,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
//HTTP API request parser //HTTP API request parser
bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply) bool handleHttpApi(AsyncWebServerRequest *request, const String& req, bool apply)
{ {
if (!(req.indexOf("win") >= 0)) return false; if (!(req.indexOf("win") >= 0)) return false;

View File

@ -683,7 +683,7 @@ void handleNotifications()
if (udpIn[0] >= 'A' && udpIn[0] <= 'Z') { //HTTP API if (udpIn[0] >= 'A' && udpIn[0] <= 'Z') { //HTTP API
String apireq = "win"; apireq += '&'; // reduce flash string usage String apireq = "win"; apireq += '&'; // reduce flash string usage
apireq += (char*)udpIn; apireq += (char*)udpIn;
handleSet(nullptr, apireq); handleHttpApi(nullptr, apireq);
} else if (udpIn[0] == '{') { //JSON API } else if (udpIn[0] == '{') { //JSON API
DeserializationError error = deserializeJson(*pDoc, udpIn); DeserializationError error = deserializeJson(*pDoc, udpIn);
JsonObject root = pDoc->as<JsonObject>(); JsonObject root = pDoc->as<JsonObject>();

View File

@ -482,7 +482,7 @@ void initServer()
return; return;
} }
if(handleSet(request, request->url())) return; if(handleHttpApi(request, request->url())) return;
#ifndef WLED_DISABLE_ALEXA #ifndef WLED_DISABLE_ALEXA
if(espalexa.handleAlexaApiCall(request)) return; if(espalexa.handleAlexaApiCall(request)) return;
#endif #endif