#include <stdio.h>#include <stdlib.h>#include <pthread.h>#include <string.h>#include <sys/time.h>#include <sys/types.h>#include <netdb.h>#include <sys/socket.h>#include <netinet/in.h>#include <netinet/tcp.h>#include <arpa/inet.h>#include <signal.h>#include <errno.h>#include <unistd.h>#include <asterisk/channel.h>#include <asterisk/file.h>#include <asterisk/manager.h>#include <asterisk/config.h>#include <asterisk/lock.h>#include <asterisk/logger.h>#include <asterisk/options.h>#include <asterisk/cli.h>#include <asterisk/app.h>#include <asterisk/pbx.h>#include <asterisk/md5.h>#include <asterisk/acl.h>Go to the source code of this file.
Data Structures | |
| struct | permalias |
Functions | |
| char * | astman_get_header (struct message *m, char *var) |
| void | astman_send_error (struct mansession *s, struct message *m, char *error) |
| void | astman_send_response (struct mansession *s, struct message *m, char *resp, char *msg) |
| void | astman_send_ack (struct mansession *s, struct message *m, char *msg) |
| int | manager_event (int category, char *event, char *fmt,...) |
| int | ast_manager_unregister (char *action) |
| int | ast_manager_register (char *action, int auth, int(*func)(struct mansession *s, struct message *m), char *synopsis) |
| int | init_manager (void) |
| int | reload_manager (void) |
|
||||||||||||||||||||
|
Definition at line 822 of file manager.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_verbose(), LOG_WARNING, malloc, option_verbose, and VERBOSE_PREFIX_2. Referenced by init_manager().
00824 {
00825 struct manager_action *cur = first_action, *prev = NULL;
00826
00827 ast_mutex_lock(&actionlock);
00828 while(cur) { /* Walk the list of actions */
00829 if (!strcasecmp(cur->action, action)) {
00830 ast_log(LOG_WARNING, "Manager: Action '%s' already registered\n", action);
00831 ast_mutex_unlock(&actionlock);
00832 return -1;
00833 }
00834 prev = cur;
00835 cur = cur->next;
00836 }
00837 cur = malloc( sizeof(struct manager_action) );
00838 if( !cur ) {
00839 ast_log(LOG_WARNING, "Manager: out of memory trying to register action\n");
00840 ast_mutex_unlock(&actionlock);
00841 return -1;
00842 }
00843 strncpy( cur->action, action, 255 );
00844 cur->authority = auth;
00845 cur->func = func;
00846 cur->synopsis = synopsis;
00847 cur->next = NULL;
00848
00849 if( prev ) prev->next = cur;
00850 else first_action = cur;
00851
00852 if (option_verbose > 1)
00853 ast_verbose(VERBOSE_PREFIX_2 "Manager registered action %s\n", action);
00854 ast_mutex_unlock(&actionlock);
00855 return 0;
00856 }
|
|
|
Definition at line 795 of file manager.c. References ast_mutex_lock, ast_mutex_unlock, ast_verbose(), free, option_verbose, and VERBOSE_PREFIX_2.
00795 {
00796 struct manager_action *cur = first_action, *prev = first_action;
00797
00798 ast_mutex_lock(&actionlock);
00799 while( cur ) {
00800 if (!strcasecmp(action, cur->action)) {
00801 prev->next = cur->next;
00802 free(cur);
00803 if (option_verbose > 1)
00804 ast_verbose(VERBOSE_PREFIX_2 "Manager unregistered action %s\n", action);
00805 ast_mutex_unlock(&actionlock);
00806 return 0;
00807 }
00808 prev = cur;
00809 cur = cur->next;
00810 }
00811 ast_mutex_unlock(&actionlock);
00812 return 0;
00813 }
|
|
||||||||||||
|
Definition at line 139 of file manager.c. References message::hdrcount, and message::headers. Referenced by astman_send_error(), and astman_send_response().
|
|
||||||||||||||||
|
Definition at line 175 of file manager.c. References astman_send_response(), and s.
00176 {
00177 astman_send_response(s, m, "Success", msg);
00178 }
|
|
||||||||||||||||
|
Definition at line 150 of file manager.c. References ast_cli(), ast_mutex_lock, ast_mutex_unlock, astman_get_header(), and s.
00151 {
00152 char *id = astman_get_header(m,"ActionID");
00153 ast_mutex_lock(&s->lock);
00154 ast_cli(s->fd, "Response: Error\r\n");
00155 if (id && strlen(id))
00156 ast_cli(s->fd, "ActionID: %s\r\n",id);
00157 ast_cli(s->fd, "Message: %s\r\n\r\n", error);
00158 ast_mutex_unlock(&s->lock);
00159 }
|
|
||||||||||||||||||||
|
Definition at line 161 of file manager.c. References ast_cli(), ast_mutex_lock, ast_mutex_unlock, astman_get_header(), and s. Referenced by astman_send_ack().
00162 {
00163 char *id = astman_get_header(m,"ActionID");
00164 ast_mutex_lock(&s->lock);
00165 ast_cli(s->fd, "Response: %s\r\n", resp);
00166 if (id && strlen(id))
00167 ast_cli(s->fd, "ActionID: %s\r\n",id);
00168 if (msg)
00169 ast_cli(s->fd, "Message: %s\r\n\r\n", msg);
00170 else
00171 ast_cli(s->fd, "\r\n");
00172 ast_mutex_unlock(&s->lock);
00173 }
|
|
|
Definition at line 860 of file manager.c. References ast_cli_register(), ast_destroy(), ast_extension_state_add(), ast_load(), ast_log(), ast_manager_register(), ast_true(), ast_variable_retrieve(), ast_verbose(), DEFAULT_MANAGER_PORT, EVENT_FLAG_CALL, EVENT_FLAG_COMMAND, LOG_NOTICE, LOG_WARNING, and option_verbose. Referenced by main(), and reload_manager().
00861 {
00862 struct ast_config *cfg;
00863 char *val;
00864 int oldportno = portno;
00865 static struct sockaddr_in ba;
00866 int x = 1;
00867 if (!registered) {
00868 /* Register default actions */
00869 ast_manager_register( "Ping", 0, action_ping, "Ping" );
00870 ast_manager_register( "Logoff", 0, action_logoff, "Logoff Manager" );
00871 ast_manager_register( "Hangup", EVENT_FLAG_CALL, action_hangup, "Hangup Channel" );
00872 ast_manager_register( "Status", EVENT_FLAG_CALL, action_status, "Status" );
00873 ast_manager_register( "Redirect", EVENT_FLAG_CALL, action_redirect, "Redirect" );
00874 ast_manager_register( "Originate", EVENT_FLAG_CALL, action_originate, "Originate Call" );
00875 ast_manager_register( "MailboxStatus", EVENT_FLAG_CALL, action_mailboxstatus, "Check Mailbox" );
00876 ast_manager_register( "Command", EVENT_FLAG_COMMAND, action_command, "Execute Command" );
00877 ast_manager_register( "ExtensionState", EVENT_FLAG_CALL, action_extensionstate, "Check Extension Status" );
00878 ast_manager_register( "AbsoluteTimeout", EVENT_FLAG_CALL, action_timeout, "Set Absolute Timeout" );
00879 ast_manager_register( "MailboxCount", EVENT_FLAG_CALL, action_mailboxcount, "Check Mailbox Message Count" );
00880
00881 ast_cli_register(&show_mancmds_cli);
00882 ast_cli_register(&show_manconn_cli);
00883 ast_extension_state_add(NULL, NULL, manager_state_cb, NULL);
00884 registered = 1;
00885 }
00886 portno = DEFAULT_MANAGER_PORT;
00887 cfg = ast_load("manager.conf");
00888 if (!cfg) {
00889 ast_log(LOG_NOTICE, "Unable to open management configuration manager.conf. Call management disabled.\n");
00890 return 0;
00891 }
00892 memset(&ba, 0, sizeof(ba));
00893 val = ast_variable_retrieve(cfg, "general", "enabled");
00894 if (val)
00895 enabled = ast_true(val);
00896
00897 if ((val = ast_variable_retrieve(cfg, "general", "portno"))) {
00898 if (sscanf(val, "%d", &portno) != 1) {
00899 ast_log(LOG_WARNING, "Invalid port number '%s'\n", val);
00900 portno = DEFAULT_MANAGER_PORT;
00901 }
00902 }
00903
00904 ba.sin_family = AF_INET;
00905 ba.sin_port = htons(portno);
00906 memset(&ba.sin_addr, 0, sizeof(ba.sin_addr));
00907
00908 if ((val = ast_variable_retrieve(cfg, "general", "bindaddr"))) {
00909 if (!inet_aton(val, &ba.sin_addr)) {
00910 ast_log(LOG_WARNING, "Invalid address '%s' specified, using 0.0.0.0\n", val);
00911 memset(&ba.sin_addr, 0, sizeof(ba.sin_addr));
00912 }
00913 }
00914
00915 if ((asock > -1) && ((portno != oldportno) || !enabled)) {
00916 #if 0
00917 /* Can't be done yet */
00918 close(asock);
00919 asock = -1;
00920 #else
00921 ast_log(LOG_WARNING, "Unable to change management port / enabled\n");
00922 #endif
00923 }
00924 ast_destroy(cfg);
00925
00926 /* If not enabled, do nothing */
00927 if (!enabled) {
00928 return 0;
00929 }
00930 if (asock < 0) {
00931 asock = socket(AF_INET, SOCK_STREAM, 0);
00932 if (asock < 0) {
00933 ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno));
00934 return -1;
00935 }
00936 setsockopt(asock, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));
00937 if (bind(asock, (struct sockaddr *)&ba, sizeof(ba))) {
00938 ast_log(LOG_WARNING, "Unable to bind socket: %s\n", strerror(errno));
00939 close(asock);
00940 asock = -1;
00941 return -1;
00942 }
00943 if (listen(asock, 2)) {
00944 ast_log(LOG_WARNING, "Unable to listen on socket: %s\n", strerror(errno));
00945 close(asock);
00946 asock = -1;
00947 return -1;
00948 }
00949 if (option_verbose)
00950 ast_verbose("Asterisk Management interface listening on port %d\n", portno);
00951 pthread_create(&t, NULL, accept_thread, NULL);
00952 }
00953 return 0;
00954 }
|
|
||||||||||||||||||||
|
Definition at line 768 of file manager.c. References ast_cli(), ast_mutex_lock, ast_mutex_unlock, and s.
00769 {
00770 struct mansession *s;
00771 char tmp[4096];
00772 va_list ap;
00773
00774 ast_mutex_lock(&sessionlock);
00775 s = sessions;
00776 while(s) {
00777 if ((s->readperm & category) == category) {
00778 ast_mutex_lock(&s->lock);
00779 if (!s->blocking) {
00780 ast_cli(s->fd, "Event: %s\r\n", event);
00781 va_start(ap, fmt);
00782 vsnprintf(tmp, sizeof(tmp), fmt, ap);
00783 va_end(ap);
00784 write(s->fd, tmp, strlen(tmp));
00785 ast_cli(s->fd, "\r\n");
00786 }
00787 ast_mutex_unlock(&s->lock);
00788 }
00789 s = s->next;
00790 }
00791 ast_mutex_unlock(&sessionlock);
00792 return 0;
00793 }
|
|
|
Definition at line 956 of file manager.c. References EVENT_FLAG_SYSTEM, init_manager(), and manager_event(). Referenced by ast_module_reload().
00957 {
00958 manager_event(EVENT_FLAG_SYSTEM, "Reload", "Message: Reload Requested\r\n");
00959 return init_manager();
00960 }
|
1.3.5