MEDIUM: compression: move the zlib-specific stuff from global.h to compression.c
This finishes to clean up the zlib-specific parts. It also unbreaks recent
commit b97c6fb ("CLEANUP: compression: use the build options list to report
the algos") which broke USE_ZLIB due to MAXWBITS not being defined anymore
in haproxy.c.
diff --git a/include/types/global.h b/include/types/global.h
index 9d71eca..0b6d439 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -156,10 +156,6 @@
unsigned int ssl_default_dh_param; /* SSL maximum DH parameter size */
int ssl_ctx_cache; /* max number of entries in the ssl_ctx cache. */
#endif
-#ifdef USE_ZLIB
- int zlibmemlevel; /* zlib memlevel */
- int zlibwindowsize; /* zlib window size */
-#endif
int comp_maxlevel; /* max HTTP compression level */
unsigned short idle_timer; /* how long before an empty buffer is considered idle (ms) */
} tune;
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 3ed2c22..e9876f8 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -901,54 +901,6 @@
}
global.tune.max_http_hdr = atol(args[1]);
}
- else if (!strcmp(args[0], "tune.zlib.memlevel")) {
-#ifdef USE_ZLIB
- if (alertif_too_many_args(1, file, linenum, args, &err_code))
- goto out;
- if (*args[1]) {
- global.tune.zlibmemlevel = atoi(args[1]);
- if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) {
- Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
- file, linenum, args[0]);
- err_code |= ERR_ALERT | ERR_FATAL;
- goto out;
- }
- } else {
- Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
- file, linenum, args[0]);
- err_code |= ERR_ALERT | ERR_FATAL;
- goto out;
- }
-#else
- Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]);
- err_code |= ERR_ALERT | ERR_FATAL;
- goto out;
-#endif
- }
- else if (!strcmp(args[0], "tune.zlib.windowsize")) {
-#ifdef USE_ZLIB
- if (alertif_too_many_args(1, file, linenum, args, &err_code))
- goto out;
- if (*args[1]) {
- global.tune.zlibwindowsize = atoi(args[1]);
- if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) {
- Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n",
- file, linenum, args[0]);
- err_code |= ERR_ALERT | ERR_FATAL;
- goto out;
- }
- } else {
- Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n",
- file, linenum, args[0]);
- err_code |= ERR_ALERT | ERR_FATAL;
- goto out;
- }
-#else
- Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]);
- err_code |= ERR_ALERT | ERR_FATAL;
- goto out;
-#endif
- }
else if (!strcmp(args[0], "tune.comp.maxlevel")) {
if (alertif_too_many_args(1, file, linenum, args, &err_code))
goto out;
diff --git a/src/compression.c b/src/compression.c
index 4ce26ec..27ab7f7 100644
--- a/src/compression.c
+++ b/src/compression.c
@@ -26,6 +26,7 @@
#undef free_func
#endif /* USE_ZLIB */
+#include <common/cfgparse.h>
#include <common/compat.h>
#include <common/memory.h>
@@ -53,6 +54,9 @@
long zlib_used_memory = 0;
+static int global_tune_zlibmemlevel = 8; /* zlib memlevel */
+static int global_tune_zlibwindowsize = MAX_WBITS; /* zlib window size */
+
#endif
unsigned int compress_min_idle = 0;
@@ -479,7 +483,7 @@
strm = &(*comp_ctx)->strm;
- if (deflateInit2(strm, level, Z_DEFLATED, global.tune.zlibwindowsize + 16, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
+ if (deflateInit2(strm, level, Z_DEFLATED, global_tune_zlibwindowsize + 16, global_tune_zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
deinit_comp_ctx(comp_ctx);
return -1;
}
@@ -499,7 +503,7 @@
strm = &(*comp_ctx)->strm;
- if (deflateInit2(strm, level, Z_DEFLATED, -global.tune.zlibwindowsize, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
+ if (deflateInit2(strm, level, Z_DEFLATED, -global_tune_zlibwindowsize, global_tune_zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
deinit_comp_ctx(comp_ctx);
return -1;
}
@@ -521,7 +525,7 @@
strm = &(*comp_ctx)->strm;
- if (deflateInit2(strm, level, Z_DEFLATED, global.tune.zlibwindowsize, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
+ if (deflateInit2(strm, level, Z_DEFLATED, global_tune_zlibwindowsize, global_tune_zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
deinit_comp_ctx(comp_ctx);
return -1;
}
@@ -619,8 +623,61 @@
return ret;
}
+/* config parser for global "tune.zlibmemlevel" */
+static int zlib_parse_global_memlevel(char **args, int section_type, struct proxy *curpx,
+ struct proxy *defpx, const char *file, int line,
+ char **err)
+{
+ if (too_many_args(1, args, err, NULL))
+ return -1;
+
+ if (*(args[1]) == 0) {
+ memprintf(err, "'%s' expects a numeric value between 1 and 9.", args[0]);
+ return -1;
+ }
+
+ global_tune_zlibmemlevel = atoi(args[1]);
+ if (global_tune_zlibmemlevel < 1 || global_tune_zlibmemlevel > 9) {
+ memprintf(err, "'%s' expects a numeric value between 1 and 9.", args[0]);
+ return -1;
+ }
+ return 0;
+}
+
+
+/* config parser for global "tune.zlibwindowsize" */
+static int zlib_parse_global_windowsize(char **args, int section_type, struct proxy *curpx,
+ struct proxy *defpx, const char *file, int line,
+ char **err)
+{
+ if (too_many_args(1, args, err, NULL))
+ return -1;
+
+ if (*(args[1]) == 0) {
+ memprintf(err, "'%s' expects a numeric value between 8 and 15.", args[0]);
+ return -1;
+ }
+
+ global_tune_zlibwindowsize = atoi(args[1]);
+ if (global_tune_zlibwindowsize < 8 || global_tune_zlibwindowsize > 15) {
+ memprintf(err, "'%s' expects a numeric value between 8 and 15.", args[0]);
+ return -1;
+ }
+ return 0;
+}
+
#endif /* USE_ZLIB */
+
+/* config keyword parsers */
+static struct cfg_kw_list cfg_kws = {ILH, {
+#ifdef USE_ZLIB
+ { CFG_GLOBAL, "tune.zlib.memlevel", zlib_parse_global_memlevel },
+ { CFG_GLOBAL, "tune.zlib.windowsize", zlib_parse_global_windowsize },
+#endif
+ { 0, NULL, NULL }
+}};
+
__attribute__((constructor))
static void __comp_fetch_init(void)
{
@@ -631,6 +688,9 @@
slz_make_crc_table();
slz_prepare_dist_table();
#endif
+#if defined(USE_ZLIB) && defined(DEFAULT_MAXZLIBMEM)
+ global.tune.maxzlibmem = DEFAULT_MAXZLIBMEM * 1024U * 1024U,
+#endif
#ifdef USE_ZLIB
memprintf(&ptr, "Built with zlib version : " ZLIB_VERSION);
memprintf(&ptr, "%s\nRunning on zlib version : %s", ptr, zlibVersion());
@@ -646,4 +706,5 @@
memprintf(&ptr, "%s none", ptr);
hap_register_build_opts(ptr, 1);
+ cfg_register_keywords(&cfg_kws);
}
diff --git a/src/haproxy.c b/src/haproxy.c
index 239db80..ef846fe 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -123,11 +123,7 @@
.nbproc = 1,
.req_count = 0,
.logsrvs = LIST_HEAD_INIT(global.logsrvs),
-#if defined(USE_ZLIB) && defined(DEFAULT_MAXZLIBMEM)
- .maxzlibmem = DEFAULT_MAXZLIBMEM * 1024U * 1024U,
-#else
.maxzlibmem = 0,
-#endif
.comp_rate_lim = 0,
.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED,
.unix_bind = {
@@ -151,10 +147,6 @@
#endif
.ssl_ctx_cache = DEFAULT_SSL_CTX_CACHE,
#endif
-#ifdef USE_ZLIB
- .zlibmemlevel = 8,
- .zlibwindowsize = MAX_WBITS,
-#endif
.comp_maxlevel = 1,
#ifdef DEFAULT_IDLE_TIMER
.idle_timer = DEFAULT_IDLE_TIMER,