Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Typedefs | Functions | Variables
manager_bridges.c File Reference

The Asterisk Management Interface - AMI (bridge event handling) More...

#include "asterisk.h"
#include "asterisk/stasis_bridges.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/manager.h"
#include "asterisk/stasis_message_router.h"
Include dependency graph for manager_bridges.c:

Go to the source code of this file.

Data Structures

struct  bridge_list_data
 

Typedefs

typedef 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. More...
 

Functions

struct ast_strast_manager_build_bridge_state_string (const struct ast_bridge_snapshot *snapshot)
 Generate the AMI message body from a bridge snapshot. More...
 
struct ast_strast_manager_build_bridge_state_string_prefix (const struct ast_bridge_snapshot *snapshot, const char *prefix)
 Generate the AMI message body from a bridge snapshot. More...
 
static struct ast_manager_event_blobbridge_create (struct ast_bridge_snapshot *old_snapshot, struct ast_bridge_snapshot *new_snapshot)
 Handle bridge creation. More...
 
static struct ast_manager_event_blobbridge_destroy (struct ast_bridge_snapshot *old_snapshot, struct ast_bridge_snapshot *new_snapshot)
 Handle bridge destruction. More...
 
static void bridge_merge_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void bridge_snapshot_update (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static struct ast_manager_event_blobbridge_video_update (struct ast_bridge_snapshot *old_snapshot, struct ast_bridge_snapshot *new_snapshot)
 
static void channel_enter_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void channel_leave_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static int manager_bridge_destroy (struct mansession *s, const struct message *m)
 
static int manager_bridge_info (struct mansession *s, const struct message *m)
 
static int manager_bridge_kick (struct mansession *s, const struct message *m)
 
static int manager_bridges_list (struct mansession *s, const struct message *m)
 
static void manager_bridging_cleanup (void)
 
int manager_bridging_init (void)
 Initialize support for AMI channel events. More...
 
static int send_bridge_info_item_cb (void *obj, void *arg, void *data, int flags)
 
static int send_bridge_list_item_cb (void *obj, void *arg, void *data, int flags)
 

Variables

bridge_snapshot_monitor bridge_monitors []
 
static struct stasis_message_routerbridge_state_router
 Message router for cached bridge state snapshot updates. More...
 
static struct stasis_forwardtopic_forwarder
 The Stasis Message Bus API subscription returned by the forwarding of the channel topic to the manager topic. More...
 

Detailed Description

The Asterisk Management Interface - AMI (bridge event handling)

Author
Kinsey Moore kmoor.nosp@m.e@di.nosp@m.gium..nosp@m.com

Definition in file manager_bridges.c.

Typedef Documentation

◆ bridge_snapshot_monitor

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

Definition at line 274 of file manager_bridges.c.

Function Documentation

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

Since
12
Parameters
snapshotthe bridge snapshot for which to generate an AMI message body
Return values
NULLon error
ast_str*on success (must be ast_freed by caller)

Definition at line 267 of file manager_bridges.c.

References ast_manager_build_bridge_state_string_prefix().

Referenced by blind_transfer_to_ami(), bridge_snapshot_update(), channel_enter_cb(), channel_leave_cb(), confbridge_publish_manager_event(), manager_bridge_info(), and send_bridge_list_item_cb().

269 {
271 }
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.

◆ ast_manager_build_bridge_state_string_prefix()

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.

Since
12
Parameters
snapshotthe bridge snapshot for which to generate an AMI message body
prefixWhat to prepend to the bridge fields
Return values
NULLon error
ast_str*on success (must be ast_freed by caller)

Definition at line 223 of file manager_bridges.c.

References AST_BRIDGE_VIDEO_MODE_NONE, ast_bridge_video_mode_to_string(), ast_free, ast_str_append(), ast_str_create, ast_str_set(), ast_strlen_zero, ast_bridge_snapshot::creator, ast_bridge_snapshot::name, NULL, ast_bridge_snapshot::num_channels, out, ast_bridge_snapshot::subclass, ast_bridge_snapshot::technology, ast_bridge_snapshot::uniqueid, ast_bridge_snapshot::video_mode, and ast_bridge_snapshot::video_source_id.

Referenced by ast_manager_build_bridge_state_string(), attended_transfer_to_ami(), bridge_merge_cb(), and multi_object_blob_to_ami().

226 {
227  struct ast_str *out = ast_str_create(128);
228  int res;
229 
230  if (!out) {
231  return NULL;
232  }
233 
234  res = ast_str_set(&out, 0,
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",
242  prefix, snapshot->uniqueid,
243  prefix, snapshot->subclass,
244  prefix, snapshot->technology,
245  prefix, ast_strlen_zero(snapshot->creator) ? "<unknown>": snapshot->creator,
246  prefix, ast_strlen_zero(snapshot->name) ? "<unknown>": snapshot->name,
247  prefix, snapshot->num_channels,
249  if (!res) {
250  ast_free(out);
251  return NULL;
252  }
253 
254  if (snapshot->video_mode != AST_BRIDGE_VIDEO_MODE_NONE
255  && !ast_strlen_zero(snapshot->video_source_id)) {
256  res = ast_str_append(&out, 0, "%sBridgeVideoSource: %s\r\n",
257  prefix, snapshot->video_source_id);
258  if (!res) {
259  ast_free(out);
260  return NULL;
261  }
262  }
263 
264  return out;
265 }
const ast_string_field video_source_id
Definition: bridge.h:336
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
#define NULL
Definition: resample.c:96
const ast_string_field creator
Definition: bridge.h:336
#define ast_strlen_zero(foo)
Definition: strings.h:52
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
const ast_string_field technology
Definition: bridge.h:336
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.
Definition: bridge.c:4018
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
const ast_string_field name
Definition: bridge.h:336
enum ast_bridge_video_mode_type video_mode
Definition: bridge.h:349
#define ast_free(a)
Definition: astmm.h:182
const ast_string_field uniqueid
Definition: bridge.h:336
unsigned int num_channels
Definition: bridge.h:345
FILE * out
Definition: utils/frame.c:33
const ast_string_field subclass
Definition: bridge.h:336
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620
static char prefix[MAX_PREFIX]
Definition: http.c:141

◆ bridge_create()

static struct ast_manager_event_blob* bridge_create ( struct ast_bridge_snapshot old_snapshot,
struct ast_bridge_snapshot new_snapshot 
)
static

Handle bridge creation.

Definition at line 279 of file manager_bridges.c.

References ast_manager_event_blob_create(), EVENT_FLAG_CALL, NO_EXTRA_FIELDS, and NULL.

282 {
283  if (!new_snapshot || old_snapshot) {
284  return NULL;
285  }
286 
288  EVENT_FLAG_CALL, "BridgeCreate", NO_EXTRA_FIELDS);
289 }
#define EVENT_FLAG_CALL
Definition: manager.h:72
#define NULL
Definition: resample.c:96
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.
Definition: manager.c:9727
#define NO_EXTRA_FIELDS
Definition: manager.h:522

◆ bridge_destroy()

static struct ast_manager_event_blob* bridge_destroy ( struct ast_bridge_snapshot old_snapshot,
struct ast_bridge_snapshot new_snapshot 
)
static

Handle bridge destruction.

Definition at line 311 of file manager_bridges.c.

References ast_manager_event_blob_create(), EVENT_FLAG_CALL, NO_EXTRA_FIELDS, and NULL.

314 {
315  if (new_snapshot || !old_snapshot) {
316  return NULL;
317  }
318 
320  EVENT_FLAG_CALL, "BridgeDestroy", NO_EXTRA_FIELDS);
321 }
#define EVENT_FLAG_CALL
Definition: manager.h:72
#define NULL
Definition: resample.c:96
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.
Definition: manager.c:9727
#define NO_EXTRA_FIELDS
Definition: manager.h:522

