#include "collectd.h"
-#include "common.h"
#include "configfile.h"
#include "filter_chain.h"
#include "plugin.h"
+#include "utils/common/common.h"
#include "utils_complain.h"
/*
char *dest;
if (orig == NULL)
- return (NULL);
+ return NULL;
sz = strlen(orig) + 1;
dest = malloc(sz);
if (dest == NULL)
- return (NULL);
+ return NULL;
memcpy(dest, orig, sz);
- return (dest);
+ return dest;
} /* }}} char *fc_strdup */
/*
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("Filter subsystem: `Match' blocks require "
"exactly one string argument.");
- return (-1);
+ return -1;
}
ptr = match_list_head;
WARNING("Filter subsystem: Cannot find a \"%s\" match. "
"Did you load the appropriate plugin?",
ci->values[0].value.string);
- return (-1);
+ return -1;
}
m = calloc(1, sizeof(*m));
if (m == NULL) {
ERROR("fc_config_add_match: calloc failed.");
- return (-1);
+ return -1;
}
sstrncpy(m->name, ptr->name, sizeof(m->name));
if (status != 0) {
WARNING("Filter subsystem: Failed to create a %s match.", m->name);
fc_free_matches(m);
- return (-1);
+ return -1;
}
}
*matches_head = m;
}
- return (0);
+ return 0;
} /* }}} int fc_config_add_match */
static int fc_config_add_target(fc_target_t **targets_head, /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("Filter subsystem: `Target' blocks require "
"exactly one string argument.");
- return (-1);
+ return -1;
}
ptr = target_list_head;
WARNING("Filter subsystem: Cannot find a \"%s\" target. "
"Did you load the appropriate plugin?",
ci->values[0].value.string);
- return (-1);
+ return -1;
}
t = calloc(1, sizeof(*t));
if (t == NULL) {
ERROR("fc_config_add_target: calloc failed.");
- return (-1);
+ return -1;
}
sstrncpy(t->name, ptr->name, sizeof(t->name));
if (status != 0) {
WARNING("Filter subsystem: Failed to create a %s target.", t->name);
fc_free_targets(t);
- return (-1);
+ return -1;
}
} else {
t->user_data = NULL;
*targets_head = t;
}
- return (0);
+ return 0;
} /* }}} int fc_config_add_target */
static int fc_config_add_rule(fc_chain_t *chain, /* {{{ */
if (ci->values_num > 1) {
WARNING("Filter subsystem: `Rule' blocks have at most one argument.");
- return (-1);
+ return -1;
} else if ((ci->values_num == 1) &&
(ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("Filter subsystem: `Rule' blocks expect one string argument "
"or no argument at all.");
- return (-1);
+ return -1;
}
rule = calloc(1, sizeof(*rule));
if (rule == NULL) {
ERROR("fc_config_add_rule: calloc failed.");
- return (-1);
+ return -1;
}
if (ci->values_num == 1) {
sstrncpy(rule->name, ci->values[0].value.string, sizeof(rule->name));
- ssnprintf(rule_name, sizeof(rule_name), "Rule \"%s\"",
- ci->values[0].value.string);
+ snprintf(rule_name, sizeof(rule_name), "Rule \"%s\"",
+ ci->values[0].value.string);
}
for (int i = 0; i < ci->children_num; i++) {
if (status != 0) {
fc_free_rules(rule);
- return (-1);
+ return -1;
}
if (chain->rules != NULL) {
chain->rules = rule;
}
- return (0);
+ return 0;
} /* }}} int fc_config_add_rule */
static int fc_config_add_chain(const oconfig_item_t *ci) /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("Filter subsystem: <Chain> blocks require exactly one "
"string argument.");
- return (-1);
+ return -1;
}
if (chain_list_head != NULL) {
chain = calloc(1, sizeof(*chain));
if (chain == NULL) {
ERROR("fc_config_add_chain: calloc failed.");
- return (-1);
+ return -1;
}
sstrncpy(chain->name, ci->values[0].value.string, sizeof(chain->name));
}
if (status != 0) {
fc_free_chains(chain);
- return (-1);
+ return -1;
}
if (chain_list_head != NULL) {
if (!new_chain)
- return (0);
+ return 0;
fc_chain_t *ptr;
chain_list_head = chain;
}
- return (0);
+ return 0;
} /* }}} int fc_config_add_chain */
/*
if (ci->children_num != 1) {
ERROR("Filter subsystem: The built-in target `jump' needs exactly "
"one `Chain' argument!");
- return (-1);
+ return -1;
}
ci_chain = ci->children;
ERROR("Filter subsystem: The built-in target `jump' does not "
"support the configuration option `%s'.",
ci_chain->key);
- return (-1);
+ return -1;
}
if ((ci_chain->values_num != 1) ||
(ci_chain->values[0].type != OCONFIG_TYPE_STRING)) {
ERROR("Filter subsystem: Built-in target `jump': The `Chain' option "
"needs exactly one string argument.");
- return (-1);
+ return -1;
}
*user_data = fc_strdup(ci_chain->values[0].value.string);
if (*user_data == NULL) {
ERROR("fc_bit_jump_create: fc_strdup failed.");
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
} /* }}} int fc_bit_jump_create */
static int fc_bit_jump_destroy(void **user_data) /* {{{ */
*user_data = NULL;
}
- return (0);
+ return 0;
} /* }}} int fc_bit_jump_destroy */
static int fc_bit_jump_invoke(const data_set_t *ds, /* {{{ */
ERROR("Filter subsystem: Built-in target `jump': There is no chain "
"named `%s'.",
chain_name);
- return (-1);
+ return -1;
}
status = fc_process_chain(ds, vl, chain);
if (status < 0)
- return (status);
+ return status;
else if (status == FC_TARGET_STOP)
- return (FC_TARGET_STOP);
+ return FC_TARGET_STOP;
else
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
} /* }}} int fc_bit_jump_invoke */
static int
value_list_t __attribute__((unused)) * vl,
notification_meta_t __attribute__((unused)) * *meta,
void __attribute__((unused)) * *user_data) {
- return (FC_TARGET_STOP);
+ return FC_TARGET_STOP;
} /* }}} int fc_bit_stop_invoke */
static int
value_list_t __attribute__((unused)) * vl,
notification_meta_t __attribute__((unused)) * *meta,
void __attribute__((unused)) * *user_data) {
- return (FC_TARGET_RETURN);
+ return FC_TARGET_RETURN;
} /* }}} int fc_bit_return_invoke */
static int fc_bit_write_create(const oconfig_item_t *ci, /* {{{ */
*user_data = plugin_list;
- return (0);
+ return 0;
} /* }}} int fc_bit_write_create */
static int fc_bit_write_destroy(void **user_data) /* {{{ */
fc_writer_t *plugin_list;
if ((user_data == NULL) || (*user_data == NULL))
- return (0);
+ return 0;
plugin_list = *user_data;
free(plugin_list[i].plugin);
free(plugin_list);
- return (0);
+ return 0;
} /* }}} int fc_bit_write_destroy */
static int fc_bit_write_invoke(const data_set_t *ds, /* {{{ */
} /* for (i = 0; plugin_list[i] != NULL; i++) */
}
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
} /* }}} int fc_bit_write_invoke */
static int fc_init_once(void) /* {{{ */
{
- static int done = 0;
+ static int done;
target_proc_t tproc = {0};
if (done != 0)
- return (0);
+ return 0;
tproc.create = fc_bit_jump_create;
tproc.destroy = fc_bit_jump_destroy;
fc_register_target("write", tproc);
done++;
- return (0);
+ return 0;
} /* }}} int fc_init_once */
/*
m = calloc(1, sizeof(*m));
if (m == NULL)
- return (-ENOMEM);
+ return -ENOMEM;
sstrncpy(m->name, name, sizeof(m->name));
memcpy(&m->proc, &proc, sizeof(m->proc));
ptr->next = m;
}
- return (0);
+ return 0;
} /* }}} int fc_register_match */
/* Add a target to list of available targets. */
t = calloc(1, sizeof(*t));
if (t == NULL)
- return (-ENOMEM);
+ return -ENOMEM;
sstrncpy(t->name, name, sizeof(t->name));
memcpy(&t->proc, &proc, sizeof(t->proc));
ptr->next = t;
}
- return (0);
+ return 0;
} /* }}} int fc_register_target */
fc_chain_t *fc_chain_get_by_name(const char *chain_name) /* {{{ */
{
if (chain_name == NULL)
- return (NULL);
+ return NULL;
for (fc_chain_t *chain = chain_list_head; chain != NULL; chain = chain->next)
if (strcasecmp(chain_name, chain->name) == 0)
- return (chain);
+ return chain;
- return (NULL);
+ return NULL;
} /* }}} int fc_chain_get_by_name */
int fc_process_chain(const data_set_t *ds, value_list_t *vl, /* {{{ */
int status = FC_TARGET_CONTINUE;
if (chain == NULL)
- return (-1);
+ return -1;
DEBUG("fc_process_chain (chain = %s);", chain->name);
} /* for (rule) */
if ((status == FC_TARGET_STOP) || (status == FC_TARGET_RETURN))
- return (status);
+ return status;
DEBUG("fc_process_chain (%s): Executing the default targets.", chain->name);
chain->name, target->name,
(status == FC_TARGET_STOP) ? "stop" : "return");
if (status == FC_TARGET_STOP)
- return (FC_TARGET_STOP);
+ return FC_TARGET_STOP;
else
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
}
DEBUG("fc_process_chain (%s): Signaling `continue' at end of chain.",
chain->name);
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
} /* }}} int fc_process_chain */
/* Iterate over all rules in the chain and execute all targets for which all
int fc_default_action(const data_set_t *ds, value_list_t *vl) /* {{{ */
{
/* FIXME: Pass the meta-data to match targets here (when implemented). */
- return (fc_bit_write_invoke(ds, vl,
- /* meta = */ NULL, /* user_data = */ NULL));
+ return fc_bit_write_invoke(ds, vl, NULL, NULL);
} /* }}} int fc_default_action */
int fc_configure(const oconfig_item_t *ci) /* {{{ */
fc_init_once();
if (ci == NULL)
- return (-EINVAL);
+ return -EINVAL;
if (strcasecmp("Chain", ci->key) == 0)
- return (fc_config_add_chain(ci));
+ return fc_config_add_chain(ci);
WARNING("Filter subsystem: Unknown top level config option `%s'.", ci->key);
- return (-1);
+ return -1;
} /* }}} int fc_configure */