Wed Jan 8 2020 09:50:12

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"

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. More...
 
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. More...
 
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. More...
 
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. More...
 
static struct
audiohook_inheritance_datastore
setup_inheritance_datastore (struct ast_channel *chan)
 create an audiohook_inheritance_datastore and attach it to a channel More...
 
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 = "ac1f6a56484a8820659555499174e588" , .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 mmich.nosp@m.elso.nosp@m.n@dig.nosp@m.ium..nosp@m.com

Definition in file func_audiohookinherit.c.

Function Documentation

static void __reg_module ( void  )
static

Definition at line 306 of file func_audiohookinherit.c.

static void __unreg_module ( void  )
static

Definition at line 306 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 143 of file func_audiohookinherit.c.

References audiohook_inheritance_datastore::allowed_list, ast_free, and AST_LIST_REMOVE_HEAD.

144 {
147 
148  while ((inheritable_audiohook = AST_LIST_REMOVE_HEAD(&audiohook_inheritance_datastore->allowed_list, list))) {
149  ast_free(inheritable_audiohook);
150  }
151 
152  ast_free(audiohook_inheritance_datastore);
153 }
struct audiohook_inheritance_datastore::@130 allowed_list
struct inheritable_audiohook::@129 list
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:818
#define ast_free(a)
Definition: astmm.h:97
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 123 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.

124 {
125  struct inheritable_audiohook *audiohook = NULL;
126  struct audiohook_inheritance_datastore *datastore = data;
127 
128  ast_debug(2, "inheritance fixup occurring for channels %s(%p) and %s(%p)", old_chan->name, old_chan, new_chan->name, new_chan);
129 
130  AST_LIST_TRAVERSE(&datastore->allowed_list, audiohook, list) {
131  ast_audiohook_move_by_source(old_chan, new_chan, audiohook->source);
132  ast_debug(3, "Moved audiohook %s from %s(%p) to %s(%p)\n",
133  audiohook->source, old_chan->name, old_chan, new_chan->name, new_chan);
134  }
135  return;
136 }
void ast_audiohook_move_by_source(struct ast_channel *old_chan, struct ast_channel *new_chan, const char *source)
Move an audiohook from one channel to a new one.
Definition: audiohook.c:480
struct audiohook_inheritance_datastore::@130 allowed_list
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
const ast_string_field name
Definition: channel.h:787
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
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 213 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.

214 {
215  int allow;
216  struct ast_datastore *datastore = NULL;
217  struct audiohook_inheritance_datastore *inheritance_datastore = NULL;
219 
220  /* Step 1: Get data from function call */
221  if (ast_strlen_zero(data)) {
222  ast_log(LOG_WARNING, "No argument provided to INHERITANCE function.\n");
223  return -1;
224  }
225 
226  if (ast_strlen_zero(value)) {
227  ast_log(LOG_WARNING, "No value provided to INHERITANCE function.\n");
228  return -1;
229  }
230 
231  if (!chan) {
232  ast_log(LOG_WARNING, "No channel was provided to INHERITANCE function.\n");
233  return -1;
234  }
235 
236  allow = ast_true(value);
237 
238  /* Step 2: retrieve or set up datastore */
239  ast_channel_lock(chan);
240  if (!(datastore = ast_channel_datastore_find(chan, &audiohook_inheritance_info, NULL))) {
241  ast_channel_unlock(chan);
242  /* In the case where we cannot find the datastore, we can take a few shortcuts */
243  if (!allow) {
244  ast_debug(1, "Audiohook %s is already set to not be inheritable on channel %s\n", data, chan->name);
245  return 0;
246  } else if (!(inheritance_datastore = setup_inheritance_datastore(chan))) {
247  ast_log(LOG_WARNING, "Unable to set up audiohook inheritance datastore on channel %s\n", chan->name);
248  return -1;
249  } else {
250  return setup_inheritable_audiohook(inheritance_datastore, data);
251  }
252  } else {
253  inheritance_datastore = datastore->data;
254  }
255  ast_channel_unlock(chan);
256 
257  /* Step 3: Traverse the list to see if we're trying something redundant */
258 
259  AST_LIST_TRAVERSE_SAFE_BEGIN(&inheritance_datastore->allowed_list, inheritable_audiohook, list) {
260  if (!strcasecmp(inheritable_audiohook->source, data)) {
261  if (allow) {
262  ast_debug(2, "Audiohook source %s is already set up to be inherited from channel %s\n", data, chan->name);
263  return 0;
264  } else {
265  ast_debug(2, "Removing inheritability of audiohook %s from channel %s\n", data, chan->name);
267  ast_free(inheritable_audiohook);
268  return 0;
269  }
270  }
271  }
273 
274  /* Step 4: There is no step 4 */
275 
276  /* Step 5: This means we are addressing an audiohook source which we have not encountered yet for the channel. Create a new inheritable
277  * audiohook structure if we're allowing inheritance, or just return if not
278  */
279 
280  if (allow) {
281  return setup_inheritable_audiohook(inheritance_datastore, data);
282  } else {
283  ast_debug(1, "Audiohook %s is already set to not be inheritable on channel %s\n", data, chan->name);
284  return 0;
285  }
286 }
static struct ast_datastore_info audiohook_inheritance_info
#define ast_channel_lock(chan)
Definition: channel.h:2466
struct audiohook_inheritance_datastore::@130 allowed_list
struct inheritable_audiohook::@129 list
#define LOG_WARNING
Definition: logger.h:144
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.
Structure for a data store object.
Definition: datastore.h:54
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2604
int value
Definition: syslog.c:39
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:600
static struct audiohook_inheritance_datastore * setup_inheritance_datastore(struct ast_channel *chan)
create an audiohook_inheritance_datastore and attach it to a channel
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:554
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: utils.c:1533
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
#define ast_free(a)
Definition: astmm.h:97
void * data
Definition: datastore.h:56
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
static int load_module ( void  )
static

