summaryrefslogtreecommitdiff
path: root/apps/app_cdr.c
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2013-06-17 03:00:38 +0000
committerMatthew Jordan <mjordan@digium.com>2013-06-17 03:00:38 +0000
commit6258bbe7bd1885ac5dec095ed0c4490c83a99f44 (patch)
treeff2794f730ca55903a09b9fe7f73f45169a71386 /apps/app_cdr.c
parent67e35c7b4748c3cef954820a2b182e2a5edf8d98 (diff)
Update Asterisk's CDRs for the new bridging framework
This patch is the initial push to update Asterisk's CDR engine for the new bridging framework. This patch guts the existing CDR engine and builds the new on top of messages coming across Stasis. As changes in channel state and bridge state are detected, CDRs are built and dispatched accordingly. This fundamentally changes CDRs in a few ways. (1) CDRs are now *very* reflective of the actual state of channels and bridges. This means CDRs track well with what an actual channel is doing - which is useful in transfer scenarios (which were previously difficult to pin down). It does, however, mean that CDRs cannot be 'fooled'. Previous behavior in Asterisk allowed for CDR applications, channels, and other properties to be spoofed in parts of the code - this no longer works. (2) CDRs have defined behavior in multi-party scenarios. This behavior will not be what everyone wants, but it is a defined behavior and as such, it is predictable. (3) The CDR manipulation functions and applications have been overhauled. Major changes have been made to ResetCDR and ForkCDR in particular. Many of the options for these two applications no longer made any sense with the new framework and the (slightly) more immutable nature of CDRs. There are a plethora of other changes. For a full description of CDR behavior, see the CDR specification on the Asterisk wiki. (closes issue ASTERISK-21196) Review: https://reviewboard.asterisk.org/r/2486/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@391947 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'apps/app_cdr.c')
-rw-r--r--apps/app_cdr.c105
1 files changed, 100 insertions, 5 deletions
diff --git a/apps/app_cdr.c b/apps/app_cdr.c
index 3c244712b..ba7139cf1 100644
--- a/apps/app_cdr.c
+++ b/apps/app_cdr.c
@@ -35,25 +35,114 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/channel.h"
#include "asterisk/module.h"
+#include "asterisk/app.h"
/*** DOCUMENTATION
<application name="NoCDR" language="en_US">
<synopsis>
- Tell Asterisk to not maintain a CDR for the current call
+ Tell Asterisk to not maintain a CDR for this channel.
</synopsis>
<syntax />
<description>
- <para>This application will tell Asterisk not to maintain a CDR for the current call.</para>
+ <para>This application will tell Asterisk not to maintain a CDR for
+ the current channel. This does <emphasis>NOT</emphasis> mean that
+ information is not tracked; rather, if the channel is hung up no
+ CDRs will be created for that channel.</para>
+ <para>If a subsequent call to ResetCDR occurs, all non-finalized
+ CDRs created for the channel will be enabled.</para>
+ <note><para>This application is deprecated. Please use the CDR_PROP
+ function to disable CDRs on a channel.</para></note>
</description>
+ <see-also>
+ <ref type="application">ResetCDR</ref>
+ <ref type="function">CDR_PROP</ref>
+ </see-also>
+ </application>
+ <application name="ResetCDR" language="en_US">
+ <synopsis>
+ Resets the Call Data Record.
+ </synopsis>
+ <syntax>
+ <parameter name="options">
+ <optionlist>
+ <option name="v">
+ <para>Save the CDR variables during the reset.</para>
+ </option>
+ <option name="e">
+ <para>Enable the CDRs for this channel only (negate
+ effects of NoCDR).</para>
+ </option>
+ </optionlist>
+ </parameter>
+ </syntax>
+ <description>
+ <para>This application causes the Call Data Record to be reset.
+ Depending on the flags passed in, this can have several effects.
+ With no options, a reset does the following:</para>
+ <para>1. The <literal>start</literal> time is set to the current time.</para>
+ <para>2. If the channel is answered, the <literal>answer</literal> time is set to the
+ current time.</para>
+ <para>3. All variables are wiped from the CDR. Note that this step
+ can be prevented with the <literal>v</literal> option.</para>
+ <para>On the other hand, if the <literal>e</literal> option is
+ specified, the effects of the NoCDR application will be lifted. CDRs
+ will be re-enabled for this channel.</para>
+ <note><para>The <literal>e</literal> option is deprecated. Please
+ use the CDR_PROP function instead.</para></note>
+ </description>
+ <see-also>
+ <ref type="application">ForkCDR</ref>
+ <ref type="application">NoCDR</ref>
+ <ref type="function">CDR_PROP</ref>
+ </see-also>
</application>
***/
static const char nocdr_app[] = "NoCDR";
+static const char resetcdr_app[] = "ResetCDR";
+
+enum reset_cdr_options {
+ OPT_DISABLE_DISPATCH = (1 << 0),
+ OPT_KEEP_VARS = (1 << 1),
+ OPT_ENABLE = (1 << 2),
+};
+
+AST_APP_OPTIONS(resetcdr_opts, {
+ AST_APP_OPTION('v', AST_CDR_FLAG_KEEP_VARS),
+ AST_APP_OPTION('e', AST_CDR_FLAG_DISABLE_ALL),
+});
+
+static int resetcdr_exec(struct ast_channel *chan, const char *data)
+{
+ char *args;
+ struct ast_flags flags = { 0 };
+ int res = 0;
+
+ if (!ast_strlen_zero(data)) {
+ args = ast_strdupa(data);
+ ast_app_parse_options(resetcdr_opts, &flags, NULL, args);
+ }
+
+ if (ast_test_flag(&flags, AST_CDR_FLAG_DISABLE_ALL)) {
+ if (ast_cdr_clear_property(ast_channel_name(chan), AST_CDR_FLAG_DISABLE_ALL)) {
+ res = 1;
+ }
+ }
+ if (ast_cdr_reset(ast_channel_name(chan), &flags)) {
+ res = 1;
+ }
+
+ if (res) {
+ ast_log(AST_LOG_WARNING, "Failed to reset CDR for channel %s\n", ast_channel_name(chan));
+ }
+ return res;
+}
static int nocdr_exec(struct ast_channel *chan, const char *data)
{
- if (ast_channel_cdr(chan))
- ast_set_flag(ast_channel_cdr(chan), AST_CDR_FLAG_POST_DISABLED);
+ if (ast_cdr_set_property(ast_channel_name(chan), AST_CDR_FLAG_DISABLE_ALL)) {
+ ast_log(AST_LOG_WARNING, "Failed to disable CDR for channel %s\n", ast_channel_name(chan));
+ }
return 0;
}
@@ -65,8 +154,14 @@ static int unload_module(void)
static int load_module(void)
{
- if (ast_register_application_xml(nocdr_app, nocdr_exec))
+ int res = 0;
+
+ res |= ast_register_application_xml(nocdr_app, nocdr_exec);
+ res |= ast_register_application_xml(resetcdr_app, resetcdr_exec);
+
+ if (res) {
return AST_MODULE_LOAD_FAILURE;
+ }
return AST_MODULE_LOAD_SUCCESS;
}