Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions | Variables
stasis_bridges.c File Reference

Stasis Messages and Data Types for Bridge Objects. More...

#include "asterisk.h"
#include "asterisk/astobj2.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_cache_pattern.h"
#include "asterisk/channel.h"
#include "asterisk/stasis_bridges.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/bridge.h"
#include "asterisk/bridge_technology.h"
Include dependency graph for stasis_bridges.c:

Go to the source code of this file.

Macros

#define SNAPSHOT_CHANNELS_BUCKETS   1
 

Functions

int ast_attended_transfer_message_add_app (struct ast_attended_transfer_message *transfer_msg, const char *app, struct ast_channel *replace_channel)
 Add details for an attended transfer to an application. More...
 
int ast_attended_transfer_message_add_link (struct ast_attended_transfer_message *transfer_msg, struct ast_channel *locals[2])
 Add details for an attended transfer that has a link between bridges. More...
 
int ast_attended_transfer_message_add_merge (struct ast_attended_transfer_message *transfer_msg, struct ast_bridge *final_bridge)
 Add details for a bridge merge to an attended transfer message. More...
 
int ast_attended_transfer_message_add_threeway (struct ast_attended_transfer_message *transfer_msg, struct ast_channel *survivor_channel, struct ast_bridge *survivor_bridge)
 Add details for an attended transfer that was resolved as a three-way call. More...
 
struct ast_attended_transfer_messageast_attended_transfer_message_create (int is_external, struct ast_channel *to_transferee, struct ast_bridge *transferee_bridge, struct ast_channel *to_transfer_target, struct ast_bridge *target_bridge, struct ast_channel *transferee, struct ast_channel *transfer_target)
 Create an Attended transfer message to be published. More...
 
struct ast_blind_transfer_messageast_blind_transfer_message_create (int is_external, struct ast_channel *transferer, const char *exten, const char *context)
 Create a blind transfer message to be published. More...
 
struct stasis_messageast_bridge_blob_create (struct stasis_message_type *message_type, struct ast_bridge *bridge, struct ast_channel *chan, struct ast_json *blob)
 Creates a ast_bridge_blob message. More...
 
struct stasis_messageast_bridge_blob_create_from_snapshots (struct stasis_message_type *message_type, struct ast_bridge_snapshot *bridge_snapshot, struct ast_channel_snapshot *chan_snapshot, struct ast_json *blob)
 Creates a ast_bridge_blob message from snapshots. More...
 
struct ast_bridge_snapshotast_bridge_get_snapshot (struct ast_bridge *bridge)
 Returns the current snapshot for the bridge. More...
 
struct ast_bridge_snapshotast_bridge_get_snapshot_by_uniqueid (const char *uniqueid)
 Returns the current snapshot for the bridge. More...
 
static struct ast_jsonast_bridge_merge_message_to_json (struct stasis_message *msg, const struct stasis_message_sanitizer *sanitize)
 
void ast_bridge_publish_attended_transfer (struct ast_attended_transfer_message *transfer_msg)
 Publish an attended transfer. More...
 
void ast_bridge_publish_blind_transfer (struct ast_blind_transfer_message *transfer_message)
 Publish a blind transfer event. More...
 
void ast_bridge_publish_enter (struct ast_bridge *bridge, struct ast_channel *chan, struct ast_channel *swap)
 Publish a bridge channel enter event. More...
 
void ast_bridge_publish_leave (struct ast_bridge *bridge, struct ast_channel *chan)
 Publish a bridge channel leave event. More...
 
void ast_bridge_publish_merge (struct ast_bridge *to, struct ast_bridge *from)
 Publish a bridge merge. More...
 
void ast_bridge_publish_state (struct ast_bridge *bridge)
 Publish the state of a bridge. More...
 
struct ast_bridge_snapshotast_bridge_snapshot_create (struct ast_bridge *bridge)
 Generate a snapshot of the bridge state. This is an ao2 object, so ao2_cleanup() to deallocate. More...
 
struct ast_jsonast_bridge_snapshot_to_json (const struct ast_bridge_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
 Build a JSON object from a ast_bridge_snapshot. More...
 
struct stasis_topicast_bridge_topic (struct ast_bridge *bridge)
 A topic which publishes the events for a particular bridge. More...
 
struct stasis_topicast_bridge_topic_all (void)
 A topic which publishes the events for all bridges. More...
 
static struct ast_jsonast_channel_entered_bridge_to_json (struct stasis_message *msg, const struct stasis_message_sanitizer *sanitize)
 
static struct ast_jsonast_channel_left_bridge_to_json (struct stasis_message *msg, const struct stasis_message_sanitizer *sanitize)
 
int ast_stasis_bridging_init (void)
 
static void attended_transfer_dtor (void *obj)
 
static struct ast_manager_event_blobattended_transfer_to_ami (struct stasis_message *message)
 
static struct ast_jsonattended_transfer_to_json (struct stasis_message *msg, const struct stasis_message_sanitizer *sanitize)
 
static void blind_transfer_dtor (void *obj)
 
static struct ast_manager_event_blobblind_transfer_to_ami (struct stasis_message *message)
 
static struct ast_jsonblind_transfer_to_json (struct stasis_message *msg, const struct stasis_message_sanitizer *sanitize)
 
static void bridge_blob_dtor (void *obj)
 
static void bridge_channel_snapshot_pair_cleanup (struct ast_bridge_channel_snapshot_pair *pair)
 
static int bridge_channel_snapshot_pair_init (struct ast_channel *channel, struct ast_bridge *bridge, struct ast_bridge_channel_snapshot_pair *snapshot_pair)
 
static struct ast_bridge_merge_messagebridge_merge_message_create (struct ast_bridge *to, struct ast_bridge *from)
 Bridge merge message creation helper. More...
 
static void bridge_merge_message_dtor (void *obj)
 Destructor for bridge merge messages. More...
 
static void bridge_publish_state_from_blob (struct ast_bridge *bridge, struct ast_bridge_blob *obj)
 
static void bridge_snapshot_dtor (void *obj)
 Destructor for bridge snapshots. More...
 
static struct ast_bridge_snapshot_updatebridge_snapshot_update_create (struct ast_bridge_snapshot *old, struct ast_bridge_snapshot *new)
 
static void bridge_snapshot_update_dtor (void *obj)
 
void bridge_topics_destroy (struct ast_bridge *bridge)
 
int bridge_topics_init (struct ast_bridge *bridge)
 
static const char * capability2str (uint32_t capabilities)
 
static struct ast_jsoncontainer_to_json_array (struct ao2_container *items, const struct stasis_message_sanitizer *sanitize)
 
static struct ast_jsonsimple_bridge_channel_event (const char *type, struct ast_bridge_snapshot *bridge_snapshot, struct ast_channel_snapshot *channel_snapshot, const struct timeval *tv, const struct stasis_message_sanitizer *sanitize)
 
static void stasis_bridging_cleanup (void)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_bridge_snapshot_type)
 Define bridge message types. More...
 
 STASIS_MESSAGE_TYPE_DEFN (ast_bridge_merge_message_type,.to_json=ast_bridge_merge_message_to_json)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_entered_bridge_type,.to_json=ast_channel_entered_bridge_to_json)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_left_bridge_type,.to_json=ast_channel_left_bridge_to_json)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_blind_transfer_type,.to_json=blind_transfer_to_json,.to_ami=blind_transfer_to_ami)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_attended_transfer_type,.to_json=attended_transfer_to_json,.to_ami=attended_transfer_to_ami)
 

Variables

static struct stasis_topicbridge_topic_all
 
static struct stasis_topic_poolbridge_topic_pool
 
static const char * result_strs []
 

Detailed Description

Stasis Messages and Data Types for Bridge Objects.

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

Definition in file stasis_bridges.c.

Macro Definition Documentation

◆ SNAPSHOT_CHANNELS_BUCKETS

#define SNAPSHOT_CHANNELS_BUCKETS   1

Definition at line 44 of file stasis_bridges.c.

Referenced by ast_bridge_snapshot_create().

Function Documentation

◆ ast_attended_transfer_message_add_app()

int ast_attended_transfer_message_add_app ( struct ast_attended_transfer_message transfer_msg,
const char *  app,
struct ast_channel replace_channel 
)

Add details for an attended transfer to an application.

If the transfer is sending one or more parties into an application, then this should be called to add appropriate details to the transfer message being published.

Parameters
transfer_msgThe message to add details to
appThe name of the application that the parties are being transferred to
replace_channelThe local channel that is in the bridge and running the application
Return values
0Success
-1Failure

Definition at line 1313 of file stasis_bridges.c.

References ast_attended_transfer_message::app, AST_ATTENDED_TRANSFER_DEST_APP, AST_ATTENDED_TRANSFER_DEST_LOCAL_APP, ast_channel_snapshot_get_latest(), ast_channel_uniqueid(), ast_copy_string(), ast_attended_transfer_message::dest, ast_attended_transfer_message::dest_type, and ast_attended_transfer_message::replace_channel.

Referenced by ast_bridge_transfer_attended(), and attended_transfer_bridge().

1315 {
1317 
1318  if (replace_channel) {
1319  transfer_msg->replace_channel = ast_channel_snapshot_get_latest(ast_channel_uniqueid(replace_channel));
1320  if (!transfer_msg->replace_channel) {
1321  return -1;
1322  }
1323  }
1324 
1325  ast_copy_string(transfer_msg->dest.app, app, sizeof(transfer_msg->dest.app));
1326 
1327  return 0;
1328 }
union ast_attended_transfer_message::@324 dest
struct ast_channel_snapshot * replace_channel
const char * ast_channel_uniqueid(const struct ast_channel *chan)
enum ast_attended_transfer_dest_type dest_type
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...
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
static const char app[]
Definition: app_mysql.c:62

◆ ast_attended_transfer_message_add_link()

int ast_attended_transfer_message_add_link ( struct ast_attended_transfer_message transfer_msg,
struct ast_channel locals[2] 
)

Add details for an attended transfer that has a link between bridges.

An attended transfer may be accomplished by linking two bridges together with local channels. If this is how the transfer is to be completed, call this function in order to fill in details about the transfer.

Parameters
transfer_msgThe message to add details to.
localsAn array of local channel halves that each are in one of the involved bridges.
Return values
0Success
-1Failure

Definition at line 1330 of file stasis_bridges.c.

References AST_ATTENDED_TRANSFER_DEST_LINK, ast_channel_snapshot_get_latest(), ast_channel_uniqueid(), ast_attended_transfer_message::dest, ast_attended_transfer_message::dest_type, and ast_attended_transfer_message::links.

Referenced by attended_transfer_bridge().

1332 {
1333  int i;
1334 
1336  for (i = 0; i < 2; ++i) {
1337  transfer_msg->dest.links[i] = ast_channel_snapshot_get_latest(ast_channel_uniqueid(locals[i]));
1338  if (!transfer_msg->dest.links[i]) {
1339  return -1;
1340  }
1341  }
1342 
1343  return 0;
1344 }
union ast_attended_transfer_message::@324 dest
struct ast_channel_snapshot * links[2]
const char * ast_channel_uniqueid(const struct ast_channel *chan)
enum ast_attended_transfer_dest_type dest_type
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...

◆ ast_attended_transfer_message_add_merge()

int ast_attended_transfer_message_add_merge ( struct ast_attended_transfer_message transfer_msg,
struct ast_bridge final_bridge 
)

Add details for a bridge merge to an attended transfer message.

If the transfer is accomplished by a bridge merge (or swap optimization), then this should be called on the created attended transfer message to have the appropriate details added on.

Parameters
transfer_msgThe transfer message to add details to
final_bridgeThe bridge where the surviving parties reside
Return values
0Success
-1Failure

Definition at line 1283 of file stasis_bridges.c.

References AST_ATTENDED_TRANSFER_DEST_BRIDGE_MERGE, ast_copy_string(), ast_attended_transfer_message::bridge, ast_attended_transfer_message::dest, ast_attended_transfer_message::dest_type, and ast_bridge::uniqueid.

Referenced by publish_transfer_success(), and two_bridge_attended_transfer().

1285 {
1287  ast_copy_string(transfer_msg->dest.bridge, final_bridge->uniqueid,
1288  sizeof(transfer_msg->dest.bridge));
1289 
1290  return 0;
1291 }
union ast_attended_transfer_message::@324 dest
const ast_string_field uniqueid
Definition: bridge.h:409
char bridge[AST_UUID_STR_LEN]
enum ast_attended_transfer_dest_type dest_type
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ ast_attended_transfer_message_add_threeway()

int ast_attended_transfer_message_add_threeway ( struct ast_attended_transfer_message transfer_msg,
struct ast_channel survivor_channel,
struct ast_bridge survivor_bridge 
)

Add details for an attended transfer that was resolved as a three-way call.

If the transfer results in a three-way call between the transferer, the transferee, and the transfer target, then this should be called in order to add appropriate details to the transfer message to be published.

