Fri Jan 18 20:01:45 2013

Asterisk developer's documentation


AMI functions

callback to display queues status in manager More...

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  channelvars
struct  eventqent
struct  fast_originate_helper
 helper function for originate More...
struct  manager_channel_variable
struct  manager_hooks
 list of hooks registered More...
struct  mansession
struct  mansession_session
struct  permalias
struct  users
 list of users found in the config file More...

Defines

#define ASTMAN_APPEND_BUF_INITSIZE   256
 initial allocated size for the astman_append_buf
#define DEFAULT_REALM   "asterisk"
#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 MAX_BLACKLIST_CMD_LEN   2
 Descriptor for a manager session, either on the AMI socket or over HTTP.
#define MSG_MOREDATA   ((char *)astman_send_response)
 send a response with an optional message, and terminate it with an empty line. m is used only to grab the 'ActionID' field.

Enumerations

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
}
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.
static void __init_astman_append_buf (void)
 thread local buffer for astman_append
static void __init_manager_event_buf (void)
static void __init_manager_event_funcbuf (void)
static void __init_userevent_buf (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_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.
static int action_coresettings (struct mansession *s, const struct message *m)
 Show PBX core settings information.
static int action_coreshowchannels (struct mansession *s, const struct message *m)
 Manager command "CoreShowChannels" - List currently defined channels and some information about them.
static int action_corestatus (struct mansession *s, const struct message *m)
 Show PBX core status information.
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 struct manager_action * action_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_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_redirect (struct mansession *s, const struct message *m)
 action_redirect: The redirect manager command
static int action_reload (struct mansession *s, const struct message *m)
 Send a reload event.
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.
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 eventqent * advance_event (struct eventqent *e)
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)
int ast_hook_send_action (struct manager_custom_hook *hook, const char *msg)
 Registered hooks can call this function to invoke actions and they will receive responses through registered callback.
static int ast_instring (const char *bigstr, const char *smallstr, const char delim)
int ast_manager_register2 (const char *action, int auth, int(*func)(struct mansession *s, const struct message *m), 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
void ast_manager_register_hook (struct manager_custom_hook *hook)
 Add a custom hook to be called when an event is fired.
static int ast_manager_register_struct (struct manager_action *act)
int ast_manager_unregister (char *action)
 Unregister a registered manager command.
void ast_manager_unregister_hook (struct manager_custom_hook *hook)
 Delete a custom hook to be called when an event is fired.
void astman_append (struct mansession *s, const char *fmt,...)
static void astman_append_json (struct mansession *s, const char *str)
const char * astman_get_header (const struct message *m, char *var)
 Return the first matching variable from an array.
struct ast_variable * astman_get_variables (const struct message *m)
 Get a linked list of the Variable: headers.
void astman_send_ack (struct mansession *s, const struct message *m, char *msg)
 Send ack in manager transaction.
void astman_send_error (struct mansession *s, const struct message *m, char *error)
 Send error in manager transaction.
void astman_send_listack (struct mansession *s, const struct message *m, char *msg, char *listflag)
 Send ack in manager list transaction.
void astman_send_response (struct mansession *s, const struct message *m, char *resp, char *msg)
 Send response in manager transaction.
static void astman_send_response_full (struct mansession *s, const struct message *m, char *resp, char *msg, char *listflag)
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.
static int blackfilter_cmp_fn (void *obj, void *arg, void *data, int flags)
static struct mansession_session * build_mansession (struct sockaddr_in sin)
 Allocate manager session structure and add it to the list of sessions.
static int check_blacklist (const char *cmd)
int check_manager_enabled (void)
 Check if AMI is enabled.
static int check_manager_session_inuse (const char *name)
int check_webmanager_enabled (void)
 Check if AMI/HTTP is enabled.
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 void free_channelvars (void)
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.
static int get_input (struct mansession *s, char *output)
static struct ast_manager_user * get_manager_by_name_locked (const char *name)
static int get_perm (const char *instr)
static struct eventqent * grab_last (void)
static char * handle_manager_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command manager reload.
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.
static char * handle_showmanconn (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command manager list connected.
static char * handle_showmaneventq (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command manager list eventq.
static enum error_type handle_updates (struct mansession *s, const struct message *m, struct ast_config *cfg, const char *dfn)
static void json_escape (char *out, const char *in)
static struct ast_variable * man_do_variable_value (struct ast_variable *head, const char *hdr_val)
static int manager_displayconnects (struct mansession_session *session)
 Get displayconnects config option.
static int manager_modulecheck (struct mansession *s, const struct message *m)
static int manager_moduleload (struct mansession *s, const struct message *m)
static int manager_state_cb (char *context, char *exten, int state, void *data)
static int mansession_cmp_fn (void *obj, void *arg, int flags)
static struct sockaddr_in * mansession_encode_sin_local (const struct mansession *s, struct sockaddr_in *sin_local)
static enum
ast_security_event_transport_type 
mansession_get_transport (const struct mansession *s)
static void mansession_lock (struct mansession *s)
 Lock the 'mansession' structure.
static void mansession_unlock (struct mansession *s)
 Unlock the 'mansession' structure.
static int match_filter (struct mansession *s, char *eventdata)
static int process_events (struct mansession *s)
static int process_message (struct mansession *s, const struct message *m)
static void purge_events (void)
static void purge_sessions (int n_max)
 remove at most n_max stale session from the list.
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(). ).
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.
static int strings_to_mask (const char *string)
static struct mansession_session * unref_mansession (struct mansession_session *s)
 Unreference manager session object. If no more references, then go ahead and delete it.
static int whitefilter_cmp_fn (void *obj, void *arg, void *data, int flags)

Variables

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 block_sockets
static int broken_events_action
struct {
   const char *   words [AST_MAX_CMD_LEN]
} command_blacklist []
static const int DEFAULT_AUTHLIMIT = 50
static const int DEFAULT_AUTHTIMEOUT = 30
static const int DEFAULT_BLOCKSOCKETS = 0
static const int DEFAULT_BROKENEVENTSACTION = 0
static const int DEFAULT_DISPLAYCONNECTS = 1
static const int DEFAULT_ENABLED = 0
static const int DEFAULT_HTTPTIMEOUT = 60
static const int DEFAULT_MANAGERDEBUG = 0
static const int DEFAULT_TIMESTAMPEVENTS = 0
static const int DEFAULT_WEBENABLED = 0
static int displayconnects
static char global_realm [MAXHOSTNAMELEN]
static int httptimeout
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 ast_threadstorage manager_event_funcbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_manager_event_funcbuf , .custom_init = NULL , }
static struct permalias perms []
static struct ao2_container * sessions = NULL
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 int webmanager_enabled = 0

Detailed Description

callback to display queues status in manager


Define Documentation

#define ASTMAN_APPEND_BUF_INITSIZE   256

initial allocated size for the astman_append_buf

Definition at line 2024 of file manager.c.

Referenced by astman_append().

#define DEFAULT_REALM   "asterisk"

Definition at line 910 of file manager.c.

Referenced by __init_manager(), and reload_config().

#define GET_HEADER_FIRST_MATCH   0

Definition at line 1777 of file manager.c.

Referenced by astman_get_header().

#define GET_HEADER_LAST_MATCH   1

Definition at line 1778 of file manager.c.

Referenced by __astman_get_header().

#define GET_HEADER_SKIP_EMPTY   2

Definition at line 1779 of file manager.c.

Referenced by __astman_get_header(), and process_message().

#define MANAGER_EVENT_BUF_INITSIZE   256

Definition at line 5159 of file manager.c.

Referenced by __ast_manager_event_multichan().

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

Referenced by check_blacklist().

#define MSG_MOREDATA   ((char *)astman_send_response)

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

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.

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

Definition at line 2065 of file manager.c.

Referenced by astman_send_response_full(), and astman_start_ack().


Enumeration Type Documentation

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 

Definition at line 842 of file manager.c.

Enumerator:
MESSAGE_OKAY 
MESSAGE_LINE_TOO_LONG 

Definition at line 1002 of file manager.c.

01002                                 {
01003    MESSAGE_OKAY,
01004    MESSAGE_LINE_TOO_LONG
01005 };


Function Documentation

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:
category Event category, matches manager authorization
event Event name
chancount Number of channels in chans parameter
chans A pointer to an array of channels involved in the event
contents Format string describing event
Since:
1.8

Definition at line 5161 of file manager.c.

References ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_unlock, append_channel_vars(), append_event(), ast_atomic_fetchadd_int(), 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_tvnow(), authority_to_str(), manager_custom_hook::helper, manager_event_buf, MANAGER_EVENT_BUF_INITSIZE, mansession_session::pending_event, eventqent::seq, sessions, unref_mansession(), and mansession_session::waiting_thread.

05163 {
05164    struct mansession_session *session;
05165    struct manager_custom_hook *hook;
05166    struct ast_str *auth = ast_str_alloca(80);
05167    const char *cat_str;
05168    va_list ap;
05169    struct timeval now;
05170    struct ast_str *buf;
05171    int i;
05172 
05173    if (!(sessions && ao2_container_count(sessions)) && AST_RWLIST_EMPTY(&manager_hooks)) {
05174       return 0;
05175    }
05176    
05177    if (!(buf = ast_str_thread_get(&manager_event_buf, MANAGER_EVENT_BUF_INITSIZE))) {
05178       return -1;
05179    }
05180 
05181    cat_str = authority_to_str(category, &auth);
05182    ast_str_set(&buf, 0,
05183          "Event: %s\r\nPrivilege: %s\r\n",
05184           event, cat_str);
05185 
05186    if (timestampevents) {
05187       now = ast_tvnow();
05188       ast_str_append(&buf, 0,
05189             "Timestamp: %ld.%06lu\r\n",
05190              (long)now.tv_sec, (unsigned long) now.tv_usec);
05191    }
05192    if (manager_debug) {
05193       static int seq;
05194       ast_str_append(&buf, 0,
05195             "SequenceNumber: %d\r\n",
05196              ast_atomic_fetchadd_int(&seq, 1));
05197       ast_str_append(&buf, 0,
05198             "File: %s\r\nLine: %d\r\nFunc: %s\r\n", file, line, func);
05199    }
05200 
05201    va_start(ap, fmt);
05202    ast_str_append_va(&buf, 0, fmt, ap);
05203    va_end(ap);
05204    for (i = 0; i < chancount; i++) {
05205       append_channel_vars(&buf, chans[i]);
05206    }
05207 
05208    ast_str_append(&buf, 0, "\r\n");
05209 
05210    append_event(ast_str_buffer(buf), category);
05211 
05212    /* Wake up any sleeping sessions */
05213    if (sessions) {
05214       struct ao2_iterator i;
05215       i = ao2_iterator_init(sessions, 0);
05216       while ((session = ao2_iterator_next(&i))) {
05217          ao2_lock(session);
05218          if (session->waiting_thread != AST_PTHREADT_NULL) {
05219             pthread_kill(session->waiting_thread, SIGURG);
05220          } else {
05221             /* We have an event to process, but the mansession is
05222              * not waiting for it. We still need to indicate that there
05223              * is an event waiting so that get_input processes the pending
05224              * event instead of polling.
05225              */
05226             session->pending_event = 1;
05227          }
05228          ao2_unlock(session);
05229          unref_mansession(session);
05230       }
05231       ao2_iterator_destroy(&i);
05232    }
05233 
05234    if (!AST_RWLIST_EMPTY(&manager_hooks)) {
05235       AST_RWLIST_RDLOCK(&manager_hooks);
05236       AST_RWLIST_TRAVERSE(&manager_hooks, hook, list) {
05237          hook->helper(category, event, ast_str_buffer(buf));
05238       }
05239       AST_RWLIST_UNLOCK(&manager_hooks);
05240    }
05241 
05242    return 0;
05243 }

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

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

Referenced by astman_get_header(), and process_message().

01795 {
01796    int x, l = strlen(var);
01797    const char *result = "";
01798 
01799    if (!m) {
01800       return result;
01801    }
01802 
01803    for (x = 0; x < m->hdrcount; x++) {
01804       const char *h = m->headers[x];
01805       if (!strncasecmp(var, h, l) && h[l] == ':') {
01806          const char *value = h + l + 1;
01807          value = ast_skip_blanks(value); /* ignore leading spaces in the value */
01808          /* found a potential candidate */
01809          if ((mode & GET_HEADER_SKIP_EMPTY) && ast_strlen_zero(value)) {
01810             continue;   /* not interesting */
01811          }
01812          if (mode & GET_HEADER_LAST_MATCH) {
01813             result = value;   /* record the last match so far */
01814          } else {
01815             return value;
01816          }
01817       }
01818    }
01819 
01820    return result;
01821 }

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

02030 {

static void __init_manager_event_buf ( void   )  [static]

Definition at line 5158 of file manager.c.

05163 {

static void __init_manager_event_funcbuf ( void   )  [static]

Definition at line 5131 of file manager.c.

05134 {

static void __init_userevent_buf ( void   )  [static]

Definition at line 2021 of file manager.c.

02030 {

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

Definition at line 3821 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(), ast_aoc_unit_entry::type, ast_aoc_unit_entry::valid_amount, and ast_aoc_unit_entry::valid_type.

Referenced by __init_manager().

03822 {
03823    const char *channel = astman_get_header(m, "Channel");
03824    const char *pchannel = astman_get_header(m, "ChannelPrefix");
03825    const char *msgtype = astman_get_header(m, "MsgType");
03826    const char *chargetype = astman_get_header(m, "ChargeType");
03827    const char *currencyname = astman_get_header(m, "CurrencyName");
03828    const char *currencyamount = astman_get_header(m, "CurrencyAmount");
03829    const char *mult = astman_get_header(m, "CurrencyMultiplier");
03830    const char *totaltype = astman_get_header(m, "TotalType");
03831    const char *aocbillingid = astman_get_header(m, "AOCBillingId");
03832    const char *association_id= astman_get_header(m, "ChargingAssociationId");
03833    const char *association_num = astman_get_header(m, "ChargingAssociationNumber");
03834    const char *association_plan = astman_get_header(m, "ChargingAssociationPlan");
03835 
03836    enum ast_aoc_type _msgtype;
03837    enum ast_aoc_charge_type _chargetype;
03838    enum ast_aoc_currency_multiplier _mult = AST_AOC_MULT_ONE;
03839    enum ast_aoc_total_type _totaltype = AST_AOC_TOTAL;
03840    enum ast_aoc_billing_id _billingid = AST_AOC_BILLING_NA;
03841    unsigned int _currencyamount = 0;
03842    int _association_id = 0;
03843    unsigned int _association_plan = 0;
03844    struct ast_channel *chan = NULL;
03845 
03846    struct ast_aoc_decoded *decoded = NULL;
03847    struct ast_aoc_encoded *encoded = NULL;
03848    size_t encoded_size = 0;
03849 
03850    if (ast_strlen_zero(channel) && ast_strlen_zero(pchannel)) {
03851       astman_send_error(s, m, "Channel and PartialChannel are not specified. Specify at least one of these.");
03852       goto aocmessage_cleanup;
03853    }
03854 
03855    if (!(chan = ast_channel_get_by_name(channel)) && !ast_strlen_zero(pchannel)) {
03856       chan = ast_channel_get_by_name_prefix(pchannel, strlen(pchannel));
03857    }
03858 
03859    if (!chan) {
03860       astman_send_error(s, m, "No such channel");
03861       goto aocmessage_cleanup;
03862    }
03863 
03864    if (ast_strlen_zero(msgtype) || (strcasecmp(msgtype, "d") && strcasecmp(msgtype, "e"))) {
03865       astman_send_error(s, m, "Invalid MsgType");
03866       goto aocmessage_cleanup;
03867    }
03868 
03869    if (ast_strlen_zero(chargetype)) {
03870       astman_send_error(s, m, "ChargeType not specified");
03871       goto aocmessage_cleanup;
03872    }
03873 
03874    _msgtype = strcasecmp(msgtype, "d") ? AST_AOC_E : AST_AOC_D;
03875 
03876    if (!strcasecmp(chargetype, "NA")) {
03877       _chargetype = AST_AOC_CHARGE_NA;
03878    } else if (!strcasecmp(chargetype, "Free")) {
03879       _chargetype = AST_AOC_CHARGE_FREE;
03880    } else if (!strcasecmp(chargetype, "Currency")) {
03881       _chargetype = AST_AOC_CHARGE_CURRENCY;
03882    } else if (!strcasecmp(chargetype, "Unit")) {
03883       _chargetype = AST_AOC_CHARGE_UNIT;
03884    } else {
03885       astman_send_error(s, m, "Invalid ChargeType");
03886       goto aocmessage_cleanup;
03887    }
03888 
03889    if (_chargetype == AST_AOC_CHARGE_CURRENCY) {
03890 
03891       if (ast_strlen_zero(currencyamount) || (sscanf(currencyamount, "%30u", &_currencyamount) != 1)) {
03892          astman_send_error(s, m, "Invalid CurrencyAmount, CurrencyAmount is a required when ChargeType is Currency");
03893          goto aocmessage_cleanup;
03894       }
03895 
03896       if (ast_strlen_zero(mult)) {
03897          astman_send_error(s, m, "ChargeMultiplier unspecified, ChargeMultiplier is required when ChargeType is Currency.");
03898          goto aocmessage_cleanup;
03899       } else if (!strcasecmp(mult, "onethousandth")) {
03900          _mult = AST_AOC_MULT_ONETHOUSANDTH;
03901       } else if (!strcasecmp(mult, "onehundredth")) {
03902          _mult = AST_AOC_MULT_ONEHUNDREDTH;
03903       } else if (!strcasecmp(mult, "onetenth")) {
03904          _mult = AST_AOC_MULT_ONETENTH;
03905       } else if (!strcasecmp(mult, "one")) {
03906          _mult = AST_AOC_MULT_ONE;
03907       } else if (!strcasecmp(mult, "ten")) {
03908          _mult = AST_AOC_MULT_TEN;
03909       } else if (!strcasecmp(mult, "hundred")) {
03910          _mult = AST_AOC_MULT_HUNDRED;
03911       } else if (!strcasecmp(mult, "thousand")) {
03912          _mult = AST_AOC_MULT_THOUSAND;
03913       } else {
03914          astman_send_error(s, m, "Invalid ChargeMultiplier");
03915          goto aocmessage_cleanup;
03916       }
03917    }
03918 
03919    /* create decoded object and start setting values */
03920    if (!(decoded = ast_aoc_create(_msgtype, _chargetype, 0))) {
03921          astman_send_error(s, m, "Message Creation Failed");
03922          goto aocmessage_cleanup;
03923    }
03924 
03925    if (_msgtype == AST_AOC_D) {
03926       if (!ast_strlen_zero(totaltype) && !strcasecmp(totaltype, "subtotal")) {
03927          _totaltype = AST_AOC_SUBTOTAL;
03928       }
03929 
03930       if (ast_strlen_zero(aocbillingid)) {
03931          /* ignore this is optional */
03932       } else if (!strcasecmp(aocbillingid, "Normal")) {
03933          _billingid = AST_AOC_BILLING_NORMAL;
03934       } else if (!strcasecmp(aocbillingid, "ReverseCharge")) {
03935          _billingid = AST_AOC_BILLING_REVERSE_CHARGE;
03936       } else if (!strcasecmp(aocbillingid, "CreditCard")) {
03937          _billingid = AST_AOC_BILLING_CREDIT_CARD;
03938       } else {
03939          astman_send_error(s, m, "Invalid AOC-D AOCBillingId");
03940          goto aocmessage_cleanup;
03941       }
03942    } else {
03943       if (ast_strlen_zero(aocbillingid)) {
03944          /* ignore this is optional */
03945       } else if (!strcasecmp(aocbillingid, "Normal")) {
03946          _billingid = AST_AOC_BILLING_NORMAL;
03947       } else if (!strcasecmp(aocbillingid, "ReverseCharge")) {
03948          _billingid = AST_AOC_BILLING_REVERSE_CHARGE;
03949       } else if (!strcasecmp(aocbillingid, "CreditCard")) {
03950          _billingid = AST_AOC_BILLING_CREDIT_CARD;
03951       } else if (!strcasecmp(aocbillingid, "CallFwdUnconditional")) {
03952          _billingid = AST_AOC_BILLING_CALL_FWD_UNCONDITIONAL;
03953       } else if (!strcasecmp(aocbillingid, "CallFwdBusy")) {
03954          _billingid = AST_AOC_BILLING_CALL_FWD_BUSY;
03955       } else if (!strcasecmp(aocbillingid, "CallFwdNoReply")) {
03956          _billingid = AST_AOC_BILLING_CALL_FWD_NO_REPLY;
03957       } else if (!strcasecmp(aocbillingid, "CallDeflection")) {
03958          _billingid = AST_AOC_BILLING_CALL_DEFLECTION;
03959       } else if (!strcasecmp(aocbillingid, "CallTransfer")) {
03960          _billingid = AST_AOC_BILLING_CALL_TRANSFER;
03961       } else {
03962          astman_send_error(s, m, "Invalid AOC-E AOCBillingId");
03963          goto aocmessage_cleanup;
03964       }
03965 
03966       if (!ast_strlen_zero(association_id) && (sscanf(association_id, "%30d", &_association_id) != 1)) {
03967          astman_send_error(s, m, "Invalid ChargingAssociationId");
03968          goto aocmessage_cleanup;
03969       }
03970       if (!ast_strlen_zero(association_plan) && (sscanf(association_plan, "%30u", &_association_plan) != 1)) {
03971          astman_send_error(s, m, "Invalid ChargingAssociationPlan");
03972          goto aocmessage_cleanup;
03973       }
03974 
03975       if (_association_id) {
03976          ast_aoc_set_association_id(decoded, _association_id);
03977       } else if (!ast_strlen_zero(association_num)) {
03978          ast_aoc_set_association_number(decoded, association_num, _association_plan);
03979       }
03980    }
03981 
03982    if (_chargetype == AST_AOC_CHARGE_CURRENCY) {
03983       ast_aoc_set_currency_info(decoded, _currencyamount, _mult, ast_strlen_zero(currencyname) ? NULL : currencyname);
03984    } else if (_chargetype == AST_AOC_CHARGE_UNIT) {
03985       struct ast_aoc_unit_entry entry;
03986       int i;
03987 
03988       /* multiple unit entries are possible, lets get them all */
03989       for (i = 0; i < 32; i++) {
03990          if (aocmessage_get_unit_entry(m, &entry, i)) {
03991             break; /* that's the end then */
03992          }
03993 
03994          ast_aoc_add_unit_entry(decoded, entry.valid_amount, entry.amount, entry.valid_type, entry.type);
03995       }
03996 
03997       /* at least one unit entry is required */
03998       if (!i) {
03999          astman_send_error(s, m, "Invalid UnitAmount(0), At least one valid unit entry is required when ChargeType is set to Unit");
04000          goto aocmessage_cleanup;
04001       }
04002 
04003    }
04004 
04005    ast_aoc_set_billing_id(decoded, _billingid);
04006    ast_aoc_set_total_type(decoded, _totaltype);
04007 
04008 
04009    if ((encoded = ast_aoc_encode(decoded, &encoded_size, NULL)) && !ast_indicate_data(chan, AST_CONTROL_AOC, encoded, encoded_size)) {
04010       astman_send_ack(s, m, "AOC Message successfully queued on channel");
04011    } else {
04012       astman_send_error(s, m, "Error encoding AOC message, could not queue onto channel");
04013    }
04014 
04015 aocmessage_cleanup:
04016 
04017    ast_aoc_destroy_decoded(decoded);
04018    ast_aoc_destroy_encoded(encoded);
04019 
04020    if (chan) {
04021       chan = ast_channel_unref(chan);
04022    }
04023    return 0;
04024 }

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

Definition at line 3549 of file manager.c.

References ast_channel_get_by_name(), ast_channel_unref, ast_find_call_feature(), AST_FRAME_DTMF, ast_queue_frame(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), context, ast_call_feature::exten, exten, and pbx_builtin_setvar_helper().

Referenced by __init_manager().

03550 {
03551    const char *name = astman_get_header(m, "Channel");
03552    const char *exten = astman_get_header(m, "Exten");
03553    const char *context = astman_get_header(m, "Context");
03554    struct ast_channel *chan = NULL;
03555    struct ast_call_feature *atxfer_feature = NULL;
03556    char *feature_code = NULL;
03557 
03558    if (ast_strlen_zero(name)) {
03559       astman_send_error(s, m, "No channel specified");
03560       return 0;
03561    }
03562    if (ast_strlen_zero(exten)) {
03563       astman_send_error(s, m, "No extension specified");
03564       return 0;
03565    }
03566 
03567    if (!(atxfer_feature = ast_find_call_feature("atxfer"))) {
03568       astman_send_error(s, m, "No attended transfer feature found");
03569       return 0;
03570    }
03571 
03572    if (!(chan = ast_channel_get_by_name(name))) {
03573       astman_send_error(s, m, "Channel specified does not exist");
03574       return 0;
03575    }
03576 
03577    if (!ast_strlen_zero(context)) {
03578       pbx_builtin_setvar_helper(chan, "TRANSFER_CONTEXT", context);
03579    }
03580 
03581    for (feature_code = atxfer_feature->exten; feature_code && *feature_code; ++feature_code) {
03582       struct ast_frame f = { AST_FRAME_DTMF, .subclass.integer = *feature_code };
03583       ast_queue_frame(chan, &f);
03584    }
03585 
03586    for (feature_code = (char *)exten; feature_code && *feature_code; ++feature_code) {
03587       struct ast_frame f = { AST_FRAME_DTMF, .subclass.integer = *feature_code };
03588       ast_queue_frame(chan, &f);
03589    }
03590 
03591    chan = ast_channel_unref(chan);
03592 
03593    astman_send_ack(s, m, "Atxfer successfully queued");
03594 
03595    return 0;
03596 }

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

Definition at line 3104 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().

03105 {
03106    const char *authtype = astman_get_header(m, "AuthType");
03107 
03108    if (!strcasecmp(authtype, "MD5")) {
03109       if (ast_strlen_zero(s->session->challenge)) {
03110          snprintf(s->session->challenge, sizeof(s->session->challenge), "%ld", ast_random());
03111       }
03112       mansession_lock(s);
03113       astman_start_ack(s, m);
03114       astman_append(s, "Challenge: %s\r\n\r\n", s->session->challenge);
03115       mansession_unlock(s);
03116    } else {
03117       astman_send_error(s, m, "Must specify AuthType");
03118    }
03119    return 0;
03120 }

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

Manager command "command" - execute CLI command.

Definition at line 3634 of file manager.c.

References ast_cli_command, ast_free, ast_log(), AST_LOG_WARNING, ast_malloc, ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), check_blacklist(), errno, LOG_WARNING, and term_strip().

Referenced by __init_manager().

03635 {
03636    const char *cmd = astman_get_header(m, "Command");
03637    const char *id = astman_get_header(m, "ActionID");
03638    char *buf = NULL, *final_buf = NULL;
03639    char template[] = "/tmp/ast-ami-XXXXXX";  /* template for temporary file */
03640    int fd;
03641    off_t l;
03642 
03643    if (ast_strlen_zero(cmd)) {
03644       astman_send_error(s, m, "No command provided");
03645       return 0;
03646    }
03647 
03648    if (check_blacklist(cmd)) {
03649       astman_send_error(s, m, "Command blacklisted");
03650       return 0;
03651    }
03652 
03653    if ((fd = mkstemp(template)) < 0) {
03654       ast_log(AST_LOG_WARNING, "Failed to create temporary file for command: %s\n", strerror(errno));
03655       astman_send_error(s, m, "Command response construction error");
03656       return 0;
03657    }
03658 
03659    astman_append(s, "Response: Follows\r\nPrivilege: Command\r\n");
03660    if (!ast_strlen_zero(id)) {
03661       astman_append(s, "ActionID: %s\r\n", id);
03662    }
03663    /* FIXME: Wedge a ActionID response in here, waiting for later changes */
03664    ast_cli_command(fd, cmd);  /* XXX need to change this to use a FILE * */
03665    /* Determine number of characters available */
03666    if ((l = lseek(fd, 0, SEEK_END)) < 0) {
03667       ast_log(LOG_WARNING, "Failed to determine number of characters for command: %s\n", strerror(errno));
03668       goto action_command_cleanup;
03669    }
03670 
03671    /* This has a potential to overflow the stack.  Hence, use the heap. */
03672    buf = ast_malloc(l + 1);
03673    final_buf = ast_malloc(l + 1);
03674 
03675    if (!buf || !final_buf) {
03676       ast_log(LOG_WARNING, "Failed to allocate memory for temporary buffer\n");
03677       goto action_command_cleanup;
03678    }
03679 
03680    if (lseek(fd, 0, SEEK_SET) < 0) {
03681       ast_log(LOG_WARNING, "Failed to set position on temporary file for command: %s\n", strerror(errno));
03682       goto action_command_cleanup;
03683    }
03684 
03685    if (read(fd, buf, l) < 0) {
03686       ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno));
03687       goto action_command_cleanup;
03688    }
03689 
03690    buf[l] = '\0';
03691    term_strip(final_buf, buf, l);
03692    final_buf[l] = '\0';
03693    astman_append(s, "%s", final_buf);
03694 
03695 action_command_cleanup:
03696 
03697    close(fd);
03698    unlink(template);
03699    astman_append(s, "--END COMMAND--\r\n\r\n");
03700 
03701    ast_free(buf);
03702    ast_free(final_buf);
03703 
03704    return 0;
03705 }

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

Show PBX core settings information.

Definition at line 4370 of file manager.c.

References AMI_VERSION, AST_CLI_YESNO, ast_config_AST_RUN_GROUP, ast_config_AST_RUN_USER, ast_config_AST_SYSTEM_NAME, ast_get_version(), ast_realtime_enabled(), ast_strlen_zero(), astman_append(), astman_get_header(), check_cdr_enabled(), check_webmanager_enabled(), option_maxcalls, option_maxfiles, and option_maxload.

Referenced by __init_manager().

04371 {
04372    const char *actionid = astman_get_header(m, "ActionID");
04373    char idText[150];
04374 
04375    if (!ast_strlen_zero(actionid)) {
04376       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
04377    } else {
04378       idText[0] = '\0';
04379    }
04380 
04381    astman_append(s, "Response: Success\r\n"
04382          "%s"
04383          "AMIversion: %s\r\n"
04384          "AsteriskVersion: %s\r\n"
04385          "SystemName: %s\r\n"
04386          "CoreMaxCalls: %d\r\n"
04387          "CoreMaxLoadAvg: %f\r\n"
04388          "CoreRunUser: %s\r\n"
04389          "CoreRunGroup: %s\r\n"
04390          "CoreMaxFilehandles: %d\r\n"
04391          "CoreRealTimeEnabled: %s\r\n"
04392          "CoreCDRenabled: %s\r\n"
04393          "CoreHTTPenabled: %s\r\n"
04394          "\r\n",
04395          idText,
04396          AMI_VERSION,
04397          ast_get_version(),
04398          ast_config_AST_SYSTEM_NAME,
04399          option_maxcalls,
04400          option_maxload,
04401          ast_config_AST_RUN_USER,
04402          ast_config_AST_RUN_GROUP,
04403          option_maxfiles,
04404          AST_CLI_YESNO(ast_realtime_enabled()),
04405          AST_CLI_YESNO(check_cdr_enabled()),
04406          AST_CLI_YESNO(check_webmanager_enabled())
04407          );
04408    return 0;
04409 }

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

References ast_channel::_state, ast_channel::appl, ast_bridged_channel(), ast_channel_iterator_all_new(), ast_channel_iterator_destroy(), ast_channel_iterator_next(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, ast_state2str(), ast_strlen_zero(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), astman_append(), astman_get_header(), astman_send_error(), astman_send_listack(), ast_channel::caller, ast_channel::cdr, ast_channel::connected, ast_channel::context, ast_channel::data, ast_channel::exten, ast_party_connected_line::id, ast_party_caller::id, ast_party_id::name, ast_party_id::number, ast_channel::priority, S_COR, S_OR, ast_cdr::start, ast_party_name::str, ast_party_number::str, ast_party_name::valid, and ast_party_number::valid.

Referenced by __init_manager().

04480 {
04481    const char *actionid = astman_get_header(m, "ActionID");
04482    char idText[256];
04483    struct ast_channel *c = NULL;
04484    int numchans = 0;
04485    int duration, durh, durm, durs;
04486    struct ast_channel_iterator *iter;
04487 
04488    if (!ast_strlen_zero(actionid)) {
04489       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
04490    } else {
04491       idText[0] = '\0';
04492    }
04493 
04494    if (!(iter = ast_channel_iterator_all_new())) {
04495       astman_send_error(s, m, "Memory Allocation Failure");
04496       return 1;
04497    }
04498 
04499    astman_send_listack(s, m, "Channels will follow", "start");
04500 
04501    for (; (c = ast_channel_iterator_next(iter)); ast_channel_unref(c)) {
04502       struct ast_channel *bc;
04503       char durbuf[10] = "";
04504 
04505       ast_channel_lock(c);
04506 
04507       bc = ast_bridged_channel(c);
04508       if (c->cdr && !ast_tvzero(c->cdr->start)) {
04509          duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000);
04510          durh = duration / 3600;
04511          durm = (duration % 3600) / 60;
04512          durs = duration % 60;
04513          snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs);
04514       }
04515 
04516       astman_append(s,
04517          "Event: CoreShowChannel\r\n"
04518          "%s"
04519          "Channel: %s\r\n"
04520          "UniqueID: %s\r\n"
04521          "Context: %s\r\n"
04522          "Extension: %s\r\n"
04523          "Priority: %d\r\n"
04524          "ChannelState: %d\r\n"
04525          "ChannelStateDesc: %s\r\n"
04526          "Application: %s\r\n"
04527          "ApplicationData: %s\r\n"
04528          "CallerIDnum: %s\r\n"
04529          "CallerIDname: %s\r\n"
04530          "ConnectedLineNum: %s\r\n"
04531          "ConnectedLineName: %s\r\n"
04532          "Duration: %s\r\n"
04533          "AccountCode: %s\r\n"
04534          "BridgedChannel: %s\r\n"
04535          "BridgedUniqueID: %s\r\n"
04536          "\r\n", idText, c->name, c->uniqueid, c->context, c->exten, c->priority, c->_state,
04537          ast_state2str(c->_state), c->appl ? c->appl : "", c->data ? S_OR(c->data, "") : "",
04538          S_COR(c->caller.id.number.valid, c->caller.id.number.str, ""),
04539          S_COR(c->caller.id.name.valid, c->caller.id.name.str, ""),
04540          S_COR(c->connected.id.number.valid, c->connected.id.number.str, ""),
04541          S_COR(c->connected.id.name.valid, c->connected.id.name.str, ""),
04542          durbuf, S_OR(c->accountcode, ""), bc ? bc->name : "", bc ? bc->uniqueid : "");
04543 
04544       ast_channel_unlock(c);
04545 
04546       numchans++;
04547    }
04548 
04549    astman_append(s,
04550       "Event: CoreShowChannelsComplete\r\n"
04551       "EventList: Complete\r\n"
04552       "ListItems: %d\r\n"
04553       "%s"
04554       "\r\n", numchans, idText);
04555 
04556    ast_channel_iterator_destroy(iter);
04557 
04558    return 0;
04559 }

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

Show PBX core status information.

Definition at line 4412 of file manager.c.

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

Referenced by __init_manager().

04413 {
04414    const char *actionid = astman_get_header(m, "ActionID");
04415    char idText[150];
04416    char startuptime[150], startupdate[150];
04417    char reloadtime[150], reloaddate[150];
04418    struct ast_tm tm;
04419 
04420    if (!ast_strlen_zero(actionid)) {
04421       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
04422    } else {
04423       idText[0] = '\0';
04424    }
04425 
04426    ast_localtime(&ast_startuptime, &tm, NULL);
04427    ast_strftime(startuptime, sizeof(startuptime), "%H:%M:%S", &tm);
04428    ast_strftime(startupdate, sizeof(startupdate), "%Y-%m-%d", &tm);
04429    ast_localtime(&ast_lastreloadtime, &tm, NULL);
04430    ast_strftime(reloadtime, sizeof(reloadtime), "%H:%M:%S", &tm);
04431    ast_strftime(reloaddate, sizeof(reloaddate), "%Y-%m-%d", &tm);
04432 
04433    astman_append(s, "Response: Success\r\n"
04434          "%s"
04435          "CoreStartupDate: %s\r\n"
04436          "CoreStartupTime: %s\r\n"
04437          "CoreReloadDate: %s\r\n"
04438          "CoreReloadTime: %s\r\n"
04439          "CoreCurrentCalls: %d\r\n"
04440          "\r\n",
04441          idText,
04442          startupdate,
04443          startuptime,
04444          reloaddate,
04445          reloadtime,
04446          ast_active_channels()
04447          );
04448    return 0;
04449 }

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

Definition at line 2880 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(), and errno.

Referenced by __init_manager().

02881 {
02882    int fd;
02883    const char *fn = astman_get_header(m, "Filename");
02884    struct ast_str *filepath = ast_str_alloca(PATH_MAX);
02885    ast_str_set(&filepath, 0, "%s/", ast_config_AST_CONFIG_DIR);
02886    ast_str_append(&filepath, 0, "%s", fn);
02887 
02888    if ((fd = open(ast_str_buffer(filepath), O_CREAT | O_EXCL, AST_FILE_MODE)) != -1) {
02889       close(fd);
02890       astman_send_ack(s, m, "New configuration file created successfully");
02891    } else {
02892       astman_send_error(s, m, strerror(errno));
02893    }
02894 
02895    return 0;
02896 }

static void action_destroy ( void *  obj  )  [static]

Definition at line 5350 of file manager.c.

References ast_string_field_free_memory.

Referenced by ast_manager_register2().

05351 {
05352    struct manager_action *doomed = obj;
05353 
05354    if (doomed->synopsis) {
05355       /* The string fields were initialized. */
05356       ast_string_field_free_memory(doomed);
05357    }
05358 }

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

Definition at line 3023 of file manager.c.

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

Referenced by __init_manager().

03024 {
03025    const char *mask = astman_get_header(m, "EventMask");
03026    int res, x;
03027    const char *id = astman_get_header(m, "ActionID");
03028    char id_text[256];
03029 
03030    if (!ast_strlen_zero(id)) {
03031       snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id);
03032    } else {
03033       id_text[0] = '\0';
03034    }
03035 
03036    res = set_eventmask(s, mask);
03037    if (broken_events_action) {
03038       /* if this option is set we should not return a response on
03039        * error, or when all events are set */
03040 
03041       if (res > 0) {
03042          for (x = 0; x < ARRAY_LEN(perms); x++) {
03043             if (!strcasecmp(perms[x].label, "all") && res == perms[x].num) {
03044                return 0;
03045             }
03046          }
03047          astman_append(s, "Response: Success\r\n%s"
03048                 "Events: On\r\n\r\n", id_text);
03049       } else if (res == 0)
03050          astman_append(s, "Response: Success\r\n%s"
03051                 "Events: Off\r\n\r\n", id_text);
03052       return 0;
03053    }
03054 
03055    if (res > 0)
03056       astman_append(s, "Response: Success\r\n%s"
03057              "Events: On\r\n\r\n", id_text);
03058    else if (res == 0)
03059       astman_append(s, "Response: Success\r\n%s"
03060              "Events: Off\r\n\r\n", id_text);
03061    else
03062       astman_send_error(s, m, "Invalid event mask");
03063 
03064    return 0;
03065 }

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

