Browse Source

* refactor apply jail defaults (closes #12)

master
Alex 'AdUser' Z 4 years ago
parent
commit
d30a22ef3f
  1. 18
      src/jail.c
  2. 6
      src/jail.h

18
src/jail.c

@ -127,8 +127,6 @@ f2b_jail_set_param(f2b_jail_t *jail, const char *param, const char *value) {
void
f2b_jail_apply_config(f2b_jail_t *jail, f2b_config_section_t *section) {
char name[CONFIG_KEY_MAX];
char init[CONFIG_KEY_MAX];
f2b_config_param_t *param = NULL;
assert(jail != NULL);
@ -141,20 +139,17 @@ f2b_jail_apply_config(f2b_jail_t *jail, f2b_config_section_t *section) {
continue;
}
if (strcmp(param->name, "source") == 0) {
f2b_jail_parse_compound_value(param->value, name, init);
jail->source = f2b_source_create(name, init);
f2b_jail_parse_compound_value(param->value, jail->source_name, jail->source_init);
jail->flags |= JAIL_HAS_SOURCE;
continue;
}
if (strcmp(param->name, "filter") == 0) {
f2b_jail_parse_compound_value(param->value, name, init);
jail->filter = f2b_filter_create(name, init);
f2b_jail_parse_compound_value(param->value, jail->filter_name, jail->filter_init);
jail->flags |= JAIL_HAS_FILTER;
continue;
}
if (strcmp(param->name, "backend") == 0) {
f2b_jail_parse_compound_value(param->value, name, init);
jail->backend = f2b_backend_create(name, init);
f2b_jail_parse_compound_value(param->value, jail->backend_name, jail->backend_init);
jail->flags |= JAIL_HAS_BACKEND;
continue;
}
@ -269,6 +264,13 @@ f2b_jail_create(f2b_config_section_t *section) {
strlcpy(jail->name, section->name, sizeof(jail->name));
f2b_jail_apply_config(jail, section);
if (jail->flags & JAIL_HAS_SOURCE)
jail->source = f2b_source_create(jail->source_name, jail->source_init);
if (jail->flags & JAIL_HAS_FILTER)
jail->filter = f2b_filter_create(jail->filter_name, jail->filter_init);
if (jail->flags & JAIL_HAS_BACKEND)
jail->backend = f2b_backend_create(jail->backend_name, jail->backend_init);
return jail;
}

6
src/jail.h

@ -41,6 +41,12 @@ typedef struct f2b_jail_t {
unsigned int bans; /**< number of ban events */
unsigned int matches; /**< number of match events */
} stats;
char source_name[CONFIG_KEY_MAX];
char source_init[CONFIG_VAL_MAX];
char filter_name[CONFIG_KEY_MAX];
char filter_init[CONFIG_VAL_MAX];
char backend_name[CONFIG_KEY_MAX];
char backend_init[CONFIG_VAL_MAX];
f2b_source_t *source; /**< pointer to source */
f2b_filter_t *filter; /**< pointer to filter */
f2b_backend_t *backend; /**< pointer to backend */

Loading…
Cancel
Save