Sat Aug 6 00:40:06 2011

Asterisk developer's documentation


AMI functions

callback to display queues status in manager More...

Data Structures

struct  ast_manager_user
struct  eventqent
struct  fast_originate_helper
struct  mansession
struct  mansession_session
struct  permalias
struct  sessions
struct  users
struct  variable_count

Defines

#define ASTMAN_APPEND_BUF_INITSIZE   256
#define MANAGER_EVENT_BUF_INITSIZE   256
#define MAX_BLACKLIST_CMD_LEN   2

Functions

static void * accept_thread (void *ignore)
static int action_command (struct mansession *s, const struct message *m)
 action_command: 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_corestatus (struct mansession *s, const struct message *m)
 Show PBX core status information.
static int action_events (struct mansession *s, const struct message *m)
static int action_extensionstate (struct mansession *s, const struct message *m)
static int action_getconfig (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_listcommands (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_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 int append_event (const char *str, int category)
static struct ast_manager_userast_get_manager_by_name_locked (const char *name)
static int ast_instring (const char *bigstr, const char *smallstr, char delim)
static int ast_is_number (const char *string)
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
static int ast_manager_register_struct (struct manager_action *act)
int ast_manager_unregister (char *action)
void astman_append (struct mansession *s, const char *fmt,...)
static void astman_append_buf_init (void)
const char * astman_get_header (const struct message *m, char *var)
ast_variableastman_get_variables (const struct message *m)
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)
void astman_send_response (struct mansession *s, const struct message *m, char *resp, char *msg)
static int authenticate (struct mansession *s, const struct message *m)
static char * authority_to_str (int authority, char *res, int reslen)
 Convert authority code to string with serveral options.
static int check_blacklist (const char *cmd)
int check_manager_enabled ()
 Check if AMI is enabled.
int check_webmanager_enabled ()
 Check if AMI/HTTP is enabled.
static char * complete_show_mancmd (const char *line, const char *word, int pos, int state)
static int compress_char (char c)
static void destroy_session (struct mansession_session *s)
static int do_message (struct mansession *s)
static void * fast_originate (void *data)
static void free_session (struct mansession_session *s)
static int get_input (struct mansession_session *s, char *output)
static int get_perm (const char *instr)
static int handle_showmanager (int fd, int argc, char *argv[])
static int handle_showmanagers (int fd, int argc, char *argv[])
static int handle_showmancmd (int fd, int argc, char *argv[])
static int handle_showmancmds (int fd, int argc, char *argv[])
 CLI command Should change to "manager show commands".
static int handle_showmanconn (int fd, int argc, char *argv[])
 CLI command show manager connected.
static int handle_showmaneventq (int fd, int argc, char *argv[])
 CLI command show manager eventq.
static void handle_updates (struct mansession *s, const struct message *m, struct ast_config *cfg)
static char * html_translate (char *in)
int manager_event (int category, const char *event, const char *fmt,...)
 manager_event: Send AMI event to client
static void manager_event_buf_init (void)
static int manager_state_cb (char *context, char *exten, int state, void *data)
static int process_events (struct mansession *s)
static int process_message (struct mansession *s, const struct message *m)
static void * session_do (void *data)
static int set_eventmask (struct mansession_session *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 void unuse_eventqent (struct eventqent *e)
static int variable_count_cmp_fn (void *obj, void *vstr, int flags)
static int variable_count_hash_fn (const void *vvc, const int flags)
static void xml_copy_escape (char **dst, size_t *maxlen, const char *src, int lower)
static char * xml_translate (char *in, struct ast_variable *vars)

Variables

static ast_rwlock_t actionlock = PTHREAD_RWLOCK_INITIALIZER
static int asock = -1
static struct ast_threadstorage astman_append_buf = { .once = PTHREAD_ONCE_INIT , .key_init = astman_append_buf_init , }
static int authlimit
static int authtimeout
static int block_sockets
static int broken_events_action
static struct ast_cli_entry cli_manager []
static struct ast_cli_entry cli_show_manager_command_deprecated
static struct ast_cli_entry cli_show_manager_commands_deprecated
static struct ast_cli_entry cli_show_manager_connected_deprecated
static struct ast_cli_entry cli_show_manager_eventq_deprecated
struct {
   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_TIMESTAMPEVENTS = 0
static const int DEFAULT_WEBENABLED = 0
static int displayconnects
static struct manager_actionfirst_action
static int httptimeout
static int manager_enabled = 0
static struct ast_threadstorage manager_event_buf = { .once = PTHREAD_ONCE_INIT , .key_init = manager_event_buf_init , }
static char mandescr_command []
static char mandescr_coresettings []
static char mandescr_corestatus []
static char mandescr_events []
static char mandescr_extensionstate []
static char mandescr_getconfig []
static char mandescr_getvar []
static char mandescr_hangup []
static char mandescr_listcommands []
static char mandescr_logoff []
static char mandescr_mailboxcount []
static char mandescr_mailboxstatus []
 Help text for manager command mailboxstatus.
static char mandescr_originate []
static char mandescr_ping []
 Manager PING.
static char mandescr_redirect []
static char mandescr_setvar []
static char mandescr_timeout []
static char mandescr_updateconfig []
static char mandescr_userevent []
static char mandescr_waitevent []
 Manager WAITEVENT.
eventqentmaster_eventq = NULL
static int num_sessions
static struct permalias perms []
static int portno = DEFAULT_MANAGER_PORT
static char showmanager_help []
static char showmanagers_help []
static char showmancmd_help []
static char showmancmds_help []
static char showmanconn_help []
static char showmaneventq_help []
static pthread_t t
static int timestampevents
static int unauth_sessions = 0
static int webmanager_enabled = 0

Detailed Description

callback to display queues status in manager


Define Documentation

#define ASTMAN_APPEND_BUF_INITSIZE   256

Definition at line 136 of file manager.c.

Referenced by astman_append().

#define MANAGER_EVENT_BUF_INITSIZE   256

Definition at line 133 of file manager.c.

Referenced by manager_event().

#define MAX_BLACKLIST_CMD_LEN   2

Definition at line 154 of file manager.c.

Referenced by check_blacklist().


Function Documentation

static void* accept_thread ( void *  ignore  )  [static]

Definition at line 2618 of file manager.c.

References asock, ast_atomic_fetchadd_int(), ast_calloc, ast_inet_ntoa(), AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log(), ast_mutex_init(), ast_poll, ast_pthread_create_background, AST_PTHREADT_NULL, ast_verbose(), authlimit, block_sockets, destroy_session(), displayconnects, errno, ast_channel::flags, free, free_session(), LOG_ERROR, LOG_WARNING, master_eventq, eventqent::next, num_sessions, option_verbose, s, session_do(), t, unauth_sessions, eventqent::usecount, and VERBOSE_PREFIX_2.

Referenced by reload_config().

02619 {
02620    int as;
02621    struct sockaddr_in sin;
02622    socklen_t sinlen;
02623    struct eventqent *eqe;
02624    struct mansession_session *s;
02625    struct protoent *p;
02626    int arg = 1;
02627    int flags;
02628    pthread_t t;
02629    pthread_attr_t attr;
02630    time_t now;
02631    struct pollfd pfds[1];
02632 
02633    pthread_attr_init(&attr);
02634    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
02635 
02636    for (;;) {
02637       time(&now);
02638       AST_LIST_LOCK(&sessions);
02639       AST_LIST_TRAVERSE_SAFE_BEGIN(&sessions, s, list) {
02640          if (s->sessiontimeout && (now > s->sessiontimeout) && !s->inuse) {
02641             AST_LIST_REMOVE_CURRENT(&sessions, list);
02642             num_sessions--;
02643             if (s->authenticated && (option_verbose > 1) && displayconnects) {
02644                ast_verbose(VERBOSE_PREFIX_2 "HTTP Manager '%s' timed out from %s\n",
02645                   s->username, ast_inet_ntoa(s->sin.sin_addr));
02646             }
02647             free_session(s);
02648             break;   
02649          }
02650       }
02651       AST_LIST_TRAVERSE_SAFE_END
02652       /* Purge master event queue of old, unused events, but make sure we
02653          always keep at least one in the queue */
02654       eqe = master_eventq;
02655       while (master_eventq->next && !master_eventq->usecount) {
02656          eqe = master_eventq;
02657          master_eventq = master_eventq->next;
02658          free(eqe);
02659       }
02660       AST_LIST_UNLOCK(&sessions);
02661 
02662       sinlen = sizeof(sin);
02663       pfds[0].fd = asock;
02664       pfds[0].events = POLLIN;
02665       /* Wait for something to happen, but timeout every few seconds so
02666          we can ditch any old manager sessions */
02667       if (ast_poll(pfds, 1, 5000) < 1)
02668          continue;
02669       as = accept(asock, (struct sockaddr *)&sin, &sinlen);
02670       if (as < 0) {
02671          ast_log(LOG_NOTICE, "Accept returned -1: %s\n", strerror(errno));
02672          continue;
02673       }
02674 
02675       if (ast_atomic_fetchadd_int(&unauth_sessions, +1) >= authlimit) {
02676          close(as);
02677          ast_atomic_fetchadd_int(&unauth_sessions, -1);
02678          ast_log(LOG_WARNING, "manager connection rejected, too many unauthenticated sessions.\n");
02679          continue;
02680       }
02681 
02682       p = getprotobyname("tcp");
02683       if (p) {
02684          if( setsockopt(as, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) {
02685             ast_log(LOG_WARNING, "Failed to set manager tcp connection to TCP_NODELAY mode: %s\n", strerror(errno));
02686          }
02687       }
02688       if (!(s = ast_calloc(1, sizeof(*s)))) {
02689          close(as);
02690          ast_atomic_fetchadd_int(&unauth_sessions, -1);
02691          continue;
02692       }
02693 
02694       memcpy(&s->sin, &sin, sizeof(sin));
02695       s->writetimeout = 100;
02696       s->waiting_thread = AST_PTHREADT_NULL;
02697 
02698       if (!block_sockets) {
02699          /* For safety, make sure socket is non-blocking */
02700          flags = fcntl(as, F_GETFL);
02701          fcntl(as, F_SETFL, flags | O_NONBLOCK);
02702       } else {
02703          flags = fcntl(as, F_GETFL);
02704          fcntl(as, F_SETFL, flags & ~O_NONBLOCK);
02705       }
02706       ast_mutex_init(&s->__lock);
02707       s->fd = as;
02708       s->send_events = -1;
02709       AST_LIST_LOCK(&sessions);
02710       AST_LIST_INSERT_HEAD(&sessions, s, list);
02711       num_sessions++;
02712       /* Find the last place in the master event queue and hook ourselves
02713          in there */
02714       s->eventq = master_eventq;
02715       while(s->eventq->next)
02716          s->eventq = s->eventq->next;
02717       ast_atomic_fetchadd_int(&s->eventq->usecount, 1);
02718       AST_LIST_UNLOCK(&sessions);
02719       if(time(&s->authstart) == -1) {
02720          ast_log(LOG_ERROR, "error executing time(): %s; disconnecting client\n", strerror(errno));
02721          ast_atomic_fetchadd_int(&unauth_sessions, -1);
02722          destroy_session(s);
02723          continue;
02724       }
02725       if (ast_pthread_create_background(&t, &attr, session_do, s)) {
02726          ast_atomic_fetchadd_int(&unauth_sessions, -1);
02727          destroy_session(s);
02728       }
02729    }
02730    pthread_attr_destroy(&attr);
02731    return NULL;
02732 }

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

action_command: Manager command "command" - execute CLI command

Definition at line 1855 of file manager.c.

References ast_calloc, ast_cli_command(), ast_free, ast_log(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), check_blacklist(), errno, LOG_WARNING, s, S_OR, and term_strip().

Referenced by init_manager().

01856 {
01857    const char *cmd = astman_get_header(m, "Command");
01858    const char *id = astman_get_header(m, "ActionID");
01859    char *buf, *final_buf;
01860    char template[] = "/tmp/ast-ami-XXXXXX";  /* template for temporary file */
01861    int fd;
01862    off_t l;
01863 
01864    if (ast_strlen_zero(cmd)) {
01865       astman_send_error(s, m, "No command provided");
01866       return 0;
01867    }
01868 
01869    if (check_blacklist(cmd)) {
01870       astman_send_error(s, m, "Command blacklisted");
01871       return 0;
01872    }
01873 
01874    fd = mkstemp(template);
01875 
01876    astman_append(s, "Response: Follows\r\nPrivilege: Command\r\n");
01877    if (!ast_strlen_zero(id))
01878       astman_append(s, "ActionID: %s\r\n", id);
01879    /* FIXME: Wedge a ActionID response in here, waiting for later changes */
01880    ast_cli_command(fd, cmd);  /* XXX need to change this to use a FILE * */
01881    l = lseek(fd, 0, SEEK_END);   /* how many chars available */
01882 
01883    /* This has a potential to overflow the stack.  Hence, use the heap. */
01884    buf = ast_calloc(1, l + 1);
01885    final_buf = ast_calloc(1, l + 1);
01886    if (buf) {
01887       lseek(fd, 0, SEEK_SET);
01888       if (read(fd, buf, l) < 0) {
01889          ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno));
01890       }
01891       buf[l] = '\0';
01892       if (final_buf) {
01893          term_strip(final_buf, buf, l);
01894          final_buf[l] = '\0';
01895       }
01896       astman_append(s, "%s", S_OR(final_buf, buf));
01897       ast_free(buf);
01898    }
01899    close(fd);
01900    unlink(template);
01901    astman_append(s, "--END COMMAND--\r\n\r\n");
01902    if (final_buf)
01903       ast_free(final_buf);
01904    return 0;
01905 }

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

Show PBX core settings information.

Definition at line 2296 of file manager.c.

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

Referenced by init_manager().

02297 {
02298    const char *actionid = astman_get_header(m, "ActionID");
02299    char idText[150] = "";
02300 
02301    if (!ast_strlen_zero(actionid))
02302       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
02303 
02304    astman_append(s, "Response: Success\r\n"
02305          "%s"
02306          "AMIversion: %s\r\n"
02307          "AsteriskVersion: %s\r\n"
02308          "SystemName: %s\r\n"
02309          "CoreMaxCalls: %d\r\n"
02310          "CoreMaxLoadAvg: %f\r\n"
02311          "CoreRunUser: %s\r\n"
02312          "CoreRunGroup: %s\r\n"
02313          "CoreMaxFilehandles: %d\r\n" 
02314          "CoreRealTimeEnabled: %s\r\n"
02315          "CoreCDRenabled: %s\r\n"
02316          "CoreHTTPenabled: %s\r\n"
02317          "\r\n",
02318          idText,
02319          AMI_VERSION,
02320          ASTERISK_VERSION, 
02321          ast_config_AST_SYSTEM_NAME,
02322          option_maxcalls,
02323          option_maxload,
02324          ast_config_AST_RUN_USER,
02325          ast_config_AST_RUN_GROUP,
02326          option_maxfiles,
02327          ast_realtime_enabled() ? "Yes" : "No",
02328          check_cdr_enabled() ? "Yes" : "No",
02329          check_webmanager_enabled() ? "Yes" : "No"
02330          );
02331    return 0;
02332 }

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

Show PBX core status information.

Definition at line 2340 of file manager.c.

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

Referenced by init_manager().

02341 {
02342    const char *actionid = astman_get_header(m, "ActionID");
02343    char idText[150];
02344    char startuptime[150];
02345    char reloadtime[150];
02346    struct tm tm;
02347 
02348    if (!ast_strlen_zero(actionid))
02349       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
02350 
02351    ast_localtime(&ast_startuptime, &tm, NULL);
02352    strftime(startuptime, sizeof(startuptime), "%H:%M:%S", &tm);
02353    ast_localtime(&ast_lastreloadtime, &tm, NULL);
02354    strftime(reloadtime, sizeof(reloadtime), "%H:%M:%S", &tm);
02355 
02356    astman_append(s, "Response: Success\r\n"
02357          "%s"
02358          "CoreStartupTime: %s\r\n"
02359          "CoreReloadTime: %s\r\n"
02360          "CoreCurrentCalls: %d\r\n"
02361          "\r\n",
02362          idText,
02363          startuptime,
02364          reloadtime,
02365          ast_active_channels()
02366          );
02367    return 0;
02368 }

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

Definition at line 1464 of file manager.c.

References ARRAY_LEN, astman_get_header(), astman_send_error(), astman_send_response(), broken_events_action, perms, s, and set_eventmask().

Referenced by init_manager().

01465 {
01466    const char *mask = astman_get_header(m, "EventMask");
01467    int res, x;
01468 
01469    res = set_eventmask(s->session, mask);
01470    if (broken_events_action) {
01471       /* if this option is set we should not return a response on
01472        * error, or when all events are set */
01473 
01474       if (res > 0) {
01475          for (x = 0; x < ARRAY_LEN(perms); x++) {
01476             if (!strcasecmp(perms[x].label, "all") && res == perms[x].num) {
01477                return 0;
01478             }
01479          }
01480          astman_send_response(s, m, "Events On", NULL);
01481       } else if (res == 0)
01482          astman_send_response(s, m, "Events Off", NULL);
01483       return 0;
01484    }
01485 
01486    if (res > 0)
01487       astman_send_response(s, m, "Events On", NULL);
01488    else if (res == 0)
01489       astman_send_response(s, m, "Events Off", NULL);
01490    else
01491       astman_send_error(s, m, "Invalid event mask");
01492 
01493    return 0;
01494 }

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

Definition at line 2173 of file manager.c.

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

Referenced by init_manager().

02174 {
02175    const char *exten = astman_get_header(m, "Exten");
02176    const char *context = astman_get_header(m, "Context");
02177    const char *id = astman_get_header(m,"ActionID");
02178    char idText[256] = "";
02179    char hint[256] = "";
02180    int status;
02181    if (ast_strlen_zero(exten)) {
02182       astman_send_error(s, m, "Extension not specified");
02183       return 0;
02184    }
02185    if (ast_strlen_zero(context))
02186       context = "default";
02187    status = ast_extension_state(NULL, context, exten);
02188    ast_get_hint(hint, sizeof(hint) - 1, NULL, 0, NULL, context, exten);
02189         if (!ast_strlen_zero(id)) {
02190                 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
02191         }
02192    astman_append(s, "Response: Success\r\n"
02193                     "%s"
02194                "Message: Extension Status\r\n"
02195                "Exten: %s\r\n"
02196                "Context: %s\r\n"
02197                "Hint: %s\r\n"
02198                "Status: %d\r\n\r\n",
02199                idText,exten, context, hint, status);
02200    return 0;
02201 }

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

Definition at line 1193 of file manager.c.

References ast_category_browse(), ast_config_destroy(), ast_config_load_with_comments(), ast_strlen_zero(), ast_variable_browse(), astman_append(), astman_get_header(), astman_send_error(), ast_variable::name, ast_variable::next, s, and ast_variable::value.

Referenced by init_manager().

01194 {
01195    struct ast_config *cfg;
01196    const char *fn = astman_get_header(m, "Filename");
01197    int catcount = 0;
01198    int lineno = 0;
01199    char *category=NULL;
01200    struct ast_variable *v;
01201    char idText[256] = "";
01202    const char *id = astman_get_header(m, "ActionID");
01203 
01204    if (!ast_strlen_zero(id))
01205       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
01206 
01207    if (ast_strlen_zero(fn)) {
01208       astman_send_error(s, m, "Filename not specified");
01209       return 0;
01210    }
01211    if (!(cfg = ast_config_load_with_comments(fn))) {
01212       astman_send_error(s, m, "Config file not found");
01213       return 0;
01214    }
01215    astman_append(s, "Response: Success\r\n%s", idText);
01216    while ((category = ast_category_browse(cfg, category))) {
01217       lineno = 0;
01218       astman_append(s, "Category-%06d: %s\r\n", catcount, category);
01219       for (v = ast_variable_browse(cfg, category); v; v = v->next)
01220          astman_append(s, "Line-%06d-%06d: %s=%s\r\n", catcount, lineno++, v->name, v->value);
01221       catcount++;
01222    }
01223    ast_config_destroy(cfg);
01224    astman_append(s, "\r\n");
01225 
01226    return 0;
01227 }

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

Definition at line 1584 of file manager.c.

References ast_channel_alloc(), ast_channel_free(), ast_channel_unlock, ast_func_read(), ast_get_channel_by_name_locked(), ast_log(), ast_strdupa, ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), copy(), LOG_ERROR, name, pbx_retrieve_variable(), s, and S_OR.

Referenced by init_manager().

01585 {
01586    struct ast_channel *c = NULL;
01587    const char *name = astman_get_header(m, "Channel");
01588    const char *varname = astman_get_header(m, "Variable");
01589    const char *id = astman_get_header(m,"ActionID");
01590    char *varval;
01591    char workspace[1024] = "";
01592 
01593    if (ast_strlen_zero(varname)) {
01594       astman_send_error(s, m, "No variable specified");
01595       return 0;
01596    }
01597 
01598    if (!ast_strlen_zero(name)) {
01599       c = ast_get_channel_by_name_locked(name);
01600       if (!c) {
01601          astman_send_error(s, m, "No such channel");
01602          return 0;
01603       }
01604    }
01605 
01606    if (varname[strlen(varname) - 1] == ')') {
01607       char *copy = ast_strdupa(varname);
01608       if (!c) {
01609          c = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Bogus/manager");
01610          if (c) {
01611             ast_func_read(c, copy, workspace, sizeof(workspace));
01612             ast_channel_free(c);
01613             c = NULL;
01614          } else
01615             ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution.  Function results may be blank.\n");
01616       } else
01617          ast_func_read(c, copy, workspace, sizeof(workspace));
01618       varval = workspace;
01619    } else {
01620       pbx_retrieve_variable(c, varname, &varval, workspace, sizeof(workspace), NULL);
01621    }
01622 
01623    if (c)
01624       ast_channel_unlock(c);
01625    astman_append(s, "Response: Success\r\n"
01626       "Variable: %s\r\nValue: %s\r\n", varname, S_OR(varval, ""));
01627    if (!ast_strlen_zero(id))
01628       astman_append(s, "ActionID: %s\r\n",id);
01629    astman_append(s, "\r\n");
01630 
01631    return 0;
01632 }

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

Definition at line 1511 of file manager.c.

References ast_channel_unlock, ast_get_channel_by_name_locked(), ast_softhangup(), AST_SOFTHANGUP_EXPLICIT, ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), name, and s.

