From 293ae8064d753e6d38488b46d21cdc52a4a6e637 Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Tue, 31 Jan 2023 23:23:52 +0100 Subject: [PATCH] Berry webserver raw content (#17844) --- .../berry_tasmota/src/be_webserver_lib.c | 2 ++ .../xdrv_52_3_berry_webserver.ino | 29 +++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/libesp32/berry_tasmota/src/be_webserver_lib.c b/lib/libesp32/berry_tasmota/src/be_webserver_lib.c index 7f6d6f93a..ad7bcadd7 100644 --- a/lib/libesp32/berry_tasmota/src/be_webserver_lib.c +++ b/lib/libesp32/berry_tasmota/src/be_webserver_lib.c @@ -16,6 +16,7 @@ extern int w_webserver_state(bvm *vm); extern int w_webserver_check_privileged_access(bvm *vm); extern int w_webserver_redirect(bvm *vm); extern int w_webserver_content_start(bvm *vm); +extern int w_webserver_content_open(bvm *vm); extern int w_webserver_content_send(bvm *vm); extern int w_webserver_content_response(bvm *vm); extern int w_webserver_content_send_style(bvm *vm); @@ -42,6 +43,7 @@ module webserver (scope: global) { content_response, func(w_webserver_content_response) content_send_style, func(w_webserver_content_send_style) content_flush, func(w_webserver_content_flush) + content_open, func(w_webserver_content_open) content_start, func(w_webserver_content_start) content_stop, func(w_webserver_content_stop) content_button, func(w_webserver_content_button) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_webserver.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_webserver.ino index dd4e8384e..599548ac4 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_webserver.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_webserver.ino @@ -144,7 +144,7 @@ extern "C" { be_raise(vm, kTypeError, nullptr); } - // Berry: `webserver.content_start() -> nil` + // Berry: `webserver.content_start(title:string) -> nil` // int32_t w_webserver_content_start(struct bvm *vm); int32_t w_webserver_content_start(struct bvm *vm) { @@ -157,13 +157,36 @@ extern "C" { be_raise(vm, kTypeError, nullptr); } + // Berry: `webserver.content_open(http_code:int, mimetype:string) -> nil` + // + int32_t w_webserver_content_open(struct bvm *vm); + int32_t w_webserver_content_open(struct bvm *vm) { + int32_t argc = be_top(vm); // Get the number of arguments + if (argc >= 2 && be_isint(vm, 1) && be_isstring(vm, 2)) { + int32_t httpcode = be_toint(vm, 1); + const char * mimetype = be_tostring(vm, 2); + Webserver->client().flush(); + WSHeaderSend(); + Webserver->setContentLength(CONTENT_LENGTH_UNKNOWN); + Webserver->send(httpcode, mimetype, ""); + Web.chunk_buffer = ""; + be_return_nil(vm); + } + be_raise(vm, kTypeError, nullptr); + } + // Berry: `webserver.content_send(string) -> nil` // int32_t w_webserver_content_send(struct bvm *vm); int32_t w_webserver_content_send(struct bvm *vm) { int32_t argc = be_top(vm); // Get the number of arguments - if (argc >= 1 && be_isstring(vm, 1)) { - const char * html = be_tostring(vm, 1); + if (argc >= 1 && (be_isstring(vm, 1) || be_iscomptr(vm, 1))) { + const char * html; + if (be_isstring(vm, 1)) { + html = be_tostring(vm, 1); + } else { + html = (const char*) be_tocomptr(vm, 1); + } WSContentSend_P(PSTR("%s"), html); be_return_nil(vm); }