[asterisk-commits] jpeeler: branch jpeeler/bug13494 r171690 - /team/jpeeler/bug13494/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 27 15:55:15 CST 2009


Author: jpeeler
Date: Tue Jan 27 15:55:15 2009
New Revision: 171690

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=171690
Log:
Redo park_space_reserve to return the parkeduser rather than just the parking number. This allows the parkeduser to be placed in the parkinglot immediately thereby avoiding any possibility of another parking reserve request to take an already reserved space.


Modified:
    team/jpeeler/bug13494/res/res_features.c

Modified: team/jpeeler/bug13494/res/res_features.c
URL: http://svn.digium.com/svn-view/asterisk/team/jpeeler/bug13494/res/res_features.c?view=diff&rev=171690&r1=171689&r2=171690
==============================================================================
--- team/jpeeler/bug13494/res/res_features.c (original)
+++ team/jpeeler/bug13494/res/res_features.c Tue Jan 27 15:55:15 2009
@@ -310,18 +310,21 @@
 		return AST_DEVICE_INUSE;
 }
 
-static int park_space_reserve(struct ast_channel *chan)
-{
-	struct parkeduser *cur;
+static struct parkeduser *park_space_reserve(struct ast_channel *chan)
+{
+	struct parkeduser *pu, *cur;
 	int i, parking_space = -1, parking_range;
 	const char *parkingexten;
+
+	/* Allocate memory for parking data */
+	if (!(pu = ast_calloc(1, sizeof(*pu)))) 
+		return NULL;
 
 	/* Lock parking lot */
 	ast_mutex_lock(&parking_lock);
 	/* Check for channel variable PARKINGEXTEN */
 	parkingexten = pbx_builtin_getvar_helper(chan, "PARKINGEXTEN");
 	if (!ast_strlen_zero(parkingexten)) {
-		char validparkingexten[AST_MAX_EXTENSION];
 
 		/*!\note The API forces us to specify a numeric parking slot, even
 		 * though the architecture would tend to support non-numeric extensions
@@ -332,14 +335,16 @@
 		if (sscanf(parkingexten, "%d", &parking_space) != 1 || parking_space < 0) {
 			ast_log(LOG_WARNING, "PARKINGEXTEN does not indicate a valid parking slot: '%s'.\n", parkingexten);
 			ast_mutex_unlock(&parking_lock);
-			return -1;
-		}
-		snprintf(validparkingexten, sizeof(validparkingexten), "%d", parking_space);
-
-		if (ast_exists_extension(NULL, parking_con, validparkingexten, 1, NULL)) {
+			free(pu);
+			return NULL;
+		}
+		snprintf(pu->parkingexten, sizeof(pu->parkingexten), "%d", parking_space);
+
+		if (ast_exists_extension(NULL, parking_con, pu->parkingexten, 1, NULL)) {
 			ast_mutex_unlock(&parking_lock);
 			ast_log(LOG_WARNING, "Requested parking extension already exists: %s@%s\n", parkingexten, parking_con);
-			return -1;
+			free(pu);
+			return NULL;
 		}
 	} else {
 		/* Select parking space within range */
@@ -359,33 +364,36 @@
 		if (!(i < parking_range)) {
 			ast_log(LOG_WARNING, "No more parking spaces\n");
 			ast_mutex_unlock(&parking_lock);
-			return -1;
+			free(pu);
+			return NULL;
 		}
 		/* Set pointer for next parking */
 		if (parkfindnext) 
 			parking_offset = parking_space - parking_start + 1;
-	}
+		snprintf(pu->parkingexten, sizeof(pu->parkingexten), "%d", parking_space);
+	}
+	
+	pu->notquiteyet = 1;
+	pu->parkingnum = parking_space;
+	pu->next = parkinglot;
+	parkinglot = pu;
 	ast_mutex_unlock(&parking_lock);
 
-	return parking_space;
-}
-
-static int park_call_full(struct ast_channel *chan, struct ast_channel *peer, int timeout, int *extout, const char *orig_chan_name, int reserved_space)
-{
-	struct parkeduser *pu;
+	return pu;
+}
+
+static int park_call_full(struct ast_channel *chan, struct ast_channel *peer, int timeout, int *extout, const char *orig_chan_name, struct parkeduser *pu)
+{
 	struct ast_context *con;
-	
-	/* Allocate memory for parking data */
-	if (!(pu = ast_calloc(1, sizeof(*pu)))) 
-		return -1;
-
+	int parkingnum_copy;
+	
 	/* Get a valid space if not already done */
-	if (reserved_space < 0)
-		reserved_space = park_space_reserve(chan);
-	if (reserved_space < 0)
+	if (pu == NULL)
+		pu = park_space_reserve(chan);
+	if (pu == NULL)
 		return 1; /* Continue execution if possible */
 
-	snprintf(pu->parkingexten, sizeof(pu->parkingexten), "%d", reserved_space);
+	snprintf(pu->parkingexten, sizeof(pu->parkingexten), "%d", pu->parkingnum);
 	
 	chan->appl = "Parked Call";
 	chan->data = NULL; 
@@ -400,10 +408,9 @@
 	}
 	
 	pu->start = ast_tvnow();