Parameters
transfer_msgThe message to add details to
survivor_channelThe transferer channel that exists in the three-way call
survivor_bridgeThe bridge where the three-way call takes place.
Return values
0Success
-1Failure

Definition at line 1293 of file stasis_bridges.c.

References AST_ATTENDED_TRANSFER_DEST_THREEWAY, ast_channel_uniqueid(), ast_channel_snapshot::base, ast_bridge_channel_snapshot_pair::bridge_snapshot, ast_bridge_channel_snapshot_pair::channel_snapshot, ast_attended_transfer_message::dest, ast_attended_transfer_message::dest_type, ast_attended_transfer_message::threeway, ast_attended_transfer_message::to_transfer_target, ast_attended_transfer_message::to_transferee, ast_channel_snapshot_base::uniqueid, ast_bridge_snapshot::uniqueid, and ast_bridge::uniqueid.

Referenced by publish_transfer_threeway().

1295 {
1297 
1298  if (!strcmp(ast_channel_uniqueid(survivor_channel), transfer_msg->to_transferee.channel_snapshot->base->uniqueid)) {
1299  transfer_msg->dest.threeway.channel_snapshot = transfer_msg->to_transferee.channel_snapshot;
1300  } else {
1301  transfer_msg->dest.threeway.channel_snapshot = transfer_msg->to_transfer_target.channel_snapshot;
1302  }
1303 
1304  if (!strcmp(survivor_bridge->uniqueid, transfer_msg->to_transferee.bridge_snapshot->uniqueid)) {
1305  transfer_msg->dest.threeway.bridge_snapshot = transfer_msg->to_transferee.bridge_snapshot;
1306  } else {
1307  transfer_msg->dest.threeway.bridge_snapshot = transfer_msg->to_transfer_target.bridge_snapshot;
1308  }
1309 
1310  return 0;
1311 }
struct ast_channel_snapshot_base * base
union ast_attended_transfer_message::@324 dest
const ast_string_field uniqueid
Definition: bridge.h:409
const ast_string_field uniqueid
struct ast_bridge_channel_snapshot_pair to_transferee
struct ast_bridge_channel_snapshot_pair to_transfer_target
const char * ast_channel_uniqueid(const struct ast_channel *chan)
enum ast_attended_transfer_dest_type dest_type
struct ast_channel_snapshot * channel_snapshot
struct ast_bridge_channel_snapshot_pair threeway
struct ast_bridge_snapshot * bridge_snapshot
const ast_string_field uniqueid
Definition: bridge.h:336

◆ ast_attended_transfer_message_create()

struct ast_attended_transfer_message* ast_attended_transfer_message_create ( int  is_external,
struct ast_channel to_transferee,
struct ast_bridge transferee_bridge,
struct ast_channel to_transfer_target,
struct ast_bridge target_bridge,
struct ast_channel transferee,
struct ast_channel transfer_target 
)

Create an Attended transfer message to be published.

The parameters to this function are the basic necessities in order to create the initial attended transfer message.

The transferee and transfer_target parameters are optional. If not provided, then this function will attempt to determine who the transferee and transfer target are based on the input transferer channels and bridges. You typically will not need to provide an explicit transferee and transfer target channel unless your attended transfer is implemented in a strange way.

Parameters
is_externalNon-zero if the transfer was initiated by a native channel driver protocol.
to_transfereeThe transferer channel that is bridged to the transferee channel.
transferee_bridgeThe bridge between the transferer and transferee. May be NULL.
to_transfer_targetThe transferer channel that is bridged to the transfer target.
target_bridgeThe bridge between the transferer and transfer target. May be NULL.
transfereeThe channel that is being transferred. Optional.
transfer_targetThe channel that is being transferred to. Optional.
Return values
NULLFailure to allocate or create snapshots
non-NULLThe created attended transfer message

Definition at line 1226 of file stasis_bridges.c.

References ao2_alloc, ao2_cleanup, ast_bridge_peer(), ast_channel_snapshot_get_latest(), ast_channel_uniqueid(), attended_transfer_dtor(), bridge_channel_snapshot_pair_init(), NULL, ast_attended_transfer_message::target, ast_attended_transfer_message::to_transfer_target, ast_attended_transfer_message::to_transferee, and ast_attended_transfer_message::transferee.

Referenced by ast_bridge_transfer_attended(), publish_transfer_fail(), publish_transfer_success(), and publish_transfer_threeway().

1230 {
1231  struct ast_attended_transfer_message *transfer_msg;
1232 
1233  transfer_msg = ao2_alloc(sizeof(*transfer_msg), attended_transfer_dtor);
1234  if (!transfer_msg) {
1235  return NULL;
1236  }
1237 
1238  if (bridge_channel_snapshot_pair_init(to_transferee, transferee_bridge, &transfer_msg->to_transferee) ||
1239  bridge_channel_snapshot_pair_init(to_transfer_target, target_bridge, &transfer_msg->to_transfer_target)) {
1240  ao2_cleanup(transfer_msg);
1241  return NULL;
1242  }
1243 
1244  if (transferee) {
1246  if (!transfer_msg->transferee) {
1247  ao2_cleanup(transfer_msg);
1248  return NULL;
1249  }
1250  } else if (transferee_bridge) {
1251  transferee = ast_bridge_peer(transferee_bridge, to_transferee);
1252  if (transferee) {
1254  ao2_cleanup(transferee);
1255  if (!transfer_msg->transferee) {
1256  ao2_cleanup(transfer_msg);
1257  return NULL;
1258  }
1259  }
1260  }
1261 
1262  if (transfer_target) {
1263  transfer_msg->target = ast_channel_snapshot_get_latest(ast_channel_uniqueid(transfer_target));
1264  if (!transfer_msg->target) {
1265  ao2_cleanup(transfer_msg);
1266  return NULL;
1267  }
1268  } else if (target_bridge) {
1269  transfer_target = ast_bridge_peer(target_bridge, to_transfer_target);
1270  if (transfer_target) {
1271  transfer_msg->target = ast_channel_snapshot_get_latest(ast_channel_uniqueid(transfer_target));
1272  ao2_cleanup(transfer_target);
1273  if (!transfer_msg->target) {
1274  ao2_cleanup(transfer_msg);
1275  return NULL;
1276  }
1277  }
1278  }
1279 
1280  return transfer_msg;
1281 }
Message representing attended transfer.
struct ast_channel_snapshot * target
#define NULL
Definition: resample.c:96
static int bridge_channel_snapshot_pair_init(struct ast_channel *channel, struct ast_bridge *bridge, struct ast_bridge_channel_snapshot_pair *snapshot_pair)
struct ast_bridge_channel_snapshot_pair to_transferee
struct ast_channel * ast_bridge_peer(struct ast_bridge *bridge, struct ast_channel *chan)
Get the channel&#39;s bridge peer only if the bridge is two-party.
Definition: bridge.c:4142
struct ast_bridge_channel_snapshot_pair to_transfer_target
static void attended_transfer_dtor(void *obj)
struct ast_channel_snapshot * transferee
const char * ast_channel_uniqueid(const struct ast_channel *chan)
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
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

◆ ast_blind_transfer_message_create()

struct ast_blind_transfer_message* ast_blind_transfer_message_create ( int  is_external,
struct ast_channel transferer,
const char *  exten,
const char *  context 
)

Create a blind transfer message to be published.

Parameters
is_externalWhether the blind transfer was initiated externally (e.g. via AMI or native protocol)
transfererThe transferer's channel that is bridged to the transferee
bridgeThe bridge the transferer and transferee are in
contextThe destination context for the blind transfer
extenThe destination extension for the blind transfer
Return values
NULLFailure to allocate or create snapshots
non-NULLThe created blind transfer message

Definition at line 929 of file stasis_bridges.c.

References ao2_alloc, ao2_cleanup, ast_channel_snapshot_get_latest(), ast_channel_uniqueid(), ast_copy_string(), blind_transfer_dtor(), ast_blind_transfer_message::context, ast_blind_transfer_message::exten, ast_blind_transfer_message::is_external, NULL, and ast_blind_transfer_message::transferer.

Referenced by ast_bridge_transfer_blind(), and AST_TEST_DEFINE().

