Asterisk - The Open Source Telephony Project GIT-master-6144b6b
Loading...
Searching...
No Matches
Data Structures
stasis_app.h File Reference

Stasis Application API. See Stasis Application API for detailed documentation. More...

#include "asterisk/channel.h"
Include dependency graph for stasis_app.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  stasis_app_control_rule
 Rule to check to see if an operation is allowed. More...
 
struct  stasis_app_event_source
 Event source information and callbacks. More...
 
typedef void(* stasis_app_cb) (void *data, const char *app_name, struct ast_json *message)
 Callback for Stasis application handler.
 
struct ao2_containerstasis_app_get_all (void)
 Gets the names of all registered Stasis applications.
 
struct stasis_appstasis_app_get_by_name (const char *name)
 Retrieve a handle to a Stasis application by its name.
 
int stasis_app_is_registered (const char *name)
 Check if a Stasis application is registered.
 
const char * stasis_app_name (const struct stasis_app *app)
 Retrieve an application's name.
 
struct ast_jsonstasis_app_object_to_json (struct stasis_app *app)
 Return the JSON representation of a Stasis application.
 
int stasis_app_register (const char *app_name, stasis_app_cb handler, void *data)
 Register a new Stasis application.
 
int stasis_app_register_all (const char *app_name, stasis_app_cb handler, void *data)
 Register a new Stasis application that receives all Asterisk events.
 
void stasis_app_register_event_source (struct stasis_app_event_source *obj)
 Register an application event source.
 
void stasis_app_register_event_sources (void)
 Register core event sources.
 
int stasis_app_send (const char *app_name, struct ast_json *message)
 Send a message to the given Stasis application.
 
enum stasis_app_subscribe_res stasis_app_subscribe (const char *app_name, const char **event_source_uris, int event_sources_count, struct ast_json **json)
 Subscribes an application to a list of event sources.
 
enum stasis_app_subscribe_res stasis_app_subscribe_channel (const char *app_name, struct ast_channel *chan)
 Directly subscribe an application to a channel.
 
enum  stasis_app_subscribe_res {
  STASIS_ASR_OK , STASIS_ASR_APP_NOT_FOUND , STASIS_ASR_EVENT_SOURCE_NOT_FOUND , STASIS_ASR_EVENT_SOURCE_BAD_SCHEME ,
  STASIS_ASR_INTERNAL_ERROR
}
 Return code for stasis_app_[un]subscribe. More...
 
struct ast_jsonstasis_app_to_json (const char *app_name)
 Return the JSON representation of a Stasis application.
 
void stasis_app_unregister (const char *app_name)
 Unregister a Stasis application and unsubscribe from all event sources.
 
void stasis_app_unregister_event_source (struct stasis_app_event_source *obj)
 Unregister an application event source.
 
void stasis_app_unregister_event_sources (void)
 Unregister core event sources.
 
enum stasis_app_subscribe_res stasis_app_unsubscribe (const char *app_name, const char **event_source_uris, int event_sources_count, struct ast_json **json)
 Unsubscribes an application from a list of event sources.
 
enum stasis_app_user_event_res stasis_app_user_event (const char *app_name, const char *event_name, const char **source_uris, int sources_count, struct ast_json *json_variables)
 Generate a Userevent for stasis app (echo to AMI)
 
enum  stasis_app_user_event_res {
  STASIS_APP_USER_OK , STASIS_APP_USER_APP_NOT_FOUND , STASIS_APP_USER_EVENT_SOURCE_NOT_FOUND , STASIS_APP_USER_EVENT_SOURCE_BAD_SCHEME ,
  STASIS_APP_USER_USEREVENT_INVALID , STASIS_APP_USER_INTERNAL_ERROR
}
 Return code for stasis_app_user_event. More...
 
struct stasis_topicast_app_get_topic (struct stasis_app *app)
 Returns the stasis topic for an app.
 
struct ast_bridgestasis_app_bridge_create (const char *type, const char *name, const char *id)
 Create a bridge of the specified type.
 
struct ast_bridgestasis_app_bridge_create_invisible (const char *type, const char *name, const char *id)
 Create an invisible bridge of the specified type.
 
void stasis_app_bridge_destroy (const char *bridge_id)
 Destroy the bridge.
 
struct ast_bridgestasis_app_bridge_find_by_id (const char *bridge_id)
 Returns the bridge with the given id.
 
struct ast_channelstasis_app_bridge_moh_channel (struct ast_bridge *bridge)
 Finds or creates an announcer channel in a bridge that can play music on hold.
 
int stasis_app_bridge_moh_stop (struct ast_bridge *bridge)
 Breaks down MOH channels playing on the bridge created by stasis_app_bridge_moh_channel.
 
int stasis_app_bridge_playback_channel_add (struct ast_bridge *bridge, struct ast_channel *chan, struct stasis_app_control *control)
 Adds a channel to the list of ARI playback channels for bridges.
 
void stasis_app_bridge_playback_channel_control_remove (const char *bridge_id, struct stasis_app_control *control)
 Remove a bridge playback channel's control from the app controls list.
 
struct ast_channelstasis_app_bridge_playback_channel_find (struct ast_bridge *bridge)
 Finds an existing ARI playback channel in a bridge.
 
void stasis_app_bridge_playback_channel_remove (char *bridge_id, struct stasis_app_control *control)
 remove channel from list of ARI playback channels for bridges.
 
int stasis_app_bridge_set_var_reportable (const char *bridge_id, const char *variable, const char *value, int report_events)
 Set or clear a variable on a bridge and control ARI event reporting for it.
 
int stasis_app_channel_is_internal (struct ast_channel *chan)
 Is this channel internal to Stasis?
 
int stasis_app_channel_is_stasis_end_published (struct ast_channel *chan)
 Has this channel had a StasisEnd published on it?
 
int stasis_app_channel_set_internal (struct ast_channel *chan)
 Mark this channel as being internal to Stasis.
 
void stasis_app_channel_set_stasis_end_published (struct ast_channel *chan)
 Indicate that this channel has had a StasisEnd published for it.
 
int stasis_app_channel_unreal_set_internal (struct ast_channel *chan)
 Mark this unreal channel and it's other half as being internal to Stasis.
 
void stasis_app_control_absorb_dtmf_in_bridge (struct stasis_app_control *control, int absorb)
 Set whether DTMF from the channel is absorbed instead of passing through to the bridge.
 
int stasis_app_control_add_channel_to_bridge (struct stasis_app_control *control, struct ast_bridge *bridge)
 Add a channel to the bridge.
 
int stasis_app_control_add_role (struct stasis_app_control *control, const char *role)
 Apply a bridge role to a channel controlled by a stasis app control.
 
int stasis_app_control_answer (struct stasis_app_control *control)
 Answer the channel associated with this control.
 
int stasis_app_control_bridge_features_init (struct stasis_app_control *control)
 Initialize bridge features into a channel control.
 
enum  stasis_app_control_channel_result { STASIS_APP_CHANNEL_OKAY = 0 , STASIS_APP_CHANNEL_RECORDING }
 Result codes used when adding/removing channels to/from bridges. More...
 
void stasis_app_control_clear_roles (struct stasis_app_control *control)
 Clear bridge roles currently applied to a channel controlled by a stasis app control.
 
int stasis_app_control_continue (struct stasis_app_control *control, const char *context, const char *extension, int priority)
 Exit res_stasis and continue execution in the dialplan.
 
struct stasis_app_controlstasis_app_control_create (struct ast_channel *chan)
 Creates a control handler for a channel that isn't in a stasis app.
 
int stasis_app_control_dial (struct stasis_app_control *control, const char *dialstring, unsigned int timeout)
 Dial a channel.
 
int stasis_app_control_dtmf (struct stasis_app_control *control, const char *dtmf, int before, int between, unsigned int duration, int after)
 Send DTMF to the channel associated with this control.
 
void stasis_app_control_execute_until_exhausted (struct ast_channel *chan, struct stasis_app_control *control)
 Act on a stasis app control queue until it is empty.
 
struct stasis_app_controlstasis_app_control_find_by_channel (const struct ast_channel *chan)
 Returns the handler for the given channel.
 
struct stasis_app_controlstasis_app_control_find_by_channel_id (const char *channel_id)
 Returns the handler for the channel with the given id.
 
void stasis_app_control_flush_queue (struct stasis_app_control *control)
 Flush the control command queue.
 
const char * stasis_app_control_get_channel_id (const struct stasis_app_control *control)
 Returns the uniqueid of the channel associated with this control.
 
struct ast_channel_snapshotstasis_app_control_get_snapshot (const struct stasis_app_control *control)
 Returns the most recent snapshot for the associated channel.
 
void stasis_app_control_hold (struct stasis_app_control *control)
 Place the channel associated with the control on hold.
 
void stasis_app_control_inhibit_colp_in_bridge (struct stasis_app_control *control, int inhibit_colp)
 Set whether COLP frames should be generated when joining the bridge.
 
int stasis_app_control_is_done (struct stasis_app_control *control)
 Check if a control is marked as done.
 
int stasis_app_control_is_failed (const struct stasis_app_control *control)
 Check if a control object is marked as "failed".
 
void stasis_app_control_mark_failed (struct stasis_app_control *control)
 Set the failed flag on a control structure.
 
void stasis_app_control_moh_start (struct stasis_app_control *control, const char *moh_class)
 Play music on hold to a channel (does not affect hold status)
 
void stasis_app_control_moh_stop (struct stasis_app_control *control)
 Stop playing music on hold to a channel (does not affect hold status)
 
int stasis_app_control_move (struct stasis_app_control *control, const char *app_name, const char *app_args)
 Exit res_stasis and move to another Stasis application.
 
int stasis_app_control_mute (struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype)
 Mute the channel associated with this control.
 
void stasis_app_control_mute_in_bridge (struct stasis_app_control *control, int mute)
 Set whether audio from the channel is muted instead of passing through to the bridge.
 
int stasis_app_control_progress (struct stasis_app_control *control)
 Indicate progress to the channel associated with this control.
 
void stasis_app_control_publish (struct stasis_app_control *control, struct stasis_message *message)
 Publish a message to the control's channel's topic.
 
int stasis_app_control_queue_control (struct stasis_app_control *control, enum ast_control_frame_type frame_type)
 Queue a control frame without payload.
 
int stasis_app_control_redirect (struct stasis_app_control *control, const char *endpoint)
 Redirect a channel in res_stasis to a particular endpoint.
 
void stasis_app_control_register_add_rule (struct stasis_app_control *control, struct stasis_app_control_rule *rule)
 Registers an add channel to bridge rule.
 
void stasis_app_control_register_remove_rule (struct stasis_app_control *control, struct stasis_app_control_rule *rule)
 Registers a remove channel from bridge rule.
 
int stasis_app_control_remove_channel_from_bridge (struct stasis_app_control *control, struct ast_bridge *bridge)
 Remove a channel from the bridge.
 
int stasis_app_control_ring (struct stasis_app_control *control)
 Indicate ringing to the channel associated with this control.
 
int stasis_app_control_ring_stop (struct stasis_app_control *control)
 Stop locally generated ringing on the channel associated with this control.
 
int stasis_app_control_set_channel_var (struct stasis_app_control *control, const char *variable, const char *value)
 Set a variable on the channel associated with this control to value.
 
int stasis_app_control_set_channel_var_reportable (struct stasis_app_control *control, const char *variable, const char *value, int report_events)
 Set a variable on the channel associated with this control to value with option of including in events.
 
void stasis_app_control_shutdown (void)
 Let Stasis app internals shut down.
 
void stasis_app_control_silence_start (struct stasis_app_control *control)
 Start playing silence to a channel.
 
void stasis_app_control_silence_stop (struct stasis_app_control *control)
 Stop playing silence to a channel.
 
void stasis_app_control_unhold (struct stasis_app_control *control)
 Remove the channel associated with the control from hold.
 
int stasis_app_control_unmute (struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype)
 Unmute the channel associated with this control.
 
void stasis_app_control_unregister_add_rule (struct stasis_app_control *control, struct stasis_app_control_rule *rule)
 UnRegister an add channel to bridge rule.
 
void stasis_app_control_unregister_remove_rule (struct stasis_app_control *control, struct stasis_app_control_rule *rule)
 Unregisters a remove channel from bridge rule.
 
int stasis_app_event_allowed (const char *app_name, struct ast_json *event)
 Check if the given event should be filtered.
 
int stasis_app_event_filter_set (struct stasis_app *app, struct ast_json *filter)
 Set the application's event type filter.
 
struct ast_jsonstasis_app_event_filter_to_json (struct stasis_app *app, struct ast_json *json)
 Convert and add the app's event type filter(s) to the given json object.
 
struct ast_bridgestasis_app_get_bridge (struct stasis_app_control *control)
 Gets the bridge currently associated with a control object.
 
int stasis_app_get_debug (struct stasis_app *app)
 Get debug status of an application.
 
int stasis_app_get_debug_by_name (const char *app_name)
 Get debug status of an application.
 
struct stasis_message_sanitizerstasis_app_get_sanitizer (void)
 Get the Stasis message sanitizer for app_stasis applications.
 