Definition at line 4208 of file manager.c.

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

Referenced by __init_manager().

04209 {
04210    const char *exten = astman_get_header(m, "Exten");
04211    const char *context = astman_get_header(m, "Context");
04212    char hint[256] = "";
04213    int status;
04214    if (ast_strlen_zero(exten)) {
04215       astman_send_error(s, m, "Extension not specified");
04216       return 0;
04217    }
04218    if (ast_strlen_zero(context)) {
04219       context = "default";
04220    }
04221    status = ast_extension_state(NULL, context, exten);
04222    ast_get_hint(hint, sizeof(hint) - 1, NULL, 0, NULL, context, exten);
04223    astman_start_ack(s, m);
04224    astman_append(s,   "Message: Extension Status\r\n"
04225             "Exten: %s\r\n"
04226             "Context: %s\r\n"
04227             "Hint: %s\r\n"
04228             "Status: %d\r\n\r\n",
04229             exten, context, hint, status);
04230    return 0;
04231 }

static struct manager_action* action_find ( const char *  name  )  [static, read]

Definition at line 1073 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().

01074 {
01075    struct manager_action *act;
01076 
01077    AST_RWLIST_RDLOCK(&actions);
01078    AST_RWLIST_TRAVERSE(&actions, act, list) {
01079       if (!strcasecmp(name, act->action)) {
01080          ao2_t_ref(act, +1, "found action object");
01081          break;
01082       }
01083    }
01084    AST_RWLIST_UNLOCK(&actions);
01085 
01086    return act;
01087 }

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

Definition at line 2498 of file manager.c.

References ast_category_browse(), ast_config_destroy(), ast_config_load2(), ast_strlen_zero(), ast_variable_browse(), 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, ast_variable::name, ast_variable::next, and ast_variable::value.

Referenced by __init_manager().

02499 {
02500    struct ast_config *cfg;
02501    const char *fn = astman_get_header(m, "Filename");
02502    const char *category = astman_get_header(m, "Category");
02503    int catcount = 0;
02504    int lineno = 0;
02505    char *cur_category = NULL;
02506    struct ast_variable *v;
02507    struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE };
02508 
02509    if (ast_strlen_zero(fn)) {
02510       astman_send_error(s, m, "Filename not specified");
02511       return 0;
02512    }
02513    cfg = ast_config_load2(fn, "manager", config_flags);
02514    if (cfg == CONFIG_STATUS_FILEMISSING) {
02515       astman_send_error(s, m, "Config file not found");
02516       return 0;
02517    } else if (cfg == CONFIG_STATUS_FILEINVALID) {
02518       astman_send_error(s, m, "Config file has invalid format");
02519       return 0;
02520    }
02521 
02522    astman_start_ack(s, m);
02523    while ((cur_category = ast_category_browse(cfg, cur_category))) {
02524       if (ast_strlen_zero(category) || (!ast_strlen_zero(category) && !strcmp(category, cur_category))) {
02525          lineno = 0;
02526          astman_append(s, "Category-%06d: %s\r\n", catcount, cur_category);
02527          for (v = ast_variable_browse(cfg, cur_category); v; v = v->next) {
02528             astman_append(s, "Line-%06d-%06d: %s=%s\r\n", catcount, lineno++, v->name, v->value);
02529          }
02530          catcount++;
02531       }
02532    }
02533    if (!ast_strlen_zero(category) && catcount == 0) { /* TODO: actually, a config with no categories doesn't even get loaded */
02534       astman_append(s, "No categories found\r\n");
02535    }
02536    ast_config_destroy(cfg);
02537    astman_append(s, "\r\n");
02538 
02539    return 0;
02540 }

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

Definition at line 2608 of file manager.c.

References ast_category_browse(), ast_config_destroy(), ast_config_load2(), ast_strlen_zero(), ast_variable_browse(), 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, ast_variable::name, ast_variable::next, and ast_variable::value.

Referenced by __init_manager().

02609 {
02610    struct ast_config *cfg;
02611    const char *fn = astman_get_header(m, "Filename");
02612    char *category = NULL;
02613    struct ast_variable *v;
02614    int comma1 = 0;
02615    struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE };
02616 
02617    if (ast_strlen_zero(fn)) {
02618       astman_send_error(s, m, "Filename not specified");
02619       return 0;
02620    }
02621 
02622    if (!(cfg = ast_config_load2(fn, "manager", config_flags))) {
02623       astman_send_error(s, m, "Config file not found");
02624       return 0;
02625    } else if (cfg == CONFIG_STATUS_FILEINVALID) {
02626       astman_send_error(s, m, "Config file has invalid format");
02627       return 0;
02628    }
02629 
02630    astman_start_ack(s, m);
02631    astman_append(s, "JSON: {");
02632    while ((category = ast_category_browse(cfg, category))) {
02633       int comma2 = 0;
02634 
02635       astman_append(s, "%s\"", comma1 ? "," : "");
02636       astman_append_json(s, category);
02637       astman_append(s, "\":[");
02638       comma1 = 1;
02639       for (v = ast_variable_browse(cfg, category); v; v = v->next) {
02640          astman_append(s, "%s\"", comma2 ? "," : "");
02641          astman_append_json(s, v->name);
02642          astman_append(s, "\":\"");
02643          astman_append_json(s, v->value);
02644          astman_append(s, "\"");
02645          comma2 = 1;
02646       }
02647       astman_append(s, "]");
02648    }
02649    astman_append(s, "}\r\n\r\n");
02650 
02651    ast_config_destroy(cfg);
02652 
02653    return 0;
02654 }

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

Definition at line 3198 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(), function_capable_string_allowed_with_auths(), LOG_ERROR, pbx_retrieve_variable(), S_OR, mansession::session, and mansession_session::writeperm.

Referenced by __init_manager().

03199 {
03200    struct ast_channel *c = NULL;
03201    const char *name = astman_get_header(m, "Channel");
03202    const char *varname = astman_get_header(m, "Variable");
03203    char *varval;
03204    char workspace[1024];
03205 
03206    if (ast_strlen_zero(varname)) {
03207       astman_send_error(s, m, "No variable specified");
03208       return 0;
03209    }
03210 
03211    /* We don't want users with insufficient permissions using certain functions. */
03212    if (!(function_capable_string_allowed_with_auths(varname, s->session->writeperm))) {
03213       astman_send_error(s, m, "GetVar Access Forbidden: Variable");
03214       return 0;
03215    }
03216 
03217    if (!ast_strlen_zero(name)) {
03218       if (!(c = ast_channel_get_by_name(name))) {
03219          astman_send_error(s, m, "No such channel");
03220          return 0;
03221       }
03222    }
03223 
03224    workspace[0] = '\0';
03225    if (varname[strlen(varname) - 1] == ')') {
03226       if (!c) {
03227          c = ast_dummy_channel_alloc();
03228          if (c) {
03229             ast_func_read(c, (char *) varname, workspace, sizeof(workspace));
03230          } else
03231             ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution.  Function results may be blank.\n");
03232       } else {
03233          ast_func_read(c, (char *) varname, workspace, sizeof(workspace));
03234       }
03235       varval = workspace;
03236    } else {
03237       pbx_retrieve_variable(c, varname, &varval, workspace, sizeof(workspace), NULL);
03238    }
03239 
03240    if (c) {
03241       c = ast_channel_unref(c);
03242    }
03243 
03244    astman_start_ack(s, m);
03245    astman_append(s, "Variable: %s\r\nValue: %s\r\n\r\n", varname, S_OR(varval, ""));
03246 
03247    return 0;
03248 }

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

Definition at line 3122 of file manager.c.