931 {
932  struct ast_blind_transfer_message *msg;
933 
934  msg = ao2_alloc(sizeof(*msg), blind_transfer_dtor);
935  if (!msg) {
936  return NULL;
937  }
938 
940  if (!msg->transferer) {
941  ao2_cleanup(msg);
942  return NULL;
943  }
944 
945  msg->is_external = is_external;
946  ast_copy_string(msg->context, context, sizeof(msg->context));
947  ast_copy_string(msg->exten, exten, sizeof(msg->exten));
948 
949  return msg;
950 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
char exten[AST_MAX_EXTENSION]
Message published during a blind transfer.
#define NULL
Definition: resample.c:96
static void blind_transfer_dtor(void *obj)
const char * ast_channel_uniqueid(const struct ast_channel *chan)
struct ast_channel_snapshot * transferer
char context[AST_MAX_CONTEXT]
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
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
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ ast_bridge_blob_create()

struct stasis_message* ast_bridge_blob_create ( struct stasis_message_type type,
struct ast_bridge bridge,
struct ast_channel chan,
struct ast_json blob 
)

Creates a ast_bridge_blob message.

Since
12 The blob JSON object requires a "type" field describing the blob. It should also be treated as immutable and not modified after it is put into the message.
Precondition
bridge is locked.
No channels are locked.
Parameters
bridgeChannel blob is associated with, or NULL for global/all bridges.
blobJSON object representing the data.
Returns
ast_bridge_blob message.
NULL on error

Definition at line 500 of file stasis_bridges.c.

References ao2_alloc, ao2_ref, ast_bridge_snapshot_create(), ast_channel_snapshot_get_latest(), ast_channel_uniqueid(), ast_json_ref(), ast_bridge_blob::blob, ast_bridge_blob::bridge, bridge_blob_dtor(), ast_bridge_blob::channel, NULL, and stasis_message_create().

Referenced by ast_bridge_publish_enter(), ast_bridge_publish_leave(), and send_conf_stasis().

505 {
506  struct ast_bridge_blob *obj;
507  struct stasis_message *msg;
508 
509  if (!message_type) {
510  return NULL;
511  }
512 
513  obj = ao2_alloc(sizeof(*obj), bridge_blob_dtor);
514  if (!obj) {
515  return NULL;
516  }
517 
518  if (bridge) {
519  obj->bridge = ast_bridge_snapshot_create(bridge);
520  if (obj->bridge == NULL) {
521  ao2_ref(obj, -1);
522 
523  return NULL;
524  }
525  }
526 
527  if (chan) {
529  if (obj->channel == NULL) {
530  ao2_ref(obj, -1);
531 
532  return NULL;
533  }
534  }
535 
536  if (blob) {
537  obj->blob = ast_json_ref(blob);
538  }
539 
540  msg = stasis_message_create(message_type, obj);
541  ao2_ref(obj, -1);
542 
543  return msg;
544 }
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
struct ast_channel_snapshot * channel
struct ast_json * blob
#define NULL
Definition: resample.c:96
struct ast_bridge_snapshot * bridge
#define ao2_ref(o, delta)
Definition: astobj2.h:464
Blob of data associated with a bridge.
const char * ast_channel_uniqueid(const struct ast_channel *chan)
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
struct ast_bridge_snapshot * ast_bridge_snapshot_create(struct ast_bridge *bridge)
Generate a snapshot of the bridge state. This is an ao2 object, so ao2_cleanup() to deallocate...
static void bridge_blob_dtor(void *obj)
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...

◆ ast_bridge_blob_create_from_snapshots()

struct stasis_message* ast_bridge_blob_create_from_snapshots ( struct stasis_message_type type,
struct ast_bridge_snapshot bridge_snapshot,
struct ast_channel_snapshot chan_snapshot,
struct ast_json blob 
)

Creates a ast_bridge_blob message from snapshots.

Since
13.28
16.5 The blob JSON object requires a "type" field describing the blob. It should also be treated as immutable and not modified after it is put into the message.
Precondition
bridge is locked.
No channels are locked.
Parameters
bridge_snapshotBridge snapshot
channel_snapshotChannel snapshot
blobJSON object representing the data.
Returns
ast_bridge_blob message.
NULL on error

Definition at line 546 of file stasis_bridges.c.

References ao2_alloc, ao2_bump, ao2_ref, ast_json_ref(), ast_bridge_blob::blob, ast_bridge_blob::bridge, bridge_blob_dtor(), ast_bridge_blob::channel, NULL, and stasis_message_create().

Referenced by send_conf_stasis_snapshots().

551 {
552  struct ast_bridge_blob *obj;
553  struct stasis_message *msg;
554 
555  if (!message_type) {
556  return NULL;
557  }
558 
559  obj = ao2_alloc(sizeof(*obj), bridge_blob_dtor);
560  if (!obj) {
561  return NULL;
562  }
563 
564  if (bridge_snapshot) {
565  obj->bridge = ao2_bump(bridge_snapshot);
566  }
567 
568  if (chan_snapshot) {
569  obj->channel = ao2_bump(chan_snapshot);
570  }
571 
572  if (blob) {
573  obj->blob = ast_json_ref(blob);
574  }
575 
576  msg = stasis_message_create(message_type, obj);
577  ao2_ref(obj, -1);
578 
579  return msg;
580 }
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
struct ast_channel_snapshot * channel
struct ast_json * blob
#define NULL
Definition: resample.c:96
#define ao2_bump(obj)
Definition: astobj2.h:491
struct ast_bridge_snapshot * bridge
#define ao2_ref(o, delta)
Definition: astobj2.h:464
Blob of data associated with a bridge.
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
static void bridge_blob_dtor(void *obj)

◆ ast_bridge_get_snapshot()

struct ast_bridge_snapshot* ast_bridge_get_snapshot ( struct ast_bridge bridge)

Returns the current snapshot for the bridge.

Since
17.0

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

Parameters
bridgeThe bridge from which to get the snapshot.
Returns
Most recent snapshot. ao2_cleanup() when done.
NULL if there isn't a snapshot.

Definition at line 1378 of file stasis_bridges.c.

References ao2_bump, ast_bridge_lock, ast_bridge_unlock, ast_bridge::current_snapshot, and NULL.

Referenced by ast_ari_bridges_list(), bridges_scrape_cb(), handle_bridge_show_all(), send_bridge_list_item_cb(), and test_cel_generate_peer_str_snapshot().

1379 {
1380  struct ast_bridge_snapshot *snapshot;
1381 
1382  if (!bridge) {
1383  return NULL;
1384  }
1385  ast_bridge_lock(bridge);
1386  snapshot = ao2_bump(bridge->current_snapshot);
1387  ast_bridge_unlock(bridge);
1388 
1389  return snapshot;
1390 }
Structure that contains a snapshot of information about a bridge.
Definition: bridge.h:322
#define NULL
Definition: resample.c:96
#define ao2_bump(obj)
Definition: astobj2.h:491
struct ast_bridge_snapshot * current_snapshot
Definition: bridge.h:414
#define ast_bridge_unlock(bridge)
Unlock the bridge.
Definition: bridge.h:493
#define ast_bridge_lock(bridge)
Lock the bridge.
Definition: bridge.h:480

◆ ast_bridge_get_snapshot_by_uniqueid()

struct ast_bridge_snapshot* ast_bridge_get_snapshot_by_uniqueid ( const char *  bridge_id)

Returns the current snapshot for the bridge.

Since
17.0

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

Parameters
bridge_idUniqueid of the bridge from which to get the snapshot.
Returns
Most recent snapshot. ao2_cleanup() when done.
NULL if bridge or snapshot doesn't exist.

Definition at line 1359 of file stasis_bridges.c.

References ao2_bump, ao2_ref, ast_assert, ast_bridge_find_by_id(), ast_bridge_lock, ast_bridge_unlock, ast_strlen_zero, ast_bridge::current_snapshot, and NULL.

Referenced by ast_ari_bridges_get(), find_bridge(), handle_bridge_show_specific(), manager_bridge_info(), and stasis_app_user_event().

1360 {
1361  struct ast_bridge *bridge;
1362  struct ast_bridge_snapshot *snapshot;
1363 
1365 
1366  bridge = ast_bridge_find_by_id(uniqueid);
1367  if (!bridge) {
1368  return NULL;
1369  }
1370  ast_bridge_lock(bridge);
1371  snapshot = ao2_bump(bridge->current_snapshot);
1372  ast_bridge_unlock(bridge);
1373  ao2_ref(bridge, -1);
1374 
1375  return snapshot;
1376 }
struct ast_bridge * ast_bridge_find_by_id(const char *bridge_id)
Find bridge by id.
Definition: bridge.c:5070
Structure that contains a snapshot of information about a bridge.
Definition: bridge.h:322
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ao2_bump(obj)
Definition: astobj2.h:491
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ast_bridge_snapshot * current_snapshot
Definition: bridge.h:414
Structure that contains information about a bridge.
Definition: bridge.h:357
#define ast_bridge_unlock(bridge)
Unlock the bridge.
Definition: bridge.h:493
const ast_string_field uniqueid
Definition: bridge.h:336
#define ast_bridge_lock(bridge)
Lock the bridge.
Definition: bridge.h:480

◆ ast_bridge_merge_message_to_json()

static struct ast_json * ast_bridge_merge_message_to_json ( struct stasis_message msg,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 438 of file stasis_bridges.c.

References ast_bridge_snapshot_to_json(), ast_json_pack(), ast_json_timeval(), ast_json_unref(), ast_bridge_merge_message::from, NULL, stasis_message_data(), stasis_message_timestamp(), and ast_bridge_merge_message::to.

441 {
442  struct ast_bridge_merge_message *merge = stasis_message_data(msg);
443  struct ast_json *json_bridge_to = ast_bridge_snapshot_to_json(merge->to, sanitize);
444  struct ast_json *json_bridge_from = ast_bridge_snapshot_to_json(merge->from, sanitize);
445 
446  if (!json_bridge_to || !json_bridge_from) {
447  ast_json_unref(json_bridge_to);
448  ast_json_unref(json_bridge_from);
449 
450  return NULL;
451  }
452 
453  return ast_json_pack("{s: s, s: o, s: o, s: o}",
454  "type", "BridgeMerged",
455  "timestamp", ast_json_timeval(*stasis_message_timestamp(msg), NULL),
456  "bridge", json_bridge_to,
457  "bridge_from", json_bridge_from);
458 }
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 NULL
Definition: resample.c:96
const struct timeval * stasis_message_timestamp(const struct stasis_message *msg)
Get the time when a message was created.
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
Definition: json.c:649
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct ast_bridge_snapshot * from
Message representing the merge of two bridges.
Abstract JSON element (object, array, string, int, ...).
struct ast_json * ast_bridge_snapshot_to_json(const struct ast_bridge_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_bridge_snapshot.
struct ast_bridge_snapshot * to

◆ ast_bridge_publish_attended_transfer()

void ast_bridge_publish_attended_transfer ( struct ast_attended_transfer_message transfer_msg)

Publish an attended transfer.

Parameters
transfer_msgThe transfer message to publish

Definition at line 1346 of file stasis_bridges.c.

References ao2_ref, ast_attended_transfer_type(), ast_bridge_topic_all(), stasis_message_create(), and stasis_publish().

Referenced by ast_bridge_transfer_attended(), publish_transfer_fail(), publish_transfer_success(), and publish_transfer_threeway().

1347 {
1348  struct stasis_message *msg;
1349 
1350  msg = stasis_message_create(ast_attended_transfer_type(), transfer_msg);
1351  if (!msg) {
1352  return;
1353  }
1354 
1356  ao2_ref(msg, -1);
1357 }
struct stasis_topic * ast_bridge_topic_all(void)
A topic which publishes the events for all bridges.
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
struct stasis_message_type * ast_attended_transfer_type(void)
Message type for ast_attended_transfer_message.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic&#39;s subscribers.
Definition: stasis.c:1511

◆ ast_bridge_publish_blind_transfer()

void ast_bridge_publish_blind_transfer ( struct ast_blind_transfer_message transfer_message)

Publish a blind transfer event.

Precondition
Bridges involved are locked. Channels involved are not locked.
Parameters
is_externalWhether the blind transfer was initiated externally (e.g. via AMI or native protocol)
resultThe success or failure of the transfer
to_transfereeThe bridge between the transferer and transferee plus the transferer channel
contextThe destination context for the blind transfer
extenThe destination extension for the blind transfer
transferee_channelIf a single channel is being transferred, this is it. If multiple parties are being transferred, this is NULL.
replace_channelIf multiple parties are being transferred or the transfer cannot reach across the bridge due to bridge flags, this is the channel connecting their bridge to the destination.

Definition at line 953 of file stasis_bridges.c.

References ao2_cleanup, ast_blind_transfer_type(), ast_bridge_topic_all(), stasis, stasis_message_create(), and stasis_publish().

Referenced by ast_bridge_transfer_blind(), and AST_TEST_DEFINE().

954 {
955  struct stasis_message *stasis;
956 
957  stasis = stasis_message_create(ast_blind_transfer_type(), transfer_message);
958  if (!stasis) {
959  return;
960  }
961 
963 
964  ao2_cleanup(stasis);
965 }
struct stasis_message_type * ast_blind_transfer_type(void)
Message type for ast_blind_transfer_message.
struct stasis_topic * ast_bridge_topic_all(void)
A topic which publishes the events for all bridges.
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic&#39;s subscribers.
Definition: stasis.c:1511
static const char * stasis
Dialplan application name.
Definition: app_stasis.c:80
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ ast_bridge_publish_enter()

void ast_bridge_publish_enter ( struct ast_bridge bridge,
struct ast_channel chan,
struct ast_channel swap 
)

Publish a bridge channel enter event.

Since
12
Precondition
bridge is locked.
No channels are locked.
Parameters
bridgeThe bridge a channel entered
chanThe channel that entered the bridge
swapThe channel being swapped out of the bridge

Definition at line 582 of file stasis_bridges.c.

References ao2_ref, ast_bridge_blob_create(), AST_BRIDGE_FLAG_INVISIBLE, ast_bridge_topic(), ast_channel_entered_bridge_type(), ast_channel_uniqueid(), ast_json_pack(), ast_json_unref(), ast_test_flag, bridge_publish_state_from_blob(), ast_bridge::feature_flags, NULL, stasis_message_data(), and stasis_publish().

Referenced by bridge_channel_internal_push_full().

584 {
585  struct stasis_message *msg;
586  struct ast_json *blob = NULL;
587 
589  return;
590  }
591 
592  if (swap) {
593  blob = ast_json_pack("{s: s}", "swap", ast_channel_uniqueid(swap));
594  if (!blob) {
595  return;
596  }
597  }
598 
599  msg = ast_bridge_blob_create(ast_channel_entered_bridge_type(), bridge, chan, blob);
600  ast_json_unref(blob);
601  if (!msg) {
602  return;
603  }
604 
605  /* enter blob first, then state */
606  stasis_publish(ast_bridge_topic(bridge), msg);
608  ao2_ref(msg, -1);
609 }
struct ast_flags feature_flags
Definition: bridge.h:377
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
struct stasis_message_type * ast_channel_entered_bridge_type(void)
Message type for channel enter bridge blob messages.
#define ast_test_flag(p, flag)
Definition: utils.h:63
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
const char * ast_channel_uniqueid(const struct ast_channel *chan)
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic&#39;s subscribers.
Definition: stasis.c:1511
static void bridge_publish_state_from_blob(struct ast_bridge *bridge, struct ast_bridge_blob *obj)
struct stasis_topic * ast_bridge_topic(struct ast_bridge *bridge)
A topic which publishes the events for a particular bridge.
Abstract JSON element (object, array, string, int, ...).
struct stasis_message * ast_bridge_blob_create(struct stasis_message_type *message_type, struct ast_bridge *bridge, struct ast_channel *chan, struct ast_json *blob)
Creates a ast_bridge_blob message.

◆ ast_bridge_publish_leave()

void ast_bridge_publish_leave ( struct ast_bridge bridge,
struct ast_channel chan 
)

Publish a bridge channel leave event.

Since
12
Precondition
bridge is locked.
No channels are locked.
Parameters
bridgeThe bridge a channel left
chanThe channel that left the bridge

Definition at line 611 of file stasis_bridges.c.

References ao2_ref, ast_bridge_blob_create(), AST_BRIDGE_FLAG_INVISIBLE, ast_bridge_topic(), ast_channel_left_bridge_type(), ast_test_flag, bridge_publish_state_from_blob(), ast_bridge::feature_flags, NULL, stasis_message_data(), and stasis_publish().

Referenced by bridge_channel_internal_pull().

612 {
613  struct stasis_message *msg;
614 
616  return;
617  }
619  if (!msg) {
620  return;
621  }
622 
623  /* state first, then leave blob (opposite of enter, preserves nesting of events) */
625  stasis_publish(ast_bridge_topic(bridge), msg);
626  ao2_ref(msg, -1);
627 }
struct ast_flags feature_flags
Definition: bridge.h:377
#define ast_test_flag(p, flag)
Definition: utils.h:63
struct stasis_message_type * ast_channel_left_bridge_type(void)
Message type for channel leave bridge blob messages.
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic&#39;s subscribers.
Definition: stasis.c:1511
static void bridge_publish_state_from_blob(struct ast_bridge *bridge, struct ast_bridge_blob *obj)
struct stasis_topic * ast_bridge_topic(struct ast_bridge *bridge)
A topic which publishes the events for a particular bridge.
struct stasis_message * ast_bridge_blob_create(struct stasis_message_type *message_type, struct ast_bridge *bridge, struct ast_channel *chan, struct ast_json *blob)
Creates a ast_bridge_blob message.

◆ ast_bridge_publish_merge()

void ast_bridge_publish_merge ( struct ast_bridge to,
struct ast_bridge from 
)

Publish a bridge merge.

Since
12
Precondition
Bridges involved are locked
Parameters
toThe bridge to which channels are being added
fromThe bridge from which channels are being removed

Definition at line 460 of file stasis_bridges.c.

References ao2_ref, ast_assert, AST_BRIDGE_FLAG_INVISIBLE, ast_bridge_merge_message_type(), ast_bridge_topic_all(), ast_test_flag, bridge_merge_message_create(), ast_bridge::feature_flags, NULL, stasis_message_create(), and stasis_publish().

Referenced by bridge_do_merge().

461 {
462  struct ast_bridge_merge_message *merge_msg;
463  struct stasis_message *msg;
464 
466  return;
467  }
468 
469  ast_assert(to != NULL);
470  ast_assert(from != NULL);
473 
474  merge_msg = bridge_merge_message_create(to, from);
475  if (!merge_msg) {
476  return;
477  }
478 
480  ao2_ref(merge_msg, -1);
481  if (!msg) {
482  return;
483  }
484 
486  ao2_ref(msg, -1);
487 }
struct ast_flags feature_flags
Definition: bridge.h:377
static struct ast_bridge_merge_message * bridge_merge_message_create(struct ast_bridge *to, struct ast_bridge *from)
Bridge merge message creation helper.
#define ast_test_flag(p, flag)
Definition: utils.h:63
struct stasis_topic * ast_bridge_topic_all(void)
A topic which publishes the events for all bridges.
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
struct stasis_message_type * ast_bridge_merge_message_type(void)
Message type for ast_bridge_merge_message.
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic&#39;s subscribers.
Definition: stasis.c:1511
Message representing the merge of two bridges.

