From 61eca9449c7eb574ec01f871a6db20b5cb833f24 Mon Sep 17 00:00:00 2001 From: Tim Wilkinson Date: Mon, 14 Oct 2024 09:47:18 -0700 Subject: [PATCH] Use new ucode zlib library (#1629) --- configs/common.config | 1 + files/app/config.uc | 2 +- files/app/root.ut | 25 +++++-------------------- patches/761-ucode-zlib.patch | 13 +++++++++++++ patches/series | 1 + 5 files changed, 21 insertions(+), 21 deletions(-) create mode 100755 patches/761-ucode-zlib.patch diff --git a/configs/common.config b/configs/common.config index 129245c1..dbda60ee 100644 --- a/configs/common.config +++ b/configs/common.config @@ -160,6 +160,7 @@ CONFIG_PACKAGE_ubi-utils=y CONFIG_PACKAGE_ucode-mod-log=y CONFIG_PACKAGE_ucode-mod-math=y CONFIG_PACKAGE_ucode-mod-resolv=y +CONFIG_PACKAGE_ucode-mod-zlib=y CONFIG_PACKAGE_uhttpd=y CONFIG_PACKAGE_uhttpd-mod-ucode=y CONFIG_PACKAGE_vtun=y diff --git a/files/app/config.uc b/files/app/config.uc index a6168a2e..07bdf722 100755 --- a/files/app/config.uc +++ b/files/app/config.uc @@ -33,7 +33,7 @@ import * as hardware from "aredn.hardware"; -export const debug = true; +export const debug = false; export const application = "/app"; export let preload = true; diff --git a/files/app/root.ut b/files/app/root.ut index 991047ad..c82bb8fd 100644 --- a/files/app/root.ut +++ b/files/app/root.ut @@ -39,6 +39,7 @@ import * as math from "math"; import * as uci from "uci"; import * as ubus from "ubus"; import * as log from "log"; +import * as zlib from "zlib"; import * as lucihttp from "lucihttp"; import * as configuration from "aredn.configuration"; import * as hardware from "aredn.hardware"; @@ -575,31 +576,15 @@ global.handle_request = function(env) res = `
ERROR: ${e.message}
${e.stacktrace[0].context}
`; } if (!response.override) { - let datafile = null; + let gzip = false; if (env.HTTP_ACCEPT_ENCODING && index(env.HTTP_ACCEPT_ENCODING, "gzip") !== -1 && config.compress) { - const r = fs.open("/dev/urandom"); - if (r) { - const rid = r.read(8); - r.close(); - datafile = `/tmp/uhttpd.${hexenc(rid)}`; - const x = fs.open(datafile, "wx"); - if (x) { - x.write(res); - x.close(); - const z = fs.popen("exec /bin/gzip -c " + datafile); - res = z.read("all"); - z.close(); - fs.unlink(datafile); - } - else { - datafile = null; - } - } + gzip = true; + res = zlib.deflate(res, true); } response.headers["Content-Length"] = `${length(res)}`; uhttpd.send( `Status: ${response.statusCode} OK\r\n`, - (datafile ? `Content-Encoding: gzip\r\n` : ``), + (gzip ? `Content-Encoding: gzip\r\n` : ``), join("", map(keys(response.headers), k => k + ": " + response.headers[k] + "\r\n")), "\r\n", res diff --git a/patches/761-ucode-zlib.patch b/patches/761-ucode-zlib.patch new file mode 100755 index 00000000..3083fe09 --- /dev/null +++ b/patches/761-ucode-zlib.patch @@ -0,0 +1,13 @@ +--- a/package/utils/ucode/Makefile ++++ b/package/utils/ucode/Makefile +@@ -174,6 +174,10 @@ + uloop, ULOOP_SUPPORT, +libubox, \ + The uloop module allows ucode scripts to interact with OpenWrt uloop event loop implementation.)) + ++$(eval $(call UcodeModule, \ ++ zlib, ZLIB_SUPPORT, +zlib, \ ++ The zlib plugin implements compression.)) ++ + $(eval $(call BuildPackage,libucode)) + $(eval $(call BuildPackage,ucode)) + diff --git a/patches/series b/patches/series index 5e3b8bec..44268437 100644 --- a/patches/series +++ b/patches/series @@ -45,6 +45,7 @@ 752-mikrotik-nand-revert.patch 753-ubiquiti-2ac.patch 760-uhttp-ucode.patch +761-ucode-zlib.patch 800-upgrade-compatibility.patch 801-mikrotik-lhg-variants.patch 802-gpio-typo.patch