[asterisk-commits] russell: branch russell/issue_5841 r61117 - /team/russell/issue_5841/res/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Apr 9 16:07:22 MST 2007


Author: russell
Date: Mon Apr  9 18:07:21 2007
New Revision: 61117

URL: http://svn.digium.com/view/asterisk?view=rev&rev=61117
Log:
some more code tweaks

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=61117&r1=61116&r2=61117
==============================================================================
--- team/russell/issue_5841/res/res_features.c (original)
+++ team/russell/issue_5841/res/res_features.c Mon Apr  9 18:07:21 2007
@@ -2054,10 +2054,10 @@
 
 static char mandescr_bridge[] =
 "Description: Bridge together two channels already in the PBX\n"
-"Variables: ( Names marked with * are required )\n"
-"	*Channel1: Channel to Bridge to Channel2\n"
-"	*Channel2: Channel to Bridge to Channel1\n"
-"	     Tone: (Yes|No) Play courtesy tone to Channel 2\n"
+"Variables: ( Headers marked with * are required )\n"
+"   *Channel1: Channel to Bridge to Channel2\n"
+"   *Channel2: Channel to Bridge to Channel1\n"
+"        Tone: (Yes|No) Play courtesy tone to Channel 2\n"
 "\n";
 
 static void do_bridge_masquerade(struct ast_channel *chan, struct ast_channel *tmpchan)
@@ -2611,23 +2611,35 @@
 static char *app_bridge = "Bridge";
 static char *bridge_synopsis = "Bridge two channels";
 static char *bridge_descrip =
-"Usage: Bridge(CHANNEL|PLAYTONE)\n"
+"Usage: Bridge(channel[|options])\n"
 "	Allows the ability to bridge two channels via the dialplan.\n"
-"The current channel is bridged to the specified CHANNEL.\n"
-"Adding PLAYTONE will play a courtesy audio tone on CHANNEL when bridged successfully.\n"
+"The current channel is bridged to the specified 'channel'.\n"
+"The following options are supported:\n"
+"   p - Play a courtesy tone to 'channel'.\n"
 "BRIDGERESULT dial plan variable will contain SUCCESS, FAILURE, LOOP, NONEXISTENT or INCOMPATIBLE.\n";
+
+enum {
+	BRIDGE_OPT_PLAYTONE,
+	/* this entry must be the last one. */
+	BRIDGE_OPT_ARRAY_SIZE,
+};
+
+AST_APP_OPTIONS(bridge_exec_options, BEGIN_OPTIONS
+	AST_APP_OPTION('p', BRIDGE_OPT_PLAYTONE)
+END_OPTIONS );
 
 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;
-	int playtone = 0;
 	char *tmp_data  = NULL;
+	struct ast_flags opts = { 0, };
+	struct ast_bridge_config bconfig = { { 0, }, };
 
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(dest_chan);
-		AST_APP_ARG(playtone);
+		AST_APP_ARG(options);
 	);
 	
 	if (ast_strlen_zero(data)) {
@@ -2638,20 +2650,14 @@
 	u = ast_module_user_add(chan);
 
 	tmp_data = ast_strdupa(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) {
-		playtone = 1;
-	}
-	
+	if (!ast_strlen_zero(args.options))
+		ast_app_parse_options(bridge_exec_options, &opts, NULL, args.options);
+
 	/* 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 (!strncmp(chan->name, args.dest_chan, 
+		strlen(chan->name) < strlen(args.dest_chan) ? 
+		strlen(chan->name) : strlen(args.dest_chan))) {
 		ast_log(LOG_WARNING, "Unable to bridge channel %s with itself\n", chan->name);
 		manager_event(EVENT_FLAG_CALL, "BridgeExec",
 					"Response: Failed\r\n"
@@ -2714,23 +2720,14 @@
 				"Response: Success\r\n"
 				"Channel1: %s\r\n"
 				"Channel2: %s\r\n", chan->name, final_dest_chan->name);
+
 	/* we have 2 valid channels to bridge, now it is just a matter of setting up the bridge config and starting the bridge */	
-	struct ast_bridge_config bconfig;
-	bconfig.play_warning = 0;
-	bconfig.warning_freq = 0;
-	bconfig.warning_sound = NULL;
-	bconfig.end_sound = NULL;
-	bconfig.start_sound = NULL;
-	bconfig.firstpass = 0;
-	bconfig.timelimit = 0;
-	bconfig.feature_timer = 0;
-	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_test_flag(&opts, BRIDGE_OPT_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 */
 	res = ast_bridge_call(chan, final_dest_chan, &bconfig);
@@ -2741,7 +2738,7 @@
 		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 (pbx_res != 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
@@ -2750,9 +2747,12 @@
 		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;
 }
+
 static int reload(void)
 {
 	return load_config();



More information about the asterisk-commits mailing list