Sun Dec 18 20:55:55 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  permalias
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_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_message (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)
static AST_LIST_HEAD_STATIC (users, ast_manager_user)
static AST_LIST_HEAD_STATIC (sessions, mansession)
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)
 AST_RWLOCK_DEFINE_STATIC (actionlock)
 AST_THREADSTORAGE (astman_append_buf, astman_append_buf_init)
 AST_THREADSTORAGE (manager_event_buf, manager_event_buf_init)
void astman_append (struct mansession *s, const char *fmt,...)
const char * astman_get_header (const struct message *m, char *var)
struct 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)
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 *s)
static int do_message (struct mansession *s)
static void * fast_originate (void *data)
static void free_session (struct mansession *s)
static int get_input (struct mansession *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 connected.
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 int manager_state_cb (char *context, char *exten, int state, void *data, char *cid_num, char *cid_name)
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 *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 int asock = -1
static int authlimit
static int authtimeout
static int block_sockets
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 int enabled
static struct manager_actionfirst_action
static int httptimeout
static char mandescr_command []
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_message []
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.
struct 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

Detailed Description

callback to display queues status in manager


Define Documentation

#define ASTMAN_APPEND_BUF_INITSIZE   256

Definition at line 134 of file manager.c.

Referenced by astman_append().

#define MANAGER_EVENT_BUF_INITSIZE   256

Definition at line 131 of file manager.c.

Referenced by manager_event().

#define MAX_BLACKLIST_CMD_LEN   2

Definition at line 153 of file manager.c.

Referenced by check_blacklist().


Function Documentation

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

Definition at line 2503 of file manager.c.

References mansession::__lock, 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_pthread_create_background, AST_PTHREADT_NULL, ast_verbose(), mansession::authenticated, mansession::authstart, destroy_session(), errno, mansession::eventq, pollfd::events, mansession::fd, pollfd::fd, ast_channel::flags, free, free_session(), mansession::inuse, LOG_ERROR, LOG_NOTICE, LOG_WARNING, eventqent::next, option_verbose, poll(), POLLIN, s, mansession::send_events, session_do(), mansession::sessiontimeout, mansession::sin, mansession::t, eventqent::usecount, mansession::username, VERBOSE_PREFIX_2, mansession::waiting_thread, and mansession::writetimeout.

Referenced by init_manager(), and reload_config().

02504 {
02505    int as;
02506    struct sockaddr_in sin;
02507    socklen_t sinlen;
02508    struct eventqent *eqe;
02509    struct mansession *s;
02510    struct protoent *p;
02511    int arg = 1;
02512    int flags;
02513    pthread_attr_t attr;
02514    time_t now;
02515    struct pollfd pfds[1];
02516 
02517    pthread_attr_init(&attr);
02518    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
02519 
02520    for (;;) {
02521       time(&now);
02522       AST_LIST_LOCK(&sessions);
02523       AST_LIST_TRAVERSE_SAFE_BEGIN(&sessions, s, list) {
02524          if (s->sessiontimeout && (now > s->sessiontimeout) && !s->inuse) {
02525             AST_LIST_REMOVE_CURRENT(&sessions, list);
02526             num_sessions--;
02527             if (s->authenticated && (option_verbose > 1) && displayconnects) {
02528                ast_verbose(VERBOSE_PREFIX_2 "HTTP Manager '%s' timed out from %s\n",
02529                   s->username, ast_inet_ntoa(s->sin.sin_addr));
02530             }
02531             free_session(s);
02532             break;   
02533          }
02534       }
02535       AST_LIST_TRAVERSE_SAFE_END
02536       /* Purge master event queue of old, unused events, but make sure we
02537          always keep at least one in the queue */
02538       eqe = master_eventq;
02539       while (master_eventq->next && !master_eventq->usecount) {
02540          eqe = master_eventq;
02541          master_eventq = master_eventq->next;
02542          free(eqe);
02543       }
02544       AST_LIST_UNLOCK(&sessions);
02545 
02546       sinlen = sizeof(sin);
02547       pfds[0].fd = asock;
02548       pfds[0].events = POLLIN;
02549       /* Wait for something to happen, but timeout every few seconds so
02550          we can ditch any old manager sessions */
02551       if (poll(pfds, 1, 5000) < 1)
02552          continue;
02553       as = accept(asock, (struct sockaddr *)&sin, &sinlen);
02554       if (as < 0) {
02555          ast_log(LOG_NOTICE, "Accept returned -1: %s\n", strerror(errno));
02556          continue;
02557       }
02558 
02559       if (ast_atomic_fetchadd_int(&unauth_sessions, +1) >= authlimit) {
02560          close(as);
02561          ast_atomic_fetchadd_int(&unauth_sessions, -1);
02562          ast_log(LOG_WARNING, "manager connection rejected, too many unauthenticated sessions.\n");
02563          continue;
02564       }
02565 
02566       p = getprotobyname("tcp");
02567       if (p) {
02568          if( setsockopt(as, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) {
02569             ast_log(LOG_WARNING, "Failed to set manager tcp connection to TCP_NODELAY mode: %s\n", strerror(errno));
02570          }
02571       }
02572       if (!(s = ast_calloc(1, sizeof(*s)))) {
02573          close(as);
02574          ast_atomic_fetchadd_int(&unauth_sessions, -1);
02575          continue;
02576       }
02577 
02578       memcpy(&s->sin, &sin, sizeof(sin));
02579       s->writetimeout = 100;
02580       s->waiting_thread = AST_PTHREADT_NULL;
02581 
02582       if (!block_sockets) {
02583          /* For safety, make sure socket is non-blocking */
02584          flags = fcntl(as, F_GETFL);
02585          fcntl(as, F_SETFL, flags | O_NONBLOCK);
02586       } else {
02587          flags = fcntl(as, F_GETFL);
02588          fcntl(as, F_SETFL, flags & ~O_NONBLOCK);
02589       }
02590       ast_mutex_init(&s->__lock);
02591       s->fd = as;
02592       s->send_events = -1;
02593       AST_LIST_LOCK(&sessions);
02594       AST_LIST_INSERT_HEAD(&sessions, s, list);
02595       num_sessions++;
02596       /* Find the last place in the master event queue and hook ourselves
02597          in there */
02598       s->eventq = master_eventq;
02599       while(s->eventq->next)
02600          s->eventq = s->eventq->next;
02601       ast_atomic_fetchadd_int(&s->eventq->usecount, 1);
02602       AST_LIST_UNLOCK(&sessions);
02603       if(time(&s->authstart) == -1) {
02604          ast_log(LOG_ERROR, "error executing time(): %s; disconnecting client\n", strerror(errno));
02605          ast_atomic_fetchadd_int(&unauth_sessions, -1);
02606          destroy_session(s);
02607          continue;
02608       }
02609       if (ast_pthread_create_background(&s->t, &attr, session_do, s)) {
02610          ast_atomic_fetchadd_int(&unauth_sessions, -1);
02611          destroy_session(s);
02612       }
02613    }
02614    pthread_attr_destroy(&attr);
02615    return NULL;
02616 }

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

action_command: Manager command "command" - execute CLI command

Definition at line 1827 of file manager.c.

References ast_calloc, ast_cli_command(), ast_free, ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), check_blacklist(), mansession::fd, S_OR, and term_strip().

Referenced by init_manager().

01828 {
01829    const char *cmd = astman_get_header(m, "Command");
01830    const char *id = astman_get_header(m, "ActionID");
01831    char *buf, *final_buf;
01832    char template[] = "/tmp/ast-ami-XXXXXX";  /* template for temporary file */
01833    int fd = mkstemp(template);
01834    off_t l;
01835 
01836    if (ast_strlen_zero(cmd)) {
01837       astman_send_error(s, m, "No command provided");
01838       return 0;
01839    }
01840 
01841    if (check_blacklist(cmd)) {
01842       astman_send_error(s, m, "Command blacklisted");
01843       return 0;
01844    }
01845 
01846    astman_append(s, "Response: Follows\r\nPrivilege: Command\r\n");
01847    if (!ast_strlen_zero(id))
01848       astman_append(s, "ActionID: %s\r\n", id);
01849    /* FIXME: Wedge a ActionID response in here, waiting for later changes */
01850    ast_cli_command(fd, cmd);  /* XXX need to change this to use a FILE * */
01851    l = lseek(fd, 0, SEEK_END);   /* how many chars available */
01852 
01853    /* This has a potential to overflow the stack.  Hence, use the heap. */
01854    buf = ast_calloc(1, l + 1);
01855    final_buf = ast_calloc(1, l + 1);
01856    if (buf) {
01857       lseek(fd, 0, SEEK_SET);
01858       read(fd, buf, l);
01859       buf[l] = '\0';
01860       if (final_buf) {
01861          term_strip(final_buf, buf, l);
01862          final_buf[l] = '\0';
01863       }
01864       astman_append(s, "%s", S_OR(final_buf, buf));
01865       ast_free(buf);
01866    }
01867    close(fd);
01868    unlink(template);
01869    astman_append(s, "--END COMMAND--\r\n\r\n");
01870    if (final_buf)
01871       ast_free(final_buf);
01872    return 0;
01873 }

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

Definition at line 1412 of file manager.c.

References astman_get_header(), astman_send_response(), and set_eventmask().

Referenced by init_manager().

01413 {
01414    const char *mask = astman_get_header(m, "EventMask");
01415    int res;
01416 
01417    res = set_eventmask(s, mask);
01418    if (res > 0)
01419       astman_send_response(s, m, "Events On", NULL);
01420    else if (res == 0)
01421       astman_send_response(s, m, "Events Off", NULL);
01422 
01423    return 0;
01424 }

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

Definition at line 2145 of file manager.c.

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

Referenced by init_manager().

02146 {
02147    const char *exten = astman_get_header(m, "Exten");
02148    const char *context = astman_get_header(m, "Context");
02149    const char *id = astman_get_header(m,"ActionID");
02150    char idText[256] = "";
02151    char hint[256] = "";
02152    int status;
02153    if (ast_strlen_zero(exten)) {
02154       astman_send_error(s, m, "Extension not specified");
02155       return 0;
02156    }
02157    if (ast_strlen_zero(context))
02158       context = "default";
02159    status = ast_extension_state(NULL, context, exten);
02160    ast_get_hint(hint, sizeof(hint) - 1, NULL, 0, NULL, context, exten);
02161         if (!ast_strlen_zero(id)) {
02162                 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
02163         }
02164    astman_append(s, "Response: Success\r\n"
02165                     "%s"
02166                "Message: Extension Status\r\n"
02167                "Exten: %s\r\n"
02168                "Context: %s\r\n"
02169                "Hint: %s\r\n"
02170                "Status: %d\r\n\r\n",
02171                idText,exten, context, hint, status);
02172    return 0;
02173 }

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

Definition at line 1141 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(), lineno, ast_variable::name, ast_variable::next, and ast_variable::value.

Referenced by init_manager().

01142 {
01143    struct ast_config *cfg;
01144    const char *fn = astman_get_header(m, "Filename");
01145    int catcount = 0;
01146    int lineno = 0;
01147    char *category=NULL;
01148    struct ast_variable *v;
01149    char idText[256] = "";
01150    const char *id = astman_get_header(m, "ActionID");
01151 
01152    if (!ast_strlen_zero(id))
01153       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
01154 
01155    if (ast_strlen_zero(fn)) {
01156       astman_send_error(s, m, "Filename not specified");
01157       return 0;
01158    }
01159    if (!(cfg = ast_config_load_with_comments(fn))) {
01160       astman_send_error(s, m, "Config file not found");
01161       return 0;
01162    }
01163    astman_append(s, "Response: Success\r\n%s", idText);
01164    while ((category = ast_category_browse(cfg, category))) {
01165       lineno = 0;
01166       astman_append(s, "Category-%06d: %s\r\n", catcount, category);
01167       for (v = ast_variable_browse(cfg, category); v; v = v->next)
01168          astman_append(s, "Line-%06d-%06d: %s=%s\r\n", catcount, lineno++, v->name, v->value);
01169       catcount++;
01170    }
01171    ast_config_destroy(cfg);
01172    astman_append(s, "\r\n");
01173 
01174    return 0;
01175 }

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

Definition at line 1556 of file manager.c.

References ast_channel_unlock, ast_func_read(), ast_get_channel_by_name_locked(), ast_strdupa, ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), copy(), name, and pbx_retrieve_variable().

Referenced by init_manager().

01557 {
01558    struct ast_channel *c = NULL;
01559    const char *name = astman_get_header(m, "Channel");
01560    const char *varname = astman_get_header(m, "Variable");
01561    const char *id = astman_get_header(m,"ActionID");
01562    char *varval;
01563    char workspace[1024] = "";
01564 
01565    if (ast_strlen_zero(varname)) {
01566       astman_send_error(s, m, "No variable specified");
01567       return 0;
01568    }
01569 
01570    if (!ast_strlen_zero(name)) {
01571       c = ast_get_channel_by_name_locked(name);
01572       if (!c) {
01573          astman_send_error(s, m, "No such channel");
01574          return 0;
01575       }
01576    }
01577 
01578    if (varname[strlen(varname) - 1] == ')') {
01579       char *copy = ast_strdupa(varname);
01580 
01581       ast_func_read(c, copy, workspace, sizeof(workspace));
01582       varval = workspace;
01583    } else {
01584       pbx_retrieve_variable(c, varname, &varval, workspace, sizeof(workspace), NULL);
01585    }
01586 
01587    if (c)
01588       ast_channel_unlock(c);
01589    astman_append(s, "Response: Success\r\n"
01590       "Variable: %s\r\nValue: %s\r\n", varname, varval);
01591    if (!ast_strlen_zero(id))
01592       astman_append(s, "ActionID: %s\r\n",id);
01593    astman_append(s, "\r\n");
01594 
01595    return 0;
01596 }

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

