X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fconfigfile.c;h=1a957f67463f138c673cc5dd5f23ebcbabffa8c3;hb=7de4b3692af84751fab5ac46a5da7414346ea50b;hp=df04289446ccfba23d598d14e80c29ce5a5fa882;hpb=181a5bd7000bb378a04d4488adbc96c02d520426;p=collectd.git diff --git a/src/configfile.c b/src/configfile.c index df042894..1a957f67 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -942,3 +942,18 @@ int cf_util_get_string (const oconfig_item_t *ci, char **ret_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 */