Referenced by init_manager().

01512 {
01513    struct ast_channel *c = NULL;
01514    const char *name = astman_get_header(m, "Channel");
01515    if (ast_strlen_zero(name)) {
01516       astman_send_error(s, m, "No channel specified");
01517       return 0;
01518    }
01519    c = ast_get_channel_by_name_locked(name);
01520    if (!c) {
01521       astman_send_error(s, m, "No such channel");
01522       return 0;
01523    }
01524    ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
01525    ast_channel_unlock(c);
01526    astman_send_ack(s, m, "Channel Hungup");
01527    return 0;
01528 }

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

Note:
The actionlock is read-locked by the caller of this function

Definition at line 1437 of file manager.c.

References manager_action::action, ast_strlen_zero(), astman_append(), astman_get_header(), manager_action::authority, authority_to_str(), first_action, manager_action::next, s, and manager_action::synopsis.

Referenced by init_manager().

01438 {
01439    struct manager_action *cur;
01440    char idText[256] = "";
01441    char temp[BUFSIZ];
01442    const char *id = astman_get_header(m,"ActionID");
01443 
01444    if (!ast_strlen_zero(id))
01445       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
01446    astman_append(s, "Response: Success\r\n%s", idText);
01447    for (cur = first_action; cur; cur = cur->next) {
01448       if ((s->session->writeperm & cur->authority) == cur->authority)
01449          astman_append(s, "%s: %s (Priv: %s)\r\n", cur->action, cur->synopsis, authority_to_str(cur->authority, temp, sizeof(temp)));
01450    }
01451    astman_append(s, "\r\n");
01452 
01453    return 0;
01454 }

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

Definition at line 1500 of file manager.c.

References astman_send_response(), and s.

Referenced by init_manager().

01501 {
01502    astman_send_response(s, m, "Goodbye", "Thanks for all the fish.");
01503    return -1;
01504 }

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

Definition at line 2137 of file manager.c.

References ast_app_inboxcount(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), mailbox, and s.

Referenced by init_manager().

02138 {
02139    const char *mailbox = astman_get_header(m, "Mailbox");
02140    const char *id = astman_get_header(m,"ActionID");
02141    char idText[256] = "";
02142    int newmsgs = 0, oldmsgs = 0;
02143    if (ast_strlen_zero(mailbox)) {
02144       astman_send_error(s, m, "Mailbox not specified");
02145       return 0;
02146    }
02147    ast_app_inboxcount(mailbox, &newmsgs, &oldmsgs);
02148    if (!ast_strlen_zero(id)) {
02149       snprintf(idText, sizeof(idText), "ActionID: %s\r\n",id);
02150    }
02151    astman_append(s, "Response: Success\r\n"
02152                "%s"
02153                "Message: Mailbox Message Count\r\n"
02154                "Mailbox: %s\r\n"
02155                "NewMessages: %d\r\n"
02156                "OldMessages: %d\r\n" 
02157                "\r\n",
02158                 idText,mailbox, newmsgs, oldmsgs);
02159    return 0;
02160 }

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

Definition at line 2105 of file manager.c.

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

Referenced by init_manager().

02106 {
02107    const char *mailbox = astman_get_header(m, "Mailbox");
02108    const char *id = astman_get_header(m,"ActionID");
02109    char idText[256] = "";
02110    int ret;
02111    if (ast_strlen_zero(mailbox)) {
02112       astman_send_error(s, m, "Mailbox not specified");
02113       return 0;
02114    }
02115         if (!ast_strlen_zero(id))
02116                 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
02117    ret = ast_app_has_voicemail(mailbox, NULL);
02118    astman_append(s, "Response: Success\r\n"
02119                "%s"
02120                "Message: Mailbox Status\r\n"
02121                "Mailbox: %s\r\n"
02122                "Waiting: %d\r\n\r\n", idText, mailbox, ret);
02123    return 0;
02124 }

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

Definition at line 1973 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, ast_shrink_phone_number(), ast_strlen_zero(), ast_true(), ast_variables_destroy(), astman_get_header(), astman_get_variables(), astman_send_ack(), astman_send_error(), context, ast_channel::data, exten, fast_originate(), format, name, ast_channel::priority, s, and ast_channel::tech.

Referenced by init_manager().

01974 {
01975    const char *name = astman_get_header(m, "Channel");
01976    const char *exten = astman_get_header(m, "Exten");
01977    const char *context = astman_get_header(m, "Context");
01978    const char *priority = astman_get_header(m, "Priority");
01979    const char *timeout = astman_get_header(m, "Timeout");
01980    const char *callerid = astman_get_header(m, "CallerID");
01981    const char *account = astman_get_header(m, "Account");
01982    const char *app = astman_get_header(m, "Application");
01983    const char *appdata = astman_get_header(m, "Data");
01984    const char *async = astman_get_header(m, "Async");
01985    const char *id = astman_get_header(m, "ActionID");
01986    const char *codecs = astman_get_header(m, "Codecs");
01987    struct ast_variable *vars;
01988    char *tech, *data;
01989    char *l = NULL, *n = NULL;
01990    int pi = 0;
01991    int res;
01992    int to = 30000;
01993    int reason = 0;
01994    char tmp[256];
01995    char tmp2[256];
01996    int format = AST_FORMAT_SLINEAR;
01997    
01998    pthread_t th;
01999    pthread_attr_t attr;
02000    if (ast_strlen_zero(name)) {
02001       astman_send_error(s, m, "Channel not specified");
02002       return 0;
02003    }
02004    if (!ast_strlen_zero(priority) && (sscanf(priority, "%30d", &pi) != 1)) {
02005       if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) {
02006          astman_send_error(s, m, "Invalid priority");
02007          return 0;
02008       }
02009    }
02010    if (!ast_strlen_zero(timeout) && (sscanf(timeout, "%30d", &to) != 1)) {
02011       astman_send_error(s, m, "Invalid timeout");
02012       return 0;
02013    }
02014    ast_copy_string(tmp, name, sizeof(tmp));
02015    tech = tmp;
02016    data = strchr(tmp, '/');
02017    if (!data) {
02018       astman_send_error(s, m, "Invalid channel");
02019       return 0;
02020    }
02021    *data++ = '\0';
02022    ast_copy_string(tmp2, callerid, sizeof(tmp2));
02023    ast_callerid_parse(tmp2, &n, &l);
02024    if (n) {
02025       if (ast_strlen_zero(n))
02026          n = NULL;
02027    }
02028    if (l) {
02029       ast_shrink_phone_number(l);
02030       if (ast_strlen_zero(l))
02031          l = NULL;
02032    }
02033    if (!ast_strlen_zero(codecs)) {
02034       format = 0;
02035       ast_parse_allow_disallow(NULL, &format, codecs, 1);
02036    }
02037    /* Allocate requested channel variables */
02038    vars = astman_get_variables(m);
02039 
02040    if (ast_true(async)) {
02041       struct fast_originate_helper *fast = ast_calloc(1, sizeof(*fast));
02042       if (!fast) {
02043          res = -1;
02044       } else {
02045          if (!ast_strlen_zero(id))
02046             snprintf(fast->idtext, sizeof(fast->idtext), "ActionID: %s", id);
02047          ast_copy_string(fast->tech, tech, sizeof(fast->tech));
02048             ast_copy_string(fast->data, data, sizeof(fast->data));
02049          ast_copy_string(fast->app, app, sizeof(fast->app));
02050          ast_copy_string(fast->appdata, appdata, sizeof(fast->appdata));
02051          if (l)
02052             ast_copy_string(fast->cid_num, l, sizeof(fast->cid_num));
02053          if (n)
02054             ast_copy_string(fast->cid_name, n, sizeof(fast->cid_name));
02055          fast->vars = vars;   
02056          ast_copy_string(fast->context, context, sizeof(fast->context));
02057          ast_copy_string(fast->exten, exten, sizeof(fast->exten));
02058          ast_copy_string(fast->account, account, sizeof(fast->account));
02059          fast->format = format;
02060          fast->timeout = to;
02061          fast->priority = pi;
02062          pthread_attr_init(&attr);
02063          pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
02064          if (ast_pthread_create(&th, &attr, fast_originate, fast)) {
02065             ast_free(fast);
02066             res = -1;
02067          } else {
02068             res = 0;
02069          }
02070          pthread_attr_destroy(&attr);
02071       }
02072    } else if (!ast_strlen_zero(app)) {
02073          res = ast_pbx_outgoing_app(tech, format, data, to, app, appdata, &reason, 1, l, n, vars, account, NULL);
02074       } else {
02075       if (exten && context && pi)
02076             res = ast_pbx_outgoing_exten(tech, format, data, to, context, exten, pi, &reason, 1, l, n, vars, account, NULL);
02077       else {
02078          astman_send_error(s, m, "Originate with 'Exten' requires 'Context' and 'Priority'");
02079          if (vars) {
02080             ast_variables_destroy(vars);
02081          }
02082          return 0;
02083       }
02084    }   
02085    if (!res)
02086       astman_send_ack(s, m, "Originate successfully queued");
02087    else
02088       astman_send_error(s, m, "Originate failed");
02089    return 0;
02090 }

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

