Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Typedefs | Enumerations | Functions
manager.h File Reference

The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party software. More...

#include "asterisk/network.h"
#include "asterisk/lock.h"
#include "asterisk/datastore.h"
#include "asterisk/xmldoc.h"
Include dependency graph for manager.h:

Go to the source code of this file.

Data Structures

struct  ast_manager_event_blob
 Struct containing info for an AMI event to send out. More...
 
struct  manager_action
 
struct  manager_custom_hook
 
struct  message
 

Macros

#define AMI_VERSION   "7.0.1"
 
#define ast_manager_event(chan, category, event, contents, ...)
 
#define ast_manager_event_multichan(category, event, nchans, chans, contents, ...)   __ast_manager_event_multichan(category, event, nchans, chans, __FILE__, __LINE__, __PRETTY_FUNCTION__, contents , ## __VA_ARGS__);
 
#define ast_manager_register(action, authority, func, synopsis)   ast_manager_register2(action, authority, func, AST_MODULE_SELF, synopsis, NULL)
 External routines may register/unregister manager callbacks this way. More...
 
#define ast_manager_register_xml(action, authority, func)   ast_manager_register2(action, authority, func, AST_MODULE_SELF, NULL, NULL)
 Register a manager callback using XML documentation to describe the manager. More...
 
#define ast_manager_register_xml_core(action, authority, func)   ast_manager_register2(action, authority, func, NULL, NULL, NULL)
 Register a manager callback using XML documentation to describe the manager. More...
 
#define AST_MAX_MANHEADERS   128
 Export manager structures. More...
 
#define DEFAULT_MANAGER_PORT   5038 /* Default port for Asterisk management via TCP */
 
#define DEFAULT_MANAGER_TLS_PORT   5039 /* Default port for Asterisk management via TCP */
 
#define manager_event(category, event, contents, ...)   __ast_manager_event_multichan(category, event, 0, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__, contents , ## __VA_ARGS__)
 External routines may send asterisk manager events this way. More...
 
#define NO_EXTRA_FIELDS   "%s", ""
 
Constant return values
Note
Currently, returning anything other than zero causes the session to terminate.
#define AMI_SUCCESS   (0)
 
#define AMI_DESTROY   (-1)
 
Manager event classes
#define EVENT_FLAG_SYSTEM   (1 << 0) /* System events such as module load/unload */
 
#define EVENT_FLAG_CALL   (1 << 1) /* Call event, such as state change, etc */
 
#define EVENT_FLAG_LOG   (1 << 2) /* Log events */
 
#define EVENT_FLAG_VERBOSE   (1 << 3) /* Verbose messages */
 
#define EVENT_FLAG_COMMAND   (1 << 4) /* Ability to read/set commands */
 
#define EVENT_FLAG_AGENT   (1 << 5) /* Ability to read/set agent info */
 
#define EVENT_FLAG_USER   (1 << 6) /* Ability to read/set user info */
 
#define EVENT_FLAG_CONFIG   (1 << 7) /* Ability to modify configurations */
 
#define EVENT_FLAG_DTMF   (1 << 8) /* Ability to read DTMF events */
 
#define EVENT_FLAG_REPORTING   (1 << 9) /* Reporting events such as rtcp sent */
 
#define EVENT_FLAG_CDR   (1 << 10) /* CDR events */
 
#define EVENT_FLAG_DIALPLAN   (1 << 11) /* Dialplan events (VarSet, NewExten) */
 
#define EVENT_FLAG_ORIGINATE   (1 << 12) /* Originate a call to an extension */
 
#define EVENT_FLAG_AGI   (1 << 13) /* AGI events */
 
#define EVENT_FLAG_HOOKRESPONSE   (1 << 14) /* Hook Response */
 
#define EVENT_FLAG_CC   (1 << 15) /* Call Completion events */
 
#define EVENT_FLAG_AOC   (1 << 16) /* Advice Of Charge events */
 
#define EVENT_FLAG_TEST   (1 << 17) /* Test event used to signal the Asterisk Test Suite */
 
#define EVENT_FLAG_SECURITY   (1 << 18) /* Security Message as AMI Event */
 
#define EVENT_FLAG_MESSAGE   (1 << 30) /* MESSAGE events. */
 

Typedefs

typedef int(* key_exclusion_cb) (const char *key)
 Callback used to determine whether a key should be skipped when converting a JSON object to a manager blob. More...
 
typedef int(* manager_hook_t) (int category, const char *event, char *body)
 Manager Helper Function. More...
 

Enumerations

enum  variable_orders { ORDER_NATURAL, ORDER_REVERSE }
 

Functions

int __ast_manager_event_multichan (int category, const char *event, int chancount, struct ast_channel **chans, const char *file, int line, const char *func, const char *contents,...)
 
int ast_hook_send_action (struct manager_custom_hook *hook, const char *msg)
 Registered hooks can call this function to invoke actions and they will receive responses through registered callback. More...
 
struct ast_strast_manager_build_bridge_state_string (const struct ast_bridge_snapshot *snapshot)
 Generate the AMI message body from a bridge snapshot. More...
 
struct ast_strast_manager_build_bridge_state_string_prefix (const struct ast_bridge_snapshot *snapshot, const char *prefix)
 Generate the AMI message body from a bridge snapshot. More...
 
struct ast_strast_manager_build_channel_state_string (const struct ast_channel_snapshot *snapshot)
 Generate the AMI message body from a channel snapshot. More...
 
struct ast_strast_manager_build_channel_state_string_prefix (const struct ast_channel_snapshot *snapshot, const char *prefix)
 Generate the AMI message body from a channel snapshot. More...
 
int ast_manager_check_enabled (void)
 Check if AMI is enabled. More...
 
struct ast_manager_event_blobast_manager_event_blob_create (int event_flags, const char *manager_event, const char *extra_fields_fmt,...)
 Construct a ast_manager_event_blob. More...
 
struct stasis_message_typeast_manager_get_generic_type (void)
 Get the stasis_message_type for generic messages. More...
 
struct stasis_message_routerast_manager_get_message_router (void)
 Get the stasis_message_router for AMI. More...
 
struct stasis_topicast_manager_get_topic (void)
 Get the Stasis Message Bus API topic for AMI. More...
 
void ast_manager_publish_event (const char *type, int class_type, struct ast_json *obj)
 Publish an event to AMI. More...
 
