[asterisk-commits] branch jcollie/manager-flags r35703 - in /team/jcollie/manager-flags: ./ incl...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Jun 23 07:14:00 MST 2006


Author: jcollie
Date: Fri Jun 23 09:14:00 2006
New Revision: 35703

URL: http://svn.digium.com/view/asterisk?rev=35703&view=rev
Log:
Check in manager flag changes ported from by bug6082 branch.

Modified:
    team/jcollie/manager-flags/include/asterisk/manager.h
    team/jcollie/manager-flags/manager.c

Modified: team/jcollie/manager-flags/include/asterisk/manager.h
URL: http://svn.digium.com/view/asterisk/team/jcollie/manager-flags/include/asterisk/manager.h?rev=35703&r1=35702&r2=35703&view=diff
==============================================================================
--- team/jcollie/manager-flags/include/asterisk/manager.h (original)
+++ team/jcollie/manager-flags/include/asterisk/manager.h Fri Jun 23 09:14:00 2006
@@ -47,13 +47,13 @@
 
 #define DEFAULT_MANAGER_PORT 5038	/* Default port for Asterisk management via TCP */
 
-#define EVENT_FLAG_SYSTEM 		(1 << 0) /* System events such as module load/unload */
-#define EVENT_FLAG_CALL			(1 << 1) /* Call event, such as state change, etc */
-#define EVENT_FLAG_LOG			(1 << 2) /* Log events */
-#define EVENT_FLAG_VERBOSE		(1 << 3) /* Verbose messages */
-#define EVENT_FLAG_COMMAND		(1 << 4) /* Ability to read/set commands */
-#define EVENT_FLAG_AGENT		(1 << 5) /* Ability to read/set agent info */
-#define EVENT_FLAG_USER                 (1 << 6) /* Ability to read/set user info */
+#define EVENT_FLAG_SYSTEM	(1 << 0) /* System events such as module load/unload */
+#define EVENT_FLAG_CALL		(1 << 1) /* Call event, such as state change, etc */
+#define EVENT_FLAG_LOG		(1 << 2) /* Log events */
+#define EVENT_FLAG_VERBOSE	(1 << 3) /* Verbose messages */
+#define EVENT_FLAG_COMMAND	(1 << 4) /* Ability to read/set commands */
+#define EVENT_FLAG_AGENT	(1 << 5) /* Ability to read/set agent info */
+#define EVENT_FLAG_USER		(1 << 6) /* Ability to read/set user info */
 
 /* Export manager structures */
 #define AST_MAX_MANHEADERS 80

Modified: team/jcollie/manager-flags/manager.c
URL: http://svn.digium.com/view/asterisk/team/jcollie/manager-flags/manager.c?rev=35703&r1=35702&r2=35703&view=diff
==============================================================================
--- team/jcollie/manager-flags/manager.c (original)
+++ team/jcollie/manager-flags/manager.c Fri Jun 23 09:14:00 2006
@@ -91,16 +91,31 @@
 	char eventdata[1];
 };
 
-static int enabled = 0;
+enum {
+	/*! Is the manager enabled? */
+	MANAGER_FLAG_ENABLED = (1 << 0),
+	/*! Have the manager actions and CLI commands been registered? */
+	MANAGER_FLAG_REGISTERED = (1 << 1),
+	/*! Should sockets be blocking or non-blocking? */
+	MANAGER_FLAG_BLOCKING_SOCKETS = (1 << 2),
+	/*! Is the HTTP manager interface enabled? */
+	MANAGER_FLAG_WEB_ENABLED = (1 << 3),
+	/*! Have the manager URIs been registered with the HTTP server? */
+	MANAGER_FLAG_WEB_REGISTERED = (1 << 4),
+	/*! Should manager connects/disconnects be logged to the CLI? */
+	MANAGER_FLAG_DISPLAY_CONNECTS = (1 << 5),
+	/*! Should a timestamp be added to events? */
+	MANAGER_FLAG_TIMESTAMP_EVENTS = (1 << 6)
+};
+
 static int portno = DEFAULT_MANAGER_PORT;
 static int asock = -1;
-static int displayconnects = 1;
-static int timestampevents = 0;
 static int httptimeout = 60;
+
+static struct ast_flags global_options = { MANAGER_FLAG_DISPLAY_CONNECTS };
 
 static pthread_t t;
 AST_MUTEX_DEFINE_STATIC(sessionlock);
-static int block_sockets = 0;
 static int num_sessions = 0;
 struct eventqent *master_eventq = NULL;
 
