Asterisk - The Open Source Telephony Project  21.4.1
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"

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   "10.0.0"
 
#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.
 
#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.
 
#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_hangup_cause_validator_t) (const char *channel_name, const char *cause)
 Callback used by ast_manager_hangup_helper that will validate the cause code. More...
 
typedef void(* manager_hangup_handler_t) (struct ast_channel *chan, int causecode)
 Callback used by ast_manager_hangup_helper that will actually hangup a channel. 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.
 
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...
 
int ast_manager_hangup_helper (struct mansession *s, const struct message *m, manager_hangup_handler_t handler, manager_hangup_cause_validator_t cause_validator)
 A manager helper function that hangs up a channel using a supplied channel type specific hangup function and cause code validator. 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.
 
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 manager 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.
 
int astman_is_authed (uint32_t ident)
 Determine if a manager session ident is authenticated.
 
void astman_live_dangerously (int new_live_dangerously)
 Enable/disable the inclusion of 'dangerous' configurations outside of the ast_config_AST_CONFIG_DIR. More...
 
void astman_send_ack (struct mansession *s, const struct message *m, char *msg)
 Send ack in manager transaction.
 
void astman_send_error (struct mansession *s, const struct message *m, char *error)
 Send error in manager transaction.
 
void astman_send_error_va (struct mansession *s, const struct message *m, const char *fmt,...)
 Send error in manager transaction (with va_args support)
 
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.
 
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

#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
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,...)
Definition: manager.c:8032

Definition at line 255 of file manager.h.

#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 188 of file manager.h.

#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 202 of file manager.h.

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

#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.

Parameters
categoryEvent category, matches manager authorization
eventEvent name
contentsContents of event

Definition at line 253 of file manager.h.

Referenced by ast_logger_rotate_channel(), ast_manager_event_blob_create(), channel_dial_cb(), logger_print_normal(), mwi_app_event_cb(), and xmpp_pak_presence().

#define NO_EXTRA_FIELDS   "%s", ""

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

Definition at line 533 of file manager.h.

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

Typedef Documentation

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 455 of file manager.h.

typedef int(* manager_hangup_cause_validator_t) (const char *channel_name, const char *cause)

Callback used by ast_manager_hangup_helper that will validate the cause code.

Parameters
channel_nameMostly for displaying log messages
causeCause code string
Returns
integer cause code

Definition at line 642 of file manager.h.

typedef void(* manager_hangup_handler_t) (struct ast_channel *chan, int causecode)

Callback used by ast_manager_hangup_helper that will actually hangup a channel.

Parameters
chanThe channel to hang up
causecodeCause code to set on the channel

Definition at line 631 of file manager.h.

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 111 of file manager.h.

Function Documentation

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

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.
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
Returns
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_str_append(), ast_str_create, ast_str_set(), ast_bridge_snapshot::creator, ast_bridge_snapshot::name, ast_bridge_snapshot::num_channels, 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().

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,
248  prefix, ast_bridge_video_mode_to_string(snapshot->video_mode));
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:328
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:1139
const ast_string_field creator
Definition: bridge.h:328
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1113
const ast_string_field technology
Definition: bridge.h:328
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:3951
Support for dynamic strings.
Definition: strings.h:623
const ast_string_field name
Definition: bridge.h:328
enum ast_bridge_video_mode_type video_mode
Definition: bridge.h:341
const ast_string_field uniqueid
Definition: bridge.h:328
unsigned int num_channels
Definition: bridge.h:337
const ast_string_field subclass
Definition: bridge.h:328
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
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
Returns
ast_str* on success (must be ast_freed by caller)

Definition at line 535 of file manager_channels.c.

References ast_manager_build_channel_state_string_prefix().

Referenced by channel_dial_cb(), and mwi_app_event_cb().

537 {
539 }
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 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
Returns
ast_str* on success (must be ast_freed by caller)

Definition at line 461 of file manager_channels.c.

