Asterisk - The Open Source Telephony Project GIT-master-590b490
Loading...
Searching...
No Matches
Macros | Functions | Variables
app_stasis_broadcast.c File Reference

Stasis broadcast dialplan application. More...

#include "asterisk.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/stasis_app_broadcast.h"
#include "asterisk/stasis_app_impl.h"
Include dependency graph for app_stasis_broadcast.c:

Go to the source code of this file.

Macros

#define DEFAULT_TIMEOUT_MS   500
 Default timeout in milliseconds.
 
#define MAX_STASIS_ARGS   128
 Maximum number of Stasis arguments.
 
#define MAX_TIMEOUT_MS   60000
 Maximum timeout in milliseconds.
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int stasis_broadcast_exec (struct ast_channel *chan, const char *data)
 StasisBroadcast dialplan application callback.
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Stasis application broadcast" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .requires = "res_stasis,res_stasis_broadcast", }
 
static const char * app = "StasisBroadcast"
 Dialplan application name.
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Stasis broadcast dialplan application.

Author
Daniel Donoghue danie.nosp@m.l.do.nosp@m.noghu.nosp@m.e@au.nosp@m.rorai.nosp@m.nnov.nosp@m.ation.nosp@m..com

Definition in file app_stasis_broadcast.c.

Macro Definition Documentation

◆ DEFAULT_TIMEOUT_MS

#define DEFAULT_TIMEOUT_MS   500

Default timeout in milliseconds.

Definition at line 140 of file app_stasis_broadcast.c.

◆ MAX_STASIS_ARGS

#define MAX_STASIS_ARGS   128

Maximum number of Stasis arguments.

Definition at line 146 of file app_stasis_broadcast.c.

◆ MAX_TIMEOUT_MS

#define MAX_TIMEOUT_MS   60000

Maximum timeout in milliseconds.

Definition at line 143 of file app_stasis_broadcast.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 286 of file app_stasis_broadcast.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 286 of file app_stasis_broadcast.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 286 of file app_stasis_broadcast.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 270 of file app_stasis_broadcast.c.

271{
273}
static int stasis_broadcast_exec(struct ast_channel *chan, const char *data)
StasisBroadcast dialplan application callback.
static const char * app
Dialplan application name.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition module.h:640

References app, ast_register_application_xml, and stasis_broadcast_exec().

◆ stasis_broadcast_exec()

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

StasisBroadcast dialplan application callback.

Definition at line 149 of file app_stasis_broadcast.c.