Definition at line 298 of file func_audiohookinherit.c.

References ast_custom_function_register, AST_MODULE_LOAD_DECLINE, and AST_MODULE_LOAD_SUCCESS.

299 {
302  } else {
304  }
305 }
static struct ast_custom_function inheritance_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
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 188 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().

189 {
191 
192  inheritable_audiohook = ast_calloc(1, sizeof(*inheritable_audiohook) + strlen(source));
193 
194  if (!inheritable_audiohook) {
195  return -1;
196  }
197 
198  strcpy(inheritable_audiohook->source, source);
199  AST_LIST_INSERT_TAIL(&audiohook_inheritance_datastore->allowed_list, inheritable_audiohook, list);
200  ast_debug(3, "Set audiohook %s to be inheritable\n", source);
201  return 0;
202 }
struct audiohook_inheritance_datastore::@130 allowed_list
struct inheritable_audiohook::@129 list
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:716
#define ast_calloc(a, b)
Definition: astmm.h:82
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
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 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(), audiohook_inheritance_info, and ast_datastore::data.

Referenced by func_inheritance_write().

161 {
162  struct ast_datastore *datastore = NULL;
164 
165  if (!(datastore = ast_datastore_alloc(&audiohook_inheritance_info, NULL))) {
166  return NULL;
167  }
168 
169  if (!(audiohook_inheritance_datastore = ast_calloc(1, sizeof(*audiohook_inheritance_datastore)))) {
170  ast_datastore_free(datastore);
171  return NULL;
172  }
173 
174  datastore->data = audiohook_inheritance_datastore;
175  ast_channel_lock(chan);
176  ast_channel_datastore_add(chan, datastore);
177  ast_channel_unlock(chan);
178  return audiohook_inheritance_datastore;
179 }
static struct ast_datastore_info audiohook_inheritance_info
#define ast_channel_lock(chan)
Definition: channel.h:2466
Structure for a data store object.
Definition: datastore.h:54
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:65
struct ast_datastore * ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
Definition: datastore.c:98
#define ast_channel_unlock(chan)
Definition: channel.h:2467
void * data
Definition: datastore.h:56
#define ast_calloc(a, b)
Definition: astmm.h:82
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2590
static int unload_module ( void  )
static

Definition at line 293 of file func_audiohookinherit.c.

References ast_custom_function_unregister().

294 {
296 }
static struct ast_custom_function inheritance_function
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814

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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 306 of file func_audiohookinherit.c.

Definition at line 306 of file func_audiohookinherit.c.

struct ast_datastore_info audiohook_inheritance_info
static
Initial value:
= {
.type = "audiohook inheritance",
}
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.

Definition at line 108 of file func_audiohookinherit.c.

Referenced by func_inheritance_write(), and setup_inheritance_datastore().

struct ast_custom_function inheritance_function
static
Initial value:
= {
.name = "AUDIOHOOK_INHERIT",
}
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.

Definition at line 288 of file func_audiohookinherit.c.