◆ bridge_merge_cb()

static void bridge_merge_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 362 of file manager_bridges.c.

References ast_assert, ast_free, ast_manager_build_bridge_state_string_prefix(), ast_str_buffer(), EVENT_FLAG_CALL, ast_bridge_merge_message::from, manager_event, NULL, RAII_VAR, stasis_message_data(), and ast_bridge_merge_message::to.

Referenced by manager_bridging_init().

364 {
365  struct ast_bridge_merge_message *merge_msg = stasis_message_data(message);
366  RAII_VAR(struct ast_str *, to_text, NULL, ast_free);
367  RAII_VAR(struct ast_str *, from_text, NULL, ast_free);
368 
369  ast_assert(merge_msg->to != NULL);
370  ast_assert(merge_msg->from != NULL);
371 
372  to_text = ast_manager_build_bridge_state_string_prefix(merge_msg->to, "To");
373  from_text = ast_manager_build_bridge_state_string_prefix(merge_msg->from, "From");
374  if (!to_text || !from_text) {
375  return;
376  }
377 
378  /*** DOCUMENTATION
379  <managerEventInstance>
380  <synopsis>Raised when two bridges are merged.</synopsis>
381  <syntax>
382  <bridge_snapshot prefix="To"/>
383  <bridge_snapshot prefix="From"/>
384  </syntax>
385  </managerEventInstance>
386  ***/
387  manager_event(EVENT_FLAG_CALL, "BridgeMerge",
388  "%s"
389  "%s",
390  ast_str_buffer(to_text),
391  ast_str_buffer(from_text));
392 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define EVENT_FLAG_CALL
Definition: manager.h:72
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#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
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#define ast_free(a)
Definition: astmm.h:182
struct ast_bridge_snapshot * from
Message representing the merge of two bridges.
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.
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:248
struct ast_bridge_snapshot * to

◆ bridge_snapshot_update()

static void bridge_snapshot_update ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 329 of file manager_bridges.c.

References ao2_cleanup, ARRAY_LEN, ast_free, ast_manager_build_bridge_state_string(), ast_str_buffer(), bridge_monitors, manager_event, ast_bridge_snapshot_update::new_snapshot, NULL, ast_bridge_snapshot_update::old_snapshot, RAII_VAR, stasis_message_data(), and update().

Referenced by manager_bridging_init().

331 {
332  RAII_VAR(struct ast_str *, bridge_event_string, NULL, ast_free);
334  size_t i;
335 
336  update = stasis_message_data(message);
337 
338  for (i = 0; i < ARRAY_LEN(bridge_monitors); ++i) {
340 
341  event = bridge_monitors[i](update->old_snapshot, update->new_snapshot);
342  if (!event) {
343  continue;
344  }
345 
346  /* If we haven't already, build the channel event string */
347  if (!bridge_event_string) {
348  bridge_event_string =
350  update->new_snapshot ? update->new_snapshot : update->old_snapshot);
351  if (!bridge_event_string) {
352  return;
353  }
354  }
355 
356  manager_event(event->event_flags, event->manager_event, "%s%s",
357  ast_str_buffer(bridge_event_string),
358  event->extra_fields);
359  }
360 }
Struct containing info for an AMI event to send out.
Definition: manager.h:491
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static void update(int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, struct g726_state *state_ptr)
Definition: codec_g726.c:367
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
Definition: astman.c:222
#define NULL
Definition: resample.c:96
#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_str * ast_manager_build_bridge_state_string(const struct ast_bridge_snapshot *snapshot)
Generate the AMI message body from a bridge snapshot.
struct ast_bridge_snapshot * old_snapshot
bridge_snapshot_monitor bridge_monitors[]
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#define ast_free(a)
Definition: astmm.h:182
struct ast_bridge_snapshot * new_snapshot
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:248