Definition at line 1181 of file manager.c.

References astman_send_response(), and s.

Referenced by init_manager().

01182 {
01183    astman_send_response(s, m, "Pong", NULL);
01184    return 0;
01185 }

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

action_redirect: The redirect manager command

Definition at line 1738 of file manager.c.

References ast_async_goto(), ast_channel_lock, ast_channel_unlock, ast_check_hangup(), ast_findlabel_extension(), AST_FLAG_BRIDGE_HANGUP_DONT, ast_get_channel_by_name_locked(), ast_set_flag, ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), context, exten, name, ast_channel::pbx, and s.

Referenced by init_manager().

01739 {
01740    const char *name = astman_get_header(m, "Channel");
01741    const char *name2 = astman_get_header(m, "ExtraChannel");
01742    const char *exten = astman_get_header(m, "Exten");
01743    const char *context = astman_get_header(m, "Context");
01744    const char *priority = astman_get_header(m, "Priority");
01745    struct ast_channel *chan, *chan2 = NULL;
01746    int pi = 0;
01747    int res;
01748 
01749    if (ast_strlen_zero(name)) {
01750       astman_send_error(s, m, "Channel not specified");
01751       return 0;
01752    }
01753    if (!ast_strlen_zero(priority) && (sscanf(priority, "%30d", &pi) != 1)) {
01754       if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) {
01755          astman_send_error(s, m, "Invalid priority");
01756          return 0;
01757       }
01758    }
01759    /* XXX watch out, possible deadlock!!! */
01760    chan = ast_get_channel_by_name_locked(name);
01761    if (!chan) {
01762       char buf[BUFSIZ];
01763       snprintf(buf, sizeof(buf), "Channel does not exist: %s", name);
01764       astman_send_error(s, m, buf);
01765       return 0;
01766    }
01767    if (ast_check_hangup(chan)) {
01768       astman_send_error(s, m, "Redirect failed, channel not up.");
01769       ast_channel_unlock(chan);
01770       return 0;
01771    }
01772    if (!ast_strlen_zero(name2))
01773       chan2 = ast_get_channel_by_name_locked(name2);
01774    if (chan2 && ast_check_hangup(chan2)) {
01775       astman_send_error(s, m, "Redirect failed, extra channel not up.");
01776       ast_channel_unlock(chan);
01777       ast_channel_unlock(chan2);
01778       return 0;
01779    }
01780    if (chan->pbx) {
01781       ast_channel_lock(chan);
01782       ast_set_flag(chan, AST_FLAG_BRIDGE_HANGUP_DONT); /* don't let the after-bridge code run the h-exten */
01783       ast_channel_unlock(chan);
01784    }
01785    res = ast_async_goto(chan, context, exten, pi);
01786    if (!res) {
01787       if (!ast_strlen_zero(name2)) {
01788          if (chan2) {
01789             if (chan2->pbx) {
01790                ast_channel_lock(chan2);
01791                ast_set_flag(chan2, AST_FLAG_BRIDGE_HANGUP_DONT); /* don't let the after-bridge code run the h-exten */
01792                ast_channel_unlock(chan2);
01793             }
01794             res = ast_async_goto(chan2, context, exten, pi);
01795          } else {
01796             res = -1;
01797          }
01798          if (!res)
01799             astman_send_ack(s, m, "Dual Redirect successful");
01800          else
01801             astman_send_error(s, m, "Secondary redirect failed");
01802       } else
01803          astman_send_ack(s, m, "Redirect successful");
01804    } else
01805       astman_send_error(s, m, "Redirect failed");
01806    if (chan)
01807       ast_channel_unlock(chan);
01808    if (chan2)
01809       ast_channel_unlock(chan2);
01810    return 0;
01811 }

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

Definition at line 1537 of file manager.c.

References ast_channel_unlock, ast_func_write(), ast_get_channel_by_name_locked(), ast_strdupa, ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), name, pbx_builtin_setvar_helper(), s, and S_OR.

Referenced by init_manager().

01538 {
01539         struct ast_channel *c = NULL;
01540    const char *name = astman_get_header(m, "Channel");
01541    const char *varname = astman_get_header(m, "Variable");
01542    const char *varval = astman_get_header(m, "Value");
01543    int res = 0;
01544    
01545    if (ast_strlen_zero(varname)) {
01546       astman_send_error(s, m, "No variable specified");
01547       return 0;
01548    }
01549    
01550    if (!ast_strlen_zero(name)) {
01551       c = ast_get_channel_by_name_locked(name);
01552       if (!c) {
01553          astman_send_error(s, m, "No such channel");
01554          return 0;
01555       }
01556    }
01557    if (varname[strlen(varname)-1] == ')') {
01558       char *function = ast_strdupa(varname);
01559       res = ast_func_write(c, function, varval);
01560    } else {
01561       pbx_builtin_setvar_helper(c, varname, S_OR(varval, ""));
01562    }
01563      
01564    if (c) {
01565       ast_channel_unlock(c);
01566    }
01567 
01568    if (res == 0) {
01569       astman_send_ack(s, m, "Variable Set"); 
01570    } else {
01571       astman_send_error(s, m, "Variable not set");
01572    }
01573 
01574    return 0;
01575 }

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

Manager "status" command to show channels.

Definition at line 1637 of file manager.c.

References ast_channel::_bridge, ast_channel::_state, ast_channel::accountcode, ast_channel_unlock, ast_channel_walk_locked(), ast_get_channel_by_name_locked(), ast_state2str(), ast_strlen_zero(), ast_tvnow(), astman_append(), astman_get_header(), astman_send_ack(), astman_send_error(), ast_channel::cdr, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_channel::context, ast_channel::exten, ast_channel::name, name, ast_channel::pbx, ast_channel::priority, s, S_OR, ast_cdr::start, and ast_channel::uniqueid.

Referenced by init_manager().

01638 {
01639    const char *id = astman_get_header(m,"ActionID");
01640    const char *name = astman_get_header(m,"Channel");
01641    char idText[256] = "";
01642    struct ast_channel *c;
01643    char bridge[256];
01644    struct timeval now = ast_tvnow();
01645    long elapsed_seconds = 0;
01646    int all = ast_strlen_zero(name); /* set if we want all channels */
01647 
01648    if (!ast_strlen_zero(id))
01649       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
01650    if (all)
01651       c = ast_channel_walk_locked(NULL);
01652    else {
01653       c = ast_get_channel_by_name_locked(name);
01654       if (!c) {
01655          astman_send_error(s, m, "No such channel");
01656          return 0;
01657       }
01658    }
01659    astman_send_ack(s, m, "Channel status will follow");
01660    /* if we look by name, we break after the first iteration */
01661    while (c) {
01662       if (c->_bridge)
01663          snprintf(bridge, sizeof(bridge), "Link: %s\r\n", c->_bridge->name);
01664       else
01665          bridge[0] = '\0';
01666       if (c->pbx) {
01667          if (c->cdr) {
01668             elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
01669          }
01670          astman_append(s,
01671          "Event: Status\r\n"
01672          "Privilege: Call\r\n"
01673          "Channel: %s\r\n"
01674          "CallerID: %s\r\n"      /* This parameter is deprecated and will be removed post-1.4 */
01675          "CallerIDNum: %s\r\n"
01676          "CallerIDName: %s\r\n"
01677          "Account: %s\r\n"
01678          "State: %s\r\n"
01679          "Context: %s\r\n"
01680          "Extension: %s\r\n"
01681          "Priority: %d\r\n"
01682          "Seconds: %ld\r\n"
01683          "%s"
01684          "Uniqueid: %s\r\n"
01685          "%s"
01686          "\r\n",
01687          c->name, 
01688          S_OR(c->cid.cid_num, "<unknown>"), 
01689          S_OR(c->cid.cid_num, "<unknown>"), 
01690          S_OR(c->cid.cid_name, "<unknown>"), 
01691          c->accountcode,
01692          ast_state2str(c->_state), c->context,
01693          c->exten, c->priority, (long)elapsed_seconds, bridge, c->uniqueid, idText);
01694       } else {
01695          astman_append(s,
01696          "Event: Status\r\n"
01697          "Privilege: Call\r\n"
01698          "Channel: %s\r\n"
01699          "CallerID: %s\r\n"      /* This parameter is deprecated and will be removed post-1.4 */
01700          "CallerIDNum: %s\r\n"
01701          "CallerIDName: %s\r\n"
01702          "Account: %s\r\n"
01703          "State: %s\r\n"
01704          "%s"
01705          "Uniqueid: %s\r\n"
01706          "%s"
01707          "\r\n",
01708          c->name, 
01709          S_OR(c->cid.cid_num, "<unknown>"), 
01710          S_OR(c->cid.cid_num, "<unknown>"), 
01711          S_OR(c->cid.cid_name, "<unknown>"), 
01712          c->accountcode,
01713          ast_state2str(c->_state), bridge, c->uniqueid, idText);
01714       }
01715       ast_channel_unlock(c);
01716       if (!all)
01717          break;
01718       c = ast_channel_walk_locked(c);
01719    }
01720    astman_append(s,
01721    "Event: StatusComplete\r\n"
01722    "%s"
01723    "\r\n",idText);
01724    return 0;
01725 }

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

Definition at line 2210 of file manager.c.

References ast_channel_setwhentohangup(), ast_channel_unlock, ast_get_channel_by_name_locked(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), name, and s.

Referenced by init_manager().

02211 {
02212    struct ast_channel *c = NULL;
02213    const char *name = astman_get_header(m, "Channel");
02214    int timeout = atoi(astman_get_header(m, "Timeout"));
02215    if (ast_strlen_zero(name)) {
02216       astman_send_error(s, m, "No channel specified");
02217       return 0;
02218    }
02219    if (!timeout) {
02220       astman_send_error(s, m, "No timeout specified");
02221       return 0;
02222    }
02223    c = ast_get_channel_by_name_locked(name);
02224    if (!c) {
02225       astman_send_error(s, m, "No such channel");
02226       return 0;
02227    }
02228    ast_channel_setwhentohangup(c, timeout);
02229    ast_channel_unlock(c);
02230    astman_send_ack(s, m, "Timeout Set");
02231    return 0;
02232 }

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

Definition at line 1304 of file manager.c.

References ast_config_destroy(), ast_config_load_with_comments(), ast_module_reload(), ast_strlen_zero(), ast_true(), astman_append(), astman_get_header(), astman_send_error(), config_text_file_save(), handle_updates(), and s.

Referenced by init_manager().

01305 {
01306    struct ast_config *cfg;
01307    const char *sfn = astman_get_header(m, "SrcFilename");
01308    const char *dfn = astman_get_header(m, "DstFilename");
01309    int res;
01310    char idText[256] = "";
01311    const char *id = astman_get_header(m, "ActionID");
01312    const char *rld = astman_get_header(m, "Reload");
01313 
01314    if (!ast_strlen_zero(id))
01315       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
01316 
01317    if (ast_strlen_zero(sfn) || ast_strlen_zero(dfn)) {
01318       astman_send_error(s, m, "Filename not specified");
01319       return 0;
01320    }
01321    if (!(cfg = ast_config_load_with_comments(sfn))) {
01322       astman_send_error(s, m, "Config file not found");
01323       return 0;
01324    }
01325    handle_updates(s, m, cfg);
01326    res = config_text_file_save(dfn, cfg, "Manager");
01327    ast_config_destroy(cfg);
01328    if (res) {
01329       astman_send_error(s, m, "Save of config failed");
01330       return 0;
01331    }
01332    astman_append(s, "Response: Success\r\n%s\r\n", idText);
01333    if (!ast_strlen_zero(rld)) {
01334       if (ast_true(rld))
01335          rld = NULL;
01336       ast_module_reload(rld); 
01337    }
01338    return 0;
01339 }

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

Definition at line 2267 of file manager.c.

References ast_copy_string(), ast_log(), astman_get_header(), message::hdrcount, message::headers, and LOG_WARNING.

Referenced by init_manager().

02268 {
02269    const char *event = astman_get_header(m, "UserEvent");
02270    char body[2048] = "";
02271    int x, bodylen = 0, xlen;
02272    for (x = 0; x < m->hdrcount; x++) {
02273       if (strncasecmp("UserEvent:", m->headers[x], strlen("UserEvent:"))) {
02274          if (sizeof(body) < bodylen + (xlen = strlen(m->headers[x])) + 3) {
02275             ast_log(LOG_WARNING, "UserEvent exceeds our buffer length.  Truncating.\n");
02276             break;
02277          }
02278          ast_copy_string(body + bodylen, m->headers[x], sizeof(body) - bodylen - 3);
02279          bodylen += xlen;
02280          ast_copy_string(body + bodylen, "\r\n", 3);
02281          bodylen += 2;
02282       }
02283    }
02284 
02285    astman_send_ack(s, m, "Event Sent");   
02286    manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", event, body);
02287    return 0;
02288 }

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

Definition at line 1349 of file manager.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), AST_PTHREADT_NULL, ast_strlen_zero(), ast_wait_for_input(), astman_append(), astman_get_header(), astman_send_response(), eventqent::category, eventqent::eventdata, LOG_DEBUG, option_debug, s, and unuse_eventqent().

Referenced by init_manager().

01350 {
01351    const char *timeouts = astman_get_header(m, "Timeout");
01352    int timeout = -1, max;
01353    int x;
01354    int needexit = 0;
01355    time_t now;
01356    struct eventqent *eqe;
01357    const char *id = astman_get_header(m,"ActionID");
01358    char idText[256] = "";
01359 
01360    if (!ast_strlen_zero(id))
01361       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
01362 
01363    if (!ast_strlen_zero(timeouts)) {
01364       sscanf(timeouts, "%30i", &timeout);
01365    }
01366    
01367    ast_mutex_lock(&s->session->__lock);
01368    if (s->session->waiting_thread != AST_PTHREADT_NULL) {
01369       pthread_kill(s->session->waiting_thread, SIGURG);
01370    }
01371    if (s->session->sessiontimeout) {
01372       time(&now);
01373       max = s->session->sessiontimeout - now - 10;
01374       if (max < 0)
01375          max = 0;
01376       if ((timeout < 0) || (timeout > max))
01377          timeout = max;
01378       if (!s->session->send_events)
01379          s->session->send_events = -1;
01380       /* Once waitevent is called, always queue events from now on */
01381    }
01382    ast_mutex_unlock(&s->session->__lock);
01383    s->session->waiting_thread = pthread_self();
01384    if (option_debug)
01385       ast_log(LOG_DEBUG, "Starting waiting for an event!\n");
01386    for (x=0; ((x < timeout) || (timeout < 0)); x++) {
01387       ast_mutex_lock(&s->session->__lock);
01388       if (s->session->eventq && s->session->eventq->next)
01389          needexit = 1;
01390       if (s->session->waiting_thread != pthread_self())
01391          needexit = 1;
01392       if (s->session->needdestroy)
01393          needexit = 1;
01394       ast_mutex_unlock(&s->session->__lock);
01395       if (needexit)
01396          break;
01397       if (s->session->fd > 0) {
01398          if (ast_wait_for_input(s->session->fd, 1000))
01399             break;
01400       } else {
01401          sleep(1);
01402       }
01403    }
01404    if (option_debug)
01405       ast_log(LOG_DEBUG, "Finished waiting for an event!\n");
01406    ast_mutex_lock(&s->session->__lock);
01407    if (s->session->waiting_thread == pthread_self()) {
01408       astman_send_response(s, m, "Success", "Waiting for Event...");
01409       /* Only show events if we're the most recent waiter */
01410       while(s->session->eventq->next) {
01411          eqe = s->session->eventq->next;
01412          if (((s->session->readperm & eqe->category) == eqe->category) &&
01413              ((s->session->send_events & eqe->category) == eqe->category)) {
01414             astman_append(s, "%s", eqe->eventdata);
01415          }
01416          unuse_eventqent(s->session->eventq);
01417          s->session->eventq = eqe;
01418       }
01419       astman_append(s,
01420          "Event: WaitEventComplete\r\n"
01421          "%s"
01422          "\r\n", idText);
01423       s->session->waiting_thread = AST_PTHREADT_NULL;
01424    } else {
01425       ast_log(LOG_DEBUG, "Abandoning event request!\n");
01426    }
01427    ast_mutex_unlock(&s->session->__lock);
01428    return 0;
01429 }

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

