[asterisk-commits] branch jcollie/bug6082 r29011 - in /team/jcollie/bug6082: ./ configs/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri May 19 21:41:05 MST 2006


Author: jcollie
Date: Fri May 19 23:41:05 2006
New Revision: 29011

URL: http://svn.digium.com/view/asterisk?rev=29011&view=rev
Log:
Create a global option that will control the generation of DTMF
events.  Also convert the rest of the global boolean options in
manager.c to use ast_flags & related macros.


Modified:
    team/jcollie/bug6082/configs/manager.conf.sample
    team/jcollie/bug6082/manager.c

Modified: team/jcollie/bug6082/configs/manager.conf.sample
URL: http://svn.digium.com/view/asterisk/team/jcollie/bug6082/configs/manager.conf.sample?rev=29011&r1=29010&r2=29011&view=diff
==============================================================================
--- team/jcollie/bug6082/configs/manager.conf.sample (original)
+++ team/jcollie/bug6082/configs/manager.conf.sample Fri May 19 23:41:05 2006
@@ -32,6 +32,10 @@
 ; Add a Unix epoch timestamp to events (not action responses)
 ;
 ;timestampevents = yes
+;
+; Global flag to control generation of DTMF events.
+;
+;generatedtmfevents = no
 
 ;[mark]
 ;secret = mysecret

Modified: team/jcollie/bug6082/manager.c
URL: http://svn.digium.com/view/asterisk/team/jcollie/bug6082/manager.c?rev=29011&r1=29010&r2=29011&view=diff
==============================================================================
--- team/jcollie/bug6082/manager.c (original)
+++ team/jcollie/bug6082/manager.c Fri May 19 23:41:05 2006
@@ -91,16 +91,33 @@
 	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),
+	/*! Should the generation of DTMF events be enabled? */
+	MANAGER_FLAG_GENERATE_DTMF_EVENTS = (1 << 7)
+};
+
 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;
 
@@ -1677,7 +1694,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));
 					}
 				}
@@ -1803,13 +1820,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));
@@ -1849,7 +1866,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));
 				}
@@ -1896,7 +1913,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);
@@ -1962,9 +1979,12 @@
 	if (!num_sessions)
 		return 0;
 
+	if (category == EVENT_FLAG_DTMF && !ast_test_flag(&global_options, MANAGER_FLAG_GENERATE_DTMF_EVENTS))
+		return 0;
+
 	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);
@@ -2195,13 +2215,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));
@@ -2298,9 +2318,6 @@
 	.callback = mxml_http_callback,
 };
 
-static int registered = 0;
-static int webregged = 0;
-
 int init_manager(void)
 {
 	struct ast_config *cfg;
@@ -2309,9 +2326,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);
@@ -2335,28 +2351,27 @@
 		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);
+	ast_set2_flag(&global_options, ast_true(ast_variable_retrieve(cfg, "general", "generatedtmfevents")), MANAGER_FLAG_GENERATE_DTMF_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) {
@@ -2365,12 +2380,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);
 
@@ -2386,7 +2395,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);
@@ -2397,19 +2406,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);
 		}
 	}
 
@@ -2417,7 +2426,7 @@
 		httptimeout = newhttptimeout;
 
 	/* If not enabled, do nothing */
-	if (!enabled) {
+	if (!ast_test_flag(&global_options, MANAGER_FLAG_ENABLED)) {
 		return 0;
 	}
 



More information about the asterisk-commits mailing list