Asterisk - The Open Source Telephony Project GIT-master-2de1a68
Data Structures | Macros | Functions | Variables
stasis_channels.c File Reference

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

#include "asterisk.h"
#include "asterisk/astobj2.h"
#include "asterisk/json.h"
#include "asterisk/pbx.h"
#include "asterisk/bridge.h"
#include "asterisk/translate.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/dial.h"
#include "asterisk/linkedlists.h"
#include "asterisk/utf8.h"
Include dependency graph for stasis_channels.c:

Go to the source code of this file.

Data Structures

struct  ast_multi_channel_blob
 A multi channel blob data structure for multi_channel_blob stasis messages. More...
 
struct  channel_role_snapshot
 A channel snapshot wrapper object used in ast_multi_channel_blob objects. More...
 
struct  dial_masquerade_datastore
 
struct  dial_target
 

Macros

#define NUM_MULTI_CHANNEL_BLOB_BUCKETS   7
 

Functions

static struct ast_manager_event_blobagent_login_to_ami (struct stasis_message *msg)
 
static struct ast_manager_event_blobagent_logoff_to_ami (struct stasis_message *msg)
 
struct stasis_messageast_channel_blob_create (struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
 Creates a ast_channel_blob message. More...
 
struct stasis_messageast_channel_blob_create_from_cache (const char *channel_id, struct stasis_message_type *type, struct ast_json *blob)
 Create a ast_channel_blob message, pulling channel state from the cache. More...
 
struct ao2_containerast_channel_cache_all (void)
 
struct ao2_containerast_channel_cache_by_name (void)
 Secondary channel cache, indexed by name. More...
 
void ast_channel_publish_blob (struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
 Publish a channel blob message. More...
 
void ast_channel_publish_cached_blob (struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
 Publish a channel blob message using the latest snapshot from the cache. More...
 
void ast_channel_publish_dial (struct ast_channel *caller, struct ast_channel *peer, const char *dialstring, const char *dialstatus)
 Publish in the ast_channel_topic or ast_channel_topic_all topics a stasis message for the channels involved in a dial operation. More...
 
void ast_channel_publish_dial_forward (struct ast_channel *caller, struct ast_channel *peer, struct ast_channel *forwarded, const char *dialstring, const char *dialstatus, const char *forward)
 Publish in the ast_channel_topic or ast_channel_topic_all topics a stasis message for the channels involved in a dial operation that is forwarded. More...
 
static void ast_channel_publish_dial_internal (struct ast_channel *caller, struct ast_channel *peer, struct ast_channel *forwarded, const char *dialstring, const char *dialstatus, const char *forward)
 
void ast_channel_publish_final_snapshot (struct ast_channel *chan)
 Send the final channel snapshot for a channel, thus removing it from cache. More...
 
void ast_channel_publish_snapshot (struct ast_channel *chan)
 Publish a ast_channel_snapshot for a channel. More...
 
void ast_channel_publish_varset (struct ast_channel *chan, const char *name, const char *value)
 Publish a ast_channel_publish_varset for a channel. More...
 
int ast_channel_snapshot_caller_id_equal (const struct ast_channel_snapshot *old_snapshot, const struct ast_channel_snapshot *new_snapshot)
 Compares the callerid info of two snapshots. More...
 
int ast_channel_snapshot_cep_equal (const struct ast_channel_snapshot *old_snapshot, const struct ast_channel_snapshot *new_snapshot)
 Compares the context, exten and priority of two snapshots. More...
 
int ast_channel_snapshot_connected_line_equal (const struct ast_channel_snapshot *old_snapshot, const struct ast_channel_snapshot *new_snapshot)
 Compares the connected line info of two snapshots. More...
 
struct ast_channel_snapshotast_channel_snapshot_create (struct ast_channel *chan)
 Generate a snapshot of the channel state. This is an ao2 object, so ao2_cleanup() to deallocate. More...
 
struct ast_channel_snapshotast_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, so use ao2_cleanup() to deallocate. More...
 
struct ast_channel_snapshotast_channel_snapshot_get_latest_by_name (const char *name)
 Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object, so use ao2_cleanup() to deallocate. More...
 
void ast_channel_snapshot_invalidate_segment (struct ast_channel *chan, enum ast_channel_snapshot_segment_invalidation segment)
 Invalidate a channel snapshot segment from being reused. More...
 
struct ast_jsonast_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. More...
 
void ast_channel_stage_snapshot (struct ast_channel *chan)
 Set flag to indicate channel snapshot is being staged. More...
 
void ast_channel_stage_snapshot_done (struct ast_channel *chan)
 Clear flag to indicate channel snapshot is being staged, and publish snapshot. More...
 
struct stasis_topicast_channel_topic_all (void)
 A topic which publishes the events for all channels. More...
 
void ast_multi_channel_blob_add_channel (struct ast_multi_channel_blob *obj, const char *role, struct ast_channel_snapshot *snapshot)
 Add a ast_channel_snapshot to a ast_multi_channel_blob object. More...
 
struct ast_multi_channel_blobast_multi_channel_blob_create (struct ast_json *blob)
 Create a ast_multi_channel_blob suitable for a stasis_message. More...
 
struct ast_channel_snapshotast_multi_channel_blob_get_channel (struct ast_multi_channel_blob *obj, const char *role)
 Retrieve a channel snapshot associated with a specific role from a ast_multi_channel_blob. More...
 
struct ao2_containerast_multi_channel_blob_get_channels (struct ast_multi_channel_blob *obj, const char *role)
 Retrieve all channel snapshots associated with a specific role from a ast_multi_channel_blob. More...
 
struct ast_jsonast_multi_channel_blob_get_json (struct ast_multi_channel_blob *obj)
 Retrieve the JSON blob from a ast_multi_channel_blob. Returned ast_json is still owned by obj. More...
 
int ast_stasis_channels_init (void)
 Initialize the stasis channel topic and message types. More...
 
static void channel_blob_dtor (void *obj)
 
static struct ast_jsonchannel_blob_to_json (struct stasis_message *message, const char *type, const struct stasis_message_sanitizer *sanitize)
 
static int channel_role_cmp_cb (void *obj, void *arg, int flags)
 
static int channel_role_hash_cb (const void *obj, const int flags)
 
static void channel_role_snapshot_dtor (void *obj)
 
static struct ast_channel_snapshot_basechannel_snapshot_base_create (struct ast_channel *chan)
 
static void channel_snapshot_base_dtor (void *obj)
 
static struct ast_channel_snapshot_bridgechannel_snapshot_bridge_create (struct ast_channel *chan)
 
static struct ast_channel_snapshot_callerchannel_snapshot_caller_create (struct ast_channel *chan)
 
static void channel_snapshot_caller_dtor (void *obj)
 
static int channel_snapshot_cmp_cb (void *obj, void *arg, int flags)
 
static struct ast_channel_snapshot_connectedchannel_snapshot_connected_create (struct ast_channel *chan)
 
static struct ast_channel_snapshot_dialplanchannel_snapshot_dialplan_create (struct ast_channel *chan)
 
static void channel_snapshot_dialplan_dtor (void *obj)
 
static void channel_snapshot_dtor (void *obj)
 
static struct ast_channel_snapshot_hangupchannel_snapshot_hangup_create (struct ast_channel *chan)
 
static int channel_snapshot_hash_cb (const void *obj, const int flags)
 
static struct ast_channel_snapshot_peerchannel_snapshot_peer_create (struct ast_channel *chan)
 
static int channel_snapshot_uniqueid_cmp_cb (void *obj, void *arg, int flags)
 
static int channel_snapshot_uniqueid_hash_cb (const void *obj, const int flags)
 
static struct ast_channel_snapshot_updatechannel_snapshot_update_create (struct ast_channel *chan)
 
static void channel_snapshot_update_dtor (void *obj)
 
static struct stasis_messagecreate_channel_blob_message (struct ast_channel_snapshot *snapshot, struct stasis_message_type *type, struct ast_json *blob)
 
static void dial_masquerade_breakdown (void *data, struct ast_channel *old_chan, struct ast_channel *new_chan)
 
static void dial_masquerade_caller_datastore_destroy (void *data)
 
static struct dial_masquerade_datastoredial_masquerade_datastore_add (struct ast_channel *chan, struct dial_masquerade_datastore *masq_data)
 
static struct dial_masquerade_datastoredial_masquerade_datastore_alloc (void)
 
static void dial_masquerade_datastore_cleanup (struct dial_masquerade_datastore *masq_data)
 
static void dial_masquerade_datastore_destroy (void *data)
 
static void dial_masquerade_datastore_dtor (void *vdoomed)
 
static struct ast_datastoredial_masquerade_datastore_find (struct ast_channel *chan)
 
static void dial_masquerade_datastore_remove_chan (struct dial_masquerade_datastore *masq_data, struct ast_channel *chan)
 
static void dial_masquerade_fixup (void *data, struct ast_channel *old_chan, struct ast_channel *new_chan)
 
static void dial_target_free (struct dial_target *doomed)
 
static struct ast_jsondial_to_json (struct stasis_message *message, const struct stasis_message_sanitizer *sanitize)
 
static struct ast_jsondtmf_end_to_json (struct stasis_message *message, const struct stasis_message_sanitizer *sanitize)
 
static struct ast_jsonhangup_request_to_json (struct stasis_message *message, const struct stasis_message_sanitizer *sanitize)
 
static struct ast_jsonhold_to_json (struct stasis_message *message, const struct stasis_message_sanitizer *sanitize)
 
static void multi_channel_blob_dtor (void *obj)
 
static void publish_message_for_channel_topics (struct stasis_message *message, struct ast_channel *chan)
 
static void remove_dial_masquerade (struct ast_channel *peer)
 
static void remove_dial_masquerade_caller (struct ast_channel *caller)
 
static int set_dial_masquerade (struct ast_channel *caller, struct ast_channel *peer, const char *dialstring)
 
static void stasis_channels_cleanup (void)
 
static struct ast_manager_event_blobtalking_start_to_ami (struct stasis_message *msg)
 
static struct ast_jsontalking_start_to_json (struct stasis_message *message, const struct stasis_message_sanitizer *sanitize)
 
static struct ast_manager_event_blobtalking_stop_to_ami (struct stasis_message *msg)
 
static struct ast_jsontalking_stop_to_json (struct stasis_message *message, const struct stasis_message_sanitizer *sanitize)
 
static struct ast_jsonunhold_to_json (struct stasis_message *message, const struct stasis_message_sanitizer *sanitize)
 
static struct ast_manager_event_blobvarset_to_ami (struct stasis_message *msg)
 
static struct ast_jsonvarset_to_json (struct stasis_message *message, const struct stasis_message_sanitizer *sanitize)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_agent_login_type,.to_ami=agent_login_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_agent_logoff_type,.to_ami=agent_logoff_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_chanspy_start_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_chanspy_stop_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_dial_type,.to_json=dial_to_json,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_dtmf_begin_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_dtmf_end_type,.to_json=dtmf_end_to_json,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_fax_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_flash_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_hangup_handler_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_hangup_request_type,.to_json=hangup_request_to_json,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_hold_type,.to_json=hold_to_json,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_masquerade_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_mixmonitor_mute_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_mixmonitor_start_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_mixmonitor_stop_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_moh_start_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_moh_stop_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_snapshot_type)
 Define channel message types. More...
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_talking_start,.to_ami=talking_start_to_ami,.to_json=talking_start_to_json,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_talking_stop,.to_ami=talking_stop_to_ami,.to_json=talking_stop_to_json,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_unhold_type,.to_json=unhold_to_json,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_varset_type,.to_ami=varset_to_ami,.to_json=varset_to_json,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_wink_type)
 

Variables

static struct ao2_containerchannel_cache
 
static struct ao2_containerchannel_cache_by_name
 
static struct stasis_topicchannel_topic_all
 
static const struct ast_datastore_info dial_masquerade_caller_info
 
static const struct ast_datastore_info dial_masquerade_info
 

Detailed Description

Stasis Messages and Data Types for Channel Objects.

Author
Matt Jordan <mjordan@digium.com> 

Definition in file stasis_channels.c.

Macro Definition Documentation

◆ NUM_MULTI_CHANNEL_BLOB_BUCKETS

#define NUM_MULTI_CHANNEL_BLOB_BUCKETS   7

Definition at line 118 of file stasis_channels.c.

Function Documentation

◆ agent_login_to_ami()

static struct ast_manager_event_blob * agent_login_to_ami ( struct stasis_message msg)
static

Definition at line 1248 of file stasis_channels.c.

1249{
1250 struct ast_str *channel_string;
1251 struct ast_channel_blob *obj = stasis_message_data(msg);
1252 const char *agent = ast_json_string_get(ast_json_object_get(obj->blob, "agent"));
1253 struct ast_manager_event_blob *ev;
1254
1255 channel_string = ast_manager_build_channel_state_string(obj->snapshot);
1256 if (!channel_string) {
1257 return NULL;
1258 }
1259
1261 "%s"
1262 "Agent: %s\r\n",
1263 ast_str_buffer(channel_string), agent);
1264 ast_free(channel_string);
1265 return ev;
1266}
#define ast_free(a)
Definition: astmm.h:180
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:283
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:407
struct ast_str * ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
Generate the AMI message body from a channel snapshot.
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:10521
#define EVENT_FLAG_AGENT
Definition: manager.h:80
#define NULL
Definition: resample.c:96
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
Blob of data associated with a channel.
struct ast_channel_snapshot * snapshot
struct ast_json * blob
Struct containing info for an AMI event to send out.
Definition: manager.h:502
Support for dynamic strings.
Definition: strings.h:623

