Fri Apr 24 16:26:31 2009

Asterisk developer's documentation


func_audiohookinherit.c File Reference

Audiohook inheritance function. More...

#include "asterisk.h"
#include "asterisk/channel.h"
#include "asterisk/audiohook.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/options.h"

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, 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_datastoresetup_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_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "f450f61f60e761b3aa089ebed76ca8a5" , .load = load_module, .unload = unload_module, }
static const 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 282 of file func_audiohookinherit.c.

static void __unreg_module ( void   )  [static]

Definition at line 282 of file func_audiohookinherit.c.

static void audiohook_inheritance_destroy ( void *  data  )  [static]

Destroy dynamically allocated data on an audiohook_inheritance_datastore.

Parameters:
data Pointer to the audiohook_inheritance_datastore in question.
Returns:
Void

Definition at line 88 of file func_audiohookinherit.c.

References audiohook_inheritance_datastore::allowed_list, ast_free, AST_LIST_REMOVE_HEAD, and inheritable_audiohook::list.

00089 {
00090    struct audiohook_inheritance_datastore *audiohook_inheritance_datastore = data;
00091    struct inheritable_audiohook *inheritable_audiohook = NULL;
00092 
00093    while ((inheritable_audiohook = AST_LIST_REMOVE_HEAD(&audiohook_inheritance_datastore->allowed_list, list))) {
00094       ast_free(inheritable_audiohook);
00095    }
00096 }

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:
data The ast_datastore containing audiohook inheritance information that will be moved
old_chan The "clone" channel from a masquerade. We are moving the audiohook in question off of this channel
new_chan The "original" channel from a masquerade. We are moving the audiohook in question to this channel
Returns:
Void

Definition at line 64 of file func_audiohookinherit.c.

References audiohook_inheritance_datastore::allowed_list, ast_audiohook_move_by_source(), AST_LIST_TRAVERSE, ast_log(), inheritable_audiohook::list, LOG_DEBUG, ast_channel::name, option_debug, and inheritable_audiohook::source.

00065 {
00066    struct inheritable_audiohook *audiohook = NULL;
00067    struct audiohook_inheritance_datastore *datastore = data;
00068 
00069    if (option_debug > 1) {
00070       ast_log(LOG_DEBUG, "inheritance fixup occurring for channels %s(%p) and %s(%p)", old_chan->name, old_chan, new_chan->name, new_chan);
00071    }
00072 
00073    AST_LIST_TRAVERSE(&datastore->allowed_list, audiohook, list) {
00074       ast_audiohook_move_by_source(old_chan, new_chan, audiohook->source);
00075       if (option_debug > 2) {
00076          ast_log(LOG_DEBUG, "Moved audiohook %s from %s(%p) to %s(%p)\n",
00077             audiohook->source, old_chan->name, old_chan, new_chan->name, new_chan);
00078       }
00079    }
00080    return;
00081 }

