#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 814 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().
00816 {
00817 struct manager_action *cur = first_action, *prev = NULL;
00818
00819 ast_mutex_lock(&actionlock);
00820 while(cur) { /* Walk the list of actions */
00821 prev = cur;
00822 cur = cur->next;
00823 }
00824 cur = malloc( sizeof(struct manager_action) );
00825 if( !cur ) {
00826 ast_log(LOG_WARNING, "Manager: out of memory trying to register action\n");
00827 ast_mutex_unlock(&actionlock);
00828 return -1;
00829 }
00830 strncpy( cur->action, action, 255 );
00831 cur->authority = auth;
00832 cur->func = func;
00833 cur->synopsis = synopsis;
00834 cur->next = NULL;
00835
00836 if( prev ) prev->next = cur;
00837 else first_action = cur;
00838
00839 if (option_verbose > 1)
00840 ast_verbose(VERBOSE_PREFIX_2 "Manager registered action %s\n", action);
00841 ast_mutex_unlock(&actionlock);
00842 return 0;
00843 }
|
|
|
Definition at line 787 of file manager.c. References ast_mutex_lock, ast_mutex_unlock, ast_verbose(), free, option_verbose, and VERBOSE_PREFIX_2.
00787 {
00788 struct manager_action *cur = first_action, *prev = first_action;
00789
00790 ast_mutex_lock(&actionlock);
00791 while( cur ) {
00792 if (!strcasecmp(action, cur->action)) {
00793 prev->next = cur->next;
00794 free(cur);
00795 if (option_verbose > 1)
00796 ast_verbose(VERBOSE_PREFIX_2 "Manager unregistered action %s\n", action);
00797 ast_mutex_unlock(&actionlock);
00798 return 0;
00799 }
00800 prev = cur;
00801 cur = cur->next;
00802 }
00803 ast_mutex_unlock(&actionlock);
00804 return 0;
00805 }
|
|
||||||||||||
|
Definition at line 137 of file manager.c. References message::hdrcount, and message::headers. Referenced by astman_send_error(), and astman_send_response().
|
|
||||||||||||||||
|
Definition at line 173 of file manager.c. References astman_send_response().
00174 {
00175 astman_send_response(s, m, "Success", msg);
00176 }
|
|
||||||||||||||||
|
Definition at line 148 of file manager.c. References ast_cli(), ast_mutex_lock, ast_mutex_unlock, astman_get_header(), mansession::fd, and mansession::lock.
00149 {
00150 char *id = astman_get_header(m,"ActionID");
00151 ast_mutex_lock(&s->lock);
00152 ast_cli(s->fd, "Response: Error\r\n");
00153 if (id && strlen(id))
00154 ast_cli(s->fd, "ActionID: %s\r\n",id);
00155 ast_cli(s->fd, "Message: %s\r\n\r\n", error);
00156 ast_mutex_unlock(&s->lock);
00157 }
|
|
||||||||||||||||||||
|
Definition at line 159 of file manager.c. References ast_cli(), ast_mutex_lock, ast_mutex_unlock, astman_get_header(), mansession::fd, and mansession::lock. Referenced by astman_send_ack().
00160 {
00161 char *id = astman_get_header(m,"ActionID");
00162 ast_mutex_lock(&s->lock);
00163 ast_cli(s->fd, "Response: %s\r\n", resp);
00164 if (id && strlen(id))
00165 ast_cli(s->fd, "ActionID: %s\r\n",id);
00166 if (msg)
00167 ast_cli(s->fd, "Message: %s\r\n\r\n", msg);
00168 else
00169 ast_cli(s->fd, "\r\n");
00170 ast_mutex_unlock(&s->lock);
00171 }
|
|
|
Definition at line 847 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().
00848 {
00849 struct ast_config *cfg;
00850 char *val;
00851 int oldportno = portno;
00852 static struct sockaddr_in ba;
00853 int x = 1;
00854 if (!registered) {
00855 /* Register default actions */
00856 ast_manager_register( "Ping", 0, action_ping, "Ping" );
00857 ast_manager_register( "Logoff", 0, action_logoff, "Logoff Manager" );
00858 ast_manager_register( "Hangup", EVENT_FLAG_CALL, action_hangup, "Hangup Channel" );
00859 ast_manager_register( "Status", EVENT_FLAG_CALL, action_status, "Status" );
00860 ast_manager_register( "Redirect", EVENT_FLAG_CALL, action_redirect, "Redirect" );
00861 ast_manager_register( "Originate", EVENT_FLAG_CALL, action_originate, "Originate Call" );
00862 ast_manager_register( "MailboxStatus", EVENT_FLAG_CALL, action_mailboxstatus, "Check Mailbox" );
00863 ast_manager_register( "Command", EVENT_FLAG_COMMAND, action_command, "Execute Command" );
00864 ast_manager_register( "ExtensionState", EVENT_FLAG_CALL, action_extensionstate, "Check Extension Status" );
00865 ast_manager_register( "AbsoluteTimeout", EVENT_FLAG_CALL, action_timeout, "Set Absolute Timeout" );
00866 ast_manager_register( "MailboxCount", EVENT_FLAG_CALL, action_mailboxcount, "Check Mailbox Message Count" );
00867
00868 ast_cli_register(&show_mancmds_cli);
00869 ast_cli_register(&show_manconn_cli);
00870 ast_extension_state_add(NULL, NULL, manager_state_cb, NULL);
00871 registered = 1;
00872 }
00873 portno = DEFAULT_MANAGER_PORT;
00874 cfg = ast_load("manager.conf");
00875 if (!cfg) {
00876 ast_log(LOG_NOTICE, "Unable to open management configuration manager.conf. Call management disabled.\n");
00877 return 0;
00878 }
00879 memset(&ba, 0, sizeof(ba));
00880 val = ast_variable_retrieve(cfg, "general", "enabled");
00881 if (val)
00882 enabled = ast_true(val);
00883
00884 if ((val = ast_variable_retrieve(cfg, "general", "portno"))) {
00885 if (sscanf(val, "%d", &portno) != 1) {
00886 ast_log(LOG_WARNING, "Invalid port number '%s'\n", val);
00887 portno = DEFAULT_MANAGER_PORT;
00888 }
00889 }
00890
00891 ba.sin_family = AF_INET;
00892 ba.sin_port = htons(portno);
00893 memset(&ba.sin_addr, 0, sizeof(ba.sin_addr));
00894
00895 if ((val = ast_variable_retrieve(cfg, "general", "bindaddr"))) {
00896 if (!inet_aton(val, &ba.sin_addr)) {
00897 ast_log(LOG_WARNING, "Invalid address '%s' specified, using 0.0.0.0\n", val);
00898 memset(&ba.sin_addr, 0, sizeof(ba.sin_addr));
00899 }
00900 }
00901
00902 if ((asock > -1) && ((portno != oldportno) || !enabled)) {
00903 #if 0
00904 /* Can't be done yet */
00905 close(asock);
00906 asock = -1;
00907 #else
00908 ast_log(LOG_WARNING, "Unable to change management port / enabled\n");
00909 #endif
00910 }
00911 ast_destroy(cfg);
00912
00913 /* If not enabled, do nothing */
00914 if (!enabled) {
00915 return 0;
00916 }
00917 if (asock < 0) {
00918 asock = socket(AF_INET, SOCK_STREAM, 0);
00919 if (asock < 0) {
00920 ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno));
00921 return -1;
00922 }
00923 setsockopt(asock, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));
00924 if (bind(asock, (struct sockaddr *)&ba, sizeof(ba))) {
00925 ast_log(LOG_WARNING, "Unable to bind socket: %s\n", strerror(errno));
00926 close(asock);
00927 asock = -1;
00928 return -1;
00929 }
00930 if (listen(asock, 2)) {
00931 ast_log(LOG_WARNING, "Unable to listen on socket: %s\n", strerror(errno));
00932 close(asock);
00933 asock = -1;
00934 return -1;
00935 }
00936 if (option_verbose)
00937 ast_verbose("Asterisk Management interface listening on port %d\n", portno);
00938 pthread_create(&t, NULL, accept_thread, NULL);
00939 }
00940 return 0;
00941 }
|
|
||||||||||||||||||||
|
Definition at line 760 of file manager.c. References ast_cli(), ast_mutex_lock, ast_mutex_unlock, mansession::blocking, mansession::fd, mansession::lock, mansession::next, and mansession::readperm.
00761 {
00762 struct mansession *s;
00763 char tmp[4096];
00764 va_list ap;
00765
00766 ast_mutex_lock(&sessionlock);
00767 s = sessions;
00768 while(s) {
00769 if ((s->readperm & category) == category) {
00770 ast_mutex_lock(&s->lock);
00771 if (!s->blocking) {
00772 ast_cli(s->fd, "Event: %s\r\n", event);
00773 va_start(ap, fmt);
00774 vsnprintf(tmp, sizeof(tmp), fmt, ap);
00775 va_end(ap);
00776 write(s->fd, tmp, strlen(tmp));
00777 ast_cli(s->fd, "\r\n");
00778 }
00779 ast_mutex_unlock(&s->lock);
00780 }
00781 s = s->next;
00782 }
00783 ast_mutex_unlock(&sessionlock);
00784 return 0;
00785 }
|
|
|
Definition at line 943 of file manager.c. References EVENT_FLAG_SYSTEM, init_manager(), and manager_event(). Referenced by ast_module_reload().
00944 {
00945 manager_event(EVENT_FLAG_SYSTEM, "Reload", "Message: Reload Requested\r\n");
00946 return init_manager();
00947 }
|
1.3.4