From 7de4b3692af84751fab5ac46a5da7414346ea50b Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 24 Sep 2009 17:38:02 +0200 Subject: [PATCH] src/configfile.[ch]: Implement "cf_util_get_port_number". --- src/configfile.c | 15 +++++++++++++++ src/configfile.h | 5 +++++ 2 files changed, 20 insertions(+) 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) */ -- 2.11.0