Definition at line 2734 of file manager.c.

References ast_malloc, master_eventq, eventqent::next, num_sessions, and eventqent::usecount.

Referenced by init_manager(), and manager_event().

02735 {
02736    struct eventqent *tmp, *prev = NULL;
02737    tmp = ast_malloc(sizeof(*tmp) + strlen(str));
02738 
02739    if (!tmp)
02740       return -1;
02741 
02742    tmp->next = NULL;
02743    tmp->category = category;
02744    strcpy(tmp->eventdata, str);
02745    
02746    if (master_eventq) {
02747       prev = master_eventq;
02748       while (prev->next) 
02749          prev = prev->next;
02750       prev->next = tmp;
02751    } else {
02752       master_eventq = tmp;
02753    }
02754    
02755    tmp->usecount = num_sessions;
02756    
02757    return 0;
02758 }

static struct ast_manager_user* ast_get_manager_by_name_locked ( const char *  name  )  [static]

Definition at line 545 of file manager.c.

References AST_LIST_TRAVERSE, mansession_session::list, and ast_manager_user::username.

Referenced by handle_showmanager(), and init_manager().

00546 {
00547    struct ast_manager_user *user = NULL;
00548 
00549    AST_LIST_TRAVERSE(&users, user, list)
00550       if (!strcasecmp(user->username, name))
00551          break;
00552    return user;
00553 }

static int ast_instring ( const char *  bigstr,
const char *  smallstr,
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 937 of file manager.c.

References ast_variable::next.

Referenced by get_perm(), and strings_to_mask().

00938 {
00939    const char *val = bigstr, *next;
00940 
00941    do {
00942       if ((next = strchr(val, delim))) {
00943          if (!strncmp(val, smallstr, (next - val)))
00944             return 1;
00945          else
00946             continue;
00947       } else
00948          return !strcmp(smallstr, val);
00949 
00950    } while (*(val = (next + 1)));
00951 
00952    return 0;
00953 }

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

Definition at line 970 of file manager.c.

Referenced by strings_to_mask().

00971 {
00972    int ret = 1, x = 0;
00973 
00974    if (!string)
00975       return 0;
00976 
00977    for (x = 0; x < strlen(string); x++) {
00978       if (!(string[x] >= 48 && string[x] <= 57)) {
00979          ret = 0;
00980          break;
00981       }
00982    }
00983    
00984    return ret ? atoi(string) : 0;
00985 }

int ast_manager_register2 ( const char *  action,
int  authority,
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

Parameters:
action Name of the requested Action:
authority Required authority for this command
func Function to call for this command
synopsis Help text (one line, up to 30 chars) for CLI manager show commands
description Help text, several lines

Definition at line 2895 of file manager.c.

References ast_free, ast_malloc, and ast_manager_register_struct().

Referenced by init_manager(), and load_module().

02896 {
02897    struct manager_action *cur;
02898 
02899    cur = ast_malloc(sizeof(*cur));
02900    if (!cur)
02901       return -1;
02902    
02903    cur->action = action;
02904    cur->authority = auth;
02905    cur->func = func;
02906    cur->synopsis = synopsis;
02907    cur->description = description;
02908    cur->next = NULL;
02909 
02910    if (ast_manager_register_struct(cur)) {
02911       ast_free(cur);
02912       return -1;
02913    }
02914 
02915    return 0;
02916 }

static int ast_manager_register_struct ( struct manager_action act  )  [static]

Definition at line 2847 of file manager.c.

References manager_action::action, actionlock, ast_log(), ast_rwlock_timedwrlock(), ast_rwlock_unlock(), ast_verbose(), first_action, LOG_ERROR, LOG_WARNING, manager_action::next, option_verbose, tv, and VERBOSE_PREFIX_2.

Referenced by ast_manager_register2().

02848 {
02849    struct manager_action *cur, *prev = NULL;
02850    int ret;
02851    struct timespec tv = { 5, };
02852 
02853    if (ast_rwlock_timedwrlock(&actionlock, &tv)) {
02854       ast_log(LOG_ERROR, "Could not obtain lock on manager list\n");
02855       return -1;
02856    }
02857    cur = first_action;
02858    while (cur) { /* Walk the list of actions */
02859       ret = strcasecmp(cur->action, act->action);
02860       if (ret == 0) {
02861          ast_log(LOG_WARNING, "Manager: Action '%s' already registered\n", act->action);
02862          ast_rwlock_unlock(&actionlock);
02863          return -1;
02864       } else if (ret > 0) {
02865          /* Insert these alphabetically */
02866          if (prev) {
02867             act->next = prev->next;
02868             prev->next = act;
02869          } else {
02870             act->next = first_action;
02871             first_action = act;
02872          }
02873          break;
02874       }
02875       prev = cur; 
02876       cur = cur->next;
02877    }
02878    
02879    if (!cur) {
02880       if (prev)
02881          prev->next = act;
02882       else
02883          first_action = act;
02884       act->next = NULL;
02885    }
02886 
02887    if (option_verbose > 1) 
02888       ast_verbose(VERBOSE_PREFIX_2 "Manager registered action %s\n", act->action);
02889    ast_rwlock_unlock(&actionlock);
02890    return 0;
02891 }

int ast_manager_unregister ( char *  action  ) 

Parameters:
action Name of registered Action:

Definition at line 2814 of file manager.c.

References manager_action::action, actionlock, ast_log(), ast_rwlock_timedwrlock(), ast_rwlock_unlock(), ast_verbose(), first_action, free, LOG_ERROR, manager_action::next, option_verbose, tv, and VERBOSE_PREFIX_2.

Referenced by __unload_module(), and unload_module().

02815 {
02816    struct manager_action *cur, *prev;
02817    struct timespec tv = { 5, };
02818 
02819    if (ast_rwlock_timedwrlock(&actionlock, &tv)) {
02820       ast_log(LOG_ERROR, "Could not obtain lock on manager list\n");
02821       return -1;
02822    }
02823    cur = prev = first_action;
02824    while (cur) {
02825       if (!strcasecmp(action, cur->action)) {
02826          prev->next = cur->next;
02827          free(cur);
02828          if (option_verbose > 1) 
02829             ast_verbose(VERBOSE_PREFIX_2 "Manager unregistered action %s\n", action);
02830          ast_rwlock_unlock(&actionlock);
02831          return 0;
02832       }
02833       prev = cur;
02834       cur = cur->next;
02835    }
02836    ast_rwlock_unlock(&actionlock);
02837    return 0;
02838 }

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

Definition at line 555 of file manager.c.

References ast_calloc, ast_carefulwrite(), ast_dynamic_str_append(), ast_dynamic_str_thread_get(), ast_dynamic_str_thread_set_va, ast_mutex_lock(), ast_mutex_unlock(), astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE, s, and ast_dynamic_str::str.

Referenced by __action_showchannels(), __iax2_show_peers(), __queues_show(), _sip_show_peer(), _sip_show_peers(), action_agents(), action_command(), action_coresettings(), action_corestatus(), action_extensionstate(), action_getconfig(), action_getvar(), action_listcommands(), action_mailboxcount(), action_mailboxstatus(), action_status(), action_updateconfig(), action_waitevent(), ast_cli_netstats(), astman_send_error(), astman_send_response(), manager_dbget(), manager_iax2_show_netstats(), manager_iax2_show_peers(), manager_jabber_send(), manager_parking_status(), manager_queues_show(), manager_queues_status(), manager_sip_show_peer(), manager_sip_show_peers(), process_message(), and session_do().

00556 {
00557    va_list ap;
00558    struct ast_dynamic_str *buf;
00559 
00560    ast_mutex_lock(&s->session->__lock);
00561 
00562    if (!(buf = ast_dynamic_str_thread_get(&astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE))) {
00563       ast_mutex_unlock(&s->session->__lock);
00564       return;
00565    }
00566 
00567    va_start(ap, fmt);
00568    ast_dynamic_str_thread_set_va(&buf, 0, &astman_append_buf, fmt, ap);
00569    va_end(ap);
00570    
00571    if (s->fd > -1)
00572       ast_carefulwrite(s->fd, buf->str, strlen(buf->str), s->session->writetimeout);
00573    else {
00574       if (!s->session->outputstr && !(s->session->outputstr = ast_calloc(1, sizeof(*s->session->outputstr)))) {
00575          ast_mutex_unlock(&s->session->__lock);
00576          return;
00577       }
00578 
00579       ast_dynamic_str_append(&s->session->outputstr, 0, "%s", buf->str);   
00580    }
00581 
00582    ast_mutex_unlock(&s->session->__lock);
00583 }

static void astman_append_buf_init ( void   )  [static]

Definition at line 135 of file manager.c.

00138 {

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

Get header from mananger transaction

Definition at line 840 of file manager.c.

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

Referenced by __action_dialoffhook(), __action_showchannels(), _sip_show_peer(), _sip_show_peers(), action_agent_callback_login(), action_agent_logoff(), action_agents(), action_command(), action_coresettings(), action_corestatus(), action_events(), action_extensionstate(), action_getconfig(), action_getvar(), action_hangup(), action_listcommands(), action_mailboxcount(), action_mailboxstatus(), action_originate(), action_redirect(), action_setcdruserfield(), action_setvar(), action_status(), action_timeout(), action_updateconfig(), action_userevent(), action_waitevent(), astman_send_error(), astman_send_response(), authenticate(), change_monitor_action(), do_pause_or_unpause(), handle_updates(), manager_add_queue_member(), manager_dbget(), manager_dbput(), manager_iax2_show_peers(), manager_jabber_send(), manager_park(), manager_parking_status(), manager_pause_queue_member(), manager_play_dtmf(), manager_queue_member_count(), manager_queues_status(), manager_remove_queue_member(), manager_sip_show_peer(), manager_sip_show_peers(), meetmemute(), process_message(), start_monitor_action(), and stop_monitor_action().

00841 {
00842    char cmp[80];
00843    int x;
00844 
00845    snprintf(cmp, sizeof(cmp), "%s: ", var);
00846 
00847    for (x = 0; x < m->hdrcount; x++) {
00848       if (!strncasecmp(cmp, m->headers[x], strlen(cmp)))
00849          return m->headers[x] + strlen(cmp);
00850    }
00851 
00852    return "";
00853 }

struct ast_variable* astman_get_variables ( const struct message m  ) 

Get a linked list of the Variable: headers

Definition at line 855 of file manager.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_variable_new(), message::hdrcount, message::headers, parse(), and var.

Referenced by action_originate().

00856 {
00857    int varlen, x, y;
00858    struct ast_variable *head = NULL, *cur;
00859    char *var, *val;
00860 
00861    char *parse;    
00862    AST_DECLARE_APP_ARGS(args,
00863       AST_APP_ARG(vars)[32];
00864    );
00865 
00866    varlen = strlen("Variable: ");   
00867 
00868    for (x = 0; x < m->hdrcount; x++) {
00869       if (strncasecmp("Variable: ", m->headers[x], varlen))
00870          continue;
00871 
00872       parse = ast_strdupa(m->headers[x] + varlen);
00873 
00874       AST_STANDARD_APP_ARGS(args, parse);
00875       if (args.argc) {
00876          for (y = 0; y < args.argc; y++) {
00877             if (!args.vars[y])
00878                continue;
00879             var = val = ast_strdupa(args.vars[y]);
00880             strsep(&val, "=");
00881             if (!val || ast_strlen_zero(var))
00882                continue;
00883             cur = ast_variable_new(var, val);
00884             if (head) {
00885                cur->next = head;
00886                head = cur;
00887             } else
00888                head = cur;
00889          }
00890       }
00891    }
00892 
00893    return head;
00894 }

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

Definition at line 927 of file manager.c.

References astman_send_response(), and s.

Referenced by action_agent_callback_login(), action_agent_logoff(), action_agents(), action_hangup(), action_originate(), action_redirect(), action_setcdruserfield(), action_setvar(), action_status(), action_timeout(), change_monitor_action(), do_pause_or_unpause(), manager_add_queue_member(), manager_dbget(), manager_dbput(), manager_jabber_send(), manager_park(), manager_parking_status(), manager_pause_queue_member(), manager_play_dtmf(), manager_queue_member_count(), manager_queues_status(), manager_remove_queue_member(), manager_sip_show_peers(), meetmemute(), process_message(), start_monitor_action(), and stop_monitor_action().

00928 {
00929    astman_send_response(s, m, "Success", msg);
00930 }

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

Note:
NOTE: 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->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.

Definition at line 904 of file manager.c.

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

Referenced by __action_dialoffhook(), __action_dnd(), __action_restart(), __action_transfer(), __action_transferhangup(), _sip_show_peer(), action_agent_callback_login(), action_agent_logoff(), action_command(), action_events(), action_extensionstate(), action_getconfig(), action_getvar(), action_hangup(), action_mailboxcount(), action_mailboxstatus(), action_originate(), action_redirect(), action_setcdruserfield(), action_setvar(), action_status(), action_timeout(), action_updateconfig(), change_monitor_action(), do_pause_or_unpause(), manager_add_queue_member(), manager_dbget(), manager_dbput(), manager_jabber_send(), manager_park(), manager_pause_queue_member(), manager_play_dtmf(), manager_queue_member_count(), manager_remove_queue_member(), manager_sip_show_peer(), meetmemute(), process_message(), start_monitor_action(), and stop_monitor_action().

00905 {
00906    const char *id = astman_get_header(m,"ActionID");
00907 
00908    astman_append(s, "Response: Error\r\n");
00909    if (!ast_strlen_zero(id))
00910       astman_append(s, "ActionID: %s\r\n", id);
00911    astman_append(s, "Message: %s\r\n\r\n", error);
00912 }

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

Definition at line 914 of file manager.c.

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

Referenced by action_events(), action_logoff(), action_ping(), action_waitevent(), and astman_send_ack().

00915 {
00916    const char *id = astman_get_header(m,"ActionID");
00917 
00918    astman_append(s, "Response: %s\r\n", resp);
00919    if (!ast_strlen_zero(id))
00920       astman_append(s, "ActionID: %s\r\n", id);
00921    if (msg)
00922       astman_append(s, "Message: %s\r\n\r\n", msg);
00923    else
00924       astman_append(s, "\r\n");
00925 }

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

Definition at line 1030 of file manager.c.

References ast_append_ha(), ast_apply_ha(), ast_category_browse(), ast_config_AST_SYSTEM_NAME, ast_config_destroy(), ast_config_load(), ast_free_ha(), ast_inet_ntoa(), ast_log(), ast_strlen_zero(), ast_true(), ast_variable_browse(), astman_get_header(), events, len(), LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, md5(), MD5Final(), MD5Init(), MD5Update(), ast_variable::name, ast_variable::next, password, s, S_OR, and ast_variable::value.

Referenced by authenticate_reply(), handle_response_invite(), process_message(), and registry_rerequest().

01031 {
01032    struct ast_config *cfg;
01033    char *cat;
01034    const char *user = astman_get_header(m, "Username");
01035    const char *pass = astman_get_header(m, "Secret");
01036    const char *authtype = astman_get_header(m, "AuthType");
01037    const char *key = astman_get_header(m, "Key");
01038    const char *events = astman_get_header(m, "Events");
01039    
01040    cfg = ast_config_load("manager.conf");
01041    if (!cfg)
01042       return -1;
01043    cat = ast_category_browse(cfg, NULL);
01044    while (cat) {
01045       if (strcasecmp(cat, "general")) {
01046          /* This is a user */
01047          if (!strcasecmp(cat, user)) {
01048             struct ast_variable *v;
01049             struct ast_ha *ha = NULL;
01050             char *password = NULL;
01051 
01052             for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
01053                if (!strcasecmp(v->name, "secret")) {
01054                   password = v->value;
01055                } else if (!strcasecmp(v->name, "displaysystemname")) {
01056                   if (ast_true(v->value)) {
01057                      if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) {
01058                         s->session->displaysystemname = 1;
01059                      } else {
01060                         ast_log(LOG_ERROR, "Can't enable displaysystemname in manager.conf - no system name configured in asterisk.conf\n");
01061                      }
01062                   }
01063                } else if (!strcasecmp(v->name, "permit") ||
01064                      !strcasecmp(v->name, "deny")) {
01065                   ha = ast_append_ha(v->name, v->value, ha);
01066                } else if (!strcasecmp(v->name, "writetimeout")) {
01067                   int val = atoi(v->value);
01068 
01069                   if (val < 100)
01070                      ast_log(LOG_WARNING, "Invalid writetimeout value '%s' at line %d\n", v->value, v->lineno);
01071                   else
01072                      s->session->writetimeout = val;
01073                }
01074                      
01075             }
01076             if (ha && !ast_apply_ha(ha, &(s->session->sin))) {
01077                ast_log(LOG_NOTICE, "%s failed to pass IP ACL as '%s'\n", ast_inet_ntoa(s->session->sin.sin_addr), user);
01078                ast_free_ha(ha);
01079                ast_config_destroy(cfg);
01080                return -1;
01081             } else if (ha)
01082                ast_free_ha(ha);
01083             if (!strcasecmp(authtype, "MD5")) {
01084                if (!ast_strlen_zero(key) && 
01085                    !ast_strlen_zero(s->session->challenge) && !ast_strlen_zero(password)) {
01086                   int x;
01087                   int len = 0;
01088                   char md5key[256] = "";
01089                   struct MD5Context md5;
01090                   unsigned char digest[16];
01091                   MD5Init(&md5);
01092                   MD5Update(&md5, (unsigned char *) s->session->challenge, strlen(s->session->challenge));
01093                   MD5Update(&md5, (unsigned char *) password, strlen(password));
01094                   MD5Final(digest, &md5);
01095                   for (x=0; x<16; x++)
01096                      len += sprintf(md5key + len, "%2.2x", digest[x]);
01097                   if (!strcmp(md5key, key))
01098                      break;
01099                   else {
01100                      ast_config_destroy(cfg);
01101                      return -1;
01102                   }
01103                } else {
01104                   ast_log(LOG_DEBUG, "MD5 authentication is not possible.  challenge: '%s'\n", 
01105                      S_OR(s->session->challenge, ""));
01106                   ast_config_destroy(cfg);
01107                   return -1;
01108                }
01109             } else if (password && !strcmp(password, pass)) {
01110                break;
01111             } else {
01112                ast_log(LOG_NOTICE, "%s failed to authenticate as '%s'\n", ast_inet_ntoa(s->session->sin.sin_addr), user);
01113                ast_config_destroy(cfg);
01114                return -1;
01115             }  
01116          }
01117       }
01118       cat = ast_category_browse(cfg, cat);
01119    }
01120    if (cat) {
01121       ast_copy_string(s->session->username, cat, sizeof(s->session->username));
01122       s->session->readperm = get_perm(ast_variable_retrieve(cfg, cat, "read"));
01123       s->session->writeperm = get_perm(ast_variable_retrieve(cfg, cat, "write"));
01124       ast_config_destroy(cfg);
01125       if (events)
01126          set_eventmask(s->session, events);
01127       return 0;
01128    }
01129    ast_config_destroy(cfg);
01130    cfg = ast_config_load("users.conf");
01131    if (!cfg)
01132       return -1;
01133    cat = ast_category_browse(cfg, NULL);
01134    while (cat) {
01135       struct ast_variable *v;
01136       const char *password = NULL;
01137       int hasmanager = 0;
01138       const char *readperms = NULL;
01139       const char *writeperms = NULL;
01140 
01141       if (strcasecmp(cat, user) || !strcasecmp(cat, "general")) {
01142          cat = ast_category_browse(cfg, cat);
01143          continue;
01144       }
01145       for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
01146          if (!strcasecmp(v->name, "secret"))
01147             password = v->value;
01148          else if (!strcasecmp(v->name, "hasmanager"))
01149             hasmanager = ast_true(v->value);
01150          else if (!strcasecmp(v->name, "managerread"))
01151             readperms = v->value;
01152          else if (!strcasecmp(v->name, "managerwrite"))
01153             writeperms = v->value;
01154       }
01155       if (!hasmanager)
01156          break;
01157       if (!password || strcmp(password, pass)) {
01158          ast_log(LOG_NOTICE, "%s failed to authenticate as '%s'\n", ast_inet_ntoa(s->session->sin.sin_addr), user);
01159          ast_config_destroy(cfg);
01160          return -1;
01161       }
01162       ast_copy_string(s->session->username, cat, sizeof(s->session->username));
01163       s->session->readperm = readperms ? get_perm(readperms) : -1;
01164       s->session->writeperm = writeperms ? get_perm(writeperms) : -1;
01165       ast_config_destroy(cfg);
01166       if (events)
01167          set_eventmask(s->session, events);
01168       return 0;
01169    }
01170    ast_log(LOG_NOTICE, "%s tried to authenticate with nonexistent user '%s'\n", ast_inet_ntoa(s->session->sin.sin_addr), user);
01171    ast_config_destroy(cfg);
01172    return -1;
01173 }

