Data Structures | |
| struct | actions |
| list of actions registered More... | |
| struct | all_events |
| struct | ast_manager_user |
| user descriptor, as read from the config file. More... | |
| struct | eventqent |
| struct | fast_originate_helper |
| helper function for originate More... | |
| struct | manager_hooks |
| list of hooks registered More... | |
| struct | mansession |
| struct | mansession_session |
| struct | permalias |
| struct | sessions |
| struct | users |
| list of users found in the config file More... | |
Defines | |
| #define | ASTMAN_APPEND_BUF_INITSIZE 256 |
| initial allocated size for the astman_append_buf | |
| #define | GET_HEADER_FIRST_MATCH 0 |
| #define | GET_HEADER_LAST_MATCH 1 |
| #define | GET_HEADER_SKIP_EMPTY 2 |
| #define | MANAGER_EVENT_BUF_INITSIZE 256 |
| #define | MAX_BLACKLIST_CMD_LEN 2 |
| Descriptor for a manager session, either on the AMI socket or over HTTP. | |
| #define | MSG_MOREDATA ((char *)astman_send_response) |
| send a response with an optional message, and terminate it with an empty line. m is used only to grab the 'ActionID' field. | |
Enumerations | |
| enum | error_type { UNKNOWN_ACTION = 1, UNKNOWN_CATEGORY, UNSPECIFIED_CATEGORY, UNSPECIFIED_ARGUMENT, FAILURE_ALLOCATION, FAILURE_NEWCAT, FAILURE_DELCAT, FAILURE_EMPTYCAT, FAILURE_UPDATE, FAILURE_DELETE, FAILURE_APPEND } |
Functions | |
| static const char * | __astman_get_header (const struct message *m, char *var, int mode) |
| static void | __init_astman_append_buf (void) |
| thread local buffer for astman_append | |
| static void | __init_manager_event_buf (void) |
| static void | __init_userevent_buf (void) |
| int | __manager_event (int category, const char *event, const char *file, int line, const char *func, const char *fmt,...) |
| manager_event: Send AMI event to client | |
| static int | action_atxfer (struct mansession *s, const struct message *m) |
| static int | action_challenge (struct mansession *s, const struct message *m) |
| static int | action_command (struct mansession *s, const struct message *m) |
| Manager command "command" - execute CLI command. | |
| static int | action_coresettings (struct mansession *s, const struct message *m) |
| Show PBX core settings information. | |
| static int | action_coreshowchannels (struct mansession *s, const struct message *m) |
| Manager command "CoreShowChannels" - List currently defined channels and some information about them. | |
| static int | action_corestatus (struct mansession *s, const struct message *m) |
| Show PBX core status information. | |
| static int | action_createconfig (struct mansession *s, const struct message *m) |
| static 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_getconfigjson (struct mansession *s, const struct message *m) |
| static int | action_getvar (struct mansession *s, const struct message *m) |
| static int | action_hangup (struct mansession *s, const struct message *m) |
| static int | action_listcategories (struct mansession *s, const struct message *m) |
| static int | action_listcommands (struct mansession *s, const struct message *m) |
| static int | action_login (struct mansession *s, const struct message *m) |
| static int | action_logoff (struct mansession *s, const struct message *m) |
| static int | action_mailboxcount (struct mansession *s, const struct message *m) |
| static int | action_mailboxstatus (struct mansession *s, const struct message *m) |
| static int | action_originate (struct mansession *s, const struct message *m) |
| static int | action_ping (struct mansession *s, const struct message *m) |
| static int | action_redirect (struct mansession *s, const struct message *m) |
| action_redirect: The redirect manager command | |
| static int | action_reload (struct mansession *s, const struct message *m) |
| Send a reload event. | |
| static int | action_sendtext (struct mansession *s, const struct message *m) |
| static int | action_setvar (struct mansession *s, const struct message *m) |
| static int | action_status (struct mansession *s, const struct message *m) |
| Manager "status" command to show channels. | |
| static int | action_timeout (struct mansession *s, const struct message *m) |
| static int | action_updateconfig (struct mansession *s, const struct message *m) |
| static int | action_userevent (struct mansession *s, const struct message *m) |
| static int | action_waitevent (struct mansession *s, const struct message *m) |
| static struct eventqent * | advance_event (struct eventqent *e) |
| static int | append_event (const char *str, int category) |
| static int | ast_instring (const char *bigstr, const char *smallstr, const char delim) |
| int | ast_manager_register2 (const char *action, int auth, int(*func)(struct mansession *s, const struct message *m), const char *synopsis, const char *description) |
| register a new command with manager, including online help. This is the preferred way to register a manager command | |
| void | ast_manager_register_hook (struct manager_custom_hook *hook) |
| Add a custom hook to be called when an event is fired. | |
| static int | ast_manager_register_struct (struct manager_action *act) |
| int | ast_manager_unregister (char *action) |
| Unregister a registered manager command. | |
| void | ast_manager_unregister_hook (struct manager_custom_hook *hook) |
| Delete a custom hook to be called when an event is fired. | |
| void | astman_append (struct mansession *s, const char *fmt,...) |
| const char * | astman_get_header (const struct message *m, char *var) |
| Get header from mananger transaction. | |
| struct ast_variable * | astman_get_variables (const struct message *m) |
| Get a linked list of the Variable: headers. | |
| void | astman_send_ack (struct mansession *s, const struct message *m, char *msg) |
| Send ack in manager transaction. | |
| void | astman_send_error (struct mansession *s, const struct message *m, char *error) |
| Send error in manager transaction. | |
| void | astman_send_listack (struct mansession *s, const struct message *m, char *msg, char *listflag) |
| Send ack in manager list transaction. | |
| void | astman_send_response (struct mansession *s, const struct message *m, char *resp, char *msg) |
| Send response in manager transaction. | |
| static void | astman_send_response_full (struct mansession *s, const struct message *m, char *resp, char *msg, char *listflag) |
| static void | astman_start_ack (struct mansession *s, const struct message *m) |
| static int | authenticate (struct mansession *s, const struct message *m) |
| static char * | authority_to_str (int authority, struct ast_str **res) |
| Convert authority code to a list of options. | |
| static int | check_blacklist (const char *cmd) |
| int | check_manager_enabled () |
| Event list management functions. We assume that the event list always has at least one element, and the delete code will not remove the last entry even if the. | |
| static int | check_manager_session_inuse (const char *name) |
| int | check_webmanager_enabled () |
| Check if AMI/HTTP is enabled. | |
| static void | destroy_session (struct mansession_session *session) |
| static int | do_message (struct mansession *s) |
| static void * | fast_originate (void *data) |
| static void | free_session (struct mansession_session *session) |
| static int | get_input (struct mansession *s, char *output) |
| static struct ast_manager_user * | get_manager_by_name_locked (const char *name) |
| static int | get_perm (const char *instr) |
| static struct eventqent * | grab_last (void) |
| static char * | handle_manager_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI command manager reload. | |
| static char * | handle_mandebug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_showmanager (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_showmanagers (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_showmancmd (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_showmancmds (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI command manager list commands. | |
| static char * | handle_showmanconn (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI command manager list connected. | |
| static char * | handle_showmaneventq (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI command manager list eventq. | |
| static enum error_type | handle_updates (struct mansession *s, const struct message *m, struct ast_config *cfg, const char *dfn) |
| static void | json_escape (char *out, const char *in) |
| static int | manager_displayconnects (struct mansession_session *session) |
| Get displayconnects config option. | |
| static int | manager_modulecheck (struct mansession *s, const struct message *m) |
| static int | manager_moduleload (struct mansession *s, const struct message *m) |
| static int | manager_state_cb (char *context, char *exten, int state, void *data) |
| static int | process_events (struct mansession *s) |
| static int | process_message (struct mansession *s, const struct message *m) |
| static void | purge_events (void) |
| static void | purge_sessions (int n_max) |
| remove at most n_max stale session from the list. | |
| static int | send_string (struct mansession *s, char *string) |
| static void * | session_do (void *data) |
| The body of the individual manager session. Call get_input() to read one line at a time (or be woken up on new events), collect the lines in a message until found an empty line, and execute the request. In any case, deliver events asynchronously through process_events() (called from here if no line is available, or at the end of process_message(). ). | |
| static int | set_eventmask (struct mansession *s, const char *eventmask) |
| Rather than braindead on,off this now can also accept a specific int mask value or a ',' delim list of mask strings (the same as manager.conf) -anthm. | |
| static int | strings_to_mask (const char *string) |
Variables | |
| static int | allowmultiplelogin = 1 |
| static struct ast_threadstorage | astman_append_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_astman_append_buf , .custom_init = NULL , } |
| static int | block_sockets |
| static int | broken_events_action |
| static struct ast_cli_entry | cli_manager [] |
| struct { | |
| char * words [AST_MAX_CMD_LEN] | |
| } | command_blacklist [] |
| static const int | DEFAULT_BLOCKSOCKETS = 0 |
| static const int | DEFAULT_BROKENEVENTSACTION = 0 |
| static const int | DEFAULT_DISPLAYCONNECTS = 1 |
| static const int | DEFAULT_ENABLED = 0 |
| static const int | DEFAULT_HTTPTIMEOUT = 60 |
| static const int | DEFAULT_TIMESTAMPEVENTS = 0 |
| static const int | DEFAULT_WEBENABLED = 0 |
| static int | displayconnects |
| static int | httptimeout |
| static int | manager_debug |
| static int | manager_enabled = 0 |
| static struct ast_threadstorage | manager_event_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_manager_event_buf , .custom_init = NULL , } |
| static char | mandescr_atxfer [] |
| static char | mandescr_command [] |
| static char | mandescr_coresettings [] |
| static char | mandescr_coreshowchannels [] |
| static char | mandescr_corestatus [] |
| static char | mandescr_createconfig [] |
| static char | mandescr_events [] |
| static char | mandescr_extensionstate [] |
| static char | mandescr_getconfig [] |
| static char | mandescr_getconfigjson [] |
| static char | mandescr_getvar [] |
| static char | mandescr_hangup [] |
| static char | mandescr_listcategories [] |
| 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_modulecheck [] |
| static char | mandescr_moduleload [] |
| static char | mandescr_originate [] |
| static char | mandescr_ping [] |
| Manager PING. | |
| static char | mandescr_redirect [] |
| static char | mandescr_reload [] |
| static char | mandescr_sendtext [] |
| static char | mandescr_setvar [] |
| static char | mandescr_status [] |
| static char | mandescr_timeout [] |
| static char | mandescr_updateconfig [] |
| static char | mandescr_userevent [] |
| static char | mandescr_waitevent [] |
| Manager WAITEVENT. | |
| static int | num_sessions |
| static struct permalias | perms [] |
| static int | timestampevents |
| static struct ast_threadstorage | userevent_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_userevent_buf , .custom_init = NULL , } |
| static int | webmanager_enabled = 0 |
callback to display list of locally configured nodes
| #define ASTMAN_APPEND_BUF_INITSIZE 256 |
initial allocated size for the astman_append_buf
Definition at line 985 of file manager.c.
Referenced by astman_append().
| #define GET_HEADER_FIRST_MATCH 0 |
| #define GET_HEADER_LAST_MATCH 1 |
| #define GET_HEADER_SKIP_EMPTY 2 |
Definition at line 890 of file manager.c.
Referenced by __astman_get_header(), and process_message().
| #define MANAGER_EVENT_BUF_INITSIZE 256 |
| #define MAX_BLACKLIST_CMD_LEN 2 |
Descriptor for a manager session, either on the AMI socket or over HTTP.
Definition at line 153 of file manager.c.
Referenced by check_blacklist().
| #define MSG_MOREDATA ((char *)astman_send_response) |
send a response with an optional message, and terminate it with an empty line. m is used only to grab the 'ActionID' field.
Definition at line 1025 of file manager.c.
Referenced by astman_send_response_full(), and astman_start_ack().
| enum error_type |
Doxygen group
| UNKNOWN_ACTION | |
| UNKNOWN_CATEGORY | |
| UNSPECIFIED_CATEGORY | |
| UNSPECIFIED_ARGUMENT | |
| FAILURE_ALLOCATION | |
| FAILURE_NEWCAT | |
| FAILURE_DELCAT | |
| FAILURE_EMPTYCAT | |
| FAILURE_UPDATE | |
| FAILURE_DELETE | |
| FAILURE_APPEND |
Definition at line 78 of file manager.c.
00078 { 00079 UNKNOWN_ACTION = 1, 00080 UNKNOWN_CATEGORY, 00081 UNSPECIFIED_CATEGORY, 00082 UNSPECIFIED_ARGUMENT, 00083 FAILURE_ALLOCATION, 00084 FAILURE_NEWCAT, 00085 FAILURE_DELCAT, 00086 FAILURE_EMPTYCAT, 00087 FAILURE_UPDATE, 00088 FAILURE_DELETE, 00089 FAILURE_APPEND 00090 };
| static const char* __astman_get_header | ( | const struct message * | m, | |
| char * | var, | |||
| int | mode | |||
| ) | [static] |
Definition at line 891 of file manager.c.
References ast_strlen_zero(), GET_HEADER_LAST_MATCH, GET_HEADER_SKIP_EMPTY, message::hdrcount, and message::headers.
Referenced by astman_get_header(), and process_message().
00892 { 00893 int x, l = strlen(var); 00894 const char *result = ""; 00895 00896 for (x = 0; x < m->hdrcount; x++) { 00897 const char *h = m->headers[x]; 00898 if (!strncasecmp(var, h, l) && h[l] == ':' && h[l+1] == ' ') { 00899 const char *value = h + l + 2; 00900 /* found a potential candidate */ 00901 if (mode & GET_HEADER_SKIP_EMPTY && ast_strlen_zero(value)) 00902 continue; /* not interesting */ 00903 if (mode & GET_HEADER_LAST_MATCH) 00904 result = value; /* record the last match so far */ 00905 else 00906 return value; 00907 } 00908 } 00909 00910 return ""; 00911 }
| static void __init_astman_append_buf | ( | void | ) | [static] |
thread local buffer for astman_append
Definition at line 981 of file manager.c.
| static void __init_manager_event_buf | ( | void | ) | [static] |
| static void __init_userevent_buf | ( | void | ) | [static] |
| int __manager_event | ( | int | category, | |
| const char * | event, | |||
| const char * | file, | |||
| int | line, | |||
| const char * | func, | |||
| const char * | fmt, | |||
| ... | ||||
| ) |
manager_event: Send AMI event to client
Definition at line 3353 of file manager.c.
References mansession_session::__lock, append_event(), ast_atomic_fetchadd_int(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_mutex_lock(), ast_mutex_unlock(), AST_PTHREADT_NULL, AST_RWLIST_EMPTY, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_str_alloca, ast_str_append(), ast_str_append_va(), ast_str_buffer(), ast_str_set(), ast_str_thread_get(), ast_tvnow(), authority_to_str(), buf, manager_custom_hook::helper, manager_event_buf, MANAGER_EVENT_BUF_INITSIZE, mansession_session::pending_event, eventqent::seq, and mansession_session::waiting_thread.
03355 { 03356 struct mansession_session *session; 03357 struct manager_custom_hook *hook; 03358 struct ast_str *auth = ast_str_alloca(80); 03359 const char *cat_str; 03360 va_list ap; 03361 struct timeval now; 03362 struct ast_str *buf; 03363 03364 /* Abort if there are neither any manager sessions nor hooks */ 03365 if (!num_sessions && AST_RWLIST_EMPTY(&manager_hooks)) 03366 return 0; 03367 03368 if (!(buf = ast_str_thread_get(&manager_event_buf, MANAGER_EVENT_BUF_INITSIZE))) 03369 return -1; 03370 03371 cat_str = authority_to_str(category, &auth); 03372 ast_str_set(&buf, 0, 03373 "Event: %s\r\nPrivilege: %s\r\n", 03374 event, cat_str); 03375 03376 if (timestampevents) { 03377 now = ast_tvnow(); 03378 ast_str_append(&buf, 0, 03379 "Timestamp: %ld.%06lu\r\n", 03380 (long)now.tv_sec, (unsigned long) now.tv_usec); 03381 } 03382 if (manager_debug) { 03383 static int seq; 03384 ast_str_append(&buf, 0, 03385 "SequenceNumber: %d\r\n", 03386 ast_atomic_fetchadd_int(&seq, 1)); 03387 ast_str_append(&buf, 0, 03388 "File: %s\r\nLine: %d\r\nFunc: %s\r\n", file, line, func); 03389 } 03390 03391 va_start(ap, fmt); 03392 ast_str_append_va(&buf, 0, fmt, ap); 03393 va_end(ap); 03394 03395 ast_str_append(&buf, 0, "\r\n"); 03396 03397 append_event(ast_str_buffer(buf), category); 03398 03399 if (num_sessions) { 03400 /* Wake up any sleeping sessions */ 03401 AST_LIST_LOCK(&sessions); 03402 AST_LIST_TRAVERSE(&sessions, session, list) { 03403 ast_mutex_lock(&session->__lock); 03404 if (session->waiting_thread != AST_PTHREADT_NULL) 03405 pthread_kill(session->waiting_thread, SIGURG); 03406 else 03407 /* We have an event to process, but the mansession is 03408 * not waiting for it. We still need to indicate that there 03409 * is an event waiting so that get_input processes the pending 03410 * event instead of polling. 03411 */ 03412 session->pending_event = 1; 03413 ast_mutex_unlock(&session->__lock); 03414 } 03415 AST_LIST_UNLOCK(&sessions); 03416 } 03417 03418 if (!AST_RWLIST_EMPTY(&manager_hooks)) { 03419 AST_RWLIST_RDLOCK(&manager_hooks); 03420 AST_RWLIST_TRAVERSE(&manager_hooks, hook, list) { 03421 hook->helper(category, event, ast_str_buffer(buf)); 03422 } 03423 AST_RWLIST_UNLOCK(&manager_hooks); 03424 } 03425 03426 return 0; 03427 }
| static int action_atxfer | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2213 of file manager.c.
References ast_channel_unlock, ast_find_call_feature(), AST_FRAME_DTMF, ast_get_channel_by_name_locked(), ast_queue_frame(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), chan, context, ast_call_feature::exten, exten, name, and pbx_builtin_setvar_helper().
Referenced by __init_manager().
02214 { 02215 const char *name = astman_get_header(m, "Channel"); 02216 const char *exten = astman_get_header(m, "Exten"); 02217 const char *context = astman_get_header(m, "Context"); 02218 struct ast_channel *chan = NULL; 02219 struct ast_call_feature *atxfer_feature = NULL; 02220 char *feature_code = NULL; 02221 02222 if (ast_strlen_zero(name)) { 02223 astman_send_error(s, m, "No channel specified"); 02224 return 0; 02225 } 02226 if (ast_strlen_zero(exten)) { 02227 astman_send_error(s, m, "No extension specified"); 02228 return 0; 02229 } 02230 02231 if (!(atxfer_feature = ast_find_call_feature("atxfer"))) { 02232 astman_send_error(s, m, "No attended transfer feature found"); 02233 return 0; 02234 } 02235 02236 if (!(chan = ast_get_channel_by_name_locked(name))) { 02237 astman_send_error(s, m, "Channel specified does not exist"); 02238 return 0; 02239 } 02240 02241 if (!ast_strlen_zero(context)) { 02242 pbx_builtin_setvar_helper(chan, "TRANSFER_CONTEXT", context); 02243 } 02244 02245 for (feature_code = atxfer_feature->exten; feature_code && *feature_code; ++feature_code) { 02246 struct ast_frame f = {AST_FRAME_DTMF, *feature_code}; 02247 ast_queue_frame(chan, &f); 02248 } 02249 02250 for (feature_code = (char *)exten; feature_code && *feature_code; ++feature_code) { 02251 struct ast_frame f = {AST_FRAME_DTMF, *feature_code}; 02252 ast_queue_frame(chan, &f); 02253 } 02254 02255 astman_send_ack(s, m, "Atxfer successfully queued"); 02256 ast_channel_unlock(chan); 02257 02258 return 0; 02259 }
| static int action_challenge | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1800 of file manager.c.
References mansession_session::__lock, ast_mutex_lock(), ast_mutex_unlock(), ast_random(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), mansession_session::challenge, and mansession::session.
Referenced by __init_manager().
01801 { 01802 const char *authtype = astman_get_header(m, "AuthType"); 01803 01804 if (!strcasecmp(authtype, "MD5")) { 01805 if (ast_strlen_zero(s->session->challenge)) 01806 snprintf(s->session->challenge, sizeof(s->session->challenge), "%ld", ast_random()); 01807 ast_mutex_lock(&s->session->__lock); 01808 astman_start_ack(s, m); 01809 astman_append(s, "Challenge: %s\r\n\r\n", s->session->challenge); 01810 ast_mutex_unlock(&s->session->__lock); 01811 } else { 01812 astman_send_error(s, m, "Must specify AuthType"); 01813 } 01814 return 0; 01815 }
| static int action_command | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Manager command "command" - execute CLI command.
Definition at line 2303 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(), buf, check_blacklist(), errno, LOG_WARNING, S_OR, and term_strip().
Referenced by __init_manager().
02304 { 02305 const char *cmd = astman_get_header(m, "Command"); 02306 const char *id = astman_get_header(m, "ActionID"); 02307 char *buf, *final_buf; 02308 char template[] = "/tmp/ast-ami-XXXXXX"; /* template for temporary file */ 02309 int fd; 02310 off_t l; 02311 02312 if (ast_strlen_zero(cmd)) { 02313 astman_send_error(s, m, "No command provided"); 02314 return 0; 02315 } 02316 02317 if (check_blacklist(cmd)) { 02318 astman_send_error(s, m, "Command blacklisted"); 02319 return 0; 02320 } 02321 02322 fd = mkstemp(template); 02323 02324 astman_append(s, "Response: Follows\r\nPrivilege: Command\r\n"); 02325 if (!ast_strlen_zero(id)) 02326 astman_append(s, "ActionID: %s\r\n", id); 02327 /* FIXME: Wedge a ActionID response in here, waiting for later changes */ 02328 ast_cli_command(fd, cmd); /* XXX need to change this to use a FILE * */ 02329 l = lseek(fd, 0, SEEK_END); /* how many chars available */ 02330 02331 /* This has a potential to overflow the stack. Hence, use the heap. */ 02332 buf = ast_calloc(1, l + 1); 02333 final_buf = ast_calloc(1, l + 1); 02334 if (buf) { 02335 lseek(fd, 0, SEEK_SET); 02336 if (read(fd, buf, l) < 0) { 02337 ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno)); 02338 } 02339 buf[l] = '\0'; 02340 if (final_buf) { 02341 term_strip(final_buf, buf, l); 02342 final_buf[l] = '\0'; 02343 } 02344 astman_append(s, "%s", S_OR(final_buf, buf)); 02345 ast_free(buf); 02346 } 02347 close(fd); 02348 unlink(template); 02349 astman_append(s, "--END COMMAND--\r\n\r\n"); 02350 if (final_buf) 02351 ast_free(final_buf); 02352 return 0; 02353 }
| static int action_coresettings | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Show PBX core settings information.
Definition at line 2760 of file manager.c.
References AMI_VERSION, ast_config_AST_RUN_GROUP, ast_config_AST_RUN_USER, ast_config_AST_SYSTEM_NAME, ast_get_version(), ast_realtime_enabled(), ast_strlen_zero(), astman_append(), astman_get_header(), check_cdr_enabled(), check_webmanager_enabled(), option_maxcalls, option_maxfiles, and option_maxload.
Referenced by __init_manager().
02761 { 02762 const char *actionid = astman_get_header(m, "ActionID"); 02763 char idText[150]; 02764 02765 if (!ast_strlen_zero(actionid)) 02766 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid); 02767 else 02768 idText[0] = '\0'; 02769 02770 astman_append(s, "Response: Success\r\n" 02771 "%s" 02772 "AMIversion: %s\r\n" 02773 "AsteriskVersion: %s\r\n" 02774 "SystemName: %s\r\n" 02775 "CoreMaxCalls: %d\r\n" 02776 "CoreMaxLoadAvg: %f\r\n" 02777 "CoreRunUser: %s\r\n" 02778 "CoreRunGroup: %s\r\n" 02779 "CoreMaxFilehandles: %d\r\n" 02780 "CoreRealTimeEnabled: %s\r\n" 02781 "CoreCDRenabled: %s\r\n" 02782 "CoreHTTPenabled: %s\r\n" 02783 "\r\n", 02784 idText, 02785 AMI_VERSION, 02786 ast_get_version(), 02787 ast_config_AST_SYSTEM_NAME, 02788 option_maxcalls, 02789 option_maxload, 02790 ast_config_AST_RUN_USER, 02791 ast_config_AST_RUN_GROUP, 02792 option_maxfiles, 02793 ast_realtime_enabled() ? "Yes" : "No", 02794 check_cdr_enabled() ? "Yes" : "No", 02795 check_webmanager_enabled() ? "Yes" : "No" 02796 ); 02797 return 0; 02798 }
| static int action_coreshowchannels | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Manager command "CoreShowChannels" - List currently defined channels and some information about them.
Definition at line 2865 of file manager.c.
References ast_channel::_state, ast_channel::accountcode, ast_channel::appl, ast_bridged_channel(), ast_channel_unlock, ast_channel_walk_locked(), ast_state2str(), ast_strlen_zero(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), astman_append(), astman_get_header(), astman_send_listack(), ast_channel::cdr, ast_channel::cid, ast_callerid::cid_num, ast_channel::context, ast_channel::data, ast_channel::exten, ast_channel::name, ast_channel::priority, S_OR, ast_cdr::start, and ast_channel::uniqueid.
Referenced by __init_manager().
02866 { 02867 const char *actionid = astman_get_header(m, "ActionID"); 02868 char idText[256]; 02869 struct ast_channel *c = NULL; 02870 int numchans = 0; 02871 int duration, durh, durm, durs; 02872 02873 if (!ast_strlen_zero(actionid)) 02874 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid); 02875 else 02876 idText[0] = '\0'; 02877 02878 astman_send_listack(s, m, "Channels will follow", "start"); 02879 02880 while ((c = ast_channel_walk_locked(c)) != NULL) { 02881 struct ast_channel *bc = ast_bridged_channel(c); 02882 char durbuf[10] = ""; 02883 02884 if (c->cdr && !ast_tvzero(c->cdr->start)) { 02885 duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000); 02886 durh = duration / 3600; 02887 durm = (duration % 3600) / 60; 02888 durs = duration % 60; 02889 snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs); 02890 } 02891 02892 astman_append(s, 02893 "Event: CoreShowChannel\r\n" 02894 "%s" 02895 "Channel: %s\r\n" 02896 "UniqueID: %s\r\n" 02897 "Context: %s\r\n" 02898 "Extension: %s\r\n" 02899 "Priority: %d\r\n" 02900 "ChannelState: %d\r\n" 02901 "ChannelStateDesc: %s\r\n" 02902 "Application: %s\r\n" 02903 "ApplicationData: %s\r\n" 02904 "CallerIDnum: %s\r\n" 02905 "Duration: %s\r\n" 02906 "AccountCode: %s\r\n" 02907 "BridgedChannel: %s\r\n" 02908 "BridgedUniqueID: %s\r\n" 02909 "\r\n", idText, c->name, c->uniqueid, c->context, c->exten, c->priority, c->_state, 02910 ast_state2str(c->_state), c->appl ? c->appl : "", c->data ? S_OR(c->data, "") : "", 02911 S_OR(c->cid.cid_num, ""), durbuf, S_OR(c->accountcode, ""), bc ? bc->name : "", bc ? bc->uniqueid : ""); 02912 ast_channel_unlock(c); 02913 numchans++; 02914 } 02915 02916 astman_append(s, 02917 "Event: CoreShowChannelsComplete\r\n" 02918 "EventList: Complete\r\n" 02919 "ListItems: %d\r\n" 02920 "%s" 02921 "\r\n", numchans, idText); 02922 02923 return 0; 02924 }
| static int action_corestatus | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Show PBX core status information.
Definition at line 2806 of file manager.c.
References ast_active_channels(), ast_lastreloadtime, ast_localtime(), ast_startuptime, ast_strftime(), ast_strlen_zero(), astman_append(), and astman_get_header().
Referenced by __init_manager().
02807 { 02808 const char *actionid = astman_get_header(m, "ActionID"); 02809 char idText[150]; 02810 char startuptime[150]; 02811 char reloadtime[150]; 02812 struct ast_tm tm; 02813 02814 if (!ast_strlen_zero(actionid)) 02815 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid); 02816 else 02817 idText[0] = '\0'; 02818 02819 ast_localtime(&ast_startuptime, &tm, NULL); 02820 ast_strftime(startuptime, sizeof(startuptime), "%H:%M:%S", &tm); 02821 ast_localtime(&ast_lastreloadtime, &tm, NULL); 02822 ast_strftime(reloadtime, sizeof(reloadtime), "%H:%M:%S", &tm); 02823 02824 astman_append(s, "Response: Success\r\n" 02825 "%s" 02826 "CoreStartupTime: %s\r\n" 02827 "CoreReloadTime: %s\r\n" 02828 "CoreCurrentCalls: %d\r\n" 02829 "\r\n", 02830 idText, 02831 startuptime, 02832 reloadtime, 02833 ast_active_channels() 02834 ); 02835 return 0; 02836 }
| static int action_createconfig | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1586 of file manager.c.
References ast_config_AST_CONFIG_DIR, AST_FILE_MODE, ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_str_set(), astman_get_header(), astman_send_ack(), astman_send_error(), and errno.
Referenced by __init_manager().
01587 { 01588 int fd; 01589 const char *fn = astman_get_header(m, "Filename"); 01590 struct ast_str *filepath = ast_str_alloca(PATH_MAX); 01591 ast_str_set(&filepath, 0, "%s/", ast_config_AST_CONFIG_DIR); 01592 ast_str_append(&filepath, 0, "%s", fn); 01593 01594 if ((fd = open(ast_str_buffer(filepath), O_CREAT | O_EXCL, AST_FILE_MODE)) != -1) { 01595 close(fd); 01596 astman_send_ack(s, m, "New configuration file created successfully"); 01597 } else { 01598 astman_send_error(s, m, strerror(errno)); 01599 } 01600 01601 return 0; 01602 }
| static int action_events | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1736 of file manager.c.
References ARRAY_LEN, astman_append(), astman_get_header(), astman_send_error(), permalias::num, perms, and set_eventmask().
Referenced by __init_manager().
01737 { 01738 const char *mask = astman_get_header(m, "EventMask"); 01739 int res, x; 01740 01741 res = set_eventmask(s, mask); 01742 if (broken_events_action) { 01743 /* if this option is set we should not return a response on 01744 * error, or when all events are set */ 01745 01746 if (res > 0) { 01747 for (x = 0; x < ARRAY_LEN(perms); x++) { 01748 if (!strcasecmp(perms[x].label, "all") && res == perms[x].num) { 01749 return 0; 01750 } 01751 } 01752 astman_append(s, "Response: Success\r\n" 01753 "Events: On\r\n\r\n"); 01754 } else if (res == 0) 01755 astman_append(s, "Response: Success\r\n" 01756 "Events: Off\r\n\r\n"); 01757 return 0; 01758 } 01759 01760 if (res > 0) 01761 astman_append(s, "Response: Success\r\n" 01762 "Events: On\r\n\r\n"); 01763 else if (res == 0) 01764 astman_append(s, "Response: Success\r\n" 01765 "Events: Off\r\n\r\n"); 01766 else 01767 astman_send_error(s, m, "Invalid event mask"); 01768 01769 return 0; 01770 }
| static int action_extensionstate | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2642 of file manager.c.
References ast_extension_state(), ast_get_hint(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), context, exten, and status.
Referenced by __init_manager().
02643 { 02644 const char *exten = astman_get_header(m, "Exten"); 02645 const char *context = astman_get_header(m, "Context"); 02646 char hint[256] = ""; 02647 int status; 02648 if (ast_strlen_zero(exten)) { 02649 astman_send_error(s, m, "Extension not specified"); 02650 return 0; 02651 } 02652 if (ast_strlen_zero(context)) 02653 context = "default"; 02654 status = ast_extension_state(NULL, context, exten); 02655 ast_get_hint(hint, sizeof(hint) - 1, NULL, 0, NULL, context, exten); 02656 astman_start_ack(s, m); 02657 astman_append(s, "Message: Extension Status\r\n" 02658 "Exten: %s\r\n" 02659 "Context: %s\r\n" 02660 "Hint: %s\r\n" 02661 "Status: %d\r\n\r\n", 02662 exten, context, hint, status); 02663 return 0; 02664 }
| static int action_getconfig | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1177 of file manager.c.
References ast_category_browse(), ast_config_destroy(), ast_config_load2(), ast_strlen_zero(), ast_variable_browse(), astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), eventqent::category, CONFIG_FLAG_NOCACHE, CONFIG_FLAG_WITHCOMMENTS, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by __init_manager().
01178 { 01179 struct ast_config *cfg; 01180 const char *fn = astman_get_header(m, "Filename"); 01181 const char *category = astman_get_header(m, "Category"); 01182 int catcount = 0; 01183 int lineno = 0; 01184 char *cur_category = NULL; 01185 struct ast_variable *v; 01186 struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE }; 01187 01188 if (ast_strlen_zero(fn)) { 01189 astman_send_error(s, m, "Filename not specified"); 01190 return 0; 01191 } 01192 cfg = ast_config_load2(fn, "manager", config_flags); 01193 if (cfg == CONFIG_STATUS_FILEMISSING) { 01194 astman_send_error(s, m, "Config file not found"); 01195 return 0; 01196 } else if (cfg == CONFIG_STATUS_FILEINVALID) { 01197 astman_send_error(s, m, "Config file has invalid format"); 01198 return 0; 01199 } 01200 01201 astman_start_ack(s, m); 01202 while ((cur_category = ast_category_browse(cfg, cur_category))) { 01203 if (ast_strlen_zero(category) || (!ast_strlen_zero(category) && !strcmp(category, cur_category))) { 01204 lineno = 0; 01205 astman_append(s, "Category-%06d: %s\r\n", catcount, cur_category); 01206 for (v = ast_variable_browse(cfg, cur_category); v; v = v->next) 01207 astman_append(s, "Line-%06d-%06d: %s=%s\r\n", catcount, lineno++, v->name, v->value); 01208 catcount++; 01209 } 01210 } 01211 if (!ast_strlen_zero(category) && catcount == 0) /* TODO: actually, a config with no categories doesn't even get loaded */ 01212 astman_append(s, "No categories found\r\n"); 01213 ast_config_destroy(cfg); 01214 astman_append(s, "\r\n"); 01215 01216 return 0; 01217 }
| static int action_getconfigjson | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1278 of file manager.c.
References ast_category_browse(), ast_config_destroy(), ast_config_load2(), ast_strlen_zero(), ast_variable_browse(), astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), buf, eventqent::category, CONFIG_FLAG_NOCACHE, CONFIG_FLAG_WITHCOMMENTS, CONFIG_STATUS_FILEINVALID, json_escape(), ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by __init_manager().
01279 { 01280 struct ast_config *cfg; 01281 const char *fn = astman_get_header(m, "Filename"); 01282 char *category = NULL; 01283 struct ast_variable *v; 01284 int comma1 = 0; 01285 char *buf = NULL; 01286 unsigned int buf_len = 0; 01287 struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE }; 01288 01289 if (ast_strlen_zero(fn)) { 01290 astman_send_error(s, m, "Filename not specified"); 01291 return 0; 01292 } 01293 01294 if (!(cfg = ast_config_load2(fn, "manager", config_flags))) { 01295 astman_send_error(s, m, "Config file not found"); 01296 return 0; 01297 } else if (cfg == CONFIG_STATUS_FILEINVALID) { 01298 astman_send_error(s, m, "Config file has invalid format"); 01299 return 0; 01300 } 01301 01302 buf_len = 512; 01303 buf = alloca(buf_len); 01304 01305 astman_start_ack(s, m); 01306 astman_append(s, "JSON: {"); 01307 while ((category = ast_category_browse(cfg, category))) { 01308 int comma2 = 0; 01309 if (buf_len < 2 * strlen(category) + 1) { 01310 buf_len *= 2; 01311 buf = alloca(buf_len); 01312 } 01313 json_escape(buf, category); 01314 astman_append(s, "%s\"%s\":[", comma1 ? "," : "", buf); 01315 if (!comma1) 01316 comma1 = 1; 01317 for (v = ast_variable_browse(cfg, category); v; v = v->next) { 01318 if (comma2) 01319 astman_append(s, ","); 01320 if (buf_len < 2 * strlen(v->name) + 1) { 01321 buf_len *= 2; 01322 buf = alloca(buf_len); 01323 } 01324 json_escape(buf, v->name); 01325 astman_append(s, "\"%s", buf); 01326 if (buf_len < 2 * strlen(v->value) + 1) { 01327 buf_len *= 2; 01328 buf = alloca(buf_len); 01329 } 01330 json_escape(buf, v->value); 01331 astman_append(s, "%s\"", buf); 01332 if (!comma2) 01333 comma2 = 1; 01334 } 01335 astman_append(s, "]"); 01336 } 01337 astman_append(s, "}\r\n\r\n"); 01338 01339 ast_config_destroy(cfg); 01340 01341 return 0; 01342 }
| static int action_getvar | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1892 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_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), LOG_ERROR, name, pbx_retrieve_variable(), and S_OR.
Referenced by __init_manager().
01893 { 01894 struct ast_channel *c = NULL; 01895 const char *name = astman_get_header(m, "Channel"); 01896 const char *varname = astman_get_header(m, "Variable"); 01897 char *varval; 01898 char workspace[1024] = ""; 01899 01900 if (ast_strlen_zero(varname)) { 01901 astman_send_error(s, m, "No variable specified"); 01902 return 0; 01903 } 01904 01905 if (!ast_strlen_zero(name)) { 01906 c = ast_get_channel_by_name_locked(name); 01907 if (!c) { 01908 astman_send_error(s, m, "No such channel"); 01909 return 0; 01910 } 01911 } 01912 01913 if (varname[strlen(varname) - 1] == ')') { 01914 if (!c) { 01915 c = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Bogus/manager"); 01916 if (c) { 01917 ast_func_read(c, (char *) varname, workspace, sizeof(workspace)); 01918 ast_channel_free(c); 01919 c = NULL; 01920 } else 01921 ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution. Function results may be blank.\n"); 01922 } else 01923 ast_func_read(c, (char *) varname, workspace, sizeof(workspace)); 01924 varval = workspace; 01925 } else { 01926 pbx_retrieve_variable(c, varname, &varval, workspace, sizeof(workspace), NULL); 01927 } 01928 01929 if (c) 01930 ast_channel_unlock(c); 01931 astman_start_ack(s, m); 01932 astman_append(s, "Variable: %s\r\nValue: %s\r\n\r\n", varname, S_OR(varval, "")); 01933 01934 return 0; 01935 }
| static int action_hangup | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1822 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(), and name.
Referenced by __init_manager().
01823 { 01824 struct ast_channel *c = NULL; 01825 const char *name = astman_get_header(m, "Channel"); 01826 if (ast_strlen_zero(name)) { 01827 astman_send_error(s, m, "No channel 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 ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT); 01836 ast_channel_unlock(c); 01837 astman_send_ack(s, m, "Channel Hungup"); 01838 return 0; 01839 }
| static int action_listcategories | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1225 of file manager.c.
References ast_category_browse(), ast_config_destroy(), ast_config_load2(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), eventqent::category, CONFIG_FLAG_NOCACHE, CONFIG_FLAG_WITHCOMMENTS, and CONFIG_STATUS_FILEINVALID.
Referenced by __init_manager().
01226 { 01227 struct ast_config *cfg; 01228 const char *fn = astman_get_header(m, "Filename"); 01229 char *category = NULL; 01230 struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE }; 01231 int catcount = 0; 01232 01233 if (ast_strlen_zero(fn)) { 01234 astman_send_error(s, m, "Filename not specified"); 01235 return 0; 01236 } 01237 if (!(cfg = ast_config_load2(fn, "manager", config_flags))) { 01238 astman_send_error(s, m, "Config file not found"); 01239 return 0; 01240 } else if (cfg == CONFIG_STATUS_FILEINVALID) { 01241 astman_send_error(s, m, "Config file has invalid format"); 01242 return 0; 01243 } 01244 astman_start_ack(s, m); 01245 while ((category = ast_category_browse(cfg, category))) { 01246 astman_append(s, "Category-%06d: %s\r\n", catcount, category); 01247 catcount++; 01248 } 01249 if (catcount == 0) /* TODO: actually, a config with no categories doesn't even get loaded */ 01250 astman_append(s, "Error: no categories found\r\n"); 01251 ast_config_destroy(cfg); 01252 astman_append(s, "\r\n"); 01253 01254 return 0; 01255 }
| static int action_listcommands | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1712 of file manager.c.
References manager_action::action, AST_RWLIST_TRAVERSE, ast_str_alloca, astman_append(), astman_start_ack(), manager_action::authority, authority_to_str(), mansession::session, manager_action::synopsis, and mansession_session::writeperm.
Referenced by __init_manager().
01713 { 01714 struct manager_action *cur; 01715 struct ast_str *temp = ast_str_alloca(BUFSIZ); /* XXX very large ? */ 01716 01717 astman_start_ack(s, m); 01718 AST_RWLIST_TRAVERSE(&actions, cur, list) { 01719 if (s->session->writeperm & cur->authority || cur->authority == 0) 01720 astman_append(s, "%s: %s (Priv: %s)\r\n", 01721 cur->action, cur->synopsis, authority_to_str(cur->authority, &temp)); 01722 } 01723 astman_append(s, "\r\n"); 01724 01725 return 0; 01726 }
| static int action_login | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1782 of file manager.c.
References ast_inet_ntoa(), ast_log(), AST_OPT_FLAG_FULLY_BOOTED, ast_opt_send_fullybooted, ast_options, ast_test_flag, ast_verb, astman_send_ack(), astman_send_error(), authenticate(), mansession_session::authenticated, EVENT_FLAG_SYSTEM, LOG_EVENT, manager_displayconnects(), manager_event, mansession_session::managerid, mansession::session, mansession_session::sin, and mansession_session::username.
Referenced by __init_manager().
01783 { 01784 if (authenticate(s, m)) { 01785 sleep(1); 01786 astman_send_error(s, m, "Authentication failed"); 01787 return -1; 01788 } 01789 s->session->authenticated = 1; 01790 if (manager_displayconnects(s->session)) 01791 ast_verb(2, "%sManager '%s' logged on from %s\n", (s->session->managerid ? "HTTP " : ""), s->session->username, ast_inet_ntoa(s->session->sin.sin_addr)); 01792 ast_log(LOG_EVENT, "%sManager '%s' logged on from %s\n", (s->session->managerid ? "HTTP " : ""), s->session->username, ast_inet_ntoa(s->session->sin.sin_addr)); 01793 astman_send_ack(s, m, "Authentication accepted"); 01794 if (ast_opt_send_fullybooted && ast_test_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED)) { 01795 manager_event(EVENT_FLAG_SYSTEM, "FullyBooted", "Status: Fully Booted\r\n"); 01796 } 01797 return 0; 01798 }
| static int action_logoff | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1776 of file manager.c.
References astman_send_response().
Referenced by __init_manager().
01777 { 01778 astman_send_response(s, m, "Goodbye", "Thanks for all the fish."); 01779 return -1; 01780 }
| static int action_mailboxcount | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2610 of file manager.c.
References ast_app_inboxcount2(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), and mailbox.
Referenced by __init_manager().
02611 { 02612 const char *mailbox = astman_get_header(m, "Mailbox"); 02613 int newmsgs = 0, oldmsgs = 0, urgentmsgs = 0;; 02614 02615 if (ast_strlen_zero(mailbox)) { 02616 astman_send_error(s, m, "Mailbox not specified"); 02617 return 0; 02618 } 02619 ast_app_inboxcount2(mailbox, &urgentmsgs, &newmsgs, &oldmsgs); 02620 astman_start_ack(s, m); 02621 astman_append(s, "Message: Mailbox Message Count\r\n" 02622 "Mailbox: %s\r\n" 02623 "UrgMessages: %d\r\n" 02624 "NewMessages: %d\r\n" 02625 "OldMessages: %d\r\n" 02626 "\r\n", 02627 mailbox, urgentmsgs, newmsgs, oldmsgs); 02628 return 0; 02629 }
| static int action_mailboxstatus | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2581 of file manager.c.
References ast_app_has_voicemail(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), and mailbox.
Referenced by __init_manager().
02582 { 02583 const char *mailbox = astman_get_header(m, "Mailbox"); 02584 int ret; 02585 02586 if (ast_strlen_zero(mailbox)) { 02587 astman_send_error(s, m, "Mailbox not specified"); 02588 return 0; 02589 } 02590 ret = ast_app_has_voicemail(mailbox, NULL); 02591 astman_start_ack(s, m); 02592 astman_append(s, "Message: Mailbox Status\r\n" 02593 "Mailbox: %s\r\n" 02594 "Waiting: %d\r\n\r\n", mailbox, ret); 02595 return 0; 02596 }
| static int action_originate | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2438 of file manager.c.
References fast_originate_helper::account, fast_originate_helper::app, app, fast_originate_helper::appdata, ast_callerid_parse(), ast_calloc, ast_copy_string(), ast_findlabel_extension(), AST_FORMAT_SLINEAR, ast_free, ast_parse_allow_disallow(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pthread_create_detached, ast_shrink_phone_number(), ast_strlen_zero(), ast_true(), ast_variables_destroy(), astman_get_header(), astman_get_variables(), astman_send_ack(), astman_send_error(), fast_originate_helper::cid_name, fast_originate_helper::cid_num, fast_originate_helper::context, context, fast_originate_helper::data, ast_frame::data, EVENT_FLAG_SYSTEM, fast_originate_helper::exten, exten, fast_originate(), fast_originate_helper::format, format, fast_originate_helper::idtext, name, fast_originate_helper::priority, mansession::session, strcasestr(), fast_originate_helper::tech, fast_originate_helper::timeout, fast_originate_helper::vars, and mansession_session::writeperm.
Referenced by __init_manager().
02439 { 02440 const char *name = astman_get_header(m, "Channel"); 02441 const char *exten = astman_get_header(m, "Exten"); 02442 const char *context = astman_get_header(m, "Context"); 02443 const char *priority = astman_get_header(m, "Priority"); 02444 const char *timeout = astman_get_header(m, "Timeout"); 02445 const char *callerid = astman_get_header(m, "CallerID"); 02446 const char *account = astman_get_header(m, "Account"); 02447 const char *app = astman_get_header(m, "Application"); 02448 const char *appdata = astman_get_header(m, "Data"); 02449 const char *async = astman_get_header(m, "Async"); 02450 const char *id = astman_get_header(m, "ActionID"); 02451 const char *codecs = astman_get_header(m, "Codecs"); 02452 struct ast_variable *vars; 02453 char *tech, *data; 02454 char *l = NULL, *n = NULL; 02455 int pi = 0; 02456 int res; 02457 int to = 30000; 02458 int reason = 0; 02459 char tmp[256]; 02460 char tmp2[256]; 02461 int format = AST_FORMAT_SLINEAR; 02462 02463 pthread_t th; 02464 if (ast_strlen_zero(name)) { 02465 astman_send_error(s, m, "Channel not specified"); 02466 return 0; 02467 } 02468 if (!ast_strlen_zero(priority) && (sscanf(priority, "%30d", &pi) != 1)) { 02469 if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) { 02470 astman_send_error(s, m, "Invalid priority"); 02471 return 0; 02472 } 02473 } 02474 if (!ast_strlen_zero(timeout) && (sscanf(timeout, "%30d", &to) != 1)) { 02475 astman_send_error(s, m, "Invalid timeout"); 02476 return 0; 02477 } 02478 ast_copy_string(tmp, name, sizeof(tmp)); 02479 tech = tmp; 02480 data = strchr(tmp, '/'); 02481 if (!data) { 02482 astman_send_error(s, m, "Invalid channel"); 02483 return 0; 02484 } 02485 *data++ = '\0'; 02486 ast_copy_string(tmp2, callerid, sizeof(tmp2)); 02487 ast_callerid_parse(tmp2, &n, &l); 02488 if (n) { 02489 if (ast_strlen_zero(n)) 02490 n = NULL; 02491 } 02492 if (l) { 02493 ast_shrink_phone_number(l); 02494 if (ast_strlen_zero(l)) 02495 l = NULL; 02496 } 02497 if (!ast_strlen_zero(codecs)) { 02498 format = 0; 02499 ast_parse_allow_disallow(NULL, &format, codecs, 1); 02500 } 02501 /* Allocate requested channel variables */ 02502 vars = astman_get_variables(m); 02503 02504 if (ast_true(async)) { 02505 struct fast_originate_helper *fast = ast_calloc(1, sizeof(*fast)); 02506 if (!fast) { 02507 res = -1; 02508 } else { 02509 if (!ast_strlen_zero(id)) 02510 snprintf(fast->idtext, sizeof(fast->idtext), "ActionID: %s", id); 02511 ast_copy_string(fast->tech, tech, sizeof(fast->tech)); 02512 ast_copy_string(fast->data, data, sizeof(fast->data)); 02513 ast_copy_string(fast->app, app, sizeof(fast->app)); 02514 ast_copy_string(fast->appdata, appdata, sizeof(fast->appdata)); 02515 if (l) 02516 ast_copy_string(fast->cid_num, l, sizeof(fast->cid_num)); 02517 if (n) 02518 ast_copy_string(fast->cid_name, n, sizeof(fast->cid_name)); 02519 fast->vars = vars; 02520 ast_copy_string(fast->context, context, sizeof(fast->context)); 02521 ast_copy_string(fast->exten, exten, sizeof(fast->exten)); 02522 ast_copy_string(fast->account, account, sizeof(fast->account)); 02523 fast->format = format; 02524 fast->timeout = to; 02525 fast->priority = pi; 02526 if (ast_pthread_create_detached(&th, NULL, fast_originate, fast)) { 02527 ast_free(fast); 02528 res = -1; 02529 } else { 02530 res = 0; 02531 } 02532 } 02533 } else if (!ast_strlen_zero(app)) { 02534 /* To run the System application (or anything else that goes to shell), you must have the additional System privilege */ 02535 if (!(s->session->writeperm & EVENT_FLAG_SYSTEM) 02536 && ( 02537 strcasestr(app, "system") || /* System(rm -rf /) 02538 TrySystem(rm -rf /) */ 02539 strcasestr(app, "exec") || /* Exec(System(rm -rf /)) 02540 TryExec(System(rm -rf /)) */ 02541 strcasestr(app, "agi") || /* AGI(/bin/rm,-rf /) 02542 EAGI(/bin/rm,-rf /) */ 02543 strstr(appdata, "SHELL") || /* NoOp(${SHELL(rm -rf /)}) */ 02544 strstr(appdata, "EVAL") /* NoOp(${EVAL(${some_var_containing_SHELL})}) */ 02545 )) { 02546 astman_send_error(s, m, "Originate with certain 'Application' arguments requires the additional System privilege, which you do not have."); 02547 return 0; 02548 } 02549 res = ast_pbx_outgoing_app(tech, format, data, to, app, appdata, &reason, 1, l, n, vars, account, NULL); 02550 } else { 02551 if (exten && context && pi) 02552 res = ast_pbx_outgoing_exten(tech, format, data, to, context, exten, pi, &reason, 1, l, n, vars, account, NULL); 02553 else { 02554 astman_send_error(s, m, "Originate with 'Exten' requires 'Context' and 'Priority'"); 02555 if (vars) { 02556 ast_variables_destroy(vars); 02557 } 02558 return 0; 02559 } 02560 } 02561 if (!res) 02562 astman_send_ack(s, m, "Originate successfully queued"); 02563 else 02564 astman_send_error(s, m, "Originate failed"); 02565 return 0; 02566 }
| static int action_ping | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1158 of file manager.c.
References ast_strlen_zero(), astman_append(), and astman_get_header().
Referenced by __init_manager().
01159 { 01160 const char *actionid = astman_get_header(m, "ActionID"); 01161 01162 astman_append(s, "Response: Success\r\n"); 01163 if (!ast_strlen_zero(actionid)){ 01164 astman_append(s, "ActionID: %s\r\n", actionid); 01165 } 01166 astman_append(s, "Ping: Pong\r\n\r\n"); 01167 return 0; 01168 }
| static int action_redirect | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
action_redirect: The redirect manager command
Definition at line 2129 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(), buf, chan, context, exten, name, ast_channel::pbx, and ast_channel::priority.
Referenced by __init_manager().
02130 { 02131 const char *name = astman_get_header(m, "Channel"); 02132 const char *name2 = astman_get_header(m, "ExtraChannel"); 02133 const char *exten = astman_get_header(m, "Exten"); 02134 const char *context = astman_get_header(m, "Context"); 02135 const char *priority = astman_get_header(m, "Priority"); 02136 struct ast_channel *chan, *chan2 = NULL; 02137 int pi = 0; 02138 int res; 02139 02140 if (ast_strlen_zero(name)) { 02141 astman_send_error(s, m, "Channel not specified"); 02142 return 0; 02143 } 02144 if (!ast_strlen_zero(priority) && (sscanf(priority, "%30d", &pi) != 1)) { 02145 if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) { 02146 astman_send_error(s, m, "Invalid priority"); 02147 return 0; 02148 } 02149 } 02150 /* XXX watch out, possible deadlock - we are trying to get two channels!!! */ 02151 chan = ast_get_channel_by_name_locked(name); 02152 if (!chan) { 02153 char buf[256]; 02154 snprintf(buf, sizeof(buf), "Channel does not exist: %s", name); 02155 astman_send_error(s, m, buf); 02156 return 0; 02157 } 02158 if (ast_check_hangup(chan)) { 02159 astman_send_error(s, m, "Redirect failed, channel not up."); 02160 ast_channel_unlock(chan); 02161 return 0; 02162 } 02163 if (!ast_strlen_zero(name2)) 02164 chan2 = ast_get_channel_by_name_locked(name2); 02165 if (chan2 && ast_check_hangup(chan2)) { 02166 astman_send_error(s, m, "Redirect failed, extra channel not up."); 02167 ast_channel_unlock(chan); 02168 ast_channel_unlock(chan2); 02169 return 0; 02170 } 02171 if (chan->pbx) { 02172 ast_channel_lock(chan); 02173 ast_set_flag(chan, AST_FLAG_BRIDGE_HANGUP_DONT); /* don't let the after-bridge code run the h-exten */ 02174 ast_channel_unlock(chan); 02175 } 02176 res = ast_async_goto(chan, context, exten, pi); 02177 if (!res) { 02178 if (!ast_strlen_zero(name2)) { 02179 if (chan2) { 02180 if (chan2->pbx) { 02181 ast_channel_lock(chan2); 02182 ast_set_flag(chan2, AST_FLAG_BRIDGE_HANGUP_DONT); /* don't let the after-bridge code run the h-exten */ 02183 ast_channel_unlock(chan2); 02184 } 02185 res = ast_async_goto(chan2, context, exten, pi); 02186 } else { 02187 res = -1; 02188 } 02189 if (!res) 02190 astman_send_ack(s, m, "Dual Redirect successful"); 02191 else 02192 astman_send_error(s, m, "Secondary redirect failed"); 02193 } else 02194 astman_send_ack(s, m, "Redirect successful"); 02195 } else 02196 astman_send_error(s, m, "Redirect failed"); 02197 if (chan) 02198 ast_channel_unlock(chan); 02199 if (chan2) 02200 ast_channel_unlock(chan2); 02201 return 0; 02202 }
| static int action_reload | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Send a reload event.
Definition at line 2845 of file manager.c.
References ast_module_reload(), astman_get_header(), astman_send_ack(), astman_send_error(), and S_OR.
Referenced by __init_manager().
02846 { 02847 const char *module = astman_get_header(m, "Module"); 02848 int res = ast_module_reload(S_OR(module, NULL)); 02849 02850 if (res == 2) 02851 astman_send_ack(s, m, "Module Reloaded"); 02852 else 02853 astman_send_error(s, m, s == 0 ? "No such module" : "Module does not support reload"); 02854 return 0; 02855 }
| static int action_sendtext | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2084 of file manager.c.
References ast_channel_unlock, ast_get_channel_by_name_locked(), ast_sendtext(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), and name.
Referenced by __init_manager().
02085 { 02086 struct ast_channel *c = NULL; 02087 const char *name = astman_get_header(m, "Channel"); 02088 const char *textmsg = astman_get_header(m, "Message"); 02089 int res = 0; 02090 02091 if (ast_strlen_zero(name)) { 02092 astman_send_error(s, m, "No channel specified"); 02093 return 0; 02094 } 02095 02096 if (ast_strlen_zero(textmsg)) { 02097 astman_send_error(s, m, "No Message specified"); 02098 return 0; 02099 } 02100 02101 c = ast_get_channel_by_name_locked(name); 02102 if (!c) { 02103 astman_send_error(s, m, "No such channel"); 02104 return 0; 02105 } 02106 02107 res = ast_sendtext(c, textmsg); 02108 ast_channel_unlock(c); 02109 02110 if (res > 0) 02111 astman_send_ack(s, m, "Success"); 02112 else 02113 astman_send_error(s, m, "Failure"); 02114 02115 return res; 02116 }
| static int action_setvar | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1848 of file manager.c.
References ast_channel_unlock, ast_func_write(), ast_get_channel_by_name_locked(), ast_strdupa, ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), name, pbx_builtin_setvar_helper(), and S_OR.
Referenced by __init_manager().
01849 { 01850 struct ast_channel *c = NULL; 01851 const char *name = astman_get_header(m, "Channel"); 01852 const char *varname = astman_get_header(m, "Variable"); 01853 const char *varval = astman_get_header(m, "Value"); 01854 int res = 0; 01855 01856 if (ast_strlen_zero(varname)) { 01857 astman_send_error(s, m, "No variable specified"); 01858 return 0; 01859 } 01860 01861 if (!ast_strlen_zero(name)) { 01862 c = ast_get_channel_by_name_locked(name); 01863 if (!c) { 01864 astman_send_error(s, m, "No such channel"); 01865 return 0; 01866 } 01867 } 01868 if (varname[strlen(varname)-1] == ')') { 01869 char *function = ast_strdupa(varname); 01870 res = ast_func_write(c, function, varval); 01871 } else { 01872 pbx_builtin_setvar_helper(c, varname, S_OR(varval, "")); 01873 } 01874 01875 if (c) 01876 ast_channel_unlock(c); 01877 if (res == 0) { 01878 astman_send_ack(s, m, "Variable Set"); 01879 } else { 01880 astman_send_error(s, m, "Variable not set"); 01881 } 01882 return 0; 01883 }
| static int action_status | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Manager "status" command to show channels.
Definition at line 1949 of file manager.c.
References ast_channel::_bridge, ast_channel::_state, ast_channel::accountcode, AST_APP_ARG, ast_channel_unlock, ast_channel_walk_locked(), AST_DECLARE_APP_ARGS, ast_free, ast_func_read(), ast_get_channel_by_name_locked(), AST_STANDARD_APP_ARGS, ast_state2str(), ast_str_append(), ast_str_buffer(), ast_str_create(), ast_str_reset(), ast_strdupa, ast_strlen_zero(), ast_tvnow(), astman_append(), astman_get_header(), astman_send_ack(), astman_send_error(), ast_channel::bridge, ast_channel::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, pbx_retrieve_variable(), ast_channel::priority, S_OR, ast_cdr::start, str, and ast_channel::uniqueid.
Referenced by __init_manager().
01950 { 01951 const char *name = astman_get_header(m, "Channel"); 01952 const char *cvariables = astman_get_header(m, "Variables"); 01953 char *variables = ast_strdupa(S_OR(cvariables, "")); 01954 struct ast_channel *c; 01955 char bridge[256]; 01956 struct timeval now = ast_tvnow(); 01957 long elapsed_seconds = 0; 01958 int channels = 0; 01959 int all = ast_strlen_zero(name); /* set if we want all channels */ 01960 const char *id = astman_get_header(m, "ActionID"); 01961 char idText[256]; 01962 AST_DECLARE_APP_ARGS(vars, 01963 AST_APP_ARG(name)[100]; 01964 ); 01965 struct ast_str *str = ast_str_create(1000); 01966 01967 if (!ast_strlen_zero(id)) 01968 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id); 01969 else 01970 idText[0] = '\0'; 01971 01972 if (all) 01973 c = ast_channel_walk_locked(NULL); 01974 else { 01975 c = ast_get_channel_by_name_locked(name); 01976 if (!c) { 01977 astman_send_error(s, m, "No such channel"); 01978 ast_free(str); 01979 return 0; 01980 } 01981 } 01982 astman_send_ack(s, m, "Channel status will follow"); 01983 01984 if (!ast_strlen_zero(cvariables)) { 01985 AST_STANDARD_APP_ARGS(vars, variables); 01986 } 01987 01988 /* if we look by name, we break after the first iteration */ 01989 while (c) { 01990 if (!ast_strlen_zero(cvariables)) { 01991 int i; 01992 ast_str_reset(str); 01993 for (i = 0; i < vars.argc; i++) { 01994 char valbuf[512], *ret = NULL; 01995 01996 if (vars.name[i][strlen(vars.name[i]) - 1] == ')') { 01997 if (ast_func_read(c, vars.name[i], valbuf, sizeof(valbuf)) < 0) { 01998 valbuf[0] = '\0'; 01999 } 02000 ret = valbuf; 02001 } else { 02002 pbx_retrieve_variable(c, vars.name[i], &ret, valbuf, sizeof(valbuf), NULL); 02003 } 02004 02005 ast_str_append(&str, 0, "Variable: %s=%s\r\n", vars.name[i], ret); 02006 } 02007 } 02008 02009 channels++; 02010 if (c->_bridge) 02011 snprintf(bridge, sizeof(bridge), "BridgedChannel: %s\r\nBridgedUniqueid: %s\r\n", c->_bridge->name, c->_bridge->uniqueid); 02012 else 02013 bridge[0] = '\0'; 02014 if (c->pbx) { 02015 if (c->cdr) { 02016 elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec; 02017 } 02018 astman_append(s, 02019 "Event: Status\r\n" 02020 "Privilege: Call\r\n" 02021 "Channel: %s\r\n" 02022 "CallerIDNum: %s\r\n" 02023 "CallerIDName: %s\r\n" 02024 "Accountcode: %s\r\n" 02025 "ChannelState: %d\r\n" 02026 "ChannelStateDesc: %s\r\n" 02027 "Context: %s\r\n" 02028 "Extension: %s\r\n" 02029 "Priority: %d\r\n" 02030 "Seconds: %ld\r\n" 02031 "%s" 02032 "Uniqueid: %s\r\n" 02033 "%s" 02034 "%s" 02035 "\r\n", 02036 c->name, 02037 S_OR(c->cid.cid_num, ""), 02038 S_OR(c->cid.cid_name, ""), 02039 c->accountcode, 02040 c->_state, 02041 ast_state2str(c->_state), c->context, 02042 c->exten, c->priority, (long)elapsed_seconds, bridge, c->uniqueid, ast_str_buffer(str), idText); 02043 } else { 02044 astman_append(s, 02045 "Event: Status\r\n" 02046 "Privilege: Call\r\n" 02047 "Channel: %s\r\n" 02048 "CallerIDNum: %s\r\n" 02049 "CallerIDName: %s\r\n" 02050 "Account: %s\r\n" 02051 "State: %s\r\n" 02052 "%s" 02053 "Uniqueid: %s\r\n" 02054 "%s" 02055 "%s" 02056 "\r\n", 02057 c->name, 02058 S_OR(c->cid.cid_num, "<unknown>"), 02059 S_OR(c->cid.cid_name, "<unknown>"), 02060 c->accountcode, 02061 ast_state2str(c->_state), bridge, c->uniqueid, ast_str_buffer(str), idText); 02062 } 02063 ast_channel_unlock(c); 02064 if (!all) 02065 break; 02066 c = ast_channel_walk_locked(c); 02067 } 02068 astman_append(s, 02069 "Event: StatusComplete\r\n" 02070 "%s" 02071 "Items: %d\r\n" 02072 "\r\n", idText, channels); 02073 ast_free(str); 02074 return 0; 02075 }
| static int action_timeout | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2673 of file manager.c.
References ast_channel_setwhentohangup_tv(), ast_channel_unlock, ast_get_channel_by_name_locked(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), and name.
Referenced by __init_manager().
02674 { 02675 struct ast_channel *c; 02676 const char *name = astman_get_header(m, "Channel"); 02677 double timeout = atof(astman_get_header(m, "Timeout")); 02678 struct timeval when = { timeout, 0 }; 02679 02680 if (ast_strlen_zero(name)) { 02681 astman_send_error(s, m, "No channel specified"); 02682 return 0; 02683 } 02684 if (!timeout || timeout < 0) { 02685 astman_send_error(s, m, "No timeout specified"); 02686 return 0; 02687 } 02688 c = ast_get_channel_by_name_locked(name); 02689 if (!c) { 02690 astman_send_error(s, m, "No such channel"); 02691 return 0; 02692 } 02693 02694 when.tv_usec = (timeout - when.tv_sec) * 1000000.0; 02695 ast_channel_setwhentohangup_tv(c, when); 02696 ast_channel_unlock(c); 02697 astman_send_ack(s, m, "Timeout Set"); 02698 return 0; 02699 }
| static int action_updateconfig | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1502 of file manager.c.
References ast_config_destroy(), ast_config_load2(), ast_config_text_file_save(), ast_include_rename(), ast_module_reload(), ast_strlen_zero(), ast_true(), astman_get_header(), astman_send_ack(), astman_send_error(), CONFIG_FLAG_NOCACHE, CONFIG_FLAG_WITHCOMMENTS, CONFIG_STATUS_FILEINVALID, FAILURE_ALLOCATION, FAILURE_APPEND, FAILURE_DELCAT, FAILURE_DELETE, FAILURE_EMPTYCAT, FAILURE_NEWCAT, FAILURE_UPDATE, handle_updates(), UNKNOWN_ACTION, UNKNOWN_CATEGORY, UNSPECIFIED_ARGUMENT, and UNSPECIFIED_CATEGORY.
Referenced by __init_manager().
01503 { 01504 struct ast_config *cfg; 01505 const char *sfn = astman_get_header(m, "SrcFilename"); 01506 const char *dfn = astman_get_header(m, "DstFilename"); 01507 int res; 01508 const char *rld = astman_get_header(m, "Reload"); 01509 struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE }; 01510 enum error_type result; 01511 01512 if (ast_strlen_zero(sfn) || ast_strlen_zero(dfn)) { 01513 astman_send_error(s, m, "Filename not specified"); 01514 return 0; 01515 } 01516 if (!(cfg = ast_config_load2(sfn, "manager", config_flags))) { 01517 astman_send_error(s, m, "Config file not found"); 01518 return 0; 01519 } else if (cfg == CONFIG_STATUS_FILEINVALID) { 01520 astman_send_error(s, m, "Config file has invalid format"); 01521 return 0; 01522 } 01523 result = handle_updates(s, m, cfg, dfn); 01524 if (!result) { 01525 ast_include_rename(cfg, sfn, dfn); /* change the include references from dfn to sfn, so things match up */ 01526 res = ast_config_text_file_save(dfn, cfg, "Manager"); 01527 ast_config_destroy(cfg); 01528 if (res) { 01529 astman_send_error(s, m, "Save of config failed"); 01530 return 0; 01531 } 01532 astman_send_ack(s, m, NULL); 01533 if (!ast_strlen_zero(rld)) { 01534 if (ast_true(rld)) 01535 rld = NULL; 01536 ast_module_reload(rld); 01537 } 01538 } else { 01539 ast_config_destroy(cfg); 01540 switch(result) { 01541 case UNKNOWN_ACTION: 01542 astman_send_error(s, m, "Unknown action command"); 01543 break; 01544 case UNKNOWN_CATEGORY: 01545 astman_send_error(s, m, "Given category does not exist"); 01546 break; 01547 case UNSPECIFIED_CATEGORY: 01548 astman_send_error(s, m, "Category not specified"); 01549 break; 01550 case UNSPECIFIED_ARGUMENT: 01551 astman_send_error(s, m, "Problem with category, value, or line (if required)"); 01552 break; 01553 case FAILURE_ALLOCATION: 01554 astman_send_error(s, m, "Memory allocation failure, this should not happen"); 01555 break; 01556 case FAILURE_NEWCAT: 01557 astman_send_error(s, m, "Create category did not complete successfully"); 01558 break; 01559 case FAILURE_DELCAT: 01560 astman_send_error(s, m, "Delete category did not complete successfully"); 01561 break; 01562 case FAILURE_EMPTYCAT: 01563 astman_send_error(s, m, "Empty category did not complete successfully"); 01564 break; 01565 case FAILURE_UPDATE: 01566 astman_send_error(s, m, "Update did not complete successfully"); 01567 break; 01568 case FAILURE_DELETE: 01569 astman_send_error(s, m, "Delete did not complete successfully"); 01570 break; 01571 case FAILURE_APPEND: 01572 astman_send_error(s, m, "Append did not complete successfully"); 01573 break; 01574 } 01575 } 01576 return 0; 01577 }
| static int action_userevent | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2735 of file manager.c.
References ast_str_append(), ast_str_buffer(), ast_str_reset(), ast_str_thread_get(), astman_get_header(), astman_send_ack(), EVENT_FLAG_USER, message::hdrcount, message::headers, manager_event, and userevent_buf.
Referenced by __init_manager().
02736 { 02737 const char *event = astman_get_header(m, "UserEvent"); 02738 struct ast_str *body = ast_str_thread_get(&userevent_buf, 16); 02739 int x; 02740 02741 ast_str_reset(body); 02742 02743 for (x = 0; x < m->hdrcount; x++) { 02744 if (strncasecmp("UserEvent:", m->headers[x], strlen("UserEvent:"))) { 02745 ast_str_append(&body, 0, "%s\r\n", m->headers[x]); 02746 } 02747 } 02748 02749 astman_send_ack(s, m, "Event Sent"); 02750 manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", event, ast_str_buffer(body)); 02751 return 0; 02752 }
| static int action_waitevent | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1612 of file manager.c.
References mansession_session::__lock, advance_event(), ast_debug, ast_mutex_lock(), ast_mutex_unlock(), AST_PTHREADT_NULL, AST_RWLIST_NEXT, ast_strlen_zero(), ast_wait_for_input(), astman_append(), astman_get_header(), astman_send_response(), eventqent::category, eventqent::eventdata, mansession_session::fd, mansession_session::last_ev, mansession_session::managerid, mansession_session::needdestroy, mansession_session::readperm, mansession_session::send_events, mansession::session, mansession_session::sessiontimeout, and mansession_session::waiting_thread.
Referenced by __init_manager().
01613 { 01614 const char *timeouts = astman_get_header(m, "Timeout"); 01615 int timeout = -1; 01616 int x; 01617 int needexit = 0; 01618 const char *id = astman_get_header(m, "ActionID"); 01619 char idText[256]; 01620 01621 if (!ast_strlen_zero(id)) 01622 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id); 01623 else 01624 idText[0] = '\0'; 01625 01626 if (!ast_strlen_zero(timeouts)) { 01627 sscanf(timeouts, "%30i", &timeout); 01628 if (timeout < -1) 01629 timeout = -1; 01630 /* XXX maybe put an upper bound, or prevent the use of 0 ? */ 01631 } 01632 01633 ast_mutex_lock(&s->session->__lock); 01634 if (s->session->waiting_thread != AST_PTHREADT_NULL) 01635 pthread_kill(s->session->waiting_thread, SIGURG); 01636 01637 if (s->session->managerid) { /* AMI-over-HTTP session */ 01638 /* 01639 * Make sure the timeout is within the expire time of the session, 01640 * as the client will likely abort the request if it does not see 01641 * data coming after some amount of time. 01642 */ 01643 time_t now = time(NULL); 01644 int max = s->session->sessiontimeout - now - 10; 01645 01646 if (max < 0) /* We are already late. Strange but possible. */ 01647 max = 0; 01648 if (timeout < 0 || timeout > max) 01649 timeout = max; 01650 if (!s->session->send_events) /* make sure we record events */ 01651 s->session->send_events = -1; 01652 } 01653 ast_mutex_unlock(&s->session->__lock); 01654 01655 /* XXX should this go inside the lock ? */ 01656 s->session->waiting_thread = pthread_self(); /* let new events wake up this thread */ 01657 ast_debug(1, "Starting waiting for an event!\n"); 01658 01659 for (x = 0; x < timeout || timeout < 0; x++) { 01660 ast_mutex_lock(&s->session->__lock); 01661 if (AST_RWLIST_NEXT(s->session->last_ev, eq_next)) { 01662 needexit = 1; 01663 } 01664 /* We can have multiple HTTP session point to the same mansession entry. 01665 * The way we deal with it is not very nice: newcomers kick out the previous 01666 * HTTP session. XXX this needs to be improved. 01667 */ 01668 if (s->session->waiting_thread != pthread_self()) 01669 needexit = 1; 01670 if (s->session->needdestroy) 01671 needexit = 1; 01672 ast_mutex_unlock(&s->session->__lock); 01673 if (needexit) 01674 break; 01675 if (s->session->managerid == 0) { /* AMI session */ 01676 if (ast_wait_for_input(s->session->fd, 1000)) 01677 break; 01678 } else { /* HTTP session */ 01679 sleep(1); 01680 } 01681 } 01682 ast_debug(1, "Finished waiting for an event!\n"); 01683 ast_mutex_lock(&s->session->__lock); 01684 if (s->session->waiting_thread == pthread_self()) { 01685 struct eventqent *eqe = s->session->last_ev; 01686 astman_send_response(s, m, "Success", "Waiting for Event completed."); 01687 while ((eqe = advance_event(eqe))) { 01688 if (((s->session->readperm & eqe->category) == eqe->category) && 01689 ((s->session->send_events & eqe->category) == eqe->category)) { 01690 astman_append(s, "%s", eqe->eventdata); 01691 } 01692 s->session->last_ev = eqe; 01693 } 01694 astman_append(s, 01695 "Event: WaitEventComplete\r\n" 01696 "%s" 01697 "\r\n", idText); 01698 s->session->waiting_thread = AST_PTHREADT_NULL; 01699 } else { 01700 ast_debug(1, "Abandoning event request!\n"); 01701 } 01702 ast_mutex_unlock(&s->session->__lock); 01703 return 0; 01704 }
Definition at line 837 of file manager.c.
References ast_atomic_fetchadd_int(), AST_RWLIST_NEXT, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, eventqent::next, and eventqent::usecount.
Referenced by action_waitevent(), and process_events().
00838 { 00839 struct eventqent *next; 00840 00841 AST_RWLIST_RDLOCK(&all_events); 00842 if ((next = AST_RWLIST_NEXT(e, eq_next))) { 00843 ast_atomic_fetchadd_int(&next->usecount, 1); 00844 ast_atomic_fetchadd_int(&e->usecount, -1); 00845 } 00846 AST_RWLIST_UNLOCK(&all_events); 00847 return next; 00848 }
| static int append_event | ( | const char * | str, | |
| int | category | |||
| ) | [static] |
Definition at line 3325 of file manager.c.
References ast_atomic_fetchadd_int(), ast_malloc, AST_RWLIST_INSERT_TAIL, AST_RWLIST_NEXT, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_tvnow(), eventqent::category, eventqent::eventdata, eventqent::seq, eventqent::tv, and eventqent::usecount.
Referenced by __init_manager(), and __manager_event().
03326 { 03327 struct eventqent *tmp = ast_malloc(sizeof(*tmp) + strlen(str)); 03328 static int seq; /* sequence number */ 03329 03330 if (!tmp) 03331 return -1; 03332 03333 /* need to init all fields, because ast_malloc() does not */ 03334 tmp->usecount = 0; 03335 tmp->category = category; 03336 tmp->seq = ast_atomic_fetchadd_int(&seq, 1); 03337 tmp->tv = ast_tvnow(); 03338 AST_RWLIST_NEXT(tmp, eq_next) = NULL; 03339 strcpy(tmp->eventdata, str); 03340 03341 AST_RWLIST_WRLOCK(&all_events); 03342 AST_RWLIST_INSERT_TAIL(&all_events, tmp, eq_next); 03343 AST_RWLIST_UNLOCK(&all_events); 03344 03345 return 0; 03346 }
| static int ast_instring | ( | const char * | bigstr, | |
| const char * | smallstr, | |||
| const char | delim | |||
| ) | [static] |
Tells you if smallstr exists inside bigstr which is delim by delim and uses no buf or stringsep ast_instring("this|that|more","this",'|') == 1;
feel free to move this to app.c -anthm
Definition at line 436 of file manager.c.
References eventqent::next.
Referenced by get_perm().
00437 { 00438 const char *val = bigstr, *next; 00439 00440 do { 00441 if ((next = strchr(val, delim))) { 00442 if (!strncmp(val, smallstr, (next - val))) 00443 return 1; 00444 else 00445 continue; 00446 } else 00447 return !strcmp(smallstr, val); 00448 } while (*(val = (next + 1))); 00449 00450 return 0; 00451 }
| int ast_manager_register2 | ( | const char * | action, | |
| int | auth, | |||
| int(*)(struct mansession *s, const struct message *m) | func, | |||
| const char * | synopsis, | |||
| const char * | description | |||
| ) |
register a new command with manager, including online help. This is the preferred way to register a manager command
Register a manager command with the manager interface.
Definition at line 3501 of file manager.c.
References manager_action::action, ast_calloc, ast_free, ast_manager_register_struct(), manager_action::authority, manager_action::description, manager_action::func, and manager_action::synopsis.
Referenced by __init_manager(), ast_features_init(), load_module(), and load_pbx().
03502 { 03503 struct manager_action *cur = NULL; 03504 03505 if (!(cur = ast_calloc(1, sizeof(*cur)))) 03506 return -1; 03507 03508 cur->action = action; 03509 cur->authority = auth; 03510 cur->func = func; 03511 cur->synopsis = synopsis; 03512 cur->description = description; 03513 03514 if (ast_manager_register_struct(cur)) { 03515 ast_free(cur); 03516 return -1; 03517 } 03518 03519 return 0; 03520 }
| void ast_manager_register_hook | ( | struct manager_custom_hook * | hook | ) |
Add a custom hook to be called when an event is fired.
Add a custom hook to be called when an event is fired
| hook | struct manager_custom_hook object to add |
Definition at line 263 of file manager.c.
References AST_RWLIST_INSERT_TAIL, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.
00264 { 00265 AST_RWLIST_WRLOCK(&manager_hooks); 00266 AST_RWLIST_INSERT_TAIL(&manager_hooks, hook, list); 00267 AST_RWLIST_UNLOCK(&manager_hooks); 00268 return; 00269 }
| static int ast_manager_register_struct | ( | struct manager_action * | act | ) | [static] |
Definition at line 3465 of file manager.c.
References manager_action::action, ast_log(), AST_RWLIST_INSERT_AFTER, AST_RWLIST_INSERT_HEAD, AST_RWLIST_TIMEDWRLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_verb, LOG_ERROR, LOG_WARNING, and eventqent::tv.
Referenced by ast_manager_register2().
03466 { 03467 struct manager_action *cur, *prev = NULL; 03468 struct timespec tv = { 5, }; 03469 03470 if (AST_RWLIST_TIMEDWRLOCK(&actions, &tv)) { 03471 ast_log(LOG_ERROR, "Could not obtain lock on manager list\n"); 03472 return -1; 03473 } 03474 AST_RWLIST_TRAVERSE(&actions, cur, list) { 03475 int ret = strcasecmp(cur->action, act->action); 03476 if (ret == 0) { 03477 ast_log(LOG_WARNING, "Manager: Action '%s' already registered\n", act->action); 03478 AST_RWLIST_UNLOCK(&actions); 03479 return -1; 03480 } 03481 if (ret > 0) { /* Insert these alphabetically */ 03482 prev = cur; 03483 break; 03484 } 03485 } 03486 03487 if (prev) 03488 AST_RWLIST_INSERT_AFTER(&actions, prev, act, list); 03489 else 03490 AST_RWLIST_INSERT_HEAD(&actions, act, list); 03491 03492 ast_verb(2, "Manager registered action %s\n", act->action); 03493 03494 AST_RWLIST_UNLOCK(&actions); 03495 03496 return 0; 03497 }
| int ast_manager_unregister | ( | char * | action | ) |
Unregister a registered manager command.
| action | Name of registered Action: |
Definition at line 3432 of file manager.c.
References manager_action::action, ast_free, ast_log(), AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TIMEDWRLOCK, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, ast_verb, LOG_ERROR, and eventqent::tv.
Referenced by __unload_module(), and unload_module().
03433 { 03434 struct manager_action *cur; 03435 struct timespec tv = { 5, }; 03436 03437 if (AST_RWLIST_TIMEDWRLOCK(&actions, &tv)) { 03438 ast_log(LOG_ERROR, "Could not obtain lock on manager list\n"); 03439 return -1; 03440 } 03441 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&actions, cur, list) { 03442 if (!strcasecmp(action, cur->action)) { 03443 AST_RWLIST_REMOVE_CURRENT(list); 03444 ast_free(cur); 03445 ast_verb(2, "Manager unregistered action %s\n", action); 03446 break; 03447 } 03448 } 03449 AST_RWLIST_TRAVERSE_SAFE_END; 03450 AST_RWLIST_UNLOCK(&actions); 03451 03452 return 0; 03453 }
| void ast_manager_unregister_hook | ( | struct manager_custom_hook * | hook | ) |
Delete a custom hook to be called when an event is fired.
Delete a custom hook to be called when an event is fired
| hook | struct manager_custom_hook object to delete |
Definition at line 272 of file manager.c.
References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.
00273 { 00274 AST_RWLIST_WRLOCK(&manager_hooks); 00275 AST_RWLIST_REMOVE(&manager_hooks, hook, list); 00276 AST_RWLIST_UNLOCK(&manager_hooks); 00277 return; 00278 }
| void astman_append | ( | struct mansession * | s, | |
| const char * | fmt, | |||
| ... | ||||
| ) |
utility functions for creating AMI replies
Definition at line 990 of file manager.c.
References ast_str_buffer(), ast_str_set_va(), ast_str_thread_get(), ast_verbose, astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE, buf, mansession_session::f, mansession::f, send_string(), and mansession::session.
Referenced by __iax2_show_peers(), _sip_show_peer(), _sip_show_peers(), _skinny_show_device(), _skinny_show_devices(), _skinny_show_line(), _skinny_show_lines(), action_agents(), action_challenge(), action_command(), action_coresettings(), action_coreshowchannels(), action_corestatus(), action_dahdishowchannels(), action_events(), action_extensionstate(), action_getconfig(), action_getconfigjson(), action_getvar(), action_listcategories(), action_listcommands(), action_mailboxcount(), action_mailboxstatus(), action_meetmelist(), action_ping(), action_status(), action_waitevent(), ast_cli_netstats(), astman_send_response_full(), do_print(), manager_dbget(), manager_iax2_show_netstats(), manager_iax2_show_peer_list(), manager_iax2_show_registry(), manager_jabber_send(), manager_list_voicemail_users(), manager_modulecheck(), manager_parking_status(), manager_queue_rule_show(), manager_queues_show(), manager_queues_status(), manager_queues_summary(), manager_rpt_local_nodes(), manager_rpt_status(), manager_show_dialplan(), manager_show_dialplan_helper(), manager_show_registry(), manager_sip_qualify_peer(), manager_sip_show_peer(), manager_sip_show_peers(), manager_skinny_show_device(), manager_skinny_show_devices(), manager_skinny_show_line(), manager_skinny_show_lines(), rpt_manager_do_stats(), rpt_manager_success(), and session_do().
00991 { 00992 va_list ap; 00993 struct ast_str *buf; 00994 00995 if (!(buf = ast_str_thread_get(&astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE))) 00996 return; 00997 00998 va_start(ap, fmt); 00999 ast_str_set_va(&buf, 0, fmt, ap); 01000 va_end(ap); 01001 01002 if (s->f != NULL || s->session->f != NULL) { 01003 send_string(s, ast_str_buffer(buf)); 01004 } else { 01005 ast_verbose("fd == -1 in astman_append, should not happen\n"); 01006 } 01007 }
| const char* astman_get_header | ( | const struct message * | m, | |
| char * | var | |||
| ) |
Get header from mananger transaction.
Definition at line 918 of file manager.c.
References __astman_get_header(), and GET_HEADER_FIRST_MATCH.
Referenced by _sip_show_peer(), _sip_show_peers(), _skinny_show_devices(), _skinny_show_lines(), action_add_agi_cmd(), action_agent_logoff(), action_agents(), action_atxfer(), action_bridge(), action_challenge(), action_command(), action_coresettings(), action_coreshowchannels(), action_corestatus(), action_createconfig(), action_dahdidialoffhook(), action_dahdidndoff(), action_dahdidndon(), action_dahdishowchannels(), action_events(), action_extensionstate(), action_getconfig(), action_getconfigjson(), action_getvar(), action_hangup(), action_listcategories(), action_mailboxcount(), action_mailboxstatus(), action_meetmelist(), action_originate(), action_ping(), action_redirect(), action_reload(), action_sendtext(), action_setvar(), action_status(), action_timeout(), action_transfer(), action_transferhangup(), action_updateconfig(), action_userevent(), action_waitevent(), astman_send_response_full(), authenticate(), change_monitor_action(), do_pause_or_unpause(), handle_updates(), manager_add_queue_member(), manager_dbdel(), manager_dbdeltree(), manager_dbget(), manager_dbput(), manager_iax2_show_peer_list(), manager_iax2_show_peers(), manager_iax2_show_registry(), manager_jabber_send(), manager_list_voicemail_users(), manager_modulecheck(), manager_moduleload(), manager_park(), manager_parking_status(), manager_pause_queue_member(), manager_play_dtmf(), manager_queue_log_custom(), manager_queue_member_penalty(), manager_queue_reload(), manager_queue_reset(), manager_queue_rule_show(), manager_queues_status(), manager_queues_summary(), manager_remove_queue_member(), manager_rpt_status(), manager_show_dialplan(), manager_show_registry(), manager_sip_qualify_peer(), manager_sip_show_peer(), manager_sip_show_peers(), manager_sipnotify(), manager_skinny_show_device(), manager_skinny_show_devices(), manager_skinny_show_line(), manager_skinny_show_lines(), meetmemute(), process_message(), rpt_manager_do_stats(), rpt_manager_success(), start_monitor_action(), and stop_monitor_action().
00919 { 00920 return __astman_get_header(m, var, GET_HEADER_FIRST_MATCH); 00921 }
| struct ast_variable* astman_get_variables | ( | const struct message * | m | ) | [read] |
Get a linked list of the Variable: headers.
Definition at line 924 of file manager.c.
References AST_APP_ARG, AST_DECLARE_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_variable_new(), message::hdrcount, message::headers, parse(), strsep(), and var.
Referenced by action_originate(), and manager_sipnotify().
00925 { 00926 int varlen, x, y; 00927 struct ast_variable *head = NULL, *cur; 00928 00929 AST_DECLARE_APP_ARGS(args, 00930 AST_APP_ARG(vars)[32]; 00931 ); 00932 00933 varlen = strlen("Variable: "); 00934 00935 for (x = 0; x < m->hdrcount; x++) { 00936 char *parse, *var, *val; 00937 00938 if (strncasecmp("Variable: ", m->headers[x], varlen)) 00939 continue; 00940 parse = ast_strdupa(m->headers[x] + varlen); 00941 00942 AST_STANDARD_APP_ARGS(args, parse); 00943 if (!args.argc) 00944 continue; 00945 for (y = 0; y < args.argc; y++) { 00946 if (!args.vars[y]) 00947 continue; 00948 var = val = ast_strdupa(args.vars[y]); 00949 strsep(&val, "="); 00950 if (!val || ast_strlen_zero(var)) 00951 continue; 00952 cur = ast_variable_new(var, val, ""); 00953 cur->next = head; 00954 head = cur; 00955 } 00956 } 00957 00958 return head; 00959 }
| void astman_send_ack | ( | struct mansession * | s, | |
| const struct message * | m, | |||
| char * | msg | |||
| ) |
Send ack in manager transaction.
Definition at line 1053 of file manager.c.
References astman_send_response_full().
Referenced by action_add_agi_cmd(), action_agent_logoff(), action_agents(), action_atxfer(), action_bridge(), action_createconfig(), action_dahdidialoffhook(), action_dahdidndoff(), action_dahdidndon(), action_dahdirestart(), action_dahdishowchannels(), action_hangup(), action_login(), action_originate(), action_redirect(), action_reload(), action_sendtext(), action_setvar(), action_status(), action_timeout(), action_transfer(), action_transferhangup(), action_updateconfig(), action_userevent(), change_monitor_action(), do_pause_or_unpause(), manager_add_queue_member(), manager_dbdel(), manager_dbdeltree(), manager_dbget(), manager_dbput(), manager_iax2_show_peers(), manager_jabber_send(), manager_list_voicemail_users(), manager_moduleload(), manager_park(), manager_parking_status(), manager_pause_queue_member(), manager_play_dtmf(), manager_queue_log_custom(), manager_queue_member_penalty(), manager_queue_reload(), manager_queue_reset(), manager_queues_status(), manager_queues_summary(), manager_remove_queue_member(), manager_sipnotify(), meetmemute(), start_monitor_action(), and stop_monitor_action().
01054 { 01055 astman_send_response_full(s, m, "Success", msg, NULL); 01056 }
| void astman_send_error | ( | struct mansession * | s, | |
| const struct message * | m, | |||
| char * | error | |||
| ) |
Send error in manager transaction.
Definition at line 1048 of file manager.c.
References astman_send_response_full().
Referenced by _sip_qualify_peer(), _sip_show_peer(), action_add_agi_cmd(), action_agent_logoff(), action_atxfer(), action_bridge(), action_challenge(), action_command(), action_createconfig(), action_dahdidialoffhook(), action_dahdidndoff(), action_dahdidndon(), action_dahdirestart(), action_events(), action_extensionstate(), action_getconfig(), action_getconfigjson(), action_getvar(), action_hangup(), action_listcategories(), action_login(), action_mailboxcount(), action_mailboxstatus(), action_meetmelist(), action_originate(), action_redirect(), action_reload(), action_sendtext(), action_setvar(), action_status(), action_timeout(), action_transfer(), action_transferhangup(), action_updateconfig(), change_monitor_action(), do_pause_or_unpause(), manager_add_queue_member(), manager_dbdel(), manager_dbdeltree(), manager_dbget(), manager_dbput(), manager_jabber_send(), manager_modulecheck(), manager_moduleload(), manager_park(), manager_pause_queue_member(), manager_play_dtmf(), manager_queue_log_custom(), manager_queue_member_penalty(), manager_queue_reload(), manager_queue_reset(), manager_remove_queue_member(), manager_rpt_status(), manager_show_dialplan(), manager_show_dialplan_helper(), manager_sip_qualify_peer(), manager_sip_show_peer(), manager_sipnotify(), manager_skinny_show_device(), manager_skinny_show_line(), meetmemute(), process_message(), rpt_manager_do_stats(), start_monitor_action(), and stop_monitor_action().
01049 { 01050 astman_send_response_full(s, m, "Error", error, NULL); 01051 }
| void astman_send_listack | ( | struct mansession * | s, | |
| const struct message * | m, | |||
| char * | msg, | |||
| char * | listflag | |||
| ) |
Send ack in manager list transaction.
Definition at line 1063 of file manager.c.
References astman_send_response_full().
Referenced by action_coreshowchannels(), action_meetmelist(), manager_dpsendack(), manager_iax2_show_registry(), manager_show_registry(), manager_sip_show_peers(), manager_skinny_show_devices(), and manager_skinny_show_lines().
01064 { 01065 astman_send_response_full(s, m, "Success", msg, listflag); 01066 }
| void astman_send_response | ( | struct mansession * | s, | |
| const struct message * | m, | |||
| char * | resp, | |||
| char * | msg | |||
| ) |
Send response in manager transaction.
Definition at line 1043 of file manager.c.
References astman_send_response_full().
Referenced by action_logoff(), and action_waitevent().
01044 { 01045 astman_send_response_full(s, m, resp, msg, NULL); 01046 }
| static void astman_send_response_full | ( | struct mansession * | s, | |
| const struct message * | m, | |||
| char * | resp, | |||
| char * | msg, | |||
| char * | listflag | |||
| ) | [static] |
Definition at line 1026 of file manager.c.
References ast_strlen_zero(), astman_append(), astman_get_header(), and MSG_MOREDATA.
Referenced by astman_send_ack(), astman_send_error(), astman_send_listack(), astman_send_response(), and astman_start_ack().
01027 { 01028 const char *id = astman_get_header(m, "ActionID"); 01029 01030 astman_append(s, "Response: %s\r\n", resp); 01031 if (!ast_strlen_zero(id)) 01032 astman_append(s, "ActionID: %s\r\n", id); 01033 if (listflag) 01034 astman_append(s, "EventList: %s\r\n", listflag); /* Start, complete, cancelled */ 01035 if (msg == MSG_MOREDATA) 01036 return; 01037 else if (msg) 01038 astman_append(s, "Message: %s\r\n\r\n", msg); 01039 else 01040 astman_append(s, "\r\n"); 01041 }
| static void astman_start_ack | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1058 of file manager.c.
References astman_send_response_full(), and MSG_MOREDATA.
Referenced by action_challenge(), action_extensionstate(), action_getconfig(), action_getconfigjson(), action_getvar(), action_listcategories(), action_listcommands(), action_mailboxcount(), and action_mailboxstatus().
01059 { 01060 astman_send_response_full(s, m, "Success", MSG_MOREDATA, NULL); 01061 }
| static int authenticate | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1092 of file manager.c.
References ast_apply_ha(), ast_copy_string(), ast_debug, ast_inet_ntoa(), ast_log(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strlen_zero(), astman_get_header(), mansession_session::challenge, get_manager_by_name_locked(), ast_manager_user::ha, len(), LOG_NOTICE, MD5Final(), MD5Init(), MD5Update(), ast_manager_user::readperm, mansession_session::readperm, S_OR, ast_manager_user::secret, mansession::session, mansession_session::sessionstart, set_eventmask(), mansession_session::sin, mansession_session::username, ast_manager_user::writeperm, mansession_session::writeperm, ast_manager_user::writetimeout, and mansession_session::writetimeout.
Referenced by action_login().
01093 { 01094 const char *username = astman_get_header(m, "Username"); 01095 const char *password = astman_get_header(m, "Secret"); 01096 int error = -1; 01097 struct ast_manager_user *user = NULL; 01098 01099 if (ast_strlen_zero(username)) /* missing username */ 01100 return -1; 01101 01102 /* locate user in locked state */ 01103 AST_RWLIST_WRLOCK(&users); 01104 01105 if (!(user = get_manager_by_name_locked(username))) { 01106 ast_log(LOG_NOTICE, "%s tried to authenticate with nonexistent user '%s'\n", ast_inet_ntoa(s->session->sin.sin_addr), username); 01107 } else if (user->ha && !ast_apply_ha(user->ha, &(s->session->sin))) { 01108 ast_log(LOG_NOTICE, "%s failed to pass IP ACL as '%s'\n", ast_inet_ntoa(s->session->sin.sin_addr), username); 01109 } else if (!strcasecmp(astman_get_header(m, "AuthType"), "MD5")) { 01110 const char *key = astman_get_header(m, "Key"); 01111 if (!ast_strlen_zero(key) && !ast_strlen_zero(s->session->challenge) && user->secret) { 01112 int x; 01113 int len = 0; 01114 char md5key[256] = ""; 01115 struct MD5Context md5; 01116 unsigned char digest[16]; 01117 01118 MD5Init(&md5); 01119 MD5Update(&md5, (unsigned char *) s->session->challenge, strlen(s->session->challenge)); 01120 MD5Update(&md5, (unsigned char *) user->secret, strlen(user->secret)); 01121 MD5Final(digest, &md5); 01122 for (x = 0; x < 16; x++) 01123 len += sprintf(md5key + len, "%2.2x", digest[x]); 01124 if (!strcmp(md5key, key)) 01125 error = 0; 01126 } else { 01127 ast_debug(1, "MD5 authentication is not possible. challenge: '%s'\n", 01128 S_OR(s->session->challenge, "")); 01129 } 01130 } else if (password && user->secret && !strcmp(password, user->secret)) 01131 error = 0; 01132 01133 if (error) { 01134 ast_log(LOG_NOTICE, "%s failed to authenticate as '%s'\n", ast_inet_ntoa(s->session->sin.sin_addr), username); 01135 AST_RWLIST_UNLOCK(&users); 01136 return -1; 01137 } 01138 01139 /* auth complete */ 01140 01141 ast_copy_string(s->session->username, username, sizeof(s->session->username)); 01142 s->session->readperm = user->readperm; 01143 s->session->writeperm = user->writeperm; 01144 s->session->writetimeout = user->writetimeout; 01145 s->session->sessionstart = time(NULL); 01146 set_eventmask(s, astman_get_header(m, "Events")); 01147 01148 AST_RWLIST_UNLOCK(&users); 01149 return 0; 01150 }
| static char* authority_to_str | ( | int | authority, | |
| struct ast_str ** | res | |||
| ) | [static] |
Convert authority code to a list of options.
Definition at line 412 of file manager.c.
References ARRAY_LEN, ast_str_append(), ast_str_buffer(), ast_str_reset(), ast_str_strlen(), num, and perms.
Referenced by __manager_event(), action_listcommands(), handle_showmanager(), handle_showmancmd(), and handle_showmancmds().
00413 { 00414 int i; 00415 char *sep = ""; 00416 00417 ast_str_reset(*res); 00418 for (i = 0; i < ARRAY_LEN(perms) - 1; i++) { 00419 if (authority & perms[i].num) { 00420 ast_str_append(res, 0, "%s%s", sep, perms[i].label); 00421 sep = ","; 00422 } 00423 } 00424 00425 if (ast_str_strlen(*res) == 0) /* replace empty string with something sensible */ 00426 ast_str_append(res, 0, "<none>"); 00427 00428 return ast_str_buffer(*res); 00429 }
| static int check_blacklist | ( | const char * | cmd | ) | [static] |
Definition at line 2261 of file manager.c.
References ARRAY_LEN, ast_strdupa, ast_strip(), ast_strlen_zero(), command_blacklist, match(), MAX_BLACKLIST_CMD_LEN, strsep(), and words.
Referenced by action_command().
02262 { 02263 char *cmd_copy, *cur_cmd; 02264 char *cmd_words[MAX_BLACKLIST_CMD_LEN] = { NULL, }; 02265 int i; 02266 02267 cmd_copy = ast_strdupa(cmd); 02268 for (i = 0; i < MAX_BLACKLIST_CMD_LEN && (cur_cmd = strsep(&cmd_copy, " ")); i++) { 02269 cur_cmd = ast_strip(cur_cmd); 02270 if (ast_strlen_zero(cur_cmd)) { 02271 i--; 02272 continue; 02273 } 02274 02275 cmd_words[i] = cur_cmd; 02276 } 02277 02278 for (i = 0; i < ARRAY_LEN(command_blacklist); i++) { 02279 int j, match = 1; 02280 02281 for (j = 0; command_blacklist[i].words[j]; j++) { 02282 if (ast_strlen_zero(cmd_words[j]) || strcasecmp(cmd_words[j], command_blacklist[i].words[j])) { 02283 match = 0; 02284 break; 02285 } 02286 } 02287 02288 if (match) { 02289 return 1; 02290 } 02291 } 02292 02293 return 0; 02294 }
| int check_manager_enabled | ( | void | ) |
Event list management functions. We assume that the event list always has at least one element, and the delete code will not remove the last entry even if the.
Check if AMI is enabled.
Definition at line 323 of file manager.c.
Referenced by handle_show_settings().
00324 { 00325 return manager_enabled; 00326 }
| static int check_manager_session_inuse | ( | const char * | name | ) | [static] |
Definition at line 495 of file manager.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, mansession_session::list, and mansession_session::username.
Referenced by process_message().
00496 { 00497 struct mansession_session *session = NULL; 00498 00499 AST_LIST_LOCK(&sessions); 00500 AST_LIST_TRAVERSE(&sessions, session, list) { 00501 if (!strcasecmp(session->username, name)) 00502 break; 00503 } 00504 AST_LIST_UNLOCK(&sessions); 00505 00506 return session ? 1 : 0; 00507 }
| int check_webmanager_enabled | ( | void | ) |
Check if AMI/HTTP is enabled.
Definition at line 328 of file manager.c.
Referenced by action_coresettings(), and handle_show_settings().
00329 { 00330 return (webmanager_enabled && manager_enabled); 00331 }
| static void destroy_session | ( | struct mansession_session * | session | ) | [static] |
Definition at line 873 of file manager.c.
References ast_atomic_fetchadd_int(), AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, and free_session().
Referenced by generic_http_callback(), and session_do().
00874 { 00875 AST_LIST_LOCK(&sessions); 00876 AST_LIST_REMOVE(&sessions, session, list); 00877 ast_atomic_fetchadd_int(&num_sessions, -1); 00878 free_session(session); 00879 AST_LIST_UNLOCK(&sessions); 00880 }
| static int do_message | ( | struct mansession * | s | ) | [static] |
Definition at line 3188 of file manager.c.
References AST_MAX_MANHEADERS, ast_strdupa, ast_strlen_zero(), get_input(), message::hdrcount, message::headers, mansession_session::inbuf, process_events(), process_message(), and mansession::session.
Referenced by session_do().
03189 { 03190 struct message m = { 0 }; 03191 char header_buf[sizeof(s->session->inbuf)] = { '\0' }; 03192 int res; 03193 03194 for (;;) { 03195 /* Check if any events are pending and do them if needed */ 03196 if (process_events(s)) 03197 return -1; 03198 res = get_input(s, header_buf); 03199 if (res == 0) { 03200 continue; 03201 } else if (res > 0) { 03202 if (ast_strlen_zero(header_buf)) 03203 return process_message(s, &m) ? -1 : 0; 03204 else if (m.hdrcount < (AST_MAX_MANHEADERS - 1)) 03205 m.headers[m.hdrcount++] = ast_strdupa(header_buf); 03206 } else { 03207 return res; 03208 } 03209 } 03210 }
| static void* fast_originate | ( | void * | data | ) | [static] |
Definition at line 2374 of file manager.c.
References fast_originate_helper::account, fast_originate_helper::app, fast_originate_helper::appdata, AST_CHANNEL_NAME, ast_channel_unlock, ast_free, ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_strlen_zero(), chan, 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, 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().
02375 { 02376 struct fast_originate_helper *in = data; 02377 int res; 02378 int reason = 0; 02379 struct ast_channel *chan = NULL; 02380 char requested_channel[AST_CHANNEL_NAME]; 02381 02382 if (!ast_strlen_zero(in->app)) { 02383 res = ast_pbx_outgoing_app(in->tech, in->format, in->data, in->timeout, in->app, in->appdata, &reason, 1, 02384 S_OR(in->cid_num, NULL), 02385 S_OR(in->cid_name, NULL), 02386 in->vars, in->account, &chan); 02387 } else { 02388 res = ast_pbx_outgoing_exten(in->tech, in->format, in->data, in->timeout, in->context, in->exten, in->priority, &reason, 1, 02389 S_OR(in->cid_num, NULL), 02390 S_OR(in->cid_name, NULL), 02391 in->vars, in->account, &chan); 02392 } 02393 02394 if (!chan) 02395 snprintf(requested_channel, AST_CHANNEL_NAME, "%s/%s", in->tech, in->data); 02396 /* Tell the manager what happened with the channel */ 02397 manager_event(EVENT_FLAG_CALL, "OriginateResponse", 02398 "%s%s" 02399 "Response: %s\r\n" 02400 "Channel: %s\r\n" 02401 "Context: %s\r\n" 02402 "Exten: %s\r\n" 02403 "Reason: %d\r\n" 02404 "Uniqueid: %s\r\n" 02405 "CallerIDNum: %s\r\n" 02406 "CallerIDName: %s\r\n", 02407 in->idtext, ast_strlen_zero(in->idtext) ? "" : "\r\n", res ? "Failure" : "Success", 02408 chan ? chan->name : requested_channel, in->context, in->exten, reason, 02409 chan ? chan->uniqueid : "<null>", 02410 S_OR(in->cid_num, "<unknown>"), 02411 S_OR(in->cid_name, "<unknown>") 02412 ); 02413 02414 /* Locked by ast_pbx_outgoing_exten or ast_pbx_outgoing_app */ 02415 if (chan) 02416 ast_channel_unlock(chan); 02417 ast_free(in); 02418 return NULL; 02419 }
| static void free_session | ( | struct mansession_session * | session | ) | [static] |
Definition at line 853 of file manager.c.
References mansession_session::__lock, ast_atomic_fetchadd_int(), ast_datastore_free(), ast_free, AST_LIST_REMOVE_HEAD, ast_mutex_destroy(), mansession_session::datastores, ast_datastore::entry, mansession_session::f, mansession_session::last_ev, and eventqent::usecount.
Referenced by destroy_session(), and purge_sessions().
00854 { 00855 struct eventqent *eqe = session->last_ev; 00856 struct ast_datastore *datastore; 00857 00858 /* Get rid of each of the data stores on the session */ 00859 while ((datastore = AST_LIST_REMOVE_HEAD(&session->datastores, entry))) { 00860 /* Free the data store */ 00861 ast_datastore_free(datastore); 00862 } 00863 00864 if (session->f != NULL) 00865 fclose(session->f); 00866 ast_mutex_destroy(&session->__lock); 00867 ast_free(session); 00868 if (eqe) { 00869 ast_atomic_fetchadd_int(&eqe->usecount, -1); 00870 } 00871 }
| static int get_input | ( | struct mansession * | s, | |
| char * | output | |||
| ) | [static] |
Read one full line (including crlf) from the manager socket.
* \r\n is the only valid terminator for the line. * (Note that, later, '\0' will be considered as the end-of-line marker, * so everything between the '\0' and the '\r\n' will not be used). * Also note that we assume output to have at least "maxlen" space. *
Definition at line 3118 of file manager.c.
References mansession_session::__lock, ast_inet_ntoa(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), AST_PTHREADT_NULL, ast_wait_for_input(), errno, mansession_session::f, mansession_session::fd, mansession_session::inbuf, mansession_session::inlen, LOG_WARNING, mansession_session::pending_event, mansession::session, mansession_session::sin, ast_frame::src, and mansession_session::waiting_thread.
Referenced by do_message().
03119 { 03120 int res, x; 03121 int maxlen = sizeof(s->session->inbuf) - 1; 03122 char *src = s->session->inbuf; 03123 03124 /* 03125 * Look for \r\n within the buffer. If found, copy to the output 03126 * buffer and return, trimming the \r\n (not used afterwards). 03127 */ 03128 for (x = 0; x < s->session->inlen; x++) { 03129 int cr; /* set if we have \r */ 03130 if (src[x] == '\r' && x+1 < s->session->inlen && src[x+1] == '\n') 03131 cr = 2; /* Found. Update length to include \r\n */ 03132 else if (src[x] == '\n') 03133 cr = 1; /* also accept \n only */ 03134 else 03135 continue; 03136 memmove(output, src, x); /*... but trim \r\n */ 03137 output[x] = '\0'; /* terminate the string */ 03138 x += cr; /* number of bytes used */ 03139 s->session->inlen -= x; /* remaining size */ 03140 memmove(src, src + x, s->session->inlen); /* remove used bytes */ 03141 return 1; 03142 } 03143 if (s->session->inlen >= maxlen) { 03144 /* no crlf found, and buffer full - sorry, too long for us */ 03145 ast_log(LOG_WARNING, "Dumping long line with no return from %s: %s\n", ast_inet_ntoa(s->session->sin.sin_addr), src); 03146 s->session->inlen = 0; 03147 } 03148 res = 0; 03149 while (res == 0) { 03150 /* XXX do we really need this locking ? */ 03151 ast_mutex_lock(&s->session->__lock); 03152 if (s->session->pending_event) { 03153 s->session->pending_event = 0; 03154 ast_mutex_unlock(&s->session->__lock); 03155 return 0; 03156 } 03157 s->session->waiting_thread = pthread_self(); 03158 ast_mutex_unlock(&s->session->__lock); 03159 03160 res = ast_wait_for_input(s->session->fd, -1); /* return 0 on timeout ? */ 03161 03162 ast_mutex_lock(&s->session->__lock); 03163 s->session->waiting_thread = AST_PTHREADT_NULL; 03164 ast_mutex_unlock(&s->session->__lock); 03165 } 03166 if (res < 0) { 03167 /* If we get a signal from some other thread (typically because 03168 * there are new events queued), return 0 to notify the caller. 03169 */ 03170 if (errno == EINTR || errno == EAGAIN) 03171 return 0; 03172 ast_log(LOG_WARNING, "poll() returned error: %s\n", strerror(errno)); 03173 return -1; 03174 } 03175 ast_mutex_lock(&s->session->__lock); 03176 res = fread(src + s->session->inlen, 1, maxlen - s->session->inlen, s->session->f); 03177 if (res < 1) 03178 res = -1; /* error return */ 03179 else { 03180 s->session->inlen += res; 03181 src[s->session->inlen] = '\0'; 03182 res = 0; 03183 } 03184 ast_mutex_unlock(&s->session->__lock); 03185 return res; 03186 }
| static struct ast_manager_user* get_manager_by_name_locked | ( | const char * | name | ) | [static, read] |
lookup an entry in the list of registered users. must be called with the list lock held.
Definition at line 514 of file manager.c.
References AST_RWLIST_TRAVERSE, ast_manager_user::list, and ast_manager_user::username.
Referenced by __init_manager(), authenticate(), handle_showmanager(), and manager_displayconnects().
00515 { 00516 struct ast_manager_user *user = NULL; 00517 00518 AST_RWLIST_TRAVERSE(&users, user, list) 00519 if (!strcasecmp(user->username, name)) 00520 break; 00521 return user; 00522 }
| static int get_perm | ( | const char * | instr | ) | [static] |
Definition at line 453 of file manager.c.
References ARRAY_LEN, ast_instring(), num, and perms.
Referenced by __init_manager(), and strings_to_mask().
00454 { 00455 int x = 0, ret = 0; 00456 00457 if (!instr) 00458 return 0; 00459 00460 for (x = 0; x < ARRAY_LEN(perms); x++) { 00461 if (ast_instring(instr, perms[x].label, ',')) 00462 ret |= perms[x].num; 00463 } 00464 00465 return ret; 00466 }
| static struct eventqent* grab_last | ( | void | ) | [static, read] |
Grab a reference to the last event, update usecount as needed. Can handle a NULL pointer.
Definition at line 337 of file manager.c.
References ast_atomic_fetchadd_int(), AST_RWLIST_LAST, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, and eventqent::usecount.
Referenced by generic_http_callback(), and session_do().
00338 { 00339 struct eventqent *ret; 00340 00341 AST_RWLIST_RDLOCK(&all_events); 00342 ret = AST_RWLIST_LAST(&all_events); 00343 /* the list is never empty now, but may become so when 00344 * we optimize it in the future, so be prepared. 00345 */ 00346 if (ret) { 00347 ast_atomic_fetchadd_int(&ret->usecount, 1); 00348 } 00349 AST_RWLIST_UNLOCK(&all_events); 00350 return ret; 00351 }
| static char* handle_manager_reload | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI command manager reload.
Definition at line 807 of file manager.c.
References ast_cli_args::argc, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, reload_manager(), and ast_cli_entry::usage.
00808 { 00809 switch (cmd) { 00810 case CLI_INIT: 00811 e->command = "manager reload"; 00812 e->usage = 00813 "Usage: manager reload\n" 00814 " Reloads the manager configuration.\n"; 00815 return NULL; 00816 case CLI_GENERATE: 00817 return NULL; 00818 } 00819 if (a->argc > 2) 00820 return CLI_SHOWUSAGE; 00821 reload_manager(); 00822 return CLI_SUCCESS; 00823 }
| static char* handle_mandebug | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 588 of file manager.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
00589 { 00590 switch (cmd) { 00591 case CLI_INIT: 00592 e->command = "manager set debug [on|off]"; 00593 e->usage = "Usage: manager set debug [on|off]\n Show, enable, disable debugging of the manager code.\n"; 00594 return NULL; 00595 case CLI_GENERATE: 00596 return NULL; 00597 } 00598 if (a->argc == 3) 00599 ast_cli(a->fd, "manager debug is %s\n", manager_debug? "on" : "off"); 00600 else if (a->argc == 4) { 00601 if (!strcasecmp(a->argv[3], "on")) 00602 manager_debug = 1; 00603 else if (!strcasecmp(a->argv[3], "off")) 00604 manager_debug = 0; 00605 else 00606 return CLI_SHOWUSAGE; 00607 } 00608 return CLI_SUCCESS; 00609 }
| static char* handle_showmanager | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 611 of file manager.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_str_alloca, ast_strdup, authority_to_str(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_manager_user::displayconnects, ast_cli_args::fd, get_manager_by_name_locked(), ast_manager_user::ha, ast_cli_args::n, ast_cli_args::pos, ast_manager_user::readperm, ast_manager_user::secret, ast_cli_entry::usage, ast_manager_user::username, ast_cli_args::word, and ast_manager_user::writeperm.
00612 { 00613 struct ast_manager_user *user = NULL; 00614 int l, which; 00615 char *ret = NULL; 00616 struct ast_str *rauthority = ast_str_alloca(128); 00617 struct ast_str *wauthority = ast_str_alloca(128); 00618 00619 switch (cmd) { 00620 case CLI_INIT: 00621 e->command = "manager show user"; 00622 e->usage = 00623 " Usage: manager show user <user>\n" 00624 " Display all information related to the manager user specified.\n"; 00625 return NULL; 00626 case CLI_GENERATE: 00627 l = strlen(a->word); 00628 which = 0; 00629 if (a->pos != 3) 00630 return NULL; 00631 AST_RWLIST_RDLOCK(&users); 00632 AST_RWLIST_TRAVERSE(&users, user, list) { 00633 if ( !strncasecmp(a->word, user->username, l) && ++which > a->n ) { 00634 ret = ast_strdup(user->username); 00635 break; 00636 } 00637 } 00638 AST_RWLIST_UNLOCK(&users); 00639 return ret; 00640 } 00641 00642 if (a->argc != 4) 00643 return CLI_SHOWUSAGE; 00644 00645 AST_RWLIST_RDLOCK(&users); 00646 00647 if (!(user = get_manager_by_name_locked(a->argv[3]))) { 00648 ast_cli(a->fd, "There is no manager called %s\n", a->argv[3]); 00649 AST_RWLIST_UNLOCK(&users); 00650 return CLI_SUCCESS; 00651 } 00652 00653 ast_cli(a->fd, "\n"); 00654 ast_cli(a->fd, 00655 " username: %s\n" 00656 " secret: %s\n" 00657 " acl: %s\n" 00658 " read perm: %s\n" 00659 " write perm: %s\n" 00660 "displayconnects: %s\n", 00661 (user->username ? user->username : "(N/A)"), 00662 (user->secret ? "<Set>" : "(N/A)"), 00663 (user->ha ? "yes" : "no"), 00664 authority_to_str(user->readperm, &rauthority), 00665 authority_to_str(user->writeperm, &wauthority), 00666 (user->displayconnects ? "yes" : "no")); 00667 00668 AST_RWLIST_UNLOCK(&users); 00669 00670 return CLI_SUCCESS; 00671 }
| static char* handle_showmanagers | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 674 of file manager.c.
References ast_cli_args::argc, ast_cli(), AST_RWLIST_EMPTY, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, ast_manager_user::list, ast_cli_entry::usage, and ast_manager_user::username.
00675 { 00676 struct ast_manager_user *user = NULL; 00677 int count_amu = 0; 00678 switch (cmd) { 00679 case CLI_INIT: 00680 e->command = "manager show users"; 00681 e->usage = 00682 "Usage: manager show users\n" 00683 " Prints a listing of all managers that are currently configured on that\n" 00684 " system.\n"; 00685 return NULL; 00686 case CLI_GENERATE: 00687 return NULL; 00688 } 00689 if (a->argc != 3) 00690 return CLI_SHOWUSAGE; 00691 00692 AST_RWLIST_RDLOCK(&users); 00693 00694 /* If there are no users, print out something along those lines */ 00695 if (AST_RWLIST_EMPTY(&users)) { 00696 ast_cli(a->fd, "There are no manager users.\n"); 00697 AST_RWLIST_UNLOCK(&users); 00698 return CLI_SUCCESS; 00699 } 00700 00701 ast_cli(a->fd, "\nusername\n--------\n"); 00702 00703 AST_RWLIST_TRAVERSE(&users, user, list) { 00704 ast_cli(a->fd, "%s\n", user->username); 00705 count_amu++; 00706 } 00707 00708 AST_RWLIST_UNLOCK(&users); 00709 00710 ast_cli(a->fd, "-------------------\n"); 00711 ast_cli(a->fd, "%d manager users configured.\n", count_amu); 00712 00713 return CLI_SUCCESS; 00714 }
| static char* handle_showmancmd | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 541 of file manager.c.
References manager_action::action, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_str_alloca, ast_strdup, manager_action::authority, authority_to_str(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, manager_action::description, ast_cli_args::fd, ast_cli_args::n, num, S_OR, manager_action::synopsis, ast_cli_entry::usage, and ast_cli_args::word.
00542 { 00543 struct manager_action *cur; 00544 struct ast_str *authority; 00545 int num, l, which; 00546 char *ret = NULL; 00547 switch (cmd) { 00548 case CLI_INIT: 00549 e->command = "manager show command"; 00550 e->usage = 00551 "Usage: manager show command <actionname> [<actionname> [<actionname> [...]]]\n" 00552 " Shows the detailed description for a specific Asterisk manager interface command.\n"; 00553 return NULL; 00554 case CLI_GENERATE: 00555 l = strlen(a->word); 00556 which = 0; 00557 AST_RWLIST_RDLOCK(&actions); 00558 AST_RWLIST_TRAVERSE(&actions, cur, list) { 00559 if (!strncasecmp(a->word, cur->action, l) && ++which > a->n) { 00560 ret = ast_strdup(cur->action); 00561 break; /* make sure we exit even if ast_strdup() returns NULL */ 00562 } 00563 } 00564 AST_RWLIST_UNLOCK(&actions); 00565 return ret; 00566 } 00567 authority = ast_str_alloca(80); 00568 if (a->argc < 4) { 00569 return CLI_SHOWUSAGE; 00570 } 00571 00572 AST_RWLIST_RDLOCK(&actions); 00573 AST_RWLIST_TRAVERSE(&actions, cur, list) { 00574 for (num = 3; num < a->argc; num++) { 00575 if (!strcasecmp(cur->action, a->argv[num])) { 00576 ast_cli(a->fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n", 00577 cur->action, cur->synopsis, 00578 authority_to_str(cur->authority, &authority), 00579 S_OR(cur->description, "")); 00580 } 00581 } 00582 } 00583 AST_RWLIST_UNLOCK(&actions); 00584 00585 return CLI_SUCCESS; 00586 }
| static char* handle_showmancmds | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI command manager list commands.
Definition at line 718 of file manager.c.
References manager_action::action, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_str_alloca, manager_action::authority, authority_to_str(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, HSMC_FORMAT, manager_action::synopsis, and ast_cli_entry::usage.
00719 { 00720 struct manager_action *cur; 00721 struct ast_str *authority; 00722 #define HSMC_FORMAT " %-15.15s %-15.15s %-55.55s\n" 00723 switch (cmd) { 00724 case CLI_INIT: 00725 e->command = "manager show commands"; 00726 e->usage = 00727 "Usage: manager show commands\n" 00728 " Prints a listing of all the available Asterisk manager interface commands.\n"; 00729 return NULL; 00730 case CLI_GENERATE: 00731 return NULL; 00732 } 00733 authority = ast_str_alloca(80); 00734 ast_cli(a->fd, HSMC_FORMAT, "Action", "Privilege", "Synopsis"); 00735 ast_cli(a->fd, HSMC_FORMAT, "------", "---------", "--------"); 00736 00737 AST_RWLIST_RDLOCK(&actions); 00738 AST_RWLIST_TRAVERSE(&actions, cur, list) 00739 ast_cli(a->fd, HSMC_FORMAT, cur->action, authority_to_str(cur->authority, &authority), cur->synopsis); 00740 AST_RWLIST_UNLOCK(&actions); 00741 00742 return CLI_SUCCESS; 00743 }
| static char* handle_showmanconn | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI command manager list connected.
Definition at line 746 of file manager.c.
References ast_cli(), ast_inet_ntoa(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, mansession_session::fd, ast_cli_args::fd, HSMCONN_FORMAT1, HSMCONN_FORMAT2, mansession_session::inuse, mansession_session::list, mansession_session::readperm, mansession_session::sessionstart, mansession_session::sin, ast_cli_entry::usage, mansession_session::username, and mansession_session::writeperm.
00747 { 00748 struct mansession_session *session; 00749 time_t now = time(NULL); 00750 #define HSMCONN_FORMAT1 " %-15.15s %-15.15s %-10.10s %-10.10s %-8.8s %-8.8s %-5.5s %-5.5s\n" 00751 #define HSMCONN_FORMAT2 " %-15.15s %-15.15s %-10d %-10d %-8d %-8d %-5.5d %-5.5d\n" 00752 int count = 0; 00753 switch (cmd) { 00754 case CLI_INIT: 00755 e->command = "manager show connected"; 00756 e->usage = 00757 "Usage: manager show connected\n" 00758 " Prints a listing of the users that are currently connected to the\n" 00759 "Asterisk manager interface.\n"; 00760 return NULL; 00761 case CLI_GENERATE: 00762 return NULL; 00763 } 00764 00765 ast_cli(a->fd, HSMCONN_FORMAT1, "Username", "IP Address", "Start", "Elapsed", "FileDes", "HttpCnt", "Read", "Write"); 00766 00767 AST_LIST_LOCK(&sessions); 00768 AST_LIST_TRAVERSE(&sessions, session, list) { 00769 ast_cli(a->fd, HSMCONN_FORMAT2, session->username, ast_inet_ntoa(session->sin.sin_addr), (int)(session->sessionstart), (int)(now - session->sessionstart), session->fd, session->inuse, session->readperm, session->writeperm); 00770 count++; 00771 } 00772 AST_LIST_UNLOCK(&sessions); 00773 00774 ast_cli(a->fd, "%d users connected.\n", count); 00775 00776 return CLI_SUCCESS; 00777 }
| static char* handle_showmaneventq | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI command manager list eventq.
Definition at line 781 of file manager.c.
References ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, eventqent::category, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, eventqent::eventdata, ast_cli_args::fd, s, ast_cli_entry::usage, and eventqent::usecount.
00782 { 00783 struct eventqent *s; 00784 switch (cmd) { 00785 case CLI_INIT: 00786 e->command = "manager show eventq"; 00787 e->usage = 00788 "Usage: manager show eventq\n" 00789 " Prints a listing of all events pending in the Asterisk manger\n" 00790 "event queue.\n"; 00791 return NULL; 00792 case CLI_GENERATE: 00793 return NULL; 00794 } 00795 AST_RWLIST_RDLOCK(&all_events); 00796 AST_RWLIST_TRAVERSE(&all_events, s, eq_next) { 00797 ast_cli(a->fd, "Usecount: %d\n", s->usecount); 00798 ast_cli(a->fd, "Category: %d\n", s->category); 00799 ast_cli(a->fd, "Event:\n%s", s->eventdata); 00800 } 00801 AST_RWLIST_UNLOCK(&all_events); 00802 00803 return CLI_SUCCESS; 00804 }
| static enum error_type handle_updates | ( | struct mansession * | s, | |
| const struct message * | m, | |||
| struct ast_config * | cfg, | |||
| const char * | dfn | |||
| ) | [static] |
Definition at line 1345 of file manager.c.
References ast_category_append(), ast_category_delete(), ast_category_empty(), ast_category_get(), ast_category_insert(), ast_category_new(), ast_category_rename(), ast_free, ast_log(), ast_str_create(), ast_strlen_zero(), ast_variable_append(), ast_variable_delete(), ast_variable_insert(), ast_variable_new(), ast_variable_update(), astman_get_header(), eventqent::category, FAILURE_ALLOCATION, FAILURE_DELCAT, FAILURE_DELETE, FAILURE_EMPTYCAT, FAILURE_NEWCAT, FAILURE_UPDATE, LOG_WARNING, match(), ast_variable::object, UNKNOWN_ACTION, UNKNOWN_CATEGORY, UNSPECIFIED_ARGUMENT, UNSPECIFIED_CATEGORY, and var.
Referenced by action_updateconfig().
01346 { 01347 int x; 01348 char hdr[40]; 01349 const char *action, *cat, *var, *value, *match, *line; 01350 struct ast_category *category; 01351 struct ast_variable *v; 01352 struct ast_str *str1 = ast_str_create(16), *str2 = ast_str_create(16); 01353 enum error_type result = 0; 01354 01355 for (x = 0; x < 100000; x++) { /* 100000 = the max number of allowed updates + 1 */ 01356 unsigned int object = 0; 01357 01358 snprintf(hdr, sizeof(hdr), "Action-%06d", x); 01359 action = astman_get_header(m, hdr); 01360 if (ast_strlen_zero(action)) /* breaks the for loop if no action header */ 01361 break; /* this could cause problems if actions come in misnumbered */ 01362 01363 snprintf(hdr, sizeof(hdr), "Cat-%06d", x); 01364 cat = astman_get_header(m, hdr); 01365 if (ast_strlen_zero(cat)) { /* every action needs a category */ 01366 result = UNSPECIFIED_CATEGORY; 01367 break; 01368 } 01369 01370 snprintf(hdr, sizeof(hdr), "Var-%06d", x); 01371 var = astman_get_header(m, hdr); 01372 01373 snprintf(hdr, sizeof(hdr), "Value-%06d", x); 01374 value = astman_get_header(m, hdr); 01375 01376 if (!ast_strlen_zero(value) && *value == '>') { 01377 object = 1; 01378 value++; 01379 } 01380 01381 snprintf(hdr, sizeof(hdr), "Match-%06d", x); 01382 match = astman_get_header(m, hdr); 01383 01384 snprintf(hdr, sizeof(hdr), "Line-%06d", x); 01385 line = astman_get_header(m, hdr); 01386 01387 if (!strcasecmp(action, "newcat")) { 01388 if (ast_category_get(cfg,cat)) { /* check to make sure the cat doesn't */ 01389 result = FAILURE_NEWCAT; /* already exist */ 01390 break; 01391 } 01392 if (!(category = ast_category_new(cat, dfn, -1))) { 01393 result = FAILURE_ALLOCATION; 01394 break; 01395 } 01396 if (ast_strlen_zero(match)) { 01397 ast_category_append(cfg, category); 01398 } else 01399 ast_category_insert(cfg, category, match); 01400 } else if (!strcasecmp(action, "renamecat")) { 01401 if (ast_strlen_zero(value)) { 01402 result = UNSPECIFIED_ARGUMENT; 01403 break; 01404 } 01405 if (!(category = ast_category_get(cfg, cat))) { 01406 result = UNKNOWN_CATEGORY; 01407 break; 01408 } 01409 ast_category_rename(category, value); 01410 } else if (!strcasecmp(action, "delcat")) { 01411 if (ast_category_delete(cfg, cat)) { 01412 result = FAILURE_DELCAT; 01413 break; 01414 } 01415 } else if (!strcasecmp(action, "emptycat")) { 01416 if (ast_category_empty(cfg, cat)) { 01417 result = FAILURE_EMPTYCAT; 01418 break; 01419 } 01420 } else if (!strcasecmp(action, "update")) { 01421 if (ast_strlen_zero(var)) { 01422 result = UNSPECIFIED_ARGUMENT; 01423 break; 01424 } 01425 if (!(category = ast_category_get(cfg,cat))) { 01426 result = UNKNOWN_CATEGORY; 01427 break; 01428 } 01429 if (ast_variable_update(category, var, value, match, object)) { 01430 result = FAILURE_UPDATE; 01431 break; 01432 } 01433 } else if (!strcasecmp(action, "delete")) { 01434 if ((ast_strlen_zero(var) && ast_strlen_zero(line))) { 01435 result = UNSPECIFIED_ARGUMENT; 01436 break; 01437 } 01438 if (!(category = ast_category_get(cfg, cat))) { 01439 result = UNKNOWN_CATEGORY; 01440 break; 01441 } 01442 if (ast_variable_delete(category, var, match, line)) { 01443 result = FAILURE_DELETE; 01444 break; 01445 } 01446 } else if (!strcasecmp(action, "append")) { 01447 if (ast_strlen_zero(var)) { 01448 result = UNSPECIFIED_ARGUMENT; 01449 break; 01450 } 01451 if (!(category = ast_category_get(cfg, cat))) { 01452 result = UNKNOWN_CATEGORY; 01453 break; 01454 } 01455 if (!(v = ast_variable_new(var, value, dfn))) { 01456 result = FAILURE_ALLOCATION; 01457 break; 01458 } 01459 if (object || (match && !strcasecmp(match, "object"))) 01460 v->object = 1; 01461 ast_variable_append(category, v); 01462 } else if (!strcasecmp(action, "insert")) { 01463 if (ast_strlen_zero(var) || ast_strlen_zero(line)) { 01464 result = UNSPECIFIED_ARGUMENT; 01465 break; 01466 } 01467 if (!(category = ast_category_get(cfg, cat))) { 01468 result = UNKNOWN_CATEGORY; 01469 break; 01470 } 01471 if (!(v = ast_variable_new(var, value, dfn))) { 01472 result = FAILURE_ALLOCATION; 01473 break; 01474 } 01475 ast_variable_insert(category, v, line); 01476 } 01477 else { 01478 ast_log(LOG_WARNING, "Action-%06d: %s not handled\n", x, action); 01479 result = UNKNOWN_ACTION; 01480 break; 01481 } 01482 } 01483 ast_free(str1); 01484 ast_free(str2); 01485 return result; 01486 }
| static void json_escape | ( | char * | out, | |
| const char * | in | |||
| ) | [static] |
The amount of space in out must be at least ( 2 * strlen(in) + 1 )
Definition at line 1261 of file manager.c.
Referenced by action_getconfigjson().
01262 { 01263 for (; *in; in++) { 01264 if (*in == '\\' || *in == '\"') 01265 *out++ = '\\'; 01266 *out++ = *in; 01267 } 01268 *out = '\0'; 01269 }
| static int manager_displayconnects | ( | struct mansession_session * | session | ) | [static] |
Get displayconnects config option.
| session | manager session to get parameter from. |
Definition at line 528 of file manager.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_manager_user::displayconnects, get_manager_by_name_locked(), and mansession_session::username.
Referenced by action_login(), generic_http_callback(), purge_sessions(), and session_do().
00529 { 00530 struct ast_manager_user *user = NULL; 00531 int ret = 0; 00532 00533 AST_RWLIST_RDLOCK(&users); 00534 if ((user = get_manager_by_name_locked (session->username))) 00535 ret = user->displayconnects; 00536 AST_RWLIST_UNLOCK(&users); 00537 00538 return ret; 00539 }
| static int manager_modulecheck | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2936 of file manager.c.
References ast_copy_string(), ast_file_version_find(), ast_log(), ast_module_check(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), LOG_DEBUG, and version.
Referenced by __init_manager().
02937 { 02938 int res; 02939 const char *module = astman_get_header(m, "Module"); 02940 const char *id = astman_get_header(m, "ActionID"); 02941 char idText[256]; 02942 #if !defined(LOW_MEMORY) 02943 const char *version; 02944 #endif 02945 char filename[PATH_MAX]; 02946 char *cut; 02947 02948 ast_copy_string(filename, module, sizeof(filename)); 02949 if ((cut = strchr(filename, '.'))) { 02950 *cut = '\0'; 02951 } else { 02952 cut = filename + strlen(filename); 02953 } 02954 snprintf(cut, (sizeof(filename) - strlen(filename)) - 1, ".so"); 02955 ast_log(LOG_DEBUG, "**** ModuleCheck .so file %s\n", filename); 02956 res = ast_module_check(filename); 02957 if (!res) { 02958 astman_send_error(s, m, "Module not loaded"); 02959 return 0; 02960 } 02961 snprintf(cut, (sizeof(filename) - strlen(filename)) - 1, ".c"); 02962 ast_log(LOG_DEBUG, "**** ModuleCheck .c file %s\n", filename); 02963 #if !defined(LOW_MEMORY) 02964 version = ast_file_version_find(filename); 02965 #endif 02966 02967 if (!ast_strlen_zero(id)) 02968 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id); 02969 else 02970 idText[0] = '\0'; 02971 astman_append(s, "Response: Success\r\n%s", idText); 02972 #if !defined(LOW_MEMORY) 02973 astman_append(s, "Version: %s\r\n\r\n", version ? version : ""); 02974 #endif 02975 return 0; 02976 }
| static int manager_moduleload | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2989 of file manager.c.
References AST_FORCE_SOFT, ast_load_resource(), ast_module_reload(), ast_unload_resource(), astman_get_header(), astman_send_ack(), and astman_send_error().
Referenced by __init_manager().
02990 { 02991 int res; 02992 const char *module = astman_get_header(m, "Module"); 02993 const char *loadtype = astman_get_header(m, "LoadType"); 02994 02995 if (!loadtype || strlen(loadtype) == 0) 02996 astman_send_error(s, m, "Incomplete ModuleLoad action."); 02997 if ((!module || strlen(module) == 0) && strcasecmp(loadtype, "reload") != 0) 02998 astman_send_error(s, m, "Need module name"); 02999 03000 if (!strcasecmp(loadtype, "load")) { 03001 res = ast_load_resource(module); 03002 if (res) 03003 astman_send_error(s, m, "Could not load module."); 03004 else 03005 astman_send_ack(s, m, "Module loaded."); 03006 } else if (!strcasecmp(loadtype, "unload")) { 03007 res = ast_unload_resource(module, AST_FORCE_SOFT); 03008 if (res) 03009 astman_send_error(s, m, "Could not unload module."); 03010 else 03011 astman_send_ack(s, m, "Module unloaded."); 03012 } else if (!strcasecmp(loadtype, "reload")) { 03013 if (module != NULL) { 03014 res = ast_module_reload(module); 03015 if (res == 0) 03016 astman_send_error(s, m, "No such module."); 03017 else if (res == 1) 03018 astman_send_error(s, m, "Module does not support reload action."); 03019 else 03020 astman_send_ack(s, m, "Module reloaded."); 03021 } else { 03022 ast_module_reload(NULL); /* Reload all modules */ 03023 astman_send_ack(s, m, "All modules reloaded"); 03024 } 03025 } else 03026 astman_send_error(s, m, "Incomplete ModuleLoad action."); 03027 return 0; 03028 }
| static int manager_state_cb | ( | char * | context, | |
| char * | exten, | |||
| int | state, | |||
| void * | data | |||
| ) | [static] |
Definition at line 3455 of file manager.c.
References ast_get_hint(), EVENT_FLAG_CALL, and manager_event.
Referenced by __init_manager().
03456 { 03457 /* Notify managers of change */ 03458 char hint[512]; 03459 ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, context, exten); 03460 03461 manager_event(EVENT_FLAG_CALL, "ExtensionStatus", "Exten: %s\r\nContext: %s\r\nHint: %s\r\nStatus: %d\r\n", exten, context, hint, state); 03462 return 0; 03463 }
| static int process_events | ( | struct mansession * | s | ) | [static] |
Send any applicable events to the client listening on this socket. Wait only for a finite time on each event, and drop all events whether they are successfully sent or not.
Definition at line 2706 of file manager.c.
References mansession_session::__lock, advance_event(), ast_mutex_lock(), ast_mutex_unlock(), mansession_session::authenticated, eventqent::category, eventqent::eventdata, mansession_session::f, mansession_session::last_ev, mansession_session::readperm, mansession_session::send_events, send_string(), and mansession::session.
Referenced by do_message(), and process_message().
02707 { 02708 int ret = 0; 02709 02710 ast_mutex_lock(&s->session->__lock); 02711 if (s->session->f != NULL) { 02712 struct eventqent *eqe = s->session->last_ev; 02713 02714 while ((eqe = advance_event(eqe))) { 02715 if (!ret && s->session->authenticated && 02716 (s->session->readperm & eqe->category) == eqe->category && 02717 (s->session->send_events & eqe->category) == eqe->category) { 02718 if (send_string(s, eqe->eventdata) < 0) 02719 ret = -1; /* don't send more */ 02720 } 02721 s->session->last_ev = eqe; 02722 } 02723 } 02724 ast_mutex_unlock(&s->session->__lock); 02725 return ret; 02726 }
| static int process_message | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 3043 of file manager.c.
References __astman_get_header(), mansession_session::__lock, manager_action::action, ast_copy_string(), ast_debug, ast_mutex_lock(), ast_mutex_unlock(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strlen_zero(), astman_get_header(), astman_send_error(), mansession_session::authenticated, manager_action::authority, buf, check_manager_session_inuse(), manager_action::func, GET_HEADER_SKIP_EMPTY, process_events(), mansession::session, and mansession_session::writeperm.
Referenced by do_message(), and generic_http_callback().
03044 { 03045 char action[80] = ""; 03046 int ret = 0; 03047 struct manager_action *tmp; 03048 const char *user = astman_get_header(m, "Username"); 03049 03050 ast_copy_string(action, __astman_get_header(m, "Action", GET_HEADER_SKIP_EMPTY), sizeof(action)); 03051 ast_debug(1, "Manager received command '%s'\n", action); 03052 03053 if (ast_strlen_zero(action)) { 03054 ast_mutex_lock(&s->session->__lock); 03055 astman_send_error(s, m, "Missing action in request"); 03056 ast_mutex_unlock(&s->session->__lock); 03057 return 0; 03058 } 03059 03060 if (!s->session->authenticated && strcasecmp(action, "Login") && strcasecmp(action, "Logoff") && strcasecmp(action, "Challenge")) { 03061 ast_mutex_lock(&s->session->__lock); 03062 astman_send_error(s, m, "Permission denied"); 03063 ast_mutex_unlock(&s->session->__lock); 03064 return 0; 03065 } 03066 03067 if (!allowmultiplelogin && !s->session->authenticated && user && 03068 (!strcasecmp(action, "Login") || !strcasecmp(action, "Challenge"))) { 03069 if (check_manager_session_inuse(user)) { 03070 sleep(1); 03071 ast_mutex_lock(&s->session->__lock); 03072 astman_send_error(s, m, "Login Already In Use"); 03073 ast_mutex_unlock(&s->session->__lock); 03074 return -1; 03075 } 03076 } 03077 03078 AST_RWLIST_RDLOCK(&actions); 03079 AST_RWLIST_TRAVERSE(&actions, tmp, list) { 03080 if (strcasecmp(action, tmp->action)) 03081 continue; 03082 if (s->session->writeperm & tmp->authority || tmp->authority == 0) 03083 ret = tmp->func(s, m); 03084 else 03085 astman_send_error(s, m, "Permission denied"); 03086 break; 03087 } 03088 AST_RWLIST_UNLOCK(&actions); 03089 03090 if (!tmp) { 03091 char buf[512]; 03092 snprintf(buf, sizeof(buf), "Invalid/unknown command: %s. Use Action: ListCommands to show available commands.", action); 03093 ast_mutex_lock(&s->session->__lock); 03094 astman_send_error(s, m, buf); 03095 ast_mutex_unlock(&s->session->__lock); 03096 } 03097 if (ret) 03098 return ret; 03099 /* Once done with our message, deliver any pending events unless the 03100 requester doesn't want them as part of this response. 03101 */ 03102 if (ast_strlen_zero(astman_get_header(m, "SuppressEvents"))) { 03103 return process_events(s); 03104 } else { 03105 return ret; 03106 } 03107 }
| static void purge_events | ( | void | ) | [static] |
Purge unused events. Remove elements from the head as long as their usecount is 0 and there is a next element.
Definition at line 357 of file manager.c.
References ast_free, AST_RWLIST_FIRST, AST_RWLIST_NEXT, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_REMOVE_HEAD, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_tvdiff_sec(), ast_tvnow(), eventqent::tv, and eventqent::usecount.
Referenced by purge_old_stuff().
00358 { 00359 struct eventqent *ev; 00360 struct timeval now = ast_tvnow(); 00361 00362 AST_RWLIST_WRLOCK(&all_events); 00363 while ( (ev = AST_RWLIST_FIRST(&all_events)) && 00364 ev->usecount == 0 && AST_RWLIST_NEXT(ev, eq_next)) { 00365 AST_RWLIST_REMOVE_HEAD(&all_events, eq_next); 00366 ast_free(ev); 00367 } 00368 00369 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&all_events, ev, eq_next) { 00370 /* Never release the last event */ 00371 if (!AST_RWLIST_NEXT(ev, eq_next)) { 00372 break; 00373 } 00374 00375 /* 2.5 times whatever the HTTP timeout is (maximum 2.5 hours) is the maximum time that we will definitely cache an event */ 00376 if (ev->usecount == 0 && ast_tvdiff_sec(now, ev->tv) > (httptimeout > 3600 ? 3600 : httptimeout) * 2.5) { 00377 AST_RWLIST_REMOVE_CURRENT(eq_next); 00378 ast_free(ev); 00379 } 00380 } 00381 AST_RWLIST_TRAVERSE_SAFE_END; 00382 AST_RWLIST_UNLOCK(&all_events); 00383 }
| static void purge_sessions | ( | int | n_max | ) | [static] |
remove at most n_max stale session from the list.
Definition at line 3298 of file manager.c.
References ast_atomic_fetchadd_int(), ast_inet_ntoa(), AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_verb, mansession_session::authenticated, free_session(), mansession_session::inuse, manager_displayconnects(), mansession_session::sessiontimeout, mansession_session::sin, mansession_session::username, and VERBOSITY_ATLEAST.
Referenced by purge_old_stuff().
03299 { 03300 struct mansession_session *session; 03301 time_t now = time(NULL); 03302 03303 AST_LIST_LOCK(&sessions); 03304 AST_LIST_TRAVERSE_SAFE_BEGIN(&sessions, session, list) { 03305 if (session->sessiontimeout && (now > session->sessiontimeout) && !session->inuse) { 03306 AST_LIST_REMOVE_CURRENT(list); 03307 ast_atomic_fetchadd_int(&num_sessions, -1); 03308 if (session->authenticated && (VERBOSITY_ATLEAST(2)) && manager_displayconnects(session)) { 03309 ast_verb(2, "HTTP Manager '%s' timed out from %s\n", 03310 session->username, ast_inet_ntoa(session->sin.sin_addr)); 03311 } 03312 free_session(session); /* XXX outside ? */ 03313 if (--n_max <= 0) 03314 break; 03315 } 03316 } 03317 AST_LIST_TRAVERSE_SAFE_END; 03318 AST_LIST_UNLOCK(&sessions); 03319 }
| static int send_string | ( | struct mansession * | s, | |
| char * | string | |||
| ) | [static] |
helper function to send a string to the socket. Return -1 on error (e.g. buffer full).
Definition at line 965 of file manager.c.
References ast_careful_fwrite(), mansession_session::f, mansession::f, mansession_session::fd, mansession::fd, mansession::session, and mansession_session::writetimeout.
Referenced by astman_append(), and process_events().
00966 { 00967 if (s->f) { 00968 return ast_careful_fwrite(s->f, s->fd, string, strlen(string), s->session->writetimeout); 00969 } else { 00970 return ast_careful_fwrite(s->session->f, s->session->fd, string, strlen(string), s->session->writetimeout); 00971 } 00972 }
| static void* session_do | ( | void * | data | ) | [static] |
The body of the individual manager session. Call get_input() to read one line at a time (or be woken up on new events), collect the lines in a message until found an empty line, and execute the request. In any case, deliver events asynchronously through process_events() (called from here if no line is available, or at the end of process_message(). ).
Definition at line 3220 of file manager.c.
References mansession_session::__lock, AMI_VERSION, ao2_ref, ast_atomic_fetchadd_int(), ast_calloc, ast_inet_ntoa(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log(), ast_mutex_init(), AST_PTHREADT_NULL, ast_verb, astman_append(), mansession_session::authenticated, mansession_session::datastores, destroy_session(), do_message(), errno, ast_tcptls_session_instance::f, mansession_session::f, mansession_session::fd, ast_tcptls_session_instance::fd, ast_frame::flags, grab_last(), mansession_session::last_ev, LOG_EVENT, LOG_WARNING, manager_displayconnects(), ast_tcptls_session_instance::remote_address, s, mansession_session::send_events, mansession::session, mansession_session::sin, mansession_session::username, mansession_session::waiting_thread, and mansession_session::writetimeout.
03221 { 03222 struct ast_tcptls_session_instance *ser = data; 03223 struct mansession_session *session = ast_calloc(1, sizeof(*session)); 03224 struct mansession s = {.session = NULL, }; 03225 int flags; 03226 int res; 03227 struct protoent *p; 03228 03229 if (session == NULL) 03230 goto done; 03231 03232 /* here we set TCP_NODELAY on the socket to disable Nagle's algorithm. 03233 * This is necessary to prevent delays (caused by buffering) as we 03234 * write to the socket in bits and peices. */ 03235 p = getprotobyname("tcp"); 03236 if (p) { 03237 int arg = 1; 03238 if( setsockopt(ser->fd, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) { 03239 ast_log(LOG_WARNING, "Failed to set manager tcp connection to TCP_NODELAY mode: %s\nSome manager actions may be slow to respond.\n", strerror(errno)); 03240 } 03241 } else { 03242 ast_log(LOG_WARNING, "Failed to set manager tcp connection to TCP_NODELAY, getprotobyname(\"tcp\") failed\nSome manager actions may be slow to respond.\n"); 03243 } 03244 03245 session->writetimeout = 100; 03246 session->waiting_thread = AST_PTHREADT_NULL; 03247 03248 flags = fcntl(ser->fd, F_GETFL); 03249 if (!block_sockets) /* make sure socket is non-blocking */ 03250 flags |= O_NONBLOCK; 03251 else 03252 flags &= ~O_NONBLOCK; 03253 fcntl(ser->fd, F_SETFL, flags); 03254 03255 ast_mutex_init(&session->__lock); 03256 session->send_events = -1; 03257 /* Hook to the tail of the event queue */ 03258 session->last_ev = grab_last(); 03259 03260 /* these fields duplicate those in the 'ser' structure */ 03261 session->fd = ser->fd; 03262 session->f = ser->f; 03263 session->sin = ser->remote_address; 03264 s.session = session; 03265 03266 AST_LIST_HEAD_INIT_NOLOCK(&session->datastores); 03267 03268 AST_LIST_LOCK(&sessions); 03269 AST_LIST_INSERT_HEAD(&sessions, session, list); 03270 ast_atomic_fetchadd_int(&num_sessions, 1); 03271 AST_LIST_UNLOCK(&sessions); 03272 03273 astman_append(&s, "Asterisk Call Manager/%s\r\n", AMI_VERSION); /* welcome prompt */ 03274 for (;;) { 03275 if ((res = do_message(&s)) < 0) 03276 break; 03277 } 03278 /* session is over, explain why and terminate */ 03279 if (session->authenticated) { 03280 if (manager_displayconnects(session)) 03281 ast_verb(2, "Manager '%s' logged off from %s\n", session->username, ast_inet_ntoa(session->sin.sin_addr)); 03282 ast_log(LOG_EVENT, "Manager '%s' logged off from %s\n", session->username, ast_inet_ntoa(session->sin.sin_addr)); 03283 } else { 03284 if (displayconnects) 03285 ast_verb(2, "Connect attempt from '%s' unable to authenticate\n", ast_inet_ntoa(session->sin.sin_addr)); 03286 ast_log(LOG_EVENT, "Failed attempt from %s\n", ast_inet_ntoa(session->sin.sin_addr)); 03287 } 03288 03289 destroy_session(session); 03290 03291 done: 03292 ao2_ref(ser, -1); 03293 ser = NULL; 03294 return NULL; 03295 }
| static int set_eventmask | ( | struct mansession * | s, | |
| const char * | eventmask | |||
| ) | [static] |
Rather than braindead on,off this now can also accept a specific int mask value or a ',' delim list of mask strings (the same as manager.conf) -anthm.
Definition at line 1073 of file manager.c.
References mansession_session::__lock, ast_mutex_lock(), ast_mutex_unlock(), mansession_session::send_events, mansession::session, and strings_to_mask().
Referenced by action_events(), and authenticate().
01074 { 01075 int maskint = strings_to_mask(eventmask); 01076 01077 ast_mutex_lock(&s->session->__lock); 01078 if (maskint >= 0) 01079 s->session->send_events = maskint; 01080 ast_mutex_unlock(&s->session->__lock); 01081 01082 return maskint; 01083 }
| static int strings_to_mask | ( | const char * | string | ) | [static] |
A number returns itself, false returns 0, true returns all flags, other strings return the flags that are set.
Definition at line 472 of file manager.c.
References ARRAY_LEN, ast_false(), ast_strlen_zero(), ast_true(), get_perm(), num, and perms.
Referenced by set_eventmask().
00473 { 00474 const char *p; 00475 00476 if (ast_strlen_zero(string)) 00477 return -1; 00478 00479 for (p = string; *p; p++) 00480 if (*p < '0' || *p > '9') 00481 break; 00482 if (!*p) /* all digits */ 00483 return atoi(string); 00484 if (ast_false(string)) 00485 return 0; 00486 if (ast_true(string)) { /* all permissions */ 00487 int x, ret = 0; 00488 for (x = 0; x < ARRAY_LEN(perms); x++) 00489 ret |= perms[x].num; 00490 return ret; 00491 } 00492 return get_perm(string); 00493 }
int allowmultiplelogin = 1 [static] |
struct ast_threadstorage astman_append_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_astman_append_buf , .custom_init = NULL , } [static] |
int block_sockets [static] |
int broken_events_action [static] |
struct ast_cli_entry cli_manager[] [static] |
struct { ... } command_blacklist[] [static] |
Referenced by check_blacklist().
const int DEFAULT_BLOCKSOCKETS = 0 [static] |
const int DEFAULT_BROKENEVENTSACTION = 0 [static] |
const int DEFAULT_DISPLAYCONNECTS = 1 [static] |
const int DEFAULT_ENABLED = 0 [static] |
const int DEFAULT_HTTPTIMEOUT = 60 [static] |
const int DEFAULT_TIMESTAMPEVENTS = 0 [static] |
const int DEFAULT_WEBENABLED = 0 [static] |
int displayconnects [static] |
int httptimeout [static] |
int manager_debug [static] |
int manager_enabled = 0 [static] |
struct ast_threadstorage manager_event_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_manager_event_buf , .custom_init = NULL , } [static] |
char mandescr_atxfer[] [static] |
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 2296 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 2754 of file manager.c.
Referenced by __init_manager().
char mandescr_coreshowchannels[] [static] |
Initial value:
"Description: List currently defined channels and some information\n" " about them.\n" "Variables:\n" " ActionID: Optional Action id for message matching.\n"
Definition at line 2857 of file manager.c.
Referenced by __init_manager().
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 2800 of file manager.c.
Referenced by __init_manager().
char mandescr_createconfig[] [static] |
char mandescr_events[] [static] |
char mandescr_extensionstate[] [static] |
char mandescr_getconfig[] [static] |
char mandescr_getconfigjson[] [static] |
char mandescr_getvar[] [static] |
char mandescr_hangup[] [static] |
Initial value:
"Description: Hangup a channel\n" "Variables: \n" " Channel: The channel name to be hungup\n"
Definition at line 1817 of file manager.c.
Referenced by __init_manager().
char mandescr_listcategories[] [static] |
Initial value:
"Description: A 'ListCategories' action will dump the categories in\n" "a given file.\n" "Variables:\n" " Filename: Configuration filename (e.g. foo.conf)\n"
Definition at line 1219 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 1706 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 1772 of file manager.c.
Referenced by __init_manager().
char mandescr_mailboxcount[] [static] |
char mandescr_mailboxstatus[] [static] |
Help text for manager command mailboxstatus.
Definition at line 2570 of file manager.c.
Referenced by __init_manager().
char mandescr_modulecheck[] [static] |
char mandescr_moduleload[] [static] |
char mandescr_originate[] [static] |
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"
Definition at line 1153 of file manager.c.
Referenced by __init_manager().
char mandescr_redirect[] [static] |
char mandescr_reload[] [static] |
Initial value:
"Description: Send a reload event.\n" "Variables: (Names marked with * are optional)\n" " *ActionID: ActionID of this transaction\n" " *Module: Name of the module to reload\n"
Definition at line 2838 of file manager.c.
Referenced by __init_manager().
char mandescr_sendtext[] [static] |
char mandescr_setvar[] [static] |
char mandescr_status[] [static] |
char mandescr_timeout[] [static] |
char mandescr_updateconfig[] [static] |
char mandescr_userevent[] [static] |
char mandescr_waitevent[] [static] |
int num_sessions [static] |
helper functions to convert back and forth between string and numeric representation of set of flags
Referenced by action_events(), authority_to_str(), get_perm(), and strings_to_mask().
int timestampevents [static] |
struct ast_threadstorage userevent_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_userevent_buf , .custom_init = NULL , } [static] |
int webmanager_enabled = 0 [static] |
1.5.9