34 #include "asterisk/stasis_message_router.h"
36 #include "asterisk/stasis_channels.h"
467 char *connected_name;
484 "%sChannelState: %u\r\n"
485 "%sChannelStateDesc: %s\r\n"
486 "%sCallerIDNum: %s\r\n"
487 "%sCallerIDName: %s\r\n"
488 "%sConnectedLineNum: %s\r\n"
489 "%sConnectedLineName: %s\r\n"
491 "%sAccountCode: %s\r\n"
496 "%sLinkedid: %s\r\n",
498 prefix, snapshot->
state,
501 prefix,
S_OR(caller_name,
"<unknown>"),
503 prefix,
S_OR(connected_name,
"<unknown>"),
512 ast_free(caller_name);
513 ast_free(connected_name);
527 var->name,
S_OR(val,
""));
551 int is_hungup, was_hungup;
566 if (!was_hungup && is_hungup) {
568 EVENT_FLAG_CALL,
"Hangup",
575 if (old_snapshot->
state != new_snapshot->
state) {
605 EVENT_FLAG_DIALPLAN,
"Newexten",
607 "Application: %s\r\n"
636 EVENT_FLAG_CALL,
"NewCallerid",
637 "CID-CallingPres: %d (%s)\r\n",
659 EVENT_FLAG_CALL,
"NewConnectedLine",
"%s",
"");
675 EVENT_FLAG_CALL,
"NewAccountCode",
682 channel_new_callerid,
683 channel_new_accountcode,
684 channel_new_connected_line,
696 for (i = 0; i < ARRAY_LEN(channel_monitors); ++i) {
705 if (!channel_event_string) {
706 channel_event_string =
708 if (!channel_event_string) {
724 if (!channel_event_string) {
733 static void channel_hangup_request_cb(
void *data,
739 struct ast_str *channel_event_string;
755 if (!channel_event_string) {
769 manager_event =
"SoftHangupRequest";
777 ast_free(channel_event_string);
788 const char *spyee_info =
"";
793 ast_log(AST_LOG_WARNING,
"Received ChanSpy Stop event with no spyer channel!\n");
798 if (!spyer_channel_string) {
805 if (spyee_channel_string) {
827 ast_log(AST_LOG_WARNING,
"Received ChanSpy Start event with no spyer channel!\n");
832 ast_log(AST_LOG_WARNING,
"Received ChanSpy Start event with no spyee channel!\n");
837 if (!spyer_channel_string) {
841 if (!spyee_channel_string) {
858 const char *direction =
863 if (!channel_event_string) {
904 const char *direction =
911 if (!channel_event_string) {
943 "DurationMs: %ld\r\n"
946 digit, duration_ms, direction);
953 struct ast_str *channel_event_string;
956 if (!channel_event_string) {
974 ast_free(channel_event_string);
981 struct ast_str *channel_event_string;
984 if (!channel_event_string) {
1002 ast_free(channel_event_string);
1016 if (!channel_event_string) {
1020 if (!strcmp(action,
"run")) {
1021 event =
"HangupHandlerRun";
1022 }
else if (!strcmp(action,
"pop")) {
1023 event =
"HangupHandlerPop";
1024 }
else if (!strcmp(action,
"push")) {
1025 event =
"HangupHandlerPush";
1055 if (!event_buffer) {
1060 if (!channel_event_string) {
1064 if (!strcmp(type,
"status")) {
1065 event =
"FAXStatus";
1066 }
else if (!strcmp(type,
"receive")) {
1067 event =
"ReceiveFAX";
1068 }
else if (!strcmp(type,
"send")) {
1080 if (local_station_id) {
1083 if (remote_station_id) {
1089 if (fax_resolution) {
1097 for (i = 0; i < array_len; i++) {
1117 if (!channel_event_string) {
1134 publish_basic_channel_event(
"MusicOnHoldStop", EVENT_FLAG_CALL, payload->
snapshot);
1142 publish_basic_channel_event(
"MixMonitorStart", EVENT_FLAG_CALL, payload->
snapshot);
1150 publish_basic_channel_event(
"MixMonitorStop", EVENT_FLAG_CALL, payload->
snapshot);
1162 if (!event_buffer) {
1167 if (!channel_event_string) {
1174 ast_str_append(&event_buffer, 0,
"State: %s\r\n", state ?
"1" :
"0");
1184 static int dial_status_end(
const char *dialstatus)
1186 return (strcmp(dialstatus,
"RINGING") &&
1187 strcmp(dialstatus,
"PROCEEDING") &&
1188 strcmp(dialstatus,
"PROGRESS"));
1198 const char *dialstatus;
1199 const char *dialstring;
1200 const char *forward;
1210 ast_assert(peer != NULL);
1212 if (!peer_event_string) {
1223 if (ast_strlen_zero(dialstatus)) {
1227 "DialString: %s\r\n",
1230 S_OR(dialstring,
"unknown"));
1232 int forwarded = !ast_strlen_zero(forward);
1234 manager_event(EVENT_FLAG_CALL, dial_status_end(dialstatus) ?
"DialEnd" :
"DialState",
1238 "DialStatus: %s\r\n",
1241 forwarded ?
"Forward: " :
"",
S_OR(forward,
""), forwarded ?
"\r\n" :
"",
1242 S_OR(dialstatus,
"unknown"));
1252 struct ast_str *channel_event_string;
1254 if (!musicclass_string) {
1259 if (!channel_event_string) {
1260 ast_free(musicclass_string);
1265 const char *musicclass;
1269 if (!ast_strlen_zero(musicclass)) {
1270 ast_str_set(&musicclass_string, 0,
"MusicClass: %s\r\n", musicclass);
1280 ast_free(musicclass_string);
1281 ast_free(channel_event_string);
1288 struct ast_str *channel_event_string;
1291 if (!channel_event_string) {
1299 ast_free(channel_event_string);
1302 static void manager_channels_shutdown(
void)
1304 stasis_forward_cancel(topic_forwarder);
1305 topic_forwarder = NULL;
1316 if (!manager_topic) {
1320 if (!message_router) {
1324 if (!channel_topic) {
1329 if (!topic_forwarder) {
1400 manager_channels_shutdown();
struct stasis_message_type * ast_channel_hold_type(void)
Message type for when a channel is placed on hold.
const ast_string_field data
Struct containing info for an AMI event to send out.
struct ast_channel_snapshot_base * base
struct stasis_message_type * ast_channel_dtmf_end_type(void)
Message type for when DTMF ends on a channel.
Channels with this particular technology are an implementation detail of Asterisk and should generall...
Asterisk main include file. File version handling, generic pbx functions.
struct stasis_message_type * ast_channel_unhold_type(void)
Message type for when a channel is removed from hold.
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.
int stasis_message_router_add(struct stasis_message_router *router, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data)
Add a route to a message router.
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
const ast_string_field name
const char * ast_describe_caller_presentation(int data)
Convert caller ID pres value to explanatory string.
struct ast_channel_snapshot * snapshot
struct stasis_message_type * ast_channel_moh_start_type(void)
Message type for starting music on hold on a channel.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
int ast_json_is_true(const struct ast_json *value)
Check if value is JSON true.
Structure representing a snapshot of channel state.
struct stasis_message_type * ast_channel_wink_type(void)
Message type for when a wink occurs on a channel.
const ast_string_field accountcode
struct stasis_message_type * ast_channel_flash_type(void)
Message type for when a hook flash occurs on a channel.
const ast_string_field uniqueid
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
const char * ast_cause2str(int cause) attribute_pure
Gives the string form of a given cause code.
struct stasis_message_type * ast_channel_chanspy_start_type(void)
Message type for when a channel starts spying on another channel.
static struct stasis_topic * manager_topic
A stasis_topic that all topics AMI cares about will be forwarded to.
Structure representing a change of snapshot of channel state.
struct ast_channel_snapshot_dialplan * dialplan
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.
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...
Blob of data associated with a channel.
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.
static void channel_dial_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Callback processing messages for channel dialing.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
const ast_string_field context
struct stasis_topic * ast_channel_topic_all(void)
A topic which publishes the events for all channels.
General Asterisk PBX channel definitions.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
const ast_string_field appl
const ast_string_field exten
struct ast_channel_snapshot_hangup * hangup
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
struct ast_str * ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
Generate the AMI message body from a channel snapshot.
Core PBX routines and definitions.
static struct ast_manager_event_blob * channel_state_change(struct ast_channel_snapshot *old_snapshot, struct ast_channel_snapshot *new_snapshot)
Handle channel state changes.
struct ast_channel_snapshot_caller * caller
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
struct ast_str * ast_manager_build_channel_state_string_prefix(const struct ast_channel_snapshot *snapshot, const char *prefix)
Generate the AMI message body from a channel snapshot.
struct stasis_message_type * ast_channel_mixmonitor_start_type(void)
Message type for starting mixmonitor on a channel.
struct varshead * manager_vars
Support for dynamic strings.
struct stasis_message_type * ast_channel_mixmonitor_stop_type(void)
Message type for stopping mixmonitor on a channel.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct stasis_message_router * ast_manager_get_message_router(void)
Get the stasis_message_router for AMI.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
struct stasis_message_type * ast_channel_hangup_handler_type(void)
Message type for hangup handler related actions.
char * ast_escape_c_alloc(const char *s)
Escape standard 'C' sequences in the given string.
struct ast_channel_snapshot * new_snapshot
enum ast_channel_state state
struct stasis_message_type * ast_channel_snapshot_type(void)
Message type for ast_channel_snapshot_update.
struct ast_channel_snapshot * old_snapshot
struct stasis_message_type * ast_channel_dtmf_begin_type(void)
Message type for when DTMF begins on a channel.
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
const ast_string_field language
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
const ast_string_field number
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
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.
size_t ast_json_array_size(const struct ast_json *array)
Get the size of a JSON array.
Abstract JSON element (object, array, string, int, ...).
static struct stasis_forward * topic_forwarder
The Stasis Message Bus API subscription returned by the forwarding of the channel topic to the manage...
struct stasis_message_type * ast_channel_dial_type(void)
Message type for when a channel dials another channel.
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.
struct stasis_message_type * ast_channel_moh_stop_type(void)
Message type for stopping music on hold on a channel.
struct stasis_forward * stasis_forward_all(struct stasis_topic *from_topic, struct stasis_topic *to_topic)
Create a subscription which forwards all messages from one topic to another.
struct ast_channel_snapshot_peer * peer
struct stasis_message_type * ast_channel_hangup_request_type(void)
Message type for when a hangup is requested on a channel.
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct stasis_message_type * ast_channel_fax_type(void)
Message type for a fax operation.
const char * ast_state2str(enum ast_channel_state state)
Gives the string form of a given channel state.
struct ast_json * ast_json_array_get(const struct ast_json *array, size_t index)
Get an element from an array.
struct ast_manager_event_blob *(* channel_snapshot_monitor)(struct ast_channel_snapshot *old_snapshot, struct ast_channel_snapshot *new_snapshot)
Typedef for callbacks that get called on channel snapshot updates.
struct ast_channel_snapshot_connected * connected
struct stasis_message_type * ast_channel_chanspy_stop_type(void)
Message type for when a channel stops spying on another channel.
int manager_channels_init(void)
Initialize support for AMI channel events.
const ast_string_field name
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
struct stasis_message_type * ast_channel_mixmonitor_mute_type(void)
Message type for muting or unmuting mixmonitor on a channel.