28 #include "asterisk/stasis_bridges.h"
29 #include "asterisk/stasis_channels.h"
31 #include "asterisk/stasis_message_router.h"
235 "%sBridgeUniqueid: %s\r\n"
236 "%sBridgeType: %s\r\n"
237 "%sBridgeTechnology: %s\r\n"
238 "%sBridgeCreator: %s\r\n"
239 "%sBridgeName: %s\r\n"
240 "%sBridgeNumChannels: %u\r\n"
241 "%sBridgeVideoSourceMode: %s\r\n",
245 prefix, ast_strlen_zero(snapshot->
creator) ?
"<unknown>": snapshot->
creator,
246 prefix, ast_strlen_zero(snapshot->
name) ?
"<unknown>": snapshot->
name,
283 if (!new_snapshot || old_snapshot) {
296 if (!new_snapshot || !old_snapshot) {
305 EVENT_FLAG_CALL,
"BridgeVideoSourceUpdate",
306 "BridgePreviousVideoSource: %s\r\n",
315 if (new_snapshot || !old_snapshot) {
338 for (i = 0; i < ARRAY_LEN(bridge_monitors); ++i) {
341 event = bridge_monitors[i](update->old_snapshot, update->new_snapshot);
347 if (!bridge_event_string) {
348 bridge_event_string =
350 update->new_snapshot ? update->new_snapshot : update->old_snapshot);
351 if (!bridge_event_string) {
358 event->extra_fields);
369 ast_assert(merge_msg->
to != NULL);
370 ast_assert(merge_msg->
from != NULL);
374 if (!to_text || !from_text) {
399 static const char *swap_name =
"SwapUniqueid: ";
407 if (!bridge_text || !channel_text) {
419 swap_id ? swap_name :
"",
421 swap_id ?
"\r\n" :
"");
433 if (!bridge_text || !channel_text) {
446 const char *type_filter;
450 static int send_bridge_list_item_cb(
void *obj,
void *arg,
void *data,
int flags)
462 if (!ast_strlen_zero(list_data->type_filter)
463 && strcmp(list_data->type_filter, snapshot->technology)) {
473 "Event: BridgeListItem\r\n"
481 ast_free(bridge_info);
486 static int manager_bridges_list(
struct mansession *s,
const struct message *m)
500 if (!list_data.id_text) {
506 if (!ast_strlen_zero(
id)) {
507 ast_str_set(&list_data.id_text, 0,
"ActionID: %s\r\n",
id);
509 list_data.type_filter = type_filter;
513 ao2_callback_data(bridges,
OBJ_NODATA, send_bridge_list_item_cb, s, &list_data);
518 ast_free(list_data.id_text);
524 static int send_bridge_info_item_cb(
void *obj,
void *arg,
void *data,
int flags)
526 char *uniqueid = obj;
547 "Event: BridgeInfoChannel\r\n"
557 static int manager_bridge_info(
struct mansession *s,
const struct message *m)
565 if (ast_strlen_zero(bridge_uniqueid)) {
583 if (!list_data.id_text) {
588 if (!ast_strlen_zero(
id)) {
589 ast_str_set(&list_data.id_text, 0,
"ActionID: %s\r\n",
id);
594 ao2_callback_data(snapshot->channels,
OBJ_NODATA, send_bridge_info_item_cb, s, &list_data);
601 ast_free(list_data.id_text);
606 static int manager_bridge_destroy(
struct mansession *s,
const struct message *m)
611 if (ast_strlen_zero(bridge_uniqueid)) {
628 static int manager_bridge_kick(
struct mansession *s,
const struct message *m)
635 if (ast_strlen_zero(channel_name)) {
646 if (ast_strlen_zero(bridge_uniqueid)) {
648 ast_channel_lock(channel);
650 ast_channel_unlock(channel);
672 static void manager_bridging_cleanup(
void)
674 stasis_forward_cancel(topic_forwarder);
675 topic_forwarder = NULL;
689 if (bridge_state_router) {
697 if (!manager_topic) {
707 if (!topic_forwarder) {
712 if (!bridge_state_router) {
717 ast_bridge_snapshot_type(), bridge_snapshot_update, NULL);
720 ast_bridge_merge_message_type(), bridge_merge_cb, NULL);
723 ast_channel_entered_bridge_type(), channel_enter_cb, NULL);
726 ast_channel_left_bridge_type(), channel_leave_cb, NULL);
737 manager_bridging_cleanup();
Struct containing info for an AMI event to send out.
Main Channel structure associated with a channel.
struct ao2_container * ast_bridges(void)
Returns the global bridges container.
void astman_append(struct mansession *s, const char *fmt,...)
Channels with this particular technology are an implementation detail of Asterisk and should generall...
Asterisk main include file. File version handling, generic pbx functions.
struct ast_flags feature_flags
int stasis_message_router_add(struct stasis_message_router *router, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data)
Add a route to a message router.
struct ast_channel_snapshot * channel
struct ast_bridge * ast_bridge_find_by_id(const char *bridge_id)
Find bridge by id.
struct ast_bridge_snapshot * ast_bridge_get_snapshot_by_uniqueid(const char *uniqueid)
Returns the current snapshot for the bridge.
void astman_send_list_complete_start(struct mansession *s, const struct message *m, const char *event_name, int count)
Start the list complete event.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Structure that contains a snapshot of information about a bridge.
const ast_string_field video_source_id
int manager_bridging_init(void)
Initialize support for AMI channel events.
Structure representing a snapshot of channel state.
int ast_bridge_destroy(struct ast_bridge *bridge, int cause)
Destroy a bridge.
struct stasis_topic * ast_bridge_topic_all(void)
A topic which publishes the events for all bridges.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
static struct stasis_topic * manager_topic
A stasis_topic that all topics AMI cares about will be forwarded to.
#define ast_manager_register_xml_core(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
struct ast_manager_event_blob * ast_manager_event_blob_create(int event_flags, const char *manager_event, const char *extra_fields_fmt,...)
Construct a ast_manager_event_blob.
const ast_string_field creator
const char * astman_get_header(const struct message *m, char *var)
Get header from manager transaction.
static struct ast_manager_event_blob * bridge_create(struct ast_bridge_snapshot *old_snapshot, struct ast_bridge_snapshot *new_snapshot)
Handle bridge creation.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
struct ast_bridge_snapshot * bridge
struct ast_bridge * ast_channel_get_bridge(const struct ast_channel *chan)
Get the bridge associated with a channel.
const ast_string_field technology
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
void astman_send_list_complete_end(struct mansession *s)
End the list complete event.
const char * ast_bridge_video_mode_to_string(enum ast_bridge_video_mode_type video_mode)
Converts an enum representation of a bridge video mode to string.
struct ast_str * ast_manager_build_bridge_state_string(const struct ast_bridge_snapshot *snapshot)
Generate the AMI message body from a bridge snapshot.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
In case you didn't read that giant block of text above the mansession_session struct, the mansession is named this solely to keep the API the same in Asterisk. This structure really represents data that is different from Manager action to Manager action. The mansession_session pointer contained within points to session-specific data.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Blob of data associated with a bridge.
struct ast_str * ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
Generate the AMI message body from a channel snapshot.
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
struct ast_bridge_snapshot * ast_bridge_get_snapshot(struct ast_bridge *bridge)
Returns the current snapshot for the bridge.
Structure that contains information about a bridge.
Support for dynamic strings.
const ast_string_field name
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
enum ast_bridge_video_mode_type video_mode
struct stasis_message_router * ast_manager_get_message_router(void)
Get the stasis_message_router for AMI.
static struct ao2_container * bridges
int ast_bridge_kick(struct ast_bridge *bridge, struct ast_channel *chan)
Kick a channel from a bridge.
struct ast_manager_event_blob *(* bridge_snapshot_monitor)(struct ast_bridge_snapshot *old_snapshot, struct ast_bridge_snapshot *new_snapshot)
Typedef for callbacks that get called on channel snapshot updates.
const ast_string_field uniqueid
unsigned int num_channels
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
struct ast_bridge_snapshot * from
Message representing the merge of two bridges.
static struct ast_manager_event_blob * bridge_video_update(struct ast_bridge_snapshot *old_snapshot, struct ast_bridge_snapshot *new_snapshot)
Handle video source updates.
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...
static struct ast_manager_event_blob * bridge_destroy(struct ast_bridge_snapshot *old_snapshot, struct ast_bridge_snapshot *new_snapshot)
Handle bridge destruction.
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
static struct stasis_message_router * bridge_state_router
Message router for cached bridge state snapshot updates.
struct ast_str * ast_manager_build_bridge_state_string_prefix(const struct ast_bridge_snapshot *snapshot, const char *prefix)
Generate the AMI message body from a bridge snapshot.
static struct stasis_forward * topic_forwarder
The Stasis Message Bus API subscription returned by the forwarding of the channel topic to the manage...
struct stasis_forward * stasis_forward_all(struct stasis_topic *from_topic, struct stasis_topic *to_topic)
Create a subscription which forwards all messages from one topic to another.
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
const ast_string_field subclass
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_bridge_snapshot * to
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag)
Send ack in manager transaction to begin a list.