Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Functions | Variables
bridge_roles.c File Reference

Channel Bridging Roles API. More...

#include "asterisk.h"
#include <signal.h>
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/datastore.h"
#include "asterisk/linkedlists.h"
#include "asterisk/bridge.h"
#include "asterisk/bridge_roles.h"
#include "asterisk/stringfields.h"
Include dependency graph for bridge_roles.c:

Go to the source code of this file.

Data Structures

struct  bridge_role
 
struct  bridge_role_option
 
struct  bridge_roles_datastore
 

Functions

void ast_bridge_channel_clear_roles (struct ast_bridge_channel *bridge_channel)
 Clear all roles from a bridge_channel's role list. More...
 
int ast_bridge_channel_establish_roles (struct ast_bridge_channel *bridge_channel)
 Clone the roles from a bridge_channel's attached ast_channel onto the bridge_channel's role list. More...
 
const char * ast_bridge_channel_get_role_option (struct ast_bridge_channel *bridge_channel, const char *role_name, const char *option)
 Retrieve the value of a requested role option from a bridge channel. More...
 
int ast_bridge_channel_has_role (struct ast_bridge_channel *bridge_channel, const char *role_name)
 Check to see if a bridge channel inherited a specific role from its channel. More...
 
int ast_channel_add_bridge_role (struct ast_channel *chan, const char *role_name)
 Adds a bridge role to a channel. More...
 
void ast_channel_clear_bridge_roles (struct ast_channel *chan)
 Removes all bridge roles currently on a channel. More...
 
const char * ast_channel_get_role_option (struct ast_channel *channel, const char *role_name, const char *option)
 Retrieve the value of a requested role option from a channel. More...
 
int ast_channel_has_role (struct ast_channel *channel, const char *role_name)
 Check if a role exists on a channel. More...
 
void ast_channel_remove_bridge_role (struct ast_channel *chan, const char *role_name)
 Removes a bridge role from a channel. More...
 
int ast_channel_set_bridge_role_option (struct ast_channel *channel, const char *role_name, const char *option, const char *value)
 Set a role option on a channel. More...
 
static void bridge_role_datastore_destroy (void *data)
 
static void bridge_role_destroy (struct bridge_role *role)
 
static struct bridge_roles_datastorefetch_bridge_roles_datastore (struct ast_channel *chan)
 
static struct bridge_roles_datastorefetch_or_create_bridge_roles_datastore (struct ast_channel *chan)
 
static struct bridge_roleget_role_from_channel (struct ast_channel *channel, const char *role_name)
 
static struct bridge_roleget_role_from_datastore (struct bridge_roles_datastore *roles_datastore, const char *role_name)
 
static struct bridge_role_optionget_role_option (struct bridge_role *role, const char *option)
 
static int setup_bridge_role (struct bridge_roles_datastore *roles_datastore, const char *role_name)
 
static int setup_bridge_role_option (struct bridge_role *role, const char *option, const char *value)
 
static struct bridge_roles_datastoresetup_bridge_roles_datastore (struct ast_channel *chan)
 

Variables

static const struct ast_datastore_info bridge_role_info
 

Detailed Description

Channel Bridging Roles API.

Author
Jonathan Rose jrose.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file bridge_roles.c.

Function Documentation

◆ ast_bridge_channel_clear_roles()

void ast_bridge_channel_clear_roles ( struct ast_bridge_channel bridge_channel)

Clear all roles from a bridge_channel's role list.

Parameters
bridge_channelthe bridge channel that we are scrubbing

If roles are already established on a bridge channel, ast_bridge_channel_establish_roles will fail unconditionally without changing any roles. In order to update a bridge channel's roles, they must first be cleared from the bridge channel using this function.

Note
ast_bridge_channel_clear_roles also serves as the destructor for the role list of a bridge channel.

Definition at line 495 of file bridge_roles.c.

References bridge_role_datastore_destroy(), ast_bridge_channel::bridge_roles, and NULL.

Referenced by agent_alert(), ast_bridge_channel_establish_roles(), and bridge_channel_internal_pull().

