[asterisk-commits] mmichelson: branch mmichelson/pool_shark2 r381642 - in /team/mmichelson/pool_...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Feb 18 11:32:02 CST 2013


Author: mmichelson
Date: Mon Feb 18 11:31:59 2013
New Revision: 381642

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=381642
Log:
Get rid of the ast_ wrappers for cloning and freeing pjsip_rx_data.

It was a decent enough idea, but actually making it bug free is going
to be difficult. Also, giving the distributor knowledge of what is stored
in the rdata's mod_data array breaks what little encapsulation already
exists, so it just feels very dirty. It may be possible to make things
more intricate, but the benefit is not that great.

The result now is that the endpoint needs to be retrieved from the
rdata before pushing a task to the serializer. This is not really
all that inconvenient.


Modified:
    team/mmichelson/pool_shark2/include/asterisk/res_sip.h
    team/mmichelson/pool_shark2/res/res_sip.exports.in
    team/mmichelson/pool_shark2/res/res_sip/sip_distributor.c
    team/mmichelson/pool_shark2/res/res_sip/sip_options.c
    team/mmichelson/pool_shark2/res/res_sip_session.c

Modified: team/mmichelson/pool_shark2/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/include/asterisk/res_sip.h?view=diff&rev=381642&r1=381641&r2=381642
==============================================================================
--- team/mmichelson/pool_shark2/include/asterisk/res_sip.h (original)
+++ team/mmichelson/pool_shark2/include/asterisk/res_sip.h Mon Feb 18 11:31:59 2013
@@ -735,29 +735,4 @@
  */
 struct ast_sip_endpoint *ast_pjsip_rdata_get_endpoint(pjsip_rx_data *rdata);
 
-/*!
- * \brief Clone a pjsip_rx_data structure
- *
- * This is a wrapper around pjsip_rx_data_clone(). The difference
- * is that this also attempts to copy mod_data from the original
- * rdata.
- *
- * This version should always be called by modules that are at priority
- * PJSIP_MOD_PRIORITY_DIALOG_USAGE or higher.
- * \param rdata The rdata to clone
- * \retval NULL Failure to copy
- * \retval non-NULL The cloned rdata
- */
-pjsip_rx_data *ast_pjsip_rx_data_clone(pjsip_rx_data *rdata);
-
-/*!
- * \brief Free a cloned rdata structure
- *
- * Use this to free a pjsip_rx_data that was created via the
- * \ref ast_pjsip_rx_data_clone function.
- *
- * \param rdata The cloned rdata to free
- */
-void ast_pjsip_rx_data_free_cloned(pjsip_rx_data *rdata);
-
 #endif /* _RES_SIP_H */

Modified: team/mmichelson/pool_shark2/res/res_sip.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/res/res_sip.exports.in?view=diff&rev=381642&r1=381641&r2=381642
==============================================================================
--- team/mmichelson/pool_shark2/res/res_sip.exports.in (original)
+++ team/mmichelson/pool_shark2/res/res_sip.exports.in Mon Feb 18 11:31:59 2013
@@ -27,8 +27,6 @@
 		LINKER_SYMBOL_PREFIXast_sip_get_endpoint_from_location;
 		LINKER_SYMBOL_PREFIXast_sip_endpoint_get_location;
 		LINKER_SYMBOL_PREFIXast_pjsip_rdata_get_endpoint;
-		LINKER_SYMBOL_PREFIXast_pjsip_rx_data_clone;
-		LINKER_SYMBOL_PREFIXast_pjsip_rx_data_free_cloned;
 		LINKER_SYMBOL_PREFIXpj_*;
 		LINKER_SYMBOL_PREFIXpjsip_*;
 		LINKER_SYMBOL_PREFIXpjmedia_*;

