[Asterisk-cvs] asterisk manager.c,1.39,1.40

citats at lists.digium.com citats at lists.digium.com
Tue Mar 2 03:55:25 CST 2004


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv15667

Modified Files:
	manager.c 
Log Message:
Remove extra spacing from manager.c and change Event action/variable to
work the same during login and action


Index: manager.c
===================================================================
RCS file: /usr/cvsroot/asterisk/manager.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- manager.c	1 Mar 2004 21:12:32 -0000	1.39
+++ manager.c	2 Mar 2004 08:45:51 -0000	1.40
@@ -63,9 +63,6 @@
 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 @@
 	return res;
 }
 
-
 static int handle_showmancmds(int fd, int argc, char *argv[])
 {
 	struct manager_action *cur = first_action;
@@ -231,6 +227,24 @@
 	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 @@
 	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 @@
 		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 @@
 	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;
-	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);
+
+	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
+		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 @@
 				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);
@@ -972,7 +970,6 @@
 	val = ast_variable_retrieve(cfg, "general", "block-sockets");
 	if(val)
 		block_sockets = ast_true(val);
-	
 
 	if ((val = ast_variable_retrieve(cfg, "general", "portno"))) {
 		if (sscanf(val, "%d", &portno) != 1) {




More information about the svn-commits mailing list