496 {
497  if (bridge_channel->bridge_roles) {
499  bridge_channel->bridge_roles = NULL;
500  }
501 }
#define NULL
Definition: resample.c:96
static void bridge_role_datastore_destroy(void *data)
Definition: bridge_roles.c:90
struct bridge_roles_datastore * bridge_roles

◆ ast_bridge_channel_establish_roles()

int ast_bridge_channel_establish_roles ( struct ast_bridge_channel bridge_channel)

Clone the roles from a bridge_channel's attached ast_channel onto the bridge_channel's role list.

Parameters
bridge_channelThe bridge channel that we are preparing
Return values
0on success
-1on failure

This function should always be called when the bridge_channel binds to an ast_channel at some point before the bridge_channel joins or is imparted onto a bridge. Failure to do so will result in an empty role list. While the list remains established, changes to roles on the ast_channel will not propogate to the bridge channel and roles can not be re-established on the bridge channel without first clearing the roles with ast_bridge_roles_bridge_channel_clear_roles.

Definition at line 447 of file bridge_roles.c.

References ast_bridge_channel_clear_roles(), ast_calloc, ast_debug, AST_LIST_LAST, AST_LIST_TRAVERSE, ast_bridge_channel::bridge_roles, ast_bridge_channel::chan, fetch_bridge_roles_datastore(), bridge_role_option::list, NULL, bridge_role_option::option, bridge_role::options, bridge_role::role, bridge_roles_datastore::role_list, setup_bridge_role(), setup_bridge_role_option(), and bridge_role_option::value.

Referenced by agent_alert(), and bridge_channel_internal_push_full().

448 {
449  struct bridge_roles_datastore *roles_datastore;
450  struct bridge_role *role = NULL;
451  struct bridge_role_option *role_option;
452 
453  if (!bridge_channel->chan) {
454  ast_debug(2, "Attempted to set roles on a bridge channel that has no associated channel. That's a bad idea.\n");
455  return -1;
456  }
457 
458  if (bridge_channel->bridge_roles) {
459  ast_debug(2, "Attempted to reset roles while roles were already established. Purge existing roles first.\n");
460  return -1;
461  }
462 
463  roles_datastore = fetch_bridge_roles_datastore(bridge_channel->chan);
464  if (!roles_datastore) {
465  /* No roles to establish. */
466  return 0;
467  }
468 
469  if (!(bridge_channel->bridge_roles = ast_calloc(1, sizeof(*bridge_channel->bridge_roles)))) {
470  return -1;
471  }
472 
473  AST_LIST_TRAVERSE(&roles_datastore->role_list, role, list) {
474  struct bridge_role *this_role_copy;
475 
476  if (setup_bridge_role(bridge_channel->bridge_roles, role->role)) {
477  /* We need to abandon the copy because we couldn't setup a role */
478  ast_bridge_channel_clear_roles(bridge_channel);
479  return -1;
480  }
481  this_role_copy = AST_LIST_LAST(&bridge_channel->bridge_roles->role_list);
482 
483  AST_LIST_TRAVERSE(&role->options, role_option, list) {
484  if (setup_bridge_role_option(this_role_copy, role_option->option, role_option->value)) {
485  /* We need to abandon the copy because we couldn't setup a role option */
486  ast_bridge_channel_clear_roles(bridge_channel);
487  return -1;
488  }
489  }
490  }
491 
492  return 0;
493 }
void ast_bridge_channel_clear_roles(struct ast_bridge_channel *bridge_channel)
Clear all roles from a bridge_channel&#39;s role list.
Definition: bridge_roles.c:495
char role[AST_ROLE_LEN]
Definition: bridge_roles.c:55
struct bridge_roles_datastore::@358 role_list
#define NULL
Definition: resample.c:96
static struct bridge_roles_datastore * fetch_bridge_roles_datastore(struct ast_channel *chan)
Definition: bridge_roles.c:148
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
const ast_string_field value
Definition: bridge_roles.c:49
struct bridge_roles_datastore * bridge_roles
static int setup_bridge_role(struct bridge_roles_datastore *roles_datastore, const char *role_name)
Definition: bridge_roles.c:260
#define AST_LIST_LAST(head)
Returns the last entry contained in a list.
Definition: linkedlists.h:428
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
struct bridge_role::@357 options
struct bridge_role::@356 list
struct ast_channel * chan
const ast_string_field option
Definition: bridge_roles.c:49
static int setup_bridge_role_option(struct bridge_role *role, const char *option, const char *value)
Definition: bridge_roles.c:291
struct bridge_role_option::@355 list

