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