[Asterisk-code-review] Stasis/messaging: tech subscriptions conflict with endpoint subscript... (asterisk[master])
Jean Aunis - Prescom
asteriskteam at digium.com
Wed Dec 30 08:02:30 CST 2020
Jean Aunis - Prescom has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15301 )
Change subject: Stasis/messaging: tech subscriptions conflict with endpoint subscriptions
......................................................................
Stasis/messaging: tech subscriptions conflict with endpoint subscriptions
When both a tech subscription and an endpoint subscription exist for a given
endpoint, TextMessageReceived events are dispatched to the tech subscription
only.
ASTERISK-29229
Change-Id: I9eac4cba5f9e27285a282509395347abc58fc2b8
---
M res/stasis/messaging.c
1 file changed, 23 insertions(+), 24 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/01/15301/1
diff --git a/res/stasis/messaging.c b/res/stasis/messaging.c
index 78d6494..0e00f3c 100644
--- a/res/stasis/messaging.c
+++ b/res/stasis/messaging.c
@@ -289,15 +289,33 @@
return json_obj;
}
+static void dispatch_message(struct message_subscription *sub, const char *endpoint_name, struct ast_json *json_msg) {
+ int i;
+
+ ast_debug(3, "Dispatching message to subscription %s for endpoint %s\n", sub->token, endpoint_name);
+ for (i = 0; i < AST_VECTOR_SIZE(&sub->applications); i++) {
+ struct application_tuple *tuple = AST_VECTOR_GET(&sub->applications, i);
+
+ tuple->callback(endpoint_name, json_msg, tuple->pvt);
+ }
+}
+
static int handle_msg_cb(struct ast_msg *msg)
{
struct message_subscription *sub;
int i;
+ int result;
char buf[256];
const char *endpoint_name;
struct ast_json *json_msg;
msg_to_endpoint(msg, buf, sizeof(buf));
+ endpoint_name = buf;
+ json_msg = msg_to_json(msg);
+ if(!json_msg) {
+ return -1;
+ }
+ result = -1;
ast_rwlock_rdlock(&tech_subscriptions_lock);
for (i = 0; i < AST_VECTOR_SIZE(&tech_subscriptions); i++) {
@@ -309,40 +327,21 @@
if (!strcmp(sub->token, TECH_WILDCARD)
|| !strncasecmp(sub->token, buf, strlen(sub->token))) {
- ast_rwlock_unlock(&tech_subscriptions_lock);
- ao2_bump(sub);
- endpoint_name = buf;
- goto match;
+ result = 0;
+ dispatch_message(sub, endpoint_name, json_msg);
}
}
ast_rwlock_unlock(&tech_subscriptions_lock);
sub = ao2_find(endpoint_subscriptions, buf, OBJ_SEARCH_KEY);
if (sub) {
- endpoint_name = buf;
- goto match;
- }
-
- return -1;
-
-match:
- ast_debug(3, "Dispatching message for %s\n", endpoint_name);
-
- json_msg = msg_to_json(msg);
- if (!json_msg) {
+ result = 0;
+ dispatch_message(sub, endpoint_name, json_msg);
ao2_ref(sub, -1);
- return -1;
- }
-
- for (i = 0; i < AST_VECTOR_SIZE(&sub->applications); i++) {
- struct application_tuple *tuple = AST_VECTOR_GET(&sub->applications, i);
-
- tuple->callback(endpoint_name, json_msg, tuple->pvt);
}
ast_json_unref(json_msg);
- ao2_ref(sub, -1);
- return 0;
+ return result;
}
struct ast_msg_handler ari_msg_handler = {
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15301
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I9eac4cba5f9e27285a282509395347abc58fc2b8
Gerrit-Change-Number: 15301
Gerrit-PatchSet: 1
Gerrit-Owner: Jean Aunis - Prescom <jean.aunis at prescom.fr>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20201230/f29c75d0/attachment.html>
More information about the asterisk-code-review
mailing list