Thu Dec 17 17:41:09 2009

Asterisk developer's documentation


AMI functions

callback to display queues status in manager More...

Data Structures

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

Defines

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

Functions

static void * accept_thread (void *ignore)
static int action_atxfer (struct mansession *s, const struct message *m)
static int action_command (struct mansession *s, const struct message *m)
 action_command: Manager command "command" - execute CLI command
static int action_coresettings (struct mansession *s, const struct message *m)
 Show PBX core settings information.
static int action_corestatus (struct mansession *s, const struct message *m)
 Show PBX core status information.
static int action_events (struct mansession *s, const struct message *m)
static int action_extensionstate (struct mansession *s, const struct message *m)
static int action_getconfig (struct mansession *s, const struct message *m)
static int action_getvar (struct mansession *s, const struct message *m)
static int action_hangup (struct mansession *s, const struct message *m)
static int action_listcommands (struct mansession *s, const struct message *m)
static int action_logoff (struct mansession *s, const struct message *m)
static int action_mailboxcount (struct mansession *s, const struct message *m)
static int action_mailboxstatus (struct mansession *s, const struct message *m)
static int action_originate (struct mansession *s, const struct message *m)
static int action_ping (struct mansession *s, const struct message *m)
static int action_redirect (struct mansession *s, const struct message *m)
 action_redirect: The redirect manager command
static int action_setvar (struct mansession *s, const struct message *m)
static int action_status (struct mansession *s, const struct message *m)
 Manager "status" command to show channels.
static int action_timeout (struct mansession *s, const struct message *m)
static int action_updateconfig (struct mansession *s, const struct message *m)
static int action_userevent (struct mansession *s, const struct message *m)
static int action_waitevent (struct mansession *s, const struct message *m)
static int append_event (const char *str, int category)
static struct ast_manager_userast_get_manager_by_name_locked (const char *name)
static int ast_instring (const char *bigstr, const char *smallstr, char delim)
static int ast_is_number (const char *string)
int ast_manager_register2 (const char *action, int auth, int(*func)(struct mansession *s, const struct message *m), const char *synopsis, const char *description)
 register a new command with manager, including online help. This is the preferred way to register a manager command
static int ast_manager_register_struct (struct manager_action *act)
int ast_manager_unregister (char *action)
void astman_append (struct mansession *s, const char *fmt,...)
static void astman_append_buf_init (void)
const char * astman_get_header (const struct message *m, char *var)
ast_variableastman_get_variables (const struct message *m)
void astman_send_ack (struct mansession *s, const struct message *m, char *msg)
void astman_send_error (struct mansession *s, const struct message *m, char *error)
void astman_send_response (struct mansession *s, const struct message *m, char *resp, char *msg)
static int authenticate (struct mansession *s, const struct message *m)
static char * authority_to_str (int authority, char *res, int reslen)
 Convert authority code to string with serveral options.
static int check_blacklist (const char *cmd)
int check_manager_enabled ()
 Check if AMI is enabled.
int check_webmanager_enabled ()
 Check if AMI/HTTP is enabled.
static char * complete_show_mancmd (const char *line, const char *word, int pos, int state)
static int compress_char (char c)
static void destroy_session (struct mansession_session *s)
static int do_message (struct mansession *s)
static void * fast_originate (void *data)
static void free_session (struct mansession_session *s)
static int get_input (struct mansession_session *s, char *output)
static int get_perm (const char *instr)
static int handle_showmanager (int fd, int argc, char *argv[])
static int handle_showmanagers (int fd, int argc, char *argv[])
static int handle_showmancmd (int fd, int argc, char *argv[])
static int handle_showmancmds (int fd, int argc, char *argv[])
 CLI command Should change to "manager show commands".
static int handle_showmanconn (int fd, int argc, char *argv[])
 CLI command show manager connected.
static int handle_showmaneventq (int fd, int argc, char *argv[])
 CLI command show manager eventq.
static void handle_updates (struct mansession *s, const struct message *m, struct ast_config *cfg)
static char * html_translate (char *in)
int manager_event (int category, const char *event, const char *fmt,...)
 manager_event: Send AMI event to client
static void manager_event_buf_init (void)
static int manager_state_cb (char *context, char *exten, int state, void *data)
static int process_events (struct mansession *s)
static int process_message (struct mansession *s, const struct message *m)
static void * session_do (void *data)
static int set_eventmask (struct mansession_session *s, const char *eventmask)
 Rather than braindead on,off this now can also accept a specific int mask value or a ',' delim list of mask strings (the same as manager.conf) -anthm.
static int strings_to_mask (const char *string)
static void unuse_eventqent (struct eventqent *e)
static int variable_count_cmp_fn (void *obj, void *vstr, int flags)
static int variable_count_hash_fn (const void *vvc, const int flags)
static void xml_copy_escape (char **dst, size_t *maxlen, const char *src, int lower)
static char * xml_translate (char *in, struct ast_variable *vars)

Variables

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

Detailed Description

callback to display queues status in manager


Define Documentation

#define ASTMAN_APPEND_BUF_INITSIZE   256

Definition at line 121 of file manager.c.

Referenced by astman_append().

#define MANAGER_EVENT_BUF_INITSIZE   256

Definition at line 118 of file manager.c.

Referenced by manager_event().

#define MAX_BLACKLIST_CMD_LEN   2

Definition at line 139 of file manager.c.

Referenced by check_blacklist().


Function Documentation

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

Definition at line 2575 of file manager.c.

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

Referenced by reload_config().

