Asterisk - The Open Source Telephony Project  GIT-master-9ed6387
Data Structures | Macros | Enumerations | Functions | Variables
app_bridgewait.c File Reference

Application to place the channel into a holding Bridge. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/features.h"
#include "asterisk/say.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/bridge.h"
#include "asterisk/musiconhold.h"
#include "asterisk/astobj2.h"
#include "asterisk/causes.h"

Go to the source code of this file.

Data Structures

struct  wait_bridge_wrapper
 

Macros

#define APP_NAME   "BridgeWait"
 
#define DEFAULT_BRIDGE_NAME   "default"
 

Enumerations

enum  bridgewait_args { OPT_ARG_ENTERTAINMENT, OPT_ARG_MOHCLASS, OPT_ARG_TIMEOUT, OPT_ARG_ARRAY_SIZE }
 
enum  bridgewait_flags { MUXFLAG_MOHCLASS = (1 << 0), MUXFLAG_ENTERTAINMENT = (1 << 1), MUXFLAG_TIMEOUT = (1 << 2) }
 
enum  wait_bridge_roles { ROLE_PARTICIPANT = 0, ROLE_ANNOUNCER, ROLE_INVALID }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int apply_option_entertainment (struct ast_channel *chan, const char *entertainment_arg)
 
static int apply_option_moh (struct ast_channel *chan, const char *class_arg)
 
static int apply_option_timeout (struct ast_bridge_features *features, char *duration_arg)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int bridgewait_exec (struct ast_channel *chan, const char *data)
 
static int bridgewait_timeout_callback (struct ast_bridge_channel *bridge_channel, void *hook_pvt)
 
static struct wait_bridge_wrapperget_wait_bridge_wrapper (const char *bridge_name)
 
static int load_module (void)
 
static int process_options (struct ast_channel *chan, struct ast_flags *flags, char **opts, struct ast_bridge_features *features, enum wait_bridge_roles role)
 
static int unload_module (void)
 
static enum wait_bridge_roles validate_role (const char *role)
 
static int wait_bridge_hash_fn (const void *obj, const int flags)
 
static int wait_bridge_sort_fn (const void *obj_left, const void *obj_right, const int flags)
 
static struct wait_bridge_wrapperwait_bridge_wrapper_alloc (const char *bridge_name, struct ast_bridge *bridge)
 
static void wait_bridge_wrapper_destructor (void *obj)
 
static struct wait_bridge_wrapperwait_bridge_wrapper_find_by_name (const char *bridge_name)
 
static void wait_wrapper_removal (struct wait_bridge_wrapper *wrapper)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Place the channel into a holding bridge application" , .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, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static const struct ast_app_option bridgewait_opts [128] = { [ 'e' ] = { .flag = MUXFLAG_ENTERTAINMENT , .arg_index = OPT_ARG_ENTERTAINMENT + 1 }, [ 'm' ] = { .flag = MUXFLAG_MOHCLASS , .arg_index = OPT_ARG_MOHCLASS + 1 }, [ 'S' ] = { .flag = MUXFLAG_TIMEOUT , .arg_index = OPT_ARG_TIMEOUT + 1 }, }
 
static struct ao2_containerwait_bridge_wrappers
 

Detailed Description

Application to place the channel into a holding Bridge.

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

Definition in file app_bridgewait.c.

Macro Definition Documentation

◆ APP_NAME

#define APP_NAME   "BridgeWait"

Definition at line 116 of file app_bridgewait.c.

Referenced by get_wait_bridge_wrapper(), load_module(), and unload_module().

◆ DEFAULT_BRIDGE_NAME

#define DEFAULT_BRIDGE_NAME   "default"

Definition at line 117 of file app_bridgewait.c.

Referenced by bridgewait_exec().

Enumeration Type Documentation

◆ bridgewait_args

Enumerator
OPT_ARG_ENTERTAINMENT 
OPT_ARG_MOHCLASS 
OPT_ARG_TIMEOUT 
OPT_ARG_ARRAY_SIZE 

Definition at line 191 of file app_bridgewait.c.

◆ bridgewait_flags

