From nils.goroll at uplex.de Mon Aug 7 13:18:06 2023 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 7 Aug 2023 13:18:06 +0000 (UTC) Subject: [master] 957509b3a VRT_fail to be annoted with cold attribute as a codepath to be taken less likely Message-ID: <20230807131806.A9FBB113CC3@lists.varnish-cache.org> commit 957509b3ae179e60319e6b9cf49e190cb4bfecbe Author: David CARLIER Date: Mon Oct 31 16:31:37 2022 +0000 VRT_fail to be annoted with cold attribute as a codepath to be taken less likely diff --git a/include/vdef.h b/include/vdef.h index 36e4fa854..2df601119 100644 --- a/include/vdef.h +++ b/include/vdef.h @@ -241,6 +241,12 @@ int __llvm_gcov_flush(void); # define v_unused_ #endif +#if __GNUC_PREREQ__(4, 3) || defined(__clang__) +# define v_cold_ __attribute__((cold)) +#else +# define v_cold_ +#endif + /* VTIM API overhaul WIP */ typedef double vtim_mono; typedef double vtim_real; diff --git a/include/vrt.h b/include/vrt.h index 9dd7f044b..fedc26da7 100644 --- a/include/vrt.h +++ b/include/vrt.h @@ -678,7 +678,7 @@ VCL_VOID VRT_SetHdr(VRT_CTX, VCL_HEADER, const char *pfx, VCL_STRANDS); VCL_VOID VRT_handling(VRT_CTX, unsigned hand); unsigned VRT_handled(VRT_CTX); VCL_VOID VRT_trace(VRT_CTX, VCL_BOOL); -VCL_VOID VRT_fail(VRT_CTX, const char *fmt, ...) v_printflike_(2,3); +VCL_VOID VRT_fail(VRT_CTX, const char *fmt, ...) v_printflike_(2,3) v_cold_; VCL_VOID VRT_hashdata(VRT_CTX, VCL_STRANDS); VCL_VOID VRT_Rollback(VRT_CTX, VCL_HTTP); From dridi.boukelmoune at gmail.com Wed Aug 16 15:18:06 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Wed, 16 Aug 2023 15:18:06 +0000 (UTC) Subject: [master] c8bb41504 ban: Require valid header variables Message-ID: <20230816151806.04A9C64646@lists.varnish-cache.org> commit c8bb415047cb6edeb3ba89391c83f77f93809ee1 Author: Walid Boudebouda Date: Tue Aug 8 14:51:41 2023 +0200 ban: Require valid header variables We must ensure that we get a complete header name before evaluating a ban, so "req.http." should not be accepted. Refs #3962 diff --git a/bin/varnishd/cache/cache_ban_build.c b/bin/varnishd/cache/cache_ban_build.c index e9a699674..bab9ac79a 100644 --- a/bin/varnishd/cache/cache_ban_build.c +++ b/bin/varnishd/cache/cache_ban_build.c @@ -260,6 +260,9 @@ BAN_AddTest(struct ban_proto *bp, VSB_putc(bp->vsb, pv->tag); if (pv->flag & BANS_FLAG_HTTP) { + if (strlen(a1 + strlen(pv->name)) < 1) + return (ban_error(bp, + "Missing header name: \"%s\"", pv->name)); assert(BANS_HAS_ARG1_SPEC(pv->tag)); ban_parse_http(bp, a1 + strlen(pv->name)); } diff --git a/bin/varnishtest/tests/r03962.vtc b/bin/varnishtest/tests/r03962.vtc index 2874353a4..f92d0257a 100644 --- a/bin/varnishtest/tests/r03962.vtc +++ b/bin/varnishtest/tests/r03962.vtc @@ -10,4 +10,5 @@ varnish v1 -cliexpect {Unknown or unsupported field "obj.ageYY"} "ban obj.ageYY varnish v1 -cliexpect {Unknown or unsupported field "req.ur"} "ban req.ur ~ foobarbazzz" varnish v1 -cliexpect {Unknown or unsupported field "req.htt"} "ban req.htt ~ foobarbazzz" varnish v1 -cliexpect {Unknown or unsupported field "req.htt.XXYY"} "ban req.htt.XXYY ~ foobarbazzz" +varnish v1 -cliexpect {Missing header name: "obj.http."} "ban obj.http. ~ foobarbazzz" varnish v1 -cliok "ban req.http.XXYY ~ foobarbazzz" diff --git a/doc/changes.rst b/doc/changes.rst index 6b7746888..e16d7c22c 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -38,6 +38,10 @@ Varnish Cache NEXT (2023-09-15) .. PLEASE keep this roughly in commit order as shown by git-log / tig (new to old) +* Two bugs in the ban expression parser have been fixed where one of them + could lead to a panic if a ban expression with an empty header name was + issued (3962_) + * A bug has been fixed where ``unset bereq.body`` had no effect when used with a cached body (3914_) @@ -87,6 +91,7 @@ Varnish Cache NEXT (2023-09-15) .. _3908: https://github.com/varnishcache/varnish-cache/pull/3908 .. _3911: https://github.com/varnishcache/varnish-cache/issues/3911 .. _3914: https://github.com/varnishcache/varnish-cache/pull/3914 +.. _3962: https://github.com/varnishcache/varnish-cache/issues/3962 ================================ Varnish Cache 7.3.0 (2023-03-15) From dridi.boukelmoune at gmail.com Wed Aug 16 15:18:05 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Wed, 16 Aug 2023 15:18:05 +0000 (UTC) Subject: [master] a8cde64ad ban: Only accept exact variable name matches Message-ID: <20230816151805.DFC2964643@lists.varnish-cache.org> commit a8cde64ad7f6914b46dde6d23a29a05cada3938b Author: Walid Boudebouda Date: Wed Aug 2 10:54:12 2023 +0200 ban: Only accept exact variable name matches Ban expression variables that partially match standard variable names (ex: req.urlXX) should not be accepted, except for variables that take an HTTP header name as a suffix. Fixes #3962 diff --git a/bin/varnishd/cache/cache_ban_build.c b/bin/varnishd/cache/cache_ban_build.c index 28376f56c..e9a699674 100644 --- a/bin/varnishd/cache/cache_ban_build.c +++ b/bin/varnishd/cache/cache_ban_build.c @@ -245,9 +245,12 @@ BAN_AddTest(struct ban_proto *bp, if (bp->err != NULL) return (bp->err); - for (pv = pvars; pv->name != NULL; pv++) - if (!strncmp(a1, pv->name, strlen(pv->name))) + for (pv = pvars; pv->name != NULL; pv++) { + if (!(pv->flag & BANS_FLAG_HTTP) && !strcmp(a1, pv->name)) break; + if ((pv->flag & BANS_FLAG_HTTP) && !strncmp(a1, pv->name, strlen(pv->name))) + break; + } if (pv->name == NULL) return (ban_error(bp, diff --git a/bin/varnishtest/tests/r03962.vtc b/bin/varnishtest/tests/r03962.vtc new file mode 100644 index 000000000..2874353a4 --- /dev/null +++ b/bin/varnishtest/tests/r03962.vtc @@ -0,0 +1,13 @@ +varnishtest "ban expression object name prefixes" + +server s1 {} -start + +varnish v1 -vcl+backend {} -start + + +varnish v1 -cliexpect {Unknown or unsupported field "req.urlXX"} "ban req.urlXX ~ foobarbazzz" +varnish v1 -cliexpect {Unknown or unsupported field "obj.ageYY"} "ban obj.ageYY < 1d" +varnish v1 -cliexpect {Unknown or unsupported field "req.ur"} "ban req.ur ~ foobarbazzz" +varnish v1 -cliexpect {Unknown or unsupported field "req.htt"} "ban req.htt ~ foobarbazzz" +varnish v1 -cliexpect {Unknown or unsupported field "req.htt.XXYY"} "ban req.htt.XXYY ~ foobarbazzz" +varnish v1 -cliok "ban req.http.XXYY ~ foobarbazzz" From dridi.boukelmoune at gmail.com Thu Aug 17 06:07:07 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Thu, 17 Aug 2023 06:07:07 +0000 (UTC) Subject: [master] 1e10f10b8 miniobj: Allocate objects with a flexible array Message-ID: <20230817060707.74CCCB0225@lists.varnish-cache.org> commit 1e10f10b8c364262c0eebe6326d1133e5460c297 Author: Dridi Boukelmoune Date: Mon Jul 10 12:21:44 2023 +0200 miniobj: Allocate objects with a flexible array diff --git a/include/miniobj.h b/include/miniobj.h index 8babaa251..832998019 100644 --- a/include/miniobj.h +++ b/include/miniobj.h @@ -30,6 +30,17 @@ (to)->magic = (type_magic); \ } while (0) +#define ALLOC_FLEX_OBJ(to, fld, len, type_magic) \ + do { \ + v_static_assert( \ + sizeof *(to) == offsetof(typeof(*(to)), fld), \ + "the last field must be a flexible array"); \ + (to) = calloc(1, \ + sizeof *(to) + ((len) * sizeof *((to)->fld))); \ + if ((to) != NULL) \ + (to)->magic = (type_magic); \ + } while (0) + #define FREE_OBJ(to) \ do { \ ZERO_OBJ(&(to)->magic, sizeof (to)->magic); \ From nils.goroll at uplex.de Thu Aug 17 17:40:07 2023 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 17 Aug 2023 17:40:07 +0000 (UTC) Subject: [master] 264046f36 Mention req.ttl return to 'supported' also in changes.rst Message-ID: <20230817174007.32412A4E73@lists.varnish-cache.org> commit 264046f36b50776f5bb5fc28ed11c42d62e81901 Author: Nils Goroll Date: Thu Aug 17 19:38:22 2023 +0200 Mention req.ttl return to 'supported' also in changes.rst We did mention it in the release docs, but not in changes.rst diff --git a/doc/changes.rst b/doc/changes.rst index e16d7c22c..fb66ea442 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -1893,6 +1893,8 @@ VCL * Fixed ``obj.hits`` in ``vcl_hit`` (had been always 0) (2746_) +* req.ttl is fully supported again + .. _2746: https://github.com/varnishcache/varnish-cache/issues/2746 .. _2696: https://github.com/varnishcache/varnish-cache/issues/2696 .. _2694: https://github.com/varnishcache/varnish-cache/issues/2694 From dridi.boukelmoune at gmail.com Fri Aug 18 06:24:08 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Fri, 18 Aug 2023 06:24:08 +0000 (UTC) Subject: [master] 5498b039c miniobj: A flex array may start in struct padding Message-ID: <20230818062408.1E4296561D@lists.varnish-cache.org> commit 5498b039c3dfc25b8ca8ddc14c1f1822aff6cd4e Author: Dridi Boukelmoune Date: Thu Aug 17 10:22:03 2023 +0200 miniobj: A flex array may start in struct padding We lose the ability to check that fld is indeed the last field, but we never had that ability to begin with. diff --git a/include/miniobj.h b/include/miniobj.h index 832998019..7551cab53 100644 --- a/include/miniobj.h +++ b/include/miniobj.h @@ -32,11 +32,8 @@ #define ALLOC_FLEX_OBJ(to, fld, len, type_magic) \ do { \ - v_static_assert( \ - sizeof *(to) == offsetof(typeof(*(to)), fld), \ - "the last field must be a flexible array"); \ - (to) = calloc(1, \ - sizeof *(to) + ((len) * sizeof *((to)->fld))); \ + (to) = calloc(1, offsetof(typeof(*(to)), fld) + \ + ((len) * sizeof *((to)->fld))); \ if ((to) != NULL) \ (to)->magic = (type_magic); \ } while (0) From phk at FreeBSD.org Fri Aug 18 09:48:08 2023 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Fri, 18 Aug 2023 09:48:08 +0000 (UTC) Subject: [master] d44064920 Expose the VENC functions in libvarnishapi Message-ID: <20230818094808.E638B96565@lists.varnish-cache.org> commit d440649202b94dc27be0c5721ba960610c8c8725 Author: Poul-Henning Kamp Date: Fri Aug 18 09:46:54 2023 +0000 Expose the VENC functions in libvarnishapi diff --git a/lib/libvarnishapi/libvarnishapi.map b/lib/libvarnishapi/libvarnishapi.map index 87b374f2e..5fe72f3fb 100644 --- a/lib/libvarnishapi/libvarnishapi.map +++ b/lib/libvarnishapi/libvarnishapi.map @@ -28,7 +28,7 @@ * SUCH DAMAGE. */ -LIBVARNISHAPI_3.0 { /* 2021-09-15 release */ +LIBVARNISHAPI_3.1 { /* 2023-09-15 release */ global: # vas.c VAS_errtxt; @@ -44,6 +44,10 @@ LIBVARNISHAPI_3.0 { /* 2021-09-15 release */ VCS_Message; VCS_String; + # venc.c + VENC_Encode_Base64; + VENC_Decode_Base64; + # vsb.c VSB_bcat; VSB_cat; From phk at FreeBSD.org Fri Aug 18 09:48:09 2023 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Fri, 18 Aug 2023 09:48:09 +0000 (UTC) Subject: [master] f16f148f9 Use VENC instead of local b64 decoder. Message-ID: <20230818094809.15BC796568@lists.varnish-cache.org> commit f16f148f94db153e36fe8b31b2eb4057566103eb Author: Poul-Henning Kamp Date: Fri Aug 18 09:47:14 2023 +0000 Use VENC instead of local b64 decoder. diff --git a/bin/varnishncsa/Makefile.am b/bin/varnishncsa/Makefile.am index 08c8421e9..519f13342 100644 --- a/bin/varnishncsa/Makefile.am +++ b/bin/varnishncsa/Makefile.am @@ -8,9 +8,7 @@ bin_PROGRAMS = varnishncsa varnishncsa_SOURCES = \ varnishncsa.c \ - varnishncsa_options.h \ - b64.h \ - b64.c + varnishncsa_options.h varnishncsa_LDADD = \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ diff --git a/bin/varnishncsa/b64.c b/bin/varnishncsa/b64.c deleted file mode 100644 index 5d398f449..000000000 --- a/bin/varnishncsa/b64.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Written by Poul-Henning Kamp - * - * This file is in the public domain. - */ - -#include "config.h" - -#include -#include - -#include "b64.h" - -static const char b64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -static char i64[256]; - -void -VB64_init(void) -{ - int i; - const char *p; - - for (i = 0; i < 256; i++) - i64[i] = -1; - for (p = b64, i = 0; *p; p++, i++) - i64[(int)*p] = (char)i; - i64['='] = 0; -} - -int -VB64_decode(char *d, unsigned dlen, const char *s, const char *e) -{ - unsigned u, v, l; - int i; - - if (e == NULL) - e = s + strlen(s); - u = 0; - l = 0; - while (s < e) { - for (v = 0; s < e && v < 4; v++) { - i = i64[(int)*s++]; - if (i < 0) - return (-1); - u <<= 6; - u |= i; - } - for (v = 0; v < 3; v++) { - if (l >= dlen - 1) - return (-1); - *d = (u >> 16) & 0xff; - u <<= 8; - l++; - d++; - } - } - *d = '\0'; - return (0); -} - -#ifdef TEST_DRIVER - -#include // for test-prog - -const char *test1 = -"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz" -"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg" -"dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu" -"dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo" -"ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="; - -int -main(int argc, char **argv) -{ - int i; - char buf[BUFSIZ]; - unsigned l; - - (void)argc; - (void)argv; - - VB64_init(); - l = sizeof buf; - VB64_decode(buf, l, test1, NULL); - printf("%s\n", buf); - return (0); -} -#endif diff --git a/bin/varnishncsa/b64.h b/bin/varnishncsa/b64.h deleted file mode 100644 index 6b0aab35b..000000000 --- a/bin/varnishncsa/b64.h +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2011 Varnish Software AS - * All rights reserved. - * - * Author: Poul-Henning Kamp - * - * SPDX-License-Identifier: BSD-2-Clause - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -void VB64_init(void); -int VB64_decode(char *d, unsigned dlen, const char *s, const char *e); diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c index 37b27834b..0ad6a8708 100644 --- a/bin/varnishncsa/varnishncsa.c +++ b/bin/varnishncsa/varnishncsa.c @@ -58,10 +58,10 @@ #include "vdef.h" -#include "b64.h" #include "vapi/vsl.h" #include "vapi/voptget.h" #include "vas.h" +#include "venc.h" #include "vsb.h" #include "vut.h" #include "vqueue.h" @@ -361,21 +361,24 @@ format_requestline(const struct format *format) static int v_matchproto_(format_f) format_auth(const struct format *format) { - char buf[128]; + struct vsb *vsb = VSB_new_auto(); + AN(vsb); char *q; if (CTX.frag[F_auth].gen != CTX.gen || - VB64_decode(buf, sizeof buf, CTX.frag[F_auth].b, - CTX.frag[F_auth].e)) { + VENC_Decode_Base64(vsb, CTX.frag[F_auth].b, CTX.frag[F_auth].e)) { + VSB_destroy(&vsb); if (format->string == NULL) return (-1); VSB_quote(CTX.vsb, format->string, -1, CTX.quote_how); return (0); } - q = strchr(buf, ':'); + AZ(VSB_finish(vsb)); + q = strchr(VSB_data(vsb), ':'); if (q != NULL) *q = '\0'; - VSB_quote(CTX.vsb, buf, -1, CTX.quote_how); + VSB_quote(CTX.vsb, VSB_data(vsb), -1, CTX.quote_how); + VSB_destroy(&vsb); return (1); } @@ -1160,7 +1163,6 @@ main(int argc, char * const *argv) VTAILQ_INIT(&CTX.watch_vsl); CTX.vsb = VSB_new_auto(); AN(CTX.vsb); - VB64_init(); CTX.quote_how = VSB_QUOTE_ESCHEX; REPLACE(CTX.missing_string, "-"); REPLACE(CTX.missing_int, "-"); From dridi.boukelmoune at gmail.com Fri Aug 18 10:42:06 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Fri, 18 Aug 2023 10:42:06 +0000 (UTC) Subject: [master] 6939fa2fd build: Retain LIBVARNISHAPI_3.0 symbols Message-ID: <20230818104206.6E9AB9B5E0@lists.varnish-cache.org> commit 6939fa2fdda8e5aae532b8ee2b0d26b844a72864 Author: Dridi Boukelmoune Date: Fri Aug 18 12:37:45 2023 +0200 build: Retain LIBVARNISHAPI_3.0 symbols diff --git a/lib/libvarnishapi/libvarnishapi.map b/lib/libvarnishapi/libvarnishapi.map index 5fe72f3fb..87a23a2b6 100644 --- a/lib/libvarnishapi/libvarnishapi.map +++ b/lib/libvarnishapi/libvarnishapi.map @@ -28,7 +28,7 @@ * SUCH DAMAGE. */ -LIBVARNISHAPI_3.1 { /* 2023-09-15 release */ +LIBVARNISHAPI_3.0 { /* 2021-09-15 release */ global: # vas.c VAS_errtxt; @@ -44,10 +44,6 @@ LIBVARNISHAPI_3.1 { /* 2023-09-15 release */ VCS_Message; VCS_String; - # venc.c - VENC_Encode_Base64; - VENC_Decode_Base64; - # vsb.c VSB_bcat; VSB_cat; @@ -166,3 +162,13 @@ LIBVARNISHAPI_3.1 { /* 2023-09-15 release */ local: *; }; + +LIBVARNISHAPI_3.1 { /* 2023-09-15 release */ + global: + # venc.c + VENC_Encode_Base64; + VENC_Decode_Base64; + + local: + *; +}; From dridi.boukelmoune at gmail.com Fri Aug 18 10:42:06 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Fri, 18 Aug 2023 10:42:06 +0000 (UTC) Subject: [master] b22da84ee build: Bump libvarnishapi soname to 3.1.0 Message-ID: <20230818104206.7CBEB9B5E3@lists.varnish-cache.org> commit b22da84ee312a847c6ac9f27ae62a040f7b8fcda Author: Dridi Boukelmoune Date: Fri Aug 18 12:40:05 2023 +0200 build: Bump libvarnishapi soname to 3.1.0 diff --git a/lib/libvarnishapi/Makefile.am b/lib/libvarnishapi/Makefile.am index 264beb1da..b278eb6d9 100644 --- a/lib/libvarnishapi/Makefile.am +++ b/lib/libvarnishapi/Makefile.am @@ -8,7 +8,7 @@ AM_CPPFLAGS = \ lib_LTLIBRARIES = libvarnishapi.la -libvarnishapi_la_LDFLAGS = $(AM_LDFLAGS) -version-info 3:0:0 +libvarnishapi_la_LDFLAGS = $(AM_LDFLAGS) -version-info 4:0:1 libvarnishapi_la_SOURCES = \ ../../include/vcs_version.h \ From phk at phk.freebsd.dk Fri Aug 18 11:01:12 2023 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Fri, 18 Aug 2023 11:01:12 +0000 Subject: [master] b22da84ee build: Bump libvarnishapi soname to 3.1.0 In-Reply-To: <20230818104206.7CBEB9B5E3@lists.varnish-cache.org> References: <20230818104206.7CBEB9B5E3@lists.varnish-cache.org> Message-ID: <202308181101.37IB1CId063389@critter.freebsd.dk> -------- Dridi Boukelmoune writes: > build: Bump libvarnishapi soname to 3.1.0 I knew there were something I forgot. Thanks for the fixes. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk at FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. From dridi.boukelmoune at gmail.com Mon Aug 21 15:26:07 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 15:26:07 +0000 (UTC) Subject: [master] 9cc2fd874 miniobj: Use sizeof for ALLOC_FLEX_OBJ() Message-ID: <20230821152607.5A3F0637C2@lists.varnish-cache.org> commit 9cc2fd874758e4cfcbfe2cb22b46fd629041b3ad Author: Dridi Boukelmoune Date: Mon Aug 21 16:40:36 2023 +0200 miniobj: Use sizeof for ALLOC_FLEX_OBJ() Even though the flexible array may start inside the padding, an array of zero elements could then lead to less than sizeof bytes. diff --git a/include/miniobj.h b/include/miniobj.h index 7551cab53..fcdc9210c 100644 --- a/include/miniobj.h +++ b/include/miniobj.h @@ -32,7 +32,7 @@ #define ALLOC_FLEX_OBJ(to, fld, len, type_magic) \ do { \ - (to) = calloc(1, offsetof(typeof(*(to)), fld) + \ + (to) = calloc(1, sizeof(*(to)) + \ ((len) * sizeof *((to)->fld))); \ if ((to) != NULL) \ (to)->magic = (type_magic); \ From dridi.boukelmoune at gmail.com Mon Aug 21 15:26:07 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 15:26:07 +0000 (UTC) Subject: [master] 9c3d28cef miniobj: Add ALLOC_OBJ_EXTRA() requested by PHK Message-ID: <20230821152607.6EE62637C4@lists.varnish-cache.org> commit 9c3d28cefcec462ac8cdb413f17428900c0cb08e Author: Dridi Boukelmoune Date: Mon Aug 21 17:11:06 2023 +0200 miniobj: Add ALLOC_OBJ_EXTRA() requested by PHK And use it to implement ALLOC_FLEX_OBJ(). diff --git a/include/miniobj.h b/include/miniobj.h index fcdc9210c..8cb9e293e 100644 --- a/include/miniobj.h +++ b/include/miniobj.h @@ -30,14 +30,16 @@ (to)->magic = (type_magic); \ } while (0) -#define ALLOC_FLEX_OBJ(to, fld, len, type_magic) \ +#define ALLOC_OBJ_EXTRA(to, extra_size, type_magic) \ do { \ - (to) = calloc(1, sizeof(*(to)) + \ - ((len) * sizeof *((to)->fld))); \ + (to) = calloc(1, sizeof(*(to)) + (extra_size)); \ if ((to) != NULL) \ (to)->magic = (type_magic); \ } while (0) +#define ALLOC_FLEX_OBJ(to, fld, len, type_magic) \ + ALLOC_OBJ_EXTRA(to, (len) * sizeof *((to)->fld), (type_magic)) + #define FREE_OBJ(to) \ do { \ ZERO_OBJ(&(to)->magic, sizeof (to)->magic); \ From nils.goroll at uplex.de Mon Aug 21 19:33:06 2023 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 21 Aug 2023 19:33:06 +0000 (UTC) Subject: [master] 80d78148c In resp_default_filter_list, check for objcore before using it Message-ID: <20230821193306.CA54896215@lists.varnish-cache.org> commit 80d78148cb1c17eefbec70a51ea3efca03d5bd6d Author: Nils Goroll Date: Mon Aug 21 21:32:12 2023 +0200 In resp_default_filter_list, check for objcore before using it Fixes #3968 diff --git a/bin/varnishd/cache/cache_vrt_filter.c b/bin/varnishd/cache/cache_vrt_filter.c index bf45372d1..bcd7ed1b3 100644 --- a/bin/varnishd/cache/cache_vrt_filter.c +++ b/bin/varnishd/cache/cache_vrt_filter.c @@ -397,11 +397,12 @@ resp_default_filter_list(void *arg, struct vsb *vsb) CAST_OBJ_NOTNULL(req, arg, REQ_MAGIC); - if (!req->disable_esi && + if (!req->disable_esi && req->objcore != NULL && ObjHasAttr(req->wrk, req->objcore, OA_ESIDATA)) VSB_cat(vsb, " esi"); if (cache_param->http_gzip_support && + req->objcore != NULL && ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED) && !RFC2616_Req_Gzip(req->http)) VSB_cat(vsb, " gunzip"); diff --git a/bin/varnishtest/tests/m00048.vtc b/bin/varnishtest/tests/m00048.vtc index f67f72a23..60440cdf9 100644 --- a/bin/varnishtest/tests/m00048.vtc +++ b/bin/varnishtest/tests/m00048.vtc @@ -79,3 +79,28 @@ client c1 -repeat 2 { rxresp expect resp.body == "Cbagb Snpgb, Pnrfne Genafvg!" } -run + +varnish v1 -vcl { + import debug; + backend none none; + + sub vcl_recv { + return (synth(200)); + } + sub vcl_synth { + set resp.body = "Ponto Facto, Caesar Transit!"; + if (req.http.Rot13) { + set resp.filters += "rot13 debug.pedantic"; + } + return (deliver); + } +} + +client c1 -repeat 2 { + txreq + rxresp + expect resp.body == "Ponto Facto, Caesar Transit!" + txreq -hdr "Rot13: please" + rxresp + expect resp.body == "Cbagb Snpgb, Pnrfne Genafvg!" +} -run From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:06 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:06 +0000 (UTC) Subject: [master] dddb171ba vte: Beginning of an incremental API Message-ID: <20230821205206.4FD349CDFA@lists.varnish-cache.org> commit dddb171babbffa918dca0d2c7075953b15b73842 Author: Dridi Boukelmoune Date: Thu Aug 17 08:29:40 2023 +0200 vte: Beginning of an incremental API diff --git a/include/Makefile.am b/include/Makefile.am index 0fa196b39..1a68ab4a3 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -80,6 +80,7 @@ nobase_pkginclude_HEADERS += \ vsb.h \ vsha256.h \ vtcp.h \ + vte.h \ vtim.h \ vtree.h \ vrnd.h diff --git a/include/vte.h b/include/vte.h new file mode 100644 index 000000000..e15d4c233 --- /dev/null +++ b/include/vte.h @@ -0,0 +1,33 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2023 Dridi Boukelmoune + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +struct vte; + +struct vte *VTE_new(int maxfields, int width); +void VTE_destroy(struct vte **); diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c index 953975333..1d915a42d 100644 --- a/lib/libvarnish/vte.c +++ b/lib/libvarnish/vte.c @@ -37,13 +37,60 @@ #include "vdef.h" #include "vqueue.h" +#include "miniobj.h" #include "vas.h" #include "vcli_serve.h" #include "vsb.h" +#include "vte.h" #define MAXCOL 10 +struct vte { + unsigned magic; +#define VTE_MAGIC 0xedf42b97 + struct vsb *vsb; + int c_off; /* input char offset */ + int l_sz; /* input line size */ + int l_maxsz; /* maximum input line size */ + int o_sz; /* output sz */ + int o_sep; /* output field separators */ + int f_off; /* input field offset */ + int f_sz; /* input field size */ + int f_cnt; /* actual number of fields */ + int f_maxcnt; /* maximum number of fields */ + int f_maxsz[]; /* maximum size per field */ +}; + +struct vte * +VTE_new(int maxfields, int width) +{ + struct vte *vte; + + assert(maxfields > 0); + assert(width > 0); + + ALLOC_FLEX_OBJ(vte, f_maxsz, maxfields, VTE_MAGIC); + if (vte != NULL) { + vte->o_sz = width; + vte->f_maxcnt = maxfields; + vte->vsb = VSB_new_auto(); + AN(vte->vsb); + } + return (vte); +} + +void +VTE_destroy(struct vte **vtep) +{ + struct vte *vte; + + TAKE_OBJ_NOTNULL(vte, vtep, VTE_MAGIC); + AN(vte->vsb); + VSB_destroy(&vte->vsb); + FREE_OBJ(vte); +} + void VCLI_VTE(struct cli *cli, struct vsb **src, int width) { From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:06 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:06 +0000 (UTC) Subject: [master] 6dcbc76fd vte: Measure fields incrementally Message-ID: <20230821205206.950D29CDFC@lists.varnish-cache.org> commit 6dcbc76fd2e6a3346590cc666bb4a2fbbbb128ba Author: Dridi Boukelmoune Date: Thu Aug 17 10:17:09 2023 +0200 vte: Measure fields incrementally diff --git a/include/vte.h b/include/vte.h index e15d4c233..b570a5c84 100644 --- a/include/vte.h +++ b/include/vte.h @@ -30,4 +30,5 @@ struct vte; struct vte *VTE_new(int maxfields, int width); +int VTE_cat(struct vte *, const char *); void VTE_destroy(struct vte **); diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c index 1d915a42d..554bb92c1 100644 --- a/lib/libvarnish/vte.c +++ b/lib/libvarnish/vte.c @@ -31,6 +31,7 @@ #include "config.h" +#include #include #include #include /* for MUSL (ssize_t) */ @@ -91,6 +92,76 @@ VTE_destroy(struct vte **vtep) FREE_OBJ(vte); } +static int +vte_update(struct vte *vte) +{ + const char *p, *q; + int len, fno; + + AZ(vte->o_sep); + + len = VSB_len(vte->vsb); + assert(len >= vte->c_off); + + p = vte->vsb->s_buf + vte->c_off; + q = vte->vsb->s_buf + len; + for (; p < q; p++) { + if (vte->f_off < 0) { + while (p < q && *p != '\n') + p++; + } + if (vte->l_sz == 0 && *p == ' ') { + vte->f_off = -1; + continue; + } + if (*p == '\t' || *p == '\n') { + fno = vte->f_off; + if (fno >= 0 && vte->f_sz > vte->f_maxsz[fno]) + vte->f_maxsz[fno] = vte->f_sz; + fno++; + assert(fno <= vte->f_maxcnt); + if (*p == '\t' && fno == vte->f_maxcnt) { + errno = EOVERFLOW; + vte->o_sep = -1; + return (-1); + } + vte->f_off = fno; + vte->f_sz = 0; + } + if (*p == '\n') { + vte->f_cnt = vmax(vte->f_cnt, vte->f_off); + vte->l_maxsz = vmax(vte->l_maxsz, vte->l_sz); + vte->f_off = 0; + vte->f_sz = 0; + vte->l_sz = 0; + } else { + vte->f_sz++; + vte->l_sz++; + } + } + + vte->c_off = len; + return (0); +} + +int +VTE_cat(struct vte *vte, const char *s) +{ + + CHECK_OBJ_NOTNULL(vte, VTE_MAGIC); + AN(s); + + if (vte->o_sep != 0) + return (-1); + + if (VSB_cat(vte->vsb, s) < 0) { + vte->o_sep = -1; + return (-1); + } + + return (vte_update(vte)); +} + void VCLI_VTE(struct cli *cli, struct vsb **src, int width) { From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:06 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:06 +0000 (UTC) Subject: [master] 6729ae2b7 vte: Add a VTE_Printf() convenience Message-ID: <20230821205206.C38D09CDFF@lists.varnish-cache.org> commit 6729ae2b7641dca1ac9b958ee0c194000779457b Author: Dridi Boukelmoune Date: Thu Aug 17 12:03:13 2023 +0200 vte: Add a VTE_Printf() convenience diff --git a/include/vte.h b/include/vte.h index b570a5c84..438321611 100644 --- a/include/vte.h +++ b/include/vte.h @@ -31,4 +31,5 @@ struct vte; struct vte *VTE_new(int maxfields, int width); int VTE_cat(struct vte *, const char *); +int VTE_printf(struct vte *, const char *, ...) v_printflike_(2, 3); void VTE_destroy(struct vte **); diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c index 554bb92c1..8529c05fe 100644 --- a/lib/libvarnish/vte.c +++ b/lib/libvarnish/vte.c @@ -32,6 +32,7 @@ #include "config.h" #include +#include #include #include #include /* for MUSL (ssize_t) */ @@ -162,6 +163,30 @@ VTE_cat(struct vte *vte, const char *s) return (vte_update(vte)); } +int +VTE_printf(struct vte *vte, const char *fmt, ...) +{ + va_list ap; + int res; + + CHECK_OBJ_NOTNULL(vte, VTE_MAGIC); + AN(fmt); + + if (vte->o_sep != 0) + return (-1); + + va_start(ap, fmt); + res = VSB_vprintf(vte->vsb, fmt, ap); + va_end(ap); + + if (res < 0) { + vte->o_sep = -1; + return (-1); + } + + return (vte_update(vte)); +} + void VCLI_VTE(struct cli *cli, struct vsb **src, int width) { From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:06 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:06 +0000 (UTC) Subject: [master] a1104edc9 vte: Add a VTE_putc() convenience Message-ID: <20230821205207.0E4939CE06@lists.varnish-cache.org> commit a1104edc95c76750a3b1ad7594ff0c7aadff156f Author: Dridi Boukelmoune Date: Thu Aug 17 12:04:47 2023 +0200 vte: Add a VTE_putc() convenience diff --git a/include/vte.h b/include/vte.h index 438321611..2573c030e 100644 --- a/include/vte.h +++ b/include/vte.h @@ -30,6 +30,7 @@ struct vte; struct vte *VTE_new(int maxfields, int width); +int VTE_putc(struct vte *, char); int VTE_cat(struct vte *, const char *); int VTE_printf(struct vte *, const char *, ...) v_printflike_(2, 3); void VTE_destroy(struct vte **); diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c index 8529c05fe..b7ec41cab 100644 --- a/lib/libvarnish/vte.c +++ b/lib/libvarnish/vte.c @@ -145,6 +145,24 @@ vte_update(struct vte *vte) return (0); } +int +VTE_putc(struct vte *vte, char c) +{ + + CHECK_OBJ_NOTNULL(vte, VTE_MAGIC); + AN(c); + + if (vte->o_sep != 0) + return (-1); + + if (VSB_putc(vte->vsb, c) < 0) { + vte->o_sep = -1; + return (-1); + } + + return (vte_update(vte)); +} + int VTE_cat(struct vte *vte, const char *s) { From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:07 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:07 +0000 (UTC) Subject: [master] 16658213c vte: Finish collecting and measuring lines Message-ID: <20230821205207.318D49CE14@lists.varnish-cache.org> commit 16658213c39c56f5428b58499ec1251f97c730d9 Author: Dridi Boukelmoune Date: Thu Aug 17 12:13:51 2023 +0200 vte: Finish collecting and measuring lines diff --git a/include/vte.h b/include/vte.h index 2573c030e..7a97cadee 100644 --- a/include/vte.h +++ b/include/vte.h @@ -33,4 +33,5 @@ struct vte *VTE_new(int maxfields, int width); int VTE_putc(struct vte *, char); int VTE_cat(struct vte *, const char *); int VTE_printf(struct vte *, const char *, ...) v_printflike_(2, 3); +int VTE_finish(struct vte *); void VTE_destroy(struct vte **); diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c index b7ec41cab..2a21d1e06 100644 --- a/lib/libvarnish/vte.c +++ b/lib/libvarnish/vte.c @@ -32,6 +32,7 @@ #include "config.h" #include +#include #include #include #include @@ -205,6 +206,29 @@ VTE_printf(struct vte *vte, const char *fmt, ...) return (vte_update(vte)); } +int +VTE_finish(struct vte *vte) +{ + + CHECK_OBJ_NOTNULL(vte, VTE_MAGIC); + + if (vte->o_sep != 0) + return (-1); + + if (VSB_finish(vte->vsb) < 0) { + vte->o_sep = -1; + return (-1); + } + + if (vte->f_cnt == 0) { + vte->o_sep = INT_MAX; + return (0); + } + + vte->o_sep = (vte->o_sz - vte->l_maxsz) / vte->f_cnt; + return (0); +} + void VCLI_VTE(struct cli *cli, struct vsb **src, int width) { From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:07 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:07 +0000 (UTC) Subject: [master] 3f88d3b6a vte: Emit the formatted output Message-ID: <20230821205207.6B0019CE1E@lists.varnish-cache.org> commit 3f88d3b6a2dad133eb967779a375e1f911b37eda Author: Dridi Boukelmoune Date: Thu Aug 17 12:37:46 2023 +0200 vte: Emit the formatted output diff --git a/include/vte.h b/include/vte.h index 7a97cadee..eb5d3ff65 100644 --- a/include/vte.h +++ b/include/vte.h @@ -29,9 +29,12 @@ struct vte; +typedef int VTE_format_f(void *priv, const char *fmt, ...) v_printflike_(2, 3); + struct vte *VTE_new(int maxfields, int width); int VTE_putc(struct vte *, char); int VTE_cat(struct vte *, const char *); int VTE_printf(struct vte *, const char *, ...) v_printflike_(2, 3); int VTE_finish(struct vte *); +int VTE_format(struct vte *, VTE_format_f *func, void *priv); void VTE_destroy(struct vte **); diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c index 2a21d1e06..f35797b98 100644 --- a/lib/libvarnish/vte.c +++ b/lib/libvarnish/vte.c @@ -48,6 +48,8 @@ #include "vte.h" #define MAXCOL 10 +#define MINSEP 1 +#define MAXSEP 3 struct vte { unsigned magic; @@ -209,6 +211,7 @@ VTE_printf(struct vte *vte, const char *fmt, ...) int VTE_finish(struct vte *vte) { + int sep; CHECK_OBJ_NOTNULL(vte, VTE_MAGIC); @@ -225,7 +228,58 @@ VTE_finish(struct vte *vte) return (0); } - vte->o_sep = (vte->o_sz - vte->l_maxsz) / vte->f_cnt; + sep = (vte->o_sz - vte->l_maxsz) / vte->f_cnt; + vte->o_sep = vlimit(sep, MINSEP, MAXSEP); + return (0); +} + +#define VTE_FORMAT(func, priv, ...) \ + do { \ + if (func(priv, __VA_ARGS__) < 0) \ + return (-1); \ + } while (0) + +int +VTE_format(struct vte *vte, VTE_format_f *func, void *priv) +{ + int fno, fsz, nsp; + const char *p; + + CHECK_OBJ_NOTNULL(vte, VTE_MAGIC); + AN(func); + + if (vte->o_sep <= 0) + return (-1); + + nsp = vte->o_sep; + p = VSB_data(vte->vsb); + AN(p); + + for (fno = fsz = 0; *p != '\0'; p++) { + if (fsz == 0 && fno == 0 && *p == ' ') { + while (p[1] != '\0') { + VTE_FORMAT(func, priv, "%c", *p); + if (*p == '\n') + break; + p++; + } + continue; + } + if (*p == '\t') { + while (fsz++ < vte->f_maxsz[fno] + nsp) + VTE_FORMAT(func, priv, " "); + fno++; + fsz = 0; + } else if (*p == '\n') { + VTE_FORMAT(func, priv, "\n"); + fno = 0; + fsz = 0; + } else { + VTE_FORMAT(func, priv, "%c", *p); + fsz++; + } + } + return (0); } From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:07 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:07 +0000 (UTC) Subject: [master] d0c241f67 vte: Excercise the incremental API with VCLI_VTE() Message-ID: <20230821205207.8CF3E9CE23@lists.varnish-cache.org> commit d0c241f672814b166428c6f02a33d0e7a71f9e81 Author: Dridi Boukelmoune Date: Thu Aug 17 13:37:07 2023 +0200 vte: Excercise the incremental API with VCLI_VTE() diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c index f35797b98..db7d0d2d0 100644 --- a/lib/libvarnish/vte.c +++ b/lib/libvarnish/vte.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include /* for MUSL (ssize_t) */ @@ -283,18 +284,29 @@ VTE_format(struct vte *vte, VTE_format_f *func, void *priv) return (0); } +/* NB: cheating in the absence of a VCLI_Outv() */ +static int +vcli_vte(void *priv, const char *fmt, ...) +{ + struct cli *cli; + va_list ap; + char buf[2]; + + cli = priv; + AN(cli); + + va_start(ap, fmt); + (void)vsnprintf(buf, sizeof buf, fmt, ap); + va_end(ap); + + VCLI_Out(cli, "%c", *buf); + return (0); +} + void VCLI_VTE(struct cli *cli, struct vsb **src, int width) { - int w_col[MAXCOL]; - int n_col = 0; - int w_ln = 0; - int cc = 0; - int wc = 0; - int wl = 0; - int nsp; - const char *p; - char *s; + struct vte *vte; AN(cli); AN(src); @@ -304,66 +316,13 @@ VCLI_VTE(struct cli *cli, struct vsb **src, int width) VSB_destroy(src); return; } - s = VSB_data(*src); - AN(s); - memset(w_col, 0, sizeof w_col); - for (p = s; *p ; p++) { - if (wl == 0 && *p == ' ') { - while (p[1] != '\0' && *p != '\n') - p++; - continue; - } - if (*p == '\t' || *p == '\n') { - if (wc > w_col[cc]) - w_col[cc] = wc; - cc++; - assert(cc < MAXCOL); - wc = 0; - } - if (*p == '\n') { - n_col = vmax(n_col, cc); - w_ln = vmax(w_ln, wl); - cc = 0; - wc = 0; - wl = 0; - } else { - wc++; - wl++; - } - } - - if (n_col == 0) - return; - AN(n_col); - nsp = vlimit_t(int, (width - (w_ln)) / n_col, 1, 3); + vte = VTE_new(MAXCOL, width); + AN(vte); + AZ(VTE_cat(vte, VSB_data(*src))); + AZ(VTE_finish(vte)); + AZ(VTE_format(vte, vcli_vte, cli)); + VTE_destroy(&vte); - cc = 0; - wc = 0; - for (p = s; *p ; p++) { - if (wc == 0 && cc == 0 && *p == ' ') { - while (p[1] != '\0') { - VCLI_Out(cli, "%c", *p); - if (*p == '\n') - break; - p++; - } - continue; - } - if (*p == '\t') { - while (wc++ < w_col[cc] + nsp) - VCLI_Out(cli, " "); - cc++; - wc = 0; - } else if (*p == '\n') { - VCLI_Out(cli, "%c", *p); - cc = 0; - wc = 0; - } else { - VCLI_Out(cli, "%c", *p); - wc++; - } - } VSB_destroy(src); } - From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:07 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:07 +0000 (UTC) Subject: [master] f691baeb7 vcli: Extract a vcli_outv() function Message-ID: <20230821205207.DD68E9CE2E@lists.varnish-cache.org> commit f691baeb72d08348eb37ce0e39529e6f89d759e8 Author: Dridi Boukelmoune Date: Thu Aug 17 14:58:43 2023 +0200 vcli: Extract a vcli_outv() function diff --git a/lib/libvarnish/vcli_serve.c b/lib/libvarnish/vcli_serve.c index 02a3d4c84..a6cce1ddf 100644 --- a/lib/libvarnish/vcli_serve.c +++ b/lib/libvarnish/vcli_serve.c @@ -637,19 +637,27 @@ VCLS_Destroy(struct VCLS **csp) * Utility functions for implementing CLI commands */ +static void +vcli_outv(struct cli *cli, const char *fmt, va_list ap) +{ + + if (VSB_len(cli->sb) < *cli->limit) + (void)VSB_vprintf(cli->sb, fmt, ap); + else if (cli->result == CLIS_OK) + cli->result = CLIS_TRUNCATED; +} + /*lint -e{818} cli could be const */ void VCLI_Out(struct cli *cli, const char *fmt, ...) { va_list ap; - AN(cli); - va_start(ap, fmt); CHECK_OBJ_NOTNULL(cli, CLI_MAGIC); - if (VSB_len(cli->sb) < *cli->limit) - (void)VSB_vprintf(cli->sb, fmt, ap); - else if (cli->result == CLIS_OK) - cli->result = CLIS_TRUNCATED; + AN(fmt); + + va_start(ap, fmt); + vcli_outv(cli, fmt, ap); va_end(ap); } From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:07 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:07 +0000 (UTC) Subject: [master] 6c4f3f8de vcli: Provide a VTE callback Message-ID: <20230821205208.0B0659CE4A@lists.varnish-cache.org> commit 6c4f3f8deaaad29fd87fac407c39368facc14bea Author: Dridi Boukelmoune Date: Thu Aug 17 15:08:40 2023 +0200 vcli: Provide a VTE callback diff --git a/include/vcli_serve.h b/include/vcli_serve.h index f3757f28b..00eae9c83 100644 --- a/include/vcli_serve.h +++ b/include/vcli_serve.h @@ -109,5 +109,8 @@ cli_func_t VCLS_func_help_json; cli_func_t VCLS_func_ping; cli_func_t VCLS_func_ping_json; +/* VTE integration */ +int VCLI_VTE_format(void *priv, const char *fmt, ...) v_printflike_(2, 3); + /* From libvarnish/vte.c */ void VCLI_VTE(struct cli *cli, struct vsb **src, int width); diff --git a/lib/libvarnish/vcli_serve.c b/lib/libvarnish/vcli_serve.c index a6cce1ddf..40b46947f 100644 --- a/lib/libvarnish/vcli_serve.c +++ b/lib/libvarnish/vcli_serve.c @@ -661,6 +661,22 @@ VCLI_Out(struct cli *cli, const char *fmt, ...) va_end(ap); } +int v_matchproto_(VTE_format_f) +VCLI_VTE_format(void *priv, const char *fmt, ...) +{ + struct cli *cli; + va_list ap; + + CAST_OBJ_NOTNULL(cli, priv, CLI_MAGIC); + AN(fmt); + + va_start(ap, fmt); + vcli_outv(cli, fmt, ap); + va_end(ap); + + return (0); +} + /*lint -e{818} cli could be const */ int VCLI_Overflow(struct cli *cli) From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:08 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:08 +0000 (UTC) Subject: [master] 92e2e3d5e mgt_vcl: Move vcl.deps to the VTE API Message-ID: <20230821205208.3EE299CE60@lists.varnish-cache.org> commit 92e2e3d5ecfbefcb7f00718e67b9f95effcedbd6 Author: Dridi Boukelmoune Date: Thu Aug 17 15:28:57 2023 +0200 mgt_vcl: Move vcl.deps to the VTE API diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c index 69b35371e..2b46db352 100644 --- a/bin/varnishd/mgt/mgt_vcl.c +++ b/bin/varnishd/mgt/mgt_vcl.c @@ -46,6 +46,7 @@ #include "vcli_serve.h" #include "vct.h" #include "vev.h" +#include "vte.h" #include "vtim.h" struct vclstate { @@ -1012,23 +1013,25 @@ mcf_vcl_deps(struct cli *cli, const char * const *av, void *priv) { struct vclprog *vp; struct vcldep *vd; - struct vsb *vsb; + struct vte *vte; (void)av; (void)priv; - vsb = VSB_new_auto(); - AN(vsb); + vte = VTE_new(2, 80); + AN(vte); VTAILQ_FOREACH(vp, &vclhead, list) { if (VTAILQ_EMPTY(&vp->dfrom)) { - VSB_printf(vsb, "%s\n", vp->name); + VTE_printf(vte, "%s\n", vp->name); continue; } VTAILQ_FOREACH(vd, &vp->dfrom, lfrom) - VSB_printf(vsb, "%s\t%s\n", vp->name, vd->to->name); + VTE_printf(vte, "%s\t%s\n", vp->name, vd->to->name); } - VCLI_VTE(cli, &vsb, 80); + AZ(VTE_finish(vte)); + AZ(VTE_format(vte, VCLI_VTE_format, cli)); + VTE_destroy(&vte); } static void v_matchproto_(cli_func_t) diff --git a/bin/varnishtest/tests/s00005.vtc b/bin/varnishtest/tests/s00005.vtc index 3ed6c0193..a0780cd93 100644 --- a/bin/varnishtest/tests/s00005.vtc +++ b/bin/varnishtest/tests/s00005.vtc @@ -132,3 +132,16 @@ varnish v1 -cliexpect \ {would create a loop} \ {vcl.label lblA vcl5} +# omitting ^vcl1 line to only get aligned fields +varnish v1 -cliexpect { +vcl2 +label1 vcl1 +label2 vcl1 +label3 vcl1 +slartibartfast vcl1 +vcl3 +lblA vcl3 +vcl4 lblA +lblB vcl4 +vcl5 lblB +} vcl.deps From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:08 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:08 +0000 (UTC) Subject: [master] 27b8fc4e8 mgt_vcl: Move vcl.list to the VTE API Message-ID: <20230821205208.5C0799CE6B@lists.varnish-cache.org> commit 27b8fc4e8197fd5360e294bcf131d3a252901647 Author: Dridi Boukelmoune Date: Thu Aug 17 15:32:53 2023 +0200 mgt_vcl: Move vcl.list to the VTE API diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c index 2b46db352..882c828aa 100644 --- a/bin/varnishd/mgt/mgt_vcl.c +++ b/bin/varnishd/mgt/mgt_vcl.c @@ -827,7 +827,7 @@ mcf_vcl_list(struct cli *cli, const char * const *av, void *priv) struct vclprog *vp; struct vcldep *vd; const struct vclstate *vs; - struct vsb *vsb; + struct vte *vte; /* NB: Shall generate same output as vcl_cli_list() */ @@ -841,29 +841,31 @@ mcf_vcl_list(struct cli *cli, const char * const *av, void *priv) } free(p); } else { - vsb = VSB_new_auto(); - AN(vsb); + vte = VTE_new(7, 80); + AN(vte); VTAILQ_FOREACH(vp, &vclhead, list) { - VSB_printf(vsb, "%s", + VTE_printf(vte, "%s", vp == mgt_vcl_active ? "active" : "available"); vs = vp->warm ? VCL_STATE_WARM : VCL_STATE_COLD; - VSB_printf(vsb, "\t%s\t%s", vp->state->name, vs->name); - VSB_printf(vsb, "\t%6s\t%s", "-", vp->name); + VTE_printf(vte, "\t%s\t%s", vp->state->name, vs->name); + VTE_printf(vte, "\t%6s\t%s", "-", vp->name); if (mcf_is_label(vp)) { vd = VTAILQ_FIRST(&vp->dfrom); AN(vd); - VSB_printf(vsb, "\t->\t%s", vd->to->name); + VTE_printf(vte, "\t->\t%s", vd->to->name); if (vp->nto > 0) - VSB_printf(vsb, " (%d return(vcl)%s)", + VTE_printf(vte, " (%d return(vcl)%s)", vp->nto, vp->nto > 1 ? "'s" : ""); } else if (vp->nto > 0) { - VSB_printf(vsb, "\t<-\t(%d label%s)", + VTE_printf(vte, "\t<-\t(%d label%s)", vp->nto, vp->nto > 1 ? "s" : ""); } - VSB_cat(vsb, "\n"); + VTE_cat(vte, "\n"); } - VCLI_VTE(cli, &vsb, 80); + AZ(VTE_finish(vte)); + AZ(VTE_format(vte, VCLI_VTE_format, cli)); + VTE_destroy(&vte); } } From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:08 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:08 +0000 (UTC) Subject: [master] 44a384757 cache_vcl: Move vcl.list to the VTE API Message-ID: <20230821205208.818849CE87@lists.varnish-cache.org> commit 44a384757a4060edfdbac8a52fda69a30cb73536 Author: Dridi Boukelmoune Date: Thu Aug 17 15:36:24 2023 +0200 cache_vcl: Move vcl.list to the VTE API diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index 63b9b9eac..0ab200739 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -45,6 +45,7 @@ #include "cache_director.h" #include "cache_vcl.h" #include "vcli_serve.h" +#include "vte.h" #include "vtim.h" #include "vcc_interface.h" @@ -750,7 +751,7 @@ vcl_cli_list(struct cli *cli, const char * const *av, void *priv) { struct vcl *vcl; const char *flg; - struct vsb *vsb; + struct vte *vte; /* NB: Shall generate same output as mcf_vcl_list() */ @@ -758,8 +759,8 @@ vcl_cli_list(struct cli *cli, const char * const *av, void *priv) (void)priv; ASSERT_CLI(); ASSERT_VCL_ACTIVE(); - vsb = VSB_new_auto(); - AN(vsb); + vte = VTE_new(7, 80); + AN(vte); VTAILQ_FOREACH(vcl, &vcl_head, list) { if (vcl == vcl_active) { flg = "active"; @@ -767,20 +768,22 @@ vcl_cli_list(struct cli *cli, const char * const *av, void *priv) flg = "discarded"; } else flg = "available"; - VSB_printf(vsb, "%s\t%s\t%s\t%6u\t%s", flg, vcl->state, + VTE_printf(vte, "%s\t%s\t%s\t%6u\t%s", flg, vcl->state, vcl->temp->name, vcl->busy, vcl->loaded_name); if (vcl->label != NULL) { - VSB_printf(vsb, "\t->\t%s", vcl->label->loaded_name); + VTE_printf(vte, "\t->\t%s", vcl->label->loaded_name); if (vcl->nrefs) - VSB_printf(vsb, " (%d return(vcl)%s)", + VTE_printf(vte, " (%d return(vcl)%s)", vcl->nrefs, vcl->nrefs > 1 ? "'s" : ""); } else if (vcl->nlabels > 0) { - VSB_printf(vsb, "\t<-\t(%d label%s)", + VTE_printf(vte, "\t<-\t(%d label%s)", vcl->nlabels, vcl->nlabels > 1 ? "s" : ""); } - VSB_cat(vsb, "\n"); + VTE_cat(vte, "\n"); } - VCLI_VTE(cli, &vsb, 80); + AZ(VTE_finish(vte)); + AZ(VTE_format(vte, VCLI_VTE_format, cli)); + VTE_destroy(&vte); } static void v_matchproto_(cli_func_t) From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:08 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:08 +0000 (UTC) Subject: [master] c1f556386 director: Move backend.list to the VTE API Message-ID: <20230821205208.A08E39CE8F@lists.varnish-cache.org> commit c1f5563861fcbb9d2f4760c2da62b6be25c3dfe7 Author: Dridi Boukelmoune Date: Thu Aug 17 15:52:45 2023 +0200 director: Move backend.list to the VTE API diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c index 166916da4..952dd717f 100644 --- a/bin/varnishd/cache/cache_director.c +++ b/bin/varnishd/cache/cache_director.c @@ -41,6 +41,7 @@ #include "cache_director.h" #include "vcli_serve.h" +#include "vte.h" #include "vtim.h" /* -------------------------------------------------------------------*/ @@ -309,6 +310,7 @@ struct list_args { int j; const char *jsep; struct vsb *vsb; + struct vte *vte; }; static const char * @@ -329,6 +331,7 @@ do_list(struct cli *cli, struct director *d, void *priv) AN(cli); CAST_OBJ_NOTNULL(la, priv, LIST_ARGS_MAGIC); AN(la->vsb); + AN(la->vte); CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); if (d->vdir->admin_health == VDI_AH_DELETED) @@ -336,21 +339,28 @@ do_list(struct cli *cli, struct director *d, void *priv) ctx = VCL_Get_CliCtx(0); - VSB_printf(la->vsb, "%s\t%s\t", d->vdir->cli_name, VDI_Ahealth(d)); + VTE_printf(la->vte, "%s\t%s\t", d->vdir->cli_name, VDI_Ahealth(d)); - if (d->vdir->methods->list != NULL) + if (d->vdir->methods->list != NULL) { + VSB_clear(la->vsb); d->vdir->methods->list(ctx, d, la->vsb, 0, 0); - else if (d->vdir->methods->healthy != NULL) - VSB_printf(la->vsb, "0/0\t%s", cli_health(ctx, d)); + AZ(VSB_finish(la->vsb)); + VTE_cat(la->vte, VSB_data(la->vsb)); + } else if (d->vdir->methods->healthy != NULL) + VTE_printf(la->vte, "0/0\t%s", cli_health(ctx, d)); else - VSB_cat(la->vsb, "0/0\thealthy"); + VTE_cat(la->vte, "0/0\thealthy"); VTIM_format(d->vdir->health_changed, time_str); - VSB_printf(la->vsb, "\t%s", time_str); - if (la->p && d->vdir->methods->list != NULL) + VTE_printf(la->vte, "\t%s", time_str); + if (la->p && d->vdir->methods->list != NULL) { + VSB_clear(la->vsb); d->vdir->methods->list(ctx, d, la->vsb, la->p, 0); + AZ(VSB_finish(la->vsb)); + VTE_cat(la->vte, VSB_data(la->vsb)); + } - VSB_cat(la->vsb, "\n"); + VTE_cat(la->vte, "\n"); AZ(VCL_Rel_CliCtx(&ctx)); AZ(ctx); @@ -443,10 +453,15 @@ cli_backend_list(struct cli *cli, const char * const *av, void *priv) } else { la->vsb = VSB_new_auto(); AN(la->vsb); - VSB_printf(la->vsb, "%s\t%s\t%s\t%s\t%s\n", + la->vte = VTE_new(5, 80); + AN(la->vte); + VTE_printf(la->vte, "%s\t%s\t%s\t%s\t%s\n", "Backend name", "Admin", "Probe", "Health", "Last change"); (void)VCL_IterDirector(cli, av[i], do_list, la); - VCLI_VTE(cli, &la->vsb, 80); + AZ(VTE_finish(la->vte)); + AZ(VTE_format(la->vte, VCLI_VTE_format, cli)); + VTE_destroy(&la->vte); + VSB_destroy(&la->vsb); } } From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:08 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:08 +0000 (UTC) Subject: [master] 084233429 vte: Remove the former all-in-one VCLI_VTE() Message-ID: <20230821205208.C256B9CE98@lists.varnish-cache.org> commit 0842334295b772925f2a4b6fb7e6387a05ff180c Author: Dridi Boukelmoune Date: Thu Aug 17 15:56:46 2023 +0200 vte: Remove the former all-in-one VCLI_VTE() diff --git a/include/vcli_serve.h b/include/vcli_serve.h index 00eae9c83..e1b721ea4 100644 --- a/include/vcli_serve.h +++ b/include/vcli_serve.h @@ -111,6 +111,3 @@ cli_func_t VCLS_func_ping_json; /* VTE integration */ int VCLI_VTE_format(void *priv, const char *fmt, ...) v_printflike_(2, 3); - -/* From libvarnish/vte.c */ -void VCLI_VTE(struct cli *cli, struct vsb **src, int width); diff --git a/include/vte.h b/include/vte.h index eb5d3ff65..2b57cfb3b 100644 --- a/include/vte.h +++ b/include/vte.h @@ -25,6 +25,14 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * Varnish Turbo Encabulator + * + * Align and print fields in a line-based output. Fields are delimited + * with a horizontal tab HT and lines starting with a space SP are kept + * verbatim. Lines are delimited with a single new line LF character. + * + * Using non-ASCII or non-printable ASCII character is undefined behavior. */ struct vte; diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c index db7d0d2d0..6216cbab6 100644 --- a/lib/libvarnish/vte.c +++ b/lib/libvarnish/vte.c @@ -3,6 +3,7 @@ * All rights reserved. * * Author: Poul-Henning Kamp + * Author: Dridi Boukelmoune * * SPDX-License-Identifier: BSD-2-Clause * @@ -34,21 +35,17 @@ #include #include #include -#include #include #include #include /* for MUSL (ssize_t) */ #include "vdef.h" -#include "vqueue.h" #include "miniobj.h" #include "vas.h" -#include "vcli_serve.h" #include "vsb.h" #include "vte.h" -#define MAXCOL 10 #define MINSEP 1 #define MAXSEP 3 @@ -283,46 +280,3 @@ VTE_format(struct vte *vte, VTE_format_f *func, void *priv) return (0); } - -/* NB: cheating in the absence of a VCLI_Outv() */ -static int -vcli_vte(void *priv, const char *fmt, ...) -{ - struct cli *cli; - va_list ap; - char buf[2]; - - cli = priv; - AN(cli); - - va_start(ap, fmt); - (void)vsnprintf(buf, sizeof buf, fmt, ap); - va_end(ap); - - VCLI_Out(cli, "%c", *buf); - return (0); -} - -void -VCLI_VTE(struct cli *cli, struct vsb **src, int width) -{ - struct vte *vte; - - AN(cli); - AN(src); - AN(*src); - AZ(VSB_finish(*src)); - if (VSB_len(*src) == 0) { - VSB_destroy(src); - return; - } - - vte = VTE_new(MAXCOL, width); - AN(vte); - AZ(VTE_cat(vte, VSB_data(*src))); - AZ(VTE_finish(vte)); - AZ(VTE_format(vte, vcli_vte, cli)); - VTE_destroy(&vte); - - VSB_destroy(src); -} From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:08 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:08 +0000 (UTC) Subject: [master] 75cc8f6f6 vte: Only print at field boundaries Message-ID: <20230821205208.E2D059CEA7@lists.varnish-cache.org> commit 75cc8f6f60a4623296db1a5db807562d98309af4 Author: Dridi Boukelmoune Date: Thu Aug 17 17:31:07 2023 +0200 vte: Only print at field boundaries This drastically reduces the number of printf-like operations. diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c index 6216cbab6..b479b37ed 100644 --- a/lib/libvarnish/vte.c +++ b/lib/libvarnish/vte.c @@ -241,7 +241,7 @@ int VTE_format(struct vte *vte, VTE_format_f *func, void *priv) { int fno, fsz, nsp; - const char *p; + const char *p, *q; CHECK_OBJ_NOTNULL(vte, VTE_MAGIC); AN(func); @@ -252,31 +252,33 @@ VTE_format(struct vte *vte, VTE_format_f *func, void *priv) nsp = vte->o_sep; p = VSB_data(vte->vsb); AN(p); + q = p; for (fno = fsz = 0; *p != '\0'; p++) { if (fsz == 0 && fno == 0 && *p == ' ') { - while (p[1] != '\0') { - VTE_FORMAT(func, priv, "%c", *p); - if (*p == '\n') - break; - p++; + p = strchr(p, '\n'); + if (p == NULL) { + p = q + 1; // trigger final flush + break; } continue; } if (*p == '\t') { - while (fsz++ < vte->f_maxsz[fno] + nsp) - VTE_FORMAT(func, priv, " "); + assert(vte->f_maxsz[fno] + nsp > fsz); + VTE_FORMAT(func, priv, "%.*s%*s", + (int)(p - q), q, + vte->f_maxsz[fno] + nsp - fsz, ""); fno++; fsz = 0; + q = p + 1; } else if (*p == '\n') { - VTE_FORMAT(func, priv, "\n"); fno = 0; fsz = 0; - } else { - VTE_FORMAT(func, priv, "%c", *p); + } else fsz++; - } } + if (q < p) + VTE_FORMAT(func, priv, "%s", q); return (0); } From dridi.boukelmoune at gmail.com Mon Aug 21 20:52:09 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 21 Aug 2023 20:52:09 +0000 (UTC) Subject: [master] 928e2e8d2 vte: Simplify format loop with strcspn() Message-ID: <20230821205209.3573F9CEAE@lists.varnish-cache.org> commit 928e2e8d2c10282913b350d1711da9c76af7fcf8 Author: Dridi Boukelmoune Date: Thu Aug 17 17:45:04 2023 +0200 vte: Simplify format loop with strcspn() diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c index b479b37ed..efccd97ac 100644 --- a/lib/libvarnish/vte.c +++ b/lib/libvarnish/vte.c @@ -254,28 +254,24 @@ VTE_format(struct vte *vte, VTE_format_f *func, void *priv) AN(p); q = p; - for (fno = fsz = 0; *p != '\0'; p++) { - if (fsz == 0 && fno == 0 && *p == ' ') { - p = strchr(p, '\n'); - if (p == NULL) { - p = q + 1; // trigger final flush - break; - } - continue; - } + fno = 0; + while (*p != 0) { + if (fno == 0 && *p == ' ') + fsz = strcspn(p, "\n"); + else + fsz = strcspn(p, "\t\n"); + p += fsz; if (*p == '\t') { assert(vte->f_maxsz[fno] + nsp > fsz); VTE_FORMAT(func, priv, "%.*s%*s", (int)(p - q), q, vte->f_maxsz[fno] + nsp - fsz, ""); fno++; - fsz = 0; - q = p + 1; + q = ++p; } else if (*p == '\n') { fno = 0; - fsz = 0; - } else - fsz++; + p++; + } } if (q < p) From dridi.boukelmoune at gmail.com Tue Aug 22 06:02:07 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Tue, 22 Aug 2023 06:02:07 +0000 (UTC) Subject: [master] a81a1d532 vte: Flexelinting Message-ID: <20230822060207.E962C588D@lists.varnish-cache.org> commit a81a1d532c2d109f14e170de43586ab0baa80bb9 Author: Dridi Boukelmoune Date: Tue Aug 22 08:00:36 2023 +0200 vte: Flexelinting diff --git a/include/vte.h b/include/vte.h index 2b57cfb3b..43279bc9a 100644 --- a/include/vte.h +++ b/include/vte.h @@ -44,5 +44,5 @@ int VTE_putc(struct vte *, char); int VTE_cat(struct vte *, const char *); int VTE_printf(struct vte *, const char *, ...) v_printflike_(2, 3); int VTE_finish(struct vte *); -int VTE_format(struct vte *, VTE_format_f *func, void *priv); +int VTE_format(const struct vte *, VTE_format_f *func, void *priv); void VTE_destroy(struct vte **); diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c index efccd97ac..44ac71afa 100644 --- a/lib/libvarnish/vte.c +++ b/lib/libvarnish/vte.c @@ -227,7 +227,7 @@ VTE_finish(struct vte *vte) } sep = (vte->o_sz - vte->l_maxsz) / vte->f_cnt; - vte->o_sep = vlimit(sep, MINSEP, MAXSEP); + vte->o_sep = vlimit_t(int, sep, MINSEP, MAXSEP); return (0); } @@ -238,7 +238,7 @@ VTE_finish(struct vte *vte) } while (0) int -VTE_format(struct vte *vte, VTE_format_f *func, void *priv) +VTE_format(const struct vte *vte, VTE_format_f *func, void *priv) { int fno, fsz, nsp; const char *p, *q; From dridi.boukelmoune at gmail.com Tue Aug 22 06:16:04 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Tue, 22 Aug 2023 06:16:04 +0000 (UTC) Subject: [master] 0ca33e78e flint: Remove duplicate rule Message-ID: <20230822061604.EE637613F@lists.varnish-cache.org> commit 0ca33e78eed4c399635ad11fa70022163561ebdc Author: Dridi Boukelmoune Date: Tue Aug 22 08:13:07 2023 +0200 flint: Remove duplicate rule diff --git a/flint.lnt b/flint.lnt index 1f5598ded..fc618608f 100644 --- a/flint.lnt +++ b/flint.lnt @@ -207,7 +207,6 @@ -esym(534, VSB_putc) -esym(534, VSB_printf) -esym(534, VSB_vprintf) --esym(534, VSB_putc) /////////////////////////////////////////////////////////////////////// // From dridi.boukelmoune at gmail.com Tue Aug 22 06:16:05 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Tue, 22 Aug 2023 06:16:05 +0000 (UTC) Subject: [master] 6f48616e2 flint: Relax certain VTE functions Message-ID: <20230822061605.119CA6142@lists.varnish-cache.org> commit 6f48616e215c8364e7c9cef56ad7b6f9bf06b0fa Author: Dridi Boukelmoune Date: Tue Aug 22 08:13:30 2023 +0200 flint: Relax certain VTE functions diff --git a/flint.lnt b/flint.lnt index fc618608f..aade0a8a2 100644 --- a/flint.lnt +++ b/flint.lnt @@ -208,6 +208,14 @@ -esym(534, VSB_printf) -esym(534, VSB_vprintf) +/////////////////////////////////////////////////////////////////////// +// + +// ignore retval +-esym(534, VTE_cat) +-esym(534, VTE_putc) +-esym(534, VTE_printf) + /////////////////////////////////////////////////////////////////////// // From nils.goroll at uplex.de Tue Aug 22 07:32:05 2023 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 22 Aug 2023 07:32:05 +0000 (UTC) Subject: [master] 6b6bbdd44 Sync debug message with reality Message-ID: <20230822073205.742206051B@lists.varnish-cache.org> commit 6b6bbdd448b227e65d75a3bbaf80704d50aa2916 Author: Nils Goroll Date: Tue Aug 22 09:30:50 2023 +0200 Sync debug message with reality ESI threads waiting for busy objects stopped looping in 2016 f839d5586842094a2cea65a2ea7337cb2836f72c diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c index bb5384c52..7fb7b87be 100644 --- a/bin/varnishd/cache/cache_esi_deliver.c +++ b/bin/varnishd/cache/cache_esi_deliver.c @@ -204,7 +204,7 @@ ved_include(struct req *preq, const char *src, const char *host, if (s == REQ_FSM_DONE) break; DSL(DBG_WAITINGLIST, req->vsl->wid, - "loop waiting for ESI (%d)", (int)s); + "waiting for ESI (%d)", (int)s); assert(s == REQ_FSM_DISEMBARK); Lck_Lock(&sp->mtx); if (!ecx->woken) From phk at FreeBSD.org Tue Aug 22 08:59:06 2023 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 22 Aug 2023 08:59:06 +0000 (UTC) Subject: [master] 11afbf3ee White space OCD Message-ID: <20230822085906.E6FC563585@lists.varnish-cache.org> commit 11afbf3ee060d3c2c691ab4585257ceb213c3ded Author: Poul-Henning Kamp Date: Tue Aug 22 08:30:33 2023 +0000 White space OCD diff --git a/bin/varnishd/mgt/mgt_jail.c b/bin/varnishd/mgt/mgt_jail.c index c5b828a9b..93711799c 100644 --- a/bin/varnishd/mgt/mgt_jail.c +++ b/bin/varnishd/mgt/mgt_jail.c @@ -220,7 +220,7 @@ VJ_unlink(const char *fname, int ignore_enoent) if (unlink(fname)) { if (errno != ENOENT || !ignore_enoent) fprintf(stderr, "Could not delete '%s': %s\n", - fname, strerror(errno)); + fname, strerror(errno)); } VJ_master(JAIL_MASTER_LOW); } From phk at FreeBSD.org Tue Aug 22 08:59:07 2023 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 22 Aug 2023 08:59:07 +0000 (UTC) Subject: [master] 871614a24 Typo Message-ID: <20230822085907.0BAF563589@lists.varnish-cache.org> commit 871614a24941e99da2f9442a5969d81f5889236a Author: Poul-Henning Kamp Date: Tue Aug 22 08:37:26 2023 +0000 Typo diff --git a/bin/varnishd/cache/cache_range.c b/bin/varnishd/cache/cache_range.c index 8161fd8ce..bde81ccc7 100644 --- a/bin/varnishd/cache/cache_range.c +++ b/bin/varnishd/cache/cache_range.c @@ -170,7 +170,7 @@ vrg_ifrange(struct req *req) return (0); /* the response needs a Date */ - // rfc7232 fc7232,l,439,440 + // rfc7232,l,439,440 if (!http_GetHdr(req->resp, H_Date, &p)) return (0); d = VTIM_parse(p); From phk at FreeBSD.org Tue Aug 22 08:59:07 2023 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 22 Aug 2023 08:59:07 +0000 (UTC) Subject: [master] 6af7d972d Redo H2 field validation Message-ID: <20230822085907.39EF66358E@lists.varnish-cache.org> commit 6af7d972d30371154d9b86943258905e58748ce5 Author: Poul-Henning Kamp Date: Tue Aug 22 08:41:21 2023 +0000 Redo H2 field validation Fixes #3952 diff --git a/bin/varnishd/http2/cache_http2_hpack.c b/bin/varnishd/http2/cache_http2_hpack.c index 8384856dd..85e045bbd 100644 --- a/bin/varnishd/http2/cache_http2_hpack.c +++ b/bin/varnishd/http2/cache_http2_hpack.c @@ -39,6 +39,7 @@ #include "http2/cache_http2.h" #include "vct.h" +// rfc9113,l,2493,2528 static h2_error h2h_checkhdr(const struct http *hp, const char *b, size_t namelen, size_t len) { @@ -48,46 +49,80 @@ h2h_checkhdr(const struct http *hp, const char *b, size_t namelen, size_t len) AN(b); assert(namelen >= 2); /* 2 chars from the ': ' that we added */ assert(namelen <= len); + assert(b[namelen - 2] == ':'); + assert(b[namelen - 1] == ' '); if (namelen == 2) { VSLb(hp->vsl, SLT_BogoHeader, "Empty name"); return (H2SE_PROTOCOL_ERROR); } - for (p = b; p < b + len; p++) { - if (p < b + (namelen - 2)) { - /* Check valid name characters */ - if (p == b && *p == ':') - continue; /* pseudo-header */ + // VSLb(hp->vsl, SLT_Debug, "CHDR [%.*s] [%.*s]", + // (int)namelen, b, (int)(len - namelen), b + namelen); + + int state = 0; + for (p = b; p < b + namelen - 2; p++) { + switch(state) { + case 0: /* First char of field */ + state = 1; + if (*p == ':') + break; + /* FALL_THROUGH */ + case 1: /* field name */ + if (*p <= 0x20 || *p >= 0x7f) { + VSLb(hp->vsl, SLT_BogoHeader, + "Illegal field header name (control): %.*s", + (int)(len > 20 ? 20 : len), b); + return (H2SE_PROTOCOL_ERROR); + } if (isupper(*p)) { VSLb(hp->vsl, SLT_BogoHeader, - "Illegal header name (upper-case): %.*s", + "Illegal field header name (upper-case): %.*s", (int)(len > 20 ? 20 : len), b); return (H2SE_PROTOCOL_ERROR); } - if (vct_istchar(*p)) { - /* XXX: vct should have a proper class for - this avoiding two checks */ - continue; + if (!vct_istchar(*p) || *p == ':') { + VSLb(hp->vsl, SLT_BogoHeader, + "Illegal field header name (non-token): %.*s", + (int)(len > 20 ? 20 : len), b); + return (H2SE_PROTOCOL_ERROR); } - VSLb(hp->vsl, SLT_BogoHeader, - "Illegal header name: %.*s", - (int)(len > 20 ? 20 : len), b); - return (H2SE_PROTOCOL_ERROR); - } else if (p < b + namelen) { - /* ': ' added by us */ - assert(*p == ':' || *p == ' '); - } else { - /* Check valid value characters */ - if (!vct_isctl(*p) || vct_issp(*p)) - continue; - VSLb(hp->vsl, SLT_BogoHeader, - "Illegal header value: %.*s", - (int)(len > 20 ? 20 : len), b); - return (H2SE_PROTOCOL_ERROR); + break; + default: + WRONG("http2 field name validation state"); } } + state = 2; + for (p = b + namelen; p < b + len; p++) { + switch(state) { + case 2: /* First char of field */ + if (*p == ' ' || *p == 0x09) { + VSLb(hp->vsl, SLT_BogoHeader, + "Illegal field value start %.*s", + (int)(len > 20 ? 20 : len), b); + return (H2SE_PROTOCOL_ERROR); + } + state = 3; + /* FALL_THROUGH */ + case 3: /* field value character */ + if (*p != 0x09 && (*p < 0x20 || *p == 0x7f)) { + VSLb(hp->vsl, SLT_BogoHeader, + "Illegal field value (control) %.*s", + (int)(len > 20 ? 20 : len), b); + return (H2SE_PROTOCOL_ERROR); + } + break; + default: + WRONG("http2 field value validation state"); + } + } + if (state == 3 && b[len - 1] <= 0x20) { + VSLb(hp->vsl, SLT_BogoHeader, + "Illegal val (end) %.*s", + (int)(len > 20 ? 20 : len), b); + return (H2SE_PROTOCOL_ERROR); + } return (0); } @@ -270,6 +305,7 @@ h2h_decode_fini(const struct h2_sess *h2) * block. This is a connection level error. * * H2E_PROTOCOL_ERROR: Malformed header or duplicate pseudo-header. + * Violation of field name/value charsets */ h2_error h2h_decode_bytes(struct h2_sess *h2, const uint8_t *in, size_t in_l) diff --git a/bin/varnishtest/tests/t02023.vtc b/bin/varnishtest/tests/t02023.vtc index cfd843da3..59c7fe5d7 100644 --- a/bin/varnishtest/tests/t02023.vtc +++ b/bin/varnishtest/tests/t02023.vtc @@ -46,3 +46,47 @@ client c1 { rxrst } -run } -run + +varnish v1 -vsl_catchup + +client c1 { + stream 1 { + txreq -hdr "fo o" " bar" + rxrst + } -run +} -run + +client c1 { + stream 1 { + txreq -hdr "foo" " " + rxrst + } -run +} -run + +client c1 { + stream 1 { + txreq -hdr ":foo" "bar" + rxrst + } -run +} -run + +client c1 { + stream 1 { + txreq -hdr "foo" "b\x0car" + rxrst + } -run +} -run + +client c1 { + stream 1 { + txreq -hdr "f o" "bar" + rxrst + } -run +} -run + +client c1 { + stream 1 { + txreq -hdr "f: o" "bar" + rxrst + } -run +} -run From phk at FreeBSD.org Tue Aug 22 10:59:05 2023 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 22 Aug 2023 10:59:05 +0000 (UTC) Subject: [master] 134248b5f Slightly more coverage & consistency Message-ID: <20230822105905.54D589343C@lists.varnish-cache.org> commit 134248b5f8970fcf87e2e195adc196f770a7b433 Author: Poul-Henning Kamp Date: Tue Aug 22 10:58:30 2023 +0000 Slightly more coverage & consistency diff --git a/bin/varnishd/http2/cache_http2_hpack.c b/bin/varnishd/http2/cache_http2_hpack.c index 85e045bbd..6261a2cd1 100644 --- a/bin/varnishd/http2/cache_http2_hpack.c +++ b/bin/varnishd/http2/cache_http2_hpack.c @@ -119,7 +119,7 @@ h2h_checkhdr(const struct http *hp, const char *b, size_t namelen, size_t len) } if (state == 3 && b[len - 1] <= 0x20) { VSLb(hp->vsl, SLT_BogoHeader, - "Illegal val (end) %.*s", + "Illegal field value (end) %.*s", (int)(len > 20 ? 20 : len), b); return (H2SE_PROTOCOL_ERROR); } diff --git a/bin/varnishtest/tests/t02023.vtc b/bin/varnishtest/tests/t02023.vtc index 59c7fe5d7..5f5f434bf 100644 --- a/bin/varnishtest/tests/t02023.vtc +++ b/bin/varnishtest/tests/t02023.vtc @@ -90,3 +90,10 @@ client c1 { rxrst } -run } -run + +client c1 { + stream 1 { + txreq -hdr "foo" "bar " + rxrst + } -run +} -run From nils.goroll at uplex.de Wed Aug 23 09:49:03 2023 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 23 Aug 2023 09:49:03 +0000 (UTC) Subject: [master] 7ef1f9472 Simple storage: Finalize busy object state also for ObjFreeObj() Message-ID: <20230823094903.C0A0EA253D@lists.varnish-cache.org> commit 7ef1f94720a45433a8144d70902b7e2b1356868e Author: Nils Goroll Date: Sun Jul 9 14:07:52 2023 +0200 Simple storage: Finalize busy object state also for ObjFreeObj() If oc->boc is not NULL for an ObjFreeObj() call, the stevedore needs to finish any busy object transaction. Fixes #3953 diff --git a/bin/varnishd/storage/storage_simple.c b/bin/varnishd/storage/storage_simple.c index 71f941e34..c94dcccb4 100644 --- a/bin/varnishd/storage/storage_simple.c +++ b/bin/varnishd/storage/storage_simple.c @@ -249,6 +249,27 @@ sml_slim(struct worker *wrk, struct objcore *oc) } } +static void +sml_bocfini(const struct stevedore *stv, struct boc *boc) +{ + struct storage *st; + + CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC); + CHECK_OBJ_NOTNULL(boc, BOC_MAGIC); + + if (boc->stevedore_priv == NULL) + return; + + /* Free any leftovers from Trim */ + TAKE_OBJ_NOTNULL(st, &boc->stevedore_priv, STORAGE_MAGIC); + sml_stv_free(stv, st); +} + +/* + * called in two cases: + * - oc->boc == NULL: cache object on LRU freed + * - oc->boc != NULL: cache object replaced for backend error + */ static void v_matchproto_(objfree_f) sml_objfree(struct worker *wrk, struct objcore *oc) { @@ -267,7 +288,9 @@ sml_objfree(struct worker *wrk, struct objcore *oc) CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC); FINI_OBJ(o); - if (oc->boc == NULL && stv->lru != NULL) + if (oc->boc != NULL) + sml_bocfini(stv, oc->boc); + else if (stv->lru != NULL) LRU_Remove(oc); sml_stv_free(stv, st); @@ -551,7 +574,6 @@ static void v_matchproto_(objbocdone_f) sml_bocdone(struct worker *wrk, struct objcore *oc, struct boc *boc) { const struct stevedore *stv; - struct storage *st; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); @@ -559,12 +581,7 @@ sml_bocdone(struct worker *wrk, struct objcore *oc, struct boc *boc) stv = oc->stobj->stevedore; CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC); - if (boc->stevedore_priv != NULL) { - /* Free any leftovers from Trim */ - CAST_OBJ_NOTNULL(st, boc->stevedore_priv, STORAGE_MAGIC); - boc->stevedore_priv = NULL; - sml_stv_free(stv, st); - } + sml_bocfini(stv, boc); if (stv->lru != NULL) { if (isnan(wrk->lastused)) From dridi.boukelmoune at gmail.com Mon Aug 28 07:22:09 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 28 Aug 2023 07:22:09 +0000 (UTC) Subject: [master] fa93cd8c7 vcc: Provision against exponent notation Message-ID: <20230828072209.737719BAE1@lists.varnish-cache.org> commit fa93cd8c76e4a0bc8ea9259eb4cf892a1cfc145a Author: Dridi Boukelmoune Date: Mon Aug 28 09:19:00 2023 +0200 vcc: Provision against exponent notation It is no longer supported in VCL, but strtod() will accept it. Fixes #3971 diff --git a/bin/varnishtest/tests/i00001.vtc b/bin/varnishtest/tests/i00001.vtc index 08cb59add..c29ae5b34 100644 --- a/bin/varnishtest/tests/i00001.vtc +++ b/bin/varnishtest/tests/i00001.vtc @@ -16,6 +16,10 @@ varnish v1 -errvcl {Too many digits for real.} { sub vcl_recv { set req.http.foo = 0.1234; } } +varnish v1 -errvcl {Unexpected character 'e'.} { + sub vcl_recv { set req.http.foo = 42.42e42; } +} + server s1 { rxreq txresp diff --git a/lib/libvcc/vcc_token.c b/lib/libvcc/vcc_token.c index 79af6eb58..268d5d4a7 100644 --- a/lib/libvcc/vcc_token.c +++ b/lib/libvcc/vcc_token.c @@ -503,6 +503,12 @@ vcc_lex_number(struct vcc *tl, struct source *sp, const char *p) vcc_ErrWhere(tl, tl->t); return (NULL); } + if (*tl->t->e == 'e' || *tl->t->e == 'E') { + VSB_printf(tl->sb, "Unexpected character '%c'.\n", *tl->t->e); + tl->t->e++; + vcc_ErrWhere(tl, tl->t); + return (NULL); + } tl->t->num = strtod(p, &s); assert(s == tl->t->e); return (r); From dridi.boukelmoune at gmail.com Mon Aug 28 13:02:06 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 28 Aug 2023 13:02:06 +0000 (UTC) Subject: [master] d09ee6409 vcc: Don't set obj.http.* symbols' lname and uname Message-ID: <20230828130206.7A20DAB0F3@lists.varnish-cache.org> commit d09ee6409a130b664a078cd051551b2ca7fd23c3 Author: Dridi Boukelmoune Date: Mon May 30 06:18:49 2022 +0200 vcc: Don't set obj.http.* symbols' lname and uname We don't need to since cache objects are mostly immutable and headers are read-only in VCL. Better diff with the --ignore-all-space option. diff --git a/lib/libvcc/vcc_var.c b/lib/libvcc/vcc_var.c index 286949e49..cb0b7e508 100644 --- a/lib/libvcc/vcc_var.c +++ b/lib/libvcc/vcc_var.c @@ -88,13 +88,19 @@ vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent, struct symbol *sym) /* Create the symbol r/l values */ sym->rname = TlDup(tl, VSB_data(vsb)); - VSB_clear(vsb); - VSB_printf(vsb, "VRT_SetHdr(ctx, %s,", sym->rname); - AZ(VSB_finish(vsb)); - sym->lname = TlDup(tl, VSB_data(vsb)); - VSB_clear(vsb); - VSB_printf(vsb, "VRT_UnsetHdr(ctx, %s)", sym->rname); - AZ(VSB_finish(vsb)); - sym->uname = TlDup(tl, VSB_data(vsb)); + + if (sym->w_methods) { + VSB_clear(vsb); + VSB_printf(vsb, "VRT_SetHdr(ctx, %s,", sym->rname); + AZ(VSB_finish(vsb)); + sym->lname = TlDup(tl, VSB_data(vsb)); + } + + if (sym->u_methods) { + VSB_clear(vsb); + VSB_printf(vsb, "VRT_UnsetHdr(ctx, %s)", sym->rname); + AZ(VSB_finish(vsb)); + sym->uname = TlDup(tl, VSB_data(vsb)); + } VSB_destroy(&vsb); } From dridi.boukelmoune at gmail.com Mon Aug 28 13:02:06 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 28 Aug 2023 13:02:06 +0000 (UTC) Subject: [master] a3d7d044c vcc: Tie wildcard-generated symbols to their parents Message-ID: <20230828130206.926BFAB0F6@lists.varnish-cache.org> commit a3d7d044c4c38d24c089ed743e567528b3418e0e Author: Dridi Boukelmoune Date: Mon May 30 06:21:42 2022 +0200 vcc: Tie wildcard-generated symbols to their parents diff --git a/lib/libvcc/vcc_var.c b/lib/libvcc/vcc_var.c index cb0b7e508..8257f1eb5 100644 --- a/lib/libvcc/vcc_var.c +++ b/lib/libvcc/vcc_var.c @@ -46,6 +46,7 @@ vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent, struct symbol *sym) struct vsb *vsb; const char *p; + AN(sym); assert(parent->type == HEADER); if (strlen(sym->name) >= 127) { @@ -65,11 +66,11 @@ vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent, struct symbol *sym) } } - AN(sym); sym->noref = 1; sym->kind = SYM_VAR; sym->type = parent->type; sym->eval = vcc_Eval_Var; + sym->eval_priv = parent; sym->r_methods = parent->r_methods; sym->w_methods = parent->w_methods; sym->u_methods = parent->u_methods; From dridi.boukelmoune at gmail.com Mon Aug 28 13:02:06 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 28 Aug 2023 13:02:06 +0000 (UTC) Subject: [master] 1c6237834 vcc: Emit HEADER C symbols in a dedicated function Message-ID: <20230828130206.B0172AB0FA@lists.varnish-cache.org> commit 1c6237834e2b4fcfe97d7d5fd73b5a209a18e4b7 Author: Dridi Boukelmoune Date: Mon May 30 06:24:33 2022 +0200 vcc: Emit HEADER C symbols in a dedicated function It turns out we no longer need the VSB at this point since it is equivalent to the symbol's rname. diff --git a/lib/libvcc/vcc_var.c b/lib/libvcc/vcc_var.c index 8257f1eb5..cfa3fec4c 100644 --- a/lib/libvcc/vcc_var.c +++ b/lib/libvcc/vcc_var.c @@ -40,6 +40,29 @@ /*--------------------------------------------------------------------*/ +static void +vcc_Header_Fh(struct vcc *tl, struct symbol *sym) +{ + const struct symbol *parent; + + AN(tl); + AN(sym); + AZ(sym->wildcard); + assert(sym->type == HEADER); + + parent = sym->eval_priv; + AN(parent); + AN(parent->wildcard); + assert(parent->type == HEADER); + + /* Create the static identifier */ + Fh(tl, 0, "static const struct gethdr_s %s =\n", sym->rname + 1); + Fh(tl, 0, " { %s, \"\\%03o%s:\"};\n", + parent->rname, (unsigned int)strlen(sym->name) + 1, sym->name); +} + +/*--------------------------------------------------------------------*/ + void v_matchproto_(sym_wildcard_t) vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent, struct symbol *sym) { @@ -82,11 +105,6 @@ vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent, struct symbol *sym) VCC_PrintCName(vsb, sym->name, NULL); AZ(VSB_finish(vsb)); - /* Create the static identifier */ - Fh(tl, 0, "static const struct gethdr_s %s =\n", VSB_data(vsb) + 1); - Fh(tl, 0, " { %s, \"\\%03o%s:\"};\n", - parent->rname, (unsigned int)strlen(sym->name) + 1, sym->name); - /* Create the symbol r/l values */ sym->rname = TlDup(tl, VSB_data(vsb)); @@ -104,4 +122,6 @@ vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent, struct symbol *sym) sym->uname = TlDup(tl, VSB_data(vsb)); } VSB_destroy(&vsb); + + vcc_Header_Fh(tl, sym); } From dridi.boukelmoune at gmail.com Mon Aug 28 13:02:06 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 28 Aug 2023 13:02:06 +0000 (UTC) Subject: [master] 00945a40c vcc: Be more explicit about wilcard symbols Message-ID: <20230828130206.D4B12AB0FF@lists.varnish-cache.org> commit 00945a40ccdd64d78b88684799ee5fcd1fe47e51 Author: Dridi Boukelmoune Date: Mon May 30 06:26:14 2022 +0200 vcc: Be more explicit about wilcard symbols diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index ab35bd7b5..a62e9427d 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -133,9 +133,18 @@ def varproto(s): fh.write(s + ";\n") varprotos[s] = True +def var_is_wildcard(sym): + return sym[-2:] == '.*' + +def var_symbol_name(sym): + if var_is_wildcard(sym): + return sym[:-2] + return sym + class vardef(object): - def __init__(self, nam, typ, rd, wr, wu, al, vlo, vhi): - self.nam = nam + def __init__(self, sym, typ, rd, wr, wu, al, vlo, vhi): + self.sym = sym + self.nam = var_symbol_name(sym) self.typ = typ self.rd = rd self.wr = wr @@ -157,7 +166,7 @@ class vardef(object): # fo.write("\t{ \"%s\", %s,\n" % (nm, self.typ)) fo.write("\tsym = VCC_MkSym(tl, \"%s\", SYM_MAIN," % self.nam) - if self.typ == "HEADER": + if var_is_wildcard(self.sym): fo.write(" SYM_NONE, %d, %d);\n" % (self.vlo, self.vhi)) fo.write("\tAN(sym);\n") fo.write("\tsym->wildcard = vcc_Var_Wildcard;\n") @@ -225,8 +234,6 @@ def parse_var(ln): l1 = ln.pop(0).split("``") assert len(l1) in (1, 3) vn = l1[0].strip() - if vn[-2:] == '.*': - vn = vn[:-2] if len(l1) == 3: vlo, vhi = parse_vcl(l1[1]) else: From dridi.boukelmoune at gmail.com Mon Aug 28 13:02:07 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 28 Aug 2023 13:02:07 +0000 (UTC) Subject: [master] 2b2a30c63 vcc: Add infrastructure for protected header fields Message-ID: <20230828130207.1F5E0AB104@lists.varnish-cache.org> commit 2b2a30c6338b90e108636533f8e81ed91e85cc5c Author: Dridi Boukelmoune Date: Mon May 30 06:29:41 2022 +0200 vcc: Add infrastructure for protected header fields diff --git a/bin/varnishtest/tests/r00694.vtc b/bin/varnishtest/tests/r00694.vtc index a28f4f124..37d7b4dcd 100644 --- a/bin/varnishtest/tests/r00694.vtc +++ b/bin/varnishtest/tests/r00694.vtc @@ -2,22 +2,19 @@ varnishtest "Wrong calculation of last storage segment length" server s1 { rxreq - send "HTTP/1.1 200 OK\r\n" - send "Transfer-encoding: chunked\r\n" - send "\r\n" + txresp -hdr "Transfer-encoding: chunked" # This is chunksize (128k) + 2 to force to chunks to be allocated chunkedlen 131074 chunkedlen 0 } -start -varnish v1 -vcl+backend { - sub vcl_deliver { - unset resp.http.content-length; - } -} -start +varnish v1 -vcl+backend "" -start client c1 { txreq -proto HTTP/1.0 rxresp + # Chunked encoding streaming HTTP/1.0 client turns + # into EOF body delivery. + expect resp.http.connection == close expect resp.bodylen == 131074 } -run diff --git a/bin/varnishtest/tests/r00801.vtc b/bin/varnishtest/tests/r00801.vtc deleted file mode 100644 index ca1a56703..000000000 --- a/bin/varnishtest/tests/r00801.vtc +++ /dev/null @@ -1,24 +0,0 @@ -varnishtest "Regression test for duplicate content-length in pass" - -server s1 { - rxreq - txresp \ - -hdr "Date: Mon, 25 Oct 2010 06:34:06 GMT" \ - -hdr "Content-length: 000010" \ - -nolen -bodylen 10 -} -start - - -varnish v1 -vcl+backend { - sub vcl_recv { return (pass); } - sub vcl_backend_response { - set beresp.do_stream = false; - unset beresp.http.content-length; - } -} -start - -client c1 { - txreq - rxresp - expect resp.http.content-length == "10" -} -run diff --git a/bin/varnishtest/tests/r00806.vtc b/bin/varnishtest/tests/r00806.vtc index 25567b58d..f2d682cab 100644 --- a/bin/varnishtest/tests/r00806.vtc +++ b/bin/varnishtest/tests/r00806.vtc @@ -14,13 +14,13 @@ varnish v1 -vcl+backend { sub vcl_recv { return(pass);} sub vcl_deliver { set resp.http.CL = resp.http.content-length; - unset resp.http.content-length; } } -start client c1 { txreq - rxresp -no_obj + rxresphdrs expect resp.status == 304 expect resp.http.cl == 100 + expect_close } -run diff --git a/bin/varnishtest/tests/v00001.vtc b/bin/varnishtest/tests/v00001.vtc index 1abed8076..8bcea8dbc 100644 --- a/bin/varnishtest/tests/v00001.vtc +++ b/bin/varnishtest/tests/v00001.vtc @@ -20,6 +20,16 @@ varnish v1 -errvcl "Variable is read only" { sub vcl_backend_response { set beresp.proto = "HTTP/1.2"; } } +varnish v1 -errvcl "Variable is read only" { + backend proforma None; + sub vcl_recv { set req.http.content-length = "42"; } +} + +varnish v1 -errvcl "Variable cannot be unset" { + backend proforma None; + sub vcl_recv { unset req.http.content-length; } +} + server s1 { rxreq txresp -hdr "Connection: close" -body "012345\n" diff --git a/doc/sphinx/reference/vcl-var.rst b/doc/sphinx/reference/vcl-var.rst index f2d832306..4d38f523f 100644 --- a/doc/sphinx/reference/vcl-var.rst +++ b/doc/sphinx/reference/vcl-var.rst @@ -35,6 +35,18 @@ and ``vcl_fini {}``. .. include:: vcl_var.rst +.. _protected_headers: + +Protected header fields +----------------------- + +The ``content-length`` and ``transfer-encoding`` headers are read-only. They +must be preserved to ensure HTTP/1 framing remains consistent and maintain a +proper request and response synchronization with both clients and backends. + +VMODs can still update these headers, when there is a reason to change the +framing, such as a transformation of a request or response body. + HTTP response status -------------------- diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst index b8a28c453..c207867e4 100644 --- a/doc/sphinx/reference/vcl_var.rst +++ b/doc/sphinx/reference/vcl_var.rst @@ -353,6 +353,27 @@ req.http.* headers present in IANA registries need to be quoted, so the quoted syntax is discouraged but available for interoperability. + Some headers that cannot be tampered with for proper HTTP fetch + or delivery are read-only. + + +req.http.content-length + + Type: HEADER + + Readable from: client + + The content-length header field is protected, see protected_headers_. + + +req.http.transfer-encoding + + Type: HEADER + + Readable from: client + + The transfer-encoding header field is protected, see protected_headers_. + .. _req.is_hitmiss: @@ -715,6 +736,24 @@ bereq.http.* See ``req.http.*`` for general notes. +bereq.http.content-length + + Type: HEADER + + Readable from: client + + The content-length header field is protected, see protected_headers_. + + +bereq.http.transfer-encoding + + Type: HEADER + + Readable from: client + + The transfer-encoding header field is protected, see protected_headers_. + + .. _bereq.is_bgfetch: bereq.is_bgfetch @@ -1119,6 +1158,24 @@ beresp.http.* See ``req.http.*`` for general notes. +beresp.http.content-length + + Type: HEADER + + Readable from: client + + The content-length header field is protected, see protected_headers_. + + +beresp.http.transfer-encoding + + Type: HEADER + + Readable from: client + + The transfer-encoding header field is protected, see protected_headers_. + + .. _beresp.keep: beresp.keep @@ -1551,6 +1608,24 @@ resp.http.* See ``req.http.*`` for general notes. +resp.http.content-length + + Type: HEADER + + Readable from: client + + The content-length header field is protected, see protected_headers_. + + +resp.http.transfer-encoding + + Type: HEADER + + Readable from: client + + The transfer-encoding header field is protected, see protected_headers_. + + .. _resp.is_streaming: resp.is_streaming diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index a62e9427d..fe5bcc9b4 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -174,20 +174,23 @@ class vardef(object): fo.write(" SYM_VAR, %d, %d);\n" % (self.vlo, self.vhi)) fo.write("\tAN(sym);\n") fo.write("\tsym->type = %s;\n" % self.typ) - fo.write("\tsym->eval = vcc_Eval_Var;\n") + if self.typ == "HEADER" and not var_is_wildcard(self.sym): + fo.write("\tsym->eval = vcc_Eval_ProtectedHeader;\n") + else: + fo.write("\tsym->eval = vcc_Eval_Var;\n") - if self.typ == "HEADER": + if var_is_wildcard(self.sym): fo.write('\tsym->rname = "HDR_') fo.write(self.nam.split(".")[0].upper()) fo.write('";\n') - elif self.rd: + elif self.rd and self.typ != "HEADER": fo.write('\tsym->rname = "VRT_r_%s(ctx)";\n' % cnam) varproto("VCL_" + self.typ + " VRT_r_%s(VRT_CTX)" % cnam) fo.write("\tsym->r_methods =\n") restrict(fo, self.rd) fo.write(";\n") - if self.typ == "HEADER": + if var_is_wildcard(self.sym): fo.write('\tsym->lname = "HDR_') fo.write(self.nam.split(".")[0].upper()) fo.write('";\n') diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h index b99e40fdf..369c66daa 100644 --- a/lib/libvcc/vcc_compile.h +++ b/lib/libvcc/vcc_compile.h @@ -355,6 +355,7 @@ sym_act_f vcc_Act_Call; sym_act_f vcc_Act_Obj; void vcc_Expr_Init(struct vcc *tl); sym_expr_t vcc_Eval_Var; +sym_expr_t vcc_Eval_ProtectedHeader; sym_expr_t vcc_Eval_Handle; sym_expr_t vcc_Eval_Sub; sym_expr_t vcc_Eval_SymFunc; @@ -455,6 +456,7 @@ char *vcc_Dup_be(const char *b, const char *e); int vcc_Has_vcl_prefix(const char *b); /* vcc_var.c */ +void vcc_Header_Fh(struct vcc *, struct symbol *); sym_wildcard_t vcc_Var_Wildcard; /* vcc_vmod.c */ diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c index 63578df9d..1e94dbf76 100644 --- a/lib/libvcc/vcc_expr.c +++ b/lib/libvcc/vcc_expr.c @@ -379,6 +379,19 @@ vcc_Eval_Var(struct vcc *tl, struct expr **e, struct token *t, (*e)->fmt = STRINGS; } +void v_matchproto_(sym_expr_t) +vcc_Eval_ProtectedHeader(struct vcc *tl, struct expr **e, struct token *t, + struct symbol *sym, vcc_type_t type) +{ + + AN(sym); + AZ(sym->lorev); + + vcc_Header_Fh(tl, sym); + sym->eval = vcc_Eval_Var; + vcc_Eval_Var(tl, e, t, sym, type); +} + /*-------------------------------------------------------------------- */ diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c index 61d05e156..fc273f2de 100644 --- a/lib/libvcc/vcc_symb.c +++ b/lib/libvcc/vcc_symb.c @@ -438,6 +438,7 @@ VCC_MkSym(struct vcc *tl, const char *b, vcc_ns_t ns, vcc_kind_t kind, { struct symtab *st; struct symbol *sym; + const struct symbol *parent; AN(tl); AN(b); @@ -450,6 +451,14 @@ VCC_MkSym(struct vcc *tl, const char *b, vcc_ns_t ns, vcc_kind_t kind, st = vcc_symtab_str(tl->syms[ns->id], b, NULL, ID); AN(st); sym = vcc_sym_in_tab(tl, st, kind, vlo, vhi); + if (sym != NULL) { + assert(sym->kind == SYM_VAR); + parent = sym->eval_priv; + AN(parent); + AN(parent->wildcard); + assert(sym->type == parent->type); + return (sym); + } AZ(sym); sym = vcc_new_symbol(tl, st, kind, vlo, vhi); AN(sym); diff --git a/lib/libvcc/vcc_var.c b/lib/libvcc/vcc_var.c index cfa3fec4c..7292924ae 100644 --- a/lib/libvcc/vcc_var.c +++ b/lib/libvcc/vcc_var.c @@ -40,7 +40,7 @@ /*--------------------------------------------------------------------*/ -static void +void vcc_Header_Fh(struct vcc *tl, struct symbol *sym) { const struct symbol *parent; @@ -123,5 +123,6 @@ vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent, struct symbol *sym) } VSB_destroy(&vsb); - vcc_Header_Fh(tl, sym); + if (sym->lorev > 0) + vcc_Header_Fh(tl, sym); } From dridi.boukelmoune at gmail.com Mon Aug 28 13:02:07 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 28 Aug 2023 13:02:07 +0000 (UTC) Subject: [master] 4957292ff man: Use references to HEADER variables Message-ID: <20230828130207.3AA84AB108@lists.varnish-cache.org> commit 4957292ff900863b992e6f87a34a911a2cb30d3a Author: Dridi Boukelmoune Date: Mon Jul 3 09:09:54 2023 +0200 man: Use references to HEADER variables diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst index c207867e4..b9b74f0e3 100644 --- a/doc/sphinx/reference/vcl_var.rst +++ b/doc/sphinx/reference/vcl_var.rst @@ -550,7 +550,7 @@ req_top.http.* HTTP headers of the top-level request in a tree of ESI requests. Identical to req.http. in non-ESI requests. - See ``req.http.*`` for general notes. + See req.http_ for general notes. .. _req_top.method: @@ -670,7 +670,7 @@ bereq.body The request body. - Unset will also remove ``bereq.http.Content-Length``. + Unset will also remove bereq.http.content-length_. .. _bereq.connect_timeout: @@ -733,9 +733,11 @@ bereq.http.* The headers to be sent to the backend. - See ``req.http.*`` for general notes. + See req.http_ for general notes. +.. _bereq.http.content-length: + bereq.http.content-length Type: HEADER @@ -1155,7 +1157,7 @@ beresp.http.* The HTTP headers returned from the server. - See ``req.http.*`` for general notes. + See req.http_ for general notes. beresp.http.content-length @@ -1422,7 +1424,7 @@ obj.http.* The HTTP headers stored in the object. - See ``req.http.*`` for general notes. + See req.http_ for general notes. .. _obj.keep: @@ -1605,7 +1607,7 @@ resp.http.* The HTTP headers that will be returned. - See ``req.http.*`` for general notes. + See req.http_ for general notes. resp.http.content-length From dridi.boukelmoune at gmail.com Mon Aug 28 13:10:06 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 28 Aug 2023 13:10:06 +0000 (UTC) Subject: [master] 1a43a0e1f vte: Add support for left-justified fields Message-ID: <20230828131006.8117BABD4F@lists.varnish-cache.org> commit 1a43a0e1f67c412fe5cc9a4e01b603774f2e36d0 Author: Dridi Boukelmoune Date: Tue Aug 22 10:25:00 2023 +0200 vte: Add support for left-justified fields diff --git a/include/vte.h b/include/vte.h index 43279bc9a..fcd13fb2b 100644 --- a/include/vte.h +++ b/include/vte.h @@ -30,9 +30,11 @@ * * Align and print fields in a line-based output. Fields are delimited * with a horizontal tab HT and lines starting with a space SP are kept - * verbatim. Lines are delimited with a single new line LF character. + * verbatim. Lines are delimited with a single new line LF character. A + * field starting with a vertical tab VT is justified to the left. * - * Using non-ASCII or non-printable ASCII character is undefined behavior. + * Using non-ASCII or non-printable ASCII characters besides delimiters + * and modifiers for fields and lines is undefined behavior. */ struct vte; diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c index 44ac71afa..3ebf57086 100644 --- a/lib/libvarnish/vte.c +++ b/lib/libvarnish/vte.c @@ -116,6 +116,8 @@ vte_update(struct vte *vte) vte->f_off = -1; continue; } + if (vte->f_off >= 0 && vte->f_sz == 0 && *p == '\v') + p++; if (*p == '\t' || *p == '\n') { fno = vte->f_off; if (fno >= 0 && vte->f_sz > vte->f_maxsz[fno]) @@ -240,8 +242,8 @@ VTE_finish(struct vte *vte) int VTE_format(const struct vte *vte, VTE_format_f *func, void *priv) { - int fno, fsz, nsp; - const char *p, *q; + int fno, fsz, nsp, just_left; + const char *p, *q, *sep; CHECK_OBJ_NOTNULL(vte, VTE_MAGIC); AN(func); @@ -255,22 +257,42 @@ VTE_format(const struct vte *vte, VTE_format_f *func, void *priv) q = p; fno = 0; + sep = ""; + just_left = 0; while (*p != 0) { - if (fno == 0 && *p == ' ') + if (*p == '\v') { + if (p - 1 > q) { /* exclude previous separator */ + VTE_FORMAT(func, priv, "%.*s%s", + (int)(p - 1 - q), q, sep); + } + q = ++p; + just_left = 1; + } + if (!just_left && fno == 0 && *p == ' ') fsz = strcspn(p, "\n"); else fsz = strcspn(p, "\t\n"); p += fsz; if (*p == '\t') { assert(vte->f_maxsz[fno] + nsp > fsz); - VTE_FORMAT(func, priv, "%.*s%*s", - (int)(p - q), q, - vte->f_maxsz[fno] + nsp - fsz, ""); + if (just_left) { + VTE_FORMAT(func, priv, "%*s%.*s%*s", + vte->f_maxsz[fno] - fsz, "", + (int)(p - q), q, + nsp, ""); + just_left = 0; + } else { + VTE_FORMAT(func, priv, "%.*s%*s", + (int)(p - q), q, + vte->f_maxsz[fno] + nsp - fsz, ""); + } fno++; q = ++p; + sep = ""; } else if (*p == '\n') { fno = 0; p++; + sep = "\n"; } } From dridi.boukelmoune at gmail.com Mon Aug 28 13:10:06 2023 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 28 Aug 2023 13:10:06 +0000 (UTC) Subject: [master] ca32d1467 cache_vcl: Align vcl.list reference counters right Message-ID: <20230828131006.B1DB9ABD52@lists.varnish-cache.org> commit ca32d146710824c1e05941f5819771a7d50fc45d Author: Dridi Boukelmoune Date: Tue Aug 22 12:07:57 2023 +0200 cache_vcl: Align vcl.list reference counters right And drop the artificial 6 digits pseudo-alignment, leading to a more compact output when VCLs get less than 100k concurrent client tasks. diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index 0ab200739..29d4b459f 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -768,7 +768,7 @@ vcl_cli_list(struct cli *cli, const char * const *av, void *priv) flg = "discarded"; } else flg = "available"; - VTE_printf(vte, "%s\t%s\t%s\t%6u\t%s", flg, vcl->state, + VTE_printf(vte, "%s\t%s\t%s\t\v%u\t%s", flg, vcl->state, vcl->temp->name, vcl->busy, vcl->loaded_name); if (vcl->label != NULL) { VTE_printf(vte, "\t->\t%s", vcl->label->loaded_name); diff --git a/bin/varnishtest/tests/r02471.vtc b/bin/varnishtest/tests/r02471.vtc index a573d4a3c..994480af5 100644 --- a/bin/varnishtest/tests/r02471.vtc +++ b/bin/varnishtest/tests/r02471.vtc @@ -23,7 +23,7 @@ varnish v1 -vcl+backend {} varnish v1 -cliok "vcl.state vcl1 cold" # Nothing holds vcl1, so it should go gold. -varnish v1 -cliexpect "cold cold 0 vcl1" "vcl.list" +varnish v1 -cliexpect "cold cold 0 vcl1" "vcl.list" # Grab hold of vcl1 @@ -43,7 +43,7 @@ client c1 { # There should still be a single busy hold on vcl1 varnish v1 -cliok "vcl.state vcl1 cold" -varnish v1 -cliexpect "cold busy [12] vcl1" "vcl.list" +varnish v1 -cliexpect "cold busy [12] vcl1" "vcl.list" # Release hold on vcl1 varnish v1 -cliok "vcl.state vcl1 auto" @@ -62,4 +62,4 @@ client c1 { # Nothing holds vcl1, so it should go gold. varnish v1 -cliok "vcl.state vcl1 cold" -varnish v1 -cliexpect "cold [a-z]+ [01] vcl1" "vcl.list" +varnish v1 -cliexpect "cold .... [01] vcl1" "vcl.list" diff --git a/bin/varnishtest/tests/u00000.vtc b/bin/varnishtest/tests/u00000.vtc index c33bfc9e4..11cbdb4a0 100644 --- a/bin/varnishtest/tests/u00000.vtc +++ b/bin/varnishtest/tests/u00000.vtc @@ -152,8 +152,8 @@ shell { } varnish v2 -arg "-f ${tmpdir}/ok1" -arg "-f ${tmpdir}/ok2" -start -varnish v2 -cliexpect {available auto warm 0 boot0} "vcl.list" -varnish v2 -cliexpect {active auto warm 0 boot} "vcl.list" +varnish v2 -cliexpect {available auto warm 0 boot0} "vcl.list" +varnish v2 -cliexpect {active auto warm 0 boot1} "vcl.list" varnish v2 -stop -wait # Test multiple -f options with a bad VCL diff --git a/bin/varnishtest/tests/v00045.vtc b/bin/varnishtest/tests/v00045.vtc index 60504ce73..812c0392a 100644 --- a/bin/varnishtest/tests/v00045.vtc +++ b/bin/varnishtest/tests/v00045.vtc @@ -17,7 +17,7 @@ varnish v1 -cliok "vcl.state vcl1 cold" # We should now see it as cooling delay 1 -varnish v1 -cliexpect "available cold cooling 0 vcl1" vcl.list +varnish v1 -cliexpect "available cold cooling 0 vcl1" vcl.list varnish v1 -clijson "vcl.list -j" # It can't be warmed up yet @@ -26,7 +26,7 @@ varnish v1 -cliexpect "vmod-debug ref on vcl1" "vcl.state vcl1 warm" # It will eventually cool down delay 2 -varnish v1 -cliexpect "available cold cold 0 vcl1" vcl.list +varnish v1 -cliexpect "available cold cold 0 vcl1" vcl.list varnish v1 -clijson "vcl.list -j" # At this point it becomes possible to warm up again From nils.goroll at uplex.de Mon Aug 28 14:07:06 2023 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 28 Aug 2023 14:07:06 +0000 (UTC) Subject: [master] 48d9f8094 Add VSHA_* to libvarnishapi Message-ID: <20230828140706.1BFFBADC41@lists.varnish-cache.org> commit 48d9f8094c9a54f4e41b44abc3931193b9ccdf7b Author: Nils Goroll Date: Mon Aug 28 16:04:24 2023 +0200 Add VSHA_* to libvarnishapi Ref #3946 diff --git a/doc/changes.rst b/doc/changes.rst index fb66ea442..1af371255 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -38,6 +38,8 @@ Varnish Cache NEXT (2023-09-15) .. PLEASE keep this roughly in commit order as shown by git-log / tig (new to old) +* The ``VSHA256_*`` functions have been added to libvarnishapi. + * Two bugs in the ban expression parser have been fixed where one of them could lead to a panic if a ban expression with an empty header name was issued (3962_) diff --git a/lib/libvarnishapi/libvarnishapi.map b/lib/libvarnishapi/libvarnishapi.map index 87a23a2b6..7fe8deb3c 100644 --- a/lib/libvarnishapi/libvarnishapi.map +++ b/lib/libvarnishapi/libvarnishapi.map @@ -168,6 +168,11 @@ LIBVARNISHAPI_3.1 { /* 2023-09-15 release */ # venc.c VENC_Encode_Base64; VENC_Decode_Base64; + # vsha256.c + VSHA256_Init; + VSHA256_Update; + VSHA256_Final; + VSHA256_Test; local: *; From phk at FreeBSD.org Wed Aug 30 12:47:09 2023 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 30 Aug 2023 12:47:09 +0000 (UTC) Subject: [master] 59945b9d0 zlib 1.3 convergence: Get rid of OF(...) Message-ID: <20230830124709.41F1A64F8D@lists.varnish-cache.org> commit 59945b9d0fbf0774a561fdbc4bbcea023fcbccd9 Author: Poul-Henning Kamp Date: Wed Aug 30 09:42:50 2023 +0000 zlib 1.3 convergence: Get rid of OF(...) diff --git a/lib/libvgz/adler32.c b/lib/libvgz/adler32.c index 7a3d10ccc..25f11472c 100644 --- a/lib/libvgz/adler32.c +++ b/lib/libvgz/adler32.c @@ -8,7 +8,7 @@ #include "zutil.h" #ifdef NOVGZ -local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); +local uLong adler32_combine_ (uLong adler1, uLong adler2, z_off64_t len2); #define BASE 65521U /* largest prime smaller than 65536 */ #define NMAX 5552 diff --git a/lib/libvgz/crc32.c b/lib/libvgz/crc32.c index 32c6d5b77..fd68dcbdf 100644 --- a/lib/libvgz/crc32.c +++ b/lib/libvgz/crc32.c @@ -104,16 +104,16 @@ #endif /* Local functions. */ -local z_crc_t multmodp OF((z_crc_t a, z_crc_t b)); -local z_crc_t x2nmodp OF((z_off64_t n, unsigned k)); +local z_crc_t multmodp (z_crc_t a, z_crc_t b); +local z_crc_t x2nmodp (z_off64_t n, unsigned k); #if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) - local z_word_t byte_swap OF((z_word_t word)); + local z_word_t byte_swap (z_word_t word); #endif #if defined(W) && !defined(ARMCRC32) - local z_crc_t crc_word OF((z_word_t data)); - local z_word_t crc_word_big OF((z_word_t data)); + local z_crc_t crc_word (z_word_t data); + local z_word_t crc_word_big (z_word_t data); #endif #if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) @@ -123,7 +123,7 @@ local z_crc_t x2nmodp OF((z_off64_t n, unsigned k)); instruction, if one is available. This assumes that word_t is either 32 bits or 64 bits. */ -local z_word_t byte_swap OF((z_word_t word)); +local z_word_t byte_swap (z_word_t word); local z_word_t byte_swap( z_word_t word @@ -156,17 +156,17 @@ local z_word_t byte_swap( local z_crc_t FAR crc_table[256]; local z_crc_t FAR x2n_table[32]; -local void make_crc_table OF((void)); +local void make_crc_table (void); #ifdef W local z_word_t FAR crc_big_table[256]; local z_crc_t FAR crc_braid_table[W][256]; local z_word_t FAR crc_braid_big_table[W][256]; - local void braid OF((z_crc_t [][256], z_word_t [][256], int, int)); + local void braid (z_crc_t [][256], z_word_t [][256], int, int); #endif #ifdef MAKECRCH - local void write_table OF((FILE *, const z_crc_t FAR *, int)); - local void write_table32hi OF((FILE *, const z_word_t FAR *, int)); - local void write_table64 OF((FILE *, const z_word_t FAR *, int)); + local void write_table (FILE *, const z_crc_t FAR *, int); + local void write_table32hi (FILE *, const z_word_t FAR *, int); + local void write_table64 (FILE *, const z_word_t FAR *, int); #endif /* MAKECRCH */ /* @@ -179,7 +179,7 @@ local void make_crc_table OF((void)); /* Definition of once functionality. */ typedef struct once_s once_t; -local void once OF((once_t *, void (*)(void))); +local void once (once_t *, void (*)(void)); /* Check for the availability of atomics. */ #if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \ @@ -225,7 +225,7 @@ struct once_s { /* Test and set. Alas, not atomic, but tries to minimize the period of vulnerability. */ -local int test_and_set OF((int volatile *)); +local int test_and_set (int volatile *); local int test_and_set(flag) int volatile *flag; { @@ -728,7 +728,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) least-significant byte of the word as the first byte of data, without any pre or post conditioning. This is used to combine the CRCs of each braid. */ -local z_crc_t crc_word OF((z_word_t data)); +local z_crc_t crc_word (z_word_t data); local z_crc_t crc_word( z_word_t data @@ -740,7 +740,7 @@ local z_crc_t crc_word( return (z_crc_t)data; } -local z_word_t crc_word_big OF((z_word_t data)); +local z_word_t crc_word_big (z_word_t data); local z_word_t crc_word_big( z_word_t data diff --git a/lib/libvgz/deflate.c b/lib/libvgz/deflate.c index 32b395342..4dd3447aa 100644 --- a/lib/libvgz/deflate.c +++ b/lib/libvgz/deflate.c @@ -71,30 +71,30 @@ typedef enum { finish_done /* finish done, accept no more input or output */ } block_state; -typedef block_state (*compress_func) OF((deflate_state *s, int flush)); +typedef block_state (*compress_func) (deflate_state *s, int flush); /* Compression function. Returns the block state after the call. */ -local int deflateStateCheck OF((z_streamp strm)); -local void slide_hash OF((deflate_state *s)); -local void fill_window OF((deflate_state *s)); -local block_state deflate_stored OF((deflate_state *s, int flush)); -local block_state deflate_fast OF((deflate_state *s, int flush)); +local int deflateStateCheck (z_streamp strm); +local void slide_hash (deflate_state *s); +local void fill_window (deflate_state *s); +local block_state deflate_stored (deflate_state *s, int flush); +local block_state deflate_fast (deflate_state *s, int flush); #ifndef FASTEST -local block_state deflate_slow OF((deflate_state *s, int flush)); +local block_state deflate_slow (deflate_state *s, int flush); #endif #ifdef NOVGZ -local block_state deflate_rle OF((deflate_state *s, int flush)); -local block_state deflate_huff OF((deflate_state *s, int flush)); +local block_state deflate_rle (deflate_state *s, int flush); +local block_state deflate_huff (deflate_state *s, int flush); #endif /* NOVGZ */ -local void lm_init OF((deflate_state *s)); -local void putShortMSB OF((deflate_state *s, uInt b)); -local void flush_pending OF((z_streamp strm)); -local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); -local uInt longest_match OF((deflate_state *s, IPos cur_match)); +local void lm_init (deflate_state *s); +local void putShortMSB (deflate_state *s, uInt b); +local void flush_pending (z_streamp strm); +local unsigned read_buf (z_streamp strm, Bytef *buf, unsigned size); +local uInt longest_match (deflate_state *s, IPos cur_match); #ifdef ZLIB_DEBUG -local void check_match OF((deflate_state *s, IPos start, IPos match, - int length)); +local void check_match (deflate_state *s, IPos start, IPos match, + int length); #endif /* =========================================================================== diff --git a/lib/libvgz/deflate.h b/lib/libvgz/deflate.h index 1a06cd5f2..6d9f6945e 100644 --- a/lib/libvgz/deflate.h +++ b/lib/libvgz/deflate.h @@ -291,14 +291,14 @@ typedef struct internal_state { memory checker errors from longest match routines */ /* in trees.c */ -void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); -int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); -void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); -void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); +void ZLIB_INTERNAL _tr_init (deflate_state *s); +int ZLIB_INTERNAL _tr_tally (deflate_state *s, unsigned dist, unsigned lc); +void ZLIB_INTERNAL _tr_flush_block (deflate_state *s, charf *buf, + ulg stored_len, int last); +void ZLIB_INTERNAL _tr_flush_bits (deflate_state *s); +void ZLIB_INTERNAL _tr_align (deflate_state *s); +void ZLIB_INTERNAL _tr_stored_block (deflate_state *s, charf *buf, + ulg stored_len, int last); #define d_code(dist) \ ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) diff --git a/lib/libvgz/gzguts.h b/lib/libvgz/gzguts.h index 3991076e6..433c8d8af 100644 --- a/lib/libvgz/gzguts.h +++ b/lib/libvgz/gzguts.h @@ -119,8 +119,8 @@ /* gz* functions always use library allocation functions */ #ifndef STDC - extern voidp malloc OF((uInt size)); - extern void free OF((voidpf ptr)); + extern voidp malloc (uInt size); + extern void free (voidpf ptr); #endif /* get errno and strerror definition */ @@ -138,10 +138,10 @@ /* provide prototypes for these when building zlib without LFS */ #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); - ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN gzFile ZEXPORT gzopen64 (const char *, const char *); + ZEXTERN z_off64_t ZEXPORT gzseek64 (gzFile, z_off64_t, int); + ZEXTERN z_off64_t ZEXPORT gztell64 (gzFile); + ZEXTERN z_off64_t ZEXPORT gzoffset64 (gzFile); #endif /* default memLevel */ @@ -203,9 +203,9 @@ typedef struct { typedef gz_state FAR *gz_statep; /* shared functions */ -void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); +void ZLIB_INTERNAL gz_error (gz_statep, int, const char *); #if defined UNDER_CE -char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); +char ZLIB_INTERNAL *gz_strwinerror (DWORD error); #endif /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t @@ -214,6 +214,6 @@ char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); #ifdef INT_MAX # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) #else -unsigned ZLIB_INTERNAL gz_intmax OF((void)); +unsigned ZLIB_INTERNAL gz_intmax (void); # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) #endif diff --git a/lib/libvgz/inffast.h b/lib/libvgz/inffast.h index e5c1aa4ca..96bd8abb8 100644 --- a/lib/libvgz/inffast.h +++ b/lib/libvgz/inffast.h @@ -8,4 +8,4 @@ subject to change. Applications should only use zlib.h. */ -void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); +void ZLIB_INTERNAL inflate_fast (z_streamp strm, unsigned start); diff --git a/lib/libvgz/inflate.c b/lib/libvgz/inflate.c index cfd708391..7cdee41b0 100644 --- a/lib/libvgz/inflate.c +++ b/lib/libvgz/inflate.c @@ -92,16 +92,16 @@ #endif /* function prototypes */ -local int inflateStateCheck OF((z_streamp strm)); -local void fixedtables OF((struct inflate_state FAR *state)); -local int updatewindow OF((z_streamp strm, const unsigned char FAR *end, - unsigned copy)); +local int inflateStateCheck (z_streamp strm); +local void fixedtables (struct inflate_state FAR *state); +local int updatewindow (z_streamp strm, const unsigned char FAR *end, + unsigned copy); #ifdef BUILDFIXED - void makefixed OF((void)); + void makefixed (void); #endif #ifdef NOVGZ -local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, - unsigned len)); +local unsigned syncsearch (unsigned FAR *have, const unsigned char FAR *buf, + unsigned len); #endif /* NOVGZ */ local int inflateStateCheck( diff --git a/lib/libvgz/inftrees.h b/lib/libvgz/inftrees.h index f53665311..c96d3b62a 100644 --- a/lib/libvgz/inftrees.h +++ b/lib/libvgz/inftrees.h @@ -57,6 +57,6 @@ typedef enum { DISTS } codetype; -int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, +int ZLIB_INTERNAL inflate_table (codetype type, unsigned short FAR *lens, unsigned codes, code FAR * FAR *table, - unsigned FAR *bits, unsigned short FAR *work)); + unsigned FAR *bits, unsigned short FAR *work); diff --git a/lib/libvgz/trees.c b/lib/libvgz/trees.c index 87b5c5f32..7f1f949fe 100644 --- a/lib/libvgz/trees.c +++ b/lib/libvgz/trees.c @@ -135,26 +135,26 @@ local const static_tree_desc static_bl_desc = * Local (static) routines in this file. */ -local void tr_static_init OF((void)); -local void init_block OF((deflate_state *s)); -local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); -local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); -local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); -local void build_tree OF((deflate_state *s, tree_desc *desc)); -local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local int build_bl_tree OF((deflate_state *s)); -local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, - int blcodes)); -local void compress_block OF((deflate_state *s, const ct_data *ltree, - const ct_data *dtree)); -local int detect_data_type OF((deflate_state *s)); -local unsigned bi_reverse OF((unsigned code, int len)); -local void bi_windup OF((deflate_state *s)); -local void bi_flush OF((deflate_state *s)); +local void tr_static_init (void); +local void init_block (deflate_state *s); +local void pqdownheap (deflate_state *s, ct_data *tree, int k); +local void gen_bitlen (deflate_state *s, tree_desc *desc); +local void gen_codes (ct_data *tree, int max_code, ushf *bl_count); +local void build_tree (deflate_state *s, tree_desc *desc); +local void scan_tree (deflate_state *s, ct_data *tree, int max_code); +local void send_tree (deflate_state *s, ct_data *tree, int max_code); +local int build_bl_tree (deflate_state *s); +local void send_all_trees (deflate_state *s, int lcodes, int dcodes, + int blcodes); +local void compress_block (deflate_state *s, const ct_data *ltree, + const ct_data *dtree); +local int detect_data_type (deflate_state *s); +local unsigned bi_reverse (unsigned code, int len); +local void bi_windup (deflate_state *s); +local void bi_flush (deflate_state *s); #ifdef GEN_TREES_H -local void gen_trees_header OF((void)); +local void gen_trees_header (void); #endif #ifndef ZLIB_DEBUG @@ -181,7 +181,7 @@ local void gen_trees_header OF((void)); * IN assertion: length <= 16 and value fits in length bits. */ #ifdef ZLIB_DEBUG -local void send_bits OF((deflate_state *s, int value, int length)); +local void send_bits (deflate_state *s, int value, int length); local void send_bits(s, value, length) deflate_state *s; diff --git a/lib/libvgz/vgz.h b/lib/libvgz/vgz.h index c545df07a..a91fd3d66 100644 --- a/lib/libvgz/vgz.h +++ b/lib/libvgz/vgz.h @@ -78,8 +78,8 @@ extern "C" { even in the case of corrupted input. */ -typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); -typedef void (*free_func) OF((voidpf opaque, voidpf address)); +typedef voidpf (*alloc_func) (voidpf opaque, uInt items, uInt size); +typedef void (*free_func) (voidpf opaque, voidpf address); struct internal_state; @@ -222,7 +222,7 @@ typedef gz_header FAR *gz_headerp; /* basic functions */ -ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +ZEXTERN const char * ZEXPORT zlibVersion (void); /* The application can compare zlibVersion and ZLIB_VERSION for consistency. If the first character differs, the library code actually used is not compatible with the zlib.h header file used by the application. This check @@ -230,7 +230,7 @@ ZEXTERN const char * ZEXPORT zlibVersion OF((void)); */ /* -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); +ZEXTERN int ZEXPORT deflateInit (z_streamp strm, int level); Initializes the internal stream state for compression. The fields zalloc, zfree and opaque must be initialized before by the caller. If @@ -252,7 +252,7 @@ ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); */ -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +ZEXTERN int ZEXPORT deflate (z_streamp strm, int flush); /* deflate compresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce @@ -365,7 +365,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); */ -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT deflateEnd (z_streamp strm); /* All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending @@ -380,7 +380,7 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); /* -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateInit (z_streamp strm); Initializes the internal stream state for decompression. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized before by @@ -402,7 +402,7 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); */ -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +ZEXTERN int ZEXPORT inflate (z_streamp strm, int flush); /* inflate decompresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce @@ -522,7 +522,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); */ -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateEnd (z_streamp strm); /* All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending @@ -540,12 +540,12 @@ ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); */ /* -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, +ZEXTERN int ZEXPORT deflateInit2 (z_streamp strm, int level, int method, int windowBits, int memLevel, - int strategy)); + int strategy); This is another version of deflateInit with more compression options. The fields zalloc, zfree and opaque must be initialized before by the caller. @@ -612,9 +612,9 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, compression: this will be done by deflate(). */ -ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, +ZEXTERN int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, - uInt dictLength)); + uInt dictLength); /* Initializes the compression dictionary from the given byte sequence without producing any compressed output. When using the zlib format, this @@ -656,9 +656,9 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, not perform any compression: this will be done by deflate(). */ -ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, +ZEXTERN int ZEXPORT deflateGetDictionary (z_streamp strm, Bytef *dictionary, - uInt *dictLength)); + uInt *dictLength); /* Returns the sliding dictionary being maintained by deflate. dictLength is set to the number of bytes in the dictionary, and that many bytes are copied @@ -678,8 +678,8 @@ ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, stream state is inconsistent. */ -ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, - z_streamp source)); +ZEXTERN int ZEXPORT deflateCopy (z_streamp dest, + z_streamp source); /* Sets the destination stream as a complete copy of the source stream. @@ -696,7 +696,7 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, destination. */ -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +ZEXTERN int ZEXPORT deflateReset (z_streamp strm); /* This function is equivalent to deflateEnd followed by deflateInit, but does not free and reallocate the internal compression state. The stream @@ -707,9 +707,9 @@ ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); stream state was inconsistent (such as zalloc or state being Z_NULL). */ -ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, +ZEXTERN int ZEXPORT deflateParams (z_streamp strm, int level, - int strategy)); + int strategy); /* Dynamically update the compression level and compression strategy. The interpretation of level and strategy is as in deflateInit2(). This can be @@ -745,11 +745,11 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, retried with more output space. */ -ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, +ZEXTERN int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, - int max_chain)); + int max_chain); /* Fine tune deflate's internal compression parameters. This should only be used by someone who understands the algorithm used by zlib's deflate for @@ -762,8 +762,8 @@ ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. */ -ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, - uLong sourceLen)); +ZEXTERN uLong ZEXPORT deflateBound (z_streamp strm, + uLong sourceLen); /* deflateBound() returns an upper bound on the compressed size after deflation of sourceLen bytes. It must be called after deflateInit() or @@ -777,9 +777,9 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, than Z_FINISH or Z_NO_FLUSH are used. */ -ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, +ZEXTERN int ZEXPORT deflatePending (z_streamp strm, unsigned *pending, - int *bits)); + int *bits); /* deflatePending() returns the number of bytes and bits of output that have been generated, but not yet provided in the available output. The bytes not @@ -792,9 +792,9 @@ ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, stream state was inconsistent. */ -ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, +ZEXTERN int ZEXPORT deflatePrime (z_streamp strm, int bits, - int value)); + int value); /* deflatePrime() inserts bits in the deflate output stream. The intent is that this function is used to start off the deflate output with the bits @@ -809,8 +809,8 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, source stream state was inconsistent. */ -ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, - gz_headerp head)); +ZEXTERN int ZEXPORT deflateSetHeader (z_streamp strm, + gz_headerp head); /* deflateSetHeader() provides gzip header information for when a gzip stream is requested by deflateInit2(). deflateSetHeader() may be called @@ -834,8 +834,8 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, */ /* -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, - int windowBits)); +ZEXTERN int ZEXPORT inflateInit2 (z_streamp strm, + int windowBits); This is another version of inflateInit with an extra parameter. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized @@ -888,9 +888,9 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, deferred until inflate() is called. */ -ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, +ZEXTERN int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, - uInt dictLength)); + uInt dictLength); /* Initializes the decompression dictionary from the given uncompressed byte sequence. This function must be called immediately after a call of inflate, @@ -911,9 +911,9 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, inflate(). */ -ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, +ZEXTERN int ZEXPORT inflateGetDictionary (z_streamp strm, Bytef *dictionary, - uInt *dictLength)); + uInt *dictLength); /* Returns the sliding dictionary being maintained by inflate. dictLength is set to the number of bytes in the dictionary, and that many bytes are copied @@ -926,7 +926,7 @@ ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, stream state is inconsistent. */ -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateSync (z_streamp strm); /* Skips invalid compressed data until a possible full flush point (see above for the description of deflate with Z_FULL_FLUSH) can be found, or until all @@ -945,8 +945,8 @@ ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); input each time, until success or end of the input data. */ -ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, - z_streamp source)); +ZEXTERN int ZEXPORT inflateCopy (z_streamp dest, + z_streamp source); /* Sets the destination stream as a complete copy of the source stream. @@ -961,7 +961,7 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, destination. */ -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateReset (z_streamp strm); /* This function is equivalent to inflateEnd followed by inflateInit, but does not free and reallocate the internal decompression state. The @@ -971,8 +971,8 @@ ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); stream state was inconsistent (such as zalloc or state being Z_NULL). */ -ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, - int windowBits)); +ZEXTERN int ZEXPORT inflateReset2 (z_streamp strm, + int windowBits); /* This function is the same as inflateReset, but it also permits changing the wrap and window size requests. The windowBits parameter is interpreted @@ -985,9 +985,9 @@ ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, the windowBits parameter is invalid. */ -ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, +ZEXTERN int ZEXPORT inflatePrime (z_streamp strm, int bits, - int value)); + int value); /* This function inserts bits in the inflate input stream. The intent is that this function is used to start inflating at a bit position in the @@ -1006,7 +1006,7 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, stream state was inconsistent. */ -ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +ZEXTERN long ZEXPORT inflateMark (z_streamp strm); /* This function returns two values, one in the lower 16 bits of the return value, and the other in the remaining upper bits, obtained by shifting the @@ -1034,8 +1034,8 @@ ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); source stream state was inconsistent. */ -ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, - gz_headerp head)); +ZEXTERN int ZEXPORT inflateGetHeader (z_streamp strm, + gz_headerp head); /* inflateGetHeader() requests that gzip header information be stored in the provided gz_header structure. inflateGetHeader() may be called after @@ -1075,8 +1075,8 @@ ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, */ /* -ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, - unsigned char FAR *window)); +ZEXTERN int ZEXPORT inflateBackInit (z_streamp strm, int windowBits, + unsigned char FAR *window); Initialize the internal stream state for decompression using inflateBack() calls. The fields zalloc, zfree and opaque in strm must be initialized @@ -1096,13 +1096,13 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, the version of the header file. */ -typedef unsigned (*in_func) OF((void FAR *, - z_const unsigned char FAR * FAR *)); -typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); +typedef unsigned (*in_func) (void FAR *, + z_const unsigned char FAR * FAR *); +typedef int (*out_func) (void FAR *, unsigned char FAR *, unsigned); -ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, +ZEXTERN int ZEXPORT inflateBack (z_streamp strm, in_func in, void FAR *in_desc, - out_func out, void FAR *out_desc)); + out_func out, void FAR *out_desc); /* inflateBack() does a raw inflate with a single call using a call-back interface for input and output. This is potentially more efficient than @@ -1170,7 +1170,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, cannot return Z_OK. */ -ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateBackEnd (z_streamp strm); /* All memory allocated by inflateBackInit() is freed. @@ -1178,7 +1178,7 @@ ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); state was inconsistent. */ -ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +ZEXTERN uLong ZEXPORT zlibCompileFlags (void); /* Return flags indicating compile-time options. Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: @@ -1231,8 +1231,8 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); you need special options. */ -ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); +ZEXTERN int ZEXPORT compress (Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen); /* Compresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size @@ -1246,9 +1246,9 @@ ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, buffer. */ -ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, +ZEXTERN int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, - int level)); + int level); /* Compresses the source buffer into the destination buffer. The level parameter has the same meaning as in deflateInit. sourceLen is the byte @@ -1262,15 +1262,15 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, Z_STREAM_ERROR if the level parameter is invalid. */ -ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +ZEXTERN uLong ZEXPORT compressBound (uLong sourceLen); /* compressBound() returns an upper bound on the compressed size after compress() or compress2() on sourceLen bytes. It would be used before a compress() or compress2() call to allocate the destination buffer. */ -ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); +ZEXTERN int ZEXPORT uncompress (Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen); /* Decompresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size @@ -1287,8 +1287,8 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, buffer with the uncompressed data up to that point. */ -ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong *sourceLen)); +ZEXTERN int ZEXPORT uncompress2 (Bytef *dest, uLongf *destLen, + const Bytef *source, uLong *sourceLen); /* Same as uncompress, except that sourceLen is a pointer, where the length of the source is *sourceLen. On return, *sourceLen is the number of @@ -1307,7 +1307,7 @@ ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ /* -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); +ZEXTERN gzFile ZEXPORT gzopen (const char *path, const char *mode); Open the gzip (.gz) file at path for reading and decompressing, or compressing and writing. The mode parameter is as in fopen ("rb" or "wb") @@ -1344,7 +1344,7 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); file could not be opened. */ -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +ZEXTERN gzFile ZEXPORT gzdopen (int fd, const char *mode); /* Associate a gzFile with the file descriptor fd. File descriptors are obtained from calls like open, dup, creat, pipe or fileno (if the file has @@ -1367,7 +1367,7 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); will not detect if fd is invalid (unless fd is -1). */ -ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +ZEXTERN int ZEXPORT gzbuffer (gzFile file, unsigned size); /* Set the internal buffer size used by this library's functions for file to size. The default buffer size is 8192 bytes. This function must be called @@ -1383,7 +1383,7 @@ ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); too late. */ -ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +ZEXTERN int ZEXPORT gzsetparams (gzFile file, int level, int strategy); /* Dynamically update the compression level and strategy for file. See the description of deflateInit2 for the meaning of these parameters. Previously @@ -1394,7 +1394,7 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); or Z_MEM_ERROR if there is a memory allocation error. */ -ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +ZEXTERN int ZEXPORT gzread (gzFile file, voidp buf, unsigned len); /* Read and decompress up to len uncompressed bytes from file into buf. If the input file is not in gzip format, gzread copies the given number of @@ -1424,8 +1424,8 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); Z_STREAM_ERROR. */ -ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, - gzFile file)); +ZEXTERN z_size_t ZEXPORT gzfread (voidp buf, z_size_t size, z_size_t nitems, + gzFile file); /* Read and decompress up to nitems items of size size from file into buf, otherwise operating as gzread() does. This duplicates the interface of @@ -1450,14 +1450,14 @@ ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, file, resetting and retrying on end-of-file, when size is not 1. */ -ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len)); +ZEXTERN int ZEXPORT gzwrite (gzFile file, voidpc buf, unsigned len); /* Compress and write the len uncompressed bytes at buf to file. gzwrite returns the number of uncompressed bytes written or 0 in case of error. */ -ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size, - z_size_t nitems, gzFile file)); +ZEXTERN z_size_t ZEXPORT gzfwrite (voidpc buf, z_size_t size, + z_size_t nitems, gzFile file); /* Compress and write nitems items of size size from buf to file, duplicating the interface of stdio's fwrite(), with size_t request and return types. If @@ -1485,7 +1485,7 @@ ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); This can be determined using zlibCompileFlags(). */ -ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +ZEXTERN int ZEXPORT gzputs (gzFile file, const char *s); /* Compress and write the given null-terminated string s to file, excluding the terminating null character. @@ -1493,7 +1493,7 @@ ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); gzputs returns the number of characters written, or -1 in case of error. */ -ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +ZEXTERN char * ZEXPORT gzgets (gzFile file, char *buf, int len); /* Read and decompress bytes from file into buf, until len-1 characters are read, or until a newline character is read and transferred to buf, or an @@ -1507,13 +1507,13 @@ ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); buf are indeterminate. */ -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +ZEXTERN int ZEXPORT gzputc (gzFile file, int c); /* Compress and write c, converted to an unsigned char, into file. gzputc returns the value that was written, or -1 in case of error. */ -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +ZEXTERN int ZEXPORT gzgetc (gzFile file); /* Read and decompress one byte from file. gzgetc returns this byte or -1 in case of end of file or error. This is implemented as a macro for speed. @@ -1522,7 +1522,7 @@ ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); points to has been clobbered or not. */ -ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +ZEXTERN int ZEXPORT gzungetc (int c, gzFile file); /* Push c back onto the stream for file to be read as the first character on the next read. At least one character of push-back is always allowed. @@ -1534,7 +1534,7 @@ ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); gzseek() or gzrewind(). */ -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +ZEXTERN int ZEXPORT gzflush (gzFile file, int flush); /* Flush all pending output to file. The parameter flush is as in the deflate() function. The return value is the zlib error number (see function @@ -1550,8 +1550,8 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); */ /* -ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, - z_off_t offset, int whence)); +ZEXTERN z_off_t ZEXPORT gzseek (gzFile file, + z_off_t offset, int whence); Set the starting position to offset relative to whence for the next gzread or gzwrite on file. The offset represents a number of bytes in the @@ -1569,7 +1569,7 @@ ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, would be before the current position. */ -ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +ZEXTERN int ZEXPORT gzrewind (gzFile file); /* Rewind file. This function is supported only for reading. @@ -1577,7 +1577,7 @@ ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); */ /* -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); +ZEXTERN z_off_t ZEXPORT gztell (gzFile file); Return the starting position for the next gzread or gzwrite on file. This position represents a number of bytes in the uncompressed data stream, @@ -1588,7 +1588,7 @@ ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); */ /* -ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); +ZEXTERN z_off_t ZEXPORT gzoffset (gzFile file); Return the current compressed (actual) read or write offset of file. This offset includes the count of bytes that precede the gzip stream, for example @@ -1597,7 +1597,7 @@ ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); be used for a progress indicator. On error, gzoffset() returns -1. */ -ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +ZEXTERN int ZEXPORT gzeof (gzFile file); /* Return true (1) if the end-of-file indicator for file has been set while reading, false (0) otherwise. Note that the end-of-file indicator is set @@ -1612,7 +1612,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file)); has grown since the previous end of file was detected. */ -ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +ZEXTERN int ZEXPORT gzdirect (gzFile file); /* Return true (1) if file is being copied directly while reading, or false (0) if file is a gzip stream being decompressed. @@ -1633,7 +1633,7 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); gzip file reading and decompression, which may not be desired.) */ -ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose (gzFile file); /* Flush all pending output for file, if necessary, close file and deallocate the (de)compression state. Note that once file is closed, you @@ -1646,8 +1646,8 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file)); last read ended in the middle of a gzip stream, or Z_OK on success. */ -ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); -ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_r (gzFile file); +ZEXTERN int ZEXPORT gzclose_w (gzFile file); /* Same as gzclose(), but gzclose_r() is only for use when reading, and gzclose_w() is only for use when writing or appending. The advantage to @@ -1658,7 +1658,7 @@ ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); zlib library. */ -ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +ZEXTERN const char * ZEXPORT gzerror (gzFile file, int *errnum); /* Return the error message for the last error which occurred on file. errnum is set to zlib error number. If an error occurred in the file system @@ -1674,7 +1674,7 @@ ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); functions above that do not distinguish those cases in their return values. */ -ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +ZEXTERN void ZEXPORT gzclearerr (gzFile file); /* Clear the error and end-of-file flags for file. This is analogous to the clearerr() function in stdio. This is useful for continuing to read a gzip @@ -1691,7 +1691,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); library. */ -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +ZEXTERN uLong ZEXPORT adler32 (uLong adler, const Bytef *buf, uInt len); /* Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum. An Adler-32 value is in the range of a 32-bit @@ -1711,15 +1711,15 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); if (adler != original_adler) error(); */ -ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf, - z_size_t len)); +ZEXTERN uLong ZEXPORT adler32_z (uLong adler, const Bytef *buf, + z_size_t len); /* Same as adler32(), but with a size_t length. */ /* -ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, - z_off_t len2)); +ZEXTERN uLong ZEXPORT adler32_combine (uLong adler1, uLong adler2, + z_off_t len2); Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for @@ -1729,7 +1729,7 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, negative, the result has no meaning or utility. */ -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +ZEXTERN uLong ZEXPORT crc32 (uLong crc, const Bytef *buf, uInt len); /* Update a running CRC-32 with the bytes buf[0..len-1] and return the updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer. @@ -1747,14 +1747,14 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); if (crc != original_crc) error(); */ -ZEXTERN uLong ZEXPORT crc32_z OF((uLong crc, const Bytef *buf, - z_size_t len)); +ZEXTERN uLong ZEXPORT crc32_z (uLong crc, const Bytef *buf, + z_size_t len); /* Same as crc32(), but with a size_t length. */ /* -ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); +ZEXTERN uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2); Combine two CRC-32 check values into one. For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, CRC-32 check values were @@ -1764,13 +1764,13 @@ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); */ /* -ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t len2)); +ZEXTERN uLong ZEXPORT crc32_combine_gen (z_off_t len2); Return the operator corresponding to length len2, to be used with crc32_combine_op(). */ -ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op)); +ZEXTERN uLong ZEXPORT crc32_combine_op (uLong crc1, uLong crc2, uLong op); /* Give the same result as crc32_combine(), using op in place of len2. op is is generated from len2 by crc32_combine_gen(). This will be faster than @@ -1783,20 +1783,20 @@ ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op)); /* deflateInit and inflateInit are macros to allow checking the zlib version * and the compiler's view of z_stream: */ -ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, +ZEXTERN int ZEXPORT deflateInit_ (z_streamp strm, int level, + const char *version, int stream_size); +ZEXTERN int ZEXPORT inflateInit_ (z_streamp strm, + const char *version, int stream_size); +ZEXTERN int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, - int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, + int stream_size); +ZEXTERN int ZEXPORT inflateInit2_ (z_streamp strm, int windowBits, + const char *version, int stream_size); +ZEXTERN int ZEXPORT inflateBackInit_ (z_streamp strm, int windowBits, unsigned char FAR *window, const char *version, - int stream_size)); + int stream_size); #ifdef Z_PREFIX_SET # define z_deflateInit(strm, level) \ deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) @@ -1841,7 +1841,7 @@ struct gzFile_s { unsigned char *next; z_off64_t pos; }; -ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ +ZEXTERN int ZEXPORT gzgetc_ (gzFile file); /* backward compatibility */ #ifdef Z_PREFIX_SET # undef z_gzgetc # define z_gzgetc(g) \ @@ -1858,13 +1858,13 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ * without large file support, _LFS64_LARGEFILE must also be true */ #ifdef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); - ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off64_t)); + ZEXTERN gzFile ZEXPORT gzopen64 (const char *, const char *); + ZEXTERN z_off64_t ZEXPORT gzseek64 (gzFile, z_off64_t, int); + ZEXTERN z_off64_t ZEXPORT gztell64 (gzFile); + ZEXTERN z_off64_t ZEXPORT gzoffset64 (gzFile); + ZEXTERN uLong ZEXPORT adler32_combine64 (uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine64 (uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64 (z_off64_t); #endif #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) @@ -1886,44 +1886,44 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ # define crc32_combine_gen crc32_combine_gen64 # endif # ifndef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); + ZEXTERN gzFile ZEXPORT gzopen64 (const char *, const char *); + ZEXTERN z_off_t ZEXPORT gzseek64 (gzFile, z_off_t, int); + ZEXTERN z_off_t ZEXPORT gztell64 (gzFile); + ZEXTERN z_off_t ZEXPORT gzoffset64 (gzFile); + ZEXTERN uLong ZEXPORT adler32_combine64 (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine64 (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64 (z_off_t); # endif #else - ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); + ZEXTERN gzFile ZEXPORT gzopen (const char *, const char *); + ZEXTERN z_off_t ZEXPORT gzseek (gzFile, z_off_t, int); + ZEXTERN z_off_t ZEXPORT gztell (gzFile); + ZEXTERN z_off_t ZEXPORT gzoffset (gzFile); + ZEXTERN uLong ZEXPORT adler32_combine (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen (z_off_t); #endif #else /* Z_SOLO */ - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); + ZEXTERN uLong ZEXPORT adler32_combine (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen (z_off_t); #endif /* !Z_SOLO */ /* undocumented functions */ -ZEXTERN const char * ZEXPORT zError OF((int)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); -ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); -ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); -ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int)); -ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF ((z_streamp)); -ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); -ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); +ZEXTERN const char * ZEXPORT zError (int); +ZEXTERN int ZEXPORT inflateSyncPoint (z_streamp); +ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table (void); +ZEXTERN int ZEXPORT inflateUndermine (z_streamp, int); +ZEXTERN int ZEXPORT inflateValidate (z_streamp, int); +ZEXTERN unsigned long ZEXPORT inflateCodesUsed (z_streamp); +ZEXTERN int ZEXPORT inflateResetKeep (z_streamp); +ZEXTERN int ZEXPORT deflateResetKeep (z_streamp); #if defined(_WIN32) && !defined(Z_SOLO) -ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, - const char *mode)); +ZEXTERN gzFile ZEXPORT gzopen_w (const wchar_t *path, + const char *mode); #endif #if defined(STDC) || defined(Z_HAVE_STDARG_H) # ifndef Z_SOLO diff --git a/lib/libvgz/zutil.c b/lib/libvgz/zutil.c index 6a5b32c3e..4082f65ac 100644 --- a/lib/libvgz/zutil.c +++ b/lib/libvgz/zutil.c @@ -302,9 +302,9 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) #ifndef MY_ZCALLOC /* Any system without a special alloc function */ #ifndef STDC -extern voidp malloc OF((uInt size)); -extern voidp calloc OF((uInt items, uInt size)); -extern void free OF((voidpf ptr)); +extern voidp malloc (uInt size); +extern voidp calloc (uInt items, uInt size); +extern void free (voidpf ptr); #endif voidpf ZLIB_INTERNAL zcalloc ( diff --git a/lib/libvgz/zutil.h b/lib/libvgz/zutil.h index 03cdb4d38..1ae739f15 100644 --- a/lib/libvgz/zutil.h +++ b/lib/libvgz/zutil.h @@ -191,9 +191,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ /* provide prototypes for these when building zlib without LFS */ #if !defined(_WIN32) && \ (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); + ZEXTERN uLong ZEXPORT adler32_combine64 (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine64 (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64 (z_off_t); #endif /* common defaults */ @@ -232,16 +232,16 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # define zmemzero(dest, len) memset(dest, 0, len) # endif #else - void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); - int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); - void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); + void ZLIB_INTERNAL zmemcpy (Bytef* dest, const Bytef* source, uInt len); + int ZLIB_INTERNAL zmemcmp (const Bytef* s1, const Bytef* s2, uInt len); + void ZLIB_INTERNAL zmemzero (Bytef* dest, uInt len); #endif /* Diagnostic functions */ #ifdef ZLIB_DEBUG # include extern int ZLIB_INTERNAL z_verbose; - extern void ZLIB_INTERNAL z_error OF((char *m)); + extern void ZLIB_INTERNAL z_error (char *m); # define Assert(cond,msg) {if(!(cond)) z_error(msg);} # define Trace(x) {if (z_verbose>=0) fprintf x ;} # define Tracev(x) {if (z_verbose>0) fprintf x ;} @@ -258,9 +258,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ #endif #ifndef Z_SOLO - voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, - unsigned size)); - void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); + voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, + unsigned size); + void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr); #endif #define ZALLOC(strm, items, size) \ From phk at FreeBSD.org Wed Aug 30 12:47:09 2023 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 30 Aug 2023 12:47:09 +0000 (UTC) Subject: [master] fd78cc322 Update to zlib 1.3 Message-ID: <20230830124709.6E1E064F90@lists.varnish-cache.org> commit fd78cc322dc9fc6979e94580b2b5c31e29ce5217 Author: Poul-Henning Kamp Date: Wed Aug 30 12:36:01 2023 +0000 Update to zlib 1.3 diff --git a/lib/libvgz/adler32.c b/lib/libvgz/adler32.c index 25f11472c..860645ac6 100644 --- a/lib/libvgz/adler32.c +++ b/lib/libvgz/adler32.c @@ -61,11 +61,7 @@ local uLong adler32_combine_ (uLong adler1, uLong adler2, z_off64_t len2); #endif /* ========================================================================= */ -uLong ZEXPORT adler32_z(adler, buf, len) - uLong adler; - const Bytef *buf; - z_size_t len; -{ +uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) { unsigned long sum2; unsigned n; @@ -132,20 +128,12 @@ uLong ZEXPORT adler32_z(adler, buf, len) } /* ========================================================================= */ -uLong ZEXPORT adler32(adler, buf, len) - uLong adler; - const Bytef *buf; - uInt len; -{ +uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) { return adler32_z(adler, buf, len); } /* ========================================================================= */ -local uLong adler32_combine_(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ +local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) { unsigned long sum1; unsigned long sum2; unsigned rem; @@ -170,28 +158,15 @@ local uLong adler32_combine_(adler1, adler2, len2) } /* ========================================================================= */ -uLong ZEXPORT adler32_combine(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off_t len2; -{ +uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) { return adler32_combine_(adler1, adler2, len2); } -uLong ZEXPORT adler32_combine64(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ +uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) { return adler32_combine_(adler1, adler2, len2); } #else /* NOVGZ */ -uLong ZEXPORT adler32( - uLong adler, - const Bytef *buf, - uInt len -) -{ +uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) { (void)adler; (void)buf; (void)len; diff --git a/lib/libvgz/crc32.c b/lib/libvgz/crc32.c index fd68dcbdf..f6971159c 100644 --- a/lib/libvgz/crc32.c +++ b/lib/libvgz/crc32.c @@ -103,19 +103,6 @@ # define ARMCRC32 #endif -/* Local functions. */ -local z_crc_t multmodp (z_crc_t a, z_crc_t b); -local z_crc_t x2nmodp (z_off64_t n, unsigned k); - -#if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) - local z_word_t byte_swap (z_word_t word); -#endif - -#if defined(W) && !defined(ARMCRC32) - local z_crc_t crc_word (z_word_t data); - local z_word_t crc_word_big (z_word_t data); -#endif - #if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) /* Swap the bytes in a z_word_t to convert between little and big endian. Any @@ -123,12 +110,7 @@ local z_crc_t x2nmodp (z_off64_t n, unsigned k); instruction, if one is available. This assumes that word_t is either 32 bits or 64 bits. */ -local z_word_t byte_swap (z_word_t word); - -local z_word_t byte_swap( - z_word_t word -) -{ +local z_word_t byte_swap (z_word_t word) { # if W == 8 return (word & 0xff00000000000000) >> 56 | @@ -149,14 +131,67 @@ local z_word_t byte_swap( } #endif +#ifdef DYNAMIC_CRC_TABLE +/* ========================================================================= + * Table of powers of x for combining CRC-32s, filled in by make_crc_table() + * below. + */ + local z_crc_t FAR x2n_table[32]; +#else +/* ========================================================================= + * Tables for byte-wise and braided CRC-32 calculations, and a table of powers + * of x for combining CRC-32s, all made by make_crc_table(). + */ +# include "crc32.h" +#endif + /* CRC polynomial. */ #define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */ -#ifdef DYNAMIC_CRC_TABLE +/* + Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial, + reflected. For speed, this requires that a not be zero. + */ +local z_crc_t multmodp(z_crc_t a, z_crc_t b) { + z_crc_t m, p; + + m = (z_crc_t)1 << 31; + p = 0; + for (;;) { + if (a & m) { + p ^= b; + if ((a & (m - 1)) == 0) + break; + } + m >>= 1; + b = b & 1 ? (b >> 1) ^ POLY : b >> 1; + } + return p; +} + +/* + Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been + initialized. + */ +local z_crc_t x2nmodp(z_off64_t n, unsigned k) { + z_crc_t p; + + p = (z_crc_t)1 << 31; /* x^0 == 1 */ + while (n) { + if (n & 1) + p = multmodp(x2n_table[k & 31], p); + n >>= 1; + k++; + } + return p; +} +#ifdef DYNAMIC_CRC_TABLE +/* ========================================================================= + * Build the tables for byte-wise and braided CRC-32 calculations, and a table + * of powers of x for combining CRC-32s. + */ local z_crc_t FAR crc_table[256]; -local z_crc_t FAR x2n_table[32]; -local void make_crc_table (void); #ifdef W local z_word_t FAR crc_big_table[256]; local z_crc_t FAR crc_braid_table[W][256]; @@ -179,7 +214,6 @@ local void make_crc_table (void); /* Definition of once functionality. */ typedef struct once_s once_t; -local void once (once_t *, void (*)(void)); /* Check for the availability of atomics. */ #if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \ @@ -199,10 +233,7 @@ struct once_s { invoke once() at the same time. The state must be a once_t initialized with ONCE_INIT. */ -local void once(state, init) - once_t *state; - void (*init)(void); -{ +local void once(once_t *state, void (*init)(void)) { if (!atomic_load(&state->done)) { if (atomic_flag_test_and_set(&state->begun)) while (!atomic_load(&state->done)) @@ -225,10 +256,7 @@ struct once_s { /* Test and set. Alas, not atomic, but tries to minimize the period of vulnerability. */ -local int test_and_set (int volatile *); -local int test_and_set(flag) - int volatile *flag; -{ +local int test_and_set (int volatile *flag) { int was; was = *flag; @@ -237,10 +265,7 @@ local int test_and_set(flag) } /* Run the provided init() function once. This is not thread-safe. */ -local void once(state, init) - once_t *state; - void (*init)(void); -{ +local void once(once_t *state, void (*init)(void)) { if (!state->done) { if (test_and_set(&state->begun)) while (!state->done) @@ -282,8 +307,7 @@ local once_t made = ONCE_INIT; combinations of CRC register values and incoming bytes. */ -local void make_crc_table() -{ +local void make_crc_table(void) { unsigned i, j, n; z_crc_t p; @@ -450,11 +474,7 @@ local void make_crc_table() Write the 32-bit values in table[0..k-1] to out, five per line in hexadecimal separated by commas. */ -local void write_table(out, table, k) - FILE *out; - const z_crc_t FAR *table; - int k; -{ +local void write_table(FILE *out, const z_crc_t FAR *table, int k) { int n; for (n = 0; n < k; n++) @@ -467,11 +487,7 @@ local void write_table(out, table, k) Write the high 32-bits of each value in table[0..k-1] to out, five per line in hexadecimal separated by commas. */ -local void write_table32hi(out, table, k) -FILE *out; -const z_word_t FAR *table; -int k; -{ +local void write_table32hi(FILE *out, const z_word_t FAR *table, int k) { int n; for (n = 0; n < k; n++) @@ -487,11 +503,7 @@ int k; bits. If not, then the type cast and format string can be adjusted accordingly. */ -local void write_table64(out, table, k) - FILE *out; - const z_word_t FAR *table; - int k; -{ +local void write_table64(FILE *out, const z_word_t FAR *table, int k) { int n; for (n = 0; n < k; n++) @@ -501,8 +513,7 @@ local void write_table64(out, table, k) } /* Actually do the deed. */ -int main() -{ +int main(void) { make_crc_table(); return 0; } @@ -514,12 +525,7 @@ int main() Generate the little and big-endian braid tables for the given n and z_word_t size w. Each array must have room for w blocks of 256 elements. */ -local void braid(ltl, big, n, w) - z_crc_t ltl[][256]; - z_word_t big[][256]; - int n; - int w; -{ +local void braid(z_crc_t ltl[][256], z_word_t big[][256], int n, int w) { int k; z_crc_t i, p, q; for (k = 0; k < w; k++) { @@ -534,71 +540,13 @@ local void braid(ltl, big, n, w) } #endif -#else /* !DYNAMIC_CRC_TABLE */ -/* ======================================================================== - * Tables for byte-wise and braided CRC-32 calculations, and a table of powers - * of x for combining CRC-32s, all made by make_crc_table(). - */ -#include "crc32.h" #endif /* DYNAMIC_CRC_TABLE */ -/* ======================================================================== - * Routines used for CRC calculation. Some are also required for the table - * generation above. - */ - -/* - Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial, - reflected. For speed, this requires that a not be zero. - */ -local z_crc_t multmodp( - z_crc_t a, - z_crc_t b -) -{ - z_crc_t m, p; - - m = (z_crc_t)1 << 31; - p = 0; - for (;;) { - if (a & m) { - p ^= b; - if ((a & (m - 1)) == 0) - break; - } - m >>= 1; - b = b & 1 ? (b >> 1) ^ POLY : b >> 1; - } - return p; -} - -/* - Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been - initialized. - */ -local z_crc_t x2nmodp( - z_off64_t n, - unsigned k -) -{ - z_crc_t p; - - p = (z_crc_t)1 << 31; /* x^0 == 1 */ - while (n) { - if (n & 1) - p = multmodp(x2n_table[k & 31], p); - n >>= 1; - k++; - } - return p; -} - /* ========================================================================= * This function can be used by asm versions of crc32(), and to force the * generation of the CRC tables in a threaded application. */ -const z_crc_t FAR * ZEXPORT get_crc_table(void) -{ +const z_crc_t FAR * ZEXPORT get_crc_table(void) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); #endif /* DYNAMIC_CRC_TABLE */ @@ -624,11 +572,8 @@ const z_crc_t FAR * ZEXPORT get_crc_table(void) #define Z_BATCH_ZEROS 0xa10d3d0c /* computed from Z_BATCH = 3990 */ #define Z_BATCH_MIN 800 /* fewest words in a final batch */ -unsigned long ZEXPORT crc32_z(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - z_size_t len; -{ +unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, + z_size_t len) { z_crc_t val; z_word_t crc1, crc2; const z_word_t *word; @@ -728,24 +673,14 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) least-significant byte of the word as the first byte of data, without any pre or post conditioning. This is used to combine the CRCs of each braid. */ -local z_crc_t crc_word (z_word_t data); - -local z_crc_t crc_word( - z_word_t data -) -{ +local z_crc_t crc_word (z_word_t data) { int k; for (k = 0; k < W; k++) data = (data >> 8) ^ crc_table[data & 0xff]; return (z_crc_t)data; } -local z_word_t crc_word_big (z_word_t data); - -local z_word_t crc_word_big( - z_word_t data -) -{ +local z_word_t crc_word_big (z_word_t data) { int k; for (k = 0; k < W; k++) data = (data << 8) ^ @@ -756,12 +691,8 @@ local z_word_t crc_word_big( #endif /* ========================================================================= */ -unsigned long ZEXPORT crc32_z( - unsigned long crc, - const unsigned char FAR *buf, - z_size_t len -) -{ +unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, + z_size_t len) { /* Return initial CRC, if requested. */ if (buf == Z_NULL) return 0; @@ -793,8 +724,8 @@ unsigned long ZEXPORT crc32_z( words = (z_word_t const *)(intptr_t)buf; /* Do endian check at execution time instead of compile time, since ARM - processors can change the endianess at execution time. If the - compiler knows what the endianess will be, it can optimize out the + processors can change the endianness at execution time. If the + compiler knows what the endianness will be, it can optimize out the check and the unused branch. */ endian = 1; if (*(unsigned char *)&endian) { @@ -1081,22 +1012,13 @@ unsigned long ZEXPORT crc32_z( #endif /* ========================================================================= */ -unsigned long ZEXPORT crc32( - unsigned long crc, - const unsigned char FAR *buf, - uInt len -) -{ +unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, + uInt len) { return crc32_z(crc, buf, len); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine64( - uLong crc1, - uLong crc2, - z_off64_t len2 -) -{ +uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); #endif /* DYNAMIC_CRC_TABLE */ @@ -1104,20 +1026,12 @@ uLong ZEXPORT crc32_combine64( } /* ========================================================================= */ -uLong ZEXPORT crc32_combine( - uLong crc1, - uLong crc2, - z_off_t len2 -) -{ +uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2) { return crc32_combine64(crc1, crc2, (z_off64_t)len2); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_gen64( - z_off64_t len2 -) -{ +uLong ZEXPORT crc32_combine_gen64(z_off64_t len2) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); #endif /* DYNAMIC_CRC_TABLE */ @@ -1125,19 +1039,11 @@ uLong ZEXPORT crc32_combine_gen64( } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_gen( - z_off_t len2 -) -{ +uLong ZEXPORT crc32_combine_gen(z_off_t len2) { return crc32_combine_gen64((z_off64_t)len2); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_op( - uLong crc1, - uLong crc2, - uLong op -) -{ +uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op) { return multmodp(op, crc1) ^ (crc2 & 0xffffffff); } diff --git a/lib/libvgz/deflate.c b/lib/libvgz/deflate.c index 4dd3447aa..bd9d5f82a 100644 --- a/lib/libvgz/deflate.c +++ b/lib/libvgz/deflate.c @@ -1,5 +1,5 @@ /* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler + * Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -53,7 +53,7 @@ extern const char deflate_copyright[]; const char deflate_copyright[] = - " deflate 1.2.13 Copyright 1995-2022 Jean-loup Gailly and Mark Adler "; + " deflate 1.3 Copyright 1995-2023 Jean-loup Gailly and Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -61,9 +61,6 @@ const char deflate_copyright[] = copyright string in the executable of your product. */ -/* =========================================================================== - * Function prototypes. - */ typedef enum { need_more, /* block not completed, need more input or more output */ block_done, /* block flush performed */ @@ -74,9 +71,6 @@ typedef enum { typedef block_state (*compress_func) (deflate_state *s, int flush); /* Compression function. Returns the block state after the call. */ -local int deflateStateCheck (z_streamp strm); -local void slide_hash (deflate_state *s); -local void fill_window (deflate_state *s); local block_state deflate_stored (deflate_state *s, int flush); local block_state deflate_fast (deflate_state *s, int flush); #ifndef FASTEST @@ -86,16 +80,6 @@ local block_state deflate_slow (deflate_state *s, int flush); local block_state deflate_rle (deflate_state *s, int flush); local block_state deflate_huff (deflate_state *s, int flush); #endif /* NOVGZ */ -local void lm_init (deflate_state *s); -local void putShortMSB (deflate_state *s, uInt b); -local void flush_pending (z_streamp strm); -local unsigned read_buf (z_streamp strm, Bytef *buf, unsigned size); -local uInt longest_match (deflate_state *s, IPos cur_match); - -#ifdef ZLIB_DEBUG -local void check_match (deflate_state *s, IPos start, IPos match, - int length); -#endif /* =========================================================================== * Local data @@ -198,10 +182,12 @@ local const config configuration_table[10] = { * bit values at the expense of memory usage). We slide even when level == 0 to * keep the hash table consistent if we switch back to level > 0 later. */ -local void slide_hash( - deflate_state *s -) -{ +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + __attribute__((no_sanitize("memory"))) +# endif +#endif +local void slide_hash(deflate_state *s) { unsigned n, m; Posf *p; uInt wsize = s->w_size; @@ -225,15 +211,171 @@ local void slide_hash( #endif } +/* =========================================================================== + * Read a new buffer from the current input stream, update the adler32 + * and total number of bytes read. All deflate() input goes through + * this function so some applications may wish to modify it to avoid + * allocating a large strm->next_in buffer and copying from it. + * (See also flush_pending()). + */ +local unsigned read_buf(z_streamp strm, Bytef *buf, unsigned size) { + unsigned len = strm->avail_in; + + if (len > size) len = size; + if (len == 0) return 0; + + strm->avail_in -= len; + + zmemcpy(buf, strm->next_in, len); + if (strm->state->wrap == 1) { + strm->adler = adler32(strm->adler, buf, len); + } +#ifdef GZIP + else if (strm->state->wrap == 2) { + strm->adler = crc32(strm->adler, buf, len); + } +#endif + strm->next_in += len; + strm->total_in += len; + + return len; +} + +/* =========================================================================== + * Fill the window when the lookahead becomes insufficient. + * Updates strstart and lookahead. + * + * IN assertion: lookahead < MIN_LOOKAHEAD + * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD + * At least one byte has been read, or avail_in == 0; reads are + * performed for at least two bytes (required for the zip translate_eol + * option -- not supported here). + */ +local void fill_window(deflate_state *s) { + unsigned n; + unsigned more; /* Amount of free space at the end of the window. */ + uInt wsize = s->w_size; + + Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); + + do { + more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); + + /* Deal with !@#$% 64K limit: */ + if (sizeof(int) <= 2) { + if (more == 0 && s->strstart == 0 && s->lookahead == 0) { + more = wsize; + + } else if (more == (unsigned)(-1)) { + /* Very unlikely, but possible on 16 bit machine if + * strstart == 0 && lookahead == 1 (input done a byte at time) + */ + more--; + } + } + + /* If the window is almost full and there is insufficient lookahead, + * move the upper half to the lower one to make room in the upper half. + */ + if (s->strstart >= wsize+MAX_DIST(s)) { + + zmemcpy(s->window, s->window+wsize, (unsigned)wsize - more); + s->match_start -= wsize; + s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ + s->block_start -= (long) wsize; + if (s->insert > s->strstart) + s->insert = s->strstart; + slide_hash(s); + more += wsize; + } + if (s->strm->avail_in == 0) break; + + /* If there was no sliding: + * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && + * more == window_size - lookahead - strstart + * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) + * => more >= window_size - 2*WSIZE + 2 + * In the BIG_MEM or MMAP case (not yet supported), + * window_size == input_size + MIN_LOOKAHEAD && + * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. + * Otherwise, window_size == 2*WSIZE so more >= 2. + * If there was sliding, more >= WSIZE. So in all cases, more >= 2. + */ + Assert(more >= 2, "more < 2"); + + n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); + s->lookahead += n; + + /* Initialize the hash value now that we have some input: */ + if (s->lookahead + s->insert >= MIN_MATCH) { + uInt str = s->strstart - s->insert; + s->ins_h = s->window[str]; + UPDATE_HASH(s, s->ins_h, s->window[str + 1]); +#if MIN_MATCH != 3 + Call UPDATE_HASH() MIN_MATCH-3 more times +#endif + while (s->insert) { + UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); +#ifndef FASTEST + s->prev[str & s->w_mask] = s->head[s->ins_h]; +#endif + s->head[s->ins_h] = (Pos)str; + str++; + s->insert--; + if (s->lookahead + s->insert < MIN_MATCH) + break; + } + } + /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, + * but this is not important since only literal bytes will be emitted. + */ + + } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); + + /* If the WIN_INIT bytes after the end of the current data have never been + * written, then zero those bytes in order to avoid memory check reports of + * the use of uninitialized (or uninitialised as Julian writes) bytes by + * the longest match routines. Update the high water mark for the next + * time through here. WIN_INIT is set to MAX_MATCH since the longest match + * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. + */ + if (s->high_water < s->window_size) { + ulg curr = s->strstart + (ulg)(s->lookahead); + ulg init; + + if (s->high_water < curr) { + /* Previous high water mark below current data -- zero WIN_INIT + * bytes or up to end of window, whichever is less. + */ + init = s->window_size - curr; + if (init > WIN_INIT) + init = WIN_INIT; + zmemzero(s->window + curr, (unsigned)init); + s->high_water = curr + init; + } + else if (s->high_water < (ulg)curr + WIN_INIT) { + /* High water mark at or above current data, but below current data + * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up + * to end of window, whichever is less. + */ + init = (ulg)curr + WIN_INIT - s->high_water; + if (init > s->window_size - s->high_water) + init = s->window_size - s->high_water; + zmemzero(s->window + s->high_water, (unsigned)init); + s->high_water += init; + } + } + + Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, + "not enough room for search"); +} + + #ifdef NOVGZ /* ========================================================================= */ -int ZEXPORT deflateInit_(strm, level, version, stream_size) - z_streamp strm; - int level; - const char *version; - int stream_size; -{ +int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, + int stream_size) { return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, version, stream_size); /* To do: ignore strm->next_in if we use it as window */ @@ -242,17 +384,9 @@ int ZEXPORT deflateInit_(strm, level, version, stream_size) #endif /* NOVGZ */ /* ========================================================================= */ -int ZEXPORT deflateInit2_( - z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy, - const char *version, - int stream_size -) -{ +int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, + int windowBits, int memLevel, int strategy, + const char *version, int stream_size) { deflate_state *s; int wrap = 1; static const char my_version[] = ZLIB_VERSION; @@ -394,10 +528,7 @@ int ZEXPORT deflateInit2_( /* ========================================================================= * Check for a valid deflate stream state. Return 0 if ok, 1 if not. */ -local int deflateStateCheck ( - z_streamp strm -) -{ +local int deflateStateCheck(z_streamp strm) { deflate_state *s; if (strm == Z_NULL || strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) @@ -422,11 +553,8 @@ local int deflateStateCheck ( #ifdef NOVGZ /* ========================================================================= */ -int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) - z_streamp strm; - const Bytef *dictionary; - uInt dictLength; -{ +int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength) { deflate_state *s; uInt str, n; int wrap; @@ -491,11 +619,8 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) } /* ========================================================================= */ -int ZEXPORT deflateGetDictionary (strm, dictionary, dictLength) - z_streamp strm; - Bytef *dictionary; - uInt *dictLength; -{ +int ZEXPORT deflateGetDictionary(z_streamp strm, Bytef *dictionary, + uInt *dictLength) { deflate_state *s; uInt len; @@ -515,10 +640,7 @@ int ZEXPORT deflateGetDictionary (strm, dictionary, dictLength) #endif /* NOVGZ */ /* ========================================================================= */ -int ZEXPORT deflateResetKeep ( - z_streamp strm -) -{ +int ZEXPORT deflateResetKeep(z_streamp strm) { deflate_state *s; if (deflateStateCheck(strm)) { @@ -554,11 +676,32 @@ int ZEXPORT deflateResetKeep ( return Z_OK; } +/* =========================================================================== + * Initialize the "longest match" routines for a new zlib stream + */ +local void lm_init(deflate_state *s) { + s->window_size = (ulg)2L*s->w_size; + + CLEAR_HASH(s); + + /* Set the default configuration parameters: + */ + s->max_lazy_match = configuration_table[s->level].max_lazy; + s->good_match = configuration_table[s->level].good_length; + s->nice_match = configuration_table[s->level].nice_length; + s->max_chain_length = configuration_table[s->level].max_chain; + + s->strstart = 0; + s->block_start = 0L; + s->lookahead = 0; + s->insert = 0; + s->match_length = s->prev_length = MIN_MATCH-1; + s->match_available = 0; + s->ins_h = 0; +} + /* ========================================================================= */ -int ZEXPORT deflateReset ( - z_streamp strm -) -{ +int ZEXPORT deflateReset(z_streamp strm) { int ret; ret = deflateResetKeep(strm); @@ -570,11 +713,7 @@ int ZEXPORT deflateReset ( #ifdef NOVGZ /* ========================================================================= */ -int ZEXPORT deflateSetHeader ( - z_streamp strm, - gz_headerp head -) -{ +int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head) { if (deflateStateCheck(strm) || strm->state->wrap != 2) return Z_STREAM_ERROR; strm->state->gzhead = head; @@ -582,12 +721,7 @@ int ZEXPORT deflateSetHeader ( } /* ========================================================================= */ -int ZEXPORT deflatePending ( - z_streamp strm, - unsigned *pending, - int *bits -) -{ +int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) { if (deflateStateCheck(strm)) return Z_STREAM_ERROR; if (pending != Z_NULL) *pending = strm->state->pending; @@ -597,11 +731,7 @@ int ZEXPORT deflatePending ( } /* ========================================================================= */ -int ZEXPORT deflatePrime (strm, bits, value) - z_streamp strm; - int bits; - int value; -{ +int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { deflate_state *s; int put; @@ -624,11 +754,7 @@ int ZEXPORT deflatePrime (strm, bits, value) } /* ========================================================================= */ -int ZEXPORT deflateParams(strm, level, strategy) - z_streamp strm; - int level; - int strategy; -{ +int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) { deflate_state *s; compress_func func; @@ -673,13 +799,8 @@ int ZEXPORT deflateParams(strm, level, strategy) } /* ========================================================================= */ -int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) - z_streamp strm; - int good_length; - int max_lazy; - int nice_length; - int max_chain; -{ +int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, + int nice_length, int max_chain) { deflate_state *s; if (deflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -715,10 +836,7 @@ int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) * * Shifts are used to approximate divisions, for speed. */ -uLong ZEXPORT deflateBound(strm, sourceLen) - z_streamp strm; - uLong sourceLen; -{ +uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) { deflate_state *s; uLong fixedlen, storelen, wraplen; @@ -774,7 +892,8 @@ uLong ZEXPORT deflateBound(strm, sourceLen) /* if not default parameters, return one of the conservative bounds */ if (s->w_bits != 15 || s->hash_bits != 8 + 7) - return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen; + return (s->w_bits <= s->hash_bits && s->level ? fixedlen : storelen) + + wraplen; /* default settings: return tight bound for that case -- ~0.03% overhead plus a small constant */ @@ -789,11 +908,7 @@ uLong ZEXPORT deflateBound(strm, sourceLen) * IN assertion: the stream state is correct and there is enough room in * pending_buf. */ -local void putShortMSB ( - deflate_state *s, - uInt b -) -{ +local void putShortMSB(deflate_state *s, uInt b) { put_byte(s, (Byte)(b >> 8)); put_byte(s, (Byte)(b & 0xff)); } @@ -804,10 +919,7 @@ local void putShortMSB ( * applications may wish to modify it to avoid allocating a large * strm->next_out buffer and copying into it. (See also read_buf()). */ -local void flush_pending( - z_streamp strm -) -{ +local void flush_pending(z_streamp strm) { unsigned len; deflate_state *s = strm->state; @@ -838,11 +950,7 @@ local void flush_pending( } while (0) /* ========================================================================= */ -int ZEXPORT deflate ( - z_streamp strm, - int flush -) -{ +int ZEXPORT deflate(z_streamp strm, int flush) { int old_flush; /* value of flush param for previous deflate call */ deflate_state *s; @@ -1167,10 +1275,7 @@ int ZEXPORT deflate ( } /* ========================================================================= */ -int ZEXPORT deflateEnd ( - z_streamp strm -) -{ +int ZEXPORT deflateEnd(z_streamp strm) { int status; if (deflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1196,11 +1301,10 @@ int ZEXPORT deflateEnd ( * To simplify the source, this is not supported for 16-bit MSDOS (which * doesn't have enough memory anyway to duplicate compression states). */ -int ZEXPORT deflateCopy (dest, source) - z_streamp dest; - z_streamp source; -{ +int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { #ifdef MAXSEG_64K + (void)dest; + (void)source; return Z_STREAM_ERROR; #else deflate_state *ds; @@ -1250,67 +1354,7 @@ int ZEXPORT deflateCopy (dest, source) #endif /* NOVGZ */ -/* =========================================================================== - * Read a new buffer from the current input stream, update the adler32 - * and total number of bytes read. All deflate() input goes through - * this function so some applications may wish to modify it to avoid - * allocating a large strm->next_in buffer and copying from it. - * (See also flush_pending()). - */ -local unsigned read_buf( - z_streamp strm, - Bytef *buf, - unsigned size -) -{ - unsigned len = strm->avail_in; - - if (len > size) len = size; - if (len == 0) return 0; - - strm->avail_in -= len; - - zmemcpy(buf, strm->next_in, len); - if (strm->state->wrap == 1) { - strm->adler = adler32(strm->adler, buf, len); - } -#ifdef GZIP - else if (strm->state->wrap == 2) { - strm->adler = crc32(strm->adler, buf, len); - } -#endif - strm->next_in += len; - strm->total_in += len; - - return len; -} - -/* =========================================================================== - * Initialize the "longest match" routines for a new zlib stream - */ -local void lm_init ( - deflate_state *s -) -{ - s->window_size = (ulg)2L*s->w_size; - CLEAR_HASH(s); - - /* Set the default configuration parameters: - */ - s->max_lazy_match = configuration_table[s->level].max_lazy; - s->good_match = configuration_table[s->level].good_length; - s->nice_match = configuration_table[s->level].nice_length; - s->max_chain_length = configuration_table[s->level].max_chain; - - s->strstart = 0; - s->block_start = 0L; - s->lookahead = 0; - s->insert = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - s->ins_h = 0; -} #ifndef FASTEST /* =========================================================================== @@ -1322,11 +1366,7 @@ local void lm_init ( * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 * OUT assertion: the match length is not greater than s->lookahead. */ -local uInt longest_match( - deflate_state *s, - IPos cur_match /* current match */ -) -{ +local uInt longest_match(deflate_state *s, IPos cur_match) { unsigned chain_length = s->max_chain_length;/* max hash chain length */ register Bytef *scan = s->window + s->strstart; /* current string */ register Bytef *match; /* matched string */ @@ -1474,10 +1514,7 @@ local uInt longest_match( /* --------------------------------------------------------------------------- * Optimized version for FASTEST only */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ +local uInt longest_match(deflate_state *s, IPos cur_match) { register Bytef *scan = s->window + s->strstart; /* current string */ register Bytef *match; /* matched string */ register int len; /* length of current match */ @@ -1538,11 +1575,7 @@ local uInt longest_match(s, cur_match) /* =========================================================================== * Check that the match at match_start is indeed a match. */ -local void check_match(s, start, match, length) - deflate_state *s; - IPos start, match; - int length; -{ +local void check_match(deflate_state *s, IPos start, IPos match, int length) { /* check that the match is indeed a match */ if (zmemcmp(s->window + match, s->window + start, length) != EQUAL) { @@ -1562,138 +1595,6 @@ local void check_match(s, start, match, length) # define check_match(s, start, match, length) #endif /* ZLIB_DEBUG */ -/* =========================================================================== - * Fill the window when the lookahead becomes insufficient. - * Updates strstart and lookahead. - * - * IN assertion: lookahead < MIN_LOOKAHEAD - * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD - * At least one byte has been read, or avail_in == 0; reads are - * performed for at least two bytes (required for the zip translate_eol - * option -- not supported here). - */ -local void fill_window( - deflate_state *s -) -{ - unsigned n; - unsigned more; /* Amount of free space at the end of the window. */ - uInt wsize = s->w_size; - - Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); - - do { - more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); - - /* Deal with !@#$% 64K limit: */ - if (sizeof(int) <= 2) { - if (more == 0 && s->strstart == 0 && s->lookahead == 0) { - more = wsize; - - } else if (more == (unsigned)(-1)) { - /* Very unlikely, but possible on 16 bit machine if - * strstart == 0 && lookahead == 1 (input done a byte at time) - */ - more--; - } - } - - /* If the window is almost full and there is insufficient lookahead, - * move the upper half to the lower one to make room in the upper half. - */ - if (s->strstart >= wsize+MAX_DIST(s)) { - - zmemcpy(s->window, s->window+wsize, (unsigned)wsize - more); - s->match_start -= wsize; - s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ - s->block_start -= (long) wsize; - if (s->insert > s->strstart) - s->insert = s->strstart; - slide_hash(s); - more += wsize; - } - if (s->strm->avail_in == 0) break; - - /* If there was no sliding: - * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && - * more == window_size - lookahead - strstart - * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) - * => more >= window_size - 2*WSIZE + 2 - * In the BIG_MEM or MMAP case (not yet supported), - * window_size == input_size + MIN_LOOKAHEAD && - * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. - * Otherwise, window_size == 2*WSIZE so more >= 2. - * If there was sliding, more >= WSIZE. So in all cases, more >= 2. - */ - Assert(more >= 2, "more < 2"); - - n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); - s->lookahead += n; - - /* Initialize the hash value now that we have some input: */ - if (s->lookahead + s->insert >= MIN_MATCH) { - uInt str = s->strstart - s->insert; - s->ins_h = s->window[str]; - UPDATE_HASH(s, s->ins_h, s->window[str + 1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - while (s->insert) { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - s->insert--; - if (s->lookahead + s->insert < MIN_MATCH) - break; - } - } - /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, - * but this is not important since only literal bytes will be emitted. - */ - - } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); - - /* If the WIN_INIT bytes after the end of the current data have never been - * written, then zero those bytes in order to avoid memory check reports of - * the use of uninitialized (or uninitialised as Julian writes) bytes by - * the longest match routines. Update the high water mark for the next - * time through here. WIN_INIT is set to MAX_MATCH since the longest match - * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. - */ - if (s->high_water < s->window_size) { - ulg curr = s->strstart + (ulg)(s->lookahead); - ulg init; - - if (s->high_water < curr) { - /* Previous high water mark below current data -- zero WIN_INIT - * bytes or up to end of window, whichever is less. - */ - init = s->window_size - curr; - if (init > WIN_INIT) - init = WIN_INIT; - zmemzero(s->window + curr, (unsigned)init); - s->high_water = curr + init; - } - else if (s->high_water < (ulg)curr + WIN_INIT) { - /* High water mark at or above current data, but below current data - * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up - * to end of window, whichever is less. - */ - init = (ulg)curr + WIN_INIT - s->high_water; - if (init > s->window_size - s->high_water) - init = s->window_size - s->high_water; - zmemzero(s->window + s->high_water, (unsigned)init); - s->high_water += init; - } - } - - Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, - "not enough room for search"); -} - /* =========================================================================== * Flush the current block, with given end-of-file flag. * IN assertion: strstart is set to the end of the current match. @@ -1738,11 +1639,7 @@ local void fill_window( * copied. It is most efficient with large input and output buffers, which * maximizes the opportunities to have a single copy from next_in to next_out. */ -local block_state deflate_stored( - deflate_state *s, - int flush -) -{ +local block_state deflate_stored(deflate_state *s, int flush) { /* Smallest worthy block size when not flushing or finishing. By default * this is 32K. This can be as small as 507 bytes for memLevel == 1. For * large input and output buffers, the stored block size will be larger. @@ -1929,11 +1826,7 @@ local block_state deflate_stored( * new strings in the dictionary only for unmatched strings or for short * matches. It is used only for the fast compression options. */ -local block_state deflate_fast( - deflate_state *s, - int flush -) -{ +local block_state deflate_fast(deflate_state *s, int flush) { IPos hash_head; /* head of the hash chain */ int bflush; /* set if current block must be flushed */ @@ -2032,11 +1925,7 @@ local block_state deflate_fast( * evaluation for matches: a match is finally adopted only if there is * no better match at the next window position. */ -local block_state deflate_slow( - deflate_state *s, - int flush -) -{ +local block_state deflate_slow(deflate_state *s, int flush) { IPos hash_head; /* head of hash chain */ int bflush; /* set if current block must be flushed */ @@ -2166,10 +2055,7 @@ local block_state deflate_slow( * one. Do not maintain a hash table. (It will be regenerated if this run of * deflate switches away from Z_RLE.) */ -local block_state deflate_rle(s, flush) - deflate_state *s; - int flush; -{ +local block_state deflate_rle(deflate_state *s, int flush) { int bflush; /* set if current block must be flushed */ uInt prev; /* byte at distance one to match */ Bytef *scan, *strend; /* scan goes up to strend for length of run */ @@ -2240,10 +2126,7 @@ local block_state deflate_rle(s, flush) * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. * (It will be regenerated if this run of deflate switches away from Huffman.) */ -local block_state deflate_huff(s, flush) - deflate_state *s; - int flush; -{ +local block_state deflate_huff(deflate_state *s, int flush) { int bflush; /* set if current block must be flushed */ for (;;) { diff --git a/lib/libvgz/gzguts.h b/lib/libvgz/gzguts.h index 433c8d8af..cfde69df5 100644 --- a/lib/libvgz/gzguts.h +++ b/lib/libvgz/gzguts.h @@ -7,9 +7,8 @@ # ifndef _LARGEFILE_SOURCE # define _LARGEFILE_SOURCE 1 # endif -# ifdef _FILE_OFFSET_BITS # undef _FILE_OFFSET_BITS -# endif +# undef _TIME_BITS #endif #ifdef HAVE_HIDDEN diff --git a/lib/libvgz/inffast.c b/lib/libvgz/inffast.c index 01b00436b..1f49bd5a5 100644 --- a/lib/libvgz/inffast.c +++ b/lib/libvgz/inffast.c @@ -47,11 +47,7 @@ requires strm->avail_out >= 258 for each loop to avoid checking for output space. */ -void ZLIB_INTERNAL inflate_fast( - z_streamp strm, - unsigned start /* inflate()'s starting value for strm->avail_out */ -) -{ +void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) { struct inflate_state FAR *state; z_const unsigned char FAR *in; /* local strm->next_in */ z_const unsigned char FAR *last; /* have enough input while in < last */ diff --git a/lib/libvgz/inflate.c b/lib/libvgz/inflate.c index 7cdee41b0..deae8231f 100644 --- a/lib/libvgz/inflate.c +++ b/lib/libvgz/inflate.c @@ -91,23 +91,7 @@ # endif #endif -/* function prototypes */ -local int inflateStateCheck (z_streamp strm); -local void fixedtables (struct inflate_state FAR *state); -local int updatewindow (z_streamp strm, const unsigned char FAR *end, - unsigned copy); -#ifdef BUILDFIXED - void makefixed (void); -#endif -#ifdef NOVGZ -local unsigned syncsearch (unsigned FAR *have, const unsigned char FAR *buf, - unsigned len); -#endif /* NOVGZ */ - -local int inflateStateCheck( - z_streamp strm -) -{ +local int inflateStateCheck(z_streamp strm) { struct inflate_state FAR *state; if (strm == Z_NULL || strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) @@ -119,10 +103,7 @@ local int inflateStateCheck( return 0; } -int ZEXPORT inflateResetKeep( - z_streamp strm -) -{ +int ZEXPORT inflateResetKeep(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -147,10 +128,7 @@ int ZEXPORT inflateResetKeep( return Z_OK; } -int ZEXPORT inflateReset( - z_streamp strm -) -{ +int ZEXPORT inflateReset(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -161,11 +139,7 @@ int ZEXPORT inflateReset( return inflateResetKeep(strm); } -int ZEXPORT inflateReset2( - z_streamp strm, - int windowBits -) -{ +int ZEXPORT inflateReset2(z_streamp strm, int windowBits) { int wrap; struct inflate_state FAR *state; @@ -202,13 +176,8 @@ int ZEXPORT inflateReset2( return inflateReset(strm); } -int ZEXPORT inflateInit2_( - z_streamp strm, - int windowBits, - const char *version, - int stream_size -) -{ +int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, + const char *version, int stream_size) { int ret; struct inflate_state FAR *state; @@ -249,24 +218,17 @@ int ZEXPORT inflateInit2_( #ifdef NOVGZ -int ZEXPORT inflateInit_( - z_streamp strm, - const char *version, - int stream_size -) -{ +int ZEXPORT inflateInit_(z_streamp strm, const char *version, + int stream_size) { return inflateInit2_(strm, DEF_WBITS, version, stream_size); } -int ZEXPORT inflatePrime( - z_streamp strm, - int bits, - int value -) -{ +int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; + if (bits == 0) + return Z_OK; state = (struct inflate_state FAR *)strm->state; if (bits < 0) { state->hold = 0; @@ -292,10 +254,7 @@ int ZEXPORT inflatePrime( used for threaded applications, since the rewriting of the tables and virgin may not be thread-safe. */ -local void fixedtables( - struct inflate_state FAR *state -) -{ +local void fixedtables(struct inflate_state FAR *state) { #ifdef BUILDFIXED static int virgin = 1; static code *lenfix, *distfix; @@ -357,7 +316,7 @@ local void fixedtables( a.out > inffixed.h */ -void makefixed() +void makefixed(void) { unsigned low, size; struct inflate_state state; @@ -411,12 +370,7 @@ void makefixed() output will fall in the output data, making match copies simpler and faster. The advantage may be dependent on the size of the processor's data caches. */ -local int updatewindow( - z_streamp strm, - const Bytef *end, - unsigned copy -) -{ +local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) { struct inflate_state FAR *state; unsigned dist; @@ -638,11 +592,7 @@ local int updatewindow( will return Z_BUF_ERROR if it has not reached the end of the stream. */ -int ZEXPORT inflate( - z_streamp strm, - int flush -) -{ +int ZEXPORT inflate(z_streamp strm, int flush) { struct inflate_state FAR *state; z_const unsigned char FAR *next; /* next input */ unsigned char FAR *put; /* next output */ @@ -1323,10 +1273,7 @@ int ZEXPORT inflate( return ret; } -int ZEXPORT inflateEnd( - z_streamp strm -) -{ +int ZEXPORT inflateEnd(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1340,11 +1287,8 @@ int ZEXPORT inflateEnd( #ifdef NOVGZ -int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength) -z_streamp strm; -Bytef *dictionary; -uInt *dictLength; -{ +int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, + uInt *dictLength) { struct inflate_state FAR *state; /* check state */ @@ -1363,11 +1307,8 @@ uInt *dictLength; return Z_OK; } -int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) -z_streamp strm; -const Bytef *dictionary; -uInt dictLength; -{ +int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength) { struct inflate_state FAR *state; unsigned long dictid; int ret; @@ -1398,10 +1339,7 @@ uInt dictLength; return Z_OK; } -int ZEXPORT inflateGetHeader(strm, head) -z_streamp strm; -gz_headerp head; -{ +int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) { struct inflate_state FAR *state; /* check state */ @@ -1426,11 +1364,8 @@ gz_headerp head; called again with more data and the *have state. *have is initialized to zero for the first call. */ -local unsigned syncsearch(have, buf, len) -unsigned FAR *have; -const unsigned char FAR *buf; -unsigned len; -{ +local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, + unsigned len) { unsigned got; unsigned next; @@ -1449,9 +1384,7 @@ unsigned len; return next; } -int ZEXPORT inflateSync(strm) -z_streamp strm; -{ +int ZEXPORT inflateSync(z_streamp strm) { unsigned len; /* number of bytes to look at or looked at */ int flags; /* temporary to save header status */ unsigned long in, out; /* temporary to save total_in and total_out */ @@ -1507,9 +1440,7 @@ z_streamp strm; block. When decompressing, PPP checks that at the end of input packet, inflate is waiting for these length bytes. */ -int ZEXPORT inflateSyncPoint(strm) -z_streamp strm; -{ +int ZEXPORT inflateSyncPoint(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1517,10 +1448,7 @@ z_streamp strm; return state->mode == STORED && state->bits == 0; } -int ZEXPORT inflateCopy(dest, source) -z_streamp dest; -z_streamp source; -{ +int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) { struct inflate_state FAR *state; struct inflate_state FAR *copy; unsigned char FAR *window; @@ -1564,10 +1492,7 @@ z_streamp source; return Z_OK; } -int ZEXPORT inflateUndermine(strm, subvert) -z_streamp strm; -int subvert; -{ +int ZEXPORT inflateUndermine(z_streamp strm, int subvert) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1582,10 +1507,7 @@ int subvert; #endif } -int ZEXPORT inflateValidate(strm, check) -z_streamp strm; -int check; -{ +int ZEXPORT inflateValidate(z_streamp strm, int check) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1597,9 +1519,7 @@ int check; return Z_OK; } -long ZEXPORT inflateMark(strm) -z_streamp strm; -{ +long ZEXPORT inflateMark(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) @@ -1610,9 +1530,7 @@ z_streamp strm; (state->mode == MATCH ? state->was - state->length : 0)); } -unsigned long ZEXPORT inflateCodesUsed(strm) -z_streamp strm; -{ +unsigned long ZEXPORT inflateCodesUsed(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return (unsigned long)-1; state = (struct inflate_state FAR *)strm->state; diff --git a/lib/libvgz/inftrees.c b/lib/libvgz/inftrees.c index a794b0e27..a6a8a9edc 100644 --- a/lib/libvgz/inftrees.c +++ b/lib/libvgz/inftrees.c @@ -1,5 +1,5 @@ /* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2022 Mark Adler + * Copyright (C) 1995-2023 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -10,7 +10,7 @@ extern const char inflate_copyright[]; const char inflate_copyright[] = - " inflate 1.2.13 Copyright 1995-2022 Mark Adler "; + " inflate 1.3 Copyright 1995-2023 Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -30,15 +30,9 @@ const char inflate_copyright[] = table index bits. It will differ if the request is greater than the longest code or if it is less than the shortest code. */ -int ZLIB_INTERNAL inflate_table( - codetype type, - unsigned short FAR *lens, - unsigned codes, - code FAR * FAR *table, - unsigned FAR *bits, - unsigned short FAR *work -) -{ +int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, + unsigned codes, code FAR * FAR *table, + unsigned FAR *bits, unsigned short FAR *work) { unsigned len; /* a code's length in bits */ unsigned sym; /* index of code symbols */ unsigned min, max; /* minimum and maximum code lengths */ @@ -64,7 +58,7 @@ int ZLIB_INTERNAL inflate_table( 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 194, 65}; + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 198, 203}; static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, diff --git a/lib/libvgz/trees.c b/lib/libvgz/trees.c index 7f1f949fe..51fdadba8 100644 --- a/lib/libvgz/trees.c +++ b/lib/libvgz/trees.c @@ -122,36 +122,113 @@ struct static_tree_desc_s { int max_length; /* max bit length for the codes */ }; -local const static_tree_desc static_l_desc = +#ifdef NO_INIT_GLOBAL_POINTERS +# define TCONST +#else +# define TCONST const +#endif + +local TCONST static_tree_desc static_l_desc = {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; -local const static_tree_desc static_d_desc = +local TCONST static_tree_desc static_d_desc = {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; -local const static_tree_desc static_bl_desc = +local TCONST static_tree_desc static_bl_desc = {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; /* =========================================================================== - * Local (static) routines in this file. + * Output a short LSB first on the stream. + * IN assertion: there is enough room in pendingBuf. + */ +#define put_short(s, w) { \ + put_byte(s, (uch)((w) & 0xff)); \ + put_byte(s, (uch)((ush)(w) >> 8)); \ +} + +/* =========================================================================== + * Reverse the first len bits of a code, using straightforward code (a faster + * method would use a table) + * IN assertion: 1 <= len <= 15 */ +local unsigned bi_reverse(unsigned code, int len) { + register unsigned res = 0; + do { + res |= code & 1; + code >>= 1, res <<= 1; + } while (--len > 0); + return res >> 1; +} -local void tr_static_init (void); -local void init_block (deflate_state *s); -local void pqdownheap (deflate_state *s, ct_data *tree, int k); -local void gen_bitlen (deflate_state *s, tree_desc *desc); -local void gen_codes (ct_data *tree, int max_code, ushf *bl_count); -local void build_tree (deflate_state *s, tree_desc *desc); -local void scan_tree (deflate_state *s, ct_data *tree, int max_code); -local void send_tree (deflate_state *s, ct_data *tree, int max_code); -local int build_bl_tree (deflate_state *s); -local void send_all_trees (deflate_state *s, int lcodes, int dcodes, - int blcodes); -local void compress_block (deflate_state *s, const ct_data *ltree, - const ct_data *dtree); -local int detect_data_type (deflate_state *s); -local unsigned bi_reverse (unsigned code, int len); -local void bi_windup (deflate_state *s); -local void bi_flush (deflate_state *s); +/* =========================================================================== + * Flush the bit buffer, keeping at most 7 bits in it. + */ +local void bi_flush(deflate_state *s) { + if (s->bi_valid == 16) { + put_short(s, s->bi_buf); + s->bi_buf = 0; + s->bi_valid = 0; + } else if (s->bi_valid >= 8) { + put_byte(s, (Byte)s->bi_buf); + s->bi_buf >>= 8; + s->bi_valid -= 8; + } +} + +/* =========================================================================== + * Flush the bit buffer and align the output on a byte boundary + */ +local void bi_windup(deflate_state *s) { + if (s->bi_valid > 8) { + put_short(s, s->bi_buf); + } else if (s->bi_valid > 0) { + put_byte(s, (Byte)s->bi_buf); + } + s->bi_buf = 0; + s->bi_valid = 0; +#ifdef ZLIB_DEBUG + s->bits_sent = (s->bits_sent+7) & ~7; +#endif +} + +/* =========================================================================== + * Generate the codes for a given tree and bit counts (which need not be + * optimal). + * IN assertion: the array bl_count contains the bit length statistics for + * the given tree and the field len is set for all tree elements. + * OUT assertion: the field code is set for all tree elements of non + * zero code length. + */ +local void gen_codes(ct_data *tree, int max_code, ushf *bl_count) { + ush next_code[MAX_BITS+1]; /* next code value for each bit length */ + unsigned code = 0; /* running code value */ + int bits; /* bit index */ + int n; /* code index */ + + /* The distribution counts are first used to generate the code values + * without bit reversal. + */ + for (bits = 1; bits <= MAX_BITS; bits++) { + code = (code + bl_count[bits-1]) << 1; + next_code[bits] = (ush)code; + } + /* Check that the bit counts in bl_count are consistent. The last code + * must be all ones. + */ + Assert (code + bl_count[MAX_BITS]-1 == (1<> 8)); \ -} - /* =========================================================================== * Send a value on a given number of bits. * IN assertion: length <= 16 and value fits in length bits. */ #ifdef ZLIB_DEBUG -local void send_bits (deflate_state *s, int value, int length); - -local void send_bits(s, value, length) - deflate_state *s; - int value; /* value to send */ - int length; /* number of bits */ -{ +local void send_bits(deflate_state *s, int value, int length) { Tracevv((stderr," l %2d v %4x ", length, value)); Assert(length > 0 && length <= 15, "invalid length"); s->bits_sent += (ulg)length; @@ -229,8 +291,7 @@ local void send_bits(s, value, length) /* =========================================================================== * Initialize the various 'constant' tables. */ -local void tr_static_init(void) -{ +local void tr_static_init(void) { #if defined(GEN_TREES_H) || !defined(STDC) static int static_init_done = 0; int n; /* iterates over tree elements */ @@ -323,8 +384,7 @@ local void tr_static_init(void) ((i) == (last)? "\n};\n\n" : \ ((i) % (width) == (width)-1 ? ",\n" : ", ")) -void gen_trees_header() -{ +void gen_trees_header(void) { FILE *header = fopen("trees.h", "w"); int i; @@ -373,13 +433,26 @@ void gen_trees_header() } #endif /* GEN_TREES_H */ +/* =========================================================================== + * Initialize a new block. + */ +local void init_block(deflate_state *s) { + int n; /* iterates over tree elements */ + + /* Initialize the trees. */ + for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; + for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; + for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; + + s->dyn_ltree[END_BLOCK].Freq = 1; + s->opt_len = s->static_len = 0L; + s->sym_next = s->matches = 0; +} + /* =========================================================================== * Initialize the tree data structures for a new zlib stream. */ -void ZLIB_INTERNAL _tr_init( - deflate_state *s -) -{ +void ZLIB_INTERNAL _tr_init(deflate_state *s) { tr_static_init(); s->l_desc.dyn_tree = s->dyn_ltree; @@ -402,25 +475,6 @@ void ZLIB_INTERNAL _tr_init( init_block(s); } -/* =========================================================================== - * Initialize a new block. - */ -local void init_block( - deflate_state *s -) -{ - int n; /* iterates over tree elements */ - - /* Initialize the trees. */ - for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; - for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; - for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; - - s->dyn_ltree[END_BLOCK].Freq = 1; - s->opt_len = s->static_len = 0L; - s->sym_next = s->matches = 0; -} - #define SMALLEST 1 /* Index within the heap array of least frequent node in the Huffman tree */ @@ -450,12 +504,7 @@ local void init_block( * when the heap property is re-established (each father smaller than its * two sons). */ -local void pqdownheap( - deflate_state *s, - ct_data *tree, /* the tree to restore */ - int k /* node to move down */ -) -{ +local void pqdownheap(deflate_state *s, ct_data *tree, int k) { int v = s->heap[k]; int j = k << 1; /* left son of k */ while (j <= s->heap_len) { @@ -486,11 +535,7 @@ local void pqdownheap( * The length opt_len is updated; static_len is also updated if stree is * not null. */ -local void gen_bitlen( - deflate_state *s, - tree_desc *desc /* the tree descriptor */ -) -{ +local void gen_bitlen(deflate_state *s, tree_desc *desc) { ct_data *tree = desc->dyn_tree; int max_code = desc->max_code; const ct_data *stree = desc->stat_desc->static_tree; @@ -565,49 +610,9 @@ local void gen_bitlen( } } -/* =========================================================================== - * Generate the codes for a given tree and bit counts (which need not be - * optimal). - * IN assertion: the array bl_count contains the bit length statistics for - * the given tree and the field len is set for all tree elements. - * OUT assertion: the field code is set for all tree elements of non - * zero code length. - */ -local void gen_codes ( - ct_data *tree, /* the tree to decorate */ - int max_code, /* largest code with non zero frequency */ - ushf *bl_count /* number of codes at each bit length */ -) -{ - ush next_code[MAX_BITS+1]; /* next code value for each bit length */ - unsigned code = 0; /* running code value */ - int bits; /* bit index */ - int n; /* code index */ - - /* The distribution counts are first used to generate the code values - * without bit reversal. - */ - for (bits = 1; bits <= MAX_BITS; bits++) { - code = (code + bl_count[bits-1]) << 1; - next_code[bits] = (ush)code; - } - /* Check that the bit counts in bl_count are consistent. The last code - * must be all ones. - */ - Assert (code + bl_count[MAX_BITS]-1 == (1< +#endif /* =========================================================================== * Construct one Huffman tree and assigns the code bit strings and lengths. @@ -617,11 +622,7 @@ local void gen_codes ( * and corresponding code. The length opt_len is updated; static_len is * also updated if stree is not null. The field max_code is set. */ -local void build_tree( - deflate_state *s, - tree_desc *desc /* the tree descriptor */ -) -{ +local void build_tree(deflate_state *s, tree_desc *desc) { ct_data *tree = desc->dyn_tree; const ct_data *stree = desc->stat_desc->static_tree; int elems = desc->stat_desc->elems; @@ -706,12 +707,7 @@ local void build_tree( * Scan a literal or distance tree to determine the frequencies of the codes * in the bit length tree. */ -local void scan_tree ( - deflate_state *s, - ct_data *tree, /* the tree to be scanned */ - int max_code /* and its largest code of non zero frequency */ -) -{ +local void scan_tree(deflate_state *s, ct_data *tree, int max_code) { int n; /* iterates over all tree elements */ int prevlen = -1; /* last emitted length */ int curlen; /* length of current code */ @@ -752,12 +748,7 @@ local void scan_tree ( * Send a literal or distance tree in compressed form, using the codes in * bl_tree. */ -local void send_tree ( - deflate_state *s, - ct_data *tree, /* the tree to be scanned */ - int max_code /* and its largest code of non zero frequency */ -) -{ +local void send_tree(deflate_state *s, ct_data *tree, int max_code) { int n; /* iterates over all tree elements */ int prevlen = -1; /* last emitted length */ int curlen; /* length of current code */ @@ -804,10 +795,7 @@ local void send_tree ( * Construct the Huffman tree for the bit lengths and return the index in * bl_order of the last bit length code to send. */ -local int build_bl_tree( - deflate_state *s -) -{ +local int build_bl_tree(deflate_state *s) { int max_blindex; /* index of last bit length code of non zero freq */ /* Determine the bit length frequencies for literal and distance trees */ @@ -840,13 +828,8 @@ local int build_bl_tree( * lengths of the bit length codes, the literal tree and the distance tree. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. */ -local void send_all_trees( - deflate_state *s, - int lcodes, - int dcodes, - int blcodes /* number of codes for each tree */ -) -{ +local void send_all_trees(deflate_state *s, int lcodes, int dcodes, + int blcodes) { int rank; /* index in bl_order */ Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); @@ -872,13 +855,8 @@ local void send_all_trees( /* =========================================================================== * Send a stored block */ -void ZLIB_INTERNAL _tr_stored_block( - deflate_state *s, - charf *buf, /* input block */ - ulg stored_len, /* length of input block */ - int last /* one if this is the last block for a file */ -) -{ +void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, + ulg stored_len, int last) { if (last) s->strm->last_bit = (s->strm->total_out + s->pending) * 8 + s->bi_valid; @@ -904,10 +882,7 @@ void ZLIB_INTERNAL _tr_stored_block( /* =========================================================================== * Flush the bits in the bit buffer to pending output (leaves at most 7 bits) */ -void ZLIB_INTERNAL _tr_flush_bits( - deflate_state *s -) -{ +void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s) { bi_flush(s); } @@ -915,10 +890,7 @@ void ZLIB_INTERNAL _tr_flush_bits( * Send one empty static block to give enough lookahead for inflate. * This takes 10 bits, of which 7 may remain in the bit buffer. */ -void ZLIB_INTERNAL _tr_align( - deflate_state *s -) -{ +void ZLIB_INTERNAL _tr_align(deflate_state *s) { send_bits(s, STATIC_TREES<<1, 3); send_code(s, END_BLOCK, static_ltree); #ifdef ZLIB_DEBUG @@ -927,17 +899,99 @@ void ZLIB_INTERNAL _tr_align( bi_flush(s); } +/* =========================================================================== + * Send the block data compressed using the given Huffman trees + */ +local void compress_block(deflate_state *s, const ct_data *ltree, + const ct_data *dtree) { + unsigned dist; /* distance of matched string */ + int lc; /* match length or unmatched char (if dist == 0) */ + unsigned sx = 0; /* running index in sym_buf */ + unsigned code; /* the code to send */ + int extra; /* number of extra bits to send */ + + if (s->sym_next != 0) do { + dist = s->sym_buf[sx++] & 0xff; + dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; + lc = s->sym_buf[sx++]; + if (dist == 0) { + send_code(s, lc, ltree); /* send a literal byte */ + Tracecv(isgraph(lc), (stderr," '%c' ", lc)); + } else { + /* Here, lc is the match length - MIN_MATCH */ + code = _length_code[lc]; + send_code(s, code + LITERALS + 1, ltree); /* send length code */ + extra = extra_lbits[code]; + if (extra != 0) { + lc -= base_length[code]; + send_bits(s, lc, extra); /* send the extra length bits */ + } + dist--; /* dist is now the match distance - 1 */ + code = d_code(dist); + Assert (code < D_CODES, "bad d_code"); + + send_code(s, code, dtree); /* send the distance code */ + extra = extra_dbits[code]; + if (extra != 0) { + dist -= (unsigned)base_dist[code]; + send_bits(s, dist, extra); /* send the extra distance bits */ + } + } /* literal or match pair ? */ + + /* Check that the overlay between pending_buf and sym_buf is ok: */ + Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); + + } while (sx < s->sym_next); + + send_code(s, END_BLOCK, ltree); +} + +/* =========================================================================== + * Check if the data type is TEXT or BINARY, using the following algorithm: + * - TEXT if the two conditions below are satisfied: + * a) There are no non-portable control characters belonging to the + * "block list" (0..6, 14..25, 28..31). + * b) There is at least one printable character belonging to the + * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). + * - BINARY otherwise. + * - The following partially-portable control characters form a + * "gray list" that is ignored in this detection algorithm: + * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). + * IN assertion: the fields Freq of dyn_ltree are set. + */ +local int detect_data_type(deflate_state *s) { + /* block_mask is the bit mask of block-listed bytes + * set bits 0..6, 14..25, and 28..31 + * 0xf3ffc07f = binary 11110011111111111100000001111111 + */ + unsigned long block_mask = 0xf3ffc07fUL; + int n; + + /* Check for non-textual ("block-listed") bytes. */ + for (n = 0; n <= 31; n++, block_mask >>= 1) + if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0)) + return Z_BINARY; + + /* Check for textual ("allow-listed") bytes. */ + if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 + || s->dyn_ltree[13].Freq != 0) + return Z_TEXT; + for (n = 32; n < LITERALS; n++) + if (s->dyn_ltree[n].Freq != 0) + return Z_TEXT; + + /* There are no "block-listed" or "allow-listed" bytes: + * this stream either is empty or has tolerated ("gray-listed") bytes only. + */ + return Z_BINARY; +} + /* =========================================================================== * Determine the best encoding for the current block: dynamic trees, static * trees or store, and write out the encoded block. */ -void ZLIB_INTERNAL _tr_flush_block( - deflate_state *s, - charf *buf, /* input block, or NULL if too old */ - ulg stored_len, /* length of input block */ - int last /* one if this is the last block for a file */ -) -{ +void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, + ulg stored_len, int last) { ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ int max_blindex = 0; /* index of last bit length code of non zero freq */ @@ -1040,12 +1094,7 @@ void ZLIB_INTERNAL _tr_flush_block( * Save the match info and tally the frequency counts. Return true if * the current block must be flushed. */ -int ZLIB_INTERNAL _tr_tally ( - deflate_state *s, - unsigned dist, /* distance of matched string */ - unsigned lc /* match length - MIN_MATCH or unmatched char (dist==0) */ -) -{ +int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) { s->sym_buf[s->sym_next++] = (uch)dist; s->sym_buf[s->sym_next++] = (uch)(dist >> 8); s->sym_buf[s->sym_next++] = (uch)lc; @@ -1065,152 +1114,3 @@ int ZLIB_INTERNAL _tr_tally ( } return (s->sym_next == s->sym_end); } - -/* =========================================================================== - * Send the block data compressed using the given Huffman trees - */ -local void compress_block( - deflate_state *s, - const ct_data *ltree, /* literal tree */ - const ct_data *dtree /* distance tree */ -) -{ - unsigned dist; /* distance of matched string */ - int lc; /* match length or unmatched char (if dist == 0) */ - unsigned sx = 0; /* running index in sym_buf */ - unsigned code; /* the code to send */ - int extra; /* number of extra bits to send */ - - if (s->sym_next != 0) do { - dist = s->sym_buf[sx++] & 0xff; - dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; - lc = s->sym_buf[sx++]; - if (dist == 0) { - send_code(s, lc, ltree); /* send a literal byte */ - Tracecv(isgraph(lc), (stderr," '%c' ", lc)); - } else { - /* Here, lc is the match length - MIN_MATCH */ - code = _length_code[lc]; - send_code(s, code + LITERALS + 1, ltree); /* send length code */ - extra = extra_lbits[code]; - if (extra != 0) { - lc -= base_length[code]; - send_bits(s, lc, extra); /* send the extra length bits */ - } - dist--; /* dist is now the match distance - 1 */ - code = d_code(dist); - Assert (code < D_CODES, "bad d_code"); - - send_code(s, code, dtree); /* send the distance code */ - extra = extra_dbits[code]; - if (extra != 0) { - dist -= (unsigned)base_dist[code]; - send_bits(s, dist, extra); /* send the extra distance bits */ - } - } /* literal or match pair ? */ - - /* Check that the overlay between pending_buf and sym_buf is ok: */ - Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); - - } while (sx < s->sym_next); - - send_code(s, END_BLOCK, ltree); -} - -/* =========================================================================== - * Check if the data type is TEXT or BINARY, using the following algorithm: - * - TEXT if the two conditions below are satisfied: - * a) There are no non-portable control characters belonging to the - * "block list" (0..6, 14..25, 28..31). - * b) There is at least one printable character belonging to the - * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). - * - BINARY otherwise. - * - The following partially-portable control characters form a - * "gray list" that is ignored in this detection algorithm: - * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). - * IN assertion: the fields Freq of dyn_ltree are set. - */ -local int detect_data_type( - deflate_state *s -) -{ - /* block_mask is the bit mask of block-listed bytes - * set bits 0..6, 14..25, and 28..31 - * 0xf3ffc07f = binary 11110011111111111100000001111111 - */ - unsigned long block_mask = 0xf3ffc07fUL; - int n; - - /* Check for non-textual ("block-listed") bytes. */ - for (n = 0; n <= 31; n++, block_mask >>= 1) - if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0)) - return Z_BINARY; - - /* Check for textual ("allow-listed") bytes. */ - if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 - || s->dyn_ltree[13].Freq != 0) - return Z_TEXT; - for (n = 32; n < LITERALS; n++) - if (s->dyn_ltree[n].Freq != 0) - return Z_TEXT; - - /* There are no "block-listed" or "allow-listed" bytes: - * this stream either is empty or has tolerated ("gray-listed") bytes only. - */ - return Z_BINARY; -} - -/* =========================================================================== - * Reverse the first len bits of a code, using straightforward code (a faster - * method would use a table) - * IN assertion: 1 <= len <= 15 - */ -local unsigned bi_reverse( - unsigned code, /* the value to invert */ - int len /* its bit length */ -) -{ - register unsigned res = 0; - do { - res |= code & 1; - code >>= 1, res <<= 1; - } while (--len > 0); - return res >> 1; -} - -/* =========================================================================== - * Flush the bit buffer, keeping at most 7 bits in it. - */ -local void bi_flush( - deflate_state *s -) -{ - if (s->bi_valid == 16) { - put_short(s, s->bi_buf); - s->bi_buf = 0; - s->bi_valid = 0; - } else if (s->bi_valid >= 8) { - put_byte(s, (Byte)s->bi_buf); - s->bi_buf >>= 8; - s->bi_valid -= 8; - } -} - -/* =========================================================================== - * Flush the bit buffer and align the output on a byte boundary - */ -local void bi_windup( - deflate_state *s -) -{ - if (s->bi_valid > 8) { - put_short(s, s->bi_buf); - } else if (s->bi_valid > 0) { - put_byte(s, (Byte)s->bi_buf); - } - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef ZLIB_DEBUG - s->bits_sent = (s->bits_sent+7) & ~7; -#endif -} diff --git a/lib/libvgz/vgz.h b/lib/libvgz/vgz.h index a91fd3d66..b423e9efd 100644 --- a/lib/libvgz/vgz.h +++ b/lib/libvgz/vgz.h @@ -1,7 +1,7 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.13, October 13th, 2022 + version 1.3, August 18th, 2023 - Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler + Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -37,11 +37,11 @@ extern "C" { #endif -#define ZLIB_VERSION "1.2.13" -#define ZLIB_VERNUM 0x12d0 +#define ZLIB_VERSION "1.3" +#define ZLIB_VERNUM 0x1300 #define ZLIB_VER_MAJOR 1 -#define ZLIB_VER_MINOR 2 -#define ZLIB_VER_REVISION 13 +#define ZLIB_VER_MINOR 3 +#define ZLIB_VER_REVISION 0 #define ZLIB_VER_SUBREVISION 0 /* @@ -235,7 +235,7 @@ ZEXTERN int ZEXPORT deflateInit (z_streamp strm, int level); Initializes the internal stream state for compression. The fields zalloc, zfree and opaque must be initialized before by the caller. If zalloc and zfree are set to Z_NULL, deflateInit updates them to use default - allocation functions. + allocation functions. total_in, total_out, adler, and msg are initialized. The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all @@ -325,8 +325,8 @@ ZEXTERN int ZEXPORT deflate (z_streamp strm, int flush); with the same value of the flush parameter and more output space (updated avail_out), until the flush is complete (deflate returns with non-zero avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that - avail_out is greater than six to avoid repeated flush markers due to - avail_out == 0 on return. + avail_out is greater than six when the flush marker begins, in order to avoid + repeated flush markers upon calling deflate() again when avail_out == 0. If the parameter flush is set to Z_FINISH, pending input is processed, pending output is flushed and deflate returns with Z_STREAM_END if there was @@ -388,7 +388,8 @@ ZEXTERN int ZEXPORT inflateInit (z_streamp strm); read or consumed. The allocation of a sliding window will be deferred to the first call of inflate (if the decompression does not complete on the first call). If zalloc and zfree are set to Z_NULL, inflateInit updates - them to use default allocation functions. + them to use default allocation functions. total_in, total_out, adler, and + msg are initialized. inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_VERSION_ERROR if the zlib library version is incompatible with the @@ -701,7 +702,7 @@ ZEXTERN int ZEXPORT deflateReset (z_streamp strm); This function is equivalent to deflateEnd followed by deflateInit, but does not free and reallocate the internal compression state. The stream will leave the compression level and any other attributes that may have been - set unchanged. + set unchanged. total_in, total_out, adler, and msg are initialized. deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being Z_NULL). @@ -734,7 +735,7 @@ ZEXTERN int ZEXPORT deflateParams (z_streamp strm, Then no more input data should be provided before the deflateParams() call. If this is done, the old level and strategy will be applied to the data compressed before deflateParams(), and the new level and strategy will be - applied to the the data compressed after deflateParams(). + applied to the data compressed after deflateParams(). deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if @@ -826,8 +827,9 @@ ZEXTERN int ZEXPORT deflateSetHeader (z_streamp strm, gzip file" and give up. If deflateSetHeader is not used, the default gzip header has text false, - the time set to zero, and os set to 255, with no extra, name, or comment - fields. The gzip header is returned to the default state by deflateReset(). + the time set to zero, and os set to the current operating system, with no + extra, name, or comment fields. The gzip header is returned to the default + state by deflateReset(). deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent. @@ -966,6 +968,7 @@ ZEXTERN int ZEXPORT inflateReset (z_streamp strm); This function is equivalent to inflateEnd followed by inflateInit, but does not free and reallocate the internal decompression state. The stream will keep attributes that may have been set by inflateInit2. + total_in, total_out, adler, and msg are initialized. inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being Z_NULL). @@ -1470,7 +1473,7 @@ ZEXTERN z_size_t ZEXPORT gzfwrite (voidpc buf, z_size_t size, is returned, and the error state is set to Z_STREAM_ERROR. */ -ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); +ZEXTERN int ZEXPORTVA gzprintf (gzFile file, const char *format, ...); /* Convert, format, compress, and write the arguments (...) to file under control of the string format, as in fprintf. gzprintf returns the number of @@ -1927,9 +1930,9 @@ ZEXTERN gzFile ZEXPORT gzopen_w (const wchar_t *path, #endif #if defined(STDC) || defined(Z_HAVE_STDARG_H) # ifndef Z_SOLO -ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, +ZEXTERN int ZEXPORTVA gzvprintf (gzFile file, const char *format, - va_list va)); + va_list va); # endif #endif diff --git a/lib/libvgz/zconf.h b/lib/libvgz/zconf.h index bf977d3e7..fb76ffe31 100644 --- a/lib/libvgz/zconf.h +++ b/lib/libvgz/zconf.h @@ -241,7 +241,11 @@ #endif #ifdef Z_SOLO - typedef unsigned long z_size_t; +# ifdef _WIN64 + typedef unsigned long long z_size_t; +# else + typedef unsigned long z_size_t; +# endif #else # define z_longlong long long # if defined(NO_SIZE_T) @@ -520,7 +524,7 @@ typedef uLong FAR uLongf; #if !defined(_WIN32) && defined(Z_LARGE64) # define z_off64_t off64_t #else -# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +# if defined(_WIN32) && !defined(__GNUC__) # define z_off64_t __int64 # else # define z_off64_t z_off_t diff --git a/lib/libvgz/zutil.c b/lib/libvgz/zutil.c index 4082f65ac..911b04ef6 100644 --- a/lib/libvgz/zutil.c +++ b/lib/libvgz/zutil.c @@ -25,13 +25,11 @@ z_const char * const z_errmsg[10] = { #ifdef NOVGZ -const char * ZEXPORT zlibVersion() -{ +const char * ZEXPORT zlibVersion(void) { return ZLIB_VERSION; } -uLong ZEXPORT zlibCompileFlags() -{ +uLong ZEXPORT zlibCompileFlags(void) { uLong flags; flags = 0; @@ -122,9 +120,7 @@ uLong ZEXPORT zlibCompileFlags() # endif int ZLIB_INTERNAL z_verbose = verbose; -void ZLIB_INTERNAL z_error (m) - char *m; -{ +void ZLIB_INTERNAL z_error (char *m) { fprintf(stderr, "%s\n", m); exit(1); } @@ -133,9 +129,7 @@ void ZLIB_INTERNAL z_error (m) /* exported to allow conversion of error code to string for compress() and * uncompress() */ -const char * ZEXPORT zError(err) - int err; -{ +const char * ZEXPORT zError(int err) { return ERR_MSG(err); } @@ -149,22 +143,14 @@ const char * ZEXPORT zError(err) #ifndef HAVE_MEMCPY -void ZLIB_INTERNAL zmemcpy(dest, source, len) - Bytef* dest; - const Bytef* source; - uInt len; -{ +void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) { if (len == 0) return; do { *dest++ = *source++; /* ??? to be unrolled */ } while (--len != 0); } -int ZLIB_INTERNAL zmemcmp(s1, s2, len) - const Bytef* s1; - const Bytef* s2; - uInt len; -{ +int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) { uInt j; for (j = 0; j < len; j++) { @@ -173,10 +159,7 @@ int ZLIB_INTERNAL zmemcmp(s1, s2, len) return 0; } -void ZLIB_INTERNAL zmemzero(dest, len) - Bytef* dest; - uInt len; -{ +void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) { if (len == 0) return; do { *dest++ = 0; /* ??? to be unrolled */ @@ -219,8 +202,7 @@ local ptr_table table[MAX_PTR]; * a protected system like OS/2. Use Microsoft C instead. */ -voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) -{ +voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) { voidpf buf; ulg bsize = (ulg)items*size; @@ -245,8 +227,7 @@ voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) return buf; } -void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) -{ +void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) { int n; (void)opaque; @@ -282,14 +263,12 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) # define _hfree hfree #endif -voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) -{ +voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) { (void)opaque; return _halloc((long)items, size); } -void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) -{ +void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) { (void)opaque; _hfree(ptr); } @@ -307,22 +286,13 @@ extern voidp calloc (uInt items, uInt size); extern void free (voidpf ptr); #endif -voidpf ZLIB_INTERNAL zcalloc ( - voidpf opaque, - unsigned items, - unsigned size -) -{ +voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) { (void)opaque; return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : (voidpf)calloc(items, size); } -void ZLIB_INTERNAL zcfree ( - voidpf opaque, - voidpf ptr -) -{ +void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { (void)opaque; free(ptr); }