Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Enumerations | Functions | Variables
AMI functions

Data Structures

struct  actions
 list of actions registered More...
 
struct  all_events
 
struct  ast_manager_user
 user descriptor, as read from the config file. More...
 
struct  eventqent
 
struct  fast_originate_helper
 helper function for originate More...
 
struct  manager_hooks
 list of hooks registered More...
 
struct  mansession
 In case you didn't read that giant block of text above the mansession_session struct, the struct mansession is named this solely to keep the API the same in Asterisk. This structure really represents data that is different from Manager action to Manager action. The mansession_session pointer contained within points to session-specific data. More...
 
struct  mansession_session
 
struct  permalias
 
struct  users
 list of users found in the config file More...
 

Macros

#define any_manager_listeners(sessions)   ((sessions && ao2_container_count(sessions)) || !AST_RWLIST_EMPTY(&manager_hooks))
 
#define ASTMAN_APPEND_BUF_INITSIZE   256
 initial allocated size for the astman_append_buf and astman_send_*_va More...
 
#define DEFAULT_REALM   "asterisk"
 
#define EVENT_FLAG_SHUTDOWN   -1
 Fake event class used to end sessions at shutdown. More...
 
#define GET_HEADER_FIRST_MATCH   0
 
#define GET_HEADER_LAST_MATCH   1
 
#define GET_HEADER_SKIP_EMPTY   2
 
#define MANAGER_EVENT_BUF_INITSIZE   256
 
#define manager_event_sessions(sessions, category, event, contents, ...)   __manager_event_sessions(sessions, category, event, 0, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__, contents , ## __VA_ARGS__)
 
#define MAX_AUTH_PERM_STRING   150
 
#define MAX_BLACKLIST_CMD_LEN   2
 Descriptor for a manager session, either on the AMI socket or over HTTP. More...
 
#define MAX_VARS   128
 
#define MGR_SHOW_TERMINAL_WIDTH   80
 
#define MSG_MOREDATA   ((char *)astman_send_response)
 

Enumerations

enum  add_filter_result { FILTER_SUCCESS, FILTER_ALLOC_FAILED, FILTER_COMPILE_FAIL }
 
enum  error_type {
  UNKNOWN_ACTION = 1, UNKNOWN_CATEGORY, UNSPECIFIED_CATEGORY, UNSPECIFIED_ARGUMENT,
  FAILURE_ALLOCATION, FAILURE_NEWCAT, FAILURE_DELCAT, FAILURE_EMPTYCAT,
  FAILURE_UPDATE, FAILURE_DELETE, FAILURE_APPEND, FAILURE_TEMPLATE
}
 
enum  mansession_message_parsing { MESSAGE_OKAY, MESSAGE_LINE_TOO_LONG }
 

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 *fmt,...)
 
static const char * __astman_get_header (const struct message *m, char *var, int mode)
 Return a matching header value. More...
 
static void __init_astman_append_buf (void)
 thread local buffer for astman_append More...
 
static void __init_manager_event_buf (void)
 
static void __init_userevent_buf (void)
 
static int __manager_event_sessions (struct ao2_container *sessions, int category, const char *event, int chancount, struct ast_channel **chans, const char *file, int line, const char *func, const char *fmt,...)
 
static int __manager_event_sessions_va (struct ao2_container *sessions, int category, const char *event, int chancount, struct ast_channel **chans, const char *file, int line, const char *func, const char *fmt, va_list ap)
 
static void acl_change_stasis_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void acl_change_stasis_subscribe (void)
 
static void acl_change_stasis_unsubscribe (void)
 
static int action_aocmessage (struct mansession *s, const struct message *m)
 
static int action_atxfer (struct mansession *s, const struct message *m)
 
static int action_blind_transfer (struct mansession *s, const struct message *m)
 
static int action_cancel_atxfer (struct mansession *s, const struct message *m)
 
static int action_challenge (struct mansession *s, const struct message *m)
 
static int action_command (struct mansession *s, const struct message *m)
 Manager command "command" - execute CLI command. More...
 
static int action_coresettings (struct mansession *s, const struct message *m)
 Show PBX core settings information. More...
 
static int action_coreshowchannels (struct mansession *s, const struct message *m)
 Manager command "CoreShowChannels" - List currently defined channels and some information about them. More...
 
static int action_corestatus (struct mansession *s, const struct message *m)
 Show PBX core status information. More...
 
static int action_createconfig (struct mansession *s, const struct message *m)
 
static void action_destroy (void *obj)
 
static int action_events (struct mansession *s, const struct message *m)
 
static int action_extensionstate (struct mansession *s, const struct message *m)
 
static int action_filter (struct mansession *s, const struct message *m)
 Manager command to add an event filter to a manager session. More...
 
static struct manager_actionaction_find (const char *name)
 
static int action_getconfig (struct mansession *s, const struct message *m)
 
static int action_getconfigjson (struct mansession *s, const struct message *m)
 
static int action_getvar (struct mansession *s, const struct message *m)
 
static int action_hangup (struct mansession *s, const struct message *m)
 
static int action_listcategories (struct mansession *s, const struct message *m)
 
static int action_listcommands (struct mansession *s, const struct message *m)
 
static int action_loggerrotate (struct mansession *s, const struct message *m)
 Manager command "LoggerRotate" - reloads and rotates the logger in the same manner as the CLI command 'logger rotate'. More...
 
static int action_login (struct mansession *s, const struct message *m)
 
static int action_logoff (struct mansession *s, const struct message *m)
 
static int action_mailboxcount (struct mansession *s, const struct message *m)
 
static int action_mailboxstatus (struct mansession *s, const struct message *m)
 
static int action_originate (struct mansession *s, const struct message *m)
 
static int action_ping (struct mansession *s, const struct message *m)
 
static int action_presencestate (struct mansession *s, const struct message *m)
 
static int action_redirect (struct mansession *s, const struct message *m)
 action_redirect: The redirect manager command More...
 
static int action_reload (struct mansession *s, const struct message *m)
 Send a reload event. More...
 
static int action_sendtext (struct mansession *s, const struct message *m)
 
static int action_setvar (struct mansession *s, const struct message *m)
 
static int action_status (struct mansession *s, const struct message *m)
 Manager "status" command to show channels. More...
 
static int action_timeout (struct mansession *s, const struct message *m)
 
static int action_updateconfig (struct mansession *s, const struct message *m)
 
static int action_userevent (struct mansession *s, const struct message *m)
 
static int action_waitevent (struct mansession *s, const struct message *m)
 
static struct eventqentadvance_event (struct eventqent *e)
 
static AO2_GLOBAL_OBJ_STATIC (mgr_sessions)
 
static AO2_GLOBAL_OBJ_STATIC (event_docs)
 A container of event documentation nodes. More...
 
static int aocmessage_get_unit_entry (const struct message *m, struct ast_aoc_unit_entry *entry, unsigned int entry_num)
 
static void append_channel_vars (struct ast_str **pbuf, struct ast_channel *chan)
 
static int append_event (const char *str, int category)
 events are appended to a queue from where they can be dispatched to clients. More...
 
int ast_hook_send_action (struct manager_custom_hook *hook, const char *msg)
 access for hooks to send action messages to ami More...
 
static int ast_instring (const char *bigstr, const char *smallstr, const char delim)
 
int ast_manager_check_enabled (void)
 Check if AMI is enabled. 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 auth, int(*func)(struct mansession *s, const struct message *m), struct ast_module *module, const char *synopsis, const char *description)
 register a new command with manager, including online help. This is the preferred way to register a manager command More...
 
void ast_manager_register_hook (struct manager_custom_hook *hook)
 Add a custom hook to be called when an event is fired. More...
 
static int ast_manager_register_struct (struct manager_action *act)
 
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)
 support functions to register/unregister AMI action handlers, 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_webmanager_check_enabled (void)
 Check if AMI/HTTP is enabled. More...
 
void astman_append (struct mansession *s, const char *fmt,...)
 
static void astman_append_headers (struct message *m, const struct ast_variable *params)
 Append additional headers into the message structure from params. More...
 
static void astman_append_json (struct mansession *s, const char *str)
 
static void astman_flush (struct mansession *s, struct ast_str *buf)
 
static void astman_free_headers (struct message *m)
 Free headers inside message structure, but not the message structure itself. More...
 
const char * astman_get_header (const struct message *m, char *var)
 Return the first matching variable from an array. 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...
 
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...
 
static void astman_send_list_complete (struct mansession *s, const struct message *m, const char *event_name, int count)
 
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...
 
static struct ast_strastman_send_list_complete_start_common (struct mansession *s, const struct message *m, const char *event_name, int count)
 
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...
 
static void astman_send_response_full (struct mansession *s, const struct message *m, char *resp, char *msg, char *listflag)
 send a response with an optional message, and terminate it with an empty line. m is used only to grab the 'ActionID' field. More...
 
static void astman_start_ack (struct mansession *s, const struct message *m)
 
static int authenticate (struct mansession *s, const struct message *m)
 
static const char * authority_to_str (int authority, struct ast_str **res)
 Convert authority code to a list of options. Note that the EVENT_FLAG_ALL authority will always be returned. More...
 
static int blackfilter_cmp_fn (void *obj, void *arg, void *data, int flags)
 
static struct mansession_sessionbuild_mansession (const struct ast_sockaddr *addr)
 Allocate manager session structure and add it to the list of sessions. More...
 
static int check_blacklist (const char *cmd)
 
static int check_manager_session_inuse (const char *name)
 
static void destroy_fast_originate_helper (struct fast_originate_helper *doomed)
 
static int do_message (struct mansession *s)
 
static void event_filter_destructor (void *obj)
 
static void * fast_originate (void *data)
 
static int function_capable_string_allowed_with_auths (const char *evaluating, int writepermlist)
 Checks to see if a string which can be used to evaluate functions should be rejected. More...
 
static void generate_status (struct mansession *s, struct ast_channel *chan, char **vars, int varc, int all_variables, char *id_text, int *count)
 
static int get_input (struct mansession *s, char *output)
 
static struct ast_manager_userget_manager_by_name_locked (const char *name)
 
static int get_perm (const char *instr)
 
static struct eventqentgrab_last (void)
 
static char * handle_manager_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command manager reload. More...
 
static char * handle_mandebug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static void handle_parse_error (struct mansession *s, struct message *m, char *error)
 
static char * handle_showmanager (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_showmanagers (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_showmancmd (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_showmancmds (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command manager list commands. More...
 
static char * handle_showmanconn (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command manager list connected. More...
 
static char * handle_showmaneventq (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command manager list eventq. More...
 
static enum error_type handle_updates (struct mansession *s, const struct message *m, struct ast_config *cfg, const char *dfn)
 helper function for action_updateconfig More...
 
static void json_escape (char *out, const char *in)
 
static void log_action (const struct message *m, const char *action)
 
static struct ast_variableman_do_variable_value (struct ast_variable *head, const char *hdr_val)
 
static enum add_filter_result manager_add_filter (const char *filter_pattern, struct ao2_container *whitefilters, struct ao2_container *blackfilters)
 Add an event filter to a manager session. More...
 
static void manager_default_msg_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static int manager_displayconnects (struct mansession_session *session)
 Get displayconnects config option. More...
 
static void manager_generic_msg_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void manager_json_array_with_key (struct ast_json *obj, const char *key, size_t index, struct ast_str **res, key_exclusion_cb exclusion_cb)
 
static void manager_json_obj_with_key (struct ast_json *obj, const char *key, const char *parent_key, struct ast_str **res, key_exclusion_cb exclusion_cb)
 
static void manager_json_to_ast_str (struct ast_json *obj, const char *key, struct ast_str **res, key_exclusion_cb exclusion_cb)
 
static void manager_json_value_str_append (struct ast_json *value, const char *key, struct ast_str **res)
 
static int manager_modulecheck (struct mansession *s, const struct message *m)
 Manager function to check if module is loaded. More...
 
static int manager_moduleload (struct mansession *s, const struct message *m)
 
static int manager_state_cb (const char *context, const char *exten, struct ast_state_cb_info *info, void *data)
 
static int mansession_cmp_fn (void *obj, void *arg, int flags)
 
static enum ast_transport mansession_get_transport (const struct mansession *s)
 
static void mansession_lock (struct mansession *s)
 Lock the 'mansession' structure. More...
 
static void mansession_unlock (struct mansession *s)
 Unlock the 'mansession' structure. More...
 
static int match_filter (struct mansession *s, char *eventdata)
 
static void print_event_instance (struct ast_cli_args *a, struct ast_xml_doc_item *instance)
 
static int process_events (struct mansession *s)
 
static int process_message (struct mansession *s, const struct message *m)
 Process an AMI message, performing desired action. Return 0 on success, -1 on error that require the session to be destroyed. More...
 
static void purge_events (void)
 
static void purge_sessions (int n_max)
 remove at most n_max stale session from the list. More...
 
static int queue_read_action_payload (struct ast_channel *chan, const unsigned char *payload, size_t payload_size, enum ast_frame_read_action action)
 Queue a given read action containing a payload onto a channel. More...
 
static int queue_sendtext (struct ast_channel *chan, const char *body)
 Queue a read action to send a text message. More...
 
static int queue_sendtext_data (struct ast_channel *chan, const char *body, const char *content_type)
 Queue a read action to send a text data message. More...
 
static int reload_module (void)
 
static void report_auth_success (const struct mansession *s)
 
static void report_failed_acl (const struct mansession *s, const char *username)
 
static void report_failed_challenge_response (const struct mansession *s, const char *response, const char *expected_response)
 
static void report_inval_password (const struct mansession *s, const char *username)
 
static void report_invalid_user (const struct mansession *s, const char *username)
 
static void report_req_bad_format (const struct mansession *s, const char *action)
 
static void report_req_not_allowed (const struct mansession *s, const char *action)
 
static void report_session_limit (const struct mansession *s)
 
static int send_string (struct mansession *s, char *string)
 
static void session_destroy (struct mansession_session *s)
 
static void session_destructor (void *obj)
 
static void * session_do (void *data)
 The body of the individual manager session. Call get_input() to read one line at a time (or be woken up on new events), collect the lines in a message until found an empty line, and execute the request. In any case, deliver events asynchronously through process_events() (called from here if no line is available, or at the end of process_message(). ) More...
 
static int set_eventmask (struct mansession *s, const char *eventmask)
 Rather than braindead on,off this now can also accept a specific int mask value or a ',' delim list of mask strings (the same as manager.conf) -anthm. More...
 
static int strings_to_mask (const char *string)
 
static struct mansession_sessionunref_mansession (struct mansession_session *s)
 Unreference manager session object. If no more references, then go ahead and delete it. More...
 
static const char * user_authority_to_str (int authority, struct ast_str **res)
 Convert authority code to a list of options for a user. This will only display those authority codes that have an explicit match on authority. More...
 
static int whitefilter_cmp_fn (void *obj, void *arg, void *data, int flags)
 

Variables

static struct stasis_subscriptionacl_change_sub
 
static struct actions actions = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
static struct all_events all_events = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
static int allowmultiplelogin = 1
 
static struct ast_threadstorage astman_append_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_astman_append_buf , .custom_init = NULL , }
 
static int authlimit
 
static int authtimeout
 
static int broken_events_action = 0
 
struct {
   const char *   words [AST_MAX_CMD_LEN]
 
command_blacklist []
 
static int displayconnects = 1
 
static char global_realm [MAXHOSTNAMELEN]
 
static int httptimeout = 60
 
static char * manager_channelvars
 
static int manager_debug = 0
 
static int manager_enabled = 0
 
static struct ast_threadstorage manager_event_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_manager_event_buf , .custom_init = NULL , }
 
static struct manager_hooks manager_hooks = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
static struct stasis_topicmanager_topic
 A stasis_topic that all topics AMI cares about will be forwarded to. More...
 
static const struct permalias perms []
 
static struct stasis_forwardrtp_topic_forwarder
 The stasis_subscription for forwarding the RTP topic to the AMI topic. More...
 
static struct stasis_forwardsecurity_topic_forwarder
 The stasis_subscription for forwarding the Security topic to the AMI topic. More...
 
static struct stasis_message_routerstasis_router
 The stasis_message_router for all Stasis Message Bus API messages. More...
 
static int subscribed = 0
 
static struct stasis_forwardtest_suite_forwarder
 The stasis_subscription for forwarding the Test topic to the AMI topic. More...
 
static int timestampevents
 
static int unauth_sessions = 0
 
static struct ast_threadstorage userevent_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_userevent_buf , .custom_init = NULL , }
 
static struct users users = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
static int webmanager_enabled = 0
 
 STASIS_MESSAGE_TYPE_DEFN (ast_manager_get_generic_type)
 Define AMI message types. More...
 

Detailed Description

Macro Definition Documentation

◆ any_manager_listeners

#define any_manager_listeners (   sessions)    ((sessions && ao2_container_count(sessions)) || !AST_RWLIST_EMPTY(&manager_hooks))

◆ ASTMAN_APPEND_BUF_INITSIZE

#define ASTMAN_APPEND_BUF_INITSIZE   256

initial allocated size for the astman_append_buf and astman_send_*_va

Definition at line 3066 of file manager.c.

Referenced by astman_append(), astman_send_error_va(), astman_send_list_complete_start_common(), and astman_send_response_full().

◆ DEFAULT_REALM

#define DEFAULT_REALM   "asterisk"

Definition at line 1483 of file manager.c.

Referenced by manager_set_defaults().

◆ EVENT_FLAG_SHUTDOWN

#define EVENT_FLAG_SHUTDOWN   -1

Fake event class used to end sessions at shutdown.

Definition at line 1511 of file manager.c.

Referenced by __manager_event_sessions_va(), authority_to_str(), manager_shutdown(), and process_events().

◆ GET_HEADER_FIRST_MATCH

#define GET_HEADER_FIRST_MATCH   0

Definition at line 2766 of file manager.c.

Referenced by astman_get_header().

◆ GET_HEADER_LAST_MATCH

#define GET_HEADER_LAST_MATCH   1

Definition at line 2767 of file manager.c.

Referenced by __astman_get_header().

◆ GET_HEADER_SKIP_EMPTY

#define GET_HEADER_SKIP_EMPTY   2

Definition at line 2768 of file manager.c.

Referenced by __astman_get_header(), and process_message().

◆ MANAGER_EVENT_BUF_INITSIZE

#define MANAGER_EVENT_BUF_INITSIZE   256

Definition at line 7110 of file manager.c.

Referenced by __manager_event_sessions_va().

◆ manager_event_sessions

#define manager_event_sessions (   sessions,
  category,
  event,
  contents,
  ... 
)    __manager_event_sessions(sessions, category, event, 0, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__, contents , ## __VA_ARGS__)

Definition at line 1832 of file manager.c.

Referenced by manager_default_msg_cb(), and manager_generic_msg_cb().

◆ MAX_AUTH_PERM_STRING

#define MAX_AUTH_PERM_STRING   150

Maximum string length of the AMI authority permission string buildable from perms[].

Definition at line 2043 of file manager.c.

Referenced by __manager_event_sessions_va(), action_listcommands(), action_login(), handle_showmanager(), and handle_showmancmd().

◆ MAX_BLACKLIST_CMD_LEN

#define MAX_BLACKLIST_CMD_LEN   2

Descriptor for a manager session, either on the AMI socket or over HTTP.

Note
AMI session have managerid == 0; the entry is created upon a connect, and destroyed with the socket. HTTP sessions have managerid != 0, the value is used as a search key to lookup sessions (using the mansession_id cookie, or nonce key from Digest Authentication http header).

Definition at line 1523 of file manager.c.

Referenced by check_blacklist().

◆ MAX_VARS

#define MAX_VARS   128

Definition at line 1508 of file manager.c.

Referenced by load_channelvars().

◆ MGR_SHOW_TERMINAL_WIDTH

#define MGR_SHOW_TERMINAL_WIDTH   80

Definition at line 1506 of file manager.c.

Referenced by handle_showmancmds().

◆ MSG_MOREDATA

#define MSG_MOREDATA   ((char *)astman_send_response)
Note
NOTE: XXX this comment is unclear and possibly wrong. Callers of astman_send_error(), astman_send_response() or astman_send_ack() must EITHER hold the session lock or be running in an action callback (in which case s->session->busy will be non-zero). In either of these cases, there is no need to lock-protect the session's fd, since no other output will be sent (events will be queued), and no input will be read until either the current action finishes or get_input() obtains the session lock.
Todo:
XXX MSG_MOREDATA should go to a header file.

Definition at line 3114 of file manager.c.

Referenced by action_command(), astman_send_response_full(), and astman_start_ack().

Enumeration Type Documentation

◆ add_filter_result

Enumerator
FILTER_SUCCESS 
FILTER_ALLOC_FAILED 
FILTER_COMPILE_FAIL 

Definition at line 1434 of file manager.c.

◆ error_type

enum error_type

Doxygen group

Enumerator
UNKNOWN_ACTION 
UNKNOWN_CATEGORY 
UNSPECIFIED_CATEGORY 
UNSPECIFIED_ARGUMENT 
FAILURE_ALLOCATION 
FAILURE_NEWCAT 
FAILURE_DELCAT 
FAILURE_EMPTYCAT 
FAILURE_UPDATE 
FAILURE_DELETE 
FAILURE_APPEND 
FAILURE_TEMPLATE 

Definition at line 1419 of file manager.c.

◆ mansession_message_parsing

Enumerator
MESSAGE_OKAY 
MESSAGE_LINE_TOO_LONG 

Definition at line 1615 of file manager.c.

Function Documentation

◆ __ast_manager_event_multichan()

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

External routines may send asterisk manager events this way

Parameters
categoryEvent category, matches manager authorization
eventEvent name
chancountNumber of channels in chans parameter
chansA pointer to an array of channels involved in the event
file,line,func
contentsFormat string describing event
...
Since
1.8

Definition at line 7233 of file manager.c.

References __manager_event_sessions_va(), any_manager_listeners, ao2_cleanup, and ao2_global_obj_ref.

7236 {
7237  struct ao2_container *sessions = ao2_global_obj_ref(mgr_sessions);
7238  va_list ap;
7239  int res;
7240 
7241  if (!any_manager_listeners(sessions)) {
7242  /* Nobody is listening */
7243  ao2_cleanup(sessions);
7244  return 0;
7245  }
7246 
7247  va_start(ap, fmt);
7248  res = __manager_event_sessions_va(sessions, category, event, chancount, chans,
7249  file, line, func, fmt, ap);
7250  va_end(ap);
7251  ao2_cleanup(sessions);
7252  return res;
7253 }
#define any_manager_listeners(sessions)
Definition: manager.c:1835
Definition: astman.c:222
#define ao2_global_obj_ref(holder)
Definition: astobj2.h:925
static int __manager_event_sessions_va(struct ao2_container *sessions, int category, const char *event, int chancount, struct ast_channel **chans, const char *file, int line, const char *func, const char *fmt, va_list ap)
Definition: manager.c:7112
static int chancount
Definition: channel.c:93
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Generic container type.

◆ __astman_get_header()

static const char* __astman_get_header ( const struct message m,
char *  var,
int  mode 
)
static

Return a matching header value.

Generic function to return either the first or the last matching header from a list of variables, possibly skipping empty strings.

Note
At the moment there is only one use of this function in this file, so we make it static.
Never returns NULL.

Definition at line 2783 of file manager.c.

References ast_skip_blanks(), ast_strlen_zero, GET_HEADER_LAST_MATCH, GET_HEADER_SKIP_EMPTY, message::hdrcount, message::headers, result, and value.

Referenced by astman_get_header(), and process_message().

2784 {
2785  int x, l = strlen(var);
2786  const char *result = "";
2787 
2788  if (!m) {
2789  return result;
2790  }
2791 
2792  for (x = 0; x < m->hdrcount; x++) {
2793  const char *h = m->headers[x];
2794  if (!strncasecmp(var, h, l) && h[l] == ':') {
2795  const char *value = h + l + 1;
2796  value = ast_skip_blanks(value); /* ignore leading spaces in the value */
2797  /* found a potential candidate */
2798  if ((mode & GET_HEADER_SKIP_EMPTY) && ast_strlen_zero(value)) {
2799  continue; /* not interesting */
2800  }
2801  if (mode & GET_HEADER_LAST_MATCH) {
2802  result = value; /* record the last match so far */
2803  } else {
2804  return value;
2805  }
2806  }
2807  }
2808 
2809  return result;
2810 }
#define GET_HEADER_LAST_MATCH
Definition: manager.c:2767
#define var
Definition: ast_expr2f.c:614
int value
Definition: syslog.c:37
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define GET_HEADER_SKIP_EMPTY
Definition: manager.c:2768
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:157
static PGresult * result
Definition: cel_pgsql.c:88
const char * headers[AST_MAX_MANHEADERS]
Definition: manager.h:146
unsigned int hdrcount
Definition: manager.h:145

◆ __init_astman_append_buf()

static void __init_astman_append_buf ( void  )
static

thread local buffer for astman_append

Note
This can not be defined within the astman_append() function because it declares a couple of functions that get used to initialize the thread local storage key.

Definition at line 3061 of file manager.c.

3069 {

◆ __init_manager_event_buf()

static void __init_manager_event_buf ( void  )
static

Definition at line 7109 of file manager.c.

7123 {

◆ __init_userevent_buf()

static void __init_userevent_buf ( void  )
static

Definition at line 3063 of file manager.c.

3069 {

◆ __manager_event_sessions()

static int __manager_event_sessions ( struct ao2_container sessions,
int  category,
const char *  event,
int  chancount,
struct ast_channel **  chans,
const char *  file,
int  line,
const char *  func,
const char *  fmt,
  ... 
)
static

Definition at line 7211 of file manager.c.

References __manager_event_sessions_va().

7222 {
7223  va_list ap;
7224  int res;
7225 
7226  va_start(ap, fmt);
7227  res = __manager_event_sessions_va(sessions, category, event, chancount, chans,
7228  file, line, func, fmt, ap);
7229  va_end(ap);
7230  return res;
7231 }
Definition: astman.c:222
static int __manager_event_sessions_va(struct ao2_container *sessions, int category, const char *event, int chancount, struct ast_channel **chans, const char *file, int line, const char *func, const char *fmt, va_list ap)
Definition: manager.c:7112
static int chancount
Definition: channel.c:93

◆ __manager_event_sessions_va()

static int __manager_event_sessions_va ( struct ao2_container sessions,
int  category,
const char *  event,
int  chancount,
struct ast_channel **  chans,
const char *  file,
int  line,
const char *  func,
const char *  fmt,
va_list  ap 
)
static

Definition at line 7112 of file manager.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, append_channel_vars(), append_event(), ast_atomic_fetchadd_int(), ast_config_AST_SYSTEM_NAME, ast_mutex_lock, ast_mutex_unlock, AST_PTHREADT_NULL, AST_RWLIST_EMPTY, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_str_alloca, ast_str_append(), ast_str_append_va(), ast_str_buffer(), ast_str_set(), ast_str_thread_get(), ast_strlen_zero, ast_tvnow(), authority_to_str(), buf, chancount, EVENT_FLAG_SHUTDOWN, manager_custom_hook::helper, manager_debug, manager_event_buf, MANAGER_EVENT_BUF_INITSIZE, MAX_AUTH_PERM_STRING, mansession_session::notify_lock, mansession_session::pending_event, eventqent::seq, session, timestampevents, unref_mansession(), and mansession_session::waiting_thread.

Referenced by __ast_manager_event_multichan(), and __manager_event_sessions().

7123 {
7125  const char *cat_str;
7126  struct timeval now;
7127  struct ast_str *buf;
7128  int i;
7129 
7131  if (!buf) {
7132  return -1;
7133  }
7134 
7135  cat_str = authority_to_str(category, &auth);
7136  ast_str_set(&buf, 0,
7137  "Event: %s\r\n"
7138  "Privilege: %s\r\n",
7139  event, cat_str);
7140 
7141  if (timestampevents) {
7142  now = ast_tvnow();
7143  ast_str_append(&buf, 0,
7144  "Timestamp: %ld.%06lu\r\n",
7145  (long)now.tv_sec, (unsigned long) now.tv_usec);
7146  }
7147  if (manager_debug) {
7148  static int seq;
7149 
7150  ast_str_append(&buf, 0,
7151  "SequenceNumber: %d\r\n",
7152  ast_atomic_fetchadd_int(&seq, 1));
7153  ast_str_append(&buf, 0,
7154  "File: %s\r\n"
7155  "Line: %d\r\n"
7156  "Func: %s\r\n",
7157  file, line, func);
7158  }
7160  ast_str_append(&buf, 0,
7161  "SystemName: %s\r\n",
7163  }
7164 
7165  ast_str_append_va(&buf, 0, fmt, ap);
7166  for (i = 0; i < chancount; i++) {
7167  append_channel_vars(&buf, chans[i]);
7168  }
7169 
7170  ast_str_append(&buf, 0, "\r\n");
7171 
7172  append_event(ast_str_buffer(buf), category);
7173 
7174  /* Wake up any sleeping sessions */
7175  if (sessions) {
7176  struct ao2_iterator iter;
7177  struct mansession_session *session;
7178 
7179  iter = ao2_iterator_init(sessions, 0);
7180  while ((session = ao2_iterator_next(&iter))) {
7181  ast_mutex_lock(&session->notify_lock);
7182  if (session->waiting_thread != AST_PTHREADT_NULL) {
7183  pthread_kill(session->waiting_thread, SIGURG);
7184  } else {
7185  /* We have an event to process, but the mansession is
7186  * not waiting for it. We still need to indicate that there
7187  * is an event waiting so that get_input processes the pending
7188  * event instead of polling.
7189  */
7190  session->pending_event = 1;
7191  }
7192  ast_mutex_unlock(&session->notify_lock);
7193  unref_mansession(session);
7194  }
7195  ao2_iterator_destroy(&iter);
7196  }
7197 
7198  if (category != EVENT_FLAG_SHUTDOWN && !AST_RWLIST_EMPTY(&manager_hooks)) {
7199  struct manager_custom_hook *hook;
7200 
7202  AST_RWLIST_TRAVERSE(&manager_hooks, hook, list) {
7203  hook->helper(category, event, ast_str_buffer(buf));
7204  }
7206  }
7207 
7208  return 0;
7209 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define MAX_AUTH_PERM_STRING
Definition: manager.c:2043
pthread_t waiting_thread
Definition: manager.c:1587
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Definition: astman.c:222
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
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define ast_mutex_lock(a)
Definition: lock.h:187
static const char * authority_to_str(int authority, struct ast_str **res)
Convert authority code to a list of options. Note that the EVENT_FLAG_ALL authority will always be re...
Definition: manager.c:2084
#define ast_str_alloca(init_len)
Definition: strings.h:800
#define MANAGER_EVENT_BUF_INITSIZE
Definition: manager.c:7110
static int append_event(const char *str, int category)
events are appended to a queue from where they can be dispatched to clients.
Definition: manager.c:7068
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
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
#define ast_strlen_zero(foo)
Definition: strings.h:52
const char * ast_config_AST_SYSTEM_NAME
Definition: options.c:170
static void append_channel_vars(struct ast_str **pbuf, struct ast_channel *chan)
Definition: manager.c:7092
static struct ast_threadstorage manager_event_buf
Definition: manager.c:7109
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
ast_mutex_t notify_lock
Definition: manager.c:1610
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
#define AST_PTHREADT_NULL
Definition: lock.h:66
static struct ast_mansession session
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
static int timestampevents
Definition: manager.c:1472
#define AST_RWLIST_EMPTY
Definition: linkedlists.h:451
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int manager_debug
Definition: manager.c:1478
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
int ast_str_append_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap)
Append to a dynamic string using a va_list.
Definition: strings.h:1000
static volatile unsigned int seq
Definition: app_sms.c:120
static int chancount
Definition: channel.c:93
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
#define EVENT_FLAG_SHUTDOWN
Fake event class used to end sessions at shutdown.
Definition: manager.c:1511
list of hooks registered
Definition: manager.c:1668
manager_hook_t helper
Definition: manager.h:112
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:861
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ acl_change_stasis_cb()

static void acl_change_stasis_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 9637 of file manager.c.

References __init_manager(), ast_log, ast_named_acl_change_type(), LOG_NOTICE, and stasis_message_type().

Referenced by acl_change_stasis_subscribe().

9640 {
9641  if (stasis_message_type(message) != ast_named_acl_change_type()) {
9642  return;
9643  }
9644 
9645  /* For now, this is going to be performed simply and just execute a forced reload. */
9646  ast_log(LOG_NOTICE, "Reloading manager in response to ACL change event.\n");
9647  __init_manager(1, 1);
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
struct stasis_message_type * ast_named_acl_change_type(void)
a stasis_message_type for changes against a named ACL or the set of all named ACLs ...
#define ast_log
Definition: astobj2.c:42
static int __init_manager(int reload, int by_external_config)
Definition: manager.c:9144
#define LOG_NOTICE
Definition: logger.h:263

◆ acl_change_stasis_subscribe()

static void acl_change_stasis_subscribe ( void  )
static

Definition at line 1534 of file manager.c.

References acl_change_stasis_cb(), ast_named_acl_change_type(), ast_security_topic(), NULL, stasis_subscribe, stasis_subscription_accept_message_type(), STASIS_SUBSCRIPTION_FILTER_SELECTIVE, and stasis_subscription_set_filter().

Referenced by __init_manager().

1535 {
1536  if (!acl_change_sub) {
1541  }
1542 }
struct stasis_topic * ast_security_topic(void)
A stasis_topic which publishes messages for security related issues.
int stasis_subscription_set_filter(struct stasis_subscription *subscription, enum stasis_subscription_message_filter filter)
Set the message type filtering level on a subscription.
Definition: stasis.c:1079
struct stasis_message_type * ast_named_acl_change_type(void)
a stasis_message_type for changes against a named ACL or the set of all named ACLs ...
#define NULL
Definition: resample.c:96
static struct stasis_subscription * acl_change_sub
Definition: manager.c:1487
#define stasis_subscribe(topic, callback, data)
Definition: stasis.h:652
int stasis_subscription_accept_message_type(struct stasis_subscription *subscription, const struct stasis_message_type *type)
Indicate to a subscription that we are interested in a message type.
Definition: stasis.c:1025
static void acl_change_stasis_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition: manager.c:9637

◆ acl_change_stasis_unsubscribe()

static void acl_change_stasis_unsubscribe ( void  )
static

Definition at line 1544 of file manager.c.

References stasis_unsubscribe_and_join().

Referenced by __init_manager(), and manager_shutdown().

1545 {
1547 }
static struct stasis_subscription * acl_change_sub
Definition: manager.c:1487
struct stasis_subscription * stasis_unsubscribe_and_join(struct stasis_subscription *subscription)
Cancel a subscription, blocking until the last message is processed.
Definition: stasis.c:1136

◆ action_aocmessage()

static int action_aocmessage ( struct mansession s,
const struct message m 
)
static

Definition at line 5518 of file manager.c.

References ast_aoc_unit_entry::amount, aocmessage_get_unit_entry(), ast_aoc_add_unit_entry(), AST_AOC_BILLING_CALL_DEFLECTION, AST_AOC_BILLING_CALL_FWD_BUSY, AST_AOC_BILLING_CALL_FWD_NO_REPLY, AST_AOC_BILLING_CALL_FWD_UNCONDITIONAL, AST_AOC_BILLING_CALL_TRANSFER, AST_AOC_BILLING_CREDIT_CARD, AST_AOC_BILLING_NA, AST_AOC_BILLING_NORMAL, AST_AOC_BILLING_REVERSE_CHARGE, AST_AOC_CHARGE_CURRENCY, AST_AOC_CHARGE_FREE, AST_AOC_CHARGE_NA, AST_AOC_CHARGE_UNIT, ast_aoc_create(), AST_AOC_D, ast_aoc_destroy_decoded(), ast_aoc_destroy_encoded(), AST_AOC_E, ast_aoc_encode(), AST_AOC_MULT_HUNDRED, AST_AOC_MULT_ONE, AST_AOC_MULT_ONEHUNDREDTH, AST_AOC_MULT_ONETENTH, AST_AOC_MULT_ONETHOUSANDTH, AST_AOC_MULT_TEN, AST_AOC_MULT_THOUSAND, ast_aoc_set_association_id(), ast_aoc_set_association_number(), ast_aoc_set_billing_id(), ast_aoc_set_currency_info(), ast_aoc_set_total_type(), AST_AOC_SUBTOTAL, AST_AOC_TOTAL, ast_channel_get_by_name(), ast_channel_get_by_name_prefix(), ast_channel_unref, AST_CONTROL_AOC, ast_indicate_data(), ast_strlen_zero, astman_get_header(), astman_send_ack(), astman_send_error(), NULL, ast_aoc_unit_entry::type, ast_aoc_unit_entry::valid_amount, and ast_aoc_unit_entry::valid_type.

Referenced by __init_manager().

5519 {
5520  const char *channel = astman_get_header(m, "Channel");
5521  const char *pchannel = astman_get_header(m, "ChannelPrefix");
5522  const char *msgtype = astman_get_header(m, "MsgType");
5523  const char *chargetype = astman_get_header(m, "ChargeType");
5524  const char *currencyname = astman_get_header(m, "CurrencyName");
5525  const char *currencyamount = astman_get_header(m, "CurrencyAmount");
5526  const char *mult = astman_get_header(m, "CurrencyMultiplier");
5527  const char *totaltype = astman_get_header(m, "TotalType");
5528  const char *aocbillingid = astman_get_header(m, "AOCBillingId");
5529  const char *association_id= astman_get_header(m, "ChargingAssociationId");
5530  const char *association_num = astman_get_header(m, "ChargingAssociationNumber");
5531  const char *association_plan = astman_get_header(m, "ChargingAssociationPlan");
5532 
5533  enum ast_aoc_type _msgtype;
5534  enum ast_aoc_charge_type _chargetype;
5536  enum ast_aoc_total_type _totaltype = AST_AOC_TOTAL;
5537  enum ast_aoc_billing_id _billingid = AST_AOC_BILLING_NA;
5538  unsigned int _currencyamount = 0;
5539  int _association_id = 0;
5540  unsigned int _association_plan = 0;
5541  struct ast_channel *chan = NULL;
5542 
5543  struct ast_aoc_decoded *decoded = NULL;
5544  struct ast_aoc_encoded *encoded = NULL;
5545  size_t encoded_size = 0;
5546 
5547  if (ast_strlen_zero(channel) && ast_strlen_zero(pchannel)) {
5548  astman_send_error(s, m, "Channel and PartialChannel are not specified. Specify at least one of these.");
5549  goto aocmessage_cleanup;
5550  }
5551 
5552  if (!(chan = ast_channel_get_by_name(channel)) && !ast_strlen_zero(pchannel)) {
5553  chan = ast_channel_get_by_name_prefix(pchannel, strlen(pchannel));
5554  }
5555 
5556  if (!chan) {
5557  astman_send_error(s, m, "No such channel");
5558  goto aocmessage_cleanup;
5559  }
5560 
5561  if (ast_strlen_zero(msgtype) || (strcasecmp(msgtype, "d") && strcasecmp(msgtype, "e"))) {
5562  astman_send_error(s, m, "Invalid MsgType");
5563  goto aocmessage_cleanup;
5564  }
5565 
5566  if (ast_strlen_zero(chargetype)) {
5567  astman_send_error(s, m, "ChargeType not specified");
5568  goto aocmessage_cleanup;
5569  }
5570 
5571  _msgtype = strcasecmp(msgtype, "d") ? AST_AOC_E : AST_AOC_D;
5572 
5573  if (!strcasecmp(chargetype, "NA")) {
5574  _chargetype = AST_AOC_CHARGE_NA;
5575  } else if (!strcasecmp(chargetype, "Free")) {
5576  _chargetype = AST_AOC_CHARGE_FREE;
5577  } else if (!strcasecmp(chargetype, "Currency")) {
5578  _chargetype = AST_AOC_CHARGE_CURRENCY;
5579  } else if (!strcasecmp(chargetype, "Unit")) {
5580  _chargetype = AST_AOC_CHARGE_UNIT;
5581  } else {
5582  astman_send_error(s, m, "Invalid ChargeType");
5583  goto aocmessage_cleanup;
5584  }
5585 
5586  if (_chargetype == AST_AOC_CHARGE_CURRENCY) {
5587 
5588  if (ast_strlen_zero(currencyamount) || (sscanf(currencyamount, "%30u", &_currencyamount) != 1)) {
5589  astman_send_error(s, m, "Invalid CurrencyAmount, CurrencyAmount is a required when ChargeType is Currency");
5590  goto aocmessage_cleanup;
5591  }
5592 
5593  if (ast_strlen_zero(mult)) {
5594  astman_send_error(s, m, "ChargeMultiplier unspecified, ChargeMultiplier is required when ChargeType is Currency.");
5595  goto aocmessage_cleanup;
5596  } else if (!strcasecmp(mult, "onethousandth")) {
5598  } else if (!strcasecmp(mult, "onehundredth")) {
5599  _mult = AST_AOC_MULT_ONEHUNDREDTH;
5600  } else if (!strcasecmp(mult, "onetenth")) {
5601  _mult = AST_AOC_MULT_ONETENTH;
5602  } else if (!strcasecmp(mult, "one")) {
5603  _mult = AST_AOC_MULT_ONE;
5604  } else if (!strcasecmp(mult, "ten")) {
5605  _mult = AST_AOC_MULT_TEN;
5606  } else if (!strcasecmp(mult, "hundred")) {
5607  _mult = AST_AOC_MULT_HUNDRED;
5608  } else if (!strcasecmp(mult, "thousand")) {
5609  _mult = AST_AOC_MULT_THOUSAND;
5610  } else {
5611  astman_send_error(s, m, "Invalid ChargeMultiplier");
5612  goto aocmessage_cleanup;
5613  }
5614  }
5615 
5616  /* create decoded object and start setting values */
5617  if (!(decoded = ast_aoc_create(_msgtype, _chargetype, 0))) {
5618  astman_send_error(s, m, "Message Creation Failed");
5619  goto aocmessage_cleanup;
5620  }
5621 
5622  if (_msgtype == AST_AOC_D) {
5623  if (!ast_strlen_zero(totaltype) && !strcasecmp(totaltype, "subtotal")) {
5624  _totaltype = AST_AOC_SUBTOTAL;
5625  }
5626 
5627  if (ast_strlen_zero(aocbillingid)) {
5628  /* ignore this is optional */
5629  } else if (!strcasecmp(aocbillingid, "Normal")) {
5630  _billingid = AST_AOC_BILLING_NORMAL;
5631  } else if (!strcasecmp(aocbillingid, "ReverseCharge")) {
5632  _billingid = AST_AOC_BILLING_REVERSE_CHARGE;
5633  } else if (!strcasecmp(aocbillingid, "CreditCard")) {
5634  _billingid = AST_AOC_BILLING_CREDIT_CARD;
5635  } else {
5636  astman_send_error(s, m, "Invalid AOC-D AOCBillingId");
5637  goto aocmessage_cleanup;
5638  }
5639  } else {
5640  if (ast_strlen_zero(aocbillingid)) {
5641  /* ignore this is optional */
5642  } else if (!strcasecmp(aocbillingid, "Normal")) {
5643  _billingid = AST_AOC_BILLING_NORMAL;
5644  } else if (!strcasecmp(aocbillingid, "ReverseCharge")) {
5645  _billingid = AST_AOC_BILLING_REVERSE_CHARGE;
5646  } else if (!strcasecmp(aocbillingid, "CreditCard")) {
5647  _billingid = AST_AOC_BILLING_CREDIT_CARD;
5648  } else if (!strcasecmp(aocbillingid, "CallFwdUnconditional")) {
5650  } else if (!strcasecmp(aocbillingid, "CallFwdBusy")) {
5651  _billingid = AST_AOC_BILLING_CALL_FWD_BUSY;
5652  } else if (!strcasecmp(aocbillingid, "CallFwdNoReply")) {
5653  _billingid = AST_AOC_BILLING_CALL_FWD_NO_REPLY;
5654  } else if (!strcasecmp(aocbillingid, "CallDeflection")) {
5655  _billingid = AST_AOC_BILLING_CALL_DEFLECTION;
5656  } else if (!strcasecmp(aocbillingid, "CallTransfer")) {
5657  _billingid = AST_AOC_BILLING_CALL_TRANSFER;
5658  } else {
5659  astman_send_error(s, m, "Invalid AOC-E AOCBillingId");
5660  goto aocmessage_cleanup;
5661  }
5662 
5663  if (!ast_strlen_zero(association_id) && (sscanf(association_id, "%30d", &_association_id) != 1)) {
5664  astman_send_error(s, m, "Invalid ChargingAssociationId");
5665  goto aocmessage_cleanup;
5666  }
5667  if (!ast_strlen_zero(association_plan) && (sscanf(association_plan, "%30u", &_association_plan) != 1)) {
5668  astman_send_error(s, m, "Invalid ChargingAssociationPlan");
5669  goto aocmessage_cleanup;
5670  }
5671 
5672  if (_association_id) {
5673  ast_aoc_set_association_id(decoded, _association_id);
5674  } else if (!ast_strlen_zero(association_num)) {
5675  ast_aoc_set_association_number(decoded, association_num, _association_plan);
5676  }
5677  }
5678 
5679  if (_chargetype == AST_AOC_CHARGE_CURRENCY) {
5680  ast_aoc_set_currency_info(decoded, _currencyamount, _mult, ast_strlen_zero(currencyname) ? NULL : currencyname);
5681  } else if (_chargetype == AST_AOC_CHARGE_UNIT) {
5682  struct ast_aoc_unit_entry entry;
5683  int i;
5684 
5685  /* multiple unit entries are possible, lets get them all */
5686  for (i = 0; i < 32; i++) {
5687  if (aocmessage_get_unit_entry(m, &entry, i)) {
5688  break; /* that's the end then */
5689  }
5690 
5691  ast_aoc_add_unit_entry(decoded, entry.valid_amount, entry.amount, entry.valid_type, entry.type);
5692  }
5693 
5694  /* at least one unit entry is required */
5695  if (!i) {
5696  astman_send_error(s, m, "Invalid UnitAmount(0), At least one valid unit entry is required when ChargeType is set to Unit");
5697  goto aocmessage_cleanup;
5698  }
5699 
5700  }
5701 
5702  ast_aoc_set_billing_id(decoded, _billingid);
5703  ast_aoc_set_total_type(decoded, _totaltype);
5704 
5705 
5706  if ((encoded = ast_aoc_encode(decoded, &encoded_size, NULL)) && !ast_indicate_data(chan, AST_CONTROL_AOC, encoded, encoded_size)) {
5707  astman_send_ack(s, m, "AOC Message successfully queued on channel");
5708  } else {
5709  astman_send_error(s, m, "Error encoding AOC message, could not queue onto channel");
5710  }
5711 
5712 aocmessage_cleanup:
5713 
5714  ast_aoc_destroy_decoded(decoded);
5715  ast_aoc_destroy_encoded(encoded);
5716 
5717  if (chan) {
5718  chan = ast_channel_unref(chan);
5719  }
5720  return 0;
5721 }
Main Channel structure associated with a channel.
int ast_aoc_add_unit_entry(struct ast_aoc_decoded *decoded, const unsigned int amount_is_present, const unsigned int amount, const unsigned int type_is_present, const unsigned int type)
Adds a unit entry into the list of units.
Definition: aoc.c:977
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
void * ast_aoc_destroy_decoded(struct ast_aoc_decoded *decoded)
free an ast_aoc_decoded object
Definition: aoc.c:307
int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen)
Indicates condition of channel, with payload.
Definition: channel.c:4698
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
Definition: muted.c:95
ast_aoc_currency_multiplier
Defines the currency multiplier for an aoc message.
Definition: aoc.h:34
#define NULL
Definition: resample.c:96
ast_aoc_total_type
Definition: aoc.h:82
static int aocmessage_get_unit_entry(const struct message *m, struct ast_aoc_unit_entry *entry, unsigned int entry_num)
Definition: manager.c:5493
struct ast_channel * ast_channel_get_by_name_prefix(const char *name, size_t name_len)
Find a channel by a name prefix.
Definition: channel.c:1434
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
int ast_aoc_set_association_number(struct ast_aoc_decoded *decoded, const char *num, uint8_t plan)
set the charging accociation number for an AOC-E message
Definition: aoc.c:1056
struct ast_aoc_encoded * ast_aoc_encode(struct ast_aoc_decoded *decoded, size_t *out_size, struct ast_channel *chan)
encodes a decoded aoc structure so it can be passed on the wire
Definition: aoc.c:650
ast_aoc_charge_type
Definition: aoc.h:69
int ast_aoc_set_billing_id(struct ast_aoc_decoded *decoded, const enum ast_aoc_billing_id id)
set the billing id for a AOC-D or AST_AOC_E message
Definition: aoc.c:1024
ast_aoc_type
Definition: aoc.h:62
int ast_aoc_set_total_type(struct ast_aoc_decoded *decoded, const enum ast_aoc_total_type type)
Sets the type of total for a AOC-D message.
Definition: aoc.c:907
void * ast_aoc_destroy_encoded(struct ast_aoc_encoded *encoded)
free an ast_aoc_encoded object
Definition: aoc.c:313
struct ast_aoc_decoded * ast_aoc_create(const enum ast_aoc_type msg_type, const enum ast_aoc_charge_type charge_type, const enum ast_aoc_request requests)
creates a ast_aoc_decode object of a specific message type
Definition: aoc.c:276
ast_aoc_billing_id
Defines the billing id options for an aoc message.
Definition: aoc.h:49
Definition: aoc.h:66
Definition: search.h:40
int ast_aoc_set_association_id(struct ast_aoc_decoded *decoded, const int id)
set the charging association id for an AST_AOC_E message
Definition: aoc.c:1040
Definition: aoc.h:178
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
Definition: aoc.h:65
int ast_aoc_set_currency_info(struct ast_aoc_decoded *decoded, const unsigned int amount, const enum ast_aoc_currency_multiplier multiplier, const char *name)
Sets the currency values for a AOC-D or AOC-E message.
Definition: aoc.c:919

◆ action_atxfer()

static int action_atxfer ( struct mansession s,
const struct message m 
)
static

Definition at line 5164 of file manager.c.

References ast_channel_get_by_name(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, AST_FEATURE_MAX_LEN, AST_FRAME_DTMF, ast_get_builtin_feature(), ast_queue_frame(), ast_strlen_zero, astman_get_header(), astman_send_ack(), astman_send_error(), context, digit, exten, name, NULL, and pbx_builtin_setvar_helper().

Referenced by __init_manager().

5165 {
5166  const char *name = astman_get_header(m, "Channel");
5167  const char *exten = astman_get_header(m, "Exten");
5168  const char *context = astman_get_header(m, "Context");
5169  struct ast_channel *chan = NULL;
5170  char feature_code[AST_FEATURE_MAX_LEN];
5171  const char *digit;
5172 
5173  if (ast_strlen_zero(name)) {
5174  astman_send_error(s, m, "No channel specified");
5175  return 0;
5176  }
5177  if (ast_strlen_zero(exten)) {
5178  astman_send_error(s, m, "No extension specified");
5179  return 0;
5180  }
5181 
5182  if (!(chan = ast_channel_get_by_name(name))) {
5183  astman_send_error(s, m, "Channel specified does not exist");
5184  return 0;
5185  }
5186 
5187  ast_channel_lock(chan);
5188  if (ast_get_builtin_feature(chan, "atxfer", feature_code, sizeof(feature_code)) ||
5189  ast_strlen_zero(feature_code)) {
5190  ast_channel_unlock(chan);
5191  astman_send_error(s, m, "No attended transfer feature code found");
5192  ast_channel_unref(chan);
5193  return 0;
5194  }
5195  ast_channel_unlock(chan);
5196 
5197  if (!ast_strlen_zero(context)) {
5198  pbx_builtin_setvar_helper(chan, "TRANSFER_CONTEXT", context);
5199  }
5200 
5201  for (digit = feature_code; *digit; ++digit) {
5202  struct ast_frame f = { AST_FRAME_DTMF, .subclass.integer = *digit };
5203  ast_queue_frame(chan, &f);
5204  }
5205 
5206  for (digit = exten; *digit; ++digit) {
5207  struct ast_frame f = { AST_FRAME_DTMF, .subclass.integer = *digit };
5208  ast_queue_frame(chan, &f);
5209  }
5210 
5211  chan = ast_channel_unref(chan);
5212 
5213  astman_send_ack(s, m, "Atxfer successfully queued");
5214 
5215  return 0;
5216 }
char digit
#define ast_channel_lock(chan)
Definition: channel.h:2945
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
#define NULL
Definition: resample.c:96
#define AST_FRAME_DTMF
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel&#39;s frame queue.
Definition: channel.c:1139
int ast_get_builtin_feature(struct ast_channel *chan, const char *feature, char *buf, size_t len)
Get the DTMF code for a builtin feature.
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static const char name[]
Definition: cdr_mysql.c:74
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
#define AST_FEATURE_MAX_LEN
Data structure associated with a single frame of data.
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_blind_transfer()

static int action_blind_transfer ( struct mansession s,
const struct message m 
)
static

Definition at line 5118 of file manager.c.

References ast_bridge_transfer_blind(), AST_BRIDGE_TRANSFER_FAIL, AST_BRIDGE_TRANSFER_INVALID, AST_BRIDGE_TRANSFER_NOT_PERMITTED, AST_BRIDGE_TRANSFER_SUCCESS, ast_channel_context(), ast_channel_get_by_name(), ast_channel_unref, ast_strlen_zero, astman_get_header(), astman_send_ack(), astman_send_error(), context, exten, name, and NULL.

Referenced by __init_manager().

5119 {
5120  const char *name = astman_get_header(m, "Channel");
5121  const char *exten = astman_get_header(m, "Exten");
5122  const char *context = astman_get_header(m, "Context");
5123  struct ast_channel *chan;
5124 
5125  if (ast_strlen_zero(name)) {
5126  astman_send_error(s, m, "No channel specified");
5127  return 0;
5128  }
5129 
5130  if (ast_strlen_zero(exten)) {
5131  astman_send_error(s, m, "No extension specified");
5132  return 0;
5133  }
5134 
5135  chan = ast_channel_get_by_name(name);
5136  if (!chan) {
5137  astman_send_error(s, m, "Channel specified does not exist");
5138  return 0;
5139  }
5140 
5141  if (ast_strlen_zero(context)) {
5142  context = ast_channel_context(chan);
5143  }
5144 
5145  switch (ast_bridge_transfer_blind(1, chan, exten, context, NULL, NULL)) {
5147  astman_send_error(s, m, "Transfer not permitted");
5148  break;
5150  astman_send_error(s, m, "Transfer invalid");
5151  break;
5153  astman_send_error(s, m, "Transfer failed");
5154  break;
5156  astman_send_ack(s, m, "Transfer succeeded");
5157  break;
5158  }
5159 
5160  ast_channel_unref(chan);
5161  return 0;
5162 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
#define NULL
Definition: resample.c:96
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
enum ast_transfer_result ast_bridge_transfer_blind(int is_external, struct ast_channel *transferer, const char *exten, const char *context, transfer_channel_cb new_channel_cb, void *user_data)
Blind transfer target to the extension and context provided.
Definition: bridge.c:4477
static const char name[]
Definition: cdr_mysql.c:74
const char * ast_channel_context(const struct ast_channel *chan)
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_cancel_atxfer()

static int action_cancel_atxfer ( struct mansession s,
const struct message m 
)
static

Definition at line 5218 of file manager.c.

References ast_channel_get_by_name(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, AST_FRAME_DTMF, ast_free, ast_get_chan_features_atxferabort(), ast_queue_frame(), ast_strlen_zero, astman_get_header(), astman_send_ack(), astman_send_error(), digit, name, and NULL.

Referenced by __init_manager().

5219 {
5220  const char *name = astman_get_header(m, "Channel");
5221  struct ast_channel *chan = NULL;
5222  char *feature_code;
5223  const char *digit;
5224 
5225  if (ast_strlen_zero(name)) {
5226  astman_send_error(s, m, "No channel specified");
5227  return 0;
5228  }
5229 
5230  if (!(chan = ast_channel_get_by_name(name))) {
5231  astman_send_error(s, m, "Channel specified does not exist");
5232  return 0;
5233  }
5234 
5235  ast_channel_lock(chan);
5236  feature_code = ast_get_chan_features_atxferabort(chan);
5237  ast_channel_unlock(chan);
5238 
5239  if (!feature_code) {
5240  astman_send_error(s, m, "No disconnect feature code found");
5241  ast_channel_unref(chan);
5242  return 0;
5243  }
5244 
5245  for (digit = feature_code; *digit; ++digit) {
5246  struct ast_frame f = { AST_FRAME_DTMF, .subclass.integer = *digit };
5247  ast_queue_frame(chan, &f);
5248  }
5249  ast_free(feature_code);
5250 
5251  chan = ast_channel_unref(chan);
5252 
5253  astman_send_ack(s, m, "CancelAtxfer successfully queued");
5254 
5255  return 0;
5256 }
char digit
#define ast_channel_lock(chan)
Definition: channel.h:2945
Main Channel structure associated with a channel.
char * ast_get_chan_features_atxferabort(struct ast_channel *chan)
Get the transfer configuration option atxferabort.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
#define NULL
Definition: resample.c:96
#define AST_FRAME_DTMF
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel&#39;s frame queue.
Definition: channel.c:1139
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static const char name[]
Definition: cdr_mysql.c:74
#define ast_free(a)
Definition: astmm.h:182
Data structure associated with a single frame of data.
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_challenge()

static int action_challenge ( struct mansession s,
const struct message m 
)
static

Definition at line 4442 of file manager.c.

References ast_random(), ast_strlen_zero, astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), mansession_session::challenge, mansession_lock(), mansession_unlock(), and mansession::session.

Referenced by __init_manager().

4443 {
4444  const char *authtype = astman_get_header(m, "AuthType");
4445 
4446  if (!strcasecmp(authtype, "MD5")) {
4447  if (ast_strlen_zero(s->session->challenge)) {
4448  snprintf(s->session->challenge, sizeof(s->session->challenge), "%ld", ast_random());
4449  }
4450  mansession_lock(s);
4451  astman_start_ack(s, m);
4452  astman_append(s, "Challenge: %s\r\n\r\n", s->session->challenge);
4453  mansession_unlock(s);
4454  } else {
4455  astman_send_error(s, m, "Must specify AuthType");
4456  }
4457  return 0;
4458 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
static void mansession_unlock(struct mansession *s)
Unlock the &#39;mansession&#39; structure.
Definition: manager.c:3257
static void astman_start_ack(struct mansession *s, const struct message *m)
Definition: manager.c:3196
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
long int ast_random(void)
Definition: main/utils.c:2064
static void mansession_lock(struct mansession *s)
Lock the &#39;mansession&#39; structure.
Definition: manager.c:3251
char challenge[10]
Definition: manager.c:1593
struct mansession_session * session
Definition: manager.c:1626
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_command()

static int action_command ( struct mansession s,
const struct message m 
)
static

Manager command "command" - execute CLI command.

Definition at line 5295 of file manager.c.

References ast_free, ast_malloc, ast_strlen_zero, astman_append(), astman_get_header(), astman_send_error(), astman_send_error_va(), astman_send_response_full(), buf, check_blacklist(), errno, len(), MSG_MOREDATA, NULL, RESULT_SUCCESS, strsep(), and term_strip().

Referenced by __init_manager().

5296 {
5297  const char *cmd = astman_get_header(m, "Command");
5298  char *buf = NULL, *final_buf = NULL, *delim, *output;
5299  char template[] = "/tmp/ast-ami-XXXXXX"; /* template for temporary file */
5300  int fd, ret;
5301  off_t len;
5302 
5303  if (ast_strlen_zero(cmd)) {
5304  astman_send_error(s, m, "No command provided");
5305  return 0;
5306  }
5307 
5308  if (check_blacklist(cmd)) {
5309  astman_send_error(s, m, "Command blacklisted");
5310  return 0;
5311  }
5312 
5313  if ((fd = mkstemp(template)) < 0) {
5314  astman_send_error_va(s, m, "Failed to create temporary file: %s", strerror(errno));
5315  return 0;
5316  }
5317 
5318  ret = ast_cli_command(fd, cmd);
5319  astman_send_response_full(s, m, ret == RESULT_SUCCESS ? "Success" : "Error", MSG_MOREDATA, NULL);
5320 
5321  /* Determine number of characters available */
5322  if ((len = lseek(fd, 0, SEEK_END)) < 0) {
5323  astman_append(s, "Message: Failed to determine number of characters: %s\r\n", strerror(errno));
5324  goto action_command_cleanup;
5325  }
5326 
5327  /* This has a potential to overflow the stack. Hence, use the heap. */
5328  buf = ast_malloc(len + 1);
5329  final_buf = ast_malloc(len + 1);
5330 
5331  if (!buf || !final_buf) {
5332  astman_append(s, "Message: Memory allocation failure\r\n");
5333  goto action_command_cleanup;
5334  }
5335 
5336  if (lseek(fd, 0, SEEK_SET) < 0) {
5337  astman_append(s, "Message: Failed to set position on temporary file: %s\r\n", strerror(errno));
5338  goto action_command_cleanup;
5339  }
5340 
5341  if (read(fd, buf, len) < 0) {
5342  astman_append(s, "Message: Failed to read from temporary file: %s\r\n", strerror(errno));
5343  goto action_command_cleanup;
5344  }
5345 
5346  buf[len] = '\0';
5347  term_strip(final_buf, buf, len);
5348  final_buf[len] = '\0';
5349 
5350  /* Trim trailing newline */
5351  if (len && final_buf[len - 1] == '\n') {
5352  final_buf[len - 1] = '\0';
5353  }
5354 
5355  astman_append(s, "Message: Command output follows\r\n");
5356 
5357  delim = final_buf;
5358  while ((output = strsep(&delim, "\n"))) {
5359  astman_append(s, "Output: %s\r\n", output);
5360  }
5361 
5362 action_command_cleanup:
5363  astman_append(s, "\r\n");
5364 
5365  close(fd);
5366  unlink(template);
5367 
5368  ast_free(buf);
5369  ast_free(final_buf);
5370 
5371  return 0;
5372 }
static int check_blacklist(const char *cmd)
Definition: manager.c:5259
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * term_strip(char *outbuf, const char *inbuf, int maxout)
Remove colorings from a specified string.
Definition: term.c:311
static void astman_send_response_full(struct mansession *s, const struct message *m, char *resp, char *msg, char *listflag)
send a response with an optional message, and terminate it with an empty line. m is used only to grab...
Definition: manager.c:3123
#define NULL
Definition: resample.c:96
void astman_send_error_va(struct mansession *s, const struct message *m, const char *fmt,...)
Send error in manager transaction (with va_args support)
Definition: manager.c:3164
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
ast_cli_command
calling arguments for new-style handlers.
Definition: cli.h:151
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
#define MSG_MOREDATA
Definition: manager.c:3114
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int errno
#define ast_free(a)
Definition: astmm.h:182
char * strsep(char **str, const char *delims)
#define RESULT_SUCCESS
Definition: cli.h:40
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_coresettings()

static int action_coresettings ( struct mansession s,
const struct message m 
)
static

Show PBX core settings information.

Definition at line 6276 of file manager.c.

References AMI_VERSION, ast_cdr_is_enabled(), AST_CLI_YESNO, ast_config_AST_RUN_GROUP, ast_config_AST_RUN_USER, ast_config_AST_SYSTEM_NAME, ast_get_version(), ast_option_maxcalls, ast_option_maxfiles, ast_option_maxload, ast_realtime_enabled(), ast_strlen_zero, ast_webmanager_check_enabled(), astman_append(), and astman_get_header().

Referenced by __init_manager().

6277 {
6278  const char *actionid = astman_get_header(m, "ActionID");
6279  char idText[150];
6280 
6281  if (!ast_strlen_zero(actionid)) {
6282  snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
6283  } else {
6284  idText[0] = '\0';
6285  }
6286 
6287  astman_append(s, "Response: Success\r\n"
6288  "%s"
6289  "AMIversion: %s\r\n"
6290  "AsteriskVersion: %s\r\n"
6291  "SystemName: %s\r\n"
6292  "CoreMaxCalls: %d\r\n"
6293  "CoreMaxLoadAvg: %f\r\n"
6294  "CoreRunUser: %s\r\n"
6295  "CoreRunGroup: %s\r\n"
6296  "CoreMaxFilehandles: %d\r\n"
6297  "CoreRealTimeEnabled: %s\r\n"
6298  "CoreCDRenabled: %s\r\n"
6299  "CoreHTTPenabled: %s\r\n"
6300  "\r\n",
6301  idText,
6302  AMI_VERSION,
6303  ast_get_version(),
6313  );
6314  return 0;
6315 }
int ast_option_maxfiles
Definition: options.c:81
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
const char * ast_get_version(void)
Retrieve the Asterisk version string.
Definition: version.c:16
double ast_option_maxload
Definition: options.c:77
const char * ast_config_AST_RUN_USER
Definition: options.c:168
int ast_option_maxcalls
Definition: options.c:79
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
int ast_realtime_enabled(void)
Check if there&#39;s any realtime engines loaded.
Definition: main/config.c:3377
int ast_webmanager_check_enabled(void)
Check if AMI/HTTP is enabled.
Definition: manager.c:1954
const char * ast_config_AST_SYSTEM_NAME
Definition: options.c:170
int ast_cdr_is_enabled(void)
Return TRUE if CDR subsystem is enabled.
Definition: cdr.c:2861
const char * ast_config_AST_RUN_GROUP
Definition: options.c:169
#define AMI_VERSION
Definition: manager.h:57
#define AST_CLI_YESNO(x)
Return Yes or No depending on the argument.
Definition: cli.h:71

◆ action_coreshowchannels()

static int action_coreshowchannels ( struct mansession s,
const struct message m 
)
static

Manager command "CoreShowChannels" - List currently defined channels and some information about them.

Definition at line 6390 of file manager.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_channel_snapshot_dialplan::appl, ast_channel_cache_by_name(), ast_free, ast_manager_build_channel_state_string_prefix(), ast_str_buffer(), ast_strlen_zero, ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), astman_append(), astman_get_header(), astman_send_list_complete(), astman_send_listack(), ast_channel_snapshot::base, ast_channel_snapshot::bridge, channels, ast_channel_snapshot_base::creationtime, ast_channel_snapshot_dialplan::data, ast_channel_snapshot::dialplan, and ast_channel_snapshot_bridge::id.

Referenced by __init_manager().

6391 {
6392  const char *actionid = astman_get_header(m, "ActionID");
6393  char idText[256];
6394  int numchans = 0;
6395  struct ao2_container *channels;
6396  struct ao2_iterator it_chans;
6397  struct ast_channel_snapshot *cs;
6398 
6399  if (!ast_strlen_zero(actionid)) {
6400  snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
6401  } else {
6402  idText[0] = '\0';
6403  }
6404 
6405  channels = ast_channel_cache_by_name();
6406 
6407  astman_send_listack(s, m, "Channels will follow", "start");
6408 
6409  it_chans = ao2_iterator_init(channels, 0);
6410  for (; (cs = ao2_iterator_next(&it_chans)); ao2_ref(cs, -1)) {
6412  char durbuf[16] = "";
6413 
6414  if (!built) {
6415  continue;
6416  }
6417 
6418  if (!ast_tvzero(cs->base->creationtime)) {
6419  int duration, durh, durm, durs;
6420 
6421  duration = (int)(ast_tvdiff_ms(ast_tvnow(), cs->base->creationtime) / 1000);
6422  durh = duration / 3600;
6423  durm = (duration % 3600) / 60;
6424  durs = duration % 60;
6425  snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs);
6426  }
6427 
6428  astman_append(s,
6429  "Event: CoreShowChannel\r\n"
6430  "%s"
6431  "%s"
6432  "Application: %s\r\n"
6433  "ApplicationData: %s\r\n"
6434  "Duration: %s\r\n"
6435  "BridgeId: %s\r\n"
6436  "\r\n",
6437  idText,
6438  ast_str_buffer(built),
6439  cs->dialplan->appl,
6440  cs->dialplan->data,
6441  durbuf,
6442  cs->bridge->id);
6443 
6444  numchans++;
6445 
6446  ast_free(built);
6447  }
6448  ao2_iterator_destroy(&it_chans);
6449 
6450  astman_send_list_complete(s, m, "CoreShowChannelsComplete", numchans);
6451 
6452  ao2_ref(channels, -1);
6453  return 0;
6454 }
struct ao2_container * ast_channel_cache_by_name(void)
Secondary channel cache, indexed by name.
const ast_string_field data
struct ast_channel_snapshot_base * base
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
Structure representing a snapshot of channel state.
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition: time.h:108
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.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:98
struct ast_channel_snapshot_dialplan * dialplan
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
const ast_string_field appl
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static struct channel_usage channels
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
#define ast_free(a)
Definition: astmm.h:182
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
struct ast_channel_snapshot_bridge * bridge
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.
static void astman_send_list_complete(struct mansession *s, const struct message *m, const char *event_name, int count)
Definition: manager.c:3228
void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag)
Send ack in manager transaction to begin a list.
Definition: manager.c:3201

◆ action_corestatus()

static int action_corestatus ( struct mansession s,
const struct message m 
)
static

Show PBX core status information.

Definition at line 6318 of file manager.c.

References ast_active_channels(), ast_lastreloadtime, ast_localtime(), ast_startuptime, ast_strftime(), ast_strlen_zero, astman_append(), astman_get_header(), and NULL.

Referenced by __init_manager().

6319 {
6320  const char *actionid = astman_get_header(m, "ActionID");
6321  char idText[150];
6322  char startuptime[150], startupdate[150];
6323  char reloadtime[150], reloaddate[150];
6324  struct ast_tm tm;
6325 
6326  if (!ast_strlen_zero(actionid)) {
6327  snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
6328  } else {
6329  idText[0] = '\0';
6330  }
6331 
6333  ast_strftime(startuptime, sizeof(startuptime), "%H:%M:%S", &tm);
6334  ast_strftime(startupdate, sizeof(startupdate), "%Y-%m-%d", &tm);
6336  ast_strftime(reloadtime, sizeof(reloadtime), "%H:%M:%S", &tm);
6337  ast_strftime(reloaddate, sizeof(reloaddate), "%Y-%m-%d", &tm);
6338 
6339  astman_append(s, "Response: Success\r\n"
6340  "%s"
6341  "CoreStartupDate: %s\r\n"
6342  "CoreStartupTime: %s\r\n"
6343  "CoreReloadDate: %s\r\n"
6344  "CoreReloadTime: %s\r\n"
6345  "CoreCurrentCalls: %d\r\n"
6346  "\r\n",
6347  idText,
6348  startupdate,
6349  startuptime,
6350  reloaddate,
6351  reloadtime,
6353  );
6354  return 0;
6355 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
#define NULL
Definition: resample.c:96
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct timeval ast_lastreloadtime
Definition: asterisk.c:337
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
Definition: localtime.c:2524
struct timeval ast_startuptime
Definition: asterisk.c:336
int ast_active_channels(void)
returns number of active/allocated channels
Definition: channel.c:499

◆ action_createconfig()

static int action_createconfig ( struct mansession s,
const struct message m 
)
static

Definition at line 4188 of file manager.c.

References ast_config_AST_CONFIG_DIR, AST_FILE_MODE, ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_str_set(), astman_get_header(), astman_send_ack(), astman_send_error(), errno, and PATH_MAX.

Referenced by __init_manager().

4189 {
4190  int fd;
4191  const char *fn = astman_get_header(m, "Filename");
4192  struct ast_str *filepath = ast_str_alloca(PATH_MAX);
4193  ast_str_set(&filepath, 0, "%s/", ast_config_AST_CONFIG_DIR);
4194  ast_str_append(&filepath, 0, "%s", fn);
4195 
4196  if ((fd = open(ast_str_buffer(filepath), O_CREAT | O_EXCL, AST_FILE_MODE)) != -1) {
4197  close(fd);
4198  astman_send_ack(s, m, "New configuration file created successfully");
4199  } else {
4200  astman_send_error(s, m, strerror(errno));
4201  }
4202 
4203  return 0;
4204 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
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
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
#define ast_str_alloca(init_len)
Definition: strings.h:800
#define AST_FILE_MODE
Definition: asterisk.h:32
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
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
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
const char * ast_config_AST_CONFIG_DIR
Definition: options.c:151
int errno
#define PATH_MAX
Definition: asterisk.h:40
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_destroy()

static void action_destroy ( void *  obj)
static

Definition at line 7372 of file manager.c.

References ao2_cleanup, ast_string_field_free_memory, manager_action::final_response, manager_action::list_responses, and manager_action::synopsis.

Referenced by ast_manager_register2().

7373 {
7374  struct manager_action *doomed = obj;
7375 
7376  if (doomed->synopsis) {
7377  /* The string fields were initialized. */
7379  }
7380  ao2_cleanup(doomed->final_response);
7381  ao2_cleanup(doomed->list_responses);
7382 }
struct ast_xml_doc_item * list_responses
Definition: manager.h:160
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
const ast_string_field synopsis
Definition: manager.h:158
struct ast_xml_doc_item * final_response
Definition: manager.h:162
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368

◆ action_events()

static int action_events ( struct mansession s,
const struct message m 
)
static

Definition at line 4343 of file manager.c.

References ARRAY_LEN, ast_strlen_zero, astman_append(), astman_get_header(), astman_send_error(), broken_events_action, permalias::num, perms, and set_eventmask().

Referenced by __init_manager().

4344 {
4345  const char *mask = astman_get_header(m, "EventMask");
4346  int res, x;
4347  const char *id = astman_get_header(m, "ActionID");
4348  char id_text[256];
4349 
4350  if (!ast_strlen_zero(id)) {
4351  snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id);
4352  } else {
4353  id_text[0] = '\0';
4354  }
4355 
4356  res = set_eventmask(s, mask);
4357  if (broken_events_action) {
4358  /* if this option is set we should not return a response on
4359  * error, or when all events are set */
4360 
4361  if (res > 0) {
4362  for (x = 0; x < ARRAY_LEN(perms); x++) {
4363  if (!strcasecmp(perms[x].label, "all") && res == perms[x].num) {
4364  return 0;
4365  }
4366  }
4367  astman_append(s, "Response: Success\r\n%s"
4368  "Events: On\r\n\r\n", id_text);
4369  } else if (res == 0)
4370  astman_append(s, "Response: Success\r\n%s"
4371  "Events: Off\r\n\r\n", id_text);
4372  return 0;
4373  }
4374 
4375  if (res > 0)
4376  astman_append(s, "Response: Success\r\n%s"
4377  "Events: On\r\n\r\n", id_text);
4378  else if (res == 0)
4379  astman_append(s, "Response: Success\r\n%s"
4380  "Events: Off\r\n\r\n", id_text);
4381  else
4382  astman_send_error(s, m, "Invalid event mask");
4383 
4384  return 0;
4385 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int num
Definition: manager.c:2016
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
static const struct permalias perms[]
static int set_eventmask(struct mansession *s, const char *eventmask)
Rather than braindead on,off this now can also accept a specific int mask value or a &#39;...
Definition: manager.c:3266
static int broken_events_action
Definition: manager.c:1474
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_extensionstate()

static int action_extensionstate ( struct mansession s,
const struct message m 
)
static

Definition at line 5974 of file manager.c.

References ast_extension_state(), ast_extension_state2str(), ast_get_hint(), ast_strlen_zero, astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), context, exten, NULL, and status.

Referenced by __init_manager().

5975 {
5976  const char *exten = astman_get_header(m, "Exten");
5977  const char *context = astman_get_header(m, "Context");
5978  char hint[256];
5979  int status;
5980 
5981  if (ast_strlen_zero(exten)) {
5982  astman_send_error(s, m, "Extension not specified");
5983  return 0;
5984  }
5985  if (ast_strlen_zero(context)) {
5986  context = "default";
5987  }
5988  status = ast_extension_state(NULL, context, exten);
5989  hint[0] = '\0';
5990  ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, context, exten);
5991  astman_start_ack(s, m);
5992  astman_append(s, "Message: Extension Status\r\n"
5993  "Exten: %s\r\n"
5994  "Context: %s\r\n"
5995  "Hint: %s\r\n"
5996  "Status: %d\r\n"
5997  "StatusText: %s\r\n"
5998  "\r\n",
5999  exten, context, hint, status,
6000  ast_extension_state2str(status));
6001  return 0;
6002 }
int ast_get_hint(char *hint, int hintsize, char *name, int namesize, struct ast_channel *c, const char *context, const char *exten)
If an extension hint exists, return non-zero.
Definition: pbx.c:4141
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
static void astman_start_ack(struct mansession *s, const struct message *m)
Definition: manager.c:3196
#define NULL
Definition: resample.c:96
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
const char * ast_extension_state2str(int extension_state)
Return string representation of the state of an extension.
Definition: pbx.c:3126
int ast_extension_state(struct ast_channel *c, const char *context, const char *exten)
Uses hint and devicestate callback to get the state of an extension.
Definition: pbx.c:3170
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
jack_status_t status
Definition: app_jack.c:146

◆ action_filter()

static int action_filter ( struct mansession s,
const struct message m 
)
static

Manager command to add an event filter to a manager session.

See also
For more details look at manager_add_filter

Definition at line 6111 of file manager.c.

References astman_get_header(), astman_send_ack(), astman_send_error(), mansession_session::blackfilters, filter(), FILTER_ALLOC_FAILED, FILTER_COMPILE_FAIL, FILTER_SUCCESS, manager_add_filter(), mansession::session, and mansession_session::whitefilters.

Referenced by __init_manager().

6112 {
6113  const char *filter = astman_get_header(m, "Filter");
6114  const char *operation = astman_get_header(m, "Operation");
6115  int res;
6116 
6117  if (!strcasecmp(operation, "Add")) {
6119 
6120  if (res != FILTER_SUCCESS) {
6121  if (res == FILTER_ALLOC_FAILED) {
6122  astman_send_error(s, m, "Internal Error. Failed to allocate regex for filter");
6123  return 0;
6124  } else if (res == FILTER_COMPILE_FAIL) {
6125  astman_send_error(s, m, "Filter did not compile. Check the syntax of the filter given.");
6126  return 0;
6127  } else {
6128  astman_send_error(s, m, "Internal Error. Failed adding filter.");
6129  return 0;
6130  }
6131  }
6132 
6133  astman_send_ack(s, m, "Success");
6134  return 0;
6135  }
6136 
6137  astman_send_error(s, m, "Unknown operation");
6138  return 0;
6139 }
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
struct ao2_container * blackfilters
Definition: manager.c:1600
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
struct ao2_container * whitefilters
Definition: manager.c:1599
static enum add_filter_result manager_add_filter(const char *filter_pattern, struct ao2_container *whitefilters, struct ao2_container *blackfilters)
Add an event filter to a manager session.
Definition: manager.c:6162
struct mansession_session * session
Definition: manager.c:1626
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:709
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_find()

static struct manager_action* action_find ( const char *  name)
static

Definition at line 1704 of file manager.c.

References manager_action::action, ao2_t_ref, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, and AST_RWLIST_UNLOCK.

Referenced by ast_hook_send_action(), and process_message().

1705 {
1706  struct manager_action *act;
1707 
1709  AST_RWLIST_TRAVERSE(&actions, act, list) {
1710  if (!strcasecmp(name, act->action)) {
1711  ao2_t_ref(act, +1, "found action object");
1712  break;
1713  }
1714  }
1716 
1717  return act;
1718 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
const char * action
Definition: manager.h:151
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
list of actions registered
Definition: manager.c:1665
static const char name[]
Definition: cdr_mysql.c:74

◆ action_getconfig()

static int action_getconfig ( struct mansession s,
const struct message m 
)
static

Definition at line 3620 of file manager.c.

References ast_category_browse_filtered(), ast_category_first(), ast_category_get_name(), ast_category_get_templates(), ast_category_is_template(), ast_config_destroy(), ast_config_load2(), ast_free, ast_str_buffer(), ast_str_strlen(), ast_strlen_zero, astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), eventqent::category, CONFIG_FLAG_NOCACHE, CONFIG_FLAG_WITHCOMMENTS, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, filter(), ast_variable::name, ast_variable::next, NULL, templates, and ast_variable::value.

Referenced by __init_manager().

3621 {
3622  struct ast_config *cfg;
3623  const char *fn = astman_get_header(m, "Filename");
3624  const char *category = astman_get_header(m, "Category");
3625  const char *filter = astman_get_header(m, "Filter");
3626  const char *category_name;
3627  int catcount = 0;
3628  int lineno = 0;
3629  struct ast_category *cur_category = NULL;
3630  struct ast_variable *v;
3631  struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE };
3632 
3633  if (ast_strlen_zero(fn)) {
3634  astman_send_error(s, m, "Filename not specified");
3635  return 0;
3636  }
3637 
3638  cfg = ast_config_load2(fn, "manager", config_flags);
3639  if (cfg == CONFIG_STATUS_FILEMISSING) {
3640  astman_send_error(s, m, "Config file not found");
3641  return 0;
3642  } else if (cfg == CONFIG_STATUS_FILEINVALID) {
3643  astman_send_error(s, m, "Config file has invalid format");
3644  return 0;
3645  }
3646 
3647  astman_start_ack(s, m);
3648  while ((cur_category = ast_category_browse_filtered(cfg, category, cur_category, filter))) {
3649  struct ast_str *templates;
3650 
3651  category_name = ast_category_get_name(cur_category);
3652  lineno = 0;
3653  astman_append(s, "Category-%06d: %s\r\n", catcount, category_name);
3654 
3655  if (ast_category_is_template(cur_category)) {
3656  astman_append(s, "IsTemplate-%06d: %d\r\n", catcount, 1);
3657  }
3658 
3659  if ((templates = ast_category_get_templates(cur_category))
3660  && ast_str_strlen(templates) > 0) {
3661  astman_append(s, "Templates-%06d: %s\r\n", catcount, ast_str_buffer(templates));
3662  ast_free(templates);
3663  }
3664 
3665  for (v = ast_category_first(cur_category); v; v = v->next) {
3666  astman_append(s, "Line-%06d-%06d: %s=%s\r\n", catcount, lineno++, v->name, v->value);
3667  }
3668 
3669  catcount++;
3670  }
3671 
3672  if (!ast_strlen_zero(category) && catcount == 0) { /* TODO: actually, a config with no categories doesn't even get loaded */
3673  astman_append(s, "No categories found\r\n");
3674  }
3675 
3676  ast_config_destroy(cfg);
3677  astman_append(s, "\r\n");
3678 
3679  return 0;
3680 }
int ast_category_is_template(const struct ast_category *category)
Check if category is a template.
Definition: main/config.c:1033
struct ast_variable * next
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
static void astman_start_ack(struct mansession *s, const struct message *m)
Definition: manager.c:3196
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define CONFIG_STATUS_FILEINVALID
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Definition: main/config.c:3154
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
struct ast_category * ast_category_browse_filtered(struct ast_config *config, const char *category_name, struct ast_category *prev, const char *filter)
Browse categories with filters.
Definition: main/config.c:1335
struct ast_str * ast_category_get_templates(const struct ast_category *category)
Return the template names this category inherits from.
Definition: main/config.c:1038
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct ast_variable * ast_category_first(struct ast_category *cat)
given a pointer to a category, return the root variable.
Definition: main/config.c:1157
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static struct templates templates
#define ast_free(a)
Definition: astmm.h:182
Structure used to handle boolean flags.
Definition: utils.h:199
#define CONFIG_STATUS_FILEMISSING
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:709
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
const char * ast_category_get_name(const struct ast_category *category)
Return the name of the category.
Definition: main/config.c:1028

◆ action_getconfigjson()

static int action_getconfigjson ( struct mansession s,
const struct message m 
)
static

Definition at line 3750 of file manager.c.

References ast_category_browse_filtered(), ast_category_first(), ast_category_get_name(), ast_category_get_templates(), ast_category_is_template(), ast_config_destroy(), ast_config_load2(), ast_free, ast_str_buffer(), ast_str_strlen(), ast_strlen_zero, astman_append(), astman_append_json(), astman_get_header(), astman_send_error(), astman_start_ack(), eventqent::category, CONFIG_FLAG_NOCACHE, CONFIG_FLAG_WITHCOMMENTS, CONFIG_STATUS_FILEINVALID, filter(), ast_variable::name, ast_variable::next, NULL, templates, and ast_variable::value.

Referenced by __init_manager().

3751 {
3752  struct ast_config *cfg;
3753  const char *fn = astman_get_header(m, "Filename");
3754  const char *filter = astman_get_header(m, "Filter");
3755  const char *category = astman_get_header(m, "Category");
3756  struct ast_category *cur_category = NULL;
3757  const char *category_name;
3758  struct ast_variable *v;
3759  int comma1 = 0;
3760  struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE };
3761 
3762  if (ast_strlen_zero(fn)) {
3763  astman_send_error(s, m, "Filename not specified");
3764  return 0;
3765  }
3766 
3767  if (!(cfg = ast_config_load2(fn, "manager", config_flags))) {
3768  astman_send_error(s, m, "Config file not found");
3769  return 0;
3770  } else if (cfg == CONFIG_STATUS_FILEINVALID) {
3771  astman_send_error(s, m, "Config file has invalid format");
3772  return 0;
3773  }
3774 
3775  astman_start_ack(s, m);
3776  astman_append(s, "JSON: {");
3777  while ((cur_category = ast_category_browse_filtered(cfg, category, cur_category, filter))) {
3778  int comma2 = 0;
3779  struct ast_str *templates;
3780 
3781  category_name = ast_category_get_name(cur_category);
3782  astman_append(s, "%s\"", comma1 ? "," : "");
3783  astman_append_json(s, category_name);
3784  astman_append(s, "\":{");
3785  comma1 = 1;
3786 
3787  if (ast_category_is_template(cur_category)) {
3788  astman_append(s, "\"istemplate\":1");
3789  comma2 = 1;
3790  }
3791 
3792  if ((templates = ast_category_get_templates(cur_category))
3793  && ast_str_strlen(templates) > 0) {
3794  astman_append(s, "%s", comma2 ? "," : "");
3795  astman_append(s, "\"templates\":\"%s\"", ast_str_buffer(templates));
3796  ast_free(templates);
3797  comma2 = 1;
3798  }
3799 
3800  for (v = ast_category_first(cur_category); v; v = v->next) {
3801  astman_append(s, "%s\"", comma2 ? "," : "");
3802  astman_append_json(s, v->name);
3803  astman_append(s, "\":\"");
3804  astman_append_json(s, v->value);
3805  astman_append(s, "\"");
3806  comma2 = 1;
3807  }
3808 
3809  astman_append(s, "}");
3810  }
3811  astman_append(s, "}\r\n\r\n");
3812 
3813  ast_config_destroy(cfg);
3814 
3815  return 0;
3816 }
int ast_category_is_template(const struct ast_category *category)
Check if category is a template.
Definition: main/config.c:1033
struct ast_variable * next
static void astman_append_json(struct mansession *s, const char *str)
Definition: manager.c:3741
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
static void astman_start_ack(struct mansession *s, const struct message *m)
Definition: manager.c:3196
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define CONFIG_STATUS_FILEINVALID
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Definition: main/config.c:3154
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
struct ast_category * ast_category_browse_filtered(struct ast_config *config, const char *category_name, struct ast_category *prev, const char *filter)
Browse categories with filters.
Definition: main/config.c:1335
struct ast_str * ast_category_get_templates(const struct ast_category *category)
Return the template names this category inherits from.
Definition: main/config.c:1038
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct ast_variable * ast_category_first(struct ast_category *cat)
given a pointer to a category, return the root variable.
Definition: main/config.c:1157
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static struct templates templates
#define ast_free(a)
Definition: astmm.h:182
Structure used to handle boolean flags.
Definition: utils.h:199
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:709
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
const char * ast_category_get_name(const struct ast_category *category)
Return the name of the category.
Definition: main/config.c:1028

◆ action_getvar()

static int action_getvar ( struct mansession s,
const struct message m 
)
static

Definition at line 4610 of file manager.c.

References ast_channel_get_by_name(), ast_channel_unref, ast_dummy_channel_alloc, ast_func_read(), ast_log, ast_strlen_zero, astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), c, function_capable_string_allowed_with_auths(), LOG_ERROR, name, NULL, pbx_retrieve_variable(), S_OR, mansession::session, and mansession_session::writeperm.

Referenced by __init_manager().

4611 {
4612  struct ast_channel *c = NULL;
4613  const char *name = astman_get_header(m, "Channel");
4614  const char *varname = astman_get_header(m, "Variable");
4615  char *varval;
4616  char workspace[1024];
4617 
4618  if (ast_strlen_zero(varname)) {
4619  astman_send_error(s, m, "No variable specified");
4620  return 0;
4621  }
4622 
4623  /* We don't want users with insufficient permissions using certain functions. */
4625  astman_send_error(s, m, "GetVar Access Forbidden: Variable");
4626  return 0;
4627  }
4628 
4629  if (!ast_strlen_zero(name)) {
4630  if (!(c = ast_channel_get_by_name(name))) {
4631  astman_send_error(s, m, "No such channel");
4632  return 0;
4633  }
4634  }
4635 
4636  workspace[0] = '\0';
4637  if (varname[strlen(varname) - 1] == ')') {
4638  if (!c) {
4640  if (c) {
4641  ast_func_read(c, (char *) varname, workspace, sizeof(workspace));
4642  } else
4643  ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution. Function results may be blank.\n");
4644  } else {
4645  ast_func_read(c, (char *) varname, workspace, sizeof(workspace));
4646  }
4647  varval = workspace;
4648  } else {
4649  pbx_retrieve_variable(c, varname, &varval, workspace, sizeof(workspace), NULL);
4650  }
4651 
4652  if (c) {
4653  c = ast_channel_unref(c);
4654  }
4655 
4656  astman_start_ack(s, m);
4657  astman_append(s, "Variable: %s\r\nValue: %s\r\n\r\n", varname, S_OR(varval, ""));
4658 
4659  return 0;
4660 }
int ast_func_read(struct ast_channel *chan, const char *function, char *workspace, size_t len)
executes a read operation on a function
Main Channel structure associated with a channel.
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
static void astman_start_ack(struct mansession *s, const struct message *m)
Definition: manager.c:3196
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
static struct test_val c
#define NULL
Definition: resample.c:96
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
#define ast_dummy_channel_alloc()
Create a fake channel structure.
Definition: channel.h:1283
#define LOG_ERROR
Definition: logger.h:285
void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp)
Retrieve the value of a builtin variable or variable from the channel variable stack.
static const char name[]
Definition: cdr_mysql.c:74
static int function_capable_string_allowed_with_auths(const char *evaluating, int writepermlist)
Checks to see if a string which can be used to evaluate functions should be rejected.
Definition: manager.c:2046
#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 mansession_session * session
Definition: manager.c:1626
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_hangup()

static int action_hangup ( struct mansession s,
const struct message m 
)
static

Definition at line 4460 of file manager.c.

References mansession_session::addr, ast_channel_get_by_name(), ast_channel_iterator_all_new(), ast_channel_iterator_destroy(), ast_channel_iterator_next(), ast_channel_name(), ast_channel_softhangup_withcause_locked(), ast_channel_unref, ast_free, ast_log, ast_regex_string_to_regex_pattern(), ast_sockaddr_stringify_addr(), ast_str_buffer(), ast_str_create, ast_strlen_zero, ast_verb, astman_append(), astman_get_header(), astman_send_ack(), astman_send_error(), astman_send_error_va(), astman_send_list_complete(), astman_send_listack(), c, LOG_NOTICE, mansession_session::managerid, NULL, mansession::session, and mansession_session::username.

Referenced by __init_manager().

4461 {
4462  struct ast_channel *c = NULL;
4463  int causecode = 0; /* all values <= 0 mean 'do not set hangupcause in channel' */
4464  const char *id = astman_get_header(m, "ActionID");
4465  const char *name_or_regex = astman_get_header(m, "Channel");
4466  const char *cause = astman_get_header(m, "Cause");
4467  char idText[256];
4468  regex_t regexbuf;
4469  struct ast_channel_iterator *iter = NULL;
4470  struct ast_str *regex_string;
4471  int channels_matched = 0;
4472 
4473  if (ast_strlen_zero(name_or_regex)) {
4474  astman_send_error(s, m, "No channel specified");
4475  return 0;
4476  }
4477 
4478  if (!ast_strlen_zero(id)) {
4479  snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
4480  } else {
4481  idText[0] = '\0';
4482  }
4483 
4484  if (!ast_strlen_zero(cause)) {
4485  char *endptr;
4486  causecode = strtol(cause, &endptr, 10);
4487  if (causecode < 0 || causecode > 127 || *endptr != '\0') {
4488  ast_log(LOG_NOTICE, "Invalid 'Cause: %s' in manager action Hangup\n", cause);
4489  /* keep going, better to hangup without cause than to not hang up at all */
4490  causecode = 0; /* do not set channel's hangupcause */
4491  }
4492  }
4493 
4494  /************************************************/
4495  /* Regular explicit match channel byname hangup */
4496 
4497  if (name_or_regex[0] != '/') {
4498  if (!(c = ast_channel_get_by_name(name_or_regex))) {
4499  ast_log(LOG_NOTICE, "Request to hangup non-existent channel: %s\n",
4500  name_or_regex);
4501  astman_send_error(s, m, "No such channel");
4502  return 0;
4503  }
4504 
4505  ast_verb(3, "%sManager '%s' from %s, hanging up channel: %s\n",
4506  (s->session->managerid ? "HTTP " : ""),
4507  s->session->username,
4509  ast_channel_name(c));
4510 
4512  c = ast_channel_unref(c);
4513 
4514  astman_send_ack(s, m, "Channel Hungup");
4515 
4516  return 0;
4517  }
4518 
4519  /***********************************************/
4520  /* find and hangup any channels matching regex */
4521 
4522  regex_string = ast_str_create(strlen(name_or_regex));
4523  if (!regex_string) {
4524  astman_send_error(s, m, "Memory Allocation Failure");
4525  return 0;
4526  }
4527 
4528  /* Make "/regex/" into "regex" */
4529  if (ast_regex_string_to_regex_pattern(name_or_regex, &regex_string) != 0) {
4530  astman_send_error(s, m, "Regex format invalid, Channel param should be /regex/");
4531  ast_free(regex_string);
4532  return 0;
4533  }
4534 
4535  /* if regex compilation fails, hangup fails */
4536  if (regcomp(&regexbuf, ast_str_buffer(regex_string), REG_EXTENDED | REG_NOSUB)) {
4537  astman_send_error_va(s, m, "Regex compile failed on: %s", name_or_regex);
4538  ast_free(regex_string);
4539  return 0;
4540  }
4541 
4542  astman_send_listack(s, m, "Channels hung up will follow", "start");
4543 
4545  if (iter) {
4546  for (; (c = ast_channel_iterator_next(iter)); ast_channel_unref(c)) {
4547  if (regexec(&regexbuf, ast_channel_name(c), 0, NULL, 0)) {
4548  continue;
4549  }
4550 
4551  ast_verb(3, "%sManager '%s' from %s, hanging up channel: %s\n",
4552  (s->session->managerid ? "HTTP " : ""),
4553  s->session->username,
4555  ast_channel_name(c));
4556 
4558  channels_matched++;
4559 
4560  astman_append(s,
4561  "Event: ChannelHungup\r\n"
4562  "Channel: %s\r\n"
4563  "%s"
4564  "\r\n", ast_channel_name(c), idText);
4565  }
4567  }
4568 
4569  regfree(&regexbuf);
4570  ast_free(regex_string);
4571 
4572  astman_send_list_complete(s, m, "ChannelsHungupListComplete", channels_matched);
4573 
4574  return 0;
4575 }
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition: netsock2.h:290
Main Channel structure associated with a channel.
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
struct ast_channel * ast_channel_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Definition: channel.c:1422
char username[80]
Definition: manager.c:1592
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
static struct test_val c
struct ast_sockaddr addr
Definition: manager.c:1583
#define NULL
Definition: resample.c:96
void astman_send_error_va(struct mansession *s, const struct message *m, const char *fmt,...)
Send error in manager transaction (with va_args support)
Definition: manager.c:3164
#define ast_verb(level,...)
Definition: logger.h:463
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define LOG_NOTICE
Definition: logger.h:263
int ast_regex_string_to_regex_pattern(const char *regex_string, struct ast_str **regex_pattern)
Given a string regex_string in the form of "/regex/", convert it into the form of "regex"...
Definition: main/utils.c:1931
#define ast_free(a)
Definition: astmm.h:182
uint32_t managerid
Definition: manager.c:1588
const char * ast_channel_name(const struct ast_channel *chan)
struct ast_channel_iterator * ast_channel_iterator_destroy(struct ast_channel_iterator *i)
Destroy a channel iterator.
Definition: channel.c:1360
struct mansession_session * session
Definition: manager.c:1626
struct ast_channel_iterator * ast_channel_iterator_all_new(void)
Create a new channel iterator.
Definition: channel.c:1408
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
void ast_channel_softhangup_withcause_locked(struct ast_channel *chan, int causecode)
Lock the given channel, then request softhangup on the channel with the given causecode.
Definition: channel.c:468
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620
static void astman_send_list_complete(struct mansession *s, const struct message *m, const char *event_name, int count)
Definition: manager.c:3228
void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag)
Send ack in manager transaction to begin a list.
Definition: manager.c:3201

◆ action_listcategories()

static int action_listcategories ( struct mansession s,
const struct message m 
)
static

Definition at line 3682 of file manager.c.

References ast_category_browse_filtered(), ast_category_get_name(), ast_config_destroy(), ast_config_load2(), ast_strlen_zero, astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), eventqent::category, CONFIG_FLAG_NOCACHE, CONFIG_FLAG_WITHCOMMENTS, CONFIG_STATUS_FILEINVALID, match(), and NULL.

Referenced by __init_manager().

3683 {
3684  struct ast_config *cfg;
3685  const char *fn = astman_get_header(m, "Filename");
3686  const char *match = astman_get_header(m, "Match");
3687  struct ast_category *category = NULL;
3688  struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE };
3689  int catcount = 0;
3690 
3691  if (ast_strlen_zero(fn)) {
3692  astman_send_error(s, m, "Filename not specified");
3693  return 0;
3694  }
3695 
3696  if (!(cfg = ast_config_load2(fn, "manager", config_flags))) {
3697  astman_send_error(s, m, "Config file not found");
3698  return 0;
3699  } else if (cfg == CONFIG_STATUS_FILEINVALID) {
3700  astman_send_error(s, m, "Config file has invalid format");
3701  return 0;
3702  }
3703 
3704  astman_start_ack(s, m);
3705  while ((category = ast_category_browse_filtered(cfg, NULL, category, match))) {
3706  astman_append(s, "Category-%06d: %s\r\n", catcount, ast_category_get_name(category));
3707  catcount++;
3708  }
3709 
3710  if (catcount == 0) { /* TODO: actually, a config with no categories doesn't even get loaded */
3711  astman_append(s, "Error: no categories found\r\n");
3712  }
3713 
3714  ast_config_destroy(cfg);
3715  astman_append(s, "\r\n");
3716 
3717  return 0;
3718 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
static void astman_start_ack(struct mansession *s, const struct message *m)
Definition: manager.c:3196
#define CONFIG_STATUS_FILEINVALID
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Definition: main/config.c:3154
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2315
#define NULL
Definition: resample.c:96
struct ast_category * ast_category_browse_filtered(struct ast_config *config, const char *category_name, struct ast_category *prev, const char *filter)
Browse categories with filters.
Definition: main/config.c:1335
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
Structure used to handle boolean flags.
Definition: utils.h:199
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
const char * ast_category_get_name(const struct ast_category *category)
Return the name of the category.
Definition: main/config.c:1028

◆ action_listcommands()

static int action_listcommands ( struct mansession s,
const struct message m 
)
static

Definition at line 4324 of file manager.c.

References manager_action::action, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_str_alloca, astman_append(), astman_start_ack(), manager_action::authority, authority_to_str(), MAX_AUTH_PERM_STRING, mansession::session, manager_action::synopsis, and mansession_session::writeperm.

Referenced by __init_manager().

4325 {
4326  struct manager_action *cur;
4328 
4329  astman_start_ack(s, m);
4331  AST_RWLIST_TRAVERSE(&actions, cur, list) {
4332  if ((s->session->writeperm & cur->authority) || cur->authority == 0) {
4333  astman_append(s, "%s: %s (Priv: %s)\r\n",
4334  cur->action, cur->synopsis, authority_to_str(cur->authority, &temp));
4335  }
4336  }
4338  astman_append(s, "\r\n");
4339 
4340  return 0;
4341 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
static void astman_start_ack(struct mansession *s, const struct message *m)
Definition: manager.c:3196
#define MAX_AUTH_PERM_STRING
Definition: manager.c:2043
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
const char * action
Definition: manager.h:151
static const char * authority_to_str(int authority, struct ast_str **res)
Convert authority code to a list of options. Note that the EVENT_FLAG_ALL authority will always be re...
Definition: manager.c:2084
#define ast_str_alloca(init_len)
Definition: strings.h:800
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
list of actions registered
Definition: manager.c:1665
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
struct mansession_session * session
Definition: manager.c:1626
const ast_string_field synopsis
Definition: manager.h:158

◆ action_loggerrotate()

static int action_loggerrotate ( struct mansession s,
const struct message m 
)
static

Manager command "LoggerRotate" - reloads and rotates the logger in the same manner as the CLI command 'logger rotate'.

Definition at line 6458 of file manager.c.

References ast_logger_rotate(), astman_send_ack(), and astman_send_error().

Referenced by __init_manager().

6459 {
6460  if (ast_logger_rotate()) {
6461  astman_send_error(s, m, "Failed to reload the logger and rotate log files");
6462  return 0;
6463  }
6464 
6465  astman_send_ack(s, m, "Reloaded the logger and rotated log files");
6466  return 0;
6467 }
int ast_logger_rotate(void)
Reload logger while rotating log files.
Definition: logger.c:1254
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_login()

static int action_login ( struct mansession s,
const struct message m 
)
static

Definition at line 4393 of file manager.c.

References mansession_session::addr, ast_atomic_fetchadd_int(), ast_lastreloadtime, AST_OPT_FLAG_FULLY_BOOTED, ast_options, ast_sockaddr_stringify_addr(), ast_startuptime, ast_str_alloca, ast_test_flag, ast_tvnow(), ast_tvsub(), ast_verb, astman_append(), astman_send_ack(), astman_send_error(), authenticate(), mansession_session::authenticated, authority_to_str(), EVENT_FLAG_SYSTEM, manager_displayconnects(), mansession_session::managerid, MAX_AUTH_PERM_STRING, mansession_session::readperm, mansession_session::send_events, mansession::session, tmp(), unauth_sessions, and mansession_session::username.

Referenced by __init_manager().

4394 {
4395 
4396  /* still authenticated - don't process again */
4397  if (s->session->authenticated) {
4398  astman_send_ack(s, m, "Already authenticated");
4399  return 0;
4400  }
4401 
4402  if (authenticate(s, m)) {
4403  sleep(1);
4404  astman_send_error(s, m, "Authentication failed");
4405  return -1;
4406  }
4407  s->session->authenticated = 1;
4409  if (manager_displayconnects(s->session)) {
4410  ast_verb(2, "%sManager '%s' logged on from %s\n", (s->session->managerid ? "HTTP " : ""), s->session->username, ast_sockaddr_stringify_addr(&s->session->addr));
4411  }
4412  astman_send_ack(s, m, "Authentication accepted");
4417  const char *cat_str = authority_to_str(EVENT_FLAG_SYSTEM, &auth);
4418  long uptime = 0;
4419  long lastreloaded = 0;
4420  struct timeval tmp;
4421  struct timeval curtime = ast_tvnow();
4422 
4423  if (ast_startuptime.tv_sec) {
4424  tmp = ast_tvsub(curtime, ast_startuptime);
4425  uptime = tmp.tv_sec;
4426  }
4427 
4428  if (ast_lastreloadtime.tv_sec) {
4429  tmp = ast_tvsub(curtime, ast_lastreloadtime);
4430  lastreloaded = tmp.tv_sec;
4431  }
4432 
4433  astman_append(s, "Event: FullyBooted\r\n"
4434  "Privilege: %s\r\n"
4435  "Uptime: %ld\r\n"
4436  "LastReload: %ld\r\n"
4437  "Status: Fully Booted\r\n\r\n", cat_str, uptime, lastreloaded);
4438  }
4439  return 0;
4440 }
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition: netsock2.h:290
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
char username[80]
Definition: manager.c:1592
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define MAX_AUTH_PERM_STRING
Definition: manager.c:2043
static int authenticate(struct mansession *s, const struct message *m)
Definition: manager.c:3505
static int tmp()
Definition: bt_open.c:389
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
static const char * authority_to_str(int authority, struct ast_str **res)
Convert authority code to a list of options. Note that the EVENT_FLAG_ALL authority will always be re...
Definition: manager.c:2084
#define ast_str_alloca(init_len)
Definition: strings.h:800
struct ast_sockaddr addr
Definition: manager.c:1583
static int unauth_sessions
Definition: manager.c:1486
#define ast_verb(level,...)
Definition: logger.h:463
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
#define EVENT_FLAG_SYSTEM
Definition: manager.h:71
struct timeval ast_lastreloadtime
Definition: asterisk.c:337
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
uint32_t managerid
Definition: manager.c:1588
struct timeval ast_startuptime
Definition: asterisk.c:336
struct ast_flags ast_options
Definition: options.c:61
struct mansession_session * session
Definition: manager.c:1626
struct timeval ast_tvsub(struct timeval a, struct timeval b)
Returns the difference of two timevals a - b.
Definition: extconf.c:2298
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
static int manager_displayconnects(struct mansession_session *session)
Get displayconnects config option.
Definition: manager.c:2322

◆ action_logoff()

static int action_logoff ( struct mansession s,
const struct message m 
)
static

Definition at line 4387 of file manager.c.

References astman_send_response().

Referenced by __init_manager().

4388 {
4389  astman_send_response(s, m, "Goodbye", "Thanks for all the fish.");
4390  return -1;
4391 }
void astman_send_response(struct mansession *s, const struct message *m, char *resp, char *msg)
Send response in manager transaction.
Definition: manager.c:3154

◆ action_mailboxcount()

static int action_mailboxcount ( struct mansession s,
const struct message m 
)
static

Definition at line 5953 of file manager.c.

References ast_app_inboxcount2(), ast_strlen_zero, astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), and mailbox.

Referenced by __init_manager().

5954 {
5955  const char *mailbox = astman_get_header(m, "Mailbox");
5956  int newmsgs = 0, oldmsgs = 0, urgentmsgs = 0;;
5957 
5958  if (ast_strlen_zero(mailbox)) {
5959  astman_send_error(s, m, "Mailbox not specified");
5960  return 0;
5961  }
5962  ast_app_inboxcount2(mailbox, &urgentmsgs, &newmsgs, &oldmsgs);
5963  astman_start_ack(s, m);
5964  astman_append(s, "Message: Mailbox Message Count\r\n"
5965  "Mailbox: %s\r\n"
5966  "UrgMessages: %d\r\n"
5967  "NewMessages: %d\r\n"
5968  "OldMessages: %d\r\n"
5969  "\r\n",
5970  mailbox, urgentmsgs, newmsgs, oldmsgs);
5971  return 0;
5972 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
static void astman_start_ack(struct mansession *s, const struct message *m)
Definition: manager.c:3196
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
static char mailbox[AST_MAX_MAILBOX_UNIQUEID]
Definition: chan_mgcp.c:204
int ast_app_inboxcount2(const char *mailboxes, int *urgentmsgs, int *newmsgs, int *oldmsgs)
Determine number of urgent/new/old messages in a mailbox.
Definition: main/app.c:692
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_mailboxstatus()

static int action_mailboxstatus ( struct mansession s,
const struct message m 
)
static

Definition at line 5936 of file manager.c.

References ast_app_has_voicemail(), ast_strlen_zero, astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), mailbox, and NULL.

Referenced by __init_manager().

5937 {
5938  const char *mailbox = astman_get_header(m, "Mailbox");
5939  int ret;
5940 
5941  if (ast_strlen_zero(mailbox)) {
5942  astman_send_error(s, m, "Mailbox not specified");
5943  return 0;
5944  }
5945  ret = ast_app_has_voicemail(mailbox, NULL);
5946  astman_start_ack(s, m);
5947  astman_append(s, "Message: Mailbox Status\r\n"
5948  "Mailbox: %s\r\n"
5949  "Waiting: %d\r\n\r\n", mailbox, ret);
5950  return 0;
5951 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
static void astman_start_ack(struct mansession *s, const struct message *m)
Definition: manager.c:3196
#define NULL
Definition: resample.c:96
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
static char mailbox[AST_MAX_MAILBOX_UNIQUEID]
Definition: chan_mgcp.c:204
int ast_app_has_voicemail(const char *mailboxes, const char *folder)
Determine if a given mailbox has any voicemail If folder is NULL, defaults to "INBOX". If folder is "INBOX", includes the number of messages in the "Urgent" folder.
Definition: main/app.c:655
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_originate()

static int action_originate ( struct mansession s,
const struct message m 
)
static

Definition at line 5723 of file manager.c.

References ao2_cleanup, app, ast_callerid_parse(), ast_calloc, ast_copy_string(), ast_exists_extension(), ast_findlabel_extension(), ast_format_cap_alloc, ast_format_cap_append, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_remove_by_type(), ast_format_cap_update_by_allow_disallow(), ast_format_slin, ast_free, AST_MAX_PUBLIC_UNIQUEID, AST_MEDIA_TYPE_UNKNOWN, AST_OUTGOING_WAIT, ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pthread_create_detached, ast_shrink_phone_number(), ast_string_field_build, ast_string_field_init, ast_string_field_set, ast_strlen_zero, ast_true(), ast_variables_destroy(), ast_variables_dup(), astman_get_header(), astman_get_variables(), astman_send_ack(), astman_send_error(), astman_send_error_va(), fast_originate_helper::cap, mansession_session::chanvars, cid_name, cid_num, codecs, context, destroy_fast_originate_helper(), fast_originate_helper::early_media, EVENT_FLAG_SYSTEM, exten, fast_originate(), name, ast_variable::next, NULL, priority, fast_originate_helper::priority, mansession::session, strcasestr(), fast_originate_helper::timeout, tmp(), ast_assigned_ids::uniqueid, ast_assigned_ids::uniqueid2, fast_originate_helper::vars, and mansession_session::writeperm.

Referenced by __init_manager().

5724 {
5725  const char *name = astman_get_header(m, "Channel");
5726  const char *exten = astman_get_header(m, "Exten");
5727  const char *context = astman_get_header(m, "Context");
5728  const char *priority = astman_get_header(m, "Priority");
5729  const char *timeout = astman_get_header(m, "Timeout");
5730  const char *callerid = astman_get_header(m, "CallerID");
5731  const char *account = astman_get_header(m, "Account");
5732  const char *app = astman_get_header(m, "Application");
5733  const char *appdata = astman_get_header(m, "Data");
5734  const char *async = astman_get_header(m, "Async");
5735  const char *id = astman_get_header(m, "ActionID");
5736  const char *codecs = astman_get_header(m, "Codecs");
5737  const char *early_media = astman_get_header(m, "Earlymedia");
5738  struct ast_assigned_ids assignedids = {
5739  .uniqueid = astman_get_header(m, "ChannelId"),
5740  .uniqueid2 = astman_get_header(m, "OtherChannelId"),
5741  };
5742  struct ast_variable *vars = NULL;
5743  char *tech, *data;
5744  char *l = NULL, *n = NULL;
5745  int pi = 0;
5746  int res;
5747  int to = 30000;
5748  int reason = 0;
5749  char tmp[256];
5750  char tmp2[256];
5752  pthread_t th;
5753  int bridge_early = 0;
5754 
5755  if (!cap) {
5756  astman_send_error(s, m, "Internal Error. Memory allocation failure.");
5757  return 0;
5758  }
5760 
5761  if ((assignedids.uniqueid && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid))
5762  || (assignedids.uniqueid2 && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid2))) {
5763  astman_send_error_va(s, m, "Uniqueid length exceeds maximum of %d\n",
5765  res = 0;
5766  goto fast_orig_cleanup;
5767  }
5768 
5769  if (ast_strlen_zero(name)) {
5770  astman_send_error(s, m, "Channel not specified");
5771  res = 0;
5772  goto fast_orig_cleanup;
5773  }
5774  if (!ast_strlen_zero(priority) && (sscanf(priority, "%30d", &pi) != 1)) {
5775  if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) {
5776  astman_send_error(s, m, "Invalid priority");
5777  res = 0;
5778  goto fast_orig_cleanup;
5779  }
5780  }
5781  if (!ast_strlen_zero(timeout) && (sscanf(timeout, "%30d", &to) != 1)) {
5782  astman_send_error(s, m, "Invalid timeout");
5783  res = 0;
5784  goto fast_orig_cleanup;
5785  }
5786  ast_copy_string(tmp, name, sizeof(tmp));
5787  tech = tmp;
5788  data = strchr(tmp, '/');
5789  if (!data) {
5790  astman_send_error(s, m, "Invalid channel");
5791  res = 0;
5792  goto fast_orig_cleanup;
5793  }
5794  *data++ = '\0';
5795  ast_copy_string(tmp2, callerid, sizeof(tmp2));
5796  ast_callerid_parse(tmp2, &n, &l);
5797  if (n) {
5798  if (ast_strlen_zero(n)) {
5799  n = NULL;
5800  }
5801  }
5802  if (l) {
5804  if (ast_strlen_zero(l)) {
5805  l = NULL;
5806  }
5807  }
5808  if (!ast_strlen_zero(codecs)) {
5811  }
5812 
5813  if (!ast_strlen_zero(app) && s->session) {
5814  int bad_appdata = 0;
5815  /* To run the System application (or anything else that goes to
5816  * shell), you must have the additional System privilege */
5817  if (!(s->session->writeperm & EVENT_FLAG_SYSTEM)
5818  && (
5819  strcasestr(app, "system") || /* System(rm -rf /)
5820  TrySystem(rm -rf /) */
5821  strcasestr(app, "exec") || /* Exec(System(rm -rf /))
5822  TryExec(System(rm -rf /)) */
5823  strcasestr(app, "agi") || /* AGI(/bin/rm,-rf /)
5824  EAGI(/bin/rm,-rf /) */
5825  strcasestr(app, "mixmonitor") || /* MixMonitor(blah,,rm -rf) */
5826  strcasestr(app, "externalivr") || /* ExternalIVR(rm -rf) */
5827  strcasestr(app, "originate") || /* Originate(Local/1234,app,System,rm -rf) */
5828  (strstr(appdata, "SHELL") && (bad_appdata = 1)) || /* NoOp(${SHELL(rm -rf /)}) */
5829  (strstr(appdata, "EVAL") && (bad_appdata = 1)) /* NoOp(${EVAL(${some_var_containing_SHELL})}) */
5830  )) {
5831  char error_buf[64];
5832  snprintf(error_buf, sizeof(error_buf), "Originate Access Forbidden: %s", bad_appdata ? "Data" : "Application");
5833  astman_send_error(s, m, error_buf);
5834  res = 0;
5835  goto fast_orig_cleanup;
5836  }
5837  }
5838 
5839  /* Check early if the extension exists. If not, we need to bail out here. */
5840  if (exten && context && pi) {
5841  if (! ast_exists_extension(NULL, context, exten, pi, l)) {
5842  /* The extension does not exist. */
5843  astman_send_error(s, m, "Extension does not exist.");
5844  res = 0;
5845  goto fast_orig_cleanup;
5846  }
5847  }
5848 
5849  /* Allocate requested channel variables */
5850  vars = astman_get_variables(m);
5851  if (s->session && s->session->chanvars) {
5852  struct ast_variable *v, *old;
5853  old = vars;
5854  vars = NULL;
5855 
5856  /* The variables in the AMI originate action are appended at the end of the list, to override any user variables that apply*/
5857 
5858  vars = ast_variables_dup(s->session->chanvars);
5859  if (old) {
5860  for (v = vars; v->next; v = v->next );
5861  if (v->next) {
5862  v->next = old; /* Append originate variables at end of list */
5863  }
5864  }
5865  }
5866 
5867  /* For originate async - we can bridge in early media stage */
5868  bridge_early = ast_true(early_media);
5869 
5870  if (ast_true(async)) {
5871  struct fast_originate_helper *fast;
5872 
5873  fast = ast_calloc(1, sizeof(*fast));
5874  if (!fast || ast_string_field_init(fast, 252)) {
5875  ast_free(fast);
5876  ast_variables_destroy(vars);
5877  res = -1;
5878  } else {
5879  if (!ast_strlen_zero(id)) {
5880  ast_string_field_build(fast, idtext, "ActionID: %s\r\n", id);
5881  }
5882  ast_string_field_set(fast, tech, tech);
5883  ast_string_field_set(fast, data, data);
5884  ast_string_field_set(fast, app, app);
5885  ast_string_field_set(fast, appdata, appdata);
5886  ast_string_field_set(fast, cid_num, l);
5887  ast_string_field_set(fast, cid_name, n);
5888  ast_string_field_set(fast, context, context);
5889  ast_string_field_set(fast, exten, exten);
5890  ast_string_field_set(fast, account, account);
5891  ast_string_field_set(fast, channelid, assignedids.uniqueid);
5892  ast_string_field_set(fast, otherchannelid, assignedids.uniqueid2);
5893  fast->vars = vars;
5894  fast->cap = cap;
5895  cap = NULL; /* transfered originate helper the capabilities structure. It is now responsible for freeing it. */
5896  fast->timeout = to;
5897  fast->early_media = bridge_early;
5898  fast->priority = pi;
5899  if (ast_pthread_create_detached(&th, NULL, fast_originate, fast)) {
5901  res = -1;
5902  } else {
5903  res = 0;
5904  }
5905  }
5906  } else if (!ast_strlen_zero(app)) {
5907  res = ast_pbx_outgoing_app(tech, cap, data, to, app, appdata, &reason,
5908  AST_OUTGOING_WAIT, l, n, vars, account, NULL,
5909  assignedids.uniqueid ? &assignedids : NULL);
5910  ast_variables_destroy(vars);
5911  } else {
5912  if (exten && context && pi) {
5913  res = ast_pbx_outgoing_exten(tech, cap, data, to,
5914  context, exten, pi, &reason, AST_OUTGOING_WAIT,
5915  l, n, vars, account, NULL, bridge_early,
5916  assignedids.uniqueid ? &assignedids : NULL);
5917  ast_variables_destroy(vars);
5918  } else {
5919  astman_send_error(s, m, "Originate with 'Exten' requires 'Context' and 'Priority'");
5920  ast_variables_destroy(vars);
5921  res = 0;
5922  goto fast_orig_cleanup;
5923  }
5924  }
5925  if (!res) {
5926  astman_send_ack(s, m, "Originate successfully queued");
5927  } else {
5928  astman_send_error(s, m, "Originate failed");
5929  }
5930 
5931 fast_orig_cleanup:
5932  ao2_cleanup(cap);
5933  return 0;
5934 }
helper function for originate
Definition: manager.c:5375
struct ast_variable * next
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
const ast_string_field otherchannelid
Definition: manager.c:5393
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
#define ast_pthread_create_detached(a, b, c, d)
Definition: utils.h:563
static int timeout
Definition: cdr_mysql.c:86
static int tmp()
Definition: bt_open.c:389
Structure for variables, used for configurations and for channel variables.
Structure to pass both assignedid values to channel drivers.
Definition: channel.h:605
const char * uniqueid
Definition: channel.h:606
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
#define NULL
Definition: resample.c:96
struct ast_format_cap * cap
Definition: manager.c:5377
int ast_pbx_outgoing_exten(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *context, const char *exten, int priority, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel, int early_media, const struct ast_assigned_ids *assignedids)
Synchronously or asynchronously make an outbound call and send it to a particular extension...
Definition: pbx.c:7951
static int priority
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:164
void astman_send_error_va(struct mansession *s, const struct message *m, const char *fmt,...)
Send error in manager transaction (with va_args support)
Definition: manager.c:3164
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct ast_variable * chanvars
Definition: manager.c:1601
int ast_format_cap_update_by_allow_disallow(struct ast_format_cap *cap, const char *list, int allowing)
Parse an "allow" or "deny" list and modify a format capabilities structure accordingly.
Definition: format_cap.c:320
static void destroy_fast_originate_helper(struct fast_originate_helper *doomed)
Definition: manager.c:5405
#define EVENT_FLAG_SYSTEM
Definition: manager.h:71
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
static struct ao2_container * codecs
Registered codecs.
Definition: codec.c:48
#define ast_format_cap_append(cap, format, framing)
Definition: format_cap.h:103
struct ast_variable * vars
Definition: manager.c:5395
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:4179
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
void ast_format_cap_remove_by_type(struct ast_format_cap *cap, enum ast_media_type type)
Remove all formats matching a specific format type.
Definition: format_cap.c:525
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1951
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
int ast_findlabel_extension(struct ast_channel *c, const char *context, const char *exten, const char *label, const char *callerid)
Find the priority of an extension that has the specified label.
Definition: pbx.c:4184
struct ast_variable * astman_get_variables(const struct message *m)
Get a linked list of the Variable: headers.
Definition: manager.c:2906
int ast_pbx_outgoing_app(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *app, const char *appdata, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel, const struct ast_assigned_ids *assignedids)
Synchronously or asynchronously make an outbound call and execute an application on the channel...
Definition: pbx.c:8015
char * strcasestr(const char *, const char *)
static const char name[]
Definition: cdr_mysql.c:74
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
#define ast_string_field_build(x, field, fmt, args...)
Set a field to a complex (built) value.
Definition: stringfields.h:550
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:165
#define AST_MAX_PUBLIC_UNIQUEID
Definition: channel.h:148
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
static void * fast_originate(void *data)
Definition: manager.c:5413
const ast_string_field channelid
Definition: manager.c:5393
const ast_string_field idtext
Definition: manager.c:5393
struct mansession_session * session
Definition: manager.c:1626
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()&#39;s, .&#39;s, and -&#39;s...
Definition: callerid.c:947
static const char app[]
Definition: app_mysql.c:62
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
const char * uniqueid2
Definition: channel.h:607
struct ast_variable * ast_variables_dup(struct ast_variable *var)
Duplicate variable list.
Definition: main/config.c:545
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1008
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ action_ping()

static int action_ping ( struct mansession s,
const struct message m 
)
static

Definition at line 3602 of file manager.c.

References ast_strlen_zero, ast_tvnow(), astman_append(), and astman_get_header().

Referenced by __init_manager().

3603 {
3604  const char *actionid = astman_get_header(m, "ActionID");
3605  struct timeval now = ast_tvnow();
3606 
3607  astman_append(s, "Response: Success\r\n");
3608  if (!ast_strlen_zero(actionid)){
3609  astman_append(s, "ActionID: %s\r\n", actionid);
3610  }
3611  astman_append(
3612  s,
3613  "Ping: Pong\r\n"
3614  "Timestamp: %ld.%06lu\r\n"
3615  "\r\n",
3616  (long) now.tv_sec, (unsigned long) now.tv_usec);
3617  return 0;
3618 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52

◆ action_presencestate()

static int action_presencestate ( struct mansession s,
const struct message m 
)
static

Definition at line 6004 of file manager.c.

References AST_PRESENCE_INVALID, ast_presence_state2str(), ast_strlen_zero, astman_append(), astman_get_header(), astman_send_error(), astman_send_error_va(), astman_start_ack(), provider, and state.

Referenced by __init_manager().

6005 {
6006  const char *provider = astman_get_header(m, "Provider");
6008  char *subtype;
6009  char *message;
6010 
6011  if (ast_strlen_zero(provider)) {
6012  astman_send_error(s, m, "No provider specified");
6013  return 0;
6014  }
6015 
6016  state = ast_presence_state(provider, &subtype, &message);
6017  if (state == AST_PRESENCE_INVALID) {
6018  astman_send_error_va(s, m, "Invalid provider %s or provider in invalid state", provider);
6019  return 0;
6020  }
6021 
6022  astman_start_ack(s, m);
6023  astman_append(s, "Message: Presence State\r\n"
6024  "State: %s\r\n", ast_presence_state2str(state));
6025 
6026  if (!ast_strlen_zero(subtype)) {
6027  astman_append(s, "Subtype: %s\r\n", subtype);
6028  }
6029 
6030  if (!ast_strlen_zero(message)) {
6031  /* XXX The Message header here is deprecated as it
6032  * duplicates the action response header 'Message'.
6033  * Remove it in the next major revision of AMI.
6034  */
6035  astman_append(s, "Message: %s\r\n"
6036  "PresenceMessage: %s\r\n",
6037  message, message);
6038  }
6039  astman_append(s, "\r\n");
6040 
6041  return 0;
6042 }
enum sip_cc_notify_state state
Definition: chan_sip.c:959
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
static void astman_start_ack(struct mansession *s, const struct message *m)
Definition: manager.c:3196
void astman_send_error_va(struct mansession *s, const struct message *m, const char *fmt,...)
Send error in manager transaction (with va_args support)
Definition: manager.c:3164
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
ast_presence_state
Definition: presencestate.h:26
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
static struct prometheus_metrics_provider provider
Definition: bridges.c:178
const char * ast_presence_state2str(enum ast_presence_state state)
Convert presence state to text string for output.

◆ action_redirect()

static int action_redirect ( struct mansession s,
const struct message m 
)
static

action_redirect: The redirect manager command

Definition at line 4973 of file manager.c.

References ast_async_goto(), ast_channel_clear_flag(), ast_channel_flags(), ast_channel_get_by_name(), ast_channel_is_bridged(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, ast_check_hangup_locked(), ast_findlabel_extension(), AST_FLAG_BRIDGE_DUAL_REDIRECT_WAIT, ast_set_flag, ast_strlen_zero, astman_get_header(), astman_send_ack(), astman_send_error(), buf, context, exten, name, NULL, and priority.

Referenced by __init_manager().

4974 {
4975  char buf[256];
4976  const char *name = astman_get_header(m, "Channel");
4977  const char *name2 = astman_get_header(m, "ExtraChannel");
4978  const char *exten = astman_get_header(m, "Exten");
4979  const char *exten2 = astman_get_header(m, "ExtraExten");
4980  const char *context = astman_get_header(m, "Context");
4981  const char *context2 = astman_get_header(m, "ExtraContext");
4982  const char *priority = astman_get_header(m, "Priority");
4983  const char *priority2 = astman_get_header(m, "ExtraPriority");
4984  struct ast_channel *chan;
4985  struct ast_channel *chan2;
4986  int pi = 0;
4987  int pi2 = 0;
4988  int res;
4989  int chan1_wait = 0;
4990  int chan2_wait = 0;
4991 
4992  if (ast_strlen_zero(name)) {
4993  astman_send_error(s, m, "Channel not specified");
4994  return 0;
4995  }
4996 
4997  if (ast_strlen_zero(context)) {
4998  astman_send_error(s, m, "Context not specified");
4999  return 0;
5000  }
5001  if (ast_strlen_zero(exten)) {
5002  astman_send_error(s, m, "Exten not specified");
5003  return 0;
5004  }
5005  if (ast_strlen_zero(priority)) {
5006  astman_send_error(s, m, "Priority not specified");
5007  return 0;
5008  }
5009  if (sscanf(priority, "%30d", &pi) != 1) {
5010  pi = ast_findlabel_extension(NULL, context, exten, priority, NULL);
5011  }
5012  if (pi < 1) {
5013  astman_send_error(s, m, "Priority is invalid");
5014  return 0;
5015  }
5016 
5017  if (!ast_strlen_zero(name2) && !ast_strlen_zero(context2)) {
5018  /* We have an ExtraChannel and an ExtraContext */
5019  if (ast_strlen_zero(exten2)) {
5020  astman_send_error(s, m, "ExtraExten not specified");
5021  return 0;
5022  }
5023  if (ast_strlen_zero(priority2)) {
5024  astman_send_error(s, m, "ExtraPriority not specified");
5025  return 0;
5026  }
5027  if (sscanf(priority2, "%30d", &pi2) != 1) {
5028  pi2 = ast_findlabel_extension(NULL, context2, exten2, priority2, NULL);
5029  }
5030  if (pi2 < 1) {
5031  astman_send_error(s, m, "ExtraPriority is invalid");
5032  return 0;
5033  }
5034  }
5035 
5036  chan = ast_channel_get_by_name(name);
5037  if (!chan) {
5038  snprintf(buf, sizeof(buf), "Channel does not exist: %s", name);
5039  astman_send_error(s, m, buf);
5040  return 0;
5041  }
5042  if (ast_check_hangup_locked(chan)) {
5043  astman_send_error(s, m, "Redirect failed, channel not up.");
5044  chan = ast_channel_unref(chan);
5045  return 0;
5046  }
5047 
5048  if (ast_strlen_zero(name2)) {
5049  /* Single channel redirect in progress. */
5050  res = ast_async_goto(chan, context, exten, pi);
5051  if (!res) {
5052  astman_send_ack(s, m, "Redirect successful");
5053  } else {
5054  astman_send_error(s, m, "Redirect failed");
5055  }
5056  chan = ast_channel_unref(chan);
5057  return 0;
5058  }
5059 
5060  chan2 = ast_channel_get_by_name(name2);
5061  if (!chan2) {
5062  snprintf(buf, sizeof(buf), "ExtraChannel does not exist: %s", name2);
5063  astman_send_error(s, m, buf);
5064  chan = ast_channel_unref(chan);
5065  return 0;
5066  }
5067  if (ast_check_hangup_locked(chan2)) {
5068  astman_send_error(s, m, "Redirect failed, extra channel not up.");
5069  chan2 = ast_channel_unref(chan2);
5070  chan = ast_channel_unref(chan);
5071  return 0;
5072  }
5073 
5074  /* Dual channel redirect in progress. */
5075  ast_channel_lock(chan);
5076  if (ast_channel_is_bridged(chan)) {
5078  chan1_wait = 1;
5079  }
5080  ast_channel_unlock(chan);
5081 
5082  ast_channel_lock(chan2);
5083  if (ast_channel_is_bridged(chan2)) {
5085  chan2_wait = 1;
5086  }
5087  ast_channel_unlock(chan2);
5088 
5089  res = ast_async_goto(chan, context, exten, pi);
5090  if (!res) {
5091  if (!ast_strlen_zero(context2)) {
5092  res = ast_async_goto(chan2, context2, exten2, pi2);
5093  } else {
5094  res = ast_async_goto(chan2, context, exten, pi);
5095  }
5096  if (!res) {
5097  astman_send_ack(s, m, "Dual Redirect successful");
5098  } else {
5099  astman_send_error(s, m, "Secondary redirect failed");
5100  }
5101  } else {
5102  astman_send_error(s, m, "Redirect failed");
5103  }
5104 
5105  /* Release the bridge wait. */
5106  if (chan1_wait) {
5108  }
5109  if (chan2_wait) {
5111  }
5112 
5113  chan2 = ast_channel_unref(chan2);
5114  chan = ast_channel_unref(chan);
5115  return 0;
5116 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_set_flag(p, flag)
Definition: utils.h:70
int ast_check_hangup_locked(struct ast_channel *chan)
Definition: channel.c:459
void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag)
Definition: channel.c:11235
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
#define NULL
Definition: resample.c:96
static int priority
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
int ast_findlabel_extension(struct ast_channel *c, const char *context, const char *exten, const char *label, const char *callerid)
Find the priority of an extension that has the specified label.
Definition: pbx.c:4184
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
Definition: channel.c:10746
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static const char name[]
Definition: cdr_mysql.c:74
int ast_async_goto(struct ast_channel *chan, const char *context, const char *exten, int priority)
Set the channel to next execute the specified dialplan location.
Definition: pbx.c:7011
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_reload()

static int action_reload ( struct mansession s,
const struct message m 
)
static

Send a reload event.

Definition at line 6358 of file manager.c.

References ast_module_reload(), AST_MODULE_RELOAD_ERROR, AST_MODULE_RELOAD_IN_PROGRESS, AST_MODULE_RELOAD_NOT_FOUND, AST_MODULE_RELOAD_NOT_IMPLEMENTED, AST_MODULE_RELOAD_QUEUED, AST_MODULE_RELOAD_SUCCESS, AST_MODULE_RELOAD_UNINITIALIZED, astman_get_header(), astman_send_ack(), astman_send_error(), NULL, and S_OR.

Referenced by __init_manager().

6359 {
6360  const char *module = astman_get_header(m, "Module");
6361  enum ast_module_reload_result res = ast_module_reload(S_OR(module, NULL));
6362 
6363  switch (res) {
6365  astman_send_error(s, m, "No such module");
6366  break;
6368  astman_send_error(s, m, "Module does not support reload");
6369  break;
6371  astman_send_error(s, m, "An unknown error occurred");
6372  break;
6374  astman_send_error(s, m, "A reload is in progress");
6375  break;
6377  astman_send_error(s, m, "Module not initialized");
6378  break;
6381  /* Treat a queued request as success */
6382  astman_send_ack(s, m, "Module Reloaded");
6383  break;
6384  }
6385  return 0;
6386 }
enum ast_module_reload_result ast_module_reload(const char *name)
Reload asterisk modules.
Definition: loader.c:1562
ast_module_reload_result
Possible return types for ast_module_reload.
Definition: module.h:109
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
#define NULL
Definition: resample.c:96
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#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
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_sendtext()

static int action_sendtext ( struct mansession s,
const struct message m 
)
static

Definition at line 4930 of file manager.c.

References ast_channel_get_by_name(), ast_channel_unref, ast_strlen_zero, astman_get_header(), astman_send_ack(), astman_send_error(), c, name, queue_sendtext(), and queue_sendtext_data().

Referenced by __init_manager().

4931 {
4932  struct ast_channel *c;
4933  const char *name = astman_get_header(m, "Channel");
4934  const char *textmsg = astman_get_header(m, "Message");
4935  const char *content_type = astman_get_header(m, "Content-Type");
4936  int res;
4937 
4938  if (ast_strlen_zero(name)) {
4939  astman_send_error(s, m, "No channel specified");
4940  return 0;
4941  }
4942 
4943  if (ast_strlen_zero(textmsg)) {
4944  astman_send_error(s, m, "No Message specified");
4945  return 0;
4946  }
4947 
4948  c = ast_channel_get_by_name(name);
4949  if (!c) {
4950  astman_send_error(s, m, "No such channel");
4951  return 0;
4952  }
4953 
4954  /*
4955  * If the "extra" data is not available, then send using "string" only.
4956  * Doing such maintains backward compatibilities.
4957  */
4958  res = ast_strlen_zero(content_type) ? queue_sendtext(c, textmsg) :
4959  queue_sendtext_data(c, textmsg, content_type);
4960 
4961  ast_channel_unref(c);
4962 
4963  if (res >= 0) {
4964  astman_send_ack(s, m, "Success");
4965  } else {
4966  astman_send_error(s, m, "Failure");
4967  }
4968 
4969  return 0;
4970 }
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
static struct test_val c
static int queue_sendtext(struct ast_channel *chan, const char *body)
Queue a read action to send a text message.
Definition: manager.c:4896
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
static const char name[]
Definition: cdr_mysql.c:74
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
static int queue_sendtext_data(struct ast_channel *chan, const char *body, const char *content_type)
Queue a read action to send a text data message.
Definition: manager.c:4911

◆ action_setvar()

static int action_setvar ( struct mansession s,
const struct message m 
)
static

Definition at line 4577 of file manager.c.

References ast_channel_get_by_name(), ast_channel_unref, ast_strlen_zero, astman_get_header(), astman_send_ack(), astman_send_error(), c, name, NULL, pbx_builtin_setvar_helper(), and S_OR.

Referenced by __init_manager().

4578 {
4579  struct ast_channel *c = NULL;
4580  const char *name = astman_get_header(m, "Channel");
4581  const char *varname = astman_get_header(m, "Variable");
4582  const char *varval = astman_get_header(m, "Value");
4583  int res = 0;
4584 
4585  if (ast_strlen_zero(varname)) {
4586  astman_send_error(s, m, "No variable specified");
4587  return 0;
4588  }
4589 
4590  if (!ast_strlen_zero(name)) {
4591  if (!(c = ast_channel_get_by_name(name))) {
4592  astman_send_error(s, m, "No such channel");
4593  return 0;
4594  }
4595  }
4596 
4597  res = pbx_builtin_setvar_helper(c, varname, S_OR(varval, ""));
4598 
4599  if (c) {
4600  c = ast_channel_unref(c);
4601  }
4602  if (res == 0) {
4603  astman_send_ack(s, m, "Variable Set");
4604  } else {
4605  astman_send_error(s, m, "Variable not set");
4606  }
4607  return 0;
4608 }
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
static struct test_val c
#define NULL
Definition: resample.c:96
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
static const char name[]
Definition: cdr_mysql.c:74
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
#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 * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_status()

static int action_status ( struct mansession s,
const struct message m 
)
static

Manager "status" command to show channels.

Definition at line 4777 of file manager.c.

References AST_APP_ARG, ast_channel_get_by_name(), ast_channel_iterator_all_new(), ast_channel_iterator_destroy(), ast_channel_iterator_next(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, AST_DECLARE_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero, ast_true(), astman_append(), astman_get_header(), astman_send_error(), astman_send_list_complete_end(), astman_send_list_complete_start(), astman_send_listack(), channels, function_capable_string_allowed_with_auths(), generate_status(), name, NULL, S_OR, mansession::session, and mansession_session::writeperm.

Referenced by __init_manager().

4778 {
4779  const char *name = astman_get_header(m, "Channel");
4780  const char *chan_variables = astman_get_header(m, "Variables");
4781  const char *all_chan_variables = astman_get_header(m, "AllVariables");
4782  int all_variables = 0;
4783  const char *id = astman_get_header(m, "ActionID");
4784  char *variables = ast_strdupa(S_OR(chan_variables, ""));
4785  struct ast_channel *chan;
4786  int channels = 0;
4787  int all = ast_strlen_zero(name); /* set if we want all channels */
4788  char id_text[256];
4789  struct ast_channel_iterator *it_chans = NULL;
4790  AST_DECLARE_APP_ARGS(vars,
4791  AST_APP_ARG(name)[100];
4792  );
4793 
4794  if (!ast_strlen_zero(all_chan_variables)) {
4795  all_variables = ast_true(all_chan_variables);
4796  }
4797 
4799  astman_send_error(s, m, "Status Access Forbidden: Variables");
4800  return 0;
4801  }
4802 
4803  if (all) {
4804  if (!(it_chans = ast_channel_iterator_all_new())) {
4805  astman_send_error(s, m, "Memory Allocation Failure");
4806  return 1;
4807  }
4808  chan = ast_channel_iterator_next(it_chans);
4809  } else {
4810  chan = ast_channel_get_by_name(name);
4811  if (!chan) {
4812  astman_send_error(s, m, "No such channel");
4813  return 0;
4814  }
4815  }
4816 
4817  astman_send_listack(s, m, "Channel status will follow", "start");
4818 
4819  if (!ast_strlen_zero(id)) {
4820  snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id);
4821  } else {
4822  id_text[0] = '\0';
4823  }
4824 
4825  if (!ast_strlen_zero(chan_variables)) {
4826  AST_STANDARD_APP_ARGS(vars, variables);
4827  }
4828 
4829  /* if we look by name, we break after the first iteration */
4830  for (; chan; all ? chan = ast_channel_iterator_next(it_chans) : 0) {
4831  ast_channel_lock(chan);
4832 
4833  generate_status(s, chan, vars.name, vars.argc, all_variables, id_text, &channels);
4834 
4835  ast_channel_unlock(chan);
4836  chan = ast_channel_unref(chan);
4837  }
4838 
4839  if (it_chans) {
4840  ast_channel_iterator_destroy(it_chans);
4841  }
4842 
4843  astman_send_list_complete_start(s, m, "StatusComplete", channels);
4844  astman_append(s, "Items: %d\r\n", channels);
4846 
4847  return 0;
4848 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
Main Channel structure associated with a channel.
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
struct ast_channel * ast_channel_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Definition: channel.c:1422
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
void astman_send_list_complete_start(struct mansession *s, const struct message *m, const char *event_name, int count)
Start the list complete event.
Definition: manager.c:3237
#define NULL
Definition: resample.c:96
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
static void generate_status(struct mansession *s, struct ast_channel *chan, char **vars, int varc, int all_variables, char *id_text, int *count)
Definition: manager.c:4662
void astman_send_list_complete_end(struct mansession *s)
End the list complete event.
Definition: manager.c:3245
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static struct channel_usage channels
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1951
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static const char name[]
Definition: cdr_mysql.c:74
static int function_capable_string_allowed_with_auths(const char *evaluating, int writepermlist)
Checks to see if a string which can be used to evaluate functions should be rejected.
Definition: manager.c:2046
#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_iterator * ast_channel_iterator_destroy(struct ast_channel_iterator *i)
Destroy a channel iterator.
Definition: channel.c:1360
struct mansession_session * session
Definition: manager.c:1626
struct ast_channel_iterator * ast_channel_iterator_all_new(void)
Create a new channel iterator.
Definition: channel.c:1408
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.
void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag)
Send ack in manager transaction to begin a list.
Definition: manager.c:3201

◆ action_timeout()

static int action_timeout ( struct mansession s,
const struct message m 
)
static

Definition at line 6044 of file manager.c.

References ast_channel_get_by_name(), ast_channel_lock, ast_channel_setwhentohangup_tv(), ast_channel_unlock, ast_channel_unref, ast_strlen_zero, astman_get_header(), astman_send_ack(), astman_send_error(), c, name, and timeout.

Referenced by __init_manager().

6045 {
6046  struct ast_channel *c;
6047  const char *name = astman_get_header(m, "Channel");
6048  double timeout = atof(astman_get_header(m, "Timeout"));
6049  struct timeval when = { timeout, 0 };
6050 
6051  if (ast_strlen_zero(name)) {
6052  astman_send_error(s, m, "No channel specified");
6053  return 0;
6054  }
6055 
6056  if (!timeout || timeout < 0) {
6057  astman_send_error(s, m, "No timeout specified");
6058  return 0;
6059  }
6060 
6061  if (!(c = ast_channel_get_by_name(name))) {
6062  astman_send_error(s, m, "No such channel");
6063  return 0;
6064  }
6065 
6066  when.tv_usec = (timeout - when.tv_sec) * 1000000.0;
6067 
6068  ast_channel_lock(c);
6070  ast_channel_unlock(c);
6071  c = ast_channel_unref(c);
6072 
6073  astman_send_ack(s, m, "Timeout Set");
6074 
6075  return 0;
6076 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset)
Set when to hang a channel up.
Definition: channel.c:510
static int timeout
Definition: cdr_mysql.c:86
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
static struct test_val c
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static const char name[]
Definition: cdr_mysql.c:74
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_updateconfig()

static int action_updateconfig ( struct mansession s,
const struct message m 
)
static

Definition at line 4102 of file manager.c.

References ast_config_destroy(), ast_config_load2(), ast_config_text_file_save2(), ast_include_rename(), ast_module_reload(), ast_strlen_zero, ast_true(), astman_get_header(), astman_send_ack(), astman_send_error(), CONFIG_FLAG_NOCACHE, CONFIG_FLAG_WITHCOMMENTS, CONFIG_SAVE_FLAG_NONE, CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT, CONFIG_STATUS_FILEINVALID, FAILURE_ALLOCATION, FAILURE_APPEND, FAILURE_DELCAT, FAILURE_DELETE, FAILURE_EMPTYCAT, FAILURE_NEWCAT, FAILURE_TEMPLATE, FAILURE_UPDATE, handle_updates(), NULL, result, UNKNOWN_ACTION, UNKNOWN_CATEGORY, UNSPECIFIED_ARGUMENT, and UNSPECIFIED_CATEGORY.

Referenced by __init_manager().

4103 {
4104  struct ast_config *cfg;
4105  const char *sfn = astman_get_header(m, "SrcFilename");
4106  const char *dfn = astman_get_header(m, "DstFilename");
4107  int res;
4108  const char *rld = astman_get_header(m, "Reload");
4109  int preserve_effective_context = CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT;
4110  const char *preserve_effective_context_string = astman_get_header(m, "PreserveEffectiveContext");
4111  struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE };
4112  enum error_type result;
4113 
4114  if (ast_strlen_zero(sfn) || ast_strlen_zero(dfn)) {
4115  astman_send_error(s, m, "Filename not specified");
4116  return 0;
4117  }
4118  if (!(cfg = ast_config_load2(sfn, "manager", config_flags))) {
4119  astman_send_error(s, m, "Config file not found");
4120  return 0;
4121  } else if (cfg == CONFIG_STATUS_FILEINVALID) {
4122  astman_send_error(s, m, "Config file has invalid format");
4123  return 0;
4124  }
4125  result = handle_updates(s, m, cfg, dfn);
4126  if (!result) {
4127  ast_include_rename(cfg, sfn, dfn); /* change the include references from dfn to sfn, so things match up */
4128  if (!ast_strlen_zero(preserve_effective_context_string) && !ast_true(preserve_effective_context_string)) {
4129  preserve_effective_context = CONFIG_SAVE_FLAG_NONE;
4130  }
4131  res = ast_config_text_file_save2(dfn, cfg, "Manager", preserve_effective_context);
4132  ast_config_destroy(cfg);
4133  if (res) {
4134  astman_send_error(s, m, "Save of config failed");
4135  return 0;
4136  }
4137  astman_send_ack(s, m, NULL);
4138  if (!ast_strlen_zero(rld)) {
4139  if (ast_true(rld)) {
4140  rld = NULL;
4141  }
4142  ast_module_reload(rld);
4143  }
4144  } else {
4145  ast_config_destroy(cfg);
4146  switch(result) {
4147  case UNKNOWN_ACTION:
4148  astman_send_error(s, m, "Unknown action command");
4149  break;
4150  case UNKNOWN_CATEGORY:
4151  astman_send_error(s, m, "Given category does not exist");
4152  break;
4153  case UNSPECIFIED_CATEGORY:
4154  astman_send_error(s, m, "Category not specified");
4155  break;
4156  case UNSPECIFIED_ARGUMENT:
4157  astman_send_error(s, m, "Problem with category, value, or line (if required)");
4158  break;
4159  case FAILURE_ALLOCATION:
4160  astman_send_error(s, m, "Memory allocation failure, this should not happen");
4161  break;
4162  case FAILURE_NEWCAT:
4163  astman_send_error(s, m, "Create category did not complete successfully");
4164  break;
4165  case FAILURE_DELCAT:
4166  astman_send_error(s, m, "Delete category did not complete successfully");
4167  break;
4168  case FAILURE_EMPTYCAT:
4169  astman_send_error(s, m, "Empty category did not complete successfully");
4170  break;
4171  case FAILURE_UPDATE:
4172  astman_send_error(s, m, "Update did not complete successfully");
4173  break;
4174  case FAILURE_DELETE:
4175  astman_send_error(s, m, "Delete did not complete successfully");
4176  break;
4177  case FAILURE_APPEND:
4178  astman_send_error(s, m, "Append did not complete successfully");
4179  break;
4180  case FAILURE_TEMPLATE:
4181  astman_send_error(s, m, "Template category not found");
4182  break;
4183  }
4184  }
4185  return 0;
4186 }
enum ast_module_reload_result ast_module_reload(const char *name)
Reload asterisk modules.
Definition: loader.c:1562
#define CONFIG_STATUS_FILEINVALID
int ast_config_text_file_save2(const char *filename, const struct ast_config *cfg, const char *generator, uint32_t flags)
Save a config text file.
Definition: main/config.c:2555
error_type
Definition: manager.c:1419
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Definition: main/config.c:3154
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
#define NULL
Definition: resample.c:96
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
static enum error_type handle_updates(struct mansession *s, const struct message *m, struct ast_config *cfg, const char *dfn)
helper function for action_updateconfig
Definition: manager.c:3819
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1951
void ast_include_rename(struct ast_config *conf, const char *from_file, const char *to_file)
Definition: main/config.c:385
Structure used to handle boolean flags.
Definition: utils.h:199
static PGresult * result
Definition: cel_pgsql.c:88
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ action_userevent()

static int action_userevent ( struct mansession s,
const struct message m 
)
static

Definition at line 6255 of file manager.c.

References ast_str_append(), ast_str_buffer(), ast_str_reset(), ast_str_thread_get(), astman_get_header(), astman_send_ack(), EVENT_FLAG_USER, message::hdrcount, message::headers, manager_event, and userevent_buf.

Referenced by __init_manager().

6256 {
6257  const char *event = astman_get_header(m, "UserEvent");
6258  struct ast_str *body = ast_str_thread_get(&userevent_buf, 16);
6259  int x;
6260 
6261  ast_str_reset(body);
6262 
6263  for (x = 0; x < m->hdrcount; x++) {
6264  if (strncasecmp("UserEvent:", m->headers[x], strlen("UserEvent:")) &&
6265  strncasecmp("Action:", m->headers[x], strlen("Action:"))) {
6266  ast_str_append(&body, 0, "%s\r\n", m->headers[x]);
6267  }
6268  }
6269 
6270  astman_send_ack(s, m, "Event Sent");
6271  manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", event, ast_str_buffer(body));
6272  return 0;
6273 }
static struct ast_threadstorage userevent_buf
Definition: manager.c:3063
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
Definition: astman.c:222
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
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define EVENT_FLAG_USER
Definition: manager.h:77
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
Definition: strings.h:653
const char * headers[AST_MAX_MANHEADERS]
Definition: manager.h:146
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:861
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:248
unsigned int hdrcount
Definition: manager.h:145

◆ action_waitevent()

static int action_waitevent ( struct mansession s,
const struct message m 
)
static

Definition at line 4206 of file manager.c.

References advance_event(), ao2_lock, ao2_unlock, ast_debug, ast_iostream_get_fd(), ast_mutex_lock, ast_mutex_unlock, AST_PTHREADT_NULL, AST_RWLIST_NEXT, ast_strlen_zero, ast_wait_for_input(), astman_append(), astman_get_header(), astman_send_response(), eventqent::category, mansession_session::last_ev, mansession_session::managerid, match_filter(), max, mansession_session::needdestroy, mansession_session::notify_lock, NULL, mansession_session::readperm, mansession_session::send_events, mansession::session, mansession_session::sessiontimeout, mansession_session::stream, timeout, and mansession_session::waiting_thread.

Referenced by __init_manager().

4207 {
4208  const char *timeouts = astman_get_header(m, "Timeout");
4209  int timeout = -1;
4210  int x;
4211  int needexit = 0;
4212  const char *id = astman_get_header(m, "ActionID");
4213  char idText[256];
4214 
4215  if (!ast_strlen_zero(id)) {
4216  snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
4217  } else {
4218  idText[0] = '\0';
4219  }
4220 
4221  if (!ast_strlen_zero(timeouts)) {
4222  sscanf(timeouts, "%30i", &timeout);
4223  if (timeout < -1) {
4224  timeout = -1;
4225  }
4226  /* XXX maybe put an upper bound, or prevent the use of 0 ? */
4227  }
4228 
4231  pthread_kill(s->session->waiting_thread, SIGURG);
4232  }
4234 
4235  ao2_lock(s->session);
4236 
4237  if (s->session->managerid) { /* AMI-over-HTTP session */
4238  /*
4239  * Make sure the timeout is within the expire time of the session,
4240  * as the client will likely abort the request if it does not see
4241  * data coming after some amount of time.
4242  */
4243  time_t now = time(NULL);
4244  int max = s->session->sessiontimeout - now - 10;
4245 
4246  if (max < 0) { /* We are already late. Strange but possible. */
4247  max = 0;
4248  }
4249  if (timeout < 0 || timeout > max) {
4250  timeout = max;
4251  }
4252  if (!s->session->send_events) { /* make sure we record events */
4253  s->session->send_events = -1;
4254  }
4255  }
4256  ao2_unlock(s->session);
4257 
4259  s->session->waiting_thread = pthread_self(); /* let new events wake up this thread */
4261  ast_debug(1, "Starting waiting for an event!\n");
4262 
4263  for (x = 0; x < timeout || timeout < 0; x++) {
4264  ao2_lock(s->session);
4265  if (AST_RWLIST_NEXT(s->session->last_ev, eq_next)) {
4266  needexit = 1;
4267  }
4268  if (s->session->needdestroy) {
4269  needexit = 1;
4270  }
4271  ao2_unlock(s->session);
4272  /* We can have multiple HTTP session point to the same mansession entry.
4273  * The way we deal with it is not very nice: newcomers kick out the previous
4274  * HTTP session. XXX this needs to be improved.
4275  */
4277  if (s->session->waiting_thread != pthread_self()) {
4278  needexit = 1;
4279  }
4281  if (needexit) {
4282  break;
4283  }
4284  if (s->session->managerid == 0) { /* AMI session */
4286  break;
4287  }
4288  } else { /* HTTP session */
4289  sleep(1);
4290  }
4291  }
4292  ast_debug(1, "Finished waiting for an event!\n");
4293 
4295  if (s->session->waiting_thread == pthread_self()) {
4296  struct eventqent *eqe = s->session->last_ev;
4297 
4300 
4301  ao2_lock(s->session);
4302  astman_send_response(s, m, "Success", "Waiting for Event completed.");
4303  while ((eqe = advance_event(eqe))) {
4304  if (((s->session->readperm & eqe->category) == eqe->category)
4305  && ((s->session->send_events & eqe->category) == eqe->category)
4306  && match_filter(s, eqe->eventdata)) {
4307  astman_append(s, "%s", eqe->eventdata);
4308  }
4309  s->session->last_ev = eqe;
4310  }
4311  astman_append(s,
4312  "Event: WaitEventComplete\r\n"
4313  "%s"
4314  "\r\n", idText);
4315  ao2_unlock(s->session);
4316  } else {
4318  ast_debug(1, "Abandoning event request!\n");
4319  }
4320 
4321  return 0;
4322 }
#define AST_RWLIST_NEXT
Definition: linkedlists.h:440
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
pthread_t waiting_thread
Definition: manager.c:1587
static int timeout
Definition: cdr_mysql.c:86
struct eventqent * last_ev
Definition: manager.c:1603
int ast_iostream_get_fd(struct ast_iostream *stream)
Get an iostream&#39;s file descriptor.
Definition: iostream.c:84
#define ast_mutex_lock(a)
Definition: lock.h:187
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
time_t sessiontimeout
Definition: manager.c:1591
ast_mutex_t notify_lock
Definition: manager.c:1610
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define AST_PTHREADT_NULL
Definition: lock.h:66
#define ao2_lock(a)
Definition: astobj2.h:718
static struct eventqent * advance_event(struct eventqent *e)
Definition: manager.c:2753
void astman_send_response(struct mansession *s, const struct message *m, char *resp, char *msg)
Send response in manager transaction.
Definition: manager.c:3154
static int match_filter(struct mansession *s, char *eventdata)
Definition: manager.c:6193
struct ast_iostream * stream
Definition: manager.c:1584
uint32_t managerid
Definition: manager.c:1588
int category
Definition: manager.c:1461
struct mansession_session * session
Definition: manager.c:1626
int ast_wait_for_input(int fd, int ms)
Definition: main/utils.c:1519
#define ast_mutex_unlock(a)
Definition: lock.h:188
#define max(a, b)
Definition: f2c.h:198

◆ advance_event()

static struct eventqent* advance_event ( struct eventqent e)
static

Definition at line 2753 of file manager.c.

References ast_atomic_fetchadd_int(), AST_RWLIST_NEXT, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, and eventqent::usecount.

Referenced by action_waitevent(), and process_events().

2754 {
2755  struct eventqent *next;
2756 
2758  if ((next = AST_RWLIST_NEXT(e, eq_next))) {
2759  ast_atomic_fetchadd_int(&next->usecount, 1);
2761  }
2763  return next;
2764 }
#define AST_RWLIST_NEXT
Definition: linkedlists.h:440
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
int usecount
Definition: manager.c:1460

◆ AO2_GLOBAL_OBJ_STATIC() [1/2]

static AO2_GLOBAL_OBJ_STATIC ( mgr_sessions  )
static

Active manager connection sessions container.

◆ AO2_GLOBAL_OBJ_STATIC() [2/2]

static AO2_GLOBAL_OBJ_STATIC ( event_docs  )
static

A container of event documentation nodes.

◆ aocmessage_get_unit_entry()

static int aocmessage_get_unit_entry ( const struct message m,
struct ast_aoc_unit_entry entry,
unsigned int  entry_num 
)
static

Definition at line 5493 of file manager.c.

References ast_aoc_unit_entry::amount, ast_str_alloca, ast_str_buffer(), ast_str_set(), ast_strlen_zero, astman_get_header(), str, ast_aoc_unit_entry::type, ast_aoc_unit_entry::valid_amount, and ast_aoc_unit_entry::valid_type.

Referenced by action_aocmessage().

5494 {
5495  const char *unitamount;
5496  const char *unittype;
5497  struct ast_str *str = ast_str_alloca(32);
5498 
5499  memset(entry, 0, sizeof(*entry));
5500 
5501  ast_str_set(&str, 0, "UnitAmount(%u)", entry_num);
5502  unitamount = astman_get_header(m, ast_str_buffer(str));
5503 
5504  ast_str_set(&str, 0, "UnitType(%u)", entry_num);
5505  unittype = astman_get_header(m, ast_str_buffer(str));
5506 
5507  if (!ast_strlen_zero(unitamount) && (sscanf(unitamount, "%30u", &entry->amount) == 1)) {
5508  entry->valid_amount = 1;
5509  }
5510 
5511  if (!ast_strlen_zero(unittype) && sscanf(unittype, "%30u", &entry->type) == 1) {
5512  entry->valid_type = 1;
5513  }
5514 
5515  return 0;
5516 }
char valid_amount
Definition: aoc.h:179
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
unsigned int type
Definition: aoc.h:182
#define ast_str_alloca(init_len)
Definition: strings.h:800
const char * str
Definition: app_jack.c:147
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#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
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
char valid_type
Definition: aoc.h:181
unsigned int amount
Definition: aoc.h:180

◆ append_channel_vars()

static void append_channel_vars ( struct ast_str **  pbuf,
struct ast_channel chan 
)
static

Definition at line 7092 of file manager.c.

References ao2_ref, ast_channel_get_manager_vars(), ast_channel_name(), AST_LIST_TRAVERSE, ast_str_append(), ast_var_t::name, ast_var_t::value, and var.

Referenced by __manager_event_sessions_va().

7093 {
7094  struct varshead *vars;
7095  struct ast_var_t *var;
7096 
7097  vars = ast_channel_get_manager_vars(chan);
7098  if (!vars) {
7099  return;
7100  }
7101 
7102  AST_LIST_TRAVERSE(vars, var, entries) {
7103  ast_str_append(pbuf, 0, "ChanVariable(%s): %s=%s\r\n", ast_channel_name(chan), var->name, var->value);
7104  }
7105  ao2_ref(vars, -1);
7106 }
struct varshead * ast_channel_get_manager_vars(struct ast_channel *chan)
Gets the variables for a given channel, as specified by ast_channel_set_manager_vars().
Definition: channel.c:8085
#define var
Definition: ast_expr2f.c:614
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 ao2_ref(o, delta)
Definition: astobj2.h:464
char name[0]
Definition: chanvars.h:31
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
struct ast_var_t::@249 entries
const char * ast_channel_name(const struct ast_channel *chan)

◆ append_event()

static int append_event ( const char *  str,
int  category 
)
static

events are appended to a queue from where they can be dispatched to clients.

Definition at line 7068 of file manager.c.

References ast_atomic_fetchadd_int(), ast_malloc, AST_RWLIST_INSERT_TAIL, AST_RWLIST_NEXT, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_tvnow(), eventqent::category, NULL, eventqent::seq, tmp(), eventqent::tv, and eventqent::usecount.

Referenced by __init_manager(), and __manager_event_sessions_va().

7069 {
7070  struct eventqent *tmp = ast_malloc(sizeof(*tmp) + strlen(str));
7071  static int seq; /* sequence number */
7072 
7073  if (!tmp) {
7074  return -1;
7075  }
7076 
7077  /* need to init all fields, because ast_malloc() does not */
7078  tmp->usecount = 0;
7079  tmp->category = category;
7080  tmp->seq = ast_atomic_fetchadd_int(&seq, 1);
7081  tmp->tv = ast_tvnow();
7082  AST_RWLIST_NEXT(tmp, eq_next) = NULL;
7083  strcpy(tmp->eventdata, str);
7084 
7086  AST_RWLIST_INSERT_TAIL(&all_events, tmp, eq_next);
7088 
7089  return 0;
7090 }
struct timeval tv
Definition: manager.c:1463
#define AST_RWLIST_NEXT
Definition: linkedlists.h:440
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
static int tmp()
Definition: bt_open.c:389
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
const char * str
Definition: app_jack.c:147
#define NULL
Definition: resample.c:96
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
int usecount
Definition: manager.c:1460
int category
Definition: manager.c:1461
static volatile unsigned int seq
Definition: app_sms.c:120
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:740
unsigned int seq
Definition: manager.c:1462

◆ ast_hook_send_action()

int ast_hook_send_action ( struct manager_custom_hook hook,
const char *  msg 
)

access for hooks to send action messages to ami

Registered hooks can call this function to invoke actions and they will receive responses through registered callback.

Definition at line 2937 of file manager.c.

References action_find(), ao2_lock, ao2_t_ref, ao2_unlock, ARRAY_LEN, ast_free, ast_module_running_ref, ast_module_unref, ast_strdup, astman_get_header(), manager_action::func, message::hdrcount, message::headers, mansession::hook, manager_action::module, NULL, manager_action::registered, and mansession::session.

Referenced by hook_send().

2938 {
2939  const char *action;
2940  int ret = 0;
2941  struct manager_action *act_found;
2942  struct mansession s = {.session = NULL, };
2943  struct message m = { 0 };
2944  char *dup_str;
2945  char *src;
2946  int x = 0;
2947  int curlen;
2948 
2949  if (hook == NULL) {
2950  return -1;
2951  }
2952 
2953  /* Create our own copy of the AMI action msg string. */
2954  src = dup_str = ast_strdup(msg);
2955  if (!dup_str) {
2956  return -1;
2957  }
2958 
2959  /* convert msg string to message struct */
2960  curlen = strlen(src);
2961  for (x = 0; x < curlen; x++) {
2962  int cr; /* set if we have \r */
2963  if (src[x] == '\r' && x+1 < curlen && src[x+1] == '\n')
2964  cr = 2; /* Found. Update length to include \r\n */
2965  else if (src[x] == '\n')
2966  cr = 1; /* also accept \n only */
2967  else
2968  continue;
2969  /* don't keep empty lines */
2970  if (x && m.hdrcount < ARRAY_LEN(m.headers)) {
2971  /* ... but trim \r\n and terminate the header string */
2972  src[x] = '\0';
2973  m.headers[m.hdrcount++] = src;
2974  }
2975  x += cr;
2976  curlen -= x; /* remaining size */
2977  src += x; /* update pointer */
2978  x = -1; /* reset loop */
2979  }
2980 
2981  action = astman_get_header(&m, "Action");
2982 
2983  do {
2984  if (!strcasecmp(action, "login")) {
2985  break;
2986  }
2987 
2988  act_found = action_find(action);
2989  if (!act_found) {
2990  break;
2991  }
2992 
2993  /*
2994  * we have to simulate a session for this action request
2995  * to be able to pass it down for processing
2996  * This is necessary to meet the previous design of manager.c
2997  */
2998  s.hook = hook;
2999 
3000  ret = -1;
3001  ao2_lock(act_found);
3002  if (act_found->registered && act_found->func) {
3003  struct ast_module *mod_ref = ast_module_running_ref(act_found->module);
3004 
3005  ao2_unlock(act_found);
3006  /* If the action is in a module it must be running. */
3007  if (!act_found->module || mod_ref) {
3008  ret = act_found->func(&s, &m);
3009  ast_module_unref(mod_ref);
3010  }
3011  } else {
3012  ao2_unlock(act_found);
3013  }
3014  ao2_t_ref(act_found, -1, "done with found action object");
3015  } while (0);
3016 
3017  ast_free(dup_str);
3018  return ret;
3019 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int(* func)(struct mansession *s, const struct message *m)
Definition: manager.h:166
#define ao2_unlock(a)
Definition: astobj2.h:730
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
static struct manager_action * action_find(const char *name)
Definition: manager.c:1704
struct ast_module * module
Definition: manager.h:167
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_module_unref(mod)
Release a reference to the module.
Definition: module.h:469
unsigned int registered
TRUE if the AMI action is registered and the callback can be called.
Definition: manager.h:178
In case you didn&#39;t read that giant block of text above the mansession_session struct, the struct mansession is named this solely to keep the API the same in Asterisk. This structure really represents data that is different from Manager action to Manager action. The mansession_session pointer contained within points to session-specific data.
Definition: manager.c:1625
#define ao2_lock(a)
Definition: astobj2.h:718
#define ast_free(a)
Definition: astmm.h:182
#define ast_module_running_ref(mod)
Hold a reference to the module if it is running.
Definition: module.h:455
const char * headers[AST_MAX_MANHEADERS]
Definition: manager.h:146
struct mansession_session * session
Definition: manager.c:1626
struct manager_custom_hook * hook
Definition: manager.c:1631
unsigned int hdrcount
Definition: manager.h:145

◆ ast_instring()

static int ast_instring ( const char *  bigstr,
const char *  smallstr,
const char  delim 
)
static

Tells you if smallstr exists inside bigstr which is delim by delim and uses no buf or stringsep ast_instring("this|that|more","this",'|') == 1;

feel free to move this to app.c -anthm

Definition at line 2112 of file manager.c.

Referenced by get_perm().

2113 {
2114  const char *val = bigstr, *next;
2115 
2116  do {
2117  if ((next = strchr(val, delim))) {
2118  if (!strncmp(val, smallstr, (next - val))) {
2119  return 1;
2120  } else {
2121  continue;
2122  }
2123  } else {
2124  return !strcmp(smallstr, val);
2125  }
2126  } while (*(val = (next + 1)));
2127 
2128  return 0;
2129 }
Definition: ast_expr2.c:325

◆ ast_manager_check_enabled()

int ast_manager_check_enabled ( void  )

Check if AMI is enabled.

Definition at line 1949 of file manager.c.

References manager_enabled.

Referenced by handle_show_settings().

1950 {
1951  return manager_enabled;
1952 }
static int manager_enabled
Definition: manager.c:1475

◆ ast_manager_get_message_router()

struct stasis_message_router* ast_manager_get_message_router ( void  )

Get the stasis_message_router for AMI.

Since
12
Return values
Thestasis_message_router for AMI
NULLon error

Definition at line 1725 of file manager.c.

References stasis_router.

Referenced by manager_bridging_init(), manager_channels_init(), manager_mwi_init(), and manager_system_init().

1726 {
1727  return stasis_router;
1728 }
static struct stasis_message_router * stasis_router
The stasis_message_router for all Stasis Message Bus API messages.
Definition: manager.c:1493

◆ ast_manager_get_topic()

struct stasis_topic* ast_manager_get_topic ( void  )

Get the Stasis Message Bus API topic for AMI.

Since
12
Return values
TheStasis Message Bus API topic for AMI
NULLon error

Definition at line 1720 of file manager.c.

References manager_topic.

Referenced by aoc_publish_blob(), ast_manager_publish_event(), endpoint_state_cb(), load_module(), manager_bridging_init(), manager_channels_init(), manager_mwi_init(), manager_system_init(), publish_load_message_type(), queue_publish_member_blob(), and stasis_app_user_event().

1721 {
1722  return manager_topic;
1723 }
static struct stasis_topic * manager_topic
A stasis_topic that all topics AMI cares about will be forwarded to.
Definition: manager.c:1490

◆ ast_manager_publish_event()

void ast_manager_publish_event ( const char *  type,
int  class_type,
struct ast_json obj 
)

Publish an event to AMI.

Since
12
Parameters
typeThe type of AMI event to publish
class_typeThe class on which to publish the event
objThe event data to be published.

Publishes a message to the Stasis Message Bus API message bus solely for the consumption of AMI. The message will be of the type provided by ast_manager_get_type, and will be published to the topic provided by ast_manager_get_topic. As such, the JSON must be constructed as defined by the ast_manager_get_type message.

Definition at line 1903 of file manager.c.

References ao2_cleanup, ast_json_pack(), ast_json_payload_create(), ast_json_ref(), ast_json_unref(), ast_manager_get_generic_type(), ast_manager_get_topic(), NULL, RAII_VAR, stasis_message_create(), and stasis_publish().

Referenced by analog_publish_channel_alarm_clear(), analog_publish_dnd_state(), publish_channel_alarm(), publish_channel_alarm_clear(), publish_dnd_state(), publish_fully_booted(), publish_qualify_peer_done(), publish_span_alarm(), publish_span_alarm_clear(), and really_quit().

1904 {
1905  RAII_VAR(struct ast_json *, event_info, NULL, ast_json_unref);
1906  RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
1908 
1909  if (!obj || !ast_manager_get_generic_type()) {
1910  return;
1911  }
1912 
1913  ast_json_ref(obj);
1914  event_info = ast_json_pack("{s: s, s: i, s: o}",
1915  "type", type,
1916  "class_type", class_type,
1917  "event", obj);
1918  if (!event_info) {
1919  return;
1920  }
1921 
1922  payload = ast_json_payload_create(event_info);
1923  if (!payload) {
1924  return;
1925  }
1927  if (!message) {
1928  return;
1929  }
1931 }
static const char type[]
Definition: chan_ooh323.c:109
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
struct ast_json_payload * ast_json_payload_create(struct ast_json *json)
Create an ao2 object to pass json blobs as data payloads for stasis.
Definition: json.c:735
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
#define NULL
Definition: resample.c:96
struct stasis_message_type * ast_manager_get_generic_type(void)
Get the stasis_message_type for generic messages.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic&#39;s subscribers.
Definition: stasis.c:1511
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition: manager.c:1720
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Abstract JSON element (object, array, string, int, ...).

◆ ast_manager_register2()

int ast_manager_register2 ( const char *  action,
int  auth,
int(*)(struct mansession *s, const struct message *m)  func,
struct ast_module module,
const char *  synopsis,
const char *  description 
)

register a new command with manager, including online help. This is the preferred way to register a manager command

Register a manager command with the manager interface.

Definition at line 7386 of file manager.c.

References manager_action::action, action_destroy(), ao2_t_alloc, ao2_t_ref, ast_free, ast_manager_register_struct(), AST_STATIC_DOC, ast_string_field_init, ast_string_field_set, ast_strlen_zero, AST_XML_DOC, ast_xmldoc_build_arguments(), ast_xmldoc_build_description(), ast_xmldoc_build_final_response(), ast_xmldoc_build_list_responses(), ast_xmldoc_build_seealso(), ast_xmldoc_build_synopsis(), ast_xmldoc_build_syntax(), manager_action::authority, manager_action::docsrc, manager_action::final_response, manager_action::func, manager_action::list_responses, manager_action::module, and NULL.

7387 {
7388  struct manager_action *cur;
7389 
7390  cur = ao2_t_alloc(sizeof(*cur), action_destroy, action);
7391  if (!cur) {
7392  return -1;
7393  }
7394  if (ast_string_field_init(cur, 128)) {
7395  ao2_t_ref(cur, -1, "action object creation failed");
7396  return -1;
7397  }
7398 
7399  cur->action = action;
7400  cur->authority = auth;
7401  cur->func = func;
7402  cur->module = module;
7403 #ifdef AST_XML_DOCS
7405  char *tmpxml;
7406 
7407  tmpxml = ast_xmldoc_build_synopsis("manager", action, NULL);
7408  ast_string_field_set(cur, synopsis, tmpxml);
7409  ast_free(tmpxml);
7410 
7411  tmpxml = ast_xmldoc_build_syntax("manager", action, NULL);
7412  ast_string_field_set(cur, syntax, tmpxml);
7413  ast_free(tmpxml);
7414 
7415  tmpxml = ast_xmldoc_build_description("manager", action, NULL);
7416  ast_string_field_set(cur, description, tmpxml);
7417  ast_free(tmpxml);
7418 
7419  tmpxml = ast_xmldoc_build_seealso("manager", action, NULL);
7420  ast_string_field_set(cur, seealso, tmpxml);
7421  ast_free(tmpxml);
7422 
7423  tmpxml = ast_xmldoc_build_arguments("manager", action, NULL);
7424  ast_string_field_set(cur, arguments, tmpxml);
7425  ast_free(tmpxml);
7426 
7429 
7430  cur->docsrc = AST_XML_DOC;
7431  } else
7432 #endif
7433  {
7436 #ifdef AST_XML_DOCS
7437  cur->docsrc = AST_STATIC_DOC;
7438 #endif
7439  }
7440  if (ast_manager_register_struct(cur)) {
7441  ao2_t_ref(cur, -1, "action object registration failed");
7442  return -1;
7443  }
7444 
7445  ao2_t_ref(cur, -1, "action object registration successful");
7446  return 0;
7447 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
static const char synopsis[]
Definition: app_mysql.c:64
#define ao2_t_alloc(data_size, destructor_fn, debug_msg)
Definition: astobj2.h:409
int(* func)(struct mansession *s, const struct message *m)
Definition: manager.h:166
char * ast_xmldoc_build_description(const char *type, const char *name, const char *module)
Generate description documentation from XML.
Definition: xmldoc.c:2250
const char * action
Definition: manager.h:151
static int ast_manager_register_struct(struct manager_action *act)
Definition: manager.c:7329
#define NULL
Definition: resample.c:96
struct ast_xml_doc_item * list_responses
Definition: manager.h:160
char * ast_xmldoc_build_synopsis(const char *type, const char *name, const char *module)
Generate synopsis documentation from XML.
Definition: xmldoc.c:2227
char * ast_xmldoc_build_arguments(const char *type, const char *name, const char *module)
Generate the [arguments] tag based on type of node (&#39;application&#39;, &#39;function&#39; or &#39;agi&#39;) and name...
Definition: xmldoc.c:2075
struct ast_xml_doc_item * ast_xmldoc_build_final_response(const char *type, const char *name, const char *module)
Generate the [final response] tag based on type of node (&#39;application&#39;, &#39;function&#39; or &#39;agi&#39;) and name...
Definition: xmldoc.c:2528
struct ast_xml_doc_item * ast_xmldoc_build_list_responses(const char *type, const char *name, const char *module)
Generate the [list responses] tag based on type of node (&#39;application&#39;, &#39;function&#39; or &#39;agi&#39;) and name...
Definition: xmldoc.c:2463
struct ast_module * module
Definition: manager.h:167
#define ast_strlen_zero(foo)
Definition: strings.h:52
enum ast_doc_src docsrc
Definition: manager.h:169
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
const ast_string_field description
Definition: manager.h:158
const ast_string_field arguments
Definition: manager.h:158
#define ast_free(a)
Definition: astmm.h:182
static void action_destroy(void *obj)
Definition: manager.c:7372
char * ast_xmldoc_build_syntax(const char *type, const char *name, const char *module)
Get the syntax for a specified application or function.
Definition: xmldoc.c:1253
char * ast_xmldoc_build_seealso(const char *type, const char *name, const char *module)
Parse the <see-also> node content.
Definition: xmldoc.c:1698
struct ast_xml_doc_item * final_response
Definition: manager.h:162
const ast_string_field seealso
Definition: manager.h:158
const ast_string_field syntax
Definition: manager.h:158
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ ast_manager_register_hook()

void ast_manager_register_hook ( struct manager_custom_hook hook)

Add a custom hook to be called when an event is fired.

Add a custom hook to be called when an event is fired

Parameters
hookstruct manager_custom_hook object to add

Definition at line 1934 of file manager.c.

References AST_RWLIST_INSERT_TAIL, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

Referenced by create_test_dialplan(), and register_hook().

1935 {
1937  AST_RWLIST_INSERT_TAIL(&manager_hooks, hook, list);
1939 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:740
list of hooks registered
Definition: manager.c:1668

◆ ast_manager_register_struct()

static int ast_manager_register_struct ( struct manager_action act)
static

Definition at line 7329 of file manager.c.

References manager_action::action, ao2_t_ref, ast_log, AST_RWLIST_INSERT_AFTER, AST_RWLIST_INSERT_HEAD, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, LOG_WARNING, NULL, ast_category::prev, and manager_action::registered.

Referenced by ast_manager_register2().

7330 {
7331  struct manager_action *cur, *prev = NULL;
7332 
7334  AST_RWLIST_TRAVERSE(&actions, cur, list) {
7335  int ret;
7336 
7337  ret = strcasecmp(cur->action, act->action);
7338  if (ret == 0) {
7339  ast_log(LOG_WARNING, "Manager: Action '%s' already registered\n", act->action);
7341  return -1;
7342  }
7343  if (ret > 0) { /* Insert these alphabetically */
7344  break;
7345  }
7346  prev = cur;
7347  }
7348 
7349  ao2_t_ref(act, +1, "action object added to list");
7350  act->registered = 1;
7351  if (prev) {
7352  AST_RWLIST_INSERT_AFTER(&actions, prev, act, list);
7353  } else {
7354  AST_RWLIST_INSERT_HEAD(&actions, act, list);
7355  }
7356 
7357  ast_verb(2, "Manager registered action %s\n", act->action);
7358 
7360 
7361  return 0;
7362 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
#define AST_RWLIST_INSERT_AFTER
Definition: linkedlists.h:701
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:274
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
const char * action
Definition: manager.h:151
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:717
#define ast_log
Definition: astobj2.c:42
unsigned int registered
TRUE if the AMI action is registered and the callback can be called.
Definition: manager.h:178
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
list of actions registered
Definition: manager.c:1665

◆ ast_manager_str_from_json_object()

struct ast_str* ast_manager_str_from_json_object ( struct ast_json blob,
key_exclusion_cb  exclusion_cb 
)

Convert a JSON object into an AMI compatible string.

Since
12
Parameters
blobThe JSON blob containing key/value pairs to convert
exclusion_cbA key_exclusion_cb pointer to a function that will exclude keys from the final AMI string
Return values
Amalloc'd ast_str object. Callers of this function should free the returned ast_str object
NULLon error

Definition at line 1821 of file manager.c.

References ast_json_is_null(), ast_str_create, manager_json_to_ast_str(), and NULL.

Referenced by agi_channel_to_ami(), aoc_to_ami(), manager_generic_msg_cb(), multi_user_event_to_ami(), mwi_app_event_cb(), queue_channel_to_ami(), queue_member_to_ami(), and queue_multi_channel_to_ami().

1822 {
1823  struct ast_str *res = ast_str_create(1024);
1824 
1825  if (!ast_json_is_null(blob)) {
1826  manager_json_to_ast_str(blob, NULL, &res, exclusion_cb);
1827  }
1828 
1829  return res;
1830 }
static void manager_json_to_ast_str(struct ast_json *obj, const char *key, struct ast_str **res, key_exclusion_cb exclusion_cb)
Definition: manager.c:1780
#define NULL
Definition: resample.c:96
int ast_json_is_null(const struct ast_json *value)
Check if value is JSON null.
Definition: json.c:263
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ ast_manager_unregister()

int ast_manager_unregister ( const char *  action)

support functions to register/unregister AMI action handlers,

Unregister a registered manager command.

Definition at line 7258 of file manager.c.

References manager_action::action, ao2_lock, ao2_t_ref, ao2_unlock, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, and manager_action::registered.

Referenced by __unload_module(), ast_res_pjsip_cleanup_options_handling(), ast_res_pjsip_destroy_configuration(), ast_sip_destroy_sorcery_auth(), ast_sip_destroy_sorcery_location(), astdb_atexit(), bridge_cleanup(), load_module(), local_shutdown(), manager_bridging_cleanup(), manager_shutdown(), message_shutdown(), unload_module(), unload_parking_manager(), and unload_pbx().

7259 {
7260  struct manager_action *cur;
7261 
7264  if (!strcasecmp(action, cur->action)) {
7266  break;
7267  }
7268  }
7271 
7272  if (cur) {
7273  /*
7274  * We have removed the action object from the container so we
7275  * are no longer in a hurry.
7276  */
7277  ao2_lock(cur);
7278  cur->registered = 0;
7279  ao2_unlock(cur);
7280 
7281  ao2_t_ref(cur, -1, "action object removed from list");
7282  ast_verb(2, "Manager unregistered action %s\n", action);
7283  }
7284 
7285  return 0;
7286 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
const char * action
Definition: manager.h:151
#define ao2_unlock(a)
Definition: astobj2.h:730
#define ast_verb(level,...)
Definition: logger.h:463
unsigned int registered
TRUE if the AMI action is registered and the callback can be called.
Definition: manager.h:178
#define ao2_lock(a)
Definition: astobj2.h:718
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:569
list of actions registered
Definition: manager.c:1665
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616

◆ ast_manager_unregister_hook()

void ast_manager_unregister_hook ( struct manager_custom_hook hook)

Delete a custom hook to be called when an event is fired.

Delete a custom hook to be called when an event is fired

Parameters
hookstruct manager_custom_hook object to delete

Definition at line 1942 of file manager.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

Referenced by register_hook(), unload_module(), and unregister_hook().

1943 {
1945  AST_RWLIST_REMOVE(&manager_hooks, hook, list);
1947 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
list of hooks registered
Definition: manager.c:1668
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:884

◆ ast_webmanager_check_enabled()

int ast_webmanager_check_enabled ( void  )

Check if AMI/HTTP is enabled.

Definition at line 1954 of file manager.c.

References manager_enabled, and webmanager_enabled.

Referenced by action_coresettings(), and handle_show_settings().

1955 {
1956  return (webmanager_enabled && manager_enabled);
1957 }
static int manager_enabled
Definition: manager.c:1475
static int webmanager_enabled
Definition: manager.c:1477

◆ astman_append()

void astman_append ( struct mansession s,
const char *  fmt,
  ... 
)

utility functions for creating AMI replies

Definition at line 3080 of file manager.c.

References AST_DYNSTR_BUILD_FAILED, ast_str_buffer(), ast_str_set_va(), ast_str_thread_get(), ast_verbose(), astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE, buf, mansession::hook, NULL, send_string(), ast_tcptls_session_instance::stream, and mansession::tcptls_session.

Referenced by _iax2_show_peers_one(), _sip_show_peer(), _sip_show_peers_one(), _skinny_show_device(), _skinny_show_devices(), _skinny_show_line(), _skinny_show_lines(), action_agents(), action_challenge(), action_command(), action_confbridgelist_item(), action_confbridgelistrooms(), action_coresettings(), action_coreshowchannels(), action_corestatus(), action_dahdishowchannels(), action_devicestatelist(), action_events(), action_extensionstate(), action_extensionstatelist(), action_getconfig(), action_getconfigjson(), action_getvar(), action_hangup(), action_listcategories(), action_listcommands(), action_login(), action_mailboxcount(), action_mailboxstatus(), action_meetmelist(), action_meetmelistrooms(), action_ping(), action_presencestate(), action_presencestatelist(), action_status(), action_waitevent(), ami_outbound_registration_task(), ami_registrations_aor(), ami_show_outbound_registrations(), ami_subscription_detail(), append_vmu_info_astman(), ast_cli_netstats(), ast_sip_format_contact_ami(), astman_append_json(), astman_send_list_complete_end(), dahdi_cc_callback(), do_print(), format_ami_aor_handler(), format_ami_aorlist_handler(), format_ami_auth_handler(), format_ami_authlist_handler(), format_ami_contactlist_handler(), format_ami_endpoint(), format_ami_endpoint_transport(), format_ami_endpoints(), format_ami_resource_lists(), generate_status(), manager_append_event_parking_lot_data_cb(), manager_bridge_info(), manager_bridge_tech_list(), manager_dbget(), manager_fax_sessions(), manager_fax_sessions_entry(), manager_fax_stats(), manager_iax2_show_netstats(), manager_iax2_show_registry(), manager_jabber_send(), manager_mixmonitor(), manager_modulecheck(), manager_mute_mixmonitor(), manager_mutestream(), manager_parking_status_all_lots(), manager_parking_status_single_lot(), manager_queue_rule_show(), manager_queues_status(), manager_queues_summary(), manager_show_dialplan(), manager_show_dialplan_helper(), manager_show_registry(), manager_sip_show_peer(), manager_skinny_show_device(), manager_skinny_show_line(), manager_stop_mixmonitor(), mwi_mailbox_get(), send_bridge_info_item_cb(), send_bridge_list_item_cb(), send_identify_ami_event(), send_manager_peer_status(), session_do(), and spandsp_manager_fax_session().

3081 {
3082  int res;
3083  va_list ap;
3084  struct ast_str *buf;
3085 
3087  return;
3088  }
3089 
3090  va_start(ap, fmt);
3091  res = ast_str_set_va(&buf, 0, fmt, ap);
3092  va_end(ap);
3093  if (res == AST_DYNSTR_BUILD_FAILED) {
3094  return;
3095  }
3096 
3097  if (s->hook || (s->tcptls_session != NULL && s->tcptls_session->stream != NULL)) {
3098  send_string(s, ast_str_buffer(buf));
3099  } else {
3100  ast_verbose("No connection stream in astman_append, should not happen\n");
3101  }
3102 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
int ast_str_set_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap)
Set a dynamic string from a va_list.
Definition: strings.h:982
void ast_verbose(const char *fmt,...)
Definition: extconf.c:2207
#define NULL
Definition: resample.c:96
#define ASTMAN_APPEND_BUF_INITSIZE
initial allocated size for the astman_append_buf and astman_send_*_va
Definition: manager.c:3066
struct ast_tcptls_session_instance * tcptls_session
Definition: manager.c:1628
static struct ast_threadstorage astman_append_buf
Definition: manager.c:3061
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int send_string(struct mansession *s, char *string)
Definition: manager.c:3025
struct ast_iostream * stream
Definition: tcptls.h:160
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:861
struct manager_custom_hook * hook
Definition: manager.c:1631

◆ astman_append_headers()

static void astman_append_headers ( struct message m,
const struct ast_variable params 
)
static

Append additional headers into the message structure from params.

Note
You likely want to initialize m->hdrcount to 0 before calling this.

Definition at line 2830 of file manager.c.

References ARRAY_LEN, ast_asprintf, message::hdrcount, message::headers, ast_variable::name, ast_variable::next, and ast_variable::value.

Referenced by auth_http_callback(), and generic_http_callback().

2831 {
2832  const struct ast_variable *v;
2833 
2834  for (v = params; v && m->hdrcount < ARRAY_LEN(m->headers); v = v->next) {
2835  if (ast_asprintf((char**)&m->headers[m->hdrcount], "%s: %s", v->name, v->value) > -1) {
2836  ++m->hdrcount;
2837  }
2838  }
2839 }
struct ast_variable * next
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
Structure for variables, used for configurations and for channel variables.
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:269
const char * headers[AST_MAX_MANHEADERS]
Definition: manager.h:146
unsigned int hdrcount
Definition: manager.h:145

◆ astman_append_json()

static void astman_append_json ( struct mansession s,
const char *  str 
)
static

Definition at line 3741 of file manager.c.

References ast_alloca, astman_append(), buf, and json_escape().

Referenced by action_getconfigjson().

3742 {
3743  char *buf;
3744 
3745  buf = ast_alloca(2 * strlen(str) + 1);
3746  json_escape(buf, str);
3747  astman_append(s, "%s", buf);
3748 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
static void json_escape(char *out, const char *in)
Definition: manager.c:3721
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
const char * str
Definition: app_jack.c:147
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290

◆ astman_flush()

static void astman_flush ( struct mansession s,
struct ast_str buf 
)
static

Definition at line 3068 of file manager.c.

References ast_str_buffer(), ast_verbose(), mansession::hook, send_string(), ast_tcptls_session_instance::stream, and mansession::tcptls_session.

Referenced by astman_send_list_complete(), astman_send_list_complete_start(), and astman_send_response_full().

3069 {
3070  if (s->hook || (s->tcptls_session && s->tcptls_session->stream)) {
3071  send_string(s, ast_str_buffer(buf));
3072  } else {
3073  ast_verbose("No connection stream in astman_append, should not happen\n");
3074  }
3075 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void ast_verbose(const char *fmt,...)
Definition: extconf.c:2207
struct ast_tcptls_session_instance * tcptls_session
Definition: manager.c:1628
static int send_string(struct mansession *s, char *string)
Definition: manager.c:3025
struct ast_iostream * stream
Definition: tcptls.h:160
struct manager_custom_hook * hook
Definition: manager.c:1631

◆ astman_free_headers()

static void astman_free_headers ( struct message m)
static

Free headers inside message structure, but not the message structure itself.

Definition at line 2844 of file manager.c.

References ast_free, message::hdrcount, message::headers, and NULL.

Referenced by auth_http_callback(), do_message(), and generic_http_callback().

2845 {
2846  while (m->hdrcount) {
2847  --m->hdrcount;
2848  ast_free((void *) m->headers[m->hdrcount]);
2849  m->headers[m->hdrcount] = NULL;
2850  }
2851 }
#define NULL
Definition: resample.c:96
#define ast_free(a)
Definition: astmm.h:182
const char * headers[AST_MAX_MANHEADERS]
Definition: manager.h:146
unsigned int hdrcount
Definition: manager.h:145

◆ astman_get_header()

const char* astman_get_header ( const struct message m,
char *  var 
)

Return the first matching variable from an array.

Get header from mananger transaction.

Note
This is the legacy function and is implemented in therms of __astman_get_header().
Never returns NULL.

Definition at line 2820 of file manager.c.

References __astman_get_header(), and GET_HEADER_FIRST_MATCH.

Referenced by _sip_qualify_peer(), _sip_show_peer(), _sip_show_peers(), _skinny_show_devices(), _skinny_show_lines(), action_add_agi_cmd(), action_agent_logoff(), action_agents(), action_aocmessage(), action_atxfer(), action_blind_transfer(), action_bridge(), action_cancel_atxfer(), action_challenge(), action_command(), action_confbridgekick(), action_confbridgelist(), action_confbridgelistrooms(), action_confbridgesetsinglevideosrc(), action_confbridgestartrecord(), action_confbridgestoprecord(), action_coresettings(), action_coreshowchannels(), action_corestatus(), action_createconfig(), action_dahdidialoffhook(), action_dahdidndoff(), action_dahdidndon(), action_dahdishowchannels(), action_devicestatelist(), action_events(), action_extensionstate(), action_extensionstatelist(), action_filter(), action_getconfig(), action_getconfigjson(), action_getvar(), action_hangup(), action_listcategories(), action_lock_unlock_helper(), action_mailboxcount(), action_mailboxstatus(), action_meetmelist(), action_meetmelistrooms(), action_messagesend(), action_mute_unmute_helper(), action_originate(), action_ping(), action_presencestate(), action_presencestatelist(), action_redirect(), action_reload(), action_sendtext(), action_setvar(), action_status(), action_timeout(), action_transfer(), action_transferhangup(), action_updateconfig(), action_userevent(), action_waitevent(), ami_register(), ami_show_aors(), ami_show_auths(), ami_show_contacts(), ami_show_endpoint(), ami_show_endpoints(), ami_show_outbound_registrations(), ami_show_registration_contact_statuses(), ami_show_registrations(), ami_show_resource_lists(), ami_show_subscriptions_inbound(), ami_show_subscriptions_outbound(), ami_sip_qualify(), ami_unregister(), aocmessage_get_unit_entry(), ast_hook_send_action(), astman_send_list_complete_start_common(), astman_send_response_full(), authenticate(), change_monitor_action(), controlplayback_manager(), dahdi_cc_callback(), do_pause_or_unpause(), handle_manager_bridge_tech_suspend(), handle_updates(), manager_add_queue_member(), manager_bridge_destroy(), manager_bridge_info(), manager_bridge_kick(), manager_bridge_tech_list(), manager_bridges_list(), manager_change_priority_caller_on_queue(), manager_dbdel(), manager_dbdeltree(), manager_dbget(), manager_dbput(), manager_dialplan_extension_add(), manager_dialplan_extension_remove(), manager_fax_session(), manager_fax_sessions(), manager_fax_stats(), manager_iax2_show_peer_list(), manager_iax2_show_peers(), manager_iax2_show_registry(), manager_jabber_send(), manager_list_voicemail_users(), manager_match_mailbox(), manager_mixmonitor(), manager_modulecheck(), manager_moduleload(), manager_mute_mixmonitor(), manager_mutestream(), manager_notify(), manager_optimize_away(), manager_park(), manager_parking_lot_list(), manager_parking_status(), manager_pause_queue_member(), manager_play_dtmf(), manager_play_mf(), manager_queue_log_custom(), manager_queue_member_penalty(), manager_queue_member_ringinuse(), manager_queue_reload(), manager_queue_reset(), manager_queue_rule_show(), manager_queues_status(), manager_queues_summary(), manager_remove_queue_member(), manager_show_dialplan(), manager_show_registry(), manager_sip_peer_status(), manager_sip_qualify_peer(), manager_sip_show_peer(), manager_sip_show_peers(), manager_sipnotify(), manager_skinny_show_device(), manager_skinny_show_line(), manager_status_voicemail_user(), manager_stop_mixmonitor(), meetmemute(), mwi_mailbox_delete(), mwi_mailbox_get(), mwi_mailbox_update(), process_message(), sorcery_memory_cache_ami_expire(), sorcery_memory_cache_ami_expire_object(), sorcery_memory_cache_ami_populate(), sorcery_memory_cache_ami_stale(), sorcery_memory_cache_ami_stale_object(), start_monitor_action(), and stop_monitor_action().

2821 {
2823 }
static const char * __astman_get_header(const struct message *m, char *var, int mode)
Return a matching header value.
Definition: manager.c:2783
#define var
Definition: ast_expr2f.c:614
#define GET_HEADER_FIRST_MATCH
Definition: manager.c:2766

◆ astman_get_variables()

struct ast_variable* astman_get_variables ( const struct message m)

Get a linked list of the Variable: headers.

Note
Order of variables is reversed from the order they are specified in the manager message

Definition at line 2906 of file manager.c.

References astman_get_variables_order(), and ORDER_REVERSE.

Referenced by action_originate().

2907 {
2909 }
struct ast_variable * astman_get_variables_order(const struct message *m, enum variable_orders order)
Get a linked list of the Variable: headers with order specified.
Definition: manager.c:2911

◆ astman_get_variables_order()

struct ast_variable* astman_get_variables_order ( const struct message m,
enum variable_orders  order 
)

Get a linked list of the Variable: headers with order specified.

Definition at line 2911 of file manager.c.

References ast_variables_reverse(), message::hdrcount, message::headers, man_do_variable_value(), NULL, and ORDER_NATURAL.

Referenced by action_messagesend(), astman_get_variables(), manager_notify_channel(), manager_notify_endpoint(), manager_notify_uri(), and manager_sipnotify().

2913 {
2914  int varlen;
2915  int x;
2916  struct ast_variable *head = NULL;
2917 
2918  static const char var_hdr[] = "Variable:";
2919 
2920  /* Process all "Variable:" headers. */
2921  varlen = strlen(var_hdr);
2922  for (x = 0; x < m->hdrcount; x++) {
2923  if (strncasecmp(var_hdr, m->headers[x], varlen)) {
2924  continue;
2925  }
2926  head = man_do_variable_value(head, m->headers[x] + varlen);
2927  }
2928 
2929  if (order == ORDER_NATURAL) {
2930  head = ast_variables_reverse(head);
2931  }
2932 
2933  return head;
2934 }
struct ast_variable * ast_variables_reverse(struct ast_variable *var)
Reverse a variable list.
Definition: main/config.c:567
static struct ast_variable * man_do_variable_value(struct ast_variable *head, const char *hdr_val)
Definition: manager.c:2862
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
integer order
Definition: analys.c:66
const char * headers[AST_MAX_MANHEADERS]
Definition: manager.h:146
unsigned int hdrcount
Definition: manager.h:145

◆ astman_send_ack()

void astman_send_ack ( struct mansession s,
const struct message m,
char *  msg 
)

Send ack in manager transaction.

Definition at line 3191 of file manager.c.

References astman_send_response_full(), and NULL.

Referenced by _sip_qualify_peer(), action_add_agi_cmd(), action_agent_logoff(), action_aocmessage(), action_atxfer(), action_blind_transfer(), action_bridge(), action_cancel_atxfer(), action_confbridgekick(), action_confbridgesetsinglevideosrc(), action_confbridgestartrecord(), action_confbridgestoprecord(), action_createconfig(), action_dahdidialoffhook(), action_dahdidndoff(), action_dahdidndon(), action_dahdirestart(), action_filter(), action_hangup(), action_lock_unlock_helper(), action_loggerrotate(), action_login(), action_messagesend(), action_mute_unmute_helper(), action_originate(), action_redirect(), action_reload(), action_sendtext(), action_setvar(), action_timeout(), action_transfer(), action_transferhangup(), action_updateconfig(), action_userevent(), ami_register(), ami_sip_qualify(), ami_unregister(), change_monitor_action(), controlplayback_manager(), dahdi_cc_callback(), do_pause_or_unpause(), handle_manager_bridge_tech_suspend(), manager_add_queue_member(), manager_bridge_destroy(), manager_bridge_kick(), manager_change_priority_caller_on_queue(), manager_dbdel(), manager_dbdeltree(), manager_dbput(), manager_dialplan_extension_add(), manager_dialplan_extension_remove(), manager_fax_session(), manager_fax_stats(), manager_jabber_send(), manager_list_voicemail_users(), manager_moduleload(), manager_notify_channel(), manager_notify_endpoint(), manager_notify_uri(), manager_optimize_away(), manager_park_bridged(), manager_park_unbridged(), manager_pause_queue_member(), manager_play_dtmf(), manager_play_mf(), manager_queue_log_custom(), manager_queue_member_penalty(), manager_queue_member_ringinuse(), manager_queue_reload(), manager_queue_reset(), manager_remove_queue_member(), manager_sipnotify(), manager_status_voicemail_user(), manager_voicemail_refresh(), meetmemute(), mwi_mailbox_delete(), mwi_mailbox_update(), sorcery_memory_cache_ami_expire(), sorcery_memory_cache_ami_expire_object(), sorcery_memory_cache_ami_populate(), sorcery_memory_cache_ami_stale(), sorcery_memory_cache_ami_stale_object(), start_monitor_action(), and stop_monitor_action().

3192 {
3193  astman_send_response_full(s, m, "Success", msg, NULL);
3194 }
static void astman_send_response_full(struct mansession *s, const struct message *m, char *resp, char *msg, char *listflag)
send a response with an optional message, and terminate it with an empty line. m is used only to grab...
Definition: manager.c:3123
#define NULL
Definition: resample.c:96

◆ astman_send_error()

void astman_send_error ( struct mansession s,
const struct message m,
char *  error 
)

Send error in manager transaction.

Definition at line 3159 of file manager.c.

References astman_send_response_full(), and NULL.

Referenced by _sip_qualify_peer(), _sip_show_peer(), action_add_agi_cmd(), action_agent_logoff(), action_aocmessage(), action_atxfer(), action_blind_transfer(), action_bridge(), action_cancel_atxfer(), action_challenge(), action_command(), action_confbridgekick(), action_confbridgelist(), action_confbridgelistrooms(), action_confbridgesetsinglevideosrc(), action_confbridgestartrecord(), action_confbridgestoprecord(), action_createconfig(), action_dahdidialoffhook(), action_dahdidndoff(), action_dahdidndon(), action_dahdirestart(), action_devicestatelist(), action_events(), action_extensionstate(), action_extensionstatelist(), action_filter(), action_getconfig(), action_getconfigjson(), action_getvar(), action_hangup(), action_listcategories(), action_lock_unlock_helper(), action_loggerrotate(), action_login(), action_mailboxcount(), action_mailboxstatus(), action_meetmelist(), action_meetmelistrooms(), action_messagesend(), action_mute_unmute_helper(), action_originate(), action_presencestate(), action_presencestatelist(), action_redirect(), action_reload(), action_sendtext(), action_setvar(), action_status(), action_timeout(), action_transfer(), action_transferhangup(), action_updateconfig(), ami_register(), ami_show_aors(), ami_show_auths(), ami_show_contacts(), ami_show_endpoints(), ami_show_outbound_registrations(), ami_show_resource_lists(), ami_sip_qualify(), ami_unregister(), change_monitor_action(), controlplayback_manager(), dahdi_cc_callback(), do_message(), do_pause_or_unpause(), handle_manager_bridge_tech_suspend(), handle_parse_error(), manager_add_queue_member(), manager_bridge_destroy(), manager_bridge_info(), manager_bridge_kick(), manager_bridge_tech_list(), manager_bridges_list(), manager_change_priority_caller_on_queue(), manager_dbdel(), manager_dbdeltree(), manager_dbget(), manager_dbput(), manager_dialplan_extension_add(), manager_dialplan_extension_remove(), manager_fax_session(), manager_jabber_send(), manager_mixmonitor(), manager_modulecheck(), manager_moduleload(), manager_mute_mixmonitor(), manager_mutestream(), manager_notify(), manager_notify_channel(), manager_notify_endpoint(), manager_notify_uri(), manager_optimize_away(), manager_park(), manager_park_bridged(), manager_park_unbridged(), manager_parking_lot_list(), manager_parking_status_all_lots(), manager_parking_status_single_lot(), manager_pause_queue_member(), manager_play_dtmf(), manager_play_mf(), manager_queue_log_custom(), manager_queue_member_penalty(), manager_queue_member_ringinuse(), manager_queue_reload(), manager_queue_reset(), manager_remove_queue_member(), manager_show_dialplan(), manager_show_dialplan_helper(), manager_sip_peer_status(), manager_sip_qualify_peer(), manager_sip_show_peer(), manager_sipnotify(), manager_skinny_show_device(), manager_skinny_show_line(), manager_status_voicemail_user(), manager_stop_mixmonitor(), meetmemute(), mwi_mailbox_delete(), mwi_mailbox_get(), mwi_mailbox_update(), process_message(), sorcery_memory_cache_ami_expire(), sorcery_memory_cache_ami_expire_object(), sorcery_memory_cache_ami_populate(), sorcery_memory_cache_ami_stale(), sorcery_memory_cache_ami_stale_object(), start_monitor_action(), and stop_monitor_action().

3160 {
3161  astman_send_response_full(s, m, "Error", error, NULL);
3162 }
static void astman_send_response_full(struct mansession *s, const struct message *m, char *resp, char *msg, char *listflag)
send a response with an optional message, and terminate it with an empty line. m is used only to grab...
Definition: manager.c:3123
#define NULL
Definition: resample.c:96
int error(const char *format,...)
Definition: utils/frame.c:999

◆ astman_send_error_va()

void astman_send_error_va ( struct mansession s,
const struct message m,
const char *  fmt,
  ... 
)

Send error in manager transaction (with va_args support)

Definition at line 3164 of file manager.c.

References AST_DYNSTR_BUILD_FAILED, ast_str_buffer(), ast_str_set_va(), ast_str_thread_get(), ast_strdupa, astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE, astman_send_response_full(), buf, and NULL.

Referenced by action_command(), action_hangup(), action_originate(), action_presencestate(), ami_show_endpoint(), ast_sip_create_ami_event(), format_ami_endpoint_transport(), manager_notify_endpoint(), mwi_mailbox_delete(), mwi_mailbox_get(), and mwi_mailbox_update().

3165 {
3166  int res;
3167  va_list ap;
3168  struct ast_str *buf;
3169  char *msg;
3170 
3172  return;
3173  }
3174 
3175  va_start(ap, fmt);
3176  res = ast_str_set_va(&buf, 0, fmt, ap);
3177  va_end(ap);
3178  if (res == AST_DYNSTR_BUILD_FAILED) {
3179  return;
3180  }
3181 
3182  /* astman_append will use the same underlying buffer, so copy the message out
3183  * before sending the response */
3184  msg = ast_str_buffer(buf);
3185  if (msg) {
3186  msg = ast_strdupa(msg);
3187  }
3188  astman_send_response_full(s, m, "Error", msg, NULL);
3189 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
int ast_str_set_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap)
Set a dynamic string from a va_list.
Definition: strings.h:982
static void astman_send_response_full(struct mansession *s, const struct message *m, char *resp, char *msg, char *listflag)
send a response with an optional message, and terminate it with an empty line. m is used only to grab...
Definition: manager.c:3123
#define NULL
Definition: resample.c:96
#define ASTMAN_APPEND_BUF_INITSIZE
initial allocated size for the astman_append_buf and astman_send_*_va
Definition: manager.c:3066
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static struct ast_threadstorage astman_append_buf
Definition: manager.c:3061
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:861

◆ astman_send_list_complete()

static void astman_send_list_complete ( struct mansession s,
const struct message m,
const char *  event_name,
int  count 
)
static

Definition at line 3228 of file manager.c.

References ast_str_append(), astman_flush(), astman_send_list_complete_start_common(), and buf.

Referenced by action_coreshowchannels(), and action_hangup().

3229 {
3230  struct ast_str *buf = astman_send_list_complete_start_common(s, m, event_name, count);
3231  if (buf) {
3232  ast_str_append(&buf, 0, "\r\n");
3233  astman_flush(s, buf);
3234  }
3235 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static struct ast_str * astman_send_list_complete_start_common(struct mansession *s, const struct message *m, const char *event_name, int count)
Definition: manager.c:3206
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
static void astman_flush(struct mansession *s, struct ast_str *buf)
Definition: manager.c:3068
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584

◆ astman_send_list_complete_end()

void astman_send_list_complete_end ( struct mansession s)

End the list complete event.

Since
13.2.0
Parameters
s- AMI session control struct.
Note
You need to call astman_send_list_complete_start() to start the AMI list completion event.
Between calling astman_send_list_complete_start() and astman_send_list_complete_end() you can add additonal headers using astman_append().
Returns
Nothing

Definition at line 3245 of file manager.c.

References astman_append().

Referenced by action_agents(), action_confbridgelist(), action_confbridgelistrooms(), action_dahdishowchannels(), action_devicestatelist(), action_extensionstatelist(), action_meetmelist(), action_meetmelistrooms(), action_presencestatelist(), action_status(), ami_show_aors(), ami_show_auths(), ami_show_contacts(), ami_show_endpoint(), ami_show_endpoints(), ami_show_outbound_registrations(), ami_show_registration_contact_statuses(), ami_show_registrations(), ami_show_resource_lists(), ami_show_subscriptions_inbound(), ami_show_subscriptions_outbound(), manager_bridge_info(), manager_bridge_tech_list(), manager_bridges_list(), manager_dbget(), manager_fax_sessions(), manager_iax2_show_peer_list(), manager_iax2_show_peers(), manager_iax2_show_registry(), manager_list_voicemail_users(), manager_parking_lot_list(), manager_parking_status_all_lots(), manager_parking_status_single_lot(), manager_queues_status(), manager_queues_summary(), manager_show_dialplan(), manager_show_registry(), manager_sip_peer_status(), manager_sip_show_peers(), manager_skinny_show_devices(), manager_skinny_show_lines(), manager_status_voicemail_user(), and mwi_mailbox_get().

3246 {
3247  astman_append(s, "\r\n");
3248 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080

◆ astman_send_list_complete_start()

void astman_send_list_complete_start ( struct mansession s,
const struct message m,
const char *  event_name,
int  count 
)

Start the list complete event.

Since
13.2.0
Parameters
s- AMI session control struct.
m- AMI action request that started the list.
event_name- AMI list complete event name.
count- Number of items in the list.
Note
You need to call astman_send_list_complete_end() to end the AMI list completion event.
Between calling astman_send_list_complete_start() and astman_send_list_complete_end() you can add additonal headers using astman_append().
Returns
Nothing

Definition at line 3237 of file manager.c.

References astman_flush(), astman_send_list_complete_start_common(), and buf.

Referenced by action_agents(), action_confbridgelist(), action_confbridgelistrooms(), action_dahdishowchannels(), action_devicestatelist(), action_extensionstatelist(), action_meetmelist(), action_meetmelistrooms(), action_presencestatelist(), action_status(), ami_show_aors(), ami_show_auths(), ami_show_contacts(), ami_show_endpoint(), ami_show_endpoints(), ami_show_outbound_registrations(), ami_show_registration_contact_statuses(), ami_show_registrations(), ami_show_resource_lists(), ami_show_subscriptions_inbound(), ami_show_subscriptions_outbound(), manager_bridge_info(), manager_bridge_tech_list(), manager_bridges_list(), manager_dbget(), manager_fax_sessions(), manager_iax2_show_peer_list(), manager_iax2_show_peers(), manager_iax2_show_registry(), manager_list_voicemail_users(), manager_parking_lot_list(), manager_parking_status_all_lots(), manager_parking_status_single_lot(), manager_queues_status(), manager_queues_summary(), manager_show_dialplan(), manager_show_registry(), manager_sip_peer_status(), manager_sip_show_peers(), manager_skinny_show_devices(), manager_skinny_show_lines(), manager_status_voicemail_user(), and mwi_mailbox_get().

3238 {
3239  struct ast_str *buf = astman_send_list_complete_start_common(s, m, event_name, count);
3240  if (buf) {
3241  astman_flush(s, buf);
3242  }
3243 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static struct ast_str * astman_send_list_complete_start_common(struct mansession *s, const struct message *m, const char *event_name, int count)
Definition: manager.c:3206
static void astman_flush(struct mansession *s, struct ast_str *buf)
Definition: manager.c:3068
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584

◆ astman_send_list_complete_start_common()

static struct ast_str* astman_send_list_complete_start_common ( struct mansession s,
const struct message m,
const char *  event_name,
int  count 
)
static

Definition at line 3206 of file manager.c.

References ast_str_append(), ast_str_set(), ast_str_thread_get(), ast_strlen_zero, astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE, astman_get_header(), buf, and NULL.

Referenced by astman_send_list_complete(), and astman_send_list_complete_start().

3207 {
3208  const char *id = astman_get_header(m, "ActionID");
3209  struct ast_str *buf;
3210 
3212  if (!buf) {
3213  return NULL;
3214  }
3215 
3216  ast_str_set(&buf, 0, "Event: %s\r\n", event_name);
3217  if (!ast_strlen_zero(id)) {
3218  ast_str_append(&buf, 0, "ActionID: %s\r\n", id);
3219  }
3220  ast_str_append(&buf, 0,
3221  "EventList: Complete\r\n"
3222  "ListItems: %d\r\n",
3223  count);
3224 
3225  return buf;
3226 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
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 char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#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
#define ASTMAN_APPEND_BUF_INITSIZE
initial allocated size for the astman_append_buf and astman_send_*_va
Definition: manager.c:3066
static struct ast_threadstorage astman_append_buf
Definition: manager.c:3061
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:861

◆ astman_send_listack()

void astman_send_listack ( struct mansession s,
const struct message m,
char *  msg,
char *  listflag 
)

Send ack in manager transaction to begin a list.

Parameters
s- AMI session control struct.
m- AMI action request that started the list.
msg- Message contents describing the list to follow.
listflag- Should always be set to "start".
Note
You need to call astman_send_list_complete_start() and astman_send_list_complete_end() to send the AMI list completion event.
Returns
Nothing

Definition at line 3201 of file manager.c.

References astman_send_response_full().

Referenced by action_agents(), action_confbridgelist(), action_confbridgelistrooms(), action_coreshowchannels(), action_dahdishowchannels(), action_devicestatelist(), action_extensionstatelist(), action_hangup(), action_meetmelist(), action_meetmelistrooms(), action_presencestatelist(), action_status(), ami_show_aors(), ami_show_auths(), ami_show_contacts(), ami_show_endpoint(), ami_show_endpoints(), ami_show_outbound_registrations(), ami_show_registration_contact_statuses(), ami_show_registrations(), ami_show_resource_lists(), ami_show_subscriptions_inbound(), ami_show_subscriptions_outbound(), manager_bridge_info(), manager_bridge_tech_list(), manager_bridges_list(), manager_dbget(), manager_dpsendack(), manager_fax_sessions(), manager_iax2_show_peer_list(), manager_iax2_show_peers(), manager_iax2_show_registry(), manager_list_voicemail_users(), manager_parking_lot_list(), manager_parking_status_all_lots(), manager_parking_status_single_lot(), manager_queues_status(), manager_queues_summary(), manager_show_registry(), manager_sip_peer_status(), manager_sip_show_peers(), manager_skinny_show_devices(), manager_skinny_show_lines(), manager_status_voicemail_user(), and mwi_mailbox_get().

3202 {
3203  astman_send_response_full(s, m, "Success", msg, listflag);
3204 }
static void astman_send_response_full(struct mansession *s, const struct message *m, char *resp, char *msg, char *listflag)
send a response with an optional message, and terminate it with an empty line. m is used only to grab...
Definition: manager.c:3123

◆ astman_send_response()

void astman_send_response ( struct mansession s,
const struct message m,
char *  resp,
char *  msg 
)

Send response in manager transaction.

Definition at line 3154 of file manager.c.

References astman_send_response_full(), and NULL.

Referenced by action_logoff(), and action_waitevent().

3155 {
3156  astman_send_response_full(s, m, resp, msg, NULL);
3157 }
static void astman_send_response_full(struct mansession *s, const struct message *m, char *resp, char *msg, char *listflag)
send a response with an optional message, and terminate it with an empty line. m is used only to grab...
Definition: manager.c:3123
#define NULL
Definition: resample.c:96

◆ astman_send_response_full()

static void astman_send_response_full ( struct mansession s,
const struct message m,
char *  resp,
char *  msg,
char *  listflag 
)
static

send a response with an optional message, and terminate it with an empty line. m is used only to grab the 'ActionID' field.

Use the explicit constant MSG_MOREDATA to remove the empty line. XXX MSG_MOREDATA should go to a header file.

Definition at line 3123 of file manager.c.

References ast_str_append(), ast_str_set(), ast_str_thread_get(), ast_strlen_zero, astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE, astman_flush(), astman_get_header(), buf, and MSG_MOREDATA.

Referenced by action_command(), astman_send_ack(), astman_send_error(), astman_send_error_va(), astman_send_listack(), astman_send_response(), and astman_start_ack().

3124 {
3125  const char *id = astman_get_header(m, "ActionID");
3126  struct ast_str *buf;
3127 
3129  if (!buf) {
3130  return;
3131  }
3132 
3133  ast_str_set(&buf, 0, "Response: %s\r\n", resp);
3134 
3135  if (!ast_strlen_zero(id)) {
3136  ast_str_append(&buf, 0, "ActionID: %s\r\n", id);
3137  }
3138 
3139  if (listflag) {
3140  /* Start, complete, cancelled */
3141  ast_str_append(&buf, 0, "EventList: %s\r\n", listflag);
3142  }
3143 
3144  if (msg != MSG_MOREDATA) {
3145  if (msg) {
3146  ast_str_append(&buf, 0, "Message: %s\r\n", msg);
3147  }
3148  ast_str_append(&buf, 0, "\r\n");
3149  }
3150 
3151  astman_flush(s, buf);
3152 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
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 * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#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
#define ASTMAN_APPEND_BUF_INITSIZE
initial allocated size for the astman_append_buf and astman_send_*_va
Definition: manager.c:3066
#define MSG_MOREDATA
Definition: manager.c:3114
static struct ast_threadstorage astman_append_buf
Definition: manager.c:3061
static void astman_flush(struct mansession *s, struct ast_str *buf)
Definition: manager.c:3068
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:861

◆ astman_start_ack()

static void astman_start_ack ( struct mansession s,
const struct message m 
)
static

Definition at line 3196 of file manager.c.

References astman_send_response_full(), MSG_MOREDATA, and NULL.

Referenced by action_challenge(), action_extensionstate(), action_getconfig(), action_getconfigjson(), action_getvar(), action_listcategories(), action_listcommands(), action_mailboxcount(), action_mailboxstatus(), and action_presencestate().

3197 {
3198  astman_send_response_full(s, m, "Success", MSG_MOREDATA, NULL);
3199 }
static void astman_send_response_full(struct mansession *s, const struct message *m, char *resp, char *msg, char *listflag)
send a response with an optional message, and terminate it with an empty line. m is used only to grab...
Definition: manager.c:3123
#define NULL
Definition: resample.c:96
#define MSG_MOREDATA
Definition: manager.c:3114

◆ authenticate()

static int authenticate ( struct mansession s,
const struct message m 
)
static

Definition at line 3505 of file manager.c.

References ast_manager_user::acl, mansession_session::addr, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_t_link, ao2_t_ref, ast_apply_acl(), ast_copy_string(), ast_debug, ast_log, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, AST_SENSE_DENY, ast_sockaddr_stringify_addr(), ast_strlen_zero, ast_tvnow(), ast_variables_dup(), astman_get_header(), mansession_session::blackfilters, ast_manager_user::blackfilters, mansession_session::challenge, mansession_session::chanvars, ast_manager_user::chanvars, error(), get_manager_by_name_locked(), len(), LOG_NOTICE, MD5Final(), MD5Init(), MD5Update(), NULL, password, mansession_session::readperm, ast_manager_user::readperm, report_auth_success(), report_failed_acl(), report_failed_challenge_response(), report_inval_password(), report_invalid_user(), S_OR, ast_manager_user::secret, mansession::session, mansession_session::sessionstart, mansession_session::sessionstart_tv, set_eventmask(), mansession_session::username, mansession_session::whitefilters, ast_manager_user::whitefilters, mansession_session::writeperm, ast_manager_user::writeperm, mansession_session::writetimeout, and ast_manager_user::writetimeout.

Referenced by action_login().

3506 {
3507  const char *username = astman_get_header(m, "Username");
3508  const char *password = astman_get_header(m, "Secret");
3509  int error = -1;
3510  struct ast_manager_user *user = NULL;
3511  regex_t *regex_filter;
3512  struct ao2_iterator filter_iter;
3513 
3514  if (ast_strlen_zero(username)) { /* missing username */
3515  return -1;
3516  }
3517 
3518  /* locate user in locked state */
3520 
3521  if (!(user = get_manager_by_name_locked(username))) {
3522  report_invalid_user(s, username);
3523  ast_log(LOG_NOTICE, "%s tried to authenticate with nonexistent user '%s'\n", ast_sockaddr_stringify_addr(&s->session->addr), username);
3524  } else if (user->acl && (ast_apply_acl(user->acl, &s->session->addr, "Manager User ACL: ") == AST_SENSE_DENY)) {
3525  report_failed_acl(s, username);
3526  ast_log(LOG_NOTICE, "%s failed to pass IP ACL as '%s'\n", ast_sockaddr_stringify_addr(&s->session->addr), username);
3527  } else if (!strcasecmp(astman_get_header(m, "AuthType"), "MD5")) {
3528  const char *key = astman_get_header(m, "Key");
3529  if (!ast_strlen_zero(key) && !ast_strlen_zero(s->session->challenge) && user->secret) {
3530  int x;
3531  int len = 0;
3532  char md5key[256] = "";
3533  struct MD5Context md5;
3534  unsigned char digest[16];
3535 
3536  MD5Init(&md5);
3537  MD5Update(&md5, (unsigned char *) s->session->challenge, strlen(s->session->challenge));
3538  MD5Update(&md5, (unsigned char *) user->secret, strlen(user->secret));
3539  MD5Final(digest, &md5);
3540  for (x = 0; x < 16; x++)
3541  len += sprintf(md5key + len, "%02hhx", digest[x]);
3542  if (!strcmp(md5key, key)) {
3543  error = 0;
3544  } else {
3545  report_failed_challenge_response(s, key, md5key);
3546  }
3547  } else {
3548  ast_debug(1, "MD5 authentication is not possible. challenge: '%s'\n",
3549  S_OR(s->session->challenge, ""));
3550  }
3551  } else if (user->secret) {
3552  if (!strcmp(password, user->secret)) {
3553  error = 0;
3554  } else {
3555  report_inval_password(s, username);
3556  }
3557  }
3558 
3559  if (error) {
3560  ast_log(LOG_NOTICE, "%s failed to authenticate as '%s'\n", ast_sockaddr_stringify_addr(&s->session->addr), username);
3562  return -1;
3563  }
3564 
3565  /* auth complete */
3566 
3567  /* All of the user parameters are copied to the session so that in the event
3568  * of a reload and a configuration change, the session parameters are not
3569  * changed. */
3570  ast_copy_string(s->session->username, username, sizeof(s->session->username));
3571  s->session->readperm = user->readperm;
3572  s->session->writeperm = user->writeperm;
3573  s->session->writetimeout = user->writetimeout;
3574  if (user->chanvars) {
3576  }
3577 
3578  filter_iter = ao2_iterator_init(user->whitefilters, 0);
3579  while ((regex_filter = ao2_iterator_next(&filter_iter))) {
3580  ao2_t_link(s->session->whitefilters, regex_filter, "add white user filter to session");
3581  ao2_t_ref(regex_filter, -1, "remove iterator ref");
3582  }
3583  ao2_iterator_destroy(&filter_iter);
3584 
3585  filter_iter = ao2_iterator_init(user->blackfilters, 0);
3586  while ((regex_filter = ao2_iterator_next(&filter_iter))) {
3587  ao2_t_link(s->session->blackfilters, regex_filter, "add black user filter to session");
3588  ao2_t_ref(regex_filter, -1, "remove iterator ref");
3589  }
3590  ao2_iterator_destroy(&filter_iter);
3591 
3592  s->session->sessionstart = time(NULL);
3594  set_eventmask(s, astman_get_header(m, "Events"));
3595 
3597 
3599  return 0;
3600 }
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition: netsock2.h:290
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
struct ao2_container * blackfilters
Definition: manager.c:1654
struct ao2_container * whitefilters
Definition: manager.c:1653
char username[80]
Definition: manager.c:1592
static void report_invalid_user(const struct mansession *s, const char *username)
Definition: manager.c:3285
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
static struct ast_manager_user * get_manager_by_name_locked(const char *name)
Definition: manager.c:2305
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
void MD5Final(unsigned char digest[16], struct MD5Context *context)
Definition: md5.c:120
#define ao2_t_link(container, obj, tag)
Add an object to a container.
Definition: astobj2.h:1547
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
struct ast_sockaddr addr
Definition: manager.c:1583
static void report_failed_challenge_response(const struct mansession *s, const char *response, const char *expected_response)
Definition: manager.c:3443
#define NULL
Definition: resample.c:96
user descriptor, as read from the config file.
Definition: manager.c:1644
struct ao2_container * blackfilters
Definition: manager.c:1600
list of users found in the config file
static struct ast_str * password
Definition: cdr_mysql.c:77
void MD5Init(struct MD5Context *context)
Definition: md5.c:57
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct ast_variable * chanvars
Definition: manager.c:1601
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
struct ao2_container * whitefilters
Definition: manager.c:1599
static void report_inval_password(const struct mansession *s, const char *username)
Definition: manager.c:3335
struct ast_variable * chanvars
Definition: manager.c:1657
struct timeval sessionstart_tv
Definition: manager.c:1590
enum ast_acl_sense ast_apply_acl(struct ast_acl_list *acl_list, const struct ast_sockaddr *addr, const char *purpose)
Apply a set of rules to a given IP address.
Definition: acl.c:800
struct ast_acl_list * acl
Definition: manager.c:1655
void MD5Update(struct MD5Context *context, unsigned char const *buf, unsigned len)
Definition: md5.c:72
static int md5(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_md5.c:52
static int set_eventmask(struct mansession *s, const char *eventmask)
Rather than braindead on,off this now can also accept a specific int mask value or a &#39;...
Definition: manager.c:3266
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void report_failed_acl(const struct mansession *s, const char *username)
Definition: manager.c:3310
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
#define LOG_NOTICE
Definition: logger.h:263
static void report_auth_success(const struct mansession *s)
Definition: manager.c:3360
structure to hold users read from users.conf
Definition: md5.h:26
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
char challenge[10]
Definition: manager.c:1593
struct mansession_session * session
Definition: manager.c:1626
int error(const char *format,...)
Definition: utils/frame.c:999
time_t sessionstart
Definition: manager.c:1589
struct ast_variable * ast_variables_dup(struct ast_variable *var)
Duplicate variable list.
Definition: main/config.c:545
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.

◆ authority_to_str()

static const char* authority_to_str ( int  authority,
struct ast_str **  res 
)
static

Convert authority code to a list of options. Note that the EVENT_FLAG_ALL authority will always be returned.

Definition at line 2084 of file manager.c.

References ARRAY_LEN, ast_str_append(), ast_str_buffer(), ast_str_reset(), ast_str_strlen(), EVENT_FLAG_SHUTDOWN, and perms.

Referenced by __manager_event_sessions_va(), action_listcommands(), action_login(), and handle_showmancmd().

2085 {
2086  int i;
2087  char *sep = "";
2088 
2089  ast_str_reset(*res);
2090  if (authority != EVENT_FLAG_SHUTDOWN) {
2091  for (i = 0; i < ARRAY_LEN(perms) - 1; i++) {
2092  if (authority & perms[i].num) {
2093  ast_str_append(res, 0, "%s%s", sep, perms[i].label);
2094  sep = ",";
2095  }
2096  }
2097  }
2098 
2099  if (ast_str_strlen(*res) == 0) {
2100  /* replace empty string with something sensible */
2101  ast_str_append(res, 0, "<none>");
2102  }
2103 
2104  return ast_str_buffer(*res);
2105 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
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
static const struct permalias perms[]
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
Definition: strings.h:653
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
#define EVENT_FLAG_SHUTDOWN
Fake event class used to end sessions at shutdown.
Definition: manager.c:1511

◆ blackfilter_cmp_fn()

static int blackfilter_cmp_fn ( void *  obj,
void *  arg,
void *  data,
int  flags 
)
static

Definition at line 6092 of file manager.c.

References CMP_MATCH, CMP_STOP, NULL, and result.

Referenced by match_filter().

6093 {
6094  regex_t *regex_filter = obj;
6095  const char *eventdata = arg;
6096  int *result = data;
6097 
6098  if (!regexec(regex_filter, eventdata, 0, NULL, 0)) {
6099  *result = 0;
6100  return (CMP_MATCH | CMP_STOP);
6101  }
6102 
6103  *result = 1;
6104  return 0;
6105 }
#define NULL
Definition: resample.c:96
static PGresult * result
Definition: cel_pgsql.c:88

◆ build_mansession()

static struct mansession_session* build_mansession ( const struct ast_sockaddr addr)
static

Allocate manager session structure and add it to the list of sessions.

Definition at line 2229 of file manager.c.

References mansession_session::addr, ao2_alloc, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_list, ao2_global_obj_ref, ao2_link, ao2_ref, ast_mutex_init, AST_PTHREADT_NULL, ast_sockaddr_copy(), mansession_session::blackfilters, mansession_session::notify_lock, NULL, mansession_session::send_events, session_destructor(), sessions, mansession_session::waiting_thread, mansession_session::whitefilters, and mansession_session::writetimeout.

Referenced by auth_http_callback(), generic_http_callback(), and session_do().

2230 {
2231  struct ao2_container *sessions;
2232  struct mansession_session *newsession;
2233 
2234  newsession = ao2_alloc(sizeof(*newsession), session_destructor);
2235  if (!newsession) {
2236  return NULL;
2237  }
2238 
2241  if (!newsession->whitefilters || !newsession->blackfilters) {
2242  ao2_ref(newsession, -1);
2243  return NULL;
2244  }
2245 
2246  newsession->waiting_thread = AST_PTHREADT_NULL;
2247  newsession->writetimeout = 100;
2248  newsession->send_events = -1;
2249  ast_sockaddr_copy(&newsession->addr, addr);
2250 
2251  ast_mutex_init(&newsession->notify_lock);
2252 
2253  sessions = ao2_global_obj_ref(mgr_sessions);
2254  if (sessions) {
2255  ao2_link(sessions, newsession);
2256  ao2_ref(sessions, -1);
2257  }
2258 
2259  return newsession;
2260 }
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:171
static struct sessions sessions
pthread_t waiting_thread
Definition: manager.c:1587
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Definition: astobj2.h:1335
#define ao2_global_obj_ref(holder)
Definition: astobj2.h:925
struct ast_sockaddr addr
Definition: manager.c:1583
static void session_destructor(void *obj)
Definition: manager.c:2198
#define NULL
Definition: resample.c:96
struct ao2_container * blackfilters
Definition: manager.c:1600
ast_mutex_t notify_lock
Definition: manager.c:1610
struct ao2_container * whitefilters
Definition: manager.c:1599
#define AST_PTHREADT_NULL
Definition: lock.h:66
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
#define ast_mutex_init(pmutex)
Definition: lock.h:184
Generic container type.
#define ao2_link(container, obj)
Definition: astobj2.h:1549

◆ check_blacklist()

static int check_blacklist ( const char *  cmd)
static

Definition at line 5259 of file manager.c.

References ARRAY_LEN, AST_MAX_CMD_LEN, ast_strdupa, ast_strip(), ast_strlen_zero, command_blacklist, match(), MAX_BLACKLIST_CMD_LEN, NULL, strsep(), and words.

Referenced by action_command().

5260 {
5261  char *cmd_copy, *cur_cmd;
5262  char *cmd_words[AST_MAX_CMD_LEN] = { NULL, };
5263  int i;
5264 
5265  cmd_copy = ast_strdupa(cmd);
5266  for (i = 0; i < MAX_BLACKLIST_CMD_LEN && (cur_cmd = strsep(&cmd_copy, " ")); i++) {
5267  cur_cmd = ast_strip(cur_cmd);
5268  if (ast_strlen_zero(cur_cmd)) {
5269  i--;
5270  continue;
5271  }
5272 
5273  cmd_words[i] = cur_cmd;
5274  }
5275 
5276  for (i = 0; i < ARRAY_LEN(command_blacklist); i++) {
5277  int j, match = 1;
5278 
5279  for (j = 0; command_blacklist[i].words[j]; j++) {
5280  if (ast_strlen_zero(cmd_words[j]) || strcasecmp(cmd_words[j], command_blacklist[i].words[j])) {
5281  match = 0;
5282  break;
5283  }
5284  }
5285 
5286  if (match) {
5287  return 1;
5288  }
5289  }
5290 
5291  return 0;
5292 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static const struct @407 command_blacklist[]
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2315
#define MAX_BLACKLIST_CMD_LEN
Descriptor for a manager session, either on the AMI socket or over HTTP.
Definition: manager.c:1523
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:219
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
const char * words[AST_MAX_CMD_LEN]
Definition: manager.c:1525
char * strsep(char **str, const char *delims)
#define AST_MAX_CMD_LEN
Definition: cli.h:48

◆ check_manager_session_inuse()

static int check_manager_session_inuse ( const char *  name)
static

Definition at line 2282 of file manager.c.

References ao2_find, ao2_global_obj_ref, ao2_ref, mansession_session::inuse, session, sessions, and unref_mansession().

Referenced by process_message().

2283 {
2284  struct ao2_container *sessions;
2285  struct mansession_session *session;
2286  int inuse = 0;
2287 
2288  sessions = ao2_global_obj_ref(mgr_sessions);
2289  if (sessions) {
2290  session = ao2_find(sessions, (char *) name, 0);
2291  ao2_ref(sessions, -1);
2292  if (session) {
2293  unref_mansession(session);
2294  inuse = 1;
2295  }
2296  }
2297  return inuse;
2298 }
static struct sessions sessions
#define ao2_global_obj_ref(holder)
Definition: astobj2.h:925
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
static const char name[]
Definition: cdr_mysql.c:74
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
Generic container type.

◆ destroy_fast_originate_helper()

static void destroy_fast_originate_helper ( struct fast_originate_helper doomed)
static

Definition at line 5405 of file manager.c.

References ao2_cleanup, ast_free, ast_string_field_free_memory, ast_variables_destroy(), fast_originate_helper::cap, and fast_originate_helper::vars.

Referenced by action_originate(), and fast_originate().

5406 {
5407  ao2_cleanup(doomed->cap);
5408  ast_variables_destroy(doomed->vars);
5410  ast_free(doomed);
5411 }
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
struct ast_format_cap * cap
Definition: manager.c:5377
struct ast_variable * vars
Definition: manager.c:5395
#define ast_free(a)
Definition: astmm.h:182
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368

◆ do_message()

static int do_message ( struct mansession s)
static

Definition at line 6852 of file manager.c.

References mansession_session::addr, ARRAY_LEN, ast_log, ast_sockaddr_stringify_addr(), ast_strdup, ast_strlen_zero, ast_verb, astman_free_headers(), astman_send_error(), mansession_session::authenticated, mansession_session::authstart, authtimeout, displayconnects, errno, get_input(), handle_parse_error(), message::hdrcount, message::headers, mansession_session::inbuf, LOG_ERROR, mansession_lock(), mansession_unlock(), MESSAGE_LINE_TOO_LONG, MESSAGE_OKAY, mansession::parsing, process_events(), process_message(), and mansession::session.

Referenced by session_do().

6853 {
6854  struct message m = { 0 };
6855  char header_buf[sizeof(s->session->inbuf)] = { '\0' };
6856  int res;
6857  int hdr_loss;
6858  time_t now;
6859 
6860  hdr_loss = 0;
6861  for (;;) {
6862  /* Check if any events are pending and do them if needed */
6863  if (process_events(s)) {
6864  res = -1;
6865  break;
6866  }
6867  res = get_input(s, header_buf);
6868  if (res == 0) {
6869  /* No input line received. */
6870  if (!s->session->authenticated) {
6871  if (time(&now) == -1) {
6872  ast_log(LOG_ERROR, "error executing time(): %s\n", strerror(errno));
6873  res = -1;
6874  break;
6875  }
6876 
6877  if (now - s->session->authstart > authtimeout) {
6878  if (displayconnects) {
6879  ast_verb(2, "Client from %s, failed to authenticate in %d seconds\n", ast_sockaddr_stringify_addr(&s->session->addr), authtimeout);
6880  }
6881  res = -1;
6882  break;
6883  }
6884  }
6885  continue;
6886  } else if (res > 0) {
6887  /* Input line received. */
6888  if (ast_strlen_zero(header_buf)) {
6889  if (hdr_loss) {
6890  mansession_lock(s);
6891  astman_send_error(s, &m, "Too many lines in message or allocation failure");
6892  mansession_unlock(s);
6893  res = 0;
6894  } else {
6895  switch (s->parsing) {
6896  case MESSAGE_OKAY:
6897  res = process_message(s, &m) ? -1 : 0;
6898  break;
6899  case MESSAGE_LINE_TOO_LONG:
6900  handle_parse_error(s, &m, "Failed to parse message: line too long");
6901  res = 0;
6902  break;
6903  }
6904  }
6905  break;
6906  } else if (m.hdrcount < ARRAY_LEN(m.headers)) {
6907  m.headers[m.hdrcount] = ast_strdup(header_buf);
6908  if (!m.headers[m.hdrcount]) {
6909  /* Allocation failure. */
6910  hdr_loss = 1;
6911  } else {
6912  ++m.hdrcount;
6913  }
6914  } else {
6915  /* Too many lines in message. */
6916  hdr_loss = 1;
6917  }
6918  } else {
6919  /* Input error. */
6920  break;
6921  }
6922  }
6923 
6924  astman_free_headers(&m);
6925 
6926  return res;
6927 }
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition: netsock2.h:290
static int get_input(struct mansession *s, char *output)
Definition: manager.c:6735
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static void mansession_unlock(struct mansession *s)
Unlock the &#39;mansession&#39; structure.
Definition: manager.c:3257
static int displayconnects
Definition: manager.c:1470
static int authtimeout
Definition: manager.c:1479
static int process_events(struct mansession *s)
Definition: manager.c:6227
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
struct ast_sockaddr addr
Definition: manager.c:1583
#define ast_verb(level,...)
Definition: logger.h:463
static int process_message(struct mansession *s, const struct message *m)
Process an AMI message, performing desired action. Return 0 on success, -1 on error that require the ...
Definition: manager.c:6607
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
enum mansession_message_parsing parsing
Definition: manager.c:1629
#define LOG_ERROR
Definition: logger.h:285
int errno
static void astman_free_headers(struct message *m)
Free headers inside message structure, but not the message structure itself.
Definition: manager.c:2844
char inbuf[1025]
Definition: manager.c:1597
static void mansession_lock(struct mansession *s)
Lock the &#39;mansession&#39; structure.
Definition: manager.c:3251
const char * headers[AST_MAX_MANHEADERS]
Definition: manager.h:146
struct mansession_session * session
Definition: manager.c:1626
static void handle_parse_error(struct mansession *s, struct message *m, char *error)
Definition: manager.c:6835
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
unsigned int hdrcount
Definition: manager.h:145

◆ event_filter_destructor()

static void event_filter_destructor ( void *  obj)
static

Definition at line 2192 of file manager.c.

Referenced by manager_add_filter().

2193 {
2194  regex_t *regex_filter = obj;
2195  regfree(regex_filter);
2196 }

◆ fast_originate()

static void* fast_originate ( void *  data)
static

Definition at line 5413 of file manager.c.

References fast_originate_helper::account, fast_originate_helper::app, fast_originate_helper::appdata, AST_CHANNEL_NAME, ast_channel_name(), ast_channel_uniqueid(), ast_channel_unlock, ast_channel_unref, ast_manager_event_multichan, AST_OUTGOING_WAIT, ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_strlen_zero, fast_originate_helper::cap, fast_originate_helper::channelid, fast_originate_helper::cid_name, fast_originate_helper::cid_num, fast_originate_helper::context, fast_originate_helper::data, destroy_fast_originate_helper(), fast_originate_helper::early_media, EVENT_FLAG_CALL, fast_originate_helper::exten, fast_originate_helper::idtext, in, NULL, fast_originate_helper::otherchannelid, fast_originate_helper::priority, S_OR, fast_originate_helper::tech, fast_originate_helper::timeout, ast_assigned_ids::uniqueid, and fast_originate_helper::vars.

Referenced by action_originate().

5414 {
5415  struct fast_originate_helper *in = data;
5416  int res;
5417  int reason = 0;
5418  struct ast_channel *chan = NULL, *chans[1];
5419  char requested_channel[AST_CHANNEL_NAME];
5420  struct ast_assigned_ids assignedids = {
5421  .uniqueid = in->channelid,
5422  .uniqueid2 = in->otherchannelid
5423  };
5424 
5425  if (!ast_strlen_zero(in->app)) {
5426  res = ast_pbx_outgoing_app(in->tech, in->cap, in->data,
5427  in->timeout, in->app, in->appdata, &reason,
5429  S_OR(in->cid_num, NULL),
5430  S_OR(in->cid_name, NULL),
5431  in->vars, in->account, &chan, &assignedids);
5432  } else {
5433  res = ast_pbx_outgoing_exten(in->tech, in->cap, in->data,
5434  in->timeout, in->context, in->exten, in->priority, &reason,
5436  S_OR(in->cid_num, NULL),
5437  S_OR(in->cid_name, NULL),
5438  in->vars, in->account, &chan, in->early_media, &assignedids);
5439  }
5440 
5441  if (!chan) {
5442  snprintf(requested_channel, AST_CHANNEL_NAME, "%s/%s", in->tech, in->data);
5443  }
5444  /* Tell the manager what happened with the channel */
5445  chans[0] = chan;
5446  if (!ast_strlen_zero(in->app)) {
5447  ast_manager_event_multichan(EVENT_FLAG_CALL, "OriginateResponse", chan ? 1 : 0, chans,
5448  "%s"
5449  "Response: %s\r\n"
5450  "Channel: %s\r\n"
5451  "Application: %s\r\n"
5452  "Data: %s\r\n"
5453  "Reason: %d\r\n"
5454  "Uniqueid: %s\r\n"
5455  "CallerIDNum: %s\r\n"
5456  "CallerIDName: %s\r\n",
5457  in->idtext, res ? "Failure" : "Success",
5458  chan ? ast_channel_name(chan) : requested_channel,
5459  in->app, in->appdata, reason,
5460  chan ? ast_channel_uniqueid(chan) : S_OR(in->channelid, "<unknown>"),
5461  S_OR(in->cid_num, "<unknown>"),
5462  S_OR(in->cid_name, "<unknown>")
5463  );
5464  } else {
5465  ast_manager_event_multichan(EVENT_FLAG_CALL, "OriginateResponse", chan ? 1 : 0, chans,
5466  "%s"
5467  "Response: %s\r\n"
5468  "Channel: %s\r\n"
5469  "Context: %s\r\n"
5470  "Exten: %s\r\n"
5471  "Reason: %d\r\n"
5472  "Uniqueid: %s\r\n"
5473  "CallerIDNum: %s\r\n"
5474  "CallerIDName: %s\r\n",
5475  in->idtext, res ? "Failure" : "Success",
5476  chan ? ast_channel_name(chan) : requested_channel,
5477  in->context, in->exten, reason,
5478  chan ? ast_channel_uniqueid(chan) : S_OR(in->channelid, "<unknown>"),
5479  S_OR(in->cid_num, "<unknown>"),
5480  S_OR(in->cid_name, "<unknown>")
5481  );
5482  }
5483 
5484  /* Locked and ref'd by ast_pbx_outgoing_exten or ast_pbx_outgoing_app */
5485  if (chan) {
5486  ast_channel_unlock(chan);
5487  ast_channel_unref(chan);
5488  }
5490  return NULL;
5491 }
helper function for originate
Definition: manager.c:5375
Main Channel structure associated with a channel.
const ast_string_field otherchannelid
Definition: manager.c:5393
const ast_string_field tech
Definition: manager.c:5393
const ast_string_field account
Definition: manager.c:5393
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
#define EVENT_FLAG_CALL
Definition: manager.h:72
Structure to pass both assignedid values to channel drivers.
Definition: channel.h:605
const char * uniqueid
Definition: channel.h:606
#define NULL
Definition: resample.c:96
struct ast_format_cap * cap
Definition: manager.c:5377
int ast_pbx_outgoing_exten(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *context, const char *exten, int priority, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel, int early_media, const struct ast_assigned_ids *assignedids)
Synchronously or asynchronously make an outbound call and send it to a particular extension...
Definition: pbx.c:7951
#define ast_strlen_zero(foo)
Definition: strings.h:52
static void destroy_fast_originate_helper(struct fast_originate_helper *doomed)
Definition: manager.c:5405
FILE * in
Definition: utils/frame.c:33
const ast_string_field cid_num
Definition: manager.c:5393
const ast_string_field exten
Definition: manager.c:5393
struct ast_variable * vars
Definition: manager.c:5395
const char * ast_channel_uniqueid(const struct ast_channel *chan)
const ast_string_field appdata
Definition: manager.c:5393
int ast_pbx_outgoing_app(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *app, const char *appdata, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel, const struct ast_assigned_ids *assignedids)
Synchronously or asynchronously make an outbound call and execute an application on the channel...
Definition: pbx.c:8015
#define ast_channel_unlock(chan)
Definition: channel.h:2946
#define AST_CHANNEL_NAME
Definition: channel.h:172
const ast_string_field cid_name
Definition: manager.c:5393
const ast_string_field data
Definition: manager.c:5393
const ast_string_field context
Definition: manager.c:5393
Definition: astman.c:88
#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
const char * ast_channel_name(const struct ast_channel *chan)
const ast_string_field app
Definition: manager.c:5393
#define ast_manager_event_multichan(category, event, nchans, chans, contents,...)
Definition: manager.h:255
const ast_string_field channelid
Definition: manager.c:5393
const ast_string_field idtext
Definition: manager.c:5393

◆ function_capable_string_allowed_with_auths()

static int function_capable_string_allowed_with_auths ( const char *  evaluating,
int  writepermlist 
)
static

Checks to see if a string which can be used to evaluate functions should be rejected.

Definition at line 2046 of file manager.c.

References EVENT_FLAG_SYSTEM.

Referenced by action_getvar(), and action_status().

2047 {
2048  if (!(writepermlist & EVENT_FLAG_SYSTEM)
2049  && (
2050  strstr(evaluating, "SHELL") || /* NoOp(${SHELL(rm -rf /)}) */
2051  strstr(evaluating, "EVAL") /* NoOp(${EVAL(${some_var_containing_SHELL})}) */
2052  )) {
2053  return 0;
2054  }
2055  return 1;
2056 }
#define EVENT_FLAG_SYSTEM
Definition: manager.h:71

◆ generate_status()

static void generate_status ( struct mansession s,
struct ast_channel chan,
char **  vars,
int  varc,
int  all_variables,
char *  id_text,
int *  count 
)
static

Definition at line 4662 of file manager.c.

References ao2_cleanup, ast_channel_appl(), ast_channel_callgroup(), ast_channel_connected_effective_id(), ast_channel_creationtime(), ast_channel_data(), ast_channel_dialed(), ast_channel_get_bridge(), ast_channel_nativeformats(), ast_channel_pickupgroup(), ast_channel_readformat(), ast_channel_readtrans(), ast_channel_snapshot_get_latest(), ast_channel_tech(), ast_channel_uniqueid(), ast_channel_varshead(), ast_channel_whentohangup(), ast_channel_writeformat(), ast_channel_writetrans(), ast_format_cap_get_names(), AST_FORMAT_CAP_NAMES_LEN, ast_format_get_name(), ast_free, ast_func_read(), AST_LIST_TRAVERSE, ast_manager_build_channel_state_string(), ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_str_create, ast_translate_path_to_str(), ast_tvdiff_sec(), ast_tvnow(), ast_var_name(), ast_var_value(), astman_append(), ast_party_id::name, NULL, ast_party_id::number, pbx_retrieve_variable(), RAII_VAR, S_COR, S_OR, ast_party_name::str, ast_party_number::str, type, ast_bridge::uniqueid, ast_party_name::valid, and ast_party_number::valid.

Referenced by action_status().

4663 {
4664  struct timeval now;
4665  long elapsed_seconds;
4666  struct ast_bridge *bridge;
4667  RAII_VAR(struct ast_str *, variable_str, NULL, ast_free);
4668  struct ast_str *write_transpath = ast_str_alloca(256);
4669  struct ast_str *read_transpath = ast_str_alloca(256);
4670  struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
4671  struct ast_party_id effective_id;
4672  int i;
4673  RAII_VAR(struct ast_channel_snapshot *, snapshot,
4675  ao2_cleanup);
4676  RAII_VAR(struct ast_str *, snapshot_str, NULL, ast_free);
4677 
4678  if (!snapshot) {
4679  return;
4680  }
4681 
4682  snapshot_str = ast_manager_build_channel_state_string(snapshot);
4683  if (!snapshot_str) {
4684  return;
4685  }
4686 
4687  if (all_variables) {
4688  variable_str = ast_str_create(2048);
4689  } else {
4690  variable_str = ast_str_create(1024);
4691  }
4692  if (!variable_str) {
4693  return;
4694  }
4695 
4696  now = ast_tvnow();
4697  elapsed_seconds = ast_tvdiff_sec(now, ast_channel_creationtime(chan));
4698 
4699  /* Even if all_variables has been specified, explicitly requested variables
4700  * may be global variables or dialplan functions */
4701  for (i = 0; i < varc; i++) {
4702  char valbuf[512], *ret = NULL;
4703 
4704  if (vars[i][strlen(vars[i]) - 1] == ')') {
4705  if (ast_func_read(chan, vars[i], valbuf, sizeof(valbuf)) < 0) {
4706  valbuf[0] = '\0';
4707  }
4708  ret = valbuf;
4709  } else {
4710  pbx_retrieve_variable(chan, vars[i], &ret, valbuf, sizeof(valbuf), NULL);
4711  }
4712 
4713  ast_str_append(&variable_str, 0, "Variable: %s=%s\r\n", vars[i], ret);
4714  }
4715 
4716  /* Walk all channel variables and add them */
4717  if (all_variables) {
4718  struct ast_var_t *variables;
4719 
4720  AST_LIST_TRAVERSE(ast_channel_varshead(chan), variables, entries) {
4721  ast_str_append(&variable_str, 0, "Variable: %s=%s\r\n",
4722  ast_var_name(variables), ast_var_value(variables));
4723  }
4724  }
4725 
4726  bridge = ast_channel_get_bridge(chan);
4727  effective_id = ast_channel_connected_effective_id(chan);
4728 
4729  astman_append(s,
4730  "Event: Status\r\n"
4731  "Privilege: Call\r\n"
4732  "%s"
4733  "Type: %s\r\n"
4734  "DNID: %s\r\n"
4735  "EffectiveConnectedLineNum: %s\r\n"
4736  "EffectiveConnectedLineName: %s\r\n"
4737  "TimeToHangup: %ld\r\n"
4738  "BridgeID: %s\r\n"
4739  "Application: %s\r\n"
4740  "Data: %s\r\n"
4741  "Nativeformats: %s\r\n"
4742  "Readformat: %s\r\n"
4743  "Readtrans: %s\r\n"
4744  "Writeformat: %s\r\n"
4745  "Writetrans: %s\r\n"
4746  "Callgroup: %llu\r\n"
4747  "Pickupgroup: %llu\r\n"
4748  "Seconds: %ld\r\n"
4749  "%s"
4750  "%s"
4751  "\r\n",
4752  ast_str_buffer(snapshot_str),
4753  ast_channel_tech(chan)->type,
4754  S_OR(ast_channel_dialed(chan)->number.str, ""),
4755  S_COR(effective_id.number.valid, effective_id.number.str, "<unknown>"),
4756  S_COR(effective_id.name.valid, effective_id.name.str, "<unknown>"),
4757  (long)ast_channel_whentohangup(chan)->tv_sec,
4758  bridge ? bridge->uniqueid : "",
4759  ast_channel_appl(chan),
4760  ast_channel_data(chan),
4763  ast_translate_path_to_str(ast_channel_readtrans(chan), &read_transpath),
4765  ast_translate_path_to_str(ast_channel_writetrans(chan), &write_transpath),
4766  ast_channel_callgroup(chan),
4768  (long)elapsed_seconds,
4769  ast_str_buffer(variable_str),
4770  id_text);
4771  ++*count;
4772 
4773  ao2_cleanup(bridge);
4774 }
static const char type[]
Definition: chan_ooh323.c:109
Information needed to identify an endpoint in a call.
Definition: channel.h:339
int ast_func_read(struct ast_channel *chan, const char *function, char *workspace, size_t len)
executes a read operation on a function
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
const ast_string_field uniqueid
Definition: bridge.h:409
const char * ast_var_value(const struct ast_var_t *var)
Definition: chanvars.c:80
const char * ast_var_name(const struct ast_var_t *var)
Definition: chanvars.c:60
int64_t ast_tvdiff_sec(struct timeval end, struct timeval start)
Computes the difference (in seconds) between two struct timeval instances.
Definition: time.h:64
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define AST_FORMAT_CAP_NAMES_LEN
Definition: format_cap.h:326
Structure representing a snapshot of channel state.
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
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define ast_str_alloca(init_len)
Definition: strings.h:800
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
struct varshead * ast_channel_varshead(struct ast_channel *chan)
#define NULL
Definition: resample.c:96
struct ast_trans_pvt * ast_channel_readtrans(const struct ast_channel *chan)
struct timeval * ast_channel_whentohangup(struct ast_channel *chan)
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
Number structure.
Definition: app_followme.c:154
struct ast_bridge * ast_channel_get_bridge(const struct ast_channel *chan)
Get the bridge associated with a channel.
Definition: channel.c:10735
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
struct ast_trans_pvt * ast_channel_writetrans(const struct ast_channel *chan)
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:85
struct ast_str * ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
Generate the AMI message body from a channel snapshot.
const char * ast_channel_uniqueid(const struct ast_channel *chan)
Structure that contains information about a bridge.
Definition: bridge.h:357
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
struct ast_party_id ast_channel_connected_effective_id(struct ast_channel *chan)
void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp)
Retrieve the value of a builtin variable or variable from the channel variable stack.
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
struct timeval ast_channel_creationtime(struct ast_channel *chan)
const char * ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf)
Get the names of codecs of a set of formats.
Definition: format_cap.c:736
const char * ast_channel_appl(const struct ast_channel *chan)
#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
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
const char * ast_channel_data(const struct ast_channel *chan)
const char * ast_translate_path_to_str(struct ast_trans_pvt *t, struct ast_str **str)
Puts a string representation of the translation path into outbuf.
Definition: translate.c:928
struct ast_channel_snapshot * ast_channel_snapshot_get_latest(const char *uniqueid)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object...
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#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
ast_group_t ast_channel_pickupgroup(const struct ast_channel *chan)
ast_group_t ast_channel_callgroup(const struct ast_channel *chan)
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ get_input()

static int get_input ( struct mansession s,
char *  output 
)
static

Read one full line (including crlf) from the manager socket.

Note
* \r\n is the only valid terminator for the line.
* (Note that, later, '\0' will be considered as the end-of-line marker,
* so everything between the '\0' and the '\r\n' will not be used).
* Also note that we assume output to have at least "maxlen" space.
* 

Definition at line 6735 of file manager.c.

References mansession_session::addr, ao2_lock, ao2_unlock, ast_iostream_get_fd(), ast_iostream_read(), ast_log, ast_mutex_lock, ast_mutex_unlock, AST_PTHREADT_NULL, ast_sockaddr_stringify_addr(), ast_wait_for_input(), mansession_session::authenticated, mansession_session::authstart, authtimeout, errno, mansession_session::inbuf, mansession_session::inlen, LOG_ERROR, LOG_WARNING, MESSAGE_LINE_TOO_LONG, mansession_session::notify_lock, mansession::parsing, mansession_session::pending_event, mansession::session, mansession_session::stream, and mansession_session::waiting_thread.

Referenced by do_message().

6736 {
6737  int res, x;
6738  int maxlen = sizeof(s->session->inbuf) - 1;
6739  char *src = s->session->inbuf;
6740  int timeout = -1;
6741  time_t now;
6742 
6743  /*
6744  * Look for \r\n within the buffer. If found, copy to the output
6745  * buffer and return, trimming the \r\n (not used afterwards).
6746  */
6747  for (x = 0; x < s->session->inlen; x++) {
6748  int cr; /* set if we have \r */
6749  if (src[x] == '\r' && x+1 < s->session->inlen && src[x + 1] == '\n') {
6750  cr = 2; /* Found. Update length to include \r\n */
6751  } else if (src[x] == '\n') {
6752  cr = 1; /* also accept \n only */
6753  } else {
6754  continue;
6755  }
6756  memmove(output, src, x); /*... but trim \r\n */
6757  output[x] = '\0'; /* terminate the string */
6758  x += cr; /* number of bytes used */
6759  s->session->inlen -= x; /* remaining size */
6760  memmove(src, src + x, s->session->inlen); /* remove used bytes */
6761  return 1;
6762  }
6763  if (s->session->inlen >= maxlen) {
6764  /* no crlf found, and buffer full - sorry, too long for us
6765  * keep the last character in case we are in the middle of a CRLF. */
6766  ast_log(LOG_WARNING, "Discarding message from %s. Line too long: %.25s...\n", ast_sockaddr_stringify_addr(&s->session->addr), src);
6767  src[0] = src[s->session->inlen - 1];
6768  s->session->inlen = 1;
6770  }
6771  res = 0;
6772  while (res == 0) {
6773  /* calculate a timeout if we are not authenticated */
6774  if (!s->session->authenticated) {
6775  if(time(&now) == -1) {
6776  ast_log(LOG_ERROR, "error executing time(): %s\n", strerror(errno));
6777  return -1;
6778  }
6779 
6780  timeout = (authtimeout - (now - s->session->authstart)) * 1000;
6781  if (timeout < 0) {
6782  /* we have timed out */
6783  return 0;
6784  }
6785  }
6786 
6788  if (s->session->pending_event) {
6789  s->session->pending_event = 0;
6791  return 0;
6792  }
6793  s->session->waiting_thread = pthread_self();
6795 
6797 
6801  }
6802  if (res < 0) {
6803  /* If we get a signal from some other thread (typically because
6804  * there are new events queued), return 0 to notify the caller.
6805  */
6806  if (errno == EINTR || errno == EAGAIN) {
6807  return 0;
6808  }
6809  ast_log(LOG_WARNING, "poll() returned error: %s\n", strerror(errno));
6810  return -1;
6811  }
6812 
6813  ao2_lock(s->session);
6814  res = ast_iostream_read(s->session->stream, src + s->session->inlen, maxlen - s->session->inlen);
6815  if (res < 1) {
6816  res = -1; /* error return */
6817  } else {
6818  s->session->inlen += res;
6819  src[s->session->inlen] = '\0';
6820  res = 0;
6821  }
6822  ao2_unlock(s->session);
6823  return res;
6824 }
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition: netsock2.h:290
pthread_t waiting_thread
Definition: manager.c:1587
#define LOG_WARNING
Definition: logger.h:274
static int timeout
Definition: cdr_mysql.c:86
static int authtimeout
Definition: manager.c:1479
int ast_iostream_get_fd(struct ast_iostream *stream)
Get an iostream&#39;s file descriptor.
Definition: iostream.c:84
#define ast_mutex_lock(a)
Definition: lock.h:187
#define ao2_unlock(a)
Definition: astobj2.h:730
struct ast_sockaddr addr
Definition: manager.c:1583
ssize_t ast_iostream_read(struct ast_iostream *stream, void *buffer, size_t count)
Read data from an iostream.
Definition: iostream.c:273
ast_mutex_t notify_lock
Definition: manager.c:1610
#define ast_log
Definition: astobj2.c:42
#define AST_PTHREADT_NULL
Definition: lock.h:66
#define ao2_lock(a)
Definition: astobj2.h:718
enum mansession_message_parsing parsing
Definition: manager.c:1629
#define LOG_ERROR
Definition: logger.h:285
int errno
struct ast_iostream * stream
Definition: manager.c:1584
char inbuf[1025]
Definition: manager.c:1597
struct mansession_session * session
Definition: manager.c:1626
int ast_wait_for_input(int fd, int ms)
Definition: main/utils.c:1519
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ get_manager_by_name_locked()

static struct ast_manager_user* get_manager_by_name_locked ( const char *  name)
static

lookup an entry in the list of registered users. must be called with the list lock held.

Definition at line 2305 of file manager.c.

References AST_RWLIST_TRAVERSE, NULL, user, and ast_manager_user::username.

Referenced by __init_manager(), auth_http_callback(), authenticate(), function_amiclient(), handle_showmanager(), manager_displayconnects(), and process_message().

2306 {
2307  struct ast_manager_user *user = NULL;
2308 
2309  AST_RWLIST_TRAVERSE(&users, user, list) {
2310  if (!strcasecmp(user->username, name)) {
2311  break;
2312  }
2313  }
2314 
2315  return user;
2316 }
static char user[512]
char username[80]
Definition: manager.c:1645
#define NULL
Definition: resample.c:96
user descriptor, as read from the config file.
Definition: manager.c:1644
list of users found in the config file
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
static const char name[]
Definition: cdr_mysql.c:74
structure to hold users read from users.conf

◆ get_perm()

static int get_perm ( const char *  instr)
static

Definition at line 2131 of file manager.c.

References ARRAY_LEN, ast_instring(), permalias::num, and perms.

Referenced by __init_manager(), and strings_to_mask().

2132 {
2133  int x = 0, ret = 0;
2134 
2135  if (!instr) {
2136  return 0;
2137  }
2138 
2139  for (x = 0; x < ARRAY_LEN(perms); x++) {
2140  if (ast_instring(instr, perms[x].label, ',')) {
2141  ret |= perms[x].num;
2142  }
2143  }
2144 
2145  return ret;
2146 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int num
Definition: manager.c:2016
static const struct permalias perms[]
static int ast_instring(const char *bigstr, const char *smallstr, const char delim)
Definition: manager.c:2112

◆ grab_last()

static struct eventqent* grab_last ( void  )
static

Grab a reference to the last event, update usecount as needed. Can handle a NULL pointer.

Definition at line 1963 of file manager.c.

References ast_atomic_fetchadd_int(), AST_RWLIST_LAST, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and eventqent::usecount.

Referenced by auth_http_callback(), generic_http_callback(), and session_do().

1964 {
1965  struct eventqent *ret;
1966 
1968  ret = AST_RWLIST_LAST(&all_events);
1969  /* the list is never empty now, but may become so when
1970  * we optimize it in the future, so be prepared.
1971  */
1972  if (ret) {
1974  }
1976  return ret;
1977 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
int usecount
Definition: manager.c:1460
#define AST_RWLIST_LAST
Definition: linkedlists.h:430

◆ handle_manager_reload()

static char* handle_manager_reload ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

CLI command manager reload.

Definition at line 2734 of file manager.c.

References ast_cli_args::argc, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, reload_module(), and ast_cli_entry::usage.

2735 {
2736  switch (cmd) {
2737  case CLI_INIT:
2738  e->command = "manager reload";
2739  e->usage =
2740  "Usage: manager reload\n"
2741  " Reloads the manager configuration.\n";
2742  return NULL;
2743  case CLI_GENERATE:
2744  return NULL;
2745  }
2746  if (a->argc > 2) {
2747  return CLI_SHOWUSAGE;
2748  }
2749  reload_module();
2750  return CLI_SUCCESS;
2751 }
const int argc
Definition: cli.h:160
Definition: cli.h:152
#define NULL
Definition: resample.c:96
#define CLI_SHOWUSAGE
Definition: cli.h:45
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
static int reload_module(void)
Definition: manager.c:9661

◆ handle_mandebug()

static char* handle_mandebug ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 2472 of file manager.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, manager_debug, NULL, and ast_cli_entry::usage.

2473 {
2474  switch (cmd) {
2475  case CLI_INIT:
2476  e->command = "manager set debug [on|off]";
2477  e->usage = "Usage: manager set debug [on|off]\n Show, enable, disable debugging of the manager code.\n";
2478  return NULL;
2479  case CLI_GENERATE:
2480  return NULL;
2481  }
2482 
2483  if (a->argc == 3) {
2484  ast_cli(a->fd, "manager debug is %s\n", manager_debug? "on" : "off");
2485  } else if (a->argc == 4) {
2486  if (!strcasecmp(a->argv[3], "on")) {
2487  manager_debug = 1;
2488  } else if (!strcasecmp(a->argv[3], "off")) {
2489  manager_debug = 0;
2490  } else {
2491  return CLI_SHOWUSAGE;
2492  }
2493  }
2494  return CLI_SUCCESS;
2495 }
const int argc
Definition: cli.h:160
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
const int fd
Definition: cli.h:159
const char *const * argv
Definition: cli.h:161
static int manager_debug
Definition: manager.c:1478
#define CLI_SHOWUSAGE
Definition: cli.h:45
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44

◆ handle_parse_error()

static void handle_parse_error ( struct mansession s,
struct message m,
char *  error 
)
static

Definition at line 6835 of file manager.c.

References astman_send_error(), mansession_lock(), mansession_unlock(), MESSAGE_OKAY, and mansession::parsing.

Referenced by do_message().

6836 {
6837  mansession_lock(s);
6838  astman_send_error(s, m, error);
6839  s->parsing = MESSAGE_OKAY;
6840  mansession_unlock(s);
6841 }
static void mansession_unlock(struct mansession *s)
Unlock the &#39;mansession&#39; structure.
Definition: manager.c:3257
enum mansession_message_parsing parsing
Definition: manager.c:1629
static void mansession_lock(struct mansession *s)
Lock the &#39;mansession&#39; structure.
Definition: manager.c:3251
int error(const char *format,...)
Definition: utils/frame.c:999
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ handle_showmanager()

static char* handle_showmanager ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 2497 of file manager.c.

References ast_manager_user::acl, ast_manager_user::allowmultiplelogin, ast_cli_args::argc, ast_cli_args::argv, ast_acl_list_is_empty(), ast_acl_output(), ast_cli(), ast_cli_completion_add(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_str_alloca, ast_strdup, ast_manager_user::chanvars, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_manager_user::displayconnects, ast_cli_args::fd, get_manager_by_name_locked(), MAX_AUTH_PERM_STRING, ast_variable::name, ast_variable::next, NULL, ast_cli_args::pos, ast_manager_user::readperm, S_OR, ast_manager_user::secret, ast_cli_entry::usage, user_authority_to_str(), ast_manager_user::username, ast_variable::value, ast_cli_args::word, and ast_manager_user::writeperm.

2498 {
2499  struct ast_manager_user *user = NULL;
2500  int l;
2501  struct ast_str *rauthority = ast_str_alloca(MAX_AUTH_PERM_STRING);
2502  struct ast_str *wauthority = ast_str_alloca(MAX_AUTH_PERM_STRING);
2503  struct ast_variable *v;
2504 
2505  switch (cmd) {
2506  case CLI_INIT:
2507  e->command = "manager show user";
2508  e->usage =
2509  " Usage: manager show user <user>\n"
2510  " Display all information related to the manager user specified.\n";
2511  return NULL;
2512  case CLI_GENERATE:
2513  l = strlen(a->word);
2514  if (a->pos != 3) {
2515  return NULL;
2516  }
2518  AST_RWLIST_TRAVERSE(&users, user, list) {
2519  if (!strncasecmp(a->word, user->username, l)) {
2521  break;
2522  }
2523  }
2524  }
2526  return NULL;
2527  }
2528 
2529  if (a->argc != 4) {
2530  return CLI_SHOWUSAGE;
2531  }
2532 
2534 
2535  if (!(user = get_manager_by_name_locked(a->argv[3]))) {
2536  ast_cli(a->fd, "There is no manager called %s\n", a->argv[3]);
2538  return CLI_SUCCESS;
2539  }
2540 
2541  ast_cli(a->fd, "\n");
2542  ast_cli(a->fd,
2543  " username: %s\n"
2544  " secret: %s\n"
2545  " ACL: %s\n"
2546  " read perm: %s\n"
2547  " write perm: %s\n"
2548  " displayconnects: %s\n"
2549  "allowmultiplelogin: %s\n",
2550  S_OR(user->username, "(N/A)"),
2551  (user->secret ? "<Set>" : "(N/A)"),
2552  ((user->acl && !ast_acl_list_is_empty(user->acl)) ? "yes" : "no"),
2553  user_authority_to_str(user->readperm, &rauthority),
2554  user_authority_to_str(user->writeperm, &wauthority),
2555  (user->displayconnects ? "yes" : "no"),
2556  (user->allowmultiplelogin ? "yes" : "no"));
2557  ast_cli(a->fd, " Variables: \n");
2558  for (v = user->chanvars ; v ; v = v->next) {
2559  ast_cli(a->fd, " %s = %s\n", v->name, v->value);
2560  }
2561  if (!ast_acl_list_is_empty(user->acl)) {
2562  ast_acl_output(a->fd, user->acl, NULL);
2563  }
2564 
2566 
2567  return CLI_SUCCESS;
2568 }
struct ast_variable * next
char username[80]
Definition: manager.c:1645
#define MAX_AUTH_PERM_STRING
Definition: manager.c:2043
static struct ast_manager_user * get_manager_by_name_locked(const char *name)
Definition: manager.c:2305
const int argc
Definition: cli.h:160
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Structure for variables, used for configurations and for channel variables.
void ast_acl_output(int fd, struct ast_acl_list *acl, const char *prefix)
output an ACL to the provided fd
Definition: acl.c:1099
Definition: cli.h:152
#define ast_str_alloca(init_len)
Definition: strings.h:800
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
user descriptor, as read from the config file.
Definition: manager.c:1644
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
list of users found in the config file
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
const int fd
Definition: cli.h:159
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
struct ast_variable * chanvars
Definition: manager.c:1657
int ast_acl_list_is_empty(struct ast_acl_list *acl_list)
Determines if an ACL is empty or if it contains entries.
Definition: acl.c:541
const char *const * argv
Definition: cli.h:161
struct ast_acl_list * acl
Definition: manager.c:1655
static const char * user_authority_to_str(int authority, struct ast_str **res)
Convert authority code to a list of options for a user. This will only display those authority codes ...
Definition: manager.c:2060
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define CLI_SHOWUSAGE
Definition: cli.h:45
int allowmultiplelogin
Definition: manager.c:1651
char * command
Definition: cli.h:186
const char * word
Definition: cli.h:163
structure to hold users read from users.conf
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
#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
const int pos
Definition: cli.h:164
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
Definition: main/cli.c:2726

◆ handle_showmanagers()

static char* handle_showmanagers ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 2570 of file manager.c.

References ast_cli_args::argc, ast_cli(), AST_RWLIST_EMPTY, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, NULL, ast_cli_entry::usage, and ast_manager_user::username.

2571 {
2572  struct ast_manager_user *user = NULL;
2573  int count_amu = 0;
2574  switch (cmd) {
2575  case CLI_INIT:
2576  e->command = "manager show users";
2577  e->usage =
2578  "Usage: manager show users\n"
2579  " Prints a listing of all managers that are currently configured on that\n"
2580  " system.\n";
2581  return NULL;
2582  case CLI_GENERATE:
2583  return NULL;
2584  }
2585  if (a->argc != 3) {
2586  return CLI_SHOWUSAGE;
2587  }
2588 
2590 
2591  /* If there are no users, print out something along those lines */
2592  if (AST_RWLIST_EMPTY(&users)) {
2593  ast_cli(a->fd, "There are no manager users.\n");
2595  return CLI_SUCCESS;
2596  }
2597 
2598  ast_cli(a->fd, "\nusername\n--------\n");
2599 
2600  AST_RWLIST_TRAVERSE(&users, user, list) {
2601  ast_cli(a->fd, "%s\n", user->username);
2602  count_amu++;
2603  }
2604 
2606 
2607  ast_cli(a->fd,"-------------------\n"
2608  "%d manager users configured.\n", count_amu);
2609  return CLI_SUCCESS;
2610 }
char username[80]
Definition: manager.c:1645
const int argc
Definition: cli.h:160
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Definition: cli.h:152
#define NULL
Definition: resample.c:96
user descriptor, as read from the config file.
Definition: manager.c:1644
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
list of users found in the config file
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
const int fd
Definition: cli.h:159
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
#define AST_RWLIST_EMPTY
Definition: linkedlists.h:451
#define CLI_SHOWUSAGE
Definition: cli.h:45
char * command
Definition: cli.h:186
structure to hold users read from users.conf
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44

◆ handle_showmancmd()

static char* handle_showmancmd ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 2340 of file manager.c.

References manager_action::action, ast_cli_args::argc, manager_action::arguments, ast_cli_args::argv, ast_cli(), ast_cli_completion_add(), ast_free, AST_LIST_NEXT, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_str_alloca, ast_strdup, AST_XML_DOC, ast_xmldoc_printable(), manager_action::authority, authority_to_str(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, COLOR_MAGENTA, ast_cli_entry::command, manager_action::description, manager_action::docsrc, ast_cli_args::fd, manager_action::final_response, manager_action::list_responses, MAX_AUTH_PERM_STRING, ast_xml_doc_item::name, ast_xml_doc_item::next, NULL, print_event_instance(), S_OR, manager_action::seealso, synopsis, manager_action::synopsis, manager_action::syntax, term_color(), ast_cli_entry::usage, and ast_cli_args::word.

2341 {
2342  struct manager_action *cur;
2343  struct ast_str *authority;
2344  int num;
2345  int l;
2346  const char *auth_str;
2347 #ifdef AST_XML_DOCS
2348  char syntax_title[64], description_title[64], synopsis_title[64], seealso_title[64];
2349  char arguments_title[64], privilege_title[64], final_response_title[64], list_responses_title[64];
2350 #endif
2351 
2352  switch (cmd) {
2353  case CLI_INIT:
2354  e->command = "manager show command";
2355  e->usage =
2356  "Usage: manager show command <actionname> [<actionname> [<actionname> [...]]]\n"
2357  " Shows the detailed description for a specific Asterisk manager interface command.\n";
2358  return NULL;
2359  case CLI_GENERATE:
2360  l = strlen(a->word);
2362  AST_RWLIST_TRAVERSE(&actions, cur, list) {
2363  if (!strncasecmp(a->word, cur->action, l)) {
2365  break;
2366  }
2367  }
2368  }
2370  return NULL;
2371  }
2372  if (a->argc < 4) {
2373  return CLI_SHOWUSAGE;
2374  }
2375 
2376  authority = ast_str_alloca(MAX_AUTH_PERM_STRING);
2377 
2378 #ifdef AST_XML_DOCS
2379  /* setup the titles */
2380  term_color(synopsis_title, "[Synopsis]\n", COLOR_MAGENTA, 0, 40);
2381  term_color(description_title, "[Description]\n", COLOR_MAGENTA, 0, 40);
2382  term_color(syntax_title, "[Syntax]\n", COLOR_MAGENTA, 0, 40);
2383  term_color(seealso_title, "[See Also]\n", COLOR_MAGENTA, 0, 40);
2384  term_color(arguments_title, "[Arguments]\n", COLOR_MAGENTA, 0, 40);
2385  term_color(privilege_title, "[Privilege]\n", COLOR_MAGENTA, 0, 40);
2386  term_color(final_response_title, "[Final Response]\n", COLOR_MAGENTA, 0, 40);
2387  term_color(list_responses_title, "[List Responses]\n", COLOR_MAGENTA, 0, 40);
2388 #endif
2389 
2391  AST_RWLIST_TRAVERSE(&actions, cur, list) {
2392  for (num = 3; num < a->argc; num++) {
2393  if (!strcasecmp(cur->action, a->argv[num])) {
2394  auth_str = authority_to_str(cur->authority, &authority);
2395 
2396 #ifdef AST_XML_DOCS
2397  if (cur->docsrc == AST_XML_DOC) {
2398  char *syntax = ast_xmldoc_printable(S_OR(cur->syntax, "Not available"), 1);
2399  char *synopsis = ast_xmldoc_printable(S_OR(cur->synopsis, "Not available"), 1);
2400  char *description = ast_xmldoc_printable(S_OR(cur->description, "Not available"), 1);
2401  char *arguments = ast_xmldoc_printable(S_OR(cur->arguments, "Not available"), 1);
2402  char *seealso = ast_xmldoc_printable(S_OR(cur->seealso, "Not available"), 1);
2403  char *privilege = ast_xmldoc_printable(S_OR(auth_str, "Not available"), 1);
2404  char *responses = ast_xmldoc_printable("None", 1);
2405 
2406  if (!syntax || !synopsis || !description || !arguments
2407  || !seealso || !privilege || !responses) {
2408  ast_free(syntax);
2409  ast_free(synopsis);
2410  ast_free(description);
2411  ast_free(arguments);
2412  ast_free(seealso);
2413  ast_free(privilege);
2414  ast_free(responses);
2415  ast_cli(a->fd, "Allocation failure.\n");
2417 
2418  return CLI_FAILURE;
2419  }
2420 
2421  ast_cli(a->fd, "%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n%s",
2422  syntax_title, syntax,
2423  synopsis_title, synopsis,
2424  description_title, description,
2425  arguments_title, arguments,
2426  seealso_title, seealso,
2427  privilege_title, privilege,
2428  list_responses_title);
2429 
2430  if (!cur->list_responses) {
2431  ast_cli(a->fd, "%s\n\n", responses);
2432  } else {
2433  struct ast_xml_doc_item *temp;
2434  for (temp = cur->list_responses; temp; temp = AST_LIST_NEXT(temp, next)) {
2435  ast_cli(a->fd, "Event: %s\n", temp->name);
2436  print_event_instance(a, temp);
2437  }
2438  }
2439 
2440  ast_cli(a->fd, "%s", final_response_title);
2441 
2442  if (!cur->final_response) {
2443  ast_cli(a->fd, "%s\n\n", responses);
2444  } else {
2445  ast_cli(a->fd, "Event: %s\n", cur->final_response->name);
2447  }
2448 
2449  ast_free(syntax);
2450  ast_free(synopsis);
2451  ast_free(description);
2452  ast_free(arguments);
2453  ast_free(seealso);
2454  ast_free(privilege);
2455  ast_free(responses);
2456  } else
2457 #endif
2458  {
2459  ast_cli(a->fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n",
2460  cur->action, cur->synopsis,
2461  auth_str,
2462  S_OR(cur->description, ""));
2463  }
2464  }
2465  }
2466  }
2468 
2469  return CLI_SUCCESS;
2470 }
static const char synopsis[]
Definition: app_mysql.c:64
struct ast_xml_doc_item * next
Definition: xmldoc.h:80
#define MAX_AUTH_PERM_STRING
Definition: manager.c:2043
const int argc
Definition: cli.h:160
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
const char * action
Definition: manager.h:151
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:438
Definition: cli.h:152
static const char * authority_to_str(int authority, struct ast_str **res)
Convert authority code to a list of options. Note that the EVENT_FLAG_ALL authority will always be re...
Definition: manager.c:2084
#define ast_str_alloca(init_len)
Definition: strings.h:800
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
struct ast_xml_doc_item * list_responses
Definition: manager.h:160
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
enum ast_doc_src docsrc
Definition: manager.h:169
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
const int fd
Definition: cli.h:159
const ast_string_field description
Definition: manager.h:158
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
static void print_event_instance(struct ast_cli_args *a, struct ast_xml_doc_item *instance)
Definition: manager.c:8793
list of actions registered
Definition: manager.c:1665
char * term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
Colorize a specified string by adding terminal color codes.
Definition: term.c:184
const ast_string_field arguments
Definition: manager.h:158
const char *const * argv
Definition: cli.h:161
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define CLI_SHOWUSAGE
Definition: cli.h:45
const ast_string_field name
Definition: xmldoc.h:74
#define CLI_FAILURE
Definition: cli.h:46
#define ast_free(a)
Definition: astmm.h:182
char * command
Definition: cli.h:186
const char * word
Definition: cli.h:163
char * ast_xmldoc_printable(const char *bwinput, int withcolors)
Colorize and put delimiters (instead of tags) to the xmldoc output.
Definition: xmldoc.c:242
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
#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 that contains the XML documentation for a particular item. Note that this is an ao2 ref counte...
Definition: xmldoc.h:56
const ast_string_field synopsis
Definition: manager.h:158
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
Definition: main/cli.c:2726
struct ast_xml_doc_item * final_response
Definition: manager.h:162
const ast_string_field seealso
Definition: manager.h:158
const ast_string_field syntax
Definition: manager.h:158
#define COLOR_MAGENTA
Definition: term.h:57

◆ handle_showmancmds()

static char* handle_showmancmds ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

CLI command manager list commands.

Definition at line 2613 of file manager.c.

References manager_action::action, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, HSMC_FORMAT, MGR_SHOW_TERMINAL_WIDTH, NULL, manager_action::synopsis, and ast_cli_entry::usage.

2614 {
2615  struct manager_action *cur;
2616  int name_len = 1;
2617  int space_remaining;
2618 #define HSMC_FORMAT " %-*.*s %-.*s\n"
2619  switch (cmd) {
2620  case CLI_INIT:
2621  e->command = "manager show commands";
2622  e->usage =
2623  "Usage: manager show commands\n"
2624  " Prints a listing of all the available Asterisk manager interface commands.\n";
2625  return NULL;
2626  case CLI_GENERATE:
2627  return NULL;
2628  }
2629 
2631  AST_RWLIST_TRAVERSE(&actions, cur, list) {
2632  int incoming_len = strlen(cur->action);
2633  if (incoming_len > name_len) {
2634  name_len = incoming_len;
2635  }
2636  }
2637 
2638  space_remaining = MGR_SHOW_TERMINAL_WIDTH - name_len - 4;
2639  if (space_remaining < 0) {
2640  space_remaining = 0;
2641  }
2642 
2643  ast_cli(a->fd, HSMC_FORMAT, name_len, name_len, "Action", space_remaining, "Synopsis");
2644  ast_cli(a->fd, HSMC_FORMAT, name_len, name_len, "------", space_remaining, "--------");
2645 
2646  AST_RWLIST_TRAVERSE(&actions, cur, list) {
2647  ast_cli(a->fd, HSMC_FORMAT, name_len, name_len, cur->action, space_remaining, cur->synopsis);
2648  }
2650 
2651  return CLI_SUCCESS;
2652 }
#define HSMC_FORMAT
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
const char * action
Definition: manager.h:151
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
const int fd
Definition: cli.h:159
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
list of actions registered
Definition: manager.c:1665
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
#define MGR_SHOW_TERMINAL_WIDTH
Definition: manager.c:1506
const ast_string_field synopsis
Definition: manager.h:158

◆ handle_showmanconn()

static char* handle_showmanconn ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

CLI command manager list connected.

Definition at line 2655 of file manager.c.

References mansession_session::addr, ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, ast_cli(), ast_iostream_get_fd(), ast_sockaddr_stringify_addr(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, HSMCONN_FORMAT1, HSMCONN_FORMAT2, mansession_session::inuse, NULL, mansession_session::readperm, session, sessions, mansession_session::sessionstart, mansession_session::stream, unref_mansession(), ast_cli_entry::usage, mansession_session::username, and mansession_session::writeperm.

2656 {
2657  struct ao2_container *sessions;
2658  struct mansession_session *session;
2659  time_t now = time(NULL);
2660 #define HSMCONN_FORMAT1 " %-15.15s %-55.55s %-10.10s %-10.10s %-8.8s %-8.8s %-5.5s %-5.5s\n"
2661 #define HSMCONN_FORMAT2 " %-15.15s %-55.55s %-10d %-10d %-8d %-8d %-5.5d %-5.5d\n"
2662  int count = 0;
2663  struct ao2_iterator i;
2664 
2665  switch (cmd) {
2666  case CLI_INIT:
2667  e->command = "manager show connected";
2668  e->usage =
2669  "Usage: manager show connected\n"
2670  " Prints a listing of the users that are currently connected to the\n"
2671  "Asterisk manager interface.\n";
2672  return NULL;
2673  case CLI_GENERATE:
2674  return NULL;
2675  }
2676 
2677  ast_cli(a->fd, HSMCONN_FORMAT1, "Username", "IP Address", "Start", "Elapsed", "FileDes", "HttpCnt", "Read", "Write");
2678 
2679  sessions = ao2_global_obj_ref(mgr_sessions);
2680  if (sessions) {
2681  i = ao2_iterator_init(sessions, 0);
2682  ao2_ref(sessions, -1);
2683  while ((session = ao2_iterator_next(&i))) {
2684  ao2_lock(session);
2685  ast_cli(a->fd, HSMCONN_FORMAT2, session->username,
2686  ast_sockaddr_stringify_addr(&session->addr),
2687  (int) (session->sessionstart),
2688  (int) (now - session->sessionstart),
2689  session->stream ? ast_iostream_get_fd(session->stream) : -1,
2690  session->inuse,
2691  session->readperm,
2692  session->writeperm);
2693  count++;
2694  ao2_unlock(session);
2695  unref_mansession(session);
2696  }
2698  }
2699  ast_cli(a->fd, "%d users connected.\n", count);
2700 
2701  return CLI_SUCCESS;
2702 }
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition: netsock2.h:290
char username[80]
Definition: manager.c:1592
#define HSMCONN_FORMAT1
static struct sessions sessions
#define HSMCONN_FORMAT2
Definition: cli.h:152
#define ao2_global_obj_ref(holder)
Definition: astobj2.h:925
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
int ast_iostream_get_fd(struct ast_iostream *stream)
Get an iostream&#39;s file descriptor.
Definition: iostream.c:84
#define ao2_unlock(a)
Definition: astobj2.h:730
struct ast_sockaddr addr
Definition: manager.c:1583
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
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
const int fd
Definition: cli.h:159
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
char * command
Definition: cli.h:186
struct ast_iostream * stream
Definition: manager.c:1584
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
Generic container type.
time_t sessionstart
Definition: manager.c:1589
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.

◆ handle_showmaneventq()

static char* handle_showmaneventq ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

CLI command manager list eventq.

Definition at line 2706 of file manager.c.

References ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, eventqent::category, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, NULL, reload_module(), ast_cli_entry::usage, and eventqent::usecount.

2707 {
2708  struct eventqent *s;
2709  switch (cmd) {
2710  case CLI_INIT:
2711  e->command = "manager show eventq";
2712  e->usage =
2713  "Usage: manager show eventq\n"
2714  " Prints a listing of all events pending in the Asterisk manger\n"
2715  "event queue.\n";
2716  return NULL;
2717  case CLI_GENERATE:
2718  return NULL;
2719  }
2721  AST_RWLIST_TRAVERSE(&all_events, s, eq_next) {
2722  ast_cli(a->fd, "Usecount: %d\n", s->usecount);
2723  ast_cli(a->fd, "Category: %d\n", s->category);
2724  ast_cli(a->fd, "Event:\n%s", s->eventdata);
2725  }
2727 
2728  return CLI_SUCCESS;
2729 }
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
const int fd
Definition: cli.h:159
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
int usecount
Definition: manager.c:1460
char * command
Definition: cli.h:186
int category
Definition: manager.c:1461
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44

◆ handle_updates()

static enum error_type handle_updates ( struct mansession s,
const struct message m,
struct ast_config cfg,
const char *  dfn 
)
static

helper function for action_updateconfig

Definition at line 3819 of file manager.c.

References ast_begins_with(), ast_category_append(), ast_category_browse_filtered(), ast_category_delete(), ast_category_destroy(), ast_category_empty(), ast_category_get(), ast_category_inherit(), ast_category_insert(), ast_category_new(), ast_category_new_template(), ast_category_rename(), ast_free, ast_log, ast_str_create, ast_strdup, ast_strlen_zero, ast_strsep(), AST_STRSEP_STRIP, ast_variable_append(), ast_variable_delete(), ast_variable_insert(), ast_variable_new, ast_variable_update(), astman_get_header(), c, eventqent::category, copy(), FAILURE_ALLOCATION, FAILURE_NEWCAT, FAILURE_TEMPLATE, FAILURE_UPDATE, LOG_WARNING, match(), NULL, ast_variable::object, options, RAII_VAR, result, UNKNOWN_ACTION, UNKNOWN_CATEGORY, UNSPECIFIED_ARGUMENT, UNSPECIFIED_CATEGORY, value, and var.

Referenced by action_updateconfig().

3820 {
3821  int x;
3822  char hdr[40];
3823  const char *action, *cat, *var, *value, *match, *line, *options;
3824  struct ast_variable *v;
3825  struct ast_str *str1 = ast_str_create(16), *str2 = ast_str_create(16);
3826  enum error_type result = 0;
3827 
3828  for (x = 0; x < 100000; x++) { /* 100000 = the max number of allowed updates + 1 */
3829  unsigned int object = 0;
3830  char *dupoptions;
3831  int allowdups = 0;
3832  int istemplate = 0;
3833  int ignoreerror = 0;
3834  RAII_VAR(char *, inherit, NULL, ast_free);
3835  RAII_VAR(char *, catfilter, NULL, ast_free);
3836  char *token;
3837  int foundvar = 0;
3838  int foundcat = 0;
3839  struct ast_category *category = NULL;
3840 
3841  snprintf(hdr, sizeof(hdr), "Action-%06d", x);
3842  action = astman_get_header(m, hdr);
3843  if (ast_strlen_zero(action)) /* breaks the for loop if no action header */
3844  break; /* this could cause problems if actions come in misnumbered */
3845 
3846  snprintf(hdr, sizeof(hdr), "Cat-%06d", x);
3847  cat = astman_get_header(m, hdr);
3848  if (ast_strlen_zero(cat)) { /* every action needs a category */
3849  result = UNSPECIFIED_CATEGORY;
3850  break;
3851  }
3852 
3853  snprintf(hdr, sizeof(hdr), "Var-%06d", x);
3854  var = astman_get_header(m, hdr);
3855 
3856  snprintf(hdr, sizeof(hdr), "Value-%06d", x);
3857  value = astman_get_header(m, hdr);
3858 
3859  if (!ast_strlen_zero(value) && *value == '>') {
3860  object = 1;
3861  value++;
3862  }
3863 
3864  snprintf(hdr, sizeof(hdr), "Match-%06d", x);
3865  match = astman_get_header(m, hdr);
3866 
3867  snprintf(hdr, sizeof(hdr), "Line-%06d", x);
3868  line = astman_get_header(m, hdr);
3869 
3870  snprintf(hdr, sizeof(hdr), "Options-%06d", x);
3871  options = astman_get_header(m, hdr);
3872  if (!ast_strlen_zero(options)) {
3873  char copy[strlen(options) + 1];
3874  strcpy(copy, options); /* safe */
3875  dupoptions = copy;
3876  while ((token = ast_strsep(&dupoptions, ',', AST_STRSEP_STRIP))) {
3877  if (!strcasecmp("allowdups", token)) {
3878  allowdups = 1;
3879  continue;
3880  }
3881  if (!strcasecmp("template", token)) {
3882  istemplate = 1;
3883  continue;
3884  }
3885  if (!strcasecmp("ignoreerror", token)) {
3886  ignoreerror = 1;
3887  continue;
3888  }
3889  if (ast_begins_with(token, "inherit")) {
3890  char *c = ast_strsep(&token, '=', AST_STRSEP_STRIP);
3891  c = ast_strsep(&token, '=', AST_STRSEP_STRIP);
3892  if (c) {
3893  inherit = ast_strdup(c);
3894  }
3895  continue;
3896  }
3897  if (ast_begins_with(token, "catfilter")) {
3898  char *c = ast_strsep(&token, '=', AST_STRSEP_STRIP);
3899  c = ast_strsep(&token, '=', AST_STRSEP_STRIP);
3900  if (c) {
3901  catfilter = ast_strdup(c);
3902  }
3903  continue;
3904  }
3905  }
3906  }
3907 
3908  if (!strcasecmp(action, "newcat")) {
3909  struct ast_category *template;
3910  char *tmpl_name = NULL;
3911 
3912  if (!allowdups) {
3913  if (ast_category_get(cfg, cat, "TEMPLATES=include")) {
3914  if (ignoreerror) {
3915  continue;
3916  } else {
3917  result = FAILURE_NEWCAT; /* already exist */
3918  break;
3919  }
3920  }
3921  }
3922 
3923  if (istemplate) {
3924  category = ast_category_new_template(cat, dfn, -1);
3925  } else {
3926  category = ast_category_new(cat, dfn, -1);
3927  }
3928 
3929  if (!category) {
3930  result = FAILURE_ALLOCATION;
3931  break;
3932  }
3933 
3934  if (inherit) {
3935  while ((tmpl_name = ast_strsep(&inherit, ',', AST_STRSEP_STRIP))) {
3936  if ((template = ast_category_get(cfg, tmpl_name, "TEMPLATES=restrict"))) {
3937  if (ast_category_inherit(category, template)) {
3938  result = FAILURE_ALLOCATION;
3939  break;
3940  }
3941  } else {
3942  ast_category_destroy(category);
3943  category = NULL;
3944  result = FAILURE_TEMPLATE; /* template not found */
3945  break;
3946  }
3947  }
3948  }
3949 
3950  if (category != NULL) {
3951  if (ast_strlen_zero(match)) {
3952  ast_category_append(cfg, category);
3953  } else {
3954  if (ast_category_insert(cfg, category, match)) {
3955  ast_category_destroy(category);
3956  result = FAILURE_NEWCAT;
3957  break;
3958  }
3959  }
3960  }
3961  } else if (!strcasecmp(action, "renamecat")) {
3962  if (ast_strlen_zero(value)) {
3963  result = UNSPECIFIED_ARGUMENT;
3964  break;
3965  }
3966 
3967  foundcat = 0;
3968  while ((category = ast_category_browse_filtered(cfg, cat, category, catfilter))) {
3969  ast_category_rename(category, value);
3970  foundcat = 1;
3971  }
3972 
3973  if (!foundcat) {
3974  result = UNKNOWN_CATEGORY;
3975  break;
3976  }
3977  } else if (!strcasecmp(action, "delcat")) {
3978  foundcat = 0;
3979  while ((category = ast_category_browse_filtered(cfg, cat, category, catfilter))) {
3980  category = ast_category_delete(cfg, category);
3981  foundcat = 1;
3982  }
3983 
3984  if (!foundcat && !ignoreerror) {
3985  result = UNKNOWN_CATEGORY;
3986  break;
3987  }
3988  } else if (!strcasecmp(action, "emptycat")) {
3989  foundcat = 0;
3990  while ((category = ast_category_browse_filtered(cfg, cat, category, catfilter))) {
3991  ast_category_empty(category);
3992  foundcat = 1;
3993  }
3994 
3995  if (!foundcat) {
3996  result = UNKNOWN_CATEGORY;
3997  break;
3998  }
3999  } else if (!strcasecmp(action, "update")) {
4000  if (ast_strlen_zero(var)) {
4001  result = UNSPECIFIED_ARGUMENT;
4002  break;
4003  }
4004 
4005  foundcat = 0;
4006  foundvar = 0;
4007  while ((category = ast_category_browse_filtered(cfg, cat, category, catfilter))) {
4008  if (!ast_variable_update(category, var, value, match, object)) {
4009  foundvar = 1;
4010  }
4011  foundcat = 1;
4012  }
4013 
4014  if (!foundcat) {
4015  result = UNKNOWN_CATEGORY;
4016  break;
4017  }
4018 
4019  if (!foundvar) {
4020  result = FAILURE_UPDATE;
4021  break;
4022  }
4023  } else if (!strcasecmp(action, "delete")) {
4024  if ((ast_strlen_zero(var) && ast_strlen_zero(line))) {
4025  result = UNSPECIFIED_ARGUMENT;
4026  break;
4027  }
4028 
4029  foundcat = 0;
4030  foundvar = 0;
4031  while ((category = ast_category_browse_filtered(cfg, cat, category, catfilter))) {
4032  if (!ast_variable_delete(category, var, match, line)) {
4033  foundvar = 1;
4034  }
4035  foundcat = 1;
4036  }
4037 
4038  if (!foundcat) {
4039  result = UNKNOWN_CATEGORY;
4040  break;
4041  }
4042 
4043  if (!foundvar && !ignoreerror) {
4044  result = FAILURE_UPDATE;
4045  break;
4046  }
4047  } else if (!strcasecmp(action, "append")) {
4048  if (ast_strlen_zero(var)) {
4049  result = UNSPECIFIED_ARGUMENT;
4050  break;
4051  }
4052 
4053  foundcat = 0;
4054  while ((category = ast_category_browse_filtered(cfg, cat, category, catfilter))) {
4055  if (!(v = ast_variable_new(var, value, dfn))) {
4056  result = FAILURE_ALLOCATION;
4057  break;
4058  }
4059  if (object || (match && !strcasecmp(match, "object"))) {
4060  v->object = 1;
4061  }
4062  ast_variable_append(category, v);
4063  foundcat = 1;
4064  }
4065 
4066  if (!foundcat) {
4067  result = UNKNOWN_CATEGORY;
4068  break;
4069  }
4070  } else if (!strcasecmp(action, "insert")) {
4071  if (ast_strlen_zero(var) || ast_strlen_zero(line)) {
4072  result = UNSPECIFIED_ARGUMENT;
4073  break;
4074  }
4075 
4076  foundcat = 0;
4077  while ((category = ast_category_browse_filtered(cfg, cat, category, catfilter))) {
4078  if (!(v = ast_variable_new(var, value, dfn))) {
4079  result = FAILURE_ALLOCATION;
4080  break;
4081  }
4082  ast_variable_insert(category, v, line);
4083  foundcat = 1;
4084  }
4085 
4086  if (!foundcat) {
4087  result = UNKNOWN_CATEGORY;
4088  break;
4089  }
4090  }
4091  else {
4092  ast_log(LOG_WARNING, "Action-%06d: %s not handled\n", x, action);
4093  result = UNKNOWN_ACTION;
4094  break;
4095  }
4096  }
4097  ast_free(str1);
4098  ast_free(str2);
4099  return result;
4100 }
struct ast_category * ast_category_new(const char *name, const char *in_file, int lineno)
Create a category.
Definition: extconf.c:2790
void ast_variable_insert(struct ast_category *category, struct ast_variable *variable, const char *line)
Definition: main/config.c:501
int ast_variable_delete(struct ast_category *category, const char *variable, const char *match, const char *line)
Definition: main/config.c:1399
struct ast_category * ast_category_delete(struct ast_config *cfg, struct ast_category *category)
Delete a category.
Definition: main/config.c:1478
#define LOG_WARNING
Definition: logger.h:274
error_type
Definition: manager.c:1419
Structure for variables, used for configurations and for channel variables.
#define var
Definition: ast_expr2f.c:614
static int copy(char *infile, char *outfile)
Utility function to copy a file.
static struct test_val c
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2315
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
void ast_category_destroy(struct ast_category *cat)
Definition: extconf.c:2847
struct ast_category * ast_category_browse_filtered(struct ast_config *config, const char *category_name, struct ast_category *prev, const char *filter)
Browse categories with filters.
Definition: main/config.c:1335
int ast_category_inherit(struct ast_category *existing, const struct ast_category *base)
Applies base (template) to category.
Definition: main/config.c:1367
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
void ast_category_rename(struct ast_category *cat, const char *name)
Definition: main/config.c:1362
#define ast_log
Definition: astobj2.c:42
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
char * ast_strsep(char **s, const char sep, uint32_t flags)
Act like strsep but ignore separators inside quotes.
Definition: main/utils.c:1656
#define ast_variable_new(name, value, filename)
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
int ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match)
Inserts new category.
Definition: main/config.c:1083
#define ast_free(a)
Definition: astmm.h:182
int ast_variable_update(struct ast_category *category, const char *variable, const char *value, const char *match, unsigned int object)
Update variable value within a config.
Definition: main/config.c:1444
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
Definition: extconf.c:1178
void ast_category_append(struct ast_config *config, struct ast_category *cat)
Appends a category to a config.
Definition: extconf.c:2835
struct ast_category * ast_category_new_template(const char *name, const char *in_file, int lineno)
Create a category making it a template.
Definition: main/config.c:995
int ast_category_empty(struct ast_category *category)
Removes and destroys all variables in a category.
Definition: main/config.c:1510
static PGresult * result
Definition: cel_pgsql.c:88
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Definition: strings.h:94
static struct test_options options
struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name, const char *filter)
Retrieve a category if it exists.
Definition: main/config.c:1022
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ json_escape()

static void json_escape ( char *  out,
const char *  in 
)
static

The amount of space in out must be at least ( 2 * strlen(in) + 1 )

Definition at line 3721 of file manager.c.

References in.

Referenced by astman_append_json().

3722 {
3723  for (; *in; in++) {
3724  if (*in == '\\' || *in == '\"') {
3725  *out++ = '\\';
3726  }
3727  *out++ = *in;
3728  }
3729  *out = '\0';
3730 }
FILE * in
Definition: utils/frame.c:33
FILE * out
Definition: utils/frame.c:33

◆ log_action()

static void log_action ( const struct message m,
const char *  action 
)
static

Definition at line 6568 of file manager.c.

References ast_free, ast_str_append(), ast_str_buffer(), ast_str_create, ast_verbose(), buf, message::hdrcount, message::headers, and manager_debug.

Referenced by process_message().

6569 {
6570  struct ast_str *buf;
6571  int x;
6572 
6573  if (!manager_debug) {
6574  return;
6575  }
6576 
6577  buf = ast_str_create(256);
6578  if (!buf) {
6579  return;
6580  }
6581 
6582  for (x = 0; x < m->hdrcount; ++x) {
6583  if (!strncasecmp(m->headers[x], "Secret", 6)) {
6584  ast_str_append(&buf, 0, "Secret: <redacted from logging>\n");
6585  } else {
6586  ast_str_append(&buf, 0, "%s\n", m->headers[x]);
6587  }
6588  }
6589 
6590  ast_verbose("<--- Examining AMI action: -->\n%s\n", ast_str_buffer(buf));
6591  ast_free(buf);
6592 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
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
void ast_verbose(const char *fmt,...)
Definition: extconf.c:2207
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int manager_debug
Definition: manager.c:1478
#define ast_free(a)
Definition: astmm.h:182
const char * headers[AST_MAX_MANHEADERS]
Definition: manager.h:146
unsigned int hdrcount
Definition: manager.h:145
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ man_do_variable_value()

static struct ast_variable* man_do_variable_value ( struct ast_variable head,
const char *  hdr_val 
)
static

Definition at line 2862 of file manager.c.

References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_skip_blanks(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero, ast_variable_new, ast_variable::next, parse(), strsep(), and var.

Referenced by astman_get_variables_order().

2863 {
2864  char *parse;
2866  AST_APP_ARG(vars)[64];
2867  );
2868 
2869  hdr_val = ast_skip_blanks(hdr_val); /* ignore leading spaces in the value */
2870  parse = ast_strdupa(hdr_val);
2871 
2872  /* Break the header value string into name=val pair items. */
2873  AST_STANDARD_APP_ARGS(args, parse);
2874  if (args.argc) {
2875  int y;
2876 
2877  /* Process each name=val pair item. */
2878  for (y = 0; y < args.argc; y++) {
2879  struct ast_variable *cur;
2880  char *var;
2881  char *val;
2882 
2883  if (!args.vars[y]) {
2884  continue;
2885  }
2886  var = val = args.vars[y];
2887  strsep(&val, "=");
2888 
2889  /* XXX We may wish to trim whitespace from the strings. */
2890  if (!val || ast_strlen_zero(var)) {
2891  continue;
2892  }
2893 
2894  /* Create new variable list node and prepend it to the list. */
2895  cur = ast_variable_new(var, val, "");
2896  if (cur) {
2897  cur->next = head;
2898  head = cur;
2899  }
2900  }
2901  }
2902 
2903  return head;
2904 }
struct ast_variable * next
Definition: ast_expr2.c:325
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Structure for variables, used for configurations and for channel variables.
#define var
Definition: ast_expr2f.c:614
const char * args
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
#define ast_variable_new(name, value, filename)
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:157
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
char * strsep(char **str, const char *delims)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ manager_add_filter()

static enum add_filter_result manager_add_filter ( const char *  filter_pattern,
struct ao2_container whitefilters,
struct ao2_container blackfilters 
)
static

Add an event filter to a manager session.

Parameters
filter_patternFilter syntax to add, see below for syntax
Returns
FILTER_ALLOC_FAILED Memory allocation failure
FILTER_COMPILE_FAIL If the filter did not compile
FILTER_SUCCESS Success

Filter will be used to match against each line of a manager event Filter can be any valid regular expression Filter can be a valid regular expression prefixed with !, which will add the filter as a black filter

Examples:

filter_pattern = "Event: Newchannel"
filter_pattern = "Event: New.*"
filter_pattern = "!Channel: DAHDI.*"

Definition at line 6162 of file manager.c.

References ao2_ref, ao2_t_alloc, ao2_t_link, ao2_t_ref, event_filter_destructor(), FILTER_ALLOC_FAILED, FILTER_COMPILE_FAIL, and FILTER_SUCCESS.

Referenced by __init_manager(), and action_filter().

6162  {
6163  regex_t *new_filter = ao2_t_alloc(sizeof(*new_filter), event_filter_destructor, "event_filter allocation");
6164  int is_blackfilter;
6165 
6166  if (!new_filter) {
6167  return FILTER_ALLOC_FAILED;
6168  }
6169 
6170  if (filter_pattern[0] == '!') {
6171  is_blackfilter = 1;
6172  filter_pattern++;
6173  } else {
6174  is_blackfilter = 0;
6175  }
6176 
6177  if (regcomp(new_filter, filter_pattern, REG_EXTENDED | REG_NOSUB)) {
6178  ao2_t_ref(new_filter, -1, "failed to make regex");
6179  return FILTER_COMPILE_FAIL;
6180  }
6181 
6182  if (is_blackfilter) {
6183  ao2_t_link(blackfilters, new_filter, "link new filter into black user container");
6184  } else {
6185  ao2_t_link(whitefilters, new_filter, "link new filter into white user container");
6186  }
6187 
6188  ao2_ref(new_filter, -1);
6189 
6190  return FILTER_SUCCESS;
6191 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
#define ao2_t_alloc(data_size, destructor_fn, debug_msg)
Definition: astobj2.h:409
#define ao2_t_link(container, obj, tag)
Add an object to a container.
Definition: astobj2.h:1547
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static void event_filter_destructor(void *obj)
Definition: manager.c:2192

◆ manager_default_msg_cb()

static void manager_default_msg_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 1838 of file manager.c.

References any_manager_listeners, ao2_cleanup, ao2_global_obj_ref, ao2_ref, ast_manager_event_blob::event_flags, ast_manager_event_blob::extra_fields, ast_manager_event_blob::manager_event, manager_event_sessions, sessions, stasis_message_can_be_ami(), and stasis_message_to_ami().

Referenced by manager_subscriptions_init().

1840 {
1841  struct ao2_container *sessions;
1842  struct ast_manager_event_blob *ev;
1843 
1844  if (!stasis_message_can_be_ami(message)) {
1845  /* Not an AMI message; disregard */
1846  return;
1847  }
1848 
1849  sessions = ao2_global_obj_ref(mgr_sessions);
1850  if (!any_manager_listeners(sessions)) {
1851  /* Nobody is listening */
1852  ao2_cleanup(sessions);
1853  return;
1854  }
1855 
1856  ev = stasis_message_to_ami(message);
1857  if (!ev) {
1858  /* Conversion failure */
1859  ao2_cleanup(sessions);
1860  return;
1861  }
1862 
1864  "%s", ev->extra_fields);
1865  ao2_ref(ev, -1);
1866  ao2_cleanup(sessions);
1867 }
Struct containing info for an AMI event to send out.
Definition: manager.h:491
#define any_manager_listeners(sessions)
Definition: manager.c:1835
const ast_string_field extra_fields
Definition: manager.h:496
static struct sessions sessions
#define ao2_global_obj_ref(holder)
Definition: astobj2.h:925
const char * manager_event
Definition: manager.h:493
struct ast_manager_event_blob * stasis_message_to_ami(struct stasis_message *msg)
Build the AMI representation of the message.
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define manager_event_sessions(sessions, category, event, contents,...)
Definition: manager.c:1832
int stasis_message_can_be_ami(struct stasis_message *msg)
Determine if the given message can be converted to AMI.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Generic container type.

◆ manager_displayconnects()

static int manager_displayconnects ( struct mansession_session session)
static

Get displayconnects config option.

Parameters
sessionmanager session to get parameter from.
Returns
displayconnects config option value.

Definition at line 2322 of file manager.c.

References a, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_manager_user::displayconnects, get_manager_by_name_locked(), NULL, print_event_instance(), and mansession_session::username.

Referenced by action_login(), generic_http_callback(), purge_sessions(), and session_do().

2323 {
2324  struct ast_manager_user *user = NULL;
2325  int ret = 0;
2326 
2328  if ((user = get_manager_by_name_locked(session->username))) {
2329  ret = user->displayconnects;
2330  }
2332 
2333  return ret;
2334 }
char username[80]
Definition: manager.c:1592
static struct ast_manager_user * get_manager_by_name_locked(const char *name)
Definition: manager.c:2305
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define NULL
Definition: resample.c:96
user descriptor, as read from the config file.
Definition: manager.c:1644
list of users found in the config file
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
structure to hold users read from users.conf

◆ manager_generic_msg_cb()

static void manager_generic_msg_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 1869 of file manager.c.

References any_manager_listeners, ao2_cleanup, ao2_global_obj_ref, ast_free, ast_json_integer_get(), ast_json_object_get(), ast_json_string_get(), ast_log, AST_LOG_WARNING, ast_manager_str_from_json_object(), ast_str_buffer(), ast_json_payload::json, manager_event_sessions, NULL, sessions, stasis_message_data(), and type.

Referenced by manager_subscriptions_init().

1871 {
1872  struct ast_json_payload *payload;
1873  int class_type;
1874  const char *type;
1875  struct ast_json *event;
1876  struct ast_str *event_buffer;
1877  struct ao2_container *sessions;
1878 
1879  sessions = ao2_global_obj_ref(mgr_sessions);
1880  if (!any_manager_listeners(sessions)) {
1881  /* Nobody is listening */
1882  ao2_cleanup(sessions);
1883  return;
1884  }
1885 
1886  payload = stasis_message_data(message);
1887  class_type = ast_json_integer_get(ast_json_object_get(payload->json, "class_type"));
1888  type = ast_json_string_get(ast_json_object_get(payload->json, "type"));
1889  event = ast_json_object_get(payload->json, "event");
1890 
1891  event_buffer = ast_manager_str_from_json_object(event, NULL);
1892  if (!event_buffer) {
1893  ast_log(AST_LOG_WARNING, "Error while creating payload for event %s\n", type);
1894  ao2_cleanup(sessions);
1895  return;
1896  }
1897  manager_event_sessions(sessions, class_type, type,
1898  "%s", ast_str_buffer(event_buffer));
1899  ast_free(event_buffer);
1900  ao2_cleanup(sessions);
1901 }
static const char type[]
Definition: chan_ooh323.c:109
#define any_manager_listeners(sessions)
Definition: manager.c:1835
static struct sessions sessions
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define AST_LOG_WARNING
Definition: logger.h:279
struct ast_json * json
Definition: json.h:1025
Definition: astman.c:222
#define ao2_global_obj_ref(holder)
Definition: astobj2.h:925
#define NULL
Definition: resample.c:96
struct ast_str * ast_manager_str_from_json_object(struct ast_json *blob, key_exclusion_cb exclusion_cb)
Convert a JSON object into an AMI compatible string.
Definition: manager.c:1821
#define ast_log
Definition: astobj2.c:42
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#define ast_free(a)
Definition: astmm.h:182
#define manager_event_sessions(sessions, category, event, contents,...)
Definition: manager.c:1832
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:397
Abstract JSON element (object, array, string, int, ...).
Generic container type.
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
Definition: json.c:322

◆ manager_json_array_with_key()

static void manager_json_array_with_key ( struct ast_json obj,
const char *  key,
size_t  index,
struct ast_str **  res,
key_exclusion_cb  exclusion_cb 
)
static

Definition at line 1755 of file manager.c.

References ast_str_alloca, ast_str_buffer(), ast_str_set(), and manager_json_to_ast_str().

Referenced by manager_json_to_ast_str().

1758 {
1759  struct ast_str *key_str = ast_str_alloca(64);
1760  ast_str_set(&key_str, 0, "%s(%zu)", key, index);
1762  res, exclusion_cb);
1763 }
static void manager_json_to_ast_str(struct ast_json *obj, const char *key, struct ast_str **res, key_exclusion_cb exclusion_cb)
Definition: manager.c:1780
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define ast_str_alloca(init_len)
Definition: strings.h:800
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
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584

◆ manager_json_obj_with_key()

static void manager_json_obj_with_key ( struct ast_json obj,
const char *  key,
const char *  parent_key,
struct ast_str **  res,
key_exclusion_cb  exclusion_cb 
)
static

Definition at line 1765 of file manager.c.

References ast_str_alloca, ast_str_buffer(), ast_str_set(), and manager_json_to_ast_str().

Referenced by manager_json_to_ast_str().

1768 {
1769  if (parent_key) {
1770  struct ast_str *key_str = ast_str_alloca(64);
1771  ast_str_set(&key_str, 0, "%s/%s", parent_key, key);
1773  res, exclusion_cb);
1774  return;
1775  }
1776 
1777  manager_json_to_ast_str(obj, key, res, exclusion_cb);
1778 }
static void manager_json_to_ast_str(struct ast_json *obj, const char *key, struct ast_str **res, key_exclusion_cb exclusion_cb)
Definition: manager.c:1780
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define ast_str_alloca(init_len)
Definition: strings.h:800
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
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584

◆ manager_json_to_ast_str()

void manager_json_to_ast_str ( struct ast_json obj,
const char *  key,
struct ast_str **  res,
key_exclusion_cb  exclusion_cb 
)
static

Definition at line 1780 of file manager.c.

References AST_JSON_ARRAY, ast_json_array_get(), ast_json_array_size(), AST_JSON_OBJECT, ast_json_object_iter(), ast_json_object_iter_key(), ast_json_object_iter_next(), ast_json_object_iter_value(), ast_json_typeof(), ast_str_create, manager_json_array_with_key(), manager_json_obj_with_key(), and manager_json_value_str_append().

Referenced by ast_manager_str_from_json_object(), manager_json_array_with_key(), manager_json_obj_with_key(), and manager_json_value_str_append().

1782 {
1783  struct ast_json_iter *i;
1784 
1785  /* If obj or res is not given, just return */
1786  if (!obj || !res) {
1787  return;
1788  }
1789 
1790  if (!*res && !(*res = ast_str_create(1024))) {
1791  return;
1792  }
1793 
1794  if (exclusion_cb && key && exclusion_cb(key)) {
1795  return;
1796  }
1797 
1798  if (ast_json_typeof(obj) != AST_JSON_OBJECT &&
1799  ast_json_typeof(obj) != AST_JSON_ARRAY) {
1800  manager_json_value_str_append(obj, key, res);
1801  return;
1802  }
1803 
1804  if (ast_json_typeof(obj) == AST_JSON_ARRAY) {
1805  size_t j;
1806  for (j = 0; j < ast_json_array_size(obj); ++j) {
1808  key, j, res, exclusion_cb);
1809  }
1810  return;
1811  }
1812 
1813  for (i = ast_json_object_iter(obj); i;
1814  i = ast_json_object_iter_next(obj, i)) {
1817  key, res, exclusion_cb);
1818  }
1819 }
Iterator for JSON object key/values.
struct ast_json_iter * ast_json_object_iter(struct ast_json *object)
Get an iterator pointing to the first field in a JSON object.
Definition: json.c:429
struct ast_json * ast_json_object_iter_value(struct ast_json_iter *iter)
Get the value from an iterator.
Definition: json.c:445
static void manager_json_value_str_append(struct ast_json *value, const char *key, struct ast_str **res)
Definition: manager.c:1730
const char * ast_json_object_iter_key(struct ast_json_iter *iter)
Get the key from an iterator.
Definition: json.c:441
static void manager_json_array_with_key(struct ast_json *obj, const char *key, size_t index, struct ast_str **res, key_exclusion_cb exclusion_cb)
Definition: manager.c:1755
enum ast_json_type ast_json_typeof(const struct ast_json *value)
Get the type of value.
Definition: json.c:78
size_t ast_json_array_size(const struct ast_json *array)
Get the size of a JSON array.
Definition: json.c:356
static void manager_json_obj_with_key(struct ast_json *obj, const char *key, const char *parent_key, struct ast_str **res, key_exclusion_cb exclusion_cb)
Definition: manager.c:1765
struct ast_json * ast_json_array_get(const struct ast_json *array, size_t index)
Get an element from an array.
Definition: json.c:360
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620
struct ast_json_iter * ast_json_object_iter_next(struct ast_json *object, struct ast_json_iter *iter)
Get the next iterator.
Definition: json.c:437

◆ manager_json_value_str_append()

static void manager_json_value_str_append ( struct ast_json value,
const char *  key,
struct ast_str **  res 
)
static

Definition at line 1730 of file manager.c.

References AST_JSON_FALSE, AST_JSON_INTEGER, ast_json_integer_get(), AST_JSON_STRING, ast_json_string_get(), AST_JSON_TRUE, ast_json_typeof(), ast_str_append(), and manager_json_to_ast_str().

Referenced by manager_json_to_ast_str().

1732 {
1733  switch (ast_json_typeof(value)) {
1734  case AST_JSON_STRING:
1735  ast_str_append(res, 0, "%s: %s\r\n", key, ast_json_string_get(value));
1736  break;
1737  case AST_JSON_INTEGER:
1738  ast_str_append(res, 0, "%s: %jd\r\n", key, ast_json_integer_get(value));
1739  break;
1740  case AST_JSON_TRUE:
1741  ast_str_append(res, 0, "%s: True\r\n", key);
1742  break;
1743  case AST_JSON_FALSE:
1744  ast_str_append(res, 0, "%s: False\r\n", key);
1745  break;
1746  default:
1747  ast_str_append(res, 0, "%s: \r\n", key);
1748  break;
1749  }
1750 }
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_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
enum ast_json_type ast_json_typeof(const struct ast_json *value)
Get the type of value.
Definition: json.c:78
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
Definition: json.c:322

◆ manager_modulecheck()

static int manager_modulecheck ( struct mansession s,
const struct message m 
)
static

Manager function to check if module is loaded.

Definition at line 6470 of file manager.c.

References ast_copy_string(), ast_debug, ast_module_check(), ast_strlen_zero, astman_append(), astman_get_header(), astman_send_error(), and PATH_MAX.

Referenced by __init_manager().

6471 {
6472  int res;
6473  const char *module = astman_get_header(m, "Module");
6474  const char *id = astman_get_header(m, "ActionID");
6475  char idText[256];
6476  char filename[PATH_MAX];
6477  char *cut;
6478 
6479  ast_copy_string(filename, module, sizeof(filename));
6480  if ((cut = strchr(filename, '.'))) {
6481  *cut = '\0';
6482  } else {
6483  cut = filename + strlen(filename);
6484  }
6485  snprintf(cut, (sizeof(filename) - strlen(filename)) - 1, ".so");
6486  ast_debug(1, "**** ModuleCheck .so file %s\n", filename);
6487  res = ast_module_check(filename);
6488  if (!res) {
6489  astman_send_error(s, m, "Module not loaded");
6490  return 0;
6491  }
6492 
6493  if (!ast_strlen_zero(id)) {
6494  snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
6495  } else {
6496  idText[0] = '\0';
6497  }
6498  astman_append(s, "Response: Success\r\n%s", idText);
6499 #if !defined(LOW_MEMORY)
6500  astman_append(s, "Version: %s\r\n\r\n", "");
6501 #endif
6502  return 0;
6503 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
int ast_module_check(const char *name)
Check if module with the name given is loaded.
Definition: loader.c:2653
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
#define PATH_MAX
Definition: asterisk.h:40
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ manager_moduleload()

static int manager_moduleload ( struct mansession s,
const struct message m 
)
static

Definition at line 6505 of file manager.c.

References AST_FORCE_SOFT, ast_load_resource(), ast_module_reload(), AST_MODULE_RELOAD_ERROR, AST_MODULE_RELOAD_IN_PROGRESS, AST_MODULE_RELOAD_NOT_FOUND, AST_MODULE_RELOAD_NOT_IMPLEMENTED, AST_MODULE_RELOAD_QUEUED, AST_MODULE_RELOAD_SUCCESS, AST_MODULE_RELOAD_UNINITIALIZED, ast_strlen_zero, ast_unload_resource(), astman_get_header(), astman_send_ack(), astman_send_error(), and NULL.

Referenced by __init_manager().

6506 {
6507  int res;
6508  const char *module = astman_get_header(m, "Module");
6509  const char *loadtype = astman_get_header(m, "LoadType");
6510 
6511  if (!loadtype || strlen(loadtype) == 0) {
6512  astman_send_error(s, m, "Incomplete ModuleLoad action.");
6513  }
6514  if ((!module || strlen(module) == 0) && strcasecmp(loadtype, "reload") != 0) {
6515  astman_send_error(s, m, "Need module name");
6516  }
6517 
6518  if (!strcasecmp(loadtype, "load")) {
6519  res = ast_load_resource(module);
6520  if (res) {
6521  astman_send_error(s, m, "Could not load module.");
6522  } else {
6523  astman_send_ack(s, m, "Module loaded.");
6524  }
6525  } else if (!strcasecmp(loadtype, "unload")) {
6526  res = ast_unload_resource(module, AST_FORCE_SOFT);
6527  if (res) {
6528  astman_send_error(s, m, "Could not unload module.");
6529  } else {
6530  astman_send_ack(s, m, "Module unloaded.");
6531  }
6532  } else if (!strcasecmp(loadtype, "reload")) {
6533  /* TODO: Unify the ack/error messages here with action_reload */
6534  if (!ast_strlen_zero(module)) {
6535  enum ast_module_reload_result reload_res = ast_module_reload(module);
6536 
6537  switch (reload_res) {
6539  astman_send_error(s, m, "No such module.");
6540  break;
6542  astman_send_error(s, m, "Module does not support reload action.");
6543  break;
6545  astman_send_error(s, m, "An unknown error occurred");
6546  break;
6548  astman_send_error(s, m, "A reload is in progress");
6549  break;
6551  astman_send_error(s, m, "Module not initialized");
6552  break;
6555  /* Treat a queued request as success */
6556  astman_send_ack(s, m, "Module reloaded.");
6557  break;
6558  }
6559  } else {
6560  ast_module_reload(NULL); /* Reload all modules */
6561  astman_send_ack(s, m, "All modules reloaded");
6562  }
6563  } else
6564  astman_send_error(s, m, "Incomplete ModuleLoad action.");
6565  return 0;
6566 }
enum ast_module_load_result ast_load_resource(const char *resource_name)
Load a module.
Definition: loader.c:1819
enum ast_module_reload_result ast_module_reload(const char *name)
Reload asterisk modules.
Definition: loader.c:1562
ast_module_reload_result
Possible return types for ast_module_reload.
Definition: module.h:109
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
#define NULL
Definition: resample.c:96
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
int ast_unload_resource(const char *resource_name, enum ast_module_unload_mode)
Unload a module.
Definition: loader.c:1229
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ manager_state_cb()

static int manager_state_cb ( const char *  context,
const char *  exten,
struct ast_state_cb_info info,
void *  data 
)
static

Definition at line 7288 of file manager.c.

References ast_extension_state2str(), ast_get_hint(), AST_HINT_UPDATE_DEVICE, AST_HINT_UPDATE_PRESENCE, ast_presence_state2str(), EVENT_FLAG_CALL, ast_state_cb_info::exten_state, manager_event, NULL, ast_state_cb_info::presence_message, ast_state_cb_info::presence_state, ast_state_cb_info::presence_subtype, and ast_state_cb_info::reason.

Referenced by __init_manager().

7289 {
7290  /* Notify managers of change */
7291  char hint[512];
7292 
7293  hint[0] = '\0';
7294  ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, context, exten);
7295 
7296  switch(info->reason) {
7298  manager_event(EVENT_FLAG_CALL, "ExtensionStatus",
7299  "Exten: %s\r\n"
7300  "Context: %s\r\n"
7301  "Hint: %s\r\n"
7302  "Status: %d\r\n"
7303  "StatusText: %s\r\n",
7304  exten,
7305  context,
7306  hint,
7307  info->exten_state,
7309  break;
7311  manager_event(EVENT_FLAG_CALL, "PresenceStatus",
7312  "Exten: %s\r\n"
7313  "Context: %s\r\n"
7314  "Hint: %s\r\n"
7315  "Status: %s\r\n"
7316  "Subtype: %s\r\n"
7317  "Message: %s\r\n",
7318  exten,
7319  context,
7320  hint,
7322  info->presence_subtype,
7323  info->presence_message);
7324  break;
7325  }
7326  return 0;
7327 }
int ast_get_hint(char *hint, int hintsize, char *name, int namesize, struct ast_channel *c, const char *context, const char *exten)
If an extension hint exists, return non-zero.
Definition: pbx.c:4141
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
const char * presence_message
Definition: pbx.h:108
enum ast_state_cb_update_reason reason
Definition: pbx.h:103
#define EVENT_FLAG_CALL
Definition: manager.h:72
#define NULL
Definition: resample.c:96
enum ast_extension_states exten_state
Definition: pbx.h:104
enum ast_presence_state presence_state
Definition: pbx.h:106
const char * ast_extension_state2str(int extension_state)
Return string representation of the state of an extension.
Definition: pbx.c:3126
const char * presence_subtype
Definition: pbx.h:107
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:248
const char * ast_presence_state2str(enum ast_presence_state state)
Convert presence state to text string for output.

◆ mansession_cmp_fn()

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

Definition at line 2262 of file manager.c.

References CMP_MATCH, str, and mansession_session::username.

Referenced by __init_manager().

2263 {
2264  struct mansession_session *s = obj;
2265  char *str = arg;
2266  return !strcasecmp(s->username, str) ? CMP_MATCH : 0;
2267 }
char username[80]
Definition: manager.c:1592
const char * str
Definition: app_jack.c:147

◆ mansession_get_transport()

static enum ast_transport mansession_get_transport ( const struct mansession s)
static

◆ mansession_lock()

static void mansession_lock ( struct mansession s)
static

Lock the 'mansession' structure.

Definition at line 3251 of file manager.c.

References ast_mutex_lock, and mansession::lock.

Referenced by action_challenge(), do_message(), handle_parse_error(), and process_message().

3252 {
3253  ast_mutex_lock(&s->lock);
3254 }
#define ast_mutex_lock(a)
Definition: lock.h:187
ast_mutex_t lock
Definition: manager.c:1632

◆ mansession_unlock()

static void mansession_unlock ( struct mansession s)
static

Unlock the 'mansession' structure.

Definition at line 3257 of file manager.c.

References ast_mutex_unlock, and mansession::lock.

Referenced by action_challenge(), do_message(), handle_parse_error(), and process_message().

3258 {
3259  ast_mutex_unlock(&s->lock);
3260 }
ast_mutex_t lock
Definition: manager.c:1632
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ match_filter()

static int match_filter ( struct mansession s,
char *  eventdata 
)
static

Definition at line 6193 of file manager.c.

References ao2_container_count(), ao2_t_callback_data, ast_debug, ast_verbose(), blackfilter_cmp_fn(), mansession_session::blackfilters, manager_debug, OBJ_NODATA, result, mansession::session, whitefilter_cmp_fn(), and mansession_session::whitefilters.

Referenced by action_waitevent(), and process_events().

6194 {
6195  int result = 0;
6196 
6197  if (manager_debug) {
6198  ast_verbose("<-- Examining AMI event: -->\n%s\n", eventdata);
6199  } else {
6200  ast_debug(3, "Examining AMI event:\n%s\n", eventdata);
6201  }
6203  return 1; /* no filtering means match all */
6205  /* white filters only: implied black all filter processed first, then white filters */
6206  ao2_t_callback_data(s->session->whitefilters, OBJ_NODATA, whitefilter_cmp_fn, eventdata, &result, "find filter in session filter container");
6208  /* black filters only: implied white all filter processed first, then black filters */
6209  ao2_t_callback_data(s->session->blackfilters, OBJ_NODATA, blackfilter_cmp_fn, eventdata, &result, "find filter in session filter container");
6210  } else {
6211  /* white and black filters: implied black all filter processed first, then white filters, and lastly black filters */
6212  ao2_t_callback_data(s->session->whitefilters, OBJ_NODATA, whitefilter_cmp_fn, eventdata, &result, "find filter in session filter container");
6213  if (result) {
6214  result = 0;
6215  ao2_t_callback_data(s->session->blackfilters, OBJ_NODATA, blackfilter_cmp_fn, eventdata, &result, "find filter in session filter container");
6216  }
6217  }
6218 
6219  return result;
6220 }
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
void ast_verbose(const char *fmt,...)
Definition: extconf.c:2207
struct ao2_container * blackfilters
Definition: manager.c:1600
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
struct ao2_container * whitefilters
Definition: manager.c:1599
static int blackfilter_cmp_fn(void *obj, void *arg, void *data, int flags)
Definition: manager.c:6092
static int manager_debug
Definition: manager.c:1478
#define ao2_t_callback_data(container, flags, cb_fn, arg, data, tag)
ao2_callback_data() is a generic function that applies cb_fn() to all objects in a container...
Definition: astobj2.h:1741
static PGresult * result
Definition: cel_pgsql.c:88
static int whitefilter_cmp_fn(void *obj, void *arg, void *data, int flags)
Definition: manager.c:6078
struct mansession_session * session
Definition: manager.c:1626

◆ print_event_instance()

static void print_event_instance ( struct ast_cli_args a,
struct ast_xml_doc_item instance 
)
static

Definition at line 8793 of file manager.c.

References ast_xml_doc_item::arguments, ast_cli(), ast_free, ast_str_buffer(), ast_strlen_zero, ast_xmldoc_printable(), COLOR_MAGENTA, ast_xml_doc_item::description, ast_cli_args::fd, ast_xml_doc_item::seealso, synopsis, ast_xml_doc_item::synopsis, ast_xml_doc_item::syntax, and term_color().

Referenced by handle_manager_show_event(), handle_showmancmd(), and manager_displayconnects().

8795 {
8796  char syntax_title[64], description_title[64], synopsis_title[64], seealso_title[64], arguments_title[64];
8797 
8798  term_color(synopsis_title, "[Synopsis]\n", COLOR_MAGENTA, 0, 40);
8799  term_color(description_title, "[Description]\n", COLOR_MAGENTA, 0, 40);
8800  term_color(syntax_title, "[Syntax]\n", COLOR_MAGENTA, 0, 40);
8801  term_color(seealso_title, "[See Also]\n", COLOR_MAGENTA, 0, 40);
8802  term_color(arguments_title, "[Arguments]\n", COLOR_MAGENTA, 0, 40);
8803 
8804  if (!ast_strlen_zero(ast_str_buffer(instance->synopsis))) {
8805  char *synopsis = ast_xmldoc_printable(ast_str_buffer(instance->synopsis), 1);
8806  ast_cli(a->fd, "%s%s\n\n", synopsis_title, synopsis);
8807  ast_free(synopsis);
8808  }
8809  if (!ast_strlen_zero(ast_str_buffer(instance->syntax))) {
8810  char *syntax = ast_xmldoc_printable(ast_str_buffer(instance->syntax), 1);
8811  ast_cli(a->fd, "%s%s\n\n", syntax_title, syntax);
8812  ast_free(syntax);
8813  }
8814  if (!ast_strlen_zero(ast_str_buffer(instance->description))) {
8815  char *description = ast_xmldoc_printable(ast_str_buffer(instance->description), 1);
8816  ast_cli(a->fd, "%s%s\n\n", description_title, description);
8817  ast_free(description);
8818  }
8819  if (!ast_strlen_zero(ast_str_buffer(instance->arguments))) {
8820  char *arguments = ast_xmldoc_printable(ast_str_buffer(instance->arguments), 1);
8821  ast_cli(a->fd, "%s%s\n\n", arguments_title, arguments);
8822  ast_free(arguments);
8823  }
8824  if (!ast_strlen_zero(ast_str_buffer(instance->seealso))) {
8825  char *seealso = ast_xmldoc_printable(ast_str_buffer(instance->seealso), 1);
8826  ast_cli(a->fd, "%s%s\n\n", seealso_title, seealso);
8827  ast_free(seealso);
8828  }
static const char synopsis[]
Definition: app_mysql.c:64
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
#define ast_strlen_zero(foo)
Definition: strings.h:52
const int fd
Definition: cli.h:159
struct ast_str * description
Definition: xmldoc.h:66
char * term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
Colorize a specified string by adding terminal color codes.
Definition: term.c:184
#define ast_free(a)
Definition: astmm.h:182
char * ast_xmldoc_printable(const char *bwinput, int withcolors)
Colorize and put delimiters (instead of tags) to the xmldoc output.
Definition: xmldoc.c:242
struct ast_str * arguments
Definition: xmldoc.h:62
struct ast_str * syntax
Definition: xmldoc.h:58
struct ast_str * seealso
Definition: xmldoc.h:60
#define COLOR_MAGENTA
Definition: term.h:57
struct ast_str * synopsis
Definition: xmldoc.h:64

◆ process_events()

static int process_events ( struct mansession s)
static

Send any applicable events to the client listening on this socket. Wait only for a finite time on each event, and drop all events whether they are successfully sent or not.

Definition at line 6227 of file manager.c.

References advance_event(), ao2_lock, ao2_unlock, ast_debug, mansession_session::authenticated, eventqent::category, EVENT_FLAG_SHUTDOWN, mansession_session::last_ev, match_filter(), NULL, mansession_session::readperm, mansession_session::send_events, send_string(), mansession::session, and mansession_session::stream.

Referenced by do_message(), and process_message().

6228 {
6229  int ret = 0;
6230 
6231  ao2_lock(s->session);
6232  if (s->session->stream != NULL) {
6233  struct eventqent *eqe = s->session->last_ev;
6234 
6235  while ((eqe = advance_event(eqe))) {
6236  if (eqe->category == EVENT_FLAG_SHUTDOWN) {
6237  ast_debug(3, "Received CloseSession event\n");
6238  ret = -1;
6239  }
6240  if (!ret && s->session->authenticated &&
6241  (s->session->readperm & eqe->category) == eqe->category &&
6242  (s->session->send_events & eqe->category) == eqe->category) {
6243  if (match_filter(s, eqe->eventdata)) {
6244  if (send_string(s, eqe->eventdata) < 0)
6245  ret = -1; /* don't send more */
6246  }
6247  }
6248  s->session->last_ev = eqe;
6249  }
6250  }
6251  ao2_unlock(s->session);
6252  return ret;
6253 }
struct eventqent * last_ev
Definition: manager.c:1603
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ao2_lock(a)
Definition: astobj2.h:718
static struct eventqent * advance_event(struct eventqent *e)
Definition: manager.c:2753
static int match_filter(struct mansession *s, char *eventdata)
Definition: manager.c:6193
struct ast_iostream * stream
Definition: manager.c:1584
static int send_string(struct mansession *s, char *string)
Definition: manager.c:3025
int category
Definition: manager.c:1461
#define EVENT_FLAG_SHUTDOWN
Fake event class used to end sessions at shutdown.
Definition: manager.c:1511
struct mansession_session * session
Definition: manager.c:1626

◆ process_message()

static int process_message ( struct mansession s,
const struct message m 
)
static

Process an AMI message, performing desired action. Return 0 on success, -1 on error that require the session to be destroyed.

Definition at line 6607 of file manager.c.

References __astman_get_header(), manager_action::action, action_find(), ast_manager_user::allowmultiplelogin, ao2_lock, ao2_t_ref, ao2_unlock, ast_debug, ast_log, ast_module_running_ref, ast_module_unref, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_shutting_down(), ast_strlen_zero, astman_get_header(), astman_send_error(), mansession_session::authenticated, manager_action::authority, buf, check_manager_session_inuse(), manager_action::func, GET_HEADER_SKIP_EMPTY, get_manager_by_name_locked(), log_action(), LOG_ERROR, mansession_lock(), mansession_unlock(), manager_action::module, NULL, process_events(), manager_action::registered, report_req_bad_format(), report_req_not_allowed(), report_session_limit(), mansession::session, and mansession_session::writeperm.

Referenced by auth_http_callback(), do_message(), and generic_http_callback().

6608 {
6609  int ret = 0;
6610  struct manager_action *act_found;
6611  struct ast_manager_user *user = NULL;
6612  const char *username;
6613  const char *action;
6614 
6615  action = __astman_get_header(m, "Action", GET_HEADER_SKIP_EMPTY);
6616  if (ast_strlen_zero(action)) {
6617  report_req_bad_format(s, "NONE");
6618  mansession_lock(s);
6619  astman_send_error(s, m, "Missing action in request");
6620  mansession_unlock(s);
6621  return 0;
6622  }
6623 
6624  log_action(m, action);
6625 
6626  if (ast_shutting_down()) {
6627  ast_log(LOG_ERROR, "Unable to process manager action '%s'. Asterisk is shutting down.\n", action);
6628  mansession_lock(s);
6629  astman_send_error(s, m, "Asterisk is shutting down");
6630  mansession_unlock(s);
6631  return 0;
6632  }
6633 
6634  if (!s->session->authenticated
6635  && strcasecmp(action, "Login")
6636  && strcasecmp(action, "Logoff")
6637  && strcasecmp(action, "Challenge")) {
6638  if (!s->session->authenticated) {
6639  report_req_not_allowed(s, action);
6640  }
6641  mansession_lock(s);
6642  astman_send_error(s, m, "Permission denied");
6643  mansession_unlock(s);
6644  return 0;
6645  }
6646 
6647  if (!s->session->authenticated
6648  && (!strcasecmp(action, "Login")
6649  || !strcasecmp(action, "Challenge"))) {
6650  username = astman_get_header(m, "Username");
6651 
6652  if (!ast_strlen_zero(username) && check_manager_session_inuse(username)) {
6654  user = get_manager_by_name_locked(username);
6655  if (user && !user->allowmultiplelogin) {
6658  sleep(1);
6659  mansession_lock(s);
6660  astman_send_error(s, m, "Login Already In Use");
6661  mansession_unlock(s);
6662  return -1;
6663  }
6665  }
6666  }
6667 
6668  act_found = action_find(action);
6669  if (act_found) {
6670  /* Found the requested AMI action. */
6671  int acted = 0;
6672 
6673  if ((s->session->writeperm & act_found->authority)
6674  || act_found->authority == 0) {
6675  /* We have the authority to execute the action. */
6676  ret = -1;
6677  ao2_lock(act_found);
6678  if (act_found->registered && act_found->func) {
6679  struct ast_module *mod_ref = ast_module_running_ref(act_found->module);
6680 
6681  ao2_unlock(act_found);
6682  if (mod_ref || !act_found->module) {
6683  ast_debug(1, "Running action '%s'\n", act_found->action);
6684  ret = act_found->func(s, m);
6685  acted = 1;
6686  ast_module_unref(mod_ref);
6687  }
6688  } else {
6689  ao2_unlock(act_found);
6690  }
6691  }
6692  if (!acted) {
6693  /*
6694  * We did not execute the action because access was denied, it
6695  * was no longer registered, or no action was really registered.
6696  * Complain about it and leave.
6697  */
6698  report_req_not_allowed(s, action);
6699  mansession_lock(s);
6700  astman_send_error(s, m, "Permission denied");
6701  mansession_unlock(s);
6702  }
6703  ao2_t_ref(act_found, -1, "done with found action object");
6704  } else {
6705  char buf[512];
6706 
6707  report_req_bad_format(s, action);
6708  snprintf(buf, sizeof(buf), "Invalid/unknown command: %s. Use Action: ListCommands to show available commands.", action);
6709  mansession_lock(s);
6710  astman_send_error(s, m, buf);
6711  mansession_unlock(s);
6712  }
6713  if (ret) {
6714  return ret;
6715  }
6716  /* Once done with our message, deliver any pending events unless the
6717  requester doesn't want them as part of this response.
6718  */
6719  if (ast_strlen_zero(astman_get_header(m, "SuppressEvents"))) {
6720  return process_events(s);
6721  } else {
6722  return ret;
6723  }
6724 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
char username[80]
Definition: manager.c:1645
static const char * __astman_get_header(const struct message *m, char *var, int mode)
Return a matching header value.
Definition: manager.c:2783
int ast_shutting_down(void)
Definition: asterisk.c:1834
static void mansession_unlock(struct mansession *s)
Unlock the &#39;mansession&#39; structure.
Definition: manager.c:3257
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
static struct ast_manager_user * get_manager_by_name_locked(const char *name)
Definition: manager.c:2305
int(* func)(struct mansession *s, const struct message *m)
Definition: manager.h:166
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
const char * action
Definition: manager.h:151
static void report_req_not_allowed(const struct mansession *s, const char *action)
Definition: manager.c:3385
static void report_session_limit(const struct mansession *s)
Definition: manager.c:3473
static int process_events(struct mansession *s)
Definition: manager.c:6227
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
user descriptor, as read from the config file.
Definition: manager.c:1644
list of users found in the config file
static struct manager_action * action_find(const char *name)
Definition: manager.c:1704
struct ast_module * module
Definition: manager.h:167
const char * astman_get_header(const struct message *m, char *var)
Return the first matching variable from an array.
Definition: manager.c:2820
#define ast_module_unref(mod)
Release a reference to the module.
Definition: module.h:469
#define ast_strlen_zero(foo)
Definition: strings.h:52
static int check_manager_session_inuse(const char *name)
Definition: manager.c:2282
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
unsigned int registered
TRUE if the AMI action is registered and the callback can be called.
Definition: manager.h:178
#define GET_HEADER_SKIP_EMPTY
Definition: manager.c:2768
#define ao2_lock(a)
Definition: astobj2.h:718
static void log_action(const struct message *m, const char *action)
Definition: manager.c:6568
#define LOG_ERROR
Definition: logger.h:285
int allowmultiplelogin
Definition: manager.c:1651
structure to hold users read from users.conf
#define ast_module_running_ref(mod)
Hold a reference to the module if it is running.
Definition: module.h:455
static void mansession_lock(struct mansession *s)
Lock the &#39;mansession&#39; structure.
Definition: manager.c:3251
struct mansession_session * session
Definition: manager.c:1626
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
static void report_req_bad_format(const struct mansession *s, const char *action)
Definition: manager.c:3414

◆ purge_events()

static void purge_events ( void  )
static

Purge unused events. Remove elements from the head as long as their usecount is 0 and there is a next element.

Definition at line 1983 of file manager.c.

References ast_free, AST_RWLIST_FIRST, AST_RWLIST_NEXT, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_REMOVE_HEAD, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_tvdiff_sec(), ast_tvnow(), httptimeout, eventqent::tv, and eventqent::usecount.

Referenced by purge_old_stuff().

1984 {
1985  struct eventqent *ev;
1986  struct timeval now = ast_tvnow();
1987 
1989  while ( (ev = AST_RWLIST_FIRST(&all_events)) &&
1990  ev->usecount == 0 && AST_RWLIST_NEXT(ev, eq_next)) {
1992  ast_free(ev);
1993  }
1994 
1996  /* Never release the last event */
1997  if (!AST_RWLIST_NEXT(ev, eq_next)) {
1998  break;
1999  }
2000 
2001  /* 2.5 times whatever the HTTP timeout is (maximum 2.5 hours) is the maximum time that we will definitely cache an event */
2002  if (ev->usecount == 0 && ast_tvdiff_sec(now, ev->tv) > (httptimeout > 3600 ? 3600 : httptimeout) * 2.5) {
2003  AST_RWLIST_REMOVE_CURRENT(eq_next);
2004  ast_free(ev);
2005  }
2006  }
2009 }
struct timeval tv
Definition: manager.c:1463
#define AST_RWLIST_NEXT
Definition: linkedlists.h:440
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
int64_t ast_tvdiff_sec(struct timeval end, struct timeval start)
Computes the difference (in seconds) between two struct timeval instances.
Definition: time.h:64
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
static int httptimeout
Definition: manager.c:1473
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:569
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
int usecount
Definition: manager.c:1460
#define ast_free(a)
Definition: astmm.h:182
#define AST_RWLIST_REMOVE_HEAD
Definition: linkedlists.h:843
#define AST_RWLIST_FIRST
Definition: linkedlists.h:422
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616

◆ purge_sessions()

static void purge_sessions ( int  n_max)
static

remove at most n_max stale session from the list.

Definition at line 7031 of file manager.c.

References mansession_session::addr, ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, ast_sockaddr_stringify_addr(), ast_verb, mansession_session::authenticated, mansession_session::inuse, manager_displayconnects(), NULL, session, session_destroy(), sessions, mansession_session::sessiontimeout, unref_mansession(), mansession_session::username, and VERBOSITY_ATLEAST.

Referenced by purge_old_stuff().

7032 {
7033  struct ao2_container *sessions;
7034  struct mansession_session *session;
7035  time_t now = time(NULL);
7036  struct ao2_iterator i;
7037 
7038  sessions = ao2_global_obj_ref(mgr_sessions);
7039  if (!sessions) {
7040  return;
7041  }
7042  i = ao2_iterator_init(sessions, 0);
7043  ao2_ref(sessions, -1);
7044  while ((session = ao2_iterator_next(&i)) && n_max > 0) {
7045  ao2_lock(session);
7046  if (session->sessiontimeout && (now > session->sessiontimeout) && !session->inuse) {
7047  if (session->authenticated
7048  && VERBOSITY_ATLEAST(2)
7049  && manager_displayconnects(session)) {
7050  ast_verb(2, "HTTP Manager '%s' timed out from %s\n",
7051  session->username, ast_sockaddr_stringify_addr(&session->addr));
7052  }
7053  ao2_unlock(session);
7054  session_destroy(session);
7055  n_max--;
7056  } else {
7057  ao2_unlock(session);
7058  unref_mansession(session);
7059  }
7060  }
7062 }
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition: netsock2.h:290
char username[80]
Definition: manager.c:1592
static struct sessions sessions
#define VERBOSITY_ATLEAST(level)
Definition: logger.h:461
#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
struct ast_sockaddr addr
Definition: manager.c:1583
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
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
time_t sessiontimeout
Definition: manager.c:1591
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
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 void session_destroy(struct mansession_session *s)
Definition: manager.c:2269
Generic container type.
static int manager_displayconnects(struct mansession_session *session)
Get displayconnects config option.
Definition: manager.c:2322
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.

◆ queue_read_action_payload()

static int queue_read_action_payload ( struct ast_channel chan,
const unsigned char *  payload,
size_t  payload_size,
enum ast_frame_read_action  action 
)
static

Queue a given read action containing a payload onto a channel.

This queues a READ_ACTION control frame that contains a given "payload", or data to be triggered and handled on the channel's read side. This ensures the "action" is handled by the channel's media reading thread.

Parameters
chanThe channel to queue the action on
payloadThe read action's payload
payload_sizeThe size of the given payload
actionThe type of read action to queue
Returns
-1 on error, 0 on success

Definition at line 4864 of file manager.c.

References AST_CONTROL_READ_ACTION, ast_free, ast_malloc, and ast_queue_control_data().

Referenced by queue_sendtext(), and queue_sendtext_data().

4866 {
4867  struct ast_control_read_action_payload *obj;
4868  size_t obj_size;
4869  int res;
4870 
4871  obj_size = payload_size + sizeof(*obj);
4872 
4873  obj = ast_malloc(obj_size);
4874  if (!obj) {
4875  return -1;
4876  }
4877 
4878  obj->action = action;
4879  obj->payload_size = payload_size;
4880  memcpy(obj->payload, payload, payload_size);
4881 
4882  res = ast_queue_control_data(chan, AST_CONTROL_READ_ACTION, obj, obj_size);
4883 
4884  ast_free(obj);
4885  return res;
4886 }
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
enum ast_frame_read_action action
#define ast_free(a)
Definition: astmm.h:182
int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control, const void *data, size_t datalen)
Queue a control frame with payload.
Definition: channel.c:1238

◆ queue_sendtext()

static int queue_sendtext ( struct ast_channel chan,
const char *  body 
)
static

Queue a read action to send a text message.

Parameters
chanThe channel to queue the action on
bodyThe body of the message
Returns
-1 on error, 0 on success

Definition at line 4896 of file manager.c.

References AST_FRAME_READ_ACTION_SEND_TEXT, and queue_read_action_payload().

Referenced by action_sendtext().

4897 {
4898  return queue_read_action_payload(chan, (const unsigned char *)body,
4899  strlen(body) + 1, AST_FRAME_READ_ACTION_SEND_TEXT);
4900 }
static int queue_read_action_payload(struct ast_channel *chan, const unsigned char *payload, size_t payload_size, enum ast_frame_read_action action)
Queue a given read action containing a payload onto a channel.
Definition: manager.c:4864

◆ queue_sendtext_data()

static int queue_sendtext_data ( struct ast_channel chan,
const char *  body,
const char *  content_type 
)
static

Queue a read action to send a text data message.

Parameters
chanThe channel to queue the action on
bodyThe body of the message
content_typeThe message's content type
Returns
-1 on error, 0 on success

Definition at line 4911 of file manager.c.

References AST_FRAME_READ_ACTION_SEND_TEXT_DATA, ast_free, ast_msg_data_alloc2(), ast_msg_data_get_length(), AST_MSG_DATA_SOURCE_TYPE_UNKNOWN, NULL, and queue_read_action_payload().

Referenced by action_sendtext().

4913 {
4914  int res;
4915  struct ast_msg_data *obj;
4916 
4918  NULL, NULL, content_type, body);
4919  if (!obj) {
4920  return -1;
4921  }
4922 
4923  res = queue_read_action_payload(chan, (const unsigned char *)obj,
4925 
4926  ast_free(obj);
4927  return res;
4928 }
size_t ast_msg_data_get_length(struct ast_msg_data *msg)
Get length of the structure.
Definition: message.c:1513
Structure used to transport a message through the frame core.
Definition: message.c:1406
#define NULL
Definition: resample.c:96
static int queue_read_action_payload(struct ast_channel *chan, const unsigned char *payload, size_t payload_size, enum ast_frame_read_action action)
Queue a given read action containing a payload onto a channel.
Definition: manager.c:4864
#define ast_free(a)
Definition: astmm.h:182
struct ast_msg_data * ast_msg_data_alloc2(enum ast_msg_data_source_type source_type, const char *to, const char *from, const char *content_type, const char *body)
Allocates an ast_msg_data structure.
Definition: message.c:1469

◆ reload_module()

static int reload_module ( void  )
static

Definition at line 9661 of file manager.c.

References __init_manager().

Referenced by handle_manager_reload(), and handle_showmaneventq().

9663 {
9664  return __init_manager(1, 0);
static int __init_manager(int reload, int by_external_config)
Definition: manager.c:9144

◆ report_auth_success()

static void report_auth_success ( const struct mansession s)
static

Definition at line 3360 of file manager.c.

References mansession_session::addr, AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_SUCCESSFUL_AUTH, AST_SECURITY_EVENT_SUCCESSFUL_AUTH_VERSION, ast_security_event_successful_auth::common, ast_security_event_common::event_type, ast_tcptls_session_args::local_address, mansession_get_transport(), ast_tcptls_session_instance::parent, mansession::session, mansession_session::sessionstart_tv, mansession::tcptls_session, and mansession_session::username.

Referenced by authenticate().

3361 {
3362  char session_id[32];
3363  struct ast_security_event_successful_auth successful_auth = {
3366  .common.service = "AMI",
3367  .common.account_id = s->session->username,
3368  .common.session_tv = &s->session->sessionstart_tv,
3369  .common.local_addr = {
3370  .addr = &s->tcptls_session->parent->local_address,
3371  .transport = mansession_get_transport(s),
3372  },
3373  .common.remote_addr = {
3374  .addr = &s->session->addr,
3375  .transport = mansession_get_transport(s),
3376  },
3377  .common.session_id = session_id,
3378  };
3379 
3380  snprintf(session_id, sizeof(session_id), "%p", s->session);
3381 
3382  ast_security_event_report(AST_SEC_EVT(&successful_auth));
3383 }
enum ast_security_event_type event_type
The security event sub-type.
FYI FWIW, Successful authentication has occurred.
char username[80]
Definition: manager.c:1592
static enum ast_transport mansession_get_transport(const struct mansession *s)
Definition: manager.c:3279
struct ast_tcptls_session_args * parent
Definition: tcptls.h:152
struct ast_sockaddr addr
Definition: manager.c:1583
#define AST_SECURITY_EVENT_SUCCESSFUL_AUTH_VERSION
Event descriptor version.
#define AST_SEC_EVT(e)
struct timeval sessionstart_tv
Definition: manager.c:1590
struct ast_tcptls_session_instance * tcptls_session
Definition: manager.c:1628
struct ast_security_event_common common
Common security event descriptor elements.
struct mansession_session * session
Definition: manager.c:1626
struct ast_sockaddr local_address
Definition: tcptls.h:130
int ast_security_event_report(const struct ast_security_event_common *sec)
Report a security event.

◆ report_failed_acl()

static void report_failed_acl ( const struct mansession s,
const char *  username 
)
static

Definition at line 3310 of file manager.c.

References mansession_session::addr, AST_SEC_EVT, AST_SECURITY_EVENT_FAILED_ACL, AST_SECURITY_EVENT_FAILED_ACL_VERSION, ast_security_event_report(), ast_security_event_failed_acl::common, ast_security_event_common::event_type, ast_tcptls_session_args::local_address, mansession_get_transport(), ast_tcptls_session_instance::parent, mansession::session, mansession_session::sessionstart_tv, and mansession::tcptls_session.

Referenced by authenticate().

3311 {
3312  char session_id[32];
3313  struct ast_security_event_failed_acl failed_acl_event = {
3315  .common.version = AST_SECURITY_EVENT_FAILED_ACL_VERSION,
3316  .common.service = "AMI",
3317  .common.account_id = username,
3318  .common.session_tv = &s->session->sessionstart_tv,
3319  .common.local_addr = {
3320  .addr = &s->tcptls_session->parent->local_address,
3321  .transport = mansession_get_transport(s),
3322  },
3323  .common.remote_addr = {
3324  .addr = &s->session->addr,
3325  .transport = mansession_get_transport(s),
3326  },
3327  .common.session_id = session_id,
3328  };
3329 
3330  snprintf(session_id, sizeof(session_id), "%p", s->session);
3331 
3332  ast_security_event_report(AST_SEC_EVT(&failed_acl_event));
3333 }
enum ast_security_event_type event_type
The security event sub-type.
static enum ast_transport mansession_get_transport(const struct mansession *s)
Definition: manager.c:3279
struct ast_tcptls_session_args * parent
Definition: tcptls.h:152
Checking against an IP access control list failed.
struct ast_sockaddr addr
Definition: manager.c:1583
#define AST_SEC_EVT(e)
#define AST_SECURITY_EVENT_FAILED_ACL_VERSION
Event descriptor version.
struct timeval sessionstart_tv
Definition: manager.c:1590
struct ast_security_event_common common
Common security event descriptor elements.
struct ast_tcptls_session_instance * tcptls_session
Definition: manager.c:1628
struct mansession_session * session
Definition: manager.c:1626
struct ast_sockaddr local_address
Definition: tcptls.h:130
int ast_security_event_report(const struct ast_security_event_common *sec)
Report a security event.

◆ report_failed_challenge_response()

static void report_failed_challenge_response ( const struct mansession s,
const char *  response,
const char *  expected_response 
)
static

Definition at line 3443 of file manager.c.

References mansession_session::addr, AST_SEC_EVT, AST_SECURITY_EVENT_CHAL_RESP_FAILED, AST_SECURITY_EVENT_CHAL_RESP_FAILED_VERSION, ast_security_event_report(), mansession_session::challenge, ast_security_event_chal_resp_failed::common, ast_security_event_common::event_type, ast_security_event_chal_resp_failed::expected_response, ast_tcptls_session_args::local_address, mansession_get_transport(), ast_tcptls_session_instance::parent, ast_security_event_chal_resp_failed::response, mansession::session, mansession_session::sessionstart_tv, mansession::tcptls_session, and mansession_session::username.

Referenced by authenticate().

3445 {
3446  char session_id[32];
3447  struct ast_security_event_chal_resp_failed chal_resp_failed = {
3450  .common.service = "AMI",
3451  .common.account_id = s->session->username,
3452  .common.session_tv = &s->session->sessionstart_tv,
3453  .common.local_addr = {
3454  .addr = &s->tcptls_session->parent->local_address,
3455  .transport = mansession_get_transport(s),
3456  },
3457  .common.remote_addr = {
3458  .addr = &s->session->addr,
3459  .transport = mansession_get_transport(s),
3460  },
3461  .common.session_id = session_id,
3462 
3463  .challenge = s->session->challenge,
3464  .response = response,
3465  .expected_response = expected_response,
3466  };
3467 
3468  snprintf(session_id, sizeof(session_id), "%p", s->session);
3469 
3470  ast_security_event_report(AST_SEC_EVT(&chal_resp_failed));
3471 }
enum ast_security_event_type event_type
The security event sub-type.
char username[80]
Definition: manager.c:1592
const char * expected_response
Response expected to be received.
static enum ast_transport mansession_get_transport(const struct mansession *s)
Definition: manager.c:3279
An attempt at challenge/response auth failed.
struct ast_tcptls_session_args * parent
Definition: tcptls.h:152
const char * response
Response received.
struct ast_security_event_common common
Common security event descriptor elements.
struct ast_sockaddr addr
Definition: manager.c:1583
#define AST_SEC_EVT(e)
struct timeval sessionstart_tv
Definition: manager.c:1590
struct ast_tcptls_session_instance * tcptls_session
Definition: manager.c:1628
An attempt at challenge/response authentication failed.
char challenge[10]
Definition: manager.c:1593
struct mansession_session * session
Definition: manager.c:1626
#define AST_SECURITY_EVENT_CHAL_RESP_FAILED_VERSION
Event descriptor version.
struct ast_sockaddr local_address
Definition: tcptls.h:130
int ast_security_event_report(const struct ast_security_event_common *sec)
Report a security event.

◆ report_inval_password()

static void report_inval_password ( const struct mansession s,
const char *  username 
)
static

Definition at line 3335 of file manager.c.

References mansession_session::addr, AST_SEC_EVT, AST_SECURITY_EVENT_INVAL_PASSWORD, AST_SECURITY_EVENT_INVAL_PASSWORD_VERSION, ast_security_event_report(), ast_security_event_inval_password::common, ast_security_event_common::event_type, ast_tcptls_session_args::local_address, mansession_get_transport(), ast_tcptls_session_instance::parent, mansession::session, mansession_session::sessionstart_tv, and mansession::tcptls_session.

Referenced by authenticate().

3336 {
3337  char session_id[32];
3338  struct ast_security_event_inval_password inval_password = {
3341  .common.service = "AMI",
3342  .common.account_id = username,
3343  .common.session_tv = &s->session->sessionstart_tv,
3344  .common.local_addr = {
3345  .addr = &s->tcptls_session->parent->local_address,
3346  .transport = mansession_get_transport(s),
3347  },
3348  .common.remote_addr = {
3349  .addr = &s->session->addr,
3350  .transport = mansession_get_transport(s),
3351  },
3352  .common.session_id = session_id,
3353  };
3354 
3355  snprintf(session_id, sizeof(session_id), "%p", s->session);
3356 
3357  ast_security_event_report(AST_SEC_EVT(&inval_password));
3358 }
An attempt at basic password authentication failed.
enum ast_security_event_type event_type
The security event sub-type.
static enum ast_transport mansession_get_transport(const struct mansession *s)
Definition: manager.c:3279
struct ast_tcptls_session_args * parent
Definition: tcptls.h:152
struct ast_sockaddr addr
Definition: manager.c:1583
#define AST_SEC_EVT(e)
An attempt at basic password auth failed.
struct ast_security_event_common common
Common security event descriptor elements.
struct timeval sessionstart_tv
Definition: manager.c:1590
struct ast_tcptls_session_instance * tcptls_session
Definition: manager.c:1628
#define AST_SECURITY_EVENT_INVAL_PASSWORD_VERSION
Event descriptor version.
struct mansession_session * session
Definition: manager.c:1626
struct ast_sockaddr local_address
Definition: tcptls.h:130
int ast_security_event_report(const struct ast_security_event_common *sec)
Report a security event.

◆ report_invalid_user()

static void report_invalid_user ( const struct mansession s,
const char *  username 
)
static

Definition at line 3285 of file manager.c.

References mansession_session::addr, AST_SEC_EVT, AST_SECURITY_EVENT_INVAL_ACCT_ID, AST_SECURITY_EVENT_INVAL_ACCT_ID_VERSION, ast_security_event_report(), ast_security_event_inval_acct_id::common, ast_security_event_common::event_type, ast_tcptls_session_args::local_address, mansession_get_transport(), ast_tcptls_session_instance::parent, mansession::session, mansession_session::sessionstart_tv, and mansession::tcptls_session.

Referenced by authenticate().

3286 {
3287  char session_id[32];
3288  struct ast_security_event_inval_acct_id inval_acct_id = {
3290  .common.version = AST_SECURITY_EVENT_INVAL_ACCT_ID_VERSION,
3291  .common.service = "AMI",
3292  .common.account_id = username,
3293  .common.session_tv = &s->session->sessionstart_tv,
3294  .common.local_addr = {
3295  .addr = &s->tcptls_session->parent->local_address,
3296  .transport = mansession_get_transport(s),
3297  },
3298  .common.remote_addr = {
3299  .addr = &s->session->addr,
3300  .transport = mansession_get_transport(s),
3301  },
3302  .common.session_id = session_id,
3303  };
3304 
3305  snprintf(session_id, sizeof(session_id), "%p", s);
3306 
3307  ast_security_event_report(AST_SEC_EVT(&inval_acct_id));
3308 }
enum ast_security_event_type event_type
The security event sub-type.
static enum ast_transport mansession_get_transport(const struct mansession *s)
Definition: manager.c:3279
struct ast_tcptls_session_args * parent
Definition: tcptls.h:152
struct ast_security_event_common common
Common security event descriptor elements.
struct ast_sockaddr addr
Definition: manager.c:1583
#define AST_SEC_EVT(e)
struct timeval sessionstart_tv
Definition: manager.c:1590
#define AST_SECURITY_EVENT_INVAL_ACCT_ID_VERSION
Event descriptor version.
struct ast_tcptls_session_instance * tcptls_session
Definition: manager.c:1628
Invalid account ID specified (invalid username, for example)
struct mansession_session * session
Definition: manager.c:1626
struct ast_sockaddr local_address
Definition: tcptls.h:130
int ast_security_event_report(const struct ast_security_event_common *sec)
Report a security event.

◆ report_req_bad_format()

static void report_req_bad_format ( const struct mansession s,
const char *  action 
)
static

Definition at line 3414 of file manager.c.

References mansession_session::addr, AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_REQ_BAD_FORMAT, AST_SECURITY_EVENT_REQ_BAD_FORMAT_VERSION, ast_security_event_req_bad_format::common, ast_security_event_common::event_type, ast_tcptls_session_args::local_address, mansession_get_transport(), ast_tcptls_session_instance::parent, ast_security_event_req_not_allowed::request_type, ast_security_event_req_bad_format::request_type, mansession::session, mansession_session::sessionstart_tv, mansession::tcptls_session, and mansession_session::username.

Referenced by process_message().

3415 {
3416  char session_id[32];
3417  char request_type[64];
3418  struct ast_security_event_req_bad_format req_bad_format = {
3421  .common.service = "AMI",
3422  .common.account_id = s->session->username,
3423  .common.session_tv = &s->session->sessionstart_tv,
3424  .common.local_addr = {
3425  .addr = &s->tcptls_session->parent->local_address,
3426  .transport = mansession_get_transport(s),
3427  },
3428  .common.remote_addr = {
3429  .addr = &s->session->addr,
3430  .transport = mansession_get_transport(s),
3431  },
3432  .common.session_id = session_id,
3433 
3434  .request_type = request_type,
3435  };
3436 
3437  snprintf(session_id, sizeof(session_id), "%p", s->session);
3438  snprintf(request_type, sizeof(request_type), "Action: %s", action);
3439 
3440  ast_security_event_report(AST_SEC_EVT(&req_bad_format));
3441 }
enum ast_security_event_type event_type
The security event sub-type.
char username[80]
Definition: manager.c:1592
static enum ast_transport mansession_get_transport(const struct mansession *s)
Definition: manager.c:3279
struct ast_tcptls_session_args * parent
Definition: tcptls.h:152
struct ast_sockaddr addr
Definition: manager.c:1583
struct ast_security_event_common common
Common security event descriptor elements.
#define AST_SEC_EVT(e)
const char * request_type
Request type that was made.
Request received with bad formatting.
struct timeval sessionstart_tv
Definition: manager.c:1590
struct ast_tcptls_session_instance * tcptls_session
Definition: manager.c:1628
#define AST_SECURITY_EVENT_REQ_BAD_FORMAT_VERSION
Event descriptor version.
struct mansession_session * session
Definition: manager.c:1626
Invalid formatting of request.
struct ast_sockaddr local_address
Definition: tcptls.h:130
int ast_security_event_report(const struct ast_security_event_common *sec)
Report a security event.

◆ report_req_not_allowed()

static void report_req_not_allowed ( const struct mansession s,
const char *  action 
)
static

Definition at line 3385 of file manager.c.

References mansession_session::addr, AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_REQ_NOT_ALLOWED, AST_SECURITY_EVENT_REQ_NOT_ALLOWED_VERSION, ast_security_event_req_not_allowed::common, ast_security_event_common::event_type, ast_tcptls_session_args::local_address, mansession_get_transport(), ast_tcptls_session_instance::parent, ast_security_event_req_not_allowed::request_type, mansession::session, mansession_session::sessionstart_tv, mansession::tcptls_session, and mansession_session::username.

Referenced by process_message().

3386 {
3387  char session_id[32];
3388  char request_type[64];
3389  struct ast_security_event_req_not_allowed req_not_allowed = {
3392  .common.service = "AMI",
3393  .common.account_id = s->session->username,
3394  .common.session_tv = &s->session->sessionstart_tv,
3395  .common.local_addr = {
3396  .addr = &s->tcptls_session->parent->local_address,
3397  .transport = mansession_get_transport(s),
3398  },
3399  .common.remote_addr = {
3400  .addr = &s->session->addr,
3401  .transport = mansession_get_transport(s),
3402  },
3403  .common.session_id = session_id,
3404 
3405  .request_type = request_type,
3406  };
3407 
3408  snprintf(session_id, sizeof(session_id), "%p", s->session);
3409  snprintf(request_type, sizeof(request_type), "Action: %s", action);
3410 
3411  ast_security_event_report(AST_SEC_EVT(&req_not_allowed));
3412 }
enum ast_security_event_type event_type
The security event sub-type.
char username[80]
Definition: manager.c:1592
static enum ast_transport mansession_get_transport(const struct mansession *s)
Definition: manager.c:3279
struct ast_tcptls_session_args * parent
Definition: tcptls.h:152
A request was made that is not allowed.
struct ast_sockaddr addr
Definition: manager.c:1583
#define AST_SEC_EVT(e)
const char * request_type
Request type that was made.
struct timeval sessionstart_tv
Definition: manager.c:1590
struct ast_tcptls_session_instance * tcptls_session
Definition: manager.c:1628
struct ast_security_event_common common
Common security event descriptor elements.
struct mansession_session * session
Definition: manager.c:1626
struct ast_sockaddr local_address
Definition: tcptls.h:130
int ast_security_event_report(const struct ast_security_event_common *sec)
Report a security event.
Request denied because it&#39;s not allowed.
const char * request_type
Request type that was made.
#define AST_SECURITY_EVENT_REQ_NOT_ALLOWED_VERSION
Event descriptor version.

◆ report_session_limit()

static void report_session_limit ( const struct mansession s)
static

Definition at line 3473 of file manager.c.

References mansession_session::addr, AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_SESSION_LIMIT, AST_SECURITY_EVENT_SESSION_LIMIT_VERSION, ast_security_event_session_limit::common, ast_security_event_common::event_type, ast_tcptls_session_args::local_address, mansession_get_transport(), ast_tcptls_session_instance::parent, mansession::session, mansession_session::sessionstart_tv, mansession::tcptls_session, and mansession_session::username.

Referenced by process_message().

3474 {
3475  char session_id[32];
3477  .common.event_type = AST_SECURITY_EVENT_SESSION_LIMIT,
3478  .common.version = AST_SECURITY_EVENT_SESSION_LIMIT_VERSION,
3479  .common.service = "AMI",
3480  .common.account_id = s->session->username,
3481  .common.session_tv = &s->session->sessionstart_tv,
3482  .common.local_addr = {
3483  .addr = &s->tcptls_session->parent->local_address,
3484  .transport = mansession_get_transport(s),
3485  },
3486  .common.remote_addr = {
3487  .addr = &s->session->addr,
3488  .transport = mansession_get_transport(s),
3489  },
3490  .common.session_id = session_id,
3491  };
3492 
3493  snprintf(session_id, sizeof(session_id), "%p", s->session);
3494 
3495  ast_security_event_report(AST_SEC_EVT(&session_limit));
3496 }
char username[80]
Definition: manager.c:1592
static enum ast_transport mansession_get_transport(const struct mansession *s)
Definition: manager.c:3279
struct ast_tcptls_session_args * parent
Definition: tcptls.h:152
struct ast_sockaddr addr
Definition: manager.c:1583
#define AST_SEC_EVT(e)
Request denied because of a session limit.
struct timeval sessionstart_tv
Definition: manager.c:1590
struct ast_tcptls_session_instance * tcptls_session
Definition: manager.c:1628
static int session_limit
Definition: http.c:106
struct mansession_session * session
Definition: manager.c:1626
struct ast_sockaddr local_address
Definition: tcptls.h:130
int ast_security_event_report(const struct ast_security_event_common *sec)
Report a security event.
#define AST_SECURITY_EVENT_SESSION_LIMIT_VERSION
Event descriptor version.

◆ send_string()

static int send_string ( struct mansession s,
char *  string 
)
static

helper function to send a string to the socket. Return -1 on error (e.g. buffer full).

Definition at line 3025 of file manager.c.

References ast_iostream_set_timeout_disable(), ast_iostream_set_timeout_inactivity(), ast_iostream_write(), EVENT_FLAG_HOOKRESPONSE, manager_custom_hook::helper, mansession::hook, len(), mansession::session, mansession_session::stream, mansession::stream, mansession::write_error, and mansession_session::writetimeout.

Referenced by astman_append(), astman_flush(), and process_events().

3026 {
3027  struct ast_iostream *stream;
3028  int len, res;
3029 
3030  /* It's a result from one of the hook's action invocation */
3031  if (s->hook) {
3032  /*
3033  * to send responses, we're using the same function
3034  * as for receiving events. We call the event "HookResponse"
3035  */
3036  s->hook->helper(EVENT_FLAG_HOOKRESPONSE, "HookResponse", string);
3037  return 0;
3038  }
3039 
3040  stream = s->stream ? s->stream : s->session->stream;
3041 
3042  len = strlen(string);
3044  res = ast_iostream_write(stream, string, len);
3046 
3047  if (res < len) {
3048  s->write_error = 1;
3049  }
3050 
3051  return res;
3052 }
struct ast_iostream * stream
Definition: manager.c:1627
ssize_t ast_iostream_write(struct ast_iostream *stream, const void *buffer, size_t count)
Write data to an iostream.
Definition: iostream.c:374
void ast_iostream_set_timeout_inactivity(struct ast_iostream *stream, int timeout)
Set the iostream inactivity timeout timer.
Definition: iostream.c:121
void ast_iostream_set_timeout_disable(struct ast_iostream *stream)
Disable the iostream timeout timer.
Definition: iostream.c:113
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define EVENT_FLAG_HOOKRESPONSE
Definition: manager.h:85
struct ast_iostream * stream
Definition: manager.c:1584
unsigned int write_error
Definition: manager.c:1630
manager_hook_t helper
Definition: manager.h:112
struct mansession_session * session
Definition: manager.c:1626
struct manager_custom_hook * hook
Definition: manager.c:1631

◆ session_destroy()

static void session_destroy ( struct mansession_session s)
static

Definition at line 2269 of file manager.c.

References ao2_global_obj_ref, ao2_ref, ao2_unlink, sessions, and unref_mansession().

Referenced by auth_http_callback(), generic_http_callback(), purge_sessions(), and session_do().

2270 {
2271  struct ao2_container *sessions;
2272 
2273  sessions = ao2_global_obj_ref(mgr_sessions);
2274  if (sessions) {
2275  ao2_unlink(sessions, s);
2276  ao2_ref(sessions, -1);
2277  }
2278  unref_mansession(s);
2279 }
static struct sessions sessions
#define ao2_global_obj_ref(holder)
Definition: astobj2.h:925
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
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_unlink(container, obj)
Definition: astobj2.h:1598
Generic container type.

◆ session_destructor()

static void session_destructor ( void *  obj)
static

Definition at line 2198 of file manager.c.

References ao2_t_ref, ast_atomic_fetchadd_int(), ast_datastore_free(), AST_LIST_REMOVE_HEAD, ast_mutex_destroy, ast_variables_destroy(), mansession_session::blackfilters, mansession_session::chanvars, mansession_session::datastores, mansession_session::last_ev, mansession_session::notify_lock, session, eventqent::usecount, and mansession_session::whitefilters.

Referenced by build_mansession().

2199 {
2200  struct mansession_session *session = obj;
2201  struct eventqent *eqe = session->last_ev;
2202  struct ast_datastore *datastore;
2203 
2204  /* Get rid of each of the data stores on the session */
2205  while ((datastore = AST_LIST_REMOVE_HEAD(&session->datastores, entry))) {
2206  /* Free the data store */
2207  ast_datastore_free(datastore);
2208  }
2209 
2210  if (eqe) {
2211  ast_atomic_fetchadd_int(&eqe->usecount, -1);
2212  }
2213  if (session->chanvars) {
2214  ast_variables_destroy(session->chanvars);
2215  }
2216 
2217  if (session->whitefilters) {
2218  ao2_t_ref(session->whitefilters, -1, "decrement ref for white container, should be last one");
2219  }
2220 
2221  if (session->blackfilters) {
2222  ao2_t_ref(session->blackfilters, -1, "decrement ref for black container, should be last one");
2223  }
2224 
2225  ast_mutex_destroy(&session->notify_lock);
2226 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
struct mansession_session::mansession_datastores datastores
struct eventqent * last_ev
Definition: manager.c:1603
Structure for a data store object.
Definition: datastore.h:68
struct ao2_container * blackfilters
Definition: manager.c:1600
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
struct ast_variable * chanvars
Definition: manager.c:1601
ast_mutex_t notify_lock
Definition: manager.c:1610
struct ao2_container * whitefilters
Definition: manager.c:1599
static struct ast_mansession session
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
int usecount
Definition: manager.c:1460
Definition: search.h:40
#define ast_mutex_destroy(a)
Definition: lock.h:186

◆ session_do()

static void* session_do ( void *  data)
static

The body of the individual manager session. Call get_input() to read one line at a time (or be woken up on new events), collect the lines in a message until found an empty line, and execute the request. In any case, deliver events asynchronously through process_events() (called from here if no line is available, or at the end of process_message(). )

Definition at line 6937 of file manager.c.

References mansession_session::addr, AMI_VERSION, ao2_lock, ao2_ref, ao2_unlock, ast_atomic_fetchadd_int(), ast_iostream_get_fd(), ast_iostream_nonblock(), ast_iostream_set_exclusive_input(), ast_iostream_set_timeout_disable(), ast_iostream_set_timeout_sequence(), AST_LIST_HEAD_INIT_NOLOCK, ast_log, ast_mutex_destroy, ast_mutex_init, ast_sockaddr_copy(), ast_sockaddr_stringify_addr(), ast_tvnow(), ast_verb, astman_append(), mansession_session::authenticated, authlimit, mansession_session::authstart, authtimeout, build_mansession(), mansession_session::datastores, displayconnects, do_message(), done, errno, grab_last(), mansession_session::last_ev, mansession::lock, LOG_ERROR, LOG_WARNING, manager_displayconnects(), NULL, ast_tcptls_session_instance::remote_address, session, mansession::session, session_destroy(), ast_tcptls_session_instance::stream, mansession_session::stream, mansession::stream, mansession::tcptls_session, unauth_sessions, mansession_session::username, and mansession::write_error.

6938 {
6939  struct ast_tcptls_session_instance *ser = data;
6940  struct mansession_session *session;
6941  struct mansession s = {
6942  .tcptls_session = data,
6943  };
6944  int res;
6945  int arg = 1;
6946  struct ast_sockaddr ser_remote_address_tmp;
6947 
6950  goto done;
6951  }
6952 
6953  ast_sockaddr_copy(&ser_remote_address_tmp, &ser->remote_address);
6954  session = build_mansession(&ser_remote_address_tmp);
6955 
6956  if (session == NULL) {
6958  goto done;
6959  }
6960 
6961  /* here we set TCP_NODELAY on the socket to disable Nagle's algorithm.
6962  * This is necessary to prevent delays (caused by buffering) as we
6963  * write to the socket in bits and pieces. */
6964  if (setsockopt(ast_iostream_get_fd(ser->stream), IPPROTO_TCP, TCP_NODELAY, (char *) &arg, sizeof(arg)) < 0) {
6965  ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on manager connection: %s\n", strerror(errno));
6966  }
6968 
6969  ao2_lock(session);
6970  /* Hook to the tail of the event queue */
6971  session->last_ev = grab_last();
6972 
6973  ast_mutex_init(&s.lock);
6974 
6975  /* these fields duplicate those in the 'ser' structure */
6976  session->stream = s.stream = ser->stream;
6977  ast_sockaddr_copy(&session->addr, &ser_remote_address_tmp);
6978  s.session = session;
6979 
6981 
6982  if(time(&session->authstart) == -1) {
6983  ast_log(LOG_ERROR, "error executing time(): %s; disconnecting client\n", strerror(errno));
6985  ao2_unlock(session);
6986  session_destroy(session);
6987  goto done;
6988  }
6989  ao2_unlock(session);
6990 
6991  /*
6992  * We cannot let the stream exclusively wait for data to arrive.
6993  * We have to wake up the task to send async events.
6994  */
6996 
6998  ast_tvnow(), authtimeout * 1000);
6999 
7000  astman_append(&s, "Asterisk Call Manager/%s\r\n", AMI_VERSION); /* welcome prompt */
7001  for (;;) {
7002  if ((res = do_message(&s)) < 0 || s.write_error) {
7003  break;
7004  }
7005  if (session->authenticated) {
7007  }
7008  }
7009  /* session is over, explain why and terminate */
7010  if (session->authenticated) {
7011  if (manager_displayconnects(session)) {
7012  ast_verb(2, "Manager '%s' logged off from %s\n", session->username, ast_sockaddr_stringify_addr(&session->addr));
7013  }
7014  } else {
7016  if (displayconnects) {
7017  ast_verb(2, "Connect attempt from '%s' unable to authenticate\n", ast_sockaddr_stringify_addr(&session->addr));
7018  }
7019  }
7020 
7021  session_destroy(session);
7022 
7023  ast_mutex_destroy(&s.lock);
7024 done:
7025  ao2_ref(ser, -1);
7026  ser = NULL;
7027  return NULL;
7028 }
void ast_iostream_set_exclusive_input(struct ast_iostream *stream, int exclusive_input)
Set the iostream if it can exclusively depend upon the set timeouts.
Definition: iostream.c:148
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition: netsock2.h:290
struct ast_iostream * stream
Definition: manager.c:1627
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
char username[80]
Definition: manager.c:1592
static int displayconnects
Definition: manager.c:1470
struct mansession_session::mansession_datastores datastores
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:171
#define LOG_WARNING
Definition: logger.h:274
struct eventqent * last_ev
Definition: manager.c:1603
static int authtimeout
Definition: manager.c:1479
int ast_iostream_get_fd(struct ast_iostream *stream)
Get an iostream&#39;s file descriptor.
Definition: iostream.c:84
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define ao2_unlock(a)
Definition: astobj2.h:730
ast_mutex_t lock
Definition: manager.c:1632
struct ast_sockaddr addr
Definition: manager.c:1583
#define NULL
Definition: resample.c:96
static int unauth_sessions
Definition: manager.c:1486
Socket address structure.
Definition: netsock2.h:97
#define ast_verb(level,...)
Definition: logger.h:463
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
int done
Definition: test_amihooks.c:48
#define ast_log
Definition: astobj2.c:42
static struct ast_mansession session
#define ao2_ref(o, delta)
Definition: astobj2.h:464
In case you didn&#39;t read that giant block of text above the mansession_session struct, the struct mansession is named this solely to keep the API the same in Asterisk. This structure really represents data that is different from Manager action to Manager action. The mansession_session pointer contained within points to session-specific data.
Definition: manager.c:1625
#define ao2_lock(a)
Definition: astobj2.h:718
static int authlimit
Definition: manager.c:1480
describes a server instance
Definition: tcptls.h:149
#define AMI_VERSION
Definition: manager.h:57
void ast_iostream_set_timeout_disable(struct ast_iostream *stream)
Disable the iostream timeout timer.
Definition: iostream.c:113
struct ast_tcptls_session_instance * tcptls_session
Definition: manager.c:1628
#define LOG_ERROR
Definition: logger.h:285
void ast_iostream_set_timeout_sequence(struct ast_iostream *stream, struct timeval start, int timeout)
Set the iostream I/O sequence timeout timer.
Definition: iostream.c:139
int errno
struct ast_iostream * stream
Definition: manager.c:1584
struct ast_iostream * stream
Definition: tcptls.h:160
unsigned int write_error
Definition: manager.c:1630
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:680
static int do_message(struct mansession *s)
Definition: manager.c:6852
static struct mansession_session * build_mansession(const struct ast_sockaddr *addr)
Allocate manager session structure and add it to the list of sessions.
Definition: manager.c:2229
static struct eventqent * grab_last(void)
Definition: manager.c:1963
void ast_iostream_nonblock(struct ast_iostream *stream)
Make an iostream non-blocking.
Definition: iostream.c:103
static void session_destroy(struct mansession_session *s)
Definition: manager.c:2269
struct mansession_session * session
Definition: manager.c:1626
#define ast_mutex_init(pmutex)
Definition: lock.h:184
#define ast_mutex_destroy(a)
Definition: lock.h:186
static int manager_displayconnects(struct mansession_session *session)
Get displayconnects config option.
Definition: manager.c:2322
struct ast_sockaddr remote_address
Definition: tcptls.h:151

◆ set_eventmask()

static int set_eventmask ( struct mansession s,
const char *  eventmask 
)
static

Rather than braindead on,off this now can also accept a specific int mask value or a ',' delim list of mask strings (the same as manager.conf) -anthm.

Definition at line 3266 of file manager.c.

References ao2_lock, ao2_unlock, mansession_session::send_events, mansession::session, and strings_to_mask().

Referenced by action_events(), and authenticate().

3267 {
3268  int maskint = strings_to_mask(eventmask);
3269 
3270  ao2_lock(s->session);
3271  if (maskint >= 0) {
3272  s->session->send_events = maskint;
3273  }
3274  ao2_unlock(s->session);
3275 
3276  return maskint;
3277 }
#define ao2_unlock(a)
Definition: astobj2.h:730
#define ao2_lock(a)
Definition: astobj2.h:718
static int strings_to_mask(const char *string)
Definition: manager.c:2152
struct mansession_session * session
Definition: manager.c:1626

◆ STASIS_MESSAGE_TYPE_DEFN()

STASIS_MESSAGE_TYPE_DEFN ( ast_manager_get_generic_type  )

Define AMI message types.

◆ strings_to_mask()

static int strings_to_mask ( const char *  string)
static

A number returns itself, false returns 0, true returns all flags, other strings return the flags that are set.

Definition at line 2152 of file manager.c.

References ARRAY_LEN, ast_false(), ast_strlen_zero, ast_true(), get_perm(), permalias::num, and perms.

Referenced by set_eventmask().

2153 {
2154  const char *p;
2155 
2156  if (ast_strlen_zero(string)) {
2157  return -1;
2158  }
2159 
2160  for (p = string; *p; p++) {
2161  if (*p < '0' || *p > '9') {
2162  break;
2163  }
2164  }
2165  if (!*p) { /* all digits */
2166  return atoi(string);
2167  }
2168  if (ast_false(string)) {
2169  return 0;
2170  }
2171  if (ast_true(string)) { /* all permissions */
2172  int x, ret = 0;
2173  for (x = 0; x < ARRAY_LEN(perms); x++) {
2174  ret |= perms[x].num;
2175  }
2176  return ret;
2177  }
2178  return get_perm(string);
2179 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int num
Definition: manager.c:2016
static int get_perm(const char *instr)
Definition: manager.c:2131
#define ast_strlen_zero(foo)
Definition: strings.h:52
static const struct permalias perms[]
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1951
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is "false"...
Definition: main/utils.c:1968

◆ unref_mansession()

static struct mansession_session* unref_mansession ( struct mansession_session s)
static

Unreference manager session object. If no more references, then go ahead and delete it.

Definition at line 2183 of file manager.c.

References ao2_ref, ast_debug, manager_debug, and NULL.

Referenced by __manager_event_sessions_va(), astman_is_authed(), astman_verify_session_readpermissions(), astman_verify_session_writepermissions(), check_manager_session_inuse(), find_session(), find_session_by_nonce(), generic_http_callback(), handle_showmanconn(), purge_sessions(), and session_destroy().

2184 {
2185  int refcount = ao2_ref(s, -1);
2186  if (manager_debug) {
2187  ast_debug(1, "Mansession: %p refcount now %d\n", s, refcount - 1);
2188  }
2189  return NULL;
2190 }
#define NULL
Definition: resample.c:96
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static int manager_debug
Definition: manager.c:1478

◆ user_authority_to_str()

static const char* user_authority_to_str ( int  authority,
struct ast_str **  res 
)
static

Convert authority code to a list of options for a user. This will only display those authority codes that have an explicit match on authority.

Definition at line 2060 of file manager.c.

References ARRAY_LEN, ast_str_append(), ast_str_buffer(), ast_str_reset(), ast_str_strlen(), permalias::num, and perms.

Referenced by handle_showmanager().

2061 {
2062  int i;
2063  char *sep = "";
2064 
2065  ast_str_reset(*res);
2066  for (i = 0; i < ARRAY_LEN(perms) - 1; i++) {
2067  if ((authority & perms[i].num) == perms[i].num) {
2068  ast_str_append(res, 0, "%s%s", sep, perms[i].label);
2069  sep = ",";
2070  }
2071  }
2072 
2073  if (ast_str_strlen(*res) == 0) {
2074  /* replace empty string with something sensible */
2075  ast_str_append(res, 0, "<none>");
2076  }
2077 
2078  return ast_str_buffer(*res);
2079 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
int num
Definition: manager.c:2016
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
static const struct permalias perms[]
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
Definition: strings.h:653
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688

◆ whitefilter_cmp_fn()

static int whitefilter_cmp_fn ( void *  obj,
void *  arg,
void *  data,
int  flags 
)
static

Definition at line 6078 of file manager.c.

References CMP_MATCH, CMP_STOP, NULL, and result.

Referenced by match_filter().

6079 {
6080  regex_t *regex_filter = obj;
6081  const char *eventdata = arg;
6082  int *result = data;
6083 
6084  if (!regexec(regex_filter, eventdata, 0, NULL, 0)) {
6085  *result = 1;
6086  return (CMP_MATCH | CMP_STOP);
6087  }
6088 
6089  return 0;
6090 }
#define NULL
Definition: resample.c:96
static PGresult * result
Definition: cel_pgsql.c:88

Variable Documentation

◆ acl_change_sub

struct stasis_subscription* acl_change_sub
static

Definition at line 1487 of file manager.c.

◆ actions

struct actions actions = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
static

◆ all_events

struct all_events all_events = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
static

◆ allowmultiplelogin

int allowmultiplelogin = 1
static

Definition at line 1471 of file manager.c.

Referenced by __init_manager(), and handle_manager_show_settings().

◆ astman_append_buf

struct ast_threadstorage astman_append_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_astman_append_buf , .custom_init = NULL , }
static

◆ authlimit

int authlimit
static

Definition at line 1480 of file manager.c.

Referenced by __init_manager(), manager_set_defaults(), and session_do().

◆ authtimeout

int authtimeout
static

Definition at line 1479 of file manager.c.

Referenced by __init_manager(), do_message(), get_input(), manager_set_defaults(), and session_do().

◆ broken_events_action

int broken_events_action = 0
static

Definition at line 1474 of file manager.c.

Referenced by __init_manager(), action_events(), and manager_set_defaults().

◆ command_blacklist

const { ... } command_blacklist[]
Initial value:
= {
{{ "module", "load", NULL }},
{{ "module", "unload", NULL }},
{{ "restart", "gracefully", NULL }},
}
#define NULL
Definition: resample.c:96

Referenced by check_blacklist().

◆ displayconnects

int displayconnects = 1
static

◆ global_realm

char global_realm[MAXHOSTNAMELEN]
static

Default realm

Definition at line 1484 of file manager.c.

Referenced by __init_manager(), auth_http_callback(), and manager_set_defaults().

◆ httptimeout

int httptimeout = 60
static

◆ manager_channelvars

char* manager_channelvars
static

Definition at line 1481 of file manager.c.

Referenced by handle_manager_show_settings(), load_channelvars(), and manager_shutdown().

◆ manager_debug

int manager_debug = 0
static

◆ manager_enabled

int manager_enabled = 0
static

◆ manager_event_buf

struct ast_threadstorage manager_event_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_manager_event_buf , .custom_init = NULL , }
static

Definition at line 7109 of file manager.c.

Referenced by __manager_event_sessions_va().

◆ manager_hooks

struct manager_hooks manager_hooks = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
static

◆ manager_topic

struct stasis_topic* manager_topic
static

A stasis_topic that all topics AMI cares about will be forwarded to.

Definition at line 1490 of file manager.c.

Referenced by ast_manager_get_topic(), load_module(), manager_bridging_init(), manager_channels_init(), manager_mwi_init(), and manager_system_init().

◆ perms

const struct permalias perms[]
static

◆ rtp_topic_forwarder

struct stasis_forward* rtp_topic_forwarder
static

The stasis_subscription for forwarding the RTP topic to the AMI topic.

Definition at line 1496 of file manager.c.

◆ security_topic_forwarder

struct stasis_forward* security_topic_forwarder
static

The stasis_subscription for forwarding the Security topic to the AMI topic.

Definition at line 1499 of file manager.c.

◆ stasis_router

struct stasis_message_router* stasis_router
static

The stasis_message_router for all Stasis Message Bus API messages.

Definition at line 1493 of file manager.c.

Referenced by ast_manager_get_message_router().

◆ subscribed

int subscribed = 0
static

◆ test_suite_forwarder

struct stasis_forward* test_suite_forwarder
static

The stasis_subscription for forwarding the Test topic to the AMI topic.

Definition at line 1503 of file manager.c.

◆ timestampevents

int timestampevents
static

◆ unauth_sessions

int unauth_sessions = 0
static

Definition at line 1486 of file manager.c.

Referenced by action_login(), and session_do().

◆ userevent_buf

struct ast_threadstorage userevent_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_userevent_buf , .custom_init = NULL , }
static

Definition at line 3063 of file manager.c.

Referenced by action_userevent().

◆ users

struct users users = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
static

◆ webmanager_enabled

int webmanager_enabled = 0
static

◆ words

const char* words[AST_MAX_CMD_LEN]

Definition at line 1525 of file manager.c.