References ast_channel_snapshot_base::accountcode, AST_CHAN_TP_INTERNAL, ast_escape_c_alloc(), 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_channel_snapshot_dialplan::exten, ast_channel_snapshot_base::language, ast_channel_snapshot_peer::linkedid, ast_channel_snapshot::manager_vars, ast_channel_snapshot_caller::name, ast_channel_snapshot_connected::name, ast_channel_snapshot_base::name, ast_channel_snapshot_caller::number, ast_channel_snapshot_connected::number, ast_channel_snapshot::peer, ast_channel_snapshot_dialplan::priority, S_OR, ast_channel_snapshot::state, ast_channel_snapshot_base::tech_properties, and ast_channel_snapshot_base::uniqueid.

Referenced by action_coreshowchannels(), ast_manager_build_channel_state_string(), channel_dial_cb(), and manager_build_parked_call_string().

464 {
465  struct ast_str *out;
466  char *caller_name;
467  char *connected_name;
468  int res;
469 
470  if (!snapshot || (snapshot->base->tech_properties & AST_CHAN_TP_INTERNAL)) {
471  return NULL;
472  }
473 
474  out = ast_str_create(1024);
475  if (!out) {
476  return NULL;
477  }
478 
479  caller_name = ast_escape_c_alloc(snapshot->caller->name);
480  connected_name = ast_escape_c_alloc(snapshot->connected->name);
481 
482  res = ast_str_set(&out, 0,
483  "%sChannel: %s\r\n"
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"
490  "%sLanguage: %s\r\n"
491  "%sAccountCode: %s\r\n"
492  "%sContext: %s\r\n"
493  "%sExten: %s\r\n"
494  "%sPriority: %d\r\n"
495  "%sUniqueid: %s\r\n"
496  "%sLinkedid: %s\r\n",
497  prefix, snapshot->base->name,
498  prefix, snapshot->state,
499  prefix, ast_state2str(snapshot->state),
500  prefix, S_OR(snapshot->caller->number, "<unknown>"),
501  prefix, S_OR(caller_name, "<unknown>"),
502  prefix, S_OR(snapshot->connected->number, "<unknown>"),
503  prefix, S_OR(connected_name, "<unknown>"),
504  prefix, snapshot->base->language,
505  prefix, snapshot->base->accountcode,
506  prefix, snapshot->dialplan->context,
507  prefix, snapshot->dialplan->exten,
508  prefix, snapshot->dialplan->priority,
509  prefix, snapshot->base->uniqueid,
510  prefix, snapshot->peer->linkedid);
511 
512  ast_free(caller_name);
513  ast_free(connected_name);
514 
515  if (!res) {
516  ast_free(out);
517  return NULL;
518  }
519 
520  if (snapshot->manager_vars) {
521  struct ast_var_t *var;
522  char *val;
523  AST_LIST_TRAVERSE(snapshot->manager_vars, var, entries) {
524  val = ast_escape_c_alloc(var->value);
525  ast_str_append(&out, 0, "%sChanVariable: %s=%s\r\n",
526  prefix,
527  var->name, S_OR(val, ""));
528  ast_free(val);
529  }
530  }
531 
532  return out;
533 }
struct ast_channel_snapshot_base * base
Channels with this particular technology are an implementation detail of Asterisk and should generall...
Definition: channel.h:971
const ast_string_field name
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:1139
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:1113
const ast_string_field context
const ast_string_field exten
struct ast_channel_snapshot_caller * caller
struct varshead * manager_vars
Support for dynamic strings.
Definition: strings.h:623
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
char * ast_escape_c_alloc(const char *s)
Escape standard 'C' sequences in the given string.
Definition: utils.c:2140
enum ast_channel_state state
const ast_string_field language
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:80
struct ast_channel_snapshot_peer * peer
const char * ast_state2str(enum ast_channel_state state)
Gives the string form of a given channel state.
Definition: channel.c:636
struct ast_channel_snapshot_connected * connected
const ast_string_field name
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
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_event_blob object.
Return values
NULLon error.

