From 7a4a83ab27ac7f9028730c4b159e0964af88f276 Mon Sep 17 00:00:00 2001 From: Alexei Gradinari Date: Tue, 15 Mar 2022 13:24:18 -0400 Subject: [PATCH] res_pjsip_pubsub: RLS '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 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 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. ASTERISK-29961 #close Change-Id: I1fcfc08fd589677f40608c59a4e143c45ee05f6c --- res/res_pjsip_pubsub.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c index 21174aeaa4..1d136955bf 100644 --- a/res/res_pjsip_pubsub.c +++ b/res/res_pjsip_pubsub.c @@ -1257,7 +1257,14 @@ static struct ast_sip_subscription *allocate_subscription(const struct ast_sip_s const char *resource, const char *display_name, struct sip_subscription_tree *tree) { struct ast_sip_subscription *sub; - pjsip_sip_uri *contact_uri; + pjsip_msg *msg; + pjsip_sip_uri *request_uri; + + msg = ast_sip_mod_data_get(tree->dlg->mod_data, pubsub_module.id, MOD_DATA_MSG); + if (!msg) { + ast_log(LOG_ERROR, "No dialog message saved for SIP subscription. Cannot allocate subscription for resource %s\n", resource); + return NULL; + } sub = ast_calloc(1, sizeof(*sub) + strlen(resource) + 1); if (!sub) { @@ -1280,8 +1287,8 @@ static struct ast_sip_subscription *allocate_subscription(const struct ast_sip_s } 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(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 -- 2.47.2