Asterisk - The Open Source Telephony Project  GIT-master-932eae6
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 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 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
#define ast_strlen_zero(a)
Definition: muted.c:73
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
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
#define ast_strlen_zero(a)
Definition: muted.c:73
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:1078
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:1024
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:1135

◆ 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:2938
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:4667
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:1430
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_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
#define ast_strlen_zero(a)
Definition: muted.c:73
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:1450
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:2902
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:2938
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
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:1135
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_strlen_zero(a)
Definition: muted.c:73
#define ast_channel_unlock(chan)
Definition: channel.h:2903
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:1450
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:2938
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
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
#define ast_strlen_zero(a)
Definition: muted.c:73
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:1450
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:2902
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:2938
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
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:1135
#define ast_strlen_zero(a)
Definition: muted.c:73
#define ast_channel_unlock(chan)
Definition: channel.h:2903
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:1450
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
long int ast_random(void)
Definition: main/utils.c:1935
#define ast_strlen_zero(a)
Definition: muted.c:73
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
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_strlen_zero(a)
Definition: muted.c:73
#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.
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
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_strlen_zero(a)
Definition: muted.c:73
#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
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_strlen_zero(a)
Definition: muted.c:73
#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
struct timeval ast_lastreloadtime
Definition: asterisk.c:337
#define ast_strlen_zero(a)
Definition: muted.c:73
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:495

◆ 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
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
#define ast_strlen_zero(a)
Definition: muted.c:73
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
const char * ast_extension_state2str(int extension_state)
Return string representation of the state of an extension.
Definition: pbx.c:3126
#define ast_strlen_zero(a)
Definition: muted.c:73
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
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_strlen_zero(a)
Definition: muted.c:73
#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
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_strlen_zero(a)
Definition: muted.c:73
#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:2938
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_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.
#define ast_strlen_zero(a)
Definition: muted.c:73
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:1450
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:1418
char username[80]
Definition: manager.c:1592
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2938
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:455
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_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:1802
#define ast_strlen_zero(a)
Definition: muted.c:73
#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:1356
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:1404
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1450
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:464
#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:2316
#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
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
#define ast_strlen_zero(a)
Definition: muted.c:73
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:1224
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:455
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
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
#define ast_strlen_zero(a)
Definition: muted.c:73
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
static char mailbox[AST_MAX_MAILBOX_UNIQUEID]
Definition: chan_mgcp.c:204
#define ast_strlen_zero(a)
Definition: muted.c:73
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:503
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
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:1822
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 *)
#define ast_strlen_zero(a)
Definition: muted.c:73
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(a)
Definition: muted.c:73

◆ 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:957
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
ast_presence_state
Definition: presencestate.h:26
#define ast_strlen_zero(a)
Definition: muted.c:73
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:170
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:2902
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:2938
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:455
void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag)
Definition: channel.c:11125
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
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:10639
#define ast_strlen_zero(a)
Definition: muted.c:73
#define ast_channel_unlock(chan)
Definition: channel.h:2903
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:1450
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:1560
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:2938
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(a)
Definition: muted.c:73
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:1450
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:2938
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(a)
Definition: muted.c:73
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:1450
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:2902
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:1418
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2938
#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
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:1822
#define ast_strlen_zero(a)
Definition: muted.c:73
#define ast_channel_unlock(chan)
Definition: channel.h:2903
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:1356
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:1404
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1450
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:2902
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2938
void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset)
Set when to hang a channel up.
Definition: channel.c:506
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(a)
Definition: muted.c:73
#define ast_channel_unlock(chan)
Definition: channel.h:2903
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:1450
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:1560
#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
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:1822
void ast_include_rename(struct ast_config *conf, const char *from_file, const char *to_file)
Definition: main/config.c:385
#define ast_strlen_zero(a)
Definition: muted.c:73
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</