◆ ast_bridge_publish_state()

void ast_bridge_publish_state ( struct ast_bridge bridge)

Publish the state of a bridge.

Since
12
Precondition
Bridge is locked
Parameters
bridgeThe bridge for which to publish state

Definition at line 350 of file stasis_bridges.c.

References ao2_cleanup, ao2_ref, ast_assert, ast_bridge_snapshot_create(), ast_bridge_snapshot_type(), ast_bridge_topic(), bridge_snapshot_update_create(), ast_bridge::current_snapshot, NULL, stasis_message_create(), stasis_publish(), and update().

Referenced by ast_bridge_set_single_src_video_mode(), ast_bridge_update_talker_src_video_mode(), bridge_reconfigured(), and bridge_register().

351 {
352  struct ast_bridge_snapshot *new_snapshot;
354  struct stasis_message *msg;
355 
356  ast_assert(bridge != NULL);
357 
358  new_snapshot = ast_bridge_snapshot_create(bridge);
359  if (!new_snapshot) {
360  return;
361  }
362 
363  update = bridge_snapshot_update_create(bridge->current_snapshot, new_snapshot);
364  /* There may not have been an old snapshot */
365  ao2_cleanup(bridge->current_snapshot);
366  bridge->current_snapshot = new_snapshot;
367  if (!update) {
368  return;
369  }
370 
372  ao2_ref(update, -1);
373  if (!msg) {
374  return;
375  }
376 
377  stasis_publish(ast_bridge_topic(bridge), msg);
378  ao2_ref(msg, -1);
379 }
struct stasis_message_type * ast_bridge_snapshot_type(void)
Message type for ast_bridge_snapshot.
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
Structure that contains a snapshot of information about a bridge.
Definition: bridge.h:322
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static struct ast_bridge_snapshot_update * bridge_snapshot_update_create(struct ast_bridge_snapshot *old, struct ast_bridge_snapshot *new)
struct ast_bridge_snapshot * current_snapshot
Definition: bridge.h:414
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
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 ast_bridge_snapshot * ast_bridge_snapshot_create(struct ast_bridge *bridge)
Generate a snapshot of the bridge state. This is an ao2 object, so ao2_cleanup() to deallocate...
struct stasis_topic * ast_bridge_topic(struct ast_bridge *bridge)
A topic which publishes the events for a particular bridge.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ ast_bridge_snapshot_create()

struct ast_bridge_snapshot* ast_bridge_snapshot_create ( struct ast_bridge bridge)

Generate a snapshot of the bridge state. This is an ao2 object, so ao2_cleanup() to deallocate.

Since
12
Precondition
Bridge is locked
Parameters
bridgeThe bridge from which to generate a snapshot
Return values
AO2refcounted snapshot on success
NULLon error

Definition at line 202 of file stasis_bridges.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_ref, AST_BRIDGE_FLAG_INVISIBLE, AST_BRIDGE_VIDEO_MODE_SINGLE_SRC, AST_BRIDGE_VIDEO_MODE_TALKER_SRC, ast_channel_uniqueid(), AST_LIST_TRAVERSE, ast_str_container_add(), ast_str_container_alloc, ast_string_field_init, ast_string_field_set, ast_test_flag, bridge_snapshot_dtor(), ast_bridge_technology::capabilities, ast_bridge_snapshot::capabilities, ast_bridge_channel::chan, ast_bridge_video_single_src_data::chan_vsrc, ast_bridge_video_talker_src_data::chan_vsrc, ast_bridge_snapshot::channels, ast_bridge::channels, ast_bridge_snapshot::creationtime, ast_bridge::creationtime, ast_bridge::creator, ast_bridge_snapshot::feature_flags, ast_bridge::feature_flags, ast_bridge_video_mode::mode, ast_bridge_video_mode::mode_data, ast_bridge_technology::name, name, ast_bridge_methods::name, ast_bridge::name, NULL, ast_bridge_snapshot::num_active, ast_bridge::num_active, ast_bridge_snapshot::num_channels, ast_bridge::num_channels, ast_bridge_video_mode::single_src_data, SNAPSHOT_CHANNELS_BUCKETS, ast_bridge::softmix, ast_bridge_video_mode::talker_src_data, ast_bridge::technology, ast_bridge::uniqueid, ast_bridge::v_table, ast_bridge_softmix::video_mode, and ast_bridge_snapshot::video_mode.

Referenced by ast_ari_bridges_create(), ast_ari_bridges_create_with_id(), ast_bridge_blob_create(), ast_bridge_publish_state(), ast_bridge_transfer_blind(), AST_TEST_DEFINE(), bridge_channel_snapshot_pair_init(), bridge_merge_message_create(), bridge_topics_destroy(), and send_conf_stasis_snapshots().

203 {
204  struct ast_bridge_snapshot *snapshot;
205  struct ast_bridge_channel *bridge_channel;
206 
208  return NULL;
209  }
210 
211  snapshot = ao2_alloc_options(sizeof(*snapshot), bridge_snapshot_dtor,
213  if (!snapshot) {
214  return NULL;
215  }
216 
217  if (ast_string_field_init(snapshot, 128)) {
218  ao2_ref(snapshot, -1);
219 
220  return NULL;
221  }
222 
224  if (!snapshot->channels) {
225  ao2_ref(snapshot, -1);
226 
227  return NULL;
228  }
229 
230  AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {
231  if (ast_str_container_add(snapshot->channels,
232  ast_channel_uniqueid(bridge_channel->chan))) {
233  ao2_ref(snapshot, -1);
234 
235  return NULL;
236  }
237  }
238 
239  ast_string_field_set(snapshot, uniqueid, bridge->uniqueid);
240  ast_string_field_set(snapshot, technology, bridge->technology->name);
241  ast_string_field_set(snapshot, subclass, bridge->v_table->name);
242  ast_string_field_set(snapshot, creator, bridge->creator);
243  ast_string_field_set(snapshot, name, bridge->name);
244 
245  snapshot->feature_flags = bridge->feature_flags;
246  snapshot->capabilities = bridge->technology->capabilities;
247  snapshot->num_channels = bridge->num_channels;
248  snapshot->num_active = bridge->num_active;
249  snapshot->creationtime = bridge->creationtime;
250  snapshot->video_mode = bridge->softmix.video_mode.mode;
253  ast_string_field_set(snapshot, video_source_id,
255  } else if (snapshot->video_mode == AST_BRIDGE_VIDEO_MODE_TALKER_SRC
257  ast_string_field_set(snapshot, video_source_id,
259  }
260 
261  return snapshot;
262 }
struct ao2_container * channels
Definition: bridge.h:339
struct timeval creationtime
Definition: bridge.h:351
struct ast_flags feature_flags
Definition: bridge.h:377
const ast_string_field uniqueid
Definition: bridge.h:409
#define SNAPSHOT_CHANNELS_BUCKETS
unsigned int num_active
Definition: bridge.h:383
#define ast_test_flag(p, flag)
Definition: utils.h:63
const char * name
Definition: bridge.h:267
Structure that contains a snapshot of information about a bridge.
Definition: bridge.h:322
struct ast_bridge_video_mode video_mode
Definition: bridge.h:287
const ast_string_field name
Definition: bridge.h:409
struct ast_channel * chan_vsrc
Definition: bridge.h:116
#define ast_str_container_alloc(buckets)
Allocates a hash container for bare strings.
Definition: strings.h:1312
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define NULL
Definition: resample.c:96
struct ast_bridge_softmix softmix
Definition: bridge.h:375
union ast_bridge_video_mode::@227 mode_data
static void bridge_snapshot_dtor(void *obj)
Destructor for bridge snapshots.
struct ast_bridge_technology * technology
Definition: bridge.h:363
uint32_t capabilities
Definition: bridge.h:343
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
struct ast_bridge_video_talker_src_data talker_src_data
Definition: bridge.h:164
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ast_bridge_video_single_src_data single_src_data
Definition: bridge.h:163
const char * ast_channel_uniqueid(const struct ast_channel *chan)
const struct ast_bridge_methods * v_table
Definition: bridge.h:359
enum ast_bridge_video_mode_type video_mode
Definition: bridge.h:349
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct timeval creationtime
Definition: bridge.h:416
static const char name[]
Definition: cdr_mysql.c:74
struct ast_flags feature_flags
Definition: bridge.h:341
unsigned int num_channels
Definition: bridge.h:345
unsigned int num_active
Definition: bridge.h:347
struct ast_bridge_channels_list channels
Definition: bridge.h:371
struct ast_channel * chan
Structure that contains information regarding a channel in a bridge.
struct ast_channel * chan_vsrc
Definition: bridge.h:123
Definition: search.h:40
const ast_string_field creator
Definition: bridge.h:409
unsigned int num_channels
Definition: bridge.h:381
enum ast_bridge_video_mode_type mode
Definition: bridge.h:160
int ast_str_container_add(struct ao2_container *str_container, const char *add)
Adds a string to a string container allocated by ast_str_container_alloc.
Definition: strings.c:206
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ ast_bridge_snapshot_to_json()

struct ast_json* ast_bridge_snapshot_to_json ( const struct ast_bridge_snapshot snapshot,
const struct stasis_message_sanitizer sanitize 
)

Build a JSON object from a ast_bridge_snapshot.

Parameters
snapshotThe bridge snapshot to convert to JSON
sanitizeThe message sanitizer to use on the snapshot
Returns
JSON object representing bridge snapshot.
NULL on error

Definition at line 712 of file stasis_bridges.c.

References AST_BRIDGE_VIDEO_MODE_NONE, ast_bridge_video_mode_to_string(), ast_json_object_set(), ast_json_pack(), ast_json_string_create(), ast_json_timeval(), ast_strlen_zero, ast_bridge_snapshot::capabilities, capability2str(), ast_bridge_snapshot::channels, container_to_json_array(), ast_bridge_snapshot::creationtime, ast_bridge_snapshot::creator, ast_bridge_snapshot::name, NULL, 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_ari_bridges_create(), ast_ari_bridges_create_with_id(), ast_ari_bridges_get(), ast_ari_bridges_list(), ast_bridge_merge_message_to_json(), attended_transfer_to_json(), blind_transfer_to_json(), bridge_to_json(), multi_user_event_to_json(), simple_bridge_channel_event(), and simple_bridge_event().

715 {
716  struct ast_json *json_bridge;
717  struct ast_json *json_channels;
718 
719  if (snapshot == NULL) {
720  return NULL;
721  }
722 
723  json_channels = container_to_json_array(snapshot->channels, sanitize);
724  if (!json_channels) {
725  return NULL;
726  }
727 
728  json_bridge = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s, s: o, s: o, s: s}",
729  "id", snapshot->uniqueid,
730  "technology", snapshot->technology,
731  "bridge_type", capability2str(snapshot->capabilities),
732  "bridge_class", snapshot->subclass,
733  "creator", snapshot->creator,
734  "name", snapshot->name,
735  "channels", json_channels,
736  "creationtime", ast_json_timeval(snapshot->creationtime, NULL),
737  "video_mode", ast_bridge_video_mode_to_string(snapshot->video_mode));
738  if (!json_bridge) {
739  return NULL;
740  }
741 
742  if (snapshot->video_mode != AST_BRIDGE_VIDEO_MODE_NONE
743  && !ast_strlen_zero(snapshot->video_source_id)) {
744  ast_json_object_set(json_bridge, "video_source_id",
746  }
747 
748  return json_bridge;
749 }
struct ao2_container * channels
Definition: bridge.h:339
struct timeval creationtime
Definition: bridge.h:351
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
const ast_string_field video_source_id
Definition: bridge.h:336
#define NULL
Definition: resample.c:96
const ast_string_field creator
Definition: bridge.h:336
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_strlen_zero(foo)
Definition: strings.h:52
uint32_t capabilities
Definition: bridge.h:343
const ast_string_field technology
Definition: bridge.h:336
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268
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
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
Definition: json.c:649
const ast_string_field name
Definition: bridge.h:336
enum ast_bridge_video_mode_type video_mode
Definition: bridge.h:349
static struct ast_json * container_to_json_array(struct ao2_container *items, const struct stasis_message_sanitizer *sanitize)
const ast_string_field uniqueid
Definition: bridge.h:336
Abstract JSON element (object, array, string, int, ...).
const ast_string_field subclass
Definition: bridge.h:336
static const char * capability2str(uint32_t capabilities)