◆ ast_bridge_channel_get_role_option()

const char* ast_bridge_channel_get_role_option ( struct ast_bridge_channel bridge_channel,
const char *  role_name,
const char *  option 
)

Retrieve the value of a requested role option from a bridge channel.

Parameters
bridge_channelThe bridge channel we are retrieving the option from
role_nameName of the role the option will be retrieved from
optionName of the option we are retrieving the value of
Return values
NULLIf either the role does not exist on the bridge_channel or the role does exist but the option has not been set
Thevalue of the option
Note
See ast_channel_set_role_option note about the need to call ast_bridge_channel_establish_roles.
The returned character pointer is only valid as long as the bridge_channel is guaranteed to be alive and hasn't had ast_bridge_channel_clear_roles called against it (as this will free all roles and role options in the bridge channel). If you need this value after one of these destruction events occurs, you must make a local copy while it is still valid.

Definition at line 427 of file bridge_roles.c.

References ast_bridge_channel::bridge_roles, get_role_from_datastore(), get_role_option(), NULL, bridge_role::role, and bridge_role_option::value.

Referenced by bridge_parking_push(), participant_entertainment_start(), and participant_idle_mode_setup().

428 {
429  struct bridge_role *role;
430  struct bridge_role_option *role_option = NULL;
431 
432  if (!bridge_channel->bridge_roles) {
433  return NULL;
434  }
435 
436  role = get_role_from_datastore(bridge_channel->bridge_roles, role_name);
437 
438  if (!role) {
439  return NULL;
440  }
441 
442  role_option = get_role_option(role, option);
443 
444  return role_option ? role_option->value : NULL;
445 }
char role[AST_ROLE_LEN]
Definition: bridge_roles.c:55
static struct bridge_role * get_role_from_datastore(struct bridge_roles_datastore *roles_datastore, const char *role_name)
Definition: bridge_roles.c:197
#define NULL
Definition: resample.c:96
const ast_string_field value
Definition: bridge_roles.c:49
struct bridge_roles_datastore * bridge_roles
static struct bridge_role_option * get_role_option(struct bridge_role *role, const char *option)
Definition: bridge_roles.c:238
const ast_string_field option
Definition: bridge_roles.c:49

◆ ast_bridge_channel_has_role()

int ast_bridge_channel_has_role ( struct ast_bridge_channel bridge_channel,
const char *  role_name 
)

Check to see if a bridge channel inherited a specific role from its channel.

Parameters
bridge_channelThe bridge channel being checked
role_nameName of the role being checked
Return values
0The bridge channel does not have the requested role
1The bridge channel does have the requested role
Note
Before a bridge_channel can effectively check roles against a bridge, ast_bridge_channel_establish_roles should be called on the bridge_channel so that roles and their respective role options can be copied from the channel datastore into the bridge_channel roles list. Otherwise this function will just return 0 because the list will be NULL.

Definition at line 418 of file bridge_roles.c.

References ast_bridge_channel::bridge_roles, and get_role_from_datastore().

Referenced by bridge_parking_push(), and holding_bridge_join().

419 {
420  if (!bridge_channel->bridge_roles) {
421  return 0;
422  }
423 
424  return get_role_from_datastore(bridge_channel->bridge_roles, role_name) ? 1 : 0;
425 }
static struct bridge_role * get_role_from_datastore(struct bridge_roles_datastore *roles_datastore, const char *role_name)
Definition: bridge_roles.c:197
struct bridge_roles_datastore * bridge_roles

◆ ast_channel_add_bridge_role()

int ast_channel_add_bridge_role ( struct ast_channel chan,
const char *  role_name 
)

Adds a bridge role to a channel.

Parameters
chanAcquirer of the requested role
role_nameName of the role being attached
Return values
0on success
-1on failure

