Asterisk - The Open Source Telephony Project  18.5.0
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...
 
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...
 
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...
 
typedef void(* stasis_app_cb) (void *data, const char *app_name, struct ast_json *message)
 Callback for Stasis application handler. More...
 
struct ao2_containerstasis_app_get_all (void)
 Gets the names of all registered Stasis applications. More...
 
struct stasis_appstasis_app_get_by_name (const char *name)
 Retrieve a handle to a Stasis application by its name. More...
 
int stasis_app_register (const char *app_name, stasis_app_cb handler, void *data)
 Register a new Stasis application. More...
 
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. More...
 
void stasis_app_unregister (const char *app_name)
 Unregister a Stasis application. More...
 
int stasis_app_send (const char *app_name, struct ast_json *message)
 Send a message to the given Stasis application. More...
 
const char * stasis_app_name (const struct stasis_app *app)
 Retrieve an application's name. More...
 
struct ast_jsonstasis_app_object_to_json (struct stasis_app *app)
 Return the JSON representation of a Stasis application. More...
 
struct ast_jsonstasis_app_to_json (const char *app_name)
 Return the JSON representation of a Stasis application. More...
 
void stasis_app_register_event_source (struct stasis_app_event_source *obj)
 Register an application event source. More...
 
void stasis_app_register_event_sources (void)
 Register core event sources. More...
 
void stasis_app_unregister_event_source (struct stasis_app_event_source *obj)
 Unregister an application event source. More...
 
void stasis_app_unregister_event_sources (void)
 Unregister core event sources. More...
 
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) More...
 
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. More...
 
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. More...
 
enum stasis_app_subscribe_res stasis_app_subscribe_channel (const char *app_name, struct ast_channel *chan)
 Directly subscribe an application to a channel. More...
 
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_register_add_rule (struct stasis_app_control *control, struct stasis_app_control_rule *rule)
 Registers an add channel to bridge rule. More...
 
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. More...
 
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. More...
 
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. More...
 
struct stasis_app_controlstasis_app_control_find_by_channel (const struct ast_channel *chan)
 Returns the handler for the given channel. More...
 
struct stasis_app_controlstasis_app_control_find_by_channel_id (const char *channel_id)
 Returns the handler for the channel with the given id. More...
 
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. More...
 
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. More...
 
int stasis_app_control_is_done (struct stasis_app_control *control)
 Check if a control is marked as done. More...
 
void stasis_app_control_flush_queue (struct stasis_app_control *control)
 Flush the control command queue. More...
 
const char * stasis_app_control_get_channel_id (const struct stasis_app_control *control)
 Returns the uniqueid of the channel associated with this control. More...
 
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. 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. More...
 
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. More...
 
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. More...
 
int stasis_app_control_redirect (struct stasis_app_control *control, const char *endpoint)
 Redirect a channel in res_stasis to a particular endpoint. More...
 
int stasis_app_control_ring (struct stasis_app_control *control)
 Indicate ringing to the channel associated with this control. More...
 
int stasis_app_control_ring_stop (struct stasis_app_control *control)
 Stop locally generated ringing on the channel associated with this control. More...
 
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. More...
 
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. More...
 
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. More...
 
int stasis_app_control_answer (struct stasis_app_control *control)
 Answer the channel associated with this control. More...
 
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. More...
 
void stasis_app_control_hold (struct stasis_app_control *control)
 Place the channel associated with the control on hold. More...
 
void stasis_app_control_unhold (struct stasis_app_control *control)
 Remove the channel associated with the control from hold. More...
 
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) More...
 
void stasis_app_control_moh_stop (struct stasis_app_control *control)
 Stop playing music on hold to a channel (does not affect hold status) More...
 
void stasis_app_control_silence_start (struct stasis_app_control *control)
 Start playing silence to a channel. More...
 
void stasis_app_control_silence_stop (struct stasis_app_control *control)
 Stop playing silence to a channel. More...
 
struct ast_channel_snapshotstasis_app_control_get_snapshot (const struct stasis_app_control *control)
 Returns the most recent snapshot for the associated channel. More...
 
void stasis_app_control_publish (struct stasis_app_control *control, struct stasis_message *message)
 Publish a message to the control's channel's topic. More...
 
struct stasis_topicast_app_get_topic (struct stasis_app *app)
 Returns the stasis topic for an app. More...
 
int stasis_app_control_queue_control (struct stasis_app_control *control, enum ast_control_frame_type frame_type)
 Queue a control frame without payload. More...
 
struct ast_bridgestasis_app_bridge_create (const char *type, const char *name, const char *id)
 Create a bridge of the specified type. More...
 
struct ast_bridgestasis_app_bridge_create_invisible (const char *type, const char *name, const char *id)
 Create an invisible bridge of the specified type. More...
 
struct ast_bridgestasis_app_bridge_find_by_id (const char *bridge_id)
 Returns the bridge with the given id. More...
 
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. More...
 
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. More...
 
struct ast_channelstasis_app_bridge_playback_channel_find (struct ast_bridge *bridge)
 Finds an existing ARI playback channel in a bridge. More...
 
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. More...
 
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. More...
 
int stasis_app_control_add_channel_to_bridge (struct stasis_app_control *control, struct ast_bridge *bridge)
 Add a channel to the bridge. More...
 
int stasis_app_control_remove_channel_from_bridge (struct stasis_app_control *control, struct ast_bridge *bridge)
 Remove a channel from the bridge. More...
 
int stasis_app_control_bridge_features_init (struct stasis_app_control *control)
 Initialize bridge features into a channel control. More...
 
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. More...
 
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. More...
 
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. More...
 
struct ast_bridgestasis_app_get_bridge (struct stasis_app_control *control)
 Gets the bridge currently associated with a control object. More...
 
void stasis_app_bridge_destroy (const char *bridge_id)
 Destroy the bridge. More...
 
struct stasis_message_sanitizerstasis_app_get_sanitizer (void)
 Get the Stasis message sanitizer for app_stasis applications. More...
 
void stasis_app_channel_set_stasis_end_published (struct ast_channel *chan)
 Indicate that this channel has had a StasisEnd published for it. More...
 
int stasis_app_channel_is_stasis_end_published (struct ast_channel *chan)
 Has this channel had a StasisEnd published on it? More...
 
int stasis_app_channel_is_internal (struct ast_channel *chan)
 Is this channel internal to Stasis? More...
 
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. More...
 
int stasis_app_channel_set_internal (struct ast_channel *chan)
 Mark this channel as being internal to Stasis. More...
 
int stasis_app_control_dial (struct stasis_app_control *control, const char *dialstring, unsigned int timeout)
 Dial a channel. More...
 
void stasis_app_control_shutdown (void)
 Let Stasis app internals shut down. More...
 
void stasis_app_set_debug (struct stasis_app *app, int debug)
 Enable/disable request/response and event logging on an application. More...
 
void stasis_app_set_debug_by_name (const char *app_name, int debug)
 Enable/disable request/response and event logging on an application. More...
 
int stasis_app_get_debug (struct stasis_app *app)
 Get debug status of an application. More...
 
int stasis_app_get_debug_by_name (const char *app_name)
 Get debug status of an application. More...
 
void stasis_app_set_global_debug (int debug)
 Enable/disable request/response and event logging on all applications. More...
 
void stasis_app_to_cli (const struct stasis_app *app, struct ast_cli_args *a)
 Dump properties of a stasis_app to the CLI. More...
 
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. More...
 
int stasis_app_event_filter_set (struct stasis_app *app, struct ast_json *filter)
 Set the application's event type filter. More...
 
int stasis_app_event_allowed (const char *app_name, struct ast_json *event)
 Check if the given event should be filtered. More...
 

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 777 of file stasis_app.h.