void stasis_app_set_debug (struct stasis_app *app, int debug)
 Enable/disable request/response and event logging on an application.
 
void stasis_app_set_debug_by_name (const char *app_name, int debug)
 Enable/disable request/response and event logging on an application.
 
void stasis_app_set_global_debug (int debug)
 Enable/disable request/response and event logging on all applications.
 
void stasis_app_to_cli (const struct stasis_app *app, struct ast_cli_args *a)
 Dump properties of a stasis_app to the CLI.
 

Detailed Description

Stasis Application API. See Stasis Application API for detailed documentation.

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m
Since
12

Definition in file stasis_app.h.

Typedef Documentation

◆ stasis_app_cb

typedef void(* stasis_app_cb) (void *data, const char *app_name, struct ast_json *message)

Callback for Stasis application handler.

The message given to the handler is a borrowed copy. If you want to keep a reference to it, you should use ao2_ref() to keep it around.

Parameters
dataData ptr given when registered.
app_nameName of the application being dispatched to.
messageMessage to handle. (borrowed copy)

Definition at line 67 of file stasis_app.h.

Enumeration Type Documentation

◆ stasis_app_control_channel_result

Result codes used when adding/removing channels to/from bridges.

Enumerator
STASIS_APP_CHANNEL_OKAY 

The channel is okay to be added/removed

STASIS_APP_CHANNEL_RECORDING 

The channel is currently recording

Definition at line 832 of file stasis_app.h.

832 {
833 /*! The channel is okay to be added/removed */
835 /*! The channel is currently recording */
837};
@ STASIS_APP_CHANNEL_RECORDING
Definition stasis_app.h:836
@ STASIS_APP_CHANNEL_OKAY
Definition stasis_app.h:834

◆ stasis_app_subscribe_res

Return code for stasis_app_[un]subscribe.

Enumerator
STASIS_ASR_OK 
STASIS_ASR_APP_NOT_FOUND 
STASIS_ASR_EVENT_SOURCE_NOT_FOUND 
STASIS_ASR_EVENT_SOURCE_BAD_SCHEME 
STASIS_ASR_INTERNAL_ERROR 

Definition at line 292 of file stasis_app.h.

292 {
298};
@ STASIS_ASR_OK
Definition stasis_app.h:293
@ STASIS_ASR_EVENT_SOURCE_BAD_SCHEME
Definition stasis_app.h:296
@ STASIS_ASR_INTERNAL_ERROR
Definition stasis_app.h:297
@ STASIS_ASR_EVENT_SOURCE_NOT_FOUND
Definition stasis_app.h:295
@ STASIS_ASR_APP_NOT_FOUND
Definition stasis_app.h:294

◆ stasis_app_user_event_res

Return code for stasis_app_user_event.

Enumerator
STASIS_APP_USER_OK 
STASIS_APP_USER_APP_NOT_FOUND 
STASIS_APP_USER_EVENT_SOURCE_NOT_FOUND 
STASIS_APP_USER_EVENT_SOURCE_BAD_SCHEME 
STASIS_APP_USER_USEREVENT_INVALID 
STASIS_APP_USER_INTERNAL_ERROR 

Definition at line 265 of file stasis_app.h.

265 {
272};
@ STASIS_APP_USER_APP_NOT_FOUND
Definition stasis_app.h:267
@ STASIS_APP_USER_EVENT_SOURCE_NOT_FOUND
Definition stasis_app.h:268
@ STASIS_APP_USER_EVENT_SOURCE_BAD_SCHEME
Definition stasis_app.h:269
@ STASIS_APP_USER_USEREVENT_INVALID
Definition stasis_app.h:270
@ STASIS_APP_USER_OK
Definition stasis_app.h:266
@ STASIS_APP_USER_INTERNAL_ERROR
Definition stasis_app.h:271

Function Documentation

◆ ast_app_get_topic()

struct stasis_topic * ast_app_get_topic ( struct stasis_app app)

Returns the stasis topic for an app.

Parameters
appStasis app to get topic of

Definition at line 1045 of file res/stasis/app.c.

1046{
1047 return app->topic;
1048}
static const char app[]

References app.

Referenced by app_send_end_msg(), send_start_msg_snapshots(), and stasis_app_user_event().

◆ stasis_app_bridge_create()

struct ast_bridge * stasis_app_bridge_create ( const char *  type,
const char *  name,
const char *  id 
)

Create a bridge of the specified type.

Parameters
typeThe type of bridge to be created
nameOptional name to give to the bridge
idOptional Unique ID to give to the bridge
Returns
New bridge.
Return values
NULLon error.

Definition at line 898 of file res_stasis.c.

899{
900 return bridge_create_common(type, name, id, 0);
901}
static const char type[]
static const char name[]
Definition format_mp3.c:68
static struct ast_bridge * bridge_create_common(const char *type, const char *name, const char *id, int invisible)
Definition res_stasis.c:828

References bridge_create_common(), name, and type.

Referenced by ast_ari_bridges_create(), and ast_ari_bridges_create_with_id().

◆ stasis_app_bridge_create_invisible()

struct ast_bridge * stasis_app_bridge_create_invisible ( const char *  type,
const char *  name,
const char *  id 
)

Create an invisible bridge of the specified type.

Parameters
typeThe type of bridge to be created
nameOptional name to give to the bridge
idOptional Unique ID to give to the bridge
Returns
New bridge.
Return values
NULLon error.

Definition at line 903 of file res_stasis.c.

904{
905 return bridge_create_common(type, name, id, 1);
906}

References bridge_create_common(), name, and type.

Referenced by get_dial_bridge().

◆ stasis_app_bridge_destroy()

void stasis_app_bridge_destroy ( const char *  bridge_id)

Destroy the bridge.

Parameters
bridge_idUniqueid of bridge to be destroyed

Definition at line 908 of file res_stasis.c.

909{
910 struct ast_bridge *bridge = stasis_app_bridge_find_by_id(bridge_id);
911 if (!bridge) {
912 return;
913 }
914 ast_debug(1, "Bridge " BRIDGE_PRINTF_SPEC ": destroying bridge\n",
915 BRIDGE_PRINTF_VARS(bridge));
916
917 ao2_unlink(app_bridges, bridge);
918 ast_debug(1, "Bridge " BRIDGE_PRINTF_SPEC ": unlinked from app_bridges. current refcount: %d\n",
919 BRIDGE_PRINTF_VARS(bridge), ao2_ref(bridge, 0));
920 ast_bridge_destroy(bridge, 0);
921}
#define ao2_unlink(container, obj)
Remove an object from a container.
Definition astobj2.h:1578
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
int ast_bridge_destroy(struct ast_bridge *bridge, int cause)
Destroy a bridge.
Definition bridge.c:1029
#define BRIDGE_PRINTF_VARS(bridge)
Definition bridge.h:80
#define BRIDGE_PRINTF_SPEC
Definition bridge.h:79
#define ast_debug(level,...)
Log a DEBUG message.
struct ast_bridge * stasis_app_bridge_find_by_id(const char *bridge_id)
Returns the bridge with the given id.
Definition res_stasis.c:807
struct ao2_container * app_bridges
Definition res_stasis.c:104
Structure that contains information about a bridge.
Definition bridge.h:355

References ao2_ref, ao2_unlink, app_bridges, ast_bridge_destroy(), ast_debug, BRIDGE_PRINTF_SPEC, BRIDGE_PRINTF_VARS, and stasis_app_bridge_find_by_id().

Referenced by ast_ari_bridges_destroy().

◆ stasis_app_bridge_find_by_id()

struct ast_bridge * stasis_app_bridge_find_by_id ( const char *  bridge_id)

Returns the bridge with the given id.

Parameters
bridge_idUniqueid of the bridge.
Returns
NULL bridge not created by a Stasis application, or bridge does not exist.
Pointer to bridge.

Definition at line 807 of file res_stasis.c.

809{
810 return ao2_find(app_bridges, bridge_id, OBJ_SEARCH_KEY);
811}
#define ao2_find(container, arg, flags)
Definition astobj2.h:1736
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition astobj2.h:1101

References ao2_find, app_bridges, and OBJ_SEARCH_KEY.

Referenced by ast_ari_bridges_get_bridge_vars(), ast_ari_bridges_set_bridge_vars(), bridge_create_common(), bridge_find(), find_bridge(), stasis_app_bridge_destroy(), and stasis_app_bridge_set_var_reportable().

◆ stasis_app_bridge_moh_channel()

struct ast_channel * stasis_app_bridge_moh_channel ( struct ast_bridge bridge)

Finds or creates an announcer channel in a bridge that can play music on hold.

Parameters
bridgeBridge we want an MOH channel for
Returns
NULL if the music on hold channel fails to be created or join the bridge for any reason.
Pointer to the ;1 end of the announcer channel chain.

Definition at line 655 of file res_stasis.c.

656{
657 struct ast_channel *chan;
658 struct stasis_app_bridge_channel_wrapper *moh_wrapper;
659
661 moh_wrapper = ao2_find(app_bridges_moh, bridge->uniqueid, OBJ_SEARCH_KEY | OBJ_NOLOCK);
662 if (!moh_wrapper) {
663 chan = bridge_moh_create(bridge);
664 }
666
667 if (moh_wrapper) {
668 chan = ast_channel_get_by_name(moh_wrapper->channel_id);
669 ao2_ref(moh_wrapper, -1);
670 }
671
672 return chan;
673}
#define ao2_unlock(a)
Definition astobj2.h:729
#define ao2_lock(a)
Definition astobj2.h:717
@ OBJ_NOLOCK
Assume that the ao2_container is already locked.
Definition astobj2.h:1063
struct ast_channel * ast_channel_get_by_name(const char *search)
Find a channel by name or uniqueid.
Definition channel.c:1417
static struct ast_channel * bridge_moh_create(struct ast_bridge *bridge)
Definition res_stasis.c:600
struct ao2_container * app_bridges_moh
Definition res_stasis.c:106
const ast_string_field uniqueid
Definition bridge.h:407
Main Channel structure associated with a channel.
const ast_string_field channel_id
Definition res_stasis.c:451

References ao2_find, ao2_lock, ao2_ref, ao2_unlock, app_bridges_moh, ast_channel_get_by_name(), bridge_moh_create(), stasis_app_bridge_channel_wrapper::channel_id, OBJ_NOLOCK, OBJ_SEARCH_KEY, and ast_bridge::uniqueid.

Referenced by ast_ari_bridges_start_moh().

◆ stasis_app_bridge_moh_stop()

int stasis_app_bridge_moh_stop ( struct ast_bridge bridge)

Breaks down MOH channels playing on the bridge created by stasis_app_bridge_moh_channel.

Parameters
bridgeBridge we want to stop the MOH on
Returns
-1 if no moh channel could be found and stopped
0 on success

Definition at line 675 of file res_stasis.c.

676{
677 struct stasis_app_bridge_channel_wrapper *moh_wrapper;
678 struct ast_channel *chan;
679
681 if (!moh_wrapper) {
682 return -1;
683 }
684
685 chan = ast_channel_get_by_name(moh_wrapper->channel_id);
686 ao2_ref(moh_wrapper, -1);
687 if (!chan) {
688 return -1;
689 }
690
691 ast_moh_stop(chan);
693 ao2_cleanup(chan);
694
695 return 0;
696}
#define ao2_cleanup(obj)
Definition astobj2.h:1934
@ OBJ_UNLINK
Definition astobj2.h:1039
#define AST_CAUSE_NORMAL_CLEARING
Definition causes.h:106
int ast_softhangup(struct ast_channel *chan, int cause)
Softly hangup up a channel.
Definition channel.c:2462
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition channel.c:7812
struct ast_bridge * bridge

References ao2_cleanup, ao2_find, ao2_ref, app_bridges_moh, AST_CAUSE_NORMAL_CLEARING, ast_channel_get_by_name(), ast_moh_stop(), ast_softhangup(), ast_channel::bridge, stasis_app_bridge_channel_wrapper::channel_id, OBJ_SEARCH_KEY, OBJ_UNLINK, and ast_bridge::uniqueid.

Referenced by ast_ari_bridges_stop_moh().

◆ stasis_app_bridge_playback_channel_add()

int stasis_app_bridge_playback_channel_add ( struct ast_bridge bridge,
struct ast_channel chan,
struct stasis_app_control control 
)

Adds a channel to the list of ARI playback channels for bridges.

Parameters
bridgeBridge we are adding the playback channel for
chanChannel being added as a playback channel (must be ;1)
controlThe app control structure for the playback channel
Return values
-1failed to add channel for any reason
0on success

Definition at line 738 of file res_stasis.c.

