summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f394c08)
raw | patch | inline | side by side (parent: f394c08)
author | Florian Forster <octo@collectd.org> | |
Mon, 6 Feb 2012 10:49:59 +0000 (11:49 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 6 Feb 2012 10:49:59 +0000 (11:49 +0100) |
Change-Id: I310c0d076a82927958fba04dd9eedbc706742dce
src/configfile.c | patch | blob | history | |
src/configfile.h | patch | blob | history |
diff --git a/src/configfile.c b/src/configfile.c
index 7c8347b15b20a1aa8d73011a1255105f5937035e..4fe50cc2e11ee71a00dcd53bd843460cf68a5973 100644 (file)
--- a/src/configfile.c
+++ b/src/configfile.c
return (tmp);
} /* }}} int cf_util_get_port_number */
+int cf_util_get_service (const oconfig_item_t *ci, char **ret_string) /* {{{ */
+{
+ int port;
+ char *service;
+ int status;
+
+ if (ci->values_num != 1)
+ {
+ ERROR ("cf_util_get_service: 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)
+ {
+ ERROR ("cf_util_get_service: The %s option requires "
+ "exactly one string or numeric argument.",
+ ci->key);
+ }
+
+ port = 0;
+ status = cf_util_get_int (ci, &port);
+ if (status != 0)
+ return (status);
+ else if ((port < 1) || (port > 65535))
+ {
+ ERROR ("cf_util_get_service: The port number given "
+ "for the %s option is out of "
+ "range (%i).", ci->key, port);
+ return (-1);
+ }
+
+ service = malloc (6);
+ if (service == NULL)
+ {
+ ERROR ("cf_util_get_service: Out of memory.");
+ return (-1);
+ }
+ ssnprintf (service, 6, "%i", port);
+
+ sfree (*ret_string);
+ *ret_string = service;
+
+ return (0);
+} /* }}} int cf_util_get_service */
+
int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value) /* {{{ */
{
if ((ci == NULL) || (ret_value == NULL))
diff --git a/src/configfile.h b/src/configfile.h
index e63a0ea047533257bde40be867bc0394060a884f..fbeafff8b956b01451b3fc714ec3107305ca1577 100644 (file)
--- a/src/configfile.h
+++ b/src/configfile.h
* failure. */
int cf_util_get_port_number (const oconfig_item_t *ci);
+/* Assures that the config option is either a service name (a string) or a port
+ * number (an integer in the appropriate range) and returns a newly allocated
+ * string. If ret_string points to a non-NULL pointer, it is freed before
+ * assigning a new value. */
+int cf_util_get_service (const oconfig_item_t *ci, char **ret_string);
+
int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value);
#endif /* defined(CONFIGFILE_H) */