[asterisk-commits] mmichelson: branch mmichelson/pool_shark r380670 - /team/mmichelson/pool_shar...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 31 12:36:00 CST 2013


Author: mmichelson
Date: Thu Jan 31 12:35:56 2013
New Revision: 380670

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380670
Log:
Do a cleaner allocation method for new request data on incoming INVITE.


Modified:
    team/mmichelson/pool_shark/res/res_sip_session.c

Modified: team/mmichelson/pool_shark/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark/res/res_sip_session.c?view=diff&rev=380670&r1=380669&r2=380670
==============================================================================
--- team/mmichelson/pool_shark/res/res_sip_session.c (original)
+++ team/mmichelson/pool_shark/res/res_sip_session.c Thu Jan 31 12:35:56 2013
@@ -694,14 +694,22 @@
 	struct ast_sip_work *work;
 };
 
-static struct new_request_data *new_request_data_alloc(pjsip_rx_data *rdata, struct ast_sip_work *work)
+static struct new_request_data *new_request_data_alloc(pjsip_rx_data *rdata)
 {
 	struct new_request_data *nrd = ast_calloc(1, sizeof(*nrd));
 	if (!nrd) {
 		return NULL;
 	}
-	nrd->rdata = rdata;
-	nrd->work = work;
+	if (pjsip_rx_data_clone(rdata, 0, &nrd->rdata) != PJ_SUCCESS) {
+		ast_free(nrd);
+		return NULL;
+	}
+	nrd->work = ast_sip_create_work();
+	if (!nrd->work) {
+		pjsip_rx_data_free_cloned(nrd->rdata);
+		ast_free(nrd);
+		return NULL;
+	}
 	return nrd;
 }
 
@@ -868,10 +876,8 @@
  */
 static pj_bool_t session_on_rx_request(pjsip_rx_data *rdata)
 { 
-	pjsip_rx_data *clone;
-	struct ast_sip_work *work;
 	struct new_request_data *nrd;
-	pj_status_t res = PJ_FALSE;
+	pj_status_t handled = PJ_FALSE;
 	pjsip_dialog *dlg = pjsip_rdata_get_dlg(rdata);
 
 	switch (rdata->msg_info.msg->line.req.method.id) {
@@ -880,32 +886,18 @@
 			ast_log(LOG_WARNING, "on_rx_request called for INVITE in mid-dialog?\n");
 			break;
 		}
-		res = PJ_TRUE;
-
-		if (pjsip_rx_data_clone(rdata, 0, &clone) != PJ_SUCCESS) {
+		handled = PJ_TRUE;
+
+		nrd = new_request_data_alloc(rdata);
+		if (!nrd) {
 			pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
 			break;
 		}
-
-		work = ast_sip_create_work();
-		if (!work) {
-			pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
-			pjsip_rx_data_free_cloned(clone);
-			break;
-		}
-
-		nrd = new_request_data_alloc(clone, work);
-		if (!nrd) {
-			pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
-			pjsip_rx_data_free_cloned(clone);
-			ast_sip_destroy_work(work);
-			break;
-		}
-		if (ast_sip_push_task(work, handle_new_invite_request, nrd)) {
+		if (ast_sip_push_task(nrd->work, handle_new_invite_request, nrd)) {
 			ast_log(LOG_WARNING, "Failed to pass new INVITE to the threadpool\n");
 			pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
-			pjsip_rx_data_free_cloned(clone);
-			ast_sip_destroy_work(work);
+			pjsip_rx_data_free_cloned(nrd->rdata);
+			ast_sip_destroy_work(nrd->work);
 			ast_free(nrd);
 		}
 		break;
@@ -916,7 +908,7 @@
 		break;
 	}
 
-	return res;
+	return handled;
 }
 
 static void session_on_tsx_state(pjsip_transaction *tsx, pjsip_event *event)




More information about the asterisk-commits mailing list