Fixup skinny registration following network issues.
[asterisk/asterisk.git] / apps / app_forkcdr.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Anthony Minessale anthmct@yahoo.com
5  * Development of this app Sponsered/Funded  by TAAN Softworks Corp
6  *
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.
12  *
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.
16  */
17
18 /*! \file
19  *
20  * \brief Fork CDR application
21  *
22  * \author Anthony Minessale anthmct@yahoo.com
23  *
24  * \note Development of this app Sponsored/Funded by TAAN Softworks Corp
25  * 
26  * \ingroup applications
27  */
28
29 /*** MODULEINFO
30         <support_level>core</support_level>
31  ***/
32
33 #include "asterisk.h"
34
35 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
36
37 #include "asterisk/file.h"
38 #include "asterisk/channel.h"
39 #include "asterisk/pbx.h"
40 #include "asterisk/cdr.h"
41 #include "asterisk/app.h"
42 #include "asterisk/module.h"
43
44 /*** DOCUMENTATION
45         <application name="ForkCDR" language="en_US">
46                 <synopsis>
47                         Forks the current Call Data Record for this channel.
48                 </synopsis>
49                 <syntax>
50                         <parameter name="options">
51                                 <optionlist>
52                                         <option name="a">
53                                                 <para>If the channel is answered, set the answer time on
54                                                 the forked CDR to the current time. If this option is
55                                                 not used, the answer time on the forked CDR will be the
56                                                 answer time on the original CDR. If the channel is not
57                                                 answered, this option has no effect.</para>
58                                                 <para>Note that this option is implicitly assumed if the
59                                                 <literal>r</literal> option is used.</para>
60                                         </option>
61                                         <option name="e">
62                                                 <para>End (finalize) the original CDR.</para>
63                                         </option>
64                                         <option name="r">
65                                                 <para>Reset the start and answer times on the forked CDR.
66                                                 This will set the start and answer times (if the channel
67                                                 is answered) to be set to the current time.</para>
68                                                 <para>Note that this option implicitly assumes the
69                                                 <literal>a</literal> option.</para>
70                                         </option>
71                                         <option name="v">
72                                                 <para>Do not copy CDR variables and attributes from the
73                                                 original CDR to the forked CDR.</para>
74                                                 <warning><para>This option has changed. Previously, the
75                                                 variables were removed from the original CDR. This no
76                                                 longer occurs - this option now controls whether or not
77                                                 a forked CDR inherits the variables from the original
78                                                 CDR.</para></warning>
79                                         </option>
80                                 </optionlist>
81                         </parameter>
82                 </syntax>
83                 <description>
84                         <para>Causes the Call Data Record engine to fork a new CDR starting
85                         from the time the application is executed. The forked CDR will be
86                         linked to the end of the CDRs associated with the channel.</para>
87                 </description>
88                 <see-also>
89                         <ref type="function">CDR</ref>
90                         <ref type="application">NoCDR</ref>
91                         <ref type="application">ResetCDR</ref>
92                 </see-also>
93         </application>
94  ***/
95
96 static char *app = "ForkCDR";
97
98 AST_APP_OPTIONS(forkcdr_exec_options, {
99         AST_APP_OPTION('a', AST_CDR_FLAG_SET_ANSWER),
100         AST_APP_OPTION('e', AST_CDR_FLAG_FINALIZE),
101         AST_APP_OPTION('r', AST_CDR_FLAG_RESET),
102         AST_APP_OPTION('v', AST_CDR_FLAG_KEEP_VARS),
103 });
104
105 static int forkcdr_exec(struct ast_channel *chan, const char *data)
106 {
107         char *parse;
108         struct ast_flags flags = { 0, };
109         AST_DECLARE_APP_ARGS(args,
110                 AST_APP_ARG(options);
111         );
112
113         parse = ast_strdupa(data);
114
115         AST_STANDARD_APP_ARGS(args, parse);
116
117         if (!ast_strlen_zero(args.options)) {
118                 ast_app_parse_options(forkcdr_exec_options, &flags, NULL, args.options);
119         }
120
121         if (ast_cdr_fork(ast_channel_name(chan), &flags)) {
122                 ast_log(AST_LOG_WARNING, "Failed to fork CDR for channel %s\n", ast_channel_name(chan));
123         }
124
125         return 0;
126 }
127
128 static int unload_module(void)
129 {
130         return ast_unregister_application(app);
131 }
132
133 static int load_module(void)
134 {
135         return ast_register_application_xml(app, forkcdr_exec);
136 }
137
138 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Fork The CDR into 2 separate entities");