Definition at line 317 of file bridge_roles.c.

References ast_channel_name(), ast_debug, ast_log, fetch_or_create_bridge_roles_datastore(), get_role_from_datastore(), LOG_WARNING, and setup_bridge_role().

Referenced by add_transferer_role(), announce_request(), app_control_add_role(), bridge_agent_hold_push(), bridge_stasis_push(), media_request_helper(), parking_channel_set_roles(), process_options(), and rec_request().

318 {
319  struct bridge_roles_datastore *roles_datastore = fetch_or_create_bridge_roles_datastore(chan);
320 
321  if (!roles_datastore) {
322  ast_log(LOG_WARNING, "Unable to set up bridge role datastore on channel %s\n", ast_channel_name(chan));
323  return -1;
324  }
325 
326  /* Check to make sure we aren't adding a redundant role */
327  if (get_role_from_datastore(roles_datastore, role_name)) {
328  ast_debug(2, "Bridge role %s is already applied to the channel %s\n", role_name, ast_channel_name(chan));
329  return 0;
330  }
331 
332  /* It wasn't already there, so we can just finish setting it up now. */
333  return setup_bridge_role(roles_datastore, role_name);
334 }
static struct bridge_role * get_role_from_datastore(struct bridge_roles_datastore *roles_datastore, const char *role_name)
Definition: bridge_roles.c:197
static struct bridge_roles_datastore * fetch_or_create_bridge_roles_datastore(struct ast_channel *chan)
Definition: bridge_roles.c:172
#define LOG_WARNING
Definition: logger.h:274
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
static int setup_bridge_role(struct bridge_roles_datastore *roles_datastore, const char *role_name)
Definition: bridge_roles.c:260
const char * ast_channel_name(const struct ast_channel *chan)

◆ ast_channel_clear_bridge_roles()

void ast_channel_clear_bridge_roles ( struct ast_channel chan)

Removes all bridge roles currently on a channel.

Parameters
chanChannel the roles are being removed from

Definition at line 360 of file bridge_roles.c.

References ast_channel_name(), ast_debug, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, bridge_role_destroy(), fetch_bridge_roles_datastore(), bridge_role_option::list, bridge_role::role, and bridge_roles_datastore::role_list.

Referenced by app_control_clear_roles(), and bridge_stasis_pull().

361 {
362  struct bridge_roles_datastore *roles_datastore = fetch_bridge_roles_datastore(chan);
363  struct bridge_role *role;
364 
365  if (!roles_datastore) {
366  /* The roles datastore didn't already exist, so there is no need to remove any roles */
367  ast_debug(2, "Roles did not exist on channel %s\n", ast_channel_name(chan));
368  return;
369  }
370 
371  AST_LIST_TRAVERSE_SAFE_BEGIN(&roles_datastore->role_list, role, list) {
372  ast_debug(2, "Removing bridge role %s from channel %s\n", role->role, ast_channel_name(chan));
374  bridge_role_destroy(role);
375  }
377 }
char role[AST_ROLE_LEN]
Definition: bridge_roles.c:55
struct bridge_roles_datastore::@358 role_list
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
static struct bridge_roles_datastore * fetch_bridge_roles_datastore(struct ast_channel *chan)
Definition: bridge_roles.c:148
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
static void bridge_role_destroy(struct bridge_role *role)
Definition: bridge_roles.c:71
struct bridge_role::@356 list
const char * ast_channel_name(const struct ast_channel *chan)
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528

◆ ast_channel_get_role_option()

const char* ast_channel_get_role_option ( struct ast_channel channel,
const char *  role_name,
const char *  option 
)

Retrieve the value of a requested role option from a channel.

Parameters
channelThe channel to retrieve the requested option from
role_nameThe role to which the option belongs
optionThe name of the option to retrieve
Return values
NULLThe option does not exist
non-NULLThe value of the option

This is an alternative to ast_bridge_channel_get_role_option that is useful if bridge roles have not yet been esstablished on a channel's bridge_channel. A possible example of when this could be used is in a bridge v_table's push() callback.

Definition at line 403 of file bridge_roles.c.

References get_role_from_channel(), get_role_option(), NULL, bridge_role::role, and bridge_role_option::value.