Definition at line 1441 of file manager.c.

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

Referenced by init_manager().

01442 {
01443    struct ast_channel *c = NULL;
01444    const char *name = astman_get_header(m, "Channel");
01445    const char *uniqueid = astman_get_header(m, "Uniqueid");
01446 
01447    if (ast_strlen_zero(name) && ast_strlen_zero(uniqueid)) {
01448       astman_send_error(s, m, "No channel or uniqueid specified");
01449       return 0;
01450    }
01451 
01452    if (!ast_strlen_zero(uniqueid)) {
01453       c = ast_get_channel_by_uniqueid_locked(uniqueid);
01454    } else {
01455        if (!ast_strlen_zero(name))
01456       c = ast_get_channel_by_name_locked(name);
01457    }
01458 
01459    if (!c) {
01460       astman_send_error(s, m, "No such channel");
01461       return 0;
01462    }
01463    ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
01464    ast_channel_unlock(c);
01465    astman_send_ack(s, m, "Channel Hungup");
01466    return 0;
01467 }

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 1385 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, manager_action::synopsis, and mansession::writeperm.

Referenced by init_manager().

01386 {
01387    struct manager_action *cur;
01388    char idText[256] = "";
01389    char temp[BUFSIZ];
01390    const char *id = astman_get_header(m,"ActionID");
01391 
01392    if (!ast_strlen_zero(id))
01393       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
01394    astman_append(s, "Response: Success\r\n%s", idText);
01395    for (cur = first_action; cur; cur = cur->next) {
01396       if ((s->writeperm & cur->authority) == cur->authority)
01397          astman_append(s, "%s: %s (Priv: %s)\r\n", cur->action, cur->synopsis, authority_to_str(cur->authority, temp, sizeof(temp)));
01398    }
01399    astman_append(s, "\r\n");
01400 
01401    return 0;
01402 }

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

Definition at line 1430 of file manager.c.

References astman_send_response().

Referenced by init_manager().

01431 {
01432    astman_send_response(s, m, "Goodbye", "Thanks for all the fish.");
01433    return -1;
01434 }

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

Definition at line 2109 of file manager.c.

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

Referenced by init_manager().

02110 {
02111    const char *mailbox = astman_get_header(m, "Mailbox");
02112    const char *id = astman_get_header(m,"ActionID");
02113    char idText[256] = "";
02114    int newmsgs = 0, oldmsgs = 0;
02115    if (ast_strlen_zero(mailbox)) {
02116       astman_send_error(s, m, "Mailbox not specified");
02117       return 0;
02118    }
02119    ast_app_inboxcount(mailbox, &newmsgs, &oldmsgs);
02120    if (!ast_strlen_zero(id)) {
02121       snprintf(idText, sizeof(idText), "ActionID: %s\r\n",id);
02122    }
02123    astman_append(s, "Response: Success\r\n"
02124                "%s"
02125                "Message: Mailbox Message Count\r\n"
02126                "Mailbox: %s\r\n"
02127                "NewMessages: %d\r\n"
02128                "OldMessages: %d\r\n" 
02129                "\r\n",
02130                 idText,mailbox, newmsgs, oldmsgs);
02131    return 0;
02132 }

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

Definition at line 2077 of file manager.c.

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

Referenced by init_manager().

02078 {
02079    const char *mailbox = astman_get_header(m, "Mailbox");
02080    const char *id = astman_get_header(m,"ActionID");
02081    char idText[256] = "";
02082    int ret;
02083    if (ast_strlen_zero(mailbox)) {
02084       astman_send_error(s, m, "Mailbox not specified");
02085       return 0;
02086    }
02087         if (!ast_strlen_zero(id))
02088                 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
02089    ret = ast_app_has_voicemail(mailbox, NULL);
02090    astman_append(s, "Response: Success\r\n"
02091                "%s"
02092                "Message: Mailbox Status\r\n"
02093                "Mailbox: %s\r\n"
02094                "Waiting: %d\r\n\r\n", idText, mailbox, ret);
02095    return 0;
02096 }

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

Definition at line 1476 of file manager.c.

References ast_send_message(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), ast_channel::data, name, and ast_channel::tech.

Referenced by init_manager().

01477 {
01478    const char *name = astman_get_header(m, "Channel");
01479    const char *from = astman_get_header(m, "From");
01480    const char *message = astman_get_header(m, "Message");
01481    const char *pdu = astman_get_header(m, "PDU");
01482    char tmp[256];
01483    char *tech, *data;
01484    int res;
01485    if (ast_strlen_zero(name) || (ast_strlen_zero(message) && ast_strlen_zero(pdu))) {
01486       astman_send_error(s, m, "No channel or message/PDU specified");
01487       return 0;
01488    }
01489    ast_copy_string(tmp, name, sizeof(tmp));
01490    tech = tmp;
01491    data = strchr(tmp, '/');
01492    if (!data) {
01493       astman_send_error(s, m, "Invalid channel\n");
01494       return 0;
01495    }
01496    *data = '\0';
01497    data++;
01498    if (ast_strlen_zero(pdu)) {
01499        res = ast_send_message(tech, (char *)data, (char *)name, (char *)from, (char *)message, 0);
01500    } else {
01501        res = ast_send_message(tech, (char *)data, (char *)name, (char *)from, (char *)pdu, 1);
01502    }
01503 
01504    if (res) {
01505       astman_send_error(s, m, "Error sending message");
01506       return 0;
01507    }
01508    astman_send_ack(s, m, "Message sent");
01509    return 0;
01510 }

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

Definition at line 1939 of file manager.c.

References fast_originate_helper::account, fast_originate_helper::app, app, fast_originate_helper::appdata, ast_alloc_uniqueid(), ast_callerid_parse(), ast_calloc, ast_cli(), ast_findlabel_extension(), AST_FORMAT_SLINEAR, ast_pbx_outgoing_app_uniqueid(), ast_pbx_outgoing_exten_uniqueid(), ast_pthread_create, ast_shrink_phone_number(), ast_strlen_zero(), ast_true(), astman_get_header(), astman_get_variables(), astman_send_error(), fast_originate_helper::callingpres, fast_originate_helper::cid_name, fast_originate_helper::cid_num, fast_originate_helper::context, context, fast_originate_helper::data, ast_channel::data, fast_originate_helper::exten, exten, fast_originate(), mansession::fd, fast_originate_helper::idtext, name, fast_originate_helper::priority, ast_channel::priority, fast_originate_helper::tech, ast_channel::tech, fast_originate_helper::timeout, fast_originate_helper::uniqueid, and fast_originate_helper::vars.

Referenced by init_manager().

01940 {
01941    const char *name = astman_get_header(m, "Channel");
01942    const char *exten = astman_get_header(m, "Exten");
01943    const char *context = astman_get_header(m, "Context");
01944    const char *priority = astman_get_header(m, "Priority");
01945    const char *timeout = astman_get_header(m, "Timeout");
01946    const char *callerid = astman_get_header(m, "CallerID");
01947    const char *account = astman_get_header(m, "Account");
01948    const char *app = astman_get_header(m, "Application");
01949    const char *appdata = astman_get_header(m, "Data");
01950    const char *async = astman_get_header(m, "Async");
01951    const char *id = astman_get_header(m, "ActionID");
01952    const char *callingpres = astman_get_header(m, "CallingPres");
01953    struct ast_variable *vars = astman_get_variables(m);
01954    char *tech, *data;
01955    char *l = NULL, *n = NULL;
01956    int pi = 0;
01957    int res;
01958    int to = 30000;
01959    int reason = 0;
01960    char tmp[256];
01961    char tmp2[256];
01962    char *uniqueid;
01963    int cpresi = 0;
01964    char idText[256] = "";
01965    
01966    pthread_t th;
01967    pthread_attr_t attr;
01968    if (!name) {
01969       astman_send_error(s, m, "Channel not specified");
01970       return 0;
01971    }
01972    if (!ast_strlen_zero(priority) && (sscanf(priority, "%d", &pi) != 1)) {
01973       if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) {
01974          astman_send_error(s, m, "Invalid priority\n");
01975          return 0;
01976       }
01977    }
01978    if (!ast_strlen_zero(timeout) && (sscanf(timeout, "%d", &to) != 1)) {
01979       astman_send_error(s, m, "Invalid timeout\n");
01980       return 0;
01981    }
01982    if (!ast_strlen_zero(callingpres) && (sscanf(callingpres, "%d", &cpresi) != 1)) {
01983       astman_send_error(s, m, "Invalid CallingPres\n");
01984       return 0;
01985    }
01986    ast_copy_string(tmp, name, sizeof(tmp));
01987    tech = tmp;
01988    data = strchr(tmp, '/');
01989    if (!data) {
01990       astman_send_error(s, m, "Invalid channel\n");
01991       return 0;
01992    }
01993    *data++ = '\0';
01994    ast_copy_string(tmp2, callerid, sizeof(tmp2));
01995    ast_callerid_parse(tmp2, &n, &l);
01996    if (n) {
01997       if (ast_strlen_zero(n))
01998          n = NULL;
01999    }
02000    if (l) {
02001       ast_shrink_phone_number(l);
02002       if (ast_strlen_zero(l))
02003          l = NULL;
02004    }
02005    uniqueid = ast_alloc_uniqueid();
02006    if (ast_true(async)) {
02007       struct fast_originate_helper *fast = ast_calloc(1, sizeof(*fast));
02008       if (!fast) {
02009          res = -1;
02010       } else {
02011          if (!ast_strlen_zero(id))
02012             snprintf(fast->idtext, sizeof(fast->idtext), "ActionID: %s\r\n", id);
02013          ast_copy_string(fast->tech, tech, sizeof(fast->tech));
02014             ast_copy_string(fast->data, data, sizeof(fast->data));
02015          ast_copy_string(fast->app, app, sizeof(fast->app));
02016          ast_copy_string(fast->appdata, appdata, sizeof(fast->appdata));
02017          if (l)
02018             ast_copy_string(fast->cid_num, l, sizeof(fast->cid_num));
02019          if (n)
02020             ast_copy_string(fast->cid_name, n, sizeof(fast->cid_name));
02021          fast->vars = vars;   
02022          ast_copy_string(fast->context, context, sizeof(fast->context));
02023          ast_copy_string(fast->exten, exten, sizeof(fast->exten));
02024          ast_copy_string(fast->account, account, sizeof(fast->account));
02025          ast_copy_string(fast->uniqueid, uniqueid, sizeof(fast->uniqueid));
02026          fast->timeout = to;
02027          fast->priority = pi;
02028          fast->callingpres = cpresi;
02029          pthread_attr_init(&attr);
02030          pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
02031          if (ast_pthread_create(&th, &attr, fast_originate, fast)) {
02032             res = -1;
02033          } else {
02034             res = 0;
02035          }
02036          pthread_attr_destroy(&attr);
02037       }
02038    } else if (!ast_strlen_zero(app)) {
02039          res = ast_pbx_outgoing_app_uniqueid(tech, AST_FORMAT_SLINEAR, data, to, app, appdata, &reason, 1, cpresi, l, n, vars, account, NULL, uniqueid);
02040       } else {
02041       if (exten && context && pi)
02042             res = ast_pbx_outgoing_exten_uniqueid(tech, AST_FORMAT_SLINEAR, data, to, context, exten, pi, &reason, 1, cpresi, l, n, vars, account, NULL, uniqueid);
02043       else {
02044          astman_send_error(s, m, "Originate with 'Exten' requires 'Context' and 'Priority'");
02045          return 0;
02046       }
02047    }   
02048    if (!res) {
02049            if (id && !ast_strlen_zero(id)) {
02050                 snprintf(idText,256,"ActionID: %s\r\n",id);
02051       }
02052       ast_cli(s->fd, "Response: Success\r\n"
02053                 "%s"
02054                "Message: Originate successfully queued\r\n"
02055                "Uniqueid: %s\r\n"
02056                "\r\n",
02057                 idText, uniqueid);
02058    } else {
02059       astman_send_error(s, m, "Originate failed");
02060    }
02061    return 0;
02062 }

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

Definition at line 1129 of file manager.c.

References astman_send_response().

Referenced by init_manager().

01130 {
01131    astman_send_response(s, m, "Pong", NULL);
01132    return 0;
01133 }

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

action_redirect: The redirect manager command

Definition at line 1702 of file manager.c.

References ast_async_goto(), ast_channel_unlock, ast_check_hangup(), ast_findlabel_extension(), ast_get_channel_by_name_locked(), ast_get_channel_by_uniqueid_locked(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), context, exten, and name.

Referenced by init_manager().

