[Asterisk-code-review] res_pjsip_pubsub: 'uri' list attribute mismatch with SUBSCRIBE request (asterisk[16])

Alexei Gradinari asteriskteam at digium.com
Wed Mar 9 16:23:26 CST 2022


Alexei Gradinari has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/18193 )


Change subject: res_pjsip_pubsub: 'uri' list attribute mismatch with SUBSCRIBE request
......................................................................

res_pjsip_pubsub: 'uri' list attribute mismatch with SUBSCRIBE request

When asterisk generates the RLMI part of NOTIFY request,
the asterisk uses the local contact uri instead of the URI to which
the SUBSCRIBE request is sent.
Because of this mismatch some IP phones (for example Cisco 5XX) ignore
this list.

According
https://datatracker.ietf.org/doc/html/rfc4662#section-5.2
  The first mandatory <list> attribute is "uri", which contains the uri
  that corresponds to the list. Typically, this is the URI to which
  the SUBSCRIBE request was sent.
https://datatracker.ietf.org/doc/html/rfc4662#section-5.3
  The "uri" attribute identifies the resource to which the <resource>
  element corresponds. Typically, this will be a SIP URI that, if
  subscribed to, would return the state of the resource.

This patch makes asterisk to generate URI using SUBSCRIBE request URI.

Change-Id: I1fcfc08fd589677f40608c59a4e143c45ee05f6c
---
M include/asterisk/res_pjsip_pubsub.h
M res/res_pjsip_pubsub.c
2 files changed, 18 insertions(+), 12 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/93/18193/1

diff --git a/include/asterisk/res_pjsip_pubsub.h b/include/asterisk/res_pjsip_pubsub.h
index aca1141..b4132d1 100644
--- a/include/asterisk/res_pjsip_pubsub.h
+++ b/include/asterisk/res_pjsip_pubsub.h
@@ -357,11 +357,13 @@
  * When a subscriber wishes to create a subscription, it may call this function
  * to allocate resources and to send the initial SUBSCRIBE out.
  *
+ * \param param rdata The inbound SUBSCRIBE message
  * \param handler The subscriber that is making the request.
  * \param endpoint The endpoint to whome the SUBSCRIBE will be sent.
  * \param resource The resource to place in the SUBSCRIBE's Request-URI.
  */
-struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_subscription_handler *handler,
+struct ast_sip_subscription *ast_sip_create_subscription(pjsip_rx_data *rdata,
+		const struct ast_sip_subscription_handler *handler,
 		struct ast_sip_endpoint *endpoint, const char *resource);
 
 /*!
diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c
index 21174ae..56b936c 100644
--- a/res/res_pjsip_pubsub.c
+++ b/res/res_pjsip_pubsub.c
@@ -1253,11 +1253,12 @@
 	destroy_subscription(root);
 }
 
-static struct ast_sip_subscription *allocate_subscription(const struct ast_sip_subscription_handler *handler,
+static struct ast_sip_subscription *allocate_subscription(pjsip_rx_data *rdata,
+		const struct ast_sip_subscription_handler *handler,
 		const char *resource, const char *display_name, struct sip_subscription_tree *tree)
 {
 	struct ast_sip_subscription *sub;
-	pjsip_sip_uri *contact_uri;
+	pjsip_sip_uri *request_uri;
 
 	sub = ast_calloc(1, sizeof(*sub) + strlen(resource) + 1);
 	if (!sub) {
@@ -1280,8 +1281,8 @@
 	}
 
 	sub->uri = pjsip_sip_uri_create(tree->dlg->pool, PJ_FALSE);
-	contact_uri = pjsip_uri_get_uri(tree->dlg->local.contact->uri);
-	pjsip_sip_uri_assign(tree->dlg->pool, sub->uri, contact_uri);
+	request_uri = pjsip_uri_get_uri(rdata->msg_info.msg->line.req.uri);
+	pjsip_sip_uri_assign(tree->dlg->pool, sub->uri, request_uri);
 	pj_strdup2(tree->dlg->pool, &sub->uri->user, resource);
 
 	/* If there is any persistence information available for this subscription that was persisted
@@ -1302,20 +1303,22 @@
 /*!
  * \brief Create a tree of virtual subscriptions based on a resource tree node.
  *
+ * \param param rdata The inbound SUBSCRIBE message
  * \param handler The handler to supply to leaf subscriptions.
  * \param resource The requested resource for this subscription.
  * \param generator Body generator to use for leaf subscriptions.
  * \param tree The root of the subscription tree.
  * \param current The tree node that corresponds to the subscription being created.
  */