References ast_channel_get_by_name(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, ast_debug, ast_log(), AST_SOFTHANGUP_EXPLICIT, ast_softhangup_nolock(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), cause, ast_channel::hangupcause, and LOG_NOTICE.

Referenced by __init_manager().

03123 {
03124    struct ast_channel *c = NULL;
03125    int causecode = 0; /* all values <= 0 mean 'do not set hangupcause in channel' */
03126    const char *name = astman_get_header(m, "Channel");
03127    const char *cause = astman_get_header(m, "Cause");
03128 
03129    if (ast_strlen_zero(name)) {
03130       astman_send_error(s, m, "No channel specified");
03131       return 0;
03132    }
03133 
03134    if (!ast_strlen_zero(cause)) {
03135       char *endptr;
03136       causecode = strtol(cause, &endptr, 10);
03137       if (causecode < 0 || causecode > 127 || *endptr != '\0') {
03138          ast_log(LOG_NOTICE, "Invalid 'Cause: %s' in manager action Hangup\n", cause);
03139          /* keep going, better to hangup without cause than to not hang up at all */
03140          causecode = 0; /* do not set channel's hangupcause */
03141       }
03142    }
03143 
03144    if (!(c = ast_channel_get_by_name(name))) {
03145       astman_send_error(s, m, "No such channel");
03146       return 0;
03147    }
03148 
03149    ast_channel_lock(c);
03150    if (causecode > 0) {
03151       ast_debug(1, "Setting hangupcause of channel %s to %d (is %d now)\n",
03152             c->name, causecode, c->hangupcause);
03153       c->hangupcause = causecode;
03154    }
03155    ast_softhangup_nolock(c, AST_SOFTHANGUP_EXPLICIT);
03156    ast_channel_unlock(c);
03157 
03158    c = ast_channel_unref(c);
03159 
03160    astman_send_ack(s, m, "Channel Hungup");
03161 
03162    return 0;
03163 }

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

Definition at line 2542 of file manager.c.

References ast_category_browse(), 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, and CONFIG_STATUS_FILEINVALID.

Referenced by __init_manager().

02543 {
02544    struct ast_config *cfg;
02545    const char *fn = astman_get_header(m, "Filename");
02546    char *category = NULL;
02547    struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE };
02548    int catcount = 0;
02549 
02550    if (ast_strlen_zero(fn)) {
02551       astman_send_error(s, m, "Filename not specified");
02552       return 0;
02553    }
02554    if (!(cfg = ast_config_load2(fn, "manager", config_flags))) {
02555       astman_send_error(s, m, "Config file not found");
02556       return 0;
02557    } else if (cfg == CONFIG_STATUS_FILEINVALID) {
02558       astman_send_error(s, m, "Config file has invalid format");
02559       return 0;
02560    }
02561    astman_start_ack(s, m);
02562    while ((category = ast_category_browse(cfg, category))) {
02563       astman_append(s, "Category-%06d: %s\r\n", catcount, category);
02564       catcount++;
02565    }
02566    if (catcount == 0) { /* TODO: actually, a config with no categories doesn't even get loaded */
02567       astman_append(s, "Error: no categories found\r\n");
02568    }
02569    ast_config_destroy(cfg);
02570    astman_append(s, "\r\n");
02571 
02572    return 0;
02573 }

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

Definition at line 3004 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(), mansession::session, and mansession_session::writeperm.

Referenced by __init_manager().

03005 {
03006    struct manager_action *cur;
03007    struct ast_str *temp = ast_str_alloca(256);
03008 
03009    astman_start_ack(s, m);
03010    AST_RWLIST_RDLOCK(&actions);
03011    AST_RWLIST_TRAVERSE(&actions, cur, list) {
03012       if ((s->session->writeperm & cur->authority) || cur->authority == 0) {
03013          astman_append(s, "%s: %s (Priv: %s)\r\n",
03014             cur->action, cur->synopsis, authority_to_str(cur->authority, &temp));
03015       }
03016    }
03017    AST_RWLIST_UNLOCK(&actions);
03018    astman_append(s, "\r\n");
03019 
03020    return 0;
03021 }

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

Definition at line 3073 of file manager.c.

References ast_atomic_fetchadd_int(), ast_inet_ntoa(), AST_OPT_FLAG_FULLY_BOOTED, ast_options, ast_str_alloca, ast_test_flag, 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, mansession_session::send_events, mansession::session, mansession_session::sin, unauth_sessions, and mansession_session::username.

Referenced by __init_manager().

03074 {
03075 
03076    /* still authenticated - don't process again */
03077    if (s->session->authenticated) {
03078       astman_send_ack(s, m, "Already authenticated");
03079       return 0;
03080    }
03081 
03082    if (authenticate(s, m)) {
03083       sleep(1);
03084       astman_send_error(s, m, "Authentication failed");
03085       return -1;
03086    }
03087    s->session->authenticated = 1;
03088    ast_atomic_fetchadd_int(&unauth_sessions, -1);
03089    if (manager_displayconnects(s->session)) {
03090       ast_verb(2, "%sManager '%s' logged on from %s\n", (s->session->managerid ? "HTTP " : ""), s->session->username, ast_inet_ntoa(s->session->sin.sin_addr));
03091    }
03092    astman_send_ack(s, m, "Authentication accepted");
03093    if ((s->session->send_events & EVENT_FLAG_SYSTEM)
03094       && ast_test_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED)) {
03095       struct ast_str *auth = ast_str_alloca(80);
03096       const char *cat_str = authority_to_str(EVENT_FLAG_SYSTEM, &auth);
03097       astman_append(s, "Event: FullyBooted\r\n"
03098          "Privilege: %s\r\n"
03099          "Status: Fully Booted\r\n\r\n", cat_str);
03100    }
03101    return 0;
03102 }

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

Definition at line 3067 of file manager.c.

References astman_send_response().

Referenced by __init_manager().

03068 {
03069    astman_send_response(s, m, "Goodbye", "Thanks for all the fish.");
03070    return -1;
03071 }

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

Definition at line 4187 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().

04188 {
04189    const char *mailbox = astman_get_header(m, "Mailbox");
04190    int newmsgs = 0, oldmsgs = 0, urgentmsgs = 0;;
04191 
04192    if (ast_strlen_zero(mailbox)) {
04193       astman_send_error(s, m, "Mailbox not specified");
04194       return 0;
04195    }
04196    ast_app_inboxcount2(mailbox, &urgentmsgs, &newmsgs, &oldmsgs);
04197    astman_start_ack(s, m);
04198    astman_append(s,   "Message: Mailbox Message Count\r\n"
04199             "Mailbox: %s\r\n"
04200             "UrgMessages: %d\r\n"
04201             "NewMessages: %d\r\n"
04202             "OldMessages: %d\r\n"
04203             "\r\n",
04204             mailbox, urgentmsgs, newmsgs, oldmsgs);
04205    return 0;
04206 }

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

Definition at line 4170 of file manager.c.

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

Referenced by __init_manager().

04171 {
04172    const char *mailbox = astman_get_header(m, "Mailbox");
04173    int ret;
04174 
04175    if (ast_strlen_zero(mailbox)) {
04176       astman_send_error(s, m, "Mailbox not specified");
04177       return 0;
04178    }
04179    ret = ast_app_has_voicemail(mailbox, NULL);
04180    astman_start_ack(s, m);
04181    astman_append(s, "Message: Mailbox Status\r\n"
04182           "Mailbox: %s\r\n"
04183           "Waiting: %d\r\n\r\n", mailbox, ret);
04184    return 0;
04185 }

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

Definition at line 4026 of file manager.c.

References app, ast_callerid_parse(), ast_calloc, ast_copy_string(), ast_findlabel_extension(), AST_FORMAT_SLINEAR, ast_free, ast_parse_allow_disallow(), 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(), astman_get_header(), astman_get_variables(), astman_send_ack(), astman_send_error(), cid_name, cid_num, context, ast_frame::data, destroy_fast_originate_helper(), EVENT_FLAG_SYSTEM, exten, fast_originate(), fast_originate_helper::format, fast_originate_helper::priority, mansession::session, fast_originate_helper::timeout, fast_originate_helper::vars, and mansession_session::writeperm.

Referenced by __init_manager().

04027 {
04028    const char *name = astman_get_header(m, "Channel");
04029    const char *exten = astman_get_header(m, "Exten");
04030    const char *context = astman_get_header(m, "Context");
04031    const char *priority = astman_get_header(m, "Priority");
04032    const char *timeout = astman_get_header(m, "Timeout");
04033    const char *callerid = astman_get_header(m, "CallerID");
04034    const char *account = astman_get_header(m, "Account");
04035    const char *app = astman_get_header(m, "Application");
04036    const char *appdata = astman_get_header(m, "Data");
04037    const char *async = astman_get_header(m, "Async");
04038    const char *id = astman_get_header(m, "ActionID");
04039    const char *codecs = astman_get_header(m, "Codecs");
04040    struct ast_variable *vars;
04041    char *tech, *data;
04042    char *l = NULL, *n = NULL;
04043    int pi = 0;
04044    int res;
04045    int to = 30000;
04046    int reason = 0;
04047    char tmp[256];
04048    char tmp2[256];
04049    format_t format = AST_FORMAT_SLINEAR;
04050 
04051    pthread_t th;
04052    if (ast_strlen_zero(name)) {
04053       astman_send_error(s, m, "Channel not specified");
04054       return 0;
04055    }
04056    if (!ast_strlen_zero(priority) && (sscanf(priority, "%30d", &pi) != 1)) {
04057       if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) {
04058          astman_send_error(s, m, "Invalid priority");
04059          return 0;
04060       }
04061    }
04062    if (!ast_strlen_zero(timeout) && (sscanf(timeout, "%30d", &to) != 1)) {
04063       astman_send_error(s, m, "Invalid timeout");
04064       return 0;
04065    }
04066    ast_copy_string(tmp, name, sizeof(tmp));
04067    tech = tmp;
04068    data = strchr(tmp, '/');
04069    if (!data) {
04070       astman_send_error(s, m, "Invalid channel");
04071       return 0;
04072    }
04073    *data++ = '\0';
04074    ast_copy_string(tmp2, callerid, sizeof(tmp2));
04075    ast_callerid_parse(tmp2, &n, &l);
04076    if (n) {
04077       if (ast_strlen_zero(n)) {
04078          n = NULL;
04079       }
04080    }
04081    if (l) {
04082       ast_shrink_phone_number(l);
04083       if (ast_strlen_zero(l)) {
04084          l = NULL;
04085       }
04086    }
04087    if (!ast_strlen_zero(codecs)) {
04088       format = 0;
04089       ast_parse_allow_disallow(NULL, &format, codecs, 1);
04090    }
04091    if (!ast_strlen_zero(app) && s->session) {
04092       int bad_appdata = 0;
04093       /* To run the System application (or anything else that goes to
04094        * shell), you must have the additional System privilege */
04095       if (!(s->session->writeperm & EVENT_FLAG_SYSTEM)
04096          && (
04097             strcasestr(app, "system") ||      /* System(rm -rf /)
04098                                                  TrySystem(rm -rf /)       */
04099             strcasestr(app, "exec") ||        /* Exec(System(rm -rf /))
04100                                                  TryExec(System(rm -rf /)) */
04101             strcasestr(app, "agi") ||         /* AGI(/bin/rm,-rf /)
04102                                                  EAGI(/bin/rm,-rf /)       */
04103             strcasestr(app, "mixmonitor") ||  /* MixMonitor(blah,,rm -rf)  */
04104             strcasestr(app, "externalivr") || /* ExternalIVR(rm -rf)       */
04105             (strstr(appdata, "SHELL") && (bad_appdata = 1)) ||       /* NoOp(${SHELL(rm -rf /)})  */
04106             (strstr(appdata, "EVAL") && (bad_appdata = 1))           /* NoOp(${EVAL(${some_var_containing_SHELL})}) */
04107             )) {
04108          char error_buf[64];
04109          snprintf(error_buf, sizeof(error_buf), "Originate Access Forbidden: %s", bad_appdata ? "Data" : "Application");
04110          astman_send_error(s, m, error_buf);
04111          return 0;
04112       }
04113    }
04114    /* Allocate requested channel variables */
04115    vars = astman_get_variables(m);
04116 
04117    if (ast_true(async)) {
04118       struct fast_originate_helper *fast;
04119 
04120       fast = ast_calloc(1, sizeof(*fast));
04121       if (!fast || ast_string_field_init(fast, 252)) {
04122          ast_free(fast);
04123          ast_variables_destroy(vars);
04124          res = -1;
04125       } else {
04126          if (!ast_strlen_zero(id)) {
04127             ast_string_field_build(fast, idtext, "ActionID: %s\r\n", id);
04128          }
04129          ast_string_field_set(fast, tech, tech);
04130          ast_string_field_set(fast, data, data);
04131          ast_string_field_set(fast, app, app);
04132          ast_string_field_set(fast, appdata, appdata);
04133          ast_string_field_set(fast, cid_num, l);
04134          ast_string_field_set(fast, cid_name, n);
04135          ast_string_field_set(fast, context, context);
04136          ast_string_field_set(fast, exten, exten);
04137          ast_string_field_set(fast, account, account);
04138          fast->vars = vars;
04139          fast->format = format;
04140          fast->timeout = to;
04141          fast->priority = pi;
04142          if (ast_pthread_create_detached(&th, NULL, fast_originate, fast)) {
04143             destroy_fast_originate_helper(fast);
04144             res = -1;
04145          } else {
04146             res = 0;
04147          }
04148       }
04149    } else if (!ast_strlen_zero(app)) {
04150       res = ast_pbx_outgoing_app(tech, format, data, to, app, appdata, &reason, 1, l, n, vars, account, NULL);
04151       /* Any vars memory was passed to ast_pbx_outgoing_app(). */
04152    } else {
04153       if (exten && context && pi) {
04154          res = ast_pbx_outgoing_exten(tech, format, data, to, context, exten, pi, &reason, 1, l, n, vars, account, NULL);
04155          /* Any vars memory was passed to ast_pbx_outgoing_exten(). */
04156       } else {
04157          astman_send_error(s, m, "Originate with 'Exten' requires 'Context' and 'Priority'");
04158          ast_variables_destroy(vars);
04159          return 0;
04160       }
04161    }
04162    if (!res) {
04163       astman_send_ack(s, m, "Originate successfully queued");
04164    } else {
04165       astman_send_error(s, m, "Originate failed");
04166    }
04167    return 0;
04168 }

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

Definition at line 2480 of file manager.c.

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

Referenced by __init_manager().

02481 {
02482    const char *actionid = astman_get_header(m, "ActionID");
02483    struct timeval now = ast_tvnow();
02484 
02485    astman_append(s, "Response: Success\r\n");
02486    if (!ast_strlen_zero(actionid)){
02487       astman_append(s, "ActionID: %s\r\n", actionid);
02488    }
02489    astman_append(
02490       s,
02491       "Ping: Pong\r\n"
02492       "Timestamp: %ld.%06lu\r\n"
02493       "\r\n",
02494       (long) now.tv_sec, (unsigned long) now.tv_usec);
02495    return 0;
02496 }

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

action_redirect: The redirect manager command

Definition at line 3449 of file manager.c.

References ast_async_goto(), ast_channel_get_by_name(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, ast_check_hangup_locked(), ast_findlabel_extension(), AST_FLAG_BRIDGE_HANGUP_DONT, ast_set_flag, ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), context, exten, ast_channel::pbx, and ast_channel::priority.

Referenced by __init_manager().

03450 {
03451    const char *name = astman_get_header(m, "Channel");
03452    const char *name2 = astman_get_header(m, "ExtraChannel");
03453    const char *exten = astman_get_header(m, "Exten");
03454    const char *exten2 = astman_get_header(m, "ExtraExten");
03455    const char *context = astman_get_header(m, "Context");
03456    const char *context2 = astman_get_header(m, "ExtraContext");
03457    const char *priority = astman_get_header(m, "Priority");
03458    const char *priority2 = astman_get_header(m, "ExtraPriority");
03459    struct ast_channel *chan, *chan2 = NULL;
03460    int pi, pi2 = 0;
03461    int res;
03462 
03463    if (ast_strlen_zero(name)) {
03464       astman_send_error(s, m, "Channel not specified");
03465       return 0;
03466    }
03467 
03468    if (!ast_strlen_zero(priority) && (sscanf(priority, "%30d", &pi) != 1)) {
03469       if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) {
03470          astman_send_error(s, m, "Invalid priority");
03471          return 0;
03472       }
03473    }
03474 
03475    if (!ast_strlen_zero(priority2) && (sscanf(priority2, "%30d", &pi2) != 1)) {
03476       if ((pi2 = ast_findlabel_extension(NULL, context2, exten2, priority2, NULL)) < 1) {
03477          astman_send_error(s, m, "Invalid ExtraPriority");
03478          return 0;
03479       }
03480    }
03481 
03482    if (!(chan = ast_channel_get_by_name(name))) {
03483       char buf[256];
03484       snprintf(buf, sizeof(buf), "Channel does not exist: %s", name);
03485       astman_send_error(s, m, buf);
03486       return 0;
03487    }
03488 
03489    if (ast_check_hangup_locked(chan)) {
03490       astman_send_error(s, m, "Redirect failed, channel not up.");
03491       chan = ast_channel_unref(chan);
03492       return 0;
03493    }
03494 
03495    if (!ast_strlen_zero(name2)) {
03496       chan2 = ast_channel_get_by_name(name2);
03497    }
03498 
03499    if (chan2 && ast_check_hangup_locked(chan2)) {
03500       astman_send_error(s, m, "Redirect failed, extra channel not up.");
03501       chan = ast_channel_unref(chan);
03502       chan2 = ast_channel_unref(chan2);
03503       return 0;
03504    }
03505 
03506    if (chan->pbx) {
03507       ast_channel_lock(chan);
03508       ast_set_flag(chan, AST_FLAG_BRIDGE_HANGUP_DONT); /* don't let the after-bridge code run the h-exten */
03509       ast_channel_unlock(chan);
03510    }
03511 
03512    res = ast_async_goto(chan, context, exten, pi);
03513    if (!res) {
03514       if (!ast_strlen_zero(name2)) {
03515          if (chan2) {
03516             if (chan2->pbx) {
03517                ast_channel_lock(chan2);
03518                ast_set_flag(chan2, AST_FLAG_BRIDGE_HANGUP_DONT); /* don't let the after-bridge code run the h-exten */
03519                ast_channel_unlock(chan2);
03520             }
03521             if (!ast_strlen_zero(context2)) {
03522                res = ast_async_goto(chan2, context2, exten2, pi2);
03523             } else {
03524                res = ast_async_goto(chan2, context, exten, pi);
03525             }
03526          } else {
03527             res = -1;
03528          }
03529          if (!res) {
03530             astman_send_ack(s, m, "Dual Redirect successful");
03531          } else {
03532             astman_send_error(s, m, "Secondary redirect failed");
03533          }
03534       } else {
03535          astman_send_ack(s, m, "Redirect successful");
03536       }
03537    } else {
03538       astman_send_error(s, m, "Redirect failed");
03539    }
03540 
03541    chan = ast_channel_unref(chan);
03542    if (chan2) {
03543       chan2 = ast_channel_unref(chan2);
03544    }
03545 
03546    return 0;
03547 }

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

Send a reload event.

Definition at line 4452 of file manager.c.

References ast_module_reload(), astman_get_header(), astman_send_ack(), astman_send_error(), and S_OR.

Referenced by __init_manager().

04453 {
04454    const char *module = astman_get_header(m, "Module");
04455    int res = ast_module_reload(S_OR(module, NULL));
04456 
04457    switch (res) {
04458    case -1:
04459       astman_send_error(s, m, "A reload is in progress");
04460       break;
04461    case 0:
04462       astman_send_error(s, m, "No such module");
04463       break;
04464    case 1:
04465       astman_send_error(s, m, "Module does not support reload");
04466       break;
04467    case 2:
04468       astman_send_ack(s, m, "Module Reloaded");
04469       break;
04470    default:
04471       astman_send_error(s, m, "An unknown error occurred");
04472       break;
04473    }
04474    return 0;
04475 }

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

Definition at line 3414 of file manager.c.

References ast_channel_get_by_name(), ast_channel_unref, ast_sendtext(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), and astman_send_error().

Referenced by __init_manager().

03415 {
03416    struct ast_channel *c = NULL;
03417    const char *name = astman_get_header(m, "Channel");
03418    const char *textmsg = astman_get_header(m, "Message");
03419    int res = 0;
03420 
03421    if (ast_strlen_zero(name)) {
03422       astman_send_error(s, m, "No channel specified");
03423       return 0;
03424    }
03425 
03426    if (ast_strlen_zero(textmsg)) {
03427       astman_send_error(s, m, "No Message specified");
03428       return 0;
03429    }
03430 
03431    if (!(c = ast_channel_get_by_name(name))) {
03432       astman_send_error(s, m, "No such channel");
03433       return 0;
03434    }
03435 
03436    res = ast_sendtext(c, textmsg);
03437    c = ast_channel_unref(c);
03438 
03439    if (res >= 0) {
03440       astman_send_ack(s, m, "Success");
03441    } else {
03442       astman_send_error(s, m, "Failure");
03443    }
03444 
03445    return res;
03446 }

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

Definition at line 3165 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(), pbx_builtin_setvar_helper(), and S_OR.

Referenced by __init_manager().

03166 {
03167    struct ast_channel *c = NULL;
03168    const char *name = astman_get_header(m, "Channel");
03169    const char *varname = astman_get_header(m, "Variable");
03170    const char *varval = astman_get_header(m, "Value");
03171    int res = 0;
03172    
03173    if (ast_strlen_zero(varname)) {
03174       astman_send_error(s, m, "No variable specified");
03175       return 0;
03176    }
03177 
03178    if (!ast_strlen_zero(name)) {
03179       if (!(c = ast_channel_get_by_name(name))) {
03180          astman_send_error(s, m, "No such channel");
03181          return 0;
03182       }
03183    }
03184 
03185    res = pbx_builtin_setvar_helper(c, varname, S_OR(varval, ""));
03186 
03187    if (c) {
03188       c = ast_channel_unref(c);
03189    }
03190    if (res == 0) {
03191       astman_send_ack(s, m, "Variable Set"); 
03192    } else {
03193       astman_send_error(s, m, "Variable not set");
03194    }
03195    return 0;
03196 }

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

Manager "status" command to show channels.

Definition at line 3252 of file manager.c.

References ast_channel::_bridge, ast_channel::_state, 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_free, ast_func_read(), AST_STANDARD_APP_ARGS, ast_state2str(), ast_str_append(), ast_str_buffer(), ast_str_create(), ast_str_reset(), ast_strdupa, ast_strlen_zero(), ast_tvnow(), astman_append(), astman_get_header(), astman_send_ack(), astman_send_error(), ast_channel::bridge, ast_channel::caller, ast_channel::cdr, channels, ast_channel::connected, ast_channel::context, ast_channel::exten, function_capable_string_allowed_with_auths(), ast_party_connected_line::id, ast_party_caller::id, ast_party_id::name, ast_party_id::number, ast_channel::pbx, pbx_retrieve_variable(), ast_channel::priority, S_COR, S_OR, mansession::session, ast_cdr::start, ast_party_name::str, ast_party_number::str, str, ast_party_name::valid, ast_party_number::valid, and mansession_session::writeperm.

Referenced by __init_manager().