Referenced by bridge_personality_atxfer_push().

404 {
405  struct bridge_role *role;
406  struct bridge_role_option *role_option;
407 
408  role = get_role_from_channel(channel, role_name);
409  if (!role) {
410  return NULL;
411  }
412 
413  role_option = get_role_option(role, option);
414 
415  return role_option ? role_option->value : NULL;
416 }
char role[AST_ROLE_LEN]
Definition: bridge_roles.c:55
static struct bridge_role * get_role_from_channel(struct ast_channel *channel, const char *role_name)
Definition: bridge_roles.c:221
#define NULL
Definition: resample.c:96
const ast_string_field value
Definition: bridge_roles.c:49
static struct bridge_role_option * get_role_option(struct bridge_role *role, const char *option)
Definition: bridge_roles.c:238
const ast_string_field option
Definition: bridge_roles.c:49

◆ ast_channel_has_role()

int ast_channel_has_role ( struct ast_channel channel,
const char *  role_name 
)

Check if a role exists on a channel.

Parameters
channelThe channel to check
role_nameThe name of the role to search for
Return values
0The requested role does not exist on the channel
1The requested role exists on the channel

This is an alternative to ast_bridge_channel_has_role that is useful if bridge roles have not yet been established on a channel's bridge_channel. A possible example of when this could be used is in a bridge v_table's push() callback.

Definition at line 398 of file bridge_roles.c.

References get_role_from_channel().

Referenced by bridge_personality_atxfer_push(), bridge_stasis_push(), and handle_hangup().

399 {
400  return get_role_from_channel(channel, role_name) ? 1 : 0;
401 }
static struct bridge_role * get_role_from_channel(struct ast_channel *channel, const char *role_name)
Definition: bridge_roles.c:221

◆ ast_channel_remove_bridge_role()

void ast_channel_remove_bridge_role ( struct ast_channel chan,
const char *  role_name 
)

Removes a bridge role from a channel.

Parameters
chanChannel the role is being removed from
role_nameName of the role being removed

Definition at line 336 of file bridge_roles.c.

References ast_channel_name(), ast_debug, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, bridge_role_destroy(), fetch_bridge_roles_datastore(), bridge_role_option::list, bridge_role::role, and bridge_roles_datastore::role_list.

Referenced by attended_transfer_properties_shutdown(), bridge_agent_hold_pull(), and bridge_agent_hold_push().

337 {
338  struct bridge_roles_datastore *roles_datastore = fetch_bridge_roles_datastore(chan);
339  struct bridge_role *role;
340 
341  if (!roles_datastore) {
342  /* The roles datastore didn't already exist, so there is no need to remove a role */
343  ast_debug(2, "Role %s did not exist on channel %s\n", role_name, ast_channel_name(chan));
344  return;
345  }
346 
347  AST_LIST_TRAVERSE_SAFE_BEGIN(&roles_datastore->role_list, role, list) {
348  if (!strcmp(role->role, role_name)) {
349  ast_debug(2, "Removing bridge role %s from channel %s\n", role_name, ast_channel_name(chan));
351  bridge_role_destroy(role);
352  return;
353  }
354  }
356 
357  ast_debug(2, "Role %s did not exist on channel %s\n", role_name, ast_channel_name(chan));
358 }
char role[AST_ROLE_LEN]
Definition: bridge_roles.c:55
struct bridge_roles_datastore::@358 role_list
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
static struct bridge_roles_datastore * fetch_bridge_roles_datastore(struct ast_channel *chan)
Definition: bridge_roles.c:148
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
static void bridge_role_destroy(struct bridge_role *role)
Definition: bridge_roles.c:71
struct bridge_role::@356 list
const char * ast_channel_name(const struct ast_channel *chan)
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528

◆ ast_channel_set_bridge_role_option()

int ast_channel_set_bridge_role_option ( struct ast_channel channel,
const char *  role_name,
const char *  option,
const char *  value 
)

Set a role option on a channel.

Parameters
channelChannel receiving the role option
role_nameRole the role option is applied to
optionName of the option
valueValue of the option
0on success
Return values
-1on failure

