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 | manager_action |
| struct | manager_custom_hook |
| struct | message |
Defines | |
| #define | AMI_VERSION "1.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(a, b, c, d) ast_manager_register2(a, b, c, d, NULL) |
| External routines may register/unregister manager callbacks this way. | |
| #define | ast_manager_register_xml(a, b, c) ast_manager_register2(a, b, c, NULL, NULL) |
| Register a manager callback using XML documentation to describe the manager. | |
| #define | AST_MAX_MANHEADERS 128 |
| Export manager structures. | |
| #define | DEFAULT_MANAGER_PORT 5038 |
| #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. | |
Constant return values | |
| |
| #define | AMI_SUCCESS (0) |
| #define | AMI_DESTROY (-1) |
Manager event classes | |
| #define | EVENT_FLAG_SYSTEM (1 << 0) |
| #define | EVENT_FLAG_CALL (1 << 1) |
| #define | EVENT_FLAG_LOG (1 << 2) |
| #define | EVENT_FLAG_VERBOSE (1 << 3) |
| #define | EVENT_FLAG_COMMAND (1 << 4) |
| #define | EVENT_FLAG_AGENT (1 << 5) |
| #define | EVENT_FLAG_USER (1 << 6) |
| #define | EVENT_FLAG_CONFIG (1 << 7) |
| #define | EVENT_FLAG_DTMF (1 << 8) |
| #define | EVENT_FLAG_REPORTING (1 << 9) |
| #define | EVENT_FLAG_CDR (1 << 10) |
| #define | EVENT_FLAG_DIALPLAN (1 << 11) |
| #define | EVENT_FLAG_ORIGINATE (1 << 12) |
| #define | EVENT_FLAG_AGI (1 << 13) |
| #define | EVENT_FLAG_HOOKRESPONSE (1 << 14) |
| #define | EVENT_FLAG_CC (1 << 15) |
| #define | EVENT_FLAG_AOC (1 << 16) |
| #define | EVENT_FLAG_TEST (1 << 17) |
Typedefs | |
| typedef int(* | manager_hook_t )(int, const char *, char *) |
| Manager Helper Function. | |
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. | |
| int | ast_manager_register2 (const char *action, int authority, int(*func)(struct mansession *s, const struct message *m), const char *synopsis, const char *description) |
| Register a manager command with the manager interface. | |
| void | ast_manager_register_hook (struct manager_custom_hook *hook) |
| Add a custom hook to be called when an event is fired. | |
| int | ast_manager_unregister (char *action) |
| Unregister a registered manager command. | |
| void | ast_manager_unregister_hook (struct manager_custom_hook *hook) |
| Delete a custom hook to be called when an event is fired. | |
| 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. | |
| struct ast_datastore * | astman_datastore_find (struct mansession *s, const struct ast_datastore_info *info, const char *uid) |
| Find a datastore on a session. | |
| int | astman_datastore_remove (struct mansession *s, struct ast_datastore *datastore) |
| Remove a datastore from a session. | |
| const char * | astman_get_header (const struct message *m, char *var) |
| Get header from mananger transaction. | |
| struct ast_variable * | astman_get_variables (const struct message *m) |
| Get a linked list of the Variable: headers. | |
| int | astman_is_authed (uint32_t ident) |
| Determinie if a manager session ident is authenticated. | |
| 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_listack (struct mansession *s, const struct message *m, char *msg, char *listflag) |
| Send ack in manager list transaction. | |
| 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. | |
| int | astman_verify_session_writepermissions (uint32_t ident, int perm) |
| Verify a session's write permissions against a permission mask. | |
| int | check_manager_enabled (void) |
| Check if AMI is enabled. | |
| int | check_webmanager_enabled (void) |
| Check if AMI/HTTP is enabled. | |
| int | init_manager (void) |
| Called by Asterisk initialization. | |
| int | reload_manager (void) |
| Called by Asterisk module functions and the CLI command. | |
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)
Definition in file manager.h.
| #define AMI_SUCCESS (0) |
Definition at line 64 of file manager.h.
Referenced by manager_mute_mixmonitor().
| #define AMI_VERSION "1.1" |
Definition at line 57 of file manager.h.
Referenced by action_coresettings(), and session_do().
| #define ast_manager_event | ( | chan, | |
| category, | |||
| event, | |||
| contents, | |||
| ... | |||
| ) |
do { \ struct ast_channel *_chans[] = { chan, }; \ __ast_manager_event_multichan(category, event, 1, _chans, __FILE__, __LINE__, __PRETTY_FUNCTION__, contents , ## __VA_ARGS__); \ } while (0)
Definition at line 211 of file manager.h.
Referenced by ast_aoc_manager_event(), channel_spy(), senddialendevent(), phase_e_handler(), send_talking_event(), conf_run(), notify_new_message(), join_queue(), leave_queue(), vm_execmain(), ast_cdr_setaccount(), ast_cdr_setpeeraccount(), dahdi_ami_channel_event(), socket_process(), __ast_channel_alloc_ap(), ast_hangup(), send_dtmf_event(), __ast_change_name_nolink(), report_new_callerid(), ast_do_masquerade(), ast_setstate(), park_call_full(), parked_call_exec(), bridge_exec(), ast_monitor_start(), ast_monitor_stop(), local_ast_moh_start(), and local_ast_moh_stop().
| #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 216 of file manager.h.
Referenced by ast_aoc_manager_event(), channel_spy(), senddialevent(), local_attended_transfer(), handle_request_refer(), ast_do_masquerade(), manager_bridge_event(), ast_channel_bridge(), action_bridge(), ast_do_pickup(), bridge_exec(), and fast_originate().
| #define ast_manager_register | ( | a, | |
| b, | |||
| c, | |||
| d | |||
| ) | ast_manager_register2(a, b, c, d, NULL) |
External routines may register/unregister manager callbacks this way.
Definition at line 159 of file manager.h.
Referenced by load_module().
| #define ast_manager_register_xml | ( | a, | |
| b, | |||
| c | |||
| ) | ast_manager_register2(a, b, c, NULL, NULL) |
Register a manager callback using XML documentation to describe the manager.
Definition at line 162 of file manager.h.
Referenced by load_module(), ast_data_init(), astdb_init(), ast_features_init(), __init_manager(), and load_pbx().
| #define AST_MAX_MANHEADERS 128 |
Export manager structures.
Definition at line 91 of file manager.h.
Referenced by do_message(), generic_http_callback(), and auth_http_callback().
| #define DEFAULT_MANAGER_PORT 5038 |
Definition at line 58 of file manager.h.
Referenced by __init_manager().
| #define EVENT_FLAG_AGENT (1 << 5) |
Definition at line 75 of file manager.h.
Referenced by update_status(), ring_entry(), record_abandoned(), rna(), send_agent_complete(), try_calling(), remove_from_queue(), add_to_queue(), set_member_paused(), set_member_penalty(), load_module(), and login_exec().
| #define EVENT_FLAG_AGI (1 << 13) |
Definition at line 83 of file manager.h.
Referenced by launch_asyncagi(), agi_handle_command(), and load_module().
| #define EVENT_FLAG_AOC (1 << 16) |
Definition at line 86 of file manager.h.
Referenced by ast_aoc_manager_event(), and __init_manager().
| #define EVENT_FLAG_CALL (1 << 1) |
Definition at line 71 of file manager.h.
Referenced by channel_spy(), senddialevent(), senddialendevent(), phase_e_handler(), conf_free(), send_talking_event(), conf_run(), load_module(), notify_new_message(), join_queue(), leave_queue(), vm_execmain(), ast_cdr_setaccount(), ast_cdr_setpeeraccount(), dahdi_ami_channel_event(), socket_process(), change_hold_state(), local_attended_transfer(), handle_request_refer(), __ast_channel_alloc_ap(), ast_hangup(), __ast_change_name_nolink(), report_new_callerid(), ast_do_masquerade(), ast_setstate(), manager_bridge_event(), ast_channel_bridge(), park_call_full(), post_manager_event(), parked_call_exec(), action_bridge(), ast_do_pickup(), bridge_exec(), ast_features_init(), fast_originate(), manager_state_cb(), __init_manager(), report_fax_status(), receivefax_exec(), sendfax_exec(), ast_monitor_start(), ast_monitor_stop(), local_ast_moh_start(), and local_ast_moh_stop().
| #define EVENT_FLAG_CC (1 << 15) |
Definition at line 85 of file manager.h.
Referenced by ast_handle_cc_control_frame(), cc_caller_offered(), request_cc(), cc_active(), cc_caller_busy(), cc_recalling(), cc_complete(), cc_failed(), and cc_monitor_failed().
| #define EVENT_FLAG_CDR (1 << 10) |
Definition at line 80 of file manager.h.
Referenced by manager_log().
| #define EVENT_FLAG_COMMAND (1 << 4) |
Definition at line 74 of file manager.h.
Referenced by __init_manager().
| #define EVENT_FLAG_CONFIG (1 << 7) |
Definition at line 77 of file manager.h.
Referenced by __init_manager(), load_pbx(), and http_post_callback().
| #define EVENT_FLAG_DIALPLAN (1 << 11) |
Definition at line 81 of file manager.h.
Referenced by frame_set_var(), shared_write(), pbx_extension_helper(), pbx_builtin_setvar_helper(), and realtime_exec().
| #define EVENT_FLAG_DTMF (1 << 8) |
Definition at line 78 of file manager.h.
Referenced by send_dtmf_event().
| #define EVENT_FLAG_HOOKRESPONSE (1 << 14) |
Definition at line 84 of file manager.h.
Referenced by send_string().
| #define EVENT_FLAG_ORIGINATE (1 << 12) |
Definition at line 82 of file manager.h.
Referenced by __init_manager().
| #define EVENT_FLAG_REPORTING (1 << 9) |
Definition at line 79 of file manager.h.
Referenced by load_module(), log_jitterstats(), astdb_init(), __init_manager(), load_pbx(), ast_rtcp_write_sr(), and ast_rtcp_read().
| #define EVENT_FLAG_SYSTEM (1 << 0) |
Definition at line 70 of file manager.h.
Referenced by quit_handler(), main(), do_reload(), handle_clear_alarms(), handle_alarms(), dahdi_dnd(), gtalk_answer(), gtalk_new(), iax2_ami_channelupdate(), iax2_ack_registry(), __expire_registry(), update_registry(), socket_process(), __iax2_poke_noanswer(), load_module(), sip_new(), sip_reg_timeout(), expire_register(), parse_register_contact(), register_verify(), handle_response_invite(), handle_response_register(), handle_response_peerpoke(), sip_poke_noanswer(), sip_request_call(), reload_config(), skinny_register(), skinny_unregister(), unload_module(), astdb_init(), private_enum_init(), load_modules(), reload_logger(), logger_print_normal(), action_login(), action_originate(), __init_manager(), __analog_handle_event(), analog_handle_init_event(), and analog_dnd().
| #define EVENT_FLAG_USER (1 << 6) |
Definition at line 76 of file manager.h.
Referenced by userevent_exec(), action_userevent(), __init_manager(), aji_log_hook(), and aji_handle_presence().
| #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.
| category | Event category, matches manager authorization |
| event | Event name |
| contents | Contents of event |
Definition at line 209 of file manager.h.
Referenced by conf_free(), update_status(), ring_entry(), record_abandoned(), rna(), send_agent_complete(), try_calling(), remove_from_queue(), add_to_queue(), set_member_paused(), set_member_penalty(), frame_set_var(), userevent_exec(), quit_handler(), main(), ast_handle_cc_control_frame(), cc_caller_offered(), request_cc(), cc_active(), cc_caller_busy(), cc_recalling(), cc_complete(), cc_failed(), cc_monitor_failed(), do_reload(), manager_log(), login_exec(), handle_clear_alarms(), handle_alarms(), dahdi_dnd(), gtalk_answer(), gtalk_new(), iax2_ami_channelupdate(), iax2_ack_registry(), __expire_registry(), update_registry(), log_jitterstats(), socket_process(), __iax2_poke_noanswer(), sip_new(), change_hold_state(), sip_reg_timeout(), expire_register(), parse_register_contact(), register_verify(), handle_response_invite(), handle_response_register(), handle_response_peerpoke(), sip_poke_noanswer(), sip_request_call(), reload_config(), skinny_register(), skinny_unregister(), unload_module(), private_enum_init(), post_manager_event(), shared_write(), load_modules(), reload_logger(), logger_print_normal(), action_userevent(), manager_state_cb(), __init_manager(), pbx_extension_helper(), pbx_builtin_setvar_helper(), realtime_exec(), launch_asyncagi(), agi_handle_command(), report_fax_status(), receivefax_exec(), sendfax_exec(), aji_log_hook(), aji_handle_presence(), ast_rtcp_write_sr(), ast_rtcp_read(), __analog_handle_event(), analog_handle_init_event(), and analog_dnd().
| typedef int(* manager_hook_t)(int, const char *, char *) |
| int astman_datastore_add | ( | struct mansession * | s, |
| struct ast_datastore * | datastore | ||
| ) |
Add a datastore to a session.
| 0 | success |
| non-zero | failure |
Definition at line 6689 of file manager.c.
References AST_LIST_INSERT_HEAD, mansession::session, and mansession_session::datastores.
{
AST_LIST_INSERT_HEAD(&s->session->datastores, datastore, entry);
return 0;
}
| struct ast_datastore* astman_datastore_find | ( | struct mansession * | s, |
| const struct ast_datastore_info * | info, | ||
| const char * | uid | ||
| ) | [read] |
Find a datastore on a session.
| pointer | to the datastore if found |
| NULL | if not found |
Definition at line 6701 of file manager.c.
References AST_LIST_TRAVERSE_SAFE_BEGIN, mansession::session, mansession_session::datastores, ast_datastore::info, ast_datastore::uid, and AST_LIST_TRAVERSE_SAFE_END.
{
struct ast_datastore *datastore = NULL;
if (info == NULL)
return NULL;
AST_LIST_TRAVERSE_SAFE_BEGIN(&s->session->datastores, datastore, entry) {
if (datastore->info != info) {
continue;
}
if (uid == NULL) {
/* matched by type only */
break;
}
if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) {
/* Matched by type AND uid */
break;
}
}
AST_LIST_TRAVERSE_SAFE_END;
return datastore;
}
| int astman_datastore_remove | ( | struct mansession * | s, |
| struct ast_datastore * | datastore | ||
| ) |
Remove a datastore from a session.
| 0 | success |
| non-zero | failure |
Definition at line 6696 of file manager.c.
References AST_LIST_REMOVE, mansession::session, and mansession_session::datastores.
{
return AST_LIST_REMOVE(&s->session->datastores, datastore, entry) ? 0 : -1;
}
| int astman_is_authed | ( | uint32_t | ident | ) |
Determinie if a manager session ident is authenticated.
Definition at line 5187 of file manager.c.
References find_session(), mansession_session::authenticated, ao2_unlock, and unref_mansession().
Referenced by static_callback(), and http_post_callback().
{
int authed;
struct mansession_session *session;
if (!(session = find_session(ident, 0)))
return 0;
authed = (session->authenticated != 0);
ao2_unlock(session);
unref_mansession(session);
return authed;
}
| int astman_verify_session_readpermissions | ( | uint32_t | ident, |
| int | perm | ||
| ) |
Verify a session's read permissions against a permission mask.
| ident | session identity |
| perm | permission mask to verify |
| 1 | if the session has the permission mask capabilities |
| 0 | otherwise |
Definition at line 5203 of file manager.c.
References ao2_iterator_init(), ao2_iterator_next, ao2_lock, mansession_session::managerid, mansession_session::readperm, ao2_unlock, unref_mansession(), and ao2_iterator_destroy().
{
int result = 0;
struct mansession_session *session;
struct ao2_iterator i;
if (ident == 0) {
return 0;
}
i = ao2_iterator_init(sessions, 0);
while ((session = ao2_iterator_next(&i))) {
ao2_lock(session);
if ((session->managerid == ident) && (session->readperm & perm)) {
result = 1;
ao2_unlock(session);
unref_mansession(session);
break;
}
ao2_unlock(session);
unref_mansession(session);
}
ao2_iterator_destroy(&i);
return result;
}
| int astman_verify_session_writepermissions | ( | uint32_t | ident, |
| int | perm | ||
| ) |
Verify a session's write permissions against a permission mask.
| ident | session identity |
| perm | permission mask to verify |
| 1 | if the session has the permission mask capabilities, otherwise 0 |
| 0 | otherwise |
Definition at line 5229 of file manager.c.
References ao2_iterator_init(), ao2_iterator_next, ao2_lock, mansession_session::managerid, mansession_session::writeperm, ao2_unlock, unref_mansession(), and ao2_iterator_destroy().
Referenced by http_post_callback().
{
int result = 0;
struct mansession_session *session;
struct ao2_iterator i;
if (ident == 0) {
return 0;
}
i = ao2_iterator_init(sessions, 0);
while ((session = ao2_iterator_next(&i))) {
ao2_lock(session);
if ((session->managerid == ident) && (session->writeperm & perm)) {
result = 1;
ao2_unlock(session);
unref_mansession(session);
break;
}
ao2_unlock(session);
unref_mansession(session);
}
ao2_iterator_destroy(&i);
return result;
}
| int init_manager | ( | void | ) |
Called by Asterisk initialization.
Definition at line 6679 of file manager.c.
References __init_manager().
Referenced by main().
{
return __init_manager(0);
}
| int reload_manager | ( | void | ) |
Called by Asterisk module functions and the CLI command.
Definition at line 6684 of file manager.c.
References __init_manager().
Referenced by handle_manager_reload().
{
return __init_manager(1);
}