[svn-commits] jpeeler: branch jpeeler/feature14882 r281910 - /team/jpeeler/feature14882/main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Aug 11 18:08:00 CDT 2010


Author: jpeeler
Date: Wed Aug 11 18:07:57 2010
New Revision: 281910

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=281910
Log:
checkpoint, mainly simplified the calls to the internal park functions

Modified:
    team/jpeeler/feature14882/main/features.c

Modified: team/jpeeler/feature14882/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/jpeeler/feature14882/main/features.c?view=diff&rev=281910&r1=281909&r2=281910
==============================================================================
--- team/jpeeler/feature14882/main/features.c (original)
+++ team/jpeeler/feature14882/main/features.c Wed Aug 11 18:07:57 2010
@@ -708,23 +708,23 @@
 	const char *orig_chan_name;
 	const char *return_con;
 	const char *return_ext;
-	const char *parkexten;
 	int return_pri;
 	uint32_t flags;
 	/*! Parked user that has already obtained a parking space */
 	struct parkeduser *pu;
+	struct ast_parkinglot *parkinglot; /*! parkinglot to be parked in */
 };
 
-static struct parkeduser *park_space_reserve(struct ast_channel *chan, struct ast_channel *peer, struct ast_park_call_args *args, struct ast_parkinglot *parkinglot)
+static struct parkeduser *park_space_reserve(struct ast_channel *chan, struct ast_channel *peer, struct ast_park_call_args *args)
 {
 	struct parkeduser *pu;
 	int i, parking_space = -1, parking_range;
 	const char *parkinglotname = NULL;
 	const char *parkingexten;
-
-	/* HACK: jpeeler fix this junk */
-	if (args->parkexten) {
-		parkinglot = ao2_callback(parkinglots, 0, find_parkinglot_by_exten_cb, (void *) args->parkexten);
+	struct ast_parkinglot *parkinglot;
+
+	if (args->parkinglot) {
+		parkinglot = args->parkinglot;
 	}
 
 	if (parkinglot) {
@@ -888,7 +888,7 @@
 	const char *event_from;
 
 	if (pu == NULL)
-		args->pu = pu = park_space_reserve(chan, peer, args, NULL);
+		args->pu = pu = park_space_reserve(chan, peer, args);
 	if (pu == NULL)
 		return 1; /* Continue execution if possible */
 
@@ -1031,16 +1031,19 @@
 /*! \brief Park a call */
 int ast_park_call(struct ast_channel *chan, struct ast_channel *peer, int timeout, const char *parkexten, int *extout)
 {
+	/* JPEELER check reference handling */
+	struct ast_parkinglot *found_lot = ao2_callback(parkinglots, 0, find_parkinglot_by_exten_cb, &parkexten);
+
 	struct ast_park_call_args args = {
 		.timeout = timeout,
 		.extout = extout,
-		.parkexten = parkexten,
+		.parkinglot = found_lot,
 	};
 
 	return park_call_full(chan, peer, &args);
 }
 
-static int masq_park_call(struct ast_channel *rchan, struct ast_channel *peer, int timeout, int *extout, int play_announcement, struct ast_park_call_args *args, struct ast_parkinglot *parkinglot)
+static int masq_park_call(struct ast_channel *rchan, struct ast_channel *peer, int timeout, int *extout, int play_announcement, struct ast_park_call_args *args)
 {
 	struct ast_channel *chan;
 	struct ast_frame *f;
@@ -1056,7 +1059,7 @@
 		args->extout = extout;
 	}
 
-	if ((args->pu = park_space_reserve(rchan, peer, args, parkinglot)) == NULL) { /* create parkinglot */
+	if ((args->pu = park_space_reserve(rchan, peer, args)) == NULL) { /* create parkinglot */
 		if (peer) { /* if error */
 			ast_stream_and_wait(peer, "beeperr", "");
 		}
@@ -1073,7 +1076,6 @@
 	chan->readformat = rchan->readformat;
 	chan->writeformat = rchan->writeformat;
 	ast_channel_masquerade(chan, rchan);
-	ast_string_field_set(chan,parkinglot,rchan->parkinglot); /* set the parkinglot */
 
 	/* Setup the extensions and such */
 	set_c_e_p(chan, rchan->context, rchan->exten, rchan->priority);
@@ -1110,17 +1112,12 @@
 /* Park call via masqueraded channel */
 int ast_masq_park_call(struct ast_channel *rchan, struct ast_channel *peer, int timeout, int *extout)
 {
-	return masq_park_call(rchan, peer, timeout, extout, 0, NULL, NULL);
-}
-
-static int masq_park_call_announce_args(struct ast_channel *rchan, struct ast_channel *peer, struct ast_park_call_args *args, struct ast_parkinglot *parkinglot)
-{
-	return masq_park_call(rchan, peer, 0, NULL, 1, args, parkinglot);
-}
-
-static int masq_park_call_announce(struct ast_channel *rchan, struct ast_channel *peer, int timeout, int *extout, struct ast_parkinglot *parkinglot)
-{
-	return masq_park_call(rchan, peer, timeout, extout, 1, NULL, parkinglot);
+	return masq_park_call(rchan, peer, timeout, extout, 0, NULL);
+}
+
+static int masq_park_call_announce(struct ast_channel *rchan, struct ast_channel *peer, struct ast_park_call_args *args)
+{
+	return masq_park_call(rchan, peer, 0, NULL, 1, args);
 }
 
 #ifdef TEST_FRAMEWORK
@@ -1257,7 +1254,7 @@
 	}
 	pbx_builtin_setvar_helper(test_channel1, "PARKINGLOT", unique_parkinglot);
 	pbx_builtin_setvar_helper(test_channel1, "PARKINGDYNPOS", parkinglot_range);
-	if (masq_park_call(test_channel1, NULL, 0, NULL, 0, &args, NULL) == AST_FEATURE_RETURN_PARKFAILED) {
+	if (masq_park_call(test_channel1, NULL, 0, NULL, 0, &args) == AST_FEATURE_RETURN_PARKFAILED) {
 		goto exit_features_test;
 	}
 	/* hangup zombie channel */
@@ -1321,17 +1318,18 @@
  * Setup channel, set return exten,priority to 's,1'
  * answer chan, sleep chan, park call
 */
+/* JPEELER should pass args as data instead of parkinglot */
 static int builtin_parkcall(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, const char *code, int sense, void *data)
 {
 	struct ast_channel *parker;
 	struct ast_channel *parkee;
 	int res = 0;
-	struct ast_parkinglot* parkinglot = NULL;
-
-	if (data){
-		parkinglot = (struct ast_parkinglot *) data;
+	struct ast_park_call_args args = {0,};
+
+	if (data) {
+		args.parkinglot = (struct ast_parkinglot *) data;
 		if (option_debug)
-			ast_log(LOG_NOTICE, "Parkinglot specified for builtin_parkcall: %s\n", parkinglot->name);
+			ast_log(LOG_NOTICE, "Parkinglot specified for builtin_parkcall: %s\n", args.parkinglot->name);
 	}
 
 	set_peers(&parker, &parkee, peer, chan, sense);
@@ -1349,7 +1347,7 @@
 		res = ast_safe_sleep(chan, 1000);
 
 	if (!res) { /* one direction used to call park_call.... */
-		res = masq_park_call_announce(parkee, parker, 0, NULL, parkinglot);
+		res = masq_park_call_announce(parkee, parker, &args);
 		/* PBX should hangup zombie channel if a masquerade actually occurred (res=0) */
 	}
 
@@ -1663,11 +1661,9 @@
 	struct ast_channel *transferer;
 	struct ast_channel *transferee;
 	const char *transferer_real_context;
-	struct ao2_iterator iter;
-	struct ast_parkinglot *parkinglot = NULL;
+	struct ast_parkinglot *found_lot = NULL;
 	char xferto[256];
 	int res, parkstatus = 0;
-	int xferto_valid = 0;
 
 	set_peers(&transferer, &transferee, peer, chan, sense);
 	transferer_real_context = real_ctx(transferer, transferee);
@@ -1694,21 +1690,15 @@
 		return res;
 	}
 
-	/* check whether xferto is a valid parking extension in parkinglots or not */
-	iter = ao2_iterator_init(parkinglots, 0);
-	while ((parkinglot = ao2_iterator_next(&iter))) {
-		if (!strcmp(xferto,parkinglot->parkext)) { 
-			xferto_valid = 1;
-			break; /* found it */
-		}
-		ao2_ref(parkinglot, -1);
-	}
-
-	if (xferto_valid) {
+	found_lot = ao2_callback(parkinglots, 0, find_parkinglot_by_exten_cb, &xferto);
+	if (found_lot) {
+		struct ast_park_call_args args = {
+			.parkinglot = found_lot,
+		};
 		res = finishup(transferee);
 		if (res)
 			res = -1;
-		else if (!(parkstatus = masq_park_call_announce(transferee, transferer, 0, NULL, parkinglot))) {	/* success */
+		else if (!(parkstatus = masq_park_call_announce(transferee, transferer, &args))) {	/* success */
 			/* We return non-zero, but tell the PBX not to hang the channel when
 			   the thread dies -- We have to be careful now though.  We are responsible for 
 			   hanging up the channel, else it will never be hung up! */
@@ -3944,7 +3934,6 @@
 	char *orig_chan_name = ast_strdupa(chan->name);
 	char orig_exten[AST_MAX_EXTENSION];
 	int orig_priority = chan->priority;
-	struct ast_parkinglot *parkinglot;
 
 	/* Data is unused at the moment but could contain a parking
 	   lot context eventually */
@@ -4008,8 +3997,9 @@
 		ast_app_parse_options(park_call_options, &flags, NULL, app_args.options);
 		args.flags = flags.flags;
 
-		parkinglot = ao2_callback(parkinglots, 0, find_parkinglot_by_exten_cb, &orig_exten);
-		res = masq_park_call_announce_args(chan, chan, &args, parkinglot);
+		/* JPEELER: this appears unsafe */
+		args.parkinglot = ao2_callback(parkinglots, 0, find_parkinglot_by_exten_cb, &orig_exten);
+		res = masq_park_call_announce(chan, chan, &args);
 		/* Continue on in the dialplan */
 		if (res == 1) {
 			ast_copy_string(chan->exten, orig_exten, sizeof(chan->exten));
@@ -5164,6 +5154,7 @@
  * Get channels involved in park, create event.
  * \return Always 0
 */
+/* JPEELER add ability to set parkinglot */
 static int manager_park(struct mansession *s, const struct message *m)
 {
 	const char *channel = astman_get_header(m, "Channel");




More information about the svn-commits mailing list