Asterisk - The Open Source Telephony Project  18.5.0
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 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_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_snapshot_type)
 Define channel message types. More...
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_dial_type,.to_json=dial_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_hangup_request_type,.to_json=hangup_request_to_json,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_masquerade_type)
 
 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_hold_type,.to_json=hold_to_json,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_unhold_type,.to_json=unhold_to_json,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_flash_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_chanspy_start_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_chanspy_stop_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_fax_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_hangup_handler_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_monitor_start_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_channel_monitor_stop_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_mixmonitor_mute_type)
 
 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_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,)
 

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 <[email protected]> 

Definition in file stasis_channels.c.

Macro Definition Documentation

◆ NUM_MULTI_CHANNEL_BLOB_BUCKETS

#define NUM_MULTI_CHANNEL_BLOB_BUCKETS   7

Function Documentation

◆ agent_login_to_ami()

static struct ast_manager_event_blob* agent_login_to_ami ( struct stasis_message msg)
static

Definition at line 1213 of file stasis_channels.c.

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

Referenced by unhold_to_json().

1214 {
1215  struct ast_str *channel_string;
1216  struct ast_channel_blob *obj = stasis_message_data(msg);
1217  const char *agent = ast_json_string_get(ast_json_object_get(obj->blob, "agent"));
1218  struct ast_manager_event_blob *ev;
1219 
1220  channel_string = ast_manager_build_channel_state_string(obj->snapshot);
1221  if (!channel_string) {
1222  return NULL;
1223  }
1224 
1226  "%s"
1227  "Agent: %s\r\n",
1228  ast_str_buffer(channel_string), agent);
1229  ast_free(channel_string);
1230  return ev;
1231 }
Struct containing info for an AMI event to send out.
Definition: manager.h:491
struct ast_json * blob
struct ast_channel_snapshot * snapshot
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define NULL
Definition: resample.c:96
struct ast_manager_event_blob * ast_manager_event_blob_create(int event_flags, const char *manager_event, const char *extra_fields_fmt,...)
Construct a ast_manager_event_blob.
Definition: manager.c:9727
Blob of data associated with a channel.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
struct ast_str * ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
Generate the AMI message body from a channel snapshot.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#define EVENT_FLAG_AGENT
Definition: manager.h:76
#define ast_free(a)
Definition: astmm.h:182
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:397

◆ agent_logoff_to_ami()

static struct ast_manager_event_blob* agent_logoff_to_ami ( struct stasis_message msg)
static

Definition at line 1233 of file stasis_channels.c.

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

Referenced by unhold_to_json().

1234 {
1235  struct ast_str *channel_string;
1236  struct ast_channel_blob *obj = stasis_message_data(msg);
1237  const char *agent = ast_json_string_get(ast_json_object_get(obj->blob, "agent"));
1238  long logintime = ast_json_integer_get(ast_json_object_get(obj->blob, "logintime"));
1239  struct ast_manager_event_blob *ev;
1240 
1241  channel_string = ast_manager_build_channel_state_string(obj->snapshot);
1242  if (!channel_string) {
1243  return NULL;
1244  }
1245 
1246  ev = ast_manager_event_blob_create(EVENT_FLAG_AGENT, "AgentLogoff",
1247  "%s"
1248  "Agent: %s\r\n"
1249  "Logintime: %ld\r\n",
1250  ast_str_buffer(channel_string), agent, logintime);
1251  ast_free(channel_string);
1252  return ev;
1253 }
Struct containing info for an AMI event to send out.
Definition: manager.h:491
struct ast_json * blob
struct ast_channel_snapshot * snapshot
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define NULL
Definition: resample.c:96
struct ast_manager_event_blob * ast_manager_event_blob_create(int event_flags, const char *manager_event, const char *extra_fields_fmt,...)
Construct a ast_manager_event_blob.
Definition: manager.c:9727
Blob of data associated with a channel.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
struct ast_str * ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
Generate the AMI message body from a channel snapshot.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#define EVENT_FLAG_AGENT
Definition: manager.h:76
#define ast_free(a)
Definition: astmm.h:182
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:397
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
Definition: json.c:322

◆ 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 602 of file stasis_channels.c.

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(), remove_dial_masquerade(), remove_dial_masquerade_caller(), S_OR, set_dial_masquerade(), and stasis_message_create().

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

