[Pkg-voip-commits] r5274 - in /asterisk/trunk/debian: changelog patches/feature-bridge patches/series

paravoid at alioth.debian.org paravoid at alioth.debian.org
Thu Mar 6 02:32:42 UTC 2008


Author: paravoid
Date: Thu Mar  6 02:32:42 2008
New Revision: 5274

URL: http://svn.debian.org/wsvn/pkg-voip/?sc=1&rev=5274
Log:
* Backport feature Bridge from 1.6, thanks to Jon Webster. (Closes: #458475)

Added:
    asterisk/trunk/debian/patches/feature-bridge
Modified:
    asterisk/trunk/debian/changelog
    asterisk/trunk/debian/patches/series

Modified: asterisk/trunk/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-voip/asterisk/trunk/debian/changelog?rev=5274&op=diff
==============================================================================
--- asterisk/trunk/debian/changelog (original)
+++ asterisk/trunk/debian/changelog Thu Mar  6 02:32:42 2008
@@ -13,6 +13,7 @@
     version (2002) incompatible to the one that works. (Closes: #465524)
   * Backport upstream's patch for chan_vpb to avoid crashes when no
     VoiceTronix cards are present. (Closes: #466729)
+  * Backport feature Bridge from 1.6, thanks to Jon Webster. (Closes: #458475)
 
   [ Tzafrir Cohen ]
   * New upstream release.
@@ -28,7 +29,7 @@
   * patch tos-libcap remeved: merged by upstream.
   * Adjusted patch bristuff/ast-device-state-CID to Asterisk 1.4.18.
 
- -- Faidon Liambotis <paravoid at debian.org>  Thu, 28 Feb 2008 13:42:11 +0200
+ -- Faidon Liambotis <paravoid at debian.org>  Thu, 06 Mar 2008 04:32:33 +0200
 
 asterisk (1:1.4.17~dfsg-2) unstable; urgency=low
 

Added: asterisk/trunk/debian/patches/feature-bridge
URL: http://svn.debian.org/wsvn/pkg-voip/asterisk/trunk/debian/patches/feature-bridge?rev=5274&op=file
==============================================================================
--- asterisk/trunk/debian/patches/feature-bridge (added)
+++ asterisk/trunk/debian/patches/feature-bridge Thu Mar  6 02:32:42 2008
@@ -1,0 +1,373 @@
+Backport of asterisk 1.5/1.6 feature that Bridges together two channels already in the PBX.
+
+ -- Jon Webster <jon at elephantoutlook.com>
+
+--- a/res/res_features.c
++++ b/res/res_features.c
+@@ -230,6 +230,7 @@ struct ast_bridge_thread_obj 
+ 	struct ast_bridge_config bconfig;
+ 	struct ast_channel *chan;
+ 	struct ast_channel *peer;
++	unsigned int return_to_pbx:1;
+ };
+ 
+ 
+@@ -284,11 +285,13 @@ static struct ast_channel *ast_feature_r
+ static void *ast_bridge_call_thread(void *data) 
+ {
+ 	struct ast_bridge_thread_obj *tobj = data;
++	int res;
+ 
+-	tobj->chan->appl = "Transferred Call";
++	tobj->chan->appl = !tobj->return_to_pbx ? "Transferred Call" : "ManagerBridge";
+ 	tobj->chan->data = tobj->peer->name;
+-	tobj->peer->appl = "Transferred Call";
++	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);
+@@ -299,10 +302,29 @@ static void *ast_bridge_call_thread(void
+ 	}
+ 
+ 	ast_bridge_call(tobj->peer, tobj->chan, &tobj->bconfig);
+-	ast_hangup(tobj->chan);
+-	ast_hangup(tobj->peer);
+-	bzero(tobj, sizeof(*tobj)); /*! \todo XXX for safety */
++
++	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 (res != AST_PBX_SUCCESS)
++				ast_log(LOG_WARNING, "FAILED continuing PBX on peer %s\n", tobj->peer->name);
++		} else
++			ast_hangup(tobj->peer);
++		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 (res != AST_PBX_SUCCESS)
++				ast_log(LOG_WARNING, "FAILED continuing PBX on chan %s\n", tobj->chan->name);
++		} else
++			ast_hangup(tobj->chan);
++	} else {
++		ast_hangup(tobj->chan);
++		ast_hangup(tobj->peer);
++	}
++
+ 	free(tobj);
++
+ 	return NULL;
+ }
+ 
+@@ -2369,6 +2391,125 @@ static int handle_showfeatures(int fd, i
+ 	return RESULT_SUCCESS;
+ }
+ 
++static char mandescr_bridge[] =
++"Description: Bridge together two channels already in the PBX\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)
++{
++	ast_moh_stop(chan);
++	ast_mutex_lock(&chan->lock);
++	ast_setstate(tmpchan, chan->_state);
++	tmpchan->readformat = chan->readformat;
++	tmpchan->writeformat = chan->writeformat;
++	ast_channel_masquerade(tmpchan, chan);
++	ast_mutex_lock(&tmpchan->lock);
++	ast_do_masquerade(tmpchan);
++	/* when returning from bridge, the channel will continue at the next priority */
++	ast_explicit_goto(tmpchan, chan->context, chan->exten, chan->priority + 1);
++	ast_mutex_unlock(&tmpchan->lock);
++	ast_mutex_unlock(&chan->lock);
++}
++
++static int action_bridge(struct mansession *s, const struct message *m)
++{
++	const char *channela = astman_get_header(m, "Channel1");
++	const char *channelb = astman_get_header(m, "Channel2");
++	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;
++
++	/* make sure valid channels were specified */
++	if (!ast_strlen_zero(channela) && !ast_strlen_zero(channelb)) {
++		chana = ast_get_channel_by_name_prefix_locked(channela, strlen(channela));
++		chanb = ast_get_channel_by_name_prefix_locked(channelb, strlen(channelb));
++		if (chana)
++			ast_mutex_unlock(&chana->lock);
++		if (chanb)
++			ast_mutex_unlock(&chanb->lock);
++
++		/* 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;
++		}
++	} else {
++		astman_send_error(s, m, "Missing channel parameter in request");
++		return 0;
++	}
++
++	/* Answer the channels if needed */
++	if (chana->_state != AST_STATE_UP)
++		ast_answer(chana);
++	if (chanb->_state != AST_STATE_UP)
++		ast_answer(chanb);
++
++	/* create the placeholder channels and grab the other channels */
++	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_channel_free(tmpchana);
++		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)) {
++		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);
++		ast_hangup(tmpchanb);
++		return 1;
++	}
++
++	/* setup the bridge thread object and start the bridge */
++	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 (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);
++		}
++	}
++
++	ast_bridge_call_thread_launch(tobj);
++
++	astman_send_ack(s, m, "Launched bridge thread with success");
++
++	return 0;
++}
++
+ static char showfeatures_help[] =
+ "Usage: feature list\n"
+ "       Lists currently configured features.\n";
+@@ -3196,6 +3337,154 @@ static int load_config(void) 
+ 
+ }
+ 
++static char *app_bridge = "Bridge";
++static char *bridge_synopsis = "Bridge two channels";
++static char *bridge_descrip =
++"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"
++"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 = (1 << 0),
++};
++
++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, *final_dest_chan;
++	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(options);
++	);
++	
++	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;
++	}
++	
++	u = ast_module_user_add(chan);
++
++	tmp_data = ast_strdupa(data);
++	AST_STANDARD_APP_ARGS(args, tmp_data);
++	if (!ast_strlen_zero(args.options))
++		ast_app_parse_options(bridge_exec_options, &opts, NULL, args.options);
++
++	/* avoid bridge with ourselves */
++	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"
++					"Reason: Unable to bridge channel to itself\r\n"
++					"Channel1: %s\r\n"
++					"Channel2: %s\r\n",
++					chan->name, args.dest_chan);
++		pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "LOOP");
++		ast_module_user_remove(u);
++		return 0;
++	}
++
++	/* make sure we have a valid end point */
++	if (!(current_dest_chan = ast_get_channel_by_name_prefix_locked(args.dest_chan, 
++		strlen(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"
++					"Reason: Cannot grab end point\r\n"
++					"Channel1: %s\r\n"
++					"Channel2: %s\r\n", chan->name, args.dest_chan);
++		pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "NONEXISTENT");
++		ast_module_user_remove(u);
++		return 0;
++	}
++	ast_mutex_unlock(&current_dest_chan->lock);
++
++	/* answer the channel if needed */
++	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 */
++	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"
++					"Reason: cannot create placeholder\r\n"
++					"Channel1: %s\r\n"
++					"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 */
++	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"
++					"Reason: Could not make channels compatible for bridge\r\n"
++					"Channel1: %s\r\n"
++					"Channel2: %s\r\n", chan->name, final_dest_chan->name);
++		ast_hangup(final_dest_chan); /* may be we should return this channel to the PBX? */
++		pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "INCOMPATIBLE");
++		ast_module_user_remove(u);
++		return 0;
++	}
++
++	/* Report that the bridge will be successfull */
++	manager_event(EVENT_FLAG_CALL, "BridgeExec",
++				"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 */	
++	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 */
++	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)) {
++		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 if (option_debug)
++			ast_log(LOG_DEBUG, "SUCCESS continuing PBX on chan %s\n", final_dest_chan->name);
++	} else {
++		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 0;
++}
++
+ static int reload(void)
+ {
+ 	autoanswer_reregister_extensions();
+@@ -3206,6 +3495,8 @@ static int load_module(void)
+ {
+ 	int res;
+ 	
++	ast_register_application(app_bridge, bridge_exec, bridge_synopsis, bridge_descrip);	
++
+ 	memset(parking_ext, 0, sizeof(parking_ext));
+ 	memset(parking_con, 0, sizeof(parking_con));
+ 
+@@ -3221,6 +3512,7 @@ static int load_module(void)
+ 		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);
+ 	}
+ 
+  	res |= ast_register_application(holdedcall, retrieve_call_exec, synopsis, descrip);
+@@ -3241,9 +3533,11 @@ static int unload_module(void)
+ 	ast_module_user_hangup_all();
+ 
+ 	ast_manager_unregister("ParkedCalls");
++	ast_manager_unregister("Bridge");
+ 	ast_manager_unregister("Park");
+ 	ast_cli_unregister_multiple(cli_features, sizeof(cli_features) / sizeof(struct ast_cli_entry));
+ 	ast_unregister_application(parkcall);
++	ast_unregister_application(app_bridge);
+  	ast_unregister_application(autoanswer);
+  	ast_unregister_application(autoanswerlogin);
+  	ast_unregister_application(holdedcall);

Modified: asterisk/trunk/debian/patches/series
URL: http://svn.debian.org/wsvn/pkg-voip/asterisk/trunk/debian/patches/series?rev=5274&op=diff
==============================================================================
--- asterisk/trunk/debian/patches/series (original)
+++ asterisk/trunk/debian/patches/series Thu Mar  6 02:32:42 2008
@@ -76,6 +76,10 @@
 # they depend on the uniqueid changes; the following are a set
 bristuff/feature-autoanswer
 bristuff/feature-holdedcalls
+# bridging app backported from 1.6
+# it needs the above feature patches applied first.
+feature-bridge
+
 bristuff/zapata_euroisdn_holded
 # GSM support; it needs the above patch applied first, unfortunately.
 bristuff/zapata-gsm




More information about the Pkg-voip-commits mailing list