<p>Joe has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15821">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_dialog_info_body_generator: Include LOCAL/REMOTE tags in BLF NOTIFY XML<br><br>PJSIP endpoints subscribed to BLF notifications will not receive<br>Caller ID information for the channel ringing on the remote extension.<br><remote> and <local> tags of the dialog are missing completely.<br><br>This patch iterates through the channels that are currently ringing,<br>and inserts that info into the NOTIFY packet so that information is<br>properly passed to the endpoint in dialog-info+xml.<br><br>ASTERISK-24601<br>Patch submitted: Joshua Elson<br>Modified by: Joseph Nadiv and Sean Bright<br>Tested by: Joseph Nadiv<br><br>Change-Id: I20c5cf5b45f34d7179df6573c5abf863eb72964b<br>---<br>A doc/CHANGES-staging/res_pjsip_dialog_info_body_generator.txt<br>M res/res_pjsip_dialog_info_body_generator.c<br>2 files changed, 96 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/21/15821/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/res_pjsip_dialog_info_body_generator.txt b/doc/CHANGES-staging/res_pjsip_dialog_info_body_generator.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..dd895ef</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/res_pjsip_dialog_info_body_generator.txt</span><br><span>@@ -0,0 +1,6 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: res_pjsip_dialog_info_body_generator</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Added functionality to iterate through the channels that are currently ringing,</span><br><span style="color: hsl(120, 100%, 40%);">+and inserts that info into NOTIFY packet sent to the endpoint so on supported</span><br><span style="color: hsl(120, 100%, 40%);">+devices the callerid information of who is calling the remote extension is</span><br><span style="color: hsl(120, 100%, 40%);">+displayed.</span><br><span>diff --git a/res/res_pjsip_dialog_info_body_generator.c b/res/res_pjsip_dialog_info_body_generator.c</span><br><span>index 3934a8a..e889b9e 100644</span><br><span>--- a/res/res_pjsip_dialog_info_body_generator.c</span><br><span>+++ b/res/res_pjsip_dialog_info_body_generator.c</span><br><span>@@ -30,6 +30,7 @@</span><br><span> #include <pjlib.h></span><br><span> </span><br><span> #include "asterisk/module.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/callerid.h"</span><br><span> #include "asterisk/res_pjsip.h"</span><br><span> #include "asterisk/res_pjsip_pubsub.h"</span><br><span> #include "asterisk/res_pjsip_presence_xml.h"</span><br><span>@@ -60,20 +61,56 @@</span><br><span> return ast_sip_presence_xml_create_node(state_data->pool, NULL, "dialog-info");</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Find the channel that is causing the RINGING update, ref'd</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_channel *find_ringing_channel(struct ao2_container *device_state_info)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_iterator citer;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_device_state_info *device_state;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_channel *c = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct timeval tv = {0,};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* iterate ringing devices and get the oldest of all causing channels */</span><br><span style="color: hsl(120, 100%, 40%);">+ citer = ao2_iterator_init(device_state_info, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ for (; (device_state = ao2_iterator_next(&citer)); ao2_ref(device_state, -1)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!device_state->causing_channel || (device_state->device_state != AST_DEVICE_RINGING &&</span><br><span style="color: hsl(120, 100%, 40%);">+ device_state->device_state != AST_DEVICE_RINGINUSE)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ continue;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_lock(device_state->causing_channel);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_tvzero(tv) || ast_tvcmp(ast_channel_creationtime(device_state->causing_channel), tv) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ c = device_state->causing_channel;</span><br><span style="color: hsl(120, 100%, 40%);">+ tv = ast_channel_creationtime(c);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(device_state->causing_channel);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_iterator_destroy(&citer);</span><br><span style="color: hsl(120, 100%, 40%);">+ return c ? ast_channel_ref(c) : NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int dialog_info_generate_body_content(void *body, void *data)</span><br><span> {</span><br><span> pj_xml_node *dialog_info = body, *dialog, *state;</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_xml_node *remote_node, *local_node, *remote_identity_node;</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_xml_node *remote_target_node, *local_identity_node, *local_target_node;</span><br><span> struct ast_datastore *datastore;</span><br><span> struct dialog_info_xml_state *datastore_state;</span><br><span> struct ast_sip_exten_state_data *state_data = data;</span><br><span> char *local = ast_strdupa(state_data->local), *stripped, *statestring = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *remote = ast_strdupa(state_data->remote), *stripped_remote;</span><br><span> char *pidfstate = NULL, *pidfnote = NULL;</span><br><span> enum ast_sip_pidf_state local_state;</span><br><span> char version_str[32], sanitized[PJSIP_MAX_URL_SIZE];</span><br><span style="color: hsl(120, 100%, 40%);">+ char remote_target[PJSIP_MAX_URL_SIZE], sanitized_remote[PJSIP_MAX_URL_SIZE];</span><br><span> struct ast_sip_endpoint *endpoint = NULL;</span><br><span> unsigned int notify_early_inuse_ringing = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_channel *callee;</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *from_domain = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ static char *invalid = "anonymous.invalid";</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (!local || !state_data->datastores) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!local || !remote || !state_data->datastores) {</span><br><span> return -1;</span><br><span> }</span><br><span> </span><br><span>@@ -111,8 +148,13 @@</span><br><span> stripped = ast_strip_quoted(local, "<", ">");</span><br><span> ast_sip_sanitize_xml(stripped, sanitized, sizeof(sanitized));</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ stripped_remote = ast_strip_quoted(remote, "<", ">");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_sanitize_xml(stripped_remote, sanitized_remote, sizeof(sanitized_remote));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (state_data->sub && (endpoint = ast_sip_subscription_get_endpoint(state_data->sub))) {</span><br><span> notify_early_inuse_ringing = endpoint->notify_early_inuse_ringing;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*subscription maintains a reference to endpoint*/</span><br><span style="color: hsl(120, 100%, 40%);">+ from_domain = endpoint ? (!ast_strlen_zero(endpoint->fromdomain) ? endpoint->fromdomain : invalid) : NULL;</span><br><span> ao2_cleanup(endpoint);</span><br><span> }</span><br><span> ast_sip_presence_exten_state_to_str(state_data->exten_state, &statestring,</span><br><span>@@ -134,6 +176,53 @@</span><br><span> ast_sip_presence_xml_create_attr(state_data->pool, dialog, "id", state_data->exten);</span><br><span> if (!ast_strlen_zero(statestring) && !strcmp(statestring, "early")) {</span><br><span> ast_sip_presence_xml_create_attr(state_data->pool, dialog, "direction", "recipient");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ callee = find_ringing_channel(state_data->device_state_info);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (callee) {</span><br><span style="color: hsl(120, 100%, 40%);">+ static char *anonymous = "anonymous";</span><br><span style="color: hsl(120, 100%, 40%);">+ char *cid_name;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *connected_num;</span><br><span style="color: hsl(120, 100%, 40%);">+ int buffer_return;</span><br><span style="color: hsl(120, 100%, 40%);">+ int connected_num_restricted;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ remote_node = ast_sip_presence_xml_create_node(state_data->pool, dialog, "remote");</span><br><span style="color: hsl(120, 100%, 40%);">+ remote_identity_node = ast_sip_presence_xml_create_node(state_data->pool, remote_node, "identity");</span><br><span style="color: hsl(120, 100%, 40%);">+ remote_target_node = ast_sip_presence_xml_create_node(state_data->pool, remote_node, "target");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_lock(callee);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ cid_name = S_COR(ast_channel_connected(callee)->id.name.valid,</span><br><span style="color: hsl(120, 100%, 40%);">+ S_COR((ast_channel_connected(callee)->id.name.presentation &</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_PRES_RESTRICTION) == AST_PRES_RESTRICTED, anonymous,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_connected(callee)->id.name.str), "");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ connected_num_restricted = (ast_channel_connected(callee)->id.number.presentation &</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_PRES_RESTRICTION) == AST_PRES_RESTRICTED;</span><br><span style="color: hsl(120, 100%, 40%);">+ connected_num = S_COR(ast_channel_connected(callee)->id.number.valid,</span><br><span style="color: hsl(120, 100%, 40%);">+ S_COR(connected_num_restricted, anonymous,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_connected(callee)->id.number.str), "");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ buffer_return = snprintf(remote_target, sizeof(remote_target), "sip:%s@%s", connected_num,</span><br><span style="color: hsl(120, 100%, 40%);">+ connected_num_restricted ? invalid : from_domain);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (buffer_return <= 0 || buffer_return >= sizeof(remote_target)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(remote_target, 32, "sip:%s@%s", anonymous, invalid);</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%);">+ ast_channel_unlock(callee);</span><br><span style="color: hsl(120, 100%, 40%);">+ callee = ast_channel_unref(callee);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strdup2(state_data->pool, &remote_identity_node->content, remote_target);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_presence_xml_create_attr(state_data->pool, remote_identity_node, "display", cid_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_presence_xml_create_attr(state_data->pool, remote_target_node, "uri", remote_target);</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%);">+ local_node = ast_sip_presence_xml_create_node(state_data->pool, dialog, "local");</span><br><span style="color: hsl(120, 100%, 40%);">+ local_identity_node = ast_sip_presence_xml_create_node(state_data->pool, local_node, "identity");</span><br><span style="color: hsl(120, 100%, 40%);">+ local_target_node = ast_sip_presence_xml_create_node(state_data->pool, local_node, "target");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strdup2(state_data->pool, &local_identity_node->content, sanitized);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_presence_xml_create_attr(state_data->pool, local_target_node, "uri", sanitized);</span><br><span> }</span><br><span> </span><br><span> state = ast_sip_presence_xml_create_node(state_data->pool, dialog, "state");</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15821">change 15821</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/+/15821"/><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: I20c5cf5b45f34d7179df6573c5abf863eb72964b </div>
<div style="display:none"> Gerrit-Change-Number: 15821 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joe <ynadiv@corpit.xyz> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>