int ast_manager_register2 (const char *action, int authority, int(*func)(struct mansession *s, const struct message *m), struct ast_module *module, const char *synopsis, const char *description)
 Register a manager command with the manager interface. More...
 
void ast_manager_register_hook (struct manager_custom_hook *hook)
 Add a custom hook to be called when an event is fired. More...
 
struct ast_strast_manager_str_from_json_object (struct ast_json *blob, key_exclusion_cb exclusion_cb)
 Convert a JSON object into an AMI compatible string. More...
 
int ast_manager_unregister (const char *action)
 Unregister a registered manager command. More...
 
void ast_manager_unregister_hook (struct manager_custom_hook *hook)
 Delete a custom hook to be called when an event is fired. More...
 
int ast_str_append_event_header (struct ast_str **fields_string, const char *header, const char *value)
 append an event header to an ast string More...
 
int ast_webmanager_check_enabled (void)
 Check if AMI/HTTP is enabled. More...
 
void astman_append (struct mansession *s, const char *fmt,...)
 
int astman_datastore_add (struct mansession *s, struct ast_datastore *datastore)
 Add a datastore to a session. More...
 
struct ast_datastoreastman_datastore_find (struct mansession *s, const struct ast_datastore_info *info, const char *uid)
 Find a datastore on a session. More...
 
int astman_datastore_remove (struct mansession *s, struct ast_datastore *datastore)
 Remove a datastore from a session. More...
 
const char * astman_get_header (const struct message *m, char *var)
 Get header from mananger transaction. More...
 
struct ast_variableastman_get_variables (const struct message *m)
 Get a linked list of the Variable: headers. More...
 
struct ast_variableastman_get_variables_order (const struct message *m, enum variable_orders order)
 Get a linked list of the Variable: headers with order specified. More...
 
int astman_is_authed (uint32_t ident)
 Determinie if a manager session ident is authenticated. More...
 
void astman_send_ack (struct mansession *s, const struct message *m, char *msg)
 Send ack in manager transaction. More...
 
void astman_send_error (struct mansession *s, const struct message *m, char *error)
 Send error in manager transaction. More...
 
void astman_send_error_va (struct mansession *s, const struct message *m, const char *fmt,...)
 Send error in manager transaction (with va_args support) More...
 
void astman_send_list_complete_end (struct mansession *s)
 End the list complete event. More...
 
void astman_send_list_complete_start (struct mansession *s, const struct message *m, const char *event_name, int count)
 Start the list complete event. More...
 
void astman_send_listack (struct mansession *s, const struct message *m, char *msg, char *listflag)
 Send ack in manager transaction to begin a list. More...
 
void astman_send_response (struct mansession *s, const struct message *m, char *resp, char *msg)
 Send response in manager transaction. More...
 
int astman_verify_session_readpermissions (uint32_t ident, int perm)
 Verify a session's read permissions against a permission mask. More...
 
int astman_verify_session_writepermissions (uint32_t ident, int perm)
 Verify a session's write permissions against a permission mask. More...
 
int manager_bridging_init (void)
 Initialize support for AMI channel events. More...
 
int manager_channels_init (void)
 Initialize support for AMI channel events. More...
 
int manager_endpoints_init (void)
 Initialize support for AMI endpoint events. More...
 
int manager_mwi_init (void)
 Initialize support for AMI MWI events. More...
 
int manager_system_init (void)
 Initialize support for AMI system events. More...
 

Detailed Description

The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party software.

Manager protocol packages are text fields of the form a: b. There is always exactly one space after the colon.

 For Actions replies, the first line of the reply is a "Response:" header with
 values "success", "error" or "follows". "Follows" implies that the
 response is coming as separate events with the same ActionID. If the
 Action request has no ActionID, it will be hard matching events
 to the Action request in the manager client.

 The first header type is the "Event" header.  Other headers vary from
 event to event.  Headers end with standard \\r\\n termination.
 The last line of the manager response or event is an empty line.
 (\\r\\n)
Note
Please try to re-use existing headers to simplify manager message parsing in clients. Don't re-use an existing header with a new meaning, please. You can find a reference of standard headers in doc/manager.txt

Definition in file manager.h.

Macro Definition Documentation

◆ AMI_DESTROY

#define AMI_DESTROY   (-1)

Definition at line 66 of file manager.h.

◆ AMI_SUCCESS

#define AMI_SUCCESS   (0)

◆ AMI_VERSION

#define AMI_VERSION   "7.0.1"

Definition at line 57 of file manager.h.

Referenced by action_coresettings(), and session_do().

◆ ast_manager_event

#define ast_manager_event (   chan,
  category,
  event,
  contents,
  ... 
)
Value:
do { \
struct ast_channel *_chans[] = { chan, }; \
__ast_manager_event_multichan(category, event, 1, _chans, __FILE__, __LINE__, __PRETTY_FUNCTION__, contents , ## __VA_ARGS__); \
} while (0)
Main Channel structure associated with a channel.
Definition: astman.c:222
const char * contents

Definition at line 250 of file manager.h.

Referenced by __ast_change_name_nolink().

◆ ast_manager_event_multichan

#define ast_manager_event_multichan (   category,
  event,
  nchans,
  chans,
  contents,
  ... 
)    __ast_manager_event_multichan(category, event, nchans, chans, __FILE__, __LINE__, __PRETTY_FUNCTION__, contents , ## __VA_ARGS__);

Definition at line 255 of file manager.h.

Referenced by fast_originate().

◆ ast_manager_register

#define ast_manager_register (   action,
  authority,
  func,
  synopsis 
)    ast_manager_register2(action, authority, func, AST_MODULE_SELF, synopsis, NULL)

External routines may register/unregister manager callbacks this way.

Note
Use ast_manager_register2() to register with help text for new manager commands

Definition at line 183 of file manager.h.

◆ ast_manager_register_xml

#define ast_manager_register_xml (   action,
  authority,
  func 
)    ast_manager_register2(action, authority, func, AST_MODULE_SELF, NULL, NULL)

Register a manager callback using XML documentation to describe the manager.

Definition at line 186 of file manager.h.

Referenced by ast_res_pjsip_init_options_handling(), ast_res_pjsip_initialize_configuration(), ast_sip_initialize_sorcery_auth(), ast_sip_initialize_sorcery_location(), load_module(), and load_parking_manager().

