Merge pull request #34 from Qyon/master_sq9mdd

Properly escape JSON
master_sq9mdd refs/heads/master-2021-06-11T050359
Rysiek Labus (SQ9MDD) 2021-06-11 07:02:26 +02:00 zatwierdzone przez GitHub
commit 832fe1d15c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 23 dodań i 19 usunięć

Wyświetl plik

@ -26,7 +26,8 @@ lib_deps =
Adafruit GFX Library
Adafruit Unified Sensor
https://github.com/SQ9MDD/AXP202X_Library.git
SparkFun u-blox Arduino Library
SparkFun u-blox Arduino Library
bblanchon/ArduinoJson
build_flags =
-Wl,--gc-sections,--relax
-D 'KISS_PROTOCOL'
@ -118,6 +119,7 @@ build_flags =
-D ENABLE_BLUETOOTH
-D ENABLE_SYSLOG
-D 'SYSLOG_IP="192.168.0.102"'
-D DEVELOPMENT_DEBUG
lib_deps =
${env.lib_deps}
arcao/Syslog

Wyświetl plik

@ -733,7 +733,7 @@ void setup(){
#ifdef ENABLE_WIFI
webServerCfg = {.callsign = Tcall};
xTaskCreate(taskWebServer, "taskWebServer", 42000, (void*)(&webServerCfg), 1, nullptr);
xTaskCreate(taskWebServer, "taskWebServer", 12000, (void*)(&webServerCfg), 1, nullptr);
writedisplaytext("LoRa-APRS","","Init:","WiFi task started"," =:-) ","");
#endif

Wyświetl plik

@ -3,6 +3,8 @@
#include "preference_storage.h"
#include "syslog_log.h"
#include <time.h>
#include <ArduinoJson.h>
/**
* @see board_build.embed_txtfiles in platformio.ini
*/
@ -15,7 +17,7 @@ extern const char web_js_js_end[] asm("_binary_data_embed_js_js_out_end");
QueueHandle_t webListReceivedQueue = nullptr;
std::list <tReceivedPacketData*> receivedPackets;
const int MAX_RECEIVED_LIST_SIZE = 50;
const int MAX_RECEIVED_LIST_SIZE = 10;
String apSSID = "";
String apPassword = "xxxxxxxxxx";
@ -36,8 +38,12 @@ void sendCacheHeader() { server.sendHeader("Cache-Control", "max-age=3600"); }
void sendGzipHeader() { server.sendHeader("Content-Encoding", "gzip"); }
String jsonEscape(String s){
s.replace("\"", "\\\"");
s.replace("\\", "\\\\");
s.replace("\\", "\\\\");
s.replace("\"", "\\\"");
s.replace("\x7f", "\\\x7f");
for(char i = 0; i < 0x1f; i++){
s.replace(String(i), "\\" + String((char)i));
}
return s;
}
@ -151,24 +157,20 @@ void handle_Cfg() {
}
void handle_ReceivedList() {
String jsonData = "{\"received\": [";
auto count = receivedPackets.size();
DynamicJsonDocument doc(MAX_RECEIVED_LIST_SIZE * 500);
JsonObject root = doc.to<JsonObject>();
auto received = root.createNestedArray("received");
for (auto element: receivedPackets){
jsonData += "{";
char buf[64];
strftime(buf, 64, "%Y.%m.%d %H:%M:%S", &element->rxTime);
jsonData += jsonLineFromString("time", buf);
jsonData += jsonLineFromString("packet", element->packet->c_str());
jsonData += jsonLineFromInt("rssi", element->RSSI);
jsonData += jsonLineFromInt("snr", element->SNR, true);
jsonData += "}";
count--;
if (count){
jsonData += ",";
}
auto packet_data = received.createNestedObject();
packet_data["time"] = String(buf);
packet_data["packet"] = element->packet->c_str();
packet_data["rssi"] = element->RSSI;
packet_data["snr"] = element->SNR / 10.0f;
}
jsonData += "]}";
server.send(200,"application/json", jsonData);
server.send(200,"application/json", doc.as<String>());
}
void handle_SaveAPRSCfg() {