config: added options to change compression algorithm priorities

Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
This commit is contained in:
Nikos Mavrogiannopoulos
2018-04-15 17:05:49 +02:00
parent 2ae4c2b2ed
commit b1e3ff580f
3 changed files with 60 additions and 0 deletions

View File

@@ -564,6 +564,17 @@ struct ini_ctx_st {
void *pool;
};
#define WARN_ON_VHOST_ONLY(vname, oname) \
({int rval; \
if (vname) { \
fprintf(stderr, WARNSTR"%s is ignored on %s virtual host\n", oname, vname); \
rval = 1; \
} else { \
rval = 0; \
} \
rval; \
})
#define WARN_ON_VHOST(vname, oname, member) \
({int rval; \
if (vname) { \
@@ -854,6 +865,12 @@ static int cfg_ini_handler(void *_ctx, const char *section, const char *name, co
READ_TF(config->match_dtls_and_tls);
} else if (strcmp(name, "compression") == 0) {
READ_TF(config->enable_compression);
} else if (strcmp(name, "compression-algo-priority") == 0) {
if (!WARN_ON_VHOST_ONLY(vhost->name, "compression-algo-priority")) {
if (switch_comp_priority(pool, value) == 0) {
fprintf(stderr, WARNSTR"invalid compression modstring %s\n", value);
}
}
} else if (strcmp(name, "no-compress-limit") == 0) {
READ_NUMERIC(config->no_compress_limit);
} else if (strcmp(name, "use-seccomp") == 0) {

View File

@@ -432,6 +432,8 @@ void clear_old_configs(struct list_head *configs);
void write_pid_file(void);
void remove_pid_file(void);
unsigned switch_comp_priority(void *pool, const char *modstring);
extern sigset_t sig_default_set;
#endif

View File

@@ -163,6 +163,47 @@ struct compression_method_st comp_methods[] = {
};
#endif
unsigned switch_comp_priority(void *pool, const char *modstring)
{
unsigned i, ret;
char *token, *str;
const char *algo = NULL;
long priority = -1;
str = talloc_strdup(pool, modstring);
if (!str)
return 0;
token = str;
token = strtok(token, ":");
algo = token;
token = strtok(NULL, ":");
if (token)
priority = strtol(token, NULL, 10);
if (algo == NULL || priority <= 0) {
ret = 0;
goto finish;
}
for (i = 0;
i < sizeof(comp_methods) / sizeof(comp_methods[0]);
i++) {
if (c_strcasecmp(algo, comp_methods[i].name) == 0) {
comp_methods[i].server_prio = priority;
ret = 1;
goto finish;
}
}
ret = 0;
finish:
talloc_free(str);
return ret;
}
static
void header_value_check(struct worker_st *ws, struct http_req_st *req)
{