◆ bridge_video_update()

static struct ast_manager_event_blob* bridge_video_update ( struct ast_bridge_snapshot old_snapshot,
struct ast_bridge_snapshot new_snapshot 
)
static

Definition at line 292 of file manager_bridges.c.

References ast_manager_event_blob_create(), EVENT_FLAG_CALL, NULL, and ast_bridge_snapshot::video_source_id.

295 {
296  if (!new_snapshot || !old_snapshot) {
297  return NULL;
298  }
299 
300  if (!strcmp(old_snapshot->video_source_id, new_snapshot->video_source_id)) {
301  return NULL;
302  }
303 
305  EVENT_FLAG_CALL, "BridgeVideoSourceUpdate",
306  "BridgePreviousVideoSource: %s\r\n",
307  old_snapshot->video_source_id);
308 }
const ast_string_field video_source_id
Definition: bridge.h:336
#define EVENT_FLAG_CALL
Definition: manager.h:72
#define NULL
Definition: resample.c:96
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.
Definition: manager.c:9727

◆ channel_enter_cb()

static void channel_enter_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 394 of file manager_bridges.c.

References ast_free, ast_json_object_get(), ast_json_string_get(), ast_manager_build_bridge_state_string(), ast_manager_build_channel_state_string(), ast_str_buffer(), ast_bridge_blob::blob, ast_bridge_blob::bridge, ast_bridge_blob::channel, EVENT_FLAG_CALL, manager_event, NULL, RAII_VAR, S_OR, and stasis_message_data().

Referenced by manager_bridging_init().