03253 {
03254    const char *name = astman_get_header(m, "Channel");
03255    const char *cvariables = astman_get_header(m, "Variables");
03256    char *variables = ast_strdupa(S_OR(cvariables, ""));
03257    struct ast_channel *c;
03258    char bridge[256];
03259    struct timeval now = ast_tvnow();
03260    long elapsed_seconds = 0;
03261    int channels = 0;
03262    int all = ast_strlen_zero(name); /* set if we want all channels */
03263    const char *id = astman_get_header(m, "ActionID");
03264    char idText[256];
03265    AST_DECLARE_APP_ARGS(vars,
03266       AST_APP_ARG(name)[100];
03267    );
03268    struct ast_str *str = ast_str_create(1000);
03269    struct ast_channel_iterator *iter = NULL;
03270 
03271    if (!ast_strlen_zero(id)) {
03272       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
03273    } else {
03274       idText[0] = '\0';
03275    }
03276 
03277    if (!(function_capable_string_allowed_with_auths(variables, s->session->writeperm))) {
03278       astman_send_error(s, m, "Status Access Forbidden: Variables");
03279       return 0;
03280    }
03281 
03282    if (all) {
03283       if (!(iter = ast_channel_iterator_all_new())) {
03284          ast_free(str);
03285          astman_send_error(s, m, "Memory Allocation Failure");
03286          return 1;
03287       }
03288       c = ast_channel_iterator_next(iter);
03289    } else {
03290       if (!(c = ast_channel_get_by_name(name))) {
03291          astman_send_error(s, m, "No such channel");
03292          ast_free(str);
03293          return 0;
03294       }
03295    }
03296 
03297    astman_send_ack(s, m, "Channel status will follow");
03298 
03299    if (!ast_strlen_zero(cvariables)) {
03300       AST_STANDARD_APP_ARGS(vars, variables);
03301    }
03302 
03303    /* if we look by name, we break after the first iteration */
03304    for (; c; c = ast_channel_iterator_next(iter)) {
03305       ast_channel_lock(c);
03306 
03307       if (!ast_strlen_zero(cvariables)) {
03308          int i;
03309          ast_str_reset(str);
03310          for (i = 0; i < vars.argc; i++) {
03311             char valbuf[512], *ret = NULL;
03312 
03313             if (vars.name[i][strlen(vars.name[i]) - 1] == ')') {
03314                if (ast_func_read(c, vars.name[i], valbuf, sizeof(valbuf)) < 0) {
03315                   valbuf[0] = '\0';
03316                }
03317                ret = valbuf;
03318             } else {
03319                pbx_retrieve_variable(c, vars.name[i], &ret, valbuf, sizeof(valbuf), NULL);
03320             }
03321 
03322             ast_str_append(&str, 0, "Variable: %s=%s\r\n", vars.name[i], ret);
03323          }
03324       }
03325 
03326       channels++;
03327       if (c->_bridge) {
03328          snprintf(bridge, sizeof(bridge), "BridgedChannel: %s\r\nBridgedUniqueid: %s\r\n", c->_bridge->name, c->_bridge->uniqueid);
03329       } else {
03330          bridge[0] = '\0';
03331       }
03332       if (c->pbx) {
03333          if (c->cdr) {
03334             elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
03335          }
03336          astman_append(s,
03337          "Event: Status\r\n"
03338          "Privilege: Call\r\n"
03339          "Channel: %s\r\n"
03340          "CallerIDNum: %s\r\n"
03341          "CallerIDName: %s\r\n"
03342          "ConnectedLineNum: %s\r\n"
03343          "ConnectedLineName: %s\r\n"
03344          "Accountcode: %s\r\n"
03345          "ChannelState: %d\r\n"
03346          "ChannelStateDesc: %s\r\n"
03347          "Context: %s\r\n"
03348          "Extension: %s\r\n"
03349          "Priority: %d\r\n"
03350          "Seconds: %ld\r\n"
03351          "%s"
03352          "Uniqueid: %s\r\n"
03353          "%s"
03354          "%s"
03355          "\r\n",
03356          c->name,
03357          S_COR(c->caller.id.number.valid, c->caller.id.number.str, "<unknown>"),
03358          S_COR(c->caller.id.name.valid, c->caller.id.name.str, "<unknown>"),
03359          S_COR(c->connected.id.number.valid, c->connected.id.number.str, "<unknown>"),
03360          S_COR(c->connected.id.name.valid, c->connected.id.name.str, "<unknown>"),
03361          c->accountcode,
03362          c->_state,
03363          ast_state2str(c->_state), c->context,
03364          c->exten, c->priority, (long)elapsed_seconds, bridge, c->uniqueid, ast_str_buffer(str), idText);
03365       } else {
03366          astman_append(s,
03367             "Event: Status\r\n"
03368             "Privilege: Call\r\n"
03369             "Channel: %s\r\n"
03370             "CallerIDNum: %s\r\n"
03371             "CallerIDName: %s\r\n"
03372             "ConnectedLineNum: %s\r\n"
03373             "ConnectedLineName: %s\r\n"
03374             "Account: %s\r\n"
03375             "State: %s\r\n"
03376             "%s"
03377             "Uniqueid: %s\r\n"
03378             "%s"
03379             "%s"
03380             "\r\n",
03381             c->name,
03382             S_COR(c->caller.id.number.valid, c->caller.id.number.str, "<unknown>"),
03383             S_COR(c->caller.id.name.valid, c->caller.id.name.str, "<unknown>"),
03384             S_COR(c->connected.id.number.valid, c->connected.id.number.str, "<unknown>"),
03385             S_COR(c->connected.id.name.valid, c->connected.id.name.str, "<unknown>"),
03386             c->accountcode,
03387             ast_state2str(c->_state), bridge, c->uniqueid,
03388             ast_str_buffer(str), idText);
03389       }
03390 
03391       ast_channel_unlock(c);
03392       c = ast_channel_unref(c);
03393 
03394       if (!all) {
03395          break;
03396       }
03397    }
03398 
03399    if (iter) {
03400       ast_channel_iterator_destroy(iter);
03401    }
03402 
03403    astman_append(s,
03404       "Event: StatusComplete\r\n"
03405       "%s"
03406       "Items: %d\r\n"
03407       "\r\n", idText, channels);
03408 
03409    ast_free(str);
03410 
03411    return 0;
03412 }

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

Definition at line 4233 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(), and astman_send_error().

Referenced by __init_manager().

04234 {
04235    struct ast_channel *c;
04236    const char *name = astman_get_header(m, "Channel");
04237    double timeout = atof(astman_get_header(m, "Timeout"));
04238    struct timeval when = { timeout, 0 };
04239 
04240    if (ast_strlen_zero(name)) {
04241       astman_send_error(s, m, "No channel specified");
04242       return 0;
04243    }
04244 
04245    if (!timeout || timeout < 0) {
04246       astman_send_error(s, m, "No timeout specified");
04247       return 0;
04248    }
04249 
04250    if (!(c = ast_channel_get_by_name(name))) {
04251       astman_send_error(s, m, "No such channel");
04252       return 0;
04253    }
04254 
04255    when.tv_usec = (timeout - when.tv_sec) * 1000000.0;
04256 
04257    ast_channel_lock(c);
04258    ast_channel_setwhentohangup_tv(c, when);
04259    ast_channel_unlock(c);
04260    c = ast_channel_unref(c);
04261 
04262    astman_send_ack(s, m, "Timeout Set");
04263 
04264    return 0;
04265 }

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

Definition at line 2802 of file manager.c.

References ast_config_destroy(), ast_config_load2(), ast_config_text_file_save(), 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_STATUS_FILEINVALID, FAILURE_ALLOCATION, FAILURE_APPEND, FAILURE_DELCAT, FAILURE_DELETE, FAILURE_EMPTYCAT, FAILURE_NEWCAT, FAILURE_UPDATE, handle_updates(), UNKNOWN_ACTION, UNKNOWN_CATEGORY, UNSPECIFIED_ARGUMENT, and UNSPECIFIED_CATEGORY.

Referenced by __init_manager().

02803 {
02804    struct ast_config *cfg;
02805    const char *sfn = astman_get_header(m, "SrcFilename");
02806    const char *dfn = astman_get_header(m, "DstFilename");
02807    int res;
02808    const char *rld = astman_get_header(m, "Reload");
02809    struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE };
02810    enum error_type result;
02811 
02812    if (ast_strlen_zero(sfn) || ast_strlen_zero(dfn)) {
02813       astman_send_error(s, m, "Filename not specified");
02814       return 0;
02815    }
02816    if (!(cfg = ast_config_load2(sfn, "manager", config_flags))) {
02817       astman_send_error(s, m, "Config file not found");
02818       return 0;
02819    } else if (cfg == CONFIG_STATUS_FILEINVALID) {
02820       astman_send_error(s, m, "Config file has invalid format");
02821       return 0;
02822    }
02823    result = handle_updates(s, m, cfg, dfn);
02824    if (!result) {
02825       ast_include_rename(cfg, sfn, dfn); /* change the include references from dfn to sfn, so things match up */
02826       res = ast_config_text_file_save(dfn, cfg, "Manager");
02827       ast_config_destroy(cfg);
02828       if (res) {
02829          astman_send_error(s, m, "Save of config failed");
02830          return 0;
02831       }
02832       astman_send_ack(s, m, NULL);
02833       if (!ast_strlen_zero(rld)) {
02834          if (ast_true(rld)) {
02835             rld = NULL;
02836          }
02837          ast_module_reload(rld);
02838       }
02839    } else {
02840       ast_config_destroy(cfg);
02841       switch(result) {
02842       case UNKNOWN_ACTION:
02843          astman_send_error(s, m, "Unknown action command");
02844          break;
02845       case UNKNOWN_CATEGORY:
02846          astman_send_error(s, m, "Given category does not exist");
02847          break;
02848       case UNSPECIFIED_CATEGORY:
02849          astman_send_error(s, m, "Category not specified");
02850          break;
02851       case UNSPECIFIED_ARGUMENT:
02852          astman_send_error(s, m, "Problem with category, value, or line (if required)");
02853          break;
02854       case FAILURE_ALLOCATION:
02855          astman_send_error(s, m, "Memory allocation failure, this should not happen");
02856          break;
02857       case FAILURE_NEWCAT:
02858          astman_send_error(s, m, "Create category did not complete successfully");
02859          break;
02860       case FAILURE_DELCAT:
02861          astman_send_error(s, m, "Delete category did not complete successfully");
02862          break;
02863       case FAILURE_EMPTYCAT:
02864          astman_send_error(s, m, "Empty category did not complete successfully");
02865          break;
02866       case FAILURE_UPDATE:
02867          astman_send_error(s, m, "Update did not complete successfully");
02868          break;
02869       case FAILURE_DELETE:
02870          astman_send_error(s, m, "Delete did not complete successfully");
02871          break;
02872       case FAILURE_APPEND:
02873          astman_send_error(s, m, "Append did not complete successfully");
02874          break;
02875       }
02876    }
02877    return 0;
02878 }

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

Definition at line 4350 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().

04351 {
04352    const char *event = astman_get_header(m, "UserEvent");
04353    struct ast_str *body = ast_str_thread_get(&userevent_buf, 16);
04354    int x;
04355 
04356    ast_str_reset(body);
04357 
04358    for (x = 0; x < m->hdrcount; x++) {
04359       if (strncasecmp("UserEvent:", m->headers[x], strlen("UserEvent:"))) {
04360          ast_str_append(&body, 0, "%s\r\n", m->headers[x]);
04361       }
04362    }
04363 
04364    astman_send_ack(s, m, "Event Sent");   
04365    manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", event, ast_str_buffer(body));
04366    return 0;
04367 }

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

Definition at line 2898 of file manager.c.

References advance_event(), ao2_lock, ao2_unlock, ast_debug, AST_PTHREADT_NULL, AST_RWLIST_NEXT, ast_strlen_zero(), ast_wait_for_input(), astman_append(), astman_get_header(), astman_send_response(), eventqent::category, eventqent::eventdata, mansession_session::fd, mansession_session::last_ev, mansession_session::managerid, mansession_session::needdestroy, mansession_session::readperm, mansession_session::send_events, mansession::session, mansession_session::sessiontimeout, and mansession_session::waiting_thread.

Referenced by __init_manager().

02899 {
02900    const char *timeouts = astman_get_header(m, "Timeout");
02901    int timeout = -1;
02902    int x;
02903    int needexit = 0;
02904    const char *id = astman_get_header(m, "ActionID");
02905    char idText[256];
02906 
02907    if (!ast_strlen_zero(id)) {
02908       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
02909    } else {
02910       idText[0] = '\0';
02911    }
02912 
02913    if (!ast_strlen_zero(timeouts)) {
02914       sscanf(timeouts, "%30i", &timeout);
02915       if (timeout < -1) {
02916          timeout = -1;
02917       }
02918       /* XXX maybe put an upper bound, or prevent the use of 0 ? */
02919    }
02920 
02921    ao2_lock(s->session);
02922    if (s->session->waiting_thread != AST_PTHREADT_NULL) {
02923       pthread_kill(s->session->waiting_thread, SIGURG);
02924    }
02925 
02926    if (s->session->managerid) { /* AMI-over-HTTP session */
02927       /*
02928        * Make sure the timeout is within the expire time of the session,
02929        * as the client will likely abort the request if it does not see
02930        * data coming after some amount of time.
02931        */
02932       time_t now = time(NULL);
02933       int max = s->session->sessiontimeout - now - 10;
02934 
02935       if (max < 0) { /* We are already late. Strange but possible. */
02936          max = 0;
02937       }
02938       if (timeout < 0 || timeout > max) {
02939          timeout = max;
02940       }
02941       if (!s->session->send_events) {  /* make sure we record events */
02942          s->session->send_events = -1;
02943       }
02944    }
02945    ao2_unlock(s->session);
02946 
02947    /* XXX should this go inside the lock ? */
02948    s->session->waiting_thread = pthread_self(); /* let new events wake up this thread */
02949    ast_debug(1, "Starting waiting for an event!\n");
02950 
02951    for (x = 0; x < timeout || timeout < 0; x++) {
02952       ao2_lock(s->session);
02953       if (AST_RWLIST_NEXT(s->session->last_ev, eq_next)) {
02954          needexit = 1;
02955       }
02956       /* We can have multiple HTTP session point to the same mansession entry.
02957        * The way we deal with it is not very nice: newcomers kick out the previous
02958        * HTTP session. XXX this needs to be improved.
02959        */
02960       if (s->session->waiting_thread != pthread_self()) {
02961          needexit = 1;
02962       }
02963       if (s->session->needdestroy) {
02964          needexit = 1;
02965       }
02966       ao2_unlock(s->session);
02967       if (needexit) {
02968          break;
02969       }
02970       if (s->session->managerid == 0) {   /* AMI session */
02971          if (ast_wait_for_input(s->session->fd, 1000)) {
02972             break;
02973          }
02974       } else { /* HTTP session */
02975          sleep(1);
02976       }
02977    }
02978    ast_debug(1, "Finished waiting for an event!\n");
02979 
02980    ao2_lock(s->session);
02981    if (s->session->waiting_thread == pthread_self()) {
02982       struct eventqent *eqe = s->session->last_ev;
02983       astman_send_response(s, m, "Success", "Waiting for Event completed.");
02984       while ((eqe = advance_event(eqe))) {
02985          if (((s->session->readperm & eqe->category) == eqe->category) &&
02986              ((s->session->send_events & eqe->category) == eqe->category)) {
02987             astman_append(s, "%s", eqe->eventdata);
02988          }
02989          s->session->last_ev = eqe;
02990       }
02991       astman_append(s,
02992          "Event: WaitEventComplete\r\n"
02993          "%s"
02994          "\r\n", idText);
02995       s->session->waiting_thread = AST_PTHREADT_NULL;
02996    } else {
02997       ast_debug(1, "Abandoning event request!\n");
02998    }
02999    ao2_unlock(s->session);
03000 
03001    return 0;
03002 }

static struct eventqent* advance_event ( struct eventqent *  e  )  [static, read]

Definition at line 1764 of file manager.c.

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

Referenced by action_waitevent(), and process_events().

01765 {
01766    struct eventqent *next;
01767 
01768    AST_RWLIST_RDLOCK(&all_events);
01769    if ((next = AST_RWLIST_NEXT(e, eq_next))) {
01770       ast_atomic_fetchadd_int(&next->usecount, 1);
01771       ast_atomic_fetchadd_int(&e->usecount, -1);
01772    }
01773    AST_RWLIST_UNLOCK(&all_events);
01774    return next;
01775 }

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

Definition at line 3796 of file manager.c.

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

Referenced by action_aocmessage().

03797 {
03798    const char *unitamount;
03799    const char *unittype;
03800    struct ast_str *str = ast_str_alloca(32);
03801 
03802    memset(entry, 0, sizeof(*entry));
03803 
03804    ast_str_set(&str, 0, "UnitAmount(%u)", entry_num);
03805    unitamount = astman_get_header(m, ast_str_buffer(str));
03806 
03807    ast_str_set(&str, 0, "UnitType(%u)", entry_num);
03808    unittype = astman_get_header(m, ast_str_buffer(str));
03809 
03810    if (!ast_strlen_zero(unitamount) && (sscanf(unitamount, "%30u", &entry->amount) == 1)) {
03811       entry->valid_amount = 1;
03812    }
03813 
03814    if (!ast_strlen_zero(unittype) && sscanf(unittype, "%30u", &entry->type) == 1) {
03815       entry->valid_type = 1;
03816    }
03817 
03818    return 0;
03819 }

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

Definition at line 5133 of file manager.c.

References ast_func_read2(), AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_str_append(), ast_str_buffer(), ast_str_thread_get(), manager_channel_variable::isfunc, manager_event_funcbuf, manager_channel_variable::name, pbx_builtin_getvar_helper(), and var.

Referenced by __ast_manager_event_multichan().

05134 {
05135    struct manager_channel_variable *var;
05136 
05137    AST_RWLIST_RDLOCK(&channelvars);
05138    AST_LIST_TRAVERSE(&channelvars, var, entry) {
05139       const char *val;
05140       struct ast_str *res;
05141 
05142       if (var->isfunc) {
05143          res = ast_str_thread_get(&manager_event_funcbuf, 16);
05144          if (res && ast_func_read2(chan, var->name, &res, 0) == 0) {
05145             val = ast_str_buffer(res);
05146          } else {
05147             val = NULL;
05148          }
05149       } else {
05150          val = pbx_builtin_getvar_helper(chan, var->name);
05151       }
05152       ast_str_append(pbuf, 0, "ChanVariable(%s): %s=%s\r\n", chan->name, var->name, val ? val : "");
05153    }
05154    AST_RWLIST_UNLOCK(&channelvars);
05155 }

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

Definition at line 5107 of file manager.c.

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

Referenced by __ast_manager_event_multichan(), and __init_manager().

05108 {
05109    struct eventqent *tmp = ast_malloc(sizeof(*tmp) + strlen(str));
05110    static int seq;   /* sequence number */
05111 
05112    if (!tmp) {
05113       return -1;
05114    }
05115 
05116    /* need to init all fields, because ast_malloc() does not */
05117    tmp->usecount = 0;
05118    tmp->category = category;
05119    tmp->seq = ast_atomic_fetchadd_int(&seq, 1);
05120    tmp->tv = ast_tvnow();
05121    AST_RWLIST_NEXT(tmp, eq_next) = NULL;
05122    strcpy(tmp->eventdata, str);
05123 
05124    AST_RWLIST_WRLOCK(&all_events);
05125    AST_RWLIST_INSERT_TAIL(&all_events, tmp, eq_next);
05126    AST_RWLIST_UNLOCK(&all_events);
05127 
05128    return 0;
05129 }

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

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

Parameters:
hook the file identifier specified in manager_custom_hook struct when registering a hook
msg ami action mesage string e.g. "Action: SipPeers\r\n"
Return values:
0 on Success
non-zero on Failure

Definition at line 1911 of file manager.c.

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

01912 {
01913    const char *action;
01914    int ret = 0;
01915    struct manager_action *act_found;
01916    struct mansession s = {.session = NULL, };
01917    struct message m = { 0 };
01918    char *dup_str;
01919    char *src;
01920    int x = 0;
01921    int curlen;
01922 
01923    if (hook == NULL) {
01924       return -1;
01925    }
01926 
01927    /* Create our own copy of the AMI action msg string. */
01928    src = dup_str = ast_strdup(msg);
01929    if (!dup_str) {
01930       return -1;
01931    }
01932 
01933    /* convert msg string to message struct */
01934    curlen = strlen(src);
01935    for (x = 0; x < curlen; x++) {
01936       int cr;  /* set if we have \r */
01937       if (src[x] == '\r' && x+1 < curlen && src[x+1] == '\n')
01938          cr = 2;  /* Found. Update length to include \r\n */
01939       else if (src[x] == '\n')
01940          cr = 1;  /* also accept \n only */
01941       else
01942          continue;
01943       /* don't keep empty lines */
01944       if (x && m.hdrcount < ARRAY_LEN(m.headers)) {
01945          /* ... but trim \r\n and terminate the header string */
01946          src[x] = '\0';
01947          m.headers[m.hdrcount++] = src;
01948       }
01949       x += cr;
01950       curlen -= x;      /* remaining size */
01951       src += x;      /* update pointer */
01952       x = -1;        /* reset loop */
01953    }
01954 
01955    action = astman_get_header(&m, "Action");
01956    if (strcasecmp(action, "login")) {
01957       act_found = action_find(action);
01958       if (act_found) {
01959          /*
01960           * we have to simulate a session for this action request
01961           * to be able to pass it down for processing
01962           * This is necessary to meet the previous design of manager.c
01963           */
01964          s.hook = hook;
01965          s.f = (void*)1; /* set this to something so our request will make it through all functions that test it*/
01966 
01967          ao2_lock(act_found);
01968          if (act_found->registered && act_found->func) {
01969             ++act_found->active_count;
01970             ao2_unlock(act_found);
01971             ret = act_found->func(&s, &m);
01972             ao2_lock(act_found);
01973             --act_found->active_count;
01974          } else {
01975             ret = -1;
01976          }
01977          ao2_unlock(act_found);
01978          ao2_t_ref(act_found, -1, "done with found action object");
01979       }
01980    }
01981    ast_free(dup_str);
01982    return ret;
01983 }

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

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

feel free to move this to app.c -anthm

Definition at line 1234 of file manager.c.

References eventqent::next.

Referenced by get_perm().

01235 {
01236    const char *val = bigstr, *next;
01237 
01238    do {
01239       if ((next = strchr(val, delim))) {
01240          if (!strncmp(val, smallstr, (next - val))) {
01241             return 1;
01242          } else {
01243             continue;
01244          }
01245       } else {
01246          return !strcmp(smallstr, val);
01247       }
01248    } while (*(val = (next + 1)));
01249 
01250    return 0;
01251 }

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

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

Register a manager command with the manager interface.

Definition at line 5362 of file manager.c.

References manager_action::action, action_destroy(), ao2_alloc, ao2_t_ref, ast_free, ast_manager_register_struct(), AST_STATIC_DOC, ast_string_field_init, ast_string_field_set, ast_strlen_zero(), AST_XML_DOC, ast_xmldoc_build_arguments(), ast_xmldoc_build_description(), ast_xmldoc_build_seealso(), ast_xmldoc_build_synopsis(), ast_xmldoc_build_syntax(), manager_action::authority, manager_action::docsrc, and manager_action::func.

Referenced by load_module().

05363 {
05364    struct manager_action *cur;
05365 
05366    cur = ao2_alloc(sizeof(*cur), action_destroy);
05367    if (!cur) {
05368       return -1;
05369    }
05370    if (ast_string_field_init(cur, 128)) {
05371       ao2_t_ref(cur, -1, "action object creation failed");
05372       return -1;
05373    }
05374 
05375    cur->action = action;
05376    cur->authority = auth;
05377    cur->func = func;
05378 #ifdef AST_XML_DOCS
05379    if (ast_strlen_zero(synopsis) && ast_strlen_zero(description)) {
05380       char *tmpxml;
05381 
05382       tmpxml = ast_xmldoc_build_synopsis("manager", action, NULL);
05383       ast_string_field_set(cur, synopsis, tmpxml);
05384       ast_free(tmpxml);
05385 
05386       tmpxml = ast_xmldoc_build_syntax("manager", action, NULL);
05387       ast_string_field_set(cur, syntax, tmpxml);
05388       ast_free(tmpxml);
05389 
05390       tmpxml = ast_xmldoc_build_description("manager", action, NULL);
05391       ast_string_field_set(cur, description, tmpxml);
05392       ast_free(tmpxml);
05393 
05394       tmpxml = ast_xmldoc_build_seealso("manager", action, NULL);
05395       ast_string_field_set(cur, seealso, tmpxml);
05396       ast_free(tmpxml);
05397 
05398       tmpxml = ast_xmldoc_build_arguments("manager", action, NULL);
05399       ast_string_field_set(cur, arguments, tmpxml);
05400       ast_free(tmpxml);
05401 
05402       cur->docsrc = AST_XML_DOC;
05403    } else
05404 #endif
05405    {
05406       ast_string_field_set(cur, synopsis, synopsis);
05407       ast_string_field_set(cur, description, description);
05408 #ifdef AST_XML_DOCS
05409       cur->docsrc = AST_STATIC_DOC;
05410 #endif
05411    }
05412    if (ast_manager_register_struct(cur)) {
05413       ao2_t_ref(cur, -1, "action object registration failed");
05414       return -1;
05415    }
05416 
05417    ao2_t_ref(cur, -1, "action object registration successful");
05418    return 0;
05419 }

void ast_manager_register_hook ( struct manager_custom_hook *  hook  ) 

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

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

Parameters:
hook struct manager_custom_hook object to add

Definition at line 1090 of file manager.c.

References AST_RWLIST_INSERT_TAIL, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and manager_action::list.

static int ast_manager_register_struct ( struct manager_action *  act  )  [static]

Definition at line 5307 of file manager.c.

References manager_action::action, ao2_t_ref, ast_log(), AST_RWLIST_INSERT_AFTER, AST_RWLIST_INSERT_HEAD, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, LOG_WARNING, and manager_action::registered.