References ast_free, ast_json_object_get(), ast_json_string_get(), ast_manager_build_channel_state_string(), ast_manager_event_blob_create(), ast_str_buffer(), ast_channel_blob::blob, EVENT_FLAG_AGENT, NULL, ast_channel_blob::snapshot, and stasis_message_data().

◆ agent_logoff_to_ami()

static struct ast_manager_event_blob * agent_logoff_to_ami ( struct stasis_message msg)
static

Definition at line 1268 of file stasis_channels.c.

1269{
1270 struct ast_str *channel_string;
1271 struct ast_channel_blob *obj = stasis_message_data(msg);
1272 const char *agent = ast_json_string_get(ast_json_object_get(obj->blob, "agent"));
1273 long logintime = ast_json_integer_get(ast_json_object_get(obj->blob, "logintime"));
1274 struct ast_manager_event_blob *ev;
1275
1276 channel_string = ast_manager_build_channel_state_string(obj->snapshot);
1277 if (!channel_string) {
1278 return NULL;
1279 }
1280
1282 "%s"
1283 "Agent: %s\r\n"
1284 "Logintime: %ld\r\n",
1285 ast_str_buffer(channel_string), agent, logintime);
1286 ast_free(channel_string);
1287 return ev;
1288}
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
Definition: json.c:332

References ast_free, ast_json_integer_get(), ast_json_object_get(), ast_json_string_get(), ast_manager_build_channel_state_string(), ast_manager_event_blob_create(), ast_str_buffer(), ast_channel_blob::blob, EVENT_FLAG_AGENT, NULL, ast_channel_blob::snapshot, and stasis_message_data().

◆ ast_channel_publish_dial_internal()

static void ast_channel_publish_dial_internal ( struct ast_channel caller,
struct ast_channel peer,
struct ast_channel forwarded,
const char *  dialstring,
const char *  dialstatus,
const char *  forward 
)
static

Definition at line 607 of file stasis_channels.c.