Enumerator
MUXFLAG_MOHCLASS 
MUXFLAG_ENTERTAINMENT 
MUXFLAG_TIMEOUT 

Definition at line 185 of file app_bridgewait.c.

185  {
186  MUXFLAG_MOHCLASS = (1 << 0),
187  MUXFLAG_ENTERTAINMENT = (1 << 1),
188  MUXFLAG_TIMEOUT = (1 << 2),
189 };

◆ wait_bridge_roles

Enumerator
ROLE_PARTICIPANT 
ROLE_ANNOUNCER 
ROLE_INVALID 

Definition at line 262 of file app_bridgewait.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 512 of file app_bridgewait.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 512 of file app_bridgewait.c.

◆ apply_option_entertainment()

static int apply_option_entertainment ( struct ast_channel chan,
const char *  entertainment_arg 
)
static

Definition at line 241 of file app_bridgewait.c.

References ast_channel_set_bridge_role_option(), ast_log, and LOG_ERROR.

Referenced by process_options().

242 {
243  char entertainment = entertainment_arg[0];
244 
245  switch (entertainment) {
246  case 'm':
247  return ast_channel_set_bridge_role_option(chan, "holding_participant", "idle_mode", "musiconhold");
248  case 'r':
249  return ast_channel_set_bridge_role_option(chan, "holding_participant", "idle_mode", "ringing");
250  case 's':
251  return ast_channel_set_bridge_role_option(chan, "holding_participant", "idle_mode", "silence");
252  case 'h':
253  return ast_channel_set_bridge_role_option(chan, "holding_participant", "idle_mode", "hold");
254  case 'n':
255  return ast_channel_set_bridge_role_option(chan, "holding_participant", "idle_mode", "none");
256  default:
257  ast_log(LOG_ERROR, "Invalid argument for BridgeWait entertainment '%s'\n", entertainment_arg);
258  return -1;
259  }
260 }
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.
Definition: bridge_roles.c:379
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285

◆ apply_option_moh()

static int apply_option_moh ( struct ast_channel chan,
const char *  class_arg 
)
static

Definition at line 236 of file app_bridgewait.c.

References ast_channel_set_bridge_role_option().

Referenced by process_options().

237 {
238  return ast_channel_set_bridge_role_option(chan, "holding_participant", "moh_class", class_arg);
239 }
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.
Definition: bridge_roles.c:379

◆ apply_option_timeout()

static int apply_option_timeout ( struct ast_bridge_features features,
char *  duration_arg 
)
static

Definition at line 212 of file app_bridgewait.c.

References AST_BRIDGE_HOOK_REMOVE_ON_PULL, ast_bridge_interval_hook(), ast_log, ast_strlen_zero, bridgewait_timeout_callback(), LOG_ERROR, and NULL.

Referenced by process_options().

