[Asterisk-code-review] res pjsip: Handle invocation of callback on outgoing request... (asterisk[13])

Joshua Colp asteriskteam at digium.com
Tue Jan 31 11:24:47 CST 2017


Joshua Colp has uploaded a new change for review. ( https://gerrit.asterisk.org/4846 )

Change subject: res_pjsip: Handle invocation of callback on outgoing request when error occurs.
......................................................................

res_pjsip: Handle invocation of callback on outgoing request when error occurs.

There are some error cases in PJSIP when sending a request that will
result in the callback for the request being invoked. The code did not
handle this case and assumed on every error case that the callback was
not invoked.

The code has been changed to check whether the callback has been invoked and
if so to absord the error and treat it as a success.

ASTERISK-26679

Change-Id: I563982ba204da5aa1428989a11c06dd9087fea91
---
M res/res_pjsip.c
1 file changed, 12 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/46/4846/1

diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 12c3baa..88f84d2 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -3538,6 +3538,7 @@
 	pj_status_t ret_val;
 	pjsip_endpoint *endpt = ast_sip_get_pjsip_endpoint();
 	pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
+	char errmsg[PJ_ERR_MSG_SIZE];
 
 	if (!cb && token) {
 		/* Silly.  Without a callback we cannot do anything with token. */
@@ -3599,14 +3600,20 @@
 	 */
 	ao2_ref(req_wrapper, +1);
 	ret_val = pjsip_endpt_send_request(endpt, tdata, -1, req_wrapper, endpt_send_request_cb);
-	if (ret_val != PJ_SUCCESS) {
-		char errmsg[PJ_ERR_MSG_SIZE];
+	if (req_wrapper->cb_called) {
+		pj_strerror(ret_val, errmsg, sizeof(errmsg));
+		ast_log(LOG_ERROR, "Error %d '%s' sending %.*s request to endpoint %s\n",
+			(int) ret_val, errmsg, (int) pj_strlen(&tdata->msg->line.req.method.name),
+			pj_strbuf(&tdata->msg->line.req.method.name),
+			endpoint ? ast_sorcery_object_get_id(endpoint) : "<unknown>");
 
 		/*
-		 * endpt_send_request_cb is not expected to ever be called
-		 * because the request didn't get far enough to attempt
-		 * sending.
+		 * If the callback has been invoked absord any failure and turn it into a success
+		 * so the caller of this function does not try to perform any cleanup.
 		 */
+		ret_val = PJ_SUCCESS;
+	} else if (ret_val != PJ_SUCCESS) {
+		/* The callback was never invoked so we drop its reference */
 		ao2_ref(req_wrapper, -1);
 
 		/* Complain of failure to send the request. */

-- 
To view, visit https://gerrit.asterisk.org/4846
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I563982ba204da5aa1428989a11c06dd9087fea91
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list