396 {
397  static const char *swap_name = "SwapUniqueid: ";
398  struct ast_bridge_blob *blob = stasis_message_data(message);
399  RAII_VAR(struct ast_str *, bridge_text, NULL, ast_free);
400  RAII_VAR(struct ast_str *, channel_text, NULL, ast_free);
401  const char *swap_id;
402 
403  bridge_text = ast_manager_build_bridge_state_string(blob->bridge);
404  channel_text = ast_manager_build_channel_state_string(blob->channel);
405  if (!bridge_text || !channel_text) {
406  return;
407  }
408 
409  swap_id = ast_json_string_get(ast_json_object_get(blob->blob, "swap"));
410 
411  manager_event(EVENT_FLAG_CALL, "BridgeEnter",
412  "%s"
413  "%s"
414  "%s%s%s",
415  ast_str_buffer(bridge_text),
416  ast_str_buffer(channel_text),
417  swap_id ? swap_name : "",
418  S_OR(swap_id, ""),
419  swap_id ? "\r\n" : "");
420 }
struct ast_channel_snapshot * channel
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
struct ast_json * blob
#define EVENT_FLAG_CALL
Definition: manager.h:72
#define NULL
Definition: resample.c:96
struct ast_bridge_snapshot * bridge
#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_str * ast_manager_build_bridge_state_string(const struct ast_bridge_snapshot *snapshot)
Generate the AMI message body from a bridge snapshot.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
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.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#define ast_free(a)
Definition: astmm.h:182
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:397
#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
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:248

◆ channel_leave_cb()

static void channel_leave_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 422 of file manager_bridges.c.

References ast_free, ast_manager_build_bridge_state_string(), ast_manager_build_channel_state_string(), ast_str_buffer(), ast_bridge_blob::blob, ast_bridge_blob::bridge, ast_bridge_blob::channel, EVENT_FLAG_CALL, manager_event, NULL, RAII_VAR, and stasis_message_data().

Referenced by manager_bridging_init().

424 {
425  struct ast_bridge_blob *blob = stasis_message_data(message);
426  RAII_VAR(struct ast_str *, bridge_text, NULL, ast_free);
427  RAII_VAR(struct ast_str *, channel_text, NULL, ast_free);
428 
429  bridge_text = ast_manager_build_bridge_state_string(blob->bridge);
430  channel_text = ast_manager_build_channel_state_string(blob->channel);
431  if (!bridge_text || !channel_text) {
432  return;
433  }
434 
435  manager_event(EVENT_FLAG_CALL, "BridgeLeave",
436  "%s"
437  "%s",
438  ast_str_buffer(bridge_text),
439  ast_str_buffer(channel_text));
440 }
struct ast_channel_snapshot * channel
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
struct ast_json * blob
#define EVENT_FLAG_CALL
Definition: manager.h:72
#define NULL
Definition: resample.c:96
struct ast_bridge_snapshot * bridge
#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_str * ast_manager_build_bridge_state_string(const struct ast_bridge_snapshot *snapshot)
Generate the AMI message body from a bridge snapshot.
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.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#define ast_free(a)
Definition: astmm.h:182
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:248

◆ manager_bridge_destroy()

static int manager_bridge_destroy ( struct mansession s,
const struct message m 
)
static

Definition at line 604 of file manager_bridges.c.

References ast_bridge_destroy(), ast_bridge_find_by_id(), ast_strlen_zero, astman_get_header(), astman_send_ack(), and astman_send_error().

Referenced by manager_bridging_init().

605 {
606  const char *bridge_uniqueid = astman_get_header(m, "BridgeUniqueid");
607  struct ast_bridge *bridge;
608 
609  if (ast_strlen_zero(bridge_uniqueid)) {
610  astman_send_error(s, m, "BridgeUniqueid must be provided");
611  return 0;
612  }
613 
614  bridge = ast_bridge_find_by_id(bridge_uniqueid);
615  if (!bridge) {
616  astman_send_error(s, m, "Specified BridgeUniqueid not found");
617  return 0;
618  }
619  ast_bridge_destroy(bridge, 0);
620 
621  astman_send_ack(s, m, "Bridge has been destroyed");
622 
623  return 0;
624 }
struct ast_bridge * ast_bridge_find_by_id(const char *bridge_id)
Find bridge by id.
Definition: bridge.c:5070
int ast_bridge_destroy(struct ast_bridge *bridge, int cause)
Destroy a bridge.
Definition: bridge.c:970
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
const char * astman_get_header(const struct message *m, char *var)
Get header from mananger transaction.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
Structure that contains information about a bridge.
Definition: bridge.h:357
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ manager_bridge_info()

static int manager_bridge_info ( struct mansession s,
const struct message m 
)
static

Definition at line 555 of file manager_bridges.c.