610{
611 struct ast_multi_channel_blob *payload;
612 struct stasis_message *msg;
613 struct ast_json *blob;
614 struct ast_channel_snapshot *peer_snapshot;
615
616 if (!ast_channel_dial_type()) {
617 return;
618 }
619
620 ast_assert(peer != NULL);
621
622 blob = ast_json_pack("{s: s, s: s, s: s}",
623 "dialstatus", S_OR(dialstatus, ""),
624 "forward", S_OR(forward, ""),
625 "dialstring", S_OR(dialstring, ""));
626 if (!blob) {
627 return;
628 }
629 payload = ast_multi_channel_blob_create(blob);
630 ast_json_unref(blob);
631 if (!payload) {
632 return;
633 }
634
635 if (caller) {
636 struct ast_channel_snapshot *caller_snapshot;
637
639 if (ast_strlen_zero(dialstatus)) {
641 } else {
642 caller_snapshot = ast_channel_snapshot_create(caller);
643 }
645 if (!caller_snapshot) {
646 ao2_ref(payload, -1);
647 return;
648 }
649 ast_multi_channel_blob_add_channel(payload, "caller", caller_snapshot);
650 ao2_ref(caller_snapshot, -1);
651 }
652
654 if (ast_strlen_zero(dialstatus)) {
656 } else {
657 peer_snapshot = ast_channel_snapshot_create(peer);
658 }
660 if (!peer_snapshot) {
661 ao2_ref(payload, -1);
662 return;
663 }
664 ast_multi_channel_blob_add_channel(payload, "peer", peer_snapshot);
665 ao2_ref(peer_snapshot, -1);
666
667 if (forwarded) {
668 struct ast_channel_snapshot *forwarded_snapshot;
669
670 ast_channel_lock(forwarded);
671 forwarded_snapshot = ast_channel_snapshot_create(forwarded);
672 ast_channel_unlock(forwarded);
673 if (!forwarded_snapshot) {
674 ao2_ref(payload, -1);
675 return;
676 }
677 ast_multi_channel_blob_add_channel(payload, "forwarded", forwarded_snapshot);
678 ao2_ref(forwarded_snapshot, -1);
679 }
680
682 ao2_ref(payload, -1);
683 if (msg) {
685 ao2_ref(msg, -1);
686 }
687}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ast_channel_lock(chan)
Definition: channel.h:2922
const char * ast_channel_uniqueid(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2923
struct ast_multi_channel_blob * ast_multi_channel_blob_create(struct ast_json *blob)
Create a ast_multi_channel_blob suitable for a stasis_message.
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,...
struct ast_channel_snapshot * ast_channel_snapshot_create(struct ast_channel *chan)
Generate a snapshot of the channel state. This is an ao2 object, so ao2_cleanup() to deallocate.
struct stasis_message_type * ast_channel_dial_type(void)
Message type for when a channel dials another channel.
void ast_multi_channel_blob_add_channel(struct ast_multi_channel_blob *obj, const char *role, struct ast_channel_snapshot *snapshot)
Add a ast_channel_snapshot to a ast_multi_channel_blob object.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
static void publish_message_for_channel_topics(struct stasis_message *message, struct ast_channel *chan)
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Structure representing a snapshot of channel state.
struct ast_channel_snapshot_peer * peer
struct ast_channel_snapshot_caller * caller
Abstract JSON element (object, array, string, int, ...).
A multi channel blob data structure for multi_channel_blob stasis messages.
#define ast_assert(a)
Definition: utils.h:739

References ao2_ref, ast_assert, ast_channel_dial_type(), ast_channel_lock, ast_channel_snapshot_create(), ast_channel_snapshot_get_latest(), ast_channel_uniqueid(), ast_channel_unlock, ast_json_pack(), ast_json_unref(), ast_multi_channel_blob_add_channel(), ast_multi_channel_blob_create(), ast_strlen_zero(), ast_channel_snapshot::caller, NULL, ast_channel_snapshot::peer, publish_message_for_channel_topics(), S_OR, and stasis_message_create().

Referenced by ast_channel_publish_dial_forward(), dial_masquerade_breakdown(), and dial_masquerade_fixup().

◆ ast_channel_snapshot_caller_id_equal()

int ast_channel_snapshot_caller_id_equal ( const struct ast_channel_snapshot old_snapshot,
const struct ast_channel_snapshot new_snapshot 
)

Compares the callerid info of two snapshots.

Since
12
Parameters
old_snapshotOld snapshot
new_snapshotNew snapshot
Return values
True(non-zero) if callerid are identical.
False(zero) if callerid changed.

Definition at line 1358 of file stasis_channels.c.

1361{
1362 ast_assert(old_snapshot != NULL);
1363 ast_assert(new_snapshot != NULL);
1364 return strcmp(old_snapshot->caller->number, new_snapshot->caller->number) == 0 &&
1365 strcmp(old_snapshot->caller->name, new_snapshot->caller->name) == 0;
1366}
const ast_string_field number
const ast_string_field name

References ast_assert, ast_channel_snapshot::caller, ast_channel_snapshot_caller::name, NULL, and ast_channel_snapshot_caller::number.

Referenced by channel_callerid(), and channel_new_callerid().

◆ ast_channel_snapshot_cep_equal()

int ast_channel_snapshot_cep_equal ( const struct ast_channel_snapshot old_snapshot,
const struct ast_channel_snapshot new_snapshot 
)

Compares the context, exten and priority of two snapshots.

Since
12
Parameters
old_snapshotOld snapshot
new_snapshotNew snapshot
Return values
True(non-zero) if context, exten or priority are identical.
False(zero) if context, exten and priority changed.

Definition at line 1337 of file stasis_channels.c.

1340{
1341 ast_assert(old_snapshot != NULL);
1342 ast_assert(new_snapshot != NULL);
1343
1344 /* We actually get some snapshots with CEP set, but before the
1345 * application is set. Since empty application is invalid, we treat
1346 * setting the application from nothing as a CEP change.
1347 */
1348 if (ast_strlen_zero(old_snapshot->dialplan->appl) &&
1349 !ast_strlen_zero(new_snapshot->dialplan->appl)) {
1350 return 0;
1351 }
1352
1353 return old_snapshot->dialplan->priority == new_snapshot->dialplan->priority &&
1354 strcmp(old_snapshot->dialplan->context, new_snapshot->dialplan->context) == 0 &&
1355 strcmp(old_snapshot->dialplan->exten, new_snapshot->dialplan->exten) == 0;
1356}
const ast_string_field context
const ast_string_field exten
const ast_string_field appl
struct ast_channel_snapshot_dialplan * dialplan

References ast_channel_snapshot_dialplan::appl, ast_assert, ast_strlen_zero(), ast_channel_snapshot_dialplan::context, ast_channel_snapshot::dialplan, ast_channel_snapshot_dialplan::exten, NULL, and ast_channel_snapshot_dialplan::priority.

Referenced by channel_dialplan(), and channel_newexten().

◆ ast_channel_snapshot_connected_line_equal()

int ast_channel_snapshot_connected_line_equal ( const struct ast_channel_snapshot old_snapshot,
const struct ast_channel_snapshot new_snapshot 
)

Compares the connected line info of two snapshots.

Since
13.1.0
Parameters
old_snapshotOld snapshot
new_snapshotNew snapshot
Return values
True(non-zero) if callerid are identical.
False(zero) if callerid changed.

Definition at line 1368 of file stasis_channels.c.

1371{
1372 ast_assert(old_snapshot != NULL);
1373 ast_assert(new_snapshot != NULL);
1374 return strcmp(old_snapshot->connected->number, new_snapshot->connected->number) == 0 &&
1375 strcmp(old_snapshot->connected->name, new_snapshot->connected->name) == 0;
1376}
struct ast_channel_snapshot_connected * connected

References ast_assert, ast_channel_snapshot::connected, ast_channel_snapshot_connected::name, NULL, and ast_channel_snapshot_connected::number.

Referenced by channel_connected_line(), and channel_new_connected_line().

◆ ast_channel_snapshot_to_json()

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.

Parameters
snapshotThe snapshot to convert to JSON
sanitizeThe message sanitizer to use on the snapshot
Returns
JSON object representing channel snapshot.
Return values
NULLon error

Definition at line 1290 of file stasis_channels.c.

1293{
1294 struct ast_json *json_chan;
1295
1296 if (snapshot == NULL
1297 || (sanitize
1298 && sanitize->channel_snapshot
1299 && sanitize->channel_snapshot(snapshot))) {
1300 return NULL;
1301 }
1302
1303 json_chan = ast_json_pack(
1304 /* Broken up into groups for readability */
1305 "{ s: s, s: s, s: s, s: s,"
1306 " s: o, s: o, s: s,"
1307 " s: o, s: o, s: s }",
1308 /* First line */
1309 "id", snapshot->base->uniqueid,
1310 "name", snapshot->base->name,
1311 "state", ast_state2str(snapshot->state),
1312 "protocol_id", snapshot->base->protocol_id,
1313 /* Second line */
1314 "caller", ast_json_name_number(
1315 snapshot->caller->name, snapshot->caller->number),
1316 "connected", ast_json_name_number(
1317 snapshot->connected->name, snapshot->connected->number),
1318 "accountcode", snapshot->base->accountcode,
1319 /* Third line */
1320 "dialplan", ast_json_dialplan_cep_app(
1321 snapshot->dialplan->context, snapshot->dialplan->exten, snapshot->dialplan->priority,
1322 snapshot->dialplan->appl, snapshot->dialplan->data),
1323 "creationtime", ast_json_timeval(snapshot->base->creationtime, NULL),
1324 "language", snapshot->base->language);
1325
1326 if (!ast_strlen_zero(snapshot->caller->rdnis)) {
1327 ast_json_object_set(json_chan, "caller_rdnis", ast_json_string_create(snapshot->caller->rdnis));
1328 }
1329
1330 if (snapshot->ari_vars && !AST_LIST_EMPTY(snapshot->ari_vars)) {
1331 ast_json_object_set(json_chan, "channelvars", ast_json_channel_vars(snapshot->ari_vars));
1332 }
1333
1334 return json_chan;
1335}
const char * ast_state2str(enum ast_channel_state state)
Gives the string form of a given channel state.
Definition: channel.c:636
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:278
struct ast_json * ast_json_name_number(const char *name, const char *number)
Common JSON rendering functions for common 'objects'.
Definition: json.c:646
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
Definition: json.c:670
struct ast_json * ast_json_dialplan_cep_app(const char *context, const char *exten, int priority, const char *app_name, const char *app_data)
Construct a context/exten/priority/application/application_data as JSON.
Definition: json.c:653
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition: json.c:414
struct ast_json * ast_json_channel_vars(struct varshead *channelvars)
Construct a JSON object from a ast_var_t list.
Definition: json.c:864
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450
const ast_string_field language
const ast_string_field accountcode
const ast_string_field uniqueid
const ast_string_field name
const ast_string_field rdnis
const ast_string_field data
struct varshead * ari_vars
struct ast_channel_snapshot_base * base
enum ast_channel_state state
int(* channel_snapshot)(const struct ast_channel_snapshot *snapshot)
Callback which determines whether a channel should be sanitized from a message based on the channel's...
Definition: stasis.h:221

References ast_channel_snapshot_base::accountcode, ast_channel_snapshot_dialplan::appl, ast_channel_snapshot::ari_vars, ast_json_channel_vars(), ast_json_dialplan_cep_app(), ast_json_name_number(), ast_json_object_set(), ast_json_pack(), ast_json_string_create(), ast_json_timeval(), AST_LIST_EMPTY, ast_state2str(), ast_strlen_zero(), ast_channel_snapshot::base, ast_channel_snapshot::caller, stasis_message_sanitizer::channel_snapshot, ast_channel_snapshot::connected, ast_channel_snapshot_dialplan::context, ast_channel_snapshot_base::creationtime, ast_channel_snapshot_dialplan::data, ast_channel_snapshot::dialplan, ast_channel_snapshot_dialplan::exten, ast_channel_snapshot_base::language, ast_channel_snapshot_caller::name, ast_channel_snapshot_connected::name, ast_channel_snapshot_base::name, NULL, ast_channel_snapshot_caller::number, ast_channel_snapshot_connected::number, ast_channel_snapshot_dialplan::priority, ast_channel_snapshot_caller::rdnis, ast_channel_snapshot::state, and ast_channel_snapshot_base::uniqueid.

Referenced by ari_channels_handle_originate_with_id(), ari_channels_handle_snoop_channel(), ast_ari_channels_create(), ast_ari_channels_get(), ast_ari_channels_list(), AST_TEST_DEFINE(), attended_transfer_to_json(), blind_transfer_to_json(), channel_blob_to_json(), channel_callerid(), channel_connected_line(), channel_destroyed_event(), channel_dialplan(), channel_to_json(), dial_to_json(), dtmf_end_to_json(), hold_to_json(), multi_user_event_to_json(), rtcp_report_to_json(), simple_bridge_channel_event(), simple_channel_event(), stasis_app_exec(), stasis_end_to_json(), stasis_start_to_json(), and unhold_to_json().

◆ ast_stasis_channels_init()

int ast_stasis_channels_init ( void  )

Initialize the stasis channel topic and message types.

Return values
0on success
Non-zeroon error

Definition at line 1704 of file stasis_channels.c.

1705{
1706 int res = 0;
1707
1709
1710 channel_topic_all = stasis_topic_create("channel:all");
1711 if (!channel_topic_all) {
1712 return -1;
1713 }
1714
1718 if (!channel_cache) {
1719 return -1;
1720 }
1721
1725 if (!channel_cache_by_name) {
1726 return -1;
1727 }
1728
1753
1754 return res;
1755}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
@ AO2_ALLOC_OPT_LOCK_RWLOCK
Definition: astobj2.h:365
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition: astobj2.h:1303
#define AST_NUM_CHANNEL_BUCKETS
Definition: channel.h:155
struct stasis_message_type * ast_channel_mixmonitor_mute_type(void)
Message type for muting or unmuting mixmonitor on a channel.
struct stasis_message_type * ast_channel_masquerade_type(void)
Message type for when a channel is being masqueraded.
struct stasis_message_type * ast_channel_hold_type(void)
Message type for when a channel is placed on hold.
struct stasis_message_type * ast_channel_talking_start(void)
Message type for a channel starting talking.
struct stasis_message_type * ast_channel_chanspy_start_type(void)
Message type for when a channel starts spying on another channel.
struct stasis_message_type * ast_channel_chanspy_stop_type(void)
Message type for when a channel stops spying on another channel.
struct stasis_message_type * ast_channel_talking_stop(void)
Message type for a channel stopping talking.
struct stasis_message_type * ast_channel_dtmf_begin_type(void)
Message type for when DTMF begins on a channel.
struct stasis_message_type * ast_channel_mixmonitor_stop_type(void)
Message type for stopping mixmonitor on a channel.
struct stasis_message_type * ast_channel_varset_type(void)
Message type for when a variable is set on a channel.
struct stasis_message_type * ast_channel_hangup_handler_type(void)
Message type for hangup handler related actions.
struct stasis_message_type * ast_channel_agent_logoff_type(void)
Message type for agent logoff on a channel.
struct stasis_message_type * ast_channel_moh_stop_type(void)
Message type for stopping music on hold on a channel.
struct stasis_message_type * ast_channel_unhold_type(void)
Message type for when a channel is removed from hold.
struct stasis_message_type * ast_channel_hangup_request_type(void)
Message type for when a hangup is requested on a channel.
struct stasis_message_type * ast_channel_agent_login_type(void)
Message type for agent login on a channel.
struct stasis_message_type * ast_channel_flash_type(void)
Message type for when a hook flash occurs on a channel.
struct stasis_message_type * ast_channel_snapshot_type(void)
Message type for ast_channel_snapshot_update.
struct stasis_message_type * ast_channel_fax_type(void)
Message type for a fax operation.
struct stasis_message_type * ast_channel_dtmf_end_type(void)
Message type for when DTMF ends on a channel.
struct stasis_message_type * ast_channel_wink_type(void)
Message type for when a wink occurs on a channel.
struct stasis_message_type * ast_channel_moh_start_type(void)
Message type for starting music on hold on a channel.
struct stasis_message_type * ast_channel_mixmonitor_start_type(void)
Message type for starting mixmonitor on a channel.
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Definition: stasis.c:617
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition: stasis.h:1493
static int channel_snapshot_cmp_cb(void *obj, void *arg, int flags)
static int channel_snapshot_uniqueid_cmp_cb(void *obj, void *arg, int flags)
static struct ao2_container * channel_cache_by_name
static struct stasis_topic * channel_topic_all
static int channel_snapshot_uniqueid_hash_cb(const void *obj, const int flags)
static struct ao2_container * channel_cache
static int channel_snapshot_hash_cb(const void *obj, const int flags)
static void stasis_channels_cleanup(void)

References AO2_ALLOC_OPT_LOCK_RWLOCK, ao2_container_alloc_hash, ast_channel_agent_login_type(), ast_channel_agent_logoff_type(), ast_channel_chanspy_start_type(), ast_channel_chanspy_stop_type(), ast_channel_dial_type(), ast_channel_dtmf_begin_type(), ast_channel_dtmf_end_type(), ast_channel_fax_type(), ast_channel_flash_type(), ast_channel_hangup_handler_type(), ast_channel_hangup_request_type(), ast_channel_hold_type(), ast_channel_masquerade_type(), ast_channel_mixmonitor_mute_type(), ast_channel_mixmonitor_start_type(), ast_channel_mixmonitor_stop_type(), ast_channel_moh_start_type(), ast_channel_moh_stop_type(), ast_channel_snapshot_type(), ast_channel_talking_start(), ast_channel_talking_stop(), ast_channel_unhold_type(), ast_channel_varset_type(), ast_channel_wink_type(), AST_NUM_CHANNEL_BUCKETS, ast_register_cleanup(), channel_cache, channel_cache_by_name, channel_snapshot_cmp_cb(), channel_snapshot_hash_cb(), channel_snapshot_uniqueid_cmp_cb(), channel_snapshot_uniqueid_hash_cb(), channel_topic_all, NULL, stasis_channels_cleanup(), STASIS_MESSAGE_TYPE_INIT, and stasis_topic_create().

Referenced by ast_channels_init().

◆ channel_blob_dtor()

static void channel_blob_dtor ( void *  obj)
static

Definition at line 600 of file stasis_channels.c.

601{
602 struct ast_channel_blob *event = obj;
603 ao2_cleanup(event->snapshot);
604 ast_json_unref(event->blob);
605}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
Definition: astman.c:222

References ao2_cleanup, and ast_json_unref().

Referenced by create_channel_blob_message().

◆ channel_blob_to_json()

static struct ast_json * channel_blob_to_json ( struct stasis_message message,
const char *  type,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 1378 of file stasis_channels.c.

1382{
1383 struct ast_json *to_json;
1384 struct ast_channel_blob *channel_blob = stasis_message_data(message);
1385 struct ast_json *blob = channel_blob->blob;
1386 struct ast_channel_snapshot *snapshot = channel_blob->snapshot;
1387 const struct timeval *tv = stasis_message_timestamp(message);
1388 int res = 0;
1389
1390 if (blob == NULL || ast_json_is_null(blob)) {
1391 to_json = ast_json_object_create();
1392 } else {
1393 /* blobs are immutable, so shallow copies are fine */
1394 to_json = ast_json_copy(blob);
1395 }
1396 if (!to_json) {
1397 return NULL;
1398 }
1399
1400 res |= ast_json_object_set(to_json, "type", ast_json_string_create(type));
1401 res |= ast_json_object_set(to_json, "timestamp",
1402 ast_json_timeval(*tv, NULL));
1403
1404 /* For global channel messages, the snapshot is optional */
1405 if (snapshot) {
1406 struct ast_json *json_channel;
1407
1408 json_channel = ast_channel_snapshot_to_json(snapshot, sanitize);
1409 if (!json_channel) {
1410 ast_json_unref(to_json);
1411 return NULL;
1412 }
1413
1414 res |= ast_json_object_set(to_json, "channel", json_channel);
1415 }
1416
1417 if (res != 0) {
1418 ast_json_unref(to_json);
1419 return NULL;
1420 }
1421
1422 return to_json;
1423}
static const char type[]
Definition: chan_ooh323.c:109
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
Definition: json.c:399
struct ast_json * ast_json_copy(const struct ast_json *value)
Copy a JSON value, but not its children.
Definition: json.c:637
int ast_json_is_null(const struct ast_json *value)
Check if value is JSON null.
Definition: json.c:273
const struct timeval * stasis_message_timestamp(const struct stasis_message *msg)
Get the time when a message was created.
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.

References ast_channel_snapshot_to_json(), ast_json_copy(), ast_json_is_null(), ast_json_object_create(), ast_json_object_set(), ast_json_string_create(), ast_json_timeval(), ast_json_unref(), ast_channel_blob::blob, NULL, ast_channel_blob::snapshot, stasis_message_data(), stasis_message_timestamp(), and type.

Referenced by hangup_request_to_json(), talking_start_to_json(), talking_stop_to_json(), and varset_to_json().

◆ channel_role_cmp_cb()

static int channel_role_cmp_cb ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 825 of file stasis_channels.c.

826{
827 const struct channel_role_snapshot *object_left = obj;
828 const struct channel_role_snapshot *object_right = arg;
829 const char *right_key = arg;
830 int cmp;
831
832 switch (flags & OBJ_SEARCH_MASK) {
834 right_key = object_right->role;
835 case OBJ_SEARCH_KEY:
836 cmp = strcasecmp(object_left->role, right_key);
837 break;
839 cmp = strncasecmp(object_left->role, right_key, strlen(right_key));
840 break;
841 default:
842 cmp = 0;
843 break;
844 }
845 if (cmp) {
846 return 0;
847 }
848 return CMP_MATCH;
849}
@ CMP_MATCH
Definition: astobj2.h:1027
@ OBJ_SEARCH_PARTIAL_KEY
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1116
@ OBJ_SEARCH_OBJECT
The arg parameter is an object of the same type.
Definition: astobj2.h:1087
@ OBJ_SEARCH_MASK
Search option field mask.
Definition: astobj2.h:1072
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1101
A channel snapshot wrapper object used in ast_multi_channel_blob objects.

References CMP_MATCH, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, OBJ_SEARCH_PARTIAL_KEY, and channel_role_snapshot::role.

Referenced by ast_multi_channel_blob_create(), and ast_multi_channel_blob_get_channels().

◆ channel_role_hash_cb()

static int channel_role_hash_cb ( const void *  obj,
const int  flags 
)
static

Definition at line 855 of file stasis_channels.c.

856{
857 const struct channel_role_snapshot *object = obj;
858 const char *key;
859
860 switch (flags & OBJ_SEARCH_MASK) {
861 case OBJ_SEARCH_KEY:
862 key = obj;
863 break;
865 key = object->role;
866 break;
867 default:
868 ast_assert(0);
869 return 0;
870 }
871 return ast_str_case_hash(key);
872}
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
Definition: strings.h:1303

References ast_assert, ast_str_case_hash(), OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, and OBJ_SEARCH_OBJECT.

Referenced by ast_multi_channel_blob_create().

◆ channel_role_snapshot_dtor()

static void channel_role_snapshot_dtor ( void *  obj)
static

Definition at line 954 of file stasis_channels.c.

955{
956 struct channel_role_snapshot *role_snapshot = obj;
957
958 ao2_cleanup(role_snapshot->snapshot);
959}
struct ast_channel_snapshot * snapshot

References ao2_cleanup, and channel_role_snapshot::snapshot.

Referenced by ast_multi_channel_blob_add_channel().

◆ channel_snapshot_base_create()

static struct ast_channel_snapshot_base * channel_snapshot_base_create ( struct ast_channel chan)
static

Definition at line 267 of file stasis_channels.c.

268{
269 struct ast_channel_snapshot_base *snapshot;
270
271 snapshot = ao2_alloc_options(sizeof(*snapshot), channel_snapshot_base_dtor,
273 if (!snapshot) {
274 return NULL;
275 }
276
277 if (ast_string_field_init(snapshot, 256) || ast_string_field_init_extended(snapshot, protocol_id)) {
278 ao2_ref(snapshot, -1);
279 return NULL;
280 }
281
288
289 snapshot->creationtime = ast_channel_creationtime(chan);
291
292 if (ast_channel_tech(chan)->get_pvt_uniqueid) {
293 ast_string_field_set(snapshot, protocol_id, ast_channel_tech(chan)->get_pvt_uniqueid(chan));
294 }
295
296 return snapshot;
297}
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:404
static char language[MAX_LANGUAGE]
Definition: chan_iax2.c:327
static char accountcode[AST_MAX_ACCOUNT_CODE]
Definition: chan_iax2.c:476
const char * ast_channel_name(const struct ast_channel *chan)
const char * ast_channel_accountcode(const struct ast_channel *chan)
const char * ast_channel_userfield(const struct ast_channel *chan)
struct timeval ast_channel_creationtime(struct ast_channel *chan)
const char * ast_channel_language(const struct ast_channel *chan)
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
static const char name[]
Definition: format_mp3.c:68
static void channel_snapshot_base_dtor(void *obj)
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:521
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
#define ast_string_field_init_extended(x, field)
Initialize an extended string field.
Definition: stringfields.h:401
Structure containing base information for a channel snapshot.
const ast_string_field userfield

References accountcode, AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_ref, ast_channel_accountcode(), ast_channel_creationtime(), ast_channel_language(), ast_channel_name(), ast_channel_tech(), ast_channel_uniqueid(), ast_channel_userfield(), ast_string_field_init, ast_string_field_init_extended, ast_string_field_set, channel_snapshot_base_dtor(), ast_channel_snapshot_base::creationtime, language, name, NULL, ast_channel_tech::properties, ast_channel_snapshot_base::tech_properties, type, ast_channel_snapshot_base::uniqueid, and ast_channel_snapshot_base::userfield.

Referenced by ast_channel_snapshot_create().

◆ channel_snapshot_base_dtor()

static void channel_snapshot_base_dtor ( void *  obj)
static

Definition at line 260 of file stasis_channels.c.

261{
262 struct ast_channel_snapshot_base *snapshot = obj;
263
265}
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:374

References ast_string_field_free_memory.

Referenced by channel_snapshot_base_create().

◆ channel_snapshot_bridge_create()

static struct ast_channel_snapshot_bridge * channel_snapshot_bridge_create ( struct ast_channel chan)
static

Definition at line 383 of file stasis_channels.c.

384{
385 const char *uniqueid = "";
386 struct ast_bridge *bridge;
387 struct ast_channel_snapshot_bridge *snapshot;
388
389 bridge = ast_channel_get_bridge(chan);
390 if (bridge && !ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) {
391 uniqueid = bridge->uniqueid;
392 }
393 ao2_cleanup(bridge);
394
395 snapshot = ao2_alloc_options(sizeof(*snapshot) + strlen(uniqueid) + 1, NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
396 if (!snapshot) {
397 return NULL;
398 }
399
400 strcpy(snapshot->id, uniqueid); /* Safe */
401
402 return snapshot;
403}
@ AST_BRIDGE_FLAG_INVISIBLE
struct ast_bridge * ast_channel_get_bridge(const struct ast_channel *chan)
Get the bridge associated with a channel.
Definition: channel.c:10533
Structure that contains information about a bridge.
Definition: bridge.h:349
const ast_string_field uniqueid
Definition: bridge.h:401
struct ast_flags feature_flags
Definition: bridge.h:369
Structure containing bridge information for a channel snapshot.
#define ast_test_flag(p, flag)
Definition: utils.h:63

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_cleanup, AST_BRIDGE_FLAG_INVISIBLE, ast_channel_get_bridge(), ast_test_flag, ast_bridge::feature_flags, ast_channel_snapshot_bridge::id, NULL, and ast_bridge::uniqueid.

Referenced by ast_channel_snapshot_create().

◆ channel_snapshot_caller_create()

static struct ast_channel_snapshot_caller * channel_snapshot_caller_create ( struct ast_channel chan)
static

Definition at line 326 of file stasis_channels.c.

327{
328 struct ast_channel_snapshot_caller *snapshot;
329
330 snapshot = ao2_alloc_options(sizeof(*snapshot), channel_snapshot_caller_dtor,
332 if (!snapshot) {
333 return NULL;
334 }
335
336 if (ast_string_field_init(snapshot, 256)) {
337 ao2_ref(snapshot, -1);
338 return NULL;
339 }
340
341 ast_string_field_set(snapshot, name,
342 S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, ""));
344 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, ""));
346 S_COR(ast_channel_caller(chan)->id.subaddress.valid, ast_channel_caller(chan)->id.subaddress.str, ""));
347 ast_string_field_set(snapshot, ani,
348 S_COR(ast_channel_caller(chan)->ani.number.valid, ast_channel_caller(chan)->ani.number.str, ""));
349
350 ast_string_field_set(snapshot, rdnis,
351 S_COR(ast_channel_redirecting(chan)->from.number.valid, ast_channel_redirecting(chan)->from.number.str, ""));
352
353 ast_string_field_set(snapshot, dnid,
354 S_OR(ast_channel_dialed(chan)->number.str, ""));
356 S_COR(ast_channel_dialed(chan)->subaddress.valid, ast_channel_dialed(chan)->subaddress.str, ""));
357
358 snapshot->pres = ast_party_id_presentation(&ast_channel_caller(chan)->id);
359
360 return snapshot;
361}
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
Definition: channel.c:1821
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
static void channel_snapshot_caller_dtor(void *obj)
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:87
Structure containing caller information for a channel snapshot.
const ast_string_field dialed_subaddr
const ast_string_field ani
const ast_string_field subaddr
const ast_string_field dnid
char * str
Subscriber phone number (Malloced)
Definition: channel.h:386
Number structure.
Definition: app_followme.c:154

