Skip to content
Snippets Groups Projects
Commit 4d32668b authored by Cyril Danilevski's avatar Cyril Danilevski :scooter:
Browse files

Handle invalid mpod responses in REST API

parent b31ac2ad
No related branches found
No related tags found
1 merge request!6Handle invalid channel replies
Pipeline #166080 passed
......@@ -142,6 +142,11 @@ bool MPOD::message(const SNMP::Message *message) {
// that far.
const char *channel = strrchr(varbind->getName(), '.') + 1;
_channel = atoi(channel);
// MPOD SNMP channel 0 does not exist (starts from 1; U0 is 1).
// Mark the channel as 0 if invalid data was received.
// This can be used later to validate a sent request.
_channel = found ? _channel : 0;
}
// Return true if nodes found, that means this is a valid response from MPOD
return found;
......
......@@ -161,7 +161,7 @@ void sendSNMP() {
if (output != NONE && channel != 0) {
setChannelStateAndWait(&ipAddr, channel, output);
success = true; // validates input parameters, not MPOD status, reported separately
success = mpod.getChannel() ? true : false;
}
String http_msg = "{\n";
......@@ -285,7 +285,12 @@ void pollMPODChannel() {
delay(MPOD_UPDATE_LATENCY);
snmp.loop(); // Force loop to update now
ret = mpod.toJSON();
if (mpod.getChannel()) {
ret = mpod.toJSON();
} else {
ret = "\"reason\": \"Invalid channel\"";
channel = 0;
}
}
String http_msg = "{\n";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment