Wed Oct 14 15:02:26 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 2573 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().

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

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 = mkstemp(template);
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    astman_append(s, "Response: Follows\r\nPrivilege: Command\r\n");
01875    if (!ast_strlen_zero(id))
01876       astman_append(s, "ActionID: %s\r\n", id);
01877    /* FIXME: Wedge a ActionID response in here, waiting for later changes */
01878    ast_cli_command(fd, cmd);  /* XXX need to change this to use a FILE * */
01879    l = lseek(fd, 0, SEEK_END);   /* how many chars available */
01880 
01881    /* This has a potential to overflow the stack.  Hence, use the heap. */
01882    buf = ast_calloc(1, l + 1);
01883    final_buf = ast_calloc(1, l + 1);
01884    if (buf) {
01885       lseek(fd, 0, SEEK_SET);
01886       if (read(fd, buf, l) < 0) {
01887          ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno));
01888       }
01889       buf[l] = '\0';
01890       if (final_buf) {
01891          term_strip(final_buf, buf, l);
01892          final_buf[l] = '\0';
01893       }
01894       astman_append(s, "%s", S_OR(final_buf, buf));
01895       ast_free(buf);
01896    }
01897    close(fd);
01898    unlink(template);
01899    astman_append(s, "--END COMMAND--\r\n\r\n");
01900    if (final_buf)
01901       ast_free(final_buf);
01902    return 0;
01903 }

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

Show PBX core settings information.

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

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

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

Show PBX core status information.

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

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

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 2164 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().

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

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 2128 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().

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

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

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

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

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

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

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

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 2201 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().

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

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

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

Referenced by init_manager().

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

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

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

Referenced by init_manager(), and manager_event().

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

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

References ast_free, ast_malloc, and ast_manager_register_struct().

Referenced by init_manager(), and load_module().

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

static int ast_manager_register_struct ( struct manager_action act  )  [static]

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

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

int ast_manager_unregister ( char *  action  ) 

Parameters:
action Name of registered Action:

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

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

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 2501 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().

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

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

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

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

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

References ast_channel::fds, and s.

Referenced by do_message(), and skinny_session().

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

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 2696 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(), 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().

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

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

References EVENT_FLAG_CALL, and manager_event().

Referenced by init_manager().

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

static int process_events ( struct mansession s  )  [static]

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

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

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

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

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

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

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

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

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 2280 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 2324 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 2153 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 2117 of file manager.c.

Referenced by init_manager().

char mandescr_mailboxstatus[] [static]

Help text for manager command mailboxstatus.

Definition at line 2085 of file manager.c.

Referenced by init_manager().

char mandescr_originate[] [static]

Definition at line 1954 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 2194 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 2251 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 Wed Oct 14 15:02:26 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7