References ast_channel_snapshot_caller::ani, AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_ref, ast_channel_caller(), ast_channel_dialed(), ast_channel_redirecting(), ast_party_id_presentation(), ast_string_field_init, ast_string_field_set, channel_snapshot_caller_dtor(), ast_channel_snapshot_caller::dialed_subaddr, ast_channel_snapshot_caller::dnid, name, NULL, ast_channel_snapshot_caller::pres, ast_channel_snapshot_caller::rdnis, S_COR, S_OR, ast_party_dialed::str, and ast_channel_snapshot_caller::subaddr.

Referenced by ast_channel_snapshot_create().

◆ channel_snapshot_caller_dtor()

static void channel_snapshot_caller_dtor ( void *  obj)
static

Definition at line 319 of file stasis_channels.c.

320{
321 struct ast_channel_snapshot_caller *snapshot = obj;
322
324}

References ast_string_field_free_memory.

Referenced by channel_snapshot_caller_create().

◆ channel_snapshot_cmp_cb()

static int channel_snapshot_cmp_cb ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 166 of file stasis_channels.c.

167{
168 const struct ast_channel_snapshot *object_left = obj;
169 const struct ast_channel_snapshot *object_right = arg;
170 const char *right_key = arg;
171 int cmp;
172
173 switch (flags & OBJ_SEARCH_MASK) {
175 right_key = object_right->base->name;
176 case OBJ_SEARCH_KEY:
177 cmp = strcasecmp(object_left->base->name, right_key);
178 break;
180 cmp = strncasecmp(object_left->base->name, right_key, strlen(right_key));
181 break;
182 default:
183 cmp = 0;
184 break;
185 }
186 if (cmp) {
187 return 0;
188 }
189 return CMP_MATCH;
190}
struct ast_flags flags