References ao2_callback_data, ao2_cleanup, ast_bridge_get_snapshot_by_uniqueid(), ast_free, ast_manager_build_bridge_state_string(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_strlen_zero, astman_append(), astman_get_header(), astman_send_error(), astman_send_list_complete_end(), astman_send_list_complete_start(), astman_send_listack(), bridge_list_data::count, bridge_list_data::id_text, NULL, OBJ_NODATA, RAII_VAR, and send_bridge_info_item_cb().

Referenced by manager_bridging_init().

556 {
557  const char *id = astman_get_header(m, "ActionID");
558  const char *bridge_uniqueid = astman_get_header(m, "BridgeUniqueid");
559  RAII_VAR(struct ast_str *, bridge_info, NULL, ast_free);
560  RAII_VAR(struct ast_bridge_snapshot *, snapshot, NULL, ao2_cleanup);
561  struct bridge_list_data list_data = { 0 };
562 
563  if (ast_strlen_zero(bridge_uniqueid)) {
564  astman_send_error(s, m, "BridgeUniqueid must be provided");
565  return 0;
566  }
567 
568  snapshot = ast_bridge_get_snapshot_by_uniqueid(bridge_uniqueid);
569  if (!snapshot) {
570  astman_send_error(s, m, "Specified BridgeUniqueid not found");
571  return 0;
572  }
573 
574  bridge_info = ast_manager_build_bridge_state_string(snapshot);
575  if (!bridge_info) {
576  astman_send_error(s, m, "Internal error");
577  return -1;
578  }
579 
580  list_data.id_text = ast_str_create(128);
581  if (!list_data.id_text) {
582  astman_send_error(s, m, "Internal error");
583  return -1;
584  }
585 
586  if (!ast_strlen_zero(id)) {
587  ast_str_set(&list_data.id_text, 0, "ActionID: %s\r\n", id);
588  }
589 
590  astman_send_listack(s, m, "Bridge channel listing will follow", "start");
591 
592  ao2_callback_data(snapshot->channels, OBJ_NODATA, send_bridge_info_item_cb, s, &list_data);
593 
594  astman_send_list_complete_start(s, m, "BridgeInfoComplete", list_data.count);
595  if (!ast_strlen_zero(ast_str_buffer(bridge_info))) {
596  astman_append(s, "%s", ast_str_buffer(bridge_info));
597  }
599  ast_free(list_data.id_text);
600 
601  return 0;
602 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
void astman_send_list_complete_start(struct mansession *s, const struct message *m, const char *event_name, int count)
Start the list complete event.
Definition: manager.c:3237
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
Structure that contains a snapshot of information about a bridge.
Definition: bridge.h:322
#define NULL
Definition: resample.c:96
const char * astman_get_header(const struct message *m, char *var)
Get header from mananger transaction.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
void astman_send_list_complete_end(struct mansession *s)
End the list complete event.
Definition: manager.c:3245
#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_str * ast_manager_build_bridge_state_string(const struct ast_bridge_snapshot *snapshot)
Generate the AMI message body from a bridge snapshot.
struct ast_str * id_text
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ao2_callback_data(container, flags, cb_fn, arg, data)
Definition: astobj2.h:1743
static int send_bridge_info_item_cb(void *obj, void *arg, void *data, int flags)
#define ast_free(a)
Definition: astmm.h:182
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
struct ast_bridge_snapshot * ast_bridge_get_snapshot_by_uniqueid(const char *bridge_id)
Returns the current snapshot for the bridge.
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620
void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag)
Send ack in manager transaction to begin a list.
Definition: manager.c:3201

◆ manager_bridge_kick()

static int manager_bridge_kick ( struct mansession s,
const struct message m 
)
static

Definition at line 626 of file manager_bridges.c.

References ao2_cleanup, ast_bridge_find_by_id(), AST_BRIDGE_FLAG_INVISIBLE, ast_bridge_kick(), ast_channel_get_bridge(), ast_channel_get_by_name(), ast_channel_lock, ast_channel_unlock, ast_strlen_zero, ast_test_flag, astman_get_header(), astman_send_ack(), astman_send_error(), NULL, and RAII_VAR.

Referenced by manager_bridging_init().

627 {
628  const char *bridge_uniqueid = astman_get_header(m, "BridgeUniqueid");
629  const char *channel_name = astman_get_header(m, "Channel");
630  RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
632 
633  if (ast_strlen_zero(channel_name)) {
634  astman_send_error(s, m, "Channel must be provided");
635  return 0;
636  }
637 
638  channel = ast_channel_get_by_name(channel_name);
639  if (!channel) {
640  astman_send_error(s, m, "Channel does not exist");
641  return 0;
642  }
643 
644  if (ast_strlen_zero(bridge_uniqueid)) {
645  /* get the bridge from the channel */
649  if (!bridge) {
650  astman_send_error(s, m, "Channel is not in a bridge");
651  return 0;
652  }
653  } else {
654  bridge = ast_bridge_find_by_id(bridge_uniqueid);
655  if (!bridge || ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) {
656  astman_send_error(s, m, "Bridge not found");
657  return 0;
658  }
659  }
660 
661  if (ast_bridge_kick(bridge, channel)) {
662  astman_send_error(s, m, "Channel kick from bridge failed");
663  return 0;
664  }
665 
666  astman_send_ack(s, m, "Channel has been kicked");
667  return 0;
668 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
Main Channel structure associated with a channel.
struct ast_bridge * ast_bridge_find_by_id(const char *bridge_id)
Find bridge by id.
Definition: bridge.c:5070
#define ast_test_flag(p, flag)
Definition: utils.h:63
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
Definition: muted.c:95
#define NULL
Definition: resample.c:96
const char * astman_get_header(const struct message *m, char *var)
Get header from mananger transaction.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct ast_bridge * ast_channel_get_bridge(const struct ast_channel *chan)
Get the bridge associated with a channel.
Definition: channel.c:10735
#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
Structure that contains information about a bridge.
Definition: bridge.h:357
#define ast_channel_unlock(chan)
Definition: channel.h:2946
int ast_bridge_kick(struct ast_bridge *bridge, struct ast_channel *chan)
Kick a channel from a bridge.
Definition: bridge.c:2025
#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
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ manager_bridges_list()

static int manager_bridges_list ( struct mansession s,
const struct message m 
)
static

Definition at line 484 of file manager_bridges.c.

References ao2_callback_data, ao2_ref, ast_bridges(), ast_free, ast_str_create, ast_str_set(), ast_strlen_zero, astman_get_header(), astman_send_error(), astman_send_list_complete_end(), astman_send_list_complete_start(), astman_send_listack(), bridges, bridge_list_data::count, bridge_list_data::id_text, OBJ_NODATA, send_bridge_list_item_cb(), and bridge_list_data::type_filter.

Referenced by manager_bridging_init().

485 {
486  const char *id = astman_get_header(m, "ActionID");
487  const char *type_filter = astman_get_header(m, "BridgeType");
488  struct ao2_container *bridges;
489  struct bridge_list_data list_data = { 0 };
490 
491  bridges = ast_bridges();
492  if (!bridges) {
493  astman_send_error(s, m, "Internal error");
494  return -1;
495  }
496 
497  list_data.id_text = ast_str_create(128);
498  if (!list_data.id_text) {
499  ao2_ref(bridges, -1);
500  astman_send_error(s, m, "Internal error");
501  return -1;
502  }
503 
504  if (!ast_strlen_zero(id)) {
505  ast_str_set(&list_data.id_text, 0, "ActionID: %s\r\n", id);
506  }
507  list_data.type_filter = type_filter;
508 
509  astman_send_listack(s, m, "Bridge listing will follow", "start");
510 
511  ao2_callback_data(bridges, OBJ_NODATA, send_bridge_list_item_cb, s, &list_data);
512 
513  astman_send_list_complete_start(s, m, "BridgeListComplete", list_data.count);
515 
516  ast_free(list_data.id_text);
517  ao2_ref(bridges, -1);
518 
519  return 0;
520 }
struct ao2_container * ast_bridges(void)
Returns the global bridges container.
Definition: bridge.c:174
const char * type_filter
void astman_send_list_complete_start(struct mansession *s, const struct message *m, const char *event_name, int count)
Start the list complete event.
Definition: manager.c:3237
const char * astman_get_header(const struct message *m, char *var)
Get header from mananger transaction.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
void astman_send_list_complete_end(struct mansession *s)
End the list complete event.
Definition: manager.c:3245
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static int send_bridge_list_item_cb(void *obj, void *arg, void *data, int flags)
struct ast_str * id_text
#define ao2_callback_data(container, flags, cb_fn, arg, data)
Definition: astobj2.h:1743
static struct ao2_container * bridges
Definition: bridge.c:123
#define ast_free(a)
Definition: astmm.h:182
Generic container type.
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620
void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag)
Send ack in manager transaction to begin a list.
Definition: manager.c:3201

◆ manager_bridging_cleanup()

static void manager_bridging_cleanup ( void  )
static

Definition at line 670 of file manager_bridges.c.

References ast_manager_unregister(), NULL, and stasis_forward_cancel().

Referenced by manager_bridging_init().

671 {
674 
675  ast_manager_unregister("BridgeList");
676  ast_manager_unregister("BridgeInfo");
677  ast_manager_unregister("BridgeDestroy");
678  ast_manager_unregister("BridgeKick");
679 }
#define NULL
Definition: resample.c:96
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition: manager.c:7258
struct stasis_forward * stasis_forward_cancel(struct stasis_forward *forward)
Definition: stasis.c:1548
static struct stasis_forward * topic_forwarder
The Stasis Message Bus API subscription returned by the forwarding of the channel topic to the manage...

◆ manager_bridging_init()

int manager_bridging_init ( void  )

Initialize support for AMI channel events.

Returns
0 on success.
non-zero on error.
Since
12

Definition at line 681 of file manager_bridges.c.

References ast_bridge_merge_message_type(), ast_bridge_snapshot_type(), ast_bridge_topic_all(), ast_channel_entered_bridge_type(), ast_channel_left_bridge_type(), ast_manager_get_message_router(), ast_manager_get_topic(), ast_manager_register_xml_core, ast_register_cleanup(), bridge_merge_cb(), bridge_snapshot_update(), channel_enter_cb(), channel_leave_cb(), manager_bridge_destroy(), manager_bridge_info(), manager_bridge_kick(), manager_bridges_list(), manager_bridging_cleanup(), manager_topic, NULL, stasis_forward_all(), and stasis_message_router_add().

Referenced by subscribe_all().

682 {
683  int ret = 0;
684  struct stasis_topic *manager_topic;
685  struct stasis_topic *bridge_topic;
686 
687  if (bridge_state_router) {
688  /* Already initialized */
689  return 0;
690  }
691 
693 
694  manager_topic = ast_manager_get_topic();
695  if (!manager_topic) {
696  return -1;
697  }
698 
699  bridge_topic = ast_bridge_topic_all();
700  if (!bridge_topic) {
701  return -1;
702  }
703 
704  topic_forwarder = stasis_forward_all(bridge_topic, manager_topic);
705  if (!topic_forwarder) {
706  return -1;
707  }
708 
710  if (!bridge_state_router) {
711  return -1;
712  }
713 
716 
719 
722 
725 
726  ret |= ast_manager_register_xml_core("BridgeList", 0, manager_bridges_list);
727  ret |= ast_manager_register_xml_core("BridgeInfo", 0, manager_bridge_info);
728  ret |= ast_manager_register_xml_core("BridgeDestroy", 0, manager_bridge_destroy);
729  ret |= ast_manager_register_xml_core("BridgeKick", 0, manager_bridge_kick);
730 
731  /* If somehow we failed to add any routes, just shut down the whole
732  * thing and fail it.
733  */
734  if (ret) {
736  return -1;
737  }
738 
739  return 0;
740 }
struct stasis_message_type * ast_bridge_snapshot_type(void)
Message type for ast_bridge_snapshot.
struct stasis_message_type * ast_channel_entered_bridge_type(void)
Message type for channel enter bridge blob messages.
static void channel_enter_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
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 stasis_message_type * ast_channel_left_bridge_type(void)
Message type for channel leave bridge blob messages.
#define NULL
Definition: resample.c:96
static struct stasis_topic * manager_topic
A stasis_topic that all topics AMI cares about will be forwarded to.
Definition: manager.c:1490
#define ast_manager_register_xml_core(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:197
static int manager_bridge_destroy(struct mansession *s, const struct message *m)
static int manager_bridge_info(struct mansession *s, const struct message *m)
struct stasis_message_type * ast_bridge_merge_message_type(void)
Message type for ast_bridge_merge_message.
static void bridge_snapshot_update(void *data, struct stasis_subscription *sub, struct stasis_message *message)
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
static void manager_bridging_cleanup(void)
static int manager_bridge_kick(struct mansession *s, const struct message *m)
struct stasis_message_router * ast_manager_get_message_router(void)
Get the stasis_message_router for AMI.
Definition: manager.c:1725
static void bridge_merge_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition: manager.c:1720
struct stasis_topic * ast_bridge_topic_all(void)
A topic which publishes the events for all bridges.
static int manager_bridges_list(struct mansession *s, const struct message *m)
static struct stasis_message_router * bridge_state_router
Message router for cached bridge state snapshot updates.
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.
Definition: stasis.c:1578
static void channel_leave_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)

