} /* int cf_read */
-void cf_log(int level, const char *format, ...) {
- char msg[1024] = ""; // Size inherits from plugin_log()
-
- char const *name = plugin_get_ctx().name;
-
- va_list ap;
- va_start(ap, format);
- vsnprintf(msg, sizeof(msg), format, ap);
- va_end(ap);
-
- plugin_log(level, "%s plugin: %s", name, msg);
-} /* void cf_log */
-
-#define CF_ERROR(...) cf_log(LOG_ERR, __VA_ARGS__)
-#define CF_WARNING(...) cf_log(LOG_WARNING, __VA_ARGS__)
-
/* Assures the config option is a string, duplicates it and returns the copy in
* "ret_string". If necessary "*ret_string" is freed first. Returns zero upon
* success. */
int cf_util_get_string(const oconfig_item_t *ci, char **ret_string) /* {{{ */
{
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
- CF_ERROR("The `%s' option requires exactly one string argument.", ci->key);
+ P_ERROR("The `%s' option requires exactly one string argument.", ci->key);
return -1;
}
return EINVAL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
- CF_ERROR("The `%s' option requires exactly one string argument.", ci->key);
+ P_ERROR("The `%s' option requires exactly one string argument.", ci->key);
return -1;
}
return EINVAL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
- CF_ERROR("The `%s' option requires exactly one numeric argument.", ci->key);
+ P_ERROR("The `%s' option requires exactly one numeric argument.", ci->key);
return -1;
}
return EINVAL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
- CF_ERROR("The `%s' option requires exactly one numeric argument.", ci->key);
+ P_ERROR("The `%s' option requires exactly one numeric argument.", ci->key);
return -1;
}
if ((ci->values_num != 1) || ((ci->values[0].type != OCONFIG_TYPE_BOOLEAN) &&
(ci->values[0].type != OCONFIG_TYPE_STRING))) {
- CF_ERROR("The `%s' option requires exactly one boolean argument.", ci->key);
+ P_ERROR("The `%s' option requires exactly one boolean argument.", ci->key);
return -1;
}
*ret_bool = ci->values[0].value.boolean ? true : false;
break;
case OCONFIG_TYPE_STRING:
- CF_WARNING("Using string value `%s' for boolean option `%s' is deprecated "
- "and will be removed in future releases. Use unquoted true or "
- "false instead.",
- ci->values[0].value.string, ci->key);
+ P_WARNING("Using string value `%s' for boolean option `%s' is deprecated "
+ "and will be removed in future releases. Use unquoted true or "
+ "false instead.",
+ ci->values[0].value.string, ci->key);
if (IS_TRUE(ci->values[0].value.string))
*ret_bool = true;
else if (IS_FALSE(ci->values[0].value.string))
*ret_bool = false;
else {
- CF_ERROR("Cannot parse string value `%s' of the `%s' option as a boolean "
- "value.",
- ci->values[0].value.string, ci->key);
+ P_ERROR("Cannot parse string value `%s' of the `%s' option as a boolean "
+ "value.",
+ ci->values[0].value.string, ci->key);
return -1;
}
break;
if ((ci->values_num != 1) || ((ci->values[0].type != OCONFIG_TYPE_STRING) &&
(ci->values[0].type != OCONFIG_TYPE_NUMBER))) {
- CF_ERROR("The `%s' option requires exactly one string argument.", ci->key);
+ P_ERROR("The `%s' option requires exactly one string argument.", ci->key);
return -1;
}
assert(ci->values[0].type == OCONFIG_TYPE_NUMBER);
tmp = (int)(ci->values[0].value.number + 0.5);
if ((tmp < 1) || (tmp > 65535)) {
- CF_ERROR("The `%s' option requires a service name or a port number. The "
- "number you specified, %i, is not in the valid range of 1-65535.",
- ci->key, tmp);
+ P_ERROR("The `%s' option requires a service name or a port number. The "
+ "number you specified, %i, is not in the valid range of 1-65535.",
+ ci->key, tmp);
return -1;
}
int status;
if (ci->values_num != 1) {
- CF_ERROR("The `%s` option requires exactly one argument.", ci->key);
+ P_ERROR("The `%s` option requires exactly one argument.", ci->key);
return -1;
}
if (ci->values[0].type == OCONFIG_TYPE_STRING)
return cf_util_get_string(ci, ret_string);
if (ci->values[0].type != OCONFIG_TYPE_NUMBER) {
- CF_ERROR("The `%s` option requires exactly one string or numeric argument.",
- ci->key);
+ P_ERROR("The `%s` option requires exactly one string or numeric argument.",
+ ci->key);
}
port = 0;
if (status != 0)
return status;
else if ((port < 1) || (port > 65535)) {
- CF_ERROR("The port number given for the `%s` option is out of range (%i).",
- ci->key, port);
+ P_ERROR("The port number given for the `%s` option is out of range (%i).",
+ ci->key, port);
return -1;
}
service = malloc(6);
if (service == NULL) {
- CF_ERROR("cf_util_get_service: Out of memory.");
+ P_ERROR("cf_util_get_service: Out of memory.");
return -1;
}
snprintf(service, 6, "%i", port);
return EINVAL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
- CF_ERROR("The `%s' option requires exactly one numeric argument.", ci->key);
+ P_ERROR("The `%s' option requires exactly one numeric argument.", ci->key);
return -1;
}
if (ci->values[0].value.number < 0.0) {
- CF_ERROR("The numeric argument of the `%s' option must not be negative.",
- ci->key);
+ P_ERROR("The numeric argument of the `%s' option must not be negative.",
+ ci->key);
return -1;
}