<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18603">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">cdr: Allow bridging and dial state changes to be ignored.<br><br>Allows bridging, parking, and dial messages to be globally<br>ignored for all CDRs.<br><br>This is useful when CDRs should endure for the lifetime of<br>an entire channel and bridging and dial updates in the<br>dialplan should not affect the CDR in any way. This can<br>reduce the amount of "CDR hacks" that were previously<br>needed to ensure that CDR was not "spoiled" by these<br>messages if that was undesired, such as putting a dummy<br>optimization-disabled local channel between the caller<br>and the actual call and putting the CDR on the channel<br>in the middle to ensure that CDR would persist for the entire<br>call and properly record start, answer, and end times.<br><br>Current default behavior remains unchanged.<br><br>ASTERISK-30091 #close<br><br>Change-Id: I393981af42732ec5ac3ff9266444abb453b7c832<br>---<br>A doc/CHANGES-staging/cdr_ignore.txt<br>M include/asterisk/cdr.h<br>M main/cdr.c<br>3 files changed, 62 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/03/18603/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/cdr_ignore.txt b/doc/CHANGES-staging/cdr_ignore.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..e82f404</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/cdr_ignore.txt</span><br><span>@@ -0,0 +1,6 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: cdr</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Two new options have been added which allow</span><br><span style="color: hsl(120, 100%, 40%);">+bridging and dial state changes to be ignored</span><br><span style="color: hsl(120, 100%, 40%);">+in CDRs, which can be useful if a single CDR</span><br><span style="color: hsl(120, 100%, 40%);">+is desired for a channel.</span><br><span>diff --git a/include/asterisk/cdr.h b/include/asterisk/cdr.h</span><br><span>index 2bbfbdb..06307c9 100644</span><br><span>--- a/include/asterisk/cdr.h</span><br><span>+++ b/include/asterisk/cdr.h</span><br><span>@@ -225,6 +225,8 @@</span><br><span>    CDR_INITIATED_SECONDS = 1 << 5,     /*!< Include microseconds into the billing time */</span><br><span>      CDR_DEBUG = 1 << 6,                 /*!< Enables extra debug statements */</span><br><span>  CDR_CHANNEL_DEFAULT_ENABLED = 1 << 7, /*!< Whether CDR is enabled for each channel by default */</span><br><span style="color: hsl(120, 100%, 40%);">+     CDR_IGNORE_STATE_CHANGES = 1 << 8,        /*!< Whether to ignore bridge and other call state change events */</span><br><span style="color: hsl(120, 100%, 40%);">+        CDR_IGNORE_DIAL_CHANGES = 1 << 9, /*!< Whether to ignore dial state changes */</span><br><span> };</span><br><span> </span><br><span> /*! \brief CDR Batch Mode settings */</span><br><span>diff --git a/main/cdr.c b/main/cdr.c</span><br><span>index b059082..f41ae42 100644</span><br><span>--- a/main/cdr.c</span><br><span>+++ b/main/cdr.c</span><br><span>@@ -111,6 +111,28 @@</span><br><span>                                       to undisable (enable) CDR for a call.</para></span><br><span>                                   </description></span><br><span>                                 </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+                         <configOption name="ignorestatechanges" default="no"></span><br><span style="color: hsl(120, 100%, 40%);">+                                       <synopsis>Whether CDR is updated or forked by bridging changes.</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+                                        <description><para>Define whether or not CDR should be updated by bridging changes.</span><br><span style="color: hsl(120, 100%, 40%);">+                                       This includes entering and leaving bridges and call parking.</para></span><br><span style="color: hsl(120, 100%, 40%);">+                                     <para>If this is set to "no", bridging changes will be ignored for all CDRs.</span><br><span style="color: hsl(120, 100%, 40%);">+                                  This should only be done if these events should not affect CDRs and are undesired,</span><br><span style="color: hsl(120, 100%, 40%);">+                                    such as to use a single CDR for the lifetime of the channel.</para></span><br><span style="color: hsl(120, 100%, 40%);">+                                     </description></span><br><span style="color: hsl(120, 100%, 40%);">+                          </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+                         <configOption name="ignoredialchanges" default="no"></span><br><span style="color: hsl(120, 100%, 40%);">+                                        <synopsis>Whether CDR is updated or forked by dial updates.</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+                                    <description><para>Define whether or not CDR should be updated by dial updates.</para></span><br><span style="color: hsl(120, 100%, 40%);">+                                      <para>If this is set to "no", a single CDR will be used for the channel, even if</span><br><span style="color: hsl(120, 100%, 40%);">+                                      multiple endpoints or destinations are dialed sequentially. Note that you will also</span><br><span style="color: hsl(120, 100%, 40%);">+                                   lose detailed nonanswer dial dispositions if this option is enabled, which may not be acceptable,</span><br><span style="color: hsl(120, 100%, 40%);">+                                     e.g. instead of detailed no-answer dispositions like BUSY and CONGESTION, the disposition</span><br><span style="color: hsl(120, 100%, 40%);">+                                     will always be NO ANSWER if the channel was unanswered (it will still be ANSWERED</span><br><span style="color: hsl(120, 100%, 40%);">+                                     if the channel was answered).</para></span><br><span style="color: hsl(120, 100%, 40%);">+                                    <para>This option should be enabled if a single CDR is desired for the lifetime of</span><br><span style="color: hsl(120, 100%, 40%);">+                                      the channel.</para></span><br><span style="color: hsl(120, 100%, 40%);">+                                     </description></span><br><span style="color: hsl(120, 100%, 40%);">+                          </configOption></span><br><span>                                <configOption name="unanswered"></span><br><span>                                     <synopsis>Log calls that are never answered and don't set an outgoing party.</synopsis></span><br><span>                                      <description><para></span><br><span>@@ -208,6 +230,8 @@</span><br><span> #define DEFAULT_END_BEFORE_H_EXTEN "1"</span><br><span> #define DEFAULT_INITIATED_SECONDS "0"</span><br><span> #define DEFAULT_CHANNEL_ENABLED "1"</span><br><span style="color: hsl(120, 100%, 40%);">+#define DEFAULT_IGNORE_STATE_CHANGES "0"</span><br><span style="color: hsl(120, 100%, 40%);">+#define DEFAULT_IGNORE_DIAL_CHANGES "0"</span><br><span> </span><br><span> #define DEFAULT_BATCH_SIZE "100"</span><br><span> #define MAX_BATCH_SIZE 1000</span><br><span>@@ -4200,6 +4224,8 @@</span><br><span>                ast_cli(a->fd, "  Log calls by default:       %s\n", ast_test_flag(&mod_cfg->general->settings, CDR_CHANNEL_DEFAULT_ENABLED) ? "Yes" : "No");</span><br><span>             ast_cli(a->fd, "  Log unanswered calls:       %s\n", ast_test_flag(&mod_cfg->general->settings, CDR_UNANSWERED) ? "Yes" : "No");</span><br><span>          ast_cli(a->fd, "  Log congestion:             %s\n\n", ast_test_flag(&mod_cfg->general->settings, CDR_CONGESTION) ? "Yes" : "No");</span><br><span style="color: hsl(120, 100%, 40%);">+         ast_cli(a->fd, "  Ignore bridging changes:    %s\n\n", ast_test_flag(&mod_cfg->general->settings, CDR_IGNORE_STATE_CHANGES) ? "Yes" : "No");</span><br><span style="color: hsl(120, 100%, 40%);">+               ast_cli(a->fd, "  Ignore dial state changes:  %s\n\n", ast_test_flag(&mod_cfg->general->settings, CDR_IGNORE_DIAL_CHANGES) ? "Yes" : "No");</span><br><span>               if (ast_test_flag(&mod_cfg->general->settings, CDR_BATCHMODE)) {</span><br><span>                   ast_cli(a->fd, "* Batch Mode Settings\n");</span><br><span>                      ast_cli(a->fd, "  -------------------\n");</span><br><span>@@ -4379,6 +4405,8 @@</span><br><span>              aco_option_register(&cfg_info, "size", ACO_EXACT, general_options, DEFAULT_BATCH_SIZE, OPT_UINT_T, PARSE_IN_RANGE, FLDSET(struct ast_cdr_config, batch_settings.size), 0, MAX_BATCH_SIZE);</span><br><span>             aco_option_register(&cfg_info, "time", ACO_EXACT, general_options, DEFAULT_BATCH_TIME, OPT_UINT_T, PARSE_IN_RANGE, FLDSET(struct ast_cdr_config, batch_settings.time), 1, MAX_BATCH_TIME);</span><br><span>             aco_option_register(&cfg_info, "channeldefaultenabled", ACO_EXACT, general_options, DEFAULT_CHANNEL_ENABLED, OPT_BOOLFLAG_T, 1, FLDSET(struct ast_cdr_config, settings), CDR_CHANNEL_DEFAULT_ENABLED);</span><br><span style="color: hsl(120, 100%, 40%);">+          aco_option_register(&cfg_info, "ignorestatechanges", ACO_EXACT, general_options, DEFAULT_IGNORE_STATE_CHANGES, OPT_BOOLFLAG_T, 1, FLDSET(struct ast_cdr_config, settings), CDR_IGNORE_STATE_CHANGES);</span><br><span style="color: hsl(120, 100%, 40%);">+           aco_option_register(&cfg_info, "ignoredialchanges", ACO_EXACT, general_options, DEFAULT_IGNORE_DIAL_CHANGES, OPT_BOOLFLAG_T, 1, FLDSET(struct ast_cdr_config, settings), CDR_IGNORE_DIAL_CHANGES);</span><br><span>     }</span><br><span> </span><br><span>        if (aco_process_config(&cfg_info, reload) == ACO_PROCESS_ERROR) {</span><br><span>@@ -4541,6 +4569,7 @@</span><br><span> </span><br><span> static int load_module(void)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+        struct module_config *mod_cfg = NULL;</span><br><span>        if (process_config(0)) {</span><br><span>             return AST_MODULE_LOAD_FAILURE;</span><br><span>      }</span><br><span>@@ -4561,13 +4590,34 @@</span><br><span>          return AST_MODULE_LOAD_FAILURE;</span><br><span>      }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ mod_cfg = ao2_global_obj_ref(module_configs);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>      stasis_message_router_add(stasis_router, ast_channel_snapshot_type(), handle_channel_snapshot_update_message, NULL);</span><br><span style="color: hsl(0, 100%, 40%);">-    stasis_message_router_add(stasis_router, ast_channel_dial_type(), handle_dial_message, NULL);</span><br><span style="color: hsl(0, 100%, 40%);">-   stasis_message_router_add(stasis_router, ast_channel_entered_bridge_type(), handle_bridge_enter_message, NULL);</span><br><span style="color: hsl(0, 100%, 40%);">- stasis_message_router_add(stasis_router, ast_channel_left_bridge_type(), handle_bridge_leave_message, NULL);</span><br><span style="color: hsl(0, 100%, 40%);">-    stasis_message_router_add(stasis_router, ast_parked_call_type(), handle_parked_call_message, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* If explicitly requested to ignore dial state changes, then ignore dial messages */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!mod_cfg || !ast_test_flag(&mod_cfg->general->settings, CDR_IGNORE_DIAL_CHANGES)) {</span><br><span style="color: hsl(120, 100%, 40%);">+             stasis_message_router_add(stasis_router, ast_channel_dial_type(), handle_dial_message, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              CDR_DEBUG("All dial messages will be ignored\n");</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* If explicitly instructed to ignore call state changes, then ignore bridging events, parking, etc. */</span><br><span style="color: hsl(120, 100%, 40%);">+       if (!mod_cfg || !ast_test_flag(&mod_cfg->general->settings, CDR_IGNORE_STATE_CHANGES)) {</span><br><span style="color: hsl(120, 100%, 40%);">+            stasis_message_router_add(stasis_router, ast_channel_entered_bridge_type(), handle_bridge_enter_message, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+               stasis_message_router_add(stasis_router, ast_channel_left_bridge_type(), handle_bridge_leave_message, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+          stasis_message_router_add(stasis_router, ast_parked_call_type(), handle_parked_call_message, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+   } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              CDR_DEBUG("All bridge and parking messages will be ignored\n");</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  stasis_message_router_add(stasis_router, cdr_sync_message_type(), handle_cdr_sync_message, NULL);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (mod_cfg) {</span><br><span style="color: hsl(120, 100%, 40%);">+                ao2_cleanup(mod_cfg);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              ast_log(LOG_WARNING, "Unable to obtain CDR configuration during module load?\n");</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  active_cdrs_master = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,</span><br><span>           AST_NUM_CHANNEL_BUCKETS, cdr_master_hash_fn, NULL, cdr_master_cmp_fn);</span><br><span>       if (!active_cdrs_master) {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18603">change 18603</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/18603"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I393981af42732ec5ac3ff9266444abb453b7c832 </div>
<div style="display:none"> Gerrit-Change-Number: 18603 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>