]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip_messaging: Ensure MESSAGE_SEND_STATUS is set properly
authorSean Bright <sean.bright@gmail.com>
Mon, 27 Jan 2020 14:03:38 +0000 (09:03 -0500)
committerSean Bright <sean.bright@gmail.com>
Mon, 27 Jan 2020 17:07:25 +0000 (12:07 -0500)
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

res/res_pjsip_messaging.c

index 76d37f2b3be46afac9715b84a4bd9e1582292269..81de9f8e6c50b1711e1f1ada7f1b83ef5e3f0a42 100644 (file)
@@ -638,7 +638,7 @@ static struct msg_data *msg_data_create(const struct ast_msg *msg, const char *t
 
 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",
@@ -682,24 +682,28 @@ static int msg_send(void *data)
                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 = {