static char* authority_to_str ( int  authority,
char *  res,
int  reslen 
) [static]

Convert authority code to string with serveral options.

Definition at line 279 of file manager.c.

References ast_copy_string(), ast_strlen_zero(), and perms.

Referenced by action_listcommands(), handle_showmancmd(), handle_showmancmds(), manager_event(), and process_message().

00280 {
00281    int running_total = 0, i;
00282 
00283    memset(res, 0, reslen);
00284    for (i = 0; i < (sizeof(perms) / sizeof(perms[0])) - 1; i++) {
00285       if (authority & perms[i].num) {
00286          if (*res) {
00287             strncat(res, ",", (reslen > running_total) ? reslen - running_total - 1 : 0);
00288             running_total++;
00289          }
00290          strncat(res, perms[i].label, (reslen > running_total) ? reslen - running_total - 1 : 0);
00291          running_total += strlen(perms[i].label);
00292       }
00293    }
00294 
00295    if (ast_strlen_zero(res))
00296       ast_copy_string(res, "<none>", reslen);
00297    
00298    return res;
00299 }

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

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

01814 {
01815    char *cmd_copy, *cur_cmd;
01816    char *cmd_words[MAX_BLACKLIST_CMD_LEN] = { NULL, };
01817    int i;
01818 
01819    cmd_copy = ast_strdupa(cmd);
01820    for (i = 0; i < MAX_BLACKLIST_CMD_LEN && (cur_cmd = strsep(&cmd_copy, " ")); i++) {
01821       cur_cmd = ast_strip(cur_cmd);
01822       if (ast_strlen_zero(cur_cmd)) {
01823          i--;
01824          continue;
01825       }
01826 
01827       cmd_words[i] = cur_cmd;
01828    }
01829 
01830    for (i = 0; i < ARRAY_LEN(command_blacklist); i++) {
01831       int j, match = 1;
01832 
01833       for (j = 0; command_blacklist[i].words[j]; j++) {
01834          if (ast_strlen_zero(cmd_words[j]) || strcasecmp(cmd_words[j], command_blacklist[i].words[j])) {
01835             match = 0;
01836             break;
01837          }
01838       }
01839 
01840       if (match) {
01841          return 1;
01842       }
01843    }
01844 
01845    return 0;
01846 }

int check_manager_enabled ( void   ) 

Check if AMI is enabled.

Definition at line 268 of file manager.c.

Referenced by handle_show_settings().

00269 {
00270    return manager_enabled;
00271 }

int check_webmanager_enabled ( void   ) 

Check if AMI/HTTP is enabled.

Definition at line 273 of file manager.c.

Referenced by action_coresettings(), and handle_show_settings().

00274 {
00275    return (webmanager_enabled && manager_enabled);
00276 }

static char* complete_show_mancmd ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 301 of file manager.c.

References manager_action::action, actionlock, ast_rwlock_rdlock(), ast_rwlock_unlock(), ast_strdup, first_action, and manager_action::next.

00302 {
00303    struct manager_action *cur;
00304    int which = 0;
00305    char *ret = NULL;
00306 
00307    ast_rwlock_rdlock(&actionlock);
00308    for (cur = first_action; cur; cur = cur->next) { /* Walk the list of actions */
00309       if (!strncasecmp(word, cur->action, strlen(word)) && ++which > state) {
00310          ret = ast_strdup(cur->action);
00311          break;   /* make sure we exit even if ast_strdup() returns NULL */
00312       }
00313    }
00314    ast_rwlock_unlock(&actionlock);
00315 
00316    return ret;
00317 }

static int compress_char ( char  c  )  [static]

Definition at line 361 of file manager.c.

Referenced by member_hash_fn(), and variable_count_hash_fn().

00362 {
00363    c &= 0x7f;
00364    if (c < 32)
00365       return 0;
00366    else if (c >= 'a' && c <= 'z')
00367       return c - 64;
00368    else if (c > 'z')
00369       return '_';
00370    else
00371       return c - 32;
00372 }

static void destroy_session ( struct mansession_session s  )  [static]

Definition at line 831 of file manager.c.

References AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, free_session(), mansession_session::list, and s.

Referenced by accept_thread(), and skinny_session().

00832 {
00833    AST_LIST_LOCK(&sessions);
00834    AST_LIST_REMOVE(&sessions, s, list);
00835    num_sessions--;
00836    free_session(s);
00837    AST_LIST_UNLOCK(&sessions);
00838 }

static int do_message ( struct mansession s  )  [static]

Definition at line 2540 of file manager.c.

References ast_inet_ntoa(), ast_log(), AST_MAX_MANHEADERS, ast_strdupa, ast_strlen_zero(), authtimeout, errno, get_input(), message::hdrcount, message::headers, LOG_ERROR, LOG_EVENT, process_events(), process_message(), and s.

Referenced by session_do().

02541 {
02542    struct message m = { 0 };
02543    char header_buf[sizeof(s->session->inbuf)] = { '\0' };
02544    int res;
02545    time_t now;
02546 
02547    for (;;) {
02548       /* Check if any events are pending and do them if needed */
02549       if (s->session->eventq->next) {
02550          if (process_events(s))
02551             return -1;
02552       }
02553       res = get_input(s->session, header_buf);
02554       if (res == 0) {
02555          if (!s->session->authenticated) {
02556             if(time(&now) == -1) {
02557                ast_log(LOG_ERROR, "error executing time(): %s\n", strerror(errno));
02558                return -1;
02559             }
02560 
02561             if (now - s->session->authstart > authtimeout) {
02562                ast_log(LOG_EVENT, "Client from %s, failed to authenticate in %d seconds\n", ast_inet_ntoa(s->session->sin.sin_addr), authtimeout);
02563                return -1;
02564             }
02565          }
02566          continue;
02567       } else if (res > 0) {
02568          /* Strip trailing \r\n */
02569          if (strlen(header_buf) < 2)
02570             continue;
02571          header_buf[strlen(header_buf) - 2] = '\0';
02572          if (ast_strlen_zero(header_buf))
02573             return process_message(s, &m) ? -1 : 0;
02574          else if (m.hdrcount < (AST_MAX_MANHEADERS - 1))
02575             m.headers[m.hdrcount++] = ast_strdupa(header_buf);
02576       } else {
02577          return res;
02578       }
02579    }
02580 }

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

Definition at line 1907 of file manager.c.

References fast_originate_helper::account, fast_originate_helper::app, fast_originate_helper::appdata, AST_CHANNEL_NAME, ast_channel_unlock, 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, EVENT_FLAG_CALL, fast_originate_helper::exten, fast_originate_helper::format, free, fast_originate_helper::idtext, manager_event(), ast_channel::name, fast_originate_helper::priority, S_OR, fast_originate_helper::tech, fast_originate_helper::timeout, ast_channel::uniqueid, and fast_originate_helper::vars.

Referenced by action_originate().

01908 {
01909    struct fast_originate_helper *in = data;
01910    int res;
01911    int reason = 0;
01912    struct ast_channel *chan = NULL;
01913    char requested_channel[AST_CHANNEL_NAME];
01914 
01915    if (!ast_strlen_zero(in->app)) {
01916       res = ast_pbx_outgoing_app(in->tech, in->format, in->data, in->timeout, in->app, in->appdata, &reason, 1, 
01917          S_OR(in->cid_num, NULL), 
01918          S_OR(in->cid_name, NULL),
01919          in->vars, in->account, &chan);
01920    } else {
01921       res = ast_pbx_outgoing_exten(in->tech, in->format, in->data, in->timeout, in->context, in->exten, in->priority, &reason, 1, 
01922          S_OR(in->cid_num, NULL), 
01923          S_OR(in->cid_name, NULL),
01924          in->vars, in->account, &chan);
01925    }
01926 
01927    if (!chan)
01928       snprintf(requested_channel, AST_CHANNEL_NAME, "%s/%s", in->tech, in->data);   
01929    /* Tell the manager what happened with the channel */
01930    manager_event(EVENT_FLAG_CALL, "OriginateResponse",
01931       "%s%s"
01932       "Response: %s\r\n"
01933       "Channel: %s\r\n"
01934       "Context: %s\r\n"
01935       "Exten: %s\r\n"
01936       "Reason: %d\r\n"
01937       "Uniqueid: %s\r\n"
01938       "CallerID: %s\r\n"      /* This parameter is deprecated and will be removed post-1.4 */
01939       "CallerIDNum: %s\r\n"
01940       "CallerIDName: %s\r\n",
01941       in->idtext, ast_strlen_zero(in->idtext) ? "" : "\r\n", res ? "Failure" : "Success", 
01942       chan ? chan->name : requested_channel, in->context, in->exten, reason, 
01943       chan ? chan->uniqueid : "<null>",
01944       S_OR(in->cid_num, "<unknown>"),
01945       S_OR(in->cid_num, "<unknown>"),
01946       S_OR(in->cid_name, "<unknown>")
01947       );
01948 
01949    /* Locked by ast_pbx_outgoing_exten or ast_pbx_outgoing_app */
01950    if (chan)
01951       ast_channel_unlock(chan);
01952    free(in);
01953    return NULL;
01954 }

static void free_session ( struct mansession_session s  )  [static]

Definition at line 815 of file manager.c.

References ast_mutex_destroy(), free, s, and unuse_eventqent().

Referenced by accept_thread(), and destroy_session().

00816 {
00817    struct eventqent *eqe;
00818    if (s->fd > -1)
00819       close(s->fd);
00820    if (s->outputstr)
00821       free(s->outputstr);
00822    ast_mutex_destroy(&s->__lock);
00823    while (s->eventq) {
00824       eqe = s->eventq;
00825       s->eventq = s->eventq->next;
00826       unuse_eventqent(eqe);
00827    }
00828    free(s);
00829 }

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

Definition at line 2461 of file manager.c.

References ast_channel::fds, and s.

Referenced by do_message(), and skinny_session().