◆ ast_bridge_topic()

struct stasis_topic* ast_bridge_topic ( struct ast_bridge bridge)

A topic which publishes the events for a particular bridge.

Since
12 If the given bridge is NULL, ast_bridge_topic_all() is returned.
Parameters
bridgeBridge for which to get a topic or NULL.
Return values
Topicfor bridge's events.
ast_bridge_topic_all()if bridge is NULL.

Definition at line 184 of file stasis_bridges.c.

References ast_bridge_topic_all(), and ast_bridge::topic.

Referenced by ari_bridges_play_new(), ast_ari_bridges_record(), ast_bridge_publish_enter(), ast_bridge_publish_leave(), ast_bridge_publish_state(), bridge_base_init(), bridge_publish_state_from_blob(), bridge_topics_destroy(), forwards_create_bridge(), send_conf_stasis(), and send_conf_stasis_snapshots().

185 {
186  if (!bridge) {
187  return ast_bridge_topic_all();
188  }
189 
190  return bridge->topic;
191 }
struct stasis_topic * ast_bridge_topic_all(void)
A topic which publishes the events for all bridges.
struct stasis_topic * topic
Definition: bridge.h:367

◆ ast_bridge_topic_all()

struct stasis_topic* ast_bridge_topic_all ( void  )

A topic which publishes the events for all bridges.

Since
12
Return values
Topicfor all bridge events.

Definition at line 179 of file stasis_bridges.c.

References bridge_topic_all.

Referenced by app_create(), ast_bridge_publish_attended_transfer(), ast_bridge_publish_blind_transfer(), ast_bridge_publish_merge(), ast_bridge_topic(), create_subscriptions(), manager_bridging_init(), manager_confbridge_init(), refer_blind_callback(), and setup_stasis_subs().

180 {
181  return bridge_topic_all;
182 }
static struct stasis_topic * bridge_topic_all

◆ ast_channel_entered_bridge_to_json()

struct ast_json * ast_channel_entered_bridge_to_json ( struct stasis_message msg,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 653 of file stasis_bridges.c.

References ast_bridge_blob::bridge, ast_bridge_blob::channel, simple_bridge_channel_event(), stasis_message_data(), and stasis_message_timestamp().

656 {
657  struct ast_bridge_blob *obj = stasis_message_data(msg);
658 
659  return simple_bridge_channel_event("ChannelEnteredBridge", obj->bridge,
660  obj->channel, stasis_message_timestamp(msg), sanitize);
661 }
struct ast_channel_snapshot * channel
struct ast_bridge_snapshot * bridge
const struct timeval * stasis_message_timestamp(const struct stasis_message *msg)
Get the time when a message was created.
static struct ast_json * simple_bridge_channel_event(const char *type, struct ast_bridge_snapshot *bridge_snapshot, struct ast_channel_snapshot *channel_snapshot, const struct timeval *tv, const struct stasis_message_sanitizer *sanitize)
Blob of data associated with a bridge.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.

◆ ast_channel_left_bridge_to_json()

struct ast_json * ast_channel_left_bridge_to_json ( struct stasis_message msg,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 663 of file stasis_bridges.c.

References ast_bridge_blob::bridge, ast_bridge_blob::channel, simple_bridge_channel_event(), stasis_message_data(), and stasis_message_timestamp().

666 {
667  struct ast_bridge_blob *obj = stasis_message_data(msg);
668 
669  return simple_bridge_channel_event("ChannelLeftBridge", obj->bridge,
670  obj->channel, stasis_message_timestamp(msg), sanitize);
671 }
struct ast_channel_snapshot * channel
struct ast_bridge_snapshot * bridge
const struct timeval * stasis_message_timestamp(const struct stasis_message *msg)
Get the time when a message was created.
static struct ast_json * simple_bridge_channel_event(const char *type, struct ast_bridge_snapshot *bridge_snapshot, struct ast_channel_snapshot *channel_snapshot, const struct timeval *tv, const struct stasis_message_sanitizer *sanitize)
Blob of data associated with a bridge.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.

◆ ast_stasis_bridging_init()

int ast_stasis_bridging_init ( void  )

Definition at line 1407 of file stasis_bridges.c.

References ast_attended_transfer_type(), ast_blind_transfer_type(), ast_bridge_merge_message_type(), ast_bridge_snapshot_type(), ast_channel_entered_bridge_type(), ast_channel_left_bridge_type(), ast_register_cleanup(), stasis_bridging_cleanup(), STASIS_MESSAGE_TYPE_INIT, stasis_topic_create(), and stasis_topic_pool_create().

Referenced by ast_bridging_init().

1408 {
1409  int res = 0;
1410 
1412 
1413  bridge_topic_all = stasis_topic_create("bridge:all");
1414  if (!bridge_topic_all) {
1415  return -1;
1416  }
1418  if (!bridge_topic_pool) {
1419  return -1;
1420  }
1421 
1428 
1429  return res;
1430 }
struct stasis_message_type * ast_bridge_snapshot_type(void)
Message type for ast_bridge_snapshot.
struct stasis_message_type * ast_blind_transfer_type(void)
Message type for ast_blind_transfer_message.
struct stasis_message_type * ast_channel_entered_bridge_type(void)
Message type for channel enter bridge blob messages.
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition: stasis.h:1501
struct stasis_message_type * ast_channel_left_bridge_type(void)
Message type for channel leave bridge blob messages.
struct stasis_topic_pool * stasis_topic_pool_create(struct stasis_topic *pooled_topic)
Create a topic pool that routes messages from dynamically generated topics to the given topic...
Definition: stasis.c:1833
struct stasis_message_type * ast_bridge_merge_message_type(void)
Message type for ast_bridge_merge_message.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Definition: stasis.c:618
static struct stasis_topic_pool * bridge_topic_pool
static struct stasis_topic * bridge_topic_all
struct stasis_message_type * ast_attended_transfer_type(void)
Message type for ast_attended_transfer_message.
static void stasis_bridging_cleanup(void)

◆ attended_transfer_dtor()

static void attended_transfer_dtor ( void *  obj)
static

Definition at line 1206 of file stasis_bridges.c.

References ao2_cleanup, ARRAY_LEN, AST_ATTENDED_TRANSFER_DEST_LINK, bridge_channel_snapshot_pair_cleanup(), ast_attended_transfer_message::dest, ast_attended_transfer_message::dest_type, ast_attended_transfer_message::links, ast_attended_transfer_message::replace_channel, ast_attended_transfer_message::target, ast_attended_transfer_message::to_transfer_target, ast_attended_transfer_message::to_transferee, and ast_attended_transfer_message::transferee.

Referenced by ast_attended_transfer_message_create().

1207 {
1208  struct ast_attended_transfer_message *msg = obj;
1209  int i;
1210 
1214  ao2_cleanup(msg->transferee);
1215  ao2_cleanup(msg->target);
1216 
1218  return;
1219  }
1220 
1221  for (i = 0; i < ARRAY_LEN(msg->dest.links); ++i) {
1222  ao2_cleanup(msg->dest.links[i]);
1223  }
1224 }
union ast_attended_transfer_message::@324 dest
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
Message representing attended transfer.
struct ast_channel_snapshot * target
struct ast_bridge_channel_snapshot_pair to_transferee
struct ast_bridge_channel_snapshot_pair to_transfer_target
struct ast_channel_snapshot * links[2]
struct ast_channel_snapshot * transferee
struct ast_channel_snapshot * replace_channel
enum ast_attended_transfer_dest_type dest_type
static void bridge_channel_snapshot_pair_cleanup(struct ast_bridge_channel_snapshot_pair *pair)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ attended_transfer_to_ami()

static struct ast_manager_event_blob * attended_transfer_to_ami ( struct stasis_message message)
static

Definition at line 1103 of file stasis_bridges.c.

References ast_attended_transfer_message::app, AST_ATTENDED_TRANSFER_DEST_APP, AST_ATTENDED_TRANSFER_DEST_BRIDGE_MERGE, AST_ATTENDED_TRANSFER_DEST_FAIL, AST_ATTENDED_TRANSFER_DEST_LINK, AST_ATTENDED_TRANSFER_DEST_LOCAL_APP, AST_ATTENDED_TRANSFER_DEST_THREEWAY, ast_free_ptr(), ast_manager_build_bridge_state_string_prefix(), ast_manager_build_channel_state_string_prefix(), ast_manager_event_blob_create(), ast_str_append(), ast_str_buffer(), ast_str_create, ast_channel_snapshot::base, ast_attended_transfer_message::bridge, ast_bridge_channel_snapshot_pair::bridge_snapshot, ast_bridge_channel_snapshot_pair::channel_snapshot, ast_attended_transfer_message::dest, ast_attended_transfer_message::dest_type, EVENT_FLAG_CALL, ast_attended_transfer_message::is_external, ast_attended_transfer_message::links, ast_channel_snapshot_base::name, NULL, RAII_VAR, ast_attended_transfer_message::result, result_strs, stasis_message_data(), ast_attended_transfer_message::target, ast_attended_transfer_message::threeway, ast_attended_transfer_message::to_transfer_target, ast_attended_transfer_message::to_transferee, ast_attended_transfer_message::transferee, and ast_bridge_snapshot::uniqueid.

1104 {
1105  RAII_VAR(struct ast_str *, variable_data, ast_str_create(64), ast_free_ptr);
1106  RAII_VAR(struct ast_str *, transferer1_state, NULL, ast_free_ptr);
1107  RAII_VAR(struct ast_str *, bridge1_state, NULL, ast_free_ptr);
1108  RAII_VAR(struct ast_str *, transferer2_state, NULL, ast_free_ptr);
1109  RAII_VAR(struct ast_str *, bridge2_state, NULL, ast_free_ptr);
1110  RAII_VAR(struct ast_str *, local1_state, NULL, ast_free_ptr);
1111  RAII_VAR(struct ast_str *, local2_state, NULL, ast_free_ptr);
1112  RAII_VAR(struct ast_str *, transferee_state, NULL, ast_free_ptr);
1113  RAII_VAR(struct ast_str *, target_state, NULL, ast_free_ptr);
1114  struct ast_attended_transfer_message *transfer_msg = stasis_message_data(msg);
1115 
1116  if (!variable_data) {
1117  return NULL;
1118  }
1119 
1120  transferer1_state = ast_manager_build_channel_state_string_prefix(transfer_msg->to_transferee.channel_snapshot, "OrigTransferer");
1121  transferer2_state = ast_manager_build_channel_state_string_prefix(transfer_msg->to_transfer_target.channel_snapshot, "SecondTransferer");
1122  if (!transferer1_state || !transferer2_state) {
1123  return NULL;
1124  }
1125  if (transfer_msg->transferee) {
1126  transferee_state = ast_manager_build_channel_state_string_prefix(transfer_msg->transferee, "Transferee");
1127  if (!transferee_state) {
1128  return NULL;
1129  }
1130  }
1131 
1132  if (transfer_msg->target) {
1133  target_state = ast_manager_build_channel_state_string_prefix(transfer_msg->target, "TransferTarget");
1134  if (!target_state) {
1135  return NULL;
1136  }
1137  }
1138 
1139  if (transfer_msg->to_transferee.bridge_snapshot) {
1141  transfer_msg->to_transferee.bridge_snapshot, "Orig");
1142  if (!bridge1_state) {
1143  return NULL;
1144  }
1145  }
1146 
1147  if (transfer_msg->to_transfer_target.bridge_snapshot) {
1149  transfer_msg->to_transfer_target.bridge_snapshot, "Second");
1150  if (!bridge2_state) {
1151  return NULL;
1152  }
1153  }
1154 
1155  switch (transfer_msg->dest_type) {
1157  ast_str_append(&variable_data, 0, "DestType: Bridge\r\n");
1158  ast_str_append(&variable_data, 0, "DestBridgeUniqueid: %s\r\n", transfer_msg->dest.bridge);
1159  break;
1162  ast_str_append(&variable_data, 0, "DestType: App\r\n");
1163  ast_str_append(&variable_data, 0, "DestApp: %s\r\n", transfer_msg->dest.app);
1164  break;
1166  local1_state = ast_manager_build_channel_state_string_prefix(transfer_msg->dest.links[0], "LocalOne");
1167  local2_state = ast_manager_build_channel_state_string_prefix(transfer_msg->dest.links[1], "LocalTwo");
1168  if (!local1_state || !local2_state) {
1169  return NULL;
1170  }
1171  ast_str_append(&variable_data, 0, "DestType: Link\r\n");
1172  ast_str_append(&variable_data, 0, "%s", ast_str_buffer(local1_state));
1173  ast_str_append(&variable_data, 0, "%s", ast_str_buffer(local2_state));
1174  break;
1176  ast_str_append(&variable_data, 0, "DestType: Threeway\r\n");
1177  ast_str_append(&variable_data, 0, "DestBridgeUniqueid: %s\r\n", transfer_msg->dest.threeway.bridge_snapshot->uniqueid);
1178  ast_str_append(&variable_data, 0, "DestTransfererChannel: %s\r\n", transfer_msg->dest.threeway.channel_snapshot->base->name);
1179  break;
1181  ast_str_append(&variable_data, 0, "DestType: Fail\r\n");
1182  break;
1183  }
1184 
1185  return ast_manager_event_blob_create(EVENT_FLAG_CALL, "AttendedTransfer",
1186  "Result: %s\r\n"
1187  "%s"
1188  "%s"
1189  "%s"
1190  "%s"
1191  "%s"
1192  "%s"
1193  "IsExternal: %s\r\n"
1194  "%s",
1195  result_strs[transfer_msg->result],
1196  ast_str_buffer(transferer1_state),
1197  bridge1_state ? ast_str_buffer(bridge1_state) : "",
1198  ast_str_buffer(transferer2_state),
1199  bridge2_state ? ast_str_buffer(bridge2_state) : "",
1200  transferee_state ? ast_str_buffer(transferee_state) : "",
1201  target_state ? ast_str_buffer(target_state) : "",
1202  transfer_msg->is_external ? "Yes" : "No",
1203  ast_str_buffer(variable_data));
1204 }
struct ast_channel_snapshot_base * base
union ast_attended_transfer_message::@324 dest
Message representing attended transfer.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
struct ast_str * ast_manager_build_channel_state_string_prefix(const struct ast_channel_snapshot *snapshot, const char *prefix)
Generate the AMI message body from a channel snapshot.
#define EVENT_FLAG_CALL
Definition: manager.h:72
struct ast_channel_snapshot * target
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
char bridge[AST_UUID_STR_LEN]
#define NULL
Definition: resample.c:96
void ast_free_ptr(void *ptr)
free() wrapper
Definition: astmm.c:1771
struct ast_bridge_channel_snapshot_pair to_transferee
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
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.
struct ast_bridge_channel_snapshot_pair to_transfer_target
enum ast_transfer_result result
struct ast_channel_snapshot * links[2]
#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_channel_snapshot * transferee
enum ast_attended_transfer_dest_type dest_type
struct ast_channel_snapshot * 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.
struct ast_bridge_channel_snapshot_pair threeway
struct ast_bridge_snapshot * bridge_snapshot
const ast_string_field uniqueid
Definition: bridge.h:336
static const char * result_strs[]
const ast_string_field name
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ attended_transfer_to_json()