213 {
214  unsigned int duration;
215 
216  if (ast_strlen_zero(duration_arg)) {
217  ast_log(LOG_ERROR, "Timeout option 'S': No value provided.\n");
218  return -1;
219  }
220  if (sscanf(duration_arg, "%u", &duration) != 1 || duration == 0) {
221  ast_log(LOG_ERROR, "Timeout option 'S': Invalid value provided '%s'.\n",
222  duration_arg);
223  return -1;
224  }
225 
226  duration *= 1000;
227  if (ast_bridge_interval_hook(features, 0, duration, bridgewait_timeout_callback,
229  ast_log(LOG_ERROR, "Timeout option 'S': Could not create timer.\n");
230  return -1;
231  }
232 
233  return 0;
234 }
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
int ast_bridge_interval_hook(struct ast_bridge_features *features, enum ast_bridge_hook_timer_option flags, unsigned int interval, ast_bridge_hook_callback callback, void *hook_pvt, ast_bridge_hook_pvt_destructor destructor, enum ast_bridge_hook_remove_flags remove_flags)
Attach an interval hook to a bridge features structure.
Definition: bridge.c:3373
static int bridgewait_timeout_callback(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
#define LOG_ERROR
Definition: logger.h:285
#define ast_strlen_zero(a)
Definition: muted.c:73

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 512 of file app_bridgewait.c.

◆ bridgewait_exec()

static int bridgewait_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 416 of file app_bridgewait.c.

References args, ast_answer(), AST_APP_ARG, ast_app_parse_options(), ast_bridge_features_cleanup(), ast_bridge_features_init(), ast_bridge_join(), ast_channel_name(), ast_check_hangup_locked(), AST_DECLARE_APP_ARGS, ast_log, AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_strdupa, ast_strlen_zero, ast_verb, wait_bridge_wrapper::bridge, bridgewait_opts, DEFAULT_BRIDGE_NAME, get_wait_bridge_wrapper(), LOG_ERROR, LOG_WARNING, wait_bridge_wrapper::name, NULL, OPT_ARG_ARRAY_SIZE, options, parse(), process_options(), ROLE_INVALID, ROLE_PARTICIPANT, ast_bridge::uniqueid, validate_role(), and wait_wrapper_removal().

Referenced by load_module().

417 {
418  char *bridge_name = DEFAULT_BRIDGE_NAME;
419  struct ast_bridge_features chan_features;
420  struct ast_flags flags = { 0 };
421  char *parse;
423  char *opts[OPT_ARG_ARRAY_SIZE] = { NULL, };
424  struct wait_bridge_wrapper *bridge_wrapper;
425  int res;
426 
428  AST_APP_ARG(name);
429  AST_APP_ARG(role);
431  AST_APP_ARG(other); /* Any remaining unused arguments */
432  );
433 
434  parse = ast_strdupa(data);
435  AST_STANDARD_APP_ARGS(args, parse);
436 
437  if (!ast_strlen_zero(args.name)) {
438  bridge_name = args.name;
439  }
440 
441  if (!ast_strlen_zero(args.role)) {
442  role = validate_role(args.role);
443  if (role == ROLE_INVALID) {
444  ast_log(LOG_ERROR, "Requested waiting bridge role '%s' is invalid.\n", args.role);
445  return -1;
446  }
447  }
448 
449  if (ast_bridge_features_init(&chan_features)) {
450  ast_bridge_features_cleanup(&chan_features);
451  ast_log(LOG_ERROR, "'%s' failed to enter the waiting bridge - could not set up channel features\n",
452  ast_channel_name(chan));
453  return -1;
454  }
455 
456  if (args.options) {
457  ast_app_parse_options(bridgewait_opts, &flags, opts, args.options);
458  }
459 
460  /* Answer the channel if needed */
461  if (ast_channel_state(chan) != AST_STATE_UP) {
462  ast_answer(chan);
463  }
464 
465  if (process_options(chan, &flags, opts, &chan_features, role)) {
466  ast_bridge_features_cleanup(&chan_features);
467  return -1;
468  }
469 
470  bridge_wrapper = get_wait_bridge_wrapper(bridge_name);
471  if (!bridge_wrapper) {
472  ast_log(LOG_WARNING, "Failed to find or create waiting bridge '%s' for '%s'.\n", bridge_name, ast_channel_name(chan));
473  ast_bridge_features_cleanup(&chan_features);
474  return -1;
475  }
476 
477  ast_verb(3, "%s is entering waiting bridge %s:%s\n", ast_channel_name(chan), bridge_name, bridge_wrapper->bridge->uniqueid);
478  res = ast_bridge_join(bridge_wrapper->bridge, chan, NULL, &chan_features, NULL, 0);
479  wait_wrapper_removal(bridge_wrapper);
480  ast_bridge_features_cleanup(&chan_features);
481 
482  if (res) {
483  /* For the lifetime of the bridge wrapper the bridge itself will be valid, if an error occurs it is because
484  * of extreme situations.
485  */
486  ast_log(LOG_WARNING, "Failed to join waiting bridge '%s' for '%s'.\n", bridge_name, ast_channel_name(chan));
487  }
488 
489  return (res || ast_check_hangup_locked(chan)) ? -1 : 0;
490 }
void ast_bridge_features_cleanup(struct ast_bridge_features *features)
Clean up the contents of a bridge features structure.
Definition: bridge.c:3711
const ast_string_field uniqueid
Definition: bridge.h:405
Structure that contains features information.
static const struct ast_app_option bridgewait_opts[128]
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
int ast_check_hangup_locked(struct ast_channel *chan)
Definition: channel.c:455
#define LOG_WARNING
Definition: logger.h:274
int ast_bridge_features_init(struct ast_bridge_features *features)
Initialize bridge features structure.
Definition: bridge.c:3678
unsigned int flags
Definition: utils.h:200
ast_channel_state
ast_channel states
Definition: channelstate.h:35
wait_bridge_roles
const char * args
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:455
static struct wait_bridge_wrapper * get_wait_bridge_wrapper(const char *bridge_name)
#define ast_log
Definition: astobj2.c:42
static void wait_wrapper_removal(struct wait_bridge_wrapper *wrapper)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: main/app.c:2829
#define LOG_ERROR
Definition: logger.h:285
#define DEFAULT_BRIDGE_NAME
struct ast_bridge * bridge
static enum wait_bridge_roles validate_role(const char *role)
#define ast_strlen_zero(a)
Definition: muted.c:73
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
static const char name[]
Definition: cdr_mysql.c:74
Structure used to handle boolean flags.
Definition: utils.h:199
int ast_bridge_join(struct ast_bridge *bridge, struct ast_channel *chan, struct ast_channel *swap, struct ast_bridge_features *features, struct ast_bridge_tech_optimizations *tech_args, enum ast_bridge_join_flags flags)
Join a channel to a bridge (blocking)
Definition: bridge.c:1667
static int process_options(struct ast_channel *chan, struct ast_flags *flags, char **opts, struct ast_bridge_features *features, enum wait_bridge_roles role)
const char * ast_channel_name(const struct ast_channel *chan)
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2780
static struct test_options options
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ bridgewait_timeout_callback()

static int bridgewait_timeout_callback ( struct ast_bridge_channel bridge_channel,
void *  hook_pvt 
)
static

Definition at line 204 of file app_bridgewait.c.

References ast_bridge_channel_leave_bridge(), AST_CAUSE_NORMAL_CLEARING, ast_channel_name(), ast_verb, BRIDGE_CHANNEL_STATE_END, and ast_bridge_channel::chan.

Referenced by apply_option_timeout().

205 {
206  ast_verb(3, "Channel %s timed out.\n", ast_channel_name(bridge_channel->chan));
209  return -1;
210 }
#define ast_verb(level,...)
Definition: logger.h:455
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:105
void ast_bridge_channel_leave_bridge(struct ast_bridge_channel *bridge_channel, enum bridge_channel_state new_state, int cause)
Set bridge channel state to leave bridge (if not leaving already).
struct ast_channel * chan
const char * ast_channel_name(const struct ast_channel *chan)

◆ get_wait_bridge_wrapper()

static struct wait_bridge_wrapper* get_wait_bridge_wrapper ( const char *  bridge_name)
static

Definition at line 341 of file app_bridgewait.c.

References APP_NAME, ast_bridge_base_new(), AST_BRIDGE_CAPABILITY_HOLDING, AST_BRIDGE_FLAG_MERGE_INHIBIT_FROM, AST_BRIDGE_FLAG_MERGE_INHIBIT_TO, AST_BRIDGE_FLAG_SWAP_INHIBIT_FROM, AST_BRIDGE_FLAG_SWAP_INHIBIT_TO, AST_BRIDGE_FLAG_TRANSFER_PROHIBITED, wait_bridge_wrapper::bridge, lock, NULL, SCOPED_AO2LOCK, wait_bridge_wrapper_alloc(), and wait_bridge_wrapper_find_by_name().

Referenced by bridgewait_exec().

342 {
343  struct wait_bridge_wrapper * wrapper;
344  struct ast_bridge *bridge = NULL;
345 
347 
348  if ((wrapper = wait_bridge_wrapper_find_by_name(bridge_name))) {
349  return wrapper;
350  }
351 
352  /*
353  * Holding bridges can allow local channel move/swap
354  * optimization to the bridge. However, we cannot allow it for
355  * this holding bridge because the call will lose the channel
356  * roles and dialplan location as a result.
357  */
362 
363  if (!bridge) {
364  return NULL;
365  }
366 
367  /* The bridge reference is unconditionally passed. */
368  return wait_bridge_wrapper_alloc(bridge_name, bridge);
369 }
#define APP_NAME
static struct wait_bridge_wrapper * wait_bridge_wrapper_find_by_name(const char *bridge_name)
#define NULL
Definition: resample.c:96
static struct wait_bridge_wrapper * wait_bridge_wrapper_alloc(const char *bridge_name, struct ast_bridge *bridge)
ast_mutex_t lock
Definition: app_meetme.c:1091
struct ast_bridge * ast_bridge_base_new(uint32_t capabilities, unsigned int flags, const char *creator, const char *name, const char *id)
Create a new base class bridge.
Definition: bridge.c:960
Structure that contains information about a bridge.
Definition: bridge.h:353
#define SCOPED_AO2LOCK(varname, obj)
scoped lock specialization for ao2 mutexes.
Definition: lock.h:602
static struct ao2_container * wait_bridge_wrappers

◆ load_module()

static int load_module ( void  )
static

Definition at line 499 of file app_bridgewait.c.

References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, APP_NAME, ast_register_application_xml, bridgewait_exec(), NULL, wait_bridge_hash_fn(), and wait_bridge_sort_fn().

500 {
504 
505  if (!wait_bridge_wrappers) {
506  return -1;
507  }
508 
510 }
#define APP_NAME
static int wait_bridge_sort_fn(const void *obj_left, const void *obj_right, const int flags)
#define NULL
Definition: resample.c:96
static int wait_bridge_hash_fn(const void *obj, const int flags)
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Definition: astobj2.h:1310
static int bridgewait_exec(struct ast_channel *chan, const char *data)
Reject objects with duplicate keys in container.
Definition: astobj2.h:1192
static struct ao2_container * wait_bridge_wrappers
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

◆ process_options()

static int process_options ( struct ast_channel chan,
struct ast_flags flags,
char **  opts,
struct ast_bridge_features features,
enum wait_bridge_roles  role 
)
static

Definition at line 268 of file app_bridgewait.c.

References apply_option_entertainment(), apply_option_moh(), apply_option_timeout(), ast_assert, ast_channel_add_bridge_role(), ast_test_flag, MUXFLAG_ENTERTAINMENT, MUXFLAG_MOHCLASS, MUXFLAG_TIMEOUT, OPT_ARG_ENTERTAINMENT, OPT_ARG_MOHCLASS, OPT_ARG_TIMEOUT, ROLE_ANNOUNCER, ROLE_INVALID, and ROLE_PARTICIPANT.

Referenced by bridgewait_exec().

269 {
270  if (ast_test_flag(flags, MUXFLAG_TIMEOUT)) {
271  if (apply_option_timeout(features, opts[OPT_ARG_TIMEOUT])) {
272  return -1;
273  }
274  }
275 
276  switch (role) {
277  case ROLE_PARTICIPANT:
278  if (ast_channel_add_bridge_role(chan, "holding_participant")) {
279  return -1;
280  }
281 
282  if (ast_test_flag(flags, MUXFLAG_MOHCLASS)) {
283  if (apply_option_moh(chan, opts[OPT_ARG_MOHCLASS])) {
284  return -1;
285  }
286  }
287 
288  if (ast_test_flag(flags, MUXFLAG_ENTERTAINMENT)) {
290  return -1;
291  }
292  }
293 
294  break;
295  case ROLE_ANNOUNCER:
296  if (ast_channel_add_bridge_role(chan, "announcer")) {
297  return -1;
298  }
299  break;
300  case ROLE_INVALID:
301  ast_assert(0);
302  return -1;
303  }
304 
305  return 0;
306 }
static int apply_option_entertainment(struct ast_channel *chan, const char *entertainment_arg)
#define ast_test_flag(p, flag)
Definition: utils.h:63
static int apply_option_timeout(struct ast_bridge_features *features, char *duration_arg)
#define ast_assert(a)
Definition: utils.h:650
int ast_channel_add_bridge_role(struct ast_channel *chan, const char *role_name)
Adds a bridge role to a channel.
Definition: bridge_roles.c:317
static int apply_option_moh(struct ast_channel *chan, const char *class_arg)

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 492 of file app_bridgewait.c.

