From 7d4a5abb1df3aefd47d3da34d4b7bd3f29f9ee96 Mon Sep 17 00:00:00 2001 From: Russell Bryant <russell@russellbryant.com> Date: Sun, 6 Nov 2005 21:00:35 +0000 Subject: [PATCH] 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 --- ChangeLog | 1 + apps/app_dial.c | 2 +- cdr.c | 12 +++++++----- include/asterisk/cdr.h | 3 ++- pbx.c | 40 +++++++++++++++++++++++++++------------- res/res_features.c | 6 +++--- 6 files changed, 41 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 061d07e79d..9c099bbe62 100755 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ * apps/app_externalivr.c: Add a space that fixes building on older versions of gcc * many files: Add doxygen updates to categorize modules into groups. Convert a lot of comments over to doxygen style. Add some text giving a basic overview of channels. * many files: Update applications to add an exit status variable, make priority jumping optional, and use new args parsing macros + * pbx.c cdr.c res/res_features.c apps/app_dial.c include/asterisk/cdr.h: 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. 2005-11-05 Kevin P. Fleming <kpfleming@digium.com> diff --git a/apps/app_dial.c b/apps/app_dial.c index f0e399ec9a..75b51299f0 100755 --- a/apps/app_dial.c +++ b/apps/app_dial.c @@ -828,7 +828,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags } if (ast_test_flag(&opts, OPT_RESETCDR) && chan->cdr) - ast_cdr_reset(chan->cdr, 0); + ast_cdr_reset(chan->cdr, NULL); if (ast_test_flag(&opts, OPT_PRIVACY) && ast_strlen_zero(opt_args[OPT_ARG_PRIVACY])) opt_args[OPT_ARG_PRIVACY] = ast_strdupa(chan->exten); if (ast_test_flag(&opts, OPT_PRIVACY) || ast_test_flag(&opts, OPT_SCREENING)) { diff --git a/cdr.c b/cdr.c index 03ff641287..c9f7ca3c9b 100755 --- a/cdr.c +++ b/cdr.c @@ -809,16 +809,18 @@ static void post_cdr(struct ast_cdr *cdr) } } -void ast_cdr_reset(struct ast_cdr *cdr, int flags) +void ast_cdr_reset(struct ast_cdr *cdr, struct ast_flags *_flags) { - struct ast_flags tmp = {flags}; struct ast_cdr *dup; + struct ast_flags flags = { 0 }; + if (_flags) + ast_copy_flags(&flags, _flags, AST_FLAGS_ALL); while (cdr) { /* Detach if post is requested */ - if (ast_test_flag(&tmp, AST_CDR_FLAG_LOCKED) || !ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) { - if (ast_test_flag(&tmp, AST_CDR_FLAG_POSTED)) { + if (ast_test_flag(&flags, AST_CDR_FLAG_LOCKED) || !ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) { + if (ast_test_flag(&flags, AST_CDR_FLAG_POSTED)) { ast_cdr_end(cdr); if ((dup = ast_cdr_dup(cdr))) { ast_cdr_detach(dup); @@ -827,7 +829,7 @@ void ast_cdr_reset(struct ast_cdr *cdr, int flags) } /* clear variables */ - if (!ast_test_flag(&tmp, AST_CDR_FLAG_KEEP_VARS)) { + if (!ast_test_flag(&flags, AST_CDR_FLAG_KEEP_VARS)) { ast_cdr_free_vars(cdr, 0); } diff --git a/include/asterisk/cdr.h b/include/asterisk/cdr.h index 2ca5671345..6598b3806b 100755 --- a/include/asterisk/cdr.h +++ b/include/asterisk/cdr.h @@ -45,6 +45,7 @@ /* Include channel.h after relevant declarations it will need */ #include "asterisk/channel.h" +#include "asterisk/utils.h" struct ast_channel; @@ -256,7 +257,7 @@ extern char *ast_cdr_disp2str(int disposition); * \param flags |AST_CDR_FLAG_POSTED whether or not to post the cdr first before resetting it * |AST_CDR_FLAG_LOCKED whether or not to reset locked CDR's */ -extern void ast_cdr_reset(struct ast_cdr *cdr, int flags); +extern void ast_cdr_reset(struct ast_cdr *cdr, struct ast_flags *flags); /*! Flags to a string */ /*! diff --git a/pbx.c b/pbx.c index 0d721e1368..6040aeeee8 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; } diff --git a/res/res_features.c b/res/res_features.c index 50a71fde1a..8e3be8d017 100755 --- a/res/res_features.c +++ b/res/res_features.c @@ -216,20 +216,20 @@ static struct ast_channel *ast_feature_request_and_dial(struct ast_channel *call static void *ast_bridge_call_thread(void *data) { struct ast_bridge_thread_obj *tobj = data; + tobj->chan->appl = "Transferred Call"; tobj->chan->data = tobj->peer->name; tobj->peer->appl = "Transferred Call"; tobj->peer->data = tobj->chan->name; if (tobj->chan->cdr) { - ast_cdr_reset(tobj->chan->cdr,0); + ast_cdr_reset(tobj->chan->cdr, NULL); ast_cdr_setdestchan(tobj->chan->cdr, tobj->peer->name); } if (tobj->peer->cdr) { - ast_cdr_reset(tobj->peer->cdr,0); + ast_cdr_reset(tobj->peer->cdr, NULL); ast_cdr_setdestchan(tobj->peer->cdr, tobj->chan->name); } - ast_bridge_call(tobj->peer, tobj->chan, &tobj->bconfig); ast_hangup(tobj->chan); ast_hangup(tobj->peer); -- GitLab