Fixup skinny registration following network issues.
[asterisk/asterisk.git] / apps / app_cdr.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Martin Pycko <martinp@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*! \file
20  *
21  * \brief Applications connected with CDR engine
22  *
23  * \author Martin Pycko <martinp@digium.com>
24  *
25  * \ingroup applications
26  */
27
28 /*** MODULEINFO
29         <support_level>core</support_level>
30  ***/
31
32 #include "asterisk.h"
33
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
35
36 #include "asterisk/channel.h"
37 #include "asterisk/module.h"
38 #include "asterisk/app.h"
39
40 /*** DOCUMENTATION
41         <application name="NoCDR" language="en_US">
42                 <synopsis>
43                         Tell Asterisk to not maintain a CDR for this channel.
44                 </synopsis>
45                 <syntax />
46                 <description>
47                         <para>This application will tell Asterisk not to maintain a CDR for
48                         the current channel. This does <emphasis>NOT</emphasis> mean that
49                         information is not tracked; rather, if the channel is hung up no
50                         CDRs will be created for that channel.</para>
51                         <para>If a subsequent call to ResetCDR occurs, all non-finalized
52                         CDRs created for the channel will be enabled.</para>
53                         <note><para>This application is deprecated. Please use the CDR_PROP
54                         function to disable CDRs on a channel.</para></note>
55                 </description>
56                 <see-also>
57                         <ref type="application">ResetCDR</ref>
58                         <ref type="function">CDR_PROP</ref>
59                 </see-also>
60         </application>
61         <application name="ResetCDR" language="en_US">
62                 <synopsis>
63                         Resets the Call Data Record.
64                 </synopsis>
65                 <syntax>
66                         <parameter name="options">
67                                 <optionlist>
68                                         <option name="v">
69                                                 <para>Save the CDR variables during the reset.</para>
70                                         </option>
71                                         <option name="e">
72                                                 <para>Enable the CDRs for this channel only (negate
73                                                 effects of NoCDR).</para>
74                                         </option>
75                                 </optionlist>
76                         </parameter>
77                 </syntax>
78                 <description>
79                         <para>This application causes the Call Data Record to be reset.
80                         Depending on the flags passed in, this can have several effects.
81                         With no options, a reset does the following:</para>
82                         <para>1. The <literal>start</literal> time is set to the current time.</para>
83                         <para>2. If the channel is answered, the <literal>answer</literal> time is set to the
84                         current time.</para>
85                         <para>3. All variables are wiped from the CDR. Note that this step
86                         can be prevented with the <literal>v</literal> option.</para>
87                         <para>On the other hand, if the <literal>e</literal> option is
88                         specified, the effects of the NoCDR application will be lifted. CDRs
89                         will be re-enabled for this channel.</para>
90                         <note><para>The <literal>e</literal> option is deprecated. Please
91                         use the CDR_PROP function instead.</para></note>
92                 </description>
93                 <see-also>
94                         <ref type="application">ForkCDR</ref>
95                         <ref type="application">NoCDR</ref>
96                         <ref type="function">CDR_PROP</ref>
97                 </see-also>
98         </application>
99  ***/
100
101 static const char nocdr_app[] = "NoCDR";
102 static const char resetcdr_app[] = "ResetCDR";
103
104 enum reset_cdr_options {
105         OPT_DISABLE_DISPATCH = (1 << 0),
106         OPT_KEEP_VARS = (1 << 1),
107         OPT_ENABLE = (1 << 2),
108 };
109
110 AST_APP_OPTIONS(resetcdr_opts, {
111         AST_APP_OPTION('v', AST_CDR_FLAG_KEEP_VARS),
112         AST_APP_OPTION('e', AST_CDR_FLAG_DISABLE_ALL),
113 });
114
115 static int resetcdr_exec(struct ast_channel *chan, const char *data)
116 {
117         char *args;
118         struct ast_flags flags = { 0 };
119         int res = 0;
120
121         if (!ast_strlen_zero(data)) {
122                 args = ast_strdupa(data);
123                 ast_app_parse_options(resetcdr_opts, &flags, NULL, args);
124         }
125
126         if (ast_test_flag(&flags, AST_CDR_FLAG_DISABLE_ALL)) {
127                 if (ast_cdr_clear_property(ast_channel_name(chan), AST_CDR_FLAG_DISABLE_ALL)) {
128                         res = 1;
129                 }
130         }
131         if (ast_cdr_reset(ast_channel_name(chan), &flags)) {
132                 res = 1;
133         }
134
135         if (res) {
136                 ast_log(AST_LOG_WARNING, "Failed to reset CDR for channel %s\n", ast_channel_name(chan));
137         }
138         return res;
139 }
140
141 static int nocdr_exec(struct ast_channel *chan, const char *data)
142 {
143         if (ast_cdr_set_property(ast_channel_name(chan), AST_CDR_FLAG_DISABLE_ALL)) {
144                 ast_log(AST_LOG_WARNING, "Failed to disable CDR for channel %s\n", ast_channel_name(chan));
145         }
146
147         return 0;
148 }
149
150 static int unload_module(void)
151 {
152         ast_unregister_application(nocdr_app);
153         ast_unregister_application(resetcdr_app);
154         return 0;
155 }
156
157 static int load_module(void)
158 {
159         int res = 0;
160
161         res |= ast_register_application_xml(nocdr_app, nocdr_exec);
162         res |= ast_register_application_xml(resetcdr_app, resetcdr_exec);
163
164         if (res) {
165                 return AST_MODULE_LOAD_FAILURE;
166         }
167         return AST_MODULE_LOAD_SUCCESS;
168 }
169
170 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Tell Asterisk to not maintain a CDR for the current call");