References ast_channel_snapshot::base, CMP_MATCH, ast_channel_snapshot::flags, ast_channel_snapshot_base::name, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.

Referenced by ast_multi_channel_blob_get_channels(), and ast_stasis_channels_init().

◆ channel_snapshot_connected_create()

static struct ast_channel_snapshot_connected * channel_snapshot_connected_create ( struct ast_channel chan)
static

Definition at line 363 of file stasis_channels.c.

364{
365 const char *name = S_COR(ast_channel_connected(chan)->id.name.valid, ast_channel_connected(chan)->id.name.str, "");
366 const char *number = S_COR(ast_channel_connected(chan)->id.number.valid, ast_channel_connected(chan)->id.number.str, "");
367 size_t name_len = strlen(name) + 1;
368 size_t number_len = strlen(number) + 1;
369 struct ast_channel_snapshot_connected *snapshot;
370
371 snapshot = ao2_alloc_options(sizeof(*snapshot) + name_len + number_len, NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
372 if (!snapshot) {
373 return NULL;
374 }
375
376 strcpy(snapshot->name, name); /* Safe */
377 snapshot->number = snapshot->name + name_len;
378 ast_copy_string(snapshot->number, number, number_len); /* Safe */
379
380 return snapshot;
381}
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
Structure containing connected information for a channel snapshot.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ast_channel_connected(), ast_copy_string(), ast_channel_snapshot_connected::name, name, NULL, ast_channel_snapshot_connected::number, and S_COR.

Referenced by ast_channel_snapshot_create().

◆ channel_snapshot_dialplan_create()

static struct ast_channel_snapshot_dialplan * channel_snapshot_dialplan_create ( struct ast_channel chan)
static

Definition at line 412 of file stasis_channels.c.

413{
414 struct ast_channel_snapshot_dialplan *snapshot;
415
416 snapshot = ao2_alloc_options(sizeof(*snapshot), channel_snapshot_dialplan_dtor,
418 if (!snapshot) {
419 return NULL;
420 }
421
422 if (ast_string_field_init(snapshot, 256)) {
423 ao2_ref(snapshot, -1);
424 return NULL;
425 }
426
427 if (ast_channel_appl(chan)) {
429 }
430 if (ast_channel_data(chan)) {
432 }
435 snapshot->priority = ast_channel_priority(chan);
436
437 return snapshot;
438}
const char * ast_channel_data(const struct ast_channel *chan)
int ast_channel_priority(const struct ast_channel *chan)
const char * ast_channel_context(const struct ast_channel *chan)
const char * ast_channel_appl(const struct ast_channel *chan)
const char * ast_channel_exten(const struct ast_channel *chan)
static void channel_snapshot_dialplan_dtor(void *obj)
Structure containing dialplan information for a channel snapshot.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_ref, ast_channel_snapshot_dialplan::appl, ast_channel_appl(), ast_channel_context(), ast_channel_data(), ast_channel_exten(), ast_channel_priority(), ast_string_field_init, ast_string_field_set, channel_snapshot_dialplan_dtor(), voicemailpwcheck::context, ast_channel_snapshot_dialplan::data, ast_channel_snapshot_dialplan::exten, NULL, and ast_channel_snapshot_dialplan::priority.

Referenced by ast_channel_snapshot_create().

◆ channel_snapshot_dialplan_dtor()

static void channel_snapshot_dialplan_dtor ( void *  obj)
static

Definition at line 405 of file stasis_channels.c.

406{
407 struct ast_channel_snapshot_dialplan *snapshot = obj;
408
410}

References ast_string_field_free_memory.

Referenced by channel_snapshot_dialplan_create().

◆ channel_snapshot_dtor()

static void channel_snapshot_dtor ( void *  obj)
static

Definition at line 245 of file stasis_channels.c.

246{
247 struct ast_channel_snapshot *snapshot = obj;
248
249 ao2_cleanup(snapshot->base);
250 ao2_cleanup(snapshot->peer);
251 ao2_cleanup(snapshot->caller);
252 ao2_cleanup(snapshot->connected);
253 ao2_cleanup(snapshot->bridge);
254 ao2_cleanup(snapshot->dialplan);
255 ao2_cleanup(snapshot->hangup);
256 ao2_cleanup(snapshot->manager_vars);
257 ao2_cleanup(snapshot->ari_vars);
258}
struct varshead * manager_vars
struct ast_channel_snapshot_bridge * bridge
struct ast_channel_snapshot_hangup * hangup

References ao2_cleanup, ast_channel_snapshot::ari_vars, ast_channel_snapshot::base, ast_channel_snapshot::bridge, ast_channel_snapshot::caller, ast_channel_snapshot::connected, ast_channel_snapshot::dialplan, ast_channel_snapshot::hangup, ast_channel_snapshot::manager_vars, and ast_channel_snapshot::peer.

Referenced by ast_channel_snapshot_create().

◆ channel_snapshot_hangup_create()

static struct ast_channel_snapshot_hangup * channel_snapshot_hangup_create ( struct ast_channel chan)
static

Definition at line 440 of file stasis_channels.c.

441{
442 const char *hangupsource = S_OR(ast_channel_hangupsource(chan), "");
443 struct ast_channel_snapshot_hangup *snapshot;
444
445 snapshot = ao2_alloc_options(sizeof(*snapshot) + strlen(hangupsource) + 1, NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
446 if (!snapshot) {
447 return NULL;
448 }
449
450 snapshot->cause = ast_channel_hangupcause(chan);
451 strcpy(snapshot->source, hangupsource); /* Safe */
452
453 return snapshot;
454}
const char * ast_channel_hangupsource(const struct ast_channel *chan)
int ast_channel_hangupcause(const struct ast_channel *chan)
Structure containing hangup information for a channel snapshot.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ast_channel_hangupcause(), ast_channel_hangupsource(), ast_channel_snapshot_hangup::cause, NULL, S_OR, and ast_channel_snapshot_hangup::source.

Referenced by ast_channel_snapshot_create().

◆ channel_snapshot_hash_cb()

static int channel_snapshot_hash_cb ( const void *  obj,
const int  flags 
)
static

Definition at line 143 of file stasis_channels.c.

144{
145 const struct ast_channel_snapshot *object = obj;
146 const char *key;
147
148 switch (flags & OBJ_SEARCH_MASK) {
149 case OBJ_SEARCH_KEY:
150 key = obj;
151 break;
153 key = object->base->name;
154 break;
155 default:
156 ast_assert(0);
157 return 0;
158 }
159 return ast_str_case_hash(key);
160}

References ast_assert, ast_str_case_hash(), ast_channel_snapshot::flags, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, and OBJ_SEARCH_OBJECT.

Referenced by ast_multi_channel_blob_get_channels(), and ast_stasis_channels_init().

◆ channel_snapshot_peer_create()

static struct ast_channel_snapshot_peer * channel_snapshot_peer_create ( struct ast_channel chan)
static

Definition at line 299 of file stasis_channels.c.

300{
301 const char *linkedid = S_OR(ast_channel_linkedid(chan), "");
302 const char *peeraccount = S_OR(ast_channel_peeraccount(chan), "");
303 size_t linkedid_len = strlen(linkedid) + 1;
304 size_t peeraccount_len = strlen(peeraccount) + 1;
305 struct ast_channel_snapshot_peer *snapshot;
306
307 snapshot = ao2_alloc_options(sizeof(*snapshot) + linkedid_len + peeraccount_len, NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
308 if (!snapshot) {
309 return NULL;
310 }
311
312 strcpy(snapshot->account, peeraccount); /* Safe */
313 snapshot->linkedid = snapshot->account + peeraccount_len;
314 ast_copy_string(snapshot->linkedid, linkedid, linkedid_len); /* Safe */
315
316 return snapshot;
317}
const char * ast_channel_linkedid(const struct ast_channel *chan)
const char * ast_channel_peeraccount(const struct ast_channel *chan)
Structure containing peer information for a channel snapshot.

References ast_channel_snapshot_peer::account, AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ast_channel_linkedid(), ast_channel_peeraccount(), ast_copy_string(), ast_channel_snapshot_peer::linkedid, NULL, and S_OR.

Referenced by ast_channel_snapshot_create().

◆ channel_snapshot_uniqueid_cmp_cb()

static int channel_snapshot_uniqueid_cmp_cb ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 219 of file stasis_channels.c.

220{
221 const struct ast_channel_snapshot *object_left = obj;
222 const struct ast_channel_snapshot *object_right = arg;
223 const char *right_key = arg;
224 int cmp;
225
226 switch (flags & OBJ_SEARCH_MASK) {
228 right_key = object_right->base->uniqueid;
229 case OBJ_SEARCH_KEY:
230 cmp = strcasecmp(object_left->base->uniqueid, right_key);
231 break;
233 cmp = strncasecmp(object_left->base->uniqueid, right_key, strlen(right_key));
234 break;
235 default:
236 cmp = 0;
237 break;
238 }
239 if (cmp) {
240 return 0;
241 }
242 return CMP_MATCH;
243}

References ast_channel_snapshot::base, CMP_MATCH, ast_channel_snapshot::flags, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, OBJ_SEARCH_PARTIAL_KEY, and ast_channel_snapshot_base::uniqueid.

Referenced by ast_stasis_channels_init().

◆ channel_snapshot_uniqueid_hash_cb()

static int channel_snapshot_uniqueid_hash_cb ( const void *  obj,
const int  flags 
)
static

Definition at line 196 of file stasis_channels.c.

197{
198 const struct ast_channel_snapshot *object = obj;
199 const char *key;
200
201 switch (flags & OBJ_SEARCH_MASK) {
202 case OBJ_SEARCH_KEY:
203 key = obj;
204 break;
206 key = object->base->uniqueid;
207 break;
208 default:
209 ast_assert(0);
210 return 0;
211 }
212 return ast_str_case_hash(key);
213}

References ast_assert, ast_str_case_hash(), ast_channel_snapshot::flags, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, and OBJ_SEARCH_OBJECT.

Referenced by ast_stasis_channels_init().

◆ channel_snapshot_update_create()

static struct ast_channel_snapshot_update * channel_snapshot_update_create ( struct ast_channel chan)
static

Definition at line 571 of file stasis_channels.c.

572{
574
577 if (!update) {
578 return NULL;
579 }
580
581 update->old_snapshot = ao2_bump(ast_channel_snapshot(chan));
582 update->new_snapshot = ast_channel_snapshot_create(chan);
583 if (!update->new_snapshot) {
584 ao2_ref(update, -1);
585 return NULL;
586 }
587
588 return update;
589}
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
struct ast_channel_snapshot * ast_channel_snapshot(const struct ast_channel *chan)
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
static void channel_snapshot_update_dtor(void *obj)
Structure representing a change of snapshot of channel state.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_bump, ao2_ref, ast_channel_snapshot(), ast_channel_snapshot_create(), channel_snapshot_update_dtor(), NULL, and update().

Referenced by ast_channel_publish_final_snapshot(), and ast_channel_publish_snapshot().

◆ channel_snapshot_update_dtor()

static void channel_snapshot_update_dtor ( void *  obj)
static

Definition at line 563 of file stasis_channels.c.

564{
566
567 ao2_cleanup(update->old_snapshot);
568 ao2_cleanup(update->new_snapshot);
569}

References ao2_cleanup, and update().

Referenced by channel_snapshot_update_create().

◆ create_channel_blob_message()

static struct stasis_message * create_channel_blob_message ( struct ast_channel_snapshot snapshot,
struct stasis_message_type type,
struct ast_json blob 
)
static

Definition at line 750 of file stasis_channels.c.

753{
754 struct stasis_message *msg;
755 struct ast_channel_blob *obj;
756
757 obj = ao2_alloc(sizeof(*obj), channel_blob_dtor);
758 if (!obj) {
759 return NULL;
760 }
761
762 if (snapshot) {
763 obj->snapshot = snapshot;
764 ao2_ref(obj->snapshot, +1);
765 }
766 if (!blob) {
768 }
769 obj->blob = ast_json_ref(blob);
770
771 msg = stasis_message_create(type, obj);
772 ao2_cleanup(obj);
773 return msg;
774}
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
struct ast_json * ast_json_null(void)
Get the JSON null value.
Definition: json.c:248
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
static void channel_blob_dtor(void *obj)

References ao2_alloc, ao2_cleanup, ao2_ref, ast_json_null(), ast_json_ref(), ast_channel_blob::blob, channel_blob_dtor(), NULL, ast_channel_blob::snapshot, stasis_message_create(), and type.

Referenced by ast_channel_blob_create(), and ast_channel_blob_create_from_cache().

◆ dial_masquerade_breakdown()

static void dial_masquerade_breakdown ( void *  data,
struct ast_channel old_chan,
struct ast_channel new_chan 
)
static

Definition at line 1919 of file stasis_channels.c.

1920{
1921 struct dial_masquerade_datastore *masq_data = data;
1922 struct dial_target *cur;
1923
1924 ao2_lock(masq_data);
1925
1926 if (!masq_data->caller) {
1927 ao2_unlock(masq_data);
1928 return;
1929 }
1930
1931 if (masq_data->caller == new_chan) {
1932 /*
1933 * The caller channel is being masqueraded into.
1934 * The masquerade is likely because of a blonde transfer.
1935 */
1936 ast_debug(1, "Caller channel %s being masqueraded into by %s (is_empty:%d)\n",
1937 ast_channel_name(old_chan), ast_channel_name(new_chan),
1938 AST_LIST_EMPTY(&masq_data->dialed_peers));
1939 AST_LIST_TRAVERSE(&masq_data->dialed_peers, cur, list) {
1941 cur->dialstring, "NOANSWER", NULL);
1943 cur->dialstring, NULL, NULL);
1944 }
1945
1946 ao2_unlock(masq_data);
1947 return;
1948 }
1949
1950 /*
1951 * One of the peer channels is being masqueraded into.
1952 * The masquerade is likely because of a call pickup.
1953 */
1954 AST_LIST_TRAVERSE(&masq_data->dialed_peers, cur, list) {
1955 if (cur->peer == new_chan) {
1956 ast_debug(1, "Peer channel %s being masqueraded into by %s\n",
1957 ast_channel_name(old_chan), ast_channel_name(new_chan));
1958 ast_channel_publish_dial_internal(masq_data->caller, old_chan, NULL,
1959 cur->dialstring, "CANCEL", NULL);
1960 ast_channel_publish_dial_internal(masq_data->caller, new_chan, NULL,
1961 cur->dialstring, NULL, NULL);
1962 break;
1963 }
1964 }
1965
1966 ao2_unlock(masq_data);
1967}
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717
#define ast_debug(level,...)
Log a DEBUG message.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
static void ast_channel_publish_dial_internal(struct ast_channel *caller, struct ast_channel *peer, struct ast_channel *forwarded, const char *dialstring, const char *dialstatus, const char *forward)
struct ast_channel * caller
struct dial_masquerade_datastore::@398 dialed_peers
struct ast_channel * peer
struct dial_target::@397 list

References ao2_lock, ao2_unlock, ast_channel_name(), ast_channel_publish_dial_internal(), ast_debug, AST_LIST_EMPTY, AST_LIST_TRAVERSE, dial_masquerade_datastore::caller, dial_masquerade_datastore::dialed_peers, dial_target::dialstring, dial_target::list, NULL, and dial_target::peer.

◆ dial_masquerade_caller_datastore_destroy()

static void dial_masquerade_caller_datastore_destroy ( void *  data)
static

Definition at line 1852 of file stasis_channels.c.

1853{
1855 ao2_ref(data, -1);
1856}
static void dial_masquerade_datastore_cleanup(struct dial_masquerade_datastore *masq_data)

References ao2_ref, and dial_masquerade_datastore_cleanup().

◆ dial_masquerade_datastore_add()

static struct dial_masquerade_datastore * dial_masquerade_datastore_add ( struct ast_channel chan,
struct dial_masquerade_datastore masq_data 
)
static

Definition at line 2014 of file stasis_channels.c.

2016{
2017 struct ast_datastore *datastore;
2018
2020 if (!datastore) {
2021 return NULL;
2022 }
2023
2024 if (!masq_data) {
2025 masq_data = dial_masquerade_datastore_alloc();
2026 if (!masq_data) {
2027 ast_datastore_free(datastore);
2028 return NULL;
2029 }
2030 masq_data->caller = chan;
2031 }
2032
2033 datastore->data = masq_data;
2034 ast_channel_datastore_add(chan, datastore);
2035
2036 return masq_data;
2037}
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2385
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:85
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
static const struct ast_datastore_info dial_masquerade_caller_info
static const struct ast_datastore_info dial_masquerade_info
static struct dial_masquerade_datastore * dial_masquerade_datastore_alloc(void)
Structure for a data store object.
Definition: datastore.h:64
void * data
Definition: datastore.h:66

References ast_channel_datastore_add(), ast_datastore_alloc, ast_datastore_free(), dial_masquerade_datastore::caller, ast_datastore::data, dial_masquerade_caller_info, dial_masquerade_datastore_alloc(), dial_masquerade_info, and NULL.

Referenced by set_dial_masquerade().

◆ dial_masquerade_datastore_alloc()

static struct dial_masquerade_datastore * dial_masquerade_datastore_alloc ( void  )
static

Definition at line 1826 of file stasis_channels.c.

1827{
1828 struct dial_masquerade_datastore *masq_data;
1829
1830 masq_data = ao2_alloc(sizeof(struct dial_masquerade_datastore),
1832 if (!masq_data) {
1833 return NULL;
1834 }
1836 return masq_data;
1837}
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:681
static void dial_masquerade_datastore_dtor(void *vdoomed)

References ao2_alloc, AST_LIST_HEAD_INIT_NOLOCK, dial_masquerade_datastore_dtor(), dial_masquerade_datastore::dialed_peers, and NULL.

Referenced by dial_masquerade_datastore_add().

◆ dial_masquerade_datastore_cleanup()

static void dial_masquerade_datastore_cleanup ( struct dial_masquerade_datastore masq_data)
static

Definition at line 1792 of file stasis_channels.c.

1793{
1794 struct dial_target *cur;
1795
1796 while ((cur = AST_LIST_REMOVE_HEAD(&masq_data->dialed_peers, list))) {
1797 dial_target_free(cur);
1798 }
1799}
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:833
static void dial_target_free(struct dial_target *doomed)

References AST_LIST_REMOVE_HEAD, dial_target_free(), dial_masquerade_datastore::dialed_peers, and dial_target::list.

Referenced by dial_masquerade_caller_datastore_destroy(), dial_masquerade_datastore_dtor(), dial_masquerade_datastore_remove_chan(), and dial_masquerade_fixup().

◆ dial_masquerade_datastore_destroy()

static void dial_masquerade_datastore_destroy ( void *  data)
static

Definition at line 1843 of file stasis_channels.c.

1844{
1845 ao2_ref(data, -1);
1846}

References ao2_ref.

◆ dial_masquerade_datastore_dtor()

static void dial_masquerade_datastore_dtor ( void *  vdoomed)
static

Definition at line 1821 of file stasis_channels.c.

1822{
1824}

References dial_masquerade_datastore_cleanup().

Referenced by dial_masquerade_datastore_alloc().

◆ dial_masquerade_datastore_find()

static struct ast_datastore * dial_masquerade_datastore_find ( struct ast_channel chan)
static

Definition at line 1991 of file stasis_channels.c.

1992{
1993 struct ast_datastore *datastore;
1994
1996 if (!datastore) {
1998 }
1999
2000 return datastore;
2001}
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2399

References ast_channel_datastore_find(), dial_masquerade_caller_info, dial_masquerade_info, and NULL.

Referenced by dial_masquerade_fixup(), remove_dial_masquerade(), remove_dial_masquerade_caller(), and set_dial_masquerade().

◆ dial_masquerade_datastore_remove_chan()

static void dial_masquerade_datastore_remove_chan ( struct dial_masquerade_datastore masq_data,
struct ast_channel chan 
)
static

Definition at line 1801 of file stasis_channels.c.

1802{
1803 struct dial_target *cur;
1804
1805 ao2_lock(masq_data);
1806 if (masq_data->caller == chan) {
1808 } else {
1810 if (cur->peer == chan) {
1812 dial_target_free(cur);
1813 break;
1814 }
1815 }
1817 }
1818 ao2_unlock(masq_data);
1819}
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:615
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:529
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:557

References ao2_lock, ao2_unlock, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, dial_masquerade_datastore::caller, dial_masquerade_datastore_cleanup(), dial_target_free(), dial_masquerade_datastore::dialed_peers, dial_target::list, and dial_target::peer.

Referenced by remove_dial_masquerade(), remove_dial_masquerade_caller(), and set_dial_masquerade().

◆ dial_masquerade_fixup()

static void dial_masquerade_fixup ( void *  data,
struct ast_channel old_chan,
struct ast_channel new_chan 
)
static

Definition at line 1860 of file stasis_channels.c.

1861{
1862 struct dial_masquerade_datastore *masq_data = data;
1863 struct dial_target *cur;
1864 struct ast_datastore *datastore;
1865
1866 ao2_lock(masq_data);
1867 if (!masq_data->caller) {
1868 /* Nothing to do but remove the datastore */
1869 } else if (masq_data->caller == old_chan) {
1870 /* The caller channel is being masqueraded out. */
1871 ast_debug(1, "Caller channel %s being masqueraded out to %s (is_empty:%d)\n",
1872 ast_channel_name(new_chan), ast_channel_name(old_chan),
1873 AST_LIST_EMPTY(&masq_data->dialed_peers));
1874 AST_LIST_TRAVERSE(&masq_data->dialed_peers, cur, list) {
1876 cur->dialstring, "NOANSWER", NULL);
1878 cur->dialstring, NULL, NULL);
1879 }
1881 } else {
1882 /* One of the peer channels is being masqueraded out. */
1883 AST_LIST_TRAVERSE_SAFE_BEGIN(&masq_data->dialed_peers, cur, list) {
1884 if (cur->peer == old_chan) {
1885 ast_debug(1, "Peer channel %s being masqueraded out to %s\n",
1886 ast_channel_name(new_chan), ast_channel_name(old_chan));
1887 ast_channel_publish_dial_internal(masq_data->caller, new_chan, NULL,
1888 cur->dialstring, "CANCEL", NULL);
1889 ast_channel_publish_dial_internal(masq_data->caller, old_chan, NULL,
1890 cur->dialstring, NULL, NULL);
1891
1893 dial_target_free(cur);
1894 break;
1895 }
1896 }
1898 }
1899 ao2_unlock(masq_data);
1900
1901 /* Remove the datastore from the channel. */
1902 datastore = dial_masquerade_datastore_find(old_chan);
1903 if (!datastore) {
1904 return;
1905 }
1906 ast_channel_datastore_remove(old_chan, datastore);
1907 ast_datastore_free(datastore);
1908}
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition: channel.c:2394
static struct ast_datastore * dial_masquerade_datastore_find(struct ast_channel *chan)