static struct ast_json * attended_transfer_to_json ( struct stasis_message msg,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 967 of file stasis_bridges.c.

References ast_attended_transfer_message::app, AST_ATTENDED_TRANSFER_DEST_APP, AST_ATTENDED_TRANSFER_DEST_BRIDGE_MERGE, AST_ATTENDED_TRANSFER_DEST_FAIL, AST_ATTENDED_TRANSFER_DEST_LINK, AST_ATTENDED_TRANSFER_DEST_LOCAL_APP, AST_ATTENDED_TRANSFER_DEST_THREEWAY, ast_bridge_snapshot_to_json(), ast_channel_snapshot_to_json(), ast_json_boolean(), ast_json_object_set(), ast_json_pack(), ast_json_ref(), ast_json_string_create(), ast_json_timeval(), ast_json_unref(), ast_attended_transfer_message::bridge, ast_bridge_channel_snapshot_pair::bridge_snapshot, ast_bridge_channel_snapshot_pair::channel_snapshot, ast_attended_transfer_message::dest, ast_attended_transfer_message::dest_type, ast_attended_transfer_message::is_external, ast_attended_transfer_message::links, NULL, out, RAII_VAR, ast_attended_transfer_message::replace_channel, ast_attended_transfer_message::result, result_strs, stasis_message_data(), stasis_message_timestamp(), ast_attended_transfer_message::target, ast_attended_transfer_message::threeway, ast_attended_transfer_message::to_transfer_target, ast_attended_transfer_message::to_transferee, and ast_attended_transfer_message::transferee.

969 {
970  struct ast_attended_transfer_message *transfer_msg = stasis_message_data(msg);
971  RAII_VAR(struct ast_json *, out, NULL, ast_json_unref);
972  struct ast_json *json_transferer1, *json_transferer2, *json_bridge, *json_channel;
973  struct ast_json *json_transferee = NULL, *json_target = NULL;
974  const struct timeval *tv = stasis_message_timestamp(msg);
975  int res = 0;
976 
977  json_transferer1 = ast_channel_snapshot_to_json(transfer_msg->to_transferee.channel_snapshot, sanitize);
978  if (!json_transferer1) {
979  return NULL;
980  }
981 
982  json_transferer2 = ast_channel_snapshot_to_json(transfer_msg->to_transfer_target.channel_snapshot, sanitize);
983  if (!json_transferer2) {
984  ast_json_unref(json_transferer1);
985  return NULL;
986  }
987 
988  if (transfer_msg->transferee) {
989  json_transferee = ast_channel_snapshot_to_json(transfer_msg->transferee, sanitize);
990  if (!json_transferee) {
991  ast_json_unref(json_transferer2);
992  ast_json_unref(json_transferer1);
993  return NULL;
994  }
995  }
996 
997  if (transfer_msg->target) {
998  json_target = ast_channel_snapshot_to_json(transfer_msg->target, sanitize);
999  if (!json_target) {
1000  ast_json_unref(json_transferee);
1001  ast_json_unref(json_transferer2);
1002  ast_json_unref(json_transferer1);
1003  return NULL;
1004  }
1005  }
1006 
1007  out = ast_json_pack("{s: s, s: o, s: o, s: o, s: s, s: o}",
1008  "type", "BridgeAttendedTransfer",
1009  "timestamp", ast_json_timeval(*tv, NULL),
1010  "transferer_first_leg", json_transferer1,
1011  "transferer_second_leg", json_transferer2,
1012  "result", result_strs[transfer_msg->result],
1013  "is_external", ast_json_boolean(transfer_msg->is_external));
1014  if (!out) {
1015  ast_json_unref(json_target);
1016  ast_json_unref(json_transferee);
1017  return NULL;
1018  }
1019  if (json_transferee && ast_json_object_set(out, "transferee", json_transferee)) {
1020  ast_json_unref(json_target);
1021  return NULL;
1022  }
1023  if (json_target && ast_json_object_set(out, "transfer_target", json_target)) {
1024  return NULL;
1025  }
1026 
1027  if (transfer_msg->to_transferee.bridge_snapshot) {
1028  json_bridge = ast_bridge_snapshot_to_json(transfer_msg->to_transferee.bridge_snapshot, sanitize);
1029 
1030  if (!json_bridge) {
1031  return NULL;
1032  }
1033 
1034  res |= ast_json_object_set(out, "transferer_first_leg_bridge", json_bridge);
1035  }
1036 
1037  if (transfer_msg->to_transfer_target.bridge_snapshot) {
1038  json_bridge = ast_bridge_snapshot_to_json(transfer_msg->to_transfer_target.bridge_snapshot, sanitize);
1039 
1040  if (!json_bridge) {
1041  return NULL;
1042  }
1043 
1044  res |= ast_json_object_set(out, "transferer_second_leg_bridge", json_bridge);
1045  }
1046 
1047  switch (transfer_msg->dest_type) {
1049  res |= ast_json_object_set(out, "destination_type", ast_json_string_create("bridge"));
1050  res |= ast_json_object_set(out, "destination_bridge", ast_json_string_create(transfer_msg->dest.bridge));
1051  break;
1053  res |= ast_json_object_set(out, "replace_channel", ast_channel_snapshot_to_json(transfer_msg->replace_channel, sanitize));
1054  /* fallthrough */
1056  res |= ast_json_object_set(out, "destination_type", ast_json_string_create("application"));
1057  res |= ast_json_object_set(out, "destination_application", ast_json_string_create(transfer_msg->dest.app));
1058  break;
1060  res |= ast_json_object_set(out, "destination_type", ast_json_string_create("link"));
1061 
1062  json_channel = ast_channel_snapshot_to_json(transfer_msg->dest.links[0], sanitize);
1063  if (!json_channel) {
1064  return NULL;
1065  }
1066  res |= ast_json_object_set(out, "destination_link_first_leg", json_channel);
1067 
1068  json_channel = ast_channel_snapshot_to_json(transfer_msg->dest.links[1], sanitize);
1069  if (!json_channel) {
1070  return NULL;
1071  }
1072  res |= ast_json_object_set(out, "destination_link_second_leg", json_channel);
1073 
1074  break;
1076  res |= ast_json_object_set(out, "destination_type", ast_json_string_create("threeway"));
1077 
1078  json_channel = ast_channel_snapshot_to_json(transfer_msg->dest.threeway.channel_snapshot, sanitize);
1079  if (!json_channel) {
1080  return NULL;
1081  }
1082  res |= ast_json_object_set(out, "destination_threeway_channel", json_channel);
1083 
1084  json_bridge = ast_bridge_snapshot_to_json(transfer_msg->dest.threeway.bridge_snapshot, sanitize);
1085  if (!json_bridge) {
1086  return NULL;
1087  }
1088  res |= ast_json_object_set(out, "destination_threeway_bridge", json_bridge);
1089 
1090  break;
1092  res |= ast_json_object_set(out, "destination_type", ast_json_string_create("fail"));
1093  break;
1094  }
1095 
1096  if (res) {
1097  return NULL;
1098  }
1099 
1100  return ast_json_ref(out);
1101 }
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
union ast_attended_transfer_message::@324 dest
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
Message representing attended transfer.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
struct ast_channel_snapshot * target
char bridge[AST_UUID_STR_LEN]
#define NULL
Definition: resample.c:96
struct ast_bridge_channel_snapshot_pair to_transferee
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_bridge_channel_snapshot_pair to_transfer_target
enum ast_transfer_result result
struct ast_channel_snapshot * links[2]
#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
struct ast_channel_snapshot * transferee
const struct timeval * stasis_message_timestamp(const struct stasis_message *msg)
Get the time when a message was created.
struct ast_channel_snapshot * replace_channel
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
Definition: json.c:649
enum ast_attended_transfer_dest_type dest_type
struct ast_channel_snapshot * channel_snapshot
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct ast_bridge_channel_snapshot_pair threeway
struct ast_bridge_snapshot * bridge_snapshot
struct ast_json * ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_channel_snapshot.
FILE * out
Definition: utils/frame.c:33
static const char * result_strs[]
Abstract JSON element (object, array, string, int, ...).
struct ast_json * ast_bridge_snapshot_to_json(const struct ast_bridge_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_bridge_snapshot.
struct ast_json * ast_json_boolean(int value)
Get the JSON boolean corresponding to value.
Definition: json.c:243

◆ blind_transfer_dtor()

static void blind_transfer_dtor ( void *  obj)
static

Definition at line 919 of file stasis_bridges.c.

References ao2_cleanup, ast_blind_transfer_message::bridge, ast_blind_transfer_message::replace_channel, ast_blind_transfer_message::transferee, and ast_blind_transfer_message::transferer.

Referenced by ast_blind_transfer_message_create().

920 {
921  struct ast_blind_transfer_message *msg = obj;
922 
923  ao2_cleanup(msg->transferer);
924  ao2_cleanup(msg->bridge);
925  ao2_cleanup(msg->transferee);
927 }
Message published during a blind transfer.
struct ast_bridge_snapshot * bridge
struct ast_channel_snapshot * transferer
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_channel_snapshot * transferee
struct ast_channel_snapshot * replace_channel

◆ blind_transfer_to_ami()

static struct ast_manager_event_blob * blind_transfer_to_ami ( struct stasis_message message)
static

Definition at line 870 of file stasis_bridges.c.

References ast_free_ptr(), ast_manager_build_bridge_state_string(), ast_manager_build_channel_state_string_prefix(), ast_manager_event_blob_create(), ast_str_buffer(), ast_blind_transfer_message::bridge, ast_blind_transfer_message::context, EVENT_FLAG_CALL, ast_blind_transfer_message::exten, ast_blind_transfer_message::is_external, NULL, RAII_VAR, ast_blind_transfer_message::result, result_strs, stasis_message_data(), ast_blind_transfer_message::transferee, and ast_blind_transfer_message::transferer.

871 {
872  RAII_VAR(struct ast_str *, transferer_state, NULL, ast_free_ptr);
873  RAII_VAR(struct ast_str *, bridge_state, NULL, ast_free_ptr);
874  RAII_VAR(struct ast_str *, transferee_state, NULL, ast_free_ptr);
875  struct ast_blind_transfer_message *transfer_msg = stasis_message_data(msg);
876 
877  if (!transfer_msg) {
878  return NULL;
879  }
880 
882  transfer_msg->transferer, "Transferer");
883  if (!transferer_state) {
884  return NULL;
885  }
886 
887  if (transfer_msg->bridge) {
888  bridge_state = ast_manager_build_bridge_state_string(transfer_msg->bridge);
889  if (!bridge_state) {
890  return NULL;
891  }
892  }
893 
894  if (transfer_msg->transferee) {
896  transfer_msg->transferee, "Transferee");
897  if (!transferee_state) {
898  return NULL;
899  }
900  }
901 
902  return ast_manager_event_blob_create(EVENT_FLAG_CALL, "BlindTransfer",
903  "Result: %s\r\n"
904  "%s"
905  "%s"
906  "%s"
907  "IsExternal: %s\r\n"
908  "Context: %s\r\n"
909  "Extension: %s\r\n",
910  result_strs[transfer_msg->result],
911  ast_str_buffer(transferer_state),
912  transferee_state ? ast_str_buffer(transferee_state) : "",
913  bridge_state ? ast_str_buffer(bridge_state) : "",
914  transfer_msg->is_external ? "Yes" : "No",
915  transfer_msg->context,
916  transfer_msg->exten);
917 }
char exten[AST_MAX_EXTENSION]
Message published during a blind transfer.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
struct ast_str * ast_manager_build_channel_state_string_prefix(const struct ast_channel_snapshot *snapshot, const char *prefix)
Generate the AMI message body from a channel snapshot.
#define EVENT_FLAG_CALL
Definition: manager.h:72
#define NULL
Definition: resample.c:96
void ast_free_ptr(void *ptr)
free() wrapper
Definition: astmm.c:1771
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 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_bridge_snapshot * bridge
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_channel_snapshot * transferer
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.
char context[AST_MAX_CONTEXT]
static const char * result_strs[]
struct ast_channel_snapshot * transferee
enum ast_transfer_result result