Modified: team/mmichelson/pool_shark2/res/res_sip/sip_distributor.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/res/res_sip/sip_distributor.c?view=diff&rev=381642&r1=381641&r2=381642
==============================================================================
--- team/mmichelson/pool_shark2/res/res_sip/sip_distributor.c (original)
+++ team/mmichelson/pool_shark2/res/res_sip/sip_distributor.c Mon Feb 18 11:31:59 2013
@@ -136,31 +136,6 @@
 	return endpoint;
 }
 
-pjsip_rx_data *ast_pjsip_rx_data_clone(pjsip_rx_data *rdata)
-{
-	pjsip_rx_data *clone;
-	pj_status_t status;
-	struct ast_sip_endpoint *endpoint;
-	status = pjsip_rx_data_clone(rdata, 0, &clone);
-	if (status != PJ_SUCCESS) {
-		return NULL;
-	}
-	memcpy(clone->endpt_info.mod_data, rdata->endpt_info.mod_data, sizeof(clone->endpt_info.mod_data));
-	endpoint = clone->endpt_info.mod_data[endpoint_mod.id];
-	if (endpoint) {
-		ao2_ref(endpoint, +1);
-	}
-	return clone;
-}
-
-void ast_pjsip_rx_data_free_cloned(pjsip_rx_data *rdata)
-{
-	struct ast_sip_endpoint *endpoint;
-	endpoint = rdata->endpt_info.mod_data[endpoint_mod.id];
-	pjsip_rx_data_free_cloned(rdata);
-	ao2_cleanup(endpoint);
-}
-
 int ast_sip_initialize_distributor(void)
 {
 	if (ast_sip_register_service(&distributor_mod)) {

Modified: team/mmichelson/pool_shark2/res/res_sip/sip_options.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/res/res_sip/sip_options.c?view=diff&rev=381642&r1=381641&r2=381642
==============================================================================
--- team/mmichelson/pool_shark2/res/res_sip/sip_options.c (original)
+++ team/mmichelson/pool_shark2/res/res_sip/sip_options.c Mon Feb 18 11:31:59 2013
@@ -125,6 +125,7 @@
 struct incoming_options_data {
 	pjsip_rx_data *rdata;
 	pjsip_dialog *dialog;
+	struct ast_sip_endpoint *endpoint;
 };
 
 static void incoming_options_data_destroy(void *obj)
@@ -136,6 +137,7 @@
 	if (iod->dialog) {
 		pjsip_dlg_dec_session(iod->dialog, &options_module);
 	}
+	ao2_cleanup(iod->endpoint);
 }
 
 static struct incoming_options_data *incoming_options_data_alloc(pjsip_rx_data *rdata, pjsip_dialog *dialog)
@@ -152,20 +154,20 @@
 		iod->dialog = dialog;
 		pjsip_dlg_inc_session(iod->dialog, &options_module);
 	}
+	iod->endpoint = ast_pjsip_rdata_get_endpoint(rdata);
 	return iod;
 }
 
 static int incoming_options(void *data)
 {
 	RAII_VAR(struct incoming_options_data *, iod, data, ao2_cleanup);
-	RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
+	struct ast_sip_endpoint *endpoint = iod->endpoint;
 	pjsip_uri *ruri;
 	pjsip_sip_uri *sip_ruri;
 	pjsip_rx_data *rdata = iod->rdata;
 	pjsip_dialog *dlg = iod->dialog;
 	char exten[AST_MAX_EXTENSION];
 
-	endpoint = ast_pjsip_rdata_get_endpoint(rdata);
 	ast_assert(endpoint != NULL);
 
 	ruri = rdata->msg_info.msg->line.req.uri;

Modified: team/mmichelson/pool_shark2/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/res/res_sip_session.c?view=diff&rev=381642&r1=381641&r2=381642
==============================================================================
--- team/mmichelson/pool_shark2/res/res_sip_session.c (original)
+++ team/mmichelson/pool_shark2/res/res_sip_session.c Mon Feb 18 11:31:59 2013
@@ -736,6 +736,7 @@
 struct new_request_data {
 	pjsip_rx_data *rdata;
 	struct ast_taskprocessor *serializer;
+	struct ast_sip_endpoint *endpoint;
 };
 
 static struct new_request_data *new_request_data_alloc(pjsip_rx_data *rdata)
@@ -744,17 +745,18 @@
 	if (!nrd) {
 		return NULL;
 	}
-	nrd->rdata = ast_pjsip_rx_data_clone(rdata);
+	nrd->rdata = pjsip_rx_data_clone(rdata);
 	if (!nrd->rdata) {
 		ast_free(nrd);
 		return NULL;
 	}
 	nrd->serializer = ast_sip_create_serializer();
 	if (!nrd->serializer) {
-		ast_pjsip_rx_data_free_cloned(nrd->rdata);
+		pjsip_rx_data_free_cloned(nrd->rdata);
 		ast_free(nrd);
 		return NULL;
 	}
+	nrd->endpoint = ast_pjsip_rdata_get_endpoint(rdata);
 	return nrd;
 }
 