Definition at line 379 of file bridge_roles.c.

References ast_string_field_set, get_role_from_channel(), get_role_option(), bridge_role::role, and setup_bridge_role_option().

Referenced by add_transferer_role(), agent_alert(), apply_option_entertainment(), apply_option_moh(), bridge_agent_hold_push(), bridge_stasis_push(), and parking_channel_set_roles().

380 {
381  struct bridge_role *role = get_role_from_channel(channel, role_name);
382  struct bridge_role_option *role_option;
383 
384  if (!role) {
385  return -1;
386  }
387 
388  role_option = get_role_option(role, option);
389 
390  if (role_option) {
391  ast_string_field_set(role_option, value, value);
392  return 0;
393  }
394 
395  return setup_bridge_role_option(role, option, value);
396 }
char role[AST_ROLE_LEN]
Definition: bridge_roles.c:55
static struct bridge_role * get_role_from_channel(struct ast_channel *channel, const char *role_name)
Definition: bridge_roles.c:221
int value
Definition: syslog.c:37
static struct bridge_role_option * get_role_option(struct bridge_role *role, const char *option)
Definition: bridge_roles.c:238
const ast_string_field option
Definition: bridge_roles.c:49
static int setup_bridge_role_option(struct bridge_role *role, const char *option, const char *value)
Definition: bridge_roles.c:291
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ bridge_role_datastore_destroy()

static void bridge_role_datastore_destroy ( void *  data)
static

Definition at line 90 of file bridge_roles.c.

References ast_free, AST_LIST_REMOVE_HEAD, bridge_role_destroy(), bridge_role_option::list, bridge_role::role, and bridge_roles_datastore::role_list.

Referenced by ast_bridge_channel_clear_roles().

91 {
92  struct bridge_roles_datastore *roles_datastore = data;
93  struct bridge_role *role;
94 
95  while ((role = AST_LIST_REMOVE_HEAD(&roles_datastore->role_list, list))) {
96  bridge_role_destroy(role);
97  }
98 
99  ast_free(roles_datastore);
100 }
char role[AST_ROLE_LEN]
Definition: bridge_roles.c:55
struct bridge_roles_datastore::@358 role_list
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
static void bridge_role_destroy(struct bridge_role *role)
Definition: bridge_roles.c:71
#define ast_free(a)
Definition: astmm.h:182
struct bridge_role::@356 list

◆ bridge_role_destroy()

static void bridge_role_destroy ( struct bridge_role role)
static

Definition at line 71 of file bridge_roles.c.

References ast_free, AST_LIST_REMOVE_HEAD, ast_string_field_free_memory, bridge_role_option::list, and bridge_role::options.

Referenced by ast_channel_clear_bridge_roles(), ast_channel_remove_bridge_role(), and bridge_role_datastore_destroy().

72 {
73  struct bridge_role_option *role_option;
74  while ((role_option = AST_LIST_REMOVE_HEAD(&role->options, list))) {
75  ast_string_field_free_memory(role_option);
76  ast_free(role_option);
77  }
78  ast_free(role);
79 }
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
#define ast_free(a)
Definition: astmm.h:182
struct bridge_role::@357 options
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368
struct bridge_role_option::@355 list

◆ fetch_bridge_roles_datastore()

static struct bridge_roles_datastore* fetch_bridge_roles_datastore ( struct ast_channel chan)
static

Definition at line 148 of file bridge_roles.c.

References ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_datastore::data, and NULL.

Referenced by ast_bridge_channel_establish_roles(), ast_channel_clear_bridge_roles(), ast_channel_remove_bridge_role(), fetch_or_create_bridge_roles_datastore(), and get_role_from_channel().

