[asterisk-dev] manager events to show file and line info ?

Luigi Rizzo rizzo at icir.org
Thu Oct 26 12:58:46 MST 2006


in trying to debug why certain manager events don't
carry the correct callerid number (which may well be my fault),
i thought it was useful to have the events themselves include
the place where they were generated.

How about committing this patch ? It is really simple...

	cheers
	luigi

Index: include/asterisk/manager.h
===================================================================
--- include/asterisk/manager.h	(revision 46307)
+++ include/asterisk/manager.h	(working copy)
@@ -111,9 +111,15 @@
 	\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);
 
Index: main/manager.c
===================================================================
--- main/manager.c	(revision 46319)
+++ main/manager.c	(working copy)
@@ -2136,7 +2136,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];
@@ -2166,6 +2167,8 @@
 		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);


More information about the asterisk-dev mailing list