-static struct ast_sip_subscription *create_virtual_subscriptions(const struct ast_sip_subscription_handler *handler,
+static struct ast_sip_subscription *create_virtual_subscriptions(pjsip_rx_data *rdata,
+		const struct ast_sip_subscription_handler *handler,
 		const char *resource, struct ast_sip_pubsub_body_generator *generator,
 		struct sip_subscription_tree *tree, struct tree_node *current)
 {
 	int i;
 	struct ast_sip_subscription *sub;
 
-	sub = allocate_subscription(handler, resource, current->display_name, tree);
+	sub = allocate_subscription(rdata, handler, resource, current->display_name, tree);
 	if (!sub) {
 		return NULL;
 	}
@@ -1328,7 +1331,7 @@
 		struct ast_sip_subscription *child;
 		struct tree_node *child_node = AST_VECTOR_GET(&current->children, i);
 
-		child = create_virtual_subscriptions(handler, child_node->resource, generator,
+		child = create_virtual_subscriptions(rdata, handler, child_node->resource, generator,
 				tree, child_node);
 
 		if (!child) {
@@ -1546,7 +1549,7 @@
 	/* Persistence information needs to be available for all the subscriptions */
 	sub_tree->persistence = ao2_bump(persistence);
 
-	sub_tree->root = create_virtual_subscriptions(handler, resource, generator, sub_tree, tree->root);
+	sub_tree->root = create_virtual_subscriptions(rdata, handler, resource, generator, sub_tree, tree->root);
 	if (AST_VECTOR_SIZE(&sub_tree->root->children) > 0) {
 		sub_tree->is_list = 1;
 	}
@@ -1891,7 +1894,8 @@
 }
 
 /* XXX This function is not used. */
-struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_subscription_handler *handler,
+struct ast_sip_subscription *ast_sip_create_subscription(pjsip_rx_data *rdata,
+		const struct ast_sip_subscription_handler *handler,
 		struct ast_sip_endpoint *endpoint, const char *resource)
 {
 	struct ast_sip_subscription *sub;
@@ -1907,7 +1911,7 @@
 		return NULL;
 	}
 
-	sub = allocate_subscription(handler, resource, NULL, sub_tree);
+	sub = allocate_subscription(rdata, handler, resource, NULL, sub_tree);
 	if (!sub) {
 		ao2_cleanup(sub_tree);
 		return NULL;
@@ -4045,7 +4049,7 @@
 			resp = build_resource_tree(endpoint, handler, resource, &tree,
 				ast_sip_pubsub_has_eventlist_support(rdata));
 			if (PJSIP_IS_STATUS_IN_CLASS(resp, 200)) {
-				new_root = create_virtual_subscriptions(handler, resource, generator, sub_tree, tree.root);
+				new_root = create_virtual_subscriptions(rdata, handler, resource, generator, sub_tree, tree.root);
 				if (new_root) {
 					if (cmp_subscription_childrens(old_root, new_root)) {
 						ast_debug(1, "RLS '%s->%s' was modified, regenerate it\n", ast_sorcery_object_get_id(endpoint), old_root->resource);

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18193
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I1fcfc08fd589677f40608c59a4e143c45ee05f6c
Gerrit-Change-Number: 18193
Gerrit-PatchSet: 1
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220309/7daecbfb/attachment.html>


More information about the asterisk-code-review mailing list