150{
151 char *parse = NULL;
152 int timeout_ms = DEFAULT_TIMEOUT_MS;
153 const char *app_filter = NULL;
154 const char *stasis_args_raw = NULL;
155 unsigned int flags = STASIS_BROADCAST_FLAG_SUPPRESS_CLAIMED;
156 char *winner = NULL;
157 int result = 0;
158 int stasis_argc = 0;
159 char *stasis_argv[MAX_STASIS_ARGS];
160
162 AST_APP_ARG(timeout);
163 AST_APP_ARG(app_filter);
164 AST_APP_ARG(stasis_args);
165 AST_APP_ARG(notify_claimed);
166 );
167
168 ast_assert(chan != NULL);
169
170 /* Initialize channel variable */
171 pbx_builtin_setvar_helper(chan, "STASISSTATUS", "");
172
173 /* Parse positional arguments if provided */
174 if (!ast_strlen_zero(data)) {
175 parse = ast_strdupa(data);
177
178 if (!ast_strlen_zero(args.timeout)) {
179 if (sscanf(args.timeout, "%d", &timeout_ms) != 1
180 || timeout_ms < 0 || timeout_ms > MAX_TIMEOUT_MS) {
182 "Channel %s: invalid timeout value '%s' (must be 0-%dms), using default %dms\n",
184 timeout_ms = DEFAULT_TIMEOUT_MS;
185 }
186 }
187
188 if (!ast_strlen_zero(args.app_filter)) {
189 app_filter = args.app_filter;
190 }
191
192 if (!ast_strlen_zero(args.stasis_args)) {
193 stasis_args_raw = args.stasis_args;
194 }
195
196 if (!ast_strlen_zero(args.notify_claimed) && ast_true(args.notify_claimed)) {
197 flags &= ~STASIS_BROADCAST_FLAG_SUPPRESS_CLAIMED;
198 }
199 }
200
201 /*
202 * Parse colon-delimited Stasis arguments. stasis_argv[] holds
203 * pointers into the stack-allocated args_copy buffer. This is
204 * safe because stasis_app_exec is called within this same
205 * function scope so the stack frame remains alive.
206 */
207 if (!ast_strlen_zero(stasis_args_raw)) {
208 char *args_copy = ast_strdupa(stasis_args_raw);
209 char *arg;
210
211 while ((arg = strsep(&args_copy, ":")) != NULL && stasis_argc < MAX_STASIS_ARGS) {
212 stasis_argv[stasis_argc++] = arg;
213 }
214 }
215
216 ast_debug(3, "Broadcasting channel %s (timeout=%dms, filter=%s, args=%d)\n",
217 ast_channel_name(chan), timeout_ms, app_filter ? app_filter : "none",
218 stasis_argc);
219
220 /* Start the broadcast */
221 result = stasis_app_broadcast_channel(chan, timeout_ms, app_filter, flags);
222 if (result) {
223 ast_log(LOG_ERROR, "Failed to broadcast channel %s: %s\n",
224 ast_channel_name(chan),
225 result == AST_OPTIONAL_API_UNAVAILABLE ? "res_stasis_broadcast not loaded" : "internal error");
226 pbx_builtin_setvar_helper(chan, "STASISSTATUS", "FAILED");
227 return 0;
228 }
229
230 /* Wait for a claim. A late claim can arrive between the timeout
231 * expiring and our cleanup call, so always check for a winner
232 * regardless of the wait result. */
233 stasis_app_broadcast_wait(chan, timeout_ms);
235
236 if (winner) {
237 int ret;
238
239 ast_debug(3, "Channel %s claimed by %s, entering Stasis\n",
240 ast_channel_name(chan), winner);
241
242 /* Defer cleanup until after Stasis so concurrent claimants can still
243 * find the context (with claimed=1) and receive 409 Conflict instead
244 * of 404 Not Found. */
245 ret = stasis_app_exec(chan, winner, stasis_argc, stasis_argv);
246 ast_free(winner);
247
248 /* Clean up now that the Stasis session has ended */
250
251 if (ret) {
252 pbx_builtin_setvar_helper(chan, "STASISSTATUS", "FAILED");
253 if (ast_check_hangup(chan)) {
254 return -1;
255 }
256 } else {
257 pbx_builtin_setvar_helper(chan, "STASISSTATUS", "SUCCESS");
258 }
259 } else {
260 /* No winner: clean up immediately, nothing to race against */
262 ast_log(LOG_WARNING, "Channel %s: not claimed within %dms timeout\n",
263 ast_channel_name(chan), timeout_ms);
264 pbx_builtin_setvar_helper(chan, "STASISSTATUS", "TIMEOUT");
265 }
266
267 return 0;
268}
#define MAX_TIMEOUT_MS
Maximum timeout in milliseconds.
#define MAX_STASIS_ARGS
Maximum number of Stasis arguments.
#define DEFAULT_TIMEOUT_MS
Default timeout in milliseconds.
char * strsep(char **str, const char *delims)
#define ast_free(a)
Definition astmm.h:180
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
#define ast_log
Definition astobj2.c:42
static PGresult * result
Definition cel_pgsql.c:84
const char * ast_channel_name(const struct ast_channel *chan)
const char * ast_channel_uniqueid(const struct ast_channel *chan)
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition channel.c:446
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define LOG_WARNING
#define AST_OPTIONAL_API_UNAVAILABLE
A common value for optional API stub functions to return.
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
static struct @522 args
#define NULL
Definition resample.c:96
void AST_OPTIONAL_API_NAME() stasis_app_broadcast_cleanup(const char *channel_id)
Clean up broadcast context for a channel.
int AST_OPTIONAL_API_NAME() stasis_app_broadcast_wait(struct ast_channel *chan, int timeout_ms)
Wait for a broadcast channel to be claimed.
#define STASIS_BROADCAST_FLAG_SUPPRESS_CLAIMED
Suppress CallClaimed event for this broadcast.
int AST_OPTIONAL_API_NAME() stasis_app_broadcast_channel(struct ast_channel *chan, int timeout_ms, const char *app_filter, unsigned int flags)
Start a broadcast for a channel.
char *AST_OPTIONAL_API_NAME() stasis_app_broadcast_winner(const char *channel_id)
Get the winner app name for a broadcast channel.
int stasis_app_exec(struct ast_channel *chan, const char *app_name, int argc, char *argv[])
Control a channel using stasis_app.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition utils.c:2233
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
#define ast_assert(a)
Definition utils.h:779

References args, AST_APP_ARG, ast_assert, ast_channel_name(), ast_channel_uniqueid(), ast_check_hangup(), ast_debug, AST_DECLARE_APP_ARGS, ast_free, ast_log, AST_OPTIONAL_API_UNAVAILABLE, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_true(), DEFAULT_TIMEOUT_MS, LOG_ERROR, LOG_WARNING, MAX_STASIS_ARGS, MAX_TIMEOUT_MS, NULL, pbx_builtin_setvar_helper(), result, stasis_app_broadcast_channel(), stasis_app_broadcast_cleanup(), stasis_app_broadcast_wait(), stasis_app_broadcast_winner(), stasis_app_exec(), STASIS_BROADCAST_FLAG_SUPPRESS_CLAIMED, and strsep().

Referenced by load_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 275 of file app_stasis_broadcast.c.

276{
278}
int ast_unregister_application(const char *app)
Unregister an application.
Definition pbx_app.c:404

References app, and ast_unregister_application().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Stasis application broadcast" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .requires = "res_stasis,res_stasis_broadcast", }
static

Definition at line 286 of file app_stasis_broadcast.c.

◆ app

const char* app = "StasisBroadcast"
static

Dialplan application name.

Definition at line 137 of file app_stasis_broadcast.c.

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 286 of file app_stasis_broadcast.c.