@@ -1700,7 +1715,7 @@
 			} else {
 				s->authenticated = 1;
 				if (option_verbose > 1) {
-					if (displayconnects) {
+					if (ast_test_flag(&global_options, MANAGER_FLAG_DISPLAY_CONNECTS)) {
 						ast_verbose(VERBOSE_PREFIX_2 "%sManager '%s' logged on from %s\n", (s->sessiontimeout ? "HTTP " : ""), s->username, ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
 					}
 				}
@@ -1826,13 +1841,13 @@
 	}
 	if (s->authenticated) {
 		if (option_verbose > 1) {
-			if (displayconnects) 
+			if (ast_test_flag(&global_options, MANAGER_FLAG_DISPLAY_CONNECTS)) 
 				ast_verbose(VERBOSE_PREFIX_2 "Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
 		}
 		ast_log(LOG_EVENT, "Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
 	} else {
 		if (option_verbose > 1) {
-			if (displayconnects)
+			if (ast_test_flag(&global_options, MANAGER_FLAG_DISPLAY_CONNECTS))
 				ast_verbose(VERBOSE_PREFIX_2 "Connect attempt from '%s' unable to authenticate\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
 		}
 		ast_log(LOG_EVENT, "Failed attempt from %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
@@ -1872,7 +1887,7 @@
 					prev->next = next;
 				else
 					sessions = next;
-				if (s->authenticated && (option_verbose > 1) && displayconnects) {
+				if (s->authenticated && (option_verbose > 1) && ast_test_flag(&global_options, MANAGER_FLAG_DISPLAY_CONNECTS)) {
 					ast_verbose(VERBOSE_PREFIX_2 "HTTP Manager '%s' timed out from %s\n",
 						s->username, ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
 				}
@@ -1919,7 +1934,7 @@
 		s->writetimeout = 100;
 		s->waiting_thread = AST_PTHREADT_NULL;
 
-		if (!block_sockets) {
+		if (!ast_test_flag(&global_options, MANAGER_FLAG_BLOCKING_SOCKETS)) {
 			/* For safety, make sure socket is non-blocking */
 			flags = fcntl(as, F_GETFL);
 			fcntl(as, F_SETFL, flags | O_NONBLOCK);
@@ -1987,7 +2002,7 @@
 
 	ast_build_string(&tmp_next, &tmp_left, "Event: %s\r\nPrivilege: %s\r\n",
 			 event, authority_to_str(category, auth, sizeof(auth)));
-	if (timestampevents) {
+	if (ast_test_flag(&global_options, MANAGER_FLAG_TIMESTAMP_EVENTS)) {
 		now = ast_tvnow();
 		ast_build_string(&tmp_next, &tmp_left, "Timestamp: %ld.%06lu\r\n",
 				 now.tv_sec, (unsigned long) now.tv_usec);
@@ -2218,13 +2233,13 @@
 		if (process_message(s, &m)) {
 			if (s->authenticated) {
 				if (option_verbose > 1) {
-					if (displayconnects) 
+					if (ast_test_flag(&global_options, MANAGER_FLAG_DISPLAY_CONNECTS)) 
 						ast_verbose(VERBOSE_PREFIX_2 "HTTP Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));    
 				}
 				ast_log(LOG_EVENT, "HTTP Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
 			} else {
 				if (option_verbose > 1) {
-					if (displayconnects)
+					if (ast_test_flag(&global_options, MANAGER_FLAG_DISPLAY_CONNECTS))
 						ast_verbose(VERBOSE_PREFIX_2 "HTTP Connect attempt from '%s' unable to authenticate\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
 				}
 				ast_log(LOG_EVENT, "HTTP Failed attempt from %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
@@ -2321,9 +2336,6 @@
 	.callback = mxml_http_callback,
 };
 
-static int registered = 0;
-static int webregged = 0;
-
 int init_manager(void)
 {
 	struct ast_config *cfg;
@@ -2332,9 +2344,8 @@
 	static struct sockaddr_in ba;
 	int x = 1;
 	int flags;
-	int webenabled = 0;
 	int newhttptimeout = 60;
-	if (!registered) {
+	if (!ast_test_flag(&global_options, MANAGER_FLAG_REGISTERED)) {
 		/* Register default actions */
 		ast_manager_register2("Ping", 0, action_ping, "Keepalive command", mandescr_ping);
 		ast_manager_register2("Events", 0, action_events, "Control Event Flow", mandescr_events);
@@ -2359,28 +2370,26 @@
 		ast_cli_register(&show_manconn_cli);
 		ast_cli_register(&show_maneventq_cli);
 		ast_extension_state_add(NULL, NULL, manager_state_cb, NULL);
-		registered = 1;
+		ast_set_flag(&global_options, MANAGER_FLAG_REGISTERED);
 		/* Append placeholder event so master_eventq never runs dry */
 		append_event("Event: Placeholder\r\n\r\n", 0);
 	}
 	portno = DEFAULT_MANAGER_PORT;
-	displayconnects = 1;
-	cfg = ast_config_load("manager.conf");
-	if (!cfg) {
+	if (!(cfg = ast_config_load("manager.conf"))) {
 		ast_log(LOG_NOTICE, "Unable to open management configuration manager.conf.  Call management disabled.\n");
 		return 0;
 	}
-	val = ast_variable_retrieve(cfg, "general", "enabled");
-	if (val)
-		enabled = ast_true(val);
-
-	val = ast_variable_retrieve(cfg, "general", "block-sockets");
-	if (val)
-		block_sockets = ast_true(val);
-
-	val = ast_variable_retrieve(cfg, "general", "webenabled");
-	if (val)
-		webenabled = ast_true(val);
+
+	ast_set2_flag(&global_options, ast_true(ast_variable_retrieve(cfg, "general", "enabled")), MANAGER_FLAG_ENABLED);
+	ast_set2_flag(&global_options, ast_true(ast_variable_retrieve(cfg, "general", "block-sockets")), MANAGER_FLAG_BLOCKING_SOCKETS);
+	ast_set2_flag(&global_options, ast_true(ast_variable_retrieve(cfg, "general", "webenabled")), MANAGER_FLAG_WEB_ENABLED);
+	ast_set2_flag(&global_options, ast_true(ast_variable_retrieve(cfg, "general", "timestampevents")), MANAGER_FLAG_TIMESTAMP_EVENTS);
+
+	/* Connections should be displayed by default so treat this one specially. */
+	if ((val = ast_variable_retrieve(cfg, "general", "displayconnects")))
+		ast_set2_flag(&global_options, ast_true(val), MANAGER_FLAG_DISPLAY_CONNECTS);
+	else
+		ast_set_flag(&global_options, MANAGER_FLAG_DISPLAY_CONNECTS);
 
 	if ((val = ast_variable_retrieve(cfg, "general", "port"))) {
 		if (sscanf(val, "%d", &portno) != 1) {
@@ -2389,12 +2398,6 @@
 		}
 	}
 
-	if ((val = ast_variable_retrieve(cfg, "general", "displayconnects")))
-		displayconnects = ast_true(val);
-
-	if ((val = ast_variable_retrieve(cfg, "general", "timestampevents")))
-		timestampevents = ast_true(val);
-
 	if ((val = ast_variable_retrieve(cfg, "general", "httptimeout")))
 		newhttptimeout = atoi(val);
 
@@ -2410,7 +2413,7 @@
 	}
 	
 
-	if ((asock > -1) && ((portno != oldportno) || !enabled)) {
+	if ((asock > -1) && ((portno != oldportno) || !ast_test_flag(&global_options, MANAGER_FLAG_ENABLED))) {
 #if 0
 		/* Can't be done yet */
 		close(asock);
@@ -2421,19 +2424,19 @@
 	}
 	ast_config_destroy(cfg);
 	
-	if (webenabled && enabled) {
-		if (!webregged) {
+	if (ast_test_flag(&global_options, MANAGER_FLAG_WEB_ENABLED) && ast_test_flag(&global_options, MANAGER_FLAG_ENABLED)) {
+		if (!ast_test_flag(&global_options, MANAGER_FLAG_WEB_REGISTERED)) {
 			ast_http_uri_link(&rawmanuri);
 			ast_http_uri_link(&manageruri);
 			ast_http_uri_link(&managerxmluri);
-			webregged = 1;
+			ast_set_flag(&global_options, MANAGER_FLAG_WEB_REGISTERED);
 		}
 	} else {
-		if (webregged) {
+		if (ast_test_flag(&global_options, MANAGER_FLAG_WEB_REGISTERED)) {
 			ast_http_uri_unlink(&rawmanuri);
 			ast_http_uri_unlink(&manageruri);
 			ast_http_uri_unlink(&managerxmluri);
-			webregged = 0;
+			ast_clear_flag(&global_options, MANAGER_FLAG_WEB_REGISTERED);
 		}
 	}
 
@@ -2441,7 +2444,7 @@
 		httptimeout = newhttptimeout;
 
 	/* If not enabled, do nothing */
-	if (!enabled)
+	if (!ast_test_flag(&global_options, MANAGER_FLAG_ENABLED)) {
 		return 0;
 
 	if (asock < 0) {



More information about the asterisk-commits mailing list