01703 {
01704    const char *name = astman_get_header(m, "Channel");
01705    const char *name2 = astman_get_header(m, "ExtraChannel");
01706    const char *exten = astman_get_header(m, "Exten");
01707    const char *context = astman_get_header(m, "Context");
01708    const char *priority = astman_get_header(m, "Priority");
01709    const char *uniqueid = astman_get_header(m, "Uniqueid");
01710    const char *uniqueid2 = astman_get_header(m, "ExtraUniqueid");
01711    const char *exten2 = astman_get_header(m, "ExtraExten");
01712    const char *context2 = astman_get_header(m, "ExtraContext");
01713    const char *priority2 = astman_get_header(m, "ExtraPriority");
01714    struct ast_channel *chan, *chan2 = NULL;
01715    int pi = 0;
01716    int pi2 = 0;
01717    int res;
01718 
01719    if (ast_strlen_zero(name) && ast_strlen_zero(uniqueid)) {
01720       astman_send_error(s, m, "Channel or Uniqueid not specified");
01721       return 0;
01722    }
01723    if (!ast_strlen_zero(priority) && (sscanf(priority, "%d", &pi) != 1)) {
01724       if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) {
01725          astman_send_error(s, m, "Invalid priority\n");
01726          return 0;
01727       }
01728    }
01729    if (!ast_strlen_zero(priority2) && (sscanf(priority2, "%d", &pi2) != 1)) {
01730       if ((pi = ast_findlabel_extension(NULL, context2, exten2, priority2, NULL)) < 1) {
01731          astman_send_error(s, m, "Invalid extra priority\n");
01732          return 0;
01733       }
01734    }
01735    /* XXX watch out, possible deadlock!!! */
01736    if (!ast_strlen_zero(uniqueid)) {
01737        chan = ast_get_channel_by_uniqueid_locked(uniqueid);
01738    } else {
01739        chan = ast_get_channel_by_name_locked(name);
01740    }
01741    if (!chan) {
01742       char buf[BUFSIZ];
01743       snprintf(buf, sizeof(buf), "Channel does not exist: %s", name);
01744       astman_send_error(s, m, buf);
01745       return 0;
01746    }
01747    if (ast_check_hangup(chan)) {
01748       astman_send_error(s, m, "Redirect failed, channel not up.\n");
01749       ast_channel_unlock(chan);
01750       return 0;
01751    }
01752    if (!ast_strlen_zero(uniqueid2)) {
01753        chan2 = ast_get_channel_by_uniqueid_locked(uniqueid2);
01754    } else if (!ast_strlen_zero(name2)) {
01755       chan2 = ast_get_channel_by_name_locked(name2);
01756    }
01757    if (chan2 && ast_check_hangup(chan2)) {
01758       astman_send_error(s, m, "Redirect failed, extra channel not up.\n");
01759       ast_channel_unlock(chan);
01760       ast_channel_unlock(chan2);
01761       return 0;
01762    }
01763    res = ast_async_goto(chan, context, exten, pi);
01764    if (!res) {
01765       if ((!ast_strlen_zero(name2)) || (!ast_strlen_zero(uniqueid2))){
01766          if (chan2)
01767             res = ast_async_goto(chan2, context2, exten2, pi2);
01768          else
01769             res = -1;
01770          if (!res)
01771             astman_send_ack(s, m, "Dual Redirect successful");
01772          else
01773             astman_send_error(s, m, "Secondary redirect failed");
01774       } else
01775          astman_send_ack(s, m, "Redirect successful");
01776    } else
01777       astman_send_error(s, m, "Redirect failed");
01778    if (chan)
01779       ast_channel_unlock(chan);
01780    if (chan2)
01781       ast_channel_unlock(chan2);
01782    return 0;
01783 }

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

Definition at line 1519 of file manager.c.

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

Referenced by init_manager().

01520 {
01521         struct ast_channel *c = NULL;
01522    const char *name = astman_get_header(m, "Channel");
01523    const char *varname = astman_get_header(m, "Variable");
01524    const char *varval = astman_get_header(m, "Value");
01525    
01526    if (ast_strlen_zero(varname)) {
01527       astman_send_error(s, m, "No variable specified");
01528       return 0;
01529    }
01530    
01531    if (!ast_strlen_zero(name)) {
01532       c = ast_get_channel_by_name_locked(name);
01533       if (!c) {
01534          astman_send_error(s, m, "No such channel");
01535          return 0;
01536       }
01537    }
01538    
01539    pbx_builtin_setvar_helper(c, varname, S_OR(varval, ""));
01540      
01541    if (c)
01542       ast_channel_unlock(c);
01543 
01544    astman_send_ack(s, m, "Variable Set"); 
01545 
01546    return 0;
01547 }

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

Manager "status" command to show channels.

Definition at line 1601 of file manager.c.

References ast_channel::_bridge, ast_channel::_state, ast_channel_unlock, ast_channel_walk_locked(), ast_get_channel_by_name_locked(), ast_state2str(), ast_strlen_zero(), 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, name, ast_channel::pbx, ast_channel::priority, S_OR, and ast_cdr::start.

Referenced by init_manager().

01602 {
01603    const char *id = astman_get_header(m,"ActionID");
01604       const char *name = astman_get_header(m,"Channel");
01605    char idText[256] = "";
01606    struct ast_channel *c;
01607    char bridge[256];
01608    struct timeval now = ast_tvnow();
01609    long elapsed_seconds = 0;
01610    int all = ast_strlen_zero(name); /* set if we want all channels */
01611 
01612    if (!ast_strlen_zero(id))
01613       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
01614    if (all)
01615       c = ast_channel_walk_locked(NULL);
01616    else {
01617       c = ast_get_channel_by_name_locked(name);
01618       if (!c) {
01619          astman_send_error(s, m, "No such channel");
01620          return 0;
01621       }
01622    }
01623    astman_send_ack(s, m, "Channel status will follow");
01624    /* if we look by name, we break after the first iteration */
01625    while (c) {
01626       if (c->_bridge)
01627          snprintf(bridge, sizeof(bridge), "Link: %s\r\n", c->_bridge->name);
01628       else
01629          bridge[0] = '\0';
01630       if (c->pbx) {
01631          if (c->cdr) {
01632             elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
01633          }
01634          astman_append(s,
01635          "Event: Status\r\n"
01636          "Privilege: Call\r\n"
01637          "Channel: %s\r\n"
01638          "CallerID: %s\r\n"      /* This parameter is deprecated and will be removed post-1.4 */
01639          "CallerIDNum: %s\r\n"
01640          "CallerIDName: %s\r\n"
01641          "Account: %s\r\n"
01642          "State: %s\r\n"
01643          "Context: %s\r\n"
01644          "Extension: %s\r\n"
01645          "Priority: %d\r\n"
01646          "Seconds: %ld\r\n"
01647          "%s"
01648          "Uniqueid: %s\r\n"
01649          "%s"
01650          "\r\n",
01651          c->name, 
01652          S_OR(c->cid.cid_num, "<unknown>"), 
01653          S_OR(c->cid.cid_num, "<unknown>"), 
01654          S_OR(c->cid.cid_name, "<unknown>"), 
01655          c->accountcode,
01656          ast_state2str(c->_state), c->context,
01657          c->exten, c->priority, (long)elapsed_seconds, bridge, c->uniqueid, idText);
01658       } else {
01659          astman_append(s,
01660          "Event: Status\r\n"
01661          "Privilege: Call\r\n"
01662          "Channel: %s\r\n"
01663          "CallerID: %s\r\n"      /* This parameter is deprecated and will be removed post-1.4 */
01664          "CallerIDNum: %s\r\n"
01665          "CallerIDName: %s\r\n"
01666          "Account: %s\r\n"
01667          "State: %s\r\n"
01668          "%s"
01669          "Uniqueid: %s\r\n"
01670          "%s"
01671          "\r\n",
01672          c->name, 
01673          S_OR(c->cid.cid_num, "<unknown>"), 
01674          S_OR(c->cid.cid_num, "<unknown>"), 
01675          S_OR(c->cid.cid_name, "<unknown>"), 
01676          c->accountcode,
01677          ast_state2str(c->_state), bridge, c->uniqueid, idText);
01678       }
01679       ast_channel_unlock(c);
01680       if (!all)
01681          break;
01682       c = ast_channel_walk_locked(c);
01683    }
01684    astman_append(s,
01685    "Event: StatusComplete\r\n"
01686    "%s"
01687    "\r\n",idText);
01688    return 0;
01689 }

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

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

Referenced by init_manager().

02183 {
02184    struct ast_channel *c = NULL;
02185    const char *name = astman_get_header(m, "Channel");
02186    int timeout = atoi(astman_get_header(m, "Timeout"));
02187    if (ast_strlen_zero(name)) {
02188       astman_send_error(s, m, "No channel specified");
02189       return 0;
02190    }
02191    if (!timeout) {
02192       astman_send_error(s, m, "No timeout specified");
02193       return 0;
02194    }
02195    c = ast_get_channel_by_name_locked(name);
02196    if (!c) {
02197       astman_send_error(s, m, "No such channel");
02198       return 0;
02199    }
02200    ast_channel_setwhentohangup(c, timeout);
02201    ast_channel_unlock(c);
02202    astman_send_ack(s, m, "Timeout Set");
02203    return 0;
02204 }

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

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

Referenced by init_manager().

01253 {
01254    struct ast_config *cfg;
01255    const char *sfn = astman_get_header(m, "SrcFilename");
01256    const char *dfn = astman_get_header(m, "DstFilename");
01257    int res;
01258    char idText[256] = "";
01259    const char *id = astman_get_header(m, "ActionID");
01260    const char *rld = astman_get_header(m, "Reload");
01261 
01262    if (!ast_strlen_zero(id))
01263       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
01264 
01265    if (ast_strlen_zero(sfn) || ast_strlen_zero(dfn)) {
01266       astman_send_error(s, m, "Filename not specified");
01267       return 0;
01268    }
01269    if (!(cfg = ast_config_load_with_comments(sfn))) {
01270       astman_send_error(s, m, "Config file not found");
01271       return 0;
01272    }
01273    handle_updates(s, m, cfg);
01274    res = config_text_file_save(dfn, cfg, "Manager");
01275    ast_config_destroy(cfg);
01276    if (res) {
01277       astman_send_error(s, m, "Save of config failed");
01278       return 0;
01279    }
01280    astman_append(s, "Response: Success\r\n%s\r\n", idText);
01281    if (!ast_strlen_zero(rld)) {
01282       if (ast_true(rld))
01283          rld = NULL;
01284       ast_module_reload(rld); 
01285    }
01286    return 0;
01287 }

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

Definition at line 2239 of file manager.c.

References astman_get_header(), event, EVENT_FLAG_USER, message::hdrcount, message::headers, and manager_event().

Referenced by init_manager().

02240 {
02241    const char *event = astman_get_header(m, "UserEvent");
02242    char body[2048] = "";
02243    int x, bodylen = 0;
02244    for (x = 0; x < m->hdrcount; x++) {
02245       if (strncasecmp("UserEvent:", m->headers[x], strlen("UserEvent:"))) {
02246          ast_copy_string(body + bodylen, m->headers[x], sizeof(body) - bodylen - 3);
02247          bodylen += strlen(m->headers[x]);
02248          ast_copy_string(body + bodylen, "\r\n", 3);
02249          bodylen += 2;
02250       }
02251    }
02252 
02253    manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", event, body);
02254    return 0;
02255 }

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

Definition at line 1297 of file manager.c.

References mansession::__lock, 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, mansession::eventq, mansession::fd, LOG_DEBUG, mansession::needdestroy, eventqent::next, option_debug, mansession::readperm, mansession::send_events, mansession::sessiontimeout, unuse_eventqent(), and mansession::waiting_thread.

Referenced by init_manager().

01298 {
01299    const char *timeouts = astman_get_header(m, "Timeout");
01300    int timeout = -1, max;
01301    int x;
01302    int needexit = 0;
01303    time_t now;
01304    struct eventqent *eqe;
01305    const char *id = astman_get_header(m,"ActionID");
01306    char idText[256] = "";
01307 
01308    if (!ast_strlen_zero(id))
01309       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
01310 
01311    if (!ast_strlen_zero(timeouts)) {
01312       sscanf(timeouts, "%i", &timeout);
01313    }
01314    
01315    ast_mutex_lock(&s->__lock);
01316    if (s->waiting_thread != AST_PTHREADT_NULL) {
01317       pthread_kill(s->waiting_thread, SIGURG);
01318    }
01319    if (s->sessiontimeout) {
01320       time(&now);
01321       max = s->sessiontimeout - now - 10;
01322       if (max < 0)
01323          max = 0;
01324       if ((timeout < 0) || (timeout > max))
01325          timeout = max;
01326       if (!s->send_events)
01327          s->send_events = -1;
01328       /* Once waitevent is called, always queue events from now on */
01329    }
01330    ast_mutex_unlock(&s->__lock);
01331    s->waiting_thread = pthread_self();
01332    if (option_debug)
01333       ast_log(LOG_DEBUG, "Starting waiting for an event!\n");
01334    for (x=0; ((x < timeout) || (timeout < 0)); x++) {
01335       ast_mutex_lock(&s->__lock);
01336       if (s->eventq && s->eventq->next)
01337          needexit = 1;
01338       if (s->waiting_thread != pthread_self())
01339          needexit = 1;
01340       if (s->needdestroy)
01341          needexit = 1;
01342       ast_mutex_unlock(&s->__lock);
01343       if (needexit)
01344          break;
01345       if (s->fd > 0) {
01346          if (ast_wait_for_input(s->fd, 1000))
01347             break;
01348       } else {
01349          sleep(1);
01350       }
01351    }
01352    if (option_debug)
01353       ast_log(LOG_DEBUG, "Finished waiting for an event!\n");
01354    ast_mutex_lock(&s->__lock);
01355    if (s->waiting_thread == pthread_self()) {
01356       astman_send_response(s, m, "Success", "Waiting for Event...");
01357       /* Only show events if we're the most recent waiter */
01358       while(s->eventq->next) {
01359          eqe = s->eventq->next;
01360          if (((s->readperm & eqe->category) == eqe->category) &&
01361              ((s->send_events & eqe->category) == eqe->category)) {
01362             astman_append(s, "%s", eqe->eventdata);
01363          }
01364          unuse_eventqent(s->eventq);
01365          s->eventq = eqe;
01366       }
01367       astman_append(s,
01368          "Event: WaitEventComplete\r\n"
01369          "%s"
01370          "\r\n", idText);
01371       s->waiting_thread = AST_PTHREADT_NULL;
01372    } else {
01373       ast_log(LOG_DEBUG, "Abandoning event request!\n");
01374    }
01375    ast_mutex_unlock(&s->__lock);
01376    return 0;
01377 }

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

