From 7d4a5abb1df3aefd47d3da34d4b7bd3f29f9ee96 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Sun, 6 Nov 2005 21:00:35 +0000 Subject: Convert some built-in applications to use new args parsing macros. Change ast_cdr_reset to take a pointer to an ast_flags structure instead of an integer for flags. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6987 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- pbx.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'pbx.c') diff --git a/pbx.c b/pbx.c index 0d721e136..6040aeeee 100755 --- a/pbx.c +++ b/pbx.c @@ -5405,15 +5405,21 @@ static int pbx_builtin_congestion(struct ast_channel *chan, void *data) static int pbx_builtin_answer(struct ast_channel *chan, void *data) { - int delay = atoi(data); + int delay = 0; int res; + if (chan->_state == AST_STATE_UP) delay = 0; + else if (!ast_strlen_zero(data)) + delay = atoi(data); + res = ast_answer(chan); if (res) return res; + if (delay) res = ast_safe_sleep(chan, delay); + return res; } @@ -5427,26 +5433,34 @@ static int pbx_builtin_setlanguage(struct ast_channel *chan, void *data) } /* Copy the language as specified */ - if (data) - ast_copy_string(chan->language, (char *) data, sizeof(chan->language)); + if (!ast_strlen_zero(data)) + ast_copy_string(chan->language, data, sizeof(chan->language)); return 0; } +AST_APP_OPTIONS(resetcdr_opts, { + AST_APP_OPTION('w', AST_CDR_FLAG_POSTED), + AST_APP_OPTION('a', AST_CDR_FLAG_LOCKED), + AST_APP_OPTION('v', AST_CDR_FLAG_KEEP_VARS), +}); + static int pbx_builtin_resetcdr(struct ast_channel *chan, void *data) { - int flags = 0; - /* Reset the CDR as specified */ - if(data) { - if(strchr((char *)data, 'w')) - flags |= AST_CDR_FLAG_POSTED; - if(strchr((char *)data, 'a')) - flags |= AST_CDR_FLAG_LOCKED; - if(strchr((char *)data, 'v')) - flags |= AST_CDR_FLAG_KEEP_VARS; + char *args; + struct ast_flags flags = { 0 }; + + if (!ast_strlen_zero(data)) { + args = ast_strdupa(data); + if (!args) { + ast_log(LOG_ERROR, "Out of memory!\n"); + return -1; + } + ast_app_parse_options(resetcdr_opts, &flags, NULL, args); } - ast_cdr_reset(chan->cdr, flags); + ast_cdr_reset(chan->cdr, &flags); + return 0; } -- cgit v1.2.3