02576 {
02577    int as;
02578    struct sockaddr_in sin;
02579    socklen_t sinlen;
02580    struct eventqent *eqe;
02581    struct mansession_session *s;
02582    struct protoent *p;
02583    int arg = 1;
02584    int flags;
02585    pthread_attr_t attr;
02586    time_t now;
02587    struct pollfd pfds[1];
02588 
02589    pthread_attr_init(&attr);
02590    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
02591 
02592    for (;;) {
02593       time(&now);
02594       AST_LIST_LOCK(&sessions);
02595       AST_LIST_TRAVERSE_SAFE_BEGIN(&sessions, s, list) {
02596          if (s->sessiontimeout && (now > s->sessiontimeout) && !s->inuse) {
02597             AST_LIST_REMOVE_CURRENT(&sessions, list);
02598             num_sessions--;
02599             if (s->authenticated && (option_verbose > 1) && displayconnects) {
02600                ast_verbose(VERBOSE_PREFIX_2 "HTTP Manager '%s' timed out from %s\n",
02601                   s->username, ast_inet_ntoa(s->sin.sin_addr));
02602             }
02603             free_session(s);
02604             break;   
02605          }
02606       }
02607       AST_LIST_TRAVERSE_SAFE_END
02608       /* Purge master event queue of old, unused events, but make sure we
02609          always keep at least one in the queue */
02610       eqe = master_eventq;
02611       while (master_eventq->next && !master_eventq->usecount) {
02612          eqe = master_eventq;
02613          master_eventq = master_eventq->next;
02614          free(eqe);
02615       }
02616       AST_LIST_UNLOCK(&sessions);
02617 
02618       sinlen = sizeof(sin);
02619       pfds[0].fd = asock;
02620       pfds[0].events = POLLIN;
02621       /* Wait for something to happen, but timeout every few seconds so
02622          we can ditch any old manager sessions */
02623       if (ast_poll(pfds, 1, 5000) < 1)
02624          continue;
02625       as = accept(asock, (struct sockaddr *)&sin, &sinlen);
02626       if (as < 0) {
02627          ast_log(LOG_NOTICE, "Accept returned -1: %s\n", strerror(errno));
02628          continue;
02629       }
02630       p = getprotobyname("tcp");
02631       if (p) {
02632          if( setsockopt(as, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) {
02633             ast_log(LOG_WARNING, "Failed to set manager tcp connection to TCP_NODELAY mode: %s\n", strerror(errno));
02634          }
02635       }
02636       if (!(s = ast_calloc(1, sizeof(*s))))
02637          continue;
02638 
02639       memcpy(&s->sin, &sin, sizeof(sin));
02640       s->writetimeout = 100;
02641       s->waiting_thread = AST_PTHREADT_NULL;
02642 
02643       if (!block_sockets) {
02644          /* For safety, make sure socket is non-blocking */
02645          flags = fcntl(as, F_GETFL);
02646          fcntl(as, F_SETFL, flags | O_NONBLOCK);
02647       } else {
02648          flags = fcntl(as, F_GETFL);
02649          fcntl(as, F_SETFL, flags & ~O_NONBLOCK);
02650       }
02651       ast_mutex_init(&s->__lock);
02652       s->fd = as;
02653       s->send_events = -1;
02654       AST_LIST_LOCK(&sessions);
02655       AST_LIST_INSERT_HEAD(&sessions, s, list);
02656       num_sessions++;
02657       /* Find the last place in the master event queue and hook ourselves
02658          in there */
02659       s->eventq = master_eventq;
02660       while(s->eventq->next)
02661          s->eventq = s->eventq->next;
02662       ast_atomic_fetchadd_int(&s->eventq->usecount, 1);
02663       AST_LIST_UNLOCK(&sessions);
02664       if (ast_pthread_create_background(&s->t, &attr, session_do, s))
02665          destroy_session(s);
02666    }
02667    pthread_attr_destroy(&attr);
02668    return NULL;
02669 }

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

Definition at line 1813 of file manager.c.

References asprintf, ast_channel_unlock, AST_CONTROL_ATXFERCMD, ast_get_channel_by_name_locked(), ast_queue_control_data(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), cleanup(), context, exten, free, len(), name, and s.

Referenced by init_manager().

01814 {
01815    struct ast_channel *c;
01816    const char *name = astman_get_header(m, "Channel");
01817    const char *exten = astman_get_header(m, "Exten");
01818    const char *context = astman_get_header(m, "Context");
01819    char *xferto;
01820    int len;
01821 
01822    if (ast_strlen_zero(name)) {
01823       astman_send_error(s, m, "No channel specified");
01824       return 0;
01825    }
01826    if (ast_strlen_zero(exten)) {
01827       astman_send_error(s, m, "No exten specified");
01828       return 0;
01829    }
01830    c = ast_get_channel_by_name_locked(name);
01831    if (!c) {
01832       astman_send_error(s, m, "No such channel");
01833       return 0;
01834    }
01835    len = asprintf(&xferto, "%s@%s", exten, context);
01836    if (len < 0) {
01837       astman_send_error(s, m, "Out of memory!");
01838       goto cleanup;
01839    }
01840    ast_queue_control_data(c, AST_CONTROL_ATXFERCMD, xferto, len+1);
01841    free(xferto);
01842    astman_send_ack(s, m, "Attended transfer started");
01843 cleanup:
01844    ast_channel_unlock(c);
01845    return 0;
01846 }

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

action_command: Manager command "command" - execute CLI command

Definition at line 1855 of file manager.c.

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

Referenced by init_manager().

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

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

Show PBX core settings information.

Definition at line 2288 of file manager.c.

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

Referenced by init_manager().

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

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

Show PBX core status information.

Definition at line 2332 of file manager.c.

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

Referenced by init_manager().

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

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

Definition at line 1449 of file manager.c.

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

Referenced by init_manager().

01450 {
01451    const char *mask = astman_get_header(m, "EventMask");
01452    int res;
01453 
01454    res = set_eventmask(s->session, mask);
01455    if (res > 0)
01456       astman_send_response(s, m, "Events On", NULL);
01457    else if (res == 0)
01458       astman_send_response(s, m, "Events Off", NULL);
01459 
01460    return 0;
01461 }

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

Definition at line 2166 of file manager.c.

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

Referenced by init_manager().

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

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

Definition at line 1178 of file manager.c.

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

Referenced by init_manager().

01179 {
01180    struct ast_config *cfg;
01181    const char *fn = astman_get_header(m, "Filename");
01182    int catcount = 0;
01183    int lineno = 0;
01184    char *category=NULL;
01185    struct ast_variable *v;
01186    char idText[256] = "";
01187    const char *id = astman_get_header(m, "ActionID");
01188 
01189    if (!ast_strlen_zero(id))
01190       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
01191 
01192    if (ast_strlen_zero(fn)) {
01193       astman_send_error(s, m, "Filename not specified");
01194       return 0;
01195    }
01196    if (!(cfg = ast_config_load_with_comments(fn))) {
01197       astman_send_error(s, m, "Config file not found");
01198       return 0;
01199    }
01200    astman_append(s, "Response: Success\r\n%s", idText);
01201    while ((category = ast_category_browse(cfg, category))) {
01202       lineno = 0;
01203       astman_append(s, "Category-%06d: %s\r\n", catcount, category);
01204       for (v = ast_variable_browse(cfg, category); v; v = v->next)
01205          astman_append(s, "Line-%06d-%06d: %s=%s\r\n", catcount, lineno++, v->name, v->value);
01206       catcount++;
01207    }
01208    ast_config_destroy(cfg);
01209    astman_append(s, "\r\n");
01210 
01211    return 0;
01212 }

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

Definition at line 1541 of file manager.c.

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

Referenced by init_manager().

01542 {
01543    struct ast_channel *c = NULL;
01544    const char *name = astman_get_header(m, "Channel");
01545    const char *varname = astman_get_header(m, "Variable");
01546    const char *id = astman_get_header(m,"ActionID");
01547    char *varval;
01548    char workspace[1024] = "";
01549 
01550    if (ast_strlen_zero(varname)) {
01551       astman_send_error(s, m, "No variable specified");
01552       return 0;
01553    }
01554 
01555    if (!ast_strlen_zero(name)) {
01556       c = ast_get_channel_by_name_locked(name);
01557       if (!c) {
01558          astman_send_error(s, m, "No such channel");
01559          return 0;
01560       }
01561    }
01562 
01563    if (varname[strlen(varname) - 1] == ')') {
01564       char *copy = ast_strdupa(varname);
01565       if (!c) {
01566          c = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Bogus/manager");
01567          if (c) {
01568             ast_func_read(c, copy, workspace, sizeof(workspace));
01569             ast_channel_free(c);
01570             c = NULL;
01571          } else
01572             ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution.  Function results may be blank.\n");
01573       } else
01574          ast_func_read(c, copy, workspace, sizeof(workspace));
01575       varval = workspace;
01576    } else {
01577       pbx_retrieve_variable(c, varname, &varval, workspace, sizeof(workspace), NULL);
01578    }
01579 
01580    if (c)
01581       ast_channel_unlock(c);
01582    astman_append(s, "Response: Success\r\n"
01583       "Variable: %s\r\nValue: %s\r\n", varname, varval);
01584    if (!ast_strlen_zero(id))
01585       astman_append(s, "ActionID: %s\r\n",id);
01586    astman_append(s, "\r\n");
01587 
01588    return 0;
01589 }

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

Definition at line 1478 of file manager.c.

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

Referenced by init_manager().

01479 {
01480    struct ast_channel *c = NULL;
01481    const char *name = astman_get_header(m, "Channel");
01482    if (ast_strlen_zero(name)) {
01483       astman_send_error(s, m, "No channel specified");
01484       return 0;
01485    }
01486    c = ast_get_channel_by_name_locked(name);
01487    if (!c) {
01488       astman_send_error(s, m, "No such channel");
01489       return 0;
01490    }
01491    ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
01492    ast_channel_unlock(c);
01493    astman_send_ack(s, m, "Channel Hungup");
01494    return 0;
01495 }

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

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

Referenced by init_manager().

01423 {
01424    struct manager_action *cur;
01425    char idText[256] = "";
01426    char temp[BUFSIZ];
01427    const char *id = astman_get_header(m,"ActionID");
01428 
01429    if (!ast_strlen_zero(id))
01430       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
01431    astman_append(s, "Response: Success\r\n%s", idText);
01432    for (cur = first_action; cur; cur = cur->next) {
01433       if ((s->session->writeperm & cur->authority) == cur->authority)
01434          astman_append(s, "%s: %s (Priv: %s)\r\n", cur->action, cur->synopsis, authority_to_str(cur->authority, temp, sizeof(temp)));
01435    }
01436    astman_append(s, "\r\n");
01437 
01438    return 0;
01439 }

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

Definition at line 1467 of file manager.c.

References astman_send_response(), and s.

Referenced by init_manager().

01468 {
01469    astman_send_response(s, m, "Goodbye", "Thanks for all the fish.");
01470    return -1;
01471 }

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

Definition at line 2130 of file manager.c.

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

Referenced by init_manager().

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

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

Definition at line 2098 of file manager.c.

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

Referenced by init_manager().

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

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

Definition at line 1972 of file manager.c.

References app, ast_callerid_parse(), ast_calloc, ast_copy_string(), ast_findlabel_extension(), AST_FORMAT_SLINEAR, ast_free, ast_parse_allow_disallow(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pthread_create, ast_shrink_phone_number(), ast_strlen_zero(), ast_true(), astman_get_header(), astman_get_variables(), astman_send_ack(), astman_send_error(), context, ast_channel::data, exten, fast_originate(), format, name, ast_channel::priority, s, and ast_channel::tech.

Referenced by init_manager().

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

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

Definition at line 1166 of file manager.c.

References astman_send_response(), and s.

Referenced by init_manager().

01167 {
01168    astman_send_response(s, m, "Pong", NULL);
01169    return 0;
01170 }

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

action_redirect: The redirect manager command

Definition at line 1695 of file manager.c.

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

Referenced by init_manager().

01696 {
01697    const char *name = astman_get_header(m, "Channel");
01698    const char *name2 = astman_get_header(m, "ExtraChannel");
01699    const char *exten = astman_get_header(m, "Exten");
01700    const char *context = astman_get_header(m, "Context");
01701    const char *priority = astman_get_header(m, "Priority");
01702    struct ast_channel *chan, *chan2 = NULL;
01703    int pi = 0;
01704    int res;
01705 
01706    if (ast_strlen_zero(name)) {
01707       astman_send_error(s, m, "Channel not specified");
01708       return 0;
01709    }
01710    if (!ast_strlen_zero(priority) && (sscanf(priority, "%30d", &pi) != 1)) {
01711       if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) {
01712          astman_send_error(s, m, "Invalid priority");
01713          return 0;
01714       }
01715    }
01716    /* XXX watch out, possible deadlock!!! */
01717    chan = ast_get_channel_by_name_locked(name);
01718    if (!chan) {
01719       char buf[BUFSIZ];
01720       snprintf(buf, sizeof(buf), "Channel does not exist: %s", name);
01721       astman_send_error(s, m, buf);
01722       return 0;
01723    }
01724    if (ast_check_hangup(chan)) {
01725       astman_send_error(s, m, "Redirect failed, channel not up.");
01726       ast_channel_unlock(chan);
01727       return 0;
01728    }
01729    if (!ast_strlen_zero(name2))
01730       chan2 = ast_get_channel_by_name_locked(name2);
01731    if (chan2 && ast_check_hangup(chan2)) {
01732       astman_send_error(s, m, "Redirect failed, extra channel not up.");
01733       ast_channel_unlock(chan);
01734       ast_channel_unlock(chan2);
01735       return 0;
01736    }
01737    if (chan->pbx) {
01738       ast_channel_lock(chan);
01739       ast_set_flag(chan, AST_FLAG_BRIDGE_HANGUP_DONT); /* don't let the after-bridge code run the h-exten */
01740       ast_channel_unlock(chan);
01741    }
01742    res = ast_async_goto(chan, context, exten, pi);
01743    if (!res) {
01744       if (!ast_strlen_zero(name2)) {
01745          if (chan2) {
01746             if (chan2->pbx) {
01747                ast_channel_lock(chan2);
01748                ast_set_flag(chan2, AST_FLAG_BRIDGE_HANGUP_DONT); /* don't let the after-bridge code run the h-exten */
01749                ast_channel_unlock(chan2);
01750             }
01751             res = ast_async_goto(chan2, context, exten, pi);
01752          } else {
01753             res = -1;
01754          }
01755          if (!res)
01756             astman_send_ack(s, m, "Dual Redirect successful");
01757          else
01758             astman_send_error(s, m, "Secondary redirect failed");
01759       } else
01760          astman_send_ack(s, m, "Redirect successful");
01761    } else
01762       astman_send_error(s, m, "Redirect failed");
01763    if (chan)
01764       ast_channel_unlock(chan);
01765    if (chan2)
01766       ast_channel_unlock(chan2);
01767    return 0;
01768 }

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

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

Referenced by init_manager().

01505 {
01506         struct ast_channel *c = NULL;
01507    const char *name = astman_get_header(m, "Channel");
01508    const char *varname = astman_get_header(m, "Variable");
01509    const char *varval = astman_get_header(m, "Value");
01510    
01511    if (ast_strlen_zero(varname)) {
01512       astman_send_error(s, m, "No variable specified");
01513       return 0;
01514    }
01515    
01516    if (!ast_strlen_zero(name)) {
01517       c = ast_get_channel_by_name_locked(name);
01518       if (!c) {
01519          astman_send_error(s, m, "No such channel");
01520          return 0;
01521       }
01522    }
01523    
01524    pbx_builtin_setvar_helper(c, varname, S_OR(varval, ""));
01525      
01526    if (c)
01527       ast_channel_unlock(c);
01528 
01529    astman_send_ack(s, m, "Variable Set"); 
01530 
01531    return 0;
01532 }

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

Manager "status" command to show channels.

Definition at line 1594 of file manager.c.

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

Referenced by init_manager().

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

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

Definition at line 2203 of file manager.c.

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

Referenced by init_manager().

02204 {
02205    struct ast_channel *c = NULL;
02206    const char *name = astman_get_header(m, "Channel");
02207    int timeout = atoi(astman_get_header(m, "Timeout"));
02208    if (ast_strlen_zero(name)) {
02209       astman_send_error(s, m, "No channel specified");
02210       return 0;
02211    }
02212    if (!timeout) {
02213       astman_send_error(s, m, "No timeout specified");
02214       return 0;
02215    }
02216    c = ast_get_channel_by_name_locked(name);
02217    if (!c) {
02218       astman_send_error(s, m, "No such channel");
02219       return 0;
02220    }
02221    ast_channel_setwhentohangup(c, timeout);
02222    ast_channel_unlock(c);
02223    astman_send_ack(s, m, "Timeout Set");
02224    return 0;
02225 }

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

Definition at line 1289 of file manager.c.

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

Referenced by init_manager().

01290 {
01291    struct ast_config *cfg;
01292    const char *sfn = astman_get_header(m, "SrcFilename");
01293    const char *dfn = astman_get_header(m, "DstFilename");
01294    int res;
01295    char idText[256] = "";
01296    const char *id = astman_get_header(m, "ActionID");
01297    const char *rld = astman_get_header(m, "Reload");
01298 
01299    if (!ast_strlen_zero(id))
01300       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
01301 
01302    if (ast_strlen_zero(sfn) || ast_strlen_zero(dfn)) {
01303       astman_send_error(s, m, "Filename not specified");
01304       return 0;
01305    }
01306    if (!(cfg = ast_config_load_with_comments(sfn))) {
01307       astman_send_error(s, m, "Config file not found");
01308       return 0;
01309    }
01310    handle_updates(s, m, cfg);
01311    res = config_text_file_save(dfn, cfg, "Manager");
01312    ast_config_destroy(cfg);
01313    if (res) {
01314       astman_send_error(s, m, "Save of config failed");
01315       return 0;
01316    }
01317    astman_append(s, "Response: Success\r\n%s\r\n", idText);
01318    if (!ast_strlen_zero(rld)) {
01319       if (ast_true(rld))
01320          rld = NULL;
01321       ast_module_reload(rld); 
01322    }
01323    return 0;
01324 }

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

Definition at line 2260 of file manager.c.

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

Referenced by init_manager().

02261 {
02262    const char *event = astman_get_header(m, "UserEvent");
02263    char body[2048] = "";
02264    int x, bodylen = 0, xlen;
02265    for (x = 0; x < m->hdrcount; x++) {
02266       if (strncasecmp("UserEvent:", m->headers[x], strlen("UserEvent:"))) {
02267          if (sizeof(body) < bodylen + (xlen = strlen(m->headers[x])) + 3) {
02268             ast_log(LOG_WARNING, "UserEvent exceeds our buffer length.  Truncating.\n");
02269             break;
02270          }
02271          ast_copy_string(body + bodylen, m->headers[x], sizeof(body) - bodylen - 3);
02272          bodylen += xlen;
02273          ast_copy_string(body + bodylen, "\r\n", 3);
02274          bodylen += 2;
02275       }
02276    }
02277 
02278    manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", event, body);
02279    return 0;
02280 }

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

Definition at line 1334 of file manager.c.

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

Referenced by init_manager().

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

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

Definition at line 2671 of file manager.c.

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

Referenced by init_manager(), and manager_event().

02672 {
02673    struct eventqent *tmp, *prev = NULL;
02674    tmp = ast_malloc(sizeof(*tmp) + strlen(str));
02675 
02676    if (!tmp)
02677       return -1;
02678 
02679    tmp->next = NULL;
02680    tmp->category = category;
02681    strcpy(tmp->eventdata, str);
02682    
02683    if (master_eventq) {
02684       prev = master_eventq;
02685       while (prev->next) 
02686          prev = prev->next;
02687       prev->next = tmp;
02688    } else {
02689       master_eventq = tmp;
02690    }
02691    
02692    tmp->usecount = num_sessions;
02693    
02694    return 0;
02695 }

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

Definition at line 531 of file manager.c.

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

Referenced by handle_showmanager(), and init_manager().

00532 {
00533    struct ast_manager_user *user = NULL;
00534 
00535    AST_LIST_TRAVERSE(&users, user, list)
00536       if (!strcasecmp(user->username, name))
00537          break;
00538    return user;
00539 }

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

References ast_variable::next.

Referenced by get_perm(), and strings_to_mask().

00923 {
00924    const char *val = bigstr, *next;
00925 
00926    do {
00927       if ((next = strchr(val, delim))) {
00928          if (!strncmp(val, smallstr, (next - val)))
00929             return 1;
00930          else
00931             continue;
00932       } else
00933          return !strcmp(smallstr, val);
00934 
00935    } while (*(val = (next + 1)));
00936 
00937    return 0;
00938 }

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

Definition at line 955 of file manager.c.

Referenced by strings_to_mask().

00956 {
00957    int ret = 1, x = 0;
00958 
00959    if (!string)
00960       return 0;
00961 
00962    for (x = 0; x < strlen(string); x++) {
00963       if (!(string[x] >= 48 && string[x] <= 57)) {
00964          ret = 0;
00965          break;
00966       }
00967    }
00968    
00969    return ret ? atoi(string) : 0;
00970 }

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

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

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

Definition at line 2832 of file manager.c.

References ast_free, ast_malloc, and ast_manager_register_struct().

Referenced by init_manager(), and load_module().

02833 {
02834    struct manager_action *cur;
02835 
02836    cur = ast_malloc(sizeof(*cur));
02837    if (!cur)
02838       return -1;
02839    
02840    cur->action = action;
02841    cur->authority = auth;
02842    cur->func = func;
02843    cur->synopsis = synopsis;
02844    cur->description = description;
02845    cur->next = NULL;
02846 
02847    if (ast_manager_register_struct(cur)) {
02848       ast_free(cur);
02849       return -1;
02850    }
02851 
02852    return 0;
02853 }

static int ast_manager_register_struct ( struct manager_action act  )  [static]

Definition at line 2784 of file manager.c.

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

Referenced by ast_manager_register2().

02785 {
02786    struct manager_action *cur, *prev = NULL;
02787    int ret;
02788    struct timespec tv = { 5, };
02789 
02790    if (ast_rwlock_timedwrlock(&actionlock, &tv)) {
02791       ast_log(LOG_ERROR, "Could not obtain lock on manager list\n");
02792       return -1;
02793    }
02794    cur = first_action;
02795    while (cur) { /* Walk the list of actions */
02796       ret = strcasecmp(cur->action, act->action);
02797       if (ret == 0) {
02798          ast_log(LOG_WARNING, "Manager: Action '%s' already registered\n", act->action);
02799          ast_rwlock_unlock(&actionlock);
02800          return -1;
02801       } else if (ret > 0) {
02802          /* Insert these alphabetically */
02803          if (prev) {
02804             act->next = prev->next;
02805             prev->next = act;
02806          } else {
02807             act->next = first_action;
02808             first_action = act;
02809          }
02810          break;
02811       }
02812       prev = cur; 
02813       cur = cur->next;
02814    }
02815    
02816    if (!cur) {
02817       if (prev)
02818          prev->next = act;
02819       else
02820          first_action = act;
02821       act->next = NULL;
02822    }
02823 
02824    if (option_verbose > 1) 
02825       ast_verbose(VERBOSE_PREFIX_2 "Manager registered action %s\n", act->action);
02826    ast_rwlock_unlock(&actionlock);
02827    return 0;
02828 }

int ast_manager_unregister ( char *  action  ) 

Parameters:
action Name of registered Action:

Definition at line 2751 of file manager.c.

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

Referenced by __unload_module(), and unload_module().

02752 {
02753    struct manager_action *cur, *prev;
02754    struct timespec tv = { 5, };
02755 
02756    if (ast_rwlock_timedwrlock(&actionlock, &tv)) {
02757       ast_log(LOG_ERROR, "Could not obtain lock on manager list\n");
02758       return -1;
02759    }
02760    cur = prev = first_action;
02761    while (cur) {
02762       if (!strcasecmp(action, cur->action)) {
02763          prev->next = cur->next;
02764          free(cur);
02765          if (option_verbose > 1) 
02766             ast_verbose(VERBOSE_PREFIX_2 "Manager unregistered action %s\n", action);
02767          ast_rwlock_unlock(&actionlock);
02768          return 0;
02769       }
02770       prev = cur;
02771       cur = cur->next;
02772    }
02773    ast_rwlock_unlock(&actionlock);
02774    return 0;
02775 }

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

Definition at line 541 of file manager.c.

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

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

00542 {
00543    va_list ap;
00544    struct ast_dynamic_str *buf;
00545 
00546    ast_mutex_lock(&s->session->__lock);
00547 
00548    if (!(buf = ast_dynamic_str_thread_get(&astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE))) {
00549       ast_mutex_unlock(&s->session->__lock);
00550       return;
00551    }
00552 
00553    va_start(ap, fmt);
00554    ast_dynamic_str_thread_set_va(&buf, 0, &astman_append_buf, fmt, ap);
00555    va_end(ap);
00556    
00557    if (s->fd > -1)
00558       ast_carefulwrite(s->fd, buf->str, strlen(buf->str), s->session->writetimeout);
00559    else {
00560       if (!s->session->outputstr && !(s->session->outputstr = ast_calloc(1, sizeof(*s->session->outputstr)))) {
00561          ast_mutex_unlock(&s->session->__lock);
00562          return;
00563       }
00564 
00565       ast_dynamic_str_append(&s->session->outputstr, 0, "%s", buf->str);   
00566    }
00567 
00568    ast_mutex_unlock(&s->session->__lock);
00569 }

static void astman_append_buf_init ( void   )  [static]

Definition at line 120 of file manager.c.

00123 {

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

Get header from mananger transaction

Definition at line 825 of file manager.c.

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

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

00826 {
00827    char cmp[80];
00828    int x;
00829 
00830    snprintf(cmp, sizeof(cmp), "%s: ", var);
00831 
00832    for (x = 0; x < m->hdrcount; x++) {
00833       if (!strncasecmp(cmp, m->headers[x], strlen(cmp)))
00834          return m->headers[x] + strlen(cmp);
00835    }
00836 
00837    return "";
00838 }

struct ast_variable* astman_get_variables ( const struct message m  ) 

Get a linked list of the Variable: headers

Definition at line 840 of file manager.c.

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

Referenced by action_originate().

00841 {
00842    int varlen, x, y;
00843    struct ast_variable *head = NULL, *cur;
00844    char *var, *val;
00845 
00846    char *parse;    
00847    AST_DECLARE_APP_ARGS(args,
00848       AST_APP_ARG(vars)[32];
00849    );
00850 
00851    varlen = strlen("Variable: ");   
00852 
00853    for (x = 0; x < m->hdrcount; x++) {
00854       if (strncasecmp("Variable: ", m->headers[x], varlen))
00855          continue;
00856 
00857       parse = ast_strdupa(m->headers[x] + varlen);
00858 
00859       AST_STANDARD_APP_ARGS(args, parse);
00860       if (args.argc) {
00861          for (y = 0; y < args.argc; y++) {
00862             if (!args.vars[y])
00863                continue;
00864             var = val = ast_strdupa(args.vars[y]);
00865             strsep(&val, "=");
00866             if (!val || ast_strlen_zero(var))
00867                continue;
00868             cur = ast_variable_new(var, val);
00869             if (head) {
00870                cur->next = head;
00871                head = cur;
00872             } else
00873                head = cur;
00874          }
00875       }
00876    }
00877 
00878    return head;
00879 }

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

Definition at line 912 of file manager.c.

References astman_send_response(), and s.

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

00913 {
00914    astman_send_response(s, m, "Success", msg);
00915 }

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

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

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

00890 {
00891    const char *id = astman_get_header(m,"ActionID");
00892 
00893    astman_append(s, "Response: Error\r\n");
00894    if (!ast_strlen_zero(id))
00895       astman_append(s, "ActionID: %s\r\n", id);
00896    astman_append(s, "Message: %s\r\n\r\n", error);
00897 }

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

Definition at line 899 of file manager.c.

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

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

00900 {
00901    const char *id = astman_get_header(m,"ActionID");
00902 
00903    astman_append(s, "Response: %s\r\n", resp);
00904    if (!ast_strlen_zero(id))
00905       astman_append(s, "ActionID: %s\r\n", id);
00906    if (msg)
00907       astman_append(s, "Message: %s\r\n\r\n", msg);
00908    else
00909       astman_append(s, "\r\n");
00910 }

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

Definition at line 1015 of file manager.c.

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

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

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

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

Convert authority code to string with serveral options.

Definition at line 265 of file manager.c.

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

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

00266 {
00267    int running_total = 0, i;
00268 
00269    memset(res, 0, reslen);
00270    for (i = 0; i < (sizeof(perms) / sizeof(perms[0])) - 1; i++) {
00271       if (authority & perms[i].num) {
00272          if (*res) {
00273             strncat(res, ",", (reslen > running_total) ? reslen - running_total - 1 : 0);
00274             running_total++;
00275          }
00276          strncat(res, perms[i].label, (reslen > running_total) ? reslen - running_total - 1 : 0);
00277          running_total += strlen(perms[i].label);
00278       }
00279    }
00280 
00281    if (ast_strlen_zero(res))
00282       ast_copy_string(res, "<none>", reslen);
00283    
00284    return res;
00285 }

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

Definition at line 1770 of file manager.c.

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

Referenced by action_command().

01771 {
01772    char *cmd_copy, *cur_cmd;
01773    char *cmd_words[MAX_BLACKLIST_CMD_LEN] = { NULL, };
01774    int i;
01775 
01776    cmd_copy = ast_strdupa(cmd);
01777    for (i = 0; i < MAX_BLACKLIST_CMD_LEN && (cur_cmd = strsep(&cmd_copy, " ")); i++) {
01778       cur_cmd = ast_strip(cur_cmd);
01779       if (ast_strlen_zero(cur_cmd)) {
01780          i--;
01781          continue;
01782       }
01783 
01784       cmd_words[i] = cur_cmd;
01785    }
01786 
01787    for (i = 0; i < ARRAY_LEN(command_blacklist); i++) {
01788       int j, match = 1;
01789 
01790       for (j = 0; command_blacklist[i].words[j]; j++) {
01791          if (ast_strlen_zero(cmd_words[j]) || strcasecmp(cmd_words[j], command_blacklist[i].words[j])) {
01792             match = 0;
01793             break;
01794          }
01795       }
01796 
01797       if (match) {
01798          return 1;
01799       }
01800    }
01801 
01802    return 0;
01803 }

int check_manager_enabled ( void   ) 

Check if AMI is enabled.

Definition at line 254 of file manager.c.

Referenced by handle_show_settings().

00255 {
00256    return manager_enabled;
00257 }

int check_webmanager_enabled ( void   ) 

Check if AMI/HTTP is enabled.

Definition at line 259 of file manager.c.

Referenced by action_coresettings(), and handle_show_settings().

00260 {
00261    return (webmanager_enabled && manager_enabled);
00262 }

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

Definition at line 287 of file manager.c.

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

00288 {
00289    struct manager_action *cur;
00290    int which = 0;
00291    char *ret = NULL;
00292 
00293    ast_rwlock_rdlock(&actionlock);
00294    for (cur = first_action; cur; cur = cur->next) { /* Walk the list of actions */
00295       if (!strncasecmp(word, cur->action, strlen(word)) && ++which > state) {
00296          ret = ast_strdup(cur->action);
00297          break;   /* make sure we exit even if ast_strdup() returns NULL */
00298       }
00299    }
00300    ast_rwlock_unlock(&actionlock);
00301 
00302    return ret;
00303 }

static int compress_char ( char  c  )  [static]

Definition at line 347 of file manager.c.

Referenced by member_hash_fn(), and variable_count_hash_fn().

00348 {
00349    c &= 0x7f;
00350    if (c < 32)
00351       return 0;
00352    else if (c >= 'a' && c <= 'z')
00353       return c - 64;
00354    else if (c > 'z')
00355       return '_';
00356    else
00357       return c - 32;
00358 }

static void destroy_session ( struct mansession_session s  )  [static]

Definition at line 816 of file manager.c.

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

Referenced by accept_thread(), and skinny_session().

00817 {
00818    AST_LIST_LOCK(&sessions);
00819    AST_LIST_REMOVE(&sessions, s, list);
00820    num_sessions--;
00821    free_session(s);
00822    AST_LIST_UNLOCK(&sessions);
00823 }

static int do_message ( struct mansession s  )  [static]

Definition at line 2503 of file manager.c.

References AST_MAX_MANHEADERS, ast_strdupa, ast_strlen_zero(), get_input(), message::hdrcount, message::headers, process_events(), process_message(), and s.

Referenced by session_do().

02504 {
02505    struct message m = { 0 };
02506    char header_buf[sizeof(s->session->inbuf)] = { '\0' };
02507    int res;
02508 
02509    for (;;) {
02510       /* Check if any events are pending and do them if needed */
02511       if (s->session->eventq->next) {
02512          if (process_events(s))
02513             return -1;
02514       }
02515       res = get_input(s->session, header_buf);
02516       if (res == 0) {
02517          continue;
02518       } else if (res > 0) {
02519          /* Strip trailing \r\n */
02520          if (strlen(header_buf) < 2)
02521             continue;
02522          header_buf[strlen(header_buf) - 2] = '\0';
02523          if (ast_strlen_zero(header_buf))
02524             return process_message(s, &m) ? -1 : 0;
02525          else if (m.hdrcount < (AST_MAX_MANHEADERS - 1))
02526             m.headers[m.hdrcount++] = ast_strdupa(header_buf);
02527       } else {
02528          return res;
02529       }
02530    }
02531 }

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

Definition at line 1907 of file manager.c.

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

Referenced by action_originate().

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

static void free_session ( struct mansession_session s  )  [static]

Definition at line 800 of file manager.c.

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

Referenced by accept_thread(), and destroy_session().

00801 {
00802    struct eventqent *eqe;
00803    if (s->fd > -1)
00804       close(s->fd);
00805    if (s->outputstr)
00806       free(s->outputstr);
00807    ast_mutex_destroy(&s->__lock);
00808    while (s->eventq) {
00809       eqe = s->eventq;
00810       s->eventq = s->eventq->next;
00811       unuse_eventqent(eqe);
00812    }
00813    free(s);
00814 }

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

Definition at line 2444 of file manager.c.

References ast_channel::fds, and s.

Referenced by do_message(), and skinny_session().

02445 {
02446    /* output must have at least sizeof(s->inbuf) space */
02447    int res;
02448    int x;
02449    struct pollfd fds[1];
02450    for (x = 1; x < s->inlen; x++) {
02451       if ((s->inbuf[x] == '\n') && (s->inbuf[x-1] == '\r')) {
02452          /* Copy output data up to and including \r\n */
02453          memcpy(output, s->inbuf, x + 1);
02454          /* Add trailing \0 */
02455          output[x+1] = '\0';
02456          /* Move remaining data back to the front */
02457          memmove(s->inbuf, s->inbuf + x + 1, s->inlen - x);
02458          s->inlen -= (x + 1);
02459          return 1;
02460       }
02461    } 
02462    if (s->inlen >= sizeof(s->inbuf) - 1) {
02463       ast_log(LOG_WARNING, "Dumping long line with no return from %s: %s\n", ast_inet_ntoa(s->sin.sin_addr), s->inbuf);
02464       s->inlen = 0;
02465    }
02466    fds[0].fd = s->fd;
02467    fds[0].events = POLLIN;
02468    do {
02469       ast_mutex_lock(&s->__lock);
02470       if (s->pending_event) {
02471          s->pending_event = 0;
02472          ast_mutex_unlock(&s->__lock);
02473          return 0;
02474       }
02475       s->waiting_thread = pthread_self();
02476       ast_mutex_unlock(&s->__lock);
02477 
02478       res = ast_poll(fds, 1, -1);
02479 
02480       ast_mutex_lock(&s->__lock);
02481       s->waiting_thread = AST_PTHREADT_NULL;
02482       ast_mutex_unlock(&s->__lock);
02483       if (res < 0) {
02484          if (errno == EINTR || errno == EAGAIN) {
02485             return 0;
02486          }
02487          ast_log(LOG_WARNING, "Select returned error: %s\n", strerror(errno));
02488          return -1;
02489       } else if (res > 0) {
02490          ast_mutex_lock(&s->__lock);
02491          res = read(s->fd, s->inbuf + s->inlen, sizeof(s->inbuf) - 1 - s->inlen);
02492          ast_mutex_unlock(&s->__lock);
02493          if (res < 1)
02494             return -1;
02495          break;
02496       }
02497    } while(1);
02498    s->inlen += res;
02499    s->inbuf[s->inlen] = '\0';
02500    return 0;
02501 }

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

Definition at line 940 of file manager.c.

References ast_instring(), and perms.

00941 {
00942    int x = 0, ret = 0;
00943 
00944    if (!instr)
00945       return 0;
00946 
00947    for (x = 0; x < (sizeof(perms) / sizeof(perms[0])); x++) {
00948       if (ast_instring(instr, perms[x].label, ','))
00949          ret |= perms[x].num;
00950    }
00951    
00952    return ret;
00953 }

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

Definition at line 593 of file manager.c.

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

00594 {
00595    struct ast_manager_user *user = NULL;
00596 
00597    if (argc != 4)
00598       return RESULT_SHOWUSAGE;
00599 
00600    AST_LIST_LOCK(&users);
00601 
00602    if (!(user = ast_get_manager_by_name_locked(argv[3]))) {
00603       ast_cli(fd, "There is no manager called %s\n", argv[3]);
00604       AST_LIST_UNLOCK(&users);
00605       return -1;
00606    }
00607 
00608    ast_cli(fd,"\n");
00609    ast_cli(fd,
00610       "       username: %s\n"
00611       "         secret: %s\n"
00612       "           deny: %s\n"
00613       "         permit: %s\n"
00614       "           read: %s\n"
00615       "          write: %s\n"
00616       "displayconnects: %s\n",
00617       (user->username ? user->username : "(N/A)"),
00618       (user->secret ? "<Set>" : "(N/A)"),
00619       (user->deny ? user->deny : "(N/A)"),
00620       (user->permit ? user->permit : "(N/A)"),
00621       (user->read ? user->read : "(N/A)"),
00622       (user->write ? user->write : "(N/A)"),
00623       (user->displayconnects ? "yes" : "no"));
00624 
00625    AST_LIST_UNLOCK(&users);
00626 
00627    return RESULT_SUCCESS;
00628 }

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

Definition at line 631 of file manager.c.

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

00632 {
00633    struct ast_manager_user *user = NULL;
00634    int count_amu = 0;
00635 
00636    if (argc != 3)
00637       return RESULT_SHOWUSAGE;
00638 
00639    AST_LIST_LOCK(&users);
00640 
00641    /* If there are no users, print out something along those lines */
00642    if (AST_LIST_EMPTY(&users)) {
00643       ast_cli(fd, "There are no manager users.\n");
00644       AST_LIST_UNLOCK(&users);
00645       return RESULT_SUCCESS;
00646    }
00647 
00648    ast_cli(fd, "\nusername\n--------\n");
00649 
00650    AST_LIST_TRAVERSE(&users, user, list) {
00651       ast_cli(fd, "%s\n", user->username);
00652       count_amu++;
00653    }
00654 
00655    AST_LIST_UNLOCK(&users);
00656 
00657    ast_cli(fd,"-------------------\n");
00658    ast_cli(fd,"%d manager users configured.\n", count_amu);
00659 
00660    return RESULT_SUCCESS;
00661 }

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

Definition at line 571 of file manager.c.

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

00572 {
00573    struct manager_action *cur;
00574    char authority[80];
00575    int num;
00576 
00577    if (argc != 4)
00578       return RESULT_SHOWUSAGE;
00579 
00580    ast_rwlock_rdlock(&actionlock);
00581    for (cur = first_action; cur; cur = cur->next) { /* Walk the list of actions */
00582       for (num = 3; num < argc; num++) {
00583          if (!strcasecmp(cur->action, argv[num])) {
00584             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 : "");
00585          }
00586       }
00587    }
00588    ast_rwlock_unlock(&actionlock);
00589 
00590    return RESULT_SUCCESS;
00591 }

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

CLI command Should change to "manager show commands".

Definition at line 666 of file manager.c.

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

00667 {
00668    struct manager_action *cur;
00669    char authority[80];
00670    char *format = "  %-15.15s  %-15.15s  %-55.55s\n";
00671 
00672    ast_cli(fd, format, "Action", "Privilege", "Synopsis");
00673    ast_cli(fd, format, "------", "---------", "--------");
00674    
00675    ast_rwlock_rdlock(&actionlock);
00676    for (cur = first_action; cur; cur = cur->next) /* Walk the list of actions */
00677       ast_cli(fd, format, cur->action, authority_to_str(cur->authority, authority, sizeof(authority) -1), cur->synopsis);
00678    ast_rwlock_unlock(&actionlock);
00679    
00680    return RESULT_SUCCESS;
00681 }

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

CLI command show manager connected.

Definition at line 685 of file manager.c.

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

00686 {
00687    struct mansession_session *s;
00688    char wtout[32];
00689    char *format = "  %-15.15s  %-15.15s  %-15.15s\n";
00690 
00691    ast_cli(fd, format, "Username", "IP Address", "Timeout");
00692    
00693    AST_LIST_LOCK(&sessions);
00694    AST_LIST_TRAVERSE(&sessions, s, list) {
00695       memset(wtout, 0, sizeof(wtout));
00696       snprintf(wtout, sizeof(wtout)-1, "%d", s->writetimeout);
00697       ast_cli(fd, format,s->username, ast_inet_ntoa(s->sin.sin_addr), wtout);
00698    }
00699    AST_LIST_UNLOCK(&sessions);
00700 
00701    return RESULT_SUCCESS;
00702 }

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

CLI command show manager eventq.

Definition at line 706 of file manager.c.

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

00707 {
00708    struct eventqent *s;
00709 
00710    AST_LIST_LOCK(&sessions);
00711    for (s = master_eventq; s; s = s->next) {
00712       ast_cli(fd, "Usecount: %d\n",s->usecount);
00713       ast_cli(fd, "Category: %d\n", s->category);
00714       ast_cli(fd, "Event:\n%s", s->eventdata);
00715    }
00716    AST_LIST_UNLOCK(&sessions);
00717 
00718    return RESULT_SUCCESS;
00719 }

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

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

01216 {
01217    int x;
01218    char hdr[40];
01219    const char *action, *cat, *var, *value, *match;
01220    struct ast_category *category;
01221    struct ast_variable *v;
01222    
01223    for (x=0;x<100000;x++) {
01224       unsigned int object = 0;
01225 
01226       snprintf(hdr, sizeof(hdr), "Action-%06d", x);
01227       action = astman_get_header(m, hdr);
01228       if (ast_strlen_zero(action))
01229          break;
01230       snprintf(hdr, sizeof(hdr), "Cat-%06d", x);
01231       cat = astman_get_header(m, hdr);
01232       snprintf(hdr, sizeof(hdr), "Var-%06d", x);
01233       var = astman_get_header(m, hdr);
01234       snprintf(hdr, sizeof(hdr), "Value-%06d", x);
01235       value = astman_get_header(m, hdr);
01236       if (!ast_strlen_zero(value) && *value == '>') {
01237          object = 1;
01238          value++;
01239       }
01240       snprintf(hdr, sizeof(hdr), "Match-%06d", x);
01241       match = astman_get_header(m, hdr);
01242       if (!strcasecmp(action, "newcat")) {
01243          if (!ast_strlen_zero(cat)) {
01244             category = ast_category_new(cat);
01245             if (category) {
01246                ast_category_append(cfg, category);
01247             }
01248          }
01249       } else if (!strcasecmp(action, "renamecat")) {
01250          if (!ast_strlen_zero(cat) && !ast_strlen_zero(value)) {
01251             category = ast_category_get(cfg, cat);
01252             if (category) 
01253                ast_category_rename(category, value);
01254          }
01255       } else if (!strcasecmp(action, "delcat")) {
01256          if (!ast_strlen_zero(cat))
01257             ast_category_delete(cfg, (char *) cat);
01258       } else if (!strcasecmp(action, "update")) {
01259          if (!ast_strlen_zero(cat) && !ast_strlen_zero(var) && (category = ast_category_get(cfg, cat)))
01260             ast_variable_update(category, var, value, match, object);
01261       } else if (!strcasecmp(action, "delete")) {
01262          if (!ast_strlen_zero(cat) && !ast_strlen_zero(var) && (category = ast_category_get(cfg, cat)))
01263             ast_variable_delete(category, (char *) var, (char *) match);
01264       } else if (!strcasecmp(action, "append")) {
01265          if (!ast_strlen_zero(cat) && !ast_strlen_zero(var) && 
01266             (category = ast_category_get(cfg, cat)) && 
01267             (v = ast_variable_new(var, value))){
01268             if (object || (match && !strcasecmp(match, "object")))
01269                v->object = 1;
01270             ast_variable_append(category, v);
01271          }
01272       }
01273    }
01274 }

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

Definition at line 482 of file manager.c.

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

00483 {
00484    int x;
00485    int colons = 0;
00486    int breaks = 0;
00487    size_t len;
00488    int count = 1;
00489    char *tmp, *var, *val, *out;
00490 
00491    for (x=0; in[x]; x++) {
00492       if (in[x] == ':')
00493          colons++;
00494       if (in[x] == '\n')
00495          breaks++;
00496    }
00497    len = strlen(in) + colons * 40 + breaks * 40; /* <tr><td></td><td></td></tr>, "<tr><td colspan=\"2\"><hr></td></tr> */
00498    out = ast_malloc(len);
00499    if (!out)
00500       return 0;
00501    tmp = out;
00502    while (*in) {
00503       var = in;
00504       while (*in && (*in >= 32))
00505          in++;
00506       if (*in) {
00507          if ((count % 4) == 0){
00508             ast_build_string(&tmp, &len, "<tr><td colspan=\"2\"><hr></td></tr>\r\n");
00509          }
00510          count = 0;
00511          while (*in && (*in < 32)) {
00512             *in = '\0';
00513             in++;
00514             count++;
00515          }
00516          val = strchr(var, ':');
00517          if (val) {
00518             *val = '\0';
00519             val++;
00520             if (*val == ' ')
00521                val++;
00522             ast_build_string(&tmp, &len, "<tr><td>%s</td><td>%s</td></tr>\r\n", var, val);
00523          }
00524       }
00525    }
00526    return out;
00527 }

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

manager_event: Send AMI event to client

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

Definition at line 2698 of file manager.c.

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

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

02699 {
02700    struct mansession_session *s;
02701    char auth[80];
02702    va_list ap;
02703    struct timeval now;
02704    struct ast_dynamic_str *buf;
02705 
02706    /* Abort if there aren't any manager sessions */
02707    if (!num_sessions)
02708       return 0;
02709 
02710    if (!(buf = ast_dynamic_str_thread_get(&manager_event_buf, MANAGER_EVENT_BUF_INITSIZE)))
02711       return -1;
02712 
02713    ast_dynamic_str_thread_set(&buf, 0, &manager_event_buf,
02714          "Event: %s\r\nPrivilege: %s\r\n",
02715           event, authority_to_str(category, auth, sizeof(auth)));
02716 
02717    if (timestampevents) {
02718       now = ast_tvnow();
02719       ast_dynamic_str_thread_append(&buf, 0, &manager_event_buf,
02720             "Timestamp: %ld.%06lu\r\n",
02721              now.tv_sec, (unsigned long) now.tv_usec);
02722    }
02723 
02724    va_start(ap, fmt);
02725    ast_dynamic_str_thread_append_va(&buf, 0, &manager_event_buf, fmt, ap);
02726    va_end(ap);
02727    
02728    ast_dynamic_str_thread_append(&buf, 0, &manager_event_buf, "\r\n");  
02729    
02730    /* Append event to master list and wake up any sleeping sessions */
02731    AST_LIST_LOCK(&sessions);
02732    append_event(buf->str, category);
02733    AST_LIST_TRAVERSE(&sessions, s, list) {
02734       ast_mutex_lock(&s->__lock);
02735       if (s->waiting_thread != AST_PTHREADT_NULL)
02736          pthread_kill(s->waiting_thread, SIGURG);
02737       else
02738          /* We have an event to process, but the mansession is
02739           * not waiting for it. We still need to indicate that there
02740           * is an event waiting so that get_input processes the pending
02741           * event instead of polling.
02742           */
02743          s->pending_event = 1;
02744       ast_mutex_unlock(&s->__lock);
02745    }
02746    AST_LIST_UNLOCK(&sessions);
02747 
02748    return 0;
02749 }

static void manager_event_buf_init ( void   )  [static]

Definition at line 117 of file manager.c.

00123 {

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

Definition at line 2777 of file manager.c.

References EVENT_FLAG_CALL, and manager_event().

Referenced by init_manager().

02778 {
02779    /* Notify managers of change */
02780    manager_event(EVENT_FLAG_CALL, "ExtensionStatus", "Exten: %s\r\nContext: %s\r\nStatus: %d\r\n", exten, context, state);
02781    return 0;
02782 }

static int process_events ( struct mansession s  )  [static]

Definition at line 2227 of file manager.c.

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

Referenced by do_message().

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

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

Definition at line 2362 of file manager.c.

References manager_action::action, actionlock, ast_copy_string(), 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(), manager_action::authority, displayconnects, first_action, manager_action::func, LOG_DEBUG, LOG_EVENT, manager_action::next, option_debug, option_verbose, s, and VERBOSE_PREFIX_2.

Referenced by do_message().

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

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

Definition at line 2533 of file manager.c.

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

Referenced by accept_thread().

02534 {
02535    struct mansession_session *session = data;
02536    int res;
02537    struct mansession s = { .session = session, .fd = session->fd };
02538 
02539    astman_append(&s, "Asterisk Call Manager/1.0\r\n");
02540    for (;;) {
02541       if ((res = do_message(&s)) < 0)
02542          break;
02543    }
02544    if (session->authenticated) {
02545       if (option_verbose > 1) {
02546          if (displayconnects) 
02547             ast_verbose(VERBOSE_PREFIX_2 "Manager '%s' logged off from %s\n", session->username, ast_inet_ntoa(session->sin.sin_addr));
02548       }
02549       ast_log(LOG_EVENT, "Manager '%s' logged off from %s\n", session->username, ast_inet_ntoa(session->sin.sin_addr));
02550    } else {
02551       if (option_verbose > 1) {
02552          if (displayconnects)
02553             ast_verbose(VERBOSE_PREFIX_2 "Connect attempt from '%s' unable to authenticate\n", ast_inet_ntoa(session->sin.sin_addr));
02554       }
02555       ast_log(LOG_EVENT, "Failed attempt from %s\n", ast_inet_ntoa(session->sin.sin_addr));
02556    }
02557 
02558    /* It is possible under certain circumstances for this session thread
02559       to complete its work and exit *before* the thread that created it
02560       has finished executing the ast_pthread_create_background() function.
02561       If this occurs, some versions of glibc appear to act in a buggy
02562       fashion and attempt to write data into memory that it thinks belongs
02563       to the thread but is in fact not owned by the thread (or may have
02564       been freed completely).
02565 
02566       Causing this thread to yield to other threads at least one time
02567       appears to work around this bug.
02568    */
02569    usleep(1);
02570 
02571    destroy_session(session);
02572    return NULL;
02573 }

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

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

Definition at line 1003 of file manager.c.

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

Referenced by action_events().

01004 {
01005    int maskint = strings_to_mask(eventmask);
01006 
01007    ast_mutex_lock(&s->__lock);
01008    if (maskint >= 0) 
01009       s->send_events = maskint;
01010    ast_mutex_unlock(&s->__lock);
01011    
01012    return maskint;
01013 }

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

Definition at line 972 of file manager.c.

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

Referenced by set_eventmask().

00973 {
00974    int x, ret = -1;
00975    
00976    x = ast_is_number(string);
00977 
00978    if (x)
00979       ret = x;
00980    else if (ast_strlen_zero(string))
00981       ret = -1;
00982    else if (ast_false(string))
00983       ret = 0;
00984    else if (ast_true(string)) {
00985       ret = 0;
00986       for (x=0; x<sizeof(perms) / sizeof(perms[0]); x++)
00987          ret |= perms[x].num;    
00988    } else {
00989       ret = 0;
00990       for (x=0; x<sizeof(perms) / sizeof(perms[0]); x++) {
00991          if (ast_instring(string, perms[x].label, ',')) 
00992             ret |= perms[x].num;    
00993       }
00994    }
00995 
00996    return ret;
00997 }

static void unuse_eventqent ( struct eventqent e  )  [static]

Definition at line 794 of file manager.c.

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

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

00795 {
00796    if (ast_atomic_dec_and_test(&e->usecount) && e->next)
00797       pthread_kill(t, SIGURG);
00798 }

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

Definition at line 372 of file manager.c.

References variable_count::varname.

Referenced by xml_translate().

00373 {
00374    /* Due to the simplicity of struct variable_count, it makes no difference
00375     * if you pass in objects or strings, the same operation applies. This is
00376     * due to the fact that the hash occurs on the first element, which means
00377     * the address of both the struct and the string are exactly the same. */
00378    struct variable_count *vc = obj;
00379    char *str = vstr;
00380    return !strcmp(vc->varname, str) ? CMP_MATCH | CMP_STOP : 0;
00381 }

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

Definition at line 360 of file manager.c.

References compress_char(), and variable_count::varname.

Referenced by xml_translate().

00361 {
00362    const struct variable_count *vc = vvc;
00363    int res = 0, i;
00364    for (i = 0; i < 5; i++) {
00365       if (vc->varname[i] == '\0')
00366          break;
00367       res += compress_char(vc->varname[i]) << (i * 6);
00368    }
00369    return res;
00370 }

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

Definition at line 305 of file manager.c.

Referenced by xml_translate().

00306 {
00307    while (*src && (*maxlen > 6)) {
00308       switch (*src) {
00309       case '<':
00310          strcpy(*dst, "&lt;");
00311          (*dst) += 4;
00312          *maxlen -= 4;
00313          break;
00314       case '>':
00315          strcpy(*dst, "&gt;");
00316          (*dst) += 4;
00317          *maxlen -= 4;
00318          break;
00319       case '\"':
00320          strcpy(*dst, "&quot;");
00321          (*dst) += 6;
00322          *maxlen -= 6;
00323          break;
00324       case '\'':
00325          strcpy(*dst, "&apos;");
00326          (*dst) += 6;
00327          *maxlen -= 6;
00328          break;
00329       case '&':
00330          strcpy(*dst, "&amp;");
00331          (*dst) += 5;
00332          *maxlen -= 5;
00333          break;      
00334       default:
00335          *(*dst)++ = lower ? tolower(*src) : *src;
00336          (*maxlen)--;
00337       }
00338       src++;
00339    }
00340 }

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

Definition at line 383 of file manager.c.

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

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


Variable Documentation

ast_rwlock_t actionlock = PTHREAD_RWLOCK_INITIALIZER [static]

Definition at line 252 of file manager.c.

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

int asock = -1 [static]

Definition at line 105 of file manager.c.

Referenced by accept_thread(), and init_manager().

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

Definition at line 120 of file manager.c.

Referenced by astman_append().

int block_sockets [static]

Definition at line 111 of file manager.c.

Referenced by accept_thread(), and init_manager().

struct ast_cli_entry cli_manager[] [static]

Definition at line 768 of file manager.c.

Referenced by init_manager().

struct ast_cli_entry cli_show_manager_command_deprecated [static]

Initial value:

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

Definition at line 748 of file manager.c.

struct ast_cli_entry cli_show_manager_commands_deprecated [static]

Initial value:

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

Definition at line 753 of file manager.c.

struct ast_cli_entry cli_show_manager_connected_deprecated [static]

Initial value:

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

Definition at line 758 of file manager.c.

struct ast_cli_entry cli_show_manager_eventq_deprecated [static]

Initial value:

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

Definition at line 763 of file manager.c.

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

Referenced by check_blacklist().

int displayconnects = 1 [static]

Definition at line 106 of file manager.c.

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

struct manager_action* first_action [static]

Definition at line 251 of file manager.c.

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

int httptimeout = 60 [static]

Definition at line 108 of file manager.c.

int manager_enabled = 0 [static]

Definition at line 101 of file manager.c.

Referenced by init_manager().

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

Definition at line 117 of file manager.c.

Referenced by manager_event().

char mandescr_atxfer[] [static]

Definition at line 1805 of file manager.c.

Referenced by init_manager().

char mandescr_command[] [static]

Initial value:

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

Definition at line 1848 of file manager.c.

Referenced by init_manager().

char mandescr_coresettings[] [static]

Initial value:

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

Definition at line 2282 of file manager.c.

char mandescr_corestatus[] [static]

Initial value:

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

Definition at line 2326 of file manager.c.

char mandescr_events[] [static]

Definition at line 1441 of file manager.c.

Referenced by init_manager().

char mandescr_extensionstate[] [static]

Definition at line 2155 of file manager.c.

Referenced by init_manager().

char mandescr_getconfig[] [static]

Initial value:

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

Definition at line 1172 of file manager.c.

Referenced by init_manager().

char mandescr_getvar[] [static]

Definition at line 1534 of file manager.c.

Referenced by init_manager().

char mandescr_hangup[] [static]

Initial value:

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

Definition at line 1473 of file manager.c.

Referenced by init_manager().

char mandescr_listcommands[] [static]

Initial value:

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

Definition at line 1416 of file manager.c.

Referenced by init_manager().

char mandescr_logoff[] [static]

Initial value:

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

Definition at line 1463 of file manager.c.

Referenced by init_manager().

char mandescr_mailboxcount[] [static]

Definition at line 2119 of file manager.c.

Referenced by init_manager().

char mandescr_mailboxstatus[] [static]

Help text for manager command mailboxstatus.

Definition at line 2087 of file manager.c.

Referenced by init_manager().

char mandescr_originate[] [static]

Definition at line 1956 of file manager.c.

Referenced by init_manager().

char mandescr_ping[] [static]

Initial value:

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

Definition at line 1161 of file manager.c.

Referenced by init_manager().

char mandescr_redirect[] [static]

Definition at line 1684 of file manager.c.

Referenced by init_manager().

char mandescr_setvar[] [static]

Definition at line 1497 of file manager.c.

Referenced by init_manager().

char mandescr_timeout[] [static]

Definition at line 2196 of file manager.c.

Referenced by init_manager().

char mandescr_updateconfig[] [static]

Definition at line 1276 of file manager.c.

Referenced by init_manager().

char mandescr_userevent[] [static]

Definition at line 2253 of file manager.c.

Referenced by init_manager().

char mandescr_waitevent[] [static]

Manager WAITEVENT.

Definition at line 1327 of file manager.c.

Referenced by init_manager().

struct eventqent* master_eventq = NULL

Definition at line 115 of file manager.c.

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

int num_sessions [static]

Definition at line 112 of file manager.c.

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

struct permalias perms[] [static]

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

int portno = DEFAULT_MANAGER_PORT [static]

Definition at line 104 of file manager.c.

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

char showmanager_help[] [static]

Initial value:

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

Definition at line 744 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 739 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 721 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 725 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 729 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 734 of file manager.c.

pthread_t t [static]

Definition at line 110 of file manager.c.

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

int timestampevents [static]

Definition at line 107 of file manager.c.

Referenced by init_manager(), and manager_event().

int webmanager_enabled = 0 [static]

Definition at line 102 of file manager.c.

Referenced by init_manager().

char* words[AST_MAX_CMD_LEN] [inherited]

Definition at line 141 of file manager.c.


Generated on Thu Dec 17 17:41:10 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7