Definition at line 2618 of file manager.c.

References ast_malloc, eventqent::category, eventqent::eventdata, eventqent::next, and eventqent::usecount.

Referenced by init_manager(), and manager_event().

02619 {
02620    struct eventqent *tmp, *prev = NULL;
02621    tmp = ast_malloc(sizeof(*tmp) + strlen(str));
02622 
02623    if (!tmp)
02624       return -1;
02625 
02626    tmp->next = NULL;
02627    tmp->category = category;
02628    strcpy(tmp->eventdata, str);
02629    
02630    if (master_eventq) {
02631       prev = master_eventq;
02632       while (prev->next) 
02633          prev = prev->next;
02634       prev->next = tmp;
02635    } else {
02636       master_eventq = tmp;
02637    }
02638    
02639    tmp->usecount = num_sessions;
02640    
02641    return 0;
02642 }

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

Definition at line 493 of file manager.c.

References AST_LIST_TRAVERSE, ast_manager_user::username, and users.

Referenced by handle_showmanager(), and init_manager().

00494 {
00495    struct ast_manager_user *user = NULL;
00496 
00497    AST_LIST_TRAVERSE(&users, user, list)
00498       if (!strcasecmp(user->username, name))
00499          break;
00500    return user;
00501 }

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

References ast_variable::next.

Referenced by get_perm(), and strings_to_mask().

00886 {
00887    const char *val = bigstr, *next;
00888 
00889    do {
00890       if ((next = strchr(val, delim))) {
00891          if (!strncmp(val, smallstr, (next - val)))
00892             return 1;
00893          else
00894             continue;
00895       } else
00896          return !strcmp(smallstr, val);
00897 
00898    } while (*(val = (next + 1)));
00899 
00900    return 0;
00901 }

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

Definition at line 918 of file manager.c.

Referenced by strings_to_mask().

00919 {
00920    int ret = 1, x = 0;
00921 
00922    if (!string)
00923       return 0;
00924 
00925    for (x = 0; x < strlen(string); x++) {
00926       if (!(string[x] >= 48 && string[x] <= 57)) {
00927          ret = 0;
00928          break;
00929       }
00930    }
00931    
00932    return ret ? atoi(string) : 0;
00933 }

static AST_LIST_HEAD_STATIC ( users  ,
ast_manager_user   
) [static]

static AST_LIST_HEAD_STATIC ( sessions  ,
mansession   
) [static]

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

Register a manager command with the manager interface

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

References manager_action::action, ast_malloc, ast_manager_register_struct(), manager_action::authority, manager_action::description, func, manager_action::func, manager_action::next, and manager_action::synopsis.

Referenced by init_manager(), and load_module().

02774 {
02775    struct manager_action *cur;
02776 
02777    cur = ast_malloc(sizeof(*cur));
02778    if (!cur)
02779       return -1;
02780    
02781    cur->action = action;
02782    cur->authority = auth;
02783    cur->func = func;
02784    cur->synopsis = synopsis;
02785    cur->description = description;
02786    cur->next = NULL;
02787 
02788    ast_manager_register_struct(cur);
02789 
02790    return 0;
02791 }

static int ast_manager_register_struct ( struct manager_action act  )  [static]

Definition at line 2729 of file manager.c.

References manager_action::action, ast_log(), ast_rwlock_unlock(), ast_rwlock_wrlock(), ast_verbose(), first_action, LOG_WARNING, manager_action::next, option_verbose, and VERBOSE_PREFIX_2.

Referenced by ast_manager_register2().

02730 {
02731    struct manager_action *cur, *prev = NULL;
02732    int ret;
02733 
02734    ast_rwlock_wrlock(&actionlock);
02735    cur = first_action;
02736    while (cur) { /* Walk the list of actions */
02737       ret = strcasecmp(cur->action, act->action);
02738       if (ret == 0) {
02739          ast_log(LOG_WARNING, "Manager: Action '%s' already registered\n", act->action);
02740          ast_rwlock_unlock(&actionlock);
02741          return -1;
02742       } else if (ret > 0) {
02743          /* Insert these alphabetically */
02744          if (prev) {
02745             act->next = prev->next;
02746             prev->next = act;
02747          } else {
02748             act->next = first_action;
02749             first_action = act;
02750          }
02751          break;
02752       }
02753       prev = cur; 
02754       cur = cur->next;
02755    }
02756    
02757    if (!cur) {
02758       if (prev)
02759          prev->next = act;
02760       else
02761          first_action = act;
02762       act->next = NULL;
02763    }
02764 
02765    if (option_verbose > 1) 
02766       ast_verbose(VERBOSE_PREFIX_2 "Manager registered action %s\n", act->action);
02767    ast_rwlock_unlock(&actionlock);
02768    return 0;
02769 }

int ast_manager_unregister ( char *  action  ) 

Unregister a registred manager command

Parameters:
action Name of registred Action:

Definition at line 2698 of file manager.c.

References manager_action::action, ast_rwlock_unlock(), ast_rwlock_wrlock(), ast_verbose(), first_action, free, manager_action::next, option_verbose, and VERBOSE_PREFIX_2.

Referenced by __unload_module(), and unload_module().

02699 {
02700    struct manager_action *cur, *prev;
02701 
02702    ast_rwlock_wrlock(&actionlock);
02703    cur = prev = first_action;
02704    while (cur) {
02705       if (!strcasecmp(action, cur->action)) {
02706          prev->next = cur->next;
02707          free(cur);
02708          if (option_verbose > 1) 
02709             ast_verbose(VERBOSE_PREFIX_2 "Manager unregistered action %s\n", action);
02710          ast_rwlock_unlock(&actionlock);
02711          return 0;
02712       }
02713       prev = cur;
02714       cur = cur->next;
02715    }
02716    ast_rwlock_unlock(&actionlock);
02717    return 0;
02718 }

AST_RWLOCK_DEFINE_STATIC ( actionlock   ) 

AST_THREADSTORAGE ( astman_append_buf  ,
astman_append_buf_init   
)

AST_THREADSTORAGE ( manager_event_buf  ,
manager_event_buf_init   
)

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

Definition at line 503 of file manager.c.

References mansession::__lock, ast_calloc, ast_carefulwrite(), ast_dynamic_str_thread_set_va, ast_mutex_lock(), ast_mutex_unlock(), ASTMAN_APPEND_BUF_INITSIZE, mansession::fd, mansession::outputstr, and mansession::writetimeout.

Referenced by __iax2_show_peers(), __queues_show(), _sip_show_peer(), _sip_show_peers(), action_agents(), action_command(), action_devstate(), action_extensionstate(), action_getconfig(), action_getvar(), action_listcommands(), action_mailboxcount(), action_mailboxstatus(), action_status(), action_updateconfig(), action_waitevent(), action_zapshowchannels(), 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().

00504 {
00505    va_list ap;
00506    struct ast_dynamic_str *buf;
00507 
00508    ast_mutex_lock(&s->__lock);
00509 
00510    if (!(buf = ast_dynamic_str_thread_get(&astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE))) {
00511       ast_mutex_unlock(&s->__lock);
00512       return;
00513    }
00514 
00515    va_start(ap, fmt);
00516    ast_dynamic_str_thread_set_va(&buf, 0, &astman_append_buf, fmt, ap);
00517    va_end(ap);
00518    
00519    if (s->fd > -1) {
00520       int res;
00521 
00522       res = ast_carefulwrite(s->fd, buf->str, strlen(buf->str), s->writetimeout);
00523       if (res) {
00524          s->write_error = 1;
00525       }
00526    } else {
00527       if (!s->outputstr && !(s->outputstr = ast_calloc(1, sizeof(*s->outputstr)))) {
00528          ast_mutex_unlock(&s->__lock);
00529          return;
00530       }
00531 
00532       ast_dynamic_str_append(&s->outputstr, 0, "%s", buf->str);   
00533    }
00534 
00535    ast_mutex_unlock(&s->__lock);
00536 }

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

Get header from mananger transaction

Definition at line 788 of file manager.c.

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

Referenced by _sip_show_peer(), _sip_show_peers(), action_agent_callback_login(), action_agent_logoff(), action_agents(), action_bridge(), action_command(), action_devstate(), action_events(), action_extensionstate(), action_getconfig(), action_getvar(), action_hangup(), action_listcommands(), action_mailboxcount(), action_mailboxstatus(), action_message(), action_originate(), action_redirect(), action_setcdruserfield(), action_setvar(), action_status(), action_timeout(), action_transfer(), action_transferhangup(), action_updateconfig(), action_userevent(), action_waitevent(), action_zapdialoffhook(), action_zapdndoff(), action_zapdndon(), action_zapshowchannels(), astman_send_error(), astman_send_response(), authenticate(), change_monitor_action(), do_pause_or_unpause(), handle_updates(), manager_add_queue_member(), manager_dbdel(), manager_dbget(), manager_dbput(), manager_iax2_show_peers(), manager_jabber_send(), manager_park(), manager_parking_status(), manager_pause_queue_member(), manager_play_dtmf(), 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().

00789 {
00790    char cmp[80];
00791    int x;
00792 
00793    snprintf(cmp, sizeof(cmp), "%s: ", var);
00794 
00795    for (x = 0; x < m->hdrcount; x++) {
00796       if (!strncasecmp(cmp, m->headers[x], strlen(cmp)))
00797          return m->headers[x] + strlen(cmp);
00798    }
00799 
00800    return "";
00801 }

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

Get a linked list of the Variable: headers

Definition at line 803 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(), strsep(), and var.

Referenced by action_originate().

00804 {
00805    int varlen, x, y;
00806    struct ast_variable *head = NULL, *cur;
00807    char *var, *val;
00808 
00809    char *parse;    
00810    AST_DECLARE_APP_ARGS(args,
00811       AST_APP_ARG(vars)[32];
00812    );
00813 
00814    varlen = strlen("Variable: ");   
00815 
00816    for (x = 0; x < m->hdrcount; x++) {
00817       if (strncasecmp("Variable: ", m->headers[x], varlen))
00818          continue;
00819 
00820       parse = ast_strdupa(m->headers[x] + varlen);
00821 
00822       AST_STANDARD_APP_ARGS(args, parse);
00823       if (args.argc) {
00824          for (y = 0; y < args.argc; y++) {
00825             if (!args.vars[y])
00826                continue;
00827             var = val = ast_strdupa(args.vars[y]);
00828             strsep(&val, "=");
00829             if (!val || ast_strlen_zero(var))
00830                continue;
00831             cur = ast_variable_new(var, val);
00832             if (head) {
00833                cur->next = head;
00834                head = cur;
00835             } else
00836                head = cur;
00837          }
00838       }
00839    }
00840 
00841    return head;
00842 }

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 
)

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

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

Referenced by _sip_show_peer(), action_agent_callback_login(), action_agent_logoff(), action_bridge(), action_command(), action_devstate(), action_extensionstate(), action_getconfig(), action_getvar(), action_hangup(), action_mailboxcount(), action_mailboxstatus(), action_message(), action_originate(), action_redirect(), action_setcdruserfield(), action_setvar(), action_status(), action_timeout(), action_transfer(), action_transferhangup(), action_updateconfig(), action_zapdialoffhook(), action_zapdndoff(), action_zapdndon(), action_zaprestart(), change_monitor_action(), do_pause_or_unpause(), manager_add_queue_member(), manager_dbdel(), manager_dbget(), manager_dbput(), manager_jabber_send(), manager_park(), manager_pause_queue_member(), manager_play_dtmf(), manager_remove_queue_member(), manager_sip_show_peer(), meetmemute(), process_message(), start_monitor_action(), and stop_monitor_action().

00853 {
00854    const char *id = astman_get_header(m,"ActionID");
00855 
00856    astman_append(s, "Response: Error\r\n");
00857    if (!ast_strlen_zero(id))
00858       astman_append(s, "ActionID: %s\r\n", id);
00859    astman_append(s, "Message: %s\r\n\r\n", error);
00860 }

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

Definition at line 862 of file manager.c.

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

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