◆ ast_manager_register_xml_core

#define ast_manager_register_xml_core (   action,
  authority,
  func 
)    ast_manager_register2(action, authority, func, NULL, NULL, NULL)

Register a manager callback using XML documentation to describe the manager.

Note
For Asterisk core modules that are not independently loadable.
Warning
If you use ast_manager_register_xml() instead when you need to use this function, Asterisk will crash on load.

Definition at line 197 of file manager.h.

Referenced by __init_manager(), ast_bridging_init(), ast_local_init(), ast_msg_init(), astdb_init(), load_module(), load_pbx(), and manager_bridging_init().

◆ AST_MAX_MANHEADERS

#define AST_MAX_MANHEADERS   128

Export manager structures.

Definition at line 95 of file manager.h.

◆ DEFAULT_MANAGER_PORT

#define DEFAULT_MANAGER_PORT   5038 /* Default port for Asterisk management via TCP */

Definition at line 58 of file manager.h.

Referenced by __init_manager().

◆ DEFAULT_MANAGER_TLS_PORT

#define DEFAULT_MANAGER_TLS_PORT   5039 /* Default port for Asterisk management via TCP */

Definition at line 59 of file manager.h.

Referenced by __init_manager().

◆ EVENT_FLAG_AGENT

#define EVENT_FLAG_AGENT   (1 << 5) /* Ability to read/set agent info */

◆ EVENT_FLAG_AGI

#define EVENT_FLAG_AGI   (1 << 13) /* AGI events */

Definition at line 84 of file manager.h.

Referenced by agi_channel_to_ami(), and load_module().

◆ EVENT_FLAG_AOC

#define EVENT_FLAG_AOC   (1 << 16) /* Advice Of Charge events */

Definition at line 87 of file manager.h.

Referenced by __init_manager(), and aoc_to_ami().

◆ EVENT_FLAG_CALL

#define EVENT_FLAG_CALL   (1 << 1) /* Call event, such as state change, etc */

◆ EVENT_FLAG_CC

#define EVENT_FLAG_CC   (1 << 15) /* Call Completion events */

◆ EVENT_FLAG_CDR

#define EVENT_FLAG_CDR   (1 << 10) /* CDR events */

Definition at line 81 of file manager.h.

Referenced by manager_log().

◆ EVENT_FLAG_COMMAND

#define EVENT_FLAG_COMMAND   (1 << 4) /* Ability to read/set commands */

Definition at line 75 of file manager.h.

Referenced by __init_manager().

◆ EVENT_FLAG_CONFIG

#define EVENT_FLAG_CONFIG   (1 << 7) /* Ability to modify configurations */

Definition at line 78 of file manager.h.

Referenced by __init_manager(), http_post_callback(), and load_pbx().

◆ EVENT_FLAG_DIALPLAN

#define EVENT_FLAG_DIALPLAN   (1 << 11) /* Dialplan events (VarSet, NewExten) */

Definition at line 82 of file manager.h.

Referenced by channel_hangup_handler_cb(), channel_newexten(), and varset_to_ami().

◆ EVENT_FLAG_DTMF

#define EVENT_FLAG_DTMF   (1 << 8) /* Ability to read DTMF events */

Definition at line 79 of file manager.h.

Referenced by channel_dtmf_begin_cb(), and channel_dtmf_end_cb().

◆ EVENT_FLAG_HOOKRESPONSE

#define EVENT_FLAG_HOOKRESPONSE   (1 << 14) /* Hook Response */

Definition at line 85 of file manager.h.

Referenced by send_string().

◆ EVENT_FLAG_LOG

#define EVENT_FLAG_LOG   (1 << 2) /* Log events */

Definition at line 73 of file manager.h.

◆ EVENT_FLAG_MESSAGE

#define EVENT_FLAG_MESSAGE   (1 << 30) /* MESSAGE events. */

Definition at line 91 of file manager.h.

Referenced by ast_msg_init().

◆ EVENT_FLAG_ORIGINATE

#define EVENT_FLAG_ORIGINATE   (1 << 12) /* Originate a call to an extension */

Definition at line 83 of file manager.h.

Referenced by __init_manager().

◆ EVENT_FLAG_REPORTING

#define EVENT_FLAG_REPORTING   (1 << 9) /* Reporting events such as rtcp sent */

◆ EVENT_FLAG_SECURITY

#define EVENT_FLAG_SECURITY   (1 << 18) /* Security Message as AMI Event */

Definition at line 89 of file manager.h.

Referenced by security_event_to_ami_blob().

◆ EVENT_FLAG_SYSTEM

#define EVENT_FLAG_SYSTEM   (1 << 0) /* System events such as module load/unload */

◆ EVENT_FLAG_TEST

#define EVENT_FLAG_TEST   (1 << 17) /* Test event used to signal the Asterisk Test Suite */

Definition at line 88 of file manager.h.

Referenced by fake_ami().

◆ EVENT_FLAG_USER

#define EVENT_FLAG_USER   (1 << 6) /* Ability to read/set user info */

◆ EVENT_FLAG_VERBOSE

#define EVENT_FLAG_VERBOSE   (1 << 3) /* Verbose messages */

Definition at line 74 of file manager.h.

◆ manager_event

