[asterisk-commits] russell: branch russell/parking_updates r114631 - in /team/russell/parking_up...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 24 16:34:07 CDT 2008


Author: russell
Date: Thu Apr 24 16:34:05 2008
New Revision: 114631

URL: http://svn.digium.com/view/asterisk?view=rev&rev=114631
Log:
expose various options to park_call_full as options to the parkcall app

Modified:
    team/russell/parking_updates/include/asterisk/features.h
    team/russell/parking_updates/main/features.c

Modified: team/russell/parking_updates/include/asterisk/features.h
URL: http://svn.digium.com/view/asterisk/team/russell/parking_updates/include/asterisk/features.h?view=diff&rev=114631&r1=114630&r2=114631
==============================================================================
--- team/russell/parking_updates/include/asterisk/features.h (original)
+++ team/russell/parking_updates/include/asterisk/features.h Thu Apr 24 16:34:05 2008
@@ -68,7 +68,6 @@
 #define AST_FEATURE_RETURN_SUCCESS           23
 #define AST_FEATURE_RETURN_KEEPTRYING        24
 
-
 /*!
  * \brief Park a call and read back parked location 
  * \param chan the channel to actually be parked

Modified: team/russell/parking_updates/main/features.c
URL: http://svn.digium.com/view/asterisk/team/russell/parking_updates/main/features.c?view=diff&rev=114631&r1=114630&r2=114631
==============================================================================
--- team/russell/parking_updates/main/features.c (original)
+++ team/russell/parking_updates/main/features.c Thu Apr 24 16:34:05 2008
@@ -423,13 +423,22 @@
 	return AST_DEVICE_INUSE;
 }
 
-enum park_call_options {
-	PARK_OPT_RINGING =   (1 << 0),
-	PARK_OPT_RANDOMIZE = (1 << 1),
+/*! Options to pass to ast_park_call_full */
+enum ast_park_call_options {
+	/*! Provide ringing to the parked caller instead of music on hold */
+	AST_PARK_OPT_RINGING =   (1 << 0),
+	/*! Randomly choose a parking spot for the caller instead of choosing
+	 *  the first one that is available. */
+	AST_PARK_OPT_RANDOMIZE = (1 << 1),
 };
 
