diff options
author | murf <murf@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-05-29 04:11:53 +0000 |
---|---|---|
committer | murf <murf@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-05-29 04:11:53 +0000 |
commit | c16d6c9c1b2ddb789f7a65854f6c212197a9b5ef (patch) | |
tree | 192db2b19d322008a70a266fd4bbff723e66febd /apps | |
parent | d63ce6eba05e5d5bd51566ae3a2b725c2c504484 (diff) |
Merged revisions 118880 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r118880 | murf | 2008-05-28 19:29:09 -0600 (Wed, 28 May 2008) | 54 lines
Merged revisions 118858 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r118858 | murf | 2008-05-28 18:25:28 -0600 (Wed, 28 May 2008) | 46 lines
(closes issue #10668)
(closes issue #11721)
(closes issue #12726)
Reported by: arkadia
Tested by: murf
These changes:
1. revert the changes made via bug 10668;
I should have known that such changes,
even tho they made sense at the time,
seemed like an omission, etc, were actually
integral to the CDR system via forkCDR.
It makes sense to me now that forkCDR didn't
natively end any CDR's, but rather depended
on natively closing them all at hangup time
via traversing and closing them all, whether
locked or not. I still don't completely
understand the benefits of setvar and answer
operating on locked cdrs, but I've seen
enough to revert those changes also, and
stop messing up users who depended on that
behavior. bug 12726 found reverting the changes
fixed his changes, and after a long review
and working on forkCDR, I can see why.
2. Apply the suggested enhancements proposed
in 10668, but in a completely compatible
way. ForkCDR will behave exactly as before,
but now has new options that will allow some
actions to be taken that will slightly
modify the outcome and side-effects of
forkCDR. Based on conversations I've had
with various people, these small tweaks
will allow some users to get the behavior
they need. For instance, users executing
forkCDR in an AGI script will find the
answer time set, and DISPOSITION set,
a situation not covered when the routines
were first written.
3. A small problem in the cdr serializer
would output answer and end times even
when they were not set. This is now
fixed.
........
................
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@118909 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps')
-rw-r--r-- | apps/app_forkcdr.c | 97 |
1 files changed, 89 insertions, 8 deletions
diff --git a/apps/app_forkcdr.c b/apps/app_forkcdr.c index c74de67b7..8d01a829c 100644 --- a/apps/app_forkcdr.c +++ b/apps/app_forkcdr.c @@ -34,6 +34,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/channel.h" #include "asterisk/pbx.h" #include "asterisk/cdr.h" +#include "asterisk/app.h" #include "asterisk/module.h" static char *app = "ForkCDR"; @@ -43,10 +44,51 @@ static char *descrip = " ForkCDR([options]): Causes the Call Data Record to fork an additional\n" "cdr record starting from the time of the fork call\n" " Options:\n" -" v - If the option is passed all cdr variables will be passed along also.\n"; - - -static void ast_cdr_fork(struct ast_channel *chan) +" a - update the answer time on the NEW CDR just after it's been inited..\n" +" The new CDR may have been answered already, the reset that forkcdr.\n" +" does will erase the answer time. This will bring it back, but.\n" +" the answer time will be a copy of the fork/start time. It will.\n" +" only do this if the initial cdr was indeed already answered..\n" +" D - Copy the disposition forward from the old cdr, after the .\n" +" init..\n" +" d - Clear the dstchannel on the new CDR after reset..\n" +" e - end the original CDR. Do this after all the necc. data.\n" +" is copied from the original CDR to the new forked CDR..\n" +" R - do NOT reset the new cdr..\n" +" s(name=val) - Set the CDR var 'name' in the original CDR, with value.\n" +" 'val'.\n" +" v - When the new CDR is forked, it gets a copy of the vars attached\n" +" to the current CDR. The vars attached to the original CDR are removed\n" +" unless this option is specified.\n"; + + +enum { + OPT_SETANS = (1 << 0), + OPT_SETDISP = (1 << 1), + OPT_RESETDEST = (1 << 2), + OPT_ENDCDR = (1 << 3), + OPT_NORESET = (1 << 4), + OPT_KEEPVARS = (1 << 5), + OPT_VARSET = (1 << 6), +}; + +enum { + OPT_ARG_VARSET = 0, + /* note: this entry _MUST_ be the last one in the enum */ + OPT_ARG_ARRAY_SIZE, +}; + +AST_APP_OPTIONS(forkcdr_exec_options, { + AST_APP_OPTION('a', OPT_SETANS), + AST_APP_OPTION('d', OPT_SETDISP), + AST_APP_OPTION('D', OPT_RESETDEST), + AST_APP_OPTION('e', OPT_ENDCDR), + AST_APP_OPTION('R', OPT_NORESET), + AST_APP_OPTION_ARG('s', OPT_VARSET, OPT_ARG_VARSET), + AST_APP_OPTION('v', OPT_KEEPVARS), +}); + +static void ast_cdr_fork(struct ast_channel *chan, struct ast_flags optflags, char *set) { struct ast_cdr *cdr; struct ast_cdr *newcdr; @@ -61,27 +103,66 @@ static void ast_cdr_fork(struct ast_channel *chan) return; ast_cdr_append(cdr, newcdr); - ast_cdr_reset(newcdr, &flags); - + + if (!ast_test_flag(&optflags, OPT_NORESET)) + ast_cdr_reset(newcdr, &flags); + if (!ast_test_flag(cdr, AST_CDR_FLAG_KEEP_VARS)) ast_cdr_free_vars(cdr, 0); + if (!ast_strlen_zero(set)) { + char *varname = ast_strdupa(set), *varval; + varval = strchr(varname,'='); + if (varval) { + *varval = 0; + varval++; + ast_cdr_setvar(cdr, varname, varval, 0); + } + } + + if (ast_test_flag(&optflags, OPT_SETANS) && !ast_tvzero(cdr->answer)) + newcdr->answer = newcdr->start; + + if (ast_test_flag(&optflags, OPT_SETDISP)) + newcdr->disposition = cdr->disposition; + + if (ast_test_flag(&optflags, OPT_RESETDEST)) + newcdr->dstchannel[0] = 0; + + if (ast_test_flag(&optflags, OPT_ENDCDR)) + ast_cdr_end(cdr); + ast_set_flag(cdr, AST_CDR_FLAG_CHILD | AST_CDR_FLAG_LOCKED); } static int forkcdr_exec(struct ast_channel *chan, void *data) { int res = 0; + char *argcopy = NULL; + struct ast_flags flags = {0}; + char *opts[OPT_ARG_ARRAY_SIZE]; + AST_DECLARE_APP_ARGS(arglist, + AST_APP_ARG(options); + ); if (!chan->cdr) { ast_log(LOG_WARNING, "Channel does not have a CDR\n"); return 0; } + argcopy = ast_strdupa(data); + + AST_STANDARD_APP_ARGS(arglist, argcopy); + + if (!ast_strlen_zero(arglist.options)) { + ast_app_parse_options(forkcdr_exec_options, &flags, opts, arglist.options); + } else + opts[OPT_ARG_VARSET] = 0; + if (!ast_strlen_zero(data)) - ast_set2_flag(chan->cdr, strchr(data, 'v'), AST_CDR_FLAG_KEEP_VARS); + ast_set2_flag(chan->cdr, ast_test_flag(&flags, OPT_KEEPVARS), AST_CDR_FLAG_KEEP_VARS); - ast_cdr_fork(chan); + ast_cdr_fork(chan, flags, opts[OPT_ARG_VARSET]); return res; } |