summaryrefslogtreecommitdiff
path: root/src/mod_deflate.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mod_deflate.c')
-rw-r--r--src/mod_deflate.c56
1 files changed, 27 insertions, 29 deletions
diff --git a/src/mod_deflate.c b/src/mod_deflate.c
index 0640ec0b..27a29cd7 100644
--- a/src/mod_deflate.c
+++ b/src/mod_deflate.c
@@ -119,8 +119,7 @@
#include "plugin.h"
-#if defined HAVE_ZLIB_H && defined HAVE_LIBZ
-# define USE_ZLIB
+#if defined WITH_ZLIB
# include <zlib.h>
#endif
#ifndef Z_DEFAULT_COMPRESSION
@@ -130,15 +129,13 @@
#define MAX_WBITS 15
#endif
-#if defined HAVE_BZLIB_H && defined HAVE_LIBBZ2
-# define USE_BZ2LIB
+#if defined WITH_BZIP
/* we don't need stdio interface */
# define BZ_NO_STDIO
# include <bzlib.h>
#endif
-#if defined HAVE_SYS_MMAN_H && defined HAVE_MMAP && defined ENABLE_MMAP
-#define USE_MMAP
+#if defined(USE_MMAP)
#include "sys-mmap.h"
#include <setjmp.h>
@@ -152,7 +149,8 @@ static void sigbus_handler(int sig) {
if (sigbus_jmp_valid) siglongjmp(sigbus_jmp, 1);
log_failed_assert(__FILE__, __LINE__, "SIGBUS");
}
-#endif
+
+#endif /* USE_MMAP */
/* request: accept-encoding */
#define HTTP_ACCEPT_ENCODING_IDENTITY BV(0)
@@ -190,10 +188,10 @@ typedef struct {
typedef struct {
union {
- #ifdef USE_ZLIB
+ #ifdef WITH_ZLIB
z_stream z;
#endif
- #ifdef USE_BZ2LIB
+ #ifdef WITH_BZIP
bz_stream bz;
#endif
int dummy;
@@ -341,10 +339,10 @@ SETDEFAULTS_FUNC(mod_deflate_setdefaults) {
if (p->encodings->used) {
size_t j = 0;
for (j = 0; j < p->encodings->used; j++) {
-#if defined(USE_ZLIB) || defined(USE_BZ2LIB)
+#if defined(WITH_ZLIB) || defined(WITH_BZIP)
data_string *ds = (data_string *)p->encodings->data[j];
#endif
-#ifdef USE_ZLIB
+#ifdef WITH_ZLIB
if (NULL != strstr(ds->value->ptr, "gzip"))
s->allowed_encodings |= HTTP_ACCEPT_ENCODING_GZIP | HTTP_ACCEPT_ENCODING_X_GZIP;
if (NULL != strstr(ds->value->ptr, "x-gzip"))
@@ -356,7 +354,7 @@ SETDEFAULTS_FUNC(mod_deflate_setdefaults) {
s->allowed_encodings |= HTTP_ACCEPT_ENCODING_COMPRESS;
*/
#endif
-#ifdef USE_BZ2LIB
+#ifdef WITH_BZIP
if (NULL != strstr(ds->value->ptr, "bzip2"))
s->allowed_encodings |= HTTP_ACCEPT_ENCODING_BZIP2 | HTTP_ACCEPT_ENCODING_X_BZIP2;
if (NULL != strstr(ds->value->ptr, "x-bzip2"))
@@ -365,12 +363,12 @@ SETDEFAULTS_FUNC(mod_deflate_setdefaults) {
}
} else {
/* default encodings */
-#ifdef USE_ZLIB
+#ifdef WITH_ZLIB
s->allowed_encodings |= HTTP_ACCEPT_ENCODING_GZIP
| HTTP_ACCEPT_ENCODING_X_GZIP
| HTTP_ACCEPT_ENCODING_DEFLATE;
#endif
-#ifdef USE_BZ2LIB
+#ifdef WITH_BZIP
s->allowed_encodings |= HTTP_ACCEPT_ENCODING_BZIP2
| HTTP_ACCEPT_ENCODING_X_BZIP2;
#endif
@@ -393,7 +391,7 @@ SETDEFAULTS_FUNC(mod_deflate_setdefaults) {
}
-#if defined(USE_ZLIB) || defined(USE_BZ2LIB)
+#if defined(WITH_ZLIB) || defined(WITH_BZIP)
static int stream_http_chunk_append_mem(server *srv, connection *con, handler_ctx *hctx, size_t len) {
/* future: might also write stream to hctx temporary file in compressed file cache */
return http_chunk_append_mem(srv, con, hctx->output->ptr, len);
@@ -401,7 +399,7 @@ static int stream_http_chunk_append_mem(server *srv, connection *con, handler_ct
#endif
-#ifdef USE_ZLIB
+#ifdef WITH_ZLIB
static int stream_deflate_init(handler_ctx *hctx) {
z_stream * const z = &hctx->u.z;
@@ -511,7 +509,7 @@ static int stream_deflate_end(server *srv, handler_ctx *hctx) {
#endif
-#ifdef USE_BZ2LIB
+#ifdef WITH_BZIP
static int stream_bzip2_init(handler_ctx *hctx) {
bz_stream * const bz = &hctx->u.bz;
@@ -616,12 +614,12 @@ static int stream_bzip2_end(server *srv, handler_ctx *hctx) {
static int mod_deflate_stream_init(handler_ctx *hctx) {
switch(hctx->compression_type) {
-#ifdef USE_ZLIB
+#ifdef WITH_ZLIB
case HTTP_ACCEPT_ENCODING_GZIP:
case HTTP_ACCEPT_ENCODING_DEFLATE:
return stream_deflate_init(hctx);
#endif
-#ifdef USE_BZ2LIB
+#ifdef WITH_BZIP
case HTTP_ACCEPT_ENCODING_BZIP2:
return stream_bzip2_init(hctx);
#endif
@@ -633,12 +631,12 @@ static int mod_deflate_stream_init(handler_ctx *hctx) {
static int mod_deflate_compress(server *srv, connection *con, handler_ctx *hctx, unsigned char *start, off_t st_size) {
if (0 == st_size) return 0;
switch(hctx->compression_type) {
-#ifdef USE_ZLIB
+#ifdef WITH_ZLIB
case HTTP_ACCEPT_ENCODING_GZIP:
case HTTP_ACCEPT_ENCODING_DEFLATE:
return stream_deflate_compress(srv, con, hctx, start, st_size);
#endif
-#ifdef USE_BZ2LIB
+#ifdef WITH_BZIP
case HTTP_ACCEPT_ENCODING_BZIP2:
return stream_bzip2_compress(srv, con, hctx, start, st_size);
#endif
@@ -653,12 +651,12 @@ static int mod_deflate_compress(server *srv, connection *con, handler_ctx *hctx,
static int mod_deflate_stream_flush(server *srv, connection *con, handler_ctx *hctx, int end) {
if (0 == hctx->bytes_in) return 0;
switch(hctx->compression_type) {
-#ifdef USE_ZLIB
+#ifdef WITH_ZLIB
case HTTP_ACCEPT_ENCODING_GZIP:
case HTTP_ACCEPT_ENCODING_DEFLATE:
return stream_deflate_flush(srv, con, hctx, end);
#endif
-#ifdef USE_BZ2LIB
+#ifdef WITH_BZIP
case HTTP_ACCEPT_ENCODING_BZIP2:
return stream_bzip2_flush(srv, con, hctx, end);
#endif
@@ -686,12 +684,12 @@ static void mod_deflate_note_ratio(server *srv, connection *con, handler_ctx *hc
static int mod_deflate_stream_end(server *srv, handler_ctx *hctx) {
switch(hctx->compression_type) {
-#ifdef USE_ZLIB
+#ifdef WITH_ZLIB
case HTTP_ACCEPT_ENCODING_GZIP:
case HTTP_ACCEPT_ENCODING_DEFLATE:
return stream_deflate_end(srv, hctx);
#endif
-#ifdef USE_BZ2LIB
+#ifdef WITH_BZIP
case HTTP_ACCEPT_ENCODING_BZIP2:
return stream_bzip2_end(srv, hctx);
#endif
@@ -993,16 +991,16 @@ static int mod_deflate_patch_connection(server *srv, connection *con, plugin_dat
static int mod_deflate_choose_encoding (const char *value, plugin_data *p, const char **label) {
/* get client side support encodings */
int accept_encoding = 0;
-#if !defined(USE_ZLIB) && !defined(USE_BZ2LIB)
+#if !defined(WITH_ZLIB) && !defined(WITH_BZIP)
UNUSED(value);
#endif
-#ifdef USE_ZLIB
+#ifdef WITH_ZLIB
if (NULL != strstr(value, "gzip")) accept_encoding |= HTTP_ACCEPT_ENCODING_GZIP;
else if (NULL != strstr(value, "x-gzip")) accept_encoding |= HTTP_ACCEPT_ENCODING_X_GZIP;
if (NULL != strstr(value, "deflate")) accept_encoding |= HTTP_ACCEPT_ENCODING_DEFLATE;
#endif
/* if (NULL != strstr(value, "compress")) accept_encoding |= HTTP_ACCEPT_ENCODING_COMPRESS; */
-#ifdef USE_BZ2LIB
+#ifdef WITH_BZIP
if (p->conf.allowed_encodings & (HTTP_ACCEPT_ENCODING_BZIP2 | HTTP_ACCEPT_ENCODING_X_BZIP2)) {
if (NULL != strstr(value, "bzip2")) accept_encoding |= HTTP_ACCEPT_ENCODING_BZIP2;
else if (NULL != strstr(value, "x-bzip2")) accept_encoding |= HTTP_ACCEPT_ENCODING_X_BZIP2;
@@ -1014,7 +1012,7 @@ static int mod_deflate_choose_encoding (const char *value, plugin_data *p, const
accept_encoding &= p->conf.allowed_encodings;
/* select best matching encoding */
-#ifdef USE_BZ2LIB
+#ifdef WITH_BZIP
if (accept_encoding & HTTP_ACCEPT_ENCODING_BZIP2) {
*label = "bzip2";
return HTTP_ACCEPT_ENCODING_BZIP2;