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

svn-commits at lists.digium.com svn-commits at lists.digium.com
Mon Apr 9 15:39:40 MST 2007


Author: russell
Date: Mon Apr  9 17:39:39 2007
New Revision: 61115

URL: http://svn.digium.com/view/asterisk?view=rev&rev=61115
Log:
Minor optimizations and code cleanup for coding guidelines issues

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=61115&r1=61114&r2=61115
==============================================================================
--- team/russell/issue_5841/res/res_features.c (original)
+++ team/russell/issue_5841/res/res_features.c Mon Apr  9 17:39:39 2007
@@ -170,7 +170,7 @@
 	struct ast_bridge_config bconfig;
 	struct ast_channel *chan;
 	struct ast_channel *peer;
-	int return_to_pbx;
+	unsigned int return_to_pbx:1;
 };
 
 
@@ -231,6 +231,7 @@
 	tobj->chan->data = tobj->peer->name;
 	tobj->peer->appl = !tobj->return_to_pbx ? "Transferred Call" : "ManagerBridge";
 	tobj->peer->data = tobj->chan->name;
+
 	if (tobj->chan->cdr) {
 		ast_cdr_reset(tobj->chan->cdr, NULL);
 		ast_cdr_setdestchan(tobj->chan->cdr, tobj->peer->name);
@@ -241,31 +242,29 @@
 	}
 
 	ast_bridge_call(tobj->peer, tobj->chan, &tobj->bconfig);