Referenced by ast_manager_register2().

05308 {
05309    struct manager_action *cur, *prev = NULL;
05310 
05311    AST_RWLIST_WRLOCK(&actions);
05312    AST_RWLIST_TRAVERSE(&actions, cur, list) {
05313       int ret;
05314 
05315       ret = strcasecmp(cur->action, act->action);
05316       if (ret == 0) {
05317          ast_log(LOG_WARNING, "Manager: Action '%s' already registered\n", act->action);
05318          AST_RWLIST_UNLOCK(&actions);
05319          return -1;
05320       }
05321       if (ret > 0) { /* Insert these alphabetically */
05322          prev = cur;
05323          break;
05324       }
05325    }
05326 
05327    ao2_t_ref(act, +1, "action object added to list");
05328    act->registered = 1;
05329    if (prev) {
05330       AST_RWLIST_INSERT_AFTER(&actions, prev, act, list);
05331    } else {
05332       AST_RWLIST_INSERT_HEAD(&actions, act, list);
05333    }
05334 
05335    ast_verb(2, "Manager registered action %s\n", act->action);
05336 
05337    AST_RWLIST_UNLOCK(&actions);
05338 
05339    return 0;
05340 }

int ast_manager_unregister ( char *  action  ) 

Unregister a registered manager command.

Parameters:
action Name of registered Action:

Definition at line 5248 of file manager.c.

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

Referenced by __unload_module(), data_shutdown(), features_shutdown(), manager_shutdown(), unload_module(), and unload_pbx().

05249 {
05250    struct manager_action *cur;
05251 
05252    AST_RWLIST_WRLOCK(&actions);
05253    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&actions, cur, list) {
05254       if (!strcasecmp(action, cur->action)) {
05255          AST_RWLIST_REMOVE_CURRENT(list);
05256          break;
05257       }
05258    }
05259    AST_RWLIST_TRAVERSE_SAFE_END;
05260    AST_RWLIST_UNLOCK(&actions);
05261 
05262    if (cur) {
05263       time_t now;
05264 
05265       /*
05266        * We have removed the action object from the container so we
05267        * are no longer in a hurry.
05268        */
05269       ao2_lock(cur);
05270       cur->registered = 0;
05271       ao2_unlock(cur);
05272 
05273       /*
05274        * Wait up to 5 seconds for any active invocations to complete
05275        * before returning.  We have to wait instead of blocking
05276        * because we may be waiting for ourself to complete.
05277        */
05278       now = time(NULL);
05279       while (cur->active_count) {
05280          if (5 <= time(NULL) - now) {
05281             ast_debug(1,
05282                "Unregister manager action %s timed out waiting for %d active instances to complete\n",
05283                action, cur->active_count);
05284             break;
05285          }
05286 
05287          sched_yield();
05288       }
05289 
05290       ao2_t_ref(cur, -1, "action object removed from list");
05291       ast_verb(2, "Manager unregistered action %s\n", action);
05292    }
05293 
05294    return 0;
05295 }

void ast_manager_unregister_hook ( struct manager_custom_hook *  hook  ) 

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

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

Parameters:
hook struct manager_custom_hook object to delete

Definition at line 1098 of file manager.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and manager_action::list.

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

utility functions for creating AMI replies

Definition at line 2029 of file manager.c.

References ast_str_buffer(), ast_str_set_va(), ast_str_thread_get(), ast_verbose, astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE, mansession_session::f, mansession::f, send_string(), and mansession::session.

Referenced by __iax2_show_peers(), _sip_show_peer(), _sip_show_peers(), _skinny_show_device(), _skinny_show_devices(), _skinny_show_line(), _skinny_show_lines(), action_agents(), action_challenge(), action_command(), action_coresettings(), action_coreshowchannels(), action_corestatus(), action_dahdishowchannels(), action_events(), action_extensionstate(), action_getconfig(), action_getconfigjson(), action_getvar(), action_listcategories(), action_listcommands(), action_login(), action_mailboxcount(), action_mailboxstatus(), action_meetmelist(), action_ping(), action_status(), action_waitevent(), ast_cli_netstats(), astman_append_json(), astman_send_response_full(), data_result_manager_output(), do_print(), manager_data_get(), manager_dbget(), manager_iax2_show_netstats(), manager_iax2_show_peer_list(), manager_iax2_show_peers(), manager_iax2_show_registry(), manager_jabber_send(), manager_list_voicemail_users(), manager_modulecheck(), manager_mute_mixmonitor(), manager_mutestream(), manager_parking_status(), manager_queue_rule_show(), manager_queues_show(), manager_queues_status(), manager_queues_summary(), manager_show_dialplan(), manager_show_dialplan_helper(), manager_show_registry(), manager_sip_qualify_peer(), manager_sip_show_peer(), manager_sip_show_peers(), manager_skinny_show_device(), manager_skinny_show_devices(), manager_skinny_show_line(), manager_skinny_show_lines(), and session_do().

02030 {
02031    va_list ap;
02032    struct ast_str *buf;
02033 
02034    if (!(buf = ast_str_thread_get(&astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE))) {
02035       return;
02036    }
02037 
02038    va_start(ap, fmt);
02039    ast_str_set_va(&buf, 0, fmt, ap);
02040    va_end(ap);
02041 
02042    if (s->f != NULL || s->session->f != NULL) {
02043       send_string(s, ast_str_buffer(buf));
02044    } else {
02045       ast_verbose("fd == -1 in astman_append, should not happen\n");
02046    }
02047 }

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

Definition at line 2599 of file manager.c.

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

Referenced by action_getconfigjson().

02600 {
02601    char *buf;
02602 
02603    buf = ast_alloca(2 * strlen(str) + 1);
02604    json_escape(buf, str);
02605    astman_append(s, "%s", buf);
02606 }

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

Return the first matching variable from an array.

Get header from mananger transaction.

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

Definition at line 1831 of file manager.c.

References __astman_get_header(), and GET_HEADER_FIRST_MATCH.

Referenced by _sip_show_peer(), _sip_show_peers(), _skinny_show_devices(), _skinny_show_lines(), action_add_agi_cmd(), action_agent_logoff(), action_agents(), action_aocmessage(), action_atxfer(), action_bridge(), action_challenge(), action_command(), action_coresettings(), action_coreshowchannels(), action_corestatus(), action_createconfig(), action_dahdidialoffhook(), action_dahdidndoff(), action_dahdidndon(), action_dahdishowchannels(), action_events(), action_extensionstate(), action_getconfig(), action_getconfigjson(), action_getvar(), action_hangup(), action_listcategories(), action_mailboxcount(), action_mailboxstatus(), action_meetmelist(), action_originate(), action_ping(), action_redirect(), action_reload(), action_sendtext(), action_setvar(), action_status(), action_timeout(), action_transfer(), action_transferhangup(), action_updateconfig(), action_userevent(), action_waitevent(), aocmessage_get_unit_entry(), ast_hook_send_action(), astman_send_response_full(), authenticate(), change_monitor_action(), do_pause_or_unpause(), handle_updates(), manager_add_queue_member(), manager_data_get(), manager_dbdel(), manager_dbdeltree(), manager_dbget(), manager_dbput(), manager_iax2_show_peer_list(), manager_iax2_show_peers(), manager_iax2_show_registry(), manager_jabber_send(), manager_list_voicemail_users(), manager_modulecheck(), manager_moduleload(), manager_mute_mixmonitor(), manager_mutestream(), manager_optimize_away(), manager_park(), manager_parking_status(), manager_pause_queue_member(), manager_play_dtmf(), manager_queue_log_custom(), manager_queue_member_penalty(), manager_queue_reload(), manager_queue_reset(), manager_queue_rule_show(), manager_queues_status(), manager_queues_summary(), manager_remove_queue_member(), manager_show_dialplan(), manager_show_registry(), manager_sip_qualify_peer(), manager_sip_show_peer(), manager_sip_show_peers(), manager_sipnotify(), manager_skinny_show_device(), manager_skinny_show_devices(), manager_skinny_show_line(), manager_skinny_show_lines(), meetmemute(), process_message(), start_monitor_action(), and stop_monitor_action().

01832 {
01833    return __astman_get_header(m, var, GET_HEADER_FIRST_MATCH);
01834 }

struct ast_variable* astman_get_variables ( const struct message *  m  )  [read]

Get a linked list of the Variable: headers.

Definition at line 1889 of file manager.c.

References message::hdrcount, message::headers, and man_do_variable_value().

Referenced by action_originate(), and manager_sipnotify().

01890 {
01891    int varlen;
01892    int x;
01893    struct ast_variable *head = NULL;
01894 
01895    static const char var_hdr[] = "Variable:";
01896 
01897    /* Process all "Variable:" headers. */
01898    varlen = strlen(var_hdr);
01899    for (x = 0; x < m->hdrcount; x++) {
01900       if (strncasecmp(var_hdr, m->headers[x], varlen)) {
01901          continue;
01902       }
01903       head = man_do_variable_value(head, m->headers[x] + varlen);
01904    }
01905 
01906    return head;
01907 }

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

Send error in manager transaction.

Definition at line 2091 of file manager.c.

References astman_send_response_full().

Referenced by _sip_qualify_peer(), _sip_show_peer(), action_add_agi_cmd(), action_agent_logoff(), action_aocmessage(), action_atxfer(), action_bridge(), action_challenge(), action_command(), action_coreshowchannels(), action_createconfig(), action_dahdidialoffhook(), action_dahdidndoff(), action_dahdidndon(), action_dahdirestart(), action_events(), action_extensionstate(), action_getconfig(), action_getconfigjson(), action_getvar(), action_hangup(), action_listcategories(), action_login(), action_mailboxcount(), action_mailboxstatus(), action_meetmelist(), action_originate(), action_redirect(), action_reload(), action_sendtext(), action_setvar(), action_status(), action_timeout(), action_transfer(), action_transferhangup(), action_updateconfig(), change_monitor_action(), do_message(), do_pause_or_unpause(), handle_parse_error(), manager_add_queue_member(), manager_data_get(), manager_dbdel(), manager_dbdeltree(), manager_dbget(), manager_dbput(), manager_jabber_send(), manager_modulecheck(), manager_moduleload(), manager_mute_mixmonitor(), manager_mutestream(), manager_optimize_away(), manager_park(), manager_pause_queue_member(), manager_play_dtmf(), manager_queue_log_custom(), manager_queue_member_penalty(), manager_queue_reload(), manager_queue_reset(), manager_remove_queue_member(), manager_show_dialplan(), manager_show_dialplan_helper(), manager_sip_qualify_peer(), manager_sip_show_peer(), manager_sipnotify(), manager_skinny_show_device(), manager_skinny_show_line(), meetmemute(), process_message(), start_monitor_action(), and stop_monitor_action().

02092 {
02093    astman_send_response_full(s, m, "Error", error, NULL);
02094 }

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

Send response in manager transaction.

Definition at line 2086 of file manager.c.

References astman_send_response_full().

Referenced by action_logoff(), and action_waitevent().

02087 {
02088    astman_send_response_full(s, m, resp, msg, NULL);
02089 }

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

Definition at line 2066 of file manager.c.

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

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

02067 {
02068    const char *id = astman_get_header(m, "ActionID");
02069 
02070    astman_append(s, "Response: %s\r\n", resp);
02071    if (!ast_strlen_zero(id)) {
02072       astman_append(s, "ActionID: %s\r\n", id);
02073    }
02074    if (listflag) {
02075       astman_append(s, "EventList: %s\r\n", listflag);   /* Start, complete, cancelled */
02076    }
02077    if (msg == MSG_MOREDATA) {
02078       return;
02079    } else if (msg) {
02080       astman_append(s, "Message: %s\r\n\r\n", msg);
02081    } else {
02082       astman_append(s, "\r\n");
02083    }
02084 }

static void astman_start_ack ( struct mansession *  s,
const struct message *  m 
) [static]
static int authenticate ( struct mansession *  s,
const struct message *  m 
) [static]