References ao2_cleanup, APP_NAME, and ast_unregister_application().

493 {
495 
497 }
#define APP_NAME
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static struct ao2_container * wait_bridge_wrappers

◆ validate_role()

static enum wait_bridge_roles validate_role ( const char *  role)
static

Definition at line 405 of file app_bridgewait.c.

References ROLE_ANNOUNCER, ROLE_INVALID, and ROLE_PARTICIPANT.

Referenced by bridgewait_exec().

406 {
407  if (!strcmp(role, "participant")) {
408  return ROLE_PARTICIPANT;
409  } else if (!strcmp(role, "announcer")) {
410  return ROLE_ANNOUNCER;
411  } else {
412  return ROLE_INVALID;
413  }
414 }

◆ wait_bridge_hash_fn()

static int wait_bridge_hash_fn ( const void *  obj,
const int  flags 
)
static

Definition at line 140 of file app_bridgewait.c.

References ast_assert, ast_str_hash(), wait_bridge_wrapper::name, OBJ_KEY, OBJ_PARTIAL_KEY, and OBJ_POINTER.

Referenced by load_module().

141 {
142  const struct wait_bridge_wrapper *entry;
143  const char *key;
144 
145  switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
146  case OBJ_KEY:
147  key = obj;
148  return ast_str_hash(key);
149  case OBJ_POINTER:
150  entry = obj;
151  return ast_str_hash(entry->name);
152  default:
153  /* Hash can only work on something with a full key. */
154  ast_assert(0);
155  return 0;
156  }
157 }
#define OBJ_KEY
Definition: astobj2.h:1155
#define OBJ_POINTER
Definition: astobj2.h:1154
#define ast_assert(a)
Definition: utils.h:650
#define OBJ_PARTIAL_KEY
Definition: astobj2.h:1156
Definition: search.h:40
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition: strings.h:1206

