From 42fcb6656dd9b6c735b09ce61f8ce4e875329c43 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Mon, 7 Jan 2019 01:11:20 -0500 Subject: Compress PNG data in image kcgi never enables compression for FastCGI. --- Makefile | 2 +- image.c | 9 ++++++++- kcgi.mk | 2 +- png.h | 8 +++++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 342e292..b1c43b1 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CHROOT_GROUP = $(CHROOT_USER) CFLAGS += -std=c11 -Wall -Wextra -Wpedantic LDFLAGS = -static -LDLIBS = -lcursesw -lutil +LDLIBS = -lcursesw -lutil -lz -include config.mk diff --git a/image.c b/image.c index ef77906..38cd7cd 100644 --- a/image.c +++ b/image.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef __FreeBSD__ #include @@ -158,7 +159,12 @@ static void render(FILE *stream, uint32_t tileX, uint32_t tileY) { } } - pngData(stream, (uint8_t *)data, sizeof(data)); + uLong zlen = compressBound(sizeof(data)); + uint8_t zdata[zlen]; + int error = compress(zdata, &zlen, (uint8_t *)data, sizeof(data)); + if (error) errx(EX_SOFTWARE, "compress: %d", error); + + pngDeflated(stream, zdata, (size_t)zlen); pngTail(stream); } @@ -229,6 +235,7 @@ static void worker(void) { if (error == KCGI_HUP) goto next; if (error) errkcgi(EX_IOERR, error, "khttp_head"); + // XXX: kcgi never enables compression for FastCGI. error = khttp_body(&req); if (error == KCGI_HUP) goto next; if (error) errkcgi(EX_IOERR, error, "khttp_body"); diff --git a/kcgi.mk b/kcgi.mk index ddfea53..8492047 100644 --- a/kcgi.mk +++ b/kcgi.mk @@ -1,3 +1,3 @@ CFLAGS += -DHAVE_KCGI -I/usr/local/include LDFLAGS += -L/usr/local/lib -LDLIBS += -lkcgi -lz +LDLIBS := -lkcgi $(LDLIBS) diff --git a/png.h b/png.h index 0df4699..d5fd3f5 100644 --- a/png.h +++ b/png.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 June McEnroe +/* Copyright (C) 2018, 2019 June McEnroe * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -102,6 +102,12 @@ static inline void pngData(FILE *file, const uint8_t *data, uint32_t len) { pngInt32(file, ~pngCRC); } +static inline void pngDeflated(FILE *file, const uint8_t *data, uint32_t len) { + pngChunk(file, "IDAT", len); + pngWrite(file, data, len); + pngInt32(file, ~pngCRC); +} + static inline void pngTail(FILE *file) { pngChunk(file, "IEND", 0); pngInt32(file, ~pngCRC); -- cgit 1.4.1 id=d755a6406d8de85f1c56deef827ba2f88df875dc&follow=1'>Add direct game selection tip to menuJune McEnroe 2021-09-27Extract chroot.tar with -pJune McEnroe 2021-09-26OpenBSD: Copy appropriate files for chrootJune McEnroe 2021-09-26Link with -lncurseswJune McEnroe 2021-09-26OpenBSD: pledge(2) and unveil(2)June McEnroe 2021-04-19Draw foundations in reverse orderJune McEnroe 2021-04-19Only print info atexit without -tJune McEnroe 2021-04-19Only use cells for moveColumnJune McEnroe 2021-04-19Force UTF-8 locale and add to chroot, link to curseswJune McEnroe 2021-04-18Add freecellJune McEnroe 2021-04-18Allow cumulative score gamesJune McEnroe 2021-01-31Check isattyJune McEnroe 2021-01-31Launch game immediately with SSH_ORIGINAL_COMMANDJune McEnroe 2021-01-29Handle getch ERR in menuJune McEnroe 2021-01-29Set process title to chosen gameJune McEnroe 2021-01-29Add pause to snakeJune McEnroe 2021-01-29Add menu to choose 2048 or snakeJune McEnroe 2021-01-29Actually wait for a non-direction keyJune McEnroe 2021-01-29Give the snake a tailJune McEnroe 2021-01-29Don't let the snake snap its own neckJune McEnroe