static int func_inheritance_write ( struct ast_channel chan,
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:
chan The channel we are operating on
function The name of the dialplan function (AUDIOHOOK_INHERIT)
data The audiohook source for which we are setting inheritance permissions
value The value indicating the permission for audiohook inheritance

Definition at line 158 of file func_audiohookinherit.c.

References audiohook_inheritance_datastore::allowed_list, ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, 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, inheritable_audiohook::list, LOG_DEBUG, LOG_WARNING, ast_channel::name, option_debug, setup_inheritable_audiohook(), setup_inheritance_datastore(), and inheritable_audiohook::source.

00159 {
00160    int allow;
00161    struct ast_datastore *datastore = NULL;
00162    struct audiohook_inheritance_datastore *inheritance_datastore = NULL;
00163    struct inheritable_audiohook *inheritable_audiohook;
00164 
00165    /* Step 1: Get data from function call */
00166    if (ast_strlen_zero(data)) {
00167       ast_log(LOG_WARNING, "No argument provided to INHERITANCE function.\n");
00168       return -1;
00169    }
00170 
00171    if (ast_strlen_zero(value)) {
00172       ast_log(LOG_WARNING, "No value provided to INHERITANCE function.\n");
00173       return -1;
00174    }
00175 
00176    allow = ast_true(value);
00177 
00178    /* Step 2: retrieve or set up datastore */
00179    ast_channel_lock(chan);
00180    if (!(datastore = ast_channel_datastore_find(chan, &audiohook_inheritance_info, NULL))) {
00181       ast_channel_unlock(chan);
00182       /* In the case where we cannot find the datastore, we can take a few shortcuts */
00183       if (!allow) {
00184          if (option_debug) {
00185             ast_log(LOG_DEBUG, "Audiohook %s is already set to not be inheritable on channel %s\n", data, chan->name);
00186          }
00187          return 0;
00188       } else if (!(inheritance_datastore = setup_inheritance_datastore(chan))) {
00189          ast_log(LOG_WARNING, "Unable to set up audiohook inheritance datastore on channel %s\n", chan->name);
00190          return -1;
00191       } else {
00192          return setup_inheritable_audiohook(inheritance_datastore, data);
00193       }
00194    } else {
00195       inheritance_datastore = datastore->data;
00196    }
00197    ast_channel_unlock(chan);
00198 
00199    /* Step 3: Traverse the list to see if we're trying something redundant */
00200 
00201    AST_LIST_TRAVERSE_SAFE_BEGIN(&inheritance_datastore->allowed_list, inheritable_audiohook, list) {
00202       if (!strcasecmp(inheritable_audiohook->source, data)) {
00203          if (allow) {
00204             if (option_debug > 1) {
00205                ast_log(LOG_DEBUG, "Audiohook source %s is already set up to be inherited from channel %s\n", data, chan->name);
00206             }
00207             return 0;
00208          } else {
00209             if (option_debug > 1) {
00210                ast_log(LOG_DEBUG, "Removing inheritability of audiohook %s from channel %s\n", data, chan->name);
00211             }
00212             AST_LIST_REMOVE_CURRENT(&inheritance_datastore->allowed_list, list);
00213             ast_free(inheritable_audiohook);
00214             return 0;
00215          }
00216       }
00217    }
00218    AST_LIST_TRAVERSE_SAFE_END;
00219 
00220    /* Step 4: There is no step 4 */
00221 
00222    /* Step 5: This means we are addressing an audiohook source which we have not encountered yet for the channel. Create a new inheritable
00223     * audiohook structure if we're allowing inheritance, or just return if not
00224     */
00225 
00226    if (allow) {
00227       return setup_inheritable_audiohook(inheritance_datastore, data);
00228    } else {
00229       if (option_debug) {
00230          ast_log(LOG_DEBUG, "Audiohook %s is already set to not be inheritable on channel %s\n", data, chan->name);
00231       }
00232       return 0;
00233    }
00234 }

static int load_module ( void   )  [static]

Definition at line 274 of file func_audiohookinherit.c.

References ast_custom_function_register(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and inheritance_function.

00275 {
00276    if (ast_custom_function_register(&inheritance_function)) {
00277       return AST_MODULE_LOAD_DECLINE;
00278    } else {
00279       return AST_MODULE_LOAD_SUCCESS;
00280    }
00281 }

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_datastore The audiohook_inheritance_datastore we want to add the new inheritable_audiohook to
source The audiohook source for the newly created inheritable_audiohook
Return values:
0 Success
non-zero Failure

Definition at line 131 of file func_audiohookinherit.c.

References audiohook_inheritance_datastore::allowed_list, ast_calloc, AST_LIST_INSERT_TAIL, ast_log(), inheritable_audiohook::list, LOG_DEBUG, and option_debug.

Referenced by func_inheritance_write().

00132 {
00133    struct inheritable_audiohook *inheritable_audiohook = NULL;
00134 
00135    inheritable_audiohook = ast_calloc(1, sizeof(*inheritable_audiohook) + strlen(source));
00136 
00137    if (!inheritable_audiohook) {
00138       return -1;
00139    }
00140 
00141    strcpy(inheritable_audiohook->source, source);
00142    AST_LIST_INSERT_TAIL(&audiohook_inheritance_datastore->allowed_list, inheritable_audiohook, list);
00143    if (option_debug > 2) {
00144       ast_log(LOG_DEBUG, "Set audiohook %s to be inheritable\n", source);
00145    }
00146    return 0;
00147 }

static struct audiohook_inheritance_datastore* setup_inheritance_datastore ( struct ast_channel chan  )  [static]

create an audiohook_inheritance_datastore and attach it to a channel

Parameters:
chan The 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 103 of file func_audiohookinherit.c.

References ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_alloc(), ast_channel_datastore_free(), ast_channel_lock, ast_channel_unlock, audiohook_inheritance_info, and ast_datastore::data.

Referenced by func_inheritance_write().

00104 {
00105    struct ast_datastore *datastore = NULL;
00106    struct audiohook_inheritance_datastore *audiohook_inheritance_datastore = NULL;
00107 
00108    if (!(datastore = ast_channel_datastore_alloc(&audiohook_inheritance_info, NULL))) {
00109       return NULL;
00110    }
00111 
00112    if (!(audiohook_inheritance_datastore = ast_calloc(1, sizeof(*audiohook_inheritance_datastore)))) {
00113       ast_channel_datastore_free(datastore);
00114       return NULL;
00115    }
00116 
00117    datastore->data = audiohook_inheritance_datastore;
00118    ast_channel_lock(chan);
00119    ast_channel_datastore_add(chan, datastore);
00120    ast_channel_unlock(chan);
00121    return audiohook_inheritance_datastore;
00122 }

static int unload_module ( void   )  [static]

Definition at line 269 of file func_audiohookinherit.c.

References ast_custom_function_unregister(), and inheritance_function.

00270 {
00271    return ast_custom_function_unregister(&inheritance_function);
00272 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "f450f61f60e761b3aa089ebed76ca8a5" , .load = load_module, .unload = unload_module, } [static]

Definition at line 282 of file func_audiohookinherit.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 282 of file func_audiohookinherit.c.

struct ast_datastore_info audiohook_inheritance_info [static]

Initial value:

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

Definition at line 49 of file func_audiohookinherit.c.

Referenced by func_inheritance_write(), and setup_inheritance_datastore().

struct ast_custom_function inheritance_function [static]

Definition at line 236 of file func_audiohookinherit.c.

Referenced by load_module(), and unload_module().


Generated on Fri Apr 24 16:26:32 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7