From: Fabian Keil Date: Fri, 8 Jul 2011 13:27:31 +0000 (+0000) Subject: Add the config directive compression-level X-Git-Tag: v_3_0_18~181 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=3947ebff095737086603dadbf9f8443e3accf0e1 Add the config directive compression-level There isn't a single best compression level for all situations, so hard-coding one makes no sense. --- diff --git a/cgi.c b/cgi.c index 86553664..028a798d 100644 --- a/cgi.c +++ b/cgi.c @@ -1,4 +1,4 @@ -const char cgi_rcs[] = "$Id: cgi.c,v 1.136 2011/07/03 17:54:29 fabiankeil Exp $"; +const char cgi_rcs[] = "$Id: cgi.c,v 1.137 2011/07/03 17:55:23 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgi.c,v $ @@ -1495,22 +1495,20 @@ static void get_locale_time(char *buf, size_t buffer_size) * Allocates a new buffer for the result, free'ing it is * up to the caller. * - * XXX: We should add a config option for the - * compression level. - * - * * Parameters : * 1 : buffer = buffer whose content should be compressed * 2 : buffer_length = length of the buffer + * 3 : compression_level = compression level for compress2() * * Returns : NULL on error, otherwise a pointer to the compressed * content of the input buffer. * *********************************************************************/ -char *compress_buffer(char *buffer, size_t *buffer_length) +char *compress_buffer(char *buffer, size_t *buffer_length, int compression_level) { char *compressed_buffer; size_t new_length = *buffer_length; + assert(-1 <= compression_level && compression_level <= 9); compressed_buffer = malloc(new_length); if (NULL == compressed_buffer) @@ -1520,7 +1518,7 @@ char *compress_buffer(char *buffer, size_t *buffer_length) } if (Z_OK != compress2((Bytef *)compressed_buffer, &new_length, - (Bytef *)buffer, *buffer_length, Z_DEFAULT_COMPRESSION)) + (Bytef *)buffer, *buffer_length, compression_level)) { log_error(LOG_LEVEL_ERROR, "Error in compress2()"); freez(compressed_buffer); @@ -1528,7 +1526,8 @@ char *compress_buffer(char *buffer, size_t *buffer_length) } log_error(LOG_LEVEL_RE_FILTER, - "Compressed content from %d to %d bytes.", *buffer_length, new_length); + "Compressed content from %d to %d bytes. Compression level: %d", + *buffer_length, new_length, compression_level); *buffer_length = new_length; @@ -1590,7 +1589,8 @@ struct http_response *finish_http_response(const struct client_state *csp, struc { char *compressed_content; - compressed_content = compress_buffer(rsp->body, &rsp->content_length); + compressed_content = compress_buffer(rsp->body, &rsp->content_length, + csp->config->compression_level); if (NULL != compressed_content) { freez(rsp->body); diff --git a/cgi.h b/cgi.h index 91cd0f8a..d9fe6a7e 100644 --- a/cgi.h +++ b/cgi.h @@ -1,6 +1,6 @@ #ifndef CGI_H_INCLUDED #define CGI_H_INCLUDED -#define CGI_H_VERSION "$Id: cgi.h,v 1.38 2011/06/23 14:01:01 fabiankeil Exp $" +#define CGI_H_VERSION "$Id: cgi.h,v 1.39 2011/07/03 17:55:23 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgi.h,v $ @@ -107,7 +107,7 @@ extern char get_char_param(const struct map *parameters, * we bother to (re-)compress it. Completely arbitrary. */ extern const size_t LOWER_LENGTH_LIMIT_FOR_COMPRESSION; -extern char *compress_buffer(char *buffer, size_t *buffer_length); +extern char *compress_buffer(char *buffer, size_t *buffer_length, int compression_level); #endif /* diff --git a/jcc.c b/jcc.c index a5cf365f..06418a87 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.353 2011/06/23 14:01:01 fabiankeil Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.354 2011/07/03 17:54:29 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -2065,7 +2065,8 @@ static void chat(struct client_state *csp) else if ((csp->flags & CSP_FLAG_CLIENT_SUPPORTS_DEFLATE) && (csp->content_length > LOWER_LENGTH_LIMIT_FOR_COMPRESSION)) { - char *compressed_content = compress_buffer(p, (size_t *)&csp->content_length); + char *compressed_content = compress_buffer(p, + (size_t *)&csp->content_length, csp->config->compression_level); if (compressed_content != NULL) { freez(p); diff --git a/loadcfg.c b/loadcfg.c index 899e4309..338e8ced 100644 --- a/loadcfg.c +++ b/loadcfg.c @@ -1,4 +1,4 @@ -const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.111 2010/08/14 23:28:52 ler762 Exp $"; +const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.112 2011/03/03 14:38:36 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $ @@ -133,6 +133,7 @@ static struct file_list *current_configfile = NULL; #define hash_admin_address 4112573064ul /* "admin-address" */ #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */ #define hash_buffer_limit 1881726070ul /* "buffer-limit */ +#define hash_compression_level 2464423563ul /* "compression-level" */ #define hash_confdir 1978389ul /* "confdir" */ #define hash_connection_sharing 1348841265ul /* "connection-sharing" */ #define hash_debug 78263ul /* "debug" */ @@ -364,6 +365,12 @@ struct configuration_spec * load_config(void) config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS; config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS; config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK; +#ifdef FEATURE_COMPRESSION + /* + * XXX: Run some benchmarks to see if there are better default values. + */ + config->compression_level = 1; +#endif configfp = fopen(configfile, "r"); if (NULL == configfp) @@ -500,6 +507,32 @@ struct configuration_spec * load_config(void) config->confdir = make_path( NULL, arg); break; +/* ************************************************************************* + * compression-level 0-9 + * *************************************************************************/ +#ifdef FEATURE_COMPRESSION + case hash_compression_level : + if (*arg != '\0') + { + int compression_level = atoi(arg); + if (-1 <= compression_level && compression_level <= 9) + { + config->compression_level = compression_level;; + } + else + { + log_error(LOG_LEVEL_FATAL, + "Invalid compression-level value: %s", arg); + } + } + else + { + log_error(LOG_LEVEL_FATAL, + "Invalid compression-level directive. Compression value missing"); + } + break; +#endif + /* ************************************************************************* * connection-sharing (0|1) * *************************************************************************/ diff --git a/project.h b/project.h index cbd548a9..d524be0c 100644 --- a/project.h +++ b/project.h @@ -1,7 +1,7 @@ #ifndef PROJECT_H_INCLUDED #define PROJECT_H_INCLUDED /** Version string. */ -#define PROJECT_H_VERSION "$Id: project.h,v 1.165 2011/06/23 14:01:01 fabiankeil Exp $" +#define PROJECT_H_VERSION "$Id: project.h,v 1.167 2011/07/03 17:55:23 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/project.h,v $ @@ -1305,6 +1305,10 @@ struct configuration_spec unsigned int default_server_timeout; #endif +#ifdef FEATURE_COMPRESSION + int compression_level; +#endif + /** All options from the config file, HTML-formatted. */ char *proxy_args;