From: Florian Forster Date: Thu, 24 Sep 2009 15:38:02 +0000 (+0200) Subject: src/configfile.[ch]: Implement "cf_util_get_port_number". X-Git-Tag: collectd-4.9.0~73^2~32 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7de4b3692af84751fab5ac46a5da7414346ea50b;p=collectd.git src/configfile.[ch]: Implement "cf_util_get_port_number". --- 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 */ diff --git a/src/configfile.h b/src/configfile.h index aca58770..74d074ed 100644 --- a/src/configfile.h +++ b/src/configfile.h @@ -91,4 +91,9 @@ const char *global_option_get (const char *option); * success. */ int cf_util_get_string (const oconfig_item_t *ci, char **ret_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); + #endif /* defined(CONFIGFILE_H) */