Convert some built-in applications to use new args parsing macros.
authorRussell Bryant <russell@russellbryant.com>
Sun, 6 Nov 2005 21:00:35 +0000 (21:00 +0000)
committerRussell Bryant <russell@russellbryant.com>
Sun, 6 Nov 2005 21:00:35 +0000 (21:00 +0000)
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
apps/app_dial.c
cdr.c
include/asterisk/cdr.h
pbx.c
res/res_features.c

index 061d07e..9c099bb 100755 (executable)
--- 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
        * 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>
 
 
 2005-11-05  Kevin P. Fleming  <kpfleming@digium.com>
 
index f0e399e..75b5129 100755 (executable)
@@ -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)
        }
 
        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)) {
        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 03ff641..c9f7ca3 100755 (executable)
--- 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_cdr *dup;
+       struct ast_flags flags = { 0 };
 
 
+       if (_flags)
+               ast_copy_flags(&flags, _flags, AST_FLAGS_ALL);
 
        while (cdr) {
                /* Detach if post is requested */
 
        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);
                                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 */
                        }
 
                        /* 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);
                        }
 
                                ast_cdr_free_vars(cdr, 0);
                        }
 
index 2ca5671..6598b38 100755 (executable)
@@ -45,6 +45,7 @@
 
 /* Include channel.h after relevant declarations it will need */
 #include "asterisk/channel.h"
 
 /* Include channel.h after relevant declarations it will need */
 #include "asterisk/channel.h"
+#include "asterisk/utils.h"
 
 struct ast_channel;
 
 
 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
  */
  * \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 */
 /*!
 
 /*! Flags to a string */
 /*!
diff --git a/pbx.c b/pbx.c
index 0d721e1..6040aee 100755 (executable)
--- 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)
 {
 
 static int pbx_builtin_answer(struct ast_channel *chan, void *data)
 {
-       int delay = atoi(data);
+       int delay = 0;
        int res;
        int res;
+
        if (chan->_state == AST_STATE_UP)
                delay = 0;
        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;
        res = ast_answer(chan);
        if (res)
                return res;
+
        if (delay)
                res = ast_safe_sleep(chan, delay);
        if (delay)
                res = ast_safe_sleep(chan, delay);
+
        return res;
 }
 
        return res;
 }
 
@@ -5427,26 +5433,34 @@ static int pbx_builtin_setlanguage(struct ast_channel *chan, void *data)
        }
 
        /* Copy the language as specified */
        }
 
        /* 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;
 }
 
 
        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)
 {
 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;
 }
 
        return 0;
 }
 
index 50a71fd..8e3be8d 100755 (executable)
@@ -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;
 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) {
        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_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_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);
        ast_bridge_call(tobj->peer, tobj->chan, &tobj->bconfig);
        ast_hangup(tobj->chan);
        ast_hangup(tobj->peer);