Mon Mar 12 2012 21:39:48

Asterisk developer's documentation


func_audiohookinherit.c File Reference

Audiohook inheritance function. More...

#include "asterisk.h"
#include "asterisk/datastore.h"
#include "asterisk/channel.h"
#include "asterisk/logger.h"
#include "asterisk/audiohook.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
Include dependency graph for func_audiohookinherit.c:

Go to the source code of this file.

Data Structures

struct  audiohook_inheritance_datastore
struct  inheritable_audiohook

Functions

static void __reg_module (void)
static void __unreg_module (void)
static void audiohook_inheritance_destroy (void *data)
 Destroy dynamically allocated data on an audiohook_inheritance_datastore.
static void audiohook_inheritance_fixup (void *data, struct ast_channel *old_chan, struct ast_channel *new_chan)
 Move audiohooks as defined by previous calls to the AUDIOHOOK_INHERIT function.
static int func_inheritance_write (struct ast_channel *chan, const char *function, char *data, const char *value)
 Set the permissibility of inheritance for a particular audiohook source on a channel.
static int load_module (void)
static int setup_inheritable_audiohook (struct audiohook_inheritance_datastore *audiohook_inheritance_datastore, const char *source)
 Create a new inheritable_audiohook structure and add it to an audiohook_inheritance_datastore.
static struct
audiohook_inheritance_datastore
setup_inheritance_datastore (struct ast_channel *chan)
 create an audiohook_inheritance_datastore and attach it to a channel
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Audiohook inheritance function" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_datastore_info audiohook_inheritance_info
static struct ast_custom_function inheritance_function

Detailed Description

Audiohook inheritance function.

Author:
Mark Michelson <mmichelson@digium.com>

Definition in file func_audiohookinherit.c.


Function Documentation

static void __reg_module ( void  ) [static]

Definition at line 299 of file func_audiohookinherit.c.

static void __unreg_module ( void  ) [static]

Definition at line 299 of file func_audiohookinherit.c.

static void audiohook_inheritance_destroy ( void *  data) [static]

Destroy dynamically allocated data on an audiohook_inheritance_datastore.

Parameters:
dataPointer to the audiohook_inheritance_datastore in question.
Returns:
Void

Definition at line 141 of file func_audiohookinherit.c.

References audiohook_inheritance_datastore::allowed_list, ast_free, and AST_LIST_REMOVE_HEAD.

{
   struct audiohook_inheritance_datastore *audiohook_inheritance_datastore = data;
   struct inheritable_audiohook *inheritable_audiohook = NULL;

   while ((inheritable_audiohook = AST_LIST_REMOVE_HEAD(&audiohook_inheritance_datastore->allowed_list, list))) {
      ast_free(inheritable_audiohook);
   }

   ast_free(audiohook_inheritance_datastore);
}
static void audiohook_inheritance_fixup ( void *  data,
struct ast_channel old_chan,
struct ast_channel new_chan 
) [static]

Move audiohooks as defined by previous calls to the AUDIOHOOK_INHERIT function.

Move allowed audiohooks from the old channel to the new channel.

Parameters:
dataThe ast_datastore containing audiohook inheritance information that will be moved
old_chanThe "clone" channel from a masquerade. We are moving the audiohook in question off of this channel
new_chanThe "original" channel from a masquerade. We are moving the audiohook in question to this channel
Returns:
Void

Definition at line 121 of file func_audiohookinherit.c.

References audiohook_inheritance_datastore::allowed_list, ast_audiohook_move_by_source(), ast_debug, AST_LIST_TRAVERSE, ast_channel::name, and inheritable_audiohook::source.

{
   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);

   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;
}
static int func_inheritance_write ( struct ast_channel chan,
const char *  function,
char *  data,
const char *  value 
) [static]

Set the permissibility of inheritance for a particular audiohook source on a channel.

For details regarding what happens in the function, see the inline comments

Parameters:
chanThe channel we are operating on
functionThe name of the dialplan function (AUDIOHOOK_INHERIT)
dataThe audiohook source for which we are setting inheritance permissions
valueThe value indicating the permission for audiohook inheritance

Definition at line 211 of file func_audiohookinherit.c.

References audiohook_inheritance_datastore::allowed_list, ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_debug, ast_free, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), ast_strlen_zero(), ast_true(), audiohook_inheritance_info, ast_datastore::data, LOG_WARNING, ast_channel::name, setup_inheritable_audiohook(), setup_inheritance_datastore(), and inheritable_audiohook::source.

