[asterisk-commits] file: branch file/gulp_transfer r389052 - /team/file/gulp_transfer/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat May 18 14:28:20 CDT 2013


Author: file
Date: Sat May 18 14:28:16 2013
New Revision: 389052

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389052
Log:
Finish incorporating review feedback.

Modified:
    team/file/gulp_transfer/res/res_sip_refer.c

Modified: team/file/gulp_transfer/res/res_sip_refer.c
URL: http://svnview.digium.com/svn/asterisk/team/file/gulp_transfer/res/res_sip_refer.c?view=diff&rev=389052&r1=389051&r2=389052
==============================================================================
--- team/file/gulp_transfer/res/res_sip_refer.c (original)
+++ team/file/gulp_transfer/res/res_sip_refer.c Sat May 18 14:28:16 2013
@@ -254,42 +254,46 @@
 }
 
 /*! \brief Internal helper function which sets up a refer progress structure if needed */
-static struct refer_progress *refer_progress_alloc(struct ast_sip_session *session, pjsip_rx_data *rdata)
-{
-	struct refer_progress *progress;
+static int refer_progress_alloc(struct ast_sip_session *session, pjsip_rx_data *rdata, struct refer_progress **progress)
+{
 	const pj_str_t str_refer_sub = { "Refer-Sub", 9 };
 	pjsip_generic_string_hdr *refer_sub = NULL;
 	const pj_str_t str_true = { "true", 4 };
 	pjsip_tx_data *tdata;
 	pjsip_hdr hdr_list;
 
+	*progress = NULL;
+
 	/* Grab the optional Refer-Sub header, it can be used to suppress the implicit subscription */
 	refer_sub = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_refer_sub, NULL);
-	if ((refer_sub && pj_strnicmp(&refer_sub->hvalue, &str_true, 4)) ||
-		!(progress = ao2_alloc(sizeof(*progress), refer_progress_destroy))) {
-		return NULL;
+	if ((refer_sub && pj_strnicmp(&refer_sub->hvalue, &str_true, 4))) {
+		return 0;
+	}
+
+	if (!(*progress = ao2_alloc(sizeof(*progress), refer_progress_destroy))) {
+		return -1;
 	}
 
 	ast_debug(3, "Created progress monitor '%p' for transfer occurring from channel '%s' and endpoint '%s'\n",
 		progress, ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint));
 
-	progress->framehook = -1;
+	(*progress)->framehook = -1;
 
 	/* To prevent a potential deadlock we need the dialog so we can lock/unlock */
-	progress->dlg = session->inv_session->dlg;
-
-	if (!(progress->serializer = ast_sip_create_serializer())) {
-		return progress;
+	(*progress)->dlg = session->inv_session->dlg;
+
+	if (!((*progress)->serializer = ast_sip_create_serializer())) {
+		goto error;
 	}
 
 	/* Create the implicit subscription for monitoring of this transfer */
-	if (pjsip_xfer_create_uas(session->inv_session->dlg, &refer_progress_evsub_cb, rdata, &progress->sub) != PJ_SUCCESS) {
-		return progress;
+	if (pjsip_xfer_create_uas(session->inv_session->dlg, &refer_progress_evsub_cb, rdata, &(*progress)->sub) != PJ_SUCCESS) {
+		goto error;
 	}
 
 	/* Associate the REFER progress structure with the subscription */
-	ao2_ref(progress, +1);
-	pjsip_evsub_set_mod_data(progress->sub, refer_progress_module.id, progress);
+	ao2_ref(*progress, +1);
+	pjsip_evsub_set_mod_data((*progress)->sub, refer_progress_module.id, *progress);
 
 	pj_list_init(&hdr_list);
 	if (refer_sub) {
@@ -299,16 +303,21 @@
 	}
 
 	/* Accept the REFER request */
-	ast_debug(3, "Accepting REFER request for progress monitor '%p'\n", progress);
-	pjsip_xfer_accept(progress->sub, rdata, 202, &hdr_list);
+	ast_debug(3, "Accepting REFER request for progress monitor '%p'\n", *progress);
+	pjsip_xfer_accept((*progress)->sub, rdata, 202, &hdr_list);
 
 	/* Send initial NOTIFY Request */
-	ast_debug(3, "Sending initial 100 Trying NOTIFY for progress monitor '%p'\n", progress);
-	if (pjsip_xfer_notify(progress->sub, PJSIP_EVSUB_STATE_ACTIVE, 100, NULL, &tdata) == PJ_SUCCESS) {
-		pjsip_xfer_send_request(progress->sub, tdata);
-	}
-
-	return progress;
+	ast_debug(3, "Sending initial 100 Trying NOTIFY for progress monitor '%p'\n", *progress);
+	if (pjsip_xfer_notify((*progress)->sub, PJSIP_EVSUB_STATE_ACTIVE, 100, NULL, &tdata) == PJ_SUCCESS) {
+		pjsip_xfer_send_request((*progress)->sub, tdata);
+	}
+
+	return 0;
+
+error:
+	ao2_cleanup(*progress);
+	*progress = NULL;
+	return -1;
 }
 
 /*! \brief Structure for attended transfer task */
@@ -317,8 +326,8 @@
 	struct ast_sip_session *transferer;
 	/*! \brief Transferer channel */
 	struct ast_channel *transferer_chan;
-	/*! \brief Transferee session */
-	struct ast_sip_session *transferee;
+	/*! \brief Second transferer session */
+	struct ast_sip_session *transferer_second	;
 	/*! \brief Optional refer progress structure */
 	struct refer_progress *progress;
 };
@@ -330,11 +339,11 @@
 
 	ao2_cleanup(attended->transferer);
 	ast_channel_unref(attended->transferer_chan);
-	ao2_cleanup(attended->transferee);
+	ao2_cleanup(attended->transferer_second);
 }
 
 /*! \brief Allocator for attended transfer task */
