X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fconfigfile.c;h=1a957f67463f138c673cc5dd5f23ebcbabffa8c3;hb=4858a84e3e51830a103a5ff4aee6b844b708ce62;hp=53f3314a31113f628f57abe2dc9c7a8a4035281d;hpb=3f0d178e58251171272a643e1667abcb9946edce;p=collectd.git diff --git a/src/configfile.c b/src/configfile.c index 53f3314a..1a957f67 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -336,7 +336,15 @@ static int dispatch_block_plugin (oconfig_item_t *ci) if (ci->children[i].children == NULL) dispatch_value_plugin (name, ci->children + i); else - {DEBUG ("No nested config blocks allowed for this plugin.");} + { + WARNING ("There is a `%s' block within the " + "configuration for the %s plugin. " + "The plugin either only expects " + "\"simple\" configuration statements " + "or wasn't loaded using `LoadPlugin'." + " Please check your configuration.", + ci->children[i].key, name); + } } return (0); @@ -909,3 +917,43 @@ int cf_read (char *filename) return (0); } /* int cf_read */ + +/* 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) /* {{{ */ +{ + char *string; + + if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) + { + ERROR ("cf_util_get_string: The %s plugin requires " + "exactly one string argument.", ci->key); + return (-1); + } + + string = strdup (ci->values[0].value.string); + if (string == NULL) + return (-1); + + if (*ret_string != NULL) + sfree (*ret_string); + *ret_string = string; + + return (0); +} /* }}} int cf_util_get_string */ + +/* Assures that the config option is a string. The string is then converted to + * a port number using `service_name_to_port_number' and returned. Returns the + * port number in the range [1-65535] or less than zero upon failure. */ +int cf_util_get_port_number (const oconfig_item_t *ci) /* {{{ */ +{ + if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) + { + ERROR ("cf_util_get_port_number: The %s plugin requires " + "exactly one string argument.", ci->key); + return (-1); + } + + return (service_name_to_port_number (ci->values[0].value.string)); +} /* }}} int cf_util_get_port_number */