[svn-commits] russell: branch russell/issue_5841 r61219 - /team/russell/issue_5841/res/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Apr 10 08:29:18 MST 2007


Author: russell
Date: Tue Apr 10 10:29:17 2007
New Revision: 61219

URL: http://svn.digium.com/view/asterisk?view=rev&rev=61219
Log:
Various bits of code and cleanup and updates to ast_channel_alloc API changes

Modified:
    team/russell/issue_5841/res/res_features.c

Modified: team/russell/issue_5841/res/res_features.c
URL: http://svn.digium.com/view/asterisk/team/russell/issue_5841/res/res_features.c?view=diff&rev=61219&r1=61218&r2=61219
==============================================================================
--- team/russell/issue_5841/res/res_features.c (original)
+++ team/russell/issue_5841/res/res_features.c Tue Apr 10 10:29:17 2007
@@ -2023,23 +2023,10 @@
 {
 	const char *channela = astman_get_header(m, "Channel1");
 	const char *channelb = astman_get_header(m, "Channel2");
-	const char *pt = astman_get_header(m, "Tone");
-	const char *actionid = astman_get_header(m, "ActionID");
-	char buf[BUFSIZ];
+	const char *playtone = astman_get_header(m, "Tone");
 	struct ast_channel *chana = NULL, *chanb = NULL;
 	struct ast_channel *tmpchana = NULL, *tmpchanb = NULL;
 	struct ast_bridge_thread_obj *tobj = NULL;
-	int playtone = 0;
-	char sActionid[1025];
-
-	/* Find out whether we're supposed to play a tone or not */
-	playtone = ast_true(pt);
-	
-	/* if ActionID specified, build a new one with \r\n included */
-	if (!ast_strlen_zero(actionid))
-		snprintf(sActionid, sizeof(sActionid), "ActionID: %s\r\n", actionid);
-	else
-		strcpy(sActionid, "");
 
 	/* make sure valid channels were specified */
 	if (!ast_strlen_zero(channela) && !ast_strlen_zero(channelb)) {
@@ -2052,11 +2039,13 @@
 
 		/* send errors if any of the channels could not be found/locked */
 		if (!chana) {
+			char buf[256];
 			snprintf(buf, sizeof(buf), "Channel1 does not exists: %s", channela);
 			astman_send_error(s, m, buf);
 			return 0;
 		}
 		if (!chanb) {
+			char buf[256];
 			snprintf(buf, sizeof(buf), "Channel2 does not exists: %s", channelb);
 			astman_send_error(s, m, buf);
 			return 0;
@@ -2067,32 +2056,27 @@
 	}
 
 	/* Answer the channels if needed */
-	if (AST_STATE_UP != chana->_state)
+	if (chana->_state != AST_STATE_UP)
 		ast_answer(chana);
-	if (AST_STATE_UP != chanb->_state)
+	if (chanb->_state != AST_STATE_UP)
 		ast_answer(chanb);
 
 	/* create the placeholder channels and grab the other channels */
-	tmpchana = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "Bridge/%s", chana->name);
-	tmpchanb = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "Bridge/%s", chanb->name);
-
-	if (tmpchana)
-		do_bridge_masquerade(chana, tmpchana);
-	else {
+	if (!(tmpchana = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL, 
+		NULL, NULL, 0, "Bridge/%s", chana->name))) {
+		astman_send_error(s, m, "Unable to create temporary channel!");
+		return 1;
+	}
+
+	if (!(tmpchana = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL, 
+		NULL, NULL, 0, "Bridge/%s", chanb->name))) {
 		astman_send_error(s, m, "Unable to create temporary channels!");
-		ast_hangup(tmpchana);
-		ast_hangup(chana);
+		ast_channel_free(tmpchana);
 		return 1;
 	}
 
