mirror of
https://github.com/asterisk/asterisk.git
synced 2026-04-23 07:08:32 +00:00
Adds two optional modules: res_stasis_broadcast.so: Infrastructure for broadcasting a single incoming channel to multiple ARI applications with atomic first-claim-wins semantics. app_stasis_broadcast.so: Provides the StasisBroadcast() dialplan application which invokes the broadcast infrastructure. Both modules are self-contained; if neither is loaded there is zero runtime impact. Loading them does not alter existing Stasis or ARI behavior unless explicitly used. Key Features (only active when modules are loaded): Fisher-Yates shuffled broadcast dispatch for fair claim races Atomic claim operations using mutex + condition variable signaling Configurable broadcast timeouts Safe regex application filtering with validation to mitigate ReDoS risk Thread-safe channel variable snapshotting (channel locked during reads) Late-claim safety: broadcast context kept alive until after the Stasis session ends so concurrent claimants always receive 409 Conflict rather than 404 Not Found Memory safety via RAII_VAR, ast_json_ref/unref, and ao2 reference counting Components Added: res/res_stasis_broadcast.c: Core broadcast + claim logic apps/app_stasis_broadcast.c: StasisBroadcast() dialplan application include/asterisk/stasis_app_broadcast.h: Public API header res/ari/resource_events.c: Integrates POST /ari/events/claim endpoint rest-api/api-docs/events.json: New CallBroadcast and CallClaimed events Implementation Notes: Broadcast contexts reside in an ao2 hash container keyed by channel id. Each context holds atomic claim state, winner application name, timeout metadata, and a condition variable for waiters. Broadcast contexts are kept alive until after stasis_app_exec() returns so that concurrent claimants racing against the timeout always receive 409 Conflict. Broadcast dispatch calls stasis_app_send() directly for each matching application in shuffled order. Regex filters are validated with bounded length, group depth, quantified group count, and alternation limits to reduce pathological backtracking. Timeout calculation uses timespec arithmetic with overflow-safe millisecond remainder handling. Event JSON follows existing Stasis/ARI conventions; references are managed correctly to avoid leaks or double frees. Optional Nature / Impact: No changes to existing APIs, events, or applications when absent. Clean fallback: systems ignoring the modules behave identically to prior versions. Development was assisted by Claude (Anthropic). All generated code has been reviewed, tested, and is understood by the author. UserNote: New optional modules res_stasis_broadcast.so and app_stasis_broadcast.so enable broadcasting an incoming channel to multiple ARI applications. The first application to successfully claim (via POST /ari/events/claim) wins channel control. StasisBroadcast() dialplan application initiates broadcasts. CallBroadcast and CallClaimed events notify applications. When modules are not loaded, behavior is unchanged. DeveloperNote: New public APIs in stasis_app_broadcast.h: stasis_app_broadcast_channel(), stasis_app_claim_channel(), stasis_app_broadcast_winner(), and stasis_app_broadcast_wait(). New ARI event types (CallBroadcast, CallClaimed) added to events.json. All code is isolated; no existing ABI modified.
<!-- Written in -*- Markdown -*- --> This directory contains the specification for the Asterisk RESTful API. The API is documented using Swagger[1]. This is used to not only generate executable documentation pages for the API, but also to generate a lot of the boilerplate necessary for implementing the API with Asterisk's HTTP server. [1]: http://swagger.wordnik.com/