◆ send_bridge_info_item_cb()

static int send_bridge_info_item_cb ( void *  obj,
void *  arg,
void *  data,
int  flags 
)
static

Definition at line 522 of file manager_bridges.c.

References ao2_cleanup, AST_CHAN_TP_INTERNAL, ast_channel_snapshot_get_latest(), ast_free, ast_manager_build_channel_state_string(), ast_str_buffer(), astman_append(), bridge_list_data::count, bridge_list_data::id_text, NULL, and RAII_VAR.

Referenced by manager_bridge_info().

523 {
524  char *uniqueid = obj;
525  struct mansession *s = arg;
526  struct bridge_list_data *list_data = data;
527  RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
528  RAII_VAR(struct ast_str *, channel_text, NULL, ast_free);
529 
530  snapshot = ast_channel_snapshot_get_latest(uniqueid);
531  if (!snapshot) {
532  return 0;
533  }
534 
535  if (snapshot->base->tech_properties & AST_CHAN_TP_INTERNAL) {
536  return 0;
537  }
538 
539  channel_text = ast_manager_build_channel_state_string(snapshot);
540  if (!channel_text) {
541  return 0;
542  }
543 
544  astman_append(s,
545  "Event: BridgeInfoChannel\r\n"
546  "%s"
547  "%s"
548  "\r\n",
549  ast_str_buffer(list_data->id_text),
550  ast_str_buffer(channel_text));
551  ++list_data->count;
552  return 0;
553 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
Structure representing a snapshot of channel state.
#define NULL
Definition: resample.c:96
#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
In case you didn&#39;t read that giant block of text above the mansession_session struct, the struct 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.
Definition: manager.c:1625
struct ast_str * id_text
Channels with this particular technology are an implementation detail of Asterisk and should generall...
Definition: channel.h:972
struct ast_str * ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
Generate the AMI message body from a channel snapshot.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_free(a)
Definition: astmm.h:182
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

◆ send_bridge_list_item_cb()

static int send_bridge_list_item_cb ( void *  obj,
void *  arg,
void *  data,
int  flags 
)
static

Definition at line 448 of file manager_bridges.c.

References ao2_cleanup, ast_bridge_get_snapshot(), ast_free, ast_manager_build_bridge_state_string(), ast_str_buffer(), ast_strlen_zero, astman_append(), bridge_list_data::count, bridge_list_data::id_text, RAII_VAR, and bridge_list_data::type_filter.

Referenced by manager_bridges_list().

449 {
450  struct ast_bridge *bridge = obj;
451  RAII_VAR(struct ast_bridge_snapshot *, snapshot, ast_bridge_get_snapshot(bridge), ao2_cleanup);
452  struct mansession *s = arg;
453  struct bridge_list_data *list_data = data;
454  struct ast_str * bridge_info;
455 
456  if (!snapshot) {
457  return 0;
458  }
459 
460  if (!ast_strlen_zero(list_data->type_filter)
461  && strcmp(list_data->type_filter, snapshot->technology)) {
462  return 0;
463  }
464 
465  bridge_info = ast_manager_build_bridge_state_string(snapshot);
466  if (!bridge_info) {
467  return 0;
468  }
469 
470  astman_append(s,
471  "Event: BridgeListItem\r\n"
472  "%s"
473  "%s"
474  "\r\n",
475  ast_str_buffer(list_data->id_text),
476  ast_str_buffer(bridge_info));
477  ++list_data->count;
478 
479  ast_free(bridge_info);
480 
481  return 0;
482 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
const char * type_filter
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
Structure that contains a snapshot of information about a bridge.
Definition: bridge.h:322
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct ast_bridge_snapshot * ast_bridge_get_snapshot(struct ast_bridge *bridge)
Returns the current snapshot for the bridge.
#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_str * ast_manager_build_bridge_state_string(const struct ast_bridge_snapshot *snapshot)
Generate the AMI message body from a bridge snapshot.
In case you didn&#39;t read that giant block of text above the mansession_session struct, the struct 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.
Definition: manager.c:1625
struct ast_str * id_text
Structure that contains information about a bridge.
Definition: bridge.h:357
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_free(a)
Definition: astmm.h:182
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

Variable Documentation

◆ bridge_monitors

bridge_snapshot_monitor bridge_monitors[]
Initial value:
= {
}
static struct ast_manager_event_blob * bridge_create(struct ast_bridge_snapshot *old_snapshot, struct ast_bridge_snapshot *new_snapshot)
Handle bridge creation.
static struct ast_manager_event_blob * bridge_video_update(struct ast_bridge_snapshot *old_snapshot, struct ast_bridge_snapshot *new_snapshot)
static struct ast_manager_event_blob * bridge_destroy(struct ast_bridge_snapshot *old_snapshot, struct ast_bridge_snapshot *new_snapshot)
Handle bridge destruction.

Definition at line 323 of file manager_bridges.c.

Referenced by bridge_snapshot_update().

◆ bridge_state_router

struct stasis_message_router* bridge_state_router
static

Message router for cached bridge state snapshot updates.

Definition at line 34 of file manager_bridges.c.

◆ topic_forwarder

struct stasis_forward* topic_forwarder
static

The Stasis Message Bus API subscription returned by the forwarding of the channel topic to the manager topic.

Definition at line 221 of file manager_bridges.c.