◆ wait_bridge_sort_fn()

static int wait_bridge_sort_fn ( const void *  obj_left,
const void *  obj_right,
const int  flags 
)
static

Definition at line 159 of file app_bridgewait.c.

References ast_assert, wait_bridge_wrapper::name, OBJ_KEY, OBJ_PARTIAL_KEY, and OBJ_POINTER.

Referenced by load_module().

160 {
161  const struct wait_bridge_wrapper *left = obj_left;
162  const struct wait_bridge_wrapper *right = obj_right;
163  const char *right_key = obj_right;
164  int cmp;
165 
166  switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
167  case OBJ_POINTER:
168  right_key = right->name;
169  /* Fall through */
170  case OBJ_KEY:
171  cmp = strcmp(left->name, right_key);
172  break;
173  case OBJ_PARTIAL_KEY:
174  cmp = strncmp(left->name, right_key, strlen(right_key));
175  break;
176  default:
177  /* Sort can only work on something with a full or partial key. */
178  ast_assert(0);
179  cmp = 0;
180  break;
181  }
182  return cmp;
183 }
#define OBJ_KEY
Definition: astobj2.h:1155
#define OBJ_POINTER
Definition: astobj2.h:1154
#define ast_assert(a)
Definition: utils.h:650
#define OBJ_PARTIAL_KEY
Definition: astobj2.h:1156

