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 | channelvars |
| struct | eventqent |
| struct | fast_originate_helper |
| helper function for originate More... | |
| struct | manager_channel_variable |
| struct | manager_hooks |
| list of hooks registered More... | |
| struct | mansession |
| struct | mansession_session |
| struct | permalias |
| 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 | DEFAULT_REALM "asterisk" |
| #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 | |
| int | __ast_manager_event_multichan (int category, const char *event, int chancount, struct ast_channel **chans, const char *file, int line, const char *func, const char *fmt,...) |
| 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_manager_event_funcbuf (void) |
| static void | __init_userevent_buf (void) |
| static int | action_aocmessage (struct mansession *s, const struct message *m) |
| 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 | aocmessage_get_unit_entry (const struct message *m, struct ast_aoc_unit_entry *entry, unsigned int entry_num) |
| static void | append_channel_vars (struct ast_str **pbuf, struct ast_channel *chan) |
| static int | append_event (const char *str, int category) |
| int | ast_hook_send_action (struct manager_custom_hook *hook, const char *msg) |
| Registered hooks can call this function to invoke actions and they will receive responses through registered callback. | |
| 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 const char * | authority_to_str (int authority, struct ast_str **res) |
| Convert authority code to a list of options. | |
| static int | blackfilter_cmp_fn (void *obj, void *arg, void *data, int flags) |
| static struct mansession_session * | build_mansession (struct sockaddr_in sin) |
| Allocate manager session structure and add it to the list of sessions. | |
| static int | check_blacklist (const char *cmd) |
| int | check_manager_enabled () |
| Check if AMI is enabled. | |
| static int | check_manager_session_inuse (const char *name) |
| int | check_webmanager_enabled () |
| Check if AMI/HTTP is enabled. | |
| static int | do_message (struct mansession *s) |
| static void | event_filter_destructor (void *obj) |
| static void * | fast_originate (void *data) |
| static void | free_channelvars (void) |
| 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 | mansession_cmp_fn (void *obj, void *arg, int flags) |
| static struct sockaddr_in * | mansession_encode_sin_local (const struct mansession *s, struct sockaddr_in *sin_local) |
| static enum ast_security_event_transport_type | mansession_get_transport (const struct mansession *s) |
| static void | mansession_lock (struct mansession *s) |
| Lock the 'mansession' structure. | |
| static void | mansession_unlock (struct mansession *s) |
| Unlock the 'mansession' structure. | |
| static int | match_filter (struct mansession *s, char *eventdata) |
| 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 void | report_auth_success (const struct mansession *s) |
| static void | report_failed_acl (const struct mansession *s, const char *username) |
| static void | report_failed_challenge_response (const struct mansession *s, const char *response, const char *expected_response) |
| static void | report_inval_password (const struct mansession *s, const char *username) |
| static void | report_invalid_user (const struct mansession *s, const char *username) |
| static void | report_req_bad_format (const struct mansession *s, const char *action) |
| static void | report_req_not_allowed (const struct mansession *s, const char *action) |
| static void | report_session_limit (const struct mansession *s) |
| static int | send_string (struct mansession *s, char *string) |
| static void | session_destroy (struct mansession_session *s) |
| static void | session_destructor (void *obj) |
| 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) |
| static struct mansession_session * | unref_mansession (struct mansession_session *s) |
| Unreference manager session object. If no more references, then go ahead and delete it. | |
| static int | whitefilter_cmp_fn (void *obj, void *arg, void *data, int flags) |
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 |
| struct { | |
| const 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 char | global_realm [MAXHOSTNAMELEN] |
| static int | httptimeout |
| static char * | manager_channelvars |
| 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 struct ast_threadstorage | manager_event_funcbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_manager_event_funcbuf , .custom_init = NULL , } |
| static struct permalias | perms [] |
| static struct ao2_container * | sessions = NULL |
| 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 1874 of file manager.c.
Referenced by astman_append().
| #define DEFAULT_REALM "asterisk" |
| #define GET_HEADER_FIRST_MATCH 0 |
| #define GET_HEADER_LAST_MATCH 1 |
| #define GET_HEADER_SKIP_EMPTY 2 |
Definition at line 1703 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 890 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 1915 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 811 of file manager.c.
00811 { 00812 UNKNOWN_ACTION = 1, 00813 UNKNOWN_CATEGORY, 00814 UNSPECIFIED_CATEGORY, 00815 UNSPECIFIED_ARGUMENT, 00816 FAILURE_ALLOCATION, 00817 FAILURE_NEWCAT, 00818 FAILURE_DELCAT, 00819 FAILURE_EMPTYCAT, 00820 FAILURE_UPDATE, 00821 FAILURE_DELETE, 00822 FAILURE_APPEND 00823 };
| int __ast_manager_event_multichan | ( | int | category, | |
| const char * | event, | |||
| int | chancount, | |||
| struct ast_channel ** | chans, | |||
| const char * | file, | |||
| int | line, | |||
| const char * | func, | |||
| const char * | contents, | |||
| ... | ||||
| ) |
External routines may send asterisk manager events this way
| category | Event category, matches manager authorization | |
| event | Event name | |
| chancount | Number of channels in chans parameter | |
| chans | A pointer to an array of channels involved in the event | |
| contents | Format string describing event |
Definition at line 4795 of file manager.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_unlock, append_channel_vars(), append_event(), ast_atomic_fetchadd_int(), 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(), manager_custom_hook::helper, manager_debug, manager_event_buf, MANAGER_EVENT_BUF_INITSIZE, mansession_session::pending_event, eventqent::seq, unref_mansession(), and mansession_session::waiting_thread.
04797 { 04798 struct mansession_session *session; 04799 struct manager_custom_hook *hook; 04800 struct ast_str *auth = ast_str_alloca(80); 04801 const char *cat_str; 04802 va_list ap; 04803 struct timeval now; 04804 struct ast_str *buf; 04805 int i; 04806 04807 if (!sessions && AST_RWLIST_EMPTY(&manager_hooks)) { 04808 return 0; 04809 } 04810 04811 if (!(buf = ast_str_thread_get(&manager_event_buf, MANAGER_EVENT_BUF_INITSIZE))) { 04812 return -1; 04813 } 04814 04815 cat_str = authority_to_str(category, &auth); 04816 ast_str_set(&buf, 0, 04817 "Event: %s\r\nPrivilege: %s\r\n", 04818 event, cat_str); 04819 04820 if (timestampevents) { 04821 now = ast_tvnow(); 04822 ast_str_append(&buf, 0, 04823 "Timestamp: %ld.%06lu\r\n", 04824 (long)now.tv_sec, (unsigned long) now.tv_usec); 04825 } 04826 if (manager_debug) { 04827 static int seq; 04828 ast_str_append(&buf, 0, 04829 "SequenceNumber: %d\r\n", 04830 ast_atomic_fetchadd_int(&seq, 1)); 04831 ast_str_append(&buf, 0, 04832 "File: %s\r\nLine: %d\r\nFunc: %s\r\n", file, line, func); 04833 } 04834 04835 va_start(ap, fmt); 04836 ast_str_append_va(&buf, 0, fmt, ap); 04837 va_end(ap); 04838 for (i = 0; i < chancount; i++) { 04839 append_channel_vars(&buf, chans[i]); 04840 } 04841 04842 ast_str_append(&buf, 0, "\r\n"); 04843 04844 append_event(ast_str_buffer(buf), category); 04845 04846 /* Wake up any sleeping sessions */ 04847 if (sessions) { 04848 struct ao2_iterator i; 04849 i = ao2_iterator_init(sessions, 0); 04850 while ((session = ao2_iterator_next(&i))) { 04851 ao2_lock(session); 04852 if (session->waiting_thread != AST_PTHREADT_NULL) { 04853 pthread_kill(session->waiting_thread, SIGURG); 04854 } else { 04855 /* We have an event to process, but the mansession is 04856 * not waiting for it. We still need to indicate that there 04857 * is an event waiting so that get_input processes the pending 04858 * event instead of polling. 04859 */ 04860 session->pending_event = 1; 04861 } 04862 ao2_unlock(session); 04863 unref_mansession(session); 04864 } 04865 ao2_iterator_destroy(&i); 04866 } 04867 04868 if (!AST_RWLIST_EMPTY(&manager_hooks)) { 04869 AST_RWLIST_RDLOCK(&manager_hooks); 04870 AST_RWLIST_TRAVERSE(&manager_hooks, hook, list) { 04871 hook->helper(category, event, ast_str_buffer(buf)); 04872 } 04873 AST_RWLIST_UNLOCK(&manager_hooks); 04874 } 04875 04876 return 0; 04877 }
| static const char* __astman_get_header | ( | const struct message * | m, | |
| char * | var, | |||
| int | mode | |||
| ) | [static] |
Definition at line 1704 of file manager.c.
References ast_skip_blanks(), ast_strlen_zero(), GET_HEADER_LAST_MATCH, GET_HEADER_SKIP_EMPTY, message::hdrcount, message::headers, and value.
Referenced by astman_get_header(), and process_message().
01705 { 01706 int x, l = strlen(var); 01707 const char *result = ""; 01708 01709 for (x = 0; x < m->hdrcount; x++) { 01710 const char *h = m->headers[x]; 01711 if (!strncasecmp(var, h, l) && h[l] == ':') { 01712 const char *value = h + l + 1; 01713 value = ast_skip_blanks(value); /* ignore leading spaces in the value */ 01714 /* found a potential candidate */ 01715 if (mode & GET_HEADER_SKIP_EMPTY && ast_strlen_zero(value)) 01716 continue; /* not interesting */ 01717 if (mode & GET_HEADER_LAST_MATCH) 01718 result = value; /* record the last match so far */ 01719 else 01720 return value; 01721 } 01722 } 01723 01724 return ""; 01725 }
| static void __init_astman_append_buf | ( | void | ) | [static] |
thread local buffer for astman_append
Definition at line 1870 of file manager.c.
| static void __init_manager_event_buf | ( | void | ) | [static] |
| static void __init_manager_event_funcbuf | ( | void | ) | [static] |
| static void __init_userevent_buf | ( | void | ) | [static] |
| static int action_aocmessage | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 3608 of file manager.c.
References ast_aoc_unit_entry::amount, aocmessage_get_unit_entry(), ast_aoc_add_unit_entry(), AST_AOC_BILLING_CALL_DEFLECTION, AST_AOC_BILLING_CALL_FWD_BUSY, AST_AOC_BILLING_CALL_FWD_NO_REPLY, AST_AOC_BILLING_CALL_FWD_UNCONDITIONAL, AST_AOC_BILLING_CALL_TRANSFER, AST_AOC_BILLING_CREDIT_CARD, AST_AOC_BILLING_NA, AST_AOC_BILLING_NORMAL, AST_AOC_BILLING_REVERSE_CHARGE, AST_AOC_CHARGE_CURRENCY, AST_AOC_CHARGE_FREE, AST_AOC_CHARGE_NA, AST_AOC_CHARGE_UNIT, ast_aoc_create(), AST_AOC_D, ast_aoc_destroy_decoded(), ast_aoc_destroy_encoded(), AST_AOC_E, ast_aoc_encode(), AST_AOC_MULT_HUNDRED, AST_AOC_MULT_ONE, AST_AOC_MULT_ONEHUNDREDTH, AST_AOC_MULT_ONETENTH, AST_AOC_MULT_ONETHOUSANDTH, AST_AOC_MULT_TEN, AST_AOC_MULT_THOUSAND, ast_aoc_set_association_id(), ast_aoc_set_association_number(), ast_aoc_set_billing_id(), ast_aoc_set_currency_info(), ast_aoc_set_total_type(), AST_AOC_SUBTOTAL, AST_AOC_TOTAL, ast_channel_get_by_name(), ast_channel_get_by_name_prefix(), ast_channel_unref, AST_CONTROL_AOC, ast_indicate_data(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), ast_aoc_unit_entry::type, ast_aoc_unit_entry::valid_amount, and ast_aoc_unit_entry::valid_type.
Referenced by __init_manager().
03609 { 03610 const char *channel = astman_get_header(m, "Channel"); 03611 const char *pchannel = astman_get_header(m, "ChannelPrefix"); 03612 const char *msgtype = astman_get_header(m, "MsgType"); 03613 const char *chargetype = astman_get_header(m, "ChargeType"); 03614 const char *currencyname = astman_get_header(m, "CurrencyName"); 03615 const char *currencyamount = astman_get_header(m, "CurrencyAmount"); 03616 const char *mult = astman_get_header(m, "CurrencyMultiplier"); 03617 const char *totaltype = astman_get_header(m, "TotalType"); 03618 const char *aocbillingid = astman_get_header(m, "AOCBillingId"); 03619 const char *association_id= astman_get_header(m, "ChargingAssociationId"); 03620 const char *association_num = astman_get_header(m, "ChargingAssociationNumber"); 03621 const char *association_plan = astman_get_header(m, "ChargingAssociationPlan"); 03622 03623 enum ast_aoc_type _msgtype; 03624 enum ast_aoc_charge_type _chargetype; 03625 enum ast_aoc_currency_multiplier _mult = AST_AOC_MULT_ONE; 03626 enum ast_aoc_total_type _totaltype = AST_AOC_TOTAL; 03627 enum ast_aoc_billing_id _billingid = AST_AOC_BILLING_NA; 03628 unsigned int _currencyamount = 0; 03629 int _association_id = 0; 03630 unsigned int _association_plan = 0; 03631 struct ast_channel *chan = NULL; 03632 03633 struct ast_aoc_decoded *decoded = NULL; 03634 struct ast_aoc_encoded *encoded = NULL; 03635 size_t encoded_size = 0; 03636 03637 if (ast_strlen_zero(channel) && ast_strlen_zero(pchannel)) { 03638 astman_send_error(s, m, "Channel and PartialChannel are not specified. Specify at least one of these."); 03639 goto aocmessage_cleanup; 03640 } 03641 03642 if (!(chan = ast_channel_get_by_name(channel)) && !ast_strlen_zero(pchannel)) { 03643 chan = ast_channel_get_by_name_prefix(pchannel, strlen(pchannel)); 03644 } 03645 03646 if (!chan) { 03647 astman_send_error(s, m, "No such channel"); 03648 goto aocmessage_cleanup; 03649 } 03650 03651 if (ast_strlen_zero(msgtype) || (strcasecmp(msgtype, "d") && strcasecmp(msgtype, "e"))) { 03652 astman_send_error(s, m, "Invalid MsgType"); 03653 goto aocmessage_cleanup; 03654 } 03655 03656 if (ast_strlen_zero(chargetype)) { 03657 astman_send_error(s, m, "ChargeType not specified"); 03658 goto aocmessage_cleanup; 03659 } 03660 03661 _msgtype = strcasecmp(msgtype, "d") ? AST_AOC_E : AST_AOC_D; 03662 03663 if (!strcasecmp(chargetype, "NA")) { 03664 _chargetype = AST_AOC_CHARGE_NA; 03665 } else if (!strcasecmp(chargetype, "Free")) { 03666 _chargetype = AST_AOC_CHARGE_FREE; 03667 } else if (!strcasecmp(chargetype, "Currency")) { 03668 _chargetype = AST_AOC_CHARGE_CURRENCY; 03669 } else if (!strcasecmp(chargetype, "Unit")) { 03670 _chargetype = AST_AOC_CHARGE_UNIT; 03671 } else { 03672 astman_send_error(s, m, "Invalid ChargeType"); 03673 goto aocmessage_cleanup; 03674 } 03675 03676 if (_chargetype == AST_AOC_CHARGE_CURRENCY) { 03677 03678 if (ast_strlen_zero(currencyamount) || (sscanf(currencyamount, "%30u", &_currencyamount) != 1)) { 03679 astman_send_error(s, m, "Invalid CurrencyAmount, CurrencyAmount is a required when ChargeType is Currency"); 03680 goto aocmessage_cleanup; 03681 } 03682 03683 if (ast_strlen_zero(mult)) { 03684 astman_send_error(s, m, "ChargeMultiplier unspecified, ChargeMultiplier is required when ChargeType is Currency."); 03685 goto aocmessage_cleanup; 03686 } else if (!strcasecmp(mult, "onethousandth")) { 03687 _mult = AST_AOC_MULT_ONETHOUSANDTH; 03688 } else if (!strcasecmp(mult, "onehundredth")) { 03689 _mult = AST_AOC_MULT_ONEHUNDREDTH; 03690 } else if (!strcasecmp(mult, "onetenth")) { 03691 _mult = AST_AOC_MULT_ONETENTH; 03692 } else if (!strcasecmp(mult, "one")) { 03693 _mult = AST_AOC_MULT_ONE; 03694 } else if (!strcasecmp(mult, "ten")) { 03695 _mult = AST_AOC_MULT_TEN; 03696 } else if (!strcasecmp(mult, "hundred")) { 03697 _mult = AST_AOC_MULT_HUNDRED; 03698 } else if (!strcasecmp(mult, "thousand")) { 03699 _mult = AST_AOC_MULT_THOUSAND; 03700 } else { 03701 astman_send_error(s, m, "Invalid ChargeMultiplier"); 03702 goto aocmessage_cleanup; 03703 } 03704 } 03705 03706 /* create decoded object and start setting values */ 03707 if (!(decoded = ast_aoc_create(_msgtype, _chargetype, 0))) { 03708 astman_send_error(s, m, "Message Creation Failed"); 03709 goto aocmessage_cleanup; 03710 } 03711 03712 if (_msgtype == AST_AOC_D) { 03713 if (!ast_strlen_zero(totaltype) && !strcasecmp(totaltype, "subtotal")) { 03714 _totaltype = AST_AOC_SUBTOTAL; 03715 } 03716 03717 if (ast_strlen_zero(aocbillingid)) { 03718 /* ignore this is optional */ 03719 } else if (!strcasecmp(aocbillingid, "Normal")) { 03720 _billingid = AST_AOC_BILLING_NORMAL; 03721 } else if (!strcasecmp(aocbillingid, "ReverseCharge")) { 03722 _billingid = AST_AOC_BILLING_REVERSE_CHARGE; 03723 } else if (!strcasecmp(aocbillingid, "CreditCard")) { 03724 _billingid = AST_AOC_BILLING_CREDIT_CARD; 03725 } else { 03726 astman_send_error(s, m, "Invalid AOC-D AOCBillingId"); 03727 goto aocmessage_cleanup; 03728 } 03729 } else { 03730 if (ast_strlen_zero(aocbillingid)) { 03731 /* ignore this is optional */ 03732 } else if (!strcasecmp(aocbillingid, "Normal")) { 03733 _billingid = AST_AOC_BILLING_NORMAL; 03734 } else if (!strcasecmp(aocbillingid, "ReverseCharge")) { 03735 _billingid = AST_AOC_BILLING_REVERSE_CHARGE; 03736 } else if (!strcasecmp(aocbillingid, "CreditCard")) { 03737 _billingid = AST_AOC_BILLING_CREDIT_CARD; 03738 } else if (!strcasecmp(aocbillingid, "CallFwdUnconditional")) { 03739 _billingid = AST_AOC_BILLING_CALL_FWD_UNCONDITIONAL; 03740 } else if (!strcasecmp(aocbillingid, "CallFwdBusy")) { 03741 _billingid = AST_AOC_BILLING_CALL_FWD_BUSY; 03742 } else if (!strcasecmp(aocbillingid, "CallFwdNoReply")) { 03743 _billingid = AST_AOC_BILLING_CALL_FWD_NO_REPLY; 03744 } else if (!strcasecmp(aocbillingid, "CallDeflection")) { 03745 _billingid = AST_AOC_BILLING_CALL_DEFLECTION; 03746 } else if (!strcasecmp(aocbillingid, "CallTransfer")) { 03747 _billingid = AST_AOC_BILLING_CALL_TRANSFER; 03748 } else { 03749 astman_send_error(s, m, "Invalid AOC-E AOCBillingId"); 03750 goto aocmessage_cleanup; 03751 } 03752 03753 if (!ast_strlen_zero(association_id) && (sscanf(association_id, "%30d", &_association_id) != 1)) { 03754 astman_send_error(s, m, "Invalid ChargingAssociationId"); 03755 goto aocmessage_cleanup; 03756 } 03757 if (!ast_strlen_zero(association_plan) && (sscanf(association_plan, "%30u", &_association_plan) != 1)) { 03758 astman_send_error(s, m, "Invalid ChargingAssociationPlan"); 03759 goto aocmessage_cleanup; 03760 } 03761 03762 if (_association_id) { 03763 ast_aoc_set_association_id(decoded, _association_id); 03764 } else if (!ast_strlen_zero(association_num)) { 03765 ast_aoc_set_association_number(decoded, association_num, _association_plan); 03766 } 03767 } 03768 03769 if (_chargetype == AST_AOC_CHARGE_CURRENCY) { 03770 ast_aoc_set_currency_info(decoded, _currencyamount, _mult, ast_strlen_zero(currencyname) ? NULL : currencyname); 03771 } else if (_chargetype == AST_AOC_CHARGE_UNIT) { 03772 struct ast_aoc_unit_entry entry; 03773 int i; 03774 03775 /* multiple unit entries are possible, lets get them all */ 03776 for (i = 0; i < 32; i++) { 03777 if (aocmessage_get_unit_entry(m, &entry, i)) { 03778 break; /* that's the end then */ 03779 } 03780 03781 ast_aoc_add_unit_entry(decoded, entry.valid_amount, entry.amount, entry.valid_type, entry.type); 03782 } 03783 03784 /* at least one unit entry is required */ 03785 if (!i) { 03786 astman_send_error(s, m, "Invalid UnitAmount(0), At least one valid unit entry is required when ChargeType is set to Unit"); 03787 goto aocmessage_cleanup; 03788 } 03789 03790 } 03791 03792 ast_aoc_set_billing_id(decoded, _billingid); 03793 ast_aoc_set_total_type(decoded, _totaltype); 03794 03795 03796 if ((encoded = ast_aoc_encode(decoded, &encoded_size, NULL)) && !ast_indicate_data(chan, AST_CONTROL_AOC, encoded, encoded_size)) { 03797 astman_send_ack(s, m, "AOC Message successfully queued on channel"); 03798 } else { 03799 astman_send_error(s, m, "Error encoding AOC message, could not queue onto channel"); 03800 } 03801 03802 aocmessage_cleanup: 03803 03804 ast_aoc_destroy_decoded(decoded); 03805 ast_aoc_destroy_encoded(encoded); 03806 03807 if (chan) { 03808 chan = ast_channel_unref(chan); 03809 } 03810 return 0; 03811 }
| static int action_atxfer | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 3375 of file manager.c.
References ast_channel_get_by_name(), ast_channel_unref, ast_find_call_feature(), AST_FRAME_DTMF, ast_queue_frame(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), context, ast_call_feature::exten, exten, and pbx_builtin_setvar_helper().
Referenced by __init_manager().
03376 { 03377 const char *name = astman_get_header(m, "Channel"); 03378 const char *exten = astman_get_header(m, "Exten"); 03379 const char *context = astman_get_header(m, "Context"); 03380 struct ast_channel *chan = NULL; 03381 struct ast_call_feature *atxfer_feature = NULL; 03382 char *feature_code = NULL; 03383 03384 if (ast_strlen_zero(name)) { 03385 astman_send_error(s, m, "No channel specified"); 03386 return 0; 03387 } 03388 if (ast_strlen_zero(exten)) { 03389 astman_send_error(s, m, "No extension specified"); 03390 return 0; 03391 } 03392 03393 if (!(atxfer_feature = ast_find_call_feature("atxfer"))) { 03394 astman_send_error(s, m, "No attended transfer feature found"); 03395 return 0; 03396 } 03397 03398 if (!(chan = ast_channel_get_by_name(name))) { 03399 astman_send_error(s, m, "Channel specified does not exist"); 03400 return 0; 03401 } 03402 03403 if (!ast_strlen_zero(context)) { 03404 pbx_builtin_setvar_helper(chan, "TRANSFER_CONTEXT", context); 03405 } 03406 03407 for (feature_code = atxfer_feature->exten; feature_code && *feature_code; ++feature_code) { 03408 struct ast_frame f = { AST_FRAME_DTMF, .subclass.integer = *feature_code }; 03409 ast_queue_frame(chan, &f); 03410 } 03411 03412 for (feature_code = (char *)exten; feature_code && *feature_code; ++feature_code) { 03413 struct ast_frame f = { AST_FRAME_DTMF, .subclass.integer = *feature_code }; 03414 ast_queue_frame(chan, &f); 03415 } 03416 03417 chan = ast_channel_unref(chan); 03418 03419 astman_send_ack(s, m, "Atxfer successfully queued"); 03420 03421 return 0; 03422 }
| static int action_challenge | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2944 of file manager.c.
References ast_random(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), mansession_session::challenge, mansession_lock(), mansession_unlock(), and mansession::session.
Referenced by __init_manager().
02945 { 02946 const char *authtype = astman_get_header(m, "AuthType"); 02947 02948 if (!strcasecmp(authtype, "MD5")) { 02949 if (ast_strlen_zero(s->session->challenge)) { 02950 snprintf(s->session->challenge, sizeof(s->session->challenge), "%ld", ast_random()); 02951 } 02952 mansession_lock(s); 02953 astman_start_ack(s, m); 02954 astman_append(s, "Challenge: %s\r\n\r\n", s->session->challenge); 02955 mansession_unlock(s); 02956 } else { 02957 astman_send_error(s, m, "Must specify AuthType"); 02958 } 02959 return 0; 02960 }
| static int action_command | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Manager command "command" - execute CLI command.
Definition at line 3460 of file manager.c.
References ast_calloc, ast_cli_command, ast_free, ast_log(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), check_blacklist(), errno, LOG_WARNING, S_OR, and term_strip().
Referenced by __init_manager().
03461 { 03462 const char *cmd = astman_get_header(m, "Command"); 03463 const char *id = astman_get_header(m, "ActionID"); 03464 char *buf, *final_buf; 03465 char template[] = "/tmp/ast-ami-XXXXXX"; /* template for temporary file */ 03466 int fd; 03467 off_t l; 03468 03469 if (ast_strlen_zero(cmd)) { 03470 astman_send_error(s, m, "No command provided"); 03471 return 0; 03472 } 03473 03474 if (check_blacklist(cmd)) { 03475 astman_send_error(s, m, "Command blacklisted"); 03476 return 0; 03477 } 03478 03479 fd = mkstemp(template); 03480 03481 astman_append(s, "Response: Follows\r\nPrivilege: Command\r\n"); 03482 if (!ast_strlen_zero(id)) { 03483 astman_append(s, "ActionID: %s\r\n", id); 03484 } 03485 /* FIXME: Wedge a ActionID response in here, waiting for later changes */ 03486 ast_cli_command(fd, cmd); /* XXX need to change this to use a FILE * */ 03487 l = lseek(fd, 0, SEEK_END); /* how many chars available */ 03488 03489 /* This has a potential to overflow the stack. Hence, use the heap. */ 03490 buf = ast_calloc(1, l + 1); 03491 final_buf = ast_calloc(1, l + 1); 03492 if (buf) { 03493 lseek(fd, 0, SEEK_SET); 03494 if (read(fd, buf, l) < 0) { 03495 ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno)); 03496 } 03497 buf[l] = '\0'; 03498 if (final_buf) { 03499 term_strip(final_buf, buf, l); 03500 final_buf[l] = '\0'; 03501 } 03502 astman_append(s, "%s", S_OR(final_buf, buf)); 03503 ast_free(buf); 03504 } 03505 close(fd); 03506 unlink(template); 03507 astman_append(s, "--END COMMAND--\r\n\r\n"); 03508 if (final_buf) { 03509 ast_free(final_buf); 03510 } 03511 return 0; 03512 }
| static int action_coresettings | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Show PBX core settings information.
Definition at line 4148 of file manager.c.
References AMI_VERSION, AST_CLI_YESNO, 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().
04149 { 04150 const char *actionid = astman_get_header(m, "ActionID"); 04151 char idText[150]; 04152 04153 if (!ast_strlen_zero(actionid)) { 04154 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid); 04155 } else { 04156 idText[0] = '\0'; 04157 } 04158 04159 astman_append(s, "Response: Success\r\n" 04160 "%s" 04161 "AMIversion: %s\r\n" 04162 "AsteriskVersion: %s\r\n" 04163 "SystemName: %s\r\n" 04164 "CoreMaxCalls: %d\r\n" 04165 "CoreMaxLoadAvg: %f\r\n" 04166 "CoreRunUser: %s\r\n" 04167 "CoreRunGroup: %s\r\n" 04168 "CoreMaxFilehandles: %d\r\n" 04169 "CoreRealTimeEnabled: %s\r\n" 04170 "CoreCDRenabled: %s\r\n" 04171 "CoreHTTPenabled: %s\r\n" 04172 "\r\n", 04173 idText, 04174 AMI_VERSION, 04175 ast_get_version(), 04176 ast_config_AST_SYSTEM_NAME, 04177 option_maxcalls, 04178 option_maxload, 04179 ast_config_AST_RUN_USER, 04180 ast_config_AST_RUN_GROUP, 04181 option_maxfiles, 04182 AST_CLI_YESNO(ast_realtime_enabled()), 04183 AST_CLI_YESNO(check_cdr_enabled()), 04184 AST_CLI_YESNO(check_webmanager_enabled()) 04185 ); 04186 return 0; 04187 }
| 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 4245 of file manager.c.
References ast_channel::_state, ast_channel::accountcode, ast_channel::appl, ast_bridged_channel(), ast_channel_iterator_all_new(), ast_channel_iterator_destroy(), ast_channel_iterator_next(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, ast_state2str(), ast_strlen_zero(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), astman_append(), astman_get_header(), astman_send_error(), astman_send_listack(), ast_channel::caller, ast_channel::cdr, ast_channel::context, ast_channel::data, ast_channel::exten, ast_party_caller::id, ast_channel::name, ast_party_id::number, ast_channel::priority, S_COR, S_OR, ast_cdr::start, ast_party_number::str, ast_channel::uniqueid, and ast_party_number::valid.
Referenced by __init_manager().
04246 { 04247 const char *actionid = astman_get_header(m, "ActionID"); 04248 char idText[256]; 04249 struct ast_channel *c = NULL; 04250 int numchans = 0; 04251 int duration, durh, durm, durs; 04252 struct ast_channel_iterator *iter; 04253 04254 if (!ast_strlen_zero(actionid)) { 04255 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid); 04256 } else { 04257 idText[0] = '\0'; 04258 } 04259 04260 if (!(iter = ast_channel_iterator_all_new())) { 04261 astman_send_error(s, m, "Memory Allocation Failure"); 04262 return 1; 04263 } 04264 04265 astman_send_listack(s, m, "Channels will follow", "start"); 04266 04267 for (; (c = ast_channel_iterator_next(iter)); ast_channel_unref(c)) { 04268 struct ast_channel *bc; 04269 char durbuf[10] = ""; 04270 04271 ast_channel_lock(c); 04272 04273 bc = ast_bridged_channel(c); 04274 if (c->cdr && !ast_tvzero(c->cdr->start)) { 04275 duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000); 04276 durh = duration / 3600; 04277 durm = (duration % 3600) / 60; 04278 durs = duration % 60; 04279 snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs); 04280 } 04281 04282 astman_append(s, 04283 "Event: CoreShowChannel\r\n" 04284 "%s" 04285 "Channel: %s\r\n" 04286 "UniqueID: %s\r\n" 04287 "Context: %s\r\n" 04288 "Extension: %s\r\n" 04289 "Priority: %d\r\n" 04290 "ChannelState: %d\r\n" 04291 "ChannelStateDesc: %s\r\n" 04292 "Application: %s\r\n" 04293 "ApplicationData: %s\r\n" 04294 "CallerIDnum: %s\r\n" 04295 "Duration: %s\r\n" 04296 "AccountCode: %s\r\n" 04297 "BridgedChannel: %s\r\n" 04298 "BridgedUniqueID: %s\r\n" 04299 "\r\n", idText, c->name, c->uniqueid, c->context, c->exten, c->priority, c->_state, 04300 ast_state2str(c->_state), c->appl ? c->appl : "", c->data ? S_OR(c->data, "") : "", 04301 S_COR(c->caller.id.number.valid, c->caller.id.number.str, ""), 04302 durbuf, S_OR(c->accountcode, ""), bc ? bc->name : "", bc ? bc->uniqueid : ""); 04303 04304 ast_channel_unlock(c); 04305 04306 numchans++; 04307 } 04308 04309 astman_append(s, 04310 "Event: CoreShowChannelsComplete\r\n" 04311 "EventList: Complete\r\n" 04312 "ListItems: %d\r\n" 04313 "%s" 04314 "\r\n", numchans, idText); 04315 04316 ast_channel_iterator_destroy(iter); 04317 04318 return 0; 04319 }
| static int action_corestatus | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Show PBX core status information.
Definition at line 4190 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().
04191 { 04192 const char *actionid = astman_get_header(m, "ActionID"); 04193 char idText[150]; 04194 char startuptime[150], startupdate[150]; 04195 char reloadtime[150], reloaddate[150]; 04196 struct ast_tm tm; 04197 04198 if (!ast_strlen_zero(actionid)) { 04199 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid); 04200 } else { 04201 idText[0] = '\0'; 04202 } 04203 04204 ast_localtime(&ast_startuptime, &tm, NULL); 04205 ast_strftime(startuptime, sizeof(startuptime), "%H:%M:%S", &tm); 04206 ast_strftime(startupdate, sizeof(startupdate), "%Y-%m-%d", &tm); 04207 ast_localtime(&ast_lastreloadtime, &tm, NULL); 04208 ast_strftime(reloadtime, sizeof(reloadtime), "%H:%M:%S", &tm); 04209 ast_strftime(reloaddate, sizeof(reloaddate), "%Y-%m-%d", &tm); 04210 04211 astman_append(s, "Response: Success\r\n" 04212 "%s" 04213 "CoreStartupDate: %s\r\n" 04214 "CoreStartupTime: %s\r\n" 04215 "CoreReloadDate: %s\r\n" 04216 "CoreReloadTime: %s\r\n" 04217 "CoreCurrentCalls: %d\r\n" 04218 "\r\n", 04219 idText, 04220 startupdate, 04221 startuptime, 04222 reloaddate, 04223 reloadtime, 04224 ast_active_channels() 04225 ); 04226 return 0; 04227 }
| static int action_createconfig | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2733 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().
02734 { 02735 int fd; 02736 const char *fn = astman_get_header(m, "Filename"); 02737 struct ast_str *filepath = ast_str_alloca(PATH_MAX); 02738 ast_str_set(&filepath, 0, "%s/", ast_config_AST_CONFIG_DIR); 02739 ast_str_append(&filepath, 0, "%s", fn); 02740 02741 if ((fd = open(ast_str_buffer(filepath), O_CREAT | O_EXCL, AST_FILE_MODE)) != -1) { 02742 close(fd); 02743 astman_send_ack(s, m, "New configuration file created successfully"); 02744 } else { 02745 astman_send_error(s, m, strerror(errno)); 02746 } 02747 02748 return 0; 02749 }
| static int action_events | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2877 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().
02878 { 02879 const char *mask = astman_get_header(m, "EventMask"); 02880 int res, x; 02881 02882 res = set_eventmask(s, mask); 02883 if (broken_events_action) { 02884 /* if this option is set we should not return a response on 02885 * error, or when all events are set */ 02886 02887 if (res > 0) { 02888 for (x = 0; x < ARRAY_LEN(perms); x++) { 02889 if (!strcasecmp(perms[x].label, "all") && res == perms[x].num) { 02890 return 0; 02891 } 02892 } 02893 astman_append(s, "Response: Success\r\n" 02894 "Events: On\r\n\r\n"); 02895 } else if (res == 0) 02896 astman_append(s, "Response: Success\r\n" 02897 "Events: Off\r\n\r\n"); 02898 return 0; 02899 } 02900 02901 if (res > 0) 02902 astman_append(s, "Response: Success\r\n" 02903 "Events: On\r\n\r\n"); 02904 else if (res == 0) 02905 astman_append(s, "Response: Success\r\n" 02906 "Events: Off\r\n\r\n"); 02907 else 02908 astman_send_error(s, m, "Invalid event mask"); 02909 02910 return 0; 02911 }
| static int action_extensionstate | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 3986 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().
03987 { 03988 const char *exten = astman_get_header(m, "Exten"); 03989 const char *context = astman_get_header(m, "Context"); 03990 char hint[256] = ""; 03991 int status; 03992 if (ast_strlen_zero(exten)) { 03993 astman_send_error(s, m, "Extension not specified"); 03994 return 0; 03995 } 03996 if (ast_strlen_zero(context)) { 03997 context = "default"; 03998 } 03999 status = ast_extension_state(NULL, context, exten); 04000 ast_get_hint(hint, sizeof(hint) - 1, NULL, 0, NULL, context, exten); 04001 astman_start_ack(s, m); 04002 astman_append(s, "Message: Extension Status\r\n" 04003 "Exten: %s\r\n" 04004 "Context: %s\r\n" 04005 "Hint: %s\r\n" 04006 "Status: %d\r\n\r\n", 04007 exten, context, hint, status); 04008 return 0; 04009 }
| static int action_getconfig | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2348 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().
02349 { 02350 struct ast_config *cfg; 02351 const char *fn = astman_get_header(m, "Filename"); 02352 const char *category = astman_get_header(m, "Category"); 02353 int catcount = 0; 02354 int lineno = 0; 02355 char *cur_category = NULL; 02356 struct ast_variable *v; 02357 struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE }; 02358 02359 if (ast_strlen_zero(fn)) { 02360 astman_send_error(s, m, "Filename not specified"); 02361 return 0; 02362 } 02363 cfg = ast_config_load2(fn, "manager", config_flags); 02364 if (cfg == CONFIG_STATUS_FILEMISSING) { 02365 astman_send_error(s, m, "Config file not found"); 02366 return 0; 02367 } else if (cfg == CONFIG_STATUS_FILEINVALID) { 02368 astman_send_error(s, m, "Config file has invalid format"); 02369 return 0; 02370 } 02371 02372 astman_start_ack(s, m); 02373 while ((cur_category = ast_category_browse(cfg, cur_category))) { 02374 if (ast_strlen_zero(category) || (!ast_strlen_zero(category) && !strcmp(category, cur_category))) { 02375 lineno = 0; 02376 astman_append(s, "Category-%06d: %s\r\n", catcount, cur_category); 02377 for (v = ast_variable_browse(cfg, cur_category); v; v = v->next) { 02378 astman_append(s, "Line-%06d-%06d: %s=%s\r\n", catcount, lineno++, v->name, v->value); 02379 } 02380 catcount++; 02381 } 02382 } 02383 if (!ast_strlen_zero(category) && catcount == 0) { /* TODO: actually, a config with no categories doesn't even get loaded */ 02384 astman_append(s, "No categories found\r\n"); 02385 } 02386 ast_config_destroy(cfg); 02387 astman_append(s, "\r\n"); 02388 02389 return 0; 02390 }
| static int action_getconfigjson | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2440 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, json_escape(), ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by __init_manager().
02441 { 02442 struct ast_config *cfg; 02443 const char *fn = astman_get_header(m, "Filename"); 02444 char *category = NULL; 02445 struct ast_variable *v; 02446 int comma1 = 0; 02447 char *buf = NULL; 02448 unsigned int buf_len = 0; 02449 struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE }; 02450 02451 if (ast_strlen_zero(fn)) { 02452 astman_send_error(s, m, "Filename not specified"); 02453 return 0; 02454 } 02455 02456 if (!(cfg = ast_config_load2(fn, "manager", config_flags))) { 02457 astman_send_error(s, m, "Config file not found"); 02458 return 0; 02459 } else if (cfg == CONFIG_STATUS_FILEINVALID) { 02460 astman_send_error(s, m, "Config file has invalid format"); 02461 return 0; 02462 } 02463 02464 buf_len = 512; 02465 buf = alloca(buf_len); 02466 02467 astman_start_ack(s, m); 02468 astman_append(s, "JSON: {"); 02469 while ((category = ast_category_browse(cfg, category))) { 02470 int comma2 = 0; 02471 if (buf_len < 2 * strlen(category) + 1) { 02472 buf_len *= 2; 02473 buf = alloca(buf_len); 02474 } 02475 json_escape(buf, category); 02476 astman_append(s, "%s\"%s\":[", comma1 ? "," : "", buf); 02477 if (!comma1) { 02478 comma1 = 1; 02479 } 02480 for (v = ast_variable_browse(cfg, category); v; v = v->next) { 02481 if (comma2) { 02482 astman_append(s, ","); 02483 } 02484 if (buf_len < 2 * strlen(v->name) + 1) { 02485 buf_len *= 2; 02486 buf = alloca(buf_len); 02487 } 02488 json_escape(buf, v->name); 02489 astman_append(s, "\"%s", buf); 02490 if (buf_len < 2 * strlen(v->value) + 1) { 02491 buf_len *= 2; 02492 buf = alloca(buf_len); 02493 } 02494 json_escape(buf, v->value); 02495 astman_append(s, "%s\"", buf); 02496 if (!comma2) { 02497 comma2 = 1; 02498 } 02499 } 02500 astman_append(s, "]"); 02501 } 02502 astman_append(s, "}\r\n\r\n"); 02503 02504 ast_config_destroy(cfg); 02505 02506 return 0; 02507 }
| static int action_getvar | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 3038 of file manager.c.
References ast_channel_get_by_name(), ast_channel_release(), ast_channel_unref, ast_dummy_channel_alloc(), ast_func_read(), ast_log(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), astman_start_ack(), LOG_ERROR, pbx_retrieve_variable(), and S_OR.
Referenced by __init_manager().
03039 { 03040 struct ast_channel *c = NULL; 03041 const char *name = astman_get_header(m, "Channel"); 03042 const char *varname = astman_get_header(m, "Variable"); 03043 char *varval; 03044 char workspace[1024] = ""; 03045 03046 if (ast_strlen_zero(varname)) { 03047 astman_send_error(s, m, "No variable specified"); 03048 return 0; 03049 } 03050 03051 if (!ast_strlen_zero(name)) { 03052 if (!(c = ast_channel_get_by_name(name))) { 03053 astman_send_error(s, m, "No such channel"); 03054 return 0; 03055 } 03056 } 03057 03058 if (varname[strlen(varname) - 1] == ')') { 03059 if (!c) { 03060 c = ast_dummy_channel_alloc(); 03061 if (c) { 03062 ast_func_read(c, (char *) varname, workspace, sizeof(workspace)); 03063 c = ast_channel_release(c); 03064 } else 03065 ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution. Function results may be blank.\n"); 03066 } else { 03067 ast_func_read(c, (char *) varname, workspace, sizeof(workspace)); 03068 } 03069 varval = workspace; 03070 } else { 03071 pbx_retrieve_variable(c, varname, &varval, workspace, sizeof(workspace), NULL); 03072 } 03073 03074 if (c) { 03075 c = ast_channel_unref(c); 03076 } 03077 03078 astman_start_ack(s, m); 03079 astman_append(s, "Variable: %s\r\nValue: %s\r\n\r\n", varname, S_OR(varval, "")); 03080 03081 return 0; 03082 }
| static int action_hangup | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2962 of file manager.c.
References ast_channel_get_by_name(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, ast_debug, ast_log(), AST_SOFTHANGUP_EXPLICIT, ast_softhangup_nolock(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), cause, ast_channel::hangupcause, LOG_NOTICE, and ast_channel::name.
Referenced by __init_manager().
02963 { 02964 struct ast_channel *c = NULL; 02965 int causecode = 0; /* all values <= 0 mean 'do not set hangupcause in channel' */ 02966 const char *name = astman_get_header(m, "Channel"); 02967 const char *cause = astman_get_header(m, "Cause"); 02968 02969 if (ast_strlen_zero(name)) { 02970 astman_send_error(s, m, "No channel specified"); 02971 return 0; 02972 } 02973 02974 if (!ast_strlen_zero(cause)) { 02975 char *endptr; 02976 causecode = strtol(cause, &endptr, 10); 02977 if (causecode < 0 || causecode > 127 || *endptr != '\0') { 02978 ast_log(LOG_NOTICE, "Invalid 'Cause: %s' in manager action Hangup\n", cause); 02979 /* keep going, better to hangup without cause than to not hang up at all */ 02980 causecode = 0; /* do not set channel's hangupcause */ 02981 } 02982 } 02983 02984 if (!(c = ast_channel_get_by_name(name))) { 02985 astman_send_error(s, m, "No such channel"); 02986 return 0; 02987 } 02988 02989 ast_channel_lock(c); 02990 if (causecode > 0) { 02991 ast_debug(1, "Setting hangupcause of channel %s to %d (is %d now)\n", 02992 c->name, causecode, c->hangupcause); 02993 c->hangupcause = causecode; 02994 } 02995 ast_softhangup_nolock(c, AST_SOFTHANGUP_EXPLICIT); 02996 ast_channel_unlock(c); 02997 02998 c = ast_channel_unref(c); 02999 03000 astman_send_ack(s, m, "Channel Hungup"); 03001 03002 return 0; 03003 }
| static int action_listcategories | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2392 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().
02393 { 02394 struct ast_config *cfg; 02395 const char *fn = astman_get_header(m, "Filename"); 02396 char *category = NULL; 02397 struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE }; 02398 int catcount = 0; 02399 02400 if (ast_strlen_zero(fn)) { 02401 astman_send_error(s, m, "Filename not specified"); 02402 return 0; 02403 } 02404 if (!(cfg = ast_config_load2(fn, "manager", config_flags))) { 02405 astman_send_error(s, m, "Config file not found"); 02406 return 0; 02407 } else if (cfg == CONFIG_STATUS_FILEINVALID) { 02408 astman_send_error(s, m, "Config file has invalid format"); 02409 return 0; 02410 } 02411 astman_start_ack(s, m); 02412 while ((category = ast_category_browse(cfg, category))) { 02413 astman_append(s, "Category-%06d: %s\r\n", catcount, category); 02414 catcount++; 02415 } 02416 if (catcount == 0) { /* TODO: actually, a config with no categories doesn't even get loaded */ 02417 astman_append(s, "Error: no categories found\r\n"); 02418 } 02419 ast_config_destroy(cfg); 02420 astman_append(s, "\r\n"); 02421 02422 return 0; 02423 }
| static int action_listcommands | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2860 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, and mansession_session::writeperm.
Referenced by __init_manager().
02861 { 02862 struct manager_action *cur; 02863 struct ast_str *temp = ast_str_alloca(BUFSIZ); /* XXX very large ? */ 02864 02865 astman_start_ack(s, m); 02866 AST_RWLIST_TRAVERSE(&actions, cur, list) { 02867 if (s->session->writeperm & cur->authority || cur->authority == 0) { 02868 astman_append(s, "%s: %s (Priv: %s)\r\n", 02869 cur->action, cur->synopsis, authority_to_str(cur->authority, &temp)); 02870 } 02871 } 02872 astman_append(s, "\r\n"); 02873 02874 return 0; 02875 }
| static int action_login | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2919 of file manager.c.
References ast_inet_ntoa(), AST_OPT_FLAG_FULLY_BOOTED, ast_options, ast_test_flag, ast_verb, astman_send_ack(), astman_send_error(), authenticate(), mansession_session::authenticated, EVENT_FLAG_SYSTEM, manager_displayconnects(), manager_event, mansession_session::managerid, mansession::session, mansession_session::sin, and mansession_session::username.
Referenced by __init_manager().
02920 { 02921 02922 /* still authenticated - don't process again */ 02923 if (s->session->authenticated) { 02924 astman_send_ack(s, m, "Already authenticated"); 02925 return 0; 02926 } 02927 02928 if (authenticate(s, m)) { 02929 sleep(1); 02930 astman_send_error(s, m, "Authentication failed"); 02931 return -1; 02932 } 02933 s->session->authenticated = 1; 02934 if (manager_displayconnects(s->session)) { 02935 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)); 02936 } 02937 astman_send_ack(s, m, "Authentication accepted"); 02938 if (ast_test_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED)) { 02939 manager_event(EVENT_FLAG_SYSTEM, "FullyBooted", "Status: Fully Booted\r\n"); 02940 } 02941 return 0; 02942 }
| static int action_logoff | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2913 of file manager.c.
References astman_send_response().
Referenced by __init_manager().
02914 { 02915 astman_send_response(s, m, "Goodbye", "Thanks for all the fish."); 02916 return -1; 02917 }
| static int action_mailboxcount | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 3965 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().
03966 { 03967 const char *mailbox = astman_get_header(m, "Mailbox"); 03968 int newmsgs = 0, oldmsgs = 0, urgentmsgs = 0;; 03969 03970 if (ast_strlen_zero(mailbox)) { 03971 astman_send_error(s, m, "Mailbox not specified"); 03972 return 0; 03973 } 03974 ast_app_inboxcount2(mailbox, &urgentmsgs, &newmsgs, &oldmsgs); 03975 astman_start_ack(s, m); 03976 astman_append(s, "Message: Mailbox Message Count\r\n" 03977 "Mailbox: %s\r\n" 03978 "UrgMessages: %d\r\n" 03979 "NewMessages: %d\r\n" 03980 "OldMessages: %d\r\n" 03981 "\r\n", 03982 mailbox, urgentmsgs, newmsgs, oldmsgs); 03983 return 0; 03984 }
| static int action_mailboxstatus | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 3948 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().
03949 { 03950 const char *mailbox = astman_get_header(m, "Mailbox"); 03951 int ret; 03952 03953 if (ast_strlen_zero(mailbox)) { 03954 astman_send_error(s, m, "Mailbox not specified"); 03955 return 0; 03956 } 03957 ret = ast_app_has_voicemail(mailbox, NULL); 03958 astman_start_ack(s, m); 03959 astman_append(s, "Message: Mailbox Status\r\n" 03960 "Mailbox: %s\r\n" 03961 "Waiting: %d\r\n\r\n", mailbox, ret); 03962 return 0; 03963 }
| static int action_originate | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 3813 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, 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().
03814 { 03815 const char *name = astman_get_header(m, "Channel"); 03816 const char *exten = astman_get_header(m, "Exten"); 03817 const char *context = astman_get_header(m, "Context"); 03818 const char *priority = astman_get_header(m, "Priority"); 03819 const char *timeout = astman_get_header(m, "Timeout"); 03820 const char *callerid = astman_get_header(m, "CallerID"); 03821 const char *account = astman_get_header(m, "Account"); 03822 const char *app = astman_get_header(m, "Application"); 03823 const char *appdata = astman_get_header(m, "Data"); 03824 const char *async = astman_get_header(m, "Async"); 03825 const char *id = astman_get_header(m, "ActionID"); 03826 const char *codecs = astman_get_header(m, "Codecs"); 03827 struct ast_variable *vars; 03828 char *tech, *data; 03829 char *l = NULL, *n = NULL; 03830 int pi = 0; 03831 int res; 03832 int to = 30000; 03833 int reason = 0; 03834 char tmp[256]; 03835 char tmp2[256]; 03836 format_t format = AST_FORMAT_SLINEAR; 03837 03838 pthread_t th; 03839 if (ast_strlen_zero(name)) { 03840 astman_send_error(s, m, "Channel not specified"); 03841 return 0; 03842 } 03843 if (!ast_strlen_zero(priority) && (sscanf(priority, "%30d", &pi) != 1)) { 03844 if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) { 03845 astman_send_error(s, m, "Invalid priority"); 03846 return 0; 03847 } 03848 } 03849 if (!ast_strlen_zero(timeout) && (sscanf(timeout, "%30d", &to) != 1)) { 03850 astman_send_error(s, m, "Invalid timeout"); 03851 return 0; 03852 } 03853 ast_copy_string(tmp, name, sizeof(tmp)); 03854 tech = tmp; 03855 data = strchr(tmp, '/'); 03856 if (!data) { 03857 astman_send_error(s, m, "Invalid channel"); 03858 return 0; 03859 } 03860 *data++ = '\0'; 03861 ast_copy_string(tmp2, callerid, sizeof(tmp2)); 03862 ast_callerid_parse(tmp2, &n, &l); 03863 if (n) { 03864 if (ast_strlen_zero(n)) { 03865 n = NULL; 03866 } 03867 } 03868 if (l) { 03869 ast_shrink_phone_number(l); 03870 if (ast_strlen_zero(l)) { 03871 l = NULL; 03872 } 03873 } 03874 if (!ast_strlen_zero(codecs)) { 03875 format = 0; 03876 ast_parse_allow_disallow(NULL, &format, codecs, 1); 03877 } 03878 /* Allocate requested channel variables */ 03879 vars = astman_get_variables(m); 03880 03881 if (ast_true(async)) { 03882 struct fast_originate_helper *fast = ast_calloc(1, sizeof(*fast)); 03883 if (!fast) { 03884 res = -1; 03885 } else { 03886 if (!ast_strlen_zero(id)) 03887 snprintf(fast->idtext, sizeof(fast->idtext), "ActionID: %s", id); 03888 ast_copy_string(fast->tech, tech, sizeof(fast->tech)); 03889 ast_copy_string(fast->data, data, sizeof(fast->data)); 03890 ast_copy_string(fast->app, app, sizeof(fast->app)); 03891 ast_copy_string(fast->appdata, appdata, sizeof(fast->appdata)); 03892 if (l) { 03893 ast_copy_string(fast->cid_num, l, sizeof(fast->cid_num)); 03894 } 03895 if (n) { 03896 ast_copy_string(fast->cid_name, n, sizeof(fast->cid_name)); 03897 } 03898 fast->vars = vars; 03899 ast_copy_string(fast->context, context, sizeof(fast->context)); 03900 ast_copy_string(fast->exten, exten, sizeof(fast->exten)); 03901 ast_copy_string(fast->account, account, sizeof(fast->account)); 03902 fast->format = format; 03903 fast->timeout = to; 03904 fast->priority = pi; 03905 if (ast_pthread_create_detached(&th, NULL, fast_originate, fast)) { 03906 ast_free(fast); 03907 res = -1; 03908 } else { 03909 res = 0; 03910 } 03911 } 03912 } else if (!ast_strlen_zero(app)) { 03913 /* To run the System application (or anything else that goes to shell), you must have the additional System privilege */ 03914 if (!(s->session->writeperm & EVENT_FLAG_SYSTEM) 03915 && ( 03916 strcasestr(app, "system") || /* System(rm -rf /) 03917 TrySystem(rm -rf /) */ 03918 strcasestr(app, "exec") || /* Exec(System(rm -rf /)) 03919 TryExec(System(rm -rf /)) */ 03920 strcasestr(app, "agi") || /* AGI(/bin/rm,-rf /) 03921 EAGI(/bin/rm,-rf /) */ 03922 strstr(appdata, "SHELL") || /* NoOp(${SHELL(rm -rf /)}) */ 03923 strstr(appdata, "EVAL") /* NoOp(${EVAL(${some_var_containing_SHELL})}) */ 03924 )) { 03925 astman_send_error(s, m, "Originate with certain 'Application' arguments requires the additional System privilege, which you do not have."); 03926 return 0; 03927 } 03928 res = ast_pbx_outgoing_app(tech, format, data, to, app, appdata, &reason, 1, l, n, vars, account, NULL); 03929 } else { 03930 if (exten && context && pi) { 03931 res = ast_pbx_outgoing_exten(tech, format, data, to, context, exten, pi, &reason, 1, l, n, vars, account, NULL); 03932 } else { 03933 astman_send_error(s, m, "Originate with 'Exten' requires 'Context' and 'Priority'"); 03934 if (vars) { 03935 ast_variables_destroy(vars); 03936 } 03937 return 0; 03938 } 03939 } 03940 if (!res) { 03941 astman_send_ack(s, m, "Originate successfully queued"); 03942 } else { 03943 astman_send_error(s, m, "Originate failed"); 03944 } 03945 return 0; 03946 }
| static int action_ping | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2330 of file manager.c.
References ast_strlen_zero(), ast_tvnow(), astman_append(), and astman_get_header().
Referenced by __init_manager().
02331 { 02332 const char *actionid = astman_get_header(m, "ActionID"); 02333 struct timeval now = ast_tvnow(); 02334 02335 astman_append(s, "Response: Success\r\n"); 02336 if (!ast_strlen_zero(actionid)){ 02337 astman_append(s, "ActionID: %s\r\n", actionid); 02338 } 02339 astman_append( 02340 s, 02341 "Ping: Pong\r\n" 02342 "Timestamp: %ld.%06lu\r\n" 02343 "\r\n", 02344 (long) now.tv_sec, (unsigned long) now.tv_usec); 02345 return 0; 02346 }
| static int action_redirect | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
action_redirect: The redirect manager command
Definition at line 3272 of file manager.c.
References ast_async_goto(), ast_channel_get_by_name(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, ast_check_hangup_locked(), ast_findlabel_extension(), AST_FLAG_BRIDGE_HANGUP_DONT, ast_set_flag, ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), context, exten, ast_channel::pbx, and ast_channel::priority.
Referenced by __init_manager().
03273 { 03274 const char *name = astman_get_header(m, "Channel"); 03275 const char *name2 = astman_get_header(m, "ExtraChannel"); 03276 const char *exten = astman_get_header(m, "Exten"); 03277 const char *exten2 = astman_get_header(m, "ExtraExten"); 03278 const char *context = astman_get_header(m, "Context"); 03279 const char *context2 = astman_get_header(m, "ExtraContext"); 03280 const char *priority = astman_get_header(m, "Priority"); 03281 const char *priority2 = astman_get_header(m, "ExtraPriority"); 03282 struct ast_channel *chan, *chan2 = NULL; 03283 int pi, pi2 = 0; 03284 int res; 03285 03286 if (ast_strlen_zero(name)) { 03287 astman_send_error(s, m, "Channel not specified"); 03288 return 0; 03289 } 03290 03291 if (!ast_strlen_zero(priority) && (sscanf(priority, "%30d", &pi) != 1)) { 03292 if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) { 03293 astman_send_error(s, m, "Invalid priority"); 03294 return 0; 03295 } 03296 } 03297 03298 if (!ast_strlen_zero(priority2) && (sscanf(priority2, "%30d", &pi2) != 1)) { 03299 if ((pi2 = ast_findlabel_extension(NULL, context2, exten2, priority2, NULL)) < 1) { 03300 astman_send_error(s, m, "Invalid ExtraPriority"); 03301 return 0; 03302 } 03303 } 03304 03305 if (!(chan = ast_channel_get_by_name(name))) { 03306 char buf[256]; 03307 snprintf(buf, sizeof(buf), "Channel does not exist: %s", name); 03308 astman_send_error(s, m, buf); 03309 return 0; 03310 } 03311 03312 if (ast_check_hangup_locked(chan)) { 03313 astman_send_error(s, m, "Redirect failed, channel not up."); 03314 chan = ast_channel_unref(chan); 03315 return 0; 03316 } 03317 03318 if (!ast_strlen_zero(name2)) { 03319 chan2 = ast_channel_get_by_name(name2); 03320 } 03321 03322 if (chan2 && ast_check_hangup_locked(chan2)) { 03323 astman_send_error(s, m, "Redirect failed, extra channel not up."); 03324 chan = ast_channel_unref(chan); 03325 chan2 = ast_channel_unref(chan2); 03326 return 0; 03327 } 03328 03329 if (chan->pbx) { 03330 ast_channel_lock(chan); 03331 ast_set_flag(chan, AST_FLAG_BRIDGE_HANGUP_DONT); /* don't let the after-bridge code run the h-exten */ 03332 ast_channel_unlock(chan); 03333 } 03334 03335 res = ast_async_goto(chan, context, exten, pi); 03336 if (!res) { 03337 if (!ast_strlen_zero(name2)) { 03338 if (chan2) { 03339 if (chan2->pbx) { 03340 ast_channel_lock(chan2); 03341 ast_set_flag(chan2, AST_FLAG_BRIDGE_HANGUP_DONT); /* don't let the after-bridge code run the h-exten */ 03342 ast_channel_unlock(chan2); 03343 } 03344 if (context2) { 03345 res = ast_async_goto(chan2, context2, exten2, pi2); 03346 } else { 03347 res = ast_async_goto(chan2, context, exten, pi); 03348 } 03349 } else { 03350 res = -1; 03351 } 03352 if (!res) { 03353 astman_send_ack(s, m, "Dual Redirect successful"); 03354 } else { 03355 astman_send_error(s, m, "Secondary redirect failed"); 03356 } 03357 } else { 03358 astman_send_ack(s, m, "Redirect successful"); 03359 } 03360 } else { 03361 astman_send_error(s, m, "Redirect failed"); 03362 } 03363 03364 if (chan) { 03365 chan = ast_channel_unref(chan); 03366 } 03367 03368 if (chan2) { 03369 chan2 = ast_channel_unref(chan2); 03370 } 03371 03372 return 0; 03373 }
| static int action_reload | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Send a reload event.
Definition at line 4230 of file manager.c.
References ast_module_reload(), astman_get_header(), astman_send_ack(), astman_send_error(), and S_OR.
Referenced by __init_manager().
04231 { 04232 const char *module = astman_get_header(m, "Module"); 04233 int res = ast_module_reload(S_OR(module, NULL)); 04234 04235 if (res == 2) { 04236 astman_send_ack(s, m, "Module Reloaded"); 04237 } else { 04238 astman_send_error(s, m, s == 0 ? "No such module" : "Module does not support reload"); 04239 } 04240 return 0; 04241 }
| static int action_sendtext | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 3235 of file manager.c.
References ast_channel_get_by_name(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, ast_sendtext(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), and astman_send_error().
Referenced by __init_manager().
03236 { 03237 struct ast_channel *c = NULL; 03238 const char *name = astman_get_header(m, "Channel"); 03239 const char *textmsg = astman_get_header(m, "Message"); 03240 int res = 0; 03241 03242 if (ast_strlen_zero(name)) { 03243 astman_send_error(s, m, "No channel specified"); 03244 return 0; 03245 } 03246 03247 if (ast_strlen_zero(textmsg)) { 03248 astman_send_error(s, m, "No Message specified"); 03249 return 0; 03250 } 03251 03252 if (!(c = ast_channel_get_by_name(name))) { 03253 astman_send_error(s, m, "No such channel"); 03254 return 0; 03255 } 03256 03257 ast_channel_lock(c); 03258 res = ast_sendtext(c, textmsg); 03259 ast_channel_unlock(c); 03260 c = ast_channel_unref(c); 03261 03262 if (res > 0) { 03263 astman_send_ack(s, m, "Success"); 03264 } else { 03265 astman_send_error(s, m, "Failure"); 03266 } 03267 03268 return res; 03269 }
| static int action_setvar | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 3005 of file manager.c.
References ast_channel_get_by_name(), ast_channel_unref, ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), pbx_builtin_setvar_helper(), and S_OR.
Referenced by __init_manager().
03006 { 03007 struct ast_channel *c = NULL; 03008 const char *name = astman_get_header(m, "Channel"); 03009 const char *varname = astman_get_header(m, "Variable"); 03010 const char *varval = astman_get_header(m, "Value"); 03011 int res = 0; 03012 03013 if (ast_strlen_zero(varname)) { 03014 astman_send_error(s, m, "No variable specified"); 03015 return 0; 03016 } 03017 03018 if (!ast_strlen_zero(name)) { 03019 if (!(c = ast_channel_get_by_name(name))) { 03020 astman_send_error(s, m, "No such channel"); 03021 return 0; 03022 } 03023 } 03024 03025 res = pbx_builtin_setvar_helper(c, varname, S_OR(varval, "")); 03026 03027 if (c) { 03028 c = ast_channel_unref(c); 03029 } 03030 if (res == 0) { 03031 astman_send_ack(s, m, "Variable Set"); 03032 } else { 03033 astman_send_error(s, m, "Variable not set"); 03034 } 03035 return 0; 03036 }
| static int action_status | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Manager "status" command to show channels.
Definition at line 3086 of file manager.c.
References ast_channel::_bridge, ast_channel::_state, ast_channel::accountcode, AST_APP_ARG, ast_channel_get_by_name(), ast_channel_iterator_all_new(), ast_channel_iterator_destroy(), ast_channel_iterator_next(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, AST_DECLARE_APP_ARGS, ast_free, ast_func_read(), 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::caller, ast_channel::cdr, channels, ast_channel::context, ast_channel::exten, ast_party_caller::id, ast_party_id::name, ast_channel::name, ast_party_id::number, ast_channel::pbx, pbx_retrieve_variable(), ast_channel::priority, S_COR, S_OR, ast_cdr::start, ast_party_name::str, ast_party_number::str, str, ast_channel::uniqueid, ast_party_name::valid, and ast_party_number::valid.
Referenced by __init_manager().
03087 { 03088 const char *name = astman_get_header(m, "Channel"); 03089 const char *cvariables = astman_get_header(m, "Variables"); 03090 char *variables = ast_strdupa(S_OR(cvariables, "")); 03091 struct ast_channel *c; 03092 char bridge[256]; 03093 struct timeval now = ast_tvnow(); 03094 long elapsed_seconds = 0; 03095 int channels = 0; 03096 int all = ast_strlen_zero(name); /* set if we want all channels */ 03097 const char *id = astman_get_header(m, "ActionID"); 03098 char idText[256]; 03099 AST_DECLARE_APP_ARGS(vars, 03100 AST_APP_ARG(name)[100]; 03101 ); 03102 struct ast_str *str = ast_str_create(1000); 03103 struct ast_channel_iterator *iter = NULL; 03104 03105 if (!ast_strlen_zero(id)) { 03106 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id); 03107 } else { 03108 idText[0] = '\0'; 03109 } 03110 03111 if (all) { 03112 if (!(iter = ast_channel_iterator_all_new())) { 03113 ast_free(str); 03114 astman_send_error(s, m, "Memory Allocation Failure"); 03115 return 1; 03116 } 03117 c = ast_channel_iterator_next(iter); 03118 } else { 03119 if (!(c = ast_channel_get_by_name(name))) { 03120 astman_send_error(s, m, "No such channel"); 03121 ast_free(str); 03122 return 0; 03123 } 03124 } 03125 03126 astman_send_ack(s, m, "Channel status will follow"); 03127 03128 if (!ast_strlen_zero(cvariables)) { 03129 AST_STANDARD_APP_ARGS(vars, variables); 03130 } 03131 03132 /* if we look by name, we break after the first iteration */ 03133 for (; c; c = ast_channel_iterator_next(iter)) { 03134 ast_channel_lock(c); 03135 03136 if (!ast_strlen_zero(cvariables)) { 03137 int i; 03138 ast_str_reset(str); 03139 for (i = 0; i < vars.argc; i++) { 03140 char valbuf[512], *ret = NULL; 03141 03142 if (vars.name[i][strlen(vars.name[i]) - 1] == ')') { 03143 if (ast_func_read(c, vars.name[i], valbuf, sizeof(valbuf)) < 0) { 03144 valbuf[0] = '\0'; 03145 } 03146 ret = valbuf; 03147 } else { 03148 pbx_retrieve_variable(c, vars.name[i], &ret, valbuf, sizeof(valbuf), NULL); 03149 } 03150 03151 ast_str_append(&str, 0, "Variable: %s=%s\r\n", vars.name[i], ret); 03152 } 03153 } 03154 03155 channels++; 03156 if (c->_bridge) { 03157 snprintf(bridge, sizeof(bridge), "BridgedChannel: %s\r\nBridgedUniqueid: %s\r\n", c->_bridge->name, c->_bridge->uniqueid); 03158 } else { 03159 bridge[0] = '\0'; 03160 } 03161 if (c->pbx) { 03162 if (c->cdr) { 03163 elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec; 03164 } 03165 astman_append(s, 03166 "Event: Status\r\n" 03167 "Privilege: Call\r\n" 03168 "Channel: %s\r\n" 03169 "CallerIDNum: %s\r\n" 03170 "CallerIDName: %s\r\n" 03171 "Accountcode: %s\r\n" 03172 "ChannelState: %d\r\n" 03173 "ChannelStateDesc: %s\r\n" 03174 "Context: %s\r\n" 03175 "Extension: %s\r\n" 03176 "Priority: %d\r\n" 03177 "Seconds: %ld\r\n" 03178 "%s" 03179 "Uniqueid: %s\r\n" 03180 "%s" 03181 "%s" 03182 "\r\n", 03183 c->name, 03184 S_COR(c->caller.id.number.valid, c->caller.id.number.str, ""), 03185 S_COR(c->caller.id.name.valid, c->caller.id.name.str, ""), 03186 c->accountcode, 03187 c->_state, 03188 ast_state2str(c->_state), c->context, 03189 c->exten, c->priority, (long)elapsed_seconds, bridge, c->uniqueid, ast_str_buffer(str), idText); 03190 } else { 03191 astman_append(s, 03192 "Event: Status\r\n" 03193 "Privilege: Call\r\n" 03194 "Channel: %s\r\n" 03195 "CallerIDNum: %s\r\n" 03196 "CallerIDName: %s\r\n" 03197 "Account: %s\r\n" 03198 "State: %s\r\n" 03199 "%s" 03200 "Uniqueid: %s\r\n" 03201 "%s" 03202 "%s" 03203 "\r\n", 03204 c->name, 03205 S_COR(c->caller.id.number.valid, c->caller.id.number.str, "<unknown>"), 03206 S_COR(c->caller.id.name.valid, c->caller.id.name.str, "<unknown>"), 03207 c->accountcode, 03208 ast_state2str(c->_state), bridge, c->uniqueid, 03209 ast_str_buffer(str), idText); 03210 } 03211 03212 ast_channel_unlock(c); 03213 c = ast_channel_unref(c); 03214 03215 if (!all) { 03216 break; 03217 } 03218 } 03219 03220 if (iter) { 03221 ast_channel_iterator_destroy(iter); 03222 } 03223 03224 astman_append(s, 03225 "Event: StatusComplete\r\n" 03226 "%s" 03227 "Items: %d\r\n" 03228 "\r\n", idText, channels); 03229 03230 ast_free(str); 03231 03232 return 0; 03233 }
| static int action_timeout | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 4011 of file manager.c.
References ast_channel_get_by_name(), ast_channel_lock, ast_channel_setwhentohangup_tv(), ast_channel_unlock, ast_channel_unref, ast_strlen_zero(), astman_get_header(), astman_send_ack(), and astman_send_error().
Referenced by __init_manager().
04012 { 04013 struct ast_channel *c; 04014 const char *name = astman_get_header(m, "Channel"); 04015 double timeout = atof(astman_get_header(m, "Timeout")); 04016 struct timeval when = { timeout, 0 }; 04017 04018 if (ast_strlen_zero(name)) { 04019 astman_send_error(s, m, "No channel specified"); 04020 return 0; 04021 } 04022 04023 if (!timeout || timeout < 0) { 04024 astman_send_error(s, m, "No timeout specified"); 04025 return 0; 04026 } 04027 04028 if (!(c = ast_channel_get_by_name(name))) { 04029 astman_send_error(s, m, "No such channel"); 04030 return 0; 04031 } 04032 04033 when.tv_usec = (timeout - when.tv_sec) * 1000000.0; 04034 04035 ast_channel_lock(c); 04036 ast_channel_setwhentohangup_tv(c, when); 04037 ast_channel_unlock(c); 04038 c = ast_channel_unref(c); 04039 04040 astman_send_ack(s, m, "Timeout Set"); 04041 04042 return 0; 04043 }
| static int action_updateconfig | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2655 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().
02656 { 02657 struct ast_config *cfg; 02658 const char *sfn = astman_get_header(m, "SrcFilename"); 02659 const char *dfn = astman_get_header(m, "DstFilename"); 02660 int res; 02661 const char *rld = astman_get_header(m, "Reload"); 02662 struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE }; 02663 enum error_type result; 02664 02665 if (ast_strlen_zero(sfn) || ast_strlen_zero(dfn)) { 02666 astman_send_error(s, m, "Filename not specified"); 02667 return 0; 02668 } 02669 if (!(cfg = ast_config_load2(sfn, "manager", config_flags))) { 02670 astman_send_error(s, m, "Config file not found"); 02671 return 0; 02672 } else if (cfg == CONFIG_STATUS_FILEINVALID) { 02673 astman_send_error(s, m, "Config file has invalid format"); 02674 return 0; 02675 } 02676 result = handle_updates(s, m, cfg, dfn); 02677 if (!result) { 02678 ast_include_rename(cfg, sfn, dfn); /* change the include references from dfn to sfn, so things match up */ 02679 res = ast_config_text_file_save(dfn, cfg, "Manager"); 02680 ast_config_destroy(cfg); 02681 if (res) { 02682 astman_send_error(s, m, "Save of config failed"); 02683 return 0; 02684 } 02685 astman_send_ack(s, m, NULL); 02686 if (!ast_strlen_zero(rld)) { 02687 if (ast_true(rld)) { 02688 rld = NULL; 02689 } 02690 ast_module_reload(rld); 02691 } 02692 } else { 02693 ast_config_destroy(cfg); 02694 switch(result) { 02695 case UNKNOWN_ACTION: 02696 astman_send_error(s, m, "Unknown action command"); 02697 break; 02698 case UNKNOWN_CATEGORY: 02699 astman_send_error(s, m, "Given category does not exist"); 02700 break; 02701 case UNSPECIFIED_CATEGORY: 02702 astman_send_error(s, m, "Category not specified"); 02703 break; 02704 case UNSPECIFIED_ARGUMENT: 02705 astman_send_error(s, m, "Problem with category, value, or line (if required)"); 02706 break; 02707 case FAILURE_ALLOCATION: 02708 astman_send_error(s, m, "Memory allocation failure, this should not happen"); 02709 break; 02710 case FAILURE_NEWCAT: 02711 astman_send_error(s, m, "Create category did not complete successfully"); 02712 break; 02713 case FAILURE_DELCAT: 02714 astman_send_error(s, m, "Delete category did not complete successfully"); 02715 break; 02716 case FAILURE_EMPTYCAT: 02717 astman_send_error(s, m, "Empty category did not complete successfully"); 02718 break; 02719 case FAILURE_UPDATE: 02720 astman_send_error(s, m, "Update did not complete successfully"); 02721 break; 02722 case FAILURE_DELETE: 02723 astman_send_error(s, m, "Delete did not complete successfully"); 02724 break; 02725 case FAILURE_APPEND: 02726 astman_send_error(s, m, "Append did not complete successfully"); 02727 break; 02728 } 02729 } 02730 return 0; 02731 }
| static int action_userevent | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 4128 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().
04129 { 04130 const char *event = astman_get_header(m, "UserEvent"); 04131 struct ast_str *body = ast_str_thread_get(&userevent_buf, 16); 04132 int x; 04133 04134 ast_str_reset(body); 04135 04136 for (x = 0; x < m->hdrcount; x++) { 04137 if (strncasecmp("UserEvent:", m->headers[x], strlen("UserEvent:"))) { 04138 ast_str_append(&body, 0, "%s\r\n", m->headers[x]); 04139 } 04140 } 04141 04142 astman_send_ack(s, m, "Event Sent"); 04143 manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", event, ast_str_buffer(body)); 04144 return 0; 04145 }
| static int action_waitevent | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2751 of file manager.c.
References advance_event(), ao2_lock, ao2_unlock, ast_debug, AST_PTHREADT_NULL, AST_RWLIST_NEXT, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, 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().
02752 { 02753 const char *timeouts = astman_get_header(m, "Timeout"); 02754 int timeout = -1; 02755 int x; 02756 int needexit = 0; 02757 const char *id = astman_get_header(m, "ActionID"); 02758 char idText[256]; 02759 02760 if (!ast_strlen_zero(id)) { 02761 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id); 02762 } else { 02763 idText[0] = '\0'; 02764 } 02765 02766 if (!ast_strlen_zero(timeouts)) { 02767 sscanf(timeouts, "%30i", &timeout); 02768 if (timeout < -1) { 02769 timeout = -1; 02770 } 02771 /* XXX maybe put an upper bound, or prevent the use of 0 ? */ 02772 } 02773 02774 ao2_lock(s->session); 02775 if (s->session->waiting_thread != AST_PTHREADT_NULL) { 02776 pthread_kill(s->session->waiting_thread, SIGURG); 02777 } 02778 02779 if (s->session->managerid) { /* AMI-over-HTTP session */ 02780 /* 02781 * Make sure the timeout is within the expire time of the session, 02782 * as the client will likely abort the request if it does not see 02783 * data coming after some amount of time. 02784 */ 02785 time_t now = time(NULL); 02786 int max = s->session->sessiontimeout - now - 10; 02787 02788 if (max < 0) { /* We are already late. Strange but possible. */ 02789 max = 0; 02790 } 02791 if (timeout < 0 || timeout > max) { 02792 timeout = max; 02793 } 02794 if (!s->session->send_events) { /* make sure we record events */ 02795 s->session->send_events = -1; 02796 } 02797 } 02798 ao2_unlock(s->session); 02799 02800 /* XXX should this go inside the lock ? */ 02801 s->session->waiting_thread = pthread_self(); /* let new events wake up this thread */ 02802 ast_debug(1, "Starting waiting for an event!\n"); 02803 02804 for (x = 0; x < timeout || timeout < 0; x++) { 02805 ao2_lock(s->session); 02806 if (AST_RWLIST_NEXT(s->session->last_ev, eq_next)) { 02807 needexit = 1; 02808 } 02809 /* We can have multiple HTTP session point to the same mansession entry. 02810 * The way we deal with it is not very nice: newcomers kick out the previous 02811 * HTTP session. XXX this needs to be improved. 02812 */ 02813 if (s->session->waiting_thread != pthread_self()) { 02814 needexit = 1; 02815 } 02816 if (s->session->needdestroy) { 02817 needexit = 1; 02818 } 02819 ao2_unlock(s->session); 02820 if (needexit) { 02821 break; 02822 } 02823 if (s->session->managerid == 0) { /* AMI session */ 02824 if (ast_wait_for_input(s->session->fd, 1000)) { 02825 break; 02826 } 02827 } else { /* HTTP session */ 02828 sleep(1); 02829 } 02830 } 02831 ast_debug(1, "Finished waiting for an event!\n"); 02832 02833 ao2_lock(s->session); 02834 if (s->session->waiting_thread == pthread_self()) { 02835 struct eventqent *eqe = s->session->last_ev; 02836 astman_send_response(s, m, "Success", "Waiting for Event completed."); 02837 AST_RWLIST_RDLOCK(&all_events); 02838 while ((eqe = advance_event(eqe))) { 02839 if (((s->session->readperm & eqe->category) == eqe->category) && 02840 ((s->session->send_events & eqe->category) == eqe->category)) { 02841 astman_append(s, "%s", eqe->eventdata); 02842 } 02843 s->session->last_ev = eqe; 02844 } 02845 AST_RWLIST_UNLOCK(&all_events); 02846 astman_append(s, 02847 "Event: WaitEventComplete\r\n" 02848 "%s" 02849 "\r\n", idText); 02850 s->session->waiting_thread = AST_PTHREADT_NULL; 02851 } else { 02852 ast_debug(1, "Abandoning event request!\n"); 02853 } 02854 ao2_unlock(s->session); 02855 02856 return 0; 02857 }
Definition at line 1682 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().
01683 { 01684 struct eventqent *next; 01685 01686 AST_RWLIST_RDLOCK(&all_events); 01687 if ((next = AST_RWLIST_NEXT(e, eq_next))) { 01688 ast_atomic_fetchadd_int(&next->usecount, 1); 01689 ast_atomic_fetchadd_int(&e->usecount, -1); 01690 } 01691 AST_RWLIST_UNLOCK(&all_events); 01692 return next; 01693 }
| static int aocmessage_get_unit_entry | ( | const struct message * | m, | |
| struct ast_aoc_unit_entry * | entry, | |||
| unsigned int | entry_num | |||
| ) | [static] |
Definition at line 3583 of file manager.c.
References ast_aoc_unit_entry::amount, ast_str_alloca, ast_str_buffer(), ast_str_set(), ast_strlen_zero(), astman_get_header(), str, ast_aoc_unit_entry::type, ast_aoc_unit_entry::valid_amount, and ast_aoc_unit_entry::valid_type.
Referenced by action_aocmessage().
03584 { 03585 const char *unitamount; 03586 const char *unittype; 03587 struct ast_str *str = ast_str_alloca(32); 03588 03589 memset(entry, 0, sizeof(*entry)); 03590 03591 ast_str_set(&str, 0, "UnitAmount(%u)", entry_num); 03592 unitamount = astman_get_header(m, ast_str_buffer(str)); 03593 03594 ast_str_set(&str, 0, "UnitType(%u)", entry_num); 03595 unittype = astman_get_header(m, ast_str_buffer(str)); 03596 03597 if (!ast_strlen_zero(unitamount) && (sscanf(unitamount, "%30u", &entry->amount) == 1)) { 03598 entry->valid_amount = 1; 03599 } 03600 03601 if (!ast_strlen_zero(unittype) && sscanf(unittype, "%30u", &entry->type) == 1) { 03602 entry->valid_type = 1; 03603 } 03604 03605 return 0; 03606 }
| static void append_channel_vars | ( | struct ast_str ** | pbuf, | |
| struct ast_channel * | chan | |||
| ) | [static] |
Definition at line 4771 of file manager.c.
References ast_func_read2(), AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_str_append(), ast_str_buffer(), ast_str_thread_get(), manager_channel_variable::isfunc, manager_event_funcbuf, ast_channel::name, manager_channel_variable::name, pbx_builtin_getvar_helper(), and var.
Referenced by __ast_manager_event_multichan().
04772 { 04773 struct manager_channel_variable *var; 04774 AST_RWLIST_RDLOCK(&channelvars); 04775 AST_LIST_TRAVERSE(&channelvars, var, entry) { 04776 const char *val = ""; 04777 if (var->isfunc) { 04778 struct ast_str *res = ast_str_thread_get(&manager_event_funcbuf, 16); 04779 int ret; 04780 if (res && (ret = ast_func_read2(chan, var->name, &res, 0)) == 0) { 04781 val = ast_str_buffer(res); 04782 } 04783 } else { 04784 val = pbx_builtin_getvar_helper(chan, var->name); 04785 } 04786 ast_str_append(pbuf, 0, "ChanVariable(%s): %s=%s\r\n", chan->name, var->name, val ? val : ""); 04787 } 04788 AST_RWLIST_UNLOCK(&channelvars); 04789 }
| static int append_event | ( | const char * | str, | |
| int | category | |||
| ) | [static] |
Definition at line 4745 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 __ast_manager_event_multichan(), and __init_manager().
04746 { 04747 struct eventqent *tmp = ast_malloc(sizeof(*tmp) + strlen(str)); 04748 static int seq; /* sequence number */ 04749 04750 if (!tmp) { 04751 return -1; 04752 } 04753 04754 /* need to init all fields, because ast_malloc() does not */ 04755 tmp->usecount = 0; 04756 tmp->category = category; 04757 tmp->seq = ast_atomic_fetchadd_int(&seq, 1); 04758 tmp->tv = ast_tvnow(); 04759 AST_RWLIST_NEXT(tmp, eq_next) = NULL; 04760 strcpy(tmp->eventdata, str); 04761 04762 AST_RWLIST_WRLOCK(&all_events); 04763 AST_RWLIST_INSERT_TAIL(&all_events, tmp, eq_next); 04764 AST_RWLIST_UNLOCK(&all_events); 04765 04766 return 0; 04767 }
| int ast_hook_send_action | ( | struct manager_custom_hook * | hook, | |
| const char * | msg | |||
| ) |
Registered hooks can call this function to invoke actions and they will receive responses through registered callback.
| hook | the file identifier specified in manager_custom_hook struct when registering a hook | |
| msg | ami action mesage string e.g. "Action: SipPeers\r\n" |
| 0 | on Success | |
| non-zero | on Failure |
Definition at line 1781 of file manager.c.
References manager_action::action, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdupa, astman_get_header(), mansession::f, manager_action::func, message::hdrcount, message::headers, mansession::hook, and mansession::session.
01782 { 01783 const char *action; 01784 int ret = 0; 01785 struct manager_action *tmp; 01786 struct mansession s = {.session = NULL, }; 01787 struct message m = { 0 }; 01788 char header_buf[1025] = { '\0' }; 01789 const char *src = msg; 01790 int x = 0; 01791 int curlen; 01792 01793 if (hook == NULL) { 01794 return -1; 01795 } 01796 01797 /* convert msg string to message struct */ 01798 curlen = strlen(msg); 01799 for (x = 0; x < curlen; x++) { 01800 int cr; /* set if we have \r */ 01801 if (src[x] == '\r' && x+1 < curlen && src[x+1] == '\n') 01802 cr = 2; /* Found. Update length to include \r\n */ 01803 else if (src[x] == '\n') 01804 cr = 1; /* also accept \n only */ 01805 else 01806 continue; 01807 /* don't copy empty lines */ 01808 if (x) { 01809 memmove(header_buf, src, x); /*... but trim \r\n */ 01810 header_buf[x] = '\0'; /* terminate the string */ 01811 m.headers[m.hdrcount++] = ast_strdupa(header_buf); 01812 } 01813 x += cr; 01814 curlen -= x; /* remaining size */ 01815 src += x; /* update pointer */ 01816 x = -1; /* reset loop */ 01817 } 01818 01819 action = astman_get_header(&m,"Action"); 01820 if (action && strcasecmp(action,"login")) { 01821 01822 AST_RWLIST_RDLOCK(&actions); 01823 AST_RWLIST_TRAVERSE(&actions, tmp, list) { 01824 if (strcasecmp(action, tmp->action)) 01825 continue; 01826 /* 01827 * we have to simulate a session for this action request 01828 * to be able to pass it down for processing 01829 * This is necessary to meet the previous design of manager.c 01830 */ 01831 s.hook = hook; 01832 s.f = (void*)1; /* set this to something so our request will make it through all functions that test it*/ 01833 ret = tmp->func(&s, &m); 01834 break; 01835 } 01836 AST_RWLIST_UNLOCK(&actions); 01837 } 01838 return ret; 01839 }
| 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 1152 of file manager.c.
References eventqent::next.
Referenced by get_perm().
01153 { 01154 const char *val = bigstr, *next; 01155 01156 do { 01157 if ((next = strchr(val, delim))) { 01158 if (!strncmp(val, smallstr, (next - val))) { 01159 return 1; 01160 } else { 01161 continue; 01162 } 01163 } else { 01164 return !strcmp(smallstr, val); 01165 } 01166 } while (*(val = (next + 1))); 01167 01168 return 0; 01169 }
| 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 4953 of file manager.c.
References manager_action::action, ast_calloc_with_stringfields, ast_free, ast_manager_register_struct(), AST_STATIC_DOC, ast_string_field_set, ast_strlen_zero(), AST_XML_DOC, ast_xmldoc_build_arguments(), ast_xmldoc_build_description(), ast_xmldoc_build_seealso(), ast_xmldoc_build_synopsis(), ast_xmldoc_build_syntax(), manager_action::authority, manager_action::docsrc, and manager_action::func.
Referenced by load_module().
04954 { 04955 struct manager_action *cur = NULL; 04956 #ifdef AST_XML_DOCS 04957 char *tmpxml; 04958 #endif 04959 04960 if (!(cur = ast_calloc_with_stringfields(1, struct manager_action, 128))) { 04961 return -1; 04962 } 04963 04964 cur->action = action; 04965 cur->authority = auth; 04966 cur->func = func; 04967 #ifdef AST_XML_DOCS 04968 if (ast_strlen_zero(synopsis) && ast_strlen_zero(description)) { 04969 tmpxml = ast_xmldoc_build_synopsis("manager", action); 04970 ast_string_field_set(cur, synopsis, tmpxml); 04971 ast_free(tmpxml); 04972 04973 tmpxml = ast_xmldoc_build_syntax("manager", action); 04974 ast_string_field_set(cur, syntax, tmpxml); 04975 ast_free(tmpxml); 04976 04977 tmpxml = ast_xmldoc_build_description("manager", action); 04978 ast_string_field_set(cur, description, tmpxml); 04979 ast_free(tmpxml); 04980 04981 tmpxml = ast_xmldoc_build_seealso("manager", action); 04982 ast_string_field_set(cur, seealso, tmpxml); 04983 ast_free(tmpxml); 04984 04985 tmpxml = ast_xmldoc_build_arguments("manager", action); 04986 ast_string_field_set(cur, arguments, tmpxml); 04987 ast_free(tmpxml); 04988 04989 cur->docsrc = AST_XML_DOC; 04990 } else { 04991 #endif 04992 ast_string_field_set(cur, synopsis, synopsis); 04993 ast_string_field_set(cur, description, description); 04994 #ifdef AST_XML_DOCS 04995 cur->docsrc = AST_STATIC_DOC; 04996 } 04997 #endif 04998 if (ast_manager_register_struct(cur)) { 04999 ast_free(cur); 05000 return -1; 05001 } 05002 05003 return 0; 05004 }
| 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 1022 of file manager.c.
References AST_RWLIST_INSERT_TAIL, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.
01023 { 01024 AST_RWLIST_WRLOCK(&manager_hooks); 01025 AST_RWLIST_INSERT_TAIL(&manager_hooks, hook, list); 01026 AST_RWLIST_UNLOCK(&manager_hooks); 01027 }
| static int ast_manager_register_struct | ( | struct manager_action * | act | ) | [static] |
Definition at line 4916 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().
04917 { 04918 struct manager_action *cur, *prev = NULL; 04919 struct timespec tv = { 5, }; 04920 04921 if (AST_RWLIST_TIMEDWRLOCK(&actions, &tv)) { 04922 ast_log(LOG_ERROR, "Could not obtain lock on manager list\n"); 04923 return -1; 04924 } 04925 AST_RWLIST_TRAVERSE(&actions, cur, list) { 04926 int ret = strcasecmp(cur->action, act->action); 04927 if (ret == 0) { 04928 ast_log(LOG_WARNING, "Manager: Action '%s' already registered\n", act->action); 04929 AST_RWLIST_UNLOCK(&actions); 04930 return -1; 04931 } 04932 if (ret > 0) { /* Insert these alphabetically */ 04933 prev = cur; 04934 break; 04935 } 04936 } 04937 04938 if (prev) { 04939 AST_RWLIST_INSERT_AFTER(&actions, prev, act, list); 04940 } else { 04941 AST_RWLIST_INSERT_HEAD(&actions, act, list); 04942 } 04943 04944 ast_verb(2, "Manager registered action %s\n", act->action); 04945 04946 AST_RWLIST_UNLOCK(&actions); 04947 04948 return 0; 04949 }
| int ast_manager_unregister | ( | char * | action | ) |
Unregister a registered manager command.
| action | Name of registered Action: |
Definition at line 4882 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_string_field_free_memory, ast_verb, LOG_ERROR, and eventqent::tv.
Referenced by __unload_module(), and unload_module().
04883 { 04884 struct manager_action *cur; 04885 struct timespec tv = { 5, }; 04886 04887 if (AST_RWLIST_TIMEDWRLOCK(&actions, &tv)) { 04888 ast_log(LOG_ERROR, "Could not obtain lock on manager list\n"); 04889 return -1; 04890 } 04891 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&actions, cur, list) { 04892 if (!strcasecmp(action, cur->action)) { 04893 AST_RWLIST_REMOVE_CURRENT(list); 04894 ast_string_field_free_memory(cur); 04895 ast_free(cur); 04896 ast_verb(2, "Manager unregistered action %s\n", action); 04897 break; 04898 } 04899 } 04900 AST_RWLIST_TRAVERSE_SAFE_END; 04901 AST_RWLIST_UNLOCK(&actions); 04902 04903 return 0; 04904 }
| 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 1030 of file manager.c.
References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.
01031 { 01032 AST_RWLIST_WRLOCK(&manager_hooks); 01033 AST_RWLIST_REMOVE(&manager_hooks, hook, list); 01034 AST_RWLIST_UNLOCK(&manager_hooks); 01035 }
| void astman_append | ( | struct mansession * | s, | |
| const char * | fmt, | |||
| ... | ||||
| ) |
utility functions for creating AMI replies
Definition at line 1879 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, 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(), data_result_manager_output(), do_print(), manager_data_get(), manager_dbget(), manager_iax2_show_netstats(), manager_iax2_show_peer_list(), manager_iax2_show_peers(), manager_iax2_show_registry(), manager_jabber_send(), manager_list_voicemail_users(), manager_modulecheck(), manager_mute_mixmonitor(), manager_mutestream(), 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().
01880 { 01881 va_list ap; 01882 struct ast_str *buf; 01883 01884 if (!(buf = ast_str_thread_get(&astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE))) { 01885 return; 01886 } 01887 01888 va_start(ap, fmt); 01889 ast_str_set_va(&buf, 0, fmt, ap); 01890 va_end(ap); 01891 01892 if (s->f != NULL || s->session->f != NULL) { 01893 send_string(s, ast_str_buffer(buf)); 01894 } else { 01895 ast_verbose("fd == -1 in astman_append, should not happen\n"); 01896 } 01897 }
| const char* astman_get_header | ( | const struct message * | m, | |
| char * | var | |||
| ) |
Get header from mananger transaction.
Definition at line 1732 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_aocmessage(), 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(), aocmessage_get_unit_entry(), ast_hook_send_action(), astman_send_response_full(), authenticate(), change_monitor_action(), do_pause_or_unpause(), handle_updates(), manager_add_queue_member(), manager_data_get(), 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_mute_mixmonitor(), manager_mutestream(), manager_optimize_away(), 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().
01733 { 01734 return __astman_get_header(m, var, GET_HEADER_FIRST_MATCH); 01735 }
| struct ast_variable* astman_get_variables | ( | const struct message * | m | ) | [read] |
Get a linked list of the Variable: headers.
Definition at line 1738 of file manager.c.
References args, 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().
01739 { 01740 int varlen, x, y; 01741 struct ast_variable *head = NULL, *cur; 01742 01743 AST_DECLARE_APP_ARGS(args, 01744 AST_APP_ARG(vars)[32]; 01745 ); 01746 01747 varlen = strlen("Variable: "); 01748 01749 for (x = 0; x < m->hdrcount; x++) { 01750 char *parse, *var, *val; 01751 01752 if (strncasecmp("Variable: ", m->headers[x], varlen)) { 01753 continue; 01754 } 01755 parse = ast_strdupa(m->headers[x] + varlen); 01756 01757 AST_STANDARD_APP_ARGS(args, parse); 01758 if (!args.argc) { 01759 continue; 01760 } 01761 for (y = 0; y < args.argc; y++) { 01762 if (!args.vars[y]) { 01763 continue; 01764 } 01765 var = val = ast_strdupa(args.vars[y]); 01766 strsep(&val, "="); 01767 if (!val || ast_strlen_zero(var)) { 01768 continue; 01769 } 01770 cur = ast_variable_new(var, val, ""); 01771 cur->next = head; 01772 head = cur; 01773 } 01774 } 01775 01776 return head; 01777 }
| void astman_send_ack | ( | struct mansession * | s, | |
| const struct message * | m, | |||
| char * | msg | |||
| ) |
Send ack in manager transaction.
Definition at line 1946 of file manager.c.
References astman_send_response_full().
Referenced by action_add_agi_cmd(), action_agent_logoff(), action_agents(), action_aocmessage(), 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_jabber_send(), manager_list_voicemail_users(), manager_moduleload(), manager_optimize_away(), 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().
01947 { 01948 astman_send_response_full(s, m, "Success", msg, NULL); 01949 }
| void astman_send_error | ( | struct mansession * | s, | |
| const struct message * | m, | |||
| char * | error | |||
| ) |
Send error in manager transaction.
Definition at line 1941 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_aocmessage(), action_atxfer(), action_bridge(), action_challenge(), action_command(), action_coreshowchannels(), 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_data_get(), manager_dbdel(), manager_dbdeltree(), manager_dbget(), manager_dbput(), manager_jabber_send(), manager_modulecheck(), manager_moduleload(), manager_mute_mixmonitor(), manager_mutestream(), manager_optimize_away(), 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().
01942 { 01943 astman_send_response_full(s, m, "Error", error, NULL); 01944 }
| void astman_send_listack | ( | struct mansession * | s, | |
| const struct message * | m, | |||
| char * | msg, | |||
| char * | listflag | |||
| ) |
Send ack in manager list transaction.
Definition at line 1956 of file manager.c.
References astman_send_response_full().
Referenced by action_coreshowchannels(), action_meetmelist(), manager_dpsendack(), manager_iax2_show_peers(), manager_iax2_show_registry(), manager_show_registry(), manager_sip_show_peers(), manager_skinny_show_devices(), and manager_skinny_show_lines().
01957 { 01958 astman_send_response_full(s, m, "Success", msg, listflag); 01959 }
| void astman_send_response | ( | struct mansession * | s, | |
| const struct message * | m, | |||
| char * | resp, | |||
| char * | msg | |||
| ) |
Send response in manager transaction.
Definition at line 1936 of file manager.c.
References astman_send_response_full().
Referenced by action_logoff(), and action_waitevent().
01937 { 01938 astman_send_response_full(s, m, resp, msg, NULL); 01939 }
| static void astman_send_response_full | ( | struct mansession * | s, | |
| const struct message * | m, | |||
| char * | resp, | |||
| char * | msg, | |||
| char * | listflag | |||
| ) | [static] |
Definition at line 1916 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().
01917 { 01918 const char *id = astman_get_header(m, "ActionID"); 01919 01920 astman_append(s, "Response: %s\r\n", resp); 01921 if (!ast_strlen_zero(id)) { 01922 astman_append(s, "ActionID: %s\r\n", id); 01923 } 01924 if (listflag) { 01925 astman_append(s, "EventList: %s\r\n", listflag); /* Start, complete, cancelled */ 01926 } 01927 if (msg == MSG_MOREDATA) { 01928 return; 01929 } else if (msg) { 01930 astman_append(s, "Message: %s\r\n\r\n", msg); 01931 } else { 01932 astman_append(s, "\r\n"); 01933 } 01934 }
| static void astman_start_ack | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 1951 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().
01952 { 01953 astman_send_response_full(s, m, "Success", MSG_MOREDATA, NULL); 01954 }
| static int authenticate | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 2233 of file manager.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_t_link, ao2_t_ref, ast_apply_ha(), ast_copy_string(), ast_debug, ast_inet_ntoa(), ast_log(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_sockaddr_from_sin, ast_strlen_zero(), ast_tvnow(), astman_get_header(), mansession_session::blackfilters, ast_manager_user::blackfilters, 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, report_auth_success(), report_failed_acl(), report_failed_challenge_response(), report_inval_password(), report_invalid_user(), S_OR, ast_manager_user::secret, mansession::session, mansession_session::sessionstart, mansession_session::sessionstart_tv, set_eventmask(), mansession_session::sin, mansession_session::username, mansession_session::whitefilters, ast_manager_user::whitefilters, ast_manager_user::writeperm, mansession_session::writeperm, ast_manager_user::writetimeout, and mansession_session::writetimeout.
Referenced by action_login().
02234 { 02235 const char *username = astman_get_header(m, "Username"); 02236 const char *password = astman_get_header(m, "Secret"); 02237 int error = -1; 02238 struct ast_manager_user *user = NULL; 02239 regex_t *regex_filter; 02240 struct ao2_iterator filter_iter; 02241 struct ast_sockaddr addr; 02242 02243 if (ast_strlen_zero(username)) { /* missing username */ 02244 return -1; 02245 } 02246 02247 /* locate user in locked state */ 02248 AST_RWLIST_WRLOCK(&users); 02249 02250 ast_sockaddr_from_sin(&addr, &s->session->sin); 02251 02252 if (!(user = get_manager_by_name_locked(username))) { 02253 report_invalid_user(s, username); 02254 ast_log(LOG_NOTICE, "%s tried to authenticate with nonexistent user '%s'\n", ast_inet_ntoa(s->session->sin.sin_addr), username); 02255 } else if (user->ha && !ast_apply_ha(user->ha, &addr)) { 02256 report_failed_acl(s, username); 02257 ast_log(LOG_NOTICE, "%s failed to pass IP ACL as '%s'\n", ast_inet_ntoa(s->session->sin.sin_addr), username); 02258 } else if (!strcasecmp(astman_get_header(m, "AuthType"), "MD5")) { 02259 const char *key = astman_get_header(m, "Key"); 02260 if (!ast_strlen_zero(key) && !ast_strlen_zero(s->session->challenge) && user->secret) { 02261 int x; 02262 int len = 0; 02263 char md5key[256] = ""; 02264 struct MD5Context md5; 02265 unsigned char digest[16]; 02266 02267 MD5Init(&md5); 02268 MD5Update(&md5, (unsigned char *) s->session->challenge, strlen(s->session->challenge)); 02269 MD5Update(&md5, (unsigned char *) user->secret, strlen(user->secret)); 02270 MD5Final(digest, &md5); 02271 for (x = 0; x < 16; x++) 02272 len += sprintf(md5key + len, "%2.2x", digest[x]); 02273 if (!strcmp(md5key, key)) { 02274 error = 0; 02275 } else { 02276 report_failed_challenge_response(s, key, md5key); 02277 } 02278 } else { 02279 ast_debug(1, "MD5 authentication is not possible. challenge: '%s'\n", 02280 S_OR(s->session->challenge, "")); 02281 } 02282 } else if (user->secret) { 02283 if (!strcmp(password, user->secret)) { 02284 error = 0; 02285 } else { 02286 report_inval_password(s, username); 02287 } 02288 } 02289 02290 if (error) { 02291 ast_log(LOG_NOTICE, "%s failed to authenticate as '%s'\n", ast_inet_ntoa(s->session->sin.sin_addr), username); 02292 AST_RWLIST_UNLOCK(&users); 02293 return -1; 02294 } 02295 02296 /* auth complete */ 02297 02298 /* All of the user parameters are copied to the session so that in the event 02299 * of a reload and a configuration change, the session parameters are not 02300 * changed. */ 02301 ast_copy_string(s->session->username, username, sizeof(s->session->username)); 02302 s->session->readperm = user->readperm; 02303 s->session->writeperm = user->writeperm; 02304 s->session->writetimeout = user->writetimeout; 02305 02306 filter_iter = ao2_iterator_init(user->whitefilters, 0); 02307 while ((regex_filter = ao2_iterator_next(&filter_iter))) { 02308 ao2_t_link(s->session->whitefilters, regex_filter, "add white user filter to session"); 02309 ao2_t_ref(regex_filter, -1, "remove iterator ref"); 02310 } 02311 ao2_iterator_destroy(&filter_iter); 02312 02313 filter_iter = ao2_iterator_init(user->blackfilters, 0); 02314 while ((regex_filter = ao2_iterator_next(&filter_iter))) { 02315 ao2_t_link(s->session->blackfilters, regex_filter, "add black user filter to session"); 02316 ao2_t_ref(regex_filter, -1, "remove iterator ref"); 02317 } 02318 ao2_iterator_destroy(&filter_iter); 02319 02320 s->session->sessionstart = time(NULL); 02321 s->session->sessionstart_tv = ast_tvnow(); 02322 set_eventmask(s, astman_get_header(m, "Events")); 02323 02324 report_auth_success(s); 02325 02326 AST_RWLIST_UNLOCK(&users); 02327 return 0; 02328 }
| static const char* authority_to_str | ( | int | authority, | |
| struct ast_str ** | res | |||
| ) | [static] |
Convert authority code to a list of options.
Definition at line 1128 of file manager.c.
References ARRAY_LEN, ast_str_append(), ast_str_buffer(), ast_str_reset(), ast_str_strlen(), and perms.
Referenced by __ast_manager_event_multichan(), action_listcommands(), handle_showmanager(), handle_showmancmd(), and handle_showmancmds().
01129 { 01130 int i; 01131 char *sep = ""; 01132 01133 ast_str_reset(*res); 01134 for (i = 0; i < ARRAY_LEN(perms) - 1; i++) { 01135 if (authority & perms[i].num) { 01136 ast_str_append(res, 0, "%s%s", sep, perms[i].label); 01137 sep = ","; 01138 } 01139 } 01140 01141 if (ast_str_strlen(*res) == 0) /* replace empty string with something sensible */ 01142 ast_str_append(res, 0, "<none>"); 01143 01144 return ast_str_buffer(*res); 01145 }
| static int blackfilter_cmp_fn | ( | void * | obj, | |
| void * | arg, | |||
| void * | data, | |||
| int | flags | |||
| ) | [static] |
Definition at line 4059 of file manager.c.
References CMP_MATCH, and CMP_STOP.
Referenced by match_filter().
04060 { 04061 regex_t *regex_filter = obj; 04062 const char *eventdata = arg; 04063 int *result = data; 04064 04065 if (regexec(regex_filter, eventdata, 0, NULL, 0)) { 04066 *result = 1; 04067 return (CMP_MATCH | CMP_STOP); 04068 } 04069 04070 return 0; 04071 }
| static struct mansession_session* build_mansession | ( | struct sockaddr_in | sin | ) | [static, read] |
Allocate manager session structure and add it to the list of sessions.
Definition at line 1269 of file manager.c.
References ao2_alloc, ao2_container_alloc, ao2_link, ao2_ref, AST_PTHREADT_NULL, mansession_session::blackfilters, mansession_session::fd, mansession_session::send_events, session_destructor(), mansession_session::sin, mansession_session::waiting_thread, mansession_session::whitefilters, and mansession_session::writetimeout.
Referenced by auth_http_callback(), generic_http_callback(), and session_do().
01270 { 01271 struct mansession_session *newsession; 01272 01273 if (!(newsession = ao2_alloc(sizeof(*newsession), session_destructor))) { 01274 return NULL; 01275 } 01276 01277 if (!(newsession->whitefilters = ao2_container_alloc(1, NULL, NULL))) { 01278 ao2_ref(newsession, -1); 01279 return NULL; 01280 } 01281 01282 if (!(newsession->blackfilters = ao2_container_alloc(1, NULL, NULL))) { 01283 ao2_ref(newsession, -1); /* session_destructor will cleanup the other filter */ 01284 return NULL; 01285 } 01286 01287 newsession->fd = -1; 01288 newsession->waiting_thread = AST_PTHREADT_NULL; 01289 newsession->writetimeout = 100; 01290 newsession->send_events = -1; 01291 newsession->sin = sin; 01292 01293 ao2_link(sessions, newsession); 01294 01295 return newsession; 01296 }
| static int check_blacklist | ( | const char * | cmd | ) | [static] |
Definition at line 3424 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().
03425 { 03426 char *cmd_copy, *cur_cmd; 03427 char *cmd_words[MAX_BLACKLIST_CMD_LEN] = { NULL, }; 03428 int i; 03429 03430 cmd_copy = ast_strdupa(cmd); 03431 for (i = 0; i < MAX_BLACKLIST_CMD_LEN && (cur_cmd = strsep(&cmd_copy, " ")); i++) { 03432 cur_cmd = ast_strip(cur_cmd); 03433 if (ast_strlen_zero(cur_cmd)) { 03434 i--; 03435 continue; 03436 } 03437 03438 cmd_words[i] = cur_cmd; 03439 } 03440 03441 for (i = 0; i < ARRAY_LEN(command_blacklist); i++) { 03442 int j, match = 1; 03443 03444 for (j = 0; command_blacklist[i].words[j]; j++) { 03445 if (ast_strlen_zero(cmd_words[j]) || strcasecmp(cmd_words[j], command_blacklist[i].words[j])) { 03446 match = 0; 03447 break; 03448 } 03449 } 03450 03451 if (match) { 03452 return 1; 03453 } 03454 } 03455 03456 return 0; 03457 }
| int check_manager_enabled | ( | void | ) |
Check if AMI is enabled.
Definition at line 1037 of file manager.c.
Referenced by handle_show_settings().
01038 { 01039 return manager_enabled; 01040 }
| static int check_manager_session_inuse | ( | const char * | name | ) | [static] |
Definition at line 1312 of file manager.c.
References ao2_find, mansession_session::inuse, and unref_mansession().
Referenced by process_message().
01313 { 01314 struct mansession_session *session = ao2_find(sessions, (char *) name, 0); 01315 int inuse = 0; 01316 01317 if (session) { 01318 inuse = 1; 01319 unref_mansession(session); 01320 } 01321 return inuse; 01322 }
| int check_webmanager_enabled | ( | void | ) |
Check if AMI/HTTP is enabled.
Definition at line 1042 of file manager.c.
Referenced by action_coresettings(), and handle_show_settings().
01043 { 01044 return (webmanager_enabled && manager_enabled); 01045 }
| static int do_message | ( | struct mansession * | s | ) | [static] |
Definition at line 4587 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().
04588 { 04589 struct message m = { 0 }; 04590 char header_buf[sizeof(s->session->inbuf)] = { '\0' }; 04591 int res; 04592 04593 for (;;) { 04594 /* Check if any events are pending and do them if needed */ 04595 if (process_events(s)) { 04596 return -1; 04597 } 04598 res = get_input(s, header_buf); 04599 if (res == 0) { 04600 continue; 04601 } else if (res > 0) { 04602 if (ast_strlen_zero(header_buf)) { 04603 return process_message(s, &m) ? -1 : 0; 04604 } else if (m.hdrcount < (AST_MAX_MANHEADERS - 1)) { 04605 m.headers[m.hdrcount++] = ast_strdupa(header_buf); 04606 } 04607 } else { 04608 return res; 04609 } 04610 } 04611 }
| static void event_filter_destructor | ( | void * | obj | ) | [static] |
| static void* fast_originate | ( | void * | data | ) | [static] |
Definition at line 3533 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_manager_event_multichan, ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_strlen_zero(), fast_originate_helper::cid_name, fast_originate_helper::cid_num, fast_originate_helper::context, fast_originate_helper::data, EVENT_FLAG_CALL, fast_originate_helper::exten, fast_originate_helper::format, fast_originate_helper::idtext, 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().
03534 { 03535 struct fast_originate_helper *in = data; 03536 int res; 03537 int reason = 0; 03538 struct ast_channel *chan = NULL, *chans[1]; 03539 char requested_channel[AST_CHANNEL_NAME]; 03540 03541 if (!ast_strlen_zero(in->app)) { 03542 res = ast_pbx_outgoing_app(in->tech, in->format, in->data, in->timeout, in->app, in->appdata, &reason, 1, 03543 S_OR(in->cid_num, NULL), 03544 S_OR(in->cid_name, NULL), 03545 in->vars, in->account, &chan); 03546 } else { 03547 res = ast_pbx_outgoing_exten(in->tech, in->format, in->data, in->timeout, in->context, in->exten, in->priority, &reason, 1, 03548 S_OR(in->cid_num, NULL), 03549 S_OR(in->cid_name, NULL), 03550 in->vars, in->account, &chan); 03551 } 03552 03553 if (!chan) { 03554 snprintf(requested_channel, AST_CHANNEL_NAME, "%s/%s", in->tech, in->data); 03555 } 03556 /* Tell the manager what happened with the channel */ 03557 chans[0] = chan; 03558 ast_manager_event_multichan(EVENT_FLAG_CALL, "OriginateResponse", chan ? 1 : 0, chans, 03559 "%s%s" 03560 "Response: %s\r\n" 03561 "Channel: %s\r\n" 03562 "Context: %s\r\n" 03563 "Exten: %s\r\n" 03564 "Reason: %d\r\n" 03565 "Uniqueid: %s\r\n" 03566 "CallerIDNum: %s\r\n" 03567 "CallerIDName: %s\r\n", 03568 in->idtext, ast_strlen_zero(in->idtext) ? "" : "\r\n", res ? "Failure" : "Success", 03569 chan ? chan->name : requested_channel, in->context, in->exten, reason, 03570 chan ? chan->uniqueid : "<null>", 03571 S_OR(in->cid_num, "<unknown>"), 03572 S_OR(in->cid_name, "<unknown>") 03573 ); 03574 03575 /* Locked by ast_pbx_outgoing_exten or ast_pbx_outgoing_app */ 03576 if (chan) { 03577 ast_channel_unlock(chan); 03578 } 03579 ast_free(in); 03580 return NULL; 03581 }
| static void free_channelvars | ( | void | ) | [static] |
Definition at line 6568 of file manager.c.
References ast_free, AST_RWLIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and var.
Referenced by __init_manager().
06569 { 06570 struct manager_channel_variable *var; 06571 AST_RWLIST_WRLOCK(&channelvars); 06572 while ((var = AST_RWLIST_REMOVE_HEAD(&channelvars, entry))) { 06573 ast_free(var); 06574 } 06575 AST_RWLIST_UNLOCK(&channelvars); 06576 }
| 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 4515 of file manager.c.
References ao2_lock, ao2_unlock, ast_inet_ntoa(), ast_log(), 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().
04516 { 04517 int res, x; 04518 int maxlen = sizeof(s->session->inbuf) - 1; 04519 char *src = s->session->inbuf; 04520 04521 /* 04522 * Look for \r\n within the buffer. If found, copy to the output 04523 * buffer and return, trimming the \r\n (not used afterwards). 04524 */ 04525 for (x = 0; x < s->session->inlen; x++) { 04526 int cr; /* set if we have \r */ 04527 if (src[x] == '\r' && x+1 < s->session->inlen && src[x + 1] == '\n') { 04528 cr = 2; /* Found. Update length to include \r\n */ 04529 } else if (src[x] == '\n') { 04530 cr = 1; /* also accept \n only */ 04531 } else { 04532 continue; 04533 } 04534 memmove(output, src, x); /*... but trim \r\n */ 04535 output[x] = '\0'; /* terminate the string */ 04536 x += cr; /* number of bytes used */ 04537 s->session->inlen -= x; /* remaining size */ 04538 memmove(src, src + x, s->session->inlen); /* remove used bytes */ 04539 return 1; 04540 } 04541 if (s->session->inlen >= maxlen) { 04542 /* no crlf found, and buffer full - sorry, too long for us */ 04543 ast_log(LOG_WARNING, "Dumping long line with no return from %s: %s\n", ast_inet_ntoa(s->session->sin.sin_addr), src); 04544 s->session->inlen = 0; 04545 } 04546 res = 0; 04547 while (res == 0) { 04548 ao2_lock(s->session); 04549 if (s->session->pending_event) { 04550 s->session->pending_event = 0; 04551 ao2_unlock(s->session); 04552 return 0; 04553 } 04554 s->session->waiting_thread = pthread_self(); 04555 ao2_unlock(s->session); 04556 04557 res = ast_wait_for_input(s->session->fd, -1); /* return 0 on timeout ? */ 04558 04559 ao2_lock(s->session); 04560 s->session->waiting_thread = AST_PTHREADT_NULL; 04561 ao2_unlock(s->session); 04562 } 04563 if (res < 0) { 04564 /* If we get a signal from some other thread (typically because 04565 * there are new events queued), return 0 to notify the caller. 04566 */ 04567 if (errno == EINTR || errno == EAGAIN) { 04568 return 0; 04569 } 04570 ast_log(LOG_WARNING, "poll() returned error: %s\n", strerror(errno)); 04571 return -1; 04572 } 04573 04574 ao2_lock(s->session); 04575 res = fread(src + s->session->inlen, 1, maxlen - s->session->inlen, s->session->f); 04576 if (res < 1) { 04577 res = -1; /* error return */ 04578 } else { 04579 s->session->inlen += res; 04580 src[s->session->inlen] = '\0'; 04581 res = 0; 04582 } 04583 ao2_unlock(s->session); 04584 return res; 04585 }
| 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 1329 of file manager.c.
References AST_RWLIST_TRAVERSE, ast_manager_user::list, and ast_manager_user::username.
Referenced by __init_manager(), auth_http_callback(), authenticate(), handle_showmanager(), and manager_displayconnects().
01330 { 01331 struct ast_manager_user *user = NULL; 01332 01333 AST_RWLIST_TRAVERSE(&users, user, list) { 01334 if (!strcasecmp(user->username, name)) { 01335 break; 01336 } 01337 } 01338 01339 return user; 01340 }
| static int get_perm | ( | const char * | instr | ) | [static] |
Definition at line 1171 of file manager.c.
References ARRAY_LEN, ast_instring(), permalias::num, and perms.
Referenced by __init_manager(), and strings_to_mask().
01172 { 01173 int x = 0, ret = 0; 01174 01175 if (!instr) { 01176 return 0; 01177 } 01178 01179 for (x = 0; x < ARRAY_LEN(perms); x++) { 01180 if (ast_instring(instr, perms[x].label, ',')) { 01181 ret |= perms[x].num; 01182 } 01183 } 01184 01185 return ret; 01186 }
| 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 1051 of file manager.c.
References ast_atomic_fetchadd_int(), AST_RWLIST_LAST, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and eventqent::usecount.
Referenced by auth_http_callback(), generic_http_callback(), and session_do().
01052 { 01053 struct eventqent *ret; 01054 01055 AST_RWLIST_WRLOCK(&all_events); 01056 ret = AST_RWLIST_LAST(&all_events); 01057 /* the list is never empty now, but may become so when 01058 * we optimize it in the future, so be prepared. 01059 */ 01060 if (ret) { 01061 ast_atomic_fetchadd_int(&ret->usecount, 1); 01062 } 01063 AST_RWLIST_UNLOCK(&all_events); 01064 return ret; 01065 }
| 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 1663 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.
01664 { 01665 switch (cmd) { 01666 case CLI_INIT: 01667 e->command = "manager reload"; 01668 e->usage = 01669 "Usage: manager reload\n" 01670 " Reloads the manager configuration.\n"; 01671 return NULL; 01672 case CLI_GENERATE: 01673 return NULL; 01674 } 01675 if (a->argc > 2) { 01676 return CLI_SHOWUSAGE; 01677 } 01678 reload_manager(); 01679 return CLI_SUCCESS; 01680 }
| static char* handle_mandebug | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 1438 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, manager_debug, and ast_cli_entry::usage.
01439 { 01440 switch (cmd) { 01441 case CLI_INIT: 01442 e->command = "manager set debug [on|off]"; 01443 e->usage = "Usage: manager set debug [on|off]\n Show, enable, disable debugging of the manager code.\n"; 01444 return NULL; 01445 case CLI_GENERATE: 01446 return NULL; 01447 } 01448 01449 if (a->argc == 3) { 01450 ast_cli(a->fd, "manager debug is %s\n", manager_debug? "on" : "off"); 01451 } else if (a->argc == 4) { 01452 if (!strcasecmp(a->argv[3], "on")) { 01453 manager_debug = 1; 01454 } else if (!strcasecmp(a->argv[3], "off")) { 01455 manager_debug = 0; 01456 } else { 01457 return CLI_SHOWUSAGE; 01458 } 01459 } 01460 return CLI_SUCCESS; 01461 }
| static char* handle_showmanager | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 1463 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.
01464 { 01465 struct ast_manager_user *user = NULL; 01466 int l, which; 01467 char *ret = NULL; 01468 struct ast_str *rauthority = ast_str_alloca(128); 01469 struct ast_str *wauthority = ast_str_alloca(128); 01470 01471 switch (cmd) { 01472 case CLI_INIT: 01473 e->command = "manager show user"; 01474 e->usage = 01475 " Usage: manager show user <user>\n" 01476 " Display all information related to the manager user specified.\n"; 01477 return NULL; 01478 case CLI_GENERATE: 01479 l = strlen(a->word); 01480 which = 0; 01481 if (a->pos != 3) { 01482 return NULL; 01483 } 01484 AST_RWLIST_RDLOCK(&users); 01485 AST_RWLIST_TRAVERSE(&users, user, list) { 01486 if ( !strncasecmp(a->word, user->username, l) && ++which > a->n ) { 01487 ret = ast_strdup(user->username); 01488 break; 01489 } 01490 } 01491 AST_RWLIST_UNLOCK(&users); 01492 return ret; 01493 } 01494 01495 if (a->argc != 4) { 01496 return CLI_SHOWUSAGE; 01497 } 01498 01499 AST_RWLIST_RDLOCK(&users); 01500 01501 if (!(user = get_manager_by_name_locked(a->argv[3]))) { 01502 ast_cli(a->fd, "There is no manager called %s\n", a->argv[3]); 01503 AST_RWLIST_UNLOCK(&users); 01504 return CLI_SUCCESS; 01505 } 01506 01507 ast_cli(a->fd, "\n"); 01508 ast_cli(a->fd, 01509 " username: %s\n" 01510 " secret: %s\n" 01511 " acl: %s\n" 01512 " read perm: %s\n" 01513 " write perm: %s\n" 01514 "displayconnects: %s\n", 01515 (user->username ? user->username : "(N/A)"), 01516 (user->secret ? "<Set>" : "(N/A)"), 01517 (user->ha ? "yes" : "no"), 01518 authority_to_str(user->readperm, &rauthority), 01519 authority_to_str(user->writeperm, &wauthority), 01520 (user->displayconnects ? "yes" : "no")); 01521 01522 AST_RWLIST_UNLOCK(&users); 01523 01524 return CLI_SUCCESS; 01525 }
| static char* handle_showmanagers | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 1527 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.
01528 { 01529 struct ast_manager_user *user = NULL; 01530 int count_amu = 0; 01531 switch (cmd) { 01532 case CLI_INIT: 01533 e->command = "manager show users"; 01534 e->usage = 01535 "Usage: manager show users\n" 01536 " Prints a listing of all managers that are currently configured on that\n" 01537 " system.\n"; 01538 return NULL; 01539 case CLI_GENERATE: 01540 return NULL; 01541 } 01542 if (a->argc != 3) { 01543 return CLI_SHOWUSAGE; 01544 } 01545 01546 AST_RWLIST_RDLOCK(&users); 01547 01548 /* If there are no users, print out something along those lines */ 01549 if (AST_RWLIST_EMPTY(&users)) { 01550 ast_cli(a->fd, "There are no manager users.\n"); 01551 AST_RWLIST_UNLOCK(&users); 01552 return CLI_SUCCESS; 01553 } 01554 01555 ast_cli(a->fd, "\nusername\n--------\n"); 01556 01557 AST_RWLIST_TRAVERSE(&users, user, list) { 01558 ast_cli(a->fd, "%s\n", user->username); 01559 count_amu++; 01560 } 01561 01562 AST_RWLIST_UNLOCK(&users); 01563 01564 ast_cli(a->fd,"-------------------\n" 01565 "%d manager users configured.\n", count_amu); 01566 return CLI_SUCCESS; 01567 }
| static char* handle_showmancmd | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 1360 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, AST_XML_DOC, ast_xmldoc_printable(), manager_action::authority, authority_to_str(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, COLOR_MAGENTA, ast_cli_entry::command, manager_action::docsrc, ast_cli_args::fd, ast_cli_args::n, S_OR, term_color(), ast_cli_entry::usage, and ast_cli_args::word.
01361 { 01362 struct manager_action *cur; 01363 struct ast_str *authority; 01364 int num, l, which; 01365 char *ret = NULL; 01366 #ifdef AST_XML_DOCS 01367 char syntax_title[64], description_title[64], synopsis_title[64], seealso_title[64], arguments_title[64]; 01368 #endif 01369 01370 switch (cmd) { 01371 case CLI_INIT: 01372 e->command = "manager show command"; 01373 e->usage = 01374 "Usage: manager show command <actionname> [<actionname> [<actionname> [...]]]\n" 01375 " Shows the detailed description for a specific Asterisk manager interface command.\n"; 01376 return NULL; 01377 case CLI_GENERATE: 01378 l = strlen(a->word); 01379 which = 0; 01380 AST_RWLIST_RDLOCK(&actions); 01381 AST_RWLIST_TRAVERSE(&actions, cur, list) { 01382 if (!strncasecmp(a->word, cur->action, l) && ++which > a->n) { 01383 ret = ast_strdup(cur->action); 01384 break; /* make sure we exit even if ast_strdup() returns NULL */ 01385 } 01386 } 01387 AST_RWLIST_UNLOCK(&actions); 01388 return ret; 01389 } 01390 authority = ast_str_alloca(80); 01391 if (a->argc < 4) { 01392 return CLI_SHOWUSAGE; 01393 } 01394 01395 #ifdef AST_XML_DOCS 01396 /* setup the titles */ 01397 term_color(synopsis_title, "[Synopsis]\n", COLOR_MAGENTA, 0, 40); 01398 term_color(description_title, "[Description]\n", COLOR_MAGENTA, 0, 40); 01399 term_color(syntax_title, "[Syntax]\n", COLOR_MAGENTA, 0, 40); 01400 term_color(seealso_title, "[See Also]\n", COLOR_MAGENTA, 0, 40); 01401 term_color(arguments_title, "[Arguments]\n", COLOR_MAGENTA, 0, 40); 01402 #endif 01403 01404 AST_RWLIST_RDLOCK(&actions); 01405 AST_RWLIST_TRAVERSE(&actions, cur, list) { 01406 for (num = 3; num < a->argc; num++) { 01407 if (!strcasecmp(cur->action, a->argv[num])) { 01408 #ifdef AST_XML_DOCS 01409 if (cur->docsrc == AST_XML_DOC) { 01410 ast_cli(a->fd, "%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n", 01411 syntax_title, 01412 ast_xmldoc_printable(S_OR(cur->syntax, "Not available"), 1), 01413 synopsis_title, 01414 ast_xmldoc_printable(S_OR(cur->synopsis, "Not available"), 1), 01415 description_title, 01416 ast_xmldoc_printable(S_OR(cur->description, "Not available"), 1), 01417 arguments_title, 01418 ast_xmldoc_printable(S_OR(cur->arguments, "Not available"), 1), 01419 seealso_title, 01420 ast_xmldoc_printable(S_OR(cur->seealso, "Not available"), 1)); 01421 } else { 01422 #endif 01423 ast_cli(a->fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n", 01424 cur->action, cur->synopsis, 01425 authority_to_str(cur->authority, &authority), 01426 S_OR(cur->description, "")); 01427 #ifdef AST_XML_DOCS 01428 } 01429 #endif 01430 } 01431 } 01432 } 01433 AST_RWLIST_UNLOCK(&actions); 01434 01435 return CLI_SUCCESS; 01436 }
| 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 1570 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, and ast_cli_entry::usage.
01571 { 01572 struct manager_action *cur; 01573 struct ast_str *authority; 01574 #define HSMC_FORMAT " %-15.15s %-15.15s %-55.55s\n" 01575 switch (cmd) { 01576 case CLI_INIT: 01577 e->command = "manager show commands"; 01578 e->usage = 01579 "Usage: manager show commands\n" 01580 " Prints a listing of all the available Asterisk manager interface commands.\n"; 01581 return NULL; 01582 case CLI_GENERATE: 01583 return NULL; 01584 } 01585 authority = ast_str_alloca(80); 01586 ast_cli(a->fd, HSMC_FORMAT, "Action", "Privilege", "Synopsis"); 01587 ast_cli(a->fd, HSMC_FORMAT, "------", "---------", "--------"); 01588 01589 AST_RWLIST_RDLOCK(&actions); 01590 AST_RWLIST_TRAVERSE(&actions, cur, list) 01591 ast_cli(a->fd, HSMC_FORMAT, cur->action, authority_to_str(cur->authority, &authority), cur->synopsis); 01592 AST_RWLIST_UNLOCK(&actions); 01593 01594 return CLI_SUCCESS; 01595 }
| 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 1598 of file manager.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_unlock, ast_cli(), ast_inet_ntoa(), 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::readperm, mansession_session::sessionstart, mansession_session::sin, unref_mansession(), ast_cli_entry::usage, mansession_session::username, and mansession_session::writeperm.
01599 { 01600 struct mansession_session *session; 01601 time_t now = time(NULL); 01602 #define HSMCONN_FORMAT1 " %-15.15s %-15.15s %-10.10s %-10.10s %-8.8s %-8.8s %-5.5s %-5.5s\n" 01603 #define HSMCONN_FORMAT2 " %-15.15s %-15.15s %-10d %-10d %-8d %-8d %-5.5d %-5.5d\n" 01604 int count = 0; 01605 struct ao2_iterator i; 01606 01607 switch (cmd) { 01608 case CLI_INIT: 01609 e->command = "manager show connected"; 01610 e->usage = 01611 "Usage: manager show connected\n" 01612 " Prints a listing of the users that are currently connected to the\n" 01613 "Asterisk manager interface.\n"; 01614 return NULL; 01615 case CLI_GENERATE: 01616 return NULL; 01617 } 01618 01619 ast_cli(a->fd, HSMCONN_FORMAT1, "Username", "IP Address", "Start", "Elapsed", "FileDes", "HttpCnt", "Read", "Write"); 01620 01621 i = ao2_iterator_init(sessions, 0); 01622 while ((session = ao2_iterator_next(&i))) { 01623 ao2_lock(session); 01624 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); 01625 count++; 01626 ao2_unlock(session); 01627 unref_mansession(session); 01628 } 01629 ao2_iterator_destroy(&i); 01630 ast_cli(a->fd, "%d users connected.\n", count); 01631 01632 return CLI_SUCCESS; 01633 }
| 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 1637 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, ast_cli_entry::usage, and eventqent::usecount.
01638 { 01639 struct eventqent *s; 01640 switch (cmd) { 01641 case CLI_INIT: 01642 e->command = "manager show eventq"; 01643 e->usage = 01644 "Usage: manager show eventq\n" 01645 " Prints a listing of all events pending in the Asterisk manger\n" 01646 "event queue.\n"; 01647 return NULL; 01648 case CLI_GENERATE: 01649 return NULL; 01650 } 01651 AST_RWLIST_RDLOCK(&all_events); 01652 AST_RWLIST_TRAVERSE(&all_events, s, eq_next) { 01653 ast_cli(a->fd, "Usecount: %d\n", s->usecount); 01654 ast_cli(a->fd, "Category: %d\n", s->category); 01655 ast_cli(a->fd, "Event:\n%s", s->eventdata); 01656 } 01657 AST_RWLIST_UNLOCK(&all_events); 01658 01659 return CLI_SUCCESS; 01660 }
| static enum error_type handle_updates | ( | struct mansession * | s, | |
| const struct message * | m, | |||
| struct ast_config * | cfg, | |||
| const char * | dfn | |||
| ) | [static] |
Definition at line 2510 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, value, and var.
Referenced by action_updateconfig().
02511 { 02512 int x; 02513 char hdr[40]; 02514 const char *action, *cat, *var, *value, *match, *line; 02515 struct ast_category *category; 02516 struct ast_variable *v; 02517 struct ast_str *str1 = ast_str_create(16), *str2 = ast_str_create(16); 02518 enum error_type result = 0; 02519 02520 for (x = 0; x < 100000; x++) { /* 100000 = the max number of allowed updates + 1 */ 02521 unsigned int object = 0; 02522 02523 snprintf(hdr, sizeof(hdr), "Action-%06d", x); 02524 action = astman_get_header(m, hdr); 02525 if (ast_strlen_zero(action)) /* breaks the for loop if no action header */ 02526 break; /* this could cause problems if actions come in misnumbered */ 02527 02528 snprintf(hdr, sizeof(hdr), "Cat-%06d", x); 02529 cat = astman_get_header(m, hdr); 02530 if (ast_strlen_zero(cat)) { /* every action needs a category */ 02531 result = UNSPECIFIED_CATEGORY; 02532 break; 02533 } 02534 02535 snprintf(hdr, sizeof(hdr), "Var-%06d", x); 02536 var = astman_get_header(m, hdr); 02537 02538 snprintf(hdr, sizeof(hdr), "Value-%06d", x); 02539 value = astman_get_header(m, hdr); 02540 02541 if (!ast_strlen_zero(value) && *value == '>') { 02542 object = 1; 02543 value++; 02544 } 02545 02546 snprintf(hdr, sizeof(hdr), "Match-%06d", x); 02547 match = astman_get_header(m, hdr); 02548 02549 snprintf(hdr, sizeof(hdr), "Line-%06d", x); 02550 line = astman_get_header(m, hdr); 02551 02552 if (!strcasecmp(action, "newcat")) { 02553 if (ast_category_get(cfg,cat)) { /* check to make sure the cat doesn't */ 02554 result = FAILURE_NEWCAT; /* already exist */ 02555 break; 02556 } 02557 if (!(category = ast_category_new(cat, dfn, -1))) { 02558 result = FAILURE_ALLOCATION; 02559 break; 02560 } 02561 if (ast_strlen_zero(match)) { 02562 ast_category_append(cfg, category); 02563 } else { 02564 ast_category_insert(cfg, category, match); 02565 } 02566 } else if (!strcasecmp(action, "renamecat")) { 02567 if (ast_strlen_zero(value)) { 02568 result = UNSPECIFIED_ARGUMENT; 02569 break; 02570 } 02571 if (!(category = ast_category_get(cfg, cat))) { 02572 result = UNKNOWN_CATEGORY; 02573 break; 02574 } 02575 ast_category_rename(category, value); 02576 } else if (!strcasecmp(action, "delcat")) { 02577 if (ast_category_delete(cfg, cat)) { 02578 result = FAILURE_DELCAT; 02579 break; 02580 } 02581 } else if (!strcasecmp(action, "emptycat")) { 02582 if (ast_category_empty(cfg, cat)) { 02583 result = FAILURE_EMPTYCAT; 02584 break; 02585 } 02586 } else if (!strcasecmp(action, "update")) { 02587 if (ast_strlen_zero(var)) { 02588 result = UNSPECIFIED_ARGUMENT; 02589 break; 02590 } 02591 if (!(category = ast_category_get(cfg,cat))) { 02592 result = UNKNOWN_CATEGORY; 02593 break; 02594 } 02595 if (ast_variable_update(category, var, value, match, object)) { 02596 result = FAILURE_UPDATE; 02597 break; 02598 } 02599 } else if (!strcasecmp(action, "delete")) { 02600 if ((ast_strlen_zero(var) && ast_strlen_zero(line))) { 02601 result = UNSPECIFIED_ARGUMENT; 02602 break; 02603 } 02604 if (!(category = ast_category_get(cfg, cat))) { 02605 result = UNKNOWN_CATEGORY; 02606 break; 02607 } 02608 if (ast_variable_delete(category, var, match, line)) { 02609 result = FAILURE_DELETE; 02610 break; 02611 } 02612 } else if (!strcasecmp(action, "append")) { 02613 if (ast_strlen_zero(var)) { 02614 result = UNSPECIFIED_ARGUMENT; 02615 break; 02616 } 02617 if (!(category = ast_category_get(cfg, cat))) { 02618 result = UNKNOWN_CATEGORY; 02619 break; 02620 } 02621 if (!(v = ast_variable_new(var, value, dfn))) { 02622 result = FAILURE_ALLOCATION; 02623 break; 02624 } 02625 if (object || (match && !strcasecmp(match, "object"))) { 02626 v->object = 1; 02627 } 02628 ast_variable_append(category, v); 02629 } else if (!strcasecmp(action, "insert")) { 02630 if (ast_strlen_zero(var) || ast_strlen_zero(line)) { 02631 result = UNSPECIFIED_ARGUMENT; 02632 break; 02633 } 02634 if (!(category = ast_category_get(cfg, cat))) { 02635 result = UNKNOWN_CATEGORY; 02636 break; 02637 } 02638 if (!(v = ast_variable_new(var, value, dfn))) { 02639 result = FAILURE_ALLOCATION; 02640 break; 02641 } 02642 ast_variable_insert(category, v, line); 02643 } 02644 else { 02645 ast_log(LOG_WARNING, "Action-%06d: %s not handled\n", x, action); 02646 result = UNKNOWN_ACTION; 02647 break; 02648 } 02649 } 02650 ast_free(str1); 02651 ast_free(str2); 02652 return result; 02653 }
| 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 2429 of file manager.c.
Referenced by action_getconfigjson().
02430 { 02431 for (; *in; in++) { 02432 if (*in == '\\' || *in == '\"') { 02433 *out++ = '\\'; 02434 } 02435 *out++ = *in; 02436 } 02437 *out = '\0'; 02438 }
| static int manager_displayconnects | ( | struct mansession_session * | session | ) | [static] |
Get displayconnects config option.
| session | manager session to get parameter from. |
Definition at line 1346 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().
01347 { 01348 struct ast_manager_user *user = NULL; 01349 int ret = 0; 01350 01351 AST_RWLIST_RDLOCK(&users); 01352 if ((user = get_manager_by_name_locked (session->username))) { 01353 ret = user->displayconnects; 01354 } 01355 AST_RWLIST_UNLOCK(&users); 01356 01357 return ret; 01358 }
| static int manager_modulecheck | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 4322 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().
04323 { 04324 int res; 04325 const char *module = astman_get_header(m, "Module"); 04326 const char *id = astman_get_header(m, "ActionID"); 04327 char idText[256]; 04328 #if !defined(LOW_MEMORY) 04329 const char *version; 04330 #endif 04331 char filename[PATH_MAX]; 04332 char *cut; 04333 04334 ast_copy_string(filename, module, sizeof(filename)); 04335 if ((cut = strchr(filename, '.'))) { 04336 *cut = '\0'; 04337 } else { 04338 cut = filename + strlen(filename); 04339 } 04340 snprintf(cut, (sizeof(filename) - strlen(filename)) - 1, ".so"); 04341 ast_log(LOG_DEBUG, "**** ModuleCheck .so file %s\n", filename); 04342 res = ast_module_check(filename); 04343 if (!res) { 04344 astman_send_error(s, m, "Module not loaded"); 04345 return 0; 04346 } 04347 snprintf(cut, (sizeof(filename) - strlen(filename)) - 1, ".c"); 04348 ast_log(LOG_DEBUG, "**** ModuleCheck .c file %s\n", filename); 04349 #if !defined(LOW_MEMORY) 04350 version = ast_file_version_find(filename); 04351 #endif 04352 04353 if (!ast_strlen_zero(id)) { 04354 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id); 04355 } else { 04356 idText[0] = '\0'; 04357 } 04358 astman_append(s, "Response: Success\r\n%s", idText); 04359 #if !defined(LOW_MEMORY) 04360 astman_append(s, "Version: %s\r\n\r\n", version ? version : ""); 04361 #endif 04362 return 0; 04363 }
| static int manager_moduleload | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 4365 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().
04366 { 04367 int res; 04368 const char *module = astman_get_header(m, "Module"); 04369 const char *loadtype = astman_get_header(m, "LoadType"); 04370 04371 if (!loadtype || strlen(loadtype) == 0) { 04372 astman_send_error(s, m, "Incomplete ModuleLoad action."); 04373 } 04374 if ((!module || strlen(module) == 0) && strcasecmp(loadtype, "reload") != 0) { 04375 astman_send_error(s, m, "Need module name"); 04376 } 04377 04378 if (!strcasecmp(loadtype, "load")) { 04379 res = ast_load_resource(module); 04380 if (res) { 04381 astman_send_error(s, m, "Could not load module."); 04382 } else { 04383 astman_send_ack(s, m, "Module loaded."); 04384 } 04385 } else if (!strcasecmp(loadtype, "unload")) { 04386 res = ast_unload_resource(module, AST_FORCE_SOFT); 04387 if (res) { 04388 astman_send_error(s, m, "Could not unload module."); 04389 } else { 04390 astman_send_ack(s, m, "Module unloaded."); 04391 } 04392 } else if (!strcasecmp(loadtype, "reload")) { 04393 if (module != NULL) { 04394 res = ast_module_reload(module); 04395 if (res == 0) { 04396 astman_send_error(s, m, "No such module."); 04397 } else if (res == 1) { 04398 astman_send_error(s, m, "Module does not support reload action."); 04399 } else { 04400 astman_send_ack(s, m, "Module reloaded."); 04401 } 04402 } else { 04403 ast_module_reload(NULL); /* Reload all modules */ 04404 astman_send_ack(s, m, "All modules reloaded"); 04405 } 04406 } else 04407 astman_send_error(s, m, "Incomplete ModuleLoad action."); 04408 return 0; 04409 }
| static int manager_state_cb | ( | char * | context, | |
| char * | exten, | |||
| int | state, | |||
| void * | data | |||
| ) | [static] |
Definition at line 4906 of file manager.c.
References ast_get_hint(), EVENT_FLAG_CALL, and manager_event.
Referenced by __init_manager().
04907 { 04908 /* Notify managers of change */ 04909 char hint[512]; 04910 ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, context, exten); 04911 04912 manager_event(EVENT_FLAG_CALL, "ExtensionStatus", "Exten: %s\r\nContext: %s\r\nHint: %s\r\nStatus: %d\r\n", exten, context, hint, state); 04913 return 0; 04914 }
| static int mansession_cmp_fn | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 1298 of file manager.c.
References CMP_MATCH, str, and mansession_session::username.
Referenced by __init_manager().
01299 { 01300 struct mansession_session *s = obj; 01301 char *str = arg; 01302 return !strcasecmp(s->username, str) ? CMP_MATCH : 0; 01303 }
| static struct sockaddr_in* mansession_encode_sin_local | ( | const struct mansession * | s, | |
| struct sockaddr_in * | sin_local | |||
| ) | [static, read] |
Definition at line 1996 of file manager.c.
References ast_sockaddr_to_sin, ast_tcptls_session_args::local_address, ast_tcptls_session_instance::parent, and mansession::tcptls_session.
Referenced by report_auth_success(), report_failed_acl(), report_failed_challenge_response(), report_inval_password(), report_invalid_user(), report_req_bad_format(), report_req_not_allowed(), and report_session_limit().
01998 { 01999 ast_sockaddr_to_sin(&s->tcptls_session->parent->local_address, 02000 sin_local); 02001 02002 return sin_local; 02003 }
| static enum ast_security_event_transport_type mansession_get_transport | ( | const struct mansession * | s | ) | [static] |
Definition at line 1990 of file manager.c.
References AST_SECURITY_EVENT_TRANSPORT_TCP, AST_SECURITY_EVENT_TRANSPORT_TLS, ast_tcptls_session_instance::parent, mansession::tcptls_session, and ast_tcptls_session_args::tls_cfg.
Referenced by report_auth_success(), report_failed_acl(), report_failed_challenge_response(), report_inval_password(), report_invalid_user(), report_req_bad_format(), report_req_not_allowed(), and report_session_limit().
01991 { 01992 return s->tcptls_session->parent->tls_cfg ? AST_SECURITY_EVENT_TRANSPORT_TLS : 01993 AST_SECURITY_EVENT_TRANSPORT_TCP; 01994 }
| static void mansession_lock | ( | struct mansession * | s | ) | [static] |
Lock the 'mansession' structure.
Definition at line 1962 of file manager.c.
References ast_mutex_lock, and mansession::lock.
Referenced by action_challenge(), and process_message().
01963 { 01964 ast_mutex_lock(&s->lock); 01965 }
| static void mansession_unlock | ( | struct mansession * | s | ) | [static] |
Unlock the 'mansession' structure.
Definition at line 1968 of file manager.c.
References ast_mutex_unlock, and mansession::lock.
Referenced by action_challenge(), and process_message().
01969 { 01970 ast_mutex_unlock(&s->lock); 01971 }
| static int match_filter | ( | struct mansession * | s, | |
| char * | eventdata | |||
| ) | [static] |
Definition at line 4073 of file manager.c.
References ao2_container_count(), ao2_t_callback_data, ast_debug, blackfilter_cmp_fn(), mansession_session::blackfilters, OBJ_NODATA, mansession::session, whitefilter_cmp_fn(), and mansession_session::whitefilters.
Referenced by process_events().
04074 { 04075 int result = 0; 04076 04077 ast_debug(3, "Examining event:\n%s\n", eventdata); 04078 if (!ao2_container_count(s->session->whitefilters) && !ao2_container_count(s->session->blackfilters)) { 04079 return 1; /* no filtering means match all */ 04080 } else if (ao2_container_count(s->session->whitefilters) && !ao2_container_count(s->session->blackfilters)) { 04081 /* white filters only: implied black all filter processed first, then white filters */ 04082 ao2_t_callback_data(s->session->whitefilters, OBJ_NODATA, whitefilter_cmp_fn, eventdata, &result, "find filter in session filter container"); 04083 } else if (!ao2_container_count(s->session->whitefilters) && ao2_container_count(s->session->blackfilters)) { 04084 /* black filters only: implied white all filter processed first, then black filters */ 04085 ao2_t_callback_data(s->session->blackfilters, OBJ_NODATA, blackfilter_cmp_fn, eventdata, &result, "find filter in session filter container"); 04086 } else { 04087 /* white and black filters: implied black all filter processed first, then white filters, and lastly black filters */ 04088 ao2_t_callback_data(s->session->whitefilters, OBJ_NODATA, whitefilter_cmp_fn, eventdata, &result, "find filter in session filter container"); 04089 if (result) { 04090 result = 0; 04091 ao2_t_callback_data(s->session->blackfilters, OBJ_NODATA, blackfilter_cmp_fn, eventdata, &result, "find filter in session filter container"); 04092 } 04093 } 04094 04095 return result; 04096 }
| 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 4103 of file manager.c.
References advance_event(), ao2_lock, ao2_unlock, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, mansession_session::authenticated, eventqent::category, eventqent::eventdata, mansession_session::f, mansession_session::last_ev, match_filter(), mansession_session::readperm, mansession_session::send_events, send_string(), and mansession::session.
Referenced by do_message(), and process_message().
04104 { 04105 int ret = 0; 04106 04107 ao2_lock(s->session); 04108 if (s->session->f != NULL) { 04109 struct eventqent *eqe = s->session->last_ev; 04110 AST_RWLIST_RDLOCK(&all_events); 04111 while ((eqe = advance_event(eqe))) { 04112 if (!ret && s->session->authenticated && 04113 (s->session->readperm & eqe->category) == eqe->category && 04114 (s->session->send_events & eqe->category) == eqe->category) { 04115 if (match_filter(s, eqe->eventdata)) { 04116 if (send_string(s, eqe->eventdata) < 0) 04117 ret = -1; /* don't send more */ 04118 } 04119 } 04120 s->session->last_ev = eqe; 04121 } 04122 AST_RWLIST_UNLOCK(&all_events); 04123 } 04124 ao2_unlock(s->session); 04125 return ret; 04126 }
| static int process_message | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 4424 of file manager.c.
References __astman_get_header(), manager_action::action, ast_copy_string(), ast_debug, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strlen_zero(), astman_get_header(), astman_send_error(), mansession_session::authenticated, manager_action::authority, check_manager_session_inuse(), manager_action::func, GET_HEADER_SKIP_EMPTY, mansession_lock(), mansession_unlock(), process_events(), report_req_bad_format(), report_req_not_allowed(), report_session_limit(), mansession::session, and mansession_session::writeperm.
Referenced by auth_http_callback(), do_message(), and generic_http_callback().
04425 { 04426 char action[80] = ""; 04427 int ret = 0; 04428 struct manager_action *tmp; 04429 const char *user = astman_get_header(m, "Username"); 04430 int (*call_func)(struct mansession *s, const struct message *m) = NULL; 04431 04432 ast_copy_string(action, __astman_get_header(m, "Action", GET_HEADER_SKIP_EMPTY), sizeof(action)); 04433 04434 if (ast_strlen_zero(action)) { 04435 report_req_bad_format(s, "NONE"); 04436 mansession_lock(s); 04437 astman_send_error(s, m, "Missing action in request"); 04438 mansession_unlock(s); 04439 return 0; 04440 } 04441 04442 if (!s->session->authenticated && strcasecmp(action, "Login") && strcasecmp(action, "Logoff") && strcasecmp(action, "Challenge")) { 04443 if (!s->session->authenticated) { 04444 report_req_not_allowed(s, action); 04445 } 04446 mansession_lock(s); 04447 astman_send_error(s, m, "Permission denied"); 04448 mansession_unlock(s); 04449 return 0; 04450 } 04451 04452 if (!allowmultiplelogin && !s->session->authenticated && user && 04453 (!strcasecmp(action, "Login") || !strcasecmp(action, "Challenge"))) { 04454 if (check_manager_session_inuse(user)) { 04455 report_session_limit(s); 04456 sleep(1); 04457 mansession_lock(s); 04458 astman_send_error(s, m, "Login Already In Use"); 04459 mansession_unlock(s); 04460 return -1; 04461 } 04462 } 04463 04464 AST_RWLIST_RDLOCK(&actions); 04465 AST_RWLIST_TRAVERSE(&actions, tmp, list) { 04466 if (strcasecmp(action, tmp->action)) { 04467 continue; 04468 } 04469 if (s->session->writeperm & tmp->authority || tmp->authority == 0) { 04470 call_func = tmp->func; 04471 } else { 04472 astman_send_error(s, m, "Permission denied"); 04473 report_req_not_allowed(s, action); 04474 } 04475 break; 04476 } 04477 AST_RWLIST_UNLOCK(&actions); 04478 04479 if (tmp && call_func) { 04480 /* call AMI function after actions list are unlocked */ 04481 ast_debug(1, "Running action '%s'\n", tmp->action); 04482 ret = call_func(s, m); 04483 } else { 04484 char buf[512]; 04485 if (!tmp) { 04486 report_req_bad_format(s, action); 04487 } 04488 snprintf(buf, sizeof(buf), "Invalid/unknown command: %s. Use Action: ListCommands to show available commands.", action); 04489 mansession_lock(s); 04490 astman_send_error(s, m, buf); 04491 mansession_unlock(s); 04492 } 04493 if (ret) { 04494 return ret; 04495 } 04496 /* Once done with our message, deliver any pending events unless the 04497 requester doesn't want them as part of this response. 04498 */ 04499 if (ast_strlen_zero(astman_get_header(m, "SuppressEvents"))) { 04500 return process_events(s); 04501 } else { 04502 return ret; 04503 } 04504 }
| 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 1071 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().
01072 { 01073 struct eventqent *ev; 01074 struct timeval now = ast_tvnow(); 01075 01076 AST_RWLIST_WRLOCK(&all_events); 01077 while ( (ev = AST_RWLIST_FIRST(&all_events)) && 01078 ev->usecount == 0 && AST_RWLIST_NEXT(ev, eq_next)) { 01079 AST_RWLIST_REMOVE_HEAD(&all_events, eq_next); 01080 ast_free(ev); 01081 } 01082 01083 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&all_events, ev, eq_next) { 01084 /* Never release the last event */ 01085 if (!AST_RWLIST_NEXT(ev, eq_next)) { 01086 break; 01087 } 01088 01089 /* 2.5 times whatever the HTTP timeout is (maximum 2.5 hours) is the maximum time that we will definitely cache an event */ 01090 if (ev->usecount == 0 && ast_tvdiff_sec(now, ev->tv) > (httptimeout > 3600 ? 3600 : httptimeout) * 2.5) { 01091 AST_RWLIST_REMOVE_CURRENT(eq_next); 01092 ast_free(ev); 01093 } 01094 } 01095 AST_RWLIST_TRAVERSE_SAFE_END; 01096 AST_RWLIST_UNLOCK(&all_events); 01097 }
| static void purge_sessions | ( | int | n_max | ) | [static] |
remove at most n_max stale session from the list.
Definition at line 4716 of file manager.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_unlock, ast_inet_ntoa(), ast_verb, mansession_session::authenticated, mansession_session::inuse, manager_displayconnects(), session_destroy(), mansession_session::sessiontimeout, mansession_session::sin, unref_mansession(), mansession_session::username, and VERBOSITY_ATLEAST.
Referenced by purge_old_stuff().
04717 { 04718 struct mansession_session *session; 04719 time_t now = time(NULL); 04720 struct ao2_iterator i; 04721 04722 i = ao2_iterator_init(sessions, 0); 04723 while ((session = ao2_iterator_next(&i)) && n_max > 0) { 04724 ao2_lock(session); 04725 if (session->sessiontimeout && (now > session->sessiontimeout) && !session->inuse) { 04726 if (session->authenticated && (VERBOSITY_ATLEAST(2)) && manager_displayconnects(session)) { 04727 ast_verb(2, "HTTP Manager '%s' timed out from %s\n", 04728 session->username, ast_inet_ntoa(session->sin.sin_addr)); 04729 } 04730 ao2_unlock(session); 04731 session_destroy(session); 04732 n_max--; 04733 } else { 04734 ao2_unlock(session); 04735 unref_mansession(session); 04736 } 04737 } 04738 ao2_iterator_destroy(&i); 04739 }
| static void report_auth_success | ( | const struct mansession * | s | ) | [static] |
Definition at line 2083 of file manager.c.
References AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_SUCCESSFUL_AUTH, AST_SECURITY_EVENT_SUCCESSFUL_AUTH_VERSION, ast_security_event_successful_auth::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, mansession_session::sin, and mansession_session::username.
Referenced by authenticate().
02084 { 02085 struct sockaddr_in sin_local; 02086 char session_id[32]; 02087 struct ast_security_event_successful_auth successful_auth = { 02088 .common.event_type = AST_SECURITY_EVENT_SUCCESSFUL_AUTH, 02089 .common.version = AST_SECURITY_EVENT_SUCCESSFUL_AUTH_VERSION, 02090 .common.service = "AMI", 02091 .common.account_id = s->session->username, 02092 .common.session_tv = &s->session->sessionstart_tv, 02093 .common.local_addr = { 02094 .sin = mansession_encode_sin_local(s, &sin_local), 02095 .transport = mansession_get_transport(s), 02096 }, 02097 .common.remote_addr = { 02098 .sin = &s->session->sin, 02099 .transport = mansession_get_transport(s), 02100 }, 02101 .common.session_id = session_id, 02102 }; 02103 02104 snprintf(session_id, sizeof(session_id), "%p", s->session); 02105 02106 ast_security_event_report(AST_SEC_EVT(&successful_auth)); 02107 }
| static void report_failed_acl | ( | const struct mansession * | s, | |
| const char * | username | |||
| ) | [static] |
Definition at line 2031 of file manager.c.
References AST_SEC_EVT, AST_SECURITY_EVENT_FAILED_ACL, AST_SECURITY_EVENT_FAILED_ACL_VERSION, ast_security_event_report(), ast_security_event_failed_acl::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, and mansession_session::sin.
Referenced by authenticate().
02032 { 02033 struct sockaddr_in sin_local; 02034 char session_id[32]; 02035 struct ast_security_event_failed_acl failed_acl_event = { 02036 .common.event_type = AST_SECURITY_EVENT_FAILED_ACL, 02037 .common.version = AST_SECURITY_EVENT_FAILED_ACL_VERSION, 02038 .common.service = "AMI", 02039 .common.account_id = username, 02040 .common.session_tv = &s->session->sessionstart_tv, 02041 .common.local_addr = { 02042 .sin = mansession_encode_sin_local(s, &sin_local), 02043 .transport = mansession_get_transport(s), 02044 }, 02045 .common.remote_addr = { 02046 .sin = &s->session->sin, 02047 .transport = mansession_get_transport(s), 02048 }, 02049 .common.session_id = session_id, 02050 }; 02051 02052 snprintf(session_id, sizeof(session_id), "%p", s->session); 02053 02054 ast_security_event_report(AST_SEC_EVT(&failed_acl_event)); 02055 }
| static void report_failed_challenge_response | ( | const struct mansession * | s, | |
| const char * | response, | |||
| const char * | expected_response | |||
| ) | [static] |
Definition at line 2169 of file manager.c.
References AST_SEC_EVT, AST_SECURITY_EVENT_CHAL_RESP_FAILED, AST_SECURITY_EVENT_CHAL_RESP_FAILED_VERSION, ast_security_event_report(), mansession_session::challenge, ast_security_event_chal_resp_failed::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, mansession_session::sin, and mansession_session::username.
Referenced by authenticate().
02171 { 02172 struct sockaddr_in sin_local; 02173 char session_id[32]; 02174 struct ast_security_event_chal_resp_failed chal_resp_failed = { 02175 .common.event_type = AST_SECURITY_EVENT_CHAL_RESP_FAILED, 02176 .common.version = AST_SECURITY_EVENT_CHAL_RESP_FAILED_VERSION, 02177 .common.service = "AMI", 02178 .common.account_id = s->session->username, 02179 .common.session_tv = &s->session->sessionstart_tv, 02180 .common.local_addr = { 02181 .sin = mansession_encode_sin_local(s, &sin_local), 02182 .transport = mansession_get_transport(s), 02183 }, 02184 .common.remote_addr = { 02185 .sin = &s->session->sin, 02186 .transport = mansession_get_transport(s), 02187 }, 02188 .common.session_id = session_id, 02189 02190 .challenge = s->session->challenge, 02191 .response = response, 02192 .expected_response = expected_response, 02193 }; 02194 02195 snprintf(session_id, sizeof(session_id), "%p", s->session); 02196 02197 ast_security_event_report(AST_SEC_EVT(&chal_resp_failed)); 02198 }
| static void report_inval_password | ( | const struct mansession * | s, | |
| const char * | username | |||
| ) | [static] |
Definition at line 2057 of file manager.c.
References AST_SEC_EVT, AST_SECURITY_EVENT_INVAL_PASSWORD, AST_SECURITY_EVENT_INVAL_PASSWORD_VERSION, ast_security_event_report(), ast_security_event_inval_password::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, and mansession_session::sin.
Referenced by authenticate().
02058 { 02059 struct sockaddr_in sin_local; 02060 char session_id[32]; 02061 struct ast_security_event_inval_password inval_password = { 02062 .common.event_type = AST_SECURITY_EVENT_INVAL_PASSWORD, 02063 .common.version = AST_SECURITY_EVENT_INVAL_PASSWORD_VERSION, 02064 .common.service = "AMI", 02065 .common.account_id = username, 02066 .common.session_tv = &s->session->sessionstart_tv, 02067 .common.local_addr = { 02068 .sin = mansession_encode_sin_local(s, &sin_local), 02069 .transport = mansession_get_transport(s), 02070 }, 02071 .common.remote_addr = { 02072 .sin = &s->session->sin, 02073 .transport = mansession_get_transport(s), 02074 }, 02075 .common.session_id = session_id, 02076 }; 02077 02078 snprintf(session_id, sizeof(session_id), "%p", s->session); 02079 02080 ast_security_event_report(AST_SEC_EVT(&inval_password)); 02081 }
| static void report_invalid_user | ( | const struct mansession * | s, | |
| const char * | username | |||
| ) | [static] |
Definition at line 2005 of file manager.c.
References AST_SEC_EVT, AST_SECURITY_EVENT_INVAL_ACCT_ID, AST_SECURITY_EVENT_INVAL_ACCT_ID_VERSION, ast_security_event_report(), ast_security_event_inval_acct_id::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, and mansession_session::sin.
Referenced by authenticate().
02006 { 02007 struct sockaddr_in sin_local; 02008 char session_id[32]; 02009 struct ast_security_event_inval_acct_id inval_acct_id = { 02010 .common.event_type = AST_SECURITY_EVENT_INVAL_ACCT_ID, 02011 .common.version = AST_SECURITY_EVENT_INVAL_ACCT_ID_VERSION, 02012 .common.service = "AMI", 02013 .common.account_id = username, 02014 .common.session_tv = &s->session->sessionstart_tv, 02015 .common.local_addr = { 02016 .sin = mansession_encode_sin_local(s, &sin_local), 02017 .transport = mansession_get_transport(s), 02018 }, 02019 .common.remote_addr = { 02020 .sin = &s->session->sin, 02021 .transport = mansession_get_transport(s), 02022 }, 02023 .common.session_id = session_id, 02024 }; 02025 02026 snprintf(session_id, sizeof(session_id), "%p", s); 02027 02028 ast_security_event_report(AST_SEC_EVT(&inval_acct_id)); 02029 }
| static void report_req_bad_format | ( | const struct mansession * | s, | |
| const char * | action | |||
| ) | [static] |
Definition at line 2139 of file manager.c.
References AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_REQ_BAD_FORMAT, AST_SECURITY_EVENT_REQ_BAD_FORMAT_VERSION, ast_security_event_req_bad_format::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, mansession_session::sin, and mansession_session::username.
Referenced by process_message().
02140 { 02141 struct sockaddr_in sin_local; 02142 char session_id[32]; 02143 char request_type[64]; 02144 struct ast_security_event_req_bad_format req_bad_format = { 02145 .common.event_type = AST_SECURITY_EVENT_REQ_BAD_FORMAT, 02146 .common.version = AST_SECURITY_EVENT_REQ_BAD_FORMAT_VERSION, 02147 .common.service = "AMI", 02148 .common.account_id = s->session->username, 02149 .common.session_tv = &s->session->sessionstart_tv, 02150 .common.local_addr = { 02151 .sin = mansession_encode_sin_local(s, &sin_local), 02152 .transport = mansession_get_transport(s), 02153 }, 02154 .common.remote_addr = { 02155 .sin = &s->session->sin, 02156 .transport = mansession_get_transport(s), 02157 }, 02158 .common.session_id = session_id, 02159 02160 .request_type = request_type, 02161 }; 02162 02163 snprintf(session_id, sizeof(session_id), "%p", s->session); 02164 snprintf(request_type, sizeof(request_type), "Action: %s", action); 02165 02166 ast_security_event_report(AST_SEC_EVT(&req_bad_format)); 02167 }
| static void report_req_not_allowed | ( | const struct mansession * | s, | |
| const char * | action | |||
| ) | [static] |
Definition at line 2109 of file manager.c.
References AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_REQ_NOT_ALLOWED, AST_SECURITY_EVENT_REQ_NOT_ALLOWED_VERSION, ast_security_event_req_not_allowed::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, mansession_session::sin, and mansession_session::username.
Referenced by process_message().
02110 { 02111 struct sockaddr_in sin_local; 02112 char session_id[32]; 02113 char request_type[64]; 02114 struct ast_security_event_req_not_allowed req_not_allowed = { 02115 .common.event_type = AST_SECURITY_EVENT_REQ_NOT_ALLOWED, 02116 .common.version = AST_SECURITY_EVENT_REQ_NOT_ALLOWED_VERSION, 02117 .common.service = "AMI", 02118 .common.account_id = s->session->username, 02119 .common.session_tv = &s->session->sessionstart_tv, 02120 .common.local_addr = { 02121 .sin = mansession_encode_sin_local(s, &sin_local), 02122 .transport = mansession_get_transport(s), 02123 }, 02124 .common.remote_addr = { 02125 .sin = &s->session->sin, 02126 .transport = mansession_get_transport(s), 02127 }, 02128 .common.session_id = session_id, 02129 02130 .request_type = request_type, 02131 }; 02132 02133 snprintf(session_id, sizeof(session_id), "%p", s->session); 02134 snprintf(request_type, sizeof(request_type), "Action: %s", action); 02135 02136 ast_security_event_report(AST_SEC_EVT(&req_not_allowed)); 02137 }
| static void report_session_limit | ( | const struct mansession * | s | ) | [static] |
Definition at line 2200 of file manager.c.
References AST_SEC_EVT, ast_security_event_report(), AST_SECURITY_EVENT_SESSION_LIMIT, AST_SECURITY_EVENT_SESSION_LIMIT_VERSION, ast_security_event_session_limit::common, ast_security_event_common::event_type, mansession_encode_sin_local(), mansession_get_transport(), mansession::session, mansession_session::sessionstart_tv, mansession_session::sin, and mansession_session::username.
Referenced by process_message().
02201 { 02202 struct sockaddr_in sin_local; 02203 char session_id[32]; 02204 struct ast_security_event_session_limit session_limit = { 02205 .common.event_type = AST_SECURITY_EVENT_SESSION_LIMIT, 02206 .common.version = AST_SECURITY_EVENT_SESSION_LIMIT_VERSION, 02207 .common.service = "AMI", 02208 .common.account_id = s->session->username, 02209 .common.session_tv = &s->session->sessionstart_tv, 02210 .common.local_addr = { 02211 .sin = mansession_encode_sin_local(s, &sin_local), 02212 .transport = mansession_get_transport(s), 02213 }, 02214 .common.remote_addr = { 02215 .sin = &s->session->sin, 02216 .transport = mansession_get_transport(s), 02217 }, 02218 .common.session_id = session_id, 02219 }; 02220 02221 snprintf(session_id, sizeof(session_id), "%p", s->session); 02222 02223 ast_security_event_report(AST_SEC_EVT(&session_limit)); 02224 }
| 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 1846 of file manager.c.
References ast_careful_fwrite(), EVENT_FLAG_HOOKRESPONSE, mansession_session::f, mansession::f, mansession_session::fd, mansession::fd, manager_custom_hook::helper, mansession::hook, mansession::session, and mansession_session::writetimeout.
Referenced by astman_append(), and process_events().
01847 { 01848 /* It's a result from one of the hook's action invocation */ 01849 if (s->hook) { 01850 /* 01851 * to send responses, we're using the same function 01852 * as for receiving events. We call the event "HookResponse" 01853 */ 01854 s->hook->helper(EVENT_FLAG_HOOKRESPONSE, "HookResponse", string); 01855 return 0; 01856 } else if (s->f) { 01857 return ast_careful_fwrite(s->f, s->fd, string, strlen(string), s->session->writetimeout); 01858 } else { 01859 return ast_careful_fwrite(s->session->f, s->session->fd, string, strlen(string), s->session->writetimeout); 01860 } 01861 }
| static void session_destroy | ( | struct mansession_session * | s | ) | [static] |
Definition at line 1305 of file manager.c.
References ao2_unlink, and unref_mansession().
Referenced by auth_http_callback(), generic_http_callback(), purge_sessions(), and session_do().
01306 { 01307 unref_mansession(s); 01308 ao2_unlink(sessions, s); 01309 }
| static void session_destructor | ( | void * | obj | ) | [static] |
Definition at line 1238 of file manager.c.
References ao2_t_callback, ao2_t_ref, ast_atomic_fetchadd_int(), ast_datastore_free(), AST_LIST_REMOVE_HEAD, mansession_session::blackfilters, mansession_session::datastores, mansession_session::f, mansession_session::last_ev, OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, eventqent::usecount, and mansession_session::whitefilters.
Referenced by build_mansession().
01239 { 01240 struct mansession_session *session = obj; 01241 struct eventqent *eqe = session->last_ev; 01242 struct ast_datastore *datastore; 01243 01244 /* Get rid of each of the data stores on the session */ 01245 while ((datastore = AST_LIST_REMOVE_HEAD(&session->datastores, entry))) { 01246 /* Free the data store */ 01247 ast_datastore_free(datastore); 01248 } 01249 01250 if (session->f != NULL) { 01251 fclose(session->f); 01252 } 01253 if (eqe) { 01254 ast_atomic_fetchadd_int(&eqe->usecount, -1); 01255 } 01256 01257 if (session->whitefilters) { 01258 ao2_t_callback(session->whitefilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all white filters"); 01259 ao2_t_ref(session->whitefilters, -1 , "decrement ref for white container, should be last one"); 01260 } 01261 01262 if (session->blackfilters) { 01263 ao2_t_callback(session->blackfilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all black filters"); 01264 ao2_t_ref(session->blackfilters, -1 , "decrement ref for black container, should be last one"); 01265 } 01266 }
| 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 4621 of file manager.c.
References AMI_VERSION, ao2_lock, ao2_ref, ao2_unlock, ast_inet_ntoa(), AST_LIST_HEAD_INIT_NOLOCK, ast_log(), ast_mutex_destroy, ast_mutex_init, ast_sockaddr_to_sin, ast_verb, astman_append(), mansession_session::authenticated, block_sockets, build_mansession(), mansession_session::datastores, do_message(), errno, ast_tcptls_session_instance::f, mansession::f, mansession_session::f, mansession::fd, mansession_session::fd, ast_tcptls_session_instance::fd, ast_frame::flags, grab_last(), mansession_session::last_ev, mansession::lock, LOG_WARNING, manager_displayconnects(), ast_tcptls_session_instance::remote_address, mansession::session, session_destroy(), mansession_session::sin, and mansession_session::username.
04622 { 04623 struct ast_tcptls_session_instance *ser = data; 04624 struct mansession_session *session; 04625 struct mansession s = { 04626 .tcptls_session = data, 04627 }; 04628 int flags; 04629 int res; 04630 struct sockaddr_in ser_remote_address_tmp; 04631 struct protoent *p; 04632 04633 ast_sockaddr_to_sin(&ser->remote_address, &ser_remote_address_tmp); 04634 session = build_mansession(ser_remote_address_tmp); 04635 04636 if (session == NULL) { 04637 goto done; 04638 } 04639 04640 /* here we set TCP_NODELAY on the socket to disable Nagle's algorithm. 04641 * This is necessary to prevent delays (caused by buffering) as we 04642 * write to the socket in bits and peices. */ 04643 p = getprotobyname("tcp"); 04644 if (p) { 04645 int arg = 1; 04646 if( setsockopt(ser->fd, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) { 04647 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)); 04648 } 04649 } else { 04650 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"); 04651 } 04652 04653 flags = fcntl(ser->fd, F_GETFL); 04654 if (!block_sockets) { /* make sure socket is non-blocking */ 04655 flags |= O_NONBLOCK; 04656 } else { 04657 flags &= ~O_NONBLOCK; 04658 } 04659 fcntl(ser->fd, F_SETFL, flags); 04660 04661 ao2_lock(session); 04662 /* Hook to the tail of the event queue */ 04663 session->last_ev = grab_last(); 04664 04665 ast_mutex_init(&s.lock); 04666 04667 /* these fields duplicate those in the 'ser' structure */ 04668 session->fd = s.fd = ser->fd; 04669 session->f = s.f = ser->f; 04670 session->sin = ser_remote_address_tmp; 04671 s.session = session; 04672 04673 AST_LIST_HEAD_INIT_NOLOCK(&session->datastores); 04674 04675 ao2_unlock(session); 04676 astman_append(&s, "Asterisk Call Manager/%s\r\n", AMI_VERSION); /* welcome prompt */ 04677 for (;;) { 04678 if ((res = do_message(&s)) < 0) { 04679 break; 04680 } 04681 } 04682 /* session is over, explain why and terminate */ 04683 if (session->authenticated) { 04684 if (manager_displayconnects(session)) { 04685 ast_verb(2, "Manager '%s' logged off from %s\n", session->username, ast_inet_ntoa(session->sin.sin_addr)); 04686 } 04687 } else { 04688 if (displayconnects) { 04689 ast_verb(2, "Connect attempt from '%s' unable to authenticate\n", ast_inet_ntoa(session->sin.sin_addr)); 04690 } 04691 } 04692 04693 /* It is possible under certain circumstances for this session thread 04694 to complete its work and exit *before* the thread that created it 04695 has finished executing the ast_pthread_create_background() function. 04696 If this occurs, some versions of glibc appear to act in a buggy 04697 fashion and attempt to write data into memory that it thinks belongs 04698 to the thread but is in fact not owned by the thread (or may have 04699 been freed completely). 04700 04701 Causing this thread to yield to other threads at least one time 04702 appears to work around this bug. 04703 */ 04704 usleep(1); 04705 04706 session_destroy(session); 04707 04708 ast_mutex_destroy(&s.lock); 04709 done: 04710 ao2_ref(ser, -1); 04711 ser = NULL; 04712 return NULL; 04713 }
| 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 1977 of file manager.c.
References ao2_lock, ao2_unlock, mansession_session::send_events, mansession::session, and strings_to_mask().
Referenced by action_events(), and authenticate().
01978 { 01979 int maskint = strings_to_mask(eventmask); 01980 01981 ao2_lock(s->session); 01982 if (maskint >= 0) { 01983 s->session->send_events = maskint; 01984 } 01985 ao2_unlock(s->session); 01986 01987 return maskint; 01988 }
| 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 1192 of file manager.c.
References ARRAY_LEN, ast_false(), ast_strlen_zero(), ast_true(), get_perm(), permalias::num, and perms.
Referenced by set_eventmask().
01193 { 01194 const char *p; 01195 01196 if (ast_strlen_zero(string)) { 01197 return -1; 01198 } 01199 01200 for (p = string; *p; p++) { 01201 if (*p < '0' || *p > '9') { 01202 break; 01203 } 01204 } 01205 if (!*p) { /* all digits */ 01206 return atoi(string); 01207 } 01208 if (ast_false(string)) { 01209 return 0; 01210 } 01211 if (ast_true(string)) { /* all permissions */ 01212 int x, ret = 0; 01213 for (x = 0; x < ARRAY_LEN(perms); x++) { 01214 ret |= perms[x].num; 01215 } 01216 return ret; 01217 } 01218 return get_perm(string); 01219 }
| static struct mansession_session* unref_mansession | ( | struct mansession_session * | s | ) | [static, read] |
Unreference manager session object. If no more references, then go ahead and delete it.
Definition at line 1223 of file manager.c.
References ao2_ref, ast_log(), LOG_DEBUG, and manager_debug.
Referenced by __ast_manager_event_multichan(), astman_is_authed(), astman_verify_session_readpermissions(), astman_verify_session_writepermissions(), check_manager_session_inuse(), find_session(), find_session_by_nonce(), handle_showmanconn(), purge_sessions(), and session_destroy().
01224 { 01225 int refcount = ao2_ref(s, -1); 01226 if (manager_debug) { 01227 ast_log(LOG_DEBUG, "Mansession: %p refcount now %d\n", s, refcount - 1); 01228 } 01229 return s; 01230 }
| static int whitefilter_cmp_fn | ( | void * | obj, | |
| void * | arg, | |||
| void * | data, | |||
| int | flags | |||
| ) | [static] |
Definition at line 4045 of file manager.c.
References CMP_MATCH, and CMP_STOP.
Referenced by match_filter().
04046 { 04047 regex_t *regex_filter = obj; 04048 const char *eventdata = arg; 04049 int *result = data; 04050 04051 if (!regexec(regex_filter, eventdata, 0, NULL, 0)) { 04052 *result = 1; 04053 return (CMP_MATCH | CMP_STOP); 04054 } 04055 04056 return 0; 04057 }
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] |
Definition at line 876 of file manager.c.
Referenced by __init_manager(), handle_manager_show_settings(), and session_do().
int broken_events_action [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] |
char global_realm[MAXHOSTNAMELEN] [static] |
Default realm
Definition at line 874 of file manager.c.
Referenced by __init_manager(), and auth_http_callback().
int httptimeout [static] |
char* manager_channelvars [static] |
int manager_debug [static] |
enable some debugging code in the manager
Definition at line 878 of file manager.c.
Referenced by __ast_manager_event_multichan(), __init_manager(), handle_manager_show_settings(), handle_mandebug(), and unref_mansession().
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] |
struct ast_threadstorage manager_event_funcbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_manager_event_funcbuf , .custom_init = NULL , } [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().
struct ao2_container* sessions = NULL [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 [static] |
1.5.9