149 {
150  struct ast_datastore *datastore = NULL;
151 
152  ast_channel_lock(chan);
153  if (!(datastore = ast_channel_datastore_find(chan, &bridge_role_info, NULL))) {
154  ast_channel_unlock(chan);
155  return NULL;
156  }
157  ast_channel_unlock(chan);
158 
159  return datastore->data;
160 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
static const struct ast_datastore_info bridge_role_info
Definition: bridge_roles.c:102
Structure for a data store object.
Definition: datastore.h:68
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:2404
#define NULL
Definition: resample.c:96
#define ast_channel_unlock(chan)
Definition: channel.h:2946
void * data
Definition: datastore.h:70

◆ fetch_or_create_bridge_roles_datastore()

static struct bridge_roles_datastore* fetch_or_create_bridge_roles_datastore ( struct ast_channel chan)
static

Definition at line 172 of file bridge_roles.c.

References ast_channel_lock, ast_channel_unlock, fetch_bridge_roles_datastore(), and setup_bridge_roles_datastore().

Referenced by ast_channel_add_bridge_role().

173 {
174  struct bridge_roles_datastore *roles_datastore;
175 
176  ast_channel_lock(chan);
177  roles_datastore = fetch_bridge_roles_datastore(chan);
178  if (!roles_datastore) {
179  roles_datastore = setup_bridge_roles_datastore(chan);
180  }
181  ast_channel_unlock(chan);
182 
183  return roles_datastore;
184 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
static struct bridge_roles_datastore * fetch_bridge_roles_datastore(struct ast_channel *chan)
Definition: bridge_roles.c:148
static struct bridge_roles_datastore * setup_bridge_roles_datastore(struct ast_channel *chan)
Definition: bridge_roles.c:117
#define ast_channel_unlock(chan)
Definition: channel.h:2946

◆ get_role_from_channel()

static struct bridge_role* get_role_from_channel ( struct ast_channel channel,
const char *  role_name 
)
static

Definition at line 221 of file bridge_roles.c.

References fetch_bridge_roles_datastore(), get_role_from_datastore(), and NULL.

Referenced by ast_channel_get_role_option(), ast_channel_has_role(), and ast_channel_set_bridge_role_option().

222 {
223  struct bridge_roles_datastore *roles_datastore = fetch_bridge_roles_datastore(channel);
224  return roles_datastore ? get_role_from_datastore(roles_datastore, role_name) : NULL;
225 }
static struct bridge_role * get_role_from_datastore(struct bridge_roles_datastore *roles_datastore, const char *role_name)
Definition: bridge_roles.c:197
#define NULL
Definition: resample.c:96
static struct bridge_roles_datastore * fetch_bridge_roles_datastore(struct ast_channel *chan)
Definition: bridge_roles.c:148

◆ get_role_from_datastore()

static struct bridge_role* get_role_from_datastore ( struct bridge_roles_datastore roles_datastore,
const char *  role_name 
)
static

Definition at line 197 of file bridge_roles.c.

References AST_LIST_TRAVERSE, bridge_role_option::list, NULL, bridge_role::role, and bridge_roles_datastore::role_list.

Referenced by ast_bridge_channel_get_role_option(), ast_bridge_channel_has_role(), ast_channel_add_bridge_role(), and get_role_from_channel().

198 {
199  struct bridge_role *role;
200 
201  AST_LIST_TRAVERSE(&roles_datastore->role_list, role, list) {
202  if (!strcmp(role->role, role_name)) {
203  return role;
204  }
205  }
206 
207  return NULL;
208 }
char role[AST_ROLE_LEN]
Definition: bridge_roles.c:55
struct bridge_roles_datastore::@358 role_list
#define NULL
Definition: resample.c:96
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct bridge_role::@356 list

◆ get_role_option()

static struct bridge_role_option* get_role_option ( struct bridge_role role,
const char *  option 
)
static

Definition at line 238 of file bridge_roles.c.

References AST_LIST_TRAVERSE, bridge_role_option::list, NULL, bridge_role_option::option, and bridge_role::options.

Referenced by ast_bridge_channel_get_role_option(), ast_channel_get_role_option(), and ast_channel_set_bridge_role_option().

239 {
240  struct bridge_role_option *role_option = NULL;
241  AST_LIST_TRAVERSE(&role->options, role_option, list) {
242  if (!strcmp(role_option->option, option)) {
243  return role_option;
244  }
245  }
246  return NULL;
247 }
#define NULL
Definition: resample.c:96
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct bridge_role::@357 options
const ast_string_field option
Definition: bridge_roles.c:49
struct bridge_role_option::@355 list

◆ setup_bridge_role()

static int setup_bridge_role ( struct bridge_roles_datastore roles_datastore,
const char *  role_name 
)
static

Definition at line 260 of file bridge_roles.c.

References ast_calloc, ast_copy_string(), ast_debug, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_TAIL, bridge_role_option::list, bridge_role::options, bridge_role::role, and bridge_roles_datastore::role_list.

Referenced by ast_bridge_channel_establish_roles(), and ast_channel_add_bridge_role().

261 {
262  struct bridge_role *role;
263  role = ast_calloc(1, sizeof(*role));
264 
265  if (!role) {
266  return -1;
267  }
268 
270 
271  ast_copy_string(role->role, role_name, sizeof(role->role));
272 
273  AST_LIST_INSERT_TAIL(&roles_datastore->role_list, role, list);
274  ast_debug(3, "Set role '%s'\n", role_name);
275 
276  return 0;
277 }
char role[AST_ROLE_LEN]
Definition: bridge_roles.c:55
struct bridge_roles_datastore::@358 role_list
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
struct bridge_role::@357 options
struct bridge_role::@356 list
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:680
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ setup_bridge_role_option()

static int setup_bridge_role_option ( struct bridge_role role,
const char *  option,
const char *  value 
)
static

Definition at line 291 of file bridge_roles.c.

References ast_calloc, ast_free, AST_LIST_INSERT_TAIL, ast_string_field_init, ast_string_field_set, bridge_role_option::list, and bridge_role::options.

Referenced by ast_bridge_channel_establish_roles(), and ast_channel_set_bridge_role_option().

292 {
293  struct bridge_role_option *role_option;
294 
295  if (!value) {
296  value = "";
297  }
298 
299  role_option = ast_calloc(1, sizeof(*role_option));
300  if (!role_option) {
301  return -1;
302  }
303 
304  if (ast_string_field_init(role_option, 32)) {
305  ast_free(role_option);
306  return -1;
307  }
308 
309  ast_string_field_set(role_option, option, option);
310  ast_string_field_set(role_option, value, value);
311 
312  AST_LIST_INSERT_TAIL(&role->options, role_option, list);
313 
314  return 0;
315 }
int value
Definition: syslog.c:37
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
struct bridge_role::@357 options
const ast_string_field option
Definition: bridge_roles.c:49
struct bridge_role_option::@355 list
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ setup_bridge_roles_datastore()

static struct bridge_roles_datastore* setup_bridge_roles_datastore ( struct ast_channel chan)
static

Definition at line 117 of file bridge_roles.c.

References ast_calloc, ast_channel_datastore_add(), ast_datastore_alloc, ast_datastore_free(), AST_LIST_HEAD_INIT_NOLOCK, ast_datastore::data, NULL, and bridge_roles_datastore::role_list.

Referenced by fetch_or_create_bridge_roles_datastore().

118 {
119  struct ast_datastore *datastore = NULL;
120  struct bridge_roles_datastore *roles_datastore = NULL;
121 
122  if (!(datastore = ast_datastore_alloc(&bridge_role_info, NULL))) {
123  return NULL;
124  }
125 
126  if (!(roles_datastore = ast_calloc(1, sizeof(*roles_datastore)))) {
127  ast_datastore_free(datastore);
128  return NULL;
129  }
130 
131  AST_LIST_HEAD_INIT_NOLOCK(&roles_datastore->role_list);
132 
133  datastore->data = roles_datastore;
134  ast_channel_datastore_add(chan, datastore);
135  return roles_datastore;
136 }
static const struct ast_datastore_info bridge_role_info
Definition: bridge_roles.c:102
struct bridge_roles_datastore::@358 role_list
Structure for a data store object.
Definition: datastore.h:68
#define NULL
Definition: resample.c:96
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
void * data
Definition: datastore.h:70
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:680
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:89
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2390

Variable Documentation

◆ bridge_role_info

const struct ast_datastore_info bridge_role_info
static
Initial value:
= {
.type = "bridge roles",
}
static void bridge_role_datastore_destroy(void *data)
Definition: bridge_roles.c:90

Definition at line 102 of file bridge_roles.c.