summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a06c1a5)
raw | patch | inline | side by side (parent: a06c1a5)
author | Florian Forster <octo@huhu.verplant.org> | |
Tue, 25 Jan 2011 06:42:53 +0000 (07:42 +0100) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Tue, 25 Jan 2011 06:42:56 +0000 (07:42 +0100) |
Why force the user into using strings when it's not strictly
necessary..?
necessary..?
src/configfile.c | patch | blob | history | |
src/configfile.h | patch | blob | history |
diff --git a/src/configfile.c b/src/configfile.c
index 33a7c200dbb3fc95d57e1b731c4e2397a2cbcd61..54d418b4a6746a3b56a8be6895e50745e831eedb 100644 (file)
--- a/src/configfile.c
+++ b/src/configfile.c
return (0);
} /* }}} int cf_util_get_flag */
-/* 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. */
+/* Assures that the config option is a string or a number if the correct range
+ * of 1-65535. 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))
+ int tmp;
+
+ if ((ci->values_num != 1)
+ || ((ci->values[0].type != OCONFIG_TYPE_STRING)
+ && (ci->values[0].type != OCONFIG_TYPE_NUMBER)))
{
- ERROR ("cf_util_get_port_number: The %s option requires "
+ ERROR ("cf_util_get_port_number: The \"%s\" option requires "
"exactly one string argument.", ci->key);
return (-1);
}
- return (service_name_to_port_number (ci->values[0].value.string));
+ if (ci->values[0].type == OCONFIG_TYPE_STRING)
+ return (service_name_to_port_number (ci->values[0].value.string));
+
+ assert (ci->values[0].type == OCONFIG_TYPE_NUMBER);
+ tmp = (int) (ci->values[0].value.number + 0.5);
+ if ((tmp < 1) || (tmp > 65535))
+ {
+ ERROR ("cf_util_get_port_number: The \"%s\" option requires "
+ "a service name or a port number. The number "
+ "you specified, %i, is not in the valid "
+ "range of 1-65535.",
+ ci->key, tmp);
+ return (-1);
+ }
+
+ return (tmp);
} /* }}} int cf_util_get_port_number */
int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value) /* {{{ */
diff --git a/src/configfile.h b/src/configfile.h
index 65b1efcdd5a07d9a0d7fe7d50228470475bdb524..c381028ca5d96c7236f1b6684a4679e503e3b2fe 100644 (file)
--- a/src/configfile.h
+++ b/src/configfile.h
int cf_util_get_flag (const oconfig_item_t *ci,
unsigned int *ret_value, unsigned int flag);
-/* 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. */
+/* Assures that the config option is a string or a number if the correct range
+ * of 1-65535. 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);
int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value);