741{
743 char *bridge_id = ast_strdup(bridge->uniqueid);
744
745 if (!bridge_id) {
746 return -1;
747 }
748
751 ast_free(bridge_id);
752 return -1;
753 }
754
755 new_wrapper = ao2_alloc_options(sizeof(*new_wrapper),
757 if (!new_wrapper) {
758 return -1;
759 }
760
761 if (ast_string_field_init(new_wrapper, 32)) {
762 return -1;
763 }
764
765 ast_string_field_set(new_wrapper, bridge_id, bridge->uniqueid);
766 ast_string_field_set(new_wrapper, channel_id, ast_channel_uniqueid(chan));
767
768 if (!ao2_link(app_bridges_playback, new_wrapper)) {
769 return -1;
770 }
771
772 ao2_link(app_controls, control);
773 return 0;
774}
#define ast_free(a)
Definition astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ao2_link(container, obj)
Add an object to a container.
Definition astobj2.h:1532
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition astobj2.h:367
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition astobj2.h:404
int ast_bridge_set_after_callback(struct ast_channel *chan, ast_bridge_after_cb callback, ast_bridge_after_cb_failed failed, void *data)
Setup an after bridge callback for when the channel leaves the bridging system.
const char * ast_channel_uniqueid(const struct ast_channel *chan)
static void stasis_app_bridge_channel_wrapper_destructor(void *obj)
Definition res_stasis.c:481
struct ao2_container * app_bridges_playback
Definition res_stasis.c:108
static void playback_after_bridge_cb(struct ast_channel *chan, void *data)
Definition res_stasis.c:731
struct ao2_container * app_controls
Definition res_stasis.c:102
static void playback_after_bridge_cb_failed(enum ast_bridge_after_cb_reason reason, void *data)
Definition res_stasis.c:724
#define NULL
Definition resample.c:96
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#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:981

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_cleanup, ao2_link, app_bridges_playback, app_controls, ast_bridge_set_after_callback(), ast_channel_uniqueid(), ast_free, ast_strdup, ast_string_field_init, ast_string_field_set, stasis_app_control::bridge, NULL, playback_after_bridge_cb(), playback_after_bridge_cb_failed(), RAII_VAR, stasis_app_bridge_channel_wrapper_destructor(), and ast_bridge::uniqueid.

Referenced by ari_bridges_play_new().

◆ stasis_app_bridge_playback_channel_control_remove()

void stasis_app_bridge_playback_channel_control_remove ( const char *  bridge_id,
struct stasis_app_control control 
)

Remove a bridge playback channel's control from the app controls list.

Parameters
bridge_idThe unique ID of the bridge the playback channel is in.
controlThe app control structure for the playback channel

Definition at line 717 of file res_stasis.c.

719{
720 ast_assert(!ast_strlen_zero(bridge_id));
721 ao2_unlink(app_controls, control);
722}
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 ao2_unlink, app_controls, ast_assert, and ast_strlen_zero().

Referenced by bridge_channel_control_thread(), and stasis_app_bridge_playback_channel_remove().

◆ stasis_app_bridge_playback_channel_find()

struct ast_channel * stasis_app_bridge_playback_channel_find ( struct ast_bridge bridge)

Finds an existing ARI playback channel in a bridge.

Parameters
bridgeBridge we want to find the playback channel for
Returns
NULL if the playback channel can not be found for any reason.
Pointer to the ;1 end of the playback channel chain.

Definition at line 792 of file res_stasis.c.

793{
794 struct stasis_app_bridge_channel_wrapper *playback_wrapper;
795 struct ast_channel *chan;
796
798 if (!playback_wrapper) {
799 return NULL;
800 }
801
802 chan = ast_channel_get_by_name(playback_wrapper->channel_id);
803 ao2_ref(playback_wrapper, -1);
804 return chan;
805}

References ao2_find, ao2_ref, app_bridges_playback, ast_channel_get_by_name(), ast_channel::bridge, stasis_app_bridge_channel_wrapper::channel_id, NULL, OBJ_SEARCH_KEY, and ast_bridge::uniqueid.

Referenced by ari_bridges_handle_play().

◆ stasis_app_bridge_playback_channel_remove()

void stasis_app_bridge_playback_channel_remove ( char *  bridge_id,
struct stasis_app_control control 
)

remove channel from list of ARI playback channels for bridges.

Parameters
bridge_idThe unique ID of the bridge the playback channel is in.
controlThe app control structure for the playback channel

Definition at line 776 of file res_stasis.c.

778{
779 struct stasis_app_bridge_channel_wrapper *wrapper;
780
782 if (wrapper) {
783 /* If wrapper is not found, then that means the after bridge callback has been
784 * called or is in progress. No need to unlink the control here since that has
785 * been done or is about to be done in the after bridge callback
786 */
788 ao2_ref(wrapper, -1);
789 }
790}
void stasis_app_bridge_playback_channel_control_remove(const char *bridge_id, struct stasis_app_control *control)
Remove a bridge playback channel's control from the app controls list.
Definition res_stasis.c:717
const ast_string_field bridge_id
Definition res_stasis.c:451

References ao2_find, ao2_ref, app_bridges_playback, stasis_app_bridge_channel_wrapper::bridge_id, OBJ_SEARCH_KEY, OBJ_UNLINK, and stasis_app_bridge_playback_channel_control_remove().

Referenced by ari_bridges_play_new().

◆ stasis_app_bridge_set_var_reportable()

int stasis_app_bridge_set_var_reportable ( const char *  bridge_id,
const char *  variable,
const char *  value,
int  report_events 
)

Set or clear a variable on a bridge and control ARI event reporting for it.

Parameters
bridge_idUniqueid of bridge
variableVariable name
valueVariable value (NULL/empty clears)
report_eventsNon-zero to include in ARI bridge events
Return values
0on success
-1on failure

Definition at line 923 of file res_stasis.c.

925{
926 RAII_VAR(struct ast_bridge *, bridge, stasis_app_bridge_find_by_id(bridge_id), ao2_cleanup);
927
928 if (!bridge) {
929 return -1;
930 }
931
932 ast_bridge_lock(bridge);
933 if (ast_bridge_set_variable(bridge, variable, value, report_events)) {
934 ast_bridge_unlock(bridge);
935 return -1;
936 }
938 ast_bridge_unlock(bridge);
939
940 return 0;
941}
#define ast_bridge_unlock(bridge)
Unlock the bridge.
Definition bridge.h:491
#define ast_bridge_lock(bridge)
Lock the bridge.
Definition bridge.h:480
int ast_bridge_set_variable(struct ast_bridge *bridge, const char *name, const char *value, int report_events)
Set a variable on the bridge.
Definition bridge.c:1341
void ast_bridge_publish_state(struct ast_bridge *bridge)
Publish the state of a bridge.
int value
Definition syslog.c:37

References ao2_cleanup, ast_bridge_lock, ast_bridge_publish_state(), ast_bridge_set_variable(), ast_bridge_unlock, RAII_VAR, stasis_app_bridge_find_by_id(), and value.

Referenced by ast_ari_bridges_set_bridge_var(), and ast_ari_bridges_set_bridge_vars().

◆ stasis_app_channel_is_internal()

int stasis_app_channel_is_internal ( struct ast_channel chan)

Is this channel internal to Stasis?

Parameters
chanThe channel to check.
Return values
0No
1Yes

Definition at line 2428 of file res_stasis.c.

2429{
2430 struct ast_datastore *datastore;
2431 int res = 0;
2432
2433 ast_channel_lock(chan);
2435 if (datastore) {
2436 res = 1;
2437 }
2438 ast_channel_unlock(chan);
2439
2440 return res;
2441}
#define ast_channel_lock(chan)
Definition channel.h:2983
#define ast_channel_unlock(chan)
Definition channel.h:2984
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition channel.c:2390
static const struct ast_datastore_info stasis_internal_channel_info
Structure for a data store object.
Definition datastore.h:64

References ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, NULL, and stasis_internal_channel_info.

Referenced by bridge_stasis_push().

◆ stasis_app_channel_is_stasis_end_published()

int stasis_app_channel_is_stasis_end_published ( struct ast_channel chan)

Has this channel had a StasisEnd published on it?

Parameters
chanThe channel upon which the query rests.
Return values
0No
1Yes

Definition at line 1371 of file res_stasis.c.

1372{
1373 struct ast_datastore *datastore;
1374
1375 ast_channel_lock(chan);
1377 ast_channel_unlock(chan);
1378
1379 return datastore ? 1 : 0;
1380}
struct ast_datastore_info set_end_published_info

References ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, NULL, and set_end_published_info.

Referenced by internal_bridge_after_cb(), and stasis_app_exec().

◆ stasis_app_channel_set_internal()

int stasis_app_channel_set_internal ( struct ast_channel chan)

Mark this channel as being internal to Stasis.

Parameters
chanThe channel to mark.
Return values
zeroSuccess
non-zeroFailure

Definition at line 2417 of file res_stasis.c.

2418{
2419 int res;
2420
2421 ast_channel_lock(chan);
2422 res = set_internal_datastore(chan);
2423 ast_channel_unlock(chan);
2424
2425 return res;
2426}
static int set_internal_datastore(struct ast_channel *chan)

References ast_channel_lock, ast_channel_unlock, ast_unreal_pvt::chan, and set_internal_datastore().

◆ stasis_app_channel_set_stasis_end_published()

void stasis_app_channel_set_stasis_end_published ( struct ast_channel chan)

Indicate that this channel has had a StasisEnd published for it.

Parameters
chanThe channel that is exiting Stasis.

Definition at line 1359 of file res_stasis.c.

1360{
1361 struct ast_datastore *datastore;
1362
1364 if (datastore) {
1365 ast_channel_lock(chan);
1366 ast_channel_datastore_add(chan, datastore);
1367 ast_channel_unlock(chan);
1368 }
1369}
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition channel.c:2376
#define ast_datastore_alloc(info, uid)
Definition datastore.h:85

References ast_channel_datastore_add(), ast_channel_lock, ast_channel_unlock, ast_datastore_alloc, NULL, and set_end_published_info.

Referenced by bridge_stasis_moving(), and channel_stolen_cb().

◆ stasis_app_channel_unreal_set_internal()

int stasis_app_channel_unreal_set_internal ( struct ast_channel chan)

Mark this unreal channel and it's other half as being internal to Stasis.

Parameters
chanThe channel to mark.
Return values
zeroSuccess
non-zeroFailure

Definition at line 2394 of file res_stasis.c.

2395{
2396 struct ast_channel *outchan = NULL, *outowner = NULL;
2397 int res = 0;
2398 struct ast_unreal_pvt *unreal_pvt = ast_channel_tech_pvt(chan);
2399
2400 ao2_ref(unreal_pvt, +1);
2401 ast_unreal_lock_all(unreal_pvt, &outowner, &outchan);
2402 if (outowner) {
2403 res |= set_internal_datastore(outowner);
2404 ast_channel_unlock(outowner);
2405 ast_channel_unref(outowner);
2406 }
2407 if (outchan) {
2408 res |= set_internal_datastore(outchan);
2409 ast_channel_unlock(outchan);
2410 ast_channel_unref(outchan);
2411 }
2412 ao2_unlock(unreal_pvt);
2413 ao2_ref(unreal_pvt, -1);
2414 return res;
2415}
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define ast_channel_unref(c)
Decrease channel reference count.
Definition channel.h:3019
void ast_unreal_lock_all(struct ast_unreal_pvt *p, struct ast_channel **outchan, struct ast_channel **outowner)
Send an unreal pvt in with no locks held and get all locks.
Definition core_unreal.c:47
The base pvt structure for local channel derivatives.
Definition core_unreal.h:91
struct ast_channel * chan
Definition core_unreal.h:94

References ao2_ref, ao2_unlock, ast_channel_tech_pvt(), ast_channel_unlock, ast_channel_unref, ast_unreal_lock_all(), ast_unreal_pvt::chan, NULL, and set_internal_datastore().

Referenced by bridge_moh_create(), and prepare_bridge_media_channel().

◆ stasis_app_control_absorb_dtmf_in_bridge()

void stasis_app_control_absorb_dtmf_in_bridge ( struct stasis_app_control control,
int  absorb 
)

Set whether DTMF from the channel is absorbed instead of passing through to the bridge.

Parameters
controlControl whose channel should have its DTMF absorbed when bridged
absorbWhether DTMF should be absorbed (1) instead of passed through (0).

Definition at line 1527 of file control.c.

1529{
1530 control->bridge_features->dtmf_passthrough = !absorb;
1531}
unsigned int dtmf_passthrough
struct ast_bridge_features * bridge_features
Definition control.c:71

References stasis_app_control::bridge_features, and ast_bridge_features::dtmf_passthrough.

Referenced by ast_ari_bridges_add_channel().

◆ stasis_app_control_add_channel_to_bridge()

int stasis_app_control_add_channel_to_bridge ( struct stasis_app_control control,
struct ast_bridge bridge 
)

Add a channel to the bridge.

Parameters
controlControl whose channel should be added to the bridge
bridgePointer to the bridge
Returns
non-zero on failure
zero on success

Definition at line 1446 of file control.c.

