<p>Alexei Gradinari has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18193">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_pubsub: 'uri' list attribute mismatch with SUBSCRIBE request<br><br>When asterisk generates the RLMI part of NOTIFY request,<br>the asterisk uses the local contact uri instead of the URI to which<br>the SUBSCRIBE request is sent.<br>Because of this mismatch some IP phones (for example Cisco 5XX) ignore<br>this list.<br><br>According<br>https://datatracker.ietf.org/doc/html/rfc4662#section-5.2<br>  The first mandatory <list> attribute is "uri", which contains the uri<br>  that corresponds to the list. Typically, this is the URI to which<br>  the SUBSCRIBE request was sent.<br>https://datatracker.ietf.org/doc/html/rfc4662#section-5.3<br>  The "uri" attribute identifies the resource to which the <resource><br>  element corresponds. Typically, this will be a SIP URI that, if<br>  subscribed to, would return the state of the resource.<br><br>This patch makes asterisk to generate URI using SUBSCRIBE request URI.<br><br>Change-Id: I1fcfc08fd589677f40608c59a4e143c45ee05f6c<br>---<br>M include/asterisk/res_pjsip_pubsub.h<br>M res/res_pjsip_pubsub.c<br>2 files changed, 18 insertions(+), 12 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/93/18193/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/res_pjsip_pubsub.h b/include/asterisk/res_pjsip_pubsub.h</span><br><span>index aca1141..b4132d1 100644</span><br><span>--- a/include/asterisk/res_pjsip_pubsub.h</span><br><span>+++ b/include/asterisk/res_pjsip_pubsub.h</span><br><span>@@ -357,11 +357,13 @@</span><br><span>  * When a subscriber wishes to create a subscription, it may call this function</span><br><span>  * to allocate resources and to send the initial SUBSCRIBE out.</span><br><span>  *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param param rdata The inbound SUBSCRIBE message</span><br><span>  * \param handler The subscriber that is making the request.</span><br><span>  * \param endpoint The endpoint to whome the SUBSCRIBE will be sent.</span><br><span>  * \param resource The resource to place in the SUBSCRIBE's Request-URI.</span><br><span>  */</span><br><span style="color: hsl(0, 100%, 40%);">-struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_subscription_handler *handler,</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_sip_subscription *ast_sip_create_subscription(pjsip_rx_data *rdata,</span><br><span style="color: hsl(120, 100%, 40%);">+            const struct ast_sip_subscription_handler *handler,</span><br><span>          struct ast_sip_endpoint *endpoint, const char *resource);</span><br><span> </span><br><span> /*!</span><br><span>diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c</span><br><span>index 21174ae..56b936c 100644</span><br><span>--- a/res/res_pjsip_pubsub.c</span><br><span>+++ b/res/res_pjsip_pubsub.c</span><br><span>@@ -1253,11 +1253,12 @@</span><br><span>  destroy_subscription(root);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static struct ast_sip_subscription *allocate_subscription(const struct ast_sip_subscription_handler *handler,</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_sip_subscription *allocate_subscription(pjsip_rx_data *rdata,</span><br><span style="color: hsl(120, 100%, 40%);">+            const struct ast_sip_subscription_handler *handler,</span><br><span>          const char *resource, const char *display_name, struct sip_subscription_tree *tree)</span><br><span> {</span><br><span>     struct ast_sip_subscription *sub;</span><br><span style="color: hsl(0, 100%, 40%);">-       pjsip_sip_uri *contact_uri;</span><br><span style="color: hsl(120, 100%, 40%);">+   pjsip_sip_uri *request_uri;</span><br><span> </span><br><span>      sub = ast_calloc(1, sizeof(*sub) + strlen(resource) + 1);</span><br><span>    if (!sub) {</span><br><span>@@ -1280,8 +1281,8 @@</span><br><span>  }</span><br><span> </span><br><span>        sub->uri = pjsip_sip_uri_create(tree->dlg->pool, PJ_FALSE);</span><br><span style="color: hsl(0, 100%, 40%);">-    contact_uri = pjsip_uri_get_uri(tree->dlg->local.contact->uri);</span><br><span style="color: hsl(0, 100%, 40%);">-        pjsip_sip_uri_assign(tree->dlg->pool, sub->uri, contact_uri);</span><br><span style="color: hsl(120, 100%, 40%);">+        request_uri = pjsip_uri_get_uri(rdata->msg_info.msg->line.req.uri);</span><br><span style="color: hsl(120, 100%, 40%);">+     pjsip_sip_uri_assign(tree->dlg->pool, sub->uri, request_uri);</span><br><span>       pj_strdup2(tree->dlg->pool, &sub->uri->user, resource);</span><br><span> </span><br><span>  /* If there is any persistence information available for this subscription that was persisted</span><br><span>@@ -1302,20 +1303,22 @@</span><br><span> /*!</span><br><span>  * \brief Create a tree of virtual subscriptions based on a resource tree node.</span><br><span>  *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param param rdata The inbound SUBSCRIBE message</span><br><span>  * \param handler The handler to supply to leaf subscriptions.</span><br><span>  * \param resource The requested resource for this subscription.</span><br><span>  * \param generator Body generator to use for leaf subscriptions.</span><br><span>  * \param tree The root of the subscription tree.</span><br><span>  * \param current The tree node that corresponds to the subscription being created.</span><br><span>  */</span><br><span style="color: hsl(0, 100%, 40%);">-static struct ast_sip_subscription *create_virtual_subscriptions(const struct ast_sip_subscription_handler *handler,</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_sip_subscription *create_virtual_subscriptions(pjsip_rx_data *rdata,</span><br><span style="color: hsl(120, 100%, 40%);">+                const struct ast_sip_subscription_handler *handler,</span><br><span>          const char *resource, struct ast_sip_pubsub_body_generator *generator,</span><br><span>               struct sip_subscription_tree *tree, struct tree_node *current)</span><br><span> {</span><br><span>  int i;</span><br><span>       struct ast_sip_subscription *sub;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   sub = allocate_subscription(handler, resource, current->display_name, tree);</span><br><span style="color: hsl(120, 100%, 40%);">+       sub = allocate_subscription(rdata, handler, resource, current->display_name, tree);</span><br><span>       if (!sub) {</span><br><span>          return NULL;</span><br><span>         }</span><br><span>@@ -1328,7 +1331,7 @@</span><br><span>            struct ast_sip_subscription *child;</span><br><span>          struct tree_node *child_node = AST_VECTOR_GET(&current->children, i);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-                child = create_virtual_subscriptions(handler, child_node->resource, generator,</span><br><span style="color: hsl(120, 100%, 40%);">+             child = create_virtual_subscriptions(rdata, handler, child_node->resource, generator,</span><br><span>                             tree, child_node);</span><br><span> </span><br><span>               if (!child) {</span><br><span>@@ -1546,7 +1549,7 @@</span><br><span>        /* Persistence information needs to be available for all the subscriptions */</span><br><span>        sub_tree->persistence = ao2_bump(persistence);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   sub_tree->root = create_virtual_subscriptions(handler, resource, generator, sub_tree, tree->root);</span><br><span style="color: hsl(120, 100%, 40%);">+      sub_tree->root = create_virtual_subscriptions(rdata, handler, resource, generator, sub_tree, tree->root);</span><br><span>      if (AST_VECTOR_SIZE(&sub_tree->root->children) > 0) {</span><br><span>           sub_tree->is_list = 1;</span><br><span>    }</span><br><span>@@ -1891,7 +1894,8 @@</span><br><span> }</span><br><span> </span><br><span> /* XXX This function is not used. */</span><br><span style="color: hsl(0, 100%, 40%);">-struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_subscription_handler *handler,</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_sip_subscription *ast_sip_create_subscription(pjsip_rx_data *rdata,</span><br><span style="color: hsl(120, 100%, 40%);">+                const struct ast_sip_subscription_handler *handler,</span><br><span>          struct ast_sip_endpoint *endpoint, const char *resource)</span><br><span> {</span><br><span>        struct ast_sip_subscription *sub;</span><br><span>@@ -1907,7 +1911,7 @@</span><br><span>            return NULL;</span><br><span>         }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   sub = allocate_subscription(handler, resource, NULL, sub_tree);</span><br><span style="color: hsl(120, 100%, 40%);">+       sub = allocate_subscription(rdata, handler, resource, NULL, sub_tree);</span><br><span>       if (!sub) {</span><br><span>          ao2_cleanup(sub_tree);</span><br><span>               return NULL;</span><br><span>@@ -4045,7 +4049,7 @@</span><br><span>                         resp = build_resource_tree(endpoint, handler, resource, &tree,</span><br><span>                           ast_sip_pubsub_has_eventlist_support(rdata));</span><br><span>                        if (PJSIP_IS_STATUS_IN_CLASS(resp, 200)) {</span><br><span style="color: hsl(0, 100%, 40%);">-                              new_root = create_virtual_subscriptions(handler, resource, generator, sub_tree, tree.root);</span><br><span style="color: hsl(120, 100%, 40%);">+                           new_root = create_virtual_subscriptions(rdata, handler, resource, generator, sub_tree, tree.root);</span><br><span>                           if (new_root) {</span><br><span>                                      if (cmp_subscription_childrens(old_root, new_root)) {</span><br><span>                                                ast_debug(1, "RLS '%s->%s' was modified, regenerate it\n", ast_sorcery_object_get_id(endpoint), old_root->resource);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18193">change 18193</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/+/18193"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I1fcfc08fd589677f40608c59a4e143c45ee05f6c </div>
<div style="display:none"> Gerrit-Change-Number: 18193 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Alexei Gradinari <alex2grad@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>