605 {
606  struct ast_multi_channel_blob *payload;
607  struct stasis_message *msg;
608  struct ast_json *blob;
609  struct ast_channel_snapshot *peer_snapshot;
610 
611  if (!ast_channel_dial_type()) {
612  return;
613  }
614 
615  ast_assert(peer != NULL);
616 
617  blob = ast_json_pack("{s: s, s: s, s: s}",
618  "dialstatus", S_OR(dialstatus, ""),
619  "forward", S_OR(forward, ""),
620  "dialstring", S_OR(dialstring, ""));
621  if (!blob) {
622  return;
623  }
624  payload = ast_multi_channel_blob_create(blob);
625  ast_json_unref(blob);
626  if (!payload) {
627  return;
628  }
629 
630  if (caller) {
631  struct ast_channel_snapshot *caller_snapshot;
632 
633  ast_channel_lock(caller);
634  if (ast_strlen_zero(dialstatus)) {
635  caller_snapshot = ast_channel_snapshot_get_latest(ast_channel_uniqueid(caller));
636  } else {
637  caller_snapshot = ast_channel_snapshot_create(caller);
638  }
639  ast_channel_unlock(caller);
640  if (!caller_snapshot) {
641  ao2_ref(payload, -1);
642  return;
643  }
644  ast_multi_channel_blob_add_channel(payload, "caller", caller_snapshot);
645  ao2_ref(caller_snapshot, -1);
646  }
647 
648  ast_channel_lock(peer);
649  if (ast_strlen_zero(dialstatus)) {
651  } else {
652  peer_snapshot = ast_channel_snapshot_create(peer);
653  }
654  ast_channel_unlock(peer);
655  if (!peer_snapshot) {
656  ao2_ref(payload, -1);
657  return;
658  }
659  ast_multi_channel_blob_add_channel(payload, "peer", peer_snapshot);
660  ao2_ref(peer_snapshot, -1);
661 
662  if (forwarded) {
663  struct ast_channel_snapshot *forwarded_snapshot;
664 
665  ast_channel_lock(forwarded);
666  forwarded_snapshot = ast_channel_snapshot_create(forwarded);
667  ast_channel_unlock(forwarded);
668  if (!forwarded_snapshot) {
669  ao2_ref(payload, -1);
670  return;
671  }
672  ast_multi_channel_blob_add_channel(payload, "forwarded", forwarded_snapshot);
673  ao2_ref(forwarded_snapshot, -1);
674  }
675 
677  ao2_ref(payload, -1);
678  if (msg) {
679  publish_message_for_channel_topics(msg, caller ?: peer);
680  ao2_ref(msg, -1);
681  }
682 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
Structure representing a snapshot of channel state.
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
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...
#define ast_strlen_zero(foo)
Definition: strings.h:52
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.
#define ao2_ref(o, delta)
Definition: astobj2.h:464
const char * ast_channel_uniqueid(const struct ast_channel *chan)
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static void publish_message_for_channel_topics(struct stasis_message *message, struct ast_channel *chan)
struct ast_channel_snapshot * ast_channel_snapshot_get_latest(const char *uniqueid)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object...
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
A multi channel blob data structure for multi_channel_blob stasis messages.
Abstract JSON element (object, array, string, int, ...).
struct stasis_message_type * ast_channel_dial_type(void)
Message type for when a channel dials another channel.
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.

◆ 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
Returns
True (non-zero) if callerid are identical.
False (zero) if callerid changed.

Definition at line 1318 of file stasis_channels.c.

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

1321 {
1322  ast_assert(old_snapshot != NULL);
1323  ast_assert(new_snapshot != NULL);
1324  return strcmp(old_snapshot->caller->number, new_snapshot->caller->number) == 0 &&
1325  strcmp(old_snapshot->caller->name, new_snapshot->caller->name) == 0;
1326 }
const ast_string_field name
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
struct ast_channel_snapshot_caller * caller
const ast_string_field number

◆ 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
Returns
True (non-zero) if context, exten or priority are identical.
False (zero) if context, exten and priority changed.

Definition at line 1297 of file stasis_channels.c.

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

1300 {
1301  ast_assert(old_snapshot != NULL);
1302  ast_assert(new_snapshot != NULL);
1303 
1304  /* We actually get some snapshots with CEP set, but before the
1305  * application is set. Since empty application is invalid, we treat
1306  * setting the application from nothing as a CEP change.
1307  */
1308  if (ast_strlen_zero(old_snapshot->dialplan->appl) &&
1309  !ast_strlen_zero(new_snapshot->dialplan->appl)) {
1310  return 0;
1311  }
1312 
1313  return old_snapshot->dialplan->priority == new_snapshot->dialplan->priority &&
1314  strcmp(old_snapshot->dialplan->context, new_snapshot->dialplan->context) == 0 &&
1315  strcmp(old_snapshot->dialplan->exten, new_snapshot->dialplan->exten) == 0;
1316 }
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
struct ast_channel_snapshot_dialplan * dialplan
#define ast_strlen_zero(foo)
Definition: strings.h:52
const ast_string_field context
const ast_string_field appl
const ast_string_field exten

◆ 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
Returns
True (non-zero) if callerid are identical.
False (zero) if callerid changed.

Definition at line 1328 of file stasis_channels.c.

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

1331 {
1332  ast_assert(old_snapshot != NULL);
1333  ast_assert(new_snapshot != NULL);
1334  return strcmp(old_snapshot->connected->number, new_snapshot->connected->number) == 0 &&
1335  strcmp(old_snapshot->connected->name, new_snapshot->connected->name) == 0;
1336 }
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
struct ast_channel_snapshot_connected * connected

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

Definition at line 1255 of file stasis_channels.c.

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_timeval(), AST_LIST_EMPTY, ast_state2str(), 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::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().

1258 {
1259  struct ast_json *json_chan;
1260 
1261  if (snapshot == NULL
1262  || (sanitize
1263  && sanitize->channel_snapshot
1264  && sanitize->channel_snapshot(snapshot))) {
1265  return NULL;
1266  }
1267 
1268  json_chan = ast_json_pack(
1269  /* Broken up into groups of three for readability */
1270  "{ s: s, s: s, s: s,"
1271  " s: o, s: o, s: s,"
1272  " s: o, s: o, s: s }",
1273  /* First line */
1274  "id", snapshot->base->uniqueid,
1275  "name", snapshot->base->name,
1276  "state", ast_state2str(snapshot->state),
1277  /* Second line */
1278  "caller", ast_json_name_number(
1279  snapshot->caller->name, snapshot->caller->number),
1280  "connected", ast_json_name_number(
1281  snapshot->connected->name, snapshot->connected->number),
1282  "accountcode", snapshot->base->accountcode,
1283  /* Third line */
1284  "dialplan", ast_json_dialplan_cep_app(
1285  snapshot->dialplan->context, snapshot->dialplan->exten, snapshot->dialplan->priority,
1286  snapshot->dialplan->appl, snapshot->dialplan->data),
1287  "creationtime", ast_json_timeval(snapshot->base->creationtime, NULL),
1288  "language", snapshot->base->language);
1289 
1290  if (snapshot->ari_vars && !AST_LIST_EMPTY(snapshot->ari_vars)) {
1291  ast_json_object_set(json_chan, "channelvars", ast_json_channel_vars(snapshot->ari_vars));
1292  }
1293 
1294  return json_chan;
1295 }
const ast_string_field data
struct ast_channel_snapshot_base * base
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
const ast_string_field name
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&#39;s...
Definition: stasis.h:221
const ast_string_field accountcode
const ast_string_field uniqueid
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
const char * ast_state2str(enum ast_channel_state)
Gives the string form of a given channel state.
Definition: channel.c:642
#define NULL
Definition: resample.c:96
struct ast_channel_snapshot_dialplan * dialplan
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition: json.c:404
struct ast_json * ast_json_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:632
struct ast_json * ast_json_channel_vars(struct varshead *channelvars)
Construct a JSON object from a ast_var_t list.
Definition: json.c:843
const ast_string_field context
struct varshead * ari_vars
struct ast_json * ast_json_name_number(const char *name, const char *number)
Common JSON rendering functions for common &#39;objects&#39;.
Definition: json.c:625
const ast_string_field appl
const ast_string_field exten
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
Definition: json.c:649
struct ast_channel_snapshot_caller * caller
enum ast_channel_state state
const ast_string_field language
const ast_string_field number
Abstract JSON element (object, array, string, int, ...).
struct ast_channel_snapshot_connected * connected
const ast_string_field name

◆ ast_stasis_channels_init()

int ast_stasis_channels_init ( void  )

Initialize the stasis channel topic and message types.

Returns
0 on success
Non-zero on error

Definition at line 1666 of file stasis_channels.c.

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_monitor_start_type(), ast_channel_monitor_stop_type(), ast_channel_snapshot_type(), ast_channel_talking_start(), ast_channel_talking_stop(), ast_channel_unhold_type(), ast_channel_varset_type(), AST_NUM_CHANNEL_BUCKETS, ast_register_cleanup(), channel_snapshot_cmp_cb(), channel_snapshot_hash_cb(), channel_snapshot_uniqueid_cmp_cb(), channel_snapshot_uniqueid_hash_cb(), NULL, stasis_channels_cleanup(), STASIS_MESSAGE_TYPE_INIT, and stasis_topic_create().

Referenced by ast_channels_init().

1667 {
1668  int res = 0;
1669 
1671 
1672  channel_topic_all = stasis_topic_create("channel:all");
1673  if (!channel_topic_all) {
1674  return -1;
1675  }
1676 
1680  if (!channel_cache) {
1681  return -1;
1682  }
1683 
1687  if (!channel_cache_by_name) {
1688  return -1;
1689  }
1690 
1716 
1717  return res;
1718 }
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_stop(void)
Message type for a channel stopping talking.
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_unhold_type(void)
Message type for when a channel is removed from hold.
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition: stasis.h:1501
struct stasis_message_type * ast_channel_moh_start_type(void)
Message type for starting music on hold on a channel.
static int channel_snapshot_uniqueid_cmp_cb(void *obj, void *arg, int flags)
struct stasis_message_type * ast_channel_flash_type(void)
Message type for when a hook flash occurs on a channel.
#define AST_NUM_CHANNEL_BUCKETS
Definition: channel.h:156
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_chanspy_start_type(void)
Message type for when a channel starts spying on another channel.
#define NULL
Definition: resample.c:96
struct stasis_message_type * ast_channel_monitor_start_type(void)
Message type for starting monitor on a channel.
struct stasis_message_type * ast_channel_talking_start(void)
Message type for a channel starting talking.
static int channel_snapshot_uniqueid_hash_cb(const void *obj, const int flags)
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
static int channel_snapshot_cmp_cb(void *obj, void *arg, int flags)
struct stasis_message_type * ast_channel_monitor_stop_type(void)
Message type for stopping monitor on a channel.
static struct stasis_topic * channel_topic_all
struct stasis_message_type * ast_channel_agent_login_type(void)
Message type for agent login on a channel.
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Definition: stasis.c:618
struct stasis_message_type * ast_channel_agent_logoff_type(void)
Message type for agent logoff on a channel.
static struct ao2_container * channel_cache_by_name
static int channel_snapshot_hash_cb(const void *obj, const int flags)
struct stasis_message_type * ast_channel_mixmonitor_start_type(void)
Message type for starting mixmonitor on a channel.
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Definition: astobj2.h:1310
struct stasis_message_type * ast_channel_mixmonitor_stop_type(void)
Message type for stopping mixmonitor 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_snapshot_type(void)
Message type for ast_channel_snapshot_update.
struct stasis_message_type * ast_channel_dtmf_begin_type(void)
Message type for when DTMF begins on a channel.
static struct ao2_container * channel_cache
struct stasis_message_type * ast_channel_dial_type(void)
Message type for when a channel dials another channel.
struct stasis_message_type * ast_channel_moh_stop_type(void)
Message type for stopping music on hold on a channel.
static void stasis_channels_cleanup(void)
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_masquerade_type(void)
Message type for when a channel is being masqueraded.
struct stasis_message_type * ast_channel_fax_type(void)
Message type for a fax operation.
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_mixmonitor_mute_type(void)
Message type for muting or unmuting mixmonitor on a channel.

◆ channel_blob_dtor()

static void channel_blob_dtor ( void *  obj)
static

Definition at line 595 of file stasis_channels.c.

References ao2_cleanup, and ast_json_unref().

Referenced by create_channel_blob_message().

596 {
597  struct ast_channel_blob *event = obj;
598  ao2_cleanup(event->snapshot);
599  ast_json_unref(event->blob);
600 }
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
Definition: astman.c:222
Blob of data associated with a channel.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ 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 1338 of file stasis_channels.c.

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, channel_role_snapshot::snapshot, stasis_message_data(), and stasis_message_timestamp().

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

1342 {
1343  struct ast_json *to_json;
1344  struct ast_channel_blob *channel_blob = stasis_message_data(message);
1345  struct ast_json *blob = channel_blob->blob;
1346  struct ast_channel_snapshot *snapshot = channel_blob->snapshot;
1347  const struct timeval *tv = stasis_message_timestamp(message);
1348  int res = 0;
1349 
1350  if (blob == NULL || ast_json_is_null(blob)) {
1351  to_json = ast_json_object_create();
1352  } else {
1353  /* blobs are immutable, so shallow copies are fine */
1354  to_json = ast_json_copy(blob);
1355  }
1356  if (!to_json) {
1357  return NULL;
1358  }
1359 
1360  res |= ast_json_object_set(to_json, "type", ast_json_string_create(type));
1361  res |= ast_json_object_set(to_json, "timestamp",
1362  ast_json_timeval(*tv, NULL));
1363 
1364  /* For global channel messages, the snapshot is optional */
1365  if (snapshot) {
1366  struct ast_json *json_channel;
1367 
1368  json_channel = ast_channel_snapshot_to_json(snapshot, sanitize);
1369  if (!json_channel) {
1370  ast_json_unref(to_json);
1371  return NULL;
1372  }
1373 
1374  res |= ast_json_object_set(to_json, "channel", json_channel);
1375  }
1376 
1377  if (res != 0) {
1378  ast_json_unref(to_json);
1379  return NULL;
1380  }
1381 
1382  return to_json;
1383 }
static const char type[]
Definition: chan_ooh323.c:109
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 * blob
struct ast_channel_snapshot * snapshot
Structure representing a snapshot of channel state.
#define NULL
Definition: resample.c:96
int ast_json_is_null(const struct ast_json *value)
Check if value is JSON null.
Definition: json.c:263
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition: json.c:404
Blob of data associated with a channel.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268
const struct timeval * stasis_message_timestamp(const struct stasis_message *msg)
Get the time when a message was created.
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
Definition: json.c:649
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
Definition: json.c:389
Abstract JSON element (object, array, string, int, ...).
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.
struct ast_json * ast_json_copy(const struct ast_json *value)
Copy a JSON value, but not its children.
Definition: json.c:616

◆ channel_role_cmp_cb()

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

Definition at line 820 of file stasis_channels.c.

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

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

◆ channel_role_hash_cb()

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

Definition at line 850 of file stasis_channels.c.

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

Referenced by ast_multi_channel_blob_create().

851 {
852  const struct channel_role_snapshot *object = obj;
853  const char *key;
854 
855  switch (flags & OBJ_SEARCH_MASK) {
856  case OBJ_SEARCH_KEY:
857  key = obj;
858  break;
859  case OBJ_SEARCH_OBJECT:
860  key = object->role;
861  break;
862  default:
863  ast_assert(0);
864  return 0;
865  }
866  return ast_str_case_hash(key);
867 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
#define ast_assert(a)
Definition: utils.h:695
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
Search option field mask.
Definition: astobj2.h:1076
A channel snapshot wrapper object used in ast_multi_channel_blob objects.
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:1250

◆ channel_role_snapshot_dtor()

static void channel_role_snapshot_dtor ( void *  obj)
static

Definition at line 949 of file stasis_channels.c.

References ao2_cleanup, and channel_role_snapshot::snapshot.

Referenced by ast_multi_channel_blob_add_channel().

950 {
951  struct channel_role_snapshot *role_snapshot = obj;
952 
953  ao2_cleanup(role_snapshot->snapshot);
954 }
struct ast_channel_snapshot * snapshot
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
A channel snapshot wrapper object used in ast_multi_channel_blob objects.

◆ channel_snapshot_base_create()

static struct ast_channel_snapshot_base* channel_snapshot_base_create ( struct ast_channel chan)
static

Definition at line 266 of file stasis_channels.c.

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

267 {
268  struct ast_channel_snapshot_base *snapshot;
269 
270  snapshot = ao2_alloc_options(sizeof(*snapshot), channel_snapshot_base_dtor,
272  if (!snapshot) {
273  return NULL;
274  }
275 
276  if (ast_string_field_init(snapshot, 256)) {
277  ao2_ref(snapshot, -1);
278  return NULL;
279  }
280 
281  ast_string_field_set(snapshot, name, ast_channel_name(chan));
282  ast_string_field_set(snapshot, type, ast_channel_tech(chan)->type);
287 
288  snapshot->creationtime = ast_channel_creationtime(chan);
289  snapshot->tech_properties = ast_channel_tech(chan)->properties;
290 
291  return snapshot;
292 }
static const char type[]
Definition: chan_ooh323.c:109
static char accountcode[AST_MAX_ACCOUNT_CODE]
Definition: chan_iax2.c:428
static void channel_snapshot_base_dtor(void *obj)
const ast_string_field uniqueid
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define NULL
Definition: resample.c:96
const char * ast_channel_accountcode(const struct ast_channel *chan)
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static char language[MAX_LANGUAGE]
Definition: chan_alsa.c:117
const char * ast_channel_uniqueid(const struct ast_channel *chan)
const char * ast_channel_userfield(const struct ast_channel *chan)
Structure containing base information for a channel snapshot.
struct timeval ast_channel_creationtime(struct ast_channel *chan)
const ast_string_field userfield
static const char name[]
Definition: cdr_mysql.c:74
const char * ast_channel_name(const 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)
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ channel_snapshot_base_dtor()

static void channel_snapshot_base_dtor ( void *  obj)
static

Definition at line 259 of file stasis_channels.c.

References ast_string_field_free_memory.

Referenced by channel_snapshot_base_create().

260 {
261  struct ast_channel_snapshot_base *snapshot = obj;
262 
264 }
Structure containing base information for a channel snapshot.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368

◆ channel_snapshot_bridge_create()

static struct ast_channel_snapshot_bridge* channel_snapshot_bridge_create ( struct ast_channel chan)
static

Definition at line 378 of file stasis_channels.c.

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

379 {
380  const char *uniqueid = "";
381  struct ast_bridge *bridge;
382  struct ast_channel_snapshot_bridge *snapshot;
383 
384  bridge = ast_channel_get_bridge(chan);
385  if (bridge && !ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) {
386  uniqueid = bridge->uniqueid;
387  }
388  ao2_cleanup(bridge);
389 
390  snapshot = ao2_alloc_options(sizeof(*snapshot) + strlen(uniqueid) + 1, NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
391  if (!snapshot) {
392  return NULL;
393  }
394 
395  strcpy(snapshot->id, uniqueid); /* Safe */
396 
397  return snapshot;
398 }
struct ast_flags feature_flags
Definition: bridge.h:377
const ast_string_field uniqueid
Definition: bridge.h:409
#define ast_test_flag(p, flag)
Definition: utils.h:63
const ast_string_field uniqueid
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define NULL
Definition: resample.c:96
struct ast_bridge * ast_channel_get_bridge(const struct ast_channel *chan)
Get the bridge associated with a channel.
Definition: channel.c:10735
Structure that contains information about a bridge.
Definition: bridge.h:357
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Structure containing bridge information for a channel snapshot.

◆ channel_snapshot_caller_create()

static struct ast_channel_snapshot_caller* channel_snapshot_caller_create ( struct ast_channel chan)
static

Definition at line 321 of file stasis_channels.c.

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

322 {
323  struct ast_channel_snapshot_caller *snapshot;
324 
325  snapshot = ao2_alloc_options(sizeof(*snapshot), channel_snapshot_caller_dtor,
327  if (!snapshot) {
328  return NULL;
329  }
330 
331  if (ast_string_field_init(snapshot, 256)) {
332  ao2_ref(snapshot, -1);
333  return NULL;
334  }
335 
336  ast_string_field_set(snapshot, name,
337  S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, ""));
338  ast_string_field_set(snapshot, number,
339  S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, ""));
340  ast_string_field_set(snapshot, subaddr,
341  S_COR(ast_channel_caller(chan)->id.subaddress.valid, ast_channel_caller(chan)->id.subaddress.str, ""));
342  ast_string_field_set(snapshot, ani,
343  S_COR(ast_channel_caller(chan)->ani.number.valid, ast_channel_caller(chan)->ani.number.str, ""));
344 
345  ast_string_field_set(snapshot, rdnis,
346  S_COR(ast_channel_redirecting(chan)->from.number.valid, ast_channel_redirecting(chan)->from.number.str, ""));
347 
348  ast_string_field_set(snapshot, dnid,
349  S_OR(ast_channel_dialed(chan)->number.str, ""));
351  S_COR(ast_channel_dialed(chan)->subaddress.valid, ast_channel_dialed(chan)->subaddress.str, ""));
352 
353  snapshot->pres = ast_party_id_presentation(&ast_channel_caller(chan)->id);
354 
355  return snapshot;
356 }
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
char * str
Subscriber phone number (Malloced)
Definition: channel.h:387
const ast_string_field rdnis
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
Definition: channel.c:1821
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define NULL
Definition: resample.c:96
Number structure.
Definition: app_followme.c:154
const ast_string_field dialed_subaddr
static void channel_snapshot_caller_dtor(void *obj)
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#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:85
const ast_string_field subaddr
const ast_string_field dnid
Structure containing caller information for a channel snapshot.
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
static const char name[]
Definition: cdr_mysql.c:74
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
const ast_string_field ani
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ channel_snapshot_caller_dtor()

static void channel_snapshot_caller_dtor ( void *  obj)
static

Definition at line 314 of file stasis_channels.c.

References ast_string_field_free_memory.

Referenced by channel_snapshot_caller_create().

315 {
316  struct ast_channel_snapshot_caller *snapshot = obj;
317 
319 }
Structure containing caller information for a channel snapshot.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368

◆ channel_snapshot_cmp_cb()

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

Definition at line 165 of file stasis_channels.c.

References ast_channel_snapshot::base, CMP_MATCH, 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().

166 {
167  const struct ast_channel_snapshot *object_left = obj;
168  const struct ast_channel_snapshot *object_right = arg;
169  const char *right_key = arg;
170  int cmp;
171 
172  switch (flags & OBJ_SEARCH_MASK) {
173  case OBJ_SEARCH_OBJECT:
174  right_key = object_right->base->name;
175  case OBJ_SEARCH_KEY:
176  cmp = strcasecmp(object_left->base->name, right_key);
177  break;
179  cmp = strncasecmp(object_left->base->name, right_key, strlen(right_key));
180  break;
181  default:
182  cmp = 0;
183  break;
184  }
185  if (cmp) {
186  return 0;
187  }
188  return CMP_MATCH;
189 }
struct ast_channel_snapshot_base * base
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
Structure representing a snapshot of channel state.
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1120
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
struct ast_flags flags
Search option field mask.
Definition: astobj2.h:1076
const ast_string_field name

◆ channel_snapshot_connected_create()

static struct ast_channel_snapshot_connected* channel_snapshot_connected_create ( struct ast_channel chan)
static

Definition at line 358 of file stasis_channels.c.

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

Referenced by ast_channel_snapshot_create().

359 {
360  const char *name = S_COR(ast_channel_connected(chan)->id.name.valid, ast_channel_connected(chan)->id.name.str, "");
361  const char *number = S_COR(ast_channel_connected(chan)->id.number.valid, ast_channel_connected(chan)->id.number.str, "");
362  size_t name_len = strlen(name) + 1;
363  size_t number_len = strlen(number) + 1;
364  struct ast_channel_snapshot_connected *snapshot;
365 
366  snapshot = ao2_alloc_options(sizeof(*snapshot) + name_len + number_len, NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
367  if (!snapshot) {
368  return NULL;
369  }
370 
371  strcpy(snapshot->name, name); /* Safe */
372  snapshot->number = snapshot->name + name_len;
373  ast_copy_string(snapshot->number, number, number_len); /* Safe */
374 
375  return snapshot;
376 }
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
Structure containing connected information for a channel snapshot.
#define NULL
Definition: resample.c:96
Number structure.
Definition: app_followme.c:154
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
#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:85
static const char name[]
Definition: cdr_mysql.c:74
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ channel_snapshot_dialplan_create()

static struct ast_channel_snapshot_dialplan* channel_snapshot_dialplan_create ( struct ast_channel chan)
static

Definition at line 407 of file stasis_channels.c.

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(), context, ast_channel_snapshot_dialplan::data, exten, NULL, and ast_channel_snapshot_dialplan::priority.

Referenced by ast_channel_snapshot_create().

408 {
409  struct ast_channel_snapshot_dialplan *snapshot;
410 
411  snapshot = ao2_alloc_options(sizeof(*snapshot), channel_snapshot_dialplan_dtor,
413  if (!snapshot) {
414  return NULL;
415  }
416 
417  if (ast_string_field_init(snapshot, 256)) {
418  ao2_ref(snapshot, -1);
419  return NULL;
420  }
421 
422  if (ast_channel_appl(chan)) {
423  ast_string_field_set(snapshot, appl, ast_channel_appl(chan));
424  }
425  if (ast_channel_data(chan)) {
426  ast_string_field_set(snapshot, data, ast_channel_data(chan));
427  }
429  ast_string_field_set(snapshot, exten, ast_channel_exten(chan));
430  snapshot->priority = ast_channel_priority(chan);
431 
432  return snapshot;
433 }
const ast_string_field data
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
static void channel_snapshot_dialplan_dtor(void *obj)
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define NULL
Definition: resample.c:96
int ast_channel_priority(const struct ast_channel *chan)
const ast_string_field appl
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
#define ao2_ref(o, delta)
Definition: astobj2.h:464
Structure containing dialplan information for a channel snapshot.
const char * ast_channel_exten(const struct ast_channel *chan)
const char * ast_channel_appl(const struct ast_channel *chan)
const char * ast_channel_data(const struct ast_channel *chan)
const char * ast_channel_context(const struct ast_channel *chan)
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ channel_snapshot_dialplan_dtor()

static void channel_snapshot_dialplan_dtor ( void *  obj)
static

Definition at line 400 of file stasis_channels.c.

References ast_string_field_free_memory.

Referenced by channel_snapshot_dialplan_create().

401 {
402  struct ast_channel_snapshot_dialplan *snapshot = obj;
403 
405 }
Structure containing dialplan information for a channel snapshot.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368

◆ channel_snapshot_dtor()

static void channel_snapshot_dtor ( void *  obj)
static

Definition at line 244 of file stasis_channels.c.

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

245 {
246  struct ast_channel_snapshot *snapshot = obj;
247 
248  ao2_cleanup(snapshot->base);
249  ao2_cleanup(snapshot->peer);
250  ao2_cleanup(snapshot->caller);
251  ao2_cleanup(snapshot->connected);
252  ao2_cleanup(snapshot->bridge);
253  ao2_cleanup(snapshot->dialplan);
254  ao2_cleanup(snapshot->hangup);
255  ao2_cleanup(snapshot->manager_vars);
256  ao2_cleanup(snapshot->ari_vars);
257 }
struct ast_channel_snapshot_base * base
Structure representing a snapshot of channel state.
struct ast_channel_snapshot_dialplan * dialplan
struct varshead * ari_vars
struct ast_channel_snapshot_hangup * hangup
struct ast_channel_snapshot_caller * caller
struct varshead * manager_vars
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_channel_snapshot_bridge * bridge
struct ast_channel_snapshot_peer * peer
struct ast_channel_snapshot_connected * connected

◆ channel_snapshot_hangup_create()

static struct ast_channel_snapshot_hangup* channel_snapshot_hangup_create ( struct ast_channel chan)
static

Definition at line 435 of file stasis_channels.c.

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

436 {
437  const char *hangupsource = S_OR(ast_channel_hangupsource(chan), "");
438  struct ast_channel_snapshot_hangup *snapshot;
439 
440  snapshot = ao2_alloc_options(sizeof(*snapshot) + strlen(hangupsource) + 1, NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
441  if (!snapshot) {
442  return NULL;
443  }
444 
445  snapshot->cause = ast_channel_hangupcause(chan);
446  strcpy(snapshot->source, hangupsource); /* Safe */
447 
448  return snapshot;
449 }
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define NULL
Definition: resample.c:96
Structure containing hangup information for a channel snapshot.
const char * ast_channel_hangupsource(const struct ast_channel *chan)
int ast_channel_hangupcause(const 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:79

◆ channel_snapshot_hash_cb()

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

Definition at line 142 of file stasis_channels.c.

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

Referenced by ast_multi_channel_blob_get_channels(), and ast_stasis_channels_init().

143 {
144  const struct ast_channel_snapshot *object = obj;
145  const char *key;
146 
147  switch (flags & OBJ_SEARCH_MASK) {
148  case OBJ_SEARCH_KEY:
149  key = obj;
150  break;
151  case OBJ_SEARCH_OBJECT:
152  key = object->base->name;
153  break;
154  default:
155  ast_assert(0);
156  return 0;
157  }
158  return ast_str_case_hash(key);
159 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
Structure representing a snapshot of channel state.
#define ast_assert(a)
Definition: utils.h:695
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
struct ast_flags flags
Search option field mask.
Definition: astobj2.h:1076
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:1250

◆ channel_snapshot_peer_create()

static struct ast_channel_snapshot_peer* channel_snapshot_peer_create ( struct ast_channel chan)
static

Definition at line 294 of file stasis_channels.c.

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

295 {
296  const char *linkedid = S_OR(ast_channel_linkedid(chan), "");
297  const char *peeraccount = S_OR(ast_channel_peeraccount(chan), "");
298  size_t linkedid_len = strlen(linkedid) + 1;
299  size_t peeraccount_len = strlen(peeraccount) + 1;
300  struct ast_channel_snapshot_peer *snapshot;
301 
302  snapshot = ao2_alloc_options(sizeof(*snapshot) + linkedid_len + peeraccount_len, NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
303  if (!snapshot) {
304  return NULL;
305  }
306 
307  strcpy(snapshot->account, peeraccount); /* Safe */
308  snapshot->linkedid = snapshot->account + peeraccount_len;
309  ast_copy_string(snapshot->linkedid, linkedid, linkedid_len); /* Safe */
310 
311  return snapshot;
312 }
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define NULL
Definition: resample.c:96
const char * ast_channel_linkedid(const struct ast_channel *chan)
Structure containing peer information for a channel snapshot.
const char * ast_channel_peeraccount(const 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:401
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79

◆ channel_snapshot_uniqueid_cmp_cb()

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

Definition at line 218 of file stasis_channels.c.

References ast_channel_snapshot::base, CMP_MATCH, 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().

219 {
220  const struct ast_channel_snapshot *object_left = obj;
221  const struct ast_channel_snapshot *object_right = arg;
222  const char *right_key = arg;
223  int cmp;
224 
225  switch (flags & OBJ_SEARCH_MASK) {
226  case OBJ_SEARCH_OBJECT:
227  right_key = object_right->base->uniqueid;
228  case OBJ_SEARCH_KEY:
229  cmp = strcasecmp(object_left->base->uniqueid, right_key);
230  break;
232  cmp = strncasecmp(object_left->base->uniqueid, right_key, strlen(right_key));
233  break;
234  default:
235  cmp = 0;
236  break;
237  }
238  if (cmp) {
239  return 0;
240  }
241  return CMP_MATCH;
242 }
struct ast_channel_snapshot_base * base
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
Structure representing a snapshot of channel state.
const ast_string_field uniqueid
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1120
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
struct ast_flags flags
Search option field mask.
Definition: astobj2.h:1076

◆ channel_snapshot_uniqueid_hash_cb()

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

Definition at line 195 of file stasis_channels.c.

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

Referenced by ast_stasis_channels_init().

196 {
197  const struct ast_channel_snapshot *object = obj;
198  const char *key;
199 
200  switch (flags & OBJ_SEARCH_MASK) {
201  case OBJ_SEARCH_KEY:
202  key = obj;
203  break;
204  case OBJ_SEARCH_OBJECT:
205  key = object->base->uniqueid;
206  break;
207  default:
208  ast_assert(0);
209  return 0;
210  }
211  return ast_str_case_hash(key);
212 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
Structure representing a snapshot of channel state.
#define ast_assert(a)
Definition: utils.h:695
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
struct ast_flags flags
Search option field mask.
Definition: astobj2.h:1076
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:1250

◆ channel_snapshot_update_create()

static struct ast_channel_snapshot_update* channel_snapshot_update_create ( struct ast_channel chan)
static

Definition at line 566 of file stasis_channels.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_bump, ao2_ref, ast_channel_snapshot(), ast_channel_snapshot_create(), channel_snapshot_update_dtor(), ast_channel_snapshot_update::new_snapshot, NULL, ast_channel_snapshot_update::old_snapshot, and update().

Referenced by ast_channel_publish_final_snapshot(), and ast_channel_publish_snapshot().

567 {
569 
570  update = ao2_alloc_options(sizeof(*update), channel_snapshot_update_dtor,
572  if (!update) {
573  return NULL;
574  }
575 
576  update->old_snapshot = ao2_bump(ast_channel_snapshot(chan));
578  if (!update->new_snapshot) {
579  ao2_ref(update, -1);
580  return NULL;
581  }
582 
583  return update;
584 }
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
struct ast_channel_snapshot * ast_channel_snapshot(const struct ast_channel *chan)
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define NULL
Definition: resample.c:96
Structure representing a change of snapshot of channel state.
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...
#define ao2_bump(obj)
Definition: astobj2.h:491
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static void channel_snapshot_update_dtor(void *obj)
struct ast_channel_snapshot * new_snapshot
struct ast_channel_snapshot * old_snapshot

◆ channel_snapshot_update_dtor()

static void channel_snapshot_update_dtor ( void *  obj)
static

Definition at line 558 of file stasis_channels.c.

References ao2_cleanup, ast_channel_snapshot_update::new_snapshot, ast_channel_snapshot_update::old_snapshot, and update().

Referenced by channel_snapshot_update_create().

559 {
560  struct ast_channel_snapshot_update *update = obj;
561 
562  ao2_cleanup(update->old_snapshot);
563  ao2_cleanup(update->new_snapshot);
564 }
static void update(int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, struct g726_state *state_ptr)
Definition: codec_g726.c:367
Structure representing a change of snapshot of channel state.
struct ast_channel_snapshot * new_snapshot
struct ast_channel_snapshot * old_snapshot
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ 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 745 of file stasis_channels.c.

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, and stasis_message_create().

Referenced by ast_channel_blob_create(), and ast_channel_blob_create_from_cache().

748 {
749  struct stasis_message *msg;
750  struct ast_channel_blob *obj;
751 
752  obj = ao2_alloc(sizeof(*obj), channel_blob_dtor);
753  if (!obj) {
754  return NULL;
755  }
756 
757  if (snapshot) {
758  obj->snapshot = snapshot;
759  ao2_ref(obj->snapshot, +1);
760  }
761  if (!blob) {
762  blob = ast_json_null();
763  }
764  obj->blob = ast_json_ref(blob);
765 
766  msg = stasis_message_create(type, obj);
767  ao2_cleanup(obj);
768  return msg;
769 }
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
struct ast_json * blob
struct ast_channel_snapshot * snapshot
#define NULL
Definition: resample.c:96
Blob of data associated with a channel.
struct ast_json * ast_json_null(void)
Get the JSON null value.
Definition: json.c:248
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
static void channel_blob_dtor(void *obj)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ dial_masquerade_breakdown()

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

Definition at line 1882 of file stasis_channels.c.

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.

1883 {
1884  struct dial_masquerade_datastore *masq_data = data;
1885  struct dial_target *cur;
1886 
1887  ao2_lock(masq_data);
1888 
1889  if (!masq_data->caller) {
1890  ao2_unlock(masq_data);
1891  return;
1892  }
1893 
1894  if (masq_data->caller == new_chan) {
1895  /*
1896  * The caller channel is being masqueraded into.
1897  * The masquerade is likely because of a blonde transfer.
1898  */
1899  ast_debug(1, "Caller channel %s being masqueraded into by %s (is_empty:%d)\n",
1900  ast_channel_name(old_chan), ast_channel_name(new_chan),
1901  AST_LIST_EMPTY(&masq_data->dialed_peers));
1902  AST_LIST_TRAVERSE(&masq_data->dialed_peers, cur, list) {
1904  cur->dialstring, "NOANSWER", NULL);
1906  cur->dialstring, NULL, NULL);
1907  }
1908 
1909  ao2_unlock(masq_data);
1910  return;
1911  }
1912 
1913  /*
1914  * One of the peer channels is being masqueraded into.
1915  * The masquerade is likely because of a call pickup.
1916  */
1917  AST_LIST_TRAVERSE(&masq_data->dialed_peers, cur, list) {
1918  if (cur->peer == new_chan) {
1919  ast_debug(1, "Peer channel %s being masqueraded into by %s\n",
1920  ast_channel_name(old_chan), ast_channel_name(new_chan));
1921  ast_channel_publish_dial_internal(masq_data->caller, old_chan, NULL,
1922  cur->dialstring, "CANCEL", NULL);
1923  ast_channel_publish_dial_internal(masq_data->caller, new_chan, NULL,
1924  cur->dialstring, NULL, NULL);
1925  break;
1926  }
1927  }
1928 
1929  ao2_unlock(masq_data);
1930 }
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 dial_masquerade_datastore::@422 dialed_peers
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ao2_lock(a)
Definition: astobj2.h:718
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct dial_target::@421 list
const char * ast_channel_name(const struct ast_channel *chan)
struct ast_channel * caller
struct ast_channel * peer

◆ dial_masquerade_caller_datastore_destroy()

static void dial_masquerade_caller_datastore_destroy ( void *  data)
static

Definition at line 1815 of file stasis_channels.c.

References ao2_ref, dial_masquerade_datastore_cleanup(), and dial_masquerade_datastore_find().

1816 {
1818  ao2_ref(data, -1);
1819 }
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static void dial_masquerade_datastore_cleanup(struct dial_masquerade_datastore *masq_data)

◆ 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 1977 of file stasis_channels.c.

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

Referenced by set_dial_masquerade().

1979 {
1980  struct ast_datastore *datastore;
1981 
1983  if (!datastore) {
1984  return NULL;
1985  }
1986 
1987  if (!masq_data) {
1988  masq_data = dial_masquerade_datastore_alloc();
1989  if (!masq_data) {
1990  ast_datastore_free(datastore);
1991  return NULL;
1992  }
1993  masq_data->caller = chan;
1994  }
1995 
1996  datastore->data = masq_data;
1997  ast_channel_datastore_add(chan, datastore);
1998 
1999  return masq_data;
2000 }
static struct dial_masquerade_datastore * dial_masquerade_datastore_alloc(void)
Structure for a data store object.
Definition: datastore.h:68
#define NULL
Definition: resample.c:96
static const struct ast_datastore_info dial_masquerade_info
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
void * data
Definition: datastore.h:70
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:89
struct ast_channel * caller
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2390

◆ dial_masquerade_datastore_alloc()

static struct dial_masquerade_datastore* dial_masquerade_datastore_alloc ( void  )
static

Definition at line 1789 of file stasis_channels.c.

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

1790 {
1791  struct dial_masquerade_datastore *masq_data;
1792 
1793  masq_data = ao2_alloc(sizeof(struct dial_masquerade_datastore),
1795  if (!masq_data) {
1796  return NULL;
1797  }
1799  return masq_data;
1800 }
struct dial_masquerade_datastore::@422 dialed_peers
#define NULL
Definition: resample.c:96
static void dial_masquerade_datastore_dtor(void *vdoomed)
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:680

◆ dial_masquerade_datastore_cleanup()

static void dial_masquerade_datastore_cleanup ( struct dial_masquerade_datastore masq_data)
static

Definition at line 1755 of file stasis_channels.c.

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

1756 {
1757  struct dial_target *cur;
1758 
1759  while ((cur = AST_LIST_REMOVE_HEAD(&masq_data->dialed_peers, list))) {
1760  dial_target_free(cur);
1761  }
1762 }
struct dial_masquerade_datastore::@422 dialed_peers
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
struct dial_target::@421 list
static void dial_target_free(struct dial_target *doomed)

◆ dial_masquerade_datastore_destroy()

static void dial_masquerade_datastore_destroy ( void *  data)
static

Definition at line 1806 of file stasis_channels.c.

References ao2_ref.

1807 {
1808  ao2_ref(data, -1);
1809 }
#define ao2_ref(o, delta)
Definition: astobj2.h:464

◆ dial_masquerade_datastore_dtor()

static void dial_masquerade_datastore_dtor ( void *  vdoomed)
static

Definition at line 1784 of file stasis_channels.c.

References dial_masquerade_datastore_cleanup().

Referenced by dial_masquerade_datastore_alloc().

1785 {
1787 }
static void dial_masquerade_datastore_cleanup(struct dial_masquerade_datastore *masq_data)

◆ dial_masquerade_datastore_find()

static struct ast_datastore * dial_masquerade_datastore_find ( struct ast_channel chan)
static

Definition at line 1954 of file stasis_channels.c.

References ast_channel_datastore_find(), and NULL.

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

1955 {
1956  struct ast_datastore *datastore;
1957 
1959  if (!datastore) {
1961  }
1962 
1963  return datastore;
1964 }
Structure for a data store object.
Definition: datastore.h:68
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2404
#define NULL
Definition: resample.c:96
static const struct ast_datastore_info dial_masquerade_info
static const struct ast_datastore_info dial_masquerade_caller_info

◆ 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 1764 of file stasis_channels.c.

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

1765 {
1766  struct dial_target *cur;
1767 
1768  ao2_lock(masq_data);
1769  if (masq_data->caller == chan) {
1771  } else {
1772  AST_LIST_TRAVERSE_SAFE_BEGIN(&masq_data->dialed_peers, cur, list) {
1773  if (cur->peer == chan) {
1775  dial_target_free(cur);
1776  break;
1777  }
1778  }
1780  }
1781  ao2_unlock(masq_data);
1782 }
struct dial_masquerade_datastore::@422 dialed_peers
#define ao2_unlock(a)
Definition: astobj2.h:730
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
#define ao2_lock(a)
Definition: astobj2.h:718
static void dial_masquerade_datastore_cleanup(struct dial_masquerade_datastore *masq_data)
struct dial_target::@421 list
static void dial_target_free(struct dial_target *doomed)
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
struct ast_channel * caller
struct ast_channel * peer

◆ dial_masquerade_fixup()

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

Definition at line 1823 of file stasis_channels.c.

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.

1824 {
1825  struct dial_masquerade_datastore *masq_data = data;
1826  struct dial_target *cur;
1827  struct ast_datastore *datastore;
1828 
1829  ao2_lock(masq_data);
1830  if (!masq_data->caller) {
1831  /* Nothing to do but remove the datastore */
1832  } else if (masq_data->caller == old_chan) {
1833  /* The caller channel is being masqueraded out. */
1834  ast_debug(1, "Caller channel %s being masqueraded out to %s (is_empty:%d)\n",
1835  ast_channel_name(new_chan), ast_channel_name(old_chan),
1836  AST_LIST_EMPTY(&masq_data->dialed_peers));
1837  AST_LIST_TRAVERSE(&masq_data->dialed_peers, cur, list) {
1839  cur->dialstring, "NOANSWER", NULL);
1841  cur->dialstring, NULL, NULL);
1842  }
1844  } else {
1845  /* One of the peer channels is being masqueraded out. */
1846  AST_LIST_TRAVERSE_SAFE_BEGIN(&masq_data->dialed_peers, cur, list) {
1847  if (cur->peer == old_chan) {
1848  ast_debug(1, "Peer channel %s being masqueraded out to %s\n",
1849  ast_channel_name(new_chan), ast_channel_name(old_chan));
1850  ast_channel_publish_dial_internal(masq_data->caller, new_chan, NULL,
1851  cur->dialstring, "CANCEL", NULL);
1852  ast_channel_publish_dial_internal(masq_data->caller, old_chan, NULL,
1853  cur->dialstring, NULL, NULL);
1854 
1856  dial_target_free(cur);
1857  break;
1858  }
1859  }
1861  }
1862  ao2_unlock(masq_data);
1863 
1864  /* Remove the datastore from the channel. */
1865  datastore = dial_masquerade_datastore_find(old_chan);
1866  if (!datastore) {
1867  return;
1868  }
1869  ast_channel_datastore_remove(old_chan, datastore);
1870  ast_datastore_free(datastore);
1871 }
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 dial_masquerade_datastore::@422 dialed_peers
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
#define ao2_unlock(a)
Definition: astobj2.h:730
Structure for a data store object.
Definition: datastore.h:68
#define NULL
Definition: resample.c:96
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
#define ao2_lock(a)
Definition: astobj2.h:718
static void dial_masquerade_datastore_cleanup(struct dial_masquerade_datastore *masq_data)
static struct ast_datastore * dial_masquerade_datastore_find(struct ast_channel *chan)
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
const char * ast_channel_name(const struct ast_channel *chan)
static void dial_target_free(struct dial_target *doomed)
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
struct ast_channel * caller
struct ast_channel * peer
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition: channel.c:2399

◆ dial_target_free()

static void dial_target_free ( struct dial_target doomed)
static

Definition at line 1733 of file stasis_channels.c.

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

1734 {
1735  if (!doomed) {
1736  return;
1737  }
1738  ast_free(doomed->dialstring);
1739  ast_channel_cleanup(doomed->peer);
1740  ast_free(doomed);
1741 }
#define ast_channel_cleanup(c)
Cleanup a channel reference.
Definition: channel.h:2992
#define ast_free(a)
Definition: astmm.h:182
struct ast_channel * peer

◆ dial_to_json()

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

Definition at line 1433 of file stasis_channels.c.

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

Referenced by unhold_to_json().

1436 {
1437  struct ast_multi_channel_blob *payload = stasis_message_data(message);
1438  struct ast_json *blob = ast_multi_channel_blob_get_json(payload);
1439  const char *dialstatus =
1440  ast_json_string_get(ast_json_object_get(blob, "dialstatus"));
1441  const char *forward =
1442  ast_json_string_get(ast_json_object_get(blob, "forward"));
1443  const char *dialstring =
1444  ast_json_string_get(ast_json_object_get(blob, "dialstring"));
1445  struct ast_json *caller_json = ast_channel_snapshot_to_json(ast_multi_channel_blob_get_channel(payload, "caller"), sanitize);
1446  struct ast_json *peer_json = ast_channel_snapshot_to_json(ast_multi_channel_blob_get_channel(payload, "peer"), sanitize);
1447  struct ast_json *forwarded_json = ast_channel_snapshot_to_json(ast_multi_channel_blob_get_channel(payload, "forwarded"), sanitize);
1448  struct ast_json *json;
1449  const struct timeval *tv = stasis_message_timestamp(message);
1450  int res = 0;
1451 
1452  json = ast_json_pack("{s: s, s: o, s: s, s: s, s: s}",
1453  "type", "Dial",
1454  "timestamp", ast_json_timeval(*tv, NULL),
1455  "dialstatus", dialstatus,
1456  "forward", forward,
1457  "dialstring", dialstring);
1458  if (!json) {
1459  ast_json_unref(caller_json);
1460  ast_json_unref(peer_json);
1461  ast_json_unref(forwarded_json);
1462  return NULL;
1463  }
1464 
1465  if (caller_json) {
1466  res |= ast_json_object_set(json, "caller", caller_json);
1467  }
1468  if (peer_json) {
1469  res |= ast_json_object_set(json, "peer", peer_json);
1470  }
1471  if (forwarded_json) {
1472  res |= ast_json_object_set(json, "forwarded", forwarded_json);
1473  }
1474 
1475  if (res) {
1476  ast_json_unref(json);
1477  return NULL;
1478  }
1479 
1480  return json;
1481 }
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
#define NULL
Definition: resample.c:96
struct ast_json * ast_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...
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition: json.c:404
const struct timeval * stasis_message_timestamp(const struct stasis_message *msg)
Get the time when a message was created.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
Definition: json.c:649
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:397
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.
A multi channel blob data structure for multi_channel_blob stasis messages.
Abstract JSON element (object, array, string, int, ...).
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.

◆ 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 1385 of file stasis_channels.c.

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, channel_role_snapshot::snapshot, stasis_message_data(), and stasis_message_timestamp().

Referenced by unhold_to_json().

1388 {
1389  struct ast_channel_blob *channel_blob = stasis_message_data(message);
1390  struct ast_json *blob = channel_blob->blob;
1391  struct ast_channel_snapshot *snapshot = channel_blob->snapshot;
1392  const char *direction =
1393  ast_json_string_get(ast_json_object_get(blob, "direction"));
1394  const char *digit =
1395  ast_json_string_get(ast_json_object_get(blob, "digit"));
1396  long duration_ms =
1397  ast_json_integer_get(ast_json_object_get(blob, "duration_ms"));
1398  const struct timeval *tv = stasis_message_timestamp(message);
1399  struct ast_json *json_channel;
1400 
1401  /* Only present received DTMF end events as JSON */
1402  if (strcasecmp("Received", direction) != 0) {
1403  return NULL;
1404  }
1405 
1406  json_channel = ast_channel_snapshot_to_json(snapshot, sanitize);
1407  if (!json_channel) {
1408  return NULL;
1409  }
1410 
1411  return ast_json_pack("{s: s, s: o, s: s, s: I, s: o}",
1412  "type", "ChannelDtmfReceived",
1413  "timestamp", ast_json_timeval(*tv, NULL),
1414  "digit", digit,
1415  "duration_ms", (ast_json_int_t)duration_ms,
1416  "channel", json_channel);
1417 }
char digit
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
struct ast_json * blob
struct ast_channel_snapshot * snapshot
AST_JSON_INT_T ast_json_int_t
Primarily used to cast when packing to an "I" type.
Definition: json.h:87
Structure representing a snapshot of channel state.
#define NULL
Definition: resample.c:96
Blob of data associated with a channel.
const struct timeval * stasis_message_timestamp(const struct stasis_message *msg)
Get the time when a message was created.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
Definition: json.c:649
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:397
Abstract JSON element (object, array, string, int, ...).
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.
direction
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
Definition: json.c:322

◆ 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 1426 of file stasis_channels.c.

References channel_blob_to_json().

Referenced by unhold_to_json().

1429 {
1430  return channel_blob_to_json(message, "ChannelHangupRequest", sanitize);
1431 }
static struct ast_json * channel_blob_to_json(struct stasis_message *message, const char *type, const struct stasis_message_sanitizer *sanitize)

◆ hold_to_json()

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

Definition at line 1535 of file stasis_channels.c.

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

Referenced by unhold_to_json().

1537 {
1538  struct ast_channel_blob *channel_blob = stasis_message_data(message);
1539  struct ast_json *blob = channel_blob->blob;
1540  struct ast_channel_snapshot *snapshot = channel_blob->snapshot;
1541  const char *musicclass = ast_json_string_get(ast_json_object_get(blob, "musicclass"));
1542  const struct timeval *tv = stasis_message_timestamp(message);
1543  struct ast_json *json_channel;
1544 
1545  json_channel = ast_channel_snapshot_to_json(snapshot, sanitize);
1546  if (!json_channel) {
1547  return NULL;
1548  }
1549 
1550  return ast_json_pack("{s: s, s: o, s: s, s: o}",
1551  "type", "ChannelHold",
1552  "timestamp", ast_json_timeval(*tv, NULL),
1553  "musicclass", S_OR(musicclass, "N/A"),
1554  "channel", json_channel);
1555 }
static char musicclass[MAX_MUSICCLASS]
Definition: chan_mgcp.c:162
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
struct ast_json * blob
struct ast_channel_snapshot * snapshot
Structure representing a snapshot of channel state.
#define NULL
Definition: resample.c:96
Blob of data associated with a channel.
const struct timeval * stasis_message_timestamp(const struct stasis_message *msg)
Get the time when a message was created.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
Definition: json.c:649
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:397
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
Abstract JSON element (object, array, string, int, ...).
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.

◆ multi_channel_blob_dtor()

static void multi_channel_blob_dtor ( void *  obj)
static

Definition at line 873 of file stasis_channels.c.

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

874 {
875  struct ast_multi_channel_blob *multi_blob = obj;
876 
877  ao2_cleanup(multi_blob->channel_snapshots);
878  ast_json_unref(multi_blob->blob);
879 }
struct ast_json * blob
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
struct ao2_container * channel_snapshots
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
A multi channel blob data structure for multi_channel_blob stasis messages.

◆ publish_message_for_channel_topics()

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

Definition at line 586 of file stasis_channels.c.

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

Referenced by ast_channel_publish_dial_internal().

587 {
588  if (chan) {
589  stasis_publish(ast_channel_topic(chan), message);
590  } else {
592  }
593 }
struct stasis_topic * ast_channel_topic_all(void)
A topic which publishes the events for all channels.
struct stasis_topic * ast_channel_topic(struct ast_channel *chan)
A topic which publishes the events for a particular channel.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic&#39;s subscribers.
Definition: stasis.c:1511

◆ remove_dial_masquerade()

static void remove_dial_masquerade ( struct ast_channel peer)
static

Definition at line 2081 of file stasis_channels.c.

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(), and ast_channel_publish_dial_internal().

2082 {
2083  struct ast_datastore *datastore;
2084  struct dial_masquerade_datastore *masq_data;
2085 
2086  datastore = dial_masquerade_datastore_find(peer);
2087  if (!datastore) {
2088  return;
2089  }
2090 
2091  masq_data = datastore->data;
2092  if (masq_data) {
2093  dial_masquerade_datastore_remove_chan(masq_data, peer);
2094  }
2095 
2096  ast_channel_datastore_remove(peer, datastore);
2097  ast_datastore_free(datastore);
2098 }
Structure for a data store object.
Definition: datastore.h:68
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
static void dial_masquerade_datastore_remove_chan(struct dial_masquerade_datastore *masq_data, struct ast_channel *chan)
static struct ast_datastore * dial_masquerade_datastore_find(struct ast_channel *chan)
void * data
Definition: datastore.h:70
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition: channel.c:2399

◆ remove_dial_masquerade_caller()

static void remove_dial_masquerade_caller ( struct ast_channel caller)
static

Definition at line 2100 of file stasis_channels.c.

References ast_channel_datastore_remove(), ast_datastore_free(), AST_LIST_EMPTY, 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(), and ast_channel_publish_dial_internal().

2101 {
2102  struct ast_datastore *datastore;
2103  struct dial_masquerade_datastore *masq_data;
2104 
2105  datastore = dial_masquerade_datastore_find(caller);
2106  if (!datastore) {
2107  return;
2108  }
2109 
2110  masq_data = datastore->data;
2111  if (!masq_data || !AST_LIST_EMPTY(&masq_data->dialed_peers)) {
2112  return;
2113  }
2114 
2115  dial_masquerade_datastore_remove_chan(masq_data, caller);
2116 
2117  ast_channel_datastore_remove(caller, datastore);
2118  ast_datastore_free(datastore);
2119 }
struct dial_masquerade_datastore::@422 dialed_peers
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
Structure for a data store object.
Definition: datastore.h:68
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
static void dial_masquerade_datastore_remove_chan(struct dial_masquerade_datastore *masq_data, struct ast_channel *chan)
static struct ast_datastore * dial_masquerade_datastore_find(struct ast_channel *chan)
void * data
Definition: datastore.h:70
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition: channel.c:2399

◆ set_dial_masquerade()

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

Definition at line 2002 of file stasis_channels.c.

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(), and ast_channel_publish_dial_internal().

2003 {
2004  struct ast_datastore *datastore;
2005  struct dial_masquerade_datastore *masq_data;
2006  struct dial_target *target;
2007 
2008  /* Find or create caller datastore */
2009  datastore = dial_masquerade_datastore_find(caller);
2010  if (!datastore) {
2011  masq_data = dial_masquerade_datastore_add(caller, NULL);
2012  } else {
2013  masq_data = datastore->data;
2014  }
2015  if (!masq_data) {
2016  return -1;
2017  }
2018  ao2_ref(masq_data, +1);
2019 
2020  /*
2021  * Someone likely forgot to do an ast_channel_publish_dial()
2022  * or ast_channel_publish_dial_forward() with a final dial
2023  * status on the channel.
2024  */
2025  ast_assert(masq_data->caller == caller);
2026 
2027  /* Create peer target to put into datastore */
2028  target = ast_calloc(1, sizeof(*target));
2029  if (!target) {
2030  ao2_ref(masq_data, -1);
2031  return -1;
2032  }
2033  if (dialstring) {
2034  target->dialstring = ast_strdup(dialstring);
2035  if (!target->dialstring) {
2036  ast_free(target);
2037  ao2_ref(masq_data, -1);
2038  return -1;
2039  }
2040  }
2041  target->peer = ast_channel_ref(peer);
2042 
2043  /* Put peer target into datastore */
2044  ao2_lock(masq_data);
2045  dial_masquerade_datastore_remove_chan(masq_data, peer);
2046  AST_LIST_INSERT_HEAD(&masq_data->dialed_peers, target, list);
2047  ao2_unlock(masq_data);
2048 
2049  datastore = dial_masquerade_datastore_find(peer);
2050  if (datastore) {
2051  if (datastore->data == masq_data) {
2052  /*
2053  * Peer already had the datastore for this dial masquerade.
2054  * This was a redundant peer dial masquerade setup.
2055  */
2056  ao2_ref(masq_data, -1);
2057  return 0;
2058  }
2059 
2060  /* Something is wrong. Try to fix if the assert doesn't abort. */
2061  ast_assert(0);
2062 
2063  /* Remove the stale dial masquerade datastore */
2064  dial_masquerade_datastore_remove_chan(datastore->data, peer);
2065  ast_channel_datastore_remove(peer, datastore);
2066  ast_datastore_free(datastore);
2067  }
2068 
2069  /* Create the peer dial masquerade datastore */
2070  if (dial_masquerade_datastore_add(peer, masq_data)) {
2071  /* Success */
2072  return 0;
2073  }
2074 
2075  /* Failed to create the peer datastore */
2076  dial_masquerade_datastore_remove_chan(masq_data, peer);
2077  ao2_ref(masq_data, -1);
2078  return -1;
2079 }
static struct dial_masquerade_datastore * dial_masquerade_datastore_add(struct ast_channel *chan, struct dial_masquerade_datastore *masq_data)
struct dial_masquerade_datastore::@422 dialed_peers
#define ast_assert(a)
Definition: utils.h:695
#define ao2_unlock(a)
Definition: astobj2.h:730
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
Structure for a data store object.
Definition: datastore.h:68
#define NULL
Definition: resample.c:96
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718
static void dial_masquerade_datastore_remove_chan(struct dial_masquerade_datastore *masq_data, struct ast_channel *chan)
static struct ast_datastore * dial_masquerade_datastore_find(struct ast_channel *chan)
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
void * data
Definition: datastore.h:70
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2970
struct dial_target::@421 list
struct ast_channel * caller
struct ast_channel * peer
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition: channel.c:2399

◆ stasis_channels_cleanup()

static void stasis_channels_cleanup ( void  )
static

Definition at line 1630 of file stasis_channels.c.

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_monitor_start_type(), ast_channel_monitor_stop_type(), ast_channel_snapshot_type(), ast_channel_talking_start(), ast_channel_talking_stop(), ast_channel_unhold_type(), ast_channel_varset_type(), NULL, and STASIS_MESSAGE_TYPE_CLEANUP.

Referenced by ast_stasis_channels_init().

1631 {
1635  channel_cache = NULL;
1638 
1664 }
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_stop(void)
Message type for a channel stopping talking.
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_unhold_type(void)
Message type for when a channel is removed from hold.
struct stasis_message_type * ast_channel_moh_start_type(void)
Message type for starting music on hold on a channel.
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
Definition: stasis.h:1523
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_varset_type(void)
Message type for when a variable is set on a channel.
struct stasis_message_type * ast_channel_chanspy_start_type(void)
Message type for when a channel starts spying on another channel.
#define NULL
Definition: resample.c:96
struct stasis_message_type * ast_channel_monitor_start_type(void)
Message type for starting monitor on a channel.
struct stasis_message_type * ast_channel_talking_start(void)
Message type for a channel starting talking.
struct stasis_message_type * ast_channel_monitor_stop_type(void)
Message type for stopping monitor on a channel.
static struct stasis_topic * channel_topic_all
struct stasis_message_type * ast_channel_agent_login_type(void)
Message type for agent login on a channel.
struct stasis_message_type * ast_channel_agent_logoff_type(void)
Message type for agent logoff on a channel.
static struct ao2_container * channel_cache_by_name
struct stasis_message_type * ast_channel_mixmonitor_start_type(void)
Message type for starting mixmonitor 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_hangup_handler_type(void)
Message type for hangup handler related actions.
struct stasis_message_type * ast_channel_snapshot_type(void)
Message type for ast_channel_snapshot_update.
struct stasis_message_type * ast_channel_dtmf_begin_type(void)
Message type for when DTMF begins on a channel.
static struct ao2_container * channel_cache
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct stasis_message_type * ast_channel_dial_type(void)
Message type for when a channel dials another 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_hangup_request_type(void)
Message type for when a hangup is requested 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_fax_type(void)
Message type for a fax operation.
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_mixmonitor_mute_type(void)
Message type for muting or unmuting mixmonitor on a channel.

◆ STASIS_MESSAGE_TYPE_DEFN() [1/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_snapshot_type  )

Define channel message types.

Referenced by unhold_to_json().

◆ STASIS_MESSAGE_TYPE_DEFN() [2/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_dial_type  ,
to_json = dial_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [3/25]

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

◆ STASIS_MESSAGE_TYPE_DEFN() [4/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_hangup_request_type  ,
to_json = hangup_request_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [5/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_masquerade_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [6/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_dtmf_begin_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [7/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_dtmf_end_type  ,
to_json = dtmf_end_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [8/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_hold_type  ,
to_json = hold_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [9/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_unhold_type  ,
to_json = unhold_to_json 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [10/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_flash_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [11/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_chanspy_start_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [12/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_chanspy_stop_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [13/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_fax_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [14/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_hangup_handler_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [15/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_moh_start_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [16/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_moh_stop_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [17/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_monitor_start_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [18/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_monitor_stop_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [19/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_mixmonitor_start_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [20/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_mixmonitor_stop_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [21/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_mixmonitor_mute_type  )

◆ STASIS_MESSAGE_TYPE_DEFN() [22/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_agent_login_type  ,
to_ami = agent_login_to_ami 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [23/25]

STASIS_MESSAGE_TYPE_DEFN ( ast_channel_agent_logoff_type  ,
to_ami = agent_logoff_to_ami 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [24/25]

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

◆ STASIS_MESSAGE_TYPE_DEFN() [25/25]

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

◆ talking_start_to_ami()

static struct ast_manager_event_blob* talking_start_to_ami ( struct stasis_message msg)
static

Definition at line 1483 of file stasis_channels.c.

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

Referenced by unhold_to_json().

1484 {
1485  struct ast_str *channel_string;
1486  struct ast_channel_blob *obj = stasis_message_data(msg);
1487  struct ast_manager_event_blob *blob;
1488 
1489  channel_string = ast_manager_build_channel_state_string(obj->snapshot);
1490  if (!channel_string) {
1491  return NULL;
1492  }
1493 
1494  blob = ast_manager_event_blob_create(EVENT_FLAG_CALL, "ChannelTalkingStart",
1495  "%s", ast_str_buffer(channel_string));
1496  ast_free(channel_string);
1497 
1498  return blob;
1499 }
Struct containing info for an AMI event to send out.
Definition: manager.h:491
struct ast_channel_snapshot * snapshot
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define EVENT_FLAG_CALL
Definition: manager.h:72
#define NULL
Definition: resample.c:96
struct ast_manager_event_blob * ast_manager_event_blob_create(int event_flags, const char *manager_event, const char *extra_fields_fmt,...)
Construct a ast_manager_event_blob.
Definition: manager.c:9727
Blob of data associated with a channel.
struct ast_str * ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
Generate the AMI message body from a channel snapshot.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#define ast_free(a)
Definition: astmm.h:182

◆ 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 1501 of file stasis_channels.c.

References channel_blob_to_json().

Referenced by unhold_to_json().

1503 {
1504  return channel_blob_to_json(message, "ChannelTalkingStarted", sanitize);
1505 }
static struct ast_json * channel_blob_to_json(struct stasis_message *message, const char *type, const struct stasis_message_sanitizer *sanitize)

◆ talking_stop_to_ami()

static struct ast_manager_event_blob* talking_stop_to_ami ( struct stasis_message msg)
static

Definition at line 1507 of file stasis_channels.c.

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

Referenced by unhold_to_json().

1508 {
1509  struct ast_str *channel_string;
1510  struct ast_channel_blob *obj = stasis_message_data(msg);
1511  int duration = ast_json_integer_get(ast_json_object_get(obj->blob, "duration"));
1512  struct ast_manager_event_blob *blob;
1513 
1514  channel_string = ast_manager_build_channel_state_string(obj->snapshot);
1515  if (!channel_string) {
1516  return NULL;
1517  }
1518 
1519  blob = ast_manager_event_blob_create(EVENT_FLAG_CALL, "ChannelTalkingStop",
1520  "%s"
1521  "Duration: %d\r\n",
1522  ast_str_buffer(channel_string),
1523  duration);
1524  ast_free(channel_string);
1525 
1526  return blob;
1527 }
Struct containing info for an AMI event to send out.
Definition: manager.h:491
struct ast_json * blob
struct ast_channel_snapshot * snapshot
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define EVENT_FLAG_CALL
Definition: manager.h:72
#define NULL
Definition: resample.c:96
struct ast_manager_event_blob * ast_manager_event_blob_create(int event_flags, const char *manager_event, const char *extra_fields_fmt,...)
Construct a ast_manager_event_blob.
Definition: manager.c:9727
Blob of data associated with a channel.
struct ast_str * ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
Generate the AMI message body from a channel snapshot.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#define ast_free(a)
Definition: astmm.h:182
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:397
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
Definition: json.c:322

◆ 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 1529 of file stasis_channels.c.

References channel_blob_to_json().

Referenced by unhold_to_json().

1531 {
1532  return channel_blob_to_json(message, "ChannelTalkingFinished", sanitize);
1533 }
static struct ast_json * channel_blob_to_json(struct stasis_message *message, const char *type, const struct stasis_message_sanitizer *sanitize)

◆ unhold_to_json()

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

Definition at line 1557 of file stasis_channels.c.

References agent_login_to_ami(), agent_logoff_to_ami(), 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_monitor_start_type(), ast_channel_monitor_stop_type(), ast_channel_snapshot_to_json(), ast_channel_snapshot_type(), ast_channel_talking_start(), ast_channel_talking_stop(), ast_channel_unhold_type(), ast_channel_varset_type(), ast_json_pack(), ast_json_timeval(), dial_to_json(), dtmf_end_to_json(), hangup_request_to_json(), hold_to_json(), NULL, ast_channel_blob::snapshot, channel_role_snapshot::snapshot, stasis_message_data(), stasis_message_timestamp(), STASIS_MESSAGE_TYPE_DEFN(), talking_start_to_ami(), talking_start_to_json(), talking_stop_to_ami(), talking_stop_to_json(), to_ami(), varset_to_ami(), and varset_to_json().

1559 {
1560  struct ast_channel_blob *channel_blob = stasis_message_data(message);
1561  struct ast_channel_snapshot *snapshot = channel_blob->snapshot;
1562  const struct timeval *tv = stasis_message_timestamp(message);
1563  struct ast_json *json_channel;
1564 
1565  json_channel = ast_channel_snapshot_to_json(snapshot, sanitize);
1566  if (!json_channel) {
1567  return NULL;
1568  }
1569 
1570  return ast_json_pack("{s: s, s: o, s: o}",
1571  "type", "ChannelUnhold",
1572  "timestamp", ast_json_timeval(*tv, NULL),
1573  "channel", json_channel);
1574 }
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
struct ast_channel_snapshot * snapshot
Structure representing a snapshot of channel state.
#define NULL
Definition: resample.c:96
Blob of data associated with a channel.
const struct timeval * stasis_message_timestamp(const struct stasis_message *msg)
Get the time when a message was created.
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
Definition: json.c:649
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
Abstract JSON element (object, array, string, int, ...).
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.

◆ varset_to_ami()

static struct ast_manager_event_blob* varset_to_ami ( struct stasis_message msg)
static

Definition at line 1175 of file stasis_channels.c.

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.

Referenced by unhold_to_json().

1176 {
1177  struct ast_str *channel_event_string;
1178  struct ast_channel_blob *obj = stasis_message_data(msg);
1179  const char *variable =
1180  ast_json_string_get(ast_json_object_get(obj->blob, "variable"));
1181  char *value;
1182  struct ast_manager_event_blob *ev;
1183 
1185  "value")));
1186  if (!value) {
1187  return NULL;
1188  }
1189 
1190  if (obj->snapshot) {
1191  channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
1192  } else {
1193  channel_event_string = ast_str_create(35);
1194  ast_str_set(&channel_event_string, 0,
1195  "Channel: none\r\n"
1196  "Uniqueid: none\r\n");
1197  }
1198  if (!channel_event_string) {
1199  ast_free(value);
1200  return NULL;
1201  }
1202 
1204  "%s"
1205  "Variable: %s\r\n"
1206  "Value: %s\r\n",
1207  ast_str_buffer(channel_event_string), variable, value);
1208  ast_free(channel_event_string);
1209  ast_free(value);
1210  return ev;
1211 }
Struct containing info for an AMI event to send out.
Definition: manager.h:491
struct ast_json * blob
struct ast_channel_snapshot * snapshot
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
#define EVENT_FLAG_DIALPLAN
Definition: manager.h:82
struct ast_manager_event_blob * ast_manager_event_blob_create(int event_flags, const char *manager_event, const char *extra_fields_fmt,...)
Construct a ast_manager_event_blob.
Definition: manager.c:9727
Blob of data associated with a channel.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
struct ast_str * ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
Generate the AMI message body from a channel snapshot.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#define ast_free(a)
Definition: astmm.h:182
char * ast_escape_c_alloc(const char *s)
Escape standard &#39;C&#39; sequences in the given string.
Definition: main/utils.c:1892
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:397
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ varset_to_json()

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

Definition at line 1419 of file stasis_channels.c.

References channel_blob_to_json().

Referenced by unhold_to_json().

1422 {
1423  return channel_blob_to_json(message, "ChannelVarset", sanitize);
1424 }
static struct ast_json * channel_blob_to_json(struct stasis_message *message, const char *type, const struct stasis_message_sanitizer *sanitize)

Variable Documentation

◆ channel_cache

struct ao2_container* channel_cache
static

Definition at line 120 of file stasis_channels.c.

Referenced by channels_scrape_cb().

◆ channel_cache_by_name

struct ao2_container* channel_cache_by_name
static

Definition at line 121 of file stasis_channels.c.

◆ channel_topic_all

struct stasis_topic* channel_topic_all
static

Definition at line 119 of file stasis_channels.c.

Referenced by ast_channel_topic_all().

◆ dial_masquerade_caller_info

const struct ast_datastore_info dial_masquerade_caller_info
static

Definition at line 1939 of file stasis_channels.c.

◆ dial_masquerade_info

const struct ast_datastore_info dial_masquerade_info
static

Definition at line 1932 of file stasis_channels.c.