Added Support to non JSON for WebQueryResponse

This commit is contained in:
Adrian Scillato 2022-04-09 05:35:17 -03:00 committed by GitHub
parent b35e392e76
commit 0bb83947e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 4 deletions

View File

@ -3164,15 +3164,22 @@ int WebQuery(char *buffer)
// Return received data to the user - Adds 900+ bytes to the code // Return received data to the user - Adds 900+ bytes to the code
const char* read = http.getString().c_str(); // File found at server - may need lot of ram or trigger out of memory! const char* read = http.getString().c_str(); // File found at server - may need lot of ram or trigger out of memory!
ResponseClear(); ResponseClear();
char text[2] = { 0 };
text[0] = '.';
Response_P(PSTR("{\"" D_CMND_WEBQUERY "\":")); Response_P(PSTR("{\"" D_CMND_WEBQUERY "\":"));
char text[2] = { 0 };
text[0] = *read++;
bool assume_json = (text[0] == '{') || (text[0] == '[');
if (!assume_json) { ResponseAppend_P(PSTR("\"")); }
while (text[0] != '\0') { while (text[0] != '\0') {
text[0] = *read++;
if (text[0] > 31) { // Remove control characters like linefeed if (text[0] > 31) { // Remove control characters like linefeed
if (ResponseAppend_P(text) == ResponseSize()) { break; }; if (assume_json) {
if (ResponseAppend_P(text) == ResponseSize()) { break; };
} else {
if (ResponseAppend_P(EscapeJSONString(text).c_str()) == ResponseSize()) { break; };
}
} }
text[0] = *read++;
} }
if (!assume_json) { ResponseAppend_P(PSTR("\"")); }
ResponseJsonEnd(); ResponseJsonEnd();
#ifdef USE_SCRIPT #ifdef USE_SCRIPT
extern uint8_t tasm_cmd_activ; extern uint8_t tasm_cmd_activ;