-	pu->parkingnum = reserved_space;
 	pu->parkingtime = (timeout > 0) ? timeout : parkingtime;
 	if (extout)
-		*extout = reserved_space;
+		*extout = pu->parkingnum;
 
 	if (peer) { 
 		/* This is so ugly that it hurts, but implementing get_base_channel() on local channels
@@ -435,12 +442,12 @@
 	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;
-	pu->next = parkinglot;
-	parkinglot = pu;
-
-	/* If parking a channel directly, don't quite yet get parking running on it */
-	if (peer == chan) 
-		pu->notquiteyet = 1;
+	parkingnum_copy = pu->parkingnum;
+
+	/* If parking a channel directly (peer == chan), don't quite yet get parking running on it.
+     * All parking lot entires are put into the parking lot with notquiteyet on. */
+	if (peer != chan) 
+		pu->notquiteyet = 0;
 
 	if (option_verbose > 1) 
 		ast_verbose(VERBOSE_PREFIX_2 "Parked %s on %d@%s. Will timeout back to extension [%s] %s, %d in %d seconds\n", pu->chan->name, pu->parkingnum, parking_con, pu->context, pu->exten, pu->priority, (pu->parkingtime/1000));
@@ -474,7 +481,6 @@
 		}
 	}
 
-	//ast_mutex_unlock(&parking_lock);
 	/* Wake up the (presumably select()ing) thread */
 	pthread_kill(parking_thread, SIGURG);
 
@@ -483,7 +489,7 @@
 		/* Make sure we don't start saying digits to the channel being parked */
 		ast_set_flag(peer, AST_FLAG_MASQ_NOSTREAM);
 		/* Tell the peer channel the number of the parking space */
-		ast_say_digits(peer, reserved_space, "", peer->language);
+		ast_say_digits(peer, parkingnum_copy, "", peer->language);
 		ast_clear_flag(peer, AST_FLAG_MASQ_NOSTREAM);
 	}
 
@@ -503,17 +509,17 @@
 	after these channels too */
 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, -1);
+	return park_call_full(chan, peer, timeout, extout, NULL, NULL);
 }
 
 static int masq_park_call(struct ast_channel *rchan, struct ast_channel *peer, int timeout, int *extout, int play_announcement, const char *orig_chan_name)
 {
 	struct ast_channel *chan;
 	struct ast_frame *f;
-	int reserved_space;
+	struct parkeduser *pu;
 	int park_status;
 
-	if ((reserved_space = park_space_reserve(rchan)) < 0) {
+	if ((pu = park_space_reserve(rchan)) == NULL) {
 		ast_stream_and_wait(peer, "beeperr", peer->language, "");
 		return FEATURE_RETURN_PARKFAILED;
 	}
@@ -545,7 +551,7 @@
 		orig_chan_name = ast_strdupa(chan->name);
 	}
 
-	park_status = park_call_full(chan, peer, timeout, extout, orig_chan_name, reserved_space);
+	park_status = park_call_full(chan, peer, timeout, extout, orig_chan_name, pu);
 	if (park_status == 1) {
 		/* would be nice to play: "invalid parking extension" */
 		ast_hangup(chan);




More information about the asterisk-commits mailing list