<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18044">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_pubsub: update RLS to reflect the changes to the lists<br><br>This patch makes the Resource List Subscriptions (RLS) dynamic.<br>The asterisk updates the current subscriptions to reflect the changes<br>to the list on the subscriptions refresh. If list items are added,<br>removed, updated or do not exist anymore, the asterisk regenerates<br>the resource list.<br><br>ASTERISK-29906 #close<br><br>Change-Id: Icee8c00459a7aaa43c643d77ce6f16fb7ab037d3<br>---<br>A doc/CHANGES-staging/rls_refresh.txt<br>M res/res_pjsip_pubsub.c<br>2 files changed, 108 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/rls_refresh.txt b/doc/CHANGES-staging/rls_refresh.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..fb36160</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/rls_refresh.txt</span><br><span>@@ -0,0 +1,7 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: res_pjsip_pubsub</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+The Resource List Subscriptions (RLS) is dynamic now.</span><br><span style="color: hsl(120, 100%, 40%);">+The asterisk now updates current subscriptions to reflect the changes</span><br><span style="color: hsl(120, 100%, 40%);">+to the list on subscription refresh. If list items are added,</span><br><span style="color: hsl(120, 100%, 40%);">+removed, updated or do not exist anymore, the asterisk regenerates</span><br><span style="color: hsl(120, 100%, 40%);">+the resource list.</span><br><span>diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c</span><br><span>index dae3fef..21174ae 100644</span><br><span>--- a/res/res_pjsip_pubsub.c</span><br><span>+++ b/res/res_pjsip_pubsub.c</span><br><span>@@ -475,6 +475,10 @@</span><br><span> * Only used for reliable transports.</span><br><span> */</span><br><span> pjsip_transport *transport;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Indicator if initial notify should be generated.</span><br><span style="color: hsl(120, 100%, 40%);">+ * Used to refresh modified RLS.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int generate_initial_notify;</span><br><span> };</span><br><span> </span><br><span> /*!</span><br><span>@@ -3902,6 +3906,15 @@</span><br><span> set_state_terminated(sub_tree->root);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (sub_tree->generate_initial_notify) {</span><br><span style="color: hsl(120, 100%, 40%);">+ sub_tree->generate_initial_notify = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (generate_initial_notify(sub_tree->root)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_evsub_terminate(sub_tree->evsub, PJ_TRUE);</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_dlg_dec_lock(dlg);</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</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%);">+</span><br><span> send_notify(sub_tree, 1);</span><br><span> </span><br><span> ast_test_suite_event_notify(sub_tree->root->subscription_state == PJSIP_EVSUB_STATE_TERMINATED ?</span><br><span>@@ -3927,6 +3940,52 @@</span><br><span> }</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Compare strings for equality checking for NULL.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This function considers NULL values as empty strings.</span><br><span style="color: hsl(120, 100%, 40%);">+ * This means NULL or empty strings are equal.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 The strings are equal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 1 The strings are not equal</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int cmp_strings(char *s1, char *s2)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(s1) && !ast_strlen_zero(s2)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return strcmp(s1, s2);</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%);">+ return ast_strlen_zero(s1) == ast_strlen_zero(s2) ? 0 : 1;</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%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief compares the childrens of two ast_sip_subscription s1 and s2</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 The s1 childrens match the s2 childrens</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 1 The s1 childrens do not match the s2 childrens</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int cmp_subscription_childrens(struct ast_sip_subscription *s1, struct ast_sip_subscription *s2)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int i;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (AST_VECTOR_SIZE(&s1->children) != AST_VECTOR_SIZE(&s2->children)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</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%);">+ for (i = 0; i < AST_VECTOR_SIZE(&s1->children); ++i) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_subscription *c1 = AST_VECTOR_GET(&s1->children, i);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_subscription *c2 = AST_VECTOR_GET(&s2->children, i);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (cmp_strings(c1->resource, c2->resource)</span><br><span style="color: hsl(120, 100%, 40%);">+ || cmp_strings(c1->display_name, c2->display_name)) {</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</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%);">+/*!</span><br><span> * \brief Called whenever an in-dialog SUBSCRIBE is received</span><br><span> *</span><br><span> * This includes both SUBSCRIBE requests that actually refresh the subscription</span><br><span>@@ -3966,6 +4025,48 @@</span><br><span> sub_tree->state = SIP_SUB_TREE_TERMINATE_PENDING;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (sub_tree->state == SIP_SUB_TREE_NORMAL && sub_tree->is_list) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* update RLS */</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *resource = sub_tree->root->resource;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_subscription *old_root = sub_tree->root;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_subscription *new_root = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_subscription_handler *handler = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_pubsub_body_generator *generator = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((endpoint = ast_pjsip_rdata_get_endpoint(rdata))</span><br><span style="color: hsl(120, 100%, 40%);">+ && (handler = subscription_get_handler_from_rdata(rdata, ast_sorcery_object_get_id(endpoint)))</span><br><span style="color: hsl(120, 100%, 40%);">+ && (generator = subscription_get_generator_from_rdata(rdata, handler))) {</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ struct resource_tree tree;</span><br><span style="color: hsl(120, 100%, 40%);">+ int resp;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ memset(&tree, 0, sizeof(tree));</span><br><span style="color: hsl(120, 100%, 40%);">+ resp = build_resource_tree(endpoint, handler, resource, &tree,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_pubsub_has_eventlist_support(rdata));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (PJSIP_IS_STATUS_IN_CLASS(resp, 200)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ new_root = create_virtual_subscriptions(handler, resource, generator, sub_tree, tree.root);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (new_root) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (cmp_subscription_childrens(old_root, new_root)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "RLS '%s->%s' was modified, regenerate it\n", ast_sorcery_object_get_id(endpoint), old_root->resource);</span><br><span style="color: hsl(120, 100%, 40%);">+ new_root->version = old_root->version;</span><br><span style="color: hsl(120, 100%, 40%);">+ sub_tree->root = new_root;</span><br><span style="color: hsl(120, 100%, 40%);">+ sub_tree->generate_initial_notify = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ shutdown_subscriptions(old_root);</span><br><span style="color: hsl(120, 100%, 40%);">+ destroy_subscriptions(old_root);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ destroy_subscriptions(new_root);</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%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ sub_tree->state = SIP_SUB_TREE_TERMINATE_PENDING;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_evsub_terminate(sub_tree->evsub, PJ_TRUE);</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%);">+ resource_tree_destroy(&tree);</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%);">+</span><br><span> subscription_persistence_update(sub_tree, rdata, SUBSCRIPTION_PERSISTENCE_REFRESHED);</span><br><span> </span><br><span> if (ast_sip_push_task(sub_tree->serializer, serialized_pubsub_on_refresh_timeout, ao2_bump(sub_tree))) {</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18044">change 18044</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/+/18044"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: Icee8c00459a7aaa43c643d77ce6f16fb7ab037d3 </div>
<div style="display:none"> Gerrit-Change-Number: 18044 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: Alexei Gradinari <alex2grad@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>