◆ wait_bridge_wrapper_alloc()

static struct wait_bridge_wrapper* wait_bridge_wrapper_alloc ( const char *  bridge_name,
struct ast_bridge bridge 
)
static

Definition at line 319 of file app_bridgewait.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_cleanup, ao2_link, ast_bridge_destroy(), wait_bridge_wrapper::bridge, wait_bridge_wrapper::name, NULL, and wait_bridge_wrapper_destructor().

Referenced by get_wait_bridge_wrapper().

320 {
321  struct wait_bridge_wrapper *bridge_wrapper;
322 
323  bridge_wrapper = ao2_alloc_options(sizeof(*bridge_wrapper) + strlen(bridge_name) + 1,
325  if (!bridge_wrapper) {
326  ast_bridge_destroy(bridge, 0);
327  return NULL;
328  }
329 
330  strcpy(bridge_wrapper->name, bridge_name);
331  bridge_wrapper->bridge = bridge;
332 
333  if (!ao2_link(wait_bridge_wrappers, bridge_wrapper)) {
334  ao2_cleanup(bridge_wrapper);
335  return NULL;
336  }
337 
338  return bridge_wrapper;
339 }
int ast_bridge_destroy(struct ast_bridge *bridge, int cause)
Destroy a bridge.
Definition: bridge.c:970
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define NULL
Definition: resample.c:96
struct ast_bridge * bridge
static void wait_bridge_wrapper_destructor(void *obj)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static struct ao2_container * wait_bridge_wrappers
#define ao2_link(container, obj)
Definition: astobj2.h:1549

◆ wait_bridge_wrapper_destructor()

static void wait_bridge_wrapper_destructor ( void *  obj)
static

Definition at line 126 of file app_bridgewait.c.

References ast_bridge_destroy(), and wait_bridge_wrapper::bridge.

Referenced by wait_bridge_wrapper_alloc().

127 {
128  struct wait_bridge_wrapper *wrapper = obj;
129 
130  if (wrapper->bridge) {
131  ast_bridge_destroy(wrapper->bridge, 0);
132  }
133 }
int ast_bridge_destroy(struct ast_bridge *bridge, int cause)
Destroy a bridge.
Definition: bridge.c:970
struct ast_bridge * bridge

◆ wait_bridge_wrapper_find_by_name()

static struct wait_bridge_wrapper* wait_bridge_wrapper_find_by_name ( const char *  bridge_name)
static

Definition at line 135 of file app_bridgewait.c.

References ao2_find, and OBJ_KEY.

Referenced by get_wait_bridge_wrapper().

136 {
137  return ao2_find(wait_bridge_wrappers, bridge_name, OBJ_KEY);
138 }
#define OBJ_KEY
Definition: astobj2.h:1155
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
static struct ao2_container * wait_bridge_wrappers

◆ wait_wrapper_removal()

static void wait_wrapper_removal ( struct wait_bridge_wrapper wrapper)
static

Definition at line 378 of file app_bridgewait.c.

References ao2_cleanup, ao2_lock, ao2_ref, ao2_unlink, and ao2_unlock.

Referenced by bridgewait_exec().

379 {
380  if (!wrapper) {
381  return;
382  }
383 
385  if (ao2_ref(wrapper, 0) == 2) {
386  /* Either we have the only real reference or else wrapper isn't in the container anyway. */
388  }
390 
391  ao2_cleanup(wrapper);
392 }
#define ao2_unlock(a)
Definition: astobj2.h:730
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718
#define ao2_unlink(container, obj)
Definition: astobj2.h:1598
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static struct ao2_container * wait_bridge_wrappers

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Place the channel into a holding bridge application" , .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, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 512 of file app_bridgewait.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 512 of file app_bridgewait.c.

◆ bridgewait_opts

const struct ast_app_option bridgewait_opts[128] = { [ 'e' ] = { .flag = MUXFLAG_ENTERTAINMENT , .arg_index = OPT_ARG_ENTERTAINMENT + 1 }, [ 'm' ] = { .flag = MUXFLAG_MOHCLASS , .arg_index = OPT_ARG_MOHCLASS + 1 }, [ 'S' ] = { .flag = MUXFLAG_TIMEOUT , .arg_index = OPT_ARG_TIMEOUT + 1 }, }
static

Definition at line 202 of file app_bridgewait.c.

Referenced by bridgewait_exec().

◆ wait_bridge_wrappers

struct ao2_container* wait_bridge_wrappers
static

Definition at line 119 of file app_bridgewait.c.