Fix a few things I missed to ensure zt_chan_conf structure is not modified in mkintf
[asterisk-bristuff.git] / apps / app_forkcdr.c
blobd9c5b293f40b68d8918a50c374170def2a9f8cfe
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Anthony Minessale anthmct@yahoo.com
5 * Development of this app Sponsered/Funded by TAAN Softworks Corp
7 * See http://www.asterisk.org for more information about
8 * the Asterisk project. Please do not directly contact
9 * any of the maintainers of this project for assistance;
10 * the project provides a web site, mailing lists and IRC
11 * channels for your use.
13 * This program is free software, distributed under the terms of
14 * the GNU General Public License Version 2. See the LICENSE file
15 * at the top of the source tree.
18 /*! \file
20 * \brief Fork CDR application
22 * \author Anthony Minessale anthmct@yahoo.com
24 * \note Development of this app Sponsored/Funded by TAAN Softworks Corp
26 * \ingroup applications
29 #include "asterisk.h"
31 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <unistd.h>
38 #include "asterisk/file.h"
39 #include "asterisk/logger.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/pbx.h"
42 #include "asterisk/cdr.h"
43 #include "asterisk/module.h"
45 static char *app = "ForkCDR";
46 static char *synopsis =
47 "Forks the Call Data Record";
48 static char *descrip =
49 " ForkCDR([options]): Causes the Call Data Record to fork an additional\n"
50 "cdr record starting from the time of the fork call\n"
51 "If the option 'v' is passed all cdr variables will be passed along also.\n";
54 static void ast_cdr_fork(struct ast_channel *chan)
56 struct ast_cdr *cdr;
57 struct ast_cdr *newcdr;
58 struct ast_flags flags = { AST_CDR_FLAG_KEEP_VARS };
60 cdr = chan->cdr;
62 while (cdr->next)
63 cdr = cdr->next;
65 if (!(newcdr = ast_cdr_dup(cdr)))
66 return;
68 ast_cdr_append(cdr, newcdr);
69 ast_cdr_reset(newcdr, &flags);
71 if (!ast_test_flag(cdr, AST_CDR_FLAG_KEEP_VARS))
72 ast_cdr_free_vars(cdr, 0);
74 ast_set_flag(cdr, AST_CDR_FLAG_CHILD | AST_CDR_FLAG_LOCKED);
77 static int forkcdr_exec(struct ast_channel *chan, void *data)
79 int res = 0;
80 struct ast_module_user *u;
82 if (!chan->cdr) {
83 ast_log(LOG_WARNING, "Channel does not have a CDR\n");
84 return 0;
87 u = ast_module_user_add(chan);
89 if (!ast_strlen_zero(data))
90 ast_set2_flag(chan->cdr, strchr(data, 'v'), AST_CDR_FLAG_KEEP_VARS);
92 ast_cdr_fork(chan);
94 ast_module_user_remove(u);
95 return res;
98 static int unload_module(void)
100 int res;
102 res = ast_unregister_application(app);
104 ast_module_user_hangup_all();
106 return res;
109 static int load_module(void)
111 return ast_register_application(app, forkcdr_exec, synopsis, descrip);
114 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Fork The CDR into 2 separate entities");