[svn-commits] rizzo: trunk r47132 - in /trunk: include/asterisk/manager.h main/manager.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Fri Nov 3 11:53:27 MST 2006


Author: rizzo
Date: Fri Nov  3 12:53:26 2006
New Revision: 47132

URL: http://svn.digium.com/view/asterisk?rev=47132&view=rev
Log:
add a new cli/manager.conf option "debug" to enable/disable
debugging code in the manager.
At the moment the debugging code is very lightweight, if the option
is enabled manager messages also carry a sequence number and
the info where they have been generated e.g.

SequenceNumber: 10
File: chan_sip.c
Line: 11927
Func: handle_response_register

It is not worthwhile having this as a compile time option
right now, because the extra work involved at runtime is
just checking one variable.


Modified:
    trunk/include/asterisk/manager.h
    trunk/main/manager.c

Modified: trunk/include/asterisk/manager.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/manager.h?rev=47132&r1=47131&r2=47132&view=diff
==============================================================================
--- trunk/include/asterisk/manager.h (original)
+++ trunk/include/asterisk/manager.h Fri Nov  3 12:53:26 2006
@@ -111,8 +111,14 @@
 	\param event	Event name
 	\param contents	Contents of event
 */
-int manager_event(int category, const char *event, const char *contents, ...)
-	__attribute__ ((format (printf, 3,4)));
+/* XXX the parser in gcc 2.95 gets confused if you don't put a space
+ * between the last arg before VA_ARGS and the comma */
+#define manager_event(category, event, contents , ...)	\
+        __manager_event(category, event, __FILE__, __LINE__, __PRETTY_FUNCTION__, contents , ## __VA_ARGS__)
+
+int __manager_event(int category, const char *event,
+		const char *file, int line, const char *func, const char *contents, ...)
+	__attribute__ ((format (printf, 6,7)));
 
 /*! Get header from mananger transaction */
 char *astman_get_header(struct message *m, char *var);

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?rev=47132&r1=47131&r2=47132&view=diff
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Fri Nov  3 12:53:26 2006
@@ -110,12 +110,13 @@
 static int asock = -1;	/* the accept socket */
 static int displayconnects = 1;
 static int timestampevents = 0;
-static int numberevents = 1;
 static int httptimeout = 60;
 
 static pthread_t accept_thread_ptr;	/*!< the accept thread */
 static int block_sockets = 0;
 static int num_sessions = 0;
+
+static int manager_debug;	/*!< enable some debugging code in the manager */
 
 AST_THREADSTORAGE(manager_event_buf);
 #define MANAGER_EVENT_BUF_INITSIZE   256
@@ -425,6 +426,21 @@
 	return RESULT_SUCCESS;
 }
 
+static int handle_mandebug(int fd, int argc, char *argv[])
+{
+	if (argc == 2)
+		ast_cli(fd, "manager debug is %s\n", manager_debug? "on" : "off");
+	else if (argc == 3) {
+		if (!strcasecmp(argv[2], "on"))
+			manager_debug = 1;
+		else if (!strcasecmp(argv[2], "off"))
+			manager_debug = 0;
+		else
+			return RESULT_SHOWUSAGE;
+	}
+	return RESULT_SUCCESS;
+}
+
 static int handle_showmanager(int fd, int argc, char *argv[])
 {
 	struct ast_manager_user *user = NULL;
@@ -598,6 +614,10 @@
 	{ { "manager", "show", "user", NULL },
 	handle_showmanager, "Display information on a specific manager user",
 	showmanager_help, NULL, NULL },
+
+	{ { "manager", "debug", NULL },
+	handle_mandebug, "Show, enable, disable debugging of the manager code",
+	"Usage: manager debug [on|off]\n	Show, enable, disable debugging of the manager code.\n", NULL, NULL },
 };
 
 /*
@@ -2189,7 +2209,8 @@
 }
 
 /*! \brief  manager_event: Send AMI event to client */
-int manager_event(int category, const char *event, const char *fmt, ...)
+int __manager_event(int category, const char *event,
+	const char *file, int line, const char *func, const char *fmt, ...)
 {
 	struct mansession *s;
 	char auth[80];
@@ -2214,11 +2235,13 @@
 				"Timestamp: %ld.%06lu\r\n",
 				 now.tv_sec, (unsigned long) now.tv_usec);
 	}
-	if (numberevents) {
+	if (manager_debug) {
 		static int seq;
 		ast_dynamic_str_thread_append(&buf, 0, &manager_event_buf,
 				"SequenceNumber: %d\r\n",
 				 ast_atomic_fetchadd_int(&seq, 1));
+		ast_dynamic_str_thread_append(&buf, 0, &manager_event_buf,
+				"File: %s\r\nLine: %d\r\nFunc: %s\r\n", file, line, func);
 	}
 
 	va_start(ap, fmt);
@@ -2844,8 +2867,8 @@
 	if ((val = ast_variable_retrieve(cfg, "general", "timestampevents")))
 		timestampevents = ast_true(val);
 
-	if ((val = ast_variable_retrieve(cfg, "general", "numberevents")))
-		numberevents = ast_true(val);
+	if ((val = ast_variable_retrieve(cfg, "general", "debug")))
+		manager_debug = ast_true(val);
 
 	if ((val = ast_variable_retrieve(cfg, "general", "httptimeout")))
 		newhttptimeout = atoi(val);



More information about the svn-commits mailing list