Definition at line 10563 of file manager.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_ref, ast_string_field_init, ast_string_field_ptr_build_va, ast_manager_event_blob::event_flags, ast_manager_event_blob::extra_fields, manager_event, and ast_manager_event_blob::manager_event.

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

10569 {
10570  struct ast_manager_event_blob *ev;
10571  va_list argp;
10572 
10573  ast_assert(extra_fields_fmt != NULL);
10574  ast_assert(manager_event != NULL);
10575 
10576  ev = ao2_alloc_options(sizeof(*ev), manager_event_blob_dtor, AO2_ALLOC_OPT_LOCK_NOLOCK);
10577  if (!ev) {
10578  return NULL;
10579  }
10580 
10581  if (ast_string_field_init(ev, 20)) {
10582  ao2_ref(ev, -1);
10583  return NULL;
10584  }
10585 
10587  ev->event_flags = event_flags;
10588 
10589  va_start(argp, extra_fields_fmt);
10590  ast_string_field_ptr_build_va(ev, &ev->extra_fields, extra_fields_fmt, argp);
10591  va_end(argp);
10592 
10593  return ev;
Struct containing info for an AMI event to send out.
Definition: manager.h:502
const ast_string_field extra_fields
Definition: manager.h:507
#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:573
const char * manager_event
Definition: manager.h:504
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:253
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
Returns
A stasis_message_type for AMI messages

Referenced by ast_manager_publish_event(), manager_subscriptions_init(), and publish_load_message_type().

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 10541 of file manager.c.

References ast_str_append(), and ast_str_create.

10544 {
10545  if (!*fields_string) {
10546  *fields_string = ast_str_create(128);
10547  if (!*fields_string) {
10548  return -1;
10549  }
10550  }
10551 
10552  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:1139
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
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 10502 of file manager.c.

References AST_LIST_INSERT_HEAD, and mansession_session::datastores.

10504 {
10505  AST_LIST_INSERT_HEAD(&s->session->datastores, datastore, entry);
10506 
10507  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:711
Definition: search.h:40
struct ast_datastore* astman_datastore_find ( struct mansession s,
const struct ast_datastore_info info,
const char *  uid 
)

Find a datastore on a session.

Returns
pointer to the datastore if found
Return values
NULLif not found
Since
1.6.1

Definition at line 10514 of file manager.c.

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

10516 {
10517  struct ast_datastore *datastore = NULL;
10518 
10519  if (info == NULL)
10520  return NULL;
10521 
10522  AST_LIST_TRAVERSE_SAFE_BEGIN(&s->session->datastores, datastore, entry) {
10523  if (datastore->info != info) {
10524  continue;
10525  }
10526 
10527  if (uid == NULL) {
10528  /* matched by type only */
10529  break;
10530  }
10531 
10532  if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) {
10533  /* Matched by type AND uid */
10534  break;
10535  }
10536  }
10538 
10539  return datastore;
struct mansession_session::mansession_datastores datastores
Structure for a data store object.
Definition: datastore.h:64
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:615
const char * uid
Definition: datastore.h:65
const struct ast_datastore_info * info
Definition: datastore.h:67
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:529
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 10509 of file manager.c.

References AST_LIST_REMOVE, and mansession_session::datastores.

10511 {
10512  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:856
Definition: search.h:40
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 8364 of file manager.c.

References ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_ref, mansession_session::managerid, mansession_session::readperm, and unref_mansession().

8366 {
8367  int result = 0;
8368  struct mansession_session *session;
8369  struct ao2_container *sessions;
8370  struct ao2_iterator i;
8371 
8372  if (ident == 0) {
8373  return 0;
8374  }
8375 
8376  sessions = ao2_global_obj_ref(mgr_sessions);
8377  if (!sessions) {
8378  return 0;
8379  }
8380  i = ao2_iterator_init(sessions, 0);
8381  ao2_ref(sessions, -1);
8382  while ((session = ao2_iterator_next(&i))) {
8383  ao2_lock(session);
8384  if ((session->managerid == ident) && (session->readperm & perm)) {
8385  result = 1;
8386  ao2_unlock(session);
8387  unref_mansession(session);
8388  break;
8389  }
8390  ao2_unlock(session);
8391  unref_mansession(session);
8392  }
8394 
8395  return result;
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
Definition: astobj2.h:918
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
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:2343
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
uint32_t managerid
Definition: manager.c:1747
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821
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.
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 8397 of file manager.c.

References ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_ref, mansession_session::managerid, unref_mansession(), and mansession_session::writeperm.

8399 {
8400  int result = 0;
8401  struct mansession_session *session;
8402  struct ao2_container *sessions;
8403  struct ao2_iterator i;
8404 
8405  if (ident == 0) {
8406  return 0;
8407  }
8408 
8409  sessions = ao2_global_obj_ref(mgr_sessions);
8410  if (!sessions) {
8411  return 0;
8412  }
8413  i = ao2_iterator_init(sessions, 0);
8414  ao2_ref(sessions, -1);
8415  while ((session = ao2_iterator_next(&i))) {
8416  ao2_lock(session);
8417  if ((session->managerid == ident) && (session->writeperm & perm)) {
8418  result = 1;
8419  ao2_unlock(session);
8420  unref_mansession(session);
8421  break;
8422  }
8423  ao2_unlock(session);
8424  unref_mansession(session);
8425  }
8427 
8428  return result;
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
Definition: astobj2.h:918
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
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:2343
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
uint32_t managerid
Definition: manager.c:1747
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821
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.
int manager_bridging_init ( void  )

Initialize support for AMI channel events.

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

Definition at line 683 of file manager_bridges.c.

References ast_bridge_topic_all(), ast_manager_get_message_router(), ast_manager_get_topic(), ast_manager_register_xml_core, ast_register_cleanup(), manager_topic, stasis_forward_all(), and stasis_message_router_add().

684 {
685  int ret = 0;
686  struct stasis_topic *manager_topic;
687  struct stasis_topic *bridge_topic;
688 
689  if (bridge_state_router) {
690  /* Already initialized */
691  return 0;
692  }
693 
694  ast_register_cleanup(manager_bridging_cleanup);
695 
696  manager_topic = ast_manager_get_topic();
697  if (!manager_topic) {
698  return -1;
699  }
700 
701  bridge_topic = ast_bridge_topic_all();
702  if (!bridge_topic) {
703  return -1;
704  }
705 
706  topic_forwarder = stasis_forward_all(bridge_topic, manager_topic);
707  if (!topic_forwarder) {
708  return -1;
709  }
710 
712  if (!bridge_state_router) {
713  return -1;
714  }
715 
717  ast_bridge_snapshot_type(), bridge_snapshot_update, NULL);
718 
720  ast_bridge_merge_message_type(), bridge_merge_cb, NULL);
721 
723  ast_channel_entered_bridge_type(), channel_enter_cb, NULL);
724 
726  ast_channel_left_bridge_type(), channel_leave_cb, NULL);
727 
728  ret |= ast_manager_register_xml_core("BridgeList", 0, manager_bridges_list);
729  ret |= ast_manager_register_xml_core("BridgeInfo", 0, manager_bridge_info);
730  ret |= ast_manager_register_xml_core("BridgeDestroy", 0, manager_bridge_destroy);
731  ret |= ast_manager_register_xml_core("BridgeKick", 0, manager_bridge_kick);
732 
733  /* If somehow we failed to add any routes, just shut down the whole
734  * thing and fail it.
735  */
736  if (ret) {
737  manager_bridging_cleanup();
738  return -1;
739  }
740 
741  return 0;
742 }
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_topic * ast_bridge_topic_all(void)
A topic which publishes the events for all bridges.
static struct stasis_topic * manager_topic
A stasis_topic that all topics AMI cares about will be forwarded to.
Definition: manager.c:1644
#define ast_manager_register_xml_core(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:202
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:1885
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition: manager.c:1880
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
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_snapshot_type(), ast_channel_topic_all(), ast_channel_unhold_type(), ast_channel_wink_type(), ast_manager_get_message_router(), ast_manager_get_topic(), ast_register_cleanup(), channel_dial_cb(), manager_topic, stasis_forward_all(), and stasis_message_router_add().

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 
1333  ast_register_cleanup(manager_channels_shutdown);
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,
1340  ast_channel_snapshot_type(), channel_snapshot_update, NULL);
1341 
1342  ret |= stasis_message_router_add(message_router,
1343  ast_channel_dtmf_begin_type(), channel_dtmf_begin_cb, NULL);
1344 
1345  ret |= stasis_message_router_add(message_router,
1346  ast_channel_dtmf_end_type(), channel_dtmf_end_cb, NULL);
1347 
1348  ret |= stasis_message_router_add(message_router,
1349  ast_channel_flash_type(), channel_flash_cb, NULL);
1350 
1351  ret |= stasis_message_router_add(message_router,
1352  ast_channel_wink_type(), channel_wink_cb, NULL);
1353 
1354  ret |= stasis_message_router_add(message_router,
1355  ast_channel_hangup_request_type(), channel_hangup_request_cb,
1356  NULL);
1357 
1358  ret |= stasis_message_router_add(message_router,
1360 
1361  ret |= stasis_message_router_add(message_router,
1362  ast_channel_hold_type(), channel_hold_cb, NULL);
1363 
1364  ret |= stasis_message_router_add(message_router,
1365  ast_channel_unhold_type(), channel_unhold_cb, NULL);
1366 
1367  ret |= stasis_message_router_add(message_router,
1368  ast_channel_fax_type(), channel_fax_cb, NULL);
1369 
1370  ret |= stasis_message_router_add(message_router,
1371  ast_channel_chanspy_start_type(), channel_chanspy_start_cb,
1372  NULL);
1373 
1374  ret |= stasis_message_router_add(message_router,
1375  ast_channel_chanspy_stop_type(), channel_chanspy_stop_cb, NULL);
1376 
1377  ret |= stasis_message_router_add(message_router,
1378  ast_channel_hangup_handler_type(), channel_hangup_handler_cb,
1379  NULL);
1380 
1381  ret |= stasis_message_router_add(message_router,
1382  ast_channel_moh_start_type(), channel_moh_start_cb, NULL);
1383 
1384  ret |= stasis_message_router_add(message_router,
1385  ast_channel_moh_stop_type(), channel_moh_stop_cb, NULL);
1386 
1387  ret |= stasis_message_router_add(message_router,
1388  ast_channel_mixmonitor_start_type(), channel_mixmonitor_start_cb, NULL);
1389 
1390  ret |= stasis_message_router_add(message_router,
1391  ast_channel_mixmonitor_stop_type(), channel_mixmonitor_stop_cb, NULL);
1392 
1393  ret |= stasis_message_router_add(message_router,
1394  ast_channel_mixmonitor_mute_type(), channel_mixmonitor_mute_cb, NULL);
1395 
1396  /* If somehow we failed to add any routes, just shut down the whole
1397  * thing and fail it.
1398  */
1399  if (ret) {
1400  manager_channels_shutdown();
1401  return -1;
1402  }
1403 
1404  return 0;
1405 }
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.
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.
struct stasis_message_type * ast_channel_wink_type(void)
Message type for when a wink occurs on a channel.
struct stasis_message_type * ast_channel_flash_type(void)
Message type for when a hook flash occurs on a channel.
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.
Definition: manager.c:1644
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.
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_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_router * ast_manager_get_message_router(void)
Get the stasis_message_router for AMI.
Definition: manager.c:1885
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.
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition: manager.c:1880
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.
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.
struct stasis_message_type * ast_channel_mixmonitor_mute_type(void)
Message type for muting or unmuting mixmonitor on a channel.
int manager_endpoints_init ( void  )

Initialize support for AMI endpoint events.

Return values
0on success.
non-zeroon 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(), and stasis_message_router_add().

53 {
54  struct stasis_topic *endpoint_topic;
55  int ret = 0;
56 
57  if (endpoint_router) {
58  /* Already initialized */
59  return 0;
60  }
61 
62  ast_register_cleanup(manager_endpoints_shutdown);
63 
64  endpoint_topic = ast_endpoint_topic_all_cached();
65  if (!endpoint_topic) {
66  return -1;
67  }
68 
69  endpoint_router = stasis_message_router_create(endpoint_topic);
70 
71  if (!endpoint_router) {
72  return -1;
73  }
74 
75  ret |= stasis_message_router_add(endpoint_router, ast_endpoint_state_type(), endpoint_state_cb, NULL);
76  ret |= stasis_message_router_add(endpoint_router, ast_endpoint_contact_state_type(), endpoint_state_cb, NULL);
77 
78  /* If somehow we failed to add any routes, just shut down the whole
79  * thing and fail it.
80  */
81  if (ret) {
82  manager_endpoints_shutdown();
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.
struct stasis_topic * ast_endpoint_topic_all_cached(void)
Cached topic for all endpoint related messages.
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_endpoint_state_type(void)
Message type for endpoint state changes.
struct stasis_message_type * ast_endpoint_contact_state_type(void)
Message type for endpoint contact state changes.
int manager_mwi_init ( void  )

Initialize support for AMI MWI events.

Since
12
Return values
0on success
non-zeroon error

Definition at line 155 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_topic, mwi_app_event_cb(), stasis_forward_all(), and stasis_message_router_add().

156 {
157  int ret = 0;
158  struct stasis_topic *manager_topic;
159  struct stasis_topic *mwi_topic;
160  struct stasis_message_router *message_router;
161 
162  manager_topic = ast_manager_get_topic();
163  if (!manager_topic) {
164  return -1;
165  }
166  message_router = ast_manager_get_message_router();
167  if (!message_router) {
168  return -1;
169  }
170  mwi_topic = ast_mwi_topic_all();
171  if (!mwi_topic) {
172  return -1;
173  }
174 
175  topic_forwarder = stasis_forward_all(mwi_topic, manager_topic);
176  if (!topic_forwarder) {
177  return -1;
178  }
179 
180  ast_register_cleanup(manager_mwi_shutdown);
181 
182  ret |= stasis_message_router_add(message_router,
184  mwi_update_cb,
185  NULL);
186 
187  ret |= stasis_message_router_add(message_router,
190  NULL);
191 
192  /* If somehow we failed to add any routes, just shut down the whole
193  * thing and fail it.
194  */
195  if (ret) {
196  manager_mwi_shutdown();
197  return -1;
198  }
199 
200  return 0;
201 }
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 struct stasis_topic * manager_topic
A stasis_topic that all topics AMI cares about will be forwarded to.
Definition: manager.c:1644
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_mwi_state_type(void)
Get the Stasis Message Bus API message type for MWI messages.
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:1885
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:1880
struct stasis_topic * ast_mwi_topic_all(void)
Get the Stasis Message Bus API topic for MWI messages.
Definition: mwi.c:89
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.
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_topic, stasis_forward_all(), and system_topic.

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 
67  ast_register_cleanup(manager_system_shutdown);
68 
69  return 0;
70 }
struct stasis_topic * ast_system_topic(void)
A Stasis Message Bus API topic which publishes messages regarding system changes. ...
static struct stasis_topic * system_topic
The Stasis Message Bus API topic for system level changes.
Definition: stasis_system.c:68
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:1644
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:1885
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition: manager.c:1880
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