Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
bridge_builtin_interval_features.c File Reference

Built in bridging interval features. More...

#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/bridge.h"
#include "asterisk/file.h"
#include "asterisk/app.h"
#include "asterisk/astobj2.h"
#include "asterisk/test.h"
#include "asterisk/say.h"
#include "asterisk/stringfields.h"
#include "asterisk/musiconhold.h"
#include "asterisk/causes.h"
Include dependency graph for bridge_builtin_interval_features.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int bridge_builtin_set_limits (struct ast_bridge_features *features, struct ast_bridge_features_limits *limits, enum ast_bridge_hook_remove_flags remove_flags)
 
static int bridge_features_connect_callback (struct ast_bridge_channel *bridge_channel, void *hook_pvt)
 
static int bridge_features_duration_callback (struct ast_bridge_channel *bridge_channel, void *hook_pvt)
 
static void bridge_features_limits_copy (struct ast_bridge_features_limits *dst, struct ast_bridge_features_limits *src)
 
static void bridge_features_limits_dtor (void *vdoomed)
 
static int bridge_features_warning_callback (struct ast_bridge_channel *bridge_channel, void *hook_pvt)
 
static void limits_interval_playback (struct ast_bridge_channel *bridge_channel, struct ast_bridge_features_limits *limits, const char *file)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Built in bridging interval features" , .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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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
 

Detailed Description

Built in bridging interval features.

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

Definition in file bridge_builtin_interval_features.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 215 of file bridge_builtin_interval_features.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 215 of file bridge_builtin_interval_features.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 215 of file bridge_builtin_interval_features.c.

◆ bridge_builtin_set_limits()

static int bridge_builtin_set_limits ( struct ast_bridge_features features,
struct ast_bridge_features_limits limits,
enum ast_bridge_hook_remove_flags  remove_flags 
)
static

Definition at line 148 of file bridge_builtin_interval_features.c.

References __ao2_cleanup(), AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_cleanup, ao2_ref, ast_bridge_features_limits_construct(), AST_BRIDGE_HOOK_TIMER_OPTION_MEDIA, ast_bridge_interval_hook(), ast_log, ast_module_ref, ast_module_unref, ast_samp2tv(), ast_strlen_zero, ast_tvadd(), ast_tvnow(), bridge_features_connect_callback(), bridge_features_duration_callback(), bridge_features_limits_copy(), bridge_features_limits_dtor(), bridge_features_warning_callback(), ast_bridge_features_limits::duration, LOG_ERROR, LOG_WARNING, NULL, RAII_VAR, and ast_module_info::self.

Referenced by load_module().

