[asterisk-commits] mmichelson: branch mmichelson/issue13538 r164563 - /team/mmichelson/issue1353...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 15 17:41:41 CST 2008


Author: mmichelson
Date: Mon Dec 15 17:41:40 2008
New Revision: 164563

URL: http://svn.digium.com/view/asterisk?view=rev&rev=164563
Log:
A sad commit...a sad commit indeed.

I'm removing the functionality of being able to prevent inheritance
of an audiohook from a parent channel. Why? Simply put, it does not
and cannot work. Instead, now if you disable audiohook inheritance
on a channel, it will just remove the audiohook source from inheritable
audiohooks list.

If there were some sort of pre-transfer hook, then it may actually be
possible to accomplish what I had originally set out to do in being
able to prevent the audiohook from being inherited...oh well. That may
be for another time.


Modified:
    team/mmichelson/issue13538/funcs/func_audiohookinherit.c

Modified: team/mmichelson/issue13538/funcs/func_audiohookinherit.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/issue13538/funcs/func_audiohookinherit.c?view=diff&rev=164563&r1=164562&r2=164563
==============================================================================
--- team/mmichelson/issue13538/funcs/func_audiohookinherit.c (original)
+++ team/mmichelson/issue13538/funcs/func_audiohookinherit.c Mon Dec 15 17:41:40 2008
@@ -39,7 +39,7 @@
 /*** DOCUMENTATION
  	<function name = "AUDIOHOOK_INHERIT" language="en_US">
 		<synopsis>
-			Set whether an audiohook may be inherited to/from another channel
+			Set whether an audiohook may be inherited to another channel
 		</snopsis>
 		<syntax>
 			<parameter name="source" required="true">
@@ -56,34 +56,30 @@
 		</syntax>
 		<description>
 			<para>By enabling audiohook inheritance on the channel, you are giving
-			permission for an audiohook to be inherited by a descendent channel. By
-			disabling audiohook inheritance on the channel, you are denying permission
-			for an audiohook to be inherited from a parent channel.
+			permission for an audiohook to be inherited by a descendent channel.
+			Inheritance may be be disabled at any point as well.
 
 			Example scenario:
 			exten => 2000,1,MixMonitor(blah.wav)
 			exten => 2000,n,Set(AUDIOHOOK_INHERIT(MixMonitor)=yes)
 			exten => 2000,n,Dial(SIP/2000)
 
-			exten => 3000,1,Set(AUDIOHOOK_INHERIT(MixMonitor)=no)
-			exten => 3000,n,Dial(SIP/3000)
-
 			exten => 4000,1,Dial(SIP/4000)
 
-			In this basic dialplan scenario, let's consider two sample calls
+			exten => 5000,1,MixMonitor(blah2.wav)
+			exten => 5000,n,Dial(SIP/5000)
+
+			In this basic dialplan scenario, let's consider the following sample calls
 			Call 1: Caller dials 2000. The person who answers then executes an attended
 					transfer to 4000.
 			Result: Since extension 2000 set MixMonitor to be inheritable, after the
 					transfer to 4000 has completed, the call will continue to be recorded
 					to blah.wav
 			
-			Call 2: Caller dials 2000. The person who answers then executes an attended
-					transfer to 3000.
-			Result: Since extension 2000 set MixMonitor to be inheritable, after the transfer
-					to 3000 has completed, we will attempt to continue the MixMonitor recording.
-					However, since extension 3000 has specifically requested not to inherit
-					MixMonitor from a parent channel, MixMonitor recording will stop once the
-					transfer has completed.</para>
+			Call 2: Caller dials 5000. The person who answers then executes an attended
+					transfer to 4000.
+			Result: Since extension 5000 did not set MixMonitor to be inheritable, the recording
+					will stop once the call has been transferred to 4000.</para>
 		</description>
 	</function>
  ***/
@@ -94,8 +90,7 @@
 };
 
 struct audiohook_inheritance_datastore {
-	AST_LIST_HEAD (inheritable_audiohook_list, inheritable_audiohook) allowed_list;
-	struct inheritable_audiohook_list unallowed_list;
+	AST_LIST_HEAD (, inheritable_audiohook) allowed_list;
 };
 
 static void audiohook_inheritance_fixup(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan);