02462 {
02463    /* output must have at least sizeof(s->inbuf) space */
02464    int res;
02465    int x;
02466    struct pollfd fds[1];
02467    int timeout = -1;
02468    time_t now;
02469    for (x = 1; x < s->inlen; x++) {
02470       if ((s->inbuf[x] == '\n') && (s->inbuf[x-1] == '\r')) {
02471          /* Copy output data up to and including \r\n */
02472          memcpy(output, s->inbuf, x + 1);
02473          /* Add trailing \0 */
02474          output[x+1] = '\0';
02475          /* Move remaining data back to the front */
02476          memmove(s->inbuf, s->inbuf + x + 1, s->inlen - x);
02477          s->inlen -= (x + 1);
02478          return 1;
02479       }
02480    } 
02481    if (s->inlen >= sizeof(s->inbuf) - 1) {
02482       ast_log(LOG_WARNING, "Dumping long line with no return from %s: %s\n", ast_inet_ntoa(s->sin.sin_addr), s->inbuf);
02483       s->inlen = 0;
02484    }
02485    fds[0].fd = s->fd;
02486    fds[0].events = POLLIN;
02487 
02488    do {
02489       /* calculate a timeout if we are not authenticated */
02490       if (!s->authenticated) {
02491          if(time(&now) == -1) {
02492             ast_log(LOG_ERROR, "error executing time(): %s\n", strerror(errno));
02493             return -1;
02494          }
02495 
02496          timeout = (authtimeout - (now - s->authstart)) * 1000;
02497          if (timeout < 0) {
02498             /* we have timed out */
02499             return 0;
02500          }
02501       }
02502 
02503       ast_mutex_lock(&s->__lock);
02504       if (s->pending_event) {
02505          s->pending_event = 0;
02506          ast_mutex_unlock(&s->__lock);
02507          return 0;
02508       }
02509       s->waiting_thread = pthread_self();
02510       ast_mutex_unlock(&s->__lock);
02511 
02512       res = ast_poll(fds, 1, timeout);
02513 
02514       ast_mutex_lock(&s->__lock);
02515       s->waiting_thread = AST_PTHREADT_NULL;
02516       ast_mutex_unlock(&s->__lock);
02517       if (res < 0) {
02518          if (errno == EINTR || errno == EAGAIN) {
02519             return 0;
02520          }
02521          ast_log(LOG_WARNING, "Select returned error: %s\n", strerror(errno));
02522          return -1;
02523       } else if (res > 0) {
02524          ast_mutex_lock(&s->__lock);
02525          res = read(s->fd, s->inbuf + s->inlen, sizeof(s->inbuf) - 1 - s->inlen);
02526          ast_mutex_unlock(&s->__lock);
02527          if (res < 1)
02528             return -1;
02529          break;
02530       } else {
02531          /* timeout */
02532          return 0;
02533       }
02534    } while(1);
02535    s->inlen += res;
02536    s->inbuf[s->inlen] = '\0';
02537    return 0;
02538 }

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

Definition at line 955 of file manager.c.

References ast_instring(), and perms.

00956 {
00957    int x = 0, ret = 0;
00958 
00959    if (!instr)
00960       return 0;
00961 
00962    for (x = 0; x < (sizeof(perms) / sizeof(perms[0])); x++) {
00963       if (ast_instring(instr, perms[x].label, ','))
00964          ret |= perms[x].num;
00965    }
00966    
00967    return ret;
00968 }

static int handle_showmanager ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 607 of file manager.c.

References ast_cli(), ast_get_manager_by_name_locked(), AST_LIST_LOCK, AST_LIST_UNLOCK, ast_manager_user::deny, ast_manager_user::displayconnects, ast_manager_user::permit, ast_manager_user::read, RESULT_SHOWUSAGE, RESULT_SUCCESS, ast_manager_user::secret, ast_manager_user::username, and ast_manager_user::write.

00608 {
00609    struct ast_manager_user *user = NULL;
00610 
00611    if (argc != 4)
00612       return RESULT_SHOWUSAGE;
00613 
00614    AST_LIST_LOCK(&users);
00615 
00616    if (!(user = ast_get_manager_by_name_locked(argv[3]))) {
00617       ast_cli(fd, "There is no manager called %s\n", argv[3]);
00618       AST_LIST_UNLOCK(&users);
00619       return -1;
00620    }
00621 
00622    ast_cli(fd,"\n");
00623    ast_cli(fd,
00624       "       username: %s\n"
00625       "         secret: %s\n"
00626       "           deny: %s\n"
00627       "         permit: %s\n"
00628       "           read: %s\n"
00629       "          write: %s\n"
00630       "displayconnects: %s\n",
00631       (user->username ? user->username : "(N/A)"),
00632       (user->secret ? "<Set>" : "(N/A)"),
00633       (user->deny ? user->deny : "(N/A)"),
00634       (user->permit ? user->permit : "(N/A)"),
00635       (user->read ? user->read : "(N/A)"),
00636       (user->write ? user->write : "(N/A)"),
00637       (user->displayconnects ? "yes" : "no"));
00638 
00639    AST_LIST_UNLOCK(&users);
00640 
00641    return RESULT_SUCCESS;
00642 }

static int handle_showmanagers ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 645 of file manager.c.

References ast_cli(), AST_LIST_EMPTY, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, mansession_session::list, RESULT_SHOWUSAGE, RESULT_SUCCESS, and ast_manager_user::username.

00646 {
00647    struct ast_manager_user *user = NULL;
00648    int count_amu = 0;
00649 
00650    if (argc != 3)
00651       return RESULT_SHOWUSAGE;
00652 
00653    AST_LIST_LOCK(&users);
00654 
00655    /* If there are no users, print out something along those lines */
00656    if (AST_LIST_EMPTY(&users)) {
00657       ast_cli(fd, "There are no manager users.\n");
00658       AST_LIST_UNLOCK(&users);
00659       return RESULT_SUCCESS;
00660    }
00661 
00662    ast_cli(fd, "\nusername\n--------\n");
00663 
00664    AST_LIST_TRAVERSE(&users, user, list) {
00665       ast_cli(fd, "%s\n", user->username);
00666       count_amu++;
00667    }
00668 
00669    AST_LIST_UNLOCK(&users);
00670 
00671    ast_cli(fd,"-------------------\n");
00672    ast_cli(fd,"%d manager users configured.\n", count_amu);
00673 
00674    return RESULT_SUCCESS;
00675 }

static int handle_showmancmd ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 585 of file manager.c.

References manager_action::action, actionlock, ast_cli(), ast_rwlock_rdlock(), manager_action::authority, authority_to_str(), manager_action::description, first_action, manager_action::next, RESULT_SHOWUSAGE, and manager_action::synopsis.