◆ blind_transfer_to_json()

static struct ast_json * blind_transfer_to_json ( struct stasis_message msg,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 799 of file stasis_bridges.c.

References ast_bridge_snapshot_to_json(), ast_channel_snapshot_to_json(), ast_json_boolean(), ast_json_object_set(), ast_json_pack(), ast_json_timeval(), ast_json_unref(), ast_blind_transfer_message::bridge, ast_blind_transfer_message::context, ast_blind_transfer_message::exten, ast_blind_transfer_message::is_external, NULL, out, ast_blind_transfer_message::replace_channel, ast_blind_transfer_message::result, result_strs, stasis_message_data(), stasis_message_timestamp(), ast_blind_transfer_message::transferee, and ast_blind_transfer_message::transferer.

801 {
802  struct ast_blind_transfer_message *transfer_msg = stasis_message_data(msg);
803  struct ast_json *json_transferer;
804  struct ast_json *json_transferee = NULL;
805  struct ast_json *out;
806  struct ast_json *json_replace = NULL;
807  const struct timeval *tv = stasis_message_timestamp(msg);
808 
809  json_transferer = ast_channel_snapshot_to_json(transfer_msg->transferer, sanitize);
810  if (!json_transferer) {
811  return NULL;
812  }
813 
814  if (transfer_msg->transferee) {
815  json_transferee = ast_channel_snapshot_to_json(transfer_msg->transferee, sanitize);
816  if (!json_transferee) {
817  ast_json_unref(json_transferer);
818  return NULL;
819  }
820  }
821 
822  if (transfer_msg->replace_channel) {
823  json_replace = ast_channel_snapshot_to_json(transfer_msg->replace_channel, sanitize);
824  if (!json_replace) {
825  ast_json_unref(json_transferee);
826  ast_json_unref(json_transferer);
827  return NULL;
828  }
829  }
830 
831  out = ast_json_pack("{s: s, s: o, s: o, s: s, s: s, s: s, s: o}",
832  "type", "BridgeBlindTransfer",
833  "timestamp", ast_json_timeval(*tv, NULL),
834  "channel", json_transferer,
835  "exten", transfer_msg->exten,
836  "context", transfer_msg->context,
837  "result", result_strs[transfer_msg->result],
838  "is_external", ast_json_boolean(transfer_msg->is_external));
839 
840  if (!out) {
841  ast_json_unref(json_transferee);
842  ast_json_unref(json_replace);
843  return NULL;
844  }
845 
846  if (json_transferee && ast_json_object_set(out, "transferee", json_transferee)) {
847  ast_json_unref(out);
848  ast_json_unref(json_replace);
849  return NULL;
850  }
851 
852  if (json_replace && ast_json_object_set(out, "replace_channel", json_replace)) {
853  ast_json_unref(out);
854  return NULL;
855  }
856 
857  if (transfer_msg->bridge) {
858  struct ast_json *json_bridge = ast_bridge_snapshot_to_json(
859  transfer_msg->bridge, sanitize);
860 
861  if (!json_bridge || ast_json_object_set(out, "bridge", json_bridge)) {
862  ast_json_unref(out);
863  return NULL;
864  }
865  }
866 
867  return out;
868 }
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
char exten[AST_MAX_EXTENSION]
Message published during a blind transfer.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
#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
const struct timeval * stasis_message_timestamp(const struct stasis_message *msg)
Get the time when a message was created.
struct ast_bridge_snapshot * bridge
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
Definition: json.c:649
struct ast_channel_snapshot * transferer
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
char context[AST_MAX_CONTEXT]
struct ast_json * ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_channel_snapshot.
FILE * out
Definition: utils/frame.c:33
static const char * result_strs[]
Abstract JSON element (object, array, string, int, ...).
struct ast_json * ast_bridge_snapshot_to_json(const struct ast_bridge_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_bridge_snapshot.
struct ast_json * ast_json_boolean(int value)
Get the JSON boolean corresponding to value.
Definition: json.c:243
struct ast_channel_snapshot * transferee
enum ast_transfer_result result
struct ast_channel_snapshot * replace_channel

◆ bridge_blob_dtor()

static void bridge_blob_dtor ( void *  obj)
static

Definition at line 489 of file stasis_bridges.c.

References ao2_cleanup, ast_json_unref(), and NULL.

Referenced by ast_bridge_blob_create(), and ast_bridge_blob_create_from_snapshots().

490 {
491  struct ast_bridge_blob *event = obj;
492  ao2_cleanup(event->bridge);
493  event->bridge = NULL;
494  ao2_cleanup(event->channel);
495  event->channel = NULL;
496  ast_json_unref(event->blob);
497  event->blob = NULL;
498 }
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
Definition: astman.c:222
#define NULL
Definition: resample.c:96
Blob of data associated with a bridge.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ bridge_channel_snapshot_pair_cleanup()

static void bridge_channel_snapshot_pair_cleanup ( struct ast_bridge_channel_snapshot_pair pair)
static

Definition at line 786 of file stasis_bridges.c.

References ao2_cleanup, ast_bridge_channel_snapshot_pair::bridge_snapshot, and ast_bridge_channel_snapshot_pair::channel_snapshot.

Referenced by attended_transfer_dtor().

787 {
790 }
struct ast_channel_snapshot * channel_snapshot
struct ast_bridge_snapshot * bridge_snapshot
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ bridge_channel_snapshot_pair_init()

static int bridge_channel_snapshot_pair_init ( struct ast_channel channel,
struct ast_bridge bridge,
struct ast_bridge_channel_snapshot_pair snapshot_pair 
)
static

Definition at line 760 of file stasis_bridges.c.

References ast_bridge_lock, ast_bridge_snapshot_create(), ast_bridge_unlock, ast_channel_snapshot_get_latest(), ast_channel_uniqueid(), ast_bridge_channel_snapshot_pair::bridge_snapshot, and ast_bridge_channel_snapshot_pair::channel_snapshot.

Referenced by ast_attended_transfer_message_create().

762 {
763  if (bridge) {
764  ast_bridge_lock(bridge);
765  snapshot_pair->bridge_snapshot = ast_bridge_snapshot_create(bridge);
766  ast_bridge_unlock(bridge);
767  if (!snapshot_pair->bridge_snapshot) {
768  return -1;
769  }
770  }
771 
773  if (!snapshot_pair->channel_snapshot) {
774  return -1;
775  }
776 
777  return 0;
778 }
const char * ast_channel_uniqueid(const struct ast_channel *chan)
struct ast_channel_snapshot * channel_snapshot
struct ast_bridge_snapshot * bridge_snapshot
#define ast_bridge_unlock(bridge)
Unlock the bridge.
Definition: bridge.h:493
struct ast_bridge_snapshot * ast_bridge_snapshot_create(struct ast_bridge *bridge)
Generate a snapshot of the bridge state. This is an ao2 object, so ao2_cleanup() to deallocate...
#define ast_bridge_lock(bridge)
Lock the bridge.
Definition: bridge.h:480
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...

◆ bridge_merge_message_create()

static struct ast_bridge_merge_message* bridge_merge_message_create ( struct ast_bridge to,
struct ast_bridge from 
)
static

Bridge merge message creation helper.

Definition at line 418 of file stasis_bridges.c.

References ao2_alloc, ao2_ref, ast_bridge_snapshot_create(), bridge_merge_message_dtor(), ast_bridge_merge_message::from, NULL, and ast_bridge_merge_message::to.

Referenced by ast_bridge_publish_merge().

419 {
420  struct ast_bridge_merge_message *msg;
421 
422  msg = ao2_alloc(sizeof(*msg), bridge_merge_message_dtor);
423  if (!msg) {
424  return NULL;
425  }
426 
427  msg->to = ast_bridge_snapshot_create(to);
428  msg->from = ast_bridge_snapshot_create(from);
429  if (!msg->to || !msg->from) {
430  ao2_ref(msg, -1);
431 
432  return NULL;
433  }
434 
435  return msg;
436 }
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static void bridge_merge_message_dtor(void *obj)
Destructor for bridge merge messages.
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
struct ast_bridge_snapshot * ast_bridge_snapshot_create(struct ast_bridge *bridge)
Generate a snapshot of the bridge state. This is an ao2 object, so ao2_cleanup() to deallocate...
struct ast_bridge_snapshot * from
Message representing the merge of two bridges.
struct ast_bridge_snapshot * to

◆ bridge_merge_message_dtor()

static void bridge_merge_message_dtor ( void *  obj)
static

Destructor for bridge merge messages.

Definition at line 407 of file stasis_bridges.c.

References ao2_cleanup, ast_bridge_merge_message::from, NULL, and ast_bridge_merge_message::to.

Referenced by bridge_merge_message_create().

408 {
409  struct ast_bridge_merge_message *msg = obj;
410 
411  ao2_cleanup(msg->to);
412  msg->to = NULL;
413  ao2_cleanup(msg->from);
414  msg->from = NULL;
415 }
#define NULL
Definition: resample.c:96
struct ast_bridge_snapshot * from
Message representing the merge of two bridges.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_bridge_snapshot * to

◆ bridge_publish_state_from_blob()

static void bridge_publish_state_from_blob ( struct ast_bridge bridge,
struct ast_bridge_blob obj 
)
static

Definition at line 381 of file stasis_bridges.c.

References ao2_bump, ao2_cleanup, ao2_ref, ast_assert, ast_bridge_snapshot_type(), ast_bridge_topic(), ast_bridge_blob::bridge, bridge_snapshot_update_create(), ast_bridge::current_snapshot, NULL, stasis_message_create(), stasis_publish(), and update().

Referenced by ast_bridge_publish_enter(), and ast_bridge_publish_leave().

383 {
385  struct stasis_message *msg;
386 
387  ast_assert(obj != NULL);
388 
389  update = bridge_snapshot_update_create(bridge->current_snapshot, obj->bridge);
390  ao2_cleanup(bridge->current_snapshot);
391  bridge->current_snapshot = ao2_bump(obj->bridge);
392  if (!update) {
393  return;
394  }
395 
397  ao2_ref(update, -1);
398  if (!msg) {
399  return;
400  }
401 
402  stasis_publish(ast_bridge_topic(bridge), msg);
403  ao2_ref(msg, -1);
404 }
struct stasis_message_type * ast_bridge_snapshot_type(void)
Message type for ast_bridge_snapshot.
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
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define ao2_bump(obj)
Definition: astobj2.h:491
struct ast_bridge_snapshot * bridge
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static struct ast_bridge_snapshot_update * bridge_snapshot_update_create(struct ast_bridge_snapshot *old, struct ast_bridge_snapshot *new)
struct ast_bridge_snapshot * current_snapshot
Definition: bridge.h:414
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
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_bridge_topic(struct ast_bridge *bridge)
A topic which publishes the events for a particular bridge.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ bridge_snapshot_dtor()

static void bridge_snapshot_dtor ( void *  obj)
static

Destructor for bridge snapshots.

Definition at line 194 of file stasis_bridges.c.

References ao2_cleanup, ast_string_field_free_memory, ast_bridge_snapshot::channels, and NULL.

Referenced by ast_bridge_snapshot_create().

195 {
196  struct ast_bridge_snapshot *snapshot = obj;
198  ao2_cleanup(snapshot->channels);
199  snapshot->channels = NULL;
200 }
struct ao2_container * channels
Definition: bridge.h:339
Structure that contains a snapshot of information about a bridge.
Definition: bridge.h:322
#define NULL
Definition: resample.c:96
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368

◆ bridge_snapshot_update_create()

static struct ast_bridge_snapshot_update* bridge_snapshot_update_create ( struct ast_bridge_snapshot old,
struct ast_bridge_snapshot new 
)
static

Definition at line 275 of file stasis_bridges.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_bump, ast_debug, bridge_snapshot_update_dtor(), ast_bridge_snapshot_update::new_snapshot, NULL, ast_bridge_snapshot_update::old_snapshot, ast_bridge_snapshot::uniqueid, and update().

Referenced by ast_bridge_publish_state(), bridge_publish_state_from_blob(), and bridge_topics_destroy().

277 {
279 
280  update = ao2_alloc_options(sizeof(*update), bridge_snapshot_update_dtor,
282  if (!update) {
283  return NULL;
284  }
285  update->old_snapshot = ao2_bump(old);
286  update->new_snapshot = ao2_bump(new);
287 
288  ast_debug(3, "Update: %p Old: %s New: %s\n", update,
289  update->old_snapshot ? update->old_snapshot->uniqueid : "<none>",
290  update->new_snapshot ? update->new_snapshot->uniqueid : "<none>");
291 
292  return update;
293 }
static void bridge_snapshot_update_dtor(void *obj)
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
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define NULL
Definition: resample.c:96
#define ao2_bump(obj)
Definition: astobj2.h:491
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
struct ast_bridge_snapshot * old_snapshot
const ast_string_field uniqueid
Definition: bridge.h:336
struct ast_bridge_snapshot * new_snapshot

◆ bridge_snapshot_update_dtor()

static void bridge_snapshot_update_dtor ( void *  obj)
static

Definition at line 264 of file stasis_bridges.c.

References ao2_cleanup, ast_debug, ast_bridge_snapshot_update::new_snapshot, ast_bridge_snapshot_update::old_snapshot, ast_bridge_snapshot::uniqueid, and update().

Referenced by bridge_snapshot_update_create().

265 {
266  struct ast_bridge_snapshot_update *update = obj;
267 
268  ast_debug(3, "Update: %p Old: %s New: %s\n", update,
269  update->old_snapshot ? update->old_snapshot->uniqueid : "<none>",
270  update->new_snapshot ? update->new_snapshot->uniqueid : "<none>");
271  ao2_cleanup(update->old_snapshot);
272  ao2_cleanup(update->new_snapshot);
273 }
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
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
struct ast_bridge_snapshot * old_snapshot
const ast_string_field uniqueid
Definition: bridge.h:336
struct ast_bridge_snapshot * new_snapshot
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ bridge_topics_destroy()

void bridge_topics_destroy ( struct ast_bridge bridge)

Definition at line 319 of file stasis_bridges.c.

References ao2_ref, ast_assert, ast_bridge_snapshot_create(), ast_bridge_snapshot_type(), ast_bridge_topic(), bridge_snapshot_update_create(), ast_bridge::current_snapshot, NULL, stasis_message_create(), stasis_publish(), stasis_topic_name(), stasis_topic_pool_delete_topic(), and update().

Referenced by destroy_bridge().

320 {
322  struct stasis_message *msg;
323 
324  ast_assert(bridge != NULL);
325 
326  if (!bridge->current_snapshot) {
328  if (!bridge->current_snapshot) {
329  return;
330  }
331  }
332 
334  if (!update) {
335  return;
336  }
337 
339  ao2_ref(update, -1);
340  if (!msg) {
341  return;
342  }
343 
344  stasis_publish(ast_bridge_topic(bridge), msg);
345  ao2_ref(msg, -1);
346 
348 }
struct stasis_message_type * ast_bridge_snapshot_type(void)
Message type for ast_bridge_snapshot.
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
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static struct ast_bridge_snapshot_update * bridge_snapshot_update_create(struct ast_bridge_snapshot *old, struct ast_bridge_snapshot *new)
void stasis_topic_pool_delete_topic(struct stasis_topic_pool *pool, const char *topic_name)
Delete a topic from the topic pool.
Definition: stasis.c:1864
struct ast_bridge_snapshot * current_snapshot
Definition: bridge.h:414
static struct stasis_topic_pool * bridge_topic_pool
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
const char * stasis_topic_name(const struct stasis_topic *topic)
Return the name of a topic.
Definition: stasis.c:628
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 ast_bridge_snapshot * ast_bridge_snapshot_create(struct ast_bridge *bridge)
Generate a snapshot of the bridge state. This is an ao2 object, so ao2_cleanup() to deallocate...
struct stasis_topic * ast_bridge_topic(struct ast_bridge *bridge)
A topic which publishes the events for a particular bridge.

◆ bridge_topics_init()

int bridge_topics_init ( struct ast_bridge bridge)

Definition at line 295 of file stasis_bridges.c.

References ast_asprintf, ast_free, ast_log, ast_strlen_zero, LOG_ERROR, stasis_topic_pool_get_topic(), ast_bridge::topic, and ast_bridge::uniqueid.

Referenced by bridge_base_init().

296 {
297  char *topic_name;
298  int ret;
299 
300  if (ast_strlen_zero(bridge->uniqueid)) {
301  ast_log(LOG_ERROR, "Bridge id initialization required\n");
302  return -1;
303  }
304 
305  ret = ast_asprintf(&topic_name, "bridge:%s", bridge->uniqueid);
306  if (ret < 0) {
307  return -1;
308  }
309 
310  bridge->topic = stasis_topic_pool_get_topic(bridge_topic_pool, topic_name);
311  ast_free(topic_name);
312  if (!bridge->topic) {
313  return -1;
314  }
315 
316  return 0;
317 }
const ast_string_field uniqueid
Definition: bridge.h:409
struct stasis_topic * stasis_topic_pool_get_topic(struct stasis_topic_pool *pool, const char *topic_name)
Find or create a topic in the pool.
Definition: stasis.c:1884
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:269
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
static struct stasis_topic_pool * bridge_topic_pool
#define ast_free(a)
Definition: astmm.h:182
struct stasis_topic * topic
Definition: bridge.h:367

◆ capability2str()

static const char* capability2str ( uint32_t  capabilities)
static

Definition at line 703 of file stasis_bridges.c.

References AST_BRIDGE_CAPABILITY_HOLDING.

Referenced by ast_bridge_snapshot_to_json().

704 {
705  if (capabilities & AST_BRIDGE_CAPABILITY_HOLDING) {
706  return "holding";
707  } else {
708  return "mixing";
709  }
710 }

◆ container_to_json_array()

static struct ast_json* container_to_json_array ( struct ao2_container items,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 673 of file stasis_bridges.c.

References ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ast_json_array_append(), ast_json_array_create(), ast_json_string_create(), ast_json_unref(), stasis_message_sanitizer::channel_id, item, and NULL.

Referenced by ast_bridge_snapshot_to_json().

675 {
676  struct ast_json *json_items = ast_json_array_create();
677  char *item;
678  struct ao2_iterator it;
679 
680  if (!json_items) {
681  return NULL;
682  }
683 
684  for (it = ao2_iterator_init(items, 0);
685  (item = ao2_iterator_next(&it)); ao2_cleanup(item)) {
686  if (sanitize && sanitize->channel_id && sanitize->channel_id(item)) {
687  continue;
688  }
689 
690  if (ast_json_array_append(json_items, ast_json_string_create(item))) {
691  ao2_cleanup(item);
693  ast_json_unref(json_items);
694 
695  return NULL;
696  }
697  }
699 
700  return json_items;
701 }
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
int(* channel_id)(const char *channel_id)
Callback which determines whether a channel should be sanitized from a message based on the channel&#39;s...
Definition: stasis.h:210
static struct aco_type item
Definition: test_config.c:1463
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define NULL
Definition: resample.c:96
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition: json.c:352
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition: json.c:368
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
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
Abstract JSON element (object, array, string, int, ...).
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.

◆ simple_bridge_channel_event()

static struct ast_json* simple_bridge_channel_event ( const char *  type,
struct ast_bridge_snapshot bridge_snapshot,
struct ast_channel_snapshot channel_snapshot,
const struct timeval *  tv,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 629 of file stasis_bridges.c.

References ast_bridge_snapshot_to_json(), ast_channel_snapshot_to_json(), ast_json_pack(), ast_json_timeval(), ast_json_unref(), and NULL.

Referenced by ast_channel_entered_bridge_to_json(), and ast_channel_left_bridge_to_json().

635 {
636  struct ast_json *json_bridge = ast_bridge_snapshot_to_json(bridge_snapshot, sanitize);
637  struct ast_json *json_channel = ast_channel_snapshot_to_json(channel_snapshot, sanitize);
638 
639  if (!json_bridge || !json_channel) {
640  ast_json_unref(json_bridge);
641  ast_json_unref(json_channel);
642 
643  return NULL;
644  }
645 
646  return ast_json_pack("{s: s, s: o, s: o, s: o}",
647  "type", type,
648  "timestamp", ast_json_timeval(*tv, NULL),
649  "bridge", json_bridge,
650  "channel", json_channel);
651 }
static const char type[]
Definition: chan_ooh323.c:109
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 NULL
Definition: resample.c:96
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
Definition: json.c:649
struct ast_json * ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_channel_snapshot.
Abstract JSON element (object, array, string, int, ...).
struct ast_json * ast_bridge_snapshot_to_json(const struct ast_bridge_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_bridge_snapshot.

◆ stasis_bridging_cleanup()

static void stasis_bridging_cleanup ( void  )
static

Definition at line 1392 of file stasis_bridges.c.

References ao2_cleanup, ast_attended_transfer_type(), ast_blind_transfer_type(), ast_bridge_merge_message_type(), ast_bridge_snapshot_type(), ast_channel_entered_bridge_type(), ast_channel_left_bridge_type(), NULL, and STASIS_MESSAGE_TYPE_CLEANUP.

Referenced by ast_stasis_bridging_init().

1393 {
1400 
1405 }
struct stasis_message_type * ast_bridge_snapshot_type(void)
Message type for ast_bridge_snapshot.
struct stasis_message_type * ast_blind_transfer_type(void)
Message type for ast_blind_transfer_message.
struct stasis_message_type * ast_channel_entered_bridge_type(void)
Message type for channel enter bridge blob messages.
struct stasis_message_type * ast_channel_left_bridge_type(void)
Message type for channel leave bridge blob messages.
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
Definition: stasis.h:1523
#define NULL
Definition: resample.c:96
struct stasis_message_type * ast_bridge_merge_message_type(void)
Message type for ast_bridge_merge_message.
static struct stasis_topic_pool * bridge_topic_pool
static struct stasis_topic * bridge_topic_all
struct stasis_message_type * ast_attended_transfer_type(void)
Message type for ast_attended_transfer_message.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ STASIS_MESSAGE_TYPE_DEFN() [1/6]

STASIS_MESSAGE_TYPE_DEFN ( ast_bridge_snapshot_type  )

Define bridge message types.

◆ STASIS_MESSAGE_TYPE_DEFN() [2/6]

STASIS_MESSAGE_TYPE_DEFN ( ast_bridge_merge_message_type  ,
to_json = ast_bridge_merge_message_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [3/6]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_entered_bridge_type  ,
to_json = ast_channel_entered_bridge_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [4/6]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_left_bridge_type  ,
to_json = ast_channel_left_bridge_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [5/6]

STASIS_MESSAGE_TYPE_DEFN ( ast_blind_transfer_type  ,
to_json = blind_transfer_to_json,
to_ami = blind_transfer_to_ami 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [6/6]

STASIS_MESSAGE_TYPE_DEFN ( ast_attended_transfer_type  ,
to_json = attended_transfer_to_json,
to_ami = attended_transfer_to_ami 
)

Variable Documentation

◆ bridge_topic_all

struct stasis_topic* bridge_topic_all
static

Definition at line 158 of file stasis_bridges.c.

Referenced by ast_bridge_topic_all().

◆ bridge_topic_pool

struct stasis_topic_pool* bridge_topic_pool
static

Definition at line 159 of file stasis_bridges.c.

◆ result_strs

const char* result_strs[]
static