about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-01-07 01:11:20 -0500
committerJune McEnroe <june@causal.agency>2019-01-07 01:11:20 -0500
commitb9551af817e9a2ba90289d9c7de0e4a34f92287d (patch)
tree53f6c362880a641d028dba50d53a5959e9cd9b96
parentmadvise MADV_NOCORE in image (diff)
downloadtorus-b9551af817e9a2ba90289d9c7de0e4a34f92287d.tar.gz
torus-b9551af817e9a2ba90289d9c7de0e4a34f92287d.zip
Compress PNG data in image
kcgi never enables compression for FastCGI.
-rw-r--r--Makefile2
-rw-r--r--image.c9
-rw-r--r--kcgi.mk2
-rw-r--r--png.h8
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 de27349..80bb2de 100644
--- a/image.c
+++ b/image.c
@@ -25,6 +25,7 @@
 #include <sys/stat.h>
 #include <sysexits.h>
 #include <unistd.h>
+#include <zlib.h>
 
 #ifdef __FreeBSD__
 #include <sys/capsicum.h>
@@ -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 4eb4da1..56ddb01 100644
--- a/png.h
+++ b/png.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2018  Curtis McEnroe <june@causal.agency>
+/* Copyright (C) 2018, 2019  C. McEnroe <june@causal.agency>
  *
  * 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);
low=1'>cgit v0.2Lars Hjemli Main changes since v0.1: -list tags in repo summary -allow search in log-view -read repository paths from cgitrc Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-05Add support for prefix and gitsrc arguments to 'make'Lars Hjemli This should improve the installation a little, especially since the new options are mentioned in the README. Also, add a make-rule to build the git binaries if necessary + a dependency between cgit and libgit.a. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-04Update cgitrc templateLars Hjemli Make the descriptions more helpfull. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-04Add support for lightweight tagsLars Hjemli There is nothing bad about a tag that has no tag-object, but the old code didn't handle such tags correctly. Fix it. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-04Read repo-info from /etc/cgitrcLars Hjemli This makes cgit read all repo-info from the configfile, instead of scanning for possible git-dirs below a common root path. This is primarily done to get better security (separate physical path from logical repo-name). In /etc/cgitrc each repo is registered with the following keys: repo.url repo.name repo.path repo.desc repo.owner Note: *Required keys are repo.url and repo.path, all others are optional *Each occurrence of repo.url starts a new repository registration *Default value for repo.name is taken from repo.url *The value of repo.url cannot contain characters with special meaning for urls (i.e. one of /?%&), while repo.name can contain anything. Example: repo.url=cgit-pub repo.name=cgit/public repo.path=/pub/git/cgit repo.desc=My public cgit repo repo.owner=Lars Hjemli repo.url=cgit-priv repo.name=cgit/private repo.path=/home/larsh/src/cgit/.git repo.desc=My private cgit repo repo.owner=Lars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-04Do not die if tag has no messageLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-03Fix search for non-virtual urlsLars Hjemli When cgit don't use virtual urls, the current repo and page url parameters must be included in the search form as hidden input fields. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-01-28Update README with install/config informationLars Hjemli