[asterisk-commits] rizzo: trunk r93925 - in /trunk: include/asterisk/config.h main/config.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Dec 19 09:15:03 CST 2007
Author: rizzo
Date: Wed Dec 19 09:15:03 2007
New Revision: 93925
URL: http://svn.digium.com/view/asterisk?view=rev&rev=93925
Log:
add support for PARSE_DOUBLE, and remove identifiers for
types not supported (INT16 and UINT16)
Modified:
trunk/include/asterisk/config.h
trunk/main/config.c
Modified: trunk/include/asterisk/config.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/config.h?view=diff&rev=93925&r1=93924&r2=93925
==============================================================================
--- trunk/include/asterisk/config.h (original)
+++ trunk/include/asterisk/config.h Wed Dec 19 09:15:03 2007
@@ -289,15 +289,18 @@
/* numeric types, with optional default value and bound checks.
* Additional arguments are passed by value.
*/
- PARSE_INT16 = 0x0001,
- PARSE_INT32 = 0x0002,
- PARSE_UINT16 = 0x0003,
- PARSE_UINT32 = 0x0004,
+ PARSE_INT32 = 0x0001,
+ PARSE_UINT32 = 0x0002,
+ PARSE_DOUBLE = 0x0003,
+#if 0 /* not supported yet */
+ PARSE_INT16 = 0x0004,
+ PARSE_UINT16 = 0x0005,
+#endif
/* Returns a struct sockaddr_in, with optional default value
* (passed by reference) and port handling (accept, ignore,
* require, forbid). The format is 'host.name[:port]'
*/
- PARSE_INADDR = 0x0005,
+ PARSE_INADDR = 0x000f,
/* Other data types can be added as needed */
Modified: trunk/main/config.c
URL: http://svn.digium.com/view/asterisk/trunk/main/config.c?view=diff&rev=93925&r1=93924&r2=93925
==============================================================================
--- trunk/main/config.c (original)
+++ trunk/main/config.c Wed Dec 19 09:15:03 2007
@@ -34,6 +34,8 @@
#include "asterisk/network.h" /* we do some sockaddr manipulation here */
#include <time.h>
#include <sys/stat.h>
+
+#include <math.h> /* HUGE_VAL */
#define AST_INCLUDE_GLOB 1
@@ -2149,6 +2151,32 @@
break;
}
+ case PARSE_DOUBLE:
+ {
+ double *result = p_result;
+ double x, def = result ? *result : 0,
+ low = -HUGE_VAL, high = HUGE_VAL;
+
+ /* optional argument: first default value, then range */
+ if (flags & PARSE_DEFAULT)
+ def = va_arg(ap, double);
+ if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) {
+ /* range requested, update bounds */
+ low = va_arg(ap, double);
+ high = va_arg(ap, double);
+ }
+ x = strtod(arg, NULL);
+ error = (x < low) || (x > high);
+ if (flags & PARSE_OUT_RANGE)
+ error = !error;
+ if (result)
+ *result = error ? def : x;
+ ast_debug(3,
+ "extract double from [%s] in [%f, %f] gives [%f](%d)\n",
+ arg, low, high,
+ result ? *result : x, error);
+ break;
+ }
case PARSE_INADDR:
{
char *port, *buf;
More information about the asterisk-commits
mailing list