From: Anthony Minessale II Date: Thu, 8 Jul 2004 15:39:35 +0000 (+0000) Subject: This patch allows an event mask to be sent on a manager login session X-Git-Tag: 1.0.0-rc1~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=568ba9c398042b143fa319422480ba0b86a40419;p=thirdparty%2Fasterisk.git 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 --- diff --git a/manager.c b/manager.c index c3f5c07adb..d534197f66 100755 --- a/manager.c +++ b/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); } +/* 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) { - char tmp[256]; - char *c; - int x; - int ret = 0; - char *stringp=NULL; + int x = 0, ret = 0; + if (!instr) return 0; - strncpy(tmp, instr, sizeof(tmp) - 1); - stringp=tmp; - c = strsep(&stringp, ","); - while(c) { - for (x=0;x= 48 && string[x] <= 57)) { + ret = 0; + break; } - c = strsep(&stringp, ","); } + + 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; xlock); - 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; + int maskint = ast_strings_to_mask(eventmask); + + ast_mutex_lock(&s->lock); + s->send_events = maskint; + ast_mutex_unlock(&s->lock); + + return s->send_events; } 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" " client.\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) { @@ -446,8 +501,7 @@ static int action_events(struct mansession *s, struct message *m) astman_send_response(s, m, "Events On", NULL); else if (res == 0) astman_send_response(s, m, "Events Off", NULL); - else - astman_send_response(s, m, "EventMask parse error", NULL); + return 0; } @@ -1128,7 +1182,7 @@ static void *accept_thread(void *ignore) } ast_mutex_init(&s->lock); s->fd = as; - s->send_events = 1; + s->send_events = -1; ast_mutex_lock(&sessionlock); s->next = sessions; sessions = s; @@ -1149,7 +1203,7 @@ int manager_event(int category, char *event, char *fmt, ...) ast_mutex_lock(&sessionlock); s = sessions; 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); if (!s->blocking) { ast_cli(s->fd, "Event: %s\r\n", event);