-static struct refer_attended *refer_attended_alloc(struct ast_sip_session *transferer, struct ast_sip_session *transferee,
+static struct refer_attended *refer_attended_alloc(struct ast_sip_session *transferer, struct ast_sip_session *transferer_second,
 	struct refer_progress *progress)
 {
 	struct refer_attended *attended = ao2_alloc(sizeof(*attended), refer_attended_destroy);
@@ -347,8 +356,8 @@
 	attended->transferer = transferer;
 	ast_channel_ref(transferer->channel);
 	attended->transferer_chan = transferer->channel;
-	ao2_ref(transferee, +1);
-	attended->transferee = transferee;
+	ao2_ref(transferer_second, +1);
+	attended->transferer_second = transferer_second;
 
 	if (progress) {
 		ao2_ref(progress, +1);
@@ -365,9 +374,9 @@
 	int response = 0;
 
 	ast_debug(3, "Performing a REFER attended transfer - Transferer #1: %s Transferer #2: %s\n",
-		ast_channel_name(attended->transferer_chan), ast_channel_name(attended->transferee->channel));
-
-	switch (ast_bridge_transfer_attended(attended->transferer_chan, attended->transferee->channel, NULL)) {
+		ast_channel_name(attended->transferer_chan), ast_channel_name(attended->transferer_second->channel));
+
+	switch (ast_bridge_transfer_attended(attended->transferer_chan, attended->transferer_second->channel, NULL)) {
 	case AST_BRIDGE_TRANSFER_INVALID:
 		response = 400;
 		break;
@@ -384,7 +393,7 @@
 	}
 
 	ast_debug(3, "Final response for REFER attended transfer - Transferer #1: %s Transferer #2: %s is '%d'\n",
-		ast_channel_name(attended->transferer_chan), ast_channel_name(attended->transferee->channel), response);
+		ast_channel_name(attended->transferer_chan), ast_channel_name(attended->transferer_second->channel), response);
 
 	if (attended->progress && response) {
 		struct refer_progress_notification *notification = refer_progress_notification_alloc(attended->progress, response, PJSIP_EVSUB_STATE_TERMINATED);
@@ -744,10 +753,7 @@
 	target_uri = pjsip_uri_get_uri(target->uri);
 
 	/* Set up REFER progress subscription if requested/possible */
-	progress = refer_progress_alloc(session, rdata);
-
-	/* If REFER progress monitoring *should* occur but an error occurred report it */
-	if (progress && !progress->sub) {
+	if (refer_progress_alloc(session, rdata, &progress)) {
 		pjsip_dlg_respond(session->inv_session->dlg, rdata, 500, NULL, NULL, NULL);
 		ast_debug(3, "Could not set up subscription for REFER on channel '%s' from endpoint '%s'\n",
 			ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint));




More information about the asterisk-commits mailing list