References ao2_lock, ao2_unlock, ast_channel_datastore_remove(), ast_channel_name(), ast_channel_publish_dial_internal(), ast_datastore_free(), ast_debug, AST_LIST_EMPTY, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, dial_masquerade_datastore::caller, dial_masquerade_datastore_cleanup(), dial_masquerade_datastore_find(), dial_target_free(), dial_masquerade_datastore::dialed_peers, dial_target::dialstring, NULL, and dial_target::peer.

◆ dial_target_free()

static void dial_target_free ( struct dial_target doomed)
static

Definition at line 1770 of file stasis_channels.c.

1771{
1772 if (!doomed) {
1773 return;
1774 }
1775 ast_free(doomed->dialstring);
1776 ast_channel_cleanup(doomed->peer);
1777 ast_free(doomed);
1778}
#define ast_channel_cleanup(c)
Cleanup a channel reference.
Definition: channel.h:2969

References ast_channel_cleanup, ast_free, dial_target::dialstring, and dial_target::peer.

Referenced by dial_masquerade_datastore_cleanup(), dial_masquerade_datastore_remove_chan(), and dial_masquerade_fixup().

◆ dial_to_json()

static struct ast_json * dial_to_json ( struct stasis_message message,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 1473 of file stasis_channels.c.

1476{
1478 struct ast_json *blob = ast_multi_channel_blob_get_json(payload);
1479 const char *dialstatus =
1480 ast_json_string_get(ast_json_object_get(blob, "dialstatus"));
1481 const char *forward =
1482 ast_json_string_get(ast_json_object_get(blob, "forward"));
1483 const char *dialstring =
1484 ast_json_string_get(ast_json_object_get(blob, "dialstring"));
1485 struct ast_json *caller_json = ast_channel_snapshot_to_json(ast_multi_channel_blob_get_channel(payload, "caller"), sanitize);
1486 struct ast_json *peer_json = ast_channel_snapshot_to_json(ast_multi_channel_blob_get_channel(payload, "peer"), sanitize);
1487 struct ast_json *forwarded_json = ast_channel_snapshot_to_json(ast_multi_channel_blob_get_channel(payload, "forwarded"), sanitize);
1488 struct ast_json *json;
1489 const struct timeval *tv = stasis_message_timestamp(message);
1490 int res = 0;
1491
1492 json = ast_json_pack("{s: s, s: o, s: s, s: s, s: s}",
1493 "type", "Dial",
1494 "timestamp", ast_json_timeval(*tv, NULL),
1495 "dialstatus", dialstatus,
1496 "forward", forward,
1497 "dialstring", dialstring);
1498 if (!json) {
1499 ast_json_unref(caller_json);
1500 ast_json_unref(peer_json);
1501 ast_json_unref(forwarded_json);
1502 return NULL;
1503 }
1504
1505 if (caller_json) {
1506 res |= ast_json_object_set(json, "caller", caller_json);
1507 }
1508 if (peer_json) {
1509 res |= ast_json_object_set(json, "peer", peer_json);
1510 }
1511 if (forwarded_json) {
1512 res |= ast_json_object_set(json, "forwarded", forwarded_json);
1513 }
1514
1515 if (res) {
1516 ast_json_unref(json);
1517 return NULL;
1518 }
1519
1520 return json;
1521}
struct ast_channel_snapshot * ast_multi_channel_blob_get_channel(struct ast_multi_channel_blob *obj, const char *role)
Retrieve a channel snapshot associated with a specific role from a ast_multi_channel_blob.
struct ast_json * ast_multi_channel_blob_get_json(struct ast_multi_channel_blob *obj)
Retrieve the JSON blob from a ast_multi_channel_blob. Returned ast_json is still owned by obj.

References ast_channel_snapshot_to_json(), ast_json_object_get(), ast_json_object_set(), ast_json_pack(), ast_json_string_get(), ast_json_timeval(), ast_json_unref(), ast_multi_channel_blob_get_channel(), ast_multi_channel_blob_get_json(), NULL, stasis_message_data(), and stasis_message_timestamp().

◆ dtmf_end_to_json()

static struct ast_json * dtmf_end_to_json ( struct stasis_message message,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 1425 of file stasis_channels.c.

1428{
1429 struct ast_channel_blob *channel_blob = stasis_message_data(message);
1430 struct ast_json *blob = channel_blob->blob;
1431 struct ast_channel_snapshot *snapshot = channel_blob->snapshot;
1432 const char *direction =
1433 ast_json_string_get(ast_json_object_get(blob, "direction"));
1434 const char *digit =
1436 long duration_ms =
1437 ast_json_integer_get(ast_json_object_get(blob, "duration_ms"));
1438 const struct timeval *tv = stasis_message_timestamp(message);
1439 struct ast_json *json_channel;
1440
1441 /* Only present received DTMF end events as JSON */
1442 if (strcasecmp("Received", direction) != 0) {
1443 return NULL;
1444 }
1445
1446 json_channel = ast_channel_snapshot_to_json(snapshot, sanitize);
1447 if (!json_channel) {
1448 return NULL;
1449 }
1450
1451 return ast_json_pack("{s: s, s: o, s: s, s: I, s: o}",
1452 "type", "ChannelDtmfReceived",
1453 "timestamp", ast_json_timeval(*tv, NULL),
1454 "digit", digit,
1455 "duration_ms", (ast_json_int_t)duration_ms,
1456 "channel", json_channel);
1457}
char digit
direction
AST_JSON_INT_T ast_json_int_t
Primarily used to cast when packing to an "I" type.
Definition: json.h:87

References ast_channel_snapshot_to_json(), ast_json_integer_get(), ast_json_object_get(), ast_json_pack(), ast_json_string_get(), ast_json_timeval(), ast_channel_blob::blob, digit, NULL, ast_channel_blob::snapshot, stasis_message_data(), and stasis_message_timestamp().

◆ hangup_request_to_json()

static struct ast_json * hangup_request_to_json ( struct stasis_message message,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 1466 of file stasis_channels.c.

1469{
1470 return channel_blob_to_json(message, "ChannelHangupRequest", sanitize);
1471}
static struct ast_json * channel_blob_to_json(struct stasis_message *message, const char *type, const struct stasis_message_sanitizer *sanitize)

References channel_blob_to_json().

◆ hold_to_json()

static struct ast_json * hold_to_json ( struct stasis_message message,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 1575 of file stasis_channels.c.

1577{
1578 struct ast_channel_blob *channel_blob = stasis_message_data(message);
1579 struct ast_json *blob = channel_blob->blob;
1580 struct ast_channel_snapshot *snapshot = channel_blob->snapshot;
1581 const char *musicclass = ast_json_string_get(ast_json_object_get(blob, "musicclass"));
1582 const struct timeval *tv = stasis_message_timestamp(message);
1583 struct ast_json *json_channel;
1584
1585 json_channel = ast_channel_snapshot_to_json(snapshot, sanitize);
1586 if (!json_channel) {
1587 return NULL;
1588 }
1589
1590 return ast_json_pack("{s: s, s: o, s: s, s: o}",
1591 "type", "ChannelHold",
1592 "timestamp", ast_json_timeval(*tv, NULL),
1593 "musicclass", S_OR(musicclass, "N/A"),
1594 "channel", json_channel);
1595}

References ast_channel_snapshot_to_json(), ast_json_object_get(), ast_json_pack(), ast_json_string_get(), ast_json_timeval(), ast_channel_blob::blob, NULL, S_OR, ast_channel_blob::snapshot, stasis_message_data(), and stasis_message_timestamp().

◆ multi_channel_blob_dtor()

static void multi_channel_blob_dtor ( void *  obj)
static

Definition at line 878 of file stasis_channels.c.

879{
880 struct ast_multi_channel_blob *multi_blob = obj;
881
882 ao2_cleanup(multi_blob->channel_snapshots);
883 ast_json_unref(multi_blob->blob);
884}
struct ast_json * blob
struct ao2_container * channel_snapshots

References ao2_cleanup, ast_json_unref(), ast_multi_channel_blob::blob, and ast_multi_channel_blob::channel_snapshots.

Referenced by ast_multi_channel_blob_create().

◆ publish_message_for_channel_topics()

static void publish_message_for_channel_topics ( struct stasis_message message,
struct ast_channel chan 
)
static

Definition at line 591 of file stasis_channels.c.

592{
593 if (chan) {
595 } else {
597 }
598}
struct stasis_topic * ast_channel_topic(struct ast_channel *chan)
A topic which publishes the events for a particular channel.
struct stasis_topic * ast_channel_topic_all(void)
A topic which publishes the events for all channels.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
Definition: stasis.c:1511

References ast_channel_topic(), ast_channel_topic_all(), and stasis_publish().

Referenced by ast_channel_publish_dial_internal().

◆ remove_dial_masquerade()

static void remove_dial_masquerade ( struct ast_channel peer)
static

Definition at line 2118 of file stasis_channels.c.

2119{
2120 struct ast_datastore *datastore;
2121 struct dial_masquerade_datastore *masq_data;
2122
2123 datastore = dial_masquerade_datastore_find(peer);
2124 if (!datastore) {
2125 return;
2126 }
2127
2128 masq_data = datastore->data;
2129 if (masq_data) {
2131 }
2132
2133 ast_channel_datastore_remove(peer, datastore);
2134 ast_datastore_free(datastore);
2135}
static void dial_masquerade_datastore_remove_chan(struct dial_masquerade_datastore *masq_data, struct ast_channel *chan)

References ast_channel_datastore_remove(), ast_datastore_free(), ast_datastore::data, dial_masquerade_datastore_find(), and dial_masquerade_datastore_remove_chan().

Referenced by ast_channel_publish_dial_forward().

◆ remove_dial_masquerade_caller()

static void remove_dial_masquerade_caller ( struct ast_channel caller)
static

Definition at line 2137 of file stasis_channels.c.

2138{
2139 struct ast_datastore *datastore;
2140 struct dial_masquerade_datastore *masq_data;
2141
2143 if (!datastore) {
2144 return;
2145 }
2146
2147 masq_data = datastore->data;
2148 if (!masq_data || !AST_LIST_EMPTY(&masq_data->dialed_peers)) {
2149 return;
2150 }
2151
2153
2155 ast_datastore_free(datastore);
2156}

References ast_channel_datastore_remove(), ast_datastore_free(), AST_LIST_EMPTY, dial_masquerade_datastore::caller, ast_datastore::data, dial_masquerade_datastore_find(), dial_masquerade_datastore_remove_chan(), and dial_masquerade_datastore::dialed_peers.

Referenced by ast_channel_publish_dial_forward().

◆ set_dial_masquerade()

static int set_dial_masquerade ( struct ast_channel caller,
struct ast_channel peer,
const char *  dialstring 
)
static

Definition at line 2039 of file stasis_channels.c.

2040{
2041 struct ast_datastore *datastore;
2042 struct dial_masquerade_datastore *masq_data;
2043 struct dial_target *target;
2044
2045 /* Find or create caller datastore */
2046 datastore = dial_masquerade_datastore_find(caller);
2047 if (!datastore) {
2048 masq_data = dial_masquerade_datastore_add(caller, NULL);
2049 } else {
2050 masq_data = datastore->data;
2051 }
2052 if (!masq_data) {
2053 return -1;
2054 }
2055 ao2_ref(masq_data, +1);
2056
2057 /*
2058 * Someone likely forgot to do an ast_channel_publish_dial()
2059 * or ast_channel_publish_dial_forward() with a final dial
2060 * status on the channel.
2061 */
2062 ast_assert(masq_data->caller == caller);
2063
2064 /* Create peer target to put into datastore */
2065 target = ast_calloc(1, sizeof(*target));
2066 if (!target) {
2067 ao2_ref(masq_data, -1);
2068 return -1;
2069 }
2070 if (dialstring) {
2071 target->dialstring = ast_strdup(dialstring);
2072 if (!target->dialstring) {
2073 ast_free(target);
2074 ao2_ref(masq_data, -1);
2075 return -1;
2076 }
2077 }
2078 target->peer = ast_channel_ref(peer);
2079
2080 /* Put peer target into datastore */
2081 ao2_lock(masq_data);
2083 AST_LIST_INSERT_HEAD(&masq_data->dialed_peers, target, list);
2084 ao2_unlock(masq_data);
2085
2087 if (datastore) {
2088 if (datastore->data == masq_data) {
2089 /*
2090 * Peer already had the datastore for this dial masquerade.
2091 * This was a redundant peer dial masquerade setup.
2092 */
2093 ao2_ref(masq_data, -1);
2094 return 0;
2095 }
2096
2097 /* Something is wrong. Try to fix if the assert doesn't abort. */
2098 ast_assert(0);
2099
2100 /* Remove the stale dial masquerade datastore */
2103 ast_datastore_free(datastore);
2104 }
2105
2106 /* Create the peer dial masquerade datastore */
2107 if (dial_masquerade_datastore_add(peer, masq_data)) {
2108 /* Success */
2109 return 0;
2110 }
2111
2112 /* Failed to create the peer datastore */
2114 ao2_ref(masq_data, -1);
2115 return -1;
2116}
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2947
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:711
static struct dial_masquerade_datastore * dial_masquerade_datastore_add(struct ast_channel *chan, struct dial_masquerade_datastore *masq_data)

References ao2_lock, ao2_ref, ao2_unlock, ast_assert, ast_calloc, ast_channel_datastore_remove(), ast_channel_ref, ast_datastore_free(), ast_free, AST_LIST_INSERT_HEAD, ast_strdup, dial_masquerade_datastore::caller, ast_datastore::data, dial_masquerade_datastore_add(), dial_masquerade_datastore_find(), dial_masquerade_datastore_remove_chan(), dial_masquerade_datastore::dialed_peers, dial_target::dialstring, dial_target::list, NULL, and dial_target::peer.

Referenced by ast_channel_publish_dial_forward().

◆ stasis_channels_cleanup()

static void stasis_channels_cleanup ( void  )
static

Definition at line 1669 of file stasis_channels.c.

1670{
1677
1702}
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
Definition: stasis.h:1515

References ao2_cleanup, ast_channel_agent_login_type(), ast_channel_agent_logoff_type(), ast_channel_chanspy_start_type(), ast_channel_chanspy_stop_type(), ast_channel_dial_type(), ast_channel_dtmf_begin_type(), ast_channel_dtmf_end_type(), ast_channel_fax_type(), ast_channel_flash_type(), ast_channel_hangup_handler_type(), ast_channel_hangup_request_type(), ast_channel_hold_type(), ast_channel_masquerade_type(), ast_channel_mixmonitor_mute_type(), ast_channel_mixmonitor_start_type(), ast_channel_mixmonitor_stop_type(), ast_channel_moh_start_type(), ast_channel_moh_stop_type(), ast_channel_snapshot_type(), ast_channel_talking_start(), ast_channel_talking_stop(), ast_channel_unhold_type(), ast_channel_varset_type(), ast_channel_wink_type(), channel_cache, channel_cache_by_name, channel_topic_all, NULL, and STASIS_MESSAGE_TYPE_CLEANUP.

Referenced by ast_stasis_channels_init().

◆ STASIS_MESSAGE_TYPE_DEFN() [1/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_agent_login_type  ,
to_ami = agent_login_to_ami 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [2/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_agent_logoff_type  ,
to_ami = agent_logoff_to_ami 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [3/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_chanspy_start_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [4/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_chanspy_stop_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [5/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_dial_type  ,
to_json = dial_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [6/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_dtmf_begin_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [7/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_dtmf_end_type  ,
to_json = dtmf_end_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [8/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_fax_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [9/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_flash_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [10/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_hangup_handler_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [11/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_hangup_request_type  ,
to_json = hangup_request_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [12/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_hold_type  ,
to_json = hold_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [13/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_masquerade_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [14/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_mixmonitor_mute_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [15/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_mixmonitor_start_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [16/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_mixmonitor_stop_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [17/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_moh_start_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [18/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_moh_stop_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [19/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_snapshot_type  )

Define channel message types.

◆ STASIS_MESSAGE_TYPE_DEFN() [20/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_talking_start  ,
to_ami = talking_start_to_ami,
to_json = talking_start_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [21/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_talking_stop  ,
to_ami = talking_stop_to_ami,
to_json = talking_stop_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [22/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_unhold_type  ,
to_json = unhold_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [23/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_varset_type  ,
to_ami = varset_to_ami,
to_json = varset_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [24/24]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_wink_type  )

◆ talking_start_to_ami()

static struct ast_manager_event_blob * talking_start_to_ami ( struct stasis_message msg)
static

Definition at line 1523 of file stasis_channels.c.

1524{
1525 struct ast_str *channel_string;
1526 struct ast_channel_blob *obj = stasis_message_data(msg);
1527 struct ast_manager_event_blob *blob;
1528
1529 channel_string = ast_manager_build_channel_state_string(obj->snapshot);
1530 if (!channel_string) {
1531 return NULL;
1532 }
1533
1534 blob = ast_manager_event_blob_create(EVENT_FLAG_CALL, "ChannelTalkingStart",
1535 "%s", ast_str_buffer(channel_string));
1536 ast_free(channel_string);
1537
1538 return blob;
1539}
#define EVENT_FLAG_CALL
Definition: manager.h:76

References ast_free, ast_manager_build_channel_state_string(), ast_manager_event_blob_create(), ast_str_buffer(), EVENT_FLAG_CALL, NULL, ast_channel_blob::snapshot, and stasis_message_data().

◆ talking_start_to_json()

static struct ast_json * talking_start_to_json ( struct stasis_message message,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 1541 of file stasis_channels.c.

1543{
1544 return channel_blob_to_json(message, "ChannelTalkingStarted", sanitize);
1545}

References channel_blob_to_json().

◆ talking_stop_to_ami()

static struct ast_manager_event_blob * talking_stop_to_ami ( struct stasis_message msg)
static

Definition at line 1547 of file stasis_channels.c.

1548{
1549 struct ast_str *channel_string;
1550 struct ast_channel_blob *obj = stasis_message_data(msg);
1551 int duration = ast_json_integer_get(ast_json_object_get(obj->blob, "duration"));
1552 struct ast_manager_event_blob *blob;
1553
1554 channel_string = ast_manager_build_channel_state_string(obj->snapshot);
1555 if (!channel_string) {
1556 return NULL;
1557 }
1558
1559 blob = ast_manager_event_blob_create(EVENT_FLAG_CALL, "ChannelTalkingStop",
1560 "%s"
1561 "Duration: %d\r\n",
1562 ast_str_buffer(channel_string),
1563 duration);
1564 ast_free(channel_string);
1565
1566 return blob;
1567}

References ast_free, ast_json_integer_get(), ast_json_object_get(), ast_manager_build_channel_state_string(), ast_manager_event_blob_create(), ast_str_buffer(), ast_channel_blob::blob, EVENT_FLAG_CALL, NULL, ast_channel_blob::snapshot, and stasis_message_data().

◆ talking_stop_to_json()

static struct ast_json * talking_stop_to_json ( struct stasis_message message,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 1569 of file stasis_channels.c.

1571{
1572 return channel_blob_to_json(message, "ChannelTalkingFinished", sanitize);
1573}

References channel_blob_to_json().

◆ unhold_to_json()

static struct ast_json * unhold_to_json ( struct stasis_message message,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 1597 of file stasis_channels.c.

1599{
1600 struct ast_channel_blob *channel_blob = stasis_message_data(message);
1601 struct ast_channel_snapshot *snapshot = channel_blob->snapshot;
1602 const struct timeval *tv = stasis_message_timestamp(message);
1603 struct ast_json *json_channel;
1604
1605 json_channel = ast_channel_snapshot_to_json(snapshot, sanitize);
1606 if (!json_channel) {
1607 return NULL;
1608 }
1609
1610 return ast_json_pack("{s: s, s: o, s: o}",
1611 "type", "ChannelUnhold",
1612 "timestamp", ast_json_timeval(*tv, NULL),
1613 "channel", json_channel);
1614}

References ast_channel_snapshot_to_json(), ast_json_pack(), ast_json_timeval(), NULL, ast_channel_blob::snapshot, stasis_message_data(), and stasis_message_timestamp().

◆ varset_to_ami()

static struct ast_manager_event_blob * varset_to_ami ( struct stasis_message msg)
static

Definition at line 1210 of file stasis_channels.c.

1211{
1212 struct ast_str *channel_event_string;
1213 struct ast_channel_blob *obj = stasis_message_data(msg);
1214 const char *variable =
1215 ast_json_string_get(ast_json_object_get(obj->blob, "variable"));
1216 char *value;
1217 struct ast_manager_event_blob *ev;
1218
1220 "value")));
1221 if (!value) {
1222 return NULL;
1223 }
1224
1225 if (obj->snapshot) {
1226 channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
1227 } else {
1228 channel_event_string = ast_str_create(35);
1229 ast_str_set(&channel_event_string, 0,
1230 "Channel: none\r\n"
1231 "Uniqueid: none\r\n");
1232 }
1233 if (!channel_event_string) {
1234 ast_free(value);
1235 return NULL;
1236 }
1237
1239 "%s"
1240 "Variable: %s\r\n"
1241 "Value: %s\r\n",
1242 ast_str_buffer(channel_event_string), variable, value);
1243 ast_free(channel_event_string);
1244 ast_free(value);
1245 return ev;
1246}
#define EVENT_FLAG_DIALPLAN
Definition: manager.h:86
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1113
char * ast_escape_c_alloc(const char *s)
Escape standard 'C' sequences in the given string.
Definition: utils.c:2140
int value
Definition: syslog.c:37

References ast_escape_c_alloc(), ast_free, ast_json_object_get(), ast_json_string_get(), ast_manager_build_channel_state_string(), ast_manager_event_blob_create(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_channel_blob::blob, EVENT_FLAG_DIALPLAN, NULL, ast_channel_blob::snapshot, stasis_message_data(), and value.

◆ varset_to_json()

static struct ast_json * varset_to_json ( struct stasis_message message,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 1459 of file stasis_channels.c.

1462{
1463 return channel_blob_to_json(message, "ChannelVarset", sanitize);
1464}

References channel_blob_to_json().

Variable Documentation

◆ channel_cache

struct ao2_container* channel_cache
static

◆ channel_cache_by_name

struct ao2_container* channel_cache_by_name
static

◆ channel_topic_all

struct stasis_topic* channel_topic_all
static

◆ dial_masquerade_caller_info

const struct ast_datastore_info dial_masquerade_caller_info
static

◆ dial_masquerade_info

const struct ast_datastore_info dial_masquerade_info
static