#define manager_event (   category,
  event,
  contents,
  ... 
)    __ast_manager_event_multichan(category, event, 0, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__, contents , ## __VA_ARGS__)

◆ NO_EXTRA_FIELDS

#define NO_EXTRA_FIELDS   "%s", ""

GCC warns about blank or NULL format strings. So, shenanigans!

Definition at line 522 of file manager.h.

Referenced by bridge_create(), bridge_destroy(), and channel_state_change().

Typedef Documentation

◆ key_exclusion_cb

typedef int(* key_exclusion_cb) (const char *key)

Callback used to determine whether a key should be skipped when converting a JSON object to a manager blob.

Since
12
Parameters
keyKey from JSON blob to be evaluated
Return values
non-zeroif the key should be excluded
zeroif the key should not be excluded

Definition at line 444 of file manager.h.

◆ manager_hook_t

typedef int(* manager_hook_t) (int category, const char *event, char *body)

Manager Helper Function.

Parameters
categoryThe class authorization category of the event
eventThe name of the event being raised
bodyThe body of the event
Return values
0Success
non-zeroError

Definition at line 106 of file manager.h.

Enumeration Type Documentation

◆ variable_orders

Enumerator
ORDER_NATURAL 
ORDER_REVERSE 

Definition at line 282 of file manager.h.

282  {
285 };

Function Documentation

◆ ast_manager_build_bridge_state_string()

struct ast_str* ast_manager_build_bridge_state_string ( const struct ast_bridge_snapshot snapshot)

Generate the AMI message body from a bridge snapshot.

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

Definition at line 267 of file manager_bridges.c.

References ast_manager_build_bridge_state_string_prefix().

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

269 {
271 }
struct ast_str * ast_manager_build_bridge_state_string_prefix(const struct ast_bridge_snapshot *snapshot, const char *prefix)
Generate the AMI message body from a bridge snapshot.

◆ ast_manager_build_bridge_state_string_prefix()

struct ast_str* ast_manager_build_bridge_state_string_prefix ( const struct ast_bridge_snapshot snapshot,
const char *  prefix 
)

Generate the AMI message body from a bridge snapshot.

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

Definition at line 223 of file manager_bridges.c.

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

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

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

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

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

Definition at line 561 of file manager_channels.c.

References ast_manager_build_channel_state_string_prefix().

Referenced by action_agents(), action_confbridgelist_item(), agent_login_to_ami(), agent_logoff_to_ami(), agi_channel_to_ami(), aoc_to_ami(), call_pickup_to_ami(), channel_dial_cb(), channel_dtmf_begin_cb(), channel_dtmf_end_cb(), channel_enter_cb(), channel_fax_cb(), channel_flash_cb(), channel_hangup_handler_cb(), channel_hangup_request_cb(), channel_hold_cb(), channel_leave_cb(), channel_mixmonitor_mute_cb(), channel_moh_start_cb(), channel_snapshot_update(), channel_unhold_cb(), confbridge_publish_manager_event(), dahdichannel_to_ami(), generate_status(), meetme_stasis_cb(), mwi_app_event_cb(), mwi_update_cb(), publish_basic_channel_event(), queue_channel_to_ami(), queue_multi_channel_to_ami(), rtcp_report_to_ami(), send_bridge_info_item_cb(), session_timeout_to_ami(), talking_start_to_ami(), talking_stop_to_ami(), and varset_to_ami().

563 {
565 }
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.

◆ ast_manager_build_channel_state_string_prefix()

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.

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

Definition at line 487 of file manager_channels.c.

References ast_channel_snapshot_base::accountcode, AST_CHAN_TP_INTERNAL, ast_escape_c_alloc(), ast_free, AST_LIST_TRAVERSE, ast_state2str(), ast_str_append(), ast_str_create, ast_str_set(), ast_channel_snapshot::base, ast_channel_snapshot::caller, ast_channel_snapshot::connected, ast_channel_snapshot_dialplan::context, ast_channel_snapshot::dialplan, ast_var_t::entries, ast_channel_snapshot_dialplan::exten, ast_channel_snapshot_base::language, ast_channel_snapshot_peer::linkedid, ast_channel_snapshot::manager_vars, ast_var_t::name, 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, out, ast_channel_snapshot::peer, ast_channel_snapshot_dialplan::priority, S_OR, ast_channel_snapshot::state, ast_channel_snapshot_base::tech_properties, ast_channel_snapshot_base::uniqueid, ast_var_t::value, and var.

Referenced by action_coreshowchannels(), ast_manager_build_channel_state_string(), attended_transfer_to_ami(), blind_transfer_to_ami(), call_pickup_to_ami(), channel_chanspy_start_cb(), channel_chanspy_stop_cb(), channel_dial_cb(), local_message_to_ami(), manager_build_parked_call_string(), multi_object_blob_to_ami(), and queue_multi_channel_to_ami().

490 {
491  struct ast_str *out;
492  char *caller_name;
493  char *connected_name;
494  int res;
495 
496  if (snapshot->base->tech_properties & AST_CHAN_TP_INTERNAL) {
497  return NULL;
498  }
499 
500  out = ast_str_create(1024);
501  if (!out) {
502  return NULL;
503  }
504 
505  caller_name = ast_escape_c_alloc(snapshot->caller->name);
506  connected_name = ast_escape_c_alloc(snapshot->connected->name);
507 
508  res = ast_str_set(&out, 0,
509  "%sChannel: %s\r\n"
510  "%sChannelState: %u\r\n"
511  "%sChannelStateDesc: %s\r\n"
512  "%sCallerIDNum: %s\r\n"
513  "%sCallerIDName: %s\r\n"
514  "%sConnectedLineNum: %s\r\n"
515  "%sConnectedLineName: %s\r\n"
516  "%sLanguage: %s\r\n"
517  "%sAccountCode: %s\r\n"
518  "%sContext: %s\r\n"
519  "%sExten: %s\r\n"
520  "%sPriority: %d\r\n"
521  "%sUniqueid: %s\r\n"
522  "%sLinkedid: %s\r\n",
523  prefix, snapshot->base->name,
524  prefix, snapshot->state,
525  prefix, ast_state2str(snapshot->state),
526  prefix, S_OR(snapshot->caller->number, "<unknown>"),
527  prefix, S_OR(caller_name, "<unknown>"),
528  prefix, S_OR(snapshot->connected->number, "<unknown>"),
529  prefix, S_OR(connected_name, "<unknown>"),
530  prefix, snapshot->base->language,
531  prefix, snapshot->base->accountcode,
532  prefix, snapshot->dialplan->context,
533  prefix, snapshot->dialplan->exten,
534  prefix, snapshot->dialplan->priority,
535  prefix, snapshot->base->uniqueid,
536  prefix, snapshot->peer->linkedid);
537 
538  ast_free(caller_name);
539  ast_free(connected_name);
540 
541  if (!res) {
542  ast_free(out);
543  return NULL;
544  }
545 
546  if (snapshot->manager_vars) {
547  struct ast_var_t *var;
548  char *val;
549  AST_LIST_TRAVERSE(snapshot->manager_vars, var, entries) {
550  val = ast_escape_c_alloc(var->value);
551  ast_str_append(&out, 0, "%sChanVariable: %s=%s\r\n",
552  prefix,
553  var->name, S_OR(val, ""));
554  ast_free(val);
555  }
556  }
557 
558  return out;
559 }
struct ast_channel_snapshot_base * base
Definition: ast_expr2.c:325
const ast_string_field name
#define var
Definition: ast_expr2f.c:614
const ast_string_field accountcode
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.
Definition: strings.h:1091
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_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
const ast_string_field context
const ast_string_field exten
Channels with this particular technology are an implementation detail of Asterisk and should generall...
Definition: channel.h:972
struct ast_channel_snapshot_caller * caller
char name[0]
Definition: chanvars.h:31
struct varshead * manager_vars
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
char * value
Definition: chanvars.h:30
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_free(a)
Definition: astmm.h:182
struct ast_var_t::@249 entries
char * ast_escape_c_alloc(const char *s)
Escape standard &#39;C&#39; sequences in the given string.
Definition: main/utils.c:1892
enum ast_channel_state state
const ast_string_field language
FILE * out
Definition: utils/frame.c:33
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...
Definition: strings.h:79
struct ast_channel_snapshot_peer * peer
struct ast_channel_snapshot_connected * connected
const ast_string_field name
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620
static char prefix[MAX_PREFIX]
Definition: http.c:141

◆ ast_manager_event_blob_create()

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.

Since
12 The returned object is AO2 managed, so clean up with ao2_cleanup().
Parameters
event_flagsFlags the event should be raised with.
manager_eventThe event to be raised, should be a string literal.
extra_fields_fmtFormat string for extra fields to include. Or NO_EXTRA_FIELDS for no extra fields.
Returns
New ast_manager_snapshot_event object.
NULL on error.

Definition at line 9727 of file manager.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_ref, ast_assert, AST_MODFLAG_GLOBAL_SYMBOLS, AST_MODFLAG_LOAD_ORDER, AST_MODPRI_CORE, AST_MODULE_INFO(), AST_MODULE_SUPPORT_CORE, ast_string_field_init, ast_string_field_ptr_build_va, ASTERISK_GPL_KEY, ast_manager_event_blob::event_flags, ast_manager_event_blob::extra_fields, load_module(), manager_event, ast_manager_event_blob::manager_event, manager_event_blob_dtor(), NULL, reload(), and unload_module().

Referenced by agent_login_to_ami(), agent_logoff_to_ami(), agi_channel_to_ami(), aoc_to_ami(), attended_transfer_to_ami(), blind_transfer_to_ami(), bridge_create(), bridge_destroy(), bridge_video_update(), call_pickup_to_ami(), cc_available_to_ami(), cc_callerrecalling_to_ami(), cc_callerstartmonitoring_to_ami(), cc_callerstopmonitoring_to_ami(), cc_failure_to_ami(), cc_monitorfailed_to_ami(), cc_offertimerstart_to_ami(), cc_recallcomplete_to_ami(), cc_requestacknowledged_to_ami(), cc_requested_to_ami(), channel_new_accountcode(), channel_new_callerid(), channel_new_connected_line(), channel_newexten(), channel_state_change(), contactstatus_to_ami(), dahdichannel_to_ami(), devstate_to_ami(), fake_ami(), local_message_to_ami(), multi_user_event_to_ami(), peerstatus_to_ami(), presence_state_to_ami(), queue_channel_to_ami(), queue_member_to_ami(), queue_multi_channel_to_ami(), rtcp_report_to_ami(), security_event_to_ami_blob(), session_timeout_to_ami(), system_registry_to_ami(), talking_start_to_ami(), talking_stop_to_ami(), test_suite_event_to_ami(), and varset_to_ami().

9733 {
9734  struct ast_manager_event_blob *ev;
9735  va_list argp;
9736 
9737  ast_assert(extra_fields_fmt != NULL);
9739 
9741  if (!ev) {
9742  return NULL;
9743  }
9744 
9745  if (ast_string_field_init(ev, 20)) {
9746  ao2_ref(ev, -1);
9747  return NULL;
9748  }
9749 
9751  ev->event_flags = event_flags;
9752 
9753  va_start(argp, extra_fields_fmt);
9754  ast_string_field_ptr_build_va(ev, &ev->extra_fields, extra_fields_fmt, argp);
9755  va_end(argp);
9756 
9757  return ev;
Struct containing info for an AMI event to send out.
Definition: manager.h:491
const ast_string_field extra_fields
Definition: manager.h:496
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define ast_string_field_ptr_build_va(x, ptr, fmt, args)
Set a field to a complex (built) value with prebuilt va_lists.
Definition: stringfields.h:569
const char * manager_event
Definition: manager.h:493
#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 manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:248
static void manager_event_blob_dtor(void *obj)
Definition: manager.c:9718

◆ ast_manager_get_generic_type()

struct stasis_message_type* ast_manager_get_generic_type ( void  )

Get the stasis_message_type for generic messages.

Since
12 A generic AMI message expects a JSON only payload. The payload must have the following structure: {type: s, class_type: i, event: [ {s: s}, ...] }
  • type is the AMI event type
  • class_type is the class authorization type for the event
  • event is a list of key/value tuples to be sent out in the message
Return values
Astasis_message_type for AMI messages

Referenced by __init_manager(), ast_manager_publish_event(), load_module(), manager_shutdown(), manager_subscriptions_init(), mwi_startup_event_cb(), publish_load_message_type(), startup_event_cb(), and subscription_persistence_event_cb().

◆ ast_str_append_event_header()

int ast_str_append_event_header ( struct ast_str **  fields_string,
const char *  header,
const char *  value 
)

append an event header to an ast string

Since
12
Parameters
fields_stringpointer to an ast_string pointer. It may be a pointer to a NULL ast_str pointer, in which case the ast_str will be initialized.
headerThe header being applied
valuethe value of the header
Return values
0if successful
non-zeroon failure

Definition at line 9705 of file manager.c.

References ast_str_append(), and ast_str_create.

Referenced by confbridge_talking_cb(), get_bool_header(), and meetme_stasis_cb().

9708 {
9709  if (!*fields_string) {
9710  *fields_string = ast_str_create(128);
9711  if (!*fields_string) {
9712  return -1;
9713  }
9714  }
9715 
9716  return (ast_str_append(fields_string, 0, "%s: %s\r\n", header, value) < 0) ? -1 : 0;
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
int value
Definition: syslog.c:37
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ astman_datastore_add()

int astman_datastore_add ( struct mansession s,
struct ast_datastore datastore 
)

Add a datastore to a session.

Return values
0success
non-zerofailure
Since
1.6.1

Definition at line 9666 of file manager.c.

References AST_LIST_INSERT_HEAD, mansession_session::datastores, and mansession::session.

9668 {
9669  AST_LIST_INSERT_HEAD(&s->session->datastores, datastore, entry);
9670 
9671  return 0;
struct mansession_session::mansession_datastores datastores
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710
struct mansession_session * session
Definition: manager.c:1626
Definition: search.h:40

◆ astman_datastore_find()

struct ast_datastore* astman_datastore_find ( struct mansession s,
const struct ast_datastore_info info,
const char *  uid 
)

Find a datastore on a session.

Return values
pointerto the datastore if found
NULLif not found
Since
1.6.1

Definition at line 9678 of file manager.c.

References AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, mansession_session::datastores, ast_datastore::info, NULL, mansession::session, and ast_datastore::uid.

9680 {
9681  struct ast_datastore *datastore = NULL;
9682 
9683  if (info == NULL)
9684  return NULL;
9685 
9687  if (datastore->info != info) {
9688  continue;
9689  }
9690 
9691  if (uid == NULL) {
9692  /* matched by type only */
9693  break;
9694  }
9695 
9696  if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) {
9697  /* Matched by type AND uid */
9698  break;
9699  }
9700  }
9702 
9703  return datastore;
struct mansession_session::mansession_datastores datastores
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
const char * uid
Definition: datastore.h:69
const struct ast_datastore_info * info
Definition: datastore.h:71
struct mansession_session * session
Definition: manager.c:1626
Definition: search.h:40
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528

◆ astman_datastore_remove()

int astman_datastore_remove ( struct mansession s,
struct ast_datastore datastore 
)

Remove a datastore from a session.

Return values
0success
non-zerofailure
Since
1.6.1

Definition at line 9673 of file manager.c.

References AST_LIST_REMOVE, mansession_session::datastores, and mansession::session.

9675 {
9676  return AST_LIST_REMOVE(&s->session->datastores, datastore, entry) ? 0 : -1;
struct mansession_session::mansession_datastores datastores
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
Definition: linkedlists.h:855
struct mansession_session * session
Definition: manager.c:1626
Definition: search.h:40

◆ astman_is_authed()

int astman_is_authed ( uint32_t  ident)

Determinie if a manager session ident is authenticated.

Definition at line 7551 of file manager.c.

References ao2_unlock, mansession_session::authenticated, find_session(), session, and unref_mansession().

Referenced by http_post_callback(), and static_callback().

7553 {
7554  int authed;
7555  struct mansession_session *session;
7556 
7557  if (!(session = find_session(ident, 0)))
7558  return 0;
7559 
7560  authed = (session->authenticated != 0);
7561 
7562  ao2_unlock(session);
7563  unref_mansession(session);
7564 
7565  return authed;
#define ao2_unlock(a)
Definition: astobj2.h:730
static struct mansession_session * unref_mansession(struct mansession_session *s)
Unreference manager session object. If no more references, then go ahead and delete it...
Definition: manager.c:2183
static struct mansession_session * find_session(uint32_t ident, int incinuse)
Definition: manager.c:7479
static struct ast_mansession session

◆ astman_verify_session_readpermissions()

int astman_verify_session_readpermissions ( uint32_t  ident,
int  perm 
)

Verify a session's read permissions against a permission mask.

Parameters
identsession identity
permpermission mask to verify
Return values
1if the session has the permission mask capabilities
0otherwise

Definition at line 7567 of file manager.c.

References ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, mansession_session::managerid, mansession_session::readperm, result, session, sessions, and unref_mansession().

7569 {
7570  int result = 0;
7571  struct mansession_session *session;
7572  struct ao2_container *sessions;
7573  struct ao2_iterator i;
7574 
7575  if (ident == 0) {
7576  return 0;
7577  }
7578 
7579  sessions = ao2_global_obj_ref(mgr_sessions);
7580  if (!sessions) {
7581  return 0;
7582  }
7583  i = ao2_iterator_init(sessions, 0);
7584  ao2_ref(sessions, -1);
7585  while ((session = ao2_iterator_next(&i))) {
7586  ao2_lock(session);
7587  if ((session->managerid == ident) && (session->readperm & perm)) {
7588  result = 1;
7589  ao2_unlock(session);
7590  unref_mansession(session);
7591  break;
7592  }
7593  ao2_unlock(session);
7594  unref_mansession(session);
7595  }
7597 
7598  return result;
static struct sessions sessions
#define ao2_global_obj_ref(holder)
Definition: astobj2.h:925
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define ao2_unlock(a)
Definition: astobj2.h:730
static struct mansession_session * unref_mansession(struct mansession_session *s)
Unreference manager session object. If no more references, then go ahead and delete it...
Definition: manager.c:2183
static struct ast_mansession session
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
uint32_t managerid
Definition: manager.c:1588
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
static PGresult * result
Definition: cel_pgsql.c:88
Generic container type.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.

◆ astman_verify_session_writepermissions()

int astman_verify_session_writepermissions ( uint32_t  ident,
int  perm 
)

Verify a session's write permissions against a permission mask.

Parameters
identsession identity
permpermission mask to verify
Return values
1if the session has the permission mask capabilities, otherwise 0
0otherwise

Definition at line 7600 of file manager.c.

References ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, mansession_session::managerid, result, session, sessions, unref_mansession(), and mansession_session::writeperm.

Referenced by http_post_callback().

7602 {
7603  int result = 0;
7604  struct mansession_session *session;
7605  struct ao2_container *sessions;
7606  struct ao2_iterator i;
7607 
7608  if (ident == 0) {
7609  return 0;
7610  }
7611 
7612  sessions = ao2_global_obj_ref(mgr_sessions);
7613  if (!sessions) {
7614  return 0;
7615  }
7616  i = ao2_iterator_init(sessions, 0);
7617  ao2_ref(sessions, -1);
7618  while ((session = ao2_iterator_next(&i))) {
7619  ao2_lock(session);
7620  if ((session->managerid == ident) && (session->writeperm & perm)) {
7621  result = 1;
7622  ao2_unlock(session);
7623  unref_mansession(session);
7624  break;
7625  }
7626  ao2_unlock(session);
7627  unref_mansession(session);
7628  }
7630 
7631  return result;
static struct sessions sessions
#define ao2_global_obj_ref(holder)
Definition: astobj2.h:925
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define ao2_unlock(a)
Definition: astobj2.h:730
static struct mansession_session * unref_mansession(struct mansession_session *s)
Unreference manager session object. If no more references, then go ahead and delete it...
Definition: manager.c:2183
static struct ast_mansession session
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
uint32_t managerid
Definition: manager.c:1588
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
static PGresult * result
Definition: cel_pgsql.c:88
Generic container type.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.

◆ manager_bridging_init()

int manager_bridging_init ( void  )

Initialize support for AMI channel events.

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

Definition at line 681 of file manager_bridges.c.

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

Referenced by subscribe_all().

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

◆ manager_channels_init()

int manager_channels_init ( void  )

Initialize support for AMI channel events.

Return values
0on success.
non-zeroon error.
Since
12

Definition at line 1308 of file manager_channels.c.

References 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_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_topic_all(), ast_channel_unhold_type(), ast_manager_get_message_router(), ast_manager_get_topic(), ast_register_cleanup(), channel_chanspy_start_cb(), channel_chanspy_stop_cb(), channel_dial_cb(), channel_dtmf_begin_cb(), channel_dtmf_end_cb(), channel_fax_cb(), channel_flash_cb(), channel_hangup_handler_cb(), channel_hangup_request_cb(), channel_hold_cb(), channel_mixmonitor_mute_cb(), channel_mixmonitor_start_cb(), channel_mixmonitor_stop_cb(), channel_moh_start_cb(), channel_moh_stop_cb(), channel_monitor_start_cb(), channel_monitor_stop_cb(), channel_snapshot_update(), channel_unhold_cb(), manager_channels_shutdown(), manager_topic, NULL, stasis_forward_all(), and stasis_message_router_add().

Referenced by subscribe_all().

1309 {
1310  int ret = 0;
1311  struct stasis_topic *manager_topic;
1312  struct stasis_topic *channel_topic;
1313  struct stasis_message_router *message_router;
1314 
1315  manager_topic = ast_manager_get_topic();
1316  if (!manager_topic) {
1317  return -1;
1318  }
1319  message_router = ast_manager_get_message_router();
1320  if (!message_router) {
1321  return -1;
1322  }
1323  channel_topic = ast_channel_topic_all();
1324  if (!channel_topic) {
1325  return -1;
1326  }
1327 
1328  topic_forwarder = stasis_forward_all(channel_topic, manager_topic);
1329  if (!topic_forwarder) {
1330  return -1;
1331  }
1332 
1334 
1335  /* The snapshot type has a special handler as it can result in multiple
1336  * manager events being queued due to aspects of the snapshot itself
1337  * changing.
1338  */
1339  ret |= stasis_message_router_add(message_router,
1341 
1342  ret |= stasis_message_router_add(message_router,
1344 
1345  ret |= stasis_message_router_add(message_router,
1347 
1348  ret |= stasis_message_router_add(message_router,
1350 
1351  ret |= stasis_message_router_add(message_router,
1353  NULL);
1354 
1355  ret |= stasis_message_router_add(message_router,
1357 
1358  ret |= stasis_message_router_add(message_router,
1360 
1361  ret |= stasis_message_router_add(message_router,
1363 
1364  ret |= stasis_message_router_add(message_router,
1366 
1367  ret |= stasis_message_router_add(message_router,
1369  NULL);
1370 
1371  ret |= stasis_message_router_add(message_router,
1373 
1374  ret |= stasis_message_router_add(message_router,
1376  NULL);
1377 
1378  ret |= stasis_message_router_add(message_router,
1380 
1381  ret |= stasis_message_router_add(message_router,
1383 
1384  ret |= stasis_message_router_add(message_router,
1386  NULL);
1387 
1388  ret |= stasis_message_router_add(message_router,
1390 
1391  ret |= stasis_message_router_add(message_router,
1393 
1394  ret |= stasis_message_router_add(message_router,
1396 
1397  ret |= stasis_message_router_add(message_router,
1399 
1400  /* If somehow we failed to add any routes, just shut down the whole
1401  * thing and fail it.
1402  */
1403  if (ret) {
1405  return -1;
1406  }
1407 
1408  return 0;
1409 }
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_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.
static void manager_channels_shutdown(void)
int stasis_message_router_add(struct stasis_message_router *router, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data)
Add a route to a message router.
struct stasis_message_type * ast_channel_moh_start_type(void)
Message type for starting music on hold on a channel.
static void channel_hangup_request_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
struct stasis_message_type * ast_channel_flash_type(void)
Message type for when a hook flash occurs on a channel.
static void channel_chanspy_start_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
static void channel_mixmonitor_stop_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
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
static struct stasis_topic * manager_topic
A stasis_topic that all topics AMI cares about will be forwarded to.
Definition: manager.c:1490
struct stasis_message_type * ast_channel_monitor_start_type(void)
Message type for starting monitor on a channel.
static void channel_dtmf_begin_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
static void channel_dial_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Callback processing messages for channel dialing.
struct stasis_topic * ast_channel_topic_all(void)
A topic which publishes the events for all channels.
static void channel_flash_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
struct stasis_message_type * ast_channel_monitor_stop_type(void)
Message type for stopping monitor on a channel.
static void channel_chanspy_stop_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
static void channel_monitor_start_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
static void channel_monitor_stop_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
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.
static void channel_dtmf_end_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
static void channel_hold_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
static void channel_unhold_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
struct stasis_message_router * ast_manager_get_message_router(void)
Get the stasis_message_router for AMI.
Definition: manager.c:1725
struct stasis_message_type * ast_channel_hangup_handler_type(void)
Message type for hangup handler related actions.
static void channel_mixmonitor_start_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
static void channel_moh_start_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
static void channel_mixmonitor_mute_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
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.
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition: manager.c:1720
static void channel_fax_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
static void channel_hangup_handler_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
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.
static void channel_moh_stop_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
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.
Definition: stasis.c:1578
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_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.
static void channel_snapshot_update(void *data, struct stasis_subscription *sub, struct stasis_message *message)
struct stasis_message_type * ast_channel_mixmonitor_mute_type(void)
Message type for muting or unmuting mixmonitor on a channel.

◆ manager_endpoints_init()

int manager_endpoints_init ( void  )

Initialize support for AMI endpoint events.

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

Definition at line 52 of file manager_endpoints.c.

References ast_endpoint_contact_state_type(), ast_endpoint_state_type(), ast_endpoint_topic_all_cached(), ast_register_cleanup(), endpoint_state_cb(), manager_endpoints_shutdown(), NULL, stasis_message_router_add(), and stasis_message_router_create.

Referenced by subscribe_all().

53 {
54  struct stasis_topic *endpoint_topic;
55  int ret = 0;
56 
57  if (endpoint_router) {
58  /* Already initialized */
59  return 0;
60  }
61 
63 
64  endpoint_topic = ast_endpoint_topic_all_cached();
65  if (!endpoint_topic) {
66  return -1;
67  }
68 
70 
71  if (!endpoint_router) {
72  return -1;
73  }
74 
77 
78  /* If somehow we failed to add any routes, just shut down the whole
79  * thing and fail it.
80  */
81  if (ret) {
83  return -1;
84  }
85 
86  return 0;
87 }
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.
#define NULL
Definition: resample.c:96
static void endpoint_state_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
struct stasis_topic * ast_endpoint_topic_all_cached(void)
Cached topic for all endpoint related messages.
static struct stasis_message_router * endpoint_router
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
#define stasis_message_router_create(topic)
struct stasis_message_type * ast_endpoint_state_type(void)
Message type for endpoint state changes.
static void manager_endpoints_shutdown(void)
struct stasis_message_type * ast_endpoint_contact_state_type(void)
Message type for endpoint contact state changes.

◆ manager_mwi_init()

int manager_mwi_init ( void  )

Initialize support for AMI MWI events.

Since
12
Return values
0on success
non-zeroon error

Definition at line 153 of file manager_mwi.c.

References ast_manager_get_message_router(), ast_manager_get_topic(), ast_mwi_state_type(), ast_mwi_topic_all(), ast_mwi_vm_app_type(), ast_register_cleanup(), manager_mwi_shutdown(), manager_topic, mwi_app_event_cb(), mwi_update_cb(), NULL, stasis_forward_all(), and stasis_message_router_add().

Referenced by subscribe_all().

154 {
155  int ret = 0;
156  struct stasis_topic *manager_topic;
157  struct stasis_topic *mwi_topic;
158  struct stasis_message_router *message_router;
159 
160  manager_topic = ast_manager_get_topic();
161  if (!manager_topic) {
162  return -1;
163  }
164  message_router = ast_manager_get_message_router();
165  if (!message_router) {
166  return -1;
167  }
168  mwi_topic = ast_mwi_topic_all();
169  if (!mwi_topic) {
170  return -1;
171  }
172 
173  topic_forwarder = stasis_forward_all(mwi_topic, manager_topic);
174  if (!topic_forwarder) {
175  return -1;
176  }
177 
179 
180  ret |= stasis_message_router_add(message_router,
183  NULL);
184 
185  ret |= stasis_message_router_add(message_router,
188  NULL);
189 
190  /* If somehow we failed to add any routes, just shut down the whole
191  * thing and fail it.
192  */
193  if (ret) {
195  return -1;
196  }
197 
198  return 0;
199 }
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.
static void manager_mwi_shutdown(void)
Definition: manager_mwi.c:147
struct stasis_topic * ast_mwi_topic_all(void)
Get the Stasis Message Bus API topic for MWI messages.
Definition: mwi.c:85
#define NULL
Definition: resample.c:96
static struct stasis_topic * manager_topic
A stasis_topic that all topics AMI cares about will be forwarded to.
Definition: manager.c:1490
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
static void mwi_app_event_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Generic MWI event callback used for one-off events from voicemail modules.
Definition: manager_mwi.c:55
struct stasis_message_router * ast_manager_get_message_router(void)
Get the stasis_message_router for AMI.
Definition: manager.c:1725
struct stasis_message_type * ast_mwi_state_type(void)
Get the Stasis Message Bus API message type for MWI messages.
static struct stasis_forward * topic_forwarder
The Stasis Message Bus API subscription returned by the forwarding of the MWI topic to the manager to...
Definition: manager_mwi.c:43
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition: manager.c:1720
static void mwi_update_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition: manager_mwi.c:86
struct stasis_forward * stasis_forward_all(struct stasis_topic *from_topic, struct stasis_topic *to_topic)
Create a subscription which forwards all messages from one topic to another.
Definition: stasis.c:1578
struct stasis_message_type * ast_mwi_vm_app_type(void)
Get the Stasis Message Bus API message type for voicemail application specific messages.

◆ manager_system_init()

int manager_system_init ( void  )

Initialize support for AMI system events.

Since
12
Return values
0on success
non-zeroon error

Definition at line 43 of file manager_system.c.

References ast_manager_get_message_router(), ast_manager_get_topic(), ast_register_cleanup(), ast_system_topic(), manager_system_shutdown(), manager_topic, stasis_forward_all(), and system_topic.

Referenced by subscribe_all().

44 {
46  struct stasis_topic *system_topic;
47  struct stasis_message_router *message_router;
48 
49  manager_topic = ast_manager_get_topic();
50  if (!manager_topic) {
51  return -1;
52  }
53  message_router = ast_manager_get_message_router();
54  if (!message_router) {
55  return -1;
56  }
57  system_topic = ast_system_topic();
58  if (!system_topic) {
59  return -1;
60  }
61 
62  topic_forwarder = stasis_forward_all(system_topic, manager_topic);
63  if (!topic_forwarder) {
64  return -1;
65  }
66 
68 
69  return 0;
70 }
static struct stasis_topic * system_topic
The Stasis Message Bus API topic for system level changes.
Definition: stasis_system.c:68
static void manager_system_shutdown(void)
static struct stasis_forward * topic_forwarder
The Stasis Message Bus API subscription returned by the forwarding of the system topic to the manager...
static struct stasis_topic * manager_topic
A stasis_topic that all topics AMI cares about will be forwarded to.
Definition: manager.c:1490
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
struct stasis_message_router * ast_manager_get_message_router(void)
Get the stasis_message_router for AMI.
Definition: manager.c:1725
struct stasis_topic * ast_system_topic(void)
A Stasis Message Bus API topic which publishes messages regarding system changes. ...
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition: manager.c:1720
struct stasis_forward * stasis_forward_all(struct stasis_topic *from_topic, struct stasis_topic *to_topic)
Create a subscription which forwards all messages from one topic to another.
Definition: stasis.c:1578