151 {
152  RAII_VAR(struct ast_bridge_features_limits *, feature_limits, NULL, ao2_cleanup);
153 
154  if (!limits->duration) {
155  return -1;
156  }
157 
158  /* Create limits hook_pvt data. */
160  feature_limits = ao2_alloc_options(sizeof(*feature_limits),
162  if (!feature_limits) {
164  return -1;
165  }
166  if (ast_bridge_features_limits_construct(feature_limits)) {
167  return -1;
168  }
169  bridge_features_limits_copy(feature_limits, limits);
170  feature_limits->quitting_time = ast_tvadd(ast_tvnow(),
171  ast_samp2tv(feature_limits->duration, 1000));
172 
173  /* Install limit hooks. */
174  ao2_ref(feature_limits, +1);
176  feature_limits->duration,
177  bridge_features_duration_callback, feature_limits, __ao2_cleanup, remove_flags)) {
178  ast_log(LOG_ERROR, "Failed to schedule the duration limiter to the bridge channel.\n");
179  ao2_ref(feature_limits, -1);
180  return -1;
181  }
182  if (!ast_strlen_zero(feature_limits->connect_sound)) {
183  ao2_ref(feature_limits, +1);
185  bridge_features_connect_callback, feature_limits, __ao2_cleanup, remove_flags)) {
186  ast_log(LOG_WARNING, "Failed to schedule connect sound to the bridge channel.\n");
187  ao2_ref(feature_limits, -1);
188  }
189  }
190  if (feature_limits->warning && feature_limits->warning < feature_limits->duration) {
191  ao2_ref(feature_limits, +1);
193  feature_limits->duration - feature_limits->warning,
194  bridge_features_warning_callback, feature_limits, __ao2_cleanup, remove_flags)) {
195  ast_log(LOG_WARNING, "Failed to schedule warning sound playback to the bridge channel.\n");
196  ao2_ref(feature_limits, -1);
197  }
198  }
199 
200  return 0;
201 }
static int bridge_features_duration_callback(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
#define LOG_WARNING
Definition: logger.h:274
static void bridge_features_limits_dtor(void *vdoomed)
void __ao2_cleanup(void *obj)
Definition: astobj2.c:674
static void bridge_features_limits_copy(struct ast_bridge_features_limits *dst, struct ast_bridge_features_limits *src)
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define NULL
Definition: resample.c:96
#define ast_module_unref(mod)
Release a reference to the module.
Definition: module.h:469
#define ast_strlen_zero(foo)
Definition: strings.h:52
static int bridge_features_warning_callback(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
#define ast_log
Definition: astobj2.c:42
struct ast_module * self
Definition: module.h:342
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct timeval ast_samp2tv(unsigned int _nsamp, unsigned int _rate)
Returns a timeval corresponding to the duration of n samples at rate r. Useful to convert samples to ...
Definition: time.h:238
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:3382
static int bridge_features_connect_callback(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
#define LOG_ERROR
Definition: logger.h:285
int ast_bridge_features_limits_construct(struct ast_bridge_features_limits *limits)
Constructor function for ast_bridge_features_limits.
Definition: bridge.c:3459
Structure that contains configuration information for the limits feature.
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: extconf.c:2283
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define ast_module_ref(mod)
Hold a reference to the module.
Definition: module.h:443

◆ bridge_features_connect_callback()

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

Definition at line 115 of file bridge_builtin_interval_features.c.

References ast_bridge_features_limits::connect_sound, and limits_interval_playback().

Referenced by bridge_builtin_set_limits().

116 {
117  struct ast_bridge_features_limits *limits = hook_pvt;
118 
119  limits_interval_playback(bridge_channel, limits, limits->connect_sound);
120  return -1;
121 }
Structure that contains configuration information for the limits feature.
static void limits_interval_playback(struct ast_bridge_channel *bridge_channel, struct ast_bridge_features_limits *limits, const char *file)
const ast_string_field connect_sound

◆ bridge_features_duration_callback()

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

Definition at line 51 of file bridge_builtin_interval_features.c.

References ast_bridge_channel_leave_bridge(), AST_CAUSE_NORMAL_CLEARING, ast_channel_name(), AST_DIGIT_NONE, ast_stream_and_wait(), ast_strlen_zero, ast_test_suite_event_notify, BRIDGE_CHANNEL_STATE_END, ast_bridge_channel::chan, and ast_bridge_features_limits::duration_sound.

Referenced by bridge_builtin_set_limits().

52 {
53  struct ast_bridge_features_limits *limits = hook_pvt;
54 
55  if (!ast_strlen_zero(limits->duration_sound)) {
56  ast_stream_and_wait(bridge_channel->chan, limits->duration_sound, AST_DIGIT_NONE);
57  }
58 
61 
62  ast_test_suite_event_notify("BRIDGE_TIMELIMIT", "Channel1: %s",
63  ast_channel_name(bridge_channel->chan));
64  return -1;
65 }
const ast_string_field duration_sound
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:105
#define ast_test_suite_event_notify(s, f,...)
Definition: test.h:196
Structure that contains configuration information for the limits feature.
#define AST_DIGIT_NONE
Definition: file.h:47
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).
int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char *digits)
stream file until digit If the file name is non-empty, try to play it.
Definition: file.c:1814
struct ast_channel * chan
const char * ast_channel_name(const struct ast_channel *chan)

◆ bridge_features_limits_copy()

static void bridge_features_limits_copy ( struct ast_bridge_features_limits dst,
struct ast_bridge_features_limits src 
)
static

Definition at line 131 of file bridge_builtin_interval_features.c.

References ast_string_fields_copy, ast_bridge_features_limits::duration, ast_bridge_features_limits::frequency, ast_bridge_features_limits::quitting_time, and ast_bridge_features_limits::warning.

Referenced by bridge_builtin_set_limits().

132 {
133  ast_string_fields_copy(dst, src);
134  dst->quitting_time = src->quitting_time;
135  dst->duration = src->duration;
136  dst->warning = src->warning;
137  dst->frequency = src->frequency;
138 }
#define ast_string_fields_copy(copy, orig)
Copy all string fields from one instance to another of the same structure.
Definition: stringfields.h:627

◆ bridge_features_limits_dtor()

static void bridge_features_limits_dtor ( void *  vdoomed)
static

Definition at line 140 of file bridge_builtin_interval_features.c.

References ast_bridge_features_limits_destroy(), ast_module_unref, and ast_module_info::self.

Referenced by bridge_builtin_set_limits().

141 {
142  struct ast_bridge_features_limits *doomed = vdoomed;
143 
146 }
void ast_bridge_features_limits_destroy(struct ast_bridge_features_limits *limits)
Destructor function for ast_bridge_features_limits.
Definition: bridge.c:3470
#define ast_module_unref(mod)
Release a reference to the module.
Definition: module.h:469
struct ast_module * self
Definition: module.h:342
Structure that contains configuration information for the limits feature.

◆ bridge_features_warning_callback()

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

Definition at line 123 of file bridge_builtin_interval_features.c.

References ast_bridge_features_limits::frequency, limits_interval_playback(), and ast_bridge_features_limits::warning_sound.

Referenced by bridge_builtin_set_limits().

124 {
125  struct ast_bridge_features_limits *limits = hook_pvt;
126 
127  limits_interval_playback(bridge_channel, limits, limits->warning_sound);
128  return limits->frequency ?: -1;
129 }
Structure that contains configuration information for the limits feature.
const ast_string_field warning_sound
static void limits_interval_playback(struct ast_bridge_channel *bridge_channel, struct ast_bridge_features_limits *limits, const char *file)

◆ limits_interval_playback()

static void limits_interval_playback ( struct ast_bridge_channel bridge_channel,
struct ast_bridge_features_limits limits,
const char *  file 
)
static

Definition at line 67 of file bridge_builtin_interval_features.c.

References ast_channel_flags(), ast_channel_language(), ast_channel_latest_musicclass(), ast_channel_lock, ast_channel_unlock, AST_DIGIT_NONE, AST_FLAG_MOH, ast_moh_start(), ast_say_number(), ast_strdupa, ast_stream_and_wait(), ast_test_flag, ast_tvdiff_ms(), ast_tvnow(), ast_bridge_channel::chan, min, NULL, and ast_bridge_features_limits::quitting_time.

Referenced by bridge_features_connect_callback(), and bridge_features_warning_callback().

68 {
69  if (!strcasecmp(file, "timeleft")) {
70  unsigned int remaining = ast_tvdiff_ms(limits->quitting_time, ast_tvnow()) / 1000;
71  unsigned int min;
72  unsigned int sec;
73 
74  if (remaining <= 0) {
75  return;
76  }
77 
78  if ((remaining / 60) > 1) {
79  min = remaining / 60;
80  sec = remaining % 60;
81  } else {
82  min = 0;
83  sec = remaining;
84  }
85 
86  ast_stream_and_wait(bridge_channel->chan, "vm-youhave", AST_DIGIT_NONE);
87  if (min) {
88  ast_say_number(bridge_channel->chan, min, AST_DIGIT_NONE,
89  ast_channel_language(bridge_channel->chan), NULL);
90  ast_stream_and_wait(bridge_channel->chan, "queue-minutes", AST_DIGIT_NONE);
91  }
92  if (sec) {
93  ast_say_number(bridge_channel->chan, sec, AST_DIGIT_NONE,
94  ast_channel_language(bridge_channel->chan), NULL);
95  ast_stream_and_wait(bridge_channel->chan, "queue-seconds", AST_DIGIT_NONE);
96  }
97  } else {
98  ast_stream_and_wait(bridge_channel->chan, file, AST_DIGIT_NONE);
99  }
100 
101  /*
102  * It may be necessary to resume music on hold after we finish
103  * playing the announcment.
104  */
105  if (ast_test_flag(ast_channel_flags(bridge_channel->chan), AST_FLAG_MOH)) {
106  const char *latest_musicclass;
107 
108  ast_channel_lock(bridge_channel->chan);
109  latest_musicclass = ast_strdupa(ast_channel_latest_musicclass(bridge_channel->chan));
110  ast_channel_unlock(bridge_channel->chan);
111  ast_moh_start(bridge_channel->chan, latest_musicclass, NULL);
112  }
113 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
#define ast_test_flag(p, flag)
Definition: utils.h:63
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:98
#define NULL
Definition: resample.c:96
const char * ast_channel_latest_musicclass(const struct ast_channel *chan)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
#define AST_DIGIT_NONE
Definition: file.h:47
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
Definition: channel.c:7866
#define ast_channel_unlock(chan)
Definition: channel.h:2946
int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char *digits)
stream file until digit If the file name is non-empty, try to play it.
Definition: file.c:1814
struct ast_channel * chan
int ast_say_number(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options)
says a number
Definition: channel.c:8337
const char * ast_channel_language(const struct ast_channel *chan)
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
#define min(a, b)
Definition: f2c.h:197

◆ load_module()

static int load_module ( void  )
static

Definition at line 209 of file bridge_builtin_interval_features.c.

References AST_BRIDGE_BUILTIN_INTERVAL_LIMITS, ast_bridge_interval_register(), and bridge_builtin_set_limits().

210 {
213 }
int ast_bridge_interval_register(enum ast_bridge_builtin_interval interval, ast_bridge_builtin_set_limits_fn callback)
Register a handler for a built in interval feature.
Definition: bridge.c:3168
static int bridge_builtin_set_limits(struct ast_bridge_features *features, struct ast_bridge_features_limits *limits, enum ast_bridge_hook_remove_flags remove_flags)

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 203 of file bridge_builtin_interval_features.c.

References AST_BRIDGE_BUILTIN_INTERVAL_LIMITS, and ast_bridge_interval_unregister().

204 {
206  return 0;
207 }
int ast_bridge_interval_unregister(enum ast_bridge_builtin_interval interval)
Definition: bridge.c:3180

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Built in bridging interval features" , .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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 215 of file bridge_builtin_interval_features.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 215 of file bridge_builtin_interval_features.c.