mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-08 19:08:14 +00:00
Remove extra spacing from manager.c and change Event action/variable to
work the same during login and action git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2291 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
55
manager.c
55
manager.c
@@ -63,9 +63,6 @@ static struct mansession *sessions = NULL;
|
||||
static struct manager_action *first_action = NULL;
|
||||
static ast_mutex_t actionlock = AST_MUTEX_INITIALIZER;
|
||||
|
||||
|
||||
|
||||
|
||||
int ast_carefulwrite(int fd, char *s, int len, int timeoutms)
|
||||
{
|
||||
/* Try to write string, but wait no more than ms milliseconds
|
||||
@@ -93,7 +90,6 @@ int ast_carefulwrite(int fd, char *s, int len, int timeoutms)
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static int handle_showmancmds(int fd, int argc, char *argv[])
|
||||
{
|
||||
struct manager_action *cur = first_action;
|
||||
@@ -231,6 +227,24 @@ static int get_perm(char *instr)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_eventmask(struct mansession *s, char *eventmask)
|
||||
{
|
||||
if (!eventmask)
|
||||
return -1;
|
||||
if (!strcasecmp(eventmask, "on") || ast_true(eventmask)) {
|
||||
ast_mutex_lock(&s->lock);
|
||||
s->send_events = 1;
|
||||
ast_mutex_unlock(&s->lock);
|
||||
return 1;
|
||||
} else if (!strcasecmp(eventmask, "off") || ast_false(eventmask)) {
|
||||
ast_mutex_lock(&s->lock);
|
||||
s->send_events = 0;
|
||||
ast_mutex_unlock(&s->lock);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int authenticate(struct mansession *s, struct message *m)
|
||||
{
|
||||
struct ast_config *cfg;
|
||||
@@ -240,7 +254,6 @@ static int authenticate(struct mansession *s, struct message *m)
|
||||
char *authtype = astman_get_header(m, "AuthType");
|
||||
char *key = astman_get_header(m, "Key");
|
||||
char *events = astman_get_header(m, "Events");
|
||||
int send_events = events ? ast_true(events) : 1;
|
||||
|
||||
cfg = ast_load("manager.conf");
|
||||
if (!cfg)
|
||||
@@ -306,7 +319,8 @@ static int authenticate(struct mansession *s, struct message *m)
|
||||
s->readperm = get_perm(ast_variable_retrieve(cfg, cat, "read"));
|
||||
s->writeperm = get_perm(ast_variable_retrieve(cfg, cat, "write"));
|
||||
ast_destroy(cfg);
|
||||
s->send_events=send_events;
|
||||
if (events)
|
||||
set_eventmask(s, events);
|
||||
return 0;
|
||||
}
|
||||
ast_log(LOG_NOTICE, "%s tried to authenticate with non-existant user '%s'\n", inet_ntoa(s->sin.sin_addr), user);
|
||||
@@ -320,35 +334,21 @@ static int action_ping(struct mansession *s, struct message *m)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int events_on_off(struct mansession *s,int onoff) {
|
||||
ast_mutex_lock(&s->lock);
|
||||
s->send_events = onoff ? 1 : 0;
|
||||
ast_mutex_unlock(&s->lock);
|
||||
return s->send_events;
|
||||
}
|
||||
|
||||
|
||||
static int action_events(struct mansession *s, struct message *m)
|
||||
{
|
||||
char *mask = astman_get_header(m, "EventMask");
|
||||
char reply[25];
|
||||
int res;
|
||||
int true=0;
|
||||
|
||||
/* ast_true might wanna learn to include 'on' as a true stmt */
|
||||
if(!strcasecmp(mask,"on"))
|
||||
true = 1;
|
||||
res = set_eventmask(s, mask);
|
||||
if (res > 0)
|
||||
astman_send_response(s, m, "Events On", NULL);
|
||||
else if (res == 0)
|
||||
astman_send_response(s, m, "Events Off", NULL);
|
||||
else
|
||||
true = ast_true(mask);
|
||||
|
||||
res = events_on_off(s,true);
|
||||
sprintf(reply,"Events are now %s",res ? "on" : "off");
|
||||
astman_send_response(s, m,reply, NULL);
|
||||
astman_send_response(s, m, "EventMask parse error", NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int action_logoff(struct mansession *s, struct message *m)
|
||||
{
|
||||
astman_send_response(s, m, "Goodbye", "Thanks for all the fish.");
|
||||
@@ -853,9 +853,7 @@ int manager_event(int category, char *event, char *fmt, ...)
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(tmp, sizeof(tmp), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
ast_carefulwrite(s->fd,tmp,strlen(tmp),100);
|
||||
/*write(s->fd, tmp, strlen(tmp));*/
|
||||
ast_cli(s->fd, "\r\n");
|
||||
}
|
||||
ast_mutex_unlock(&s->lock);
|
||||
@@ -973,7 +971,6 @@ int init_manager(void)
|
||||
if(val)
|
||||
block_sockets = ast_true(val);
|
||||
|
||||
|
||||
if ((val = ast_variable_retrieve(cfg, "general", "portno"))) {
|
||||
if (sscanf(val, "%d", &portno) != 1) {
|
||||
ast_log(LOG_WARNING, "Invalid port number '%s'\n", val);
|
||||
|
||||
Reference in New Issue
Block a user