[Asterisk-code-review] res_pjsip_messaging: Ensure MESSAGE_SEND_STATUS is set properly (asterisk[16])

Friendly Automation asteriskteam at digium.com
Tue Jan 28 10:17:53 CST 2020


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/13693 )

Change subject: res_pjsip_messaging: Ensure MESSAGE_SEND_STATUS is set properly
......................................................................

res_pjsip_messaging: Ensure MESSAGE_SEND_STATUS is set properly

We need to wait for the message sending callback to finish to know if
we succeeded or failed.

ASTERISK-25421 #close
Reported by:  Dmitriy Serov

Change-Id: I22b954398821d2caf4c6fe58f0607c8cfa378059
---
M res/res_pjsip_messaging.c
1 file changed, 10 insertions(+), 6 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/res/res_pjsip_messaging.c b/res/res_pjsip_messaging.c
index 930cf84..72b7d17 100644
--- a/res/res_pjsip_messaging.c
+++ b/res/res_pjsip_messaging.c
@@ -637,7 +637,7 @@
 
 static int msg_send(void *data)
 {
-	RAII_VAR(struct msg_data *, mdata, data, ao2_cleanup);
+	struct msg_data *mdata = data; /* The caller holds a reference */
 
 	const struct ast_sip_body body = {
 		.type = "text",
@@ -681,24 +681,28 @@
 		return -1;
 	}
 
-	return PJ_SUCCESS;
+	return 0;
 }
 
 static int sip_msg_send(const struct ast_msg *msg, const char *to, const char *from)
 {
 	struct msg_data *mdata;
+	int res;
 
 	if (ast_strlen_zero(to)) {
 		ast_log(LOG_ERROR, "SIP MESSAGE - a 'To' URI  must be specified\n");
 		return -1;
 	}
 
-	if (!(mdata = msg_data_create(msg, to, from)) ||
-	    ast_sip_push_task(message_serializer, msg_send, mdata)) {
-		ao2_cleanup(mdata);
+	mdata = msg_data_create(msg, to, from);
+	if (!mdata) {
 		return -1;
 	}
-	return 0;
+
+	res = ast_sip_push_task_wait_serializer(message_serializer, msg_send, mdata);
+	ao2_ref(mdata, -1);
+
+	return res;
 }
 
 static const struct ast_msg_tech msg_tech = {

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/13693
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I22b954398821d2caf4c6fe58f0607c8cfa378059
Gerrit-Change-Number: 13693
Gerrit-PatchSet: 2
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200128/ecbd15b3/attachment.html>


More information about the asterisk-code-review mailing list