@@ -772,12 +774,13 @@
 	struct ast_taskprocessor *serializer = nrd->serializer;
 	pjsip_tx_data *tdata = NULL;
 	pjsip_inv_session *inv_session = NULL;
-	struct ast_sip_endpoint *endpoint = NULL;
+	struct ast_sip_endpoint *endpoint = nrd->endpoint;
 	struct ast_sip_session *session = NULL;
 	pjsip_timer_setting timer;
 	pjsip_rdata_sdp_info *sdp_info;
 	pjmedia_sdp_session *local = NULL;
 	int destroy_serializer = 1;
+	int destroy_endpoint = 1;
 
 	endpoint = ast_pjsip_rdata_get_endpoint(rdata);
 	ast_assert(endpoint != NULL);
@@ -801,10 +804,12 @@
 	/* From this point on, any calls to pjsip_inv_terminate have the last argument as PJ_TRUE
 	 * so that we will be notified so we can destroy the session properly
 	 *
-	 * Also from this point on, the serializer belongs to the session, so there is no need to destroy
-	 * it ourselves. When the session dies, so will the serializer.
+	 * Also from this point on, the serializer and endpoint belong to the session, so
+	 * there is no need to destroy them ourselves. When the session dies, so will the
+	 * serializer and endpoint.
 	 */
 	destroy_serializer = 0;
+	destroy_endpoint = 0;
 
 	switch (get_destination(session, rdata)) {
 	case SIP_GET_DEST_EXTEN_FOUND:
@@ -874,7 +879,10 @@
 	if (destroy_serializer) {
 		ast_taskprocessor_unreference(serializer);
 	}
-	ast_pjsip_rx_data_free_cloned(rdata);
+	if (destroy_endpoint) {
+		ao2_cleanup(endpoint);
+	}
+	pjsip_rx_data_free_cloned(rdata);
 	ast_free(nrd);
 	return 0;
 }
@@ -916,8 +924,9 @@
 		if (ast_sip_push_task(nrd->serializer, 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);
-			ast_pjsip_rx_data_free_cloned(nrd->rdata);
+			pjsip_rx_data_free_cloned(nrd->rdata);
 			ast_taskprocessor_unreference(nrd->serializer);
+			ao2_cleanup(nrd->endpoint);
 			ast_free(nrd);
 		}
 		break;
@@ -982,7 +991,7 @@
 {
 	struct handle_incoming_data *hid = obj;
 	if (hid->rdata) {
-		ast_pjsip_rx_data_free_cloned(hid->rdata);
+		pjsip_rx_data_free_cloned(hid->rdata);
 	}
 	if (hid->session) {
 		ao2_ref(hid->session, -1);
@@ -995,7 +1004,7 @@
 	if (!hid) {
 		return NULL;
 	}
-	hid->rdata = ast_pjsip_rx_data_clone(rdata);
+	hid->rdata = pjsip_rx_data_clone(rdata);
 	if (!hid->rdata) {
 		ao2_ref(hid, -1);
 		return NULL;




More information about the asterisk-commits mailing list