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

Validate JSON and routes

parent f47b91f1
No related branches found
No related tags found
No related merge requests found
Pipeline #163253 passed
......@@ -129,15 +129,21 @@ void sendSNMP() {
uint16_t channel = 0;
bool success = false;
String argName;
String argVal;
for (uint8_t i = 0; i < restServer.args(); i++) {
if (restServer.argName(i) == "output") {
if (restServer.arg(i) == "on") {
argName = restServer.argName(i);
argName.toLowerCase();
argVal = restServer.arg(i);
if (argName == "output") {
argVal.toLowerCase();
if (argVal == "on") {
output = ON;
} else if (restServer.arg(i) == "off") {
} else if (argVal == "off") {
output = OFF;
}
} else if (restServer.argName(i) == "ch") {
channel = restServer.arg(i).toInt();
} else if (argName == "ch") {
channel = argVal.toInt();
}
}
......@@ -156,7 +162,7 @@ void sendSNMP() {
http_msg += "\"success\":" + String(success);
if (success) {
http_msg += ",\n";
http_msg += ",\n\"status\":";
http_msg += mpod.toJSON();
}
......@@ -171,13 +177,21 @@ void powerGroup() {
String ret;
bool success = false;
String argName;
String argVal;
for (uint8_t i = 0; i < restServer.args(); i++) {
if (restServer.argName(i) == "output") {
if (restServer.arg(i) == "on" || restServer.arg(i) == "off") {
output = restServer.arg(i);
argName = restServer.argName(i);
argName.toLowerCase();
argVal = restServer.arg(i);
argVal.toLowerCase();
if (argName == "output") {
if (argVal == "on" || argVal == "off") {
output = argVal;
}
} else if (restServer.argName(i) == "group") {
group = restServer.arg(i);
} else if (argName == "group") {
argVal.toUpperCase(); // Uppercase to match Karabo definitions
group = argVal;
}
}
......@@ -227,12 +241,10 @@ void pollMPODChannel() {
}
String http_msg = "{\n";
http_msg += "\"status\": ";
http_msg += ret;
http_msg += ",\"success\": ";
http_msg += channel ? 1 : 0;
http_msg +=
",\"channel\": "; // TODO: test with invalid channel (request w/o "ch" arg). JSON invalid.
http_msg += channel;
http_msg += "\n}";
restServer.send(channel ? 200 : 406, "text/json", http_msg);
......
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