-	if (tmpchanb)
-		do_bridge_masquerade(chanb, tmpchanb);
-	else {
-		astman_send_error(s, m, "Unable to create temporary channels!");
-		ast_hangup(tmpchanb);
-		ast_hangup(chanb);
-		return 1;
-	}
+	do_bridge_masquerade(chana, tmpchana);
+	do_bridge_masquerade(chanb, tmpchanb);
 	
 	/* make the channels compatible, send error if we fail doing so */
 	if (ast_channel_make_compatible(tmpchana, tmpchanb)) {
@@ -2116,7 +2100,7 @@
 	tobj->peer = tmpchanb;
 	tobj->return_to_pbx = 1;
 	
-	if (playtone) {
+	if (ast_true(playtone)) {
 		if (!ast_strlen_zero(xfersound) && !ast_streamfile(tmpchanb, xfersound, tmpchanb->language)) {
 			if (ast_waitstream(tmpchanb, "") < 0)
 				ast_log(LOG_WARNING, "Failed to play a courtesy tone on chan %s\n", tmpchanb->name);
@@ -2574,8 +2558,8 @@
 static int bridge_exec(struct ast_channel *chan, void *data)
 {
 	struct ast_module_user *u;
-	struct ast_channel *current_dest_chan = NULL, *final_dest_chan = NULL;
-	int res, pbx_res = 0;
+	struct ast_channel *current_dest_chan, *final_dest_chan;
+	int bridge_res;
 	char *tmp_data  = NULL;
 	struct ast_flags opts = { 0, };
 	struct ast_bridge_config bconfig = { { 0, }, };
@@ -2614,8 +2598,7 @@
 	}
 
 	/* make sure we have a valid end point */
-	current_dest_chan = ast_get_channel_by_name_locked(args.dest_chan);
-	if (!current_dest_chan) {
+	if (!(current_dest_chan = ast_get_channel_by_name_locked(args.dest_chan))) {
 		ast_log(LOG_WARNING, "Bridge failed because channel %s does not exists or we cannot get its lock\n", args.dest_chan);
 		manager_event(EVENT_FLAG_CALL, "BridgeExec",
 					"Response: Failed\r\n"
@@ -2629,12 +2612,12 @@
 	ast_mutex_unlock(&current_dest_chan->lock);
 
 	/* answer the channel if needed */
-	if (AST_STATE_UP != current_dest_chan->_state)
+	if (current_dest_chan->_state != AST_STATE_UP)
 		ast_answer(current_dest_chan);
 
 	/* try to allocate a place holder where current_dest_chan will be placed */
-	final_dest_chan = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "Bridge/%s", current_dest_chan->name);
-	if (!final_dest_chan) {
+	if (!(final_dest_chan = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL, 
+		NULL, NULL, 0, "Bridge/%s", current_dest_chan->name))) {
 		ast_log(LOG_WARNING, "Cannot create placeholder channel for chan %s\n", args.dest_chan);
 		manager_event(EVENT_FLAG_CALL, "BridgeExec",
 					"Response: Failed\r\n"
@@ -2643,10 +2626,10 @@
 					"Channel2: %s\r\n", chan->name, args.dest_chan);
 	}
 	do_bridge_masquerade(current_dest_chan, final_dest_chan);
+
 	/* now current_dest_chan is a ZOMBIE and with softhangup set to 1 and final_dest_chan is our end point */
 	/* try to make compatible, send error if we fail */
-	res = ast_channel_make_compatible(chan, final_dest_chan);
-	if (res < 0) {
+	if (ast_channel_make_compatible(chan, final_dest_chan) < 0) {
 		ast_log(LOG_WARNING, "Could not make channels %s and %s compatible for bridge\n", chan->name, final_dest_chan->name);
 		manager_event(EVENT_FLAG_CALL, "BridgeExec",
 					"Response: Failed\r\n"
@@ -2658,6 +2641,7 @@
 		ast_module_user_remove(u);
 		return 0;
 	}
+
 	/* Report that the bridge will be successfull */
 	manager_event(EVENT_FLAG_CALL, "BridgeExec",
 				"Response: Success\r\n"
@@ -2673,27 +2657,32 @@
 	}
 	
 	/* do the bridge */
-	res = ast_bridge_call(chan, final_dest_chan, &bconfig);
+	bridge_res = ast_bridge_call(chan, final_dest_chan, &bconfig);
 
 	/* the bridge has ended, set BRIDGERESULT to SUCCESS. If the other channel has not been hung up, return it to the PBX */
 	pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "SUCCESS");
 	if (!ast_check_hangup(final_dest_chan)) {
-		ast_log(LOG_DEBUG, "starting new PBX in %s,%s,%d for chan %s\n", final_dest_chan->context, final_dest_chan->exten, 
-		final_dest_chan->priority, final_dest_chan->name);
-		pbx_res = ast_pbx_start(final_dest_chan);
-		if (pbx_res != AST_PBX_SUCCESS) {
+		if (option_debug) {
+			ast_log(LOG_DEBUG, "starting new PBX in %s,%s,%d for chan %s\n", 
+			final_dest_chan->context, final_dest_chan->exten, 
+			final_dest_chan->priority, final_dest_chan->name);
+		}
+
+		if (ast_pbx_start(final_dest_chan) != AST_PBX_SUCCESS) {
 			ast_log(LOG_WARNING, "FAILED continuing PBX on dest chan %s\n", final_dest_chan->name);
 			ast_hangup(final_dest_chan);
-		} else
+		} else if (option_debug)
 			ast_log(LOG_DEBUG, "SUCCESS continuing PBX on chan %s\n", final_dest_chan->name);
+
 	} else {
-		ast_log(LOG_DEBUG, "hangup chan %s since the other endpoint has hung up\n", final_dest_chan->name);
+		if (option_debug)
+			ast_log(LOG_DEBUG, "hangup chan %s since the other endpoint has hung up\n", final_dest_chan->name);
 		ast_hangup(final_dest_chan);
 	}
 
 	ast_module_user_remove(u);
 
-	return res;
+	return bridge_res;
 }
 
 static int reload(void)



More information about the svn-commits mailing list