mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-26 06:26:41 +00:00
This patch allows an event mask to be sent on a manager login session
either using an integer value or a ',' sep list of flags exactly like the manager.conf read and write lines. e.g. Events: system,call,log or Events: off or Events: on Also you can change it mid-session with Action: Events e.g. Action: Events EventMask: system,call,log -Tony (anthm) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3399 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
122
manager.c
122
manager.c
@@ -269,44 +269,97 @@ void astman_send_ack(struct mansession *s, struct message *m, char *msg)
|
|||||||
astman_send_response(s, m, "Success", msg);
|
astman_send_response(s, m, "Success", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
|
static int ast_instring(char *bigstr, char *smallstr, char delim) {
|
||||||
|
char *val = bigstr, *next;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if ( ( next = strchr ( val, delim ) ) )
|
||||||
|
if ( ! strncmp ( val , smallstr , ( next - val ) ) )
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
return ! strcmp ( smallstr , val );
|
||||||
|
|
||||||
|
} while ( * ( val = ( next + 1 ) ) ) ;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int get_perm(char *instr)
|
static int get_perm(char *instr)
|
||||||
{
|
{
|
||||||
char tmp[256];
|
int x = 0, ret = 0;
|
||||||
char *c;
|
|
||||||
int x;
|
|
||||||
int ret = 0;
|
|
||||||
char *stringp=NULL;
|
|
||||||
if (!instr)
|
if (!instr)
|
||||||
return 0;
|
return 0;
|
||||||
strncpy(tmp, instr, sizeof(tmp) - 1);
|
|
||||||
stringp=tmp;
|
for (x=0; x<sizeof(perms) / sizeof(perms[0]); x++)
|
||||||
c = strsep(&stringp, ",");
|
if (ast_instring(instr, perms[x].label, ','))
|
||||||
while(c) {
|
ret |= perms[x].num;
|
||||||
for (x=0;x<sizeof(perms) / sizeof(perms[0]);x++) {
|
|
||||||
if (!strcasecmp(perms[x].label, c))
|
|
||||||
ret |= perms[x].num;
|
|
||||||
}
|
|
||||||
c = strsep(&stringp, ",");
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ast_is_number(char *string) {
|
||||||
|
int ret = 1, x = 0;
|
||||||
|
|
||||||
|
if(!string)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (x=0; x < strlen(string) ; x++ ) {
|
||||||
|
if (! (string[x] >= 48 && string[x] <= 57)) {
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret ? atoi(string) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int ast_strings_to_mask(char *string) {
|
||||||
|
int x = 0, ret = -1;
|
||||||
|
|
||||||
|
x = ast_is_number(string);
|
||||||
|
|
||||||
|
if(x)
|
||||||
|
ret = x;
|
||||||
|
else if (! string || ast_strlen_zero(string))
|
||||||
|
ret = -1;
|
||||||
|
else if (!strcasecmp(string, "off") || ast_false(string))
|
||||||
|
ret = 0;
|
||||||
|
else if (!strcasecmp(string, "on") || ast_true(string))
|
||||||
|
ret = -1;
|
||||||
|
else {
|
||||||
|
ret = 0;
|
||||||
|
for (x=0; x<sizeof(perms) / sizeof(perms[0]); x++)
|
||||||
|
if (ast_instring(string, perms[x].label, ','))
|
||||||
|
ret |= perms[x].num;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 set_eventmask(struct mansession *s, char *eventmask)
|
static int set_eventmask(struct mansession *s, char *eventmask)
|
||||||
{
|
{
|
||||||
if (!eventmask)
|
int maskint = ast_strings_to_mask(eventmask);
|
||||||
return -1;
|
|
||||||
if (!strcasecmp(eventmask, "on") || ast_true(eventmask)) {
|
ast_mutex_lock(&s->lock);
|
||||||
ast_mutex_lock(&s->lock);
|
s->send_events = maskint;
|
||||||
s->send_events = 1;
|
ast_mutex_unlock(&s->lock);
|
||||||
ast_mutex_unlock(&s->lock);
|
|
||||||
return 1;
|
return s->send_events;
|
||||||
} 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)
|
static int authenticate(struct mansession *s, struct message *m)
|
||||||
@@ -434,7 +487,9 @@ static char mandescr_events[] =
|
|||||||
"Description: Enable/Disable sending of events to this manager\n"
|
"Description: Enable/Disable sending of events to this manager\n"
|
||||||
" client.\n"
|
" client.\n"
|
||||||
"Variables:\n"
|
"Variables:\n"
|
||||||
" EventMask: 'on' if events should be sent, 'off' if not\n";
|
" EventMask: 'on' if all events should be sent,\n"
|
||||||
|
" EventMask: 'system,call,log' if events should be sent matching these specific channels,\n"
|
||||||
|
" EventMask: 'off' if no events should be sent.\n";
|
||||||
|
|
||||||
static int action_events(struct mansession *s, struct message *m)
|
static int action_events(struct mansession *s, struct message *m)
|
||||||
{
|
{
|
||||||
@@ -446,8 +501,7 @@ static int action_events(struct mansession *s, struct message *m)
|
|||||||
astman_send_response(s, m, "Events On", NULL);
|
astman_send_response(s, m, "Events On", NULL);
|
||||||
else if (res == 0)
|
else if (res == 0)
|
||||||
astman_send_response(s, m, "Events Off", NULL);
|
astman_send_response(s, m, "Events Off", NULL);
|
||||||
else
|
|
||||||
astman_send_response(s, m, "EventMask parse error", NULL);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1128,7 +1182,7 @@ static void *accept_thread(void *ignore)
|
|||||||
}
|
}
|
||||||
ast_mutex_init(&s->lock);
|
ast_mutex_init(&s->lock);
|
||||||
s->fd = as;
|
s->fd = as;
|
||||||
s->send_events = 1;
|
s->send_events = -1;
|
||||||
ast_mutex_lock(&sessionlock);
|
ast_mutex_lock(&sessionlock);
|
||||||
s->next = sessions;
|
s->next = sessions;
|
||||||
sessions = s;
|
sessions = s;
|
||||||
@@ -1149,7 +1203,7 @@ int manager_event(int category, char *event, char *fmt, ...)
|
|||||||
ast_mutex_lock(&sessionlock);
|
ast_mutex_lock(&sessionlock);
|
||||||
s = sessions;
|
s = sessions;
|
||||||
while(s) {
|
while(s) {
|
||||||
if (((s->readperm & category) == category) && s->send_events) {
|
if (((s->readperm & category) == category) && ((s->send_events & category) == category) ) {
|
||||||
ast_mutex_lock(&s->lock);
|
ast_mutex_lock(&s->lock);
|
||||||
if (!s->blocking) {
|
if (!s->blocking) {
|
||||||
ast_cli(s->fd, "Event: %s\r\n", event);
|
ast_cli(s->fd, "Event: %s\r\n", event);
|
||||||
|
|||||||
Reference in New Issue
Block a user