00863 {
00864    const char *id = astman_get_header(m,"ActionID");
00865 
00866    astman_append(s, "Response: %s\r\n", resp);
00867    if (!ast_strlen_zero(id))
00868       astman_append(s, "ActionID: %s\r\n", id);
00869    if (msg)
00870       astman_append(s, "Message: %s\r\n\r\n", msg);
00871    else
00872       astman_append(s, "\r\n");
00873 }

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

Definition at line 978 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(), ast_variable_retrieve(), astman_get_header(), mansession::challenge, mansession::displaysystemname, events, get_perm(), len, ast_variable::lineno, LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, MD5Final(), MD5Init(), MD5Update(), ast_variable::name, ast_variable::next, password, mansession::readperm, S_OR, set_eventmask(), mansession::sin, mansession::username, ast_variable::value, mansession::writeperm, and mansession::writetimeout.

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

00979 {
00980    struct ast_config *cfg;
00981    char *cat;
00982    const char *user = astman_get_header(m, "Username");
00983    const char *pass = astman_get_header(m, "Secret");
00984    const char *authtype = astman_get_header(m, "AuthType");
00985    const char *key = astman_get_header(m, "Key");
00986    const char *events = astman_get_header(m, "Events");
00987    
00988    cfg = ast_config_load("manager.conf");
00989    if (!cfg)
00990       return -1;
00991    cat = ast_category_browse(cfg, NULL);
00992    while (cat) {
00993       if (strcasecmp(cat, "general")) {
00994          /* This is a user */
00995          if (!strcasecmp(cat, user)) {
00996             struct ast_variable *v;
00997             struct ast_ha *ha = NULL;
00998             char *password = NULL;
00999 
01000             for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
01001                if (!strcasecmp(v->name, "secret")) {
01002                   password = v->value;
01003                } else if (!strcasecmp(v->name, "displaysystemname")) {
01004                   if (ast_true(v->value)) {
01005                      if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) {
01006                         s->displaysystemname = 1;
01007                      } else {
01008                         ast_log(LOG_ERROR, "Can't enable displaysystemname in manager.conf - no system name configured in asterisk.conf\n");
01009                      }
01010                   }
01011                } else if (!strcasecmp(v->name, "permit") ||
01012                      !strcasecmp(v->name, "deny")) {
01013                   ha = ast_append_ha(v->name, v->value, ha);
01014                } else if (!strcasecmp(v->name, "writetimeout")) {
01015                   int val = atoi(v->value);
01016 
01017                   if (val < 100)
01018                      ast_log(LOG_WARNING, "Invalid writetimeout value '%s' at line %d\n", v->value, v->lineno);
01019                   else
01020                      s->writetimeout = val;
01021                }
01022                      
01023             }
01024             if (ha && !ast_apply_ha(ha, &(s->sin))) {
01025                ast_log(LOG_NOTICE, "%s failed to pass IP ACL as '%s'\n", ast_inet_ntoa(s->sin.sin_addr), user);
01026                ast_free_ha(ha);
01027                ast_config_destroy(cfg);
01028                return -1;
01029             } else if (ha)
01030                ast_free_ha(ha);
01031             if (!strcasecmp(authtype, "MD5")) {
01032                if (!ast_strlen_zero(key) && 
01033                    !ast_strlen_zero(s->challenge) && !ast_strlen_zero(password)) {
01034                   int x;
01035                   int len = 0;
01036                   char md5key[256] = "";
01037                   struct MD5Context md5;
01038                   unsigned char digest[16];
01039                   MD5Init(&md5);
01040                   MD5Update(&md5, (unsigned char *) s->challenge, strlen(s->challenge));
01041                   MD5Update(&md5, (unsigned char *) password, strlen(password));
01042                   MD5Final(digest, &md5);
01043                   for (x=0; x<16; x++)
01044                      len += sprintf(md5key + len, "%2.2x", digest[x]);
01045                   if (!strcmp(md5key, key))
01046                      break;
01047                   else {
01048                      ast_config_destroy(cfg);
01049                      return -1;
01050                   }
01051                } else {
01052                   ast_log(LOG_DEBUG, "MD5 authentication is not possible.  challenge: '%s'\n", 
01053                      S_OR(s->challenge, ""));
01054                   ast_config_destroy(cfg);
01055                   return -1;
01056                }
01057             } else if (password && !strcmp(password, pass)) {
01058                break;
01059             } else {
01060                ast_log(LOG_NOTICE, "%s failed to authenticate as '%s'\n", ast_inet_ntoa(s->sin.sin_addr), user);
01061                ast_config_destroy(cfg);
01062                return -1;
01063             }  
01064          }
01065       }
01066       cat = ast_category_browse(cfg, cat);
01067    }
01068    if (cat) {
01069       ast_copy_string(s->username, cat, sizeof(s->username));
01070       s->readperm = get_perm(ast_variable_retrieve(cfg, cat, "read"));
01071       s->writeperm = get_perm(ast_variable_retrieve(cfg, cat, "write"));
01072       ast_config_destroy(cfg);
01073       if (events)
01074          set_eventmask(s, events);
01075       return 0;
01076    }
01077    ast_config_destroy(cfg);
01078    cfg = ast_config_load("users.conf");
01079    if (!cfg)
01080       return -1;
01081    cat = ast_category_browse(cfg, NULL);
01082    while (cat) {
01083       struct ast_variable *v;
01084       const char *password = NULL;
01085       int hasmanager = 0;
01086       const char *readperms = NULL;
01087       const char *writeperms = NULL;
01088 
01089       if (strcasecmp(cat, user) || !strcasecmp(cat, "general")) {
01090          cat = ast_category_browse(cfg, cat);
01091          continue;
01092       }
01093       for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
01094          if (!strcasecmp(v->name, "secret"))
01095             password = v->value;
01096          else if (!strcasecmp(v->name, "hasmanager"))
01097             hasmanager = ast_true(v->value);
01098          else if (!strcasecmp(v->name, "managerread"))
01099             readperms = v->value;
01100          else if (!strcasecmp(v->name, "managerwrite"))
01101             writeperms = v->value;
01102       }
01103       if (!hasmanager)
01104          break;
01105       if (!password || strcmp(password, pass)) {
01106          ast_log(LOG_NOTICE, "%s failed to authenticate as '%s'\n", ast_inet_ntoa(s->sin.sin_addr), user);
01107          ast_config_destroy(cfg);
01108          return -1;
01109       }
01110       ast_copy_string(s->username, cat, sizeof(s->username));
01111       s->readperm = readperms ? get_perm(readperms) : -1;
01112       s->writeperm = writeperms ? get_perm(writeperms) : -1;
01113       ast_config_destroy(cfg);
01114       if (events)
01115          set_eventmask(s, events);
01116       return 0;
01117    }
01118    ast_log(LOG_NOTICE, "%s tried to authenticate with nonexistent user '%s'\n", ast_inet_ntoa(s->sin.sin_addr), user);
01119    ast_config_destroy(cfg);
01120    return -1;
01121 }

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

Convert authority code to string with serveral options.

Definition at line 227 of file manager.c.

References ast_strlen_zero(), and perms.

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

00228 {
00229    int running_total = 0, i;
00230 
00231    memset(res, 0, reslen);
00232    for (i = 0; i < (sizeof(perms) / sizeof(perms[0])) - 1; i++) {
00233       if (authority & perms[i].num) {
00234          if (*res) {
00235             strncat(res, ",", (reslen > running_total) ? reslen - running_total - 1 : 0);
00236             running_total++;
00237          }
00238          strncat(res, perms[i].label, (reslen > running_total) ? reslen - running_total - 1 : 0);
00239          running_total += strlen(perms[i].label);
00240       }
00241    }
00242 
00243    if (ast_strlen_zero(res))
00244       ast_copy_string(res, "<none>", reslen);
00245    
00246    return res;
00247 }

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

Definition at line 1785 of file manager.c.

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

Referenced by action_command().

01786 {
01787    char *cmd_copy, *cur_cmd;
01788    char *cmd_words[MAX_BLACKLIST_CMD_LEN] = { NULL, };
01789    int i;
01790 
01791    cmd_copy = ast_strdupa(cmd);
01792    for (i = 0; i < MAX_BLACKLIST_CMD_LEN && (cur_cmd = strsep(&cmd_copy, " ")); i++) {
01793       cur_cmd = ast_strip(cur_cmd);
01794       if (ast_strlen_zero(cur_cmd)) {
01795          i--;
01796          continue;
01797       }
01798 
01799       cmd_words[i] = cur_cmd;
01800    }
01801 
01802    for (i = 0; i < ARRAY_LEN(command_blacklist); i++) {
01803       int j, match = 1;
01804 
01805       for (j = 0; command_blacklist[i].words[j]; j++) {
01806          if (ast_strlen_zero(cmd_words[j]) || strcasecmp(cmd_words[j], command_blacklist[i].words[j])) {
01807             match = 0;
01808             break;
01809          }
01810       }
01811 
01812       if (match) {
01813          return 1;
01814       }
01815    }
01816 
01817    return 0;
01818 }

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

Definition at line 249 of file manager.c.

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

00250 {
00251    struct manager_action *cur;
00252    int which = 0;
00253    char *ret = NULL;
00254 
00255    ast_rwlock_rdlock(&actionlock);
00256    for (cur = first_action; cur; cur = cur->next) { /* Walk the list of actions */
00257       if (!strncasecmp(word, cur->action, strlen(word)) && ++which > state) {
00258          ret = ast_strdup(cur->action);
00259          break;   /* make sure we exit even if ast_strdup() returns NULL */
00260       }
00261    }
00262    ast_rwlock_unlock(&actionlock);
00263 
00264    return ret;
00265 }

static int compress_char ( char  c  )  [static]

Definition at line 309 of file manager.c.

Referenced by member_hash_fn(), and variable_count_hash_fn().

00310 {
00311    c &= 0x7f;
00312    if (c < 32)
00313       return 0;
00314    else if (c >= 'a' && c <= 'z')
00315       return c - 64;
00316    else if (c > 'z')
00317       return '_';
00318    else
00319       return c - 32;
00320 }

static void destroy_session ( struct mansession s  )  [static]

Definition at line 779 of file manager.c.

References AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, and free_session().

Referenced by accept_thread(), generic_http_callback(), session_do(), and skinny_session().

00780 {
00781    AST_LIST_LOCK(&sessions);
00782    AST_LIST_REMOVE(&sessions, s, list);
00783    num_sessions--;
00784    free_session(s);
00785    AST_LIST_UNLOCK(&sessions);
00786 }

static int do_message ( struct mansession s  )  [static]

Definition at line 2419 of file manager.c.

References ast_inet_ntoa(), ast_log(), AST_MAX_MANHEADERS, ast_strdupa, ast_strlen_zero(), mansession::authenticated, mansession::authstart, errno, mansession::eventq, get_input(), message::hdrcount, message::headers, mansession::inbuf, LOG_ERROR, LOG_EVENT, eventqent::next, process_events(), process_message(), and mansession::sin.

Referenced by session_do().

02420 {
02421    struct message m = { 0 };
02422    char header_buf[sizeof(s->inbuf)] = { '\0' };
02423    int res;
02424    time_t now;
02425 
02426    for (;;) {
02427       /* Check if any events are pending and do them if needed */
02428       if (s->eventq->next) {
02429          if (process_events(s))
02430             return -1;
02431       }
02432       res = get_input(s, header_buf);
02433       if (res == 0) {
02434          if (!s->authenticated) {
02435             if(time(&now) == -1) {
02436                ast_log(LOG_ERROR, "error executing time(): %s\n", strerror(errno));
02437                return -1;
02438             }
02439 
02440             if (now - s->authstart > authtimeout) {
02441                ast_log(LOG_EVENT, "Client from %s, failed to authenticate in %d seconds\n", ast_inet_ntoa(s->sin.sin_addr), authtimeout);
02442                return -1;
02443             }
02444          }
02445          continue;
02446       } else if (res > 0) {
02447          /* Strip trailing \r\n */
02448          if (strlen(header_buf) < 2)
02449             continue;
02450          header_buf[strlen(header_buf) - 2] = '\0';
02451          if (ast_strlen_zero(header_buf))
02452             return process_message(s, &m) ? -1 : 0;
02453          else if (m.hdrcount < (AST_MAX_MANHEADERS - 1))
02454             m.headers[m.hdrcount++] = ast_strdupa(header_buf);
02455       } else {
02456          return res;
02457       }
02458    }
02459 }

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

Definition at line 1875 of file manager.c.

References fast_originate_helper::account, fast_originate_helper::app, fast_originate_helper::appdata, AST_CHANNEL_NAME, ast_channel_unlock, AST_FORMAT_SLINEAR, ast_pbx_outgoing_app_uniqueid(), ast_pbx_outgoing_exten_uniqueid(), ast_strlen_zero(), fast_originate_helper::callingpres, 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, free, fast_originate_helper::idtext, manager_event(), fast_originate_helper::priority, S_OR, fast_originate_helper::tech, fast_originate_helper::timeout, fast_originate_helper::uniqueid, and fast_originate_helper::vars.

Referenced by action_originate().