-	if ( tobj->return_to_pbx ) {
-		if ( !ast_check_hangup(tobj->peer) ) {
+
+	if (tobj->return_to_pbx) {
+		if (!ast_check_hangup(tobj->peer)) {
 			ast_log(LOG_VERBOSE, "putting peer %s into PBX again\n", tobj->peer->name);
 			res = ast_pbx_start(tobj->peer);
-			if ( AST_PBX_SUCCESS != res )
-				ast_log(LOG_WARNING, "FAILED continuing PBX on peer %s\n", tobj->peer->name);
-			else
-				ast_log(LOG_DEBUG, "SUCCESS continuing PBX on peer %s\n", tobj->peer->name);
+			ast_log(LOG_WARNING, "%s continuing PBX on peer %s\n", 
+				res == AST_PBX_SUCCESS ? "SUCCESS" : "FAILED", tobj->peer->name);
 		} else
 			ast_hangup(tobj->peer);
-		if ( !ast_check_hangup(tobj->chan) ) {
+		if (!ast_check_hangup(tobj->chan)) {
 			ast_log(LOG_VERBOSE, "putting chan %s into PBX again\n", tobj->chan->name);
 			res = ast_pbx_start(tobj->chan);
-			if ( AST_PBX_SUCCESS != res )
-				ast_log(LOG_WARNING, "FAILED continuing PBX on chan %s\n", tobj->chan->name);
-			else
-				ast_log(LOG_DEBUG, "SUCCESS continuing PBX on chan %s\n", tobj->chan->name);
+			ast_log(LOG_WARNING, "%s continuing PBX on chan %s\n", 
+				res == AST_PBX_SUCCESS ? "SUCCESS" : "FAILED", tobj->chan->name);
 		} else
 			ast_hangup(tobj->chan);
 	} else {
 		ast_hangup(tobj->chan);
 		ast_hangup(tobj->peer);
 	}
-	bzero(tobj, sizeof(*tobj)); /*! \todo XXX for safety */
+
 	free(tobj);
+
 	return NULL;
 }
 
@@ -616,7 +615,7 @@
 			snprintf(args, len, "%s|%s|m", S_OR(touch_format, "wav"), touch_filename);
 		}
 
-		for( x = 0; x < strlen(args); x++) {
+		for(x = 0; x < strlen(args); x++) {
 			if (args[x] == '/')
 				args[x] = '-';
 		}
@@ -740,7 +739,7 @@
 		if (option_verbose > 2)	
 			ast_verbose(VERBOSE_PREFIX_3 "Unable to find extension '%s' in context '%s'\n", xferto, transferer_real_context);
 	}
-	if (ast_stream_and_wait(transferer, xferfailsound, AST_DIGIT_ANY) < 0 ) {
+	if (ast_stream_and_wait(transferer, xferfailsound, AST_DIGIT_ANY) < 0) {
 		finishup(transferee);
 		return -1;
 	}
@@ -1224,12 +1223,12 @@
 						if (f->subclass == AST_CONTROL_RINGING) {
 							state = f->subclass;
 							if (option_verbose > 2)
-								ast_verbose( VERBOSE_PREFIX_3 "%s is ringing\n", chan->name);
+								ast_verbose(VERBOSE_PREFIX_3 "%s is ringing\n", chan->name);
 							ast_indicate(caller, AST_CONTROL_RINGING);
 						} else if ((f->subclass == AST_CONTROL_BUSY) || (f->subclass == AST_CONTROL_CONGESTION)) {
 							state = f->subclass;
 							if (option_verbose > 2)
-								ast_verbose( VERBOSE_PREFIX_3 "%s is busy\n", chan->name);
+								ast_verbose(VERBOSE_PREFIX_3 "%s is busy\n", chan->name);
 							ast_indicate(caller, AST_CONTROL_BUSY);
 							ast_frfree(f);
 							f = NULL;
@@ -1555,7 +1554,7 @@
 		
 		if (!f || (f->frametype == AST_FRAME_CONTROL &&
 				(f->subclass == AST_CONTROL_HANGUP || f->subclass == AST_CONTROL_BUSY || 
-					f->subclass == AST_CONTROL_CONGESTION ) ) ) {
+					f->subclass == AST_CONTROL_CONGESTION))) {
 			res = -1;
 			break;
 		}
@@ -2087,7 +2086,6 @@
 	struct ast_channel *chana = NULL, *chanb = NULL;
 	struct ast_channel *tmpchana = NULL, *tmpchanb = NULL;
 	struct ast_bridge_thread_obj *tobj = NULL;
-	int res = 0;
 	int playtone = 0;
 	char sActionid[1025];
 
@@ -2095,27 +2093,27 @@
 	playtone = ast_true(pt);
 	
 	/* if ActionID specified, build a new one with \r\n included */
-	if ( !ast_strlen_zero(actionid) )
+	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) ) {
+	if (!ast_strlen_zero(channela) && !ast_strlen_zero(channelb)) {
 		chana = ast_get_channel_by_name_locked(channela);
 		chanb = ast_get_channel_by_name_locked(channelb);
-		if ( chana )
+		if (chana)
 			ast_mutex_unlock(&chana->lock);
-		if ( chanb )
+		if (chanb)
 			ast_mutex_unlock(&chanb->lock);
 
 		/* send errors if any of the channels could not be found/locked */
-		if ( !chana ) {
+		if (!chana) {
 			snprintf(buf, sizeof(buf), "Channel1 does not exists: %s", channela);
 			astman_send_error(s, m, buf);
 			return 0;
 		}
-		if ( !chanb ) {
+		if (!chanb) {
 			snprintf(buf, sizeof(buf), "Channel2 does not exists: %s", channelb);
 			astman_send_error(s, m, buf);
 			return 0;
@@ -2126,16 +2124,16 @@
 	}
 
 	/* Answer the channels if needed */
-	if ( AST_STATE_UP != chana->_state )
+	if (AST_STATE_UP != chana->_state)
 		ast_answer(chana);
-	if ( AST_STATE_UP != chanb->_state )
+	if (AST_STATE_UP != chanb->_state)
 		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 )
+	if (tmpchana)
 		do_bridge_masquerade(chana, tmpchana);
 	else {
 		astman_send_error(s, m, "Unable to create temporary channels!");
@@ -2144,7 +2142,7 @@
 		return 1;
 	}
 
-	if ( tmpchanb )
+	if (tmpchanb)
 		do_bridge_masquerade(chanb, tmpchanb);
 	else {
 		astman_send_error(s, m, "Unable to create temporary channels!");
@@ -2154,8 +2152,7 @@
 	}
 	
 	/* make the channels compatible, send error if we fail doing so */
-	res = ast_channel_make_compatible(tmpchana, tmpchanb);
-	if ( res ) {
+	if (ast_channel_make_compatible(tmpchana, tmpchanb)) {
 		ast_log(LOG_WARNING, "Could not make channels %s and %s compatible for manager bridge\n", tmpchana->name, tmpchanb->name);
 		astman_send_error(s, m, "Could not make channels compatible for manager bridge");
 		ast_hangup(tmpchana);
@@ -2164,34 +2161,30 @@
 	}
 
 	/* setup the bridge thread object and start the bridge */
-	tobj = malloc(sizeof(struct ast_bridge_thread_obj));
-	if ( tobj ) {
-		memset(tobj, 0, sizeof(struct ast_bridge_thread_obj));
-		tobj->chan = tmpchana;
-		tobj->peer = tmpchanb;
-		tobj->return_to_pbx = 1;
-		tobj->bconfig.play_warning = 0;
-		tobj->bconfig.warning_freq = 0;
-		tobj->bconfig.warning_sound = NULL;
-		tobj->bconfig.end_sound = NULL;
-		tobj->bconfig.start_sound = NULL;
-		tobj->bconfig.firstpass = 0;
-		tobj->bconfig.timelimit = 0;
-		tobj->bconfig.feature_timer = 0;
-		if ( 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);
-		ast_bridge_call_thread_launch(tobj);
-		astman_send_ack(s, m, "Launched bridge thread with success");
-		return 0;
-	} else {
+	if (!(tobj = ast_calloc(1, sizeof(*tobj)))) {
 		ast_log(LOG_WARNING, "Unable to spawn a new bridge thread on %s and %s: %s\n", tmpchana->name, tmpchanb->name, strerror(errno));
 		astman_send_error(s, m, "Unable to spawn a new bridge thread");
 		ast_hangup(tmpchana);
 		ast_hangup(tmpchanb);
 		return 1;
 	}
+
+	tobj->chan = tmpchana;
+	tobj->peer = tmpchanb;
+	tobj->return_to_pbx = 1;
+	
+	if (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);
+		}
+	}
+
+	ast_bridge_call_thread_launch(tobj);
+
+	astman_send_ack(s, m, "Launched bridge thread with success");
+
+	return 0;
 }
 
 static char showfeatures_help[] =
@@ -2237,7 +2230,7 @@
 };
 
 /*! \brief Dump lot status */
-static int manager_parking_status( struct mansession *s, const struct message *m)
+static int manager_parking_status(struct mansession *s, const struct message *m)
 {
 	struct parkeduser *cur;
 	const char *id = astman_get_header(m, "ActionID");
@@ -2344,7 +2337,7 @@
 	struct ast_channel *cur = NULL;
 	int res = -1;
 
-	while ( (cur = ast_channel_walk_locked(cur)) != NULL) {
+	while ((cur = ast_channel_walk_locked(cur)) != NULL) {
 		if (!cur->pbx && 
 			(cur != chan) &&
 			(chan->pickupgroup & cur->callgroup) &&
@@ -2637,7 +2630,7 @@
 		AST_APP_ARG(playtone);
 	);
 	
-	if ( ast_strlen_zero(data) ) {
+	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "Bridge require at least 1 argument specifying the other end of the bridge\n");
 		return -1;
 	}
@@ -2645,20 +2638,20 @@
 	u = ast_module_user_add(chan);
 
 	tmp_data = ast_strdupa(data);
-	if ( !tmp_data ) {
+	if (!tmp_data) {
 		ast_log(LOG_ERROR, "Out of memory!\n");
 		ast_module_user_remove(u);
 		return -1;
 	}
 
 	AST_STANDARD_APP_ARGS(args, tmp_data);
-	if ( args.playtone ) {
+	if (args.playtone) {
 		playtone = 1;
 	}
 	
 	/* avoid bridge with ourselves */
 	int cmplen = strlen(chan->name) < strlen(args.dest_chan) ? strlen(chan->name) : strlen(args.dest_chan);
-	if ( 0 == strncmp(chan->name, args.dest_chan, cmplen) ) {
+	if (0 == strncmp(chan->name, args.dest_chan, cmplen)) {
 		ast_log(LOG_WARNING, "Unable to bridge channel %s with itself\n", chan->name);
 		manager_event(EVENT_FLAG_CALL, "BridgeExec",
 					"Response: Failed\r\n"
@@ -2673,7 +2666,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_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"
@@ -2687,12 +2680,12 @@
 	ast_mutex_unlock(&current_dest_chan->lock);
 
 	/* answer the channel if needed */
-	if ( AST_STATE_UP != current_dest_chan->_state )
+	if (AST_STATE_UP != current_dest_chan->_state)
 		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_log(LOG_WARNING, "Cannot create placeholder channel for chan %s\n", args.dest_chan);
 		manager_event(EVENT_FLAG_CALL, "BridgeExec",
 					"Response: Failed\r\n"
@@ -2704,7 +2697,7 @@
 	/* 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 (res < 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"
@@ -2734,9 +2727,9 @@
 	ast_clear_flag(&(bconfig.features_caller), AST_FLAGS_ALL);
 	ast_clear_flag(&(bconfig.features_callee), AST_FLAGS_ALL);
 
-	if ( playtone && !ast_strlen_zero(xfersound) )
-		if ( !ast_streamfile(final_dest_chan, xfersound, final_dest_chan->language) )
-			if ( ast_waitstream(final_dest_chan, "") < 0 )
+	if (playtone && !ast_strlen_zero(xfersound))
+		if (!ast_streamfile(final_dest_chan, xfersound, final_dest_chan->language))
+			if (ast_waitstream(final_dest_chan, "") < 0)
 				ast_log(LOG_WARNING, "Failed to play courtesy tone on %s\n", final_dest_chan->name);
 	
 	/* do the bridge */
@@ -2744,11 +2737,11 @@
 
 	/* 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) ) {
+	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 ( AST_PBX_SUCCESS != pbx_res ) {
+		if (AST_PBX_SUCCESS != pbx_res) {
 			ast_log(LOG_WARNING, "FAILED continuing PBX on dest chan %s\n", final_dest_chan->name);
 			ast_hangup(final_dest_chan);
 		} else
@@ -2782,7 +2775,7 @@
 	if (!res)
 		res = ast_register_application(parkcall, park_call_exec, synopsis2, descrip2);
 	if (!res) {
-		ast_manager_register("ParkedCalls", 0, manager_parking_status, "List parked calls" );
+		ast_manager_register("ParkedCalls", 0, manager_parking_status, "List parked calls");
 		ast_manager_register2("Park", EVENT_FLAG_CALL, manager_park,
 			"Park a channel", mandescr_park); 
 		ast_manager_register2("Bridge", EVENT_FLAG_COMMAND, action_bridge, "Bridge two channels already in the PBX", mandescr_bridge);
@@ -2812,4 +2805,4 @@
 		.load = load_module,
 		.unload = unload_module,
 		.reload = reload,
-	       );
+	      );



More information about the svn-commits mailing list