[asterisk-commits] russell: branch russell/parking_updates r114616 - /team/russell/parking_updat...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 24 13:20:05 CDT 2008


Author: russell
Date: Thu Apr 24 13:20:05 2008
New Revision: 114616

URL: http://svn.digium.com/view/asterisk?view=rev&rev=114616
Log:
Put args to park_call_full in a struct, since I'm about to add some more ...

Modified:
    team/russell/parking_updates/main/features.c

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=114616&r1=114615&r2=114616
==============================================================================
--- team/russell/parking_updates/main/features.c (original)
+++ team/russell/parking_updates/main/features.c Thu Apr 24 13:20:05 2008
@@ -423,8 +423,15 @@
 	return AST_DEVICE_INUSE;
 }
 
+struct park_call_args {
+	int timeout;
+	int *extout;
+	const char *orig_chan_name;
+	struct ast_parkinglot *parkinglot;
+};
+
 /* Park a call */
-static int park_call_full(struct ast_channel *chan, struct ast_channel *peer, int timeout, int *extout, char *orig_chan_name, struct ast_parkinglot *parkinglot)
+static int park_call_full(struct ast_channel *chan, struct ast_channel *peer, struct park_call_args *args)
 {
 	struct parkeduser *pu, *cur;
 	int i, x = -1, parking_range;
@@ -437,41 +444,41 @@
 	if (parkinglotname) {
 		if (option_debug)
 			ast_log(LOG_DEBUG, "Found chanvar Parkinglot: %s\n", parkinglotname);
-		parkinglot = find_parkinglot(parkinglotname);	
-	}
-	if (!parkinglot)
-		parkinglot = default_parkinglot;
-
-	parkinglot_addref(parkinglot);
+		args->parkinglot = find_parkinglot(parkinglotname);	
+	}
+	if (!args->parkinglot)
+		args->parkinglot = default_parkinglot;
+
+	parkinglot_addref(args->parkinglot);
 	if (option_debug)
-		ast_log(LOG_DEBUG, "Parkinglot: %s\n", parkinglot->name);
+		ast_log(LOG_DEBUG, "Parkinglot: %s\n", args->parkinglot->name);
 
 	/* Allocate memory for parking data */
 	if (!(pu = ast_calloc(1, sizeof(*pu)))) {
-		parkinglot_unref(parkinglot);
+		parkinglot_unref(args->parkinglot);
 		return -1;
 	}
 
 	/* Lock parking list */
