<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15345">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Stasis/messaging: tech subscriptions conflict with endpoint subscriptions.<br><br>When both a tech subscription and an endpoint subscription exist for a given<br>endpoint, TextMessageReceived events are dispatched to the tech subscription<br>only.<br><br>ASTERISK-29229<br><br>Change-Id: I9eac4cba5f9e27285a282509395347abc58fc2b8<br>---<br>M res/stasis/messaging.c<br>1 file changed, 36 insertions(+), 22 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/stasis/messaging.c b/res/stasis/messaging.c</span><br><span>index 78d6494..2caa8ed 100644</span><br><span>--- a/res/stasis/messaging.c</span><br><span>+++ b/res/stasis/messaging.c</span><br><span>@@ -289,18 +289,42 @@</span><br><span> return json_obj;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void dispatch_message(struct message_subscription *sub, const char *endpoint_name, struct ast_json *json_msg)</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%);">+ ast_debug(3, "Dispatching message to subscription %s for endpoint %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ sub->token,</span><br><span style="color: hsl(120, 100%, 40%);">+ endpoint_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < AST_VECTOR_SIZE(&sub->applications); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct application_tuple *tuple = AST_VECTOR_GET(&sub->applications, i);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ tuple->callback(endpoint_name, json_msg, tuple->pvt);</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> static int handle_msg_cb(struct ast_msg *msg)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* We have at most 3 subscriptions: TECH_WILDCARD, tech itself, and endpoint. */</span><br><span style="color: hsl(120, 100%, 40%);">+ struct message_subscription *matching_subscriptions[3];</span><br><span> struct message_subscription *sub;</span><br><span style="color: hsl(0, 100%, 40%);">- int i;</span><br><span style="color: hsl(120, 100%, 40%);">+ int i, j;</span><br><span style="color: hsl(120, 100%, 40%);">+ int result;</span><br><span> char buf[256];</span><br><span> const char *endpoint_name;</span><br><span> struct ast_json *json_msg;</span><br><span> </span><br><span> msg_to_endpoint(msg, buf, sizeof(buf));</span><br><span style="color: hsl(120, 100%, 40%);">+ endpoint_name = buf;</span><br><span style="color: hsl(120, 100%, 40%);">+ json_msg = msg_to_json(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!json_msg) {</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%);">+ result = -1;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Find subscriptions to TECH_WILDCARD and to the endpoint's technology. */</span><br><span> ast_rwlock_rdlock(&tech_subscriptions_lock);</span><br><span style="color: hsl(0, 100%, 40%);">- for (i = 0; i < AST_VECTOR_SIZE(&tech_subscriptions); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0, j = 0; i < AST_VECTOR_SIZE(&tech_subscriptions) && j < 2; i++) {</span><br><span> sub = AST_VECTOR_GET(&tech_subscriptions, i);</span><br><span> </span><br><span> if (!sub) {</span><br><span>@@ -309,40 +333,30 @@</span><br><span> </span><br><span> if (!strcmp(sub->token, TECH_WILDCARD)</span><br><span> || !strncasecmp(sub->token, buf, strlen(sub->token))) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_rwlock_unlock(&tech_subscriptions_lock);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_bump(sub);</span><br><span style="color: hsl(0, 100%, 40%);">- endpoint_name = buf;</span><br><span style="color: hsl(0, 100%, 40%);">- goto match;</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(sub, +1);</span><br><span style="color: hsl(120, 100%, 40%);">+ matching_subscriptions[j++] = sub;</span><br><span> }</span><br><span> }</span><br><span> ast_rwlock_unlock(&tech_subscriptions_lock);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Find the subscription to this particular endpoint. */</span><br><span> sub = ao2_find(endpoint_subscriptions, buf, OBJ_SEARCH_KEY);</span><br><span> if (sub) {</span><br><span style="color: hsl(0, 100%, 40%);">- endpoint_name = buf;</span><br><span style="color: hsl(0, 100%, 40%);">- goto match;</span><br><span style="color: hsl(120, 100%, 40%);">+ matching_subscriptions[j++] = sub;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Dispatch the message to all matching subscriptions. */</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < j; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ sub = matching_subscriptions[i];</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-match:</span><br><span style="color: hsl(0, 100%, 40%);">- ast_debug(3, "Dispatching message for %s\n", endpoint_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ dispatch_message(sub, endpoint_name, json_msg);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- json_msg = msg_to_json(msg);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!json_msg) {</span><br><span> ao2_ref(sub, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- for (i = 0; i < AST_VECTOR_SIZE(&sub->applications); i++) {</span><br><span style="color: hsl(0, 100%, 40%);">- struct application_tuple *tuple = AST_VECTOR_GET(&sub->applications, i);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- tuple->callback(endpoint_name, json_msg, tuple->pvt);</span><br><span style="color: hsl(120, 100%, 40%);">+ result = 0;</span><br><span> }</span><br><span> </span><br><span> ast_json_unref(json_msg);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(sub, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ return result;</span><br><span> }</span><br><span> </span><br><span> struct ast_msg_handler ari_msg_handler = {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15345">change 15345</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/+/15345"/><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: I9eac4cba5f9e27285a282509395347abc58fc2b8 </div>
<div style="display:none"> Gerrit-Change-Number: 15345 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Jean Aunis - Prescom <jean.aunis@prescom.fr> </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-MessageType: merged </div>