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"
Go to the source code of this file.
Data Structures | |
struct | audiohook_inheritance_datastore |
struct | inheritable_audiohook |
Functions | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Audiohook inheritance function") | |
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_datastore_info | audiohook_inheritance_info |
static struct ast_custom_function | inheritance_function |
Audiohook inheritance function.
Definition in file func_audiohookinherit.c.
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Audiohook inheritance function" | ||||
) |
static void audiohook_inheritance_destroy | ( | void * | data | ) | [static] |
Destroy dynamically allocated data on an audiohook_inheritance_datastore.
data | Pointer to the audiohook_inheritance_datastore in question. |
Definition at line 143 of file func_audiohookinherit.c.
References ast_free, and AST_LIST_REMOVE_HEAD.
00144 { 00145 struct audiohook_inheritance_datastore *audiohook_inheritance_datastore = data; 00146 struct inheritable_audiohook *inheritable_audiohook = NULL; 00147 00148 while ((inheritable_audiohook = AST_LIST_REMOVE_HEAD(&audiohook_inheritance_datastore->allowed_list, list))) { 00149 ast_free(inheritable_audiohook); 00150 } 00151 00152 ast_free(audiohook_inheritance_datastore); 00153 }
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.
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 |
Definition at line 123 of file func_audiohookinherit.c.
References ast_audiohook_move_by_source(), ast_debug, and AST_LIST_TRAVERSE.
00124 { 00125 struct inheritable_audiohook *audiohook = NULL; 00126 struct audiohook_inheritance_datastore *datastore = data; 00127 00128 ast_debug(2, "inheritance fixup occurring for channels %s(%p) and %s(%p)", old_chan->name, old_chan, new_chan->name, new_chan); 00129 00130 AST_LIST_TRAVERSE(&datastore->allowed_list, audiohook, list) { 00131 ast_audiohook_move_by_source(old_chan, new_chan, audiohook->source); 00132 ast_debug(3, "Moved audiohook %s from %s(%p) to %s(%p)\n", 00133 audiohook->source, old_chan->name, old_chan, new_chan->name, new_chan); 00134 } 00135 return; 00136 }
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
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 213 of file func_audiohookinherit.c.
References 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(), ast_datastore::data, LOG_WARNING, setup_inheritable_audiohook(), and setup_inheritance_datastore().
00214 { 00215 int allow; 00216 struct ast_datastore *datastore = NULL; 00217 struct audiohook_inheritance_datastore *inheritance_datastore = NULL; 00218 struct inheritable_audiohook *inheritable_audiohook; 00219 00220 /* Step 1: Get data from function call */ 00221 if (ast_strlen_zero(data)) { 00222 ast_log(LOG_WARNING, "No argument provided to INHERITANCE function.\n"); 00223 return -1; 00224 } 00225 00226 if (ast_strlen_zero(value)) { 00227 ast_log(LOG_WARNING, "No value provided to INHERITANCE function.\n"); 00228 return -1; 00229 } 00230 00231 allow = ast_true(value); 00232 00233 /* Step 2: retrieve or set up datastore */ 00234 ast_channel_lock(chan); 00235 if (!(datastore = ast_channel_datastore_find(chan, &audiohook_inheritance_info, NULL))) { 00236 ast_channel_unlock(chan); 00237 /* In the case where we cannot find the datastore, we can take a few shortcuts */ 00238 if (!allow) { 00239 ast_debug(1, "Audiohook %s is already set to not be inheritable on channel %s\n", data, chan->name); 00240 return 0; 00241 } else if (!(inheritance_datastore = setup_inheritance_datastore(chan))) { 00242 ast_log(LOG_WARNING, "Unable to set up audiohook inheritance datastore on channel %s\n", chan->name); 00243 return -1; 00244 } else { 00245 return setup_inheritable_audiohook(inheritance_datastore, data); 00246 } 00247 } else { 00248 inheritance_datastore = datastore->data; 00249 } 00250 ast_channel_unlock(chan); 00251 00252 /* Step 3: Traverse the list to see if we're trying something redundant */ 00253 00254 AST_LIST_TRAVERSE_SAFE_BEGIN(&inheritance_datastore->allowed_list, inheritable_audiohook, list) { 00255 if (!strcasecmp(inheritable_audiohook->source, data)) { 00256 if (allow) { 00257 ast_debug(2, "Audiohook source %s is already set up to be inherited from channel %s\n", data, chan->name); 00258 return 0; 00259 } else { 00260 ast_debug(2, "Removing inheritability of audiohook %s from channel %s\n", data, chan->name); 00261 AST_LIST_REMOVE_CURRENT(list); 00262 ast_free(inheritable_audiohook); 00263 return 0; 00264 } 00265 } 00266 } 00267 AST_LIST_TRAVERSE_SAFE_END; 00268 00269 /* Step 4: There is no step 4 */ 00270 00271 /* Step 5: This means we are addressing an audiohook source which we have not encountered yet for the channel. Create a new inheritable 00272 * audiohook structure if we're allowing inheritance, or just return if not 00273 */ 00274 00275 if (allow) { 00276 return setup_inheritable_audiohook(inheritance_datastore, data); 00277 } else { 00278 ast_debug(1, "Audiohook %s is already set to not be inheritable on channel %s\n", data, chan->name); 00279 return 0; 00280 } 00281 }
static int load_module | ( | void | ) | [static] |
Definition at line 293 of file func_audiohookinherit.c.
References ast_custom_function_register, AST_MODULE_LOAD_DECLINE, and AST_MODULE_LOAD_SUCCESS.
00294 { 00295 if (ast_custom_function_register(&inheritance_function)) { 00296 return AST_MODULE_LOAD_DECLINE; 00297 } else { 00298 return AST_MODULE_LOAD_SUCCESS; 00299 } 00300 }
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.
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 |
0 | Success | |
non-zero | Failure |
Definition at line 188 of file func_audiohookinherit.c.
References ast_calloc, ast_debug, and AST_LIST_INSERT_TAIL.
Referenced by func_inheritance_write().
00189 { 00190 struct inheritable_audiohook *inheritable_audiohook = NULL; 00191 00192 inheritable_audiohook = ast_calloc(1, sizeof(*inheritable_audiohook) + strlen(source)); 00193 00194 if (!inheritable_audiohook) { 00195 return -1; 00196 } 00197 00198 strcpy(inheritable_audiohook->source, source); 00199 AST_LIST_INSERT_TAIL(&audiohook_inheritance_datastore->allowed_list, inheritable_audiohook, list); 00200 ast_debug(3, "Set audiohook %s to be inheritable\n", source); 00201 return 0; 00202 }
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
chan | The channel to which we wish to attach the new datastore |
Definition at line 160 of file func_audiohookinherit.c.
References ast_calloc, ast_channel_datastore_add(), ast_channel_lock, ast_channel_unlock, ast_datastore_alloc, ast_datastore_free(), and ast_datastore::data.
Referenced by func_inheritance_write().
00161 { 00162 struct ast_datastore *datastore = NULL; 00163 struct audiohook_inheritance_datastore *audiohook_inheritance_datastore = NULL; 00164 00165 if (!(datastore = ast_datastore_alloc(&audiohook_inheritance_info, NULL))) { 00166 return NULL; 00167 } 00168 00169 if (!(audiohook_inheritance_datastore = ast_calloc(1, sizeof(*audiohook_inheritance_datastore)))) { 00170 ast_datastore_free(datastore); 00171 return NULL; 00172 } 00173 00174 datastore->data = audiohook_inheritance_datastore; 00175 ast_channel_lock(chan); 00176 ast_channel_datastore_add(chan, datastore); 00177 ast_channel_unlock(chan); 00178 return audiohook_inheritance_datastore; 00179 }
static int unload_module | ( | void | ) | [static] |
Definition at line 288 of file func_audiohookinherit.c.
References ast_custom_function_unregister().
00289 { 00290 return ast_custom_function_unregister(&inheritance_function); 00291 }
struct ast_datastore_info audiohook_inheritance_info [static] |
{ .type = "audiohook inheritance", .destroy = audiohook_inheritance_destroy, .chan_fixup = audiohook_inheritance_fixup, }
Definition at line 108 of file func_audiohookinherit.c.
struct ast_custom_function inheritance_function [static] |
{ .name = "AUDIOHOOK_INHERIT", .write = func_inheritance_write, }
Definition at line 283 of file func_audiohookinherit.c.