@@ -118,36 +113,16 @@
  */
 static void audiohook_inheritance_fixup(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan)
 {
-	struct inheritable_audiohook *old_audiohook = NULL;
-	struct inheritable_audiohook *new_audiohook = NULL;
-	struct audiohook_inheritance_datastore *old_datastore = data;
-	struct ast_datastore *datastore =  ast_channel_datastore_find(new_chan, &audiohook_inheritance_info, NULL);
-	struct audiohook_inheritance_datastore *new_datastore = datastore ? datastore->data : NULL;
+	struct inheritable_audiohook *audiohook = NULL;
+	struct audiohook_inheritance_datastore *datastore = data;
 
 	ast_debug(2, "inheritance fixup occurring for channels %s(%p) and %s(%p)", old_chan->name, old_chan, new_chan->name, new_chan);
 
-	if (!new_datastore) {
-		ast_log(LOG_NOTICE, "The new channel has no datastore\n");
-		AST_LIST_TRAVERSE(&old_datastore->allowed_list, old_audiohook, list) {
-			ast_audiohook_move_by_source(old_chan, new_chan, old_audiohook->source);
-			ast_debug(3, "Moved audiohook %s from %s(%p) to %s(%p)\n", old_audiohook->source, old_chan->name, old_chan, new_chan->name, new_chan);
-		}
-		return;
-	}
-
-	AST_LIST_TRAVERSE(&old_datastore->allowed_list, old_audiohook, list) {
-		AST_LIST_TRAVERSE(&new_datastore->unallowed_list, new_audiohook, list) {
-			if (!strcasecmp(old_audiohook->source, new_audiohook->source)) {
-				break;
-			}
-		}
-		if (!new_audiohook) {
-			ast_audiohook_move_by_source(old_chan, new_chan, old_audiohook->source);
-			ast_debug(3, "Moved audiohook %s from %s(%p) to %s(%p)\n", old_audiohook->source, old_chan->name, old_chan, new_chan->name, new_chan);
-		} else {
-			ast_debug(3, "Audiohook %s prevented from being moved from %s(%p) to %s(%p)\n", old_audiohook->source, old_chan->name, old_chan, new_chan->name, new_chan);
-		}
-	}
+	AST_LIST_TRAVERSE(&datastore->allowed_list, audiohook, list) {
+		ast_audiohook_move_by_source(old_chan, new_chan, audiohook->source);
+		ast_debug(3, "Moved audiohook %s from %s(%p) to %s(%p)\n", audiohook->source, old_chan->name, old_chan, new_chan->name, new_chan);
+	}
+	return;
 }
 
 /*! \brief Destroy dynamically allocated data on an audiohook_inheritance_datastore
@@ -161,10 +136,6 @@
 	struct inheritable_audiohook *inheritable_audiohook = NULL;
 
 	while ((inheritable_audiohook = AST_LIST_REMOVE_HEAD(&audiohook_inheritance_datastore->allowed_list, list))) {
-		ast_free(inheritable_audiohook);
-	}
-	
-	while ((inheritable_audiohook = AST_LIST_REMOVE_HEAD(&audiohook_inheritance_datastore->unallowed_list, list))) {
 		ast_free(inheritable_audiohook);
 	}
 }
@@ -198,14 +169,14 @@
 /*! \brief Create a new inheritable_audiohook structure and add it to an audiohook_inheritance_datastore
  *
  * \param audiohook_inheritance_datastore The audiohook_inheritance_datastore we want to add the new inheritable_audiohook to
- * \param allow A boolean used to determine which list to add the source to
  * \param source The audiohook source for the newly created inheritable_audiohook
  * \return Returns 0 on success, non-zero on failure
  */