-struct park_call_args {
+struct ast_park_call_args {
+	/*! How long to wait in the parking lot before the call gets sent back
+	 *  to the specified return extension (or a best guess at where it came
+	 *  from if not explicitly specified). */
 	int timeout;
+	/*! An output parameter to store the parking space where the parked caller
+	 *  was placed. */
 	int *extout;
 	const char *orig_chan_name;
 	struct ast_parkinglot *parkinglot;
@@ -440,7 +449,8 @@
 };
 
 /* Park a call */
-static int park_call_full(struct ast_channel *chan, struct ast_channel *peer, struct park_call_args *args)
+static int ast_park_call_full(struct ast_channel *chan, struct ast_channel *peer, 
+	struct ast_park_call_args *args)
 {
 	struct parkeduser *pu;
 	int i, x = -1, parking_range;
@@ -489,7 +499,7 @@
 		/* Select parking space within range */
 		parking_range = args->parkinglot->parking_stop - args->parkinglot->parking_start + 1;
 
-		if (ast_test_flag(args, PARK_OPT_RANDOMIZE)) {
+		if (ast_test_flag(args, AST_PARK_OPT_RANDOMIZE)) {
 			start = ast_random() % (args->parkinglot->parking_stop - args->parkinglot->parking_start + 1);
 		} else {
 			start = args->parkinglot->parking_start;
@@ -531,7 +541,7 @@
 	
 	/* Put the parked channel on hold if we have two different channels */
 	if (chan != peer) {
-		if (ast_test_flag(args, PARK_OPT_RINGING)) {
+		if (ast_test_flag(args, AST_PARK_OPT_RINGING)) {
 			ast_indicate(pu->chan, AST_CONTROL_RINGING);
 		} else {
 			ast_indicate_data(pu->chan, AST_CONTROL_HOLD, 
@@ -621,12 +631,12 @@
 /*! \brief Park a call */
 int ast_park_call(struct ast_channel *chan, struct ast_channel *peer, int timeout, int *extout)
 {
-	struct park_call_args args = {
+	struct ast_park_call_args args = {
 		.timeout = timeout,
 		.extout = extout,
 	};
 
-	return park_call_full(chan, peer, &args);
+	return ast_park_call_full(chan, peer, &args);
 }
 
 /* Park call via masquraded channel */
@@ -657,13 +667,13 @@
 	orig_chan_name = ast_strdupa(chan->name);
 
 	{
-		struct park_call_args args = {
+		struct ast_park_call_args args = {
 			.timeout = timeout,
 			.extout = extout,
 			.orig_chan_name = orig_chan_name,
 		};
 
-		park_call_full(chan, peer, &args);
+		ast_park_call_full(chan, peer, &args);
 	}
 
 	return 0;
@@ -2525,6 +2535,11 @@
 	return parkinglot;
 }
 
+AST_APP_OPTIONS(park_call_options, BEGIN_OPTIONS
+	AST_APP_OPTION('r', AST_PARK_OPT_RINGING),
+	AST_APP_OPTION('R', AST_PARK_OPT_RANDOMIZE),
+END_OPTIONS );
+
 /*! \brief Park a call */
 static int park_call_exec(struct ast_channel *chan, void *data)
 {
@@ -2542,6 +2557,20 @@
 	   lot context eventually */
 	int res = 0;
 
+	char *parse;
+	AST_DECLARE_APP_ARGS(app_args,
+		AST_APP_ARG(timeout);
+		AST_APP_ARG(return_con);
+		AST_APP_ARG(return_ext);
+		AST_APP_ARG(return_pri);
+		AST_APP_ARG(options);
+	);
+
+	if (!ast_strlen_zero(data)) {
+		parse = ast_strdupa(data);
+		AST_STANDARD_APP_ARGS(app_args, parse);
+	}
+
 	ast_copy_string(orig_exten, chan->exten, sizeof(orig_exten));
 
 	/* Check if the channel has a parking lot */
@@ -2553,25 +2582,47 @@
 		parkinglot = find_parkinglot(parkinglotname);	
 	}
 
-
 	/* Setup the exten/priority to be s/1 since we don't know
 	   where this call should return */
 	strcpy(chan->exten, "s");
 	chan->priority = 1;
+
 	/* Answer if call is not up */
 	if (chan->_state != AST_STATE_UP)
 		res = ast_answer(chan);
+
 	/* Sleep to allow VoIP streams to settle down */
 	if (!res)
 		res = ast_safe_sleep(chan, 1000);
+
 	/* Park the call */
 	if (!res) {
-		struct park_call_args args = {
+		struct ast_park_call_args args = {
 			.orig_chan_name = orig_chan_name,
 			.parkinglot = parkinglot,
 		};
-
-		res = park_call_full(chan, chan, &args);
+		struct ast_flags flags = { 0 };
+
+		if (!ast_strlen_zero(app_args.timeout)) {
+			if (sscanf(app_args.timeout, "%d", &args.timeout) != 1) {
+				ast_log(LOG_WARNING, "Invalid timeout '%s' provided\n", app_args.timeout);
+				args.timeout = 0;
+			}
+		}
+
+		args.return_con = app_args.return_con;
+		args.return_ext = app_args.return_ext;
+		if (!ast_strlen_zero(app_args.return_pri)) {
+			if (sscanf(app_args.return_pri, "%d", &args.return_pri) != 1) {
+				ast_log(LOG_WARNING, "Invalid priority '%s' specified\n", app_args.return_pri);
+				args.return_pri = 0;
+			}
+		}
+
+		ast_app_parse_options(park_call_options, &flags, NULL, NULL);
+		args.flags = flags.flags;
+
+		res = ast_park_call_full(chan, chan, &args);
 		/* Continue on in the dialplan */
 		if (res == 1) {
 			ast_copy_string(chan->exten, orig_exten, sizeof(chan->exten));




More information about the asterisk-commits mailing list