{
   int allow;
   struct ast_datastore *datastore = NULL;
   struct audiohook_inheritance_datastore *inheritance_datastore = NULL;
   struct inheritable_audiohook *inheritable_audiohook;

   /* Step 1: Get data from function call */
   if (ast_strlen_zero(data)) {
      ast_log(LOG_WARNING, "No argument provided to INHERITANCE function.\n");
      return -1;
   }

   if (ast_strlen_zero(value)) {
      ast_log(LOG_WARNING, "No value provided to INHERITANCE function.\n");
      return -1;
   }

   allow = ast_true(value);

   /* Step 2: retrieve or set up datastore */
   ast_channel_lock(chan);
   if (!(datastore = ast_channel_datastore_find(chan, &audiohook_inheritance_info, NULL))) {
      ast_channel_unlock(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_WARNING, "Unable to set up audiohook inheritance datastore on channel %s\n", chan->name);
         return -1;
      } else {
         return setup_inheritable_audiohook(inheritance_datastore, data);
      }
   } else {
      inheritance_datastore = datastore->data;
   }
   ast_channel_unlock(chan);

   /* 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_debug(1, "Audiohook %s is already set to not be inheritable on channel %s\n", data, chan->name);
      return 0;
   }
}
static int load_module ( void  ) [static]
static int setup_inheritable_audiohook ( struct audiohook_inheritance_datastore audiohook_inheritance_datastore,
const char *  source 
) [static]

Create a new inheritable_audiohook structure and add it to an audiohook_inheritance_datastore.

Parameters:
audiohook_inheritance_datastoreThe audiohook_inheritance_datastore we want to add the new inheritable_audiohook to
sourceThe audiohook source for the newly created inheritable_audiohook
Return values:
0Success
non-zeroFailure

Definition at line 186 of file func_audiohookinherit.c.

References audiohook_inheritance_datastore::allowed_list, ast_calloc, ast_debug, AST_LIST_INSERT_TAIL, and inheritable_audiohook::source.

Referenced by func_inheritance_write().

{
   struct inheritable_audiohook *inheritable_audiohook = NULL;

   inheritable_audiohook = ast_calloc(1, sizeof(*inheritable_audiohook) + strlen(source));

   if (!inheritable_audiohook) {
      return -1;
   }

   strcpy(inheritable_audiohook->source, source);
   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;
}
static struct audiohook_inheritance_datastore* setup_inheritance_datastore ( struct ast_channel chan) [static, read]

create an audiohook_inheritance_datastore and attach it to a channel

Parameters:
chanThe channel to which we wish to attach the new datastore
Returns:
Returns the newly created audiohook_inheritance_datastore or NULL on error

Definition at line 158 of file func_audiohookinherit.c.

References ast_calloc, ast_channel_datastore_add(), ast_channel_lock, ast_channel_unlock, ast_datastore_alloc(), ast_datastore_free(), audiohook_inheritance_info, and ast_datastore::data.

Referenced by func_inheritance_write().

{
   struct ast_datastore *datastore = NULL;
   struct audiohook_inheritance_datastore *audiohook_inheritance_datastore = NULL;

   if (!(datastore = ast_datastore_alloc(&audiohook_inheritance_info, NULL))) {
      return NULL;
   }

   if (!(audiohook_inheritance_datastore = ast_calloc(1, sizeof(*audiohook_inheritance_datastore)))) {
      ast_datastore_free(datastore);
      return NULL;
   }

   datastore->data = audiohook_inheritance_datastore;
   ast_channel_lock(chan);
   ast_channel_datastore_add(chan, datastore);
   ast_channel_unlock(chan);
   return audiohook_inheritance_datastore;
}
static int unload_module ( void  ) [static]

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Audiohook inheritance function" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 299 of file func_audiohookinherit.c.

Definition at line 299 of file func_audiohookinherit.c.

Initial value:
 {
   .type = "audiohook inheritance",
   .destroy = audiohook_inheritance_destroy,
   .chan_fixup = audiohook_inheritance_fixup,
}

Definition at line 106 of file func_audiohookinherit.c.

Referenced by func_inheritance_write(), and setup_inheritance_datastore().

Initial value:
 {
   .name = "AUDIOHOOK_INHERIT",
   .write = func_inheritance_write,
}

Definition at line 281 of file func_audiohookinherit.c.