-	AST_LIST_LOCK(&parkinglot->parkings);
+	AST_LIST_LOCK(&args->parkinglot->parkings);
 	/* Check for channel variable PARKINGEXTEN */
 	parkingexten = pbx_builtin_getvar_helper(chan, "PARKINGEXTEN");
 	if (!ast_strlen_zero(parkingexten)) {
-		if (ast_exists_extension(NULL, parkinglot->parking_con, parkingexten, 1, NULL)) {
-			AST_LIST_UNLOCK(&parkinglot->parkings);
-			parkinglot_unref(parkinglot);
+		if (ast_exists_extension(NULL, args->parkinglot->parking_con, parkingexten, 1, NULL)) {
+			AST_LIST_UNLOCK(&args->parkinglot->parkings);
+			parkinglot_unref(args->parkinglot);
 			ast_free(pu);
-			ast_log(LOG_WARNING, "Requested parking extension already exists: %s@%s\n", parkingexten, parkinglot->parking_con);
+			ast_log(LOG_WARNING, "Requested parking extension already exists: %s@%s\n", parkingexten, args->parkinglot->parking_con);
 			return 1;	/* Continue execution if possible */
 		}
 		ast_copy_string(pu->parkingexten, parkingexten, sizeof(pu->parkingexten));
 		x = atoi(parkingexten);
 	} else {
 		/* Select parking space within range */
-		parking_range = parkinglot->parking_stop - parkinglot->parking_start+1;
+		parking_range = args->parkinglot->parking_stop - args->parkinglot->parking_start+1;
 		for (i = 0; i < parking_range; i++) {
-			x = (i + parkinglot->parking_offset) % parking_range + parkinglot->parking_start;
-			AST_LIST_TRAVERSE(&parkinglot->parkings, cur, list) {
+			x = (i + args->parkinglot->parking_offset) % parking_range + args->parkinglot->parking_start;
+			AST_LIST_TRAVERSE(&args->parkinglot->parkings, cur, list) {
 				if (cur->parkingnum == x)
 					break;
 			}
@@ -482,13 +489,13 @@
 		if (!(i < parking_range)) {
 			ast_log(LOG_WARNING, "No more parking spaces\n");
 			ast_free(pu);
-			AST_LIST_UNLOCK(&parkinglot->parkings);
-			parkinglot_unref(parkinglot);
+			AST_LIST_UNLOCK(&args->parkinglot->parkings);
+			parkinglot_unref(args->parkinglot);
 			return -1;
 		}
 		/* Set pointer for next parking */
-		if (parkinglot->parkfindnext) 
-			parkinglot->parking_offset = x - parkinglot->parking_start + 1;
+		if (args->parkinglot->parkfindnext) 
+			args->parkinglot->parking_offset = x - args->parkinglot->parking_start + 1;
 	}
 	
 	chan->appl = "Parked Call";
@@ -499,16 +506,16 @@
 	/* Put the parked channel on hold if we have two different channels */
 	if (chan != peer) {
 		ast_indicate_data(pu->chan, AST_CONTROL_HOLD, 
-			S_OR(parkinglot->mohclass, NULL),
-			!ast_strlen_zero(parkinglot->mohclass) ? strlen(parkinglot->mohclass) + 1 : 0);
+			S_OR(args->parkinglot->mohclass, NULL),
+			!ast_strlen_zero(args->parkinglot->mohclass) ? strlen(args->parkinglot->mohclass) + 1 : 0);
 	}
 	
 	pu->start = ast_tvnow();
 	pu->parkingnum = x;
-	pu->parkinglot = parkinglot;
-	pu->parkingtime = (timeout > 0) ? timeout : parkinglot->parkingtime;
-	if (extout)
-		*extout = x;
+	pu->parkinglot = args->parkinglot;
+	pu->parkingtime = (args->timeout > 0) ? args->timeout : args->parkinglot->parkingtime;
+	if (args->extout)
+		*(args->extout) = x;
 
 	if (peer) 
 		ast_copy_string(pu->peername, peer->name, sizeof(pu->peername));
@@ -518,16 +525,16 @@
 	ast_copy_string(pu->context, S_OR(chan->macrocontext, chan->context), sizeof(pu->context));
 	ast_copy_string(pu->exten, S_OR(chan->macroexten, chan->exten), sizeof(pu->exten));
 	pu->priority = chan->macropriority ? chan->macropriority : chan->priority;
-	AST_LIST_INSERT_TAIL(&parkinglot->parkings, pu, list);
+	AST_LIST_INSERT_TAIL(&args->parkinglot->parkings, pu, list);
 
 	/* If parking a channel directly, don't quiet yet get parking running on it */
 	if (peer == chan) 
 		pu->notquiteyet = 1;
-	AST_LIST_UNLOCK(&parkinglot->parkings);
+	AST_LIST_UNLOCK(&args->parkinglot->parkings);
 
 	/* Wake up the (presumably select()ing) thread */
 	pthread_kill(parking_thread, SIGURG);
-	ast_verb(2, "Parked %s on %d (lot %s). Will timeout back to extension [%s] %s, %d in %d seconds\n", pu->chan->name, pu->parkingnum, parkinglot->name, pu->context, pu->exten, pu->priority, (pu->parkingtime/1000));
+	ast_verb(2, "Parked %s on %d (lot %s). Will timeout back to extension [%s] %s, %d in %d seconds\n", pu->chan->name, pu->parkingnum, args->parkinglot->name, pu->context, pu->exten, pu->priority, (pu->parkingtime/1000));
 
 	if (pu->parkingnum != -1)
 		snprintf(pu->parkingexten, sizeof(pu->parkingexten), "%d", x);
@@ -550,11 +557,11 @@
 		ast_adsi_unload_session(peer);
 	}
 
-	con = ast_context_find_or_create(NULL, NULL, parkinglot->parking_con, registrar);
+	con = ast_context_find_or_create(NULL, NULL, args->parkinglot->parking_con, registrar);
 	if (!con)	/* Still no context? Bad */
-		ast_log(LOG_ERROR, "Parking context '%s' does not exist and unable to create\n", parkinglot->parking_con);
+		ast_log(LOG_ERROR, "Parking context '%s' does not exist and unable to create\n", args->parkinglot->parking_con);
 	/* Tell the peer channel the number of the parking space */
-	if (peer && ((pu->parkingnum != -1 && ast_strlen_zero(orig_chan_name)) || !strcasecmp(peer->name, orig_chan_name))) { /* Only say number if it's a number and the channel hasn't been masqueraded away */
+	if (peer && ((pu->parkingnum != -1 && ast_strlen_zero(args->orig_chan_name)) || !strcasecmp(peer->name, args->orig_chan_name))) { /* Only say number if it's a number and the channel hasn't been masqueraded away */
 		/* If a channel is masqueraded into peer while playing back the parking slot number do not continue playing it back. This is the case if an attended transfer occurs. */
 		ast_set_flag(peer, AST_FLAG_MASQ_NOSTREAM);
 		ast_say_digits(peer, pu->parkingnum, "", peer->language);
@@ -562,13 +569,13 @@
 	}
 	if (con) {
 		if (!ast_add_extension2(con, 1, pu->parkingexten, 1, NULL, NULL, parkedcall, ast_strdup(pu->parkingexten), ast_free_ptr, registrar))
-			notify_metermaids(pu->parkingexten, parkinglot->parking_con, AST_DEVICE_INUSE);
+			notify_metermaids(pu->parkingexten, args->parkinglot->parking_con, AST_DEVICE_INUSE);
 	}
 	if (pu->notquiteyet) {
 		/* Wake up parking thread if we're really done */
 		ast_indicate_data(pu->chan, AST_CONTROL_HOLD, 
-			S_OR(parkinglot->mohclass, NULL),
-			!ast_strlen_zero(parkinglot->mohclass) ? strlen(parkinglot->mohclass) + 1 : 0);
+			S_OR(args->parkinglot->mohclass, NULL),
+			!ast_strlen_zero(args->parkinglot->mohclass) ? strlen(args->parkinglot->mohclass) + 1 : 0);
 		pu->notquiteyet = 0;
 		pthread_kill(parking_thread, SIGURG);
 	}
@@ -578,7 +585,12 @@
 /*! \brief Park a call */
 int ast_park_call(struct ast_channel *chan, struct ast_channel *peer, int timeout, int *extout)
 {
-	return park_call_full(chan, peer, timeout, extout, NULL, NULL);
+	struct park_call_args args = {
+		.timeout = timeout,
+		.extout = extout,
+	};
+
+	return park_call_full(chan, peer, &args);
 }
 
 /* Park call via masquraded channel */
@@ -608,7 +620,15 @@
 
 	orig_chan_name = ast_strdupa(chan->name);
 
-	park_call_full(chan, peer, timeout, extout, orig_chan_name, NULL);
+	{
+		struct park_call_args args = {
+			.timeout = timeout,
+			.extout = extout,
+			.orig_chan_name = orig_chan_name,
+		};
+
+		park_call_full(chan, peer, &args);
+	}
 
 	return 0;
 }
@@ -2510,7 +2530,12 @@
 		res = ast_safe_sleep(chan, 1000);
 	/* Park the call */
 	if (!res) {
-		res = park_call_full(chan, chan, 0, NULL, orig_chan_name, parkinglot);
+		struct park_call_args args = {
+			.orig_chan_name = orig_chan_name,
+			.parkinglot = parkinglot,
+		};
+
+		res = 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