01876 {
01877    struct fast_originate_helper *in = data;
01878    int res;
01879    int reason = 0;
01880    struct ast_channel *chan = NULL;
01881    char requested_channel[AST_CHANNEL_NAME];
01882 
01883    if (!ast_strlen_zero(in->app)) {
01884       res = ast_pbx_outgoing_app_uniqueid(in->tech, AST_FORMAT_SLINEAR, in->data, in->timeout, in->app, in->appdata, &reason, 1, in->callingpres,
01885          S_OR(in->cid_num, NULL), 
01886          S_OR(in->cid_name, NULL),
01887          in->vars, in->account, &chan, in->uniqueid);
01888    } else {
01889       res = ast_pbx_outgoing_exten_uniqueid(in->tech, AST_FORMAT_SLINEAR, in->data, in->timeout, in->context, in->exten, in->priority, &reason, 1, in->callingpres,
01890          S_OR(in->cid_num, NULL), 
01891          S_OR(in->cid_name, NULL),
01892          in->vars, in->account, &chan, in->uniqueid);
01893    }
01894 
01895    if (!chan)
01896       snprintf(requested_channel, AST_CHANNEL_NAME, "%s/%s", in->tech, in->data);   
01897    /* Tell the manager what happened with the channel */
01898    manager_event(EVENT_FLAG_CALL, "OriginateResponse",
01899       "%s"
01900       "Response: %s\r\n"
01901       "Channel: %s\r\n"
01902       "Context: %s\r\n"
01903       "Exten: %s\r\n"
01904       "Reason: %d\r\n"
01905       "Uniqueid: %s\r\n"
01906       "CallerID: %s\r\n"      /* This parameter is deprecated and will be removed post-1.4 */
01907       "CallerIDNum: %s\r\n"
01908       "CallerIDName: %s\r\n",
01909       in->idtext, res ? "Failure" : "Success", chan ? chan->name : requested_channel, in->context, in->exten, reason, 
01910       chan ? chan->uniqueid : "<null>",
01911       S_OR(in->cid_num, "<unknown>"),
01912       S_OR(in->cid_num, "<unknown>"),
01913       S_OR(in->cid_name, "<unknown>")
01914       );
01915 
01916    /* Locked by ast_pbx_outgoing_exten or ast_pbx_outgoing_app */
01917    if (chan)
01918       ast_channel_unlock(chan);
01919    free(in);
01920    return NULL;
01921 }

static void free_session ( struct mansession s  )  [static]

Definition at line 763 of file manager.c.

References mansession::__lock, ast_mutex_destroy(), mansession::eventq, mansession::fd, free, eventqent::next, mansession::outputstr, and unuse_eventqent().

Referenced by accept_thread(), and destroy_session().

00764 {
00765    struct eventqent *eqe;
00766    if (s->fd > -1)
00767       close(s->fd);
00768    if (s->outputstr)
00769       free(s->outputstr);
00770    ast_mutex_destroy(&s->__lock);
00771    while (s->eventq) {
00772       eqe = s->eventq;
00773       s->eventq = s->eventq->next;
00774       unuse_eventqent(eqe);
00775    }
00776    free(s);
00777 }

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

Definition at line 2340 of file manager.c.

References mansession::__lock, ast_inet_ntoa(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), AST_PTHREADT_NULL, mansession::authenticated, mansession::authstart, errno, pollfd::events, mansession::fd, pollfd::fd, ast_channel::fds, mansession::inbuf, mansession::inlen, LOG_ERROR, LOG_WARNING, mansession::pending_event, poll(), POLLIN, mansession::sin, and mansession::waiting_thread.

Referenced by do_message(), and skinny_session().

02341 {
02342    /* output must have at least sizeof(s->inbuf) space */
02343    int res;
02344    int x;
02345    struct pollfd fds[1];
02346    int timeout = -1;
02347    time_t now;
02348    for (x = 1; x < s->inlen; x++) {
02349       if ((s->inbuf[x] == '\n') && (s->inbuf[x-1] == '\r')) {
02350          /* Copy output data up to and including \r\n */
02351          memcpy(output, s->inbuf, x + 1);
02352          /* Add trailing \0 */
02353          output[x+1] = '\0';
02354          /* Move remaining data back to the front */
02355          memmove(s->inbuf, s->inbuf + x + 1, s->inlen - x);
02356          s->inlen -= (x + 1);
02357          return 1;
02358       }
02359    } 
02360    if (s->inlen >= sizeof(s->inbuf) - 1) {
02361       ast_log(LOG_WARNING, "Dumping long line with no return from %s: %s\n", ast_inet_ntoa(s->sin.sin_addr), s->inbuf);
02362       s->inlen = 0;
02363    }
02364    fds[0].fd = s->fd;
02365    fds[0].events = POLLIN;
02366 
02367    do {
02368       /* calculate a timeout if we are not authenticated */
02369       if (!s->authenticated) {
02370          if(time(&now) == -1) {
02371             ast_log(LOG_ERROR, "error executing time(): %s\n", strerror(errno));
02372             return -1;
02373          }
02374 
02375          timeout = (authtimeout - (now - s->authstart)) * 1000;
02376          if (timeout < 0) {
02377             /* we have timed out */
02378             return 0;
02379          }
02380       }
02381 
02382       ast_mutex_lock(&s->__lock);
02383       if (s->pending_event) {
02384          s->pending_event = 0;
02385          ast_mutex_unlock(&s->__lock);
02386          return 0;
02387       }
02388       s->waiting_thread = pthread_self();
02389       ast_mutex_unlock(&s->__lock);
02390 
02391       res = poll(fds, 1, timeout);
02392 
02393       ast_mutex_lock(&s->__lock);
02394       s->waiting_thread = AST_PTHREADT_NULL;
02395       ast_mutex_unlock(&s->__lock);
02396       if (res < 0) {
02397          if (errno == EINTR || errno == EAGAIN) {
02398             return 0;
02399          }
02400          ast_log(LOG_WARNING, "Select returned error: %s\n", strerror(errno));
02401          return -1;
02402       } else if (res > 0) {
02403          ast_mutex_lock(&s->__lock);
02404          res = read(s->fd, s->inbuf + s->inlen, sizeof(s->inbuf) - 1 - s->inlen);
02405          ast_mutex_unlock(&s->__lock);
02406          if (res < 1)
02407             return -1;
02408          break;
02409       } else {
02410          /* timeout */
02411          return 0;
02412       }
02413    } while(1);
02414    s->inlen += res;
02415    s->inbuf[s->inlen] = '\0';
02416    return 0;
02417 }

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

Definition at line 903 of file manager.c.

References ast_instring(), and perms.

Referenced by authenticate().

00904 {
00905    int x = 0, ret = 0;
00906 
00907    if (!instr)
00908       return 0;
00909 
00910    for (x = 0; x < (sizeof(perms) / sizeof(perms[0])); x++) {
00911       if (ast_instring(instr, perms[x].label, ','))
00912          ret |= perms[x].num;
00913    }
00914    
00915    return ret;
00916 }

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

Definition at line 560 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, users, and ast_manager_user::write.

00561 {
00562    struct ast_manager_user *user = NULL;
00563 
00564    if (argc != 4)
00565       return RESULT_SHOWUSAGE;
00566 
00567    AST_LIST_LOCK(&users);
00568 
00569    if (!(user = ast_get_manager_by_name_locked(argv[3]))) {
00570       ast_cli(fd, "There is no manager called %s\n", argv[3]);
00571       AST_LIST_UNLOCK(&users);
00572       return -1;
00573    }
00574 
00575    ast_cli(fd,"\n");
00576    ast_cli(fd,
00577       "       username: %s\n"
00578       "         secret: %s\n"
00579       "           deny: %s\n"
00580       "         permit: %s\n"
00581       "           read: %s\n"
00582       "          write: %s\n"
00583       "displayconnects: %s\n",
00584       (user->username ? user->username : "(N/A)"),
00585       (user->secret ? "<Set>" : "(N/A)"),
00586       (user->deny ? user->deny : "(N/A)"),
00587       (user->permit ? user->permit : "(N/A)"),
00588       (user->read ? user->read : "(N/A)"),
00589       (user->write ? user->write : "(N/A)"),
00590       (user->displayconnects ? "yes" : "no"));
00591 
00592    AST_LIST_UNLOCK(&users);
00593 
00594    return RESULT_SUCCESS;
00595 }

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

Definition at line 598 of file manager.c.

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

00599 {
00600    struct ast_manager_user *user = NULL;
00601    int count_amu = 0;
00602 
00603    if (argc != 3)
00604       return RESULT_SHOWUSAGE;
00605 
00606    AST_LIST_LOCK(&users);
00607 
00608    /* If there are no users, print out something along those lines */
00609    if (AST_LIST_EMPTY(&users)) {
00610       ast_cli(fd, "There are no manager users.\n");
00611       AST_LIST_UNLOCK(&users);
00612       return RESULT_SUCCESS;
00613    }
00614 
00615    ast_cli(fd, "\nusername\n--------\n");
00616 
00617    AST_LIST_TRAVERSE(&users, user, list) {
00618       ast_cli(fd, "%s\n", user->username);
00619       count_amu++;
00620    }
00621 
00622    AST_LIST_UNLOCK(&users);
00623 
00624    ast_cli(fd,"-------------------\n");
00625    ast_cli(fd,"%d manager users configured.\n", count_amu);
00626 
00627    return RESULT_SUCCESS;
00628 }

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

Definition at line 538 of file manager.c.

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

00539 {
00540    struct manager_action *cur;
00541    char authority[80];
00542    int num;
00543 
00544    if (argc != 4)
00545       return RESULT_SHOWUSAGE;
00546 
00547    ast_rwlock_rdlock(&actionlock);
00548    for (cur = first_action; cur; cur = cur->next) { /* Walk the list of actions */
00549       for (num = 3; num < argc; num++) {
00550          if (!strcasecmp(cur->action, argv[num])) {
00551             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 : "");
00552          }
00553       }
00554    }
00555    ast_rwlock_unlock(&actionlock);
00556 
00557    return RESULT_SUCCESS;
00558 }

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

CLI command Should change to "manager show commands".

Definition at line 633 of file manager.c.

References manager_action::action, 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.

00634 {
00635    struct manager_action *cur;
00636    char authority[80];
00637    char *format = "  %-15.15s  %-15.15s  %-55.55s\n";
00638 
00639    ast_cli(fd, format, "Action", "Privilege", "Synopsis");
00640    ast_cli(fd, format, "------", "---------", "--------");
00641    
00642    ast_rwlock_rdlock(&actionlock);
00643    for (cur = first_action; cur; cur = cur->next) /* Walk the list of actions */
00644       ast_cli(fd, format, cur->action, authority_to_str(cur->authority, authority, sizeof(authority) -1), cur->synopsis);
00645    ast_rwlock_unlock(&actionlock);
00646    
00647    return RESULT_SUCCESS;
00648 }

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

CLI command show manager connected.

Definition at line 652 of file manager.c.

