2 * Asterisk -- A telephony toolkit for Linux.
5 * Copyright Anthony Minessale anthmct@yahoo.com
6 * Development of this app Sponsered/Funded by TAAN Softworks Corp
8 * This program is free software, distributed under the terms of
9 * the GNU General Public License
12 #include <asterisk/file.h>
13 #include <asterisk/logger.h>
14 #include <asterisk/channel.h>
15 #include <asterisk/pbx.h>
16 #include <asterisk/cdr.h>
17 #include <asterisk/module.h>
23 static char *tdesc = "Fork The CDR into 2 separate entities.";
24 static char *app = "ForkCDR";
25 static char *synopsis =
26 "Forks the Call Data Record";
27 static char *descrip =
28 " ForkCDR([options]): Causes the Call Data Record to fork an additional\n"
29 "cdr record starting from the time of the fork call\n"
30 "If the option 'v' is passed all cdr variables will be passed along also.\n"
39 static void ast_cdr_clone(struct ast_cdr *cdr)
41 struct ast_cdr *newcdr = ast_cdr_alloc();
42 memcpy(newcdr,cdr,sizeof(struct ast_cdr));
43 ast_cdr_append(cdr,newcdr);
44 gettimeofday(&newcdr->start, NULL);
45 memset(&newcdr->answer, 0, sizeof(newcdr->answer));
46 memset(&newcdr->varshead, 0, sizeof(newcdr->varshead));
47 ast_cdr_copy_vars(newcdr, cdr);
48 if (!ast_test_flag(cdr, AST_CDR_FLAG_KEEP_VARS)) {
49 ast_cdr_free_vars(cdr, 0);
51 newcdr->disposition = AST_CDR_NOANSWER;
52 ast_set_flag(cdr, AST_CDR_FLAG_CHILD|AST_CDR_FLAG_LOCKED);
55 static void ast_cdr_fork(struct ast_channel *chan)
57 if(chan && chan->cdr) {
58 ast_cdr_clone(chan->cdr);
62 static int forkcdr_exec(struct ast_channel *chan, void *data)
67 ast_set2_flag(chan->cdr, strchr((char *)data, 'v'), AST_CDR_FLAG_KEEP_VARS);
75 int unload_module(void)
77 STANDARD_HANGUP_LOCALUSERS;
78 return ast_unregister_application(app);
83 return ast_register_application(app, forkcdr_exec, synopsis, descrip);
86 char *description(void)
94 STANDARD_USECOUNT(res);
100 return ASTERISK_GPL_KEY;