|
Asterisk - The Open Source Telephony Project GIT-master-590b490
|
Stasis application broadcast resource. More...
#include "asterisk.h"#include <errno.h>#include <regex.h>#include "asterisk/astobj2.h"#include "asterisk/channel.h"#include "asterisk/http.h"#include "asterisk/json.h"#include "asterisk/lock.h"#include "asterisk/module.h"#include "asterisk/pbx.h"#include "asterisk/stasis_app.h"#include "asterisk/stasis_app_impl.h"#include "asterisk/stasis_channels.h"#include "asterisk/time.h"#include "asterisk/utils.h"#include "asterisk/stasis_app_broadcast.h"
Go to the source code of this file.
Data Structures | |
| struct | stasis_broadcast_ctx |
| Broadcast context stored on channel. More... | |
Macros | |
| #define | ALTERNATION_DEPTH_THRESHOLD 2 |
| Group depth threshold for alternation limits. | |
| #define | AST_API_MODULE /* Mark this as the module providing the API */ |
| #define | BROADCAST_BUCKETS 37 |
| #define | BROADCAST_POLL_INTERVAL_MS 200 |
| Interval in ms between hangup checks while waiting for a claim. | |
| #define | MAX_ALTERNATIONS 20 |
| Maximum alternations allowed in deeply nested groups. | |
| #define | MAX_BROADCAST_TIMEOUT_MS (24 * 60 * 60 * 1000) |
| Maximum broadcast timeout in milliseconds (24 hours) | |
| #define | MAX_GROUP_DEPTH 10 |
| Maximum depth for regex group nesting. | |
| #define | MAX_NESTED_QUANTIFIERS 3 |
| Maximum number of nested quantifiers in regex. | |
| #define | MAX_QUANTIFIER_BOUND 100 |
| Maximum value for brace quantifier bounds {m,n}. | |
| #define | MAX_REGEX_LENGTH 256 |
| Maximum length for app_filter regex pattern. | |
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| struct ast_module * | AST_MODULE_SELF_SYM (void) |
| static struct stasis_broadcast_ctx * | broadcast_ctx_create (const char *channel_id, const char *app_filter, unsigned int flags) |
| Create a new broadcast context. | |
| static void | broadcast_ctx_destructor (void *obj) |
| Destructor for broadcast context. | |
| static void | broadcast_datastore_destroy (void *data) |
| Destructor for broadcast datastore. | |
| static int | load_module (void) |
| static int | send_broadcast_event (struct ast_channel *chan, struct stasis_broadcast_ctx *ctx) |
| Create and send broadcast event to all applications. | |
| 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. | |
| 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. | |
| char *AST_OPTIONAL_API_NAME() | stasis_app_broadcast_winner (const char *channel_id) |
| Get the winner app name for a broadcast channel. | |
| int AST_OPTIONAL_API_NAME() | stasis_app_claim_channel (const char *channel_id, const char *app_name) |
| Attempt to claim a broadcast channel. | |
| static int | unload_module (void) |
| static int | validate_regex_pattern (const char *pattern) |
| Validate a regex pattern for safety. | |
Variables | |
| static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .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_ari,http", .load_pri = AST_MODPRI_APP_DEPEND - 1, } |
| static const struct ast_module_info * | ast_module_info = &__mod_info |
| static struct ao2_container * | broadcast_contexts |
| Container for all active broadcast contexts. | |
| static const struct ast_datastore_info | broadcast_datastore_info |
| Datastore information for broadcast context. | |
Stasis application broadcast resource.
Definition in file res_stasis_broadcast.c.
| #define ALTERNATION_DEPTH_THRESHOLD 2 |
Group depth threshold for alternation limits.
Definition at line 71 of file res_stasis_broadcast.c.
| #define AST_API_MODULE /* Mark this as the module providing the API */ |
Definition at line 50 of file res_stasis_broadcast.c.
| #define BROADCAST_BUCKETS 37 |
Definition at line 53 of file res_stasis_broadcast.c.
| #define BROADCAST_POLL_INTERVAL_MS 200 |
Interval in ms between hangup checks while waiting for a claim.
Definition at line 77 of file res_stasis_broadcast.c.
| #define MAX_ALTERNATIONS 20 |
Maximum alternations allowed in deeply nested groups.
Definition at line 68 of file res_stasis_broadcast.c.
| #define MAX_BROADCAST_TIMEOUT_MS (24 * 60 * 60 * 1000) |
Maximum broadcast timeout in milliseconds (24 hours)
Definition at line 74 of file res_stasis_broadcast.c.
| #define MAX_GROUP_DEPTH 10 |
Maximum depth for regex group nesting.
Definition at line 59 of file res_stasis_broadcast.c.
| #define MAX_NESTED_QUANTIFIERS 3 |
Maximum number of nested quantifiers in regex.
Definition at line 62 of file res_stasis_broadcast.c.
| #define MAX_QUANTIFIER_BOUND 100 |
Maximum value for brace quantifier bounds {m,n}.
Definition at line 65 of file res_stasis_broadcast.c.
| #define MAX_REGEX_LENGTH 256 |
Maximum length for app_filter regex pattern.
Definition at line 56 of file res_stasis_broadcast.c.
|
static |
Definition at line 933 of file res_stasis_broadcast.c.
|
static |
Definition at line 933 of file res_stasis_broadcast.c.
| struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 933 of file res_stasis_broadcast.c.
|
static |
Create a new broadcast context.
Validates and compiles the app_filter regex if provided. On regex failure the context is still created but broadcasts will be sent to all applications (i.e. no filtering).
Definition at line 151 of file res_stasis_broadcast.c.
References ao2_alloc, ao2_bump, stasis_broadcast_ctx::app_filter, ast_cond_init, ast_copy_string(), ast_debug, ast_log, ast_strlen_zero(), broadcast_contexts, broadcast_ctx_destructor(), stasis_broadcast_ctx::channel_id, stasis_broadcast_ctx::compiled_filter, stasis_broadcast_ctx::cond, stasis_broadcast_ctx::container, stasis_broadcast_ctx::filter_compiled, stasis_broadcast_ctx::flags, LOG_WARNING, NULL, and validate_regex_pattern().
Referenced by stasis_app_broadcast_channel().
|
static |
Destructor for broadcast context.
Definition at line 132 of file res_stasis_broadcast.c.
References ao2_cleanup, ast_cond_destroy, ast_free, stasis_broadcast_ctx::compiled_filter, stasis_broadcast_ctx::cond, stasis_broadcast_ctx::container, stasis_broadcast_ctx::filter_compiled, and stasis_broadcast_ctx::winner_app.
Referenced by broadcast_ctx_create().
|
static |
Destructor for broadcast datastore.
Called when the channel is destroyed. Ensures the broadcast context is unlinked from the global container even if the caller never reached stasis_app_broadcast_cleanup (e.g. abnormal channel teardown).
Definition at line 112 of file res_stasis_broadcast.c.
References ao2_cleanup, ao2_unlink, and stasis_broadcast_ctx::container.
|
static |
Definition at line 899 of file res_stasis_broadcast.c.
References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ast_debug, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, BROADCAST_BUCKETS, broadcast_contexts, and NULL.
|
static |
Create and send broadcast event to all applications.
Uses the compiled regex cached in ctx for application filtering.
Definition at line 412 of file res_stasis_broadcast.c.
References ao2_bump, ao2_cleanup, ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, app_name(), ast_channel_caller(), ast_channel_exten(), ast_channel_lock, ast_channel_name(), ast_channel_snapshot_to_json(), ast_channel_uniqueid(), ast_channel_unlock, ast_debug, ast_free, ast_json_deep_copy(), ast_json_pack(), ast_json_timeval(), ast_json_unref(), ast_log, ast_malloc, ast_random(), ast_strdupa, ast_tvnow(), stasis_broadcast_ctx::compiled_filter, stasis_broadcast_ctx::filter_compiled, LOG_ERROR, NULL, RAII_VAR, S_OR, stasis_app_get_all(), and stasis_app_send().
Referenced by stasis_app_broadcast_channel().
| 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.
| chan | The channel to broadcast |
| timeout_ms | Timeout in milliseconds |
| app_filter | Optional regex filter for applications |
Definition at line 550 of file res_stasis_broadcast.c.
References ao2_bump, ao2_cleanup, ao2_link, ao2_unlink, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_channel_lock, ast_channel_uniqueid(), ast_channel_unlock, ast_datastore_alloc, ast_datastore_free(), ast_debug, ast_log, broadcast_contexts, broadcast_ctx_create(), broadcast_datastore_info, ast_datastore::data, LOG_ERROR, NULL, RAII_VAR, and send_broadcast_event().
Referenced by stasis_broadcast_exec().
| void AST_OPTIONAL_API_NAME() stasis_app_broadcast_cleanup | ( | const char * | channel_id | ) |
Clean up broadcast context for a channel.
This is the normal-path cleanup called by the dialplan application after the broadcast completes. The channel datastore destructor (broadcast_datastore_destroy) also unlinks the context as a safety net for abnormal teardown; ao2_unlink is idempotent so the double call is harmless.
| channel_id | The unique ID of the channel |
Definition at line 885 of file res_stasis_broadcast.c.
References ao2_cleanup, ao2_find, ast_debug, ast_strlen_zero(), broadcast_contexts, NULL, OBJ_SEARCH_KEY, OBJ_UNLINK, and RAII_VAR.
Referenced by stasis_broadcast_exec().
| int AST_OPTIONAL_API_NAME() stasis_app_broadcast_wait | ( | struct ast_channel * | chan, |
| int | timeout_ms | ||
| ) |
Wait for a broadcast channel to be claimed.
Blocks until the channel is claimed, the timeout expires, or the channel hangs up. The hangup check runs every BROADCAST_POLL_INTERVAL_MS so that a dead channel does not tie up a PBX thread for the full timeout period.
| chan | The channel |
| timeout_ms | Maximum time to wait in milliseconds |
Definition at line 782 of file res_stasis_broadcast.c.
References ao2_cleanup, ao2_find, ao2_lock, ao2_object_get_lockaddr(), ao2_unlock, ast_channel_uniqueid(), ast_check_hangup(), ast_cond_timedwait, ast_debug, ast_log, ast_tv(), ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), broadcast_contexts, BROADCAST_POLL_INTERVAL_MS, LOG_WARNING, MAX_BROADCAST_TIMEOUT_MS, NULL, OBJ_SEARCH_KEY, RAII_VAR, result, and wait_result().
Referenced by stasis_broadcast_exec().
| char *AST_OPTIONAL_API_NAME() stasis_app_broadcast_winner | ( | const char * | channel_id | ) |
Get the winner app name for a broadcast channel.
| channel_id | The unique ID of the channel |
Definition at line 743 of file res_stasis_broadcast.c.
References ao2_cleanup, ao2_find, ao2_lock, ao2_unlock, ast_strdup, ast_strlen_zero(), broadcast_contexts, NULL, OBJ_SEARCH_KEY, and RAII_VAR.
Referenced by stasis_broadcast_exec().
| int AST_OPTIONAL_API_NAME() stasis_app_claim_channel | ( | const char * | channel_id, |
| const char * | app_name | ||
| ) |
Attempt to claim a broadcast channel.
| channel_id | The unique ID of the channel |
| app_name | The name of the application claiming the channel |
Definition at line 637 of file res_stasis_broadcast.c.
References ao2_cleanup, ao2_find, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, app_name(), ast_channel_snapshot_get_latest(), ast_channel_snapshot_to_json(), ast_cond_signal, ast_debug, ast_json_deep_copy(), ast_json_pack(), ast_json_timeval(), ast_json_unref(), ast_log, ast_strdup, ast_strlen_zero(), ast_tvnow(), ast_verb, broadcast_contexts, LOG_ERROR, NULL, OBJ_SEARCH_KEY, RAII_VAR, stasis_app_get_all(), stasis_app_send(), and STASIS_BROADCAST_FLAG_SUPPRESS_CLAIMED.
Referenced by ast_ari_events_claim_channel().
|
static |
Definition at line 912 of file res_stasis_broadcast.c.
References ao2_cleanup, ast_debug, broadcast_contexts, and NULL.
|
static |
Validate a regex pattern for safety.
Checks that the regex pattern is within length limits and doesn't contain patterns that could cause excessive backtracking or denial of service.
| pattern | The regex pattern to validate |
Definition at line 207 of file res_stasis_broadcast.c.
References ALTERNATION_DEPTH_THRESHOLD, ast_debug, ast_strlen_zero(), digit, len(), MAX_ALTERNATIONS, MAX_GROUP_DEPTH, MAX_NESTED_QUANTIFIERS, MAX_QUANTIFIER_BOUND, and MAX_REGEX_LENGTH.
Referenced by broadcast_ctx_create().
|
static |
Definition at line 933 of file res_stasis_broadcast.c.
|
static |
Definition at line 933 of file res_stasis_broadcast.c.
|
static |
Container for all active broadcast contexts.
Definition at line 104 of file res_stasis_broadcast.c.
Referenced by broadcast_ctx_create(), load_module(), stasis_app_broadcast_channel(), stasis_app_broadcast_cleanup(), stasis_app_broadcast_wait(), stasis_app_broadcast_winner(), stasis_app_claim_channel(), and unload_module().
|
static |
Datastore information for broadcast context.
Definition at line 123 of file res_stasis_broadcast.c.
Referenced by stasis_app_broadcast_channel().