777  {
778  /*! The channel is okay to be added/removed */
780  /*! The channel is currently recording */
782 };

◆ 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 282 of file stasis_app.h.

◆ 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 255 of file stasis_app.h.

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 1028 of file res/stasis/app.c.

References stasis_app::topic.

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

1029 {
1030  return app->topic;
1031 }
struct stasis_topic * topic

◆ 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.
NULL on error.

Definition at line 851 of file res_stasis.c.

References bridge_create_common().

Referenced by ast_ari_bridges_create(), and ast_ari_bridges_create_with_id().

852 {
853  return bridge_create_common(type, name, id, 0);
854 }
static const char type[]
Definition: chan_ooh323.c:109
static struct ast_bridge * bridge_create_common(const char *type, const char *name, const char *id, int invisible)
Definition: res_stasis.c:795
static const char name[]
Definition: cdr_mysql.c:74

◆ 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.
NULL on error.

Definition at line 856 of file res_stasis.c.

References bridge_create_common().

Referenced by get_dial_bridge().

857 {
858  return bridge_create_common(type, name, id, 1);
859 }
static const char type[]
Definition: chan_ooh323.c:109
static struct ast_bridge * bridge_create_common(const char *type, const char *name, const char *id, int invisible)
Definition: res_stasis.c:795
static const char name[]
Definition: cdr_mysql.c:74

◆ stasis_app_bridge_destroy()

void stasis_app_bridge_destroy ( const char *  bridge_id)

Destroy the bridge.

Parameters
bridge_idUniqueid of bridge to be destroyed
Return values
non-zeroon failure
zeroon success

Definition at line 861 of file res_stasis.c.

References ao2_unlink, ast_bridge_destroy(), and stasis_app_bridge_find_by_id().

Referenced by ast_ari_bridges_destroy().

862 {
863  struct ast_bridge *bridge = stasis_app_bridge_find_by_id(bridge_id);
864  if (!bridge) {
865  return;
866  }
867  ao2_unlink(app_bridges, bridge);
868  ast_bridge_destroy(bridge, 0);
869 }
int ast_bridge_destroy(struct ast_bridge *bridge, int cause)
Destroy a bridge.
Definition: bridge.c:970
struct ao2_container * app_bridges
Definition: res_stasis.c:104
Structure that contains information about a bridge.
Definition: bridge.h:357
#define ao2_unlink(container, obj)
Definition: astobj2.h:1598
struct ast_bridge * stasis_app_bridge_find_by_id(const char *bridge_id)
Returns the bridge with the given id.
Definition: res_stasis.c:774

◆ 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 774 of file res_stasis.c.

References ao2_find, and OBJ_SEARCH_KEY.

Referenced by bridge_find(), find_bridge(), and stasis_app_bridge_destroy().

776 {
777  return ao2_find(app_bridges, bridge_id, OBJ_SEARCH_KEY);
778 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
struct ao2_container * app_bridges
Definition: res_stasis.c:104
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756

◆ 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 629 of file res_stasis.c.

References ao2_find, ao2_lock, ao2_ref, ao2_unlock, 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().

630 {
631  struct ast_channel *chan;
632  struct stasis_app_bridge_channel_wrapper *moh_wrapper;
633 
635  moh_wrapper = ao2_find(app_bridges_moh, bridge->uniqueid, OBJ_SEARCH_KEY | OBJ_NOLOCK);
636  if (!moh_wrapper) {
637  chan = bridge_moh_create(bridge);
638  }
640 
641  if (moh_wrapper) {
642  chan = ast_channel_get_by_name(moh_wrapper->channel_id);
643  ao2_ref(moh_wrapper, -1);
644  }
645 
646  return chan;
647 }
Main Channel structure associated with a channel.
const ast_string_field uniqueid
Definition: bridge.h:409
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
struct ao2_container * app_bridges_moh
Definition: res_stasis.c:106
Assume that the ao2_container is already locked.
Definition: astobj2.h:1067
static struct ast_channel * bridge_moh_create(struct ast_bridge *bridge)
Definition: res_stasis.c:574
#define ao2_unlock(a)
Definition: astobj2.h:730
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718
const ast_string_field channel_id
Definition: res_stasis.c:425
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454

◆ 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 649 of file res_stasis.c.

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

Referenced by ast_ari_bridges_stop_moh().

650 {
651  struct stasis_app_bridge_channel_wrapper *moh_wrapper;
652  struct ast_channel *chan;
653 
654  moh_wrapper = ao2_find(app_bridges_moh, bridge->uniqueid, OBJ_SEARCH_KEY | OBJ_UNLINK);
655  if (!moh_wrapper) {
656  return -1;
657  }
658 
659  chan = ast_channel_get_by_name(moh_wrapper->channel_id);
660  ao2_ref(moh_wrapper, -1);
661  if (!chan) {
662  return -1;
663  }
664 
665  ast_moh_stop(chan);
667  ao2_cleanup(chan);
668 
669  return 0;
670 }
Main Channel structure associated with a channel.
const ast_string_field uniqueid
Definition: bridge.h:409
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
struct ao2_container * app_bridges_moh
Definition: res_stasis.c:106
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition: channel.c:7876
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:105
#define ao2_ref(o, delta)
Definition: astobj2.h:464
int ast_softhangup(struct ast_channel *chan, int reason)
Softly hangup up a channel.
Definition: channel.c:2476
const ast_string_field channel_id
Definition: res_stasis.c:425
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454

◆ 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)
Return values
-1failed to add channel for any reason
0on success

Definition at line 705 of file res_stasis.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_cleanup, ao2_link, ast_bridge_set_after_callback(), ast_channel_uniqueid(), ast_free, ast_strdup, ast_string_field_init, ast_string_field_set, 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().

708 {
710  char *bridge_id = ast_strdup(bridge->uniqueid);
711 
712  if (!bridge_id) {
713  return -1;
714  }
715 
718  ast_free(bridge_id);
719  return -1;
720  }
721 
722  new_wrapper = ao2_alloc_options(sizeof(*new_wrapper),
724  if (!new_wrapper) {
725  return -1;
726  }
727 
728  if (ast_string_field_init(new_wrapper, 32)) {
729  return -1;
730  }
731 
732  ast_string_field_set(new_wrapper, bridge_id, bridge->uniqueid);
733  ast_string_field_set(new_wrapper, channel_id, ast_channel_uniqueid(chan));
734 
735  if (!ao2_link(app_bridges_playback, new_wrapper)) {
736  return -1;
737  }
738 
739  ao2_link(app_controls, control);
740  return 0;
741 }
static void playback_after_bridge_cb(struct ast_channel *chan, void *data)
Definition: res_stasis.c:698
const ast_string_field uniqueid
Definition: bridge.h:409
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
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.
Definition: bridge_after.c:259
struct ao2_container * app_controls
Definition: res_stasis.c:102
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
const char * ast_channel_uniqueid(const struct ast_channel *chan)
struct ao2_container * app_bridges_playback
Definition: res_stasis.c:108
#define ast_free(a)
Definition: astmm.h:182
static void playback_after_bridge_cb_failed(enum ast_bridge_after_cb_reason reason, void *data)
Definition: res_stasis.c:691
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static void stasis_app_bridge_channel_wrapper_destructor(void *obj)
Definition: res_stasis.c:455
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514
#define ao2_link(container, obj)
Definition: astobj2.h:1549

◆ 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 759 of file res_stasis.c.

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

Referenced by ari_bridges_handle_play().

