diff options
-rw-r--r-- | .github/workflows/build.yml | 4 | ||||
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | configure.ac | 34 | ||||
-rw-r--r-- | doc/install.md | 6 | ||||
-rw-r--r-- | src/IO/http.c | 14 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/decode.c | 90 |
7 files changed, 145 insertions, 10 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 870ca97b..b7ffaa3e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,7 +15,7 @@ jobs: - name: Update package lists run: sudo apt update - name: Install dependencies - run: sudo apt install -y libfltk1.3-dev libssl-dev libpng-dev libjpeg-dev libwebp-dev xvfb x11-apps x11-utils imagemagick + run: sudo apt install -y libfltk1.3-dev libssl-dev libpng-dev libjpeg-dev libwebp-dev libbrotli-dev xvfb x11-apps x11-utils imagemagick - name: autogen run: ./autogen.sh @@ -271,7 +271,7 @@ jobs: fetch-depth: 1 - uses: cygwin/cygwin-install-action@master with: - packages: gcc-core gcc-g++ autoconf automake make zlib-devel mbedtls-devel libfltk-devel libiconv-devel libpng-devel libjpeg-devel libwebp-devel libgif-devel + packages: gcc-core gcc-g++ autoconf automake make zlib-devel mbedtls-devel libfltk-devel libiconv-devel libpng-devel libjpeg-devel libwebp-devel libgif-devel libbrotli-devel - shell: C:\cygwin\bin\bash.exe --login --norc -eo pipefail -o igncr '{0}' run: | set -x @@ -6,6 +6,11 @@ Here we list changes that are relatively significant and/or visible to the user. For a history of changes in full detail, see our Git repository at https://github.com/dillo-browser/dillo +dillo-3.3.0 [Unreleased] + ++- Add optional support for brotli (br) content encoding. + Patches: Rodrigo Arias Mallo + dillo-3.2.0 [Jan 18, 2025] +- Add new_tab_page option to open a custom new tab page. diff --git a/configure.ac b/configure.ac index fd5c8faa..08fa1f32 100644 --- a/configure.ac +++ b/configure.ac @@ -107,6 +107,11 @@ AC_ARG_ENABLE([mbedtls], [enable_mbedtls=$enableval], [enable_mbedtls=yes]) +AC_ARG_ENABLE([brotli], + [AS_HELP_STRING([--disable-brotli], [Disable support for brotli encoding])], + [enable_brotli=$enableval], + [enable_brotli=yes]) + AC_ARG_WITH([ca-certs-file], [AS_HELP_STRING([--with-ca-certs-file=FILE], [Specify where to find a bundle of trusted CA certificates for TLS])], CA_CERTS_FILE=$withval) @@ -332,6 +337,33 @@ else fi dnl --------------- +dnl Test for brotli +dnl --------------- +dnl +if test "x$enable_brotli" = "xyes"; then + AC_CHECK_HEADER(brotli/decode.h, brotli_ok=yes, brotli_ok=no) + + if test "x$brotli_ok" = "xyes"; then + old_libs="$LIBS" + AC_CHECK_LIB(brotlidec, BrotliDecoderVersion, brotli_ok=yes, brotli_ok=no) + LIBS="$old_libs" + + if test "x$brotli_ok" = "xyes"; then + BROTLI_LIBS="-lbrotlidec" + else + AC_MSG_WARN([*** libbrotlidec not found. Disabling brotli encoding.***]) + fi + else + AC_MSG_WARN([*** brotli/decode.h not found. Disabling brotli encoding.***]) + fi + +fi + +if test "x$brotli_ok" = "xyes"; then + AC_DEFINE([ENABLE_BROTLI], [1], [Enable brotli encoding]) +fi + +dnl --------------- dnl Test for libpng dnl --------------- dnl @@ -742,6 +774,7 @@ AC_SUBST(LIBPNG_LIBS) AC_SUBST(LIBPNG_CFLAGS) AC_SUBST(LIBWEBP_LIBS) AC_SUBST(LIBZ_LIBS) +AC_SUBST(BROTLI_LIBS) AC_SUBST(LIBSSL_LIBS) AC_SUBST(LIBPTHREAD_LIBS) AC_SUBST(LIBPTHREAD_LDFLAGS) @@ -793,6 +826,7 @@ _AS_ECHO([ PNG enabled : ${png_ok}]) _AS_ECHO([ GIF enabled : ${enable_gif}]) _AS_ECHO([ SVG enabled : ${enable_svg}]) _AS_ECHO([ WEBP enabled : ${enable_webp}]) +_AS_ECHO([ Brotli enabled : ${enable_brotli}]) _AS_ECHO([]) _AS_ECHO([ HTML tests : ${html_tests_ok}]) _AS_ECHO([]) diff --git a/doc/install.md b/doc/install.md index 7a0250eb..c26365af 100644 --- a/doc/install.md +++ b/doc/install.md @@ -35,7 +35,7 @@ packages to build Dillo: ```sh $ sudo apt install gcc g++ autoconf automake make zlib1g-dev \ libfltk1.3-dev libssl-dev libc6-dev \ - libpng-dev libjpeg-dev libwebp-dev + libpng-dev libjpeg-dev libwebp-dev libbrotli-dev ``` If you prefer to use mbedTLS, replace `libssl-dev` with @@ -170,7 +170,7 @@ will need the following dependencies to build Dillo with mbedTLS: ``` gcc-core gcc-g++ autoconf automake make zlib-devel mbedtls-devel libfltk-devel -libiconv-devel libpng-devel libjpeg-devel libwebp-devel +libiconv-devel libpng-devel libjpeg-devel libwebp-devel libbrotli-devel ``` **Note**: Dillo can also be built with OpenSSL (libssl-devel) but there is a @@ -187,7 +187,7 @@ xorg-server xinit You can also install all the dependencies from the command line with: ``` -setup-x86_64.exe -q -P gcc-core,gcc-g++,autoconf,automake,make,zlib-devel,mbedtls-devel,libfltk-devel,libiconv-devel,libpng-devel,libjpeg-devel,libwebp-devel,xorg-server,xinit +setup-x86_64.exe -q -P gcc-core,gcc-g++,autoconf,automake,make,zlib-devel,mbedtls-devel,libfltk-devel,libiconv-devel,libpng-devel,libjpeg-devel,libwebp-devel,libbrotli-devel,xorg-server,xinit ``` To build Dillo, follow the usual steps from a Cygwin shell: diff --git a/src/IO/http.c b/src/IO/http.c index 3c178bf1..d552664d 100644 --- a/src/IO/http.c +++ b/src/IO/http.c @@ -2,7 +2,7 @@ * File: http.c * * Copyright (C) 2000-2007 Jorge Arellano Cid <jcid@dillo.org> - * Copyright (C) 2024 Rodrigo Arias Mallo <rodarima@gmail.com> + * Copyright (C) 2024-2025 Rodrigo Arias Mallo <rodarima@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -425,7 +425,11 @@ static Dstr *Http_make_query_str(DilloWeb *web, bool_t use_proxy, bool_t use_tls "User-Agent: %s\r\n" "Accept: %s\r\n" "%s" /* language */ - "Accept-Encoding: gzip, deflate\r\n" + "Accept-Encoding: gzip, deflate" +#ifdef ENABLE_BROTLI + ", br" +#endif + "\r\n" "%s" /* auth */ "DNT: 1\r\n" "%s" /* proxy auth */ @@ -449,7 +453,11 @@ static Dstr *Http_make_query_str(DilloWeb *web, bool_t use_proxy, bool_t use_tls "User-Agent: %s\r\n" "Accept: %s\r\n" "%s" /* language */ - "Accept-Encoding: gzip, deflate\r\n" + "Accept-Encoding: gzip, deflate" +#ifdef ENABLE_BROTLI + ", br" +#endif + "\r\n" "%s" /* auth */ "DNT: 1\r\n" "%s" /* proxy auth */ diff --git a/src/Makefile.am b/src/Makefile.am index bc3a2b37..b34745a7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,7 +21,7 @@ dillo_LDADD = \ $(top_builddir)/dw/libDw-core.a \ $(top_builddir)/lout/liblout.a \ @LIBJPEG_LIBS@ @LIBPNG_LIBS@ @LIBWEBP_LIBS@ @LIBFLTK_LIBS@ @LIBZ_LIBS@ \ - @LIBICONV_LIBS@ @LIBPTHREAD_LIBS@ @LIBX11_LIBS@ @LIBSSL_LIBS@ + @LIBICONV_LIBS@ @LIBPTHREAD_LIBS@ @LIBX11_LIBS@ @LIBSSL_LIBS@ @BROTLI_LIBS@ dillo_SOURCES = \ dillo.cc \ diff --git a/src/decode.c b/src/decode.c index 0e95f386..535a5971 100644 --- a/src/decode.c +++ b/src/decode.c @@ -2,6 +2,7 @@ * File: decode.c * * Copyright 2007-2008 Jorge Arellano Cid <jcid@dillo.org> + * Copyright 2025 Rodrigo Arias Mallo <rodarima@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -9,11 +10,17 @@ * (at your option) any later version. */ +#include "config.h" + #include <zlib.h> #include <iconv.h> #include <errno.h> #include <stdlib.h> /* strtol */ +#ifdef ENABLE_BROTLI +#include <brotli/decode.h> +#endif + #include "decode.h" #include "utf8.hh" #include "msg.h" @@ -232,6 +239,82 @@ static Dstr *Decode_deflate(Decode *dc, const char *instr, int inlen) return output; } +#ifdef ENABLE_BROTLI +/** + * Decode brotli compressed data in stream mode. + */ +static Dstr *Decode_brotli_process(Decode *dc, const char *instr, int inlen) +{ + Dstr *output = dStr_new(""); + BrotliDecoderState *st = (BrotliDecoderState *) dc->state; + + const uint8_t *next_in = (const uint8_t *) instr; + size_t avail_in = inlen; + BrotliDecoderResult res; + + _MSG("Decode_brotli_process inlen=%d\n", inlen); + + /* Handle empty case */ + if (avail_in == 0) + return output; + + do { + /* Always reset output buffer */ + uint8_t *next_out = (uint8_t *) dc->buffer; + size_t avail_out = bufsize; + + _MSG("Decode_brotli_process decoding %zd bytes\n", avail_in); + + res = BrotliDecoderDecompressStream(st, + &avail_in, &next_in, &avail_out, &next_out, NULL); + + _MSG("Decode_brotli_process res=%d\n", res); + + if (res == BROTLI_DECODER_RESULT_ERROR) { + MSG_ERR("brotli decompression error\n"); + break; + } + + size_t delta = bufsize - avail_out; + _MSG("Decode_brotli_process delta=%zd\n", delta); + dStr_append_l(output, dc->buffer, delta); + + } while (res == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT); + + _MSG("Decode_brotli_process exitting with res=%d\n", res); + + return output; +} + +static void Decode_brotli_free(Decode *dc) +{ + BrotliDecoderState *st = (BrotliDecoderState *) dc->state; + BrotliDecoderDestroyInstance(st); + + dFree(dc->buffer); +} + +static Decode *Decode_brotli_init(void) +{ + BrotliDecoderState *st = BrotliDecoderCreateInstance(NULL, NULL, NULL); + if (st == NULL) { + MSG_ERR("Cannot create brotli decoder instance\n"); + return NULL; + } + + Decode *dc = dNew0(Decode, 1); + + dc->buffer = dNew(char, bufsize); + dc->state = st; + dc->leftover = NULL; /* not used */ + dc->decode = Decode_brotli_process; + dc->free = Decode_brotli_free; + + return dc; +} +#endif /* ENABLE_BROTLI */ + + /** * Translate to desired character set (UTF-8) */ @@ -322,7 +405,7 @@ static Decode *Decode_content_init_common(void) } /** - * Initialize content decoder. Currently handles 'gzip' and 'deflate'. + * Initialize content decoder. Currently handles 'gzip', 'deflate' and 'br'. */ Decode *a_Decode_content_init(const char *format) { @@ -348,6 +431,11 @@ Decode *a_Decode_content_init(const char *format) inflateInit(zs); dc->decode = Decode_deflate; +#ifdef ENABLE_BROTLI + } else if (!dStrAsciiCasecmp(format, "br")) { + _MSG("brotli data!\n"); + dc = Decode_brotli_init(); +#endif } else { MSG("Content-Encoding '%s' not recognized.\n", format); } |