00586 {
00587    struct manager_action *cur;
00588    char authority[80];
00589    int num;
00590 
00591    if (argc != 4)
00592       return RESULT_SHOWUSAGE;
00593 
00594    ast_rwlock_rdlock(&actionlock);
00595    for (cur = first_action; cur; cur = cur->next) { /* Walk the list of actions */
00596       for (num = 3; num < argc; num++) {
00597          if (!strcasecmp(cur->action, argv[num])) {
00598             ast_cli(fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n", cur->action, cur->synopsis, authority_to_str(cur->authority, authority, sizeof(authority) -1), cur->description ? cur->description : "");
00599          }
00600       }
00601    }
00602    ast_rwlock_unlock(&actionlock);
00603 
00604    return RESULT_SUCCESS;
00605 }

static int handle_showmancmds ( int  fd,
int  argc,
char *  argv[] 
) [static]

CLI command Should change to "manager show commands".

Definition at line 680 of file manager.c.

References manager_action::action, actionlock, ast_cli(), ast_rwlock_rdlock(), ast_rwlock_unlock(), manager_action::authority, authority_to_str(), first_action, format, manager_action::next, RESULT_SUCCESS, and manager_action::synopsis.

00681 {
00682    struct manager_action *cur;
00683    char authority[80];
00684    char *format = "  %-15.15s  %-15.15s  %-55.55s\n";
00685 
00686    ast_cli(fd, format, "Action", "Privilege", "Synopsis");
00687    ast_cli(fd, format, "------", "---------", "--------");
00688    
00689    ast_rwlock_rdlock(&actionlock);
00690    for (cur = first_action; cur; cur = cur->next) /* Walk the list of actions */
00691       ast_cli(fd, format, cur->action, authority_to_str(cur->authority, authority, sizeof(authority) -1), cur->synopsis);
00692    ast_rwlock_unlock(&actionlock);
00693    
00694    return RESULT_SUCCESS;
00695 }

static int handle_showmanconn ( int  fd,
int  argc,
char *  argv[] 
) [static]

CLI command show manager connected.

Definition at line 699 of file manager.c.

References ast_cli(), ast_inet_ntoa(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, format, mansession_session::list, RESULT_SUCCESS, and s.

00700 {
00701    struct mansession_session *s;
00702    char wtout[32];
00703    char *format = "  %-15.15s  %-15.15s  %-15.15s\n";
00704 
00705    ast_cli(fd, format, "Username", "IP Address", "Timeout");
00706    
00707    AST_LIST_LOCK(&sessions);
00708    AST_LIST_TRAVERSE(&sessions, s, list) {
00709       memset(wtout, 0, sizeof(wtout));
00710       snprintf(wtout, sizeof(wtout)-1, "%d", s->writetimeout);
00711       ast_cli(fd, format,s->username, ast_inet_ntoa(s->sin.sin_addr), wtout);
00712    }
00713    AST_LIST_UNLOCK(&sessions);
00714 
00715    return RESULT_SUCCESS;
00716 }

static int handle_showmaneventq ( int  fd,
int  argc,
char *  argv[] 
) [static]

CLI command show manager eventq.

Definition at line 720 of file manager.c.

References ast_cli(), AST_LIST_LOCK, AST_LIST_UNLOCK, master_eventq, RESULT_SUCCESS, and s.

00721 {
00722    struct eventqent *s;
00723 
00724    AST_LIST_LOCK(&sessions);
00725    for (s = master_eventq; s; s = s->next) {
00726       ast_cli(fd, "Usecount: %d\n",s->usecount);
00727       ast_cli(fd, "Category: %d\n", s->category);
00728       ast_cli(fd, "Event:\n%s", s->eventdata);
00729    }
00730    AST_LIST_UNLOCK(&sessions);
00731 
00732    return RESULT_SUCCESS;
00733 }

static void handle_updates ( struct mansession s,
const struct message m,
struct ast_config cfg 
) [static]

Definition at line 1230 of file manager.c.

References ast_category_append(), ast_category_delete(), ast_category_get(), ast_category_new(), ast_category_rename(), ast_strlen_zero(), ast_variable_append(), ast_variable_delete(), ast_variable_new(), ast_variable_update(), astman_get_header(), match(), ast_variable::object, ast_variable::value, and var.

Referenced by action_updateconfig().

01231 {
01232    int x;
01233    char hdr[40];
01234    const char *action, *cat, *var, *value, *match;
01235    struct ast_category *category;
01236    struct ast_variable *v;
01237    
01238    for (x=0;x<100000;x++) {
01239       unsigned int object = 0;
01240 
01241       snprintf(hdr, sizeof(hdr), "Action-%06d", x);
01242       action = astman_get_header(m, hdr);
01243       if (ast_strlen_zero(action))
01244          break;
01245       snprintf(hdr, sizeof(hdr), "Cat-%06d", x);
01246       cat = astman_get_header(m, hdr);
01247       snprintf(hdr, sizeof(hdr), "Var-%06d", x);
01248       var = astman_get_header(m, hdr);
01249       snprintf(hdr, sizeof(hdr), "Value-%06d", x);
01250       value = astman_get_header(m, hdr);
01251       if (!ast_strlen_zero(value) && *value == '>') {
01252          object = 1;
01253          value++;
01254       }
01255       snprintf(hdr, sizeof(hdr), "Match-%06d", x);
01256       match = astman_get_header(m, hdr);
01257       if (!strcasecmp(action, "newcat")) {
01258          if (!ast_strlen_zero(cat)) {
01259             category = ast_category_new(cat);
01260             if (category) {
01261                ast_category_append(cfg, category);
01262             }
01263          }
01264       } else if (!strcasecmp(action, "renamecat")) {
01265          if (!ast_strlen_zero(cat) && !ast_strlen_zero(value)) {
01266             category = ast_category_get(cfg, cat);
01267             if (category) 
01268                ast_category_rename(category, value);
01269          }
01270       } else if (!strcasecmp(action, "delcat")) {
01271          if (!ast_strlen_zero(cat))
01272             ast_category_delete(cfg, (char *) cat);
01273       } else if (!strcasecmp(action, "update")) {
01274          if (!ast_strlen_zero(cat) && !ast_strlen_zero(var) && (category = ast_category_get(cfg, cat)))
01275             ast_variable_update(category, var, value, match, object);
01276       } else if (!strcasecmp(action, "delete")) {
01277          if (!ast_strlen_zero(cat) && !ast_strlen_zero(var) && (category = ast_category_get(cfg, cat)))
01278             ast_variable_delete(category, (char *) var, (char *) match);
01279       } else if (!strcasecmp(action, "append")) {
01280          if (!ast_strlen_zero(cat) && !ast_strlen_zero(var) && 
01281             (category = ast_category_get(cfg, cat)) && 
01282             (v = ast_variable_new(var, value))){
01283             if (object || (match && !strcasecmp(match, "object")))
01284                v->object = 1;
01285             ast_variable_append(category, v);
01286          }
01287       }
01288    }
01289 }

static char* html_translate ( char *  in  )  [static]

Definition at line 496 of file manager.c.

References ast_build_string(), ast_malloc, len(), and var.

00497 {
00498    int x;
00499    int colons = 0;
00500    int breaks = 0;
00501    size_t len;
00502    int count = 1;
00503    char *tmp, *var, *val, *out;
00504 
00505    for (x=0; in[x]; x++) {
00506       if (in[x] == ':')
00507          colons++;
00508       if (in[x] == '\n')
00509          breaks++;
00510    }
00511    len = strlen(in) + colons * 40 + breaks * 40; /* <tr><td></td><td></td></tr>, "<tr><td colspan=\"2\"><hr></td></tr> */
00512    out = ast_malloc(len);
00513    if (!out)
00514       return 0;
00515    tmp = out;
00516    while (*in) {
00517       var = in;
00518       while (*in && (*in >= 32))
00519          in++;
00520       if (*in) {
00521          if ((count % 4) == 0){
00522             ast_build_string(&tmp, &len, "<tr><td colspan=\"2\"><hr></td></tr>\r\n");
00523          }
00524          count = 0;
00525          while (*in && (*in < 32)) {
00526             *in = '\0';
00527             in++;
00528             count++;
00529          }
00530          val = strchr(var, ':');
00531          if (val) {
00532             *val = '\0';
00533             val++;
00534             if (*val == ' ')
00535                val++;
00536             ast_build_string(&tmp, &len, "<tr><td>%s</td><td>%s</td></tr>\r\n", var, val);
00537          }
00538       }
00539    }
00540    return out;
00541 }

int manager_event ( int  category,
const char *  event,
const char *  contents,
  ... 
)

manager_event: Send AMI event to client

Parameters:
category Event category, matches manager authorization
event Event name
contents Contents of event

Definition at line 2761 of file manager.c.

References append_event(), ast_dynamic_str_thread_append(), ast_dynamic_str_thread_append_va, ast_dynamic_str_thread_get(), ast_dynamic_str_thread_set(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_mutex_lock(), ast_mutex_unlock(), AST_PTHREADT_NULL, ast_tvnow(), authority_to_str(), manager_event_buf, MANAGER_EVENT_BUF_INITSIZE, num_sessions, s, ast_dynamic_str::str, and timestampevents.

Referenced by __expire_registry(), __iax2_poke_noanswer(), __login_exec(), action_agent_callback_login(), add_to_queue(), agent_logoff_maintenance(), aji_log_hook(), ast_change_name(), ast_channel_bridge(), ast_do_masquerade(), ast_hangup(), ast_log(), ast_setstate(), builtin_automonitor(), change_hold_state(), conf_run(), dahdi_handle_event(), dahdi_r2_on_hardware_alarm(), expire_register(), fast_originate(), handle_alarms(), handle_init_event(), handle_response_peerpoke(), handle_response_register(), iax2_ack_registry(), join_queue(), leave_queue(), main(), manager_log(), manager_state_cb(), notify_new_message(), park_call_full(), park_exec(), parse_register_contact(), pbx_extension_helper(), post_manager_event(), quit_handler(), realtime_exec(), record_abandoned(), register_verify(), reload_logger(), reload_manager(), remove_from_queue(), report_new_callerid(), ring_entry(), send_talking_event(), senddialevent(), set_member_paused(), sip_poke_noanswer(), sip_reg_timeout(), socket_process(), ss_thread(), try_calling(), update_registry(), update_status(), and vm_execmain().

02762 {
02763    struct mansession_session *s;
02764    char auth[80];
02765    va_list ap;
02766    struct timeval now;
02767    struct ast_dynamic_str *buf;
02768 
02769    /* Abort if there aren't any manager sessions */
02770    if (!num_sessions)
02771       return 0;
02772 
02773    if (!(buf = ast_dynamic_str_thread_get(&manager_event_buf, MANAGER_EVENT_BUF_INITSIZE)))
02774       return -1;
02775 
02776    ast_dynamic_str_thread_set(&buf, 0, &manager_event_buf,
02777          "Event: %s\r\nPrivilege: %s\r\n",
02778           event, authority_to_str(category, auth, sizeof(auth)));
02779 
02780    if (timestampevents) {
02781       now = ast_tvnow();
02782       ast_dynamic_str_thread_append(&buf, 0, &manager_event_buf,
02783             "Timestamp: %ld.%06lu\r\n",
02784              (long) now.tv_sec, (unsigned long) now.tv_usec);
02785    }
02786 
02787    va_start(ap, fmt);
02788    ast_dynamic_str_thread_append_va(&buf, 0, &manager_event_buf, fmt, ap);
02789    va_end(ap);
02790    
02791    ast_dynamic_str_thread_append(&buf, 0, &manager_event_buf, "\r\n");  
02792    
02793    /* Append event to master list and wake up any sleeping sessions */
02794    AST_LIST_LOCK(&sessions);
02795    append_event(buf->str, category);
02796    AST_LIST_TRAVERSE(&sessions, s, list) {
02797       ast_mutex_lock(&s->__lock);
02798       if (s->waiting_thread != AST_PTHREADT_NULL)
02799          pthread_kill(s->waiting_thread, SIGURG);
02800       else
02801          /* We have an event to process, but the mansession is
02802           * not waiting for it. We still need to indicate that there
02803           * is an event waiting so that get_input processes the pending
02804           * event instead of polling.
02805           */
02806          s->pending_event = 1;
02807       ast_mutex_unlock(&s->__lock);
02808    }
02809    AST_LIST_UNLOCK(&sessions);
02810 
02811    return 0;
02812 }

static void manager_event_buf_init ( void   )  [static]

Definition at line 132 of file manager.c.

00138 {

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

Definition at line 2840 of file manager.c.

References EVENT_FLAG_CALL, and manager_event().

Referenced by init_manager().

02841 {
02842    /* Notify managers of change */
02843    manager_event(EVENT_FLAG_CALL, "ExtensionStatus", "Exten: %s\r\nContext: %s\r\nStatus: %d\r\n", exten, context, state);
02844    return 0;
02845 }

static int process_events ( struct mansession s  )  [static]

Definition at line 2234 of file manager.c.

References ast_calloc, ast_carefulwrite(), ast_dynamic_str_append(), ast_mutex_lock(), ast_mutex_unlock(), eventqent::category, eventqent::eventdata, master_eventq, s, and unuse_eventqent().

Referenced by do_message().

02235 {
02236    struct eventqent *eqe;
02237    int ret = 0;
02238    ast_mutex_lock(&s->session->__lock);
02239    if (!s->session->eventq)
02240       s->session->eventq = master_eventq;
02241    while(s->session->eventq->next) {
02242       eqe = s->session->eventq->next;
02243       if ((s->session->authenticated && (s->session->readperm & eqe->category) == eqe->category) &&
02244                ((s->session->send_events & eqe->category) == eqe->category)) {
02245          if (s->fd > -1) {
02246             if (!ret && ast_carefulwrite(s->fd, eqe->eventdata, strlen(eqe->eventdata), s->session->writetimeout) < 0)
02247                ret = -1;
02248          } else if (!s->session->outputstr && !(s->session->outputstr = ast_calloc(1, sizeof(*s->session->outputstr)))) 
02249             ret = -1;
02250          else 
02251             ast_dynamic_str_append(&s->session->outputstr, 0, "%s", eqe->eventdata);
02252       }
02253       unuse_eventqent(s->session->eventq);
02254       s->session->eventq = eqe;
02255    }
02256    ast_mutex_unlock(&s->session->__lock);
02257    return ret;
02258 }

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

Definition at line 2370 of file manager.c.

References manager_action::action, actionlock, ast_atomic_fetchadd_int(), ast_copy_string(), ast_inet_ntoa(), ast_log(), AST_OPT_FLAG_FULLY_BOOTED, ast_opt_send_fullybooted, ast_options, ast_random(), ast_rwlock_rdlock(), ast_rwlock_unlock(), ast_strlen_zero(), ast_test_flag, ast_verbose(), astman_append(), astman_get_header(), astman_send_ack(), astman_send_error(), authenticate(), manager_action::authority, authority_to_str(), displayconnects, EVENT_FLAG_SYSTEM, first_action, manager_action::func, LOG_DEBUG, LOG_EVENT, manager_action::next, option_debug, option_verbose, s, unauth_sessions, and VERBOSE_PREFIX_2.

Referenced by do_message().

02371 {
02372    char action[80] = "";
02373    struct manager_action *tmp;
02374    const char *id = astman_get_header(m,"ActionID");
02375    char idText[256] = "";
02376    int ret = 0;
02377 
02378    ast_copy_string(action, astman_get_header(m, "Action"), sizeof(action));
02379    if (option_debug)
02380       ast_log( LOG_DEBUG, "Manager received command '%s'\n", action );
02381 
02382    if (ast_strlen_zero(action)) {
02383       astman_send_error(s, m, "Missing action in request");
02384       return 0;
02385    }
02386    if (!ast_strlen_zero(id)) {
02387       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
02388    }
02389    if (!s->session->authenticated) {
02390       if (!strcasecmp(action, "Challenge")) {
02391          const char *authtype = astman_get_header(m, "AuthType");
02392 
02393          if (!strcasecmp(authtype, "MD5")) {
02394             if (ast_strlen_zero(s->session->challenge))
02395                snprintf(s->session->challenge, sizeof(s->session->challenge), "%ld", ast_random());
02396             astman_append(s, "Response: Success\r\n"
02397                   "%s"
02398                   "Challenge: %s\r\n\r\n",
02399                   idText, s->session->challenge);
02400             return 0;
02401          } else {
02402             astman_send_error(s, m, "Must specify AuthType");
02403             return 0;
02404          }
02405       } else if (!strcasecmp(action, "Login")) {
02406          if (authenticate(s, m)) {
02407             sleep(1);
02408             astman_send_error(s, m, "Authentication failed");
02409             return -1;
02410          } else {
02411             s->session->authenticated = 1;
02412             ast_atomic_fetchadd_int(&unauth_sessions, -1);
02413             if (option_verbose > 1) {
02414                if (displayconnects) {
02415                   ast_verbose(VERBOSE_PREFIX_2 "%sManager '%s' logged on from %s\n", 
02416                      (s->session->sessiontimeout ? "HTTP " : ""), s->session->username, ast_inet_ntoa(s->session->sin.sin_addr));
02417                }
02418             }
02419             ast_log(LOG_EVENT, "%sManager '%s' logged on from %s\n", 
02420                (s->session->sessiontimeout ? "HTTP " : ""), s->session->username, ast_inet_ntoa(s->session->sin.sin_addr));
02421             astman_send_ack(s, m, "Authentication accepted");
02422             if (ast_opt_send_fullybooted && ast_test_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED)) {
02423                char auth[80];
02424                   authority_to_str(EVENT_FLAG_SYSTEM, auth, sizeof(auth));
02425                astman_append(s, "Event: FullyBooted\r\n"
02426                   "Privilege: %s\r\n"
02427                   "Status: Fully Booted\r\n\r\n",
02428                   auth);
02429             }
02430          }
02431       } else if (!strcasecmp(action, "Logoff")) {
02432          astman_send_ack(s, m, "See ya");
02433          return -1;
02434       } else
02435          astman_send_error(s, m, "Authentication Required");
02436    } else {
02437       if (!strcasecmp(action, "Login"))
02438          astman_send_ack(s, m, "Already logged in");
02439       else {
02440          ast_rwlock_rdlock(&actionlock);
02441          for (tmp = first_action; tmp; tmp = tmp->next) {      
02442             if (strcasecmp(action, tmp->action))
02443                continue;
02444             if ((s->session->writeperm & tmp->authority) == tmp->authority) {
02445                if (tmp->func(s, m))
02446                   ret = -1;
02447             } else
02448                astman_send_error(s, m, "Permission denied");
02449             break;
02450          }
02451          ast_rwlock_unlock(&actionlock);
02452          if (!tmp)
02453             astman_send_error(s, m, "Invalid/unknown command");
02454       }
02455    }
02456    if (ret)
02457       return ret;
02458    return process_events(s);
02459 }

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

Definition at line 2582 of file manager.c.

References ast_inet_ntoa(), ast_log(), ast_verbose(), astman_append(), mansession_session::authenticated, displayconnects, do_message(), mansession_session::fd, LOG_EVENT, option_verbose, s, mansession_session::sin, mansession_session::username, and VERBOSE_PREFIX_2.

Referenced by accept_thread().

02583 {
02584    struct mansession_session *session = data;
02585    int res;
02586    struct mansession s = { .session = session, .fd = session->fd };
02587 
02588    astman_append(&s, "Asterisk Call Manager/1.0\r\n");
02589    for (;;) {
02590       if ((res = do_message(&s)) < 0)
02591          break;
02592    }
02593    if (session->authenticated) {
02594       if (option_verbose > 1) {
02595          if (displayconnects) 
02596             ast_verbose(VERBOSE_PREFIX_2 "Manager '%s' logged off from %s\n", session->username, ast_inet_ntoa(session->sin.sin_addr));
02597       }
02598       ast_log(LOG_EVENT, "Manager '%s' logged off from %s\n", session->username, ast_inet_ntoa(session->sin.sin_addr));
02599    } else {
02600       ast_atomic_fetchadd_int(&unauth_sessions, -1);
02601       if (option_verbose > 1) {
02602          if (displayconnects)
02603             ast_verbose(VERBOSE_PREFIX_2 "Connect attempt from '%s' unable to authenticate\n", ast_inet_ntoa(session->sin.sin_addr));
02604       }
02605       ast_log(LOG_EVENT, "Failed attempt from %s\n", ast_inet_ntoa(session->sin.sin_addr));
02606    }
02607 
02608    /* At one point there was a usleep(1) here intended to allow the call
02609     * to ast_pthread_create_background() to complete before this thread
02610     * exited. This should no longer be necessary as the thread id is no
02611     * longer stored in the mansessions_session.
02612     */
02613 
02614    destroy_session(session);
02615    return NULL;
02616 }

static int set_eventmask ( struct mansession_session 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 1018 of file manager.c.

References ast_mutex_lock(), ast_mutex_unlock(), s, and strings_to_mask().

Referenced by action_events().

01019 {
01020    int maskint = strings_to_mask(eventmask);
01021 
01022    ast_mutex_lock(&s->__lock);
01023    if (maskint >= 0) 
01024       s->send_events = maskint;
01025    ast_mutex_unlock(&s->__lock);
01026    
01027    return maskint;
01028 }

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

Definition at line 987 of file manager.c.

References ast_false(), ast_instring(), ast_is_number(), ast_strlen_zero(), ast_true(), and perms.

Referenced by set_eventmask().

00988 {
00989    int x, ret = -1;
00990    
00991    x = ast_is_number(string);
00992 
00993    if (x)
00994       ret = x;
00995    else if (ast_strlen_zero(string))
00996       ret = -1;
00997    else if (ast_false(string))
00998       ret = 0;
00999    else if (ast_true(string)) {
01000       ret = 0;
01001       for (x=0; x<sizeof(perms) / sizeof(perms[0]); x++)
01002          ret |= perms[x].num;    
01003    } else {
01004       ret = 0;
01005       for (x=0; x<sizeof(perms) / sizeof(perms[0]); x++) {
01006          if (ast_instring(string, perms[x].label, ',')) 
01007             ret |= perms[x].num;    
01008       }
01009    }
01010 
01011    return ret;
01012 }

static void unuse_eventqent ( struct eventqent e  )  [static]

Definition at line 808 of file manager.c.

References ast_atomic_dec_and_test(), eventqent::next, mansession_session::next, and eventqent::usecount.

Referenced by action_waitevent(), free_session(), and process_events().

00809 {
00810    struct eventqent *next = e->next;
00811    if (ast_atomic_dec_and_test(&e->usecount) && next)
00812       pthread_kill(t, SIGURG);
00813 }

static int variable_count_cmp_fn ( void *  obj,
void *  vstr,
int  flags 
) [static]

Definition at line 386 of file manager.c.

References variable_count::varname.

Referenced by xml_translate().

00387 {
00388    /* Due to the simplicity of struct variable_count, it makes no difference
00389     * if you pass in objects or strings, the same operation applies. This is
00390     * due to the fact that the hash occurs on the first element, which means
00391     * the address of both the struct and the string are exactly the same. */
00392    struct variable_count *vc = obj;
00393    char *str = vstr;
00394    return !strcmp(vc->varname, str) ? CMP_MATCH | CMP_STOP : 0;
00395 }

static int variable_count_hash_fn ( const void *  vvc,
const int  flags 
) [static]

Definition at line 374 of file manager.c.

References compress_char(), and variable_count::varname.

Referenced by xml_translate().

00375 {
00376    const struct variable_count *vc = vvc;
00377    int res = 0, i;
00378    for (i = 0; i < 5; i++) {
00379       if (vc->varname[i] == '\0')
00380          break;
00381       res += compress_char(vc->varname[i]) << (i * 6);
00382    }
00383    return res;
00384 }

static void xml_copy_escape ( char **  dst,
size_t *  maxlen,
const char *  src,
int  lower 
) [static]

Definition at line 319 of file manager.c.

Referenced by xml_translate().

00320 {
00321    while (*src && (*maxlen > 6)) {
00322       switch (*src) {
00323       case '<':
00324          strcpy(*dst, "&lt;");
00325          (*dst) += 4;
00326          *maxlen -= 4;
00327          break;
00328       case '>':
00329          strcpy(*dst, "&gt;");
00330          (*dst) += 4;
00331          *maxlen -= 4;
00332          break;
00333       case '\"':
00334          strcpy(*dst, "&quot;");
00335          (*dst) += 6;
00336          *maxlen -= 6;
00337          break;
00338       case '\'':
00339          strcpy(*dst, "&apos;");
00340          (*dst) += 6;
00341          *maxlen -= 6;
00342          break;
00343       case '&':
00344          strcpy(*dst, "&amp;");
00345          (*dst) += 5;
00346          *maxlen -= 5;
00347          break;      
00348       default:
00349          *(*dst)++ = lower ? tolower(*src) : *src;
00350          (*maxlen)--;
00351       }
00352       src++;
00353    }
00354 }

static char* xml_translate ( char *  in,
struct ast_variable vars 
) [static]

Definition at line 397 of file manager.c.

References ao2_alloc(), ao2_container_alloc(), ao2_find(), ao2_ref(), ast_build_string(), ast_malloc, variable_count::count, len(), ast_variable::name, ast_variable::next, ast_variable::value, var, variable_count_cmp_fn(), variable_count_hash_fn(), and xml_copy_escape().

00398 {
00399    struct ast_variable *v;
00400    char *dest = NULL;
00401    char *out, *tmp, *var, *val;
00402    char *objtype = NULL;
00403    int colons = 0;
00404    int breaks = 0;
00405    size_t len;
00406    int count = 1;
00407    int escaped = 0;
00408    int inobj = 0;
00409    int x;
00410    struct variable_count *vc = NULL;
00411    struct ao2_container *vco = NULL;
00412 
00413    for (v = vars; v; v = v->next) {
00414       if (!dest && !strcasecmp(v->name, "ajaxdest"))
00415          dest = v->value;
00416       else if (!objtype && !strcasecmp(v->name, "ajaxobjtype")) 
00417          objtype = v->value;
00418    }
00419    if (!dest)
00420       dest = "unknown";
00421    if (!objtype)
00422       objtype = "generic";
00423    for (x = 0; in[x]; x++) {
00424       if (in[x] == ':')
00425          colons++;
00426       else if (in[x] == '\n')
00427          breaks++;
00428       else if (strchr("&\"<>\'", in[x]))
00429          escaped++;
00430    }
00431    len = (size_t) (strlen(in) + colons * 5 + breaks * (40 + strlen(dest) + strlen(objtype)) + escaped * 10); /* foo="bar", "<response type=\"object\" id=\"dest\"", "&amp;" */
00432    out = ast_malloc(len);
00433    if (!out)
00434       return 0;
00435    tmp = out;
00436    while (*in) {
00437       var = in;
00438       while (*in && (*in >= 32))
00439          in++;
00440       if (*in) {
00441          if ((count > 3) && inobj) {
00442             ast_build_string(&tmp, &len, " /></response>\n");
00443             inobj = 0;
00444 
00445             /* Entity is closed, so close out the name cache */
00446             ao2_ref(vco, -1);
00447             vco = NULL;
00448          }
00449          count = 0;
00450          while (*in && (*in < 32)) {
00451             *in = '\0';
00452             in++;
00453             count++;
00454          }
00455          val = strchr(var, ':');
00456          if (val) {
00457             *val = '\0';
00458             val++;
00459             if (*val == ' ')
00460                val++;
00461             if (!inobj) {
00462                vco = ao2_container_alloc(37, variable_count_hash_fn, variable_count_cmp_fn);
00463                ast_build_string(&tmp, &len, "<response type='object' id='%s'><%s", dest, objtype);
00464                inobj = 1;
00465             }
00466 
00467             /* Check if the var has been used already */
00468             if ((vc = ao2_find(vco, var, 0)))
00469                vc->count++;
00470             else {
00471                /* Create a new entry for this one */
00472                vc = ao2_alloc(sizeof(*vc), NULL);
00473                vc->varname = var;
00474                vc->count = 1;
00475                ao2_link(vco, vc);
00476             }
00477 
00478             ast_build_string(&tmp, &len, " ");
00479             xml_copy_escape(&tmp, &len, var, 1);
00480             if (vc->count > 1)
00481                ast_build_string(&tmp, &len, "-%d", vc->count);
00482             ast_build_string(&tmp, &len, "='");
00483             xml_copy_escape(&tmp, &len, val, 0);
00484             ast_build_string(&tmp, &len, "'");
00485             ao2_ref(vc, -1);
00486          }
00487       }
00488    }
00489    if (inobj)
00490       ast_build_string(&tmp, &len, " /></response>\n");
00491    if (vco)
00492       ao2_ref(vco, -1);
00493    return out;
00494 }


Variable Documentation

ast_rwlock_t actionlock = PTHREAD_RWLOCK_INITIALIZER [static]

Definition at line 266 of file manager.c.

Referenced by ast_manager_register_struct(), ast_manager_unregister(), complete_show_mancmd(), handle_showmancmd(), handle_showmancmds(), and process_message().

int asock = -1 [static]

Definition at line 116 of file manager.c.

Referenced by accept_thread(), and init_manager().

struct ast_threadstorage astman_append_buf = { .once = PTHREAD_ONCE_INIT , .key_init = astman_append_buf_init , } [static]

Definition at line 135 of file manager.c.

Referenced by astman_append().

int authlimit [static]

Definition at line 122 of file manager.c.

Referenced by accept_thread(), and init_manager().

int authtimeout [static]

Definition at line 121 of file manager.c.

Referenced by do_message(), and init_manager().

int block_sockets [static]

Definition at line 125 of file manager.c.

Referenced by accept_thread(), and init_manager().

int broken_events_action [static]

Definition at line 120 of file manager.c.

Referenced by action_events(), and init_manager().

struct ast_cli_entry cli_manager[] [static]

Definition at line 782 of file manager.c.

Referenced by init_manager().

struct ast_cli_entry cli_show_manager_command_deprecated [static]

Initial value:

 {
   { "show", "manager", "command", NULL },
   handle_showmancmd, NULL,
   NULL, complete_show_mancmd }

Definition at line 762 of file manager.c.

struct ast_cli_entry cli_show_manager_commands_deprecated [static]

Initial value:

 {
   { "show", "manager", "commands", NULL },
   handle_showmancmds, NULL,
   NULL }

Definition at line 767 of file manager.c.

struct ast_cli_entry cli_show_manager_connected_deprecated [static]

Initial value:

 {
   { "show", "manager", "connected", NULL },
   handle_showmanconn, NULL,
   NULL }

Definition at line 772 of file manager.c.

struct ast_cli_entry cli_show_manager_eventq_deprecated [static]

Initial value:

 {
   { "show", "manager", "eventq", NULL },
   handle_showmaneventq, NULL,
   NULL }

Definition at line 777 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 109 of file manager.c.

Referenced by init_manager().

const int DEFAULT_AUTHTIMEOUT = 30 [static]

Default setting for authtimeout

Definition at line 108 of file manager.c.

Referenced by init_manager().

const int DEFAULT_BLOCKSOCKETS = 0 [static]

Default setting for block-sockets

Definition at line 103 of file manager.c.

Referenced by init_manager().

const int DEFAULT_BROKENEVENTSACTION = 0 [static]

Default setting for brokeneventsaction

Definition at line 107 of file manager.c.

Referenced by init_manager().

const int DEFAULT_DISPLAYCONNECTS = 1 [static]

Default setting for displaying manager connections

Definition at line 104 of file manager.c.

Referenced by init_manager().

const int DEFAULT_ENABLED = 0 [static]

Default setting for manager to be enabled

Definition at line 101 of file manager.c.

const int DEFAULT_HTTPTIMEOUT = 60 [static]

Default manager http timeout

Definition at line 106 of file manager.c.

Referenced by init_manager().

const int DEFAULT_TIMESTAMPEVENTS = 0 [static]

Default setting for timestampevents

Definition at line 105 of file manager.c.

Referenced by init_manager().

const int DEFAULT_WEBENABLED = 0 [static]

Default setting for the web interface to be enabled

Definition at line 102 of file manager.c.

Referenced by init_manager().

int displayconnects [static]

Definition at line 117 of file manager.c.

Referenced by accept_thread(), init_manager(), process_message(), and session_do().

struct manager_action* first_action [static]

Definition at line 265 of file manager.c.

Referenced by action_listcommands(), ast_manager_register_struct(), ast_manager_unregister(), complete_show_mancmd(), handle_showmancmd(), handle_showmancmds(), and process_message().

int httptimeout [static]

Definition at line 119 of file manager.c.

Referenced by init_manager().

int manager_enabled = 0 [static]

Definition at line 112 of file manager.c.

Referenced by init_manager().

struct ast_threadstorage manager_event_buf = { .once = PTHREAD_ONCE_INIT , .key_init = manager_event_buf_init , } [static]

Definition at line 132 of file manager.c.

Referenced by manager_event().

char mandescr_command[] [static]

Initial value:

 
"Description: Run a CLI command.\n"
"Variables: (Names marked with * are required)\n"
"  *Command: Asterisk CLI command to run\n"
"  ActionID: Optional Action id for message matching.\n"

Definition at line 1848 of file manager.c.

Referenced by init_manager().

char mandescr_coresettings[] [static]

Initial value:

"Description: Query for Core PBX settings.\n"
"Variables: (Names marked with * are optional)\n"
"       *ActionID: ActionID of this transaction\n"

Definition at line 2290 of file manager.c.

char mandescr_corestatus[] [static]

Initial value:

"Description: Query for Core PBX status.\n"
"Variables: (Names marked with * are optional)\n"
"       *ActionID: ActionID of this transaction\n"

Definition at line 2334 of file manager.c.

char mandescr_events[] [static]

Definition at line 1456 of file manager.c.

Referenced by init_manager().

char mandescr_extensionstate[] [static]

Definition at line 2162 of file manager.c.

Referenced by init_manager().

char mandescr_getconfig[] [static]

Initial value:

"Description: A 'GetConfig' action will dump the contents of a configuration\n"
"file by category and contents.\n"
"Variables:\n"
"   Filename: Configuration filename (e.g. foo.conf)\n"

Definition at line 1187 of file manager.c.

Referenced by init_manager().

char mandescr_getvar[] [static]

Definition at line 1577 of file manager.c.

Referenced by init_manager().

char mandescr_hangup[] [static]

Initial value:

 
"Description: Hangup a channel\n"
"Variables: \n"
"  Channel: The channel name to be hungup\n"

Definition at line 1506 of file manager.c.

Referenced by init_manager().

char mandescr_listcommands[] [static]

Initial value:

 
"Description: Returns the action name and synopsis for every\n"
"  action that is available to the user\n"
"Variables: NONE\n"

Definition at line 1431 of file manager.c.

Referenced by init_manager().

char mandescr_logoff[] [static]

Initial value:

 
"Description: Logoff this manager session\n"
"Variables: NONE\n"

Definition at line 1496 of file manager.c.

Referenced by init_manager().

char mandescr_mailboxcount[] [static]

Definition at line 2126 of file manager.c.

Referenced by init_manager().

char mandescr_mailboxstatus[] [static]

Help text for manager command mailboxstatus.

Definition at line 2094 of file manager.c.

Referenced by init_manager().

char mandescr_originate[] [static]

Definition at line 1956 of file manager.c.

Referenced by init_manager().

char mandescr_ping[] [static]

Initial value:

 
"Description: A 'Ping' action will ellicit a 'Pong' response.  Used to keep the\n"
"  manager connection open.\n"
"Variables: NONE\n"
Manager PING.

Definition at line 1176 of file manager.c.

Referenced by init_manager().

char mandescr_redirect[] [static]

Definition at line 1727 of file manager.c.

Referenced by init_manager().

char mandescr_setvar[] [static]

Definition at line 1530 of file manager.c.

Referenced by init_manager().

char mandescr_timeout[] [static]

Definition at line 2203 of file manager.c.

Referenced by init_manager().

char mandescr_updateconfig[] [static]

Definition at line 1291 of file manager.c.

Referenced by init_manager().

char mandescr_userevent[] [static]

Definition at line 2260 of file manager.c.

Referenced by init_manager().

char mandescr_waitevent[] [static]

Manager WAITEVENT.

Definition at line 1342 of file manager.c.

Referenced by init_manager().

struct eventqent* master_eventq = NULL

Definition at line 130 of file manager.c.

Referenced by accept_thread(), append_event(), handle_showmaneventq(), and process_events().

int num_sessions [static]

Definition at line 126 of file manager.c.

Referenced by accept_thread(), append_event(), and manager_event().

struct permalias perms[] [static]

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

int portno = DEFAULT_MANAGER_PORT [static]

Definition at line 115 of file manager.c.

Referenced by ast_netsock_bind(), create_addr(), init_manager(), process_sdp(), and set_config().

char showmanager_help[] [static]

Initial value:

" Usage: manager show user <user>\n"
"        Display all information related to the manager user specified.\n"

Definition at line 758 of file manager.c.

char showmanagers_help[] [static]

Initial value:

"Usage: manager show users\n"
"       Prints a listing of all managers that are currently configured on that\n"
" system.\n"

Definition at line 753 of file manager.c.

char showmancmd_help[] [static]

Initial value:

 
"Usage: manager show command <actionname>\n"
"  Shows the detailed description for a specific Asterisk manager interface command.\n"

Definition at line 735 of file manager.c.

char showmancmds_help[] [static]

Initial value:

 
"Usage: manager show commands\n"
"  Prints a listing of all the available Asterisk manager interface commands.\n"

Definition at line 739 of file manager.c.

char showmanconn_help[] [static]

Initial value:

 
"Usage: manager show connected\n"
"  Prints a listing of the users that are currently connected to the\n"
"Asterisk manager interface.\n"

Definition at line 743 of file manager.c.

char showmaneventq_help[] [static]

Initial value:

 
"Usage: manager show eventq\n"
"  Prints a listing of all events pending in the Asterisk manger\n"
"event queue.\n"

Definition at line 748 of file manager.c.

pthread_t t [static]

Definition at line 124 of file manager.c.

Referenced by __ast_register_translator(), __schedule_action(), accept_thread(), acf_odbc_write(), add_sdp(), append_date(), ast_channel_bridge(), ast_check_timing(), ast_do_masquerade(), ast_get_time_t(), ast_httpd_helper_thread(), ast_log(), ast_pbx_start(), ast_say_enumeration_full_da(), ast_say_enumeration_full_de(), ast_say_enumeration_full_en(), ast_say_number_full_de(), ast_translator_activate(), ast_translator_build_path(), ast_translator_deactivate(), ast_tvdiff_ms(), ast_tveq(), ast_unregister_translator(), ast_verbose(), background_detect_exec(), build_mapping(), byteReverse(), calc_cost(), calc_txstamp(), callerid_genmsg(), callerid_getcarrier(), cb_events(), cdr_get_tv(), check_switch_expr(), check_user_full(), cli_prompt(), config_text_file_save(), destroy(), do_monitor(), does_peer_need_mwi(), dump_cmd_queues(), expr2_token_subst(), gen_match_to_pattern(), gen_tone(), gen_tones(), get_date(), get_trans_id(), gtalk_action(), gtalk_create_candidates(), gtalk_digit(), gtalk_invite(), gtalk_invite_response(), handle_bchan(), handle_call_token(), handle_enbloc_call_message(), handle_hd_hf(), handle_offhook_message(), handle_save_dialplan(), handle_soft_key_event_message(), handle_stimulus_message(), iax2_datetime(), iax2_process_thread(), iax2_show_threads(), iax_template_parse(), launch_service(), listener(), local_new(), localsub(), lws2sws(), manager_log(), MD5Update(), misdn_read(), newpvt(), osp_create_provider(), osp_load(), packdate(), parse_moved_contact(), pgsql_log(), pri_dchannel(), prune_gateways(), rebuild_matrix(), register_verify(), rpt(), rpt_do_lstats(), rpt_exec(), rpt_tele_thread(), send_request(), SHA1ProcessMessageBlock(), sms_readfile(), socket_read(), sqlite_log(), strip_quotes(), tdd_getcarrier(), time2sub(), transmit_notify_request_with_callerid(), transmit_notify_with_mwi(), transmit_state_notify(), and write_metadata().

int timestampevents [static]

Definition at line 118 of file manager.c.

Referenced by init_manager(), and manager_event().

int unauth_sessions = 0 [static]

Definition at line 127 of file manager.c.

Referenced by accept_thread(), destroy_session(), handle_register_message(), and process_message().

int webmanager_enabled = 0 [static]

Definition at line 113 of file manager.c.

Referenced by init_manager().

char* words[AST_MAX_CMD_LEN] [inherited]

Definition at line 156 of file manager.c.


Generated on Sat Aug 6 00:40:07 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7