Add internal function 'WSContentSendRaw_P' (#23641)

This commit is contained in:
Theo Arends 2025-07-07 14:27:45 +02:00
parent 9e7be254c2
commit 59c80254cd
7 changed files with 29 additions and 21 deletions

View File

@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- Berry f-strings now support ':' in expression (#23618) - Berry f-strings now support ':' in expression (#23618)
- Universal display driver for ZJY169S0800TG01 ST7789 280x240 (#23638) - Universal display driver for ZJY169S0800TG01 ST7789 280x240 (#23638)
- Commands `LoRaWanDecoder "` and `LoRaWanName "` to clear name (#23394) - Commands `LoRaWanDecoder "` and `LoRaWanName "` to clear name (#23394)
- Internal function 'WSContentSendRaw_P' (#23641)
### Breaking Changed ### Breaking Changed

View File

@ -116,7 +116,8 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm
## Changelog v15.0.1.1 ## Changelog v15.0.1.1
### Added ### Added
- Commands `LoRaWanDecoder "` and `LoRaWanName "` to clear name (#23394)[#23394](https://github.com/arendst/Tasmota/issues/23394) - Commands `LoRaWanDecoder "` and `LoRaWanName "` to clear name [#23394](https://github.com/arendst/Tasmota/issues/23394)
- Internal function 'WSContentSendRaw_P' [#23641](https://github.com/arendst/Tasmota/issues/23641)
- Universal display driver for ZJY169S0800TG01 ST7789 280x240 [#23638](https://github.com/arendst/Tasmota/issues/23638) - Universal display driver for ZJY169S0800TG01 ST7789 280x240 [#23638](https://github.com/arendst/Tasmota/issues/23638)
- NeoPool add Redox tank alarm [#19811](https://github.com/arendst/Tasmota/issues/19811) - NeoPool add Redox tank alarm [#19811](https://github.com/arendst/Tasmota/issues/19811)
- I2S additions [#23543](https://github.com/arendst/Tasmota/issues/23543) - I2S additions [#23543](https://github.com/arendst/Tasmota/issues/23543)

View File

@ -881,29 +881,39 @@ void WSContentFlush(void) {
/*-------------------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------------------*/
void _WSContentSendBufferChunk(const char* content) { void _WSContentSendBufferChunk_P(const char* content) {
int len = strlen(content); int len = strlen_P(content);
if (len < CHUNKED_BUFFER_SIZE) { // Append chunk buffer with small content if (len < CHUNKED_BUFFER_SIZE) { // Append chunk buffer with small content
Web.chunk_buffer += content; Web.chunk_buffer += (const __FlashStringHelper *)content;
len = Web.chunk_buffer.length(); len = Web.chunk_buffer.length();
} }
if (len >= CHUNKED_BUFFER_SIZE) { // Either content or chunk buffer is oversize if (len >= CHUNKED_BUFFER_SIZE) { // Either content or chunk buffer is oversize
WSContentFlush(); // Send chunk buffer before possible content oversize WSContentFlush(); // Send chunk buffer before possible content oversize
} }
if (strlen(content) >= CHUNKED_BUFFER_SIZE) { // Content is oversize len = strlen_P(content);
_WSContentSend(content); // Send content if (len >= CHUNKED_BUFFER_SIZE) { // Content is oversize
_WSContentSend(content, len); // Send content
} }
} }
/*-------------------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------------------*/
void WSContentSendRaw_P(const char* content) { // Content sent without formatting
if (nullptr == content || !strlen_P(content)) { return; }
WSContentSeparator(2); // Print separator on next WSContentSeparator(1)
_WSContentSendBufferChunk_P(content);
}
/*-------------------------------------------------------------------------------------------*/
void WSContentSend(const char* content, size_t size) { void WSContentSend(const char* content, size_t size) {
// To speed up transmission use chunked buffer if possible // To speed up transmission use chunked buffer if possible
if (size < CHUNKED_BUFFER_SIZE) { if (size < CHUNKED_BUFFER_SIZE) {
// Terminate non-terminated content // Terminate non-terminated content
char buffer[size +1]; char buffer[size +1];
strlcpy(buffer, content, sizeof(buffer)); // Terminate with '\0' strlcpy(buffer, content, sizeof(buffer)); // Terminate with '\0'
_WSContentSendBufferChunk(buffer); _WSContentSendBufferChunk_P(buffer);
} else { } else {
WSContentFlush(); // Flush chunk buffer WSContentFlush(); // Flush chunk buffer
_WSContentSend(content, size); _WSContentSend(content, size);
@ -917,10 +927,6 @@ void _WSContentSendBuffer(bool decimal, const char * formatP, va_list arg) {
if (content == nullptr) { return; } // Avoid crash if (content == nullptr) { return; } // Avoid crash
int len = strlen(content); int len = strlen(content);
if (0 == len) { return; } // No content
WSContentSeparator(2); // Print separator on next WSContentSeparator(1)
if (decimal && (D_DECIMAL_SEPARATOR[0] != '.')) { if (decimal && (D_DECIMAL_SEPARATOR[0] != '.')) {
for (uint32_t i = 0; i < len; i++) { for (uint32_t i = 0; i < len; i++) {
if ('.' == content[i]) { if ('.' == content[i]) {
@ -929,7 +935,7 @@ void _WSContentSendBuffer(bool decimal, const char * formatP, va_list arg) {
} }
} }
_WSContentSendBufferChunk(content); WSContentSendRaw_P(content);
free(content); free(content);
} }
@ -1009,14 +1015,14 @@ void WSContentSendStyle_P(const char* formatP, ...) {
WebColor(COL_CONSOLE_TEXT) // --c_csltxt WebColor(COL_CONSOLE_TEXT) // --c_csltxt
); );
WSContentSend_P(PSTR("%s"), HTTP_HEAD_STYLE1); WSContentSendRaw_P(HTTP_HEAD_STYLE1);
WSContentSend_P(PSTR("%s"), HTTP_HEAD_STYLE2); WSContentSendRaw_P(HTTP_HEAD_STYLE2);
#ifdef USE_WEB_STATUS_LINE_WIFI #ifdef USE_WEB_STATUS_LINE_WIFI
WSContentSend_P(PSTR("%s"), HTTP_HEAD_STYLE_WIFI); WSContentSendRaw_P(HTTP_HEAD_STYLE_WIFI);
#endif #endif
#if defined(USE_ZIGBEE) || defined(USE_LORAWAN_BRIDGE) #if defined(USE_ZIGBEE) || defined(USE_LORAWAN_BRIDGE)
WSContentSend_P(HTTP_HEAD_STYLE_ZIGBEE); WSContentSendRaw_P(HTTP_HEAD_STYLE_ZIGBEE);
#endif // USE_ZIGBEE #endif // USE_ZIGBEE
if (formatP != nullptr) { if (formatP != nullptr) {
// This uses char strings. Be aware of sending %% if % is needed // This uses char strings. Be aware of sending %% if % is needed

View File

@ -159,7 +159,7 @@ void Z_Mapper::dumpInternals(void) const {
const char *fname = device.friendlyName; const char *fname = device.friendlyName;
if (fname != nullptr) { if (fname != nullptr) {
WSContentSend_P(PSTR("%s"), EscapeJSONString(fname).c_str()); WSContentSendRaw_P( EscapeJSONString(fname).c_str());
} else { } else {
WSContentSend_P(PSTR("0x%04X"), device.shortaddr); WSContentSend_P(PSTR("0x%04X"), device.shortaddr);
} }

View File

@ -1773,7 +1773,7 @@ void UfsEditor(void) {
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_UFS "UfsEditor: read=%d"), l); AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_UFS "UfsEditor: read=%d"), l);
if (l < 0) { break; } if (l < 0) { break; }
buf[l] = '\0'; buf[l] = '\0';
WSContentSend_P(PSTR("%s"), HtmlEscape((char*)buf).c_str()); WSContentSendRaw_P( HtmlEscape((char*)buf).c_str());
filelen -= l; filelen -= l;
} }
fp.close(); fp.close();

View File

@ -800,7 +800,7 @@ extern "C" {
const char *msg = be_tostring(vm, 2); const char *msg = be_tostring(vm, 2);
be_pop(vm, top); // avoid Error be_top is non zero message be_pop(vm, top); // avoid Error be_top is non zero message
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
WSContentSend_P(PSTR("%s"), msg); WSContentSendRaw_P( msg);
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
be_return_nil(vm); // Return nil when something goes wrong be_return_nil(vm); // Return nil when something goes wrong
} }

View File

@ -249,7 +249,7 @@ extern "C" {
} else { } else {
html = (const char*) be_tocomptr(vm, 1); html = (const char*) be_tocomptr(vm, 1);
} }
WSContentSend_P(PSTR("%s"), html); WSContentSendRaw_P( html);
be_return_nil(vm); be_return_nil(vm);
} }
be_raise(vm, kTypeError, nullptr); be_raise(vm, kTypeError, nullptr);