References ast_cli(), ast_inet_ntoa(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, format, RESULT_SUCCESS, s, mansession::sin, and mansession::username.

00653 {
00654    struct mansession *s;
00655    char *format = "  %-15.15s  %-15.15s\n";
00656 
00657    ast_cli(fd, format, "Username", "IP Address");
00658    
00659    AST_LIST_LOCK(&sessions);
00660    AST_LIST_TRAVERSE(&sessions, s, list)
00661       ast_cli(fd, format,s->username, ast_inet_ntoa(s->sin.sin_addr));
00662    AST_LIST_UNLOCK(&sessions);
00663 
00664    return RESULT_SUCCESS;
00665 }

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

CLI command show manager connected.

Definition at line 669 of file manager.c.

References ast_cli(), AST_LIST_LOCK, AST_LIST_UNLOCK, eventqent::category, eventqent::eventdata, eventqent::next, RESULT_SUCCESS, s, and eventqent::usecount.

00670 {
00671    struct eventqent *s;
00672 
00673    AST_LIST_LOCK(&sessions);
00674    for (s = master_eventq; s; s = s->next) {
00675       ast_cli(fd, "Usecount: %d\n",s->usecount);
00676       ast_cli(fd, "Category: %d\n", s->category);
00677       ast_cli(fd, "Event:\n%s", s->eventdata);
00678    }
00679    AST_LIST_UNLOCK(&sessions);
00680 
00681    return RESULT_SUCCESS;
00682 }

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

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

01179 {
01180    int x;
01181    char hdr[40];
01182    const char *action, *cat, *var, *value, *match;
01183    struct ast_category *category;
01184    struct ast_variable *v;
01185    
01186    for (x=0;x<100000;x++) {
01187       unsigned int object = 0;
01188 
01189       snprintf(hdr, sizeof(hdr), "Action-%06d", x);
01190       action = astman_get_header(m, hdr);
01191       if (ast_strlen_zero(action))
01192          break;
01193       snprintf(hdr, sizeof(hdr), "Cat-%06d", x);
01194       cat = astman_get_header(m, hdr);
01195       snprintf(hdr, sizeof(hdr), "Var-%06d", x);
01196       var = astman_get_header(m, hdr);
01197       snprintf(hdr, sizeof(hdr), "Value-%06d", x);
01198       value = astman_get_header(m, hdr);
01199       if (!ast_strlen_zero(value) && *value == '>') {
01200          object = 1;
01201          value++;
01202       }
01203       snprintf(hdr, sizeof(hdr), "Match-%06d", x);
01204       match = astman_get_header(m, hdr);
01205       if (!strcasecmp(action, "newcat")) {
01206          if (!ast_strlen_zero(cat)) {
01207             category = ast_category_new(cat);
01208             if (category) {
01209                ast_category_append(cfg, category);
01210             }
01211          }
01212       } else if (!strcasecmp(action, "renamecat")) {
01213          if (!ast_strlen_zero(cat) && !ast_strlen_zero(value)) {
01214             category = ast_category_get(cfg, cat);
01215             if (category) 
01216                ast_category_rename(category, value);
01217          }
01218       } else if (!strcasecmp(action, "delcat")) {
01219          if (!ast_strlen_zero(cat))
01220             ast_category_delete(cfg, (char *) cat);
01221       } else if (!strcasecmp(action, "update")) {
01222          if (!ast_strlen_zero(cat) && !ast_strlen_zero(var) && (category = ast_category_get(cfg, cat)))
01223             ast_variable_update(category, var, value, match, object);
01224       } else if (!strcasecmp(action, "delete")) {
01225          if (!ast_strlen_zero(cat) && !ast_strlen_zero(var) && (category = ast_category_get(cfg, cat)))
01226             ast_variable_delete(category, (char *) var, (char *) match);
01227       } else if (!strcasecmp(action, "append")) {
01228          if (!ast_strlen_zero(cat) && !ast_strlen_zero(var) && 
01229             (category = ast_category_get(cfg, cat)) && 
01230             (v = ast_variable_new(var, value))){
01231             if (object || (match && !strcasecmp(match, "object")))
01232                v->object = 1;
01233             ast_variable_append(category, v);
01234          }
01235       }
01236    }
01237 }

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

Definition at line 444 of file manager.c.

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

Referenced by generic_http_callback().

00445 {
00446    int x;
00447    int colons = 0;
00448    int breaks = 0;
00449    size_t len;
00450    int count = 1;
00451    char *tmp, *var, *val, *out;
00452 
00453    for (x=0; in[x]; x++) {
00454       if (in[x] == ':')
00455          colons++;
00456       if (in[x] == '\n')
00457          breaks++;
00458    }
00459    len = strlen(in) + colons * 40 + breaks * 40; /* <tr><td></td><td></td></tr>, "<tr><td colspan=\"2\"><hr></td></tr> */
00460    out = ast_malloc(len);
00461    if (!out)
00462       return 0;
00463    tmp = out;
00464    while (*in) {
00465       var = in;
00466       while (*in && (*in >= 32))
00467          in++;
00468       if (*in) {
00469          if ((count % 4) == 0){
00470             ast_build_string(&tmp, &len, "<tr><td colspan=\"2\"><hr></td></tr>\r\n");
00471          }
00472          count = 0;
00473          while (*in && (*in < 32)) {
00474             *in = '\0';
00475             in++;
00476             count++;
00477          }
00478          val = strchr(var, ':');
00479          if (val) {
00480             *val = '\0';
00481             val++;
00482             if (*val == ' ')
00483                val++;
00484             ast_build_string(&tmp, &len, "<tr><td>%s</td><td>%s</td></tr>\r\n", var, val);
00485          }
00486       }
00487    }
00488    return out;
00489 }

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

manager_event: Send AMI event to client

Definition at line 2645 of file manager.c.

References mansession::__lock, append_event(), ast_dynamic_str_thread_append(), ast_dynamic_str_thread_append_va, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_mutex_lock(), ast_mutex_unlock(), AST_PTHREADT_NULL, authority_to_str(), MANAGER_EVENT_BUF_INITSIZE, mansession::pending_event, s, and mansession::waiting_thread.

Referenced by __expire_registry(), __iax2_poke_noanswer(), __login_exec(), action_agent_callback_login(), action_userevent(), add_to_queue(), agent_logoff_maintenance(), aji_log_hook(), ast_autoanswer_login(), ast_change_name(), ast_channel_alloc(), ast_channel_bridge(), ast_do_masquerade(), ast_hangup(), ast_hold_call(), ast_log(), ast_monitor_stop(), ast_set_callerid(), ast_setstate_and_callerid(), autoanswer_exec(), bridge_exec(), change_hold_state(), conf_run(), do_autoanswer_thread(), expire_register(), fast_originate(), handle_init_event(), handle_response_peerpoke(), handle_response_register(), iax2_ack_registry(), join_queue(), leave_queue(), 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_config(), reload_logger(), reload_manager(), remove_from_queue(), ring_entry(), senddialevent(), set_member_paused(), sip_poke_noanswer(), sip_reg_timeout(), socket_process(), ss_thread(), try_calling(), update_registry(), update_status(), userevent_exec(), vm_execmain(), and zt_handle_event().

02646 {
02647    struct mansession *s;
02648    char auth[80];
02649    va_list ap;
02650    struct timeval now;
02651    struct ast_dynamic_str *buf;
02652 
02653    /* Abort if there aren't any manager sessions */
02654    if (!num_sessions)
02655       return 0;
02656 
02657    if (!(buf = ast_dynamic_str_thread_get(&manager_event_buf, MANAGER_EVENT_BUF_INITSIZE)))
02658       return -1;
02659 
02660    ast_dynamic_str_thread_set(&buf, 0, &manager_event_buf,
02661          "Event: %s\r\nPrivilege: %s\r\n",
02662           event, authority_to_str(category, auth, sizeof(auth)));
02663 
02664    if (timestampevents) {
02665       now = ast_tvnow();
02666       ast_dynamic_str_thread_append(&buf, 0, &manager_event_buf,
02667             "Timestamp: %ld.%06lu\r\n",
02668              now.tv_sec, (unsigned long) now.tv_usec);
02669    }
02670 
02671    va_start(ap, fmt);
02672    ast_dynamic_str_thread_append_va(&buf, 0, &manager_event_buf, fmt, ap);
02673    va_end(ap);
02674    
02675    ast_dynamic_str_thread_append(&buf, 0, &manager_event_buf, "\r\n");  
02676    
02677    /* Append event to master list and wake up any sleeping sessions */
02678    AST_LIST_LOCK(&sessions);
02679    append_event(buf->str, category);
02680    AST_LIST_TRAVERSE(&sessions, s, list) {
02681       ast_mutex_lock(&s->__lock);
02682       if (s->waiting_thread != AST_PTHREADT_NULL)
02683          pthread_kill(s->waiting_thread, SIGURG);
02684       else
02685          /* We have an event to process, but the mansession is
02686           * not waiting for it. We still need to indicate that there
02687           * is an event waiting so that get_input processes the pending
02688           * event instead of polling.
02689           */
02690          s->pending_event = 1;
02691       ast_mutex_unlock(&s->__lock);
02692    }
02693    AST_LIST_UNLOCK(&sessions);
02694 
02695    return 0;
02696 }

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

Definition at line 2720 of file manager.c.

References ast_get_hint(), EVENT_FLAG_EXTENSIONSTATUS, and manager_event().

Referenced by init_manager().

02721 {
02722    char hint[256] = "";
02723    ast_get_hint(hint, sizeof(hint) - 1, NULL, 0, NULL, context, exten);
02724    /* Notify managers of change */
02725    manager_event(EVENT_FLAG_EXTENSIONSTATUS, "ExtensionStatus", "Exten: %s\r\nContext: %s\r\nStatus: %d\r\nCallerID: \"%s\" <%s>\r\nHint: %s\r\n", exten, context, state, cid_num, cid_name, hint);
02726    return 0;
02727 }

static int process_events ( struct mansession s  )  [static]

Definition at line 2206 of file manager.c.

References mansession::__lock, ast_calloc, ast_carefulwrite(), ast_mutex_lock(), ast_mutex_unlock(), mansession::authenticated, eventqent::category, eventqent::eventdata, mansession::eventq, mansession::fd, eventqent::next, mansession::outputstr, mansession::readperm, mansession::send_events, unuse_eventqent(), and mansession::writetimeout.

Referenced by do_message(), and process_message().

02207 {
02208    struct eventqent *eqe;
02209    int ret = 0;
02210    ast_mutex_lock(&s->__lock);
02211    if (!s->eventq)
02212       s->eventq = master_eventq;
02213    while(s->eventq->next) {
02214       eqe = s->eventq->next;
02215       if ((s->authenticated && (s->readperm & eqe->category) == eqe->category) &&
02216                ((s->send_events & eqe->category) == eqe->category)) {
02217          if (s->fd > -1) {
02218             if (!ret && ast_carefulwrite(s->fd, eqe->eventdata, strlen(eqe->eventdata), s->writetimeout) < 0)
02219                ret = -1;
02220          } else if (!s->outputstr && !(s->outputstr = ast_calloc(1, sizeof(*s->outputstr)))) 
02221             ret = -1;
02222          else 
02223             ast_dynamic_str_append(&s->outputstr, 0, "%s", eqe->eventdata);
02224       }
02225       unuse_eventqent(s->eventq);
02226       s->eventq = eqe;
02227    }
02228    ast_mutex_unlock(&s->__lock);
02229    return ret;
02230 }

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

Definition at line 2257 of file manager.c.

References manager_action::action, ast_inet_ntoa(), ast_log(), ast_random(), ast_rwlock_rdlock(), ast_rwlock_unlock(), ast_strlen_zero(), ast_verbose(), astman_append(), astman_get_header(), astman_send_ack(), astman_send_error(), authenticate(), mansession::authenticated, manager_action::authority, mansession::challenge, first_action, manager_action::func, LOG_DEBUG, LOG_EVENT, manager_action::next, option_debug, option_verbose, process_events(), mansession::sessiontimeout, mansession::sin, mansession::username, VERBOSE_PREFIX_2, and mansession::writeperm.

Referenced by do_message(), and generic_http_callback().

02258 {
02259    char action[80] = "";
02260    struct manager_action *tmp;
02261    const char *id = astman_get_header(m,"ActionID");
02262    char idText[256] = "";
02263    int ret = 0;
02264 
02265    ast_copy_string(action, astman_get_header(m, "Action"), sizeof(action));
02266    if (option_debug)
02267       ast_log( LOG_DEBUG, "Manager received command '%s'\n", action );
02268 
02269    if (ast_strlen_zero(action)) {
02270       astman_send_error(s, m, "Missing action in request");
02271       return 0;
02272    }
02273    if (!ast_strlen_zero(id)) {
02274       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
02275    }
02276    if (!s->authenticated) {
02277       if (!strcasecmp(action, "Challenge")) {
02278          const char *authtype = astman_get_header(m, "AuthType");
02279 
02280          if (!strcasecmp(authtype, "MD5")) {
02281             if (ast_strlen_zero(s->challenge))
02282                snprintf(s->challenge, sizeof(s->challenge), "%ld", ast_random());
02283             astman_append(s, "Response: Success\r\n"
02284                   "%s"
02285                   "Challenge: %s\r\n\r\n",
02286                   idText, s->challenge);
02287             return 0;
02288          } else {
02289             astman_send_error(s, m, "Must specify AuthType");
02290             return 0;
02291          }
02292       } else if (!strcasecmp(action, "Login")) {
02293          if (authenticate(s, m)) {
02294             sleep(1);
02295             astman_send_error(s, m, "Authentication failed");
02296             return -1;
02297          } else {
02298             s->authenticated = 1;
02299             ast_atomic_fetchadd_int(&unauth_sessions, -1);
02300             if (option_verbose > 1) {
02301                if (displayconnects) {
02302                   ast_verbose(VERBOSE_PREFIX_2 "%sManager '%s' logged on from %s\n", 
02303                      (s->sessiontimeout ? "HTTP " : ""), s->username, ast_inet_ntoa(s->sin.sin_addr));
02304                }
02305             }
02306             ast_log(LOG_EVENT, "%sManager '%s' logged on from %s\n", 
02307                (s->sessiontimeout ? "HTTP " : ""), s->username, ast_inet_ntoa(s->sin.sin_addr));
02308             astman_send_ack(s, m, "Authentication accepted");
02309          }
02310       } else if (!strcasecmp(action, "Logoff")) {
02311          astman_send_ack(s, m, "See ya");
02312          return -1;
02313       } else
02314          astman_send_error(s, m, "Authentication Required");
02315    } else {
02316       if (!strcasecmp(action, "Login"))
02317          astman_send_ack(s, m, "Already logged in");
02318       else {
02319          ast_rwlock_rdlock(&actionlock);
02320          for (tmp = first_action; tmp; tmp = tmp->next) {      
02321             if (strcasecmp(action, tmp->action))
02322                continue;
02323             if ((s->writeperm & tmp->authority) == tmp->authority) {
02324                if (tmp->func(s, m))
02325                   ret = -1;
02326             } else
02327                astman_send_error(s, m, "Permission denied");
02328             break;
02329          }
02330          ast_rwlock_unlock(&actionlock);
02331          if (!tmp)
02332             astman_send_error(s, m, "Invalid/unknown command");
02333       }
02334    }
02335    if (ret)
02336       return ret;
02337    return process_events(s);
02338 }

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

Definition at line 2461 of file manager.c.

References ast_inet_ntoa(), ast_log(), ast_verbose(), astman_append(), mansession::authenticated, destroy_session(), do_message(), LOG_EVENT, option_verbose, s, mansession::sin, mansession::username, and VERBOSE_PREFIX_2.

Referenced by accept_thread().

02462 {
02463    struct mansession *s = data;
02464    int res;
02465    
02466    astman_append(s, "Asterisk Call Manager/1.0\r\n");
02467    for (;;) {
02468       if ((res = do_message(s)) < 0 || s->write_error)
02469          break;
02470    }
02471    if (s->authenticated) {
02472       if (option_verbose > 1) {
02473          if (displayconnects) 
02474             ast_verbose(VERBOSE_PREFIX_2 "Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(s->sin.sin_addr));
02475       }
02476       ast_log(LOG_EVENT, "Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(s->sin.sin_addr));
02477    } else {
02478       ast_atomic_fetchadd_int(&unauth_sessions, -1);
02479       if (option_verbose > 1) {
02480          if (displayconnects)
02481             ast_verbose(VERBOSE_PREFIX_2 "Connect attempt from '%s' unable to authenticate\n", ast_inet_ntoa(s->sin.sin_addr));
02482       }
02483       ast_log(LOG_EVENT, "Failed attempt from %s\n", ast_inet_ntoa(s->sin.sin_addr));
02484    }
02485 
02486    /* It is possible under certain circumstances for this session thread
02487       to complete its work and exit *before* the thread that created it
02488       has finished executing the ast_pthread_create_background() function.
02489       If this occurs, some versions of glibc appear to act in a buggy
02490       fashion and attempt to write data into memory that it thinks belongs
02491       to the thread but is in fact not owned by the thread (or may have
02492       been freed completely).
02493 
02494       Causing this thread to yield to other threads at least one time
02495       appears to work around this bug.
02496    */
02497    usleep(1);
02498 
02499    destroy_session(s);
02500    return NULL;
02501 }

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

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

Definition at line 966 of file manager.c.

References mansession::__lock, ast_mutex_lock(), ast_mutex_unlock(), mansession::send_events, and strings_to_mask().

Referenced by action_events(), and authenticate().

00967 {
00968    int maskint = strings_to_mask(eventmask);
00969 
00970    ast_mutex_lock(&s->__lock);
00971    if (maskint >= 0) 
00972       s->send_events = maskint;
00973    ast_mutex_unlock(&s->__lock);
00974    
00975    return maskint;
00976 }

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

Definition at line 935 of file manager.c.

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

Referenced by set_eventmask().

00936 {
00937    int x, ret = -1;
00938    
00939    x = ast_is_number(string);
00940 
00941    if (x)
00942       ret = x;
00943    else if (ast_strlen_zero(string))
00944       ret = -1;
00945    else if (ast_false(string))
00946       ret = 0;
00947    else if (ast_true(string)) {
00948       ret = 0;
00949       for (x=0; x<sizeof(perms) / sizeof(perms[0]); x++)
00950          ret |= perms[x].num;    
00951    } else {
00952       ret = 0;
00953       for (x=0; x<sizeof(perms) / sizeof(perms[0]); x++) {
00954          if (ast_instring(string, perms[x].label, ',')) 
00955             ret |= perms[x].num;    
00956       }
00957    }
00958 
00959    return ret;
00960 }

static void unuse_eventqent ( struct eventqent e  )  [static]

Definition at line 757 of file manager.c.

References eventqent::next, and eventqent::usecount.

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

00758 {
00759    if (ast_atomic_dec_and_test(&e->usecount) && e->next)
00760       pthread_kill(t, SIGURG);
00761 }

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

Definition at line 334 of file manager.c.

References variable_count::varname.

Referenced by xml_translate().

00335 {
00336    /* Due to the simplicity of struct variable_count, it makes no difference
00337     * if you pass in objects or strings, the same operation applies. This is
00338     * due to the fact that the hash occurs on the first element, which means
00339     * the address of both the struct and the string are exactly the same. */
00340    struct variable_count *vc = obj;
00341    char *str = vstr;
00342    return !strcmp(vc->varname, str) ? CMP_MATCH : 0;
00343 }

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

Definition at line 322 of file manager.c.

References compress_char(), and variable_count::varname.

Referenced by xml_translate().

00323 {
00324    const struct variable_count *vc = vvc;
00325    int res = 0, i;
00326    for (i = 0; i < 5; i++) {
00327       if (vc->varname[i] == '\0')
00328          break;
00329       res += compress_char(vc->varname[i]) << (i * 6);
00330    }
00331    return res;
00332 }

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

Definition at line 267 of file manager.c.

Referenced by xml_translate().

00268 {
00269    while (*src && (*maxlen > 6)) {
00270       switch (*src) {
00271       case '<':
00272          strcpy(*dst, "&lt;");
00273          (*dst) += 4;
00274          *maxlen -= 4;
00275          break;
00276       case '>':
00277          strcpy(*dst, "&gt;");
00278          (*dst) += 4;
00279          *maxlen -= 4;
00280          break;
00281       case '\"':
00282          strcpy(*dst, "&quot;");
00283          (*dst) += 6;
00284          *maxlen -= 6;
00285          break;
00286       case '\'':
00287          strcpy(*dst, "&apos;");
00288          (*dst) += 6;
00289          *maxlen -= 6;
00290          break;
00291       case '&':
00292          strcpy(*dst, "&amp;");
00293          (*dst) += 5;
00294          *maxlen -= 5;
00295          break;      
00296       default:
00297          *(*dst)++ = lower ? tolower(*src) : *src;
00298          (*maxlen)--;
00299       }
00300       src++;
00301    }
00302 }

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

Definition at line 345 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(), variable_count::varname, and xml_copy_escape().

Referenced by generic_http_callback().

00346 {
00347    struct ast_variable *v;
00348    char *dest = NULL;
00349    char *out, *tmp, *var, *val;
00350    char *objtype = NULL;
00351    int colons = 0;
00352    int breaks = 0;
00353    size_t len;
00354    int count = 1;
00355    int escaped = 0;
00356    int inobj = 0;
00357    int x;
00358    struct variable_count *vc = NULL;
00359    struct ao2_container *vco = NULL;
00360 
00361    for (v = vars; v; v = v->next) {
00362       if (!dest && !strcasecmp(v->name, "ajaxdest"))
00363          dest = v->value;
00364       else if (!objtype && !strcasecmp(v->name, "ajaxobjtype")) 
00365          objtype = v->value;
00366    }
00367    if (!dest)
00368       dest = "unknown";
00369    if (!objtype)
00370       objtype = "generic";
00371    for (x = 0; in[x]; x++) {
00372       if (in[x] == ':')
00373          colons++;
00374       else if (in[x] == '\n')
00375          breaks++;
00376       else if (strchr("&\"<>\'", in[x]))
00377          escaped++;
00378    }
00379    len = (size_t) (strlen(in) + colons * 5 + breaks * (40 + strlen(dest) + strlen(objtype)) + escaped * 10); /* foo="bar", "<response type=\"object\" id=\"dest\"", "&amp;" */
00380    out = ast_malloc(len);
00381    if (!out)
00382       return 0;
00383    tmp = out;
00384    while (*in) {
00385       var = in;
00386       while (*in && (*in >= 32))
00387          in++;
00388       if (*in) {
00389          if ((count > 3) && inobj) {
00390             ast_build_string(&tmp, &len, " /></response>\n");
00391             inobj = 0;
00392 
00393             /* Entity is closed, so close out the name cache */
00394             ao2_ref(vco, -1);
00395             vco = NULL;
00396          }
00397          count = 0;
00398          while (*in && (*in < 32)) {
00399             *in = '\0';
00400             in++;
00401             count++;
00402          }
00403          val = strchr(var, ':');
00404          if (val) {
00405             *val = '\0';
00406             val++;
00407             if (*val == ' ')
00408                val++;
00409             if (!inobj) {
00410                vco = ao2_container_alloc(37, variable_count_hash_fn, variable_count_cmp_fn);
00411                ast_build_string(&tmp, &len, "<response type='object' id='%s'><%s", dest, objtype);
00412                inobj = 1;
00413             }
00414 
00415             /* Check if the var has been used already */
00416             if ((vc = ao2_find(vco, var, 0)))
00417                vc->count++;
00418             else {
00419                /* Create a new entry for this one */
00420                vc = ao2_alloc(sizeof(*vc), NULL);
00421                vc->varname = var;
00422                vc->count = 1;
00423                ao2_link(vco, vc);
00424             }
00425 
00426             ast_build_string(&tmp, &len, " ");
00427             xml_copy_escape(&tmp, &len, var, 1);
00428             if (vc->count > 1)
00429                ast_build_string(&tmp, &len, "-%d", vc->count);
00430             ast_build_string(&tmp, &len, "='");
00431             xml_copy_escape(&tmp, &len, val, 0);
00432             ast_build_string(&tmp, &len, "'");
00433             ao2_ref(vc, -1);
00434          }
00435       }
00436    }
00437    if (inobj)
00438       ast_build_string(&tmp, &len, " /></response>\n");
00439    if (vco)
00440       ao2_ref(vco, -1);
00441    return out;
00442 }


Variable Documentation

int asock = -1 [static]

Definition at line 115 of file manager.c.

int authlimit [static]

Definition at line 120 of file manager.c.

int authtimeout [static]

Definition at line 119 of file manager.c.

int block_sockets [static]

Definition at line 123 of file manager.c.

struct ast_cli_entry cli_manager[] [static]

Definition at line 731 of file manager.c.

Initial value:

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

Definition at line 711 of file manager.c.

Initial value:

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

Definition at line 716 of file manager.c.

Initial value:

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

Definition at line 721 of file manager.c.

Initial value:

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

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

const int DEFAULT_AUTHTIMEOUT = 30 [static]

Default setting for authtimeout

Definition at line 109 of file manager.c.

const int DEFAULT_BLOCKSOCKETS = 0 [static]

Default setting for block-sockets

Definition at line 104 of file manager.c.

const int DEFAULT_BROKENEVENTSACTION = 0 [static]

Default setting for brokeneventsaction

Definition at line 108 of file manager.c.

const int DEFAULT_DISPLAYCONNECTS = 1 [static]

Default setting for displaying manager connections

Definition at line 105 of file manager.c.

const int DEFAULT_ENABLED = 0 [static]

Default setting for manager to be enabled

Definition at line 102 of file manager.c.

const int DEFAULT_HTTPTIMEOUT = 60 [static]

Default manager http timeout

Definition at line 107 of file manager.c.

const int DEFAULT_TIMESTAMPEVENTS = 0 [static]

Default setting for timestampevents

Definition at line 106 of file manager.c.

const int DEFAULT_WEBENABLED = 0 [static]

Default setting for the web interface to be enabled

Definition at line 103 of file manager.c.

int displayconnects [static]

Definition at line 116 of file manager.c.

int enabled [static]

Definition at line 113 of file manager.c.

struct manager_action* first_action [static]

int httptimeout [static]

Definition at line 118 of file manager.c.

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

char mandescr_events[] [static]

Definition at line 1404 of file manager.c.

char mandescr_extensionstate[] [static]

Definition at line 2134 of file manager.c.

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

char mandescr_getvar[] [static]

Definition at line 1549 of file manager.c.

char mandescr_hangup[] [static]

Initial value:

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

Definition at line 1436 of file manager.c.

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

char mandescr_logoff[] [static]

Initial value:

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

Definition at line 1426 of file manager.c.

char mandescr_mailboxcount[] [static]

Definition at line 2098 of file manager.c.

char mandescr_mailboxstatus[] [static]

Help text for manager command mailboxstatus.

Definition at line 2066 of file manager.c.

char mandescr_message[] [static]

Definition at line 1469 of file manager.c.

char mandescr_originate[] [static]

Definition at line 1923 of file manager.c.

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

char mandescr_redirect[] [static]

Definition at line 1691 of file manager.c.

char mandescr_setvar[] [static]

Definition at line 1512 of file manager.c.

char mandescr_timeout[] [static]

Definition at line 2175 of file manager.c.

char mandescr_updateconfig[] [static]

Definition at line 1239 of file manager.c.

char mandescr_userevent[] [static]

Definition at line 2232 of file manager.c.

char mandescr_waitevent[] [static]

Manager WAITEVENT.

Definition at line 1290 of file manager.c.

struct eventqent* master_eventq = NULL

Definition at line 128 of file manager.c.

int num_sessions [static]

Definition at line 124 of file manager.c.

struct permalias perms[] [static]

int portno = DEFAULT_MANAGER_PORT [static]

Definition at line 114 of file manager.c.

Referenced by ast_netsock_bind(), create_addr(), 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 707 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 702 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 684 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 688 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 692 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 697 of file manager.c.

pthread_t t [static]

Definition at line 122 of file manager.c.

Referenced by __schedule_action(), acf_odbc_write(), add_sdp(), add_t38_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_build_path(), ast_verbose(), background_detect_exec(), build_mapping(), byteReverse(), 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(), handle_bchan(), 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(), osp_create_provider(), osp_load(), packdate(), parse_moved_contact(), pgsql_log(), play_message_datetime(), prune_gateways(), rebuild_matrix(), register_verify(), send_request(), SHA1ProcessMessageBlock(), socket_read(), sqlite_log(), strip_quotes(), tdd_getcarrier(), time1(), time2(), time2sub(), transmit_notify_request_with_callerid(), transmit_notify_with_mwi(), transmit_state_notify(), vmu_tm(), and write_metadata().

int timestampevents [static]

Definition at line 117 of file manager.c.

int unauth_sessions = 0 [static]

Definition at line 125 of file manager.c.

char* words[AST_MAX_CMD_LEN] [inherited]

Definition at line 155 of file manager.c.


Generated on Sun Dec 18 20:55:55 2011 for Asterisk - the Open Source PBX by  doxygen 1.5.6