1448{
1449 ast_debug(3, "%s: Sending channel add_to_bridge command\n",
1451
1453 control, control_add_channel_to_bridge, bridge, NULL,
1455}
const char * stasis_app_control_get_channel_id(const struct stasis_app_control *control)
Returns the uniqueid of the channel associated with this control.
Definition control.c:1493
int control_add_channel_to_bridge(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Command callback for adding a channel to a bridge.
Definition control.c:1441
static int app_send_command_on_condition(struct stasis_app_control *control, stasis_app_command_cb command_fn, void *data, command_data_destructor_fn data_destructor, app_command_can_exec_cb can_exec_fn)
Definition control.c:918
static int app_control_can_add_channel_to_bridge(struct stasis_app_control *control)
Definition control.c:253

References app_control_can_add_channel_to_bridge(), app_send_command_on_condition(), ast_debug, control_add_channel_to_bridge(), NULL, and stasis_app_control_get_channel_id().

Referenced by ast_ari_bridges_add_channel().

◆ stasis_app_control_add_role()

int stasis_app_control_add_role ( struct stasis_app_control control,
const char *  role 
)

Apply a bridge role to a channel controlled by a stasis app control.

Parameters
controlControl for res_stasis
roleRole to apply
Returns
0 for success
-1 for error.

Definition at line 331 of file control.c.

332{
333 char *role_dup;
334
335 role_dup = ast_strdup(role);
336 if (!role_dup) {
337 return -1;
338 }
339
341
342 return 0;
343}
void ast_free_ptr(void *ptr)
free() wrapper
Definition astmm.c:1739
static int app_control_add_role(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:323
int stasis_app_send_command_async(struct stasis_app_control *control, stasis_app_command_cb command_fn, void *data, command_data_destructor_fn data_destructor)
Asynchronous version of stasis_app_send_command().
Definition control.c:956

References app_control_add_role(), ast_free_ptr(), ast_strdup, and stasis_app_send_command_async().

Referenced by ast_ari_bridges_add_channel().

◆ stasis_app_control_answer()

int stasis_app_control_answer ( struct stasis_app_control control)

Answer the channel associated with this control.

Parameters
controlControl for res_stasis.
Returns
0 for success.
Non-zero for error.

Definition at line 44 of file res_stasis_answer.c.

45{
46 int retval;
47
48 ast_debug(3, "%s: Sending answer command\n",
50
52
53 if (retval != 0) {
54 ast_log(LOG_WARNING, "%s: Failed to answer channel\n",
56 return -1;
57 }
58
59 return 0;
60}
#define ast_log
Definition astobj2.c:42
#define LOG_WARNING
static int app_control_answer(struct stasis_app_control *control, struct ast_channel *chan, void *data)
const char * stasis_app_control_get_channel_id(const struct stasis_app_control *control)
Returns the uniqueid of the channel associated with this control.
Definition control.c:1493
int stasis_app_send_command(struct stasis_app_control *control, stasis_app_command_cb command, void *data, command_data_destructor_fn data_destructor)
Invokes a command on a control's channel.
Definition control.c:950

References app_control_answer(), ast_debug, ast_log, LOG_WARNING, NULL, stasis_app_control_get_channel_id(), and stasis_app_send_command().

Referenced by ast_ari_channels_answer().

◆ stasis_app_control_bridge_features_init()

int stasis_app_control_bridge_features_init ( struct stasis_app_control control)

Initialize bridge features into a channel control.

Note
Bridge features on a control are destroyed after each bridge session, so new features need to be initialized before each bridge add.
Parameters
controlControl in which to store the features
Returns
non-zero on failure
zero on success

Definition at line 1514 of file control.c.

1516{
1517 struct ast_bridge_features *features;
1518
1519 features = ast_bridge_features_new();
1520 if (!features) {
1521 return 1;
1522 }
1523 control->bridge_features = features;
1524 return 0;
1525}
struct ast_bridge_features * ast_bridge_features_new(void)
Allocate a new bridge features struct.
Definition bridge.c:3892
Structure that contains features information.

References ast_bridge_features_new(), and stasis_app_control::bridge_features.

Referenced by ast_ari_bridges_add_channel().

◆ stasis_app_control_clear_roles()

void stasis_app_control_clear_roles ( struct stasis_app_control control)

Clear bridge roles currently applied to a channel controlled by a stasis app control.

Parameters
controlControl for res_stasis

Definition at line 353 of file control.c.

354{
356}
static int app_control_clear_roles(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:345

References app_control_clear_roles(), NULL, and stasis_app_send_command_async().

Referenced by ast_ari_bridges_add_channel().

◆ stasis_app_control_continue()

int stasis_app_control_continue ( struct stasis_app_control control,
const char *  context,
const char *  extension,
int  priority 
)

Exit res_stasis and continue execution in the dialplan.

If the channel is no longer in res_stasis, this function does nothing.

Parameters
controlControl for res_stasis
contextAn optional context to continue to
extensionAn optional extension to continue to
priorityAn optional priority to continue to
Returns
0 for success
-1 for error.

Definition at line 415 of file control.c.

416{
417 struct stasis_app_control_continue_data *continue_data;
418
419 if (!(continue_data = ast_calloc(1, sizeof(*continue_data)))) {
420 return -1;
421 }
422 ast_copy_string(continue_data->context, S_OR(context, ""), sizeof(continue_data->context));
423 ast_copy_string(continue_data->extension, S_OR(extension, ""), sizeof(continue_data->extension));
424 if (priority > 0) {
425 continue_data->priority = priority;
426 } else {
427 continue_data->priority = -1;
428 }
429
431
432 return 0;
433}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
static int priority
static int app_control_continue(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:394
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition strings.h:80
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425
structure to hold extensions
char extension[AST_MAX_EXTENSION]
Definition control.c:390
char context[AST_MAX_CONTEXT]
Definition control.c:389

References app_control_continue(), ast_calloc, ast_copy_string(), ast_free_ptr(), stasis_app_control_continue_data::context, stasis_app_control_continue_data::extension, priority, stasis_app_control_continue_data::priority, S_OR, and stasis_app_send_command_async().

Referenced by ast_ari_channels_continue_in_dialplan(), and outbound_session_handler_thread().

◆ stasis_app_control_create()

struct stasis_app_control * stasis_app_control_create ( struct ast_channel chan)

Creates a control handler for a channel that isn't in a stasis app.

Since
12.0.0
Parameters
chanChannel to create controller handle for
Returns
NULL on failure to create the handle
Pointer to res_stasis handler.

Definition at line 333 of file res_stasis.c.

334{
335 return control_create(chan, NULL);
336}
struct stasis_app_control * control_create(struct ast_channel *channel, struct stasis_app *app)
Create a control object.
Definition control.c:131

References control_create(), and NULL.

Referenced by ari_bridges_play_new(), and ast_ari_bridges_record().

◆ stasis_app_control_dial()

int stasis_app_control_dial ( struct stasis_app_control control,
const char *  dialstring,
unsigned int  timeout 
)

Dial a channel.

Parameters
controlControl for res_stasis.
dialstringThe dialstring to pass to the channel driver
timeoutOptional timeout in milliseconds

Definition at line 1729 of file control.c.

1731{
1732 struct control_dial_args *args;
1733
1735 if (!args) {
1736 return -1;
1737 }
1738
1741}
static struct control_dial_args * control_dial_args_alloc(const char *dialstring, unsigned int timeout)
Definition control.c:1636
static void control_dial_args_destroy(void *data)
Definition control.c:1653
static int app_control_dial(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:1691
static struct @522 args
char dialstring[0]
Definition control.c:1633
unsigned int timeout
Definition control.c:1632

References app_control_dial(), args, control_dial_args_alloc(), control_dial_args_destroy(), control_dial_args::dialstring, stasis_app_send_command_async(), and control_dial_args::timeout.

Referenced by ast_ari_channels_dial().

◆ stasis_app_control_dtmf()

int stasis_app_control_dtmf ( struct stasis_app_control control,
const char *  dtmf,
int  before,
int  between,
unsigned int  duration,
int  after 
)

Send DTMF to the channel associated with this control.

Parameters
controlControl for res_stasis.
dtmfDTMF string.
beforeAmount of time to wait before sending DTMF digits.
betweenAmount of time between each DTMF digit.
durationAmount of time each DTMF digit lasts for.
afterAmount of time to wait after sending DTMF digits.
Returns
0 for success.
-1 for error.

Definition at line 591 of file control.c.

592{
593 struct stasis_app_control_dtmf_data *dtmf_data;
594
595 if (!(dtmf_data = ast_calloc(1, sizeof(*dtmf_data) + strlen(dtmf) + 1))) {
596 return -1;
597 }
598
599 dtmf_data->before = before;
600 dtmf_data->between = between;
601 dtmf_data->duration = duration;
602 dtmf_data->after = after;
603 strcpy(dtmf_data->dtmf, dtmf);
604
606
607 return 0;
608}
static int app_control_dtmf(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:573

References stasis_app_control_dtmf_data::after, app_control_dtmf(), ast_calloc, ast_free_ptr(), stasis_app_control_dtmf_data::before, stasis_app_control_dtmf_data::between, stasis_app_control_dtmf_data::dtmf, stasis_app_control_dtmf_data::duration, and stasis_app_send_command_async().

Referenced by ast_ari_channels_send_dtmf().

◆ stasis_app_control_execute_until_exhausted()

void stasis_app_control_execute_until_exhausted ( struct ast_channel chan,
struct stasis_app_control control 
)

Act on a stasis app control queue until it is empty.

Since
12.0.0
Parameters
chanChannel to handle
controlControl object to execute

Definition at line 1322 of file res_stasis.c.

1323{
1324 while (!control_is_done(control)) {
1325 int command_count;
1326 command_count = control_dispatch_all(control, chan);
1327
1328 ao2_lock(control);
1329
1330 if (control_command_count(control)) {
1331 /* If the command queue isn't empty, something added to the queue before it was locked. */
1332 ao2_unlock(control);
1333 continue;
1334 }
1335
1336 if (command_count == 0 || ast_channel_fdno(chan) == -1) {
1337 control_mark_done(control);
1338 ao2_unlock(control);
1339 break;
1340 }
1341 ao2_unlock(control);
1342 }
1343}
int ast_channel_fdno(const struct ast_channel *chan)
int control_is_done(struct stasis_app_control *control)
Returns true if control_continue() has been called on this control.
Definition control.c:363
int control_dispatch_all(struct stasis_app_control *control, struct ast_channel *chan)
Dispatch all commands enqueued to this control.
Definition control.c:1558
int control_command_count(struct stasis_app_control *control)
Returns the count of items in a control's command queue.
Definition control.c:358
void control_mark_done(struct stasis_app_control *control)
Definition control.c:369

References ao2_lock, ao2_unlock, ast_channel_fdno(), control_command_count(), control_dispatch_all(), control_is_done(), and control_mark_done().

Referenced by bridge_channel_control_thread().

◆ stasis_app_control_find_by_channel()

struct stasis_app_control * stasis_app_control_find_by_channel ( const struct ast_channel chan)

Returns the handler for the given channel.

Parameters
chanChannel to handle.
Returns
NULL channel not in Stasis application.
Pointer to res_stasis handler.

Definition at line 338 of file res_stasis.c.

340{
341 if (chan == NULL) {
342 return NULL;
343 }
344
347}
struct stasis_app_control * stasis_app_control_find_by_channel_id(const char *channel_id)
Returns the handler for the channel with the given id.
Definition res_stasis.c:349

References ast_channel_uniqueid(), NULL, and stasis_app_control_find_by_channel_id().

Referenced by ari_bridges_play_found(), bridge_stasis_moving(), bridge_stasis_push(), bridge_stasis_push_peek(), and bridge_timeout().

◆ stasis_app_control_find_by_channel_id()

struct stasis_app_control * stasis_app_control_find_by_channel_id ( const char *  channel_id)

Returns the handler for the channel with the given id.

Parameters
channel_idUniqueid of the channel.
Returns
NULL channel not in Stasis application, or channel does not exist.
Pointer to res_stasis handler.

Definition at line 349 of file res_stasis.c.

351{
352 return ao2_find(app_controls, channel_id, OBJ_SEARCH_KEY);
353}

References ao2_find, app_controls, and OBJ_SEARCH_KEY.

Referenced by find_channel_control(), find_control(), outbound_session_handler_thread(), remove_bridge_playback(), and stasis_app_control_find_by_channel().

◆ stasis_app_control_flush_queue()

void stasis_app_control_flush_queue ( struct stasis_app_control control)

Flush the control command queue.

Since
13.9.0
Parameters
controlControl object to flush command queue.

Definition at line 1350 of file res_stasis.c.

1351{
1352 control_flush_queue(control);
1353}
void control_flush_queue(struct stasis_app_control *control)
Flush the control command queue.
Definition control.c:1545

References control_flush_queue().

Referenced by bridge_channel_control_thread().

◆ stasis_app_control_get_channel_id()

const char * stasis_app_control_get_channel_id ( const struct stasis_app_control control)

◆ stasis_app_control_get_snapshot()

struct ast_channel_snapshot * stasis_app_control_get_snapshot ( const struct stasis_app_control control)

Returns the most recent snapshot for the associated channel.

The returned pointer is AO2 managed, so ao2_cleanup() when you're done.

Parameters
controlControl for res_stasis.
Returns
Most recent snapshot. ao2_cleanup() when done.
Return values
NULLif channel isn't in cache.

Definition at line 912 of file control.c.

914{
916}
struct ast_channel_snapshot * ast_channel_snapshot_get_latest(const char *uniqueid)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object,...

References ast_channel_snapshot_get_latest(), and stasis_app_control_get_channel_id().

Referenced by ari_bridges_play_helper(), ari_channels_handle_play(), ast_ari_channels_continue_in_dialplan(), and channel_state_invalid().

◆ stasis_app_control_hold()

void stasis_app_control_hold ( struct stasis_app_control control)

Place the channel associated with the control on hold.

Parameters
controlControl for res_stasis.

Definition at line 800 of file control.c.

801{
803}
static int app_control_hold(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:792

References app_control_hold(), NULL, and stasis_app_send_command_async().

Referenced by ast_ari_channels_hold().

◆ stasis_app_control_inhibit_colp_in_bridge()

void stasis_app_control_inhibit_colp_in_bridge ( struct stasis_app_control control,
int  inhibit_colp 
)

Set whether COLP frames should be generated when joining the bridge.

Since
18
Parameters
controlControl whose channel should have its COLP frames inhibited when bridged
inhibit_colpWhether COLP frames should be generated (0) or not (1).

Definition at line 1539 of file control.c.

1541{
1542 control->bridge_features->inhibit_colp = inhibit_colp;
1543}
unsigned int inhibit_colp

References stasis_app_control::bridge_features, and ast_bridge_features::inhibit_colp.

Referenced by ast_ari_bridges_add_channel().

◆ stasis_app_control_is_done()

int stasis_app_control_is_done ( struct stasis_app_control control)

Check if a control is marked as done.

Since
12.2.0
Parameters
controlWhich control object is being evaluated

Definition at line 1345 of file res_stasis.c.

1346{
1347 return control_is_done(control);
1348}

References control_is_done().

Referenced by ari_bridges_play_found().

◆ stasis_app_control_is_failed()

int stasis_app_control_is_failed ( const struct stasis_app_control control)

Check if a control object is marked as "failed".

Parameters
controlControl object to check

Definition at line 382 of file control.c.

383{
384 return control->failed;
385}
unsigned int failed
Definition control.c:110

References stasis_app_control::failed.

Referenced by stasis_app_exec().

◆ stasis_app_control_mark_failed()

void stasis_app_control_mark_failed ( struct stasis_app_control control)

Set the failed flag on a control structure.

Parameters
controlControl object to be updated

Definition at line 377 of file control.c.

378{
379 control->failed = 1;
380}

References stasis_app_control::failed.

Referenced by outbound_session_handler_thread().

◆ stasis_app_control_moh_start()

void stasis_app_control_moh_start ( struct stasis_app_control control,
const char *  moh_class 
)

Play music on hold to a channel (does not affect hold status)

Parameters
controlControl for res_stasis.
moh_classclass of music on hold to play (NULL allowed)

Definition at line 832 of file control.c.

833{
834 char *data = NULL;
835
836 if (!ast_strlen_zero(moh_class)) {
837 data = ast_strdup(moh_class);
838 }
839
841}
static int app_control_moh_start(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:818

References app_control_moh_start(), ast_free_ptr(), ast_strdup, ast_strlen_zero(), NULL, and stasis_app_send_command_async().

Referenced by ast_ari_channels_start_moh().

◆ stasis_app_control_moh_stop()

void stasis_app_control_moh_stop ( struct stasis_app_control control)

Stop playing music on hold to a channel (does not affect hold status)

Parameters
controlControl for res_stasis.

Definition at line 850 of file control.c.

851{
853}
static int app_control_moh_stop(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:843

References app_control_moh_stop(), NULL, and stasis_app_send_command_async().

Referenced by ast_ari_channels_stop_moh().

◆ stasis_app_control_move()

int stasis_app_control_move ( struct stasis_app_control control,
const char *  app_name,
const char *  app_args 
)

Exit res_stasis and move to another Stasis application.

If the channel is no longer in res_stasis, this function does nothing.

Parameters
controlControl for res_stasis
app_nameThe name of the application to switch to
app_argsThe list of arguments to pass to the application
Returns
0 for success
-1 for error

Definition at line 477 of file control.c.

478{
479 struct stasis_app_control_move_data *move_data;
480 size_t size;
481
482 size = sizeof(*move_data) + strlen(app_name) + 1;
483 if (app_args) {
484 /* Application arguments are optional */
485 size += strlen(app_args) + 1;
486 }
487
488 if (!(move_data = ast_calloc(1, size))) {
489 return -1;
490 }
491
492 move_data->app_name = (char *)move_data + sizeof(*move_data);
493 strcpy(move_data->app_name, app_name); /* Safe */
494
495 if (app_args) {
496 move_data->app_args = move_data->app_name + strlen(app_name) + 1;
497 strcpy(move_data->app_args, app_args); /* Safe */
498 } else {
499 move_data->app_args = NULL;
500 }
501
503
504 return 0;
505}
static int app_control_move(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:440
const char * app_name(struct ast_app *app)
Definition pbx_app.c:475

References stasis_app_control_move_data::app_args, app_control_move(), app_name(), stasis_app_control_move_data::app_name, ast_calloc, ast_free_ptr(), NULL, and stasis_app_send_command_async().

Referenced by ast_ari_channels_move().

◆ stasis_app_control_mute()

int stasis_app_control_mute ( struct stasis_app_control control,
unsigned int  direction,
enum ast_frame_type  frametype 
)

Mute the channel associated with this control.

Parameters
controlControl for res_stasis.
directionThe direction in which the audio should be muted.
frametypeThe type of stream that should be muted.
Returns
0 for success
-1 for error.

Definition at line 672 of file control.c.

673{
674 struct stasis_app_control_mute_data *mute_data;
675
676 if (!(mute_data = ast_calloc(1, sizeof(*mute_data)))) {
677 return -1;
678 }
679
680 mute_data->direction = direction;
681 mute_data->frametype = frametype;
682
684
685 return 0;
686}
static int app_control_mute(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:660
direction
enum ast_frame_type frametype
Definition control.c:656

References app_control_mute(), ast_calloc, ast_free_ptr(), stasis_app_control_mute_data::direction, stasis_app_control_mute_data::frametype, and stasis_app_send_command_async().

Referenced by ast_ari_channels_mute().

◆ stasis_app_control_mute_in_bridge()

void stasis_app_control_mute_in_bridge ( struct stasis_app_control control,
int  mute 
)

Set whether audio from the channel is muted instead of passing through to the bridge.

Parameters
controlControl whose channel should have its audio muted when bridged
muteWhether audio should be muted (1) instead of passed through (0).

Definition at line 1533 of file control.c.

1535{
1536 control->bridge_features->mute = mute;
1537}

References stasis_app_control::bridge_features, and ast_bridge_features::mute.

Referenced by ast_ari_bridges_add_channel().

◆ stasis_app_control_progress()

int stasis_app_control_progress ( struct stasis_app_control control)

Indicate progress to the channel associated with this control.

Parameters
controlControl for res_stasis.
Returns
0 for success.
-1 for error.

Definition at line 648 of file control.c.

649{
651
652 return 0;
653}
static int app_control_progress(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:640

References app_control_progress(), NULL, and stasis_app_send_command_async().

Referenced by ast_ari_channels_progress().

◆ stasis_app_control_publish()

void stasis_app_control_publish ( struct stasis_app_control control,
struct stasis_message message 
)

Publish a message to the control's channel's topic.

Parameters
controlControl to publish to
messageMessage to publish

Definition at line 1499 of file control.c.

1501{
1502 if (!control || !control->channel || !message) {
1503 return;
1504 }
1506}
struct stasis_topic * ast_channel_topic(struct ast_channel *chan)
A topic which publishes the events for a particular channel.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
Definition stasis.c:1589

References ast_channel_topic(), stasis_app_control::channel, and stasis_publish().

Referenced by playback_publish(), and recording_publish().

◆ stasis_app_control_queue_control()

int stasis_app_control_queue_control ( struct stasis_app_control control,
enum ast_control_frame_type  frame_type 
)

Queue a control frame without payload.

Parameters
controlControl to publish to.
frame_typetype of control frame.
Returns
zero on success
non-zero on failure

Definition at line 1508 of file control.c.

1510{
1511 return ast_queue_control(control->channel, frame_type);
1512}
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
Definition channel.c:1289
frame_type

References ast_queue_control(), and stasis_app_control::channel.

Referenced by playback_forward(), playback_pause(), playback_restart(), playback_reverse(), playback_stop(), playback_unpause(), recording_cancel(), recording_pause(), recording_stop(), recording_unpause(), and toggle_recording_mute().

◆ stasis_app_control_redirect()

int stasis_app_control_redirect ( struct stasis_app_control control,
const char *  endpoint 
)

Redirect a channel in res_stasis to a particular endpoint.

Parameters
controlControl for res_stasis
endpointThe endpoint transfer string where the channel should be sent to
Returns
0 for success
-1 for error

Definition at line 526 of file control.c.

527{
528 char *endpoint_data = ast_strdup(endpoint);
529
530 if (!endpoint_data) {
531 return -1;
532 }
533
535
536 return 0;
537}
static int app_control_redirect(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:507

References app_control_redirect(), ast_free_ptr(), ast_strdup, and stasis_app_send_command_async().

Referenced by ast_ari_channels_redirect().

◆ stasis_app_control_register_add_rule()

void stasis_app_control_register_add_rule ( struct stasis_app_control control,
struct stasis_app_control_rule rule 
)

Registers an add channel to bridge rule.

Parameters
controlControl object
ruleThe rule to register

Definition at line 225 of file control.c.

228{
229 return app_control_register_rule(control, &control->add_rules, rule);
230}
static void app_control_register_rule(struct stasis_app_control *control, struct app_control_rules *list, struct stasis_app_control_rule *obj)
Definition control.c:170
struct app_control_rules add_rules
Definition control.c:79

References stasis_app_control::add_rules, and app_control_register_rule().

Referenced by stasis_app_control_record().

◆ stasis_app_control_register_remove_rule()

void stasis_app_control_register_remove_rule ( struct stasis_app_control control,
struct stasis_app_control_rule rule 
)

Registers a remove channel from bridge rule.

Parameters
controlControl object
ruleThe rule to register

Definition at line 239 of file control.c.

242{
243 return app_control_register_rule(control, &control->remove_rules, rule);
244}
struct app_control_rules remove_rules
Definition control.c:83

References app_control_register_rule(), and stasis_app_control::remove_rules.

◆ stasis_app_control_remove_channel_from_bridge()

int stasis_app_control_remove_channel_from_bridge ( struct stasis_app_control control,
struct ast_bridge bridge 
)

Remove a channel from the bridge.

Parameters
controlControl whose channel should be removed from the bridge
bridgePointer to the bridge
Returns
non-zero on failure
zero on success

Definition at line 1483 of file control.c.

1485{
1486 ast_debug(3, "%s: Sending channel remove_from_bridge command\n",
1491}
static int app_control_remove_channel_from_bridge(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:1457
static int app_control_can_remove_channel_from_bridge(struct stasis_app_control *control)
Definition control.c:259

References app_control_can_remove_channel_from_bridge(), app_control_remove_channel_from_bridge(), app_send_command_on_condition(), ast_debug, NULL, and stasis_app_control_get_channel_id().

Referenced by ast_ari_bridges_remove_channel().

◆ stasis_app_control_ring()

int stasis_app_control_ring ( struct stasis_app_control control)

Indicate ringing to the channel associated with this control.

Parameters
controlControl for res_stasis.
Returns
0 for success.
-1 for error.

Definition at line 618 of file control.c.

619{
621
622 return 0;
623}
static int app_control_ring(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:610

References app_control_ring(), NULL, and stasis_app_send_command_async().

Referenced by ast_ari_channels_ring().

◆ stasis_app_control_ring_stop()

int stasis_app_control_ring_stop ( struct stasis_app_control control)

Stop locally generated ringing on the channel associated with this control.

Parameters
controlControl for res_stasis.
Returns
0 for success.
-1 for error.

Definition at line 633 of file control.c.

634{
636
637 return 0;
638}
static int app_control_ring_stop(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:625

References app_control_ring_stop(), NULL, and stasis_app_send_command_async().

Referenced by ast_ari_channels_ring_stop().

◆ stasis_app_control_set_channel_var()

int stasis_app_control_set_channel_var ( struct stasis_app_control control,
const char *  variable,
const char *  value 
)

Set a variable on the channel associated with this control to value.

Parameters
controlControl for res_stasis.
variableThe name of the variable
valueThe value to set the variable to
Returns
0 for success.
-1 for error.

Definition at line 758 of file control.c.

759{
760 return stasis_app_control_set_channel_var_reportable(control, variable, value, 0);
761}
int stasis_app_control_set_channel_var_reportable(struct stasis_app_control *control, const char *variable, const char *value, int report_events)
Set a variable on the channel associated with this control to value with option of including in event...
Definition control.c:763

References stasis_app_control_set_channel_var_reportable(), and value.

◆ stasis_app_control_set_channel_var_reportable()

int stasis_app_control_set_channel_var_reportable ( struct stasis_app_control control,
const char *  variable,
const char *  value,
int  report_events 
)

Set a variable on the channel associated with this control to value with option of including in events.

Parameters
controlControl for res_stasis.
variableThe name of the variable
valueThe value to set the variable to
report_eventsWhether to include this variable in channel events.
Returns
0 for success.
-1 for error.

Definition at line 763 of file control.c.

764{
765 struct chanvar *var;
766
767 var = ast_calloc(1, sizeof(*var));
768 if (!var) {
769 return -1;
770 }
771
772 var->name = ast_strdup(variable);
773 if (!var->name) {
775 return -1;
776 }
777
778 /* It's kosher for value to be NULL. It means the variable is being unset */
779 if (value) {
780 var->value = ast_strdup(value);
781 if (!var->value) {
783 return -1;
784 }
785 }
786
787 var->report_events = report_events ? 1 : 0;
788
790}
#define var
Definition ast_expr2f.c:605
static int app_control_set_channel_var(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:744
int stasis_app_send_command(struct stasis_app_control *control, stasis_app_command_cb command_fn, void *data, command_data_destructor_fn data_destructor)
Invokes a command on a control's channel.
Definition control.c:950
static void free_chanvar(void *data)
Definition control.c:735
structure for queuing ARI channel variable setting
Definition control.c:726
unsigned int report_events
Definition control.c:732

References app_control_set_channel_var(), ast_calloc, ast_strdup, free_chanvar(), chanvar::report_events, stasis_app_send_command(), value, and var.

Referenced by ast_ari_channels_set_channel_var(), ast_ari_channels_set_channel_vars(), and stasis_app_control_set_channel_var().

◆ stasis_app_control_shutdown()

void stasis_app_control_shutdown ( void  )

Let Stasis app internals shut down.

This is called when res_stasis is unloaded. It ensures that the Stasis app internals can free any resources they may have allocated during the time that res_stasis was loaded.

Definition at line 1743 of file control.c.

1744{
1746 shutting_down = 1;
1747 if (dial_bridge) {
1749 dial_bridge = NULL;
1750 }
1752}
static struct ast_bridge * dial_bridge
Singleton dial bridge.
Definition control.c:1010
static int shutting_down
Indicates if the Stasis app internals are being shut down.
Definition control.c:52
static ast_mutex_t dial_bridge_lock
Definition control.c:1011
#define ast_mutex_unlock(a)
Definition lock.h:197
#define ast_mutex_lock(a)
Definition lock.h:196

References ast_bridge_destroy(), ast_mutex_lock, ast_mutex_unlock, dial_bridge, dial_bridge_lock, NULL, and shutting_down.

Referenced by unload_module().

◆ stasis_app_control_silence_start()

void stasis_app_control_silence_start ( struct stasis_app_control control)

Start playing silence to a channel.

Parameters
controlControl for res_stasis.

Definition at line 884 of file control.c.

885{
887}
static int app_control_silence_start(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:855

References app_control_silence_start(), NULL, and stasis_app_send_command_async().

Referenced by ast_ari_channels_start_silence().

◆ stasis_app_control_silence_stop()

void stasis_app_control_silence_stop ( struct stasis_app_control control)

Stop playing silence to a channel.

Parameters
controlControl for res_stasis.

Definition at line 907 of file control.c.

908{
910}
static int app_control_silence_stop(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:900

References app_control_silence_stop(), NULL, and stasis_app_send_command_async().

Referenced by ast_ari_channels_stop_silence().

◆ stasis_app_control_unhold()

void stasis_app_control_unhold ( struct stasis_app_control control)

Remove the channel associated with the control from hold.

Parameters
controlControl for res_stasis.

Definition at line 813 of file control.c.

814{
816}
static int app_control_unhold(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:805

References app_control_unhold(), NULL, and stasis_app_send_command_async().

Referenced by ast_ari_channels_unhold().

◆ stasis_app_control_unmute()

int stasis_app_control_unmute ( struct stasis_app_control control,
unsigned int  direction,
enum ast_frame_type  frametype 
)

Unmute the channel associated with this control.

Parameters
controlControl for res_stasis.
directionThe direction in which the audio should be unmuted.
frametypeThe type of stream that should be unmuted.
Returns
0 for success
-1 for error.

Definition at line 700 of file control.c.

701{
702 struct stasis_app_control_mute_data *mute_data;
703
704 if (!(mute_data = ast_calloc(1, sizeof(*mute_data)))) {
705 return -1;
706 }
707
708 mute_data->direction = direction;
709 mute_data->frametype = frametype;
710
712
713 return 0;
714}
static int app_control_unmute(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition control.c:688

References app_control_unmute(), ast_calloc, ast_free_ptr(), stasis_app_control_mute_data::direction, stasis_app_control_mute_data::frametype, and stasis_app_send_command_async().

Referenced by ast_ari_channels_unmute().

◆ stasis_app_control_unregister_add_rule()

void stasis_app_control_unregister_add_rule ( struct stasis_app_control control,
struct stasis_app_control_rule rule 
)

UnRegister an add channel to bridge rule.

Parameters
controlControl object
ruleThe rule to unregister

Definition at line 232 of file control.c.

235{
236 app_control_unregister_rule(control, &control->add_rules, rule);
237}
static void app_control_unregister_rule(struct stasis_app_control *control, struct app_control_rules *list, struct stasis_app_control_rule *obj)
Definition control.c:179

References stasis_app_control::add_rules, and app_control_unregister_rule().

Referenced by record_file(), and recording_fail().

◆ stasis_app_control_unregister_remove_rule()

void stasis_app_control_unregister_remove_rule ( struct stasis_app_control control,
struct stasis_app_control_rule rule 
)

Unregisters a remove channel from bridge rule.

Parameters
controlControl object
ruleThe rule to unregister

Definition at line 246 of file control.c.

249{
250 app_control_unregister_rule(control, &control->remove_rules, rule);
251}

References app_control_unregister_rule(), and stasis_app_control::remove_rules.

◆ stasis_app_event_allowed()

int stasis_app_event_allowed ( const char *  app_name,
struct ast_json event 
)

Check if the given event should be filtered.

Attempts first to find the event in the application's disallowed events list. If found then the event won't be sent to the remote. If not found in the disallowed list then a search is done to see if it can be found in the allowed list. If found the event message is sent, otherwise it is not sent.

Parameters
app_nameThe application name
eventThe event to check
Returns
True if allowed, false otherwise

Definition at line 1751 of file res/stasis/app.c.

1752{
1754 int res;
1755
1756 if (!app) {
1757 return 0;
1758 }
1759
1760 ao2_lock(app);
1761 res = !app_event_filter_matched(app->events_disallowed, event, 0) &&
1762 app_event_filter_matched(app->events_allowed, event, 1);
1763 ao2_unlock(app);
1764 ao2_ref(app, -1);
1765
1766 return res;
1767}
static int app_event_filter_matched(struct ast_json *array, struct ast_json *event, int empty)
struct stasis_app * stasis_app_get_by_name(const char *name)
Retrieve a handle to a Stasis application by its name.

References ao2_lock, ao2_ref, ao2_unlock, app, app_event_filter_matched(), app_name(), and stasis_app_get_by_name().

Referenced by ari_websocket_send_event().

◆ stasis_app_event_filter_set()

int stasis_app_event_filter_set ( struct stasis_app app,
struct ast_json filter 
)

Set the application's event type filter.

Parameters
appThe application
filterThe allowed and/or disallowed event filter
Returns
0 if successfully set

Definition at line 1725 of file res/stasis/app.c.

1726{
1728}
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
static int app_events_allowed_set(struct stasis_app *app, struct ast_json *filter)
static int app_events_disallowed_set(struct stasis_app *app, struct ast_json *filter)

References app, app_events_allowed_set(), app_events_disallowed_set(), and filter().

Referenced by ast_ari_applications_filter().

◆ stasis_app_event_filter_to_json()

struct ast_json * stasis_app_event_filter_to_json ( struct stasis_app app,
struct ast_json json 
)

Convert and add the app's event type filter(s) to the given json object.

Parameters
appThe application
jsonThe json object to add the filter data to
Returns
The given json object

Definition at line 1653 of file res/stasis/app.c.

1654{
1655 if (!app || !json) {
1656 return json;
1657 }
1658
1659 ast_json_object_set(json, "events_allowed", app->events_allowed ?
1660 ast_json_ref(app->events_allowed) : ast_json_array_create());
1661 ast_json_object_set(json, "events_disallowed", app->events_disallowed ?
1662 ast_json_ref(app->events_disallowed) : ast_json_array_create());
1663
1664 return json;
1665}
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition json.c:362
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition json.c:67
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition json.c:414

References app, ast_json_array_create(), ast_json_object_set(), and ast_json_ref().

Referenced by stasis_app_object_to_json().

◆ stasis_app_get_all()

struct ao2_container * stasis_app_get_all ( void  )

Gets the names of all registered Stasis applications.

Returns
ast_str_container of container names.
Return values
NULLon error.

Definition at line 1796 of file res_stasis.c.

1797{
1798 struct ao2_container *apps;
1799
1800 if (!apps_registry) {
1801 return NULL;
1802 }
1803
1805 if (!apps) {
1806 return NULL;
1807 }
1808
1810
1811 return apps;
1812}
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition astobj2.h:1693
@ OBJ_NODATA
Definition astobj2.h:1044
static int append_name(void *obj, void *arg, int flags)
struct ao2_container * apps_registry
Stasis application container.
Definition res_stasis.c:100
#define ast_str_container_alloc(buckets)
Allocates a hash container for bare strings.
Definition strings.h:1365
Generic container type.
Registered applications container.
Definition pbx_app.c:69

References ao2_callback, append_name(), apps_registry, ast_str_container_alloc, NULL, and OBJ_NODATA.

Referenced by ari_set_debug(), ari_show_app(), ari_show_apps(), ast_ari_applications_list(), send_broadcast_event(), stasis_app_claim_channel(), and stasis_app_set_global_debug().

◆ stasis_app_get_bridge()

struct ast_bridge * stasis_app_get_bridge ( struct stasis_app_control control)

Gets the bridge currently associated with a control object.

Since
12
Note
If the bridge returned by this function is to be held for any length of time, its refcount should be incremented until the caller is finished with it.
Parameters
controlControl object for the channel to query.
Returns
Associated ast_bridge.
Return values
NULLif not associated with a bridge.

Definition at line 983 of file control.c.

984{
985 struct ast_bridge *ret;
986
987 if (!control) {
988 return NULL;
989 }
990
991 ao2_lock(control);
992 ret = control->bridge;
993 ao2_unlock(control);
994
995 return ret;
996}
struct ast_bridge * bridge
Definition control.c:67

References ao2_lock, ao2_unlock, stasis_app_control::bridge, and NULL.

Referenced by app_control_continue(), app_control_dtmf(), app_control_remove_channel_from_bridge(), ast_ari_bridges_remove_channel(), ast_ari_bridges_set_video_source(), control_swap_channel_in_bridge(), play_uri(), record_file(), and stasis_app_exec().

◆ stasis_app_get_by_name()

struct stasis_app * stasis_app_get_by_name ( const char *  name)

Retrieve a handle to a Stasis application by its name.

Parameters
nameThe name of the registered Stasis application
Returns
stasis_app on success.
Return values
NULLon error.

Definition at line 1769 of file res_stasis.c.

1770{
1771 return find_app_by_name(name);
1772}
static struct stasis_app * find_app_by_name(const char *app_name)

References find_app_by_name(), and name.

Referenced by ari_set_debug(), ari_show_app(), ast_ari_applications_filter(), stasis_app_event_allowed(), stasis_app_get_debug_by_name(), stasis_app_set_debug_by_name(), and stasis_app_set_global_debug().

◆ stasis_app_get_debug()

int stasis_app_get_debug ( struct stasis_app app)

Get debug status of an application.

Parameters
appThe app to check
Returns
The debug flag for the app || the global debug flag

Definition at line 880 of file res/stasis/app.c.

881{
882 return (app ? app->debug : 0) || global_debug;
883}
int global_debug

References app, and global_debug.

◆ stasis_app_get_debug_by_name()

int stasis_app_get_debug_by_name ( const char *  app_name)

Get debug status of an application.

Parameters
app_nameThe app_name to check
Returns
The debug flag for the app || the global debug flag

Definition at line 885 of file res/stasis/app.c.

886{
887 int debug_enabled = 0;
888
889 if (global_debug) {
890 debug_enabled = 1;
891 } else {
893
894 if (app) {
895 if (app->debug) {
896 debug_enabled = 1;
897 }
898 ao2_ref(app, -1);
899 }
900 }
901 return debug_enabled;
902}

References ao2_ref, app, app_name(), global_debug, and stasis_app_get_by_name().

Referenced by ari_websocket_process_request(), ast_ari_callback(), session_send_app_event(), and stasis_app_message_handler().

◆ stasis_app_get_sanitizer()

struct stasis_message_sanitizer * stasis_app_get_sanitizer ( void  )

Get the Stasis message sanitizer for app_stasis applications.

Return values
Thestasis message sanitizer

Definition at line 2370 of file res_stasis.c.

2371{
2372 return &app_sanitizer;
2373}
struct stasis_message_sanitizer app_sanitizer
Sanitization callbacks for communication to Stasis applications.

References app_sanitizer.

Referenced by app_send_end_msg(), ast_ari_bridges_create(), ast_ari_bridges_create_with_id(), ast_ari_bridges_get(), ast_ari_bridges_list(), ast_ari_channels_list(), ast_ari_endpoints_get(), ast_ari_endpoints_list(), ast_ari_endpoints_list_by_tech(), channel_callerid(), channel_connected_line(), channel_destroyed_event(), channel_dialplan(), message_received_handler(), simple_bridge_event(), simple_channel_event(), and simple_endpoint_event().

◆ stasis_app_is_registered()

int stasis_app_is_registered ( const char *  name)

Check if a Stasis application is registered.

Parameters
nameThe name of the registered Stasis application
Returns
1 if the application is registered.
0 if the application is not registered.

Definition at line 1774 of file res_stasis.c.

1775{
1777
1778 /*
1779 * It's safe to unref app here because we're not actually
1780 * using it or returning it.
1781 */
1783
1784 return app != NULL;
1785}

References ao2_cleanup, app, find_app_by_name(), name, and NULL.

Referenced by app_exec(), and session_register_apps().

◆ stasis_app_name()

const char * stasis_app_name ( const struct stasis_app app)

Retrieve an application's name.

Parameters
appAn application
Returns
The name of the application.

Definition at line 1168 of file res/stasis/app.c.

1169{
1170 return app->name;
1171}

References app.

Referenced by app_compare(), app_hash(), app_send_end_msg(), app_subscribe(), app_unsubscribe(), append_name(), ari_set_debug(), bridge_stasis_push_peek(), cleanup_cb(), device_state_subscription_create(), devices_to_json(), find_device_state_subscription(), send_start_msg_snapshots(), stasis_app_exec(), and subscribe_device_state().

◆ stasis_app_object_to_json()

struct ast_json * stasis_app_object_to_json ( struct stasis_app app)

Return the JSON representation of a Stasis application.

Since
16.3.0
Parameters
appThe application.
Returns
JSON representation of app with given name.
Return values
NULLon error.

Definition at line 1972 of file res_stasis.c.

1973{
1974 if (!app) {
1975 return NULL;
1976 }
1977
1980}
struct ast_json * app_to_json(const struct stasis_app *app)
Create a JSON representation of a stasis_app.
static struct ast_json * app_event_sources_to_json(const struct stasis_app *app, struct ast_json *json)
struct ast_json * stasis_app_event_filter_to_json(struct stasis_app *app, struct ast_json *json)
Convert and add the app's event type filter(s) to the given json object.

References app, app_event_sources_to_json(), app_to_json(), NULL, and stasis_app_event_filter_to_json().

Referenced by app_handle_subscriptions(), ast_ari_applications_filter(), and stasis_app_to_json().

◆ stasis_app_register()

int stasis_app_register ( const char *  app_name,
stasis_app_cb  handler,
void *  data 
)

Register a new Stasis application.

If an application is already registered with the given name, the old application is sent a 'replaced' message and unregistered.

Parameters
app_nameName of this application.
handlerCallback for application messages.
dataData blob to pass to the callback. Must be AO2 managed.
Returns
0 for success
-1 for error.

Definition at line 1865 of file res_stasis.c.

1866{
1867 return __stasis_app_register(app_name, handler, data, 0);
1868}
static int __stasis_app_register(const char *app_name, stasis_app_cb handler, void *data, int all_events)
static void handler(const char *name, int response_code, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Definition test_ari.c:59

References __stasis_app_register(), app_name(), and handler().

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), and session_register_apps().

◆ stasis_app_register_all()

int stasis_app_register_all ( const char *  app_name,
stasis_app_cb  handler,
void *  data 
)

Register a new Stasis application that receives all Asterisk events.

If an application is already registered with the given name, the old application is sent a 'replaced' message and unregistered.

Parameters
app_nameName of this application.
handlerCallback for application messages.
dataData blob to pass to the callback. Must be AO2 managed.
Returns
0 for success
-1 for error.

Definition at line 1870 of file res_stasis.c.

1871{
1872 return __stasis_app_register(app_name, handler, data, 1);
1873}

References __stasis_app_register(), app_name(), and handler().

Referenced by session_register_apps().

◆ stasis_app_register_event_source()

void stasis_app_register_event_source ( struct stasis_app_event_source obj)

Register an application event source.

Parameters
objthe event source to register

Definition at line 1922 of file res_stasis.c.

1923{
1927}
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.

References AST_LIST_INSERT_TAIL, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and stasis_app_event_source::next.

Referenced by load_module(), and stasis_app_register_event_sources().

◆ stasis_app_register_event_sources()

void stasis_app_register_event_sources ( void  )

Register core event sources.

Definition at line 1639 of file res/stasis/app.c.

1640{
1644}
struct stasis_app_event_source bridge_event_source
struct stasis_app_event_source channel_event_source
struct stasis_app_event_source endpoint_event_source
void stasis_app_register_event_source(struct stasis_app_event_source *obj)
Register an application event source.

References bridge_event_source, channel_event_source, endpoint_event_source, and stasis_app_register_event_source().

Referenced by load_module().

◆ stasis_app_send()

int stasis_app_send ( const char *  app_name,
struct ast_json message 
)

Send a message to the given Stasis application.

The message given to the handler is a borrowed copy. If you want to keep a reference to it, you should use ao2_ref() to keep it around.

Parameters
app_nameName of the application to invoke.
messageMessage to send (borrowed reference)
Returns
0 for success.
-1 for error.

Definition at line 1731 of file res_stasis.c.

1732{
1733 struct stasis_app *app;
1734
1735 if (!apps_registry) {
1736 return -1;
1737 }
1738
1740 if (!app) {
1741 /* XXX We can do a better job handling late binding, queueing up
1742 * the call for a few seconds to wait for the app to register.
1743 */
1745 "Stasis app '%s' not registered\n", app_name);
1746 return -1;
1747 }
1749 ao2_ref(app, -1);
1750
1751 return 0;
1752}
void app_send(struct stasis_app *app, struct ast_json *message)
Send a message to an application.

References ao2_find, ao2_ref, app, app_name(), app_send(), apps_registry, ast_log, LOG_WARNING, and OBJ_SEARCH_KEY.

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), send_broadcast_event(), send_device_state(), and stasis_app_claim_channel().

◆ stasis_app_set_debug()

void stasis_app_set_debug ( struct stasis_app app,
int  debug 
)

Enable/disable request/response and event logging on an application.

Parameters
appThe app to debug
debugIf non-zero, enable debugging. If zero, disable.

Definition at line 859 of file res/stasis/app.c.

860{
861 if (!app) {
862 return;
863 }
864
865 app->debug = debug;
866}
static int debug
Global debug status.
Definition res_xmpp.c:570

References app, and debug.

Referenced by ari_set_debug(), and stasis_app_set_global_debug().

◆ stasis_app_set_debug_by_name()

void stasis_app_set_debug_by_name ( const char *  app_name,
int  debug 
)

Enable/disable request/response and event logging on an application.

Parameters
app_nameThe app name to debug
debugIf non-zero, enable debugging. If zero, disable.

Definition at line 868 of file res/stasis/app.c.

869{
871
872 if (!app) {
873 return;
874 }
875
876 app->debug = debug;
878}

References ao2_cleanup, app, app_name(), debug, and stasis_app_get_by_name().

◆ stasis_app_set_global_debug()

void stasis_app_set_global_debug ( int  debug)

Enable/disable request/response and event logging on all applications.

Parameters
debugIf non-zero, enable debugging. If zero, disable.

Definition at line 904 of file res/stasis/app.c.

905{
907 if (!global_debug) {
908 struct ao2_container *app_names = stasis_app_get_all();
909 struct ao2_iterator it_app_names;
910 char *app_name;
911 struct stasis_app *app;
912
913 if (!app_names || !ao2_container_count(app_names)) {
914 ao2_cleanup(app_names);
915 return;
916 }
917
918 it_app_names = ao2_iterator_init(app_names, 0);
919 while ((app_name = ao2_iterator_next(&it_app_names))) {
922 }
923
926 }
927 ao2_iterator_cleanup(&it_app_names);
928 ao2_cleanup(app_names);
929 }
930}
#define ao2_iterator_next(iter)
Definition astobj2.h:1911
void ao2_iterator_cleanup(struct ao2_iterator *iter)
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
void stasis_app_set_debug(struct stasis_app *app, int debug)
Enable/disable request/response and event logging on an application.
struct ao2_container * stasis_app_get_all(void)
Gets the names of all registered Stasis applications.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition astobj2.h:1821

References ao2_cleanup, ao2_container_count(), ao2_iterator_cleanup(), ao2_iterator_init(), ao2_iterator_next, app, app_name(), debug, global_debug, stasis_app_get_all(), stasis_app_get_by_name(), and stasis_app_set_debug().

Referenced by ari_set_debug().

◆ stasis_app_subscribe()

enum stasis_app_subscribe_res stasis_app_subscribe ( const char *  app_name,
const char **  event_source_uris,
int  event_sources_count,
struct ast_json **  json 
)

Subscribes an application to a list of event sources.

Parameters
app_nameName of the application to subscribe.
event_source_urisURIs for the event sources to subscribe to.
event_sources_countArray size of event_source_uris.
jsonOptional output pointer for JSON representation of the app after adding the subscription.
Returns
stasis_app_subscribe_res return code.
Note
Do not hold any channel locks if subscribing to a channel.

Definition at line 2151 of file res_stasis.c.

2154{
2156 app_name, event_source_uris, event_sources_count,
2157 json, app_subscribe);
2158}
static enum stasis_app_subscribe_res app_subscribe(struct stasis_app *app, const char *uri, struct stasis_app_event_source *event_source)
static enum stasis_app_subscribe_res app_handle_subscriptions(const char *app_name, const char **event_source_uris, int event_sources_count, struct ast_json **json, app_subscription_handler handler)

References app_handle_subscriptions(), app_name(), and app_subscribe().

Referenced by ast_ari_applications_subscribe().

◆ stasis_app_subscribe_channel()

enum stasis_app_subscribe_res stasis_app_subscribe_channel ( const char *  app_name,
struct ast_channel chan 
)

Directly subscribe an application to a channel.

Parameters
app_nameName of the application to subscribe.
chanThe channel to subscribe to
Returns
stasis_app_subscribe_res return code.
Note
This method can be used when you already hold a channel and its lock. This bypasses the channel lookup that would normally be performed by stasis_app_subscribe.

Definition at line 2090 of file res_stasis.c.

2092{
2094 int res;
2095
2096 if (!app) {
2098 }
2099
2100 ast_debug(3, "%s: Subscribing to %s\n", app_name, ast_channel_uniqueid(chan));
2101
2102 res = app_subscribe_channel(app, chan);
2103 ao2_ref(app, -1);
2104
2105 if (res != 0) {
2106 ast_log(LOG_ERROR, "Error subscribing app '%s' to channel '%s'\n",
2109 }
2110
2111 return STASIS_ASR_OK;
2112}
#define LOG_ERROR
int app_subscribe_channel(struct stasis_app *app, struct ast_channel *chan)
Subscribes an application to a channel.

References ao2_ref, app, app_name(), app_subscribe_channel(), ast_channel_uniqueid(), ast_debug, ast_log, find_app_by_name(), LOG_ERROR, STASIS_ASR_APP_NOT_FOUND, STASIS_ASR_INTERNAL_ERROR, and STASIS_ASR_OK.

Referenced by ari_channels_handle_originate_with_id(), and ast_ari_channels_create().

◆ stasis_app_to_cli()

void stasis_app_to_cli ( const struct stasis_app app,
struct ast_cli_args a 
)

Dump properties of a stasis_app to the CLI.

Parameters
appThe application
aThe CLI arguments

Definition at line 1185 of file res/stasis/app.c.

1186{
1187 struct ao2_iterator *channels;
1188 struct ao2_iterator *endpoints;
1189 struct ao2_iterator *bridges;
1190 struct app_forwards *forward;
1192
1193 ast_cli(a->fd, "Name: %s\n"
1194 " Debug: %s\n"
1195 " Subscription Model: %s\n",
1196 app->name,
1197 app->debug ? "Yes" : "No",
1198 app->subscription_model == STASIS_APP_SUBSCRIBE_ALL ?
1199 "Global Resource Subscription" :
1200 "Application/Explicit Resource Subscription");
1201 ast_cli(a->fd, " Subscriptions: %d\n", ao2_container_count(app->forwards));
1202
1203 ast_cli(a->fd, " Channels:\n");
1207 if (channels) {
1208 while ((forward = ao2_iterator_next(channels))) {
1209 ast_cli(a->fd, " %s (%d)\n", forward->id, forward->interested);
1210 ao2_ref(forward, -1);
1211 }
1213 }
1214
1215 ast_cli(a->fd, " Bridges:\n");
1217 bridges = ao2_callback(app->forwards, OBJ_MULTIPLE,
1219 if (bridges) {
1220 while ((forward = ao2_iterator_next(bridges))) {
1221 ast_cli(a->fd, " %s (%d)\n", forward->id, forward->interested);
1222 ao2_ref(forward, -1);
1223 }
1225 }
1226
1227 ast_cli(a->fd, " Endpoints:\n");
1231 if (endpoints) {
1232 while ((forward = ao2_iterator_next(endpoints))) {
1233 ast_cli(a->fd, " %s (%d)\n", forward->id, forward->interested);
1234 ao2_ref(forward, -1);
1235 }
1237 }
1238}
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
@ OBJ_MULTIPLE
Definition astobj2.h:1049
static struct ao2_container * bridges
Definition bridge.c:132
void ast_cli(int fd, const char *fmt,...)
Definition clicompat.c:6
static struct channel_usage channels
static struct ao2_container * endpoints
static int forwards_filter_by_type(void *obj, void *arg, int flags)
forward_type
@ FORWARD_CHANNEL
@ FORWARD_ENDPOINT
@ FORWARD_BRIDGE
@ STASIS_APP_SUBSCRIBE_ALL
An application is automatically subscribed to all resources in Asterisk, even if it does not control ...
const char * name
static struct test_val a

References a, ao2_callback, ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_next, ao2_ref, app, ast_cli(), bridges, channels, endpoints, FORWARD_BRIDGE, FORWARD_CHANNEL, FORWARD_ENDPOINT, forwards_filter_by_type(), app_forwards::id, app_forwards::interested, test_val::name, OBJ_MULTIPLE, and STASIS_APP_SUBSCRIBE_ALL.

Referenced by ari_show_app().

◆ stasis_app_to_json()

struct ast_json * stasis_app_to_json ( const char *  app_name)

Return the JSON representation of a Stasis application.

Parameters
app_nameName of the application.
Returns
JSON representation of app with given name.
Return values
NULLon error.

Definition at line 1982 of file res_stasis.c.

1983{
1985 struct ast_json *json = stasis_app_object_to_json(app);
1986
1988
1989 return json;
1990}
struct ast_json * stasis_app_object_to_json(struct stasis_app *app)
Return the JSON representation of a Stasis application.
Abstract JSON element (object, array, string, int, ...).

References ao2_cleanup, app, app_name(), find_app_by_name(), and stasis_app_object_to_json().

Referenced by append_json(), and ast_ari_applications_get().

◆ stasis_app_unregister()

void stasis_app_unregister ( const char *  app_name)

Unregister a Stasis application and unsubscribe from all event sources.

Parameters
app_nameName of the application to unregister.

Definition at line 1875 of file res_stasis.c.

1876{
1877 struct stasis_app *app;
1878 struct stasis_app_event_source *source;
1879 int res;
1880
1881 if (!app_name) {
1882 return;
1883 }
1884
1885 if (!apps_registry) {
1886 return;
1887 }
1888
1890 if (!app) {
1892 "Stasis app '%s' not registered\n", app_name);
1893 return;
1894 }
1895
1896 /* Unsubscribe from all event sources. */
1899 if (!source->unsubscribe || !source->is_subscribed
1900 || !source->is_subscribed(app, NULL)) {
1901 continue;
1902 }
1903
1904 res = source->unsubscribe(app, NULL);
1905 if (res) {
1906 ast_log(LOG_WARNING, "%s: Error unsubscribing from event source '%s'\n",
1907 app_name, source->scheme);
1908 }
1909 }
1911
1913
1914 /* There's a decent chance that app is ready for cleanup. Go ahead
1915 * and clean up, just in case
1916 */
1917 cleanup();
1918
1919 ao2_ref(app, -1);
1920}
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition linkedlists.h:78
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
void app_deactivate(struct stasis_app *app)
Deactivates an application.
static void cleanup(void)
Clean up any old apps that we don't need any more.
Definition res_stasis.c:327
Event source information and callbacks.
Definition stasis_app.h:184
const char * scheme
The scheme to match against on [un]subscribes.
Definition stasis_app.h:186
int(* unsubscribe)(struct stasis_app *app, const char *id)
Cancel the subscription an app has to an event source.
Definition stasis_app.h:216
struct stasis_app_event_source * next
Definition stasis_app.h:237
int(* is_subscribed)(struct stasis_app *app, const char *id)
Find an event source by the given id/name.
Definition stasis_app.h:226

References ao2_find, ao2_ref, app, app_deactivate(), app_name(), apps_registry, AST_LIST_TRAVERSE, ast_log, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, cleanup(), stasis_app_event_source::is_subscribed, LOG_ERROR, LOG_WARNING, stasis_app_event_source::next, NULL, OBJ_SEARCH_KEY, stasis_app_event_source::scheme, and stasis_app_event_source::unsubscribe.

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), and session_unregister_app_cb().

◆ stasis_app_unregister_event_source()

void stasis_app_unregister_event_source ( struct stasis_app_event_source obj)

Unregister an application event source.

Parameters
objthe event source to unregister

Definition at line 1929 of file res_stasis.c.

1930{
1931 struct stasis_app_event_source *source;
1932
1935 if (source == obj) {
1937 break;
1938 }
1939 }
1942}
#define AST_RWLIST_REMOVE_CURRENT
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
#define AST_RWLIST_TRAVERSE_SAFE_END

References AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and stasis_app_event_source::next.

Referenced by stasis_app_unregister_event_sources(), and unload_module().

◆ stasis_app_unregister_event_sources()

void stasis_app_unregister_event_sources ( void  )

Unregister core event sources.

Definition at line 1646 of file res/stasis/app.c.

1647{
1651}
void stasis_app_unregister_event_source(struct stasis_app_event_source *obj)
Unregister an application event source.

References bridge_event_source, channel_event_source, endpoint_event_source, and stasis_app_unregister_event_source().

Referenced by unload_module().

◆ stasis_app_unsubscribe()

enum stasis_app_subscribe_res stasis_app_unsubscribe ( const char *  app_name,
const char **  event_source_uris,
int  event_sources_count,
struct ast_json **  json 
)

Unsubscribes an application from a list of event sources.

Parameters
app_nameName of the application to subscribe.
event_source_urisURIs for the event sources to subscribe to.
event_sources_countArray size of event_source_uris.
jsonOptional output pointer for JSON representation of the app after adding the subscription.
Returns
stasis_app_subscribe_res return code.

Definition at line 2192 of file res_stasis.c.

2195{
2197 app_name, event_source_uris, event_sources_count,
2198 json, app_unsubscribe);
2199}
static enum stasis_app_subscribe_res app_unsubscribe(struct stasis_app *app, const char *uri, struct stasis_app_event_source *event_source)

References app_handle_subscriptions(), app_name(), and app_unsubscribe().

Referenced by ast_ari_applications_unsubscribe().

◆ stasis_app_user_event()

enum stasis_app_user_event_res stasis_app_user_event ( const char *  app_name,
const char *  event_name,
const char **  source_uris,
int  sources_count,
struct ast_json json_variables 
)

Generate a Userevent for stasis app (echo to AMI)

Parameters
app_nameName of the application to generate event for/to.
event_nameName of the Userevent.
source_urisURIs for the source objects to attach to event.
sources_countArray size of source_uris.
json_variablesevent blob variables.
Returns
stasis_app_user_event_res return code.

Definition at line 2201 of file res_stasis.c.

2205{
2207 struct ast_json *blob = NULL;
2208 struct ast_multi_object_blob *multi;
2209 struct stasis_message *message;
2211 int have_channel = 0;
2212 int i;
2213
2214 if (!app) {
2215 ast_log(LOG_WARNING, "App %s not found\n", app_name);
2217 }
2218
2220 return res;
2221 }
2222
2223 if (json_variables) {
2224 struct ast_json *json_value = ast_json_string_create(event_name);
2225
2226 if (json_value && !ast_json_object_set(json_variables, "eventname", json_value)) {
2227 blob = ast_json_ref(json_variables);
2228 }
2229 } else {
2230 blob = ast_json_pack("{s: s}", "eventname", event_name);
2231 }
2232
2233 if (!blob) {
2234 ast_log(LOG_ERROR, "Failed to initialize blob\n");
2235
2236 return res;
2237 }
2238
2239 multi = ast_multi_object_blob_create(blob);
2240 ast_json_unref(blob);
2241 if (!multi) {
2242 ast_log(LOG_ERROR, "Failed to initialize multi\n");
2243
2244 return res;
2245 }
2246
2247 for (i = 0; i < sources_count; ++i) {
2248 const char *uri = source_uris[i];
2249 void *snapshot=NULL;
2251
2252 if (ast_begins_with(uri, "channel:")) {
2254 snapshot = ast_channel_snapshot_get_latest(uri + 8);
2255 have_channel = 1;
2256 } else if (ast_begins_with(uri, "bridge:")) {
2258 snapshot = ast_bridge_get_snapshot_by_uniqueid(uri + 7);
2259 } else if (ast_begins_with(uri, "endpoint:")) {
2261 snapshot = ast_endpoint_latest_snapshot(uri + 9, NULL);
2262 } else {
2263 ast_log(LOG_WARNING, "Invalid scheme: %s\n", uri);
2264 ao2_ref(multi, -1);
2265
2267 }
2268 if (!snapshot) {
2269 ast_log(LOG_ERROR, "Unable to get snapshot for %s\n", uri);
2270 ao2_ref(multi, -1);
2271
2273 }
2274 ast_multi_object_blob_add(multi, type, snapshot);
2275 }
2276
2278 ao2_ref(multi, -1);
2279
2280 if (!message) {
2281 ast_log(LOG_ERROR, "Unable to create stasis user event message\n");
2282 return res;
2283 }
2284
2285 /*
2286 * Publishing to two different topics is normally to be avoided -- except
2287 * in this case both are final destinations with no forwards (only listeners).
2288 * The message has to be delivered to the application topic for ARI, but a
2289 * copy is also delivered directly to the manager for AMI if there is a channel.
2290 */
2292
2293 if (have_channel) {
2295 }
2296 ao2_ref(message, -1);
2297
2298 return STASIS_APP_USER_OK;
2299}
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition manager.c:450
void ast_multi_object_blob_add(struct ast_multi_object_blob *multi, enum stasis_user_multi_object_snapshot_type type, void *object)
Add an object to a multi object blob previously created.
Definition stasis.c:2213
stasis_user_multi_object_snapshot_type
Object type code for multi user object snapshots.
Definition stasis.h:1384
struct ast_multi_object_blob * ast_multi_object_blob_create(struct ast_json *blob)
Create a stasis multi object blob.
Definition stasis.c:2187
struct ast_endpoint_snapshot * ast_endpoint_latest_snapshot(const char *tech, const char *resource)
Retrieve the most recent snapshot for the endpoint with the given name.
struct stasis_message_type * ast_multi_user_event_type(void)
Message type for custom user defined events with multi object blobs.
@ STASIS_UMOS_ENDPOINT
Definition stasis.h:1387
@ STASIS_UMOS_BRIDGE
Definition stasis.h:1386
@ STASIS_UMOS_CHANNEL
Definition stasis.h:1385
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition json.c:278
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition json.c:73
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition json.c:612
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
struct stasis_topic * ast_app_get_topic(struct stasis_app *app)
Returns the stasis topic for an app.
stasis_app_user_event_res
Return code for stasis_app_user_event.
Definition stasis_app.h:265
struct ast_bridge_snapshot * ast_bridge_get_snapshot_by_uniqueid(const char *bridge_id)
Returns the current snapshot for the bridge.
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Checks whether a string begins with another.
Definition strings.h:97
A multi object blob data structure to carry user event stasis messages.
Definition stasis.c:2162

References ao2_cleanup, ao2_ref, app, app_name(), ast_app_get_topic(), ast_begins_with(), ast_bridge_get_snapshot_by_uniqueid(), ast_channel_snapshot_get_latest(), ast_endpoint_latest_snapshot(), ast_json_object_set(), ast_json_pack(), ast_json_ref(), ast_json_string_create(), ast_json_unref(), ast_log, ast_manager_get_topic(), ast_multi_object_blob_add(), ast_multi_object_blob_create(), ast_multi_user_event_type(), find_app_by_name(), LOG_ERROR, LOG_WARNING, NULL, RAII_VAR, STASIS_APP_USER_APP_NOT_FOUND, STASIS_APP_USER_EVENT_SOURCE_BAD_SCHEME, STASIS_APP_USER_EVENT_SOURCE_NOT_FOUND, STASIS_APP_USER_INTERNAL_ERROR, STASIS_APP_USER_OK, stasis_message_create(), stasis_publish(), STASIS_UMOS_BRIDGE, STASIS_UMOS_CHANNEL, STASIS_UMOS_ENDPOINT, and type.

Referenced by ast_ari_events_user_event().