-static int setup_inheritable_audiohook(struct audiohook_inheritance_datastore *audiohook_inheritance_datastore, const int allow, const char *source)
-{
-	struct inheritable_audiohook *inheritable_audiohook = ast_calloc(1, sizeof(*inheritable_audiohook) + strlen(source));
-	struct inheritable_audiohook_list *inheritable_audiohook_list = allow ? &audiohook_inheritance_datastore->allowed_list : &audiohook_inheritance_datastore->unallowed_list;
+static int setup_inheritable_audiohook(struct audiohook_inheritance_datastore *audiohook_inheritance_datastore, const char *source)
+{
+	struct inheritable_audiohook *inheritable_audiohook = NULL;
+
+	inheritable_audiohook = ast_calloc(1, sizeof(*inheritable_audiohook) + strlen(source));
 
 	if (!inheritable_audiohook) {
 		ast_log(LOG_ERROR, "Could not allocate memory for inheritable audiohook structure\n");
@@ -213,7 +184,8 @@
 	}
 
 	strcpy(inheritable_audiohook->source, source);
-	AST_LIST_INSERT_TAIL(inheritable_audiohook_list, inheritable_audiohook, list);
+	AST_LIST_INSERT_TAIL(&audiohook_inheritance_datastore->allowed_list, inheritable_audiohook, list);
+	ast_debug(3, "Set audiohook %s to be inheritable\n", source);
 	return 0;
 }
 
@@ -248,38 +220,49 @@
 
 	/* Step 2: retrieve or set up datastore */
 	if (!(datastore = ast_channel_datastore_find(chan, &audiohook_inheritance_info, NULL))) {
-		if (!(inheritance_datastore = setup_inheritance_datastore(chan))) {
+		/* In the case where we cannot find the datastore, we can take a few shortcuts */
+		if (!allow) {
+			ast_debug(1, "Audiohook %s is already set to not be inheritable on channel %s\n", data, chan->name);
+			return 0;
+		} else if (!(inheritance_datastore = setup_inheritance_datastore(chan))) {
 			ast_log(LOG_NOTICE, "Unable to set up audiohook inheritance datastore on channel %s\n", chan->name);
 			return -1;
+		} else {
+			return setup_inheritable_audiohook(inheritance_datastore, data);
 		}
-		return setup_inheritable_audiohook(inheritance_datastore, allow, data);
 	} else {
 		inheritance_datastore = datastore->data;
 	}
 
-	/* Step 3: Traverse the lists to see if we're trying something redundant */
-
-	if (allow) {
-		AST_LIST_TRAVERSE(&inheritance_datastore->allowed_list, inheritable_audiohook, list) {
-			if (!strcasecmp(inheritable_audiohook->source, data)) {
+	/* Step 3: Traverse the list to see if we're trying something redundant */
+
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&inheritance_datastore->allowed_list, inheritable_audiohook, list) {
+		if (!strcasecmp(inheritable_audiohook->source, data)) {
+			if (allow) {
 				ast_debug(2, "Audiohook source %s is already set up to be inherited from channel %s\n", data, chan->name);
+				return 0;
+			} else {
+				ast_debug(2, "Removing inheritability of audiohook %s from channel %s\n", data, chan->name);
+				AST_LIST_REMOVE_CURRENT(list);
+				ast_free(inheritable_audiohook);
 				return 0;
 			}
 		}
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
+
+	/* Step 4: There is no step 4 */
+
+	/* Step 5: This means we are addressing an audiohook source which we have not encountered yet for the channel. Create a new inheritable
+	 * audiohook structure if we're allowing inheritance, or just return if not
+	 */
+
+	if (allow) {
+		return setup_inheritable_audiohook(inheritance_datastore, data);
 	} else {
-		AST_LIST_TRAVERSE(&inheritance_datastore->unallowed_list, inheritable_audiohook, list) {
-			if (!strcasecmp(inheritable_audiohook->source, data)) {
-				ast_debug(2, "Audiohook source %s is already prevented from being inherited by channel %s\n", data, chan->name);
-				return 0;
-			}
-		}
-	}
-
-	/* Step 4: There is no step 4 */
-
-	/* Step 5: This means we need to create a new inheritable_audiohook and add it to the correct list */
-
-	return setup_inheritable_audiohook(inheritance_datastore, allow, data);
+		ast_debug(1, "Audiohook %s is already set to not be inheritable on channel %s\n", data, chan->name);
+		return 0;
+	}
 }
 
 static struct ast_custom_function inheritance_function = {




More information about the asterisk-commits mailing list