760 {
761  struct stasis_app_bridge_channel_wrapper *playback_wrapper;
762  struct ast_channel *chan;
763 
764  playback_wrapper = ao2_find(app_bridges_playback, bridge->uniqueid, OBJ_SEARCH_KEY);
765  if (!playback_wrapper) {
766  return NULL;
767  }
768 
769  chan = ast_channel_get_by_name(playback_wrapper->channel_id);
770  ao2_ref(playback_wrapper, -1);
771  return chan;
772 }
Main Channel structure associated with a channel.
const ast_string_field uniqueid
Definition: bridge.h:409
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ao2_container * app_bridges_playback
Definition: res_stasis.c:108
const ast_string_field channel_id
Definition: res_stasis.c:425
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454

◆ 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 743 of file res_stasis.c.

References ao2_find, ao2_ref, ao2_unlink, OBJ_SEARCH_KEY, and OBJ_UNLINK.

Referenced by ari_bridges_play_new(), and bridge_channel_control_thread().

745 {
746  struct stasis_app_bridge_channel_wrapper *wrapper;
747 
749  if (wrapper) {
750  /* If wrapper is not found, then that means the after bridge callback has been
751  * called or is in progress. No need to unlink the control here since that has
752  * been done or is about to be done in the after bridge callback
753  */
754  ao2_unlink(app_controls, control);
755  ao2_ref(wrapper, -1);
756  }
757 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
const ast_string_field bridge_id
Definition: res_stasis.c:425
struct ao2_container * app_controls
Definition: res_stasis.c:102
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ao2_container * app_bridges_playback
Definition: res_stasis.c:108
#define ao2_unlink(container, obj)
Definition: astobj2.h:1598
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756

◆ 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 2322 of file res_stasis.c.

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

Referenced by bridge_stasis_push().

2323 {
2324  struct ast_datastore *datastore;
2325  int res = 0;
2326 
2327  ast_channel_lock(chan);
2329  if (datastore) {
2330  res = 1;
2331  }
2332  ast_channel_unlock(chan);
2333 
2334  return res;
2335 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
Structure for a data store object.
Definition: datastore.h:68
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:2404
#define NULL
Definition: resample.c:96
static const struct ast_datastore_info stasis_internal_channel_info
Definition: res_stasis.c:2269
#define ast_channel_unlock(chan)
Definition: channel.h:2946

◆ 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 1299 of file res_stasis.c.

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

Referenced by internal_bridge_after_cb(), and stasis_app_exec().

1300 {
1301  struct ast_datastore *datastore;
1302 
1303  ast_channel_lock(chan);
1305  ast_channel_unlock(chan);
1306 
1307  return datastore ? 1 : 0;
1308 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
Structure for a data store object.
Definition: datastore.h:68
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:2404
struct ast_datastore_info set_end_published_info
Definition: res_stasis.c:1283
#define NULL
Definition: resample.c:96
#define ast_channel_unlock(chan)
Definition: channel.h:2946

◆ 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 2311 of file res_stasis.c.

References ast_channel_lock, ast_channel_unlock, and set_internal_datastore().

2312 {
2313  int res;
2314 
2315  ast_channel_lock(chan);
2316  res = set_internal_datastore(chan);
2317  ast_channel_unlock(chan);
2318 
2319  return res;
2320 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static int set_internal_datastore(struct ast_channel *chan)
Definition: res_stasis.c:2273

◆ 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
Thechannel that is exiting Stasis.

Definition at line 1287 of file res_stasis.c.

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

Referenced by bridge_stasis_moving(), and channel_stolen_cb().

1288 {
1289  struct ast_datastore *datastore;
1290 
1292  if (datastore) {
1293  ast_channel_lock(chan);
1294  ast_channel_datastore_add(chan, datastore);
1295  ast_channel_unlock(chan);
1296  }
1297 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
Structure for a data store object.
Definition: datastore.h:68
struct ast_datastore_info set_end_published_info
Definition: res_stasis.c:1283
#define NULL
Definition: resample.c:96
#define ast_channel_unlock(chan)
Definition: channel.h:2946
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:89
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2390

◆ 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 2288 of file res_stasis.c.

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

Referenced by bridge_moh_create(), and prepare_bridge_media_channel().

2289 {
2290  struct ast_channel *outchan = NULL, *outowner = NULL;
2291  int res = 0;
2292  struct ast_unreal_pvt *unreal_pvt = ast_channel_tech_pvt(chan);
2293 
2294  ao2_ref(unreal_pvt, +1);
2295  ast_unreal_lock_all(unreal_pvt, &outowner, &outchan);
2296  if (outowner) {
2297  res |= set_internal_datastore(outowner);
2298  ast_channel_unlock(outowner);
2299  ast_channel_unref(outowner);
2300  }
2301  if (outchan) {
2302  res |= set_internal_datastore(outchan);
2303  ast_channel_unlock(outchan);
2304  ast_channel_unref(outchan);
2305  }
2306  ao2_unlock(unreal_pvt);
2307  ao2_ref(unreal_pvt, -1);
2308  return res;
2309 }
Main Channel structure associated with a channel.
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
The base pvt structure for local channel derivatives.
Definition: core_unreal.h:91
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static int set_internal_datastore(struct ast_channel *chan)
Definition: res_stasis.c:2273
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

◆ 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 1464 of file control.c.

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

Referenced by ast_ari_bridges_add_channel().

1466 {
1467  control->bridge_features->dtmf_passthrough = !absorb;
1468 }
struct ast_bridge_features * bridge_features
Definition: control.c:68
unsigned int dtmf_passthrough

◆ 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 1383 of file control.c.

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().

1385 {
1386  ast_debug(3, "%s: Sending channel add_to_bridge command\n",
1388 
1390  control, control_add_channel_to_bridge, bridge, NULL,
1392 }
#define NULL
Definition: resample.c:96
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:1378
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
static int app_control_can_add_channel_to_bridge(struct stasis_app_control *control)
Definition: control.c:245
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:866
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:1430

◆ 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 316 of file control.c.

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

Referenced by ast_ari_bridges_add_channel().

317 {
318  char *role_dup;
319 
320  role_dup = ast_strdup(role);
321  if (!role_dup) {
322  return -1;
323  }
324 
326 
327  return 0;
328 }
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
void ast_free_ptr(void *ptr)
free() wrapper
Definition: astmm.c:1771
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:904
static int app_control_add_role(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:308

◆ 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.

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

Referenced by ast_ari_channels_answer().

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 LOG_WARNING
Definition: logger.h:274
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:898
static int app_control_answer(struct stasis_app_control *control, struct ast_channel *chan, void *data)
#define NULL
Definition: resample.c:96
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
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:1430
static ENTRY retval
Definition: hsearch.c:50

◆ 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 1451 of file control.c.

References ast_bridge_features_new(), and stasis_app_control::bridge_features.

Referenced by ast_ari_bridges_add_channel().

1453 {
1454  struct ast_bridge_features *features;
1455 
1456  features = ast_bridge_features_new();
1457  if (!features) {
1458  return 1;
1459  }
1460  control->bridge_features = features;
1461  return 0;
1462 }
Structure that contains features information.
struct ast_bridge_features * bridge_features
Definition: control.c:68
struct ast_bridge_features * ast_bridge_features_new(void)
Allocate a new bridge features struct.
Definition: bridge.c:3750

◆ 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 338 of file control.c.

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

Referenced by ast_ari_bridges_add_channel().

339 {
341 }
#define NULL
Definition: resample.c:96
static int app_control_clear_roles(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:330
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:904

◆ 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 389 of file control.c.

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().

390 {
391  struct stasis_app_control_continue_data *continue_data;
392 
393  if (!(continue_data = ast_calloc(1, sizeof(*continue_data)))) {
394  return -1;
395  }
396  ast_copy_string(continue_data->context, S_OR(context, ""), sizeof(continue_data->context));
397  ast_copy_string(continue_data->extension, S_OR(extension, ""), sizeof(continue_data->extension));
398  if (priority > 0) {
399  continue_data->priority = priority;
400  } else {
401  continue_data->priority = -1;
402  }
403 
405 
406  return 0;
407 }
static int priority
void ast_free_ptr(void *ptr)
free() wrapper
Definition: astmm.c:1771
structure to hold extensions
char context[AST_MAX_CONTEXT]
Definition: control.c:363
char extension[AST_MAX_EXTENSION]
Definition: control.c:364
static int app_control_continue(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:368
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
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:904
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ 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.

References control_create(), and NULL.

Referenced by ari_bridges_play_new(), and ast_ari_bridges_record().

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

◆ 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 1666 of file control.c.

References app_control_dial(), args, control_dial_args_alloc(), control_dial_args_destroy(), and stasis_app_send_command_async().

Referenced by ast_ari_channels_dial().

1668 {
1669  struct control_dial_args *args;
1670 
1672  if (!args) {
1673  return -1;
1674  }
1675 
1678 }
static int timeout
Definition: cdr_mysql.c:86
static struct control_dial_args * control_dial_args_alloc(const char *dialstring, unsigned int timeout)
Definition: control.c:1573
const char * args
char dialstring[0]
Definition: control.c:1570
static void control_dial_args_destroy(void *data)
Definition: control.c:1590
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:904
static int app_control_dial(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:1628

◆ 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 565 of file control.c.

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().

566 {
567  struct stasis_app_control_dtmf_data *dtmf_data;
568 
569  if (!(dtmf_data = ast_calloc(1, sizeof(*dtmf_data) + strlen(dtmf) + 1))) {
570  return -1;
571  }
572 
573  dtmf_data->before = before;
574  dtmf_data->between = between;
575  dtmf_data->duration = duration;
576  dtmf_data->after = after;
577  strcpy(dtmf_data->dtmf, dtmf);
578 
580 
581  return 0;
582 }
void ast_free_ptr(void *ptr)
free() wrapper
Definition: astmm.c:1771
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
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:904
static int app_control_dtmf(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:547

◆ 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 1250 of file res_stasis.c.

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().

1251 {
1252  while (!control_is_done(control)) {
1253  int command_count;
1254  command_count = control_dispatch_all(control, chan);
1255 
1256  ao2_lock(control);
1257 
1258  if (control_command_count(control)) {
1259  /* If the command queue isn't empty, something added to the queue before it was locked. */
1260  ao2_unlock(control);
1261  continue;
1262  }
1263 
1264  if (command_count == 0 || ast_channel_fdno(chan) == -1) {
1265  control_mark_done(control);
1266  ao2_unlock(control);
1267  break;
1268  }
1269  ao2_unlock(control);
1270  }
1271 }
void control_mark_done(struct stasis_app_control *control)
Definition: control.c:354
#define ao2_unlock(a)
Definition: astobj2.h:730
int control_command_count(struct stasis_app_control *control)
Returns the count of items in a control's command queue.
Definition: control.c:343
int control_dispatch_all(struct stasis_app_control *control, struct ast_channel *chan)
Dispatch all commands enqueued to this control.
Definition: control.c:1495
#define ao2_lock(a)
Definition: astobj2.h:718
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:348

◆ 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.

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().

340 {
341  if (chan == NULL) {
342  return NULL;
343  }
344 
346  ast_channel_uniqueid(chan));
347 }
#define NULL
Definition: resample.c:96
const char * ast_channel_uniqueid(const struct ast_channel *chan)
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

◆ 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.

References ao2_find, and OBJ_SEARCH_KEY.

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

351 {
352  return ao2_find(app_controls, channel_id, OBJ_SEARCH_KEY);
353 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
struct ao2_container * app_controls
Definition: res_stasis.c:102
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756

◆ 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.
Returns
Nothing

Definition at line 1278 of file res_stasis.c.

References control_flush_queue().

Referenced by bridge_channel_control_thread().

1279 {
1280  control_flush_queue(control);
1281 }
void control_flush_queue(struct stasis_app_control *control)
Flush the control command queue.
Definition: control.c:1482

◆ stasis_app_control_get_channel_id()

const char* stasis_app_control_get_channel_id ( const struct stasis_app_control control)

Returns the uniqueid of the channel associated with this control.

Parameters
controlControl object.
Returns
Uniqueid of the associate channel.
NULL if control is NULL.

Definition at line 1430 of file control.c.

References ast_channel_uniqueid(), and stasis_app_control::channel.

Referenced by app_control_answer(), app_control_remove_channel_from_bridge(), app_control_silence_start(), check_add_remove_channel(), control_compare(), control_hash(), control_silence_stop_now(), control_swap_channel_in_bridge(), masq_match_cb(), playback_publish(), recording_publish(), stasis_app_control_add_channel_to_bridge(), stasis_app_control_answer(), stasis_app_control_get_snapshot(), stasis_app_control_play_uri(), stasis_app_control_record(), and stasis_app_control_remove_channel_from_bridge().

1432 {
1433  return ast_channel_uniqueid(control->channel);
1434 }
struct ast_channel * channel
Definition: control.c:60
const char * ast_channel_uniqueid(const struct ast_channel *chan)

◆ 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.
NULL if channel isn't in cache.

Definition at line 860 of file control.c.

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().

862 {
864 }
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:1430
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...

◆ 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 748 of file control.c.

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

Referenced by ast_ari_channels_hold().

749 {
751 }
#define NULL
Definition: resample.c:96
static int app_control_hold(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:740
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:904

◆ 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
muteWhether COLP frames should be generated (0) or not (1).

Definition at line 1476 of file control.c.

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

Referenced by ast_ari_bridges_add_channel().

1478 {
1479  control->bridge_features->inhibit_colp = inhibit_colp;
1480 }
unsigned int inhibit_colp
struct ast_bridge_features * bridge_features
Definition: control.c:68

◆ 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 1273 of file res_stasis.c.

References control_is_done().

Referenced by ari_bridges_play_found().

1274 {
1275  return control_is_done(control);
1276 }
int control_is_done(struct stasis_app_control *control)
Returns true if control_continue() has been called on this control.
Definition: control.c:348

◆ 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 780 of file control.c.

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().

781 {
782  char *data = NULL;
783 
784  if (!ast_strlen_zero(moh_class)) {
785  data = ast_strdup(moh_class);
786  }
787 
789 }
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
void ast_free_ptr(void *ptr)
free() wrapper
Definition: astmm.c:1771
#define ast_strlen_zero(foo)
Definition: strings.h:52
static int app_control_moh_start(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:766
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:904

◆ 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 798 of file control.c.

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

Referenced by ast_ari_channels_stop_moh().

799 {
801 }
#define NULL
Definition: resample.c:96
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:904
static int app_control_moh_stop(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:791

◆ 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 451 of file control.c.

References stasis_app_control_move_data::app_args, app_control_move(), 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().

452 {
453  struct stasis_app_control_move_data *move_data;
454  size_t size;
455 
456  size = sizeof(*move_data) + strlen(app_name) + 1;
457  if (app_args) {
458  /* Application arguments are optional */
459  size += strlen(app_args) + 1;
460  }
461 
462  if (!(move_data = ast_calloc(1, size))) {
463  return -1;
464  }
465 
466  move_data->app_name = (char *)move_data + sizeof(*move_data);
467  strcpy(move_data->app_name, app_name); /* Safe */
468 
469  if (app_args) {
470  move_data->app_args = move_data->app_name + strlen(app_name) + 1;
471  strcpy(move_data->app_args, app_args); /* Safe */
472  } else {
473  move_data->app_args = NULL;
474  }
475 
477 
478  return 0;
479 }
#define NULL
Definition: resample.c:96
void ast_free_ptr(void *ptr)
free() wrapper
Definition: astmm.c:1771
static int app_control_move(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:414
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
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:904

◆ 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 631 of file control.c.

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().

632 {
633  struct stasis_app_control_mute_data *mute_data;
634 
635  if (!(mute_data = ast_calloc(1, sizeof(*mute_data)))) {
636  return -1;
637  }
638 
639  mute_data->direction = direction;
640  mute_data->frametype = frametype;
641 
643 
644  return 0;
645 }
void ast_free_ptr(void *ptr)
free() wrapper
Definition: astmm.c:1771
enum ast_frame_type frametype
Definition: control.c:615
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
static int app_control_mute(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:619
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:904
direction

◆ 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 1470 of file control.c.

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

Referenced by ast_ari_bridges_add_channel().

1472 {
1473  control->bridge_features->mute = mute;
1474 }
static int mute
Definition: chan_alsa.c:144
struct ast_bridge_features * bridge_features
Definition: control.c:68

◆ 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 1436 of file control.c.

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

Referenced by playback_publish(), and recording_publish().

1438 {
1439  if (!control || !control->channel || !message) {
1440  return;
1441  }
1442  stasis_publish(ast_channel_topic(control->channel), message);
1443 }
struct ast_channel * channel
Definition: control.c:60
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:1511

◆ 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 1445 of file control.c.

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_mute(), recording_pause(), recording_stop(), recording_unmute(), and recording_unpause().

1447 {
1448  return ast_queue_control(control->channel, frame_type);
1449 }
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
Definition: channel.c:1231
struct ast_channel * channel
Definition: control.c:60
frame_type
Definition: codec_builtin.c:44

◆ 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 500 of file control.c.

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

Referenced by ast_ari_channels_redirect().

501 {
502  char *endpoint_data = ast_strdup(endpoint);
503 
504  if (!endpoint_data) {
505  return -1;
506  }
507 
509 
510  return 0;
511 }
static int app_control_redirect(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:481
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
void ast_free_ptr(void *ptr)
free() wrapper
Definition: astmm.c:1771
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:904

◆ 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 217 of file control.c.

References stasis_app_control::add_rules, and app_control_register_rule().

Referenced by stasis_app_control_record().

220 {
221  return app_control_register_rule(control, &control->add_rules, rule);
222 }
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:162
struct app_control_rules add_rules
Definition: control.c:76

◆ 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 231 of file control.c.

References app_control_register_rule(), and stasis_app_control::remove_rules.

234 {
235  return app_control_register_rule(control, &control->remove_rules, rule);
236 }
struct app_control_rules remove_rules
Definition: control.c:80
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:162

◆ 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 1420 of file control.c.

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().

1422 {
1423  ast_debug(3, "%s: Sending channel remove_from_bridge command\n",
1426  control, app_control_remove_channel_from_bridge, bridge, NULL,
1428 }
static int app_control_can_remove_channel_from_bridge(struct stasis_app_control *control)
Definition: control.c:251
#define NULL
Definition: resample.c:96
static int app_control_remove_channel_from_bridge(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:1394
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
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:866
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:1430

◆ 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 592 of file control.c.

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

Referenced by ast_ari_channels_ring().

593 {
595 
596  return 0;
597 }
#define NULL
Definition: resample.c:96
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:904
static int app_control_ring(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:584

◆ 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 607 of file control.c.

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

Referenced by ast_ari_channels_ring_stop().

608 {
610 
611  return 0;
612 }
#define NULL
Definition: resample.c:96
static int app_control_ring_stop(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:599
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:904

◆ 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 711 of file control.c.

References app_control_set_channel_var(), ast_calloc, ast_strdup, free_chanvar(), chanvar::name, stasis_app_send_command_async(), chanvar::value, and var.

Referenced by ast_ari_channels_set_channel_var().

712 {
713  struct chanvar *var;
714 
715  var = ast_calloc(1, sizeof(*var));
716  if (!var) {
717  return -1;
718  }
719 
720  var->name = ast_strdup(variable);
721  if (!var->name) {
722  free_chanvar(var);
723  return -1;
724  }
725 
726  /* It's kosher for value to be NULL. It means the variable is being unset */
727  if (value) {
728  var->value = ast_strdup(value);
729  if (!var->value) {
730  free_chanvar(var);
731  return -1;
732  }
733  }
734 
736 
737  return 0;
738 }
#define var
Definition: ast_expr2f.c:614
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
int value
Definition: syslog.c:37
char * value
Definition: control.c:689
static int app_control_set_channel_var(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:701
static void free_chanvar(void *data)
Definition: control.c:692
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
structure for queuing ARI channel variable setting
Definition: control.c:685
char * name
Definition: control.c:687
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:904

◆ 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 1680 of file control.c.

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

Referenced by unload_module().

1681 {
1683  shutting_down = 1;
1684  if (dial_bridge) {
1686  dial_bridge = NULL;
1687  }
1689 }
int ast_bridge_destroy(struct ast_bridge *bridge, int cause)
Destroy a bridge.
Definition: bridge.c:970
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
static ast_mutex_t dial_bridge_lock
Definition: control.c:959
static int shutting_down
Indicates if the Stasis app internals are being shut down.
Definition: control.c:49
static struct ast_bridge * dial_bridge
Singleton dial bridge.
Definition: control.c:958
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ 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 832 of file control.c.

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

Referenced by ast_ari_channels_start_silence().

833 {
835 }
#define NULL
Definition: resample.c:96
static int app_control_silence_start(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:803
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:904

◆ 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 855 of file control.c.

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

Referenced by ast_ari_channels_stop_silence().

856 {
858 }
#define NULL
Definition: resample.c:96
static int app_control_silence_stop(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:848
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:904

◆ 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 761 of file control.c.

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

Referenced by ast_ari_channels_unhold().

762 {
764 }
static int app_control_unhold(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:753
#define NULL
Definition: resample.c:96
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:904

◆ 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 659 of file control.c.

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().

660 {
661  struct stasis_app_control_mute_data *mute_data;
662 
663  if (!(mute_data = ast_calloc(1, sizeof(*mute_data)))) {
664  return -1;
665  }
666 
667  mute_data->direction = direction;
668  mute_data->frametype = frametype;
669 
671 
672  return 0;
673 }
void ast_free_ptr(void *ptr)
free() wrapper
Definition: astmm.c:1771
static int app_control_unmute(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:647
enum ast_frame_type frametype
Definition: control.c:615
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
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:904
direction

◆ 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 224 of file control.c.

References stasis_app_control::add_rules, and app_control_unregister_rule().

Referenced by record_file(), and recording_fail().

227 {
228  app_control_unregister_rule(control, &control->add_rules, rule);
229 }
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:171
struct app_control_rules add_rules
Definition: control.c:76

◆ 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 238 of file control.c.

References app_control_unregister_rule(), and stasis_app_control::remove_rules.

241 {
242  app_control_unregister_rule(control, &control->remove_rules, rule);
243 }
struct app_control_rules remove_rules
Definition: control.c:80
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:171

◆ 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 1739 of file res/stasis/app.c.

References ao2_lock, ao2_ref, ao2_unlock, app, app_event_filter_matched(), stasis_app::events_allowed, stasis_app::events_disallowed, and stasis_app_get_by_name().

Referenced by stasis_app_message_handler().

1740 {
1742  int res;
1743 
1744  if (!app) {
1745  return 0;
1746  }
1747 
1748  ao2_lock(app);
1749  res = !app_event_filter_matched(app->events_disallowed, event, 0) &&
1750  app_event_filter_matched(app->events_allowed, event, 1);
1751  ao2_unlock(app);
1752  ao2_ref(app, -1);
1753 
1754  return res;
1755 }
struct ast_json * events_allowed
struct stasis_app * stasis_app_get_by_name(const char *name)
Retrieve a handle to a Stasis application by its name.
Definition: res_stasis.c:1694
#define ao2_unlock(a)
Definition: astobj2.h:730
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
struct ast_json * events_disallowed
static const char app[]
Definition: app_mysql.c:62
static int app_event_filter_matched(struct ast_json *array, struct ast_json *event, int empty)

◆ 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 1713 of file res/stasis/app.c.

References app_events_allowed_set(), and app_events_disallowed_set().

Referenced by ast_ari_applications_filter().

1714 {
1715  return app_events_disallowed_set(app, filter) || app_events_allowed_set(app, filter);
1716 }
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)

◆ 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 1641 of file res/stasis/app.c.

References ast_json_array_create(), ast_json_object_set(), ast_json_ref(), stasis_app::events_allowed, and stasis_app::events_disallowed.

Referenced by stasis_app_object_to_json().

1642 {
1643  if (!app || !json) {
1644  return json;
1645  }
1646 
1647  ast_json_object_set(json, "events_allowed", app->events_allowed ?
1649  ast_json_object_set(json, "events_disallowed", app->events_disallowed ?
1651 
1652  return json;
1653 }
struct ast_json * events_allowed
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:404
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition: json.c:352
struct ast_json * events_disallowed

◆ 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.
NULL on error.

Definition at line 1708 of file res_stasis.c.

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

Referenced by ari_show_apps(), ast_ari_applications_list(), complete_ari_app(), and stasis_app_set_global_debug().

1709 {
1710  struct ao2_container *apps;
1711 
1712  if (!apps_registry) {
1713  return NULL;
1714  }
1715 
1716  apps = ast_str_container_alloc(1);
1717  if (!apps) {
1718  return NULL;
1719  }
1720 
1722 
1723  return apps;
1724 }
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
#define ast_str_container_alloc(buckets)
Allocates a hash container for bare strings.
Definition: strings.h:1312
#define NULL
Definition: resample.c:96
static struct apps apps
static int append_name(void *obj, void *arg, int flags)
Definition: res_stasis.c:1699
struct ao2_container * apps_registry
Stasis application container.
Definition: res_stasis.c:100
Generic container type.

◆ 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.
NULL if not associated with a bridge.

Definition at line 931 of file control.c.

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().

932 {
933  struct ast_bridge *ret;
934 
935  if (!control) {
936  return NULL;
937  }
938 
939  ao2_lock(control);
940  ret = control->bridge;
941  ao2_unlock(control);
942 
943  return ret;
944 }
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
#define ao2_lock(a)
Definition: astobj2.h:718
Structure that contains information about a bridge.
Definition: bridge.h:357
struct ast_bridge * bridge
Definition: control.c:64

◆ 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.
NULL on error.

Definition at line 1694 of file res_stasis.c.

References find_app_by_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().

1695 {
1696  return find_app_by_name(name);
1697 }
static const char name[]
Definition: cdr_mysql.c:74
static struct stasis_app * find_app_by_name(const char *app_name)
Definition: res_stasis.c:1679

◆ 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 863 of file res/stasis/app.c.

References stasis_app::debug, and global_debug.

864 {
865  return (app ? app->debug : 0) || global_debug;
866 }
int 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 868 of file res/stasis/app.c.

References ao2_ref, app, stasis_app::debug, global_debug, and stasis_app_get_by_name().

Referenced by ast_ari_callback(), and stasis_app_message_handler().

869 {
870  int debug_enabled = 0;
871 
872  if (global_debug) {
873  debug_enabled = 1;
874  } else {
876 
877  if (app) {
878  if (app->debug) {
879  debug_enabled = 1;
880  }
881  ao2_ref(app, -1);
882  }
883  }
884  return debug_enabled;
885 }
struct stasis_app * stasis_app_get_by_name(const char *name)
Retrieve a handle to a Stasis application by its name.
Definition: res_stasis.c:1694
#define ao2_ref(o, delta)
Definition: astobj2.h:464
int global_debug
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
static const char app[]
Definition: app_mysql.c:62

◆ stasis_app_get_sanitizer()

struct stasis_message_sanitizer* stasis_app_get_sanitizer ( void  )

◆ 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 1156 of file res/stasis/app.c.

References stasis_app::name.

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().

1157 {
1158  return app->name;
1159 }

◆ 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.
NULL on error.

Definition at line 1866 of file res_stasis.c.

References 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().

1867 {
1868  if (!app) {
1869  return NULL;
1870  }
1871 
1873  app, app_event_sources_to_json(app, app_to_json(app)));
1874 }
#define NULL
Definition: resample.c:96
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.
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)
Definition: res_stasis.c:1850

◆ 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 1777 of file res_stasis.c.

References __stasis_app_register().

Referenced by AST_TEST_DEFINE(), and event_session_alloc().

1778 {
1780 }
static int __stasis_app_register(const char *app_name, stasis_app_cb handler, void *data, int all_events)
Definition: res_stasis.c:1726
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
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

◆ 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 1782 of file res_stasis.c.

References __stasis_app_register().

Referenced by event_session_alloc().

1783 {
1785 }
static int __stasis_app_register(const char *app_name, stasis_app_cb handler, void *data, int all_events)
Definition: res_stasis.c:1726
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
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

◆ 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 1816 of file res_stasis.c.

References AST_LIST_INSERT_TAIL, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

Referenced by load_module(), and stasis_app_register_event_sources().

1817 {
1819  AST_LIST_INSERT_TAIL(&event_sources, obj, next);
1821 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730

◆ stasis_app_register_event_sources()

void stasis_app_register_event_sources ( void  )

Register core event sources.

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

References stasis_app_register_event_source().

Referenced by load_module().

1628 {
1632 }
struct stasis_app_event_source bridge_event_source
struct stasis_app_event_source endpoint_event_source
struct stasis_app_event_source channel_event_source
void stasis_app_register_event_source(struct stasis_app_event_source *obj)
Register an application event source.
Definition: res_stasis.c:1816

◆ 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 1656 of file res_stasis.c.

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

Referenced by AST_TEST_DEFINE(), and send_device_state().

1657 {
1658  struct stasis_app *app;
1659 
1660  if (!apps_registry) {
1661  return -1;
1662  }
1663 
1665  if (!app) {
1666  /* XXX We can do a better job handling late binding, queueing up
1667  * the call for a few seconds to wait for the app to register.
1668  */
1670  "Stasis app '%s' not registered\n", app_name);
1671  return -1;
1672  }
1673  app_send(app, message);
1674  ao2_ref(app, -1);
1675 
1676  return 0;
1677 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
#define LOG_WARNING
Definition: logger.h:274
#define ast_log
Definition: astobj2.c:42
#define ao2_ref(o, delta)
Definition: astobj2.h:464
void app_send(struct stasis_app *app, struct ast_json *message)
Send a message to the given application.
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
struct ao2_container * apps_registry
Stasis application container.
Definition: res_stasis.c:100
static const char app[]
Definition: app_mysql.c:62

◆ 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 842 of file res/stasis/app.c.

References stasis_app::debug.

Referenced by ari_set_debug(), and stasis_app_set_global_debug().

843 {
844  if (!app) {
845  return;
846  }
847 
848  app->debug = debug;
849 }
static int debug
Global debug status.
Definition: res_xmpp.c:435

◆ 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 851 of file res/stasis/app.c.

References ao2_cleanup, app, stasis_app::debug, and stasis_app_get_by_name().

852 {
854 
855  if (!app) {
856  return;
857  }
858 
859  app->debug = debug;
860  ao2_cleanup(app);
861 }
struct stasis_app * stasis_app_get_by_name(const char *name)
Retrieve a handle to a Stasis application by its name.
Definition: res_stasis.c:1694
static int debug
Global debug status.
Definition: res_xmpp.c:435
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static const char app[]
Definition: app_mysql.c:62

◆ 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 887 of file res/stasis/app.c.

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

Referenced by ari_set_debug().

888 {
890  if (!global_debug) {
891  struct ao2_container *app_names = stasis_app_get_all();
892  struct ao2_iterator it_app_names;
893  char *app_name;
894  struct stasis_app *app;
895 
896  if (!app_names || !ao2_container_count(app_names)) {
897  ao2_cleanup(app_names);
898  return;
899  }
900 
901  it_app_names = ao2_iterator_init(app_names, 0);
902  while ((app_name = ao2_iterator_next(&it_app_names))) {
903  if ((app = stasis_app_get_by_name(app_name))) {
904  stasis_app_set_debug(app, 0);
905  }
906 
907  ao2_cleanup(app_name);
908  ao2_cleanup(app);
909  }
910  ao2_iterator_cleanup(&it_app_names);
911  ao2_cleanup(app_names);
912  }
913 }
struct stasis_app * stasis_app_get_by_name(const char *name)
Retrieve a handle to a Stasis application by its name.
Definition: res_stasis.c:1694
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
static int debug
Global debug status.
Definition: res_xmpp.c:435
void ao2_iterator_cleanup(struct ao2_iterator *iter)
void stasis_app_set_debug(struct stasis_app *app, int debug)
Enable/disable request/response and event logging on an application.
int global_debug
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
struct ao2_container * stasis_app_get_all(void)
Gets the names of all registered Stasis applications.
Definition: res_stasis.c:1708
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Generic container type.
static const char app[]
Definition: app_mysql.c:62
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.

◆ 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 2045 of file res_stasis.c.

References app_handle_subscriptions(), and app_subscribe().

Referenced by ast_ari_applications_subscribe().

2048 {
2049  return app_handle_subscriptions(
2050  app_name, event_source_uris, event_sources_count,
2051  json, app_subscribe);
2052 }
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
static enum stasis_app_subscribe_res app_subscribe(struct stasis_app *app, const char *uri, struct stasis_app_event_source *event_source)
Definition: res_stasis.c:2019
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)
Definition: res_stasis.c:1939

◆ 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 1984 of file res_stasis.c.

References ao2_ref, 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().

1986 {
1988  int res;
1989 
1990  if (!app) {
1991  return STASIS_ASR_APP_NOT_FOUND;
1992  }
1993 
1994  ast_debug(3, "%s: Subscribing to %s\n", app_name, ast_channel_uniqueid(chan));
1995 
1996  res = app_subscribe_channel(app, chan);
1997  ao2_ref(app, -1);
1998 
1999  if (res != 0) {
2000  ast_log(LOG_ERROR, "Error subscribing app '%s' to channel '%s'\n",
2003  }
2004 
2005  return STASIS_ASR_OK;
2006 }
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define ao2_ref(o, delta)
Definition: astobj2.h:464
const char * ast_channel_uniqueid(const struct ast_channel *chan)
#define LOG_ERROR
Definition: logger.h:285
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
int app_subscribe_channel(struct stasis_app *app, struct ast_channel *chan)
Subscribes an application to a channel.
static struct stasis_app * find_app_by_name(const char *app_name)
Definition: res_stasis.c:1679
static const char app[]
Definition: app_mysql.c:62

◆ 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 1173 of file res/stasis/app.c.

References ao2_callback, ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_next, ao2_ref, ast_cli(), bridges, channels, stasis_app::debug, endpoints, ast_cli_args::fd, FORWARD_BRIDGE, FORWARD_CHANNEL, FORWARD_ENDPOINT, stasis_app::forwards, forwards_filter_by_type(), app_forwards::id, app_forwards::interested, stasis_app::name, OBJ_MULTIPLE, STASIS_APP_SUBSCRIBE_ALL, and stasis_app::subscription_model.

Referenced by ari_show_app().

1174 {
1175  struct ao2_iterator *channels;
1176  struct ao2_iterator *endpoints;
1177  struct ao2_iterator *bridges;
1178  struct app_forwards *forward;
1180 
1181  ast_cli(a->fd, "Name: %s\n"
1182  " Debug: %s\n"
1183  " Subscription Model: %s\n",
1184  app->name,
1185  app->debug ? "Yes" : "No",
1187  "Global Resource Subscription" :
1188  "Application/Explicit Resource Subscription");
1189  ast_cli(a->fd, " Subscriptions: %d\n", ao2_container_count(app->forwards));
1190 
1191  ast_cli(a->fd, " Channels:\n");
1192  forward_type = FORWARD_CHANNEL;
1193  channels = ao2_callback(app->forwards, OBJ_MULTIPLE,
1194  forwards_filter_by_type, &forward_type);
1195  if (channels) {
1196  while ((forward = ao2_iterator_next(channels))) {
1197  ast_cli(a->fd, " %s (%d)\n", forward->id, forward->interested);
1198  ao2_ref(forward, -1);
1199  }
1200  ao2_iterator_destroy(channels);
1201  }
1202 
1203  ast_cli(a->fd, " Bridges:\n");
1204  forward_type = FORWARD_BRIDGE;
1205  bridges = ao2_callback(app->forwards, OBJ_MULTIPLE,
1206  forwards_filter_by_type, &forward_type);
1207  if (bridges) {
1208  while ((forward = ao2_iterator_next(bridges))) {
1209  ast_cli(a->fd, " %s (%d)\n", forward->id, forward->interested);
1210  ao2_ref(forward, -1);
1211  }
1212  ao2_iterator_destroy(bridges);
1213  }
1214 
1215  ast_cli(a->fd, " Endpoints:\n");
1216  forward_type = FORWARD_ENDPOINT;
1217  endpoints = ao2_callback(app->forwards, OBJ_MULTIPLE,
1218  forwards_filter_by_type, &forward_type);
1219  if (endpoints) {
1220  while ((forward = ao2_iterator_next(endpoints))) {
1221  ast_cli(a->fd, " %s (%d)\n", forward->id, forward->interested);
1222  ao2_ref(forward, -1);
1223  }
1224  ao2_iterator_destroy(endpoints);
1225  }
1226 }
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
static int forwards_filter_by_type(void *obj, void *arg, int flags)
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
struct ao2_container * forwards
const int fd
Definition: cli.h:159
static struct ao2_container * endpoints
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static struct channel_usage channels
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
static struct ao2_container * bridges
Definition: bridge.c:123
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
forward_type
enum stasis_app_subscription_model subscription_model

◆ 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.
NULL on error.

Definition at line 1876 of file res_stasis.c.

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

Referenced by append_json(), and ast_ari_applications_get().

1877 {
1879  struct ast_json *json = stasis_app_object_to_json(app);
1880 
1881  ao2_cleanup(app);
1882 
1883  return json;
1884 }
struct ast_json * stasis_app_object_to_json(struct stasis_app *app)
Return the JSON representation of a Stasis application.
Definition: res_stasis.c:1866
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Abstract JSON element (object, array, string, int, ...).
static struct stasis_app * find_app_by_name(const char *app_name)
Definition: res_stasis.c:1679
static const char app[]
Definition: app_mysql.c:62

◆ stasis_app_unregister()

void stasis_app_unregister ( const char *  app_name)

Unregister a Stasis application.

Parameters
app_nameName of the application to unregister.

Definition at line 1787 of file res_stasis.c.

References ao2_find, ao2_ref, app, app_deactivate(), ast_log, cleanup(), LOG_ERROR, and OBJ_SEARCH_KEY.

Referenced by AST_TEST_DEFINE(), and event_session_shutdown().

1788 {
1789  struct stasis_app *app;
1790 
1791  if (!app_name) {
1792  return;
1793  }
1794 
1795  if (!apps_registry) {
1796  return;
1797  }
1798 
1800  if (!app) {
1802  "Stasis app '%s' not registered\n", app_name);
1803  return;
1804  }
1805 
1806  app_deactivate(app);
1807 
1808  /* There's a decent chance that app is ready for cleanup. Go ahead
1809  * and clean up, just in case
1810  */
1811  cleanup();
1812 
1813  ao2_ref(app, -1);
1814 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
void app_deactivate(struct stasis_app *app)
Deactivates an application.
#define ast_log
Definition: astobj2.c:42
static void cleanup(void)
Clean up any old apps that we don't need any more.
Definition: res_stasis.c:327
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define LOG_ERROR
Definition: logger.h:285
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
struct ao2_container * apps_registry
Stasis application container.
Definition: res_stasis.c:100
static const char app[]
Definition: app_mysql.c:62

◆ 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 1823 of file res_stasis.c.

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().

1824 {
1825  struct stasis_app_event_source *source;
1826 
1829  if (source == obj) {
1831  break;
1832  }
1833  }
1836 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Event source information and callbacks.
Definition: stasis_app.h:174
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:569
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
struct stasis_app_event_source * next
Definition: stasis_app.h:227
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616

◆ stasis_app_unregister_event_sources()

void stasis_app_unregister_event_sources ( void  )

Unregister core event sources.

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

References stasis_app_unregister_event_source().

Referenced by unload_module().

1635 {
1639 }
struct stasis_app_event_source bridge_event_source
struct stasis_app_event_source endpoint_event_source
void stasis_app_unregister_event_source(struct stasis_app_event_source *obj)
Unregister an application event source.
Definition: res_stasis.c:1823
struct stasis_app_event_source channel_event_source

◆ 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 2086 of file res_stasis.c.

References app_handle_subscriptions(), and app_unsubscribe().

Referenced by ast_ari_applications_unsubscribe().

2089 {
2090  return app_handle_subscriptions(
2091  app_name, event_source_uris, event_sources_count,
2092  json, app_unsubscribe);
2093 }
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
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)
Definition: res_stasis.c:1939
static enum stasis_app_subscribe_res app_unsubscribe(struct stasis_app *app, const char *uri, struct stasis_app_event_source *event_source)
Definition: res_stasis.c:2064

◆ 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 2095 of file res_stasis.c.

References ao2_cleanup, ao2_ref, 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(), start_message_blob::blob, 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().

2099 {
2101  struct ast_json *blob = NULL;
2102  struct ast_multi_object_blob *multi;
2103  struct stasis_message *message;
2105  int have_channel = 0;
2106  int i;
2107 
2108  if (!app) {
2109  ast_log(LOG_WARNING, "App %s not found\n", app_name);
2111  }
2112 
2113  if (!ast_multi_user_event_type()) {
2114  return res;
2115  }
2116 
2117  if (json_variables) {
2118  struct ast_json *json_value = ast_json_string_create(event_name);
2119 
2120  if (json_value && !ast_json_object_set(json_variables, "eventname", json_value)) {
2121  blob = ast_json_ref(json_variables);
2122  }
2123  } else {
2124  blob = ast_json_pack("{s: s}", "eventname", event_name);
2125  }
2126 
2127  if (!blob) {
2128  ast_log(LOG_ERROR, "Failed to initialize blob\n");
2129 
2130  return res;
2131  }
2132 
2133  multi = ast_multi_object_blob_create(blob);
2134  ast_json_unref(blob);
2135  if (!multi) {
2136  ast_log(LOG_ERROR, "Failed to initialize multi\n");
2137 
2138  return res;
2139  }
2140 
2141  for (i = 0; i < sources_count; ++i) {
2142  const char *uri = source_uris[i];
2143  void *snapshot=NULL;
2145 
2146  if (ast_begins_with(uri, "channel:")) {
2147  type = STASIS_UMOS_CHANNEL;
2148  snapshot = ast_channel_snapshot_get_latest(uri + 8);
2149  have_channel = 1;
2150  } else if (ast_begins_with(uri, "bridge:")) {
2151  type = STASIS_UMOS_BRIDGE;
2152  snapshot = ast_bridge_get_snapshot_by_uniqueid(uri + 7);
2153  } else if (ast_begins_with(uri, "endpoint:")) {
2154  type = STASIS_UMOS_ENDPOINT;
2155  snapshot = ast_endpoint_latest_snapshot(uri + 9, NULL);
2156  } else {
2157  ast_log(LOG_WARNING, "Invalid scheme: %s\n", uri);
2158  ao2_ref(multi, -1);
2159 
2161  }
2162  if (!snapshot) {
2163  ast_log(LOG_ERROR, "Unable to get snapshot for %s\n", uri);
2164  ao2_ref(multi, -1);
2165 
2167  }
2168  ast_multi_object_blob_add(multi, type, snapshot);
2169  }
2170 
2172  ao2_ref(multi, -1);
2173 
2174  if (!message) {
2175  ast_log(LOG_ERROR, "Unable to create stasis user event message\n");
2176  return res;
2177  }
2178 
2179  /*
2180  * Publishing to two different topics is normally to be avoided -- except
2181  * in this case both are final destinations with no forwards (only listeners).
2182  * The message has to be delivered to the application topic for ARI, but a
2183  * copy is also delivered directly to the manager for AMI if there is a channel.
2184  */
2186 
2187  if (have_channel) {
2189  }
2190  ao2_ref(message, -1);
2191 
2192  return STASIS_APP_USER_OK;
2193 }
static const char type[]
Definition: chan_ooh323.c:109
struct stasis_topic * ast_app_get_topic(struct stasis_app *app)
Returns the stasis topic for an app.
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
struct ast_multi_object_blob * ast_multi_object_blob_create(struct ast_json *blob)
Create a stasis multi object blob.
Definition: stasis.c:1975
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
#define LOG_WARNING
Definition: logger.h:274
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.
#define NULL
Definition: resample.c:96
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:404
#define ast_log
Definition: astobj2.c:42
A multi object blob data structure to carry user event stasis messages.
Definition: stasis.c:1950
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268
#define ao2_ref(o, delta)
Definition: astobj2.h:464
stasis_user_multi_object_snapshot_type
Object type code for multi user object snapshots.
Definition: stasis.h:1357
#define LOG_ERROR
Definition: logger.h:285
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic&#39;s subscribers.
Definition: stasis.c:1511
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition: manager.c:1720
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:2001
struct stasis_message_type * ast_multi_user_event_type(void)
Message type for custom user defined events with multi object blobs.
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...
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
stasis_app_user_event_res
Return code for stasis_app_user_event.
Definition: stasis_app.h:255
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Definition: strings.h:94
Abstract JSON element (object, array, string, int, ...).
static struct stasis_app * find_app_by_name(const char *app_name)
Definition: res_stasis.c:1679
static const char app[]
Definition: app_mysql.c:62
struct ast_bridge_snapshot * ast_bridge_get_snapshot_by_uniqueid(const char *bridge_id)
Returns the current snapshot for the bridge.