<p>Jean Aunis - Prescom has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15301">View Change</a></p><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, 23 insertions(+), 24 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/01/15301/1</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..0e00f3c 100644</span><br><span>--- a/res/stasis/messaging.c</span><br><span>+++ b/res/stasis/messaging.c</span><br><span>@@ -289,15 +289,33 @@</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%);">+ 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", sub->token, 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> struct message_subscription *sub;</span><br><span> int i;</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> ast_rwlock_rdlock(&tech_subscriptions_lock);</span><br><span> for (i = 0; i < AST_VECTOR_SIZE(&tech_subscriptions); i++) {</span><br><span>@@ -309,40 +327,21 @@</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%);">+ result = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ dispatch_message(sub, endpoint_name, json_msg);</span><br><span> }</span><br><span> }</span><br><span> ast_rwlock_unlock(&tech_subscriptions_lock);</span><br><span> </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(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</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%);">-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(0, 100%, 40%);">-</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 style="color: hsl(120, 100%, 40%);">+ result = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ dispatch_message(sub, endpoint_name, 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> }</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/+/15301">change 15301</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/+/15301"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I9eac4cba5f9e27285a282509395347abc58fc2b8 </div>
<div style="display:none"> Gerrit-Change-Number: 15301 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Jean Aunis - Prescom <jean.aunis@prescom.fr> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>