Definition at line 2383 of file manager.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_t_link, ao2_t_ref, ast_apply_ha(), ast_copy_string(), ast_debug, ast_inet_ntoa(), ast_log(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_sockaddr_from_sin, ast_strlen_zero(), ast_tvnow(), astman_get_header(), mansession_session::blackfilters, ast_manager_user::blackfilters, mansession_session::challenge, get_manager_by_name_locked(), ast_manager_user::ha, len(), LOG_NOTICE, MD5Final(), MD5Init(), MD5Update(), ast_manager_user::readperm, mansession_session::readperm, report_auth_success(), report_failed_acl(), report_failed_challenge_response(), report_inval_password(), report_invalid_user(), S_OR, ast_manager_user::secret, mansession::session, mansession_session::sessionstart, mansession_session::sessionstart_tv, set_eventmask(), mansession_session::sin, mansession_session::username, mansession_session::whitefilters, ast_manager_user::whitefilters, ast_manager_user::writeperm, mansession_session::writeperm, ast_manager_user::writetimeout, and mansession_session::writetimeout.

Referenced by action_login().

02384 {
02385    const char *username = astman_get_header(m, "Username");
02386    const char *password = astman_get_header(m, "Secret");
02387    int error = -1;
02388    struct ast_manager_user *user = NULL;
02389    regex_t *regex_filter;
02390    struct ao2_iterator filter_iter;
02391    struct ast_sockaddr addr;
02392 
02393    if (ast_strlen_zero(username)) { /* missing username */
02394       return -1;
02395    }
02396 
02397    /* locate user in locked state */
02398    AST_RWLIST_WRLOCK(&users);
02399 
02400    ast_sockaddr_from_sin(&addr, &s->session->sin);
02401 
02402    if (!(user = get_manager_by_name_locked(username))) {
02403       report_invalid_user(s, username);
02404       ast_log(LOG_NOTICE, "%s tried to authenticate with nonexistent user '%s'\n", ast_inet_ntoa(s->session->sin.sin_addr), username);
02405    } else if (user->ha && !ast_apply_ha(user->ha, &addr)) {
02406       report_failed_acl(s, username);
02407       ast_log(LOG_NOTICE, "%s failed to pass IP ACL as '%s'\n", ast_inet_ntoa(s->session->sin.sin_addr), username);
02408    } else if (!strcasecmp(astman_get_header(m, "AuthType"), "MD5")) {
02409       const char *key = astman_get_header(m, "Key");
02410       if (!ast_strlen_zero(key) && !ast_strlen_zero(s->session->challenge) && user->secret) {
02411          int x;
02412          int len = 0;
02413          char md5key[256] = "";
02414          struct MD5Context md5;
02415          unsigned char digest[16];
02416 
02417          MD5Init(&md5);
02418          MD5Update(&md5, (unsigned char *) s->session->challenge, strlen(s->session->challenge));
02419          MD5Update(&md5, (unsigned char *) user->secret, strlen(user->secret));
02420          MD5Final(digest, &md5);
02421          for (x = 0; x < 16; x++)
02422             len += sprintf(md5key + len, "%2.2x", digest[x]);
02423          if (!strcmp(md5key, key)) {
02424             error = 0;
02425          } else {
02426             report_failed_challenge_response(s, key, md5key);
02427          }
02428       } else {
02429          ast_debug(1, "MD5 authentication is not possible.  challenge: '%s'\n",
02430             S_OR(s->session->challenge, ""));
02431       }
02432    } else if (user->secret) {
02433       if (!strcmp(password, user->secret)) {
02434          error = 0;
02435       } else {
02436          report_inval_password(s, username);
02437       }
02438    }
02439 
02440    if (error) {
02441       ast_log(LOG_NOTICE, "%s failed to authenticate as '%s'\n", ast_inet_ntoa(s->session->sin.sin_addr), username);
02442       AST_RWLIST_UNLOCK(&users);
02443       return -1;
02444    }
02445 
02446    /* auth complete */
02447 
02448    /* All of the user parameters are copied to the session so that in the event
02449      * of a reload and a configuration change, the session parameters are not
02450      * changed. */
02451    ast_copy_string(s->session->username, username, sizeof(s->session->username));
02452    s->session->readperm = user->readperm;
02453    s->session->writeperm = user->writeperm;
02454    s->session->writetimeout = user->writetimeout;
02455 
02456    filter_iter = ao2_iterator_init(user->whitefilters, 0);
02457    while ((regex_filter = ao2_iterator_next(&filter_iter))) {
02458       ao2_t_link(s->session->whitefilters, regex_filter, "add white user filter to session");
02459       ao2_t_ref(regex_filter, -1, "remove iterator ref");
02460    }
02461    ao2_iterator_destroy(&filter_iter);
02462 
02463    filter_iter = ao2_iterator_init(user->blackfilters, 0);
02464    while ((regex_filter = ao2_iterator_next(&filter_iter))) {
02465       ao2_t_link(s->session->blackfilters, regex_filter, "add black user filter to session");
02466       ao2_t_ref(regex_filter, -1, "remove iterator ref");
02467    }
02468    ao2_iterator_destroy(&filter_iter);
02469 
02470    s->session->sessionstart = time(NULL);
02471    s->session->sessionstart_tv = ast_tvnow();
02472    set_eventmask(s, astman_get_header(m, "Events"));
02473 
02474    report_auth_success(s);
02475 
02476    AST_RWLIST_UNLOCK(&users);
02477    return 0;
02478 }

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

Convert authority code to a list of options.

Definition at line 1210 of file manager.c.

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

Referenced by __ast_manager_event_multichan(), action_listcommands(), action_login(), handle_showmanager(), handle_showmancmd(), and handle_showmancmds().

01211 {
01212    int i;
01213    char *sep = "";
01214 
01215    ast_str_reset(*res);
01216    for (i = 0; i < ARRAY_LEN(perms) - 1; i++) {
01217       if (authority & perms[i].num) {
01218          ast_str_append(res, 0, "%s%s", sep, perms[i].label);
01219          sep = ",";
01220       }
01221    }
01222 
01223    if (ast_str_strlen(*res) == 0)   /* replace empty string with something sensible */
01224       ast_str_append(res, 0, "<none>");
01225 
01226    return ast_str_buffer(*res);
01227 }

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

Definition at line 4281 of file manager.c.

References CMP_MATCH, and CMP_STOP.

Referenced by match_filter().

04282 {
04283    regex_t *regex_filter = obj;
04284    const char *eventdata = arg;
04285    int *result = data;
04286 
04287    if (!regexec(regex_filter, eventdata, 0, NULL, 0)) {
04288       *result = 0;
04289       return (CMP_MATCH | CMP_STOP);
04290    }
04291 
04292    *result = 1;
04293    return 0;
04294 }

static struct mansession_session* build_mansession ( struct sockaddr_in  sin  )  [static, read]

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

Definition at line 1351 of file manager.c.

References ao2_alloc, ao2_container_alloc, ao2_link, ao2_ref, AST_PTHREADT_NULL, mansession_session::blackfilters, mansession_session::fd, mansession_session::send_events, session_destructor(), sessions, mansession_session::sin, mansession_session::waiting_thread, mansession_session::whitefilters, and mansession_session::writetimeout.

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

01352 {
01353    struct mansession_session *newsession;
01354 
01355    if (!(newsession = ao2_alloc(sizeof(*newsession), session_destructor))) {
01356       return NULL;
01357    }
01358 
01359    if (!(newsession->whitefilters = ao2_container_alloc(1, NULL, NULL))) {
01360       ao2_ref(newsession, -1);
01361       return NULL;
01362    }
01363 
01364    if (!(newsession->blackfilters = ao2_container_alloc(1, NULL, NULL))) {
01365       ao2_ref(newsession, -1); /* session_destructor will cleanup the other filter */
01366       return NULL;
01367    }
01368 
01369    newsession->fd = -1;
01370    newsession->waiting_thread = AST_PTHREADT_NULL;
01371    newsession->writetimeout = 100;
01372    newsession->send_events = -1;
01373    newsession->sin = sin;
01374 
01375    ao2_link(sessions, newsession);
01376 
01377    return newsession;
01378 }

static int check_blacklist ( const char *  cmd  )  [static]

Definition at line 3598 of file manager.c.

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

Referenced by action_command().

03599 {
03600    char *cmd_copy, *cur_cmd;
03601    char *cmd_words[MAX_BLACKLIST_CMD_LEN] = { NULL, };
03602    int i;
03603 
03604    cmd_copy = ast_strdupa(cmd);
03605    for (i = 0; i < MAX_BLACKLIST_CMD_LEN && (cur_cmd = strsep(&cmd_copy, " ")); i++) {
03606       cur_cmd = ast_strip(cur_cmd);
03607       if (ast_strlen_zero(cur_cmd)) {
03608          i--;
03609          continue;
03610       }
03611 
03612       cmd_words[i] = cur_cmd;
03613    }
03614 
03615    for (i = 0; i < ARRAY_LEN(command_blacklist); i++) {
03616       int j, match = 1;
03617 
03618       for (j = 0; command_blacklist[i].words[j]; j++) {
03619          if (ast_strlen_zero(cmd_words[j]) || strcasecmp(cmd_words[j], command_blacklist[i].words[j])) {
03620             match = 0;
03621             break;
03622          }
03623       }
03624 
03625       if (match) {
03626          return 1;
03627       }
03628    }
03629 
03630    return 0;
03631 }

int check_manager_enabled ( void   ) 

Check if AMI is enabled.

Definition at line 1105 of file manager.c.

Referenced by handle_show_settings().

01106 {
01107    return manager_enabled;
01108 }

static int check_manager_session_inuse ( const char *  name  )  [static]

Definition at line 1394 of file manager.c.

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

Referenced by process_message().

01395 {
01396    struct mansession_session *session = ao2_find(sessions, (char *) name, 0);
01397    int inuse = 0;
01398 
01399    if (session) {
01400       inuse = 1;
01401       unref_mansession(session);
01402    }
01403    return inuse;
01404 }

int check_webmanager_enabled ( void   ) 

Check if AMI/HTTP is enabled.

Definition at line 1110 of file manager.c.

Referenced by action_coresettings(), and handle_show_settings().

01111 {
01112    return (webmanager_enabled && manager_enabled);
01113 }

static void destroy_fast_originate_helper ( struct fast_originate_helper *  doomed  )  [static]

Definition at line 3735 of file manager.c.

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

Referenced by action_originate(), and fast_originate().

03736 {
03737    ast_variables_destroy(doomed->vars);
03738    ast_string_field_free_memory(doomed);
03739    ast_free(doomed);
03740 }

static int do_message ( struct mansession *  s  )  [static]

Definition at line 4887 of file manager.c.

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

Referenced by session_do().

04888 {
04889    struct message m = { 0 };
04890    char header_buf[sizeof(s->session->inbuf)] = { '\0' };
04891    int res;
04892    int idx;
04893    int hdr_loss;
04894    time_t now;
04895 
04896    hdr_loss = 0;
04897    for (;;) {
04898       /* Check if any events are pending and do them if needed */
04899       if (process_events(s)) {
04900          res = -1;
04901          break;
04902       }
04903       res = get_input(s, header_buf);
04904       if (res == 0) {
04905          /* No input line received. */
04906          if (!s->session->authenticated) {
04907             if (time(&now) == -1) {
04908                ast_log(LOG_ERROR, "error executing time(): %s\n", strerror(errno));
04909                res = -1;
04910                break;
04911             }
04912 
04913             if (now - s->session->authstart > authtimeout) {
04914                if (displayconnects) {
04915                   ast_verb(2, "Client from %s, failed to authenticate in %d seconds\n", ast_inet_ntoa(s->session->sin.sin_addr), authtimeout);
04916                }
04917                res = -1;
04918                break;
04919             }
04920          }
04921          continue;
04922       } else if (res > 0) {
04923          /* Input line received. */
04924          if (ast_strlen_zero(header_buf)) {
04925             if (hdr_loss) {
04926                mansession_lock(s);
04927                astman_send_error(s, &m, "Too many lines in message or allocation failure");
04928                mansession_unlock(s);
04929                res = 0;
04930             } else {
04931                switch (s->parsing) {
04932                case MESSAGE_OKAY:
04933                   res = process_message(s, &m) ? -1 : 0;
04934                   break;
04935                case MESSAGE_LINE_TOO_LONG:
04936                   handle_parse_error(s, &m, "Failed to parse message: line too long");
04937                   res = 0;
04938                   break;
04939                }
04940             }
04941             break;
04942          } else if (m.hdrcount < ARRAY_LEN(m.headers)) {
04943             m.headers[m.hdrcount] = ast_strdup(header_buf);
04944             if (!m.headers[m.hdrcount]) {
04945                /* Allocation failure. */
04946                hdr_loss = 1;
04947             } else {
04948                ++m.hdrcount;
04949             }
04950          } else {
04951             /* Too many lines in message. */
04952             hdr_loss = 1;
04953          }
04954       } else {
04955          /* Input error. */
04956          break;
04957       }
04958    }
04959 
04960    /* Free AMI request headers. */
04961    for (idx = 0; idx < m.hdrcount; ++idx) {
04962       ast_free((void *) m.headers[idx]);
04963    }
04964    return res;
04965 }

static void event_filter_destructor ( void *  obj  )  [static]

Definition at line 1314 of file manager.c.

Referenced by __init_manager().

01315 {
01316    regex_t *regex_filter = obj;
01317    regfree(regex_filter);
01318 }

static void* fast_originate ( void *  data  )  [static]

Definition at line 3742 of file manager.c.

References fast_originate_helper::account, fast_originate_helper::app, fast_originate_helper::appdata, AST_CHANNEL_NAME, ast_channel_unlock, ast_manager_event_multichan, ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_strlen_zero(), fast_originate_helper::cid_name, fast_originate_helper::cid_num, fast_originate_helper::context, fast_originate_helper::data, destroy_fast_originate_helper(), EVENT_FLAG_CALL, fast_originate_helper::exten, fast_originate_helper::format, fast_originate_helper::idtext, fast_originate_helper::priority, S_OR, fast_originate_helper::tech, fast_originate_helper::timeout, and fast_originate_helper::vars.

Referenced by action_originate().

03743 {
03744    struct fast_originate_helper *in = data;
03745    int res;
03746    int reason = 0;
03747    struct ast_channel *chan = NULL, *chans[1];
03748    char requested_channel[AST_CHANNEL_NAME];
03749 
03750    if (!ast_strlen_zero(in->app)) {
03751       res = ast_pbx_outgoing_app(in->tech, in->format, (char *) in->data,
03752          in->timeout, in->app, in->appdata, &reason, 1,
03753          S_OR(in->cid_num, NULL),
03754          S_OR(in->cid_name, NULL),
03755          in->vars, in->account, &chan);
03756    } else {
03757       res = ast_pbx_outgoing_exten(in->tech, in->format, (char *) in->data,
03758          in->timeout, in->context, in->exten, in->priority, &reason, 1,
03759          S_OR(in->cid_num, NULL),
03760          S_OR(in->cid_name, NULL),
03761          in->vars, in->account, &chan);
03762    }
03763    /* Any vars memory was passed to the ast_pbx_outgoing_xxx() calls. */
03764    in->vars = NULL;
03765 
03766    if (!chan) {
03767       snprintf(requested_channel, AST_CHANNEL_NAME, "%s/%s", in->tech, in->data);
03768    }
03769    /* Tell the manager what happened with the channel */
03770    chans[0] = chan;
03771    ast_manager_event_multichan(EVENT_FLAG_CALL, "OriginateResponse", chan ? 1 : 0, chans,
03772       "%s"
03773       "Response: %s\r\n"
03774       "Channel: %s\r\n"
03775       "Context: %s\r\n"
03776       "Exten: %s\r\n"
03777       "Reason: %d\r\n"
03778       "Uniqueid: %s\r\n"
03779       "CallerIDNum: %s\r\n"
03780       "CallerIDName: %s\r\n",
03781       in->idtext, res ? "Failure" : "Success",
03782       chan ? chan->name : requested_channel, in->context, in->exten, reason,
03783       chan ? chan->uniqueid : "<null>",
03784       S_OR(in->cid_num, "<unknown>"),
03785       S_OR(in->cid_name, "<unknown>")
03786       );
03787 
03788    /* Locked by ast_pbx_outgoing_exten or ast_pbx_outgoing_app */
03789    if (chan) {
03790       ast_channel_unlock(chan);
03791    }
03792    destroy_fast_originate_helper(in);
03793    return NULL;
03794 }

static void free_channelvars ( void   )  [static]

Definition at line 7138 of file manager.c.

References ast_free, AST_RWLIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and var.

Referenced by __init_manager(), and load_channelvars().

07139 {
07140    struct manager_channel_variable *var;
07141    AST_RWLIST_WRLOCK(&channelvars);
07142    while ((var = AST_RWLIST_REMOVE_HEAD(&channelvars, entry))) {
07143       ast_free(var);
07144    }
07145    AST_RWLIST_UNLOCK(&channelvars);
07146 }

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

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

Definition at line 1197 of file manager.c.

References EVENT_FLAG_SYSTEM.

Referenced by action_getvar(), and action_status().

01198 {
01199    if (!(writepermlist & EVENT_FLAG_SYSTEM)
01200       && (
01201          strstr(evaluating, "SHELL") ||       /* NoOp(${SHELL(rm -rf /)})  */
01202          strstr(evaluating, "EVAL")           /* NoOp(${EVAL(${some_var_containing_SHELL})}) */
01203       )) {
01204       return 0;
01205    }
01206    return 1;
01207 }

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

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

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

Definition at line 4772 of file manager.c.

References ao2_lock, ao2_unlock, ast_inet_ntoa(), ast_log(), AST_PTHREADT_NULL, ast_wait_for_input(), mansession_session::authenticated, mansession_session::authstart, errno, mansession_session::f, mansession_session::fd, mansession_session::inbuf, mansession_session::inlen, LOG_ERROR, LOG_WARNING, MESSAGE_LINE_TOO_LONG, mansession::parsing, mansession_session::pending_event, mansession::session, mansession_session::sin, ast_frame::src, and mansession_session::waiting_thread.

Referenced by do_message().

04773 {
04774    int res, x;
04775    int maxlen = sizeof(s->session->inbuf) - 1;
04776    char *src = s->session->inbuf;
04777    int timeout = -1;
04778    time_t now;
04779 
04780    /*
04781     * Look for \r\n within the buffer. If found, copy to the output
04782     * buffer and return, trimming the \r\n (not used afterwards).
04783     */
04784    for (x = 0; x < s->session->inlen; x++) {
04785       int cr;  /* set if we have \r */
04786       if (src[x] == '\r' && x+1 < s->session->inlen && src[x + 1] == '\n') {
04787          cr = 2;  /* Found. Update length to include \r\n */
04788       } else if (src[x] == '\n') {
04789          cr = 1;  /* also accept \n only */
04790       } else {
04791          continue;
04792       }
04793       memmove(output, src, x);   /*... but trim \r\n */
04794       output[x] = '\0';    /* terminate the string */
04795       x += cr;       /* number of bytes used */
04796       s->session->inlen -= x;       /* remaining size */
04797       memmove(src, src + x, s->session->inlen); /* remove used bytes */
04798       return 1;
04799    }
04800    if (s->session->inlen >= maxlen) {
04801       /* no crlf found, and buffer full - sorry, too long for us */
04802       ast_log(LOG_WARNING, "Discarding message from %s. Line too long: %.25s...\n", ast_inet_ntoa(s->session->sin.sin_addr), src);
04803       s->session->inlen = 0;
04804       s->parsing = MESSAGE_LINE_TOO_LONG;
04805    }
04806    res = 0;
04807    while (res == 0) {
04808       /* calculate a timeout if we are not authenticated */
04809       if (!s->session->authenticated) {
04810          if(time(&now) == -1) {
04811             ast_log(LOG_ERROR, "error executing time(): %s\n", strerror(errno));
04812             return -1;
04813          }
04814 
04815          timeout = (authtimeout - (now - s->session->authstart)) * 1000;
04816          if (timeout < 0) {
04817             /* we have timed out */
04818             return 0;
04819          }
04820       }
04821 
04822       ao2_lock(s->session);
04823       if (s->session->pending_event) {
04824          s->session->pending_event = 0;
04825          ao2_unlock(s->session);
04826          return 0;
04827       }
04828       s->session->waiting_thread = pthread_self();
04829       ao2_unlock(s->session);
04830 
04831       res = ast_wait_for_input(s->session->fd, timeout);
04832 
04833       ao2_lock(s->session);
04834       s->session->waiting_thread = AST_PTHREADT_NULL;
04835       ao2_unlock(s->session);
04836    }
04837    if (res < 0) {
04838       /* If we get a signal from some other thread (typically because
04839        * there are new events queued), return 0 to notify the caller.
04840        */
04841       if (errno == EINTR || errno == EAGAIN) {
04842          return 0;
04843       }
04844       ast_log(LOG_WARNING, "poll() returned error: %s\n", strerror(errno));
04845       return -1;
04846    }
04847 
04848    ao2_lock(s->session);
04849    res = fread(src + s->session->inlen, 1, maxlen - s->session->inlen, s->session->f);
04850    if (res < 1) {
04851       res = -1;   /* error return */
04852    } else {
04853       s->session->inlen += res;
04854       src[s->session->inlen] = '\0';
04855       res = 0;
04856    }
04857    ao2_unlock(s->session);
04858    return res;
04859 }

static struct ast_manager_user* get_manager_by_name_locked ( const char *  name  )  [static, read]

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

Definition at line 1411 of file manager.c.

References AST_RWLIST_TRAVERSE, ast_manager_user::list, and ast_manager_user::username.

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

01412 {
01413    struct ast_manager_user *user = NULL;
01414 
01415    AST_RWLIST_TRAVERSE(&users, user, list) {
01416       if (!strcasecmp(user->username, name)) {
01417          break;
01418       }
01419    }
01420 
01421    return user;
01422 }

static int get_perm ( const char *  instr  )  [static]

Definition at line 1253 of file manager.c.

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

Referenced by __init_manager(), and strings_to_mask().

01254 {
01255    int x = 0, ret = 0;
01256 
01257    if (!instr) {
01258       return 0;
01259    }
01260 
01261    for (x = 0; x < ARRAY_LEN(perms); x++) {
01262       if (ast_instring(instr, perms[x].label, ',')) {
01263          ret |= perms[x].num;
01264       }
01265    }
01266 
01267    return ret;
01268 }

static struct eventqent* grab_last ( void   )  [static, read]

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

Definition at line 1119 of file manager.c.

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

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

01120 {
01121    struct eventqent *ret;
01122 
01123    AST_RWLIST_WRLOCK(&all_events);
01124    ret = AST_RWLIST_LAST(&all_events);
01125    /* the list is never empty now, but may become so when
01126     * we optimize it in the future, so be prepared.
01127     */
01128    if (ret) {
01129       ast_atomic_fetchadd_int(&ret->usecount, 1);
01130    }
01131    AST_RWLIST_UNLOCK(&all_events);
01132    return ret;
01133 }

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

CLI command manager reload.

Definition at line 1745 of file manager.c.

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

01746 {
01747    switch (cmd) {
01748    case CLI_INIT:
01749       e->command = "manager reload";
01750       e->usage =
01751          "Usage: manager reload\n"
01752          "       Reloads the manager configuration.\n";
01753       return NULL;
01754    case CLI_GENERATE:
01755       return NULL;
01756    }
01757    if (a->argc > 2) {
01758       return CLI_SHOWUSAGE;
01759    }
01760    reload_manager();
01761    return CLI_SUCCESS;
01762 }

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

Definition at line 1519 of file manager.c.

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

01520 {
01521    switch (cmd) {
01522    case CLI_INIT:
01523       e->command = "manager set debug [on|off]";
01524       e->usage = "Usage: manager set debug [on|off]\n Show, enable, disable debugging of the manager code.\n";
01525       return NULL;
01526    case CLI_GENERATE:
01527       return NULL;
01528    }
01529 
01530    if (a->argc == 3) {
01531       ast_cli(a->fd, "manager debug is %s\n", manager_debug? "on" : "off");
01532    } else if (a->argc == 4) {
01533       if (!strcasecmp(a->argv[3], "on")) {
01534          manager_debug = 1;
01535       } else if (!strcasecmp(a->argv[3], "off")) {
01536          manager_debug = 0;
01537       } else {
01538          return CLI_SHOWUSAGE;
01539       }
01540    }
01541    return CLI_SUCCESS;
01542 }

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

Definition at line 4870 of file manager.c.

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

Referenced by do_message().

04871 {
04872    mansession_lock(s);
04873    astman_send_error(s, m, error);
04874    s->parsing = MESSAGE_OKAY;
04875    mansession_unlock(s);
04876 }

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

Definition at line 1544 of file manager.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_str_alloca, ast_strdup, authority_to_str(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_manager_user::displayconnects, ast_cli_args::fd, get_manager_by_name_locked(), ast_manager_user::ha, ast_cli_args::n, ast_cli_args::pos, ast_manager_user::readperm, ast_manager_user::secret, ast_cli_entry::usage, ast_manager_user::username, ast_cli_args::word, and ast_manager_user::writeperm.

01545 {
01546    struct ast_manager_user *user = NULL;
01547    int l, which;
01548    char *ret = NULL;
01549    struct ast_str *rauthority = ast_str_alloca(128);
01550    struct ast_str *wauthority = ast_str_alloca(128);
01551 
01552    switch (cmd) {
01553    case CLI_INIT:
01554       e->command = "manager show user";
01555       e->usage =
01556          " Usage: manager show user <user>\n"
01557          "        Display all information related to the manager user specified.\n";
01558       return NULL;
01559    case CLI_GENERATE:
01560       l = strlen(a->word);
01561       which = 0;
01562       if (a->pos != 3) {
01563          return NULL;
01564       }
01565       AST_RWLIST_RDLOCK(&users);
01566       AST_RWLIST_TRAVERSE(&users, user, list) {
01567          if ( !strncasecmp(a->word, user->username, l) && ++which > a->n ) {
01568             ret = ast_strdup(user->username);
01569             break;
01570          }
01571       }
01572       AST_RWLIST_UNLOCK(&users);
01573       return ret;
01574    }
01575 
01576    if (a->argc != 4) {
01577       return CLI_SHOWUSAGE;
01578    }
01579 
01580    AST_RWLIST_RDLOCK(&users);
01581 
01582    if (!(user = get_manager_by_name_locked(a->argv[3]))) {
01583       ast_cli(a->fd, "There is no manager called %s\n", a->argv[3]);
01584       AST_RWLIST_UNLOCK(&users);
01585       return CLI_SUCCESS;
01586    }
01587 
01588    ast_cli(a->fd, "\n");
01589    ast_cli(a->fd,
01590       "       username: %s\n"
01591       "         secret: %s\n"
01592       "            acl: %s\n"
01593       "      read perm: %s\n"
01594       "     write perm: %s\n"
01595       "displayconnects: %s\n",
01596       (user->username ? user->username : "(N/A)"),
01597       (user->secret ? "<Set>" : "(N/A)"),
01598       (user->ha ? "yes" : "no"),
01599       authority_to_str(user->readperm, &rauthority),
01600       authority_to_str(user->writeperm, &wauthority),
01601       (user->displayconnects ? "yes" : "no"));
01602 
01603    AST_RWLIST_UNLOCK(&users);
01604 
01605    return CLI_SUCCESS;
01606 }

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

Definition at line 1608 of file manager.c.

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

01609 {
01610    struct ast_manager_user *user = NULL;
01611    int count_amu = 0;
01612    switch (cmd) {
01613    case CLI_INIT:
01614       e->command = "manager show users";
01615       e->usage =
01616          "Usage: manager show users\n"
01617          "       Prints a listing of all managers that are currently configured on that\n"
01618          " system.\n";
01619       return NULL;
01620    case CLI_GENERATE:
01621       return NULL;
01622    }
01623    if (a->argc != 3) {
01624       return CLI_SHOWUSAGE;
01625    }
01626 
01627    AST_RWLIST_RDLOCK(&users);
01628 
01629    /* If there are no users, print out something along those lines */
01630    if (AST_RWLIST_EMPTY(&users)) {
01631       ast_cli(a->fd, "There are no manager users.\n");
01632       AST_RWLIST_UNLOCK(&users);
01633       return CLI_SUCCESS;
01634    }
01635 
01636    ast_cli(a->fd, "\nusername\n--------\n");
01637 
01638    AST_RWLIST_TRAVERSE(&users, user, list) {
01639       ast_cli(a->fd, "%s\n", user->username);
01640       count_amu++;
01641    }
01642 
01643    AST_RWLIST_UNLOCK(&users);
01644 
01645    ast_cli(a->fd,"-------------------\n"
01646             "%d manager users configured.\n", count_amu);
01647    return CLI_SUCCESS;
01648 }

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

Definition at line 1442 of file manager.c.

References manager_action::action, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_str_alloca, ast_strdup, AST_XML_DOC, ast_xmldoc_printable(), manager_action::authority, authority_to_str(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, COLOR_MAGENTA, ast_cli_entry::command, manager_action::docsrc, ast_cli_args::fd, ast_cli_args::n, S_OR, term_color(), ast_cli_entry::usage, and ast_cli_args::word.

01443 {
01444    struct manager_action *cur;
01445    struct ast_str *authority;
01446    int num, l, which;
01447    char *ret = NULL;
01448 #ifdef AST_XML_DOCS
01449    char syntax_title[64], description_title[64], synopsis_title[64], seealso_title[64], arguments_title[64];
01450 #endif
01451 
01452    switch (cmd) {
01453    case CLI_INIT:
01454       e->command = "manager show command";
01455       e->usage =
01456          "Usage: manager show command <actionname> [<actionname> [<actionname> [...]]]\n"
01457          "  Shows the detailed description for a specific Asterisk manager interface command.\n";
01458       return NULL;
01459    case CLI_GENERATE:
01460       l = strlen(a->word);
01461       which = 0;
01462       AST_RWLIST_RDLOCK(&actions);
01463       AST_RWLIST_TRAVERSE(&actions, cur, list) {
01464          if (!strncasecmp(a->word, cur->action, l) && ++which > a->n) {
01465             ret = ast_strdup(cur->action);
01466             break;   /* make sure we exit even if ast_strdup() returns NULL */
01467          }
01468       }
01469       AST_RWLIST_UNLOCK(&actions);
01470       return ret;
01471    }
01472    authority = ast_str_alloca(80);
01473    if (a->argc < 4) {
01474       return CLI_SHOWUSAGE;
01475    }
01476 
01477 #ifdef AST_XML_DOCS
01478    /* setup the titles */
01479    term_color(synopsis_title, "[Synopsis]\n", COLOR_MAGENTA, 0, 40);
01480    term_color(description_title, "[Description]\n", COLOR_MAGENTA, 0, 40);
01481    term_color(syntax_title, "[Syntax]\n", COLOR_MAGENTA, 0, 40);
01482    term_color(seealso_title, "[See Also]\n", COLOR_MAGENTA, 0, 40);
01483    term_color(arguments_title, "[Arguments]\n", COLOR_MAGENTA, 0, 40);
01484 #endif
01485 
01486    AST_RWLIST_RDLOCK(&actions);
01487    AST_RWLIST_TRAVERSE(&actions, cur, list) {
01488       for (num = 3; num < a->argc; num++) {
01489          if (!strcasecmp(cur->action, a->argv[num])) {
01490 #ifdef AST_XML_DOCS
01491             if (cur->docsrc == AST_XML_DOC) {
01492                ast_cli(a->fd, "%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n",
01493                   syntax_title,
01494                   ast_xmldoc_printable(S_OR(cur->syntax, "Not available"), 1),
01495                   synopsis_title,
01496                   ast_xmldoc_printable(S_OR(cur->synopsis, "Not available"), 1),
01497                   description_title,
01498                   ast_xmldoc_printable(S_OR(cur->description, "Not available"), 1),
01499                   arguments_title,
01500                   ast_xmldoc_printable(S_OR(cur->arguments, "Not available"), 1),
01501                   seealso_title,
01502                   ast_xmldoc_printable(S_OR(cur->seealso, "Not available"), 1));
01503             } else
01504 #endif
01505             {
01506                ast_cli(a->fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n",
01507                   cur->action, cur->synopsis,
01508                   authority_to_str(cur->authority, &authority),
01509                   S_OR(cur->description, ""));
01510             }
01511          }
01512       }
01513    }
01514    AST_RWLIST_UNLOCK(&actions);
01515 
01516    return CLI_SUCCESS;
01517 }

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

CLI command manager list commands.

Definition at line 1651 of file manager.c.

References manager_action::action, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_str_alloca, manager_action::authority, authority_to_str(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, HSMC_FORMAT, and ast_cli_entry::usage.

01652 {
01653    struct manager_action *cur;
01654    struct ast_str *authority;
01655 #define HSMC_FORMAT "  %-15.15s  %-15.15s  %-55.55s\n"
01656    switch (cmd) {
01657    case CLI_INIT:
01658       e->command = "manager show commands";
01659       e->usage =
01660          "Usage: manager show commands\n"
01661          "  Prints a listing of all the available Asterisk manager interface commands.\n";
01662       return NULL;
01663    case CLI_GENERATE:
01664       return NULL;
01665    }
01666    authority = ast_str_alloca(80);
01667    ast_cli(a->fd, HSMC_FORMAT, "Action", "Privilege", "Synopsis");
01668    ast_cli(a->fd, HSMC_FORMAT, "------", "---------", "--------");
01669 
01670    AST_RWLIST_RDLOCK(&actions);
01671    AST_RWLIST_TRAVERSE(&actions, cur, list) {
01672       ast_cli(a->fd, HSMC_FORMAT, cur->action, authority_to_str(cur->authority, &authority), cur->synopsis);
01673    }
01674    AST_RWLIST_UNLOCK(&actions);
01675 
01676    return CLI_SUCCESS;
01677 }

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

CLI command manager list connected.

Definition at line 1680 of file manager.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_unlock, ast_cli(), ast_inet_ntoa(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, mansession_session::fd, ast_cli_args::fd, HSMCONN_FORMAT1, HSMCONN_FORMAT2, mansession_session::inuse, mansession_session::readperm, sessions, mansession_session::sessionstart, mansession_session::sin, unref_mansession(), ast_cli_entry::usage, mansession_session::username, and mansession_session::writeperm.

01681 {
01682    struct mansession_session *session;
01683    time_t now = time(NULL);
01684 #define HSMCONN_FORMAT1 "  %-15.15s  %-15.15s  %-10.10s  %-10.10s  %-8.8s  %-8.8s  %-5.5s  %-5.5s\n"
01685 #define HSMCONN_FORMAT2 "  %-15.15s  %-15.15s  %-10d  %-10d  %-8d  %-8d  %-5.5d  %-5.5d\n"
01686    int count = 0;
01687    struct ao2_iterator i;
01688 
01689    switch (cmd) {
01690    case CLI_INIT:
01691       e->command = "manager show connected";
01692       e->usage =
01693          "Usage: manager show connected\n"
01694          "  Prints a listing of the users that are currently connected to the\n"
01695          "Asterisk manager interface.\n";
01696       return NULL;
01697    case CLI_GENERATE:
01698       return NULL;
01699    }
01700 
01701    ast_cli(a->fd, HSMCONN_FORMAT1, "Username", "IP Address", "Start", "Elapsed", "FileDes", "HttpCnt", "Read", "Write");
01702 
01703    i = ao2_iterator_init(sessions, 0);
01704    while ((session = ao2_iterator_next(&i))) {
01705       ao2_lock(session);
01706       ast_cli(a->fd, HSMCONN_FORMAT2, session->username, ast_inet_ntoa(session->sin.sin_addr), (int)(session->sessionstart), (int)(now - session->sessionstart), session->fd, session->inuse, session->readperm, session->writeperm);
01707       count++;
01708       ao2_unlock(session);
01709       unref_mansession(session);
01710    }
01711    ao2_iterator_destroy(&i);
01712    ast_cli(a->fd, "%d users connected.\n", count);
01713 
01714    return CLI_SUCCESS;
01715 }

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

CLI command manager list eventq.

Definition at line 1719 of file manager.c.

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

01720 {
01721    struct eventqent *s;
01722    switch (cmd) {
01723    case CLI_INIT:
01724       e->command = "manager show eventq";
01725       e->usage =
01726          "Usage: manager show eventq\n"
01727          "  Prints a listing of all events pending in the Asterisk manger\n"
01728          "event queue.\n";
01729       return NULL;
01730    case CLI_GENERATE:
01731       return NULL;
01732    }
01733    AST_RWLIST_RDLOCK(&all_events);
01734    AST_RWLIST_TRAVERSE(&all_events, s, eq_next) {
01735       ast_cli(a->fd, "Usecount: %d\n", s->usecount);
01736       ast_cli(a->fd, "Category: %d\n", s->category);
01737       ast_cli(a->fd, "Event:\n%s", s->eventdata);
01738    }
01739    AST_RWLIST_UNLOCK(&all_events);
01740 
01741    return CLI_SUCCESS;
01742 }

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

Definition at line 2657 of file manager.c.

References ast_category_append(), ast_category_delete(), ast_category_empty(), ast_category_get(), ast_category_insert(), ast_category_new(), ast_category_rename(), ast_free, ast_log(), ast_str_create(), ast_strlen_zero(), ast_variable_append(), ast_variable_delete(), ast_variable_insert(), ast_variable_new(), ast_variable_update(), astman_get_header(), eventqent::category, FAILURE_ALLOCATION, FAILURE_DELCAT, FAILURE_DELETE, FAILURE_EMPTYCAT, FAILURE_NEWCAT, FAILURE_UPDATE, LOG_WARNING, match(), ast_variable::object, UNKNOWN_ACTION, UNKNOWN_CATEGORY, UNSPECIFIED_ARGUMENT, UNSPECIFIED_CATEGORY, value, and var.

Referenced by action_updateconfig().

02658 {
02659    int x;
02660    char hdr[40];
02661    const char *action, *cat, *var, *value, *match, *line;
02662    struct ast_category *category;
02663    struct ast_variable *v;
02664    struct ast_str *str1 = ast_str_create(16), *str2 = ast_str_create(16);
02665    enum error_type result = 0;
02666 
02667    for (x = 0; x < 100000; x++) {   /* 100000 = the max number of allowed updates + 1 */
02668       unsigned int object = 0;
02669 
02670       snprintf(hdr, sizeof(hdr), "Action-%06d", x);
02671       action = astman_get_header(m, hdr);
02672       if (ast_strlen_zero(action))     /* breaks the for loop if no action header */
02673          break;                        /* this could cause problems if actions come in misnumbered */
02674 
02675       snprintf(hdr, sizeof(hdr), "Cat-%06d", x);
02676       cat = astman_get_header(m, hdr);
02677       if (ast_strlen_zero(cat)) {      /* every action needs a category */
02678          result =  UNSPECIFIED_CATEGORY;
02679          break;
02680       }
02681 
02682       snprintf(hdr, sizeof(hdr), "Var-%06d", x);
02683       var = astman_get_header(m, hdr);
02684 
02685       snprintf(hdr, sizeof(hdr), "Value-%06d", x);
02686       value = astman_get_header(m, hdr);
02687 
02688       if (!ast_strlen_zero(value) && *value == '>') {
02689          object = 1;
02690          value++;
02691       }
02692 
02693       snprintf(hdr, sizeof(hdr), "Match-%06d", x);
02694       match = astman_get_header(m, hdr);
02695 
02696       snprintf(hdr, sizeof(hdr), "Line-%06d", x);
02697       line = astman_get_header(m, hdr);
02698 
02699       if (!strcasecmp(action, "newcat")) {
02700          if (ast_category_get(cfg,cat)) { /* check to make sure the cat doesn't */
02701             result = FAILURE_NEWCAT;   /* already exist */
02702             break;
02703          }
02704          if (!(category = ast_category_new(cat, dfn, -1))) {
02705             result = FAILURE_ALLOCATION;
02706             break;
02707          }
02708          if (ast_strlen_zero(match)) {
02709             ast_category_append(cfg, category);
02710          } else {
02711             ast_category_insert(cfg, category, match);
02712          }
02713       } else if (!strcasecmp(action, "renamecat")) {
02714          if (ast_strlen_zero(value)) {
02715             result = UNSPECIFIED_ARGUMENT;
02716             break;
02717          }
02718          if (!(category = ast_category_get(cfg, cat))) {
02719             result = UNKNOWN_CATEGORY;
02720             break;
02721          }
02722          ast_category_rename(category, value);
02723       } else if (!strcasecmp(action, "delcat")) {
02724          if (ast_category_delete(cfg, cat)) {
02725             result = FAILURE_DELCAT;
02726             break;
02727          }
02728       } else if (!strcasecmp(action, "emptycat")) {
02729          if (ast_category_empty(cfg, cat)) {
02730             result = FAILURE_EMPTYCAT;
02731             break;
02732          }
02733       } else if (!strcasecmp(action, "update")) {
02734          if (ast_strlen_zero(var)) {
02735             result = UNSPECIFIED_ARGUMENT;
02736             break;
02737          }
02738          if (!(category = ast_category_get(cfg,cat))) {
02739             result = UNKNOWN_CATEGORY;
02740             break;
02741          }
02742          if (ast_variable_update(category, var, value, match, object)) {
02743             result = FAILURE_UPDATE;
02744             break;
02745          }
02746       } else if (!strcasecmp(action, "delete")) {
02747          if ((ast_strlen_zero(var) && ast_strlen_zero(line))) {
02748             result = UNSPECIFIED_ARGUMENT;
02749             break;
02750          }
02751          if (!(category = ast_category_get(cfg, cat))) {
02752             result = UNKNOWN_CATEGORY;
02753             break;
02754          }
02755          if (ast_variable_delete(category, var, match, line)) {
02756             result = FAILURE_DELETE;
02757             break;
02758          }
02759       } else if (!strcasecmp(action, "append")) {
02760          if (ast_strlen_zero(var)) {
02761             result = UNSPECIFIED_ARGUMENT;
02762             break;
02763          }
02764          if (!(category = ast_category_get(cfg, cat))) {
02765             result = UNKNOWN_CATEGORY;
02766             break;
02767          }
02768          if (!(v = ast_variable_new(var, value, dfn))) {
02769             result = FAILURE_ALLOCATION;
02770             break;
02771          }
02772          if (object || (match && !strcasecmp(match, "object"))) {
02773             v->object = 1;
02774          }
02775          ast_variable_append(category, v);
02776       } else if (!strcasecmp(action, "insert")) {
02777          if (ast_strlen_zero(var) || ast_strlen_zero(line)) {
02778             result = UNSPECIFIED_ARGUMENT;
02779             break;
02780          }
02781          if (!(category = ast_category_get(cfg, cat))) {
02782             result = UNKNOWN_CATEGORY;
02783             break;
02784          }
02785          if (!(v = ast_variable_new(var, value, dfn))) {
02786             result = FAILURE_ALLOCATION;
02787             break;
02788          }
02789          ast_variable_insert(category, v, line);
02790       }
02791       else {
02792          ast_log(LOG_WARNING, "Action-%06d: %s not handled\n", x, action);
02793          result = UNKNOWN_ACTION;
02794          break;
02795       }
02796    }
02797    ast_free(str1);
02798    ast_free(str2);
02799    return result;
02800 }

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

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

Definition at line 2579 of file manager.c.

Referenced by astman_append_json().

02580 {
02581    for (; *in; in++) {
02582       if (*in == '\\' || *in == '\"') {
02583          *out++ = '\\';
02584       }
02585       *out++ = *in;
02586    }
02587    *out = '\0';
02588 }

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

Definition at line 1845 of file manager.c.

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

Referenced by astman_get_variables().

01846 {
01847    char *parse;
01848    AST_DECLARE_APP_ARGS(args,
01849       AST_APP_ARG(vars)[64];
01850    );
01851 
01852    hdr_val = ast_skip_blanks(hdr_val); /* ignore leading spaces in the value */
01853    parse = ast_strdupa(hdr_val);
01854 
01855    /* Break the header value string into name=val pair items. */
01856    AST_STANDARD_APP_ARGS(args, parse);
01857    if (args.argc) {
01858       int y;
01859 
01860       /* Process each name=val pair item. */
01861       for (y = 0; y < args.argc; y++) {
01862          struct ast_variable *cur;
01863          char *var;
01864          char *val;
01865 
01866          if (!args.vars[y]) {
01867             continue;
01868          }
01869          var = val = args.vars[y];
01870          strsep(&val, "=");
01871 
01872          /* XXX We may wish to trim whitespace from the strings. */
01873          if (!val || ast_strlen_zero(var)) {
01874             continue;
01875          }
01876 
01877          /* Create new variable list node and prepend it to the list. */
01878          cur = ast_variable_new(var, val, "");
01879          if (cur) {
01880             cur->next = head;
01881             head = cur;
01882          }
01883       }
01884    }
01885 
01886    return head;
01887 }

static int manager_displayconnects ( struct mansession_session *  session  )  [static]

Get displayconnects config option.

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

Definition at line 1428 of file manager.c.

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

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

01429 {
01430    struct ast_manager_user *user = NULL;
01431    int ret = 0;
01432 
01433    AST_RWLIST_RDLOCK(&users);
01434    if ((user = get_manager_by_name_locked (session->username))) {
01435       ret = user->displayconnects;
01436    }
01437    AST_RWLIST_UNLOCK(&users);
01438 
01439    return ret;
01440 }

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

Definition at line 4562 of file manager.c.

References ast_copy_string(), ast_file_version_find(), ast_log(), ast_module_check(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), LOG_DEBUG, and version.

Referenced by __init_manager().

04563 {
04564    int res;
04565    const char *module = astman_get_header(m, "Module");
04566    const char *id = astman_get_header(m, "ActionID");
04567    char idText[256];
04568 #if !defined(LOW_MEMORY)
04569    const char *version;
04570 #endif
04571    char filename[PATH_MAX];
04572    char *cut;
04573 
04574    ast_copy_string(filename, module, sizeof(filename));
04575    if ((cut = strchr(filename, '.'))) {
04576       *cut = '\0';
04577    } else {
04578       cut = filename + strlen(filename);
04579    }
04580    snprintf(cut, (sizeof(filename) - strlen(filename)) - 1, ".so");
04581    ast_log(LOG_DEBUG, "**** ModuleCheck .so file %s\n", filename);
04582    res = ast_module_check(filename);
04583    if (!res) {
04584       astman_send_error(s, m, "Module not loaded");
04585       return 0;
04586    }
04587    snprintf(cut, (sizeof(filename) - strlen(filename)) - 1, ".c");
04588    ast_log(LOG_DEBUG, "**** ModuleCheck .c file %s\n", filename);
04589 #if !defined(LOW_MEMORY)
04590    version = ast_file_version_find(filename);
04591 #endif
04592 
04593    if (!ast_strlen_zero(id)) {
04594       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
04595    } else {
04596       idText[0] = '\0';
04597    }
04598    astman_append(s, "Response: Success\r\n%s", idText);
04599 #if !defined(LOW_MEMORY)
04600    astman_append(s, "Version: %s\r\n\r\n", version ? version : "");
04601 #endif
04602    return 0;
04603 }

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

Definition at line 4605 of file manager.c.

References AST_FORCE_SOFT, ast_load_resource(), ast_module_reload(), ast_strlen_zero(), ast_unload_resource(), astman_get_header(), astman_send_ack(), and astman_send_error().

Referenced by __init_manager().

04606 {
04607    int res;
04608    const char *module = astman_get_header(m, "Module");
04609    const char *loadtype = astman_get_header(m, "LoadType");
04610 
04611    if (!loadtype || strlen(loadtype) == 0) {
04612       astman_send_error(s, m, "Incomplete ModuleLoad action.");
04613    }
04614    if ((!module || strlen(module) == 0) && strcasecmp(loadtype, "reload") != 0) {
04615       astman_send_error(s, m, "Need module name");
04616    }
04617 
04618    if (!strcasecmp(loadtype, "load")) {
04619       res = ast_load_resource(module);
04620       if (res) {
04621          astman_send_error(s, m, "Could not load module.");
04622       } else {
04623          astman_send_ack(s, m, "Module loaded.");
04624       }
04625    } else if (!strcasecmp(loadtype, "unload")) {
04626       res = ast_unload_resource(module, AST_FORCE_SOFT);
04627       if (res) {
04628          astman_send_error(s, m, "Could not unload module.");
04629       } else {
04630          astman_send_ack(s, m, "Module unloaded.");
04631       }
04632    } else if (!strcasecmp(loadtype, "reload")) {
04633       if (!ast_strlen_zero(module)) {
04634          res = ast_module_reload(module);
04635          if (res == 0) {
04636             astman_send_error(s, m, "No such module.");
04637          } else if (res == 1) {
04638             astman_send_error(s, m, "Module does not support reload action.");
04639          } else {
04640             astman_send_ack(s, m, "Module reloaded.");
04641          }
04642       } else {
04643          ast_module_reload(NULL);   /* Reload all modules */
04644          astman_send_ack(s, m, "All modules reloaded");
04645       }
04646    } else
04647       astman_send_error(s, m, "Incomplete ModuleLoad action.");
04648    return 0;
04649 }

static int manager_state_cb ( char *  context,
char *  exten,
int  state,
void *  data 
) [static]

Definition at line 5297 of file manager.c.

References ast_get_hint(), EVENT_FLAG_CALL, and manager_event.

Referenced by __init_manager().

05298 {
05299    /* Notify managers of change */
05300    char hint[512];
05301    ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, context, exten);
05302 
05303    manager_event(EVENT_FLAG_CALL, "ExtensionStatus", "Exten: %s\r\nContext: %s\r\nHint: %s\r\nStatus: %d\r\n", exten, context, hint, state);
05304    return 0;
05305 }

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

Definition at line 1380 of file manager.c.

References CMP_MATCH, str, and mansession_session::username.

Referenced by __init_manager().

01381 {
01382    struct mansession_session *s = obj;
01383    char *str = arg;
01384    return !strcasecmp(s->username, str) ? CMP_MATCH : 0;
01385 }

static struct sockaddr_in* mansession_encode_sin_local ( const struct mansession *  s,
struct sockaddr_in *  sin_local 
) [static, read]
static enum ast_security_event_transport_type mansession_get_transport ( const struct mansession *  s  )  [static]
static void mansession_lock ( struct mansession *  s  )  [static]

Lock the 'mansession' structure.

Definition at line 2112 of file manager.c.

References ast_mutex_lock, and mansession::lock.

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

02113 {
02114    ast_mutex_lock(&s->lock);
02115 }

static void mansession_unlock ( struct mansession *  s  )  [static]

Unlock the 'mansession' structure.

Definition at line 2118 of file manager.c.

References ast_mutex_unlock, and mansession::lock.

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

02119 {
02120    ast_mutex_unlock(&s->lock);
02121 }

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

Definition at line 4296 of file manager.c.

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

Referenced by process_events().

04297 {
04298    int result = 0;
04299 
04300    ast_debug(3, "Examining event:\n%s\n", eventdata);
04301    if (!ao2_container_count(s->session->whitefilters) && !ao2_container_count(s->session->blackfilters)) {
04302       return 1; /* no filtering means match all */
04303    } else if (ao2_container_count(s->session->whitefilters) && !ao2_container_count(s->session->blackfilters)) {
04304       /* white filters only: implied black all filter processed first, then white filters */
04305       ao2_t_callback_data(s->session->whitefilters, OBJ_NODATA, whitefilter_cmp_fn, eventdata, &result, "find filter in session filter container"); 
04306    } else if (!ao2_container_count(s->session->whitefilters) && ao2_container_count(s->session->blackfilters)) {
04307       /* black filters only: implied white all filter processed first, then black filters */
04308       ao2_t_callback_data(s->session->blackfilters, OBJ_NODATA, blackfilter_cmp_fn, eventdata, &result, "find filter in session filter container"); 
04309    } else {
04310       /* white and black filters: implied black all filter processed first, then white filters, and lastly black filters */
04311       ao2_t_callback_data(s->session->whitefilters, OBJ_NODATA, whitefilter_cmp_fn, eventdata, &result, "find filter in session filter container"); 
04312       if (result) {
04313          result = 0;
04314          ao2_t_callback_data(s->session->blackfilters, OBJ_NODATA, blackfilter_cmp_fn, eventdata, &result, "find filter in session filter container"); 
04315       }
04316    }
04317 
04318    return result;
04319 }

static int process_events ( struct mansession *  s  )  [static]

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

Definition at line 4326 of file manager.c.

References advance_event(), ao2_lock, ao2_unlock, mansession_session::authenticated, eventqent::category, eventqent::eventdata, mansession_session::f, mansession_session::last_ev, match_filter(), mansession_session::readperm, mansession_session::send_events, send_string(), and mansession::session.

Referenced by do_message(), and process_message().

04327 {
04328    int ret = 0;
04329 
04330    ao2_lock(s->session);
04331    if (s->session->f != NULL) {
04332       struct eventqent *eqe = s->session->last_ev;
04333 
04334       while ((eqe = advance_event(eqe))) {
04335          if (!ret && s->session->authenticated &&
04336              (s->session->readperm & eqe->category) == eqe->category &&
04337              (s->session->send_events & eqe->category) == eqe->category) {
04338                if (match_filter(s, eqe->eventdata)) {
04339                   if (send_string(s, eqe->eventdata) < 0)
04340                      ret = -1;   /* don't send more */
04341                }
04342          }
04343          s->session->last_ev = eqe;
04344       }
04345    }
04346    ao2_unlock(s->session);
04347    return ret;
04348 }

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

Definition at line 4664 of file manager.c.

References __astman_get_header(), manager_action::action, action_find(), manager_action::active_count, ao2_lock, ao2_t_ref, ao2_unlock, ast_debug, ast_strlen_zero(), astman_get_header(), astman_send_error(), mansession_session::authenticated, manager_action::authority, check_manager_session_inuse(), manager_action::func, GET_HEADER_SKIP_EMPTY, mansession_lock(), mansession_unlock(), process_events(), manager_action::registered, report_req_bad_format(), report_req_not_allowed(), report_session_limit(), mansession::session, and mansession_session::writeperm.

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

04665 {
04666    int ret = 0;
04667    struct manager_action *act_found;
04668    const char *user;
04669    const char *action;
04670 
04671    action = __astman_get_header(m, "Action", GET_HEADER_SKIP_EMPTY);
04672    if (ast_strlen_zero(action)) {
04673       report_req_bad_format(s, "NONE");
04674       mansession_lock(s);
04675       astman_send_error(s, m, "Missing action in request");
04676       mansession_unlock(s);
04677       return 0;
04678    }
04679 
04680    if (!s->session->authenticated
04681       && strcasecmp(action, "Login")
04682       && strcasecmp(action, "Logoff")
04683       && strcasecmp(action, "Challenge")) {
04684       if (!s->session->authenticated) {
04685          report_req_not_allowed(s, action);
04686       }
04687       mansession_lock(s);
04688       astman_send_error(s, m, "Permission denied");
04689       mansession_unlock(s);
04690       return 0;
04691    }
04692 
04693    if (!allowmultiplelogin
04694       && !s->session->authenticated
04695       && (!strcasecmp(action, "Login")
04696          || !strcasecmp(action, "Challenge"))) {
04697       user = astman_get_header(m, "Username");
04698 
04699       if (!ast_strlen_zero(user) && check_manager_session_inuse(user)) {
04700          report_session_limit(s);
04701          sleep(1);
04702          mansession_lock(s);
04703          astman_send_error(s, m, "Login Already In Use");
04704          mansession_unlock(s);
04705          return -1;
04706       }
04707    }
04708 
04709    act_found = action_find(action);
04710    if (act_found) {
04711       /* Found the requested AMI action. */
04712       int acted = 0;
04713 
04714       if ((s->session->writeperm & act_found->authority)
04715          || act_found->authority == 0) {
04716          /* We have the authority to execute the action. */
04717          ao2_lock(act_found);
04718          if (act_found->registered && act_found->func) {
04719             ast_debug(1, "Running action '%s'\n", act_found->action);
04720             ++act_found->active_count;
04721             ao2_unlock(act_found);
04722             ret = act_found->func(s, m);
04723             acted = 1;
04724             ao2_lock(act_found);
04725             --act_found->active_count;
04726          }
04727          ao2_unlock(act_found);
04728       }
04729       if (!acted) {
04730          /*
04731           * We did not execute the action because access was denied, it
04732           * was no longer registered, or no action was really registered.
04733           * Complain about it and leave.
04734           */
04735          report_req_not_allowed(s, action);
04736          mansession_lock(s);
04737          astman_send_error(s, m, "Permission denied");
04738          mansession_unlock(s);
04739       }
04740       ao2_t_ref(act_found, -1, "done with found action object");
04741    } else {
04742       char buf[512];
04743 
04744       report_req_bad_format(s, action);
04745       snprintf(buf, sizeof(buf), "Invalid/unknown command: %s. Use Action: ListCommands to show available commands.", action);
04746       mansession_lock(s);
04747       astman_send_error(s, m, buf);
04748       mansession_unlock(s);
04749    }
04750    if (ret) {
04751       return ret;
04752    }
04753    /* Once done with our message, deliver any pending events unless the
04754       requester doesn't want them as part of this response.
04755    */
04756    if (ast_strlen_zero(astman_get_header(m, "SuppressEvents"))) {
04757       return process_events(s);
04758    } else {
04759       return ret;
04760    }
04761 }

static void purge_events ( void   )  [static]

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

Definition at line 1139 of file manager.c.

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

Referenced by purge_old_stuff().

01140 {
01141    struct eventqent *ev;
01142    struct timeval now = ast_tvnow();
01143 
01144    AST_RWLIST_WRLOCK(&all_events);
01145    while ( (ev = AST_RWLIST_FIRST(&all_events)) &&
01146        ev->usecount == 0 && AST_RWLIST_NEXT(ev, eq_next)) {
01147       AST_RWLIST_REMOVE_HEAD(&all_events, eq_next);
01148       ast_free(ev);
01149    }
01150 
01151    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&all_events, ev, eq_next) {
01152       /* Never release the last event */
01153       if (!AST_RWLIST_NEXT(ev, eq_next)) {
01154          break;
01155       }
01156 
01157       /* 2.5 times whatever the HTTP timeout is (maximum 2.5 hours) is the maximum time that we will definitely cache an event */
01158       if (ev->usecount == 0 && ast_tvdiff_sec(now, ev->tv) > (httptimeout > 3600 ? 3600 : httptimeout) * 2.5) {
01159          AST_RWLIST_REMOVE_CURRENT(eq_next);
01160          ast_free(ev);
01161       }
01162    }
01163    AST_RWLIST_TRAVERSE_SAFE_END;
01164    AST_RWLIST_UNLOCK(&all_events);
01165 }

static void purge_sessions ( int  n_max  )  [static]

remove at most n_max stale session from the list.

Definition at line 5074 of file manager.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_unlock, ast_inet_ntoa(), ast_verb, mansession_session::authenticated, mansession_session::inuse, manager_displayconnects(), session_destroy(), sessions, mansession_session::sessiontimeout, mansession_session::sin, unref_mansession(), mansession_session::username, and VERBOSITY_ATLEAST.

Referenced by purge_old_stuff().

05075 {
05076    struct mansession_session *session;
05077    time_t now = time(NULL);
05078    struct ao2_iterator i;
05079 
05080    if (!sessions) {
05081       return;
05082    }
05083 
05084    i = ao2_iterator_init(sessions, 0);
05085    while ((session = ao2_iterator_next(&i)) && n_max > 0) {
05086       ao2_lock(session);
05087       if (session->sessiontimeout && (now > session->sessiontimeout) && !session->inuse) {
05088          if (session->authenticated && (VERBOSITY_ATLEAST(2)) && manager_displayconnects(session)) {
05089             ast_verb(2, "HTTP Manager '%s' timed out from %s\n",
05090                session->username, ast_inet_ntoa(session->sin.sin_addr));
05091          }
05092          ao2_unlock(session);
05093          session_destroy(session);
05094          n_max--;
05095       } else {
05096          ao2_unlock(session);
05097          unref_mansession(session);
05098       }
05099    }
05100    ao2_iterator_destroy(&i);
05101 }

static void report_auth_success ( const struct mansession *  s  )  [static]

Definition at line 2233 of file manager.c.

References AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_SUCCESSFUL_AUTH, AST_SECURITY_EVENT_SUCCESSFUL_AUTH_VERSION, ast_security_event_successful_auth::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, mansession_session::sin, and mansession_session::username.

Referenced by authenticate().

02234 {
02235    struct sockaddr_in sin_local;
02236    char session_id[32];
02237    struct ast_security_event_successful_auth successful_auth = {
02238       .common.event_type = AST_SECURITY_EVENT_SUCCESSFUL_AUTH,
02239       .common.version    = AST_SECURITY_EVENT_SUCCESSFUL_AUTH_VERSION,
02240       .common.service    = "AMI",
02241       .common.account_id = s->session->username,
02242       .common.session_tv = &s->session->sessionstart_tv,
02243       .common.local_addr = {
02244          .sin       = mansession_encode_sin_local(s, &sin_local),
02245          .transport = mansession_get_transport(s),
02246       },
02247       .common.remote_addr = {
02248          .sin       = &s->session->sin,
02249          .transport = mansession_get_transport(s),
02250       },
02251       .common.session_id = session_id,
02252    };
02253 
02254    snprintf(session_id, sizeof(session_id), "%p", s->session);
02255 
02256    ast_security_event_report(AST_SEC_EVT(&successful_auth));
02257 }

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

Definition at line 2181 of file manager.c.

References AST_SEC_EVT, AST_SECURITY_EVENT_FAILED_ACL, AST_SECURITY_EVENT_FAILED_ACL_VERSION, ast_security_event_report(), ast_security_event_failed_acl::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, and mansession_session::sin.

Referenced by authenticate().

02182 {
02183    struct sockaddr_in sin_local;
02184    char session_id[32];
02185    struct ast_security_event_failed_acl failed_acl_event = {
02186       .common.event_type = AST_SECURITY_EVENT_FAILED_ACL,
02187       .common.version    = AST_SECURITY_EVENT_FAILED_ACL_VERSION,
02188       .common.service    = "AMI",
02189       .common.account_id = username,
02190       .common.session_tv = &s->session->sessionstart_tv,
02191       .common.local_addr = {
02192          .sin       = mansession_encode_sin_local(s, &sin_local),
02193          .transport = mansession_get_transport(s),
02194       },
02195       .common.remote_addr = {
02196          .sin       = &s->session->sin,
02197          .transport = mansession_get_transport(s),
02198       },
02199       .common.session_id = session_id,
02200    };
02201 
02202    snprintf(session_id, sizeof(session_id), "%p", s->session);
02203 
02204    ast_security_event_report(AST_SEC_EVT(&failed_acl_event));
02205 }

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

Definition at line 2319 of file manager.c.

References AST_SEC_EVT, AST_SECURITY_EVENT_CHAL_RESP_FAILED, AST_SECURITY_EVENT_CHAL_RESP_FAILED_VERSION, ast_security_event_report(), mansession_session::challenge, ast_security_event_chal_resp_failed::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, mansession_session::sin, and mansession_session::username.

Referenced by authenticate().

02321 {
02322    struct sockaddr_in sin_local;
02323    char session_id[32];
02324    struct ast_security_event_chal_resp_failed chal_resp_failed = {
02325       .common.event_type = AST_SECURITY_EVENT_CHAL_RESP_FAILED,
02326       .common.version    = AST_SECURITY_EVENT_CHAL_RESP_FAILED_VERSION,
02327       .common.service    = "AMI",
02328       .common.account_id = s->session->username,
02329       .common.session_tv = &s->session->sessionstart_tv,
02330       .common.local_addr = {
02331          .sin       = mansession_encode_sin_local(s, &sin_local),
02332          .transport = mansession_get_transport(s),
02333       },
02334       .common.remote_addr = {
02335          .sin       = &s->session->sin,
02336          .transport = mansession_get_transport(s),
02337       },
02338       .common.session_id = session_id,
02339 
02340       .challenge         = s->session->challenge,
02341       .response          = response,
02342       .expected_response = expected_response,
02343    };
02344 
02345    snprintf(session_id, sizeof(session_id), "%p", s->session);
02346 
02347    ast_security_event_report(AST_SEC_EVT(&chal_resp_failed));
02348 }

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

Definition at line 2207 of file manager.c.

References AST_SEC_EVT, AST_SECURITY_EVENT_INVAL_PASSWORD, AST_SECURITY_EVENT_INVAL_PASSWORD_VERSION, ast_security_event_report(), ast_security_event_inval_password::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, and mansession_session::sin.

Referenced by authenticate().

02208 {
02209    struct sockaddr_in sin_local;
02210    char session_id[32];
02211    struct ast_security_event_inval_password inval_password = {
02212       .common.event_type = AST_SECURITY_EVENT_INVAL_PASSWORD,
02213       .common.version    = AST_SECURITY_EVENT_INVAL_PASSWORD_VERSION,
02214       .common.service    = "AMI",
02215       .common.account_id = username,
02216       .common.session_tv = &s->session->sessionstart_tv,
02217       .common.local_addr = {
02218          .sin       = mansession_encode_sin_local(s, &sin_local),
02219          .transport = mansession_get_transport(s),
02220       },
02221       .common.remote_addr = {
02222          .sin       = &s->session->sin,
02223          .transport = mansession_get_transport(s),
02224       },
02225       .common.session_id = session_id,
02226    };
02227 
02228    snprintf(session_id, sizeof(session_id), "%p", s->session);
02229 
02230    ast_security_event_report(AST_SEC_EVT(&inval_password));
02231 }

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

Definition at line 2155 of file manager.c.

References AST_SEC_EVT, AST_SECURITY_EVENT_INVAL_ACCT_ID, AST_SECURITY_EVENT_INVAL_ACCT_ID_VERSION, ast_security_event_report(), ast_security_event_inval_acct_id::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, and mansession_session::sin.

Referenced by authenticate().

02156 {
02157    struct sockaddr_in sin_local;
02158    char session_id[32];
02159    struct ast_security_event_inval_acct_id inval_acct_id = {
02160       .common.event_type = AST_SECURITY_EVENT_INVAL_ACCT_ID,
02161       .common.version    = AST_SECURITY_EVENT_INVAL_ACCT_ID_VERSION,
02162       .common.service    = "AMI",
02163       .common.account_id = username,
02164       .common.session_tv = &s->session->sessionstart_tv,
02165       .common.local_addr = {
02166          .sin       = mansession_encode_sin_local(s, &sin_local),
02167          .transport = mansession_get_transport(s),
02168       },
02169       .common.remote_addr = {
02170          .sin       = &s->session->sin,
02171          .transport = mansession_get_transport(s),
02172       },
02173       .common.session_id = session_id,
02174    };
02175 
02176    snprintf(session_id, sizeof(session_id), "%p", s);
02177 
02178    ast_security_event_report(AST_SEC_EVT(&inval_acct_id));
02179 }

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

Definition at line 2289 of file manager.c.

References AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_REQ_BAD_FORMAT, AST_SECURITY_EVENT_REQ_BAD_FORMAT_VERSION, ast_security_event_req_bad_format::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, mansession_session::sin, and mansession_session::username.

Referenced by process_message().

02290 {
02291    struct sockaddr_in sin_local;
02292    char session_id[32];
02293    char request_type[64];
02294    struct ast_security_event_req_bad_format req_bad_format = {
02295       .common.event_type = AST_SECURITY_EVENT_REQ_BAD_FORMAT,
02296       .common.version    = AST_SECURITY_EVENT_REQ_BAD_FORMAT_VERSION,
02297       .common.service    = "AMI",
02298       .common.account_id = s->session->username,
02299       .common.session_tv = &s->session->sessionstart_tv,
02300       .common.local_addr = {
02301          .sin       = mansession_encode_sin_local(s, &sin_local),
02302          .transport = mansession_get_transport(s),
02303       },
02304       .common.remote_addr = {
02305          .sin       = &s->session->sin,
02306          .transport = mansession_get_transport(s),
02307       },
02308       .common.session_id = session_id,
02309 
02310       .request_type      = request_type,
02311    };
02312 
02313    snprintf(session_id, sizeof(session_id), "%p", s->session);
02314    snprintf(request_type, sizeof(request_type), "Action: %s", action);
02315 
02316    ast_security_event_report(AST_SEC_EVT(&req_bad_format));
02317 }

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

Definition at line 2259 of file manager.c.

References AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_REQ_NOT_ALLOWED, AST_SECURITY_EVENT_REQ_NOT_ALLOWED_VERSION, ast_security_event_req_not_allowed::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, mansession_session::sin, and mansession_session::username.

Referenced by process_message().

02260 {
02261    struct sockaddr_in sin_local;
02262    char session_id[32];
02263    char request_type[64];
02264    struct ast_security_event_req_not_allowed req_not_allowed = {
02265       .common.event_type = AST_SECURITY_EVENT_REQ_NOT_ALLOWED,
02266       .common.version    = AST_SECURITY_EVENT_REQ_NOT_ALLOWED_VERSION,
02267       .common.service    = "AMI",
02268       .common.account_id = s->session->username,
02269       .common.session_tv = &s->session->sessionstart_tv,
02270       .common.local_addr = {
02271          .sin       = mansession_encode_sin_local(s, &sin_local),
02272          .transport = mansession_get_transport(s),
02273       },
02274       .common.remote_addr = {
02275          .sin       = &s->session->sin,
02276          .transport = mansession_get_transport(s),
02277       },
02278       .common.session_id = session_id,
02279 
02280       .request_type      = request_type,
02281    };
02282 
02283    snprintf(session_id, sizeof(session_id), "%p", s->session);
02284    snprintf(request_type, sizeof(request_type), "Action: %s", action);
02285 
02286    ast_security_event_report(AST_SEC_EVT(&req_not_allowed));
02287 }

static void report_session_limit ( const struct mansession *  s  )  [static]

Definition at line 2350 of file manager.c.

References AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_SESSION_LIMIT, AST_SECURITY_EVENT_SESSION_LIMIT_VERSION, ast_security_event_session_limit::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, mansession_session::sin, and mansession_session::username.

Referenced by process_message().

02351 {
02352    struct sockaddr_in sin_local;
02353    char session_id[32];
02354    struct ast_security_event_session_limit session_limit = {
02355       .common.event_type = AST_SECURITY_EVENT_SESSION_LIMIT,
02356       .common.version    = AST_SECURITY_EVENT_SESSION_LIMIT_VERSION,
02357       .common.service    = "AMI",
02358       .common.account_id = s->session->username,
02359       .common.session_tv = &s->session->sessionstart_tv,
02360       .common.local_addr = {
02361          .sin       = mansession_encode_sin_local(s, &sin_local),
02362          .transport = mansession_get_transport(s),
02363       },
02364       .common.remote_addr = {
02365          .sin       = &s->session->sin,
02366          .transport = mansession_get_transport(s),
02367       },
02368       .common.session_id = session_id,
02369    };
02370 
02371    snprintf(session_id, sizeof(session_id), "%p", s->session);
02372 
02373    ast_security_event_report(AST_SEC_EVT(&session_limit));
02374 }

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

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

Definition at line 1990 of file manager.c.

References ast_careful_fwrite(), EVENT_FLAG_HOOKRESPONSE, mansession_session::f, mansession::f, f, mansession_session::fd, mansession::fd, manager_custom_hook::helper, mansession::hook, mansession::session, mansession::write_error, and mansession_session::writetimeout.

Referenced by astman_append(), and process_events().

01991 {
01992    int res;
01993    FILE *f = s->f ? s->f : s->session->f;
01994    int fd = s->f ? s->fd : s->session->fd;
01995 
01996    /* It's a result from one of the hook's action invocation */
01997    if (s->hook) {
01998       /*
01999        * to send responses, we're using the same function
02000        * as for receiving events. We call the event "HookResponse"
02001        */
02002       s->hook->helper(EVENT_FLAG_HOOKRESPONSE, "HookResponse", string);
02003       return 0;
02004    }
02005        
02006    if ((res = ast_careful_fwrite(f, fd, string, strlen(string), s->session->writetimeout))) {
02007       s->write_error = 1;
02008    }
02009 
02010    return res;
02011 }

static void session_destroy ( struct mansession_session *  s  )  [static]

Definition at line 1387 of file manager.c.

References ao2_unlink, sessions, and unref_mansession().

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

01388 {
01389    unref_mansession(s);
01390    ao2_unlink(sessions, s);
01391 }

static void session_destructor ( void *  obj  )  [static]

Definition at line 1320 of file manager.c.

References ao2_t_callback, ao2_t_ref, ast_atomic_fetchadd_int(), ast_datastore_free(), AST_LIST_REMOVE_HEAD, mansession_session::blackfilters, mansession_session::datastores, mansession_session::f, mansession_session::last_ev, OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, eventqent::usecount, and mansession_session::whitefilters.

Referenced by build_mansession().

01321 {
01322    struct mansession_session *session = obj;
01323    struct eventqent *eqe = session->last_ev;
01324    struct ast_datastore *datastore;
01325 
01326    /* Get rid of each of the data stores on the session */
01327    while ((datastore = AST_LIST_REMOVE_HEAD(&session->datastores, entry))) {
01328       /* Free the data store */
01329       ast_datastore_free(datastore);
01330    }
01331 
01332    if (session->f != NULL) {
01333       fclose(session->f);
01334    }
01335    if (eqe) {
01336       ast_atomic_fetchadd_int(&eqe->usecount, -1);
01337    }
01338 
01339    if (session->whitefilters) {
01340       ao2_t_callback(session->whitefilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all white filters");
01341       ao2_t_ref(session->whitefilters, -1 , "decrement ref for white container, should be last one");
01342    }
01343 
01344    if (session->blackfilters) {
01345       ao2_t_callback(session->blackfilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all black filters");
01346       ao2_t_ref(session->blackfilters, -1 , "decrement ref for black container, should be last one");
01347    }
01348 }

static void* session_do ( void *  data  )  [static]

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

Definition at line 4975 of file manager.c.

References AMI_VERSION, ao2_lock, ao2_ref, ao2_unlock, ast_atomic_fetchadd_int(), ast_inet_ntoa(), AST_LIST_HEAD_INIT_NOLOCK, ast_log(), ast_mutex_destroy, ast_mutex_init, ast_sockaddr_to_sin, ast_verb, astman_append(), mansession_session::authenticated, mansession_session::authstart, block_sockets, build_mansession(), mansession_session::datastores, do_message(), errno, mansession::f, mansession_session::f, ast_tcptls_session_instance::f, mansession::fd, mansession_session::fd, ast_tcptls_session_instance::fd, ast_frame::flags, grab_last(), mansession_session::last_ev, mansession::lock, LOG_ERROR, LOG_WARNING, manager_displayconnects(), ast_tcptls_session_instance::remote_address, mansession::session, session_destroy(), mansession_session::sin, unauth_sessions, mansession_session::username, and mansession::write_error.

04976 {
04977    struct ast_tcptls_session_instance *ser = data;
04978    struct mansession_session *session;
04979    struct mansession s = {
04980       .tcptls_session = data,
04981    };
04982    int flags;
04983    int res;
04984    struct sockaddr_in ser_remote_address_tmp;
04985    struct protoent *p;
04986 
04987    if (ast_atomic_fetchadd_int(&unauth_sessions, +1) >= authlimit) {
04988       fclose(ser->f);
04989       ast_atomic_fetchadd_int(&unauth_sessions, -1);
04990       goto done;
04991    }
04992 
04993    ast_sockaddr_to_sin(&ser->remote_address, &ser_remote_address_tmp);
04994    session = build_mansession(ser_remote_address_tmp);
04995 
04996    if (session == NULL) {
04997       fclose(ser->f);
04998       ast_atomic_fetchadd_int(&unauth_sessions, -1);
04999       goto done;
05000    }
05001 
05002    /* here we set TCP_NODELAY on the socket to disable Nagle's algorithm.
05003     * This is necessary to prevent delays (caused by buffering) as we
05004     * write to the socket in bits and peices. */
05005    p = getprotobyname("tcp");
05006    if (p) {
05007       int arg = 1;
05008       if( setsockopt(ser->fd, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) {
05009          ast_log(LOG_WARNING, "Failed to set manager tcp connection to TCP_NODELAY mode: %s\nSome manager actions may be slow to respond.\n", strerror(errno));
05010       }
05011    } else {
05012       ast_log(LOG_WARNING, "Failed to set manager tcp connection to TCP_NODELAY, getprotobyname(\"tcp\") failed\nSome manager actions may be slow to respond.\n");
05013    }
05014 
05015    flags = fcntl(ser->fd, F_GETFL);
05016    if (!block_sockets) { /* make sure socket is non-blocking */
05017       flags |= O_NONBLOCK;
05018    } else {
05019       flags &= ~O_NONBLOCK;
05020    }
05021    fcntl(ser->fd, F_SETFL, flags);
05022 
05023    ao2_lock(session);
05024    /* Hook to the tail of the event queue */
05025    session->last_ev = grab_last();
05026 
05027    ast_mutex_init(&s.lock);
05028 
05029    /* these fields duplicate those in the 'ser' structure */
05030    session->fd = s.fd = ser->fd;
05031    session->f = s.f = ser->f;
05032    session->sin = ser_remote_address_tmp;
05033    s.session = session;
05034 
05035    AST_LIST_HEAD_INIT_NOLOCK(&session->datastores);
05036 
05037    if(time(&session->authstart) == -1) {
05038       ast_log(LOG_ERROR, "error executing time(): %s; disconnecting client\n", strerror(errno));
05039       ast_atomic_fetchadd_int(&unauth_sessions, -1);
05040       ao2_unlock(session);
05041       session_destroy(session);
05042       goto done;
05043    }
05044    ao2_unlock(session);
05045 
05046    astman_append(&s, "Asterisk Call Manager/%s\r\n", AMI_VERSION);   /* welcome prompt */
05047    for (;;) {
05048       if ((res = do_message(&s)) < 0 || s.write_error) {
05049          break;
05050       }
05051    }
05052    /* session is over, explain why and terminate */
05053    if (session->authenticated) {
05054       if (manager_displayconnects(session)) {
05055          ast_verb(2, "Manager '%s' logged off from %s\n", session->username, ast_inet_ntoa(session->sin.sin_addr));
05056       }
05057    } else {
05058       ast_atomic_fetchadd_int(&unauth_sessions, -1);
05059       if (displayconnects) {
05060          ast_verb(2, "Connect attempt from '%s' unable to authenticate\n", ast_inet_ntoa(session->sin.sin_addr));
05061       }
05062    }
05063 
05064    session_destroy(session);
05065 
05066    ast_mutex_destroy(&s.lock);
05067 done:
05068    ao2_ref(ser, -1);
05069    ser = NULL;
05070    return NULL;
05071 }

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

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

Definition at line 2127 of file manager.c.

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

Referenced by action_events(), and authenticate().

02128 {
02129    int maskint = strings_to_mask(eventmask);
02130 
02131    ao2_lock(s->session);
02132    if (maskint >= 0) {
02133       s->session->send_events = maskint;
02134    }
02135    ao2_unlock(s->session);
02136 
02137    return maskint;
02138 }

static int strings_to_mask ( const char *  string  )  [static]

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

Definition at line 1274 of file manager.c.

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

Referenced by set_eventmask().

01275 {
01276    const char *p;
01277 
01278    if (ast_strlen_zero(string)) {
01279       return -1;
01280    }
01281 
01282    for (p = string; *p; p++) {
01283       if (*p < '0' || *p > '9') {
01284          break;
01285       }
01286    }
01287    if (!*p) { /* all digits */
01288       return atoi(string);
01289    }
01290    if (ast_false(string)) {
01291       return 0;
01292    }
01293    if (ast_true(string)) { /* all permissions */
01294       int x, ret = 0;
01295       for (x = 0; x < ARRAY_LEN(perms); x++) {
01296          ret |= perms[x].num;
01297       }
01298       return ret;
01299    }
01300    return get_perm(string);
01301 }

static struct mansession_session* unref_mansession ( struct mansession_session *  s  )  [static, read]

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

Definition at line 1305 of file manager.c.

References ao2_ref, ast_log(), and LOG_DEBUG.

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

01306 {
01307    int refcount = ao2_ref(s, -1);
01308         if (manager_debug) {
01309       ast_log(LOG_DEBUG, "Mansession: %p refcount now %d\n", s, refcount - 1);
01310    }
01311    return s;
01312 }

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

Definition at line 4267 of file manager.c.

References CMP_MATCH, and CMP_STOP.

Referenced by match_filter().

04268 {
04269    regex_t *regex_filter = obj;
04270    const char *eventdata = arg;
04271    int *result = data;
04272 
04273    if (!regexec(regex_filter, eventdata, 0, NULL, 0)) {
04274       *result = 1;
04275       return (CMP_MATCH | CMP_STOP);
04276    }
04277 
04278    return 0;
04279 }


Variable Documentation

int allowmultiplelogin = 1 [static]

Definition at line 899 of file manager.c.

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

Definition at line 2020 of file manager.c.

Referenced by astman_append().

int authlimit [static]

Definition at line 907 of file manager.c.

int authtimeout [static]

Definition at line 906 of file manager.c.

int block_sockets [static]

Definition at line 913 of file manager.c.

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

int broken_events_action [static]

Definition at line 902 of file manager.c.

struct { ... } command_blacklist[] [static]

Referenced by check_blacklist().

const int DEFAULT_AUTHLIMIT = 50 [static]

Default setting for authlimit

Definition at line 895 of file manager.c.

Referenced by reload_config().

const int DEFAULT_AUTHTIMEOUT = 30 [static]

Default setting for authtimeout

Definition at line 894 of file manager.c.

Referenced by reload_config().

const int DEFAULT_BLOCKSOCKETS = 0 [static]

Default setting for block-sockets

Definition at line 889 of file manager.c.

const int DEFAULT_BROKENEVENTSACTION = 0 [static]

Default setting for brokeneventsaction

Definition at line 893 of file manager.c.

const int DEFAULT_DISPLAYCONNECTS = 1 [static]

Default setting for displaying manager connections

Definition at line 890 of file manager.c.

const int DEFAULT_ENABLED = 0 [static]

Default setting for manager to be enabled

Definition at line 887 of file manager.c.

const int DEFAULT_HTTPTIMEOUT = 60 [static]

Default manager http timeout

Definition at line 892 of file manager.c.

const int DEFAULT_MANAGERDEBUG = 0 [static]

Default setting for manager debug

Definition at line 896 of file manager.c.

const int DEFAULT_TIMESTAMPEVENTS = 0 [static]

Default setting for timestampevents

Definition at line 891 of file manager.c.

const int DEFAULT_WEBENABLED = 0 [static]

Default setting for the web interface to be enabled

Definition at line 888 of file manager.c.

int displayconnects [static]

Definition at line 898 of file manager.c.

char global_realm[MAXHOSTNAMELEN] [static]

Default realm

Definition at line 911 of file manager.c.

Referenced by __init_manager(), and auth_http_callback().

int httptimeout [static]

Definition at line 901 of file manager.c.

char* manager_channelvars [static]

Definition at line 908 of file manager.c.

int manager_debug = 0 [static]

enable some debugging code in the manager

Definition at line 905 of file manager.c.

int manager_enabled = 0 [static]

Definition at line 903 of file manager.c.

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

Definition at line 5158 of file manager.c.

Referenced by __ast_manager_event_multichan().

struct ast_threadstorage manager_event_funcbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_manager_event_funcbuf , .custom_init = NULL , } [static]

Definition at line 5131 of file manager.c.

Referenced by append_channel_vars().

struct permalias perms[] [static]

helper functions to convert back and forth between string and numeric representation of set of flags

Referenced by action_events(), authority_to_str(), get_perm(), and strings_to_mask().

struct ao2_container* sessions = NULL [static]
int timestampevents [static]

Definition at line 900 of file manager.c.

int unauth_sessions = 0 [static]

Definition at line 914 of file manager.c.

Referenced by action_login(), and session_do().

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

Definition at line 2021 of file manager.c.

Referenced by action_userevent().

int webmanager_enabled = 0 [static]

Definition at line 904 of file manager.c.

const char* words[AST_MAX_CMD_LEN] [inherited]

Definition at line 929 of file manager.c.


Generated on 18 Jan 2013 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1