[asterisk-dev] common functions for int2string conversion
Luigi Rizzo
rizzo at icir.org
Mon Jul 16 09:34:26 CDT 2007
On Mon, Jul 16, 2007 at 04:13:55PM +0200, Klaus Darilion wrote:
> Hi!
>
> Are somewhere common functions for string/integer conversion defined?
i don't think there are. As a matter of fact i am working right now
on a common function to convert argument into int/sockaddr/port
numbers, with optional bounds checks and assignment of default
values, so that the parsing of config file options will be
simplified and made more consistent (and correct).
The interface should be something like this:
enum ast_parse_flags {
PARSE_TYPE = 0x000f, /* mask for argument type */
/* numeric types have optional bounds checks and default value */
PARSE_INT16 = 0x0001,
PARSE_INT32 = 0x0002,
PARSE_UINT16 = 0x0003,
PARSE_UINT32 = 0x0004,
PARSE_DOUBLE = 0x0005,
/* string have optional default value, malloc, regexp matching */
PARSE_STRING = 0x0006,
/* inaddr have optional default value and port
PARSE_INADDR = 0x0007,
/* next 8 bits are used for restrictions */
PARSE_DEFAULT = 0x0010, /* assign default on error */
/* applicable to numeric types */
PARSE_IN_RANGE = 0x0020, /* accept values inside a range */
PARSE_OUT_RANGE = 0x0040, /* accept values outside a range */
/* applicable to strings */
PARSE_STRING_MALLOC = 0x1000, /* malloc a buffer for the result */
PARSE_STRING_REGEXP = 0x2000, /* use regexp to match */
/* options to handle port numbers */
PARSE_PORT_MASK = 0x0300, /* 0x000: accept if present */
PARSE_PORT_IGNORE = 0x0100, /* 0x100: ignore if present */
PARSE_PORT_REQUIRE = 0x0200, /* 0x200: mandatory */
PARSE_PORT_FORBID = 0x0300, /* 0x100: forbidden */
};
int ast_parsearg(const char *arg, enum ast_parse_flags flags,
void *result, void *p_default, void *p_low, void *p_high)
cheers
luigi
More information about the asterisk-dev
mailing list