[asterisk-commits] jpeeler: trunk r122433 - in /trunk: apps/app_parkandannounce.c main/features.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 12 18:08:37 CDT 2008


Author: jpeeler
Date: Thu Jun 12 18:08:37 2008
New Revision: 122433

URL: http://svn.digium.com/view/asterisk?view=rev&rev=122433
Log:
(closes issue 0012193)
Reported by: davidw
Patch by: Corydon76, modified by me to work properly with ParkAndAnnounce app

Modified:
    trunk/apps/app_parkandannounce.c
    trunk/main/features.c

Modified: trunk/apps/app_parkandannounce.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_parkandannounce.c?view=diff&rev=122433&r1=122432&r2=122433
==============================================================================
--- trunk/apps/app_parkandannounce.c (original)
+++ trunk/apps/app_parkandannounce.c Thu Jun 12 18:08:37 2008
@@ -113,7 +113,9 @@
 	/* we are using masq_park here to protect * from touching the channel once we park it.  If the channel comes out of timeout
 	before we are done announcing and the channel is messed with, Kablooeee.  So we use Masq to prevent this.  */
 
-	ast_masq_park_call(chan, NULL, timeout, &lot);
+	res = ast_masq_park_call(chan, NULL, timeout, &lot);
+	if (res == -1)
+		return res;
 
 	ast_verb(3, "Call Parking Called, lot: %d, timeout: %d, context: %s\n", lot, timeout, args.return_context);
 

Modified: trunk/main/features.c
URL: http://svn.digium.com/view/asterisk/trunk/main/features.c?view=diff&rev=122433&r1=122432&r2=122433
==============================================================================
--- trunk/main/features.c (original)
+++ trunk/main/features.c Thu Jun 12 18:08:37 2008
@@ -494,15 +494,28 @@
 	/* 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)) {
+		/*!\note The API forces us to specify a numeric parking slot, even
+		 * though the architecture would tend to support non-numeric extensions
+		 * (as are possible with SIP, for example).  Hence, we enforce that
+		 * limitation here.  If extout was not numeric, we could permit
+		 * arbitrary non-numeric extensions.
+		 */
+        if (sscanf(parkingexten, "%d", &x) != 1 || x < 0) {
+			AST_LIST_UNLOCK(&parkinglot->parkings);
+			parkinglot_unref(parkinglot);
+            free(pu);
+            ast_log(LOG_WARNING, "PARKINGEXTEN does not indicate a valid parking slot: '%s'.\n", parkingexten);
+            return 1;   /* Continue execution if possible */
+        }
+        snprintf(pu->parkingexten, sizeof(pu->parkingexten), "%d", x);
+
+		if (ast_exists_extension(NULL, parkinglot->parking_con, pu->parkingexten, 1, NULL)) {
 			AST_LIST_UNLOCK(&parkinglot->parkings);
 			parkinglot_unref(parkinglot);
 			ast_free(pu);
 			ast_log(LOG_WARNING, "Requested parking extension already exists: %s@%s\n", parkingexten, parkinglot->parking_con);
 			return 1;	/* Continue execution if possible */
 		}
-		ast_copy_string(pu->parkingexten, parkingexten, sizeof(pu->parkingexten));
-		x = atoi(parkingexten);
 	} else {
 		int start;
 		struct parkeduser *cur = NULL;
@@ -544,6 +557,7 @@
 		/* Set pointer for next parking */
 		if (parkinglot->parkfindnext) 
 			parkinglot->parking_offset = x - parkinglot->parking_start + 1;
+		snprintf(pu->parkingexten, sizeof(pu->parkingexten), "%d", x);
 	}
 	
 	chan->appl = "Parked Call";
@@ -595,8 +609,6 @@
 	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));
 
-	if (pu->parkingnum != -1)
-		snprintf(pu->parkingexten, sizeof(pu->parkingexten), "%d", x);
 	manager_event(EVENT_FLAG_CALL, "ParkedCall",
 		"Exten: %s\r\n"
 		"Channel: %s\r\n"
@@ -620,7 +632,7 @@
 	if (!con)	/* Still no context? Bad */
 		ast_log(LOG_ERROR, "Parking context '%s' does not exist and unable to create\n", parkinglot->parking_con);
 	/* Tell the peer channel the number of the parking space */
-	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 (peer && (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);
@@ -658,6 +670,7 @@
 	struct ast_channel *chan;
 	struct ast_frame *f;
 	char *orig_chan_name = NULL;
+	int park_status;
 
 	/* Make a new, fake channel that we'll use to masquerade in the real one */
 	if (!(chan = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, rchan->accountcode, rchan->exten, rchan->context, rchan->amaflags, "Parked/%s",rchan->name))) {
@@ -686,7 +699,12 @@
 			.orig_chan_name = orig_chan_name,
 		};
 
-		ast_park_call_full(chan, peer, &args);
+		park_status = ast_park_call_full(chan, peer, &args);
+		if (park_status == 1) {
+		/* would be nice to play "invalid parking extension" */
+			ast_hangup(chan);
+			return -1;
+		}
 	}
 
 	return 0;




More information about the asterisk-commits mailing list