[svn-commits] file: trunk r47229 - in /trunk: include/asterisk/ main/ utils/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Mon Nov 6 10:05:05 MST 2006


Author: file
Date: Mon Nov  6 11:05:04 2006
New Revision: 47229

URL: http://svn.digium.com/view/asterisk?rev=47229&view=rev
Log:
Add support for manager hooks, so you could fire off manager events over IRC if you were crazy enough. (issue #5161 reported by anthm with mods by moi)

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

Modified: trunk/include/asterisk/manager.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/manager.h?rev=47229&r1=47228&r2=47229&view=diff
==============================================================================
--- trunk/include/asterisk/manager.h (original)
+++ trunk/include/asterisk/manager.h Mon Nov  6 11:05:04 2006
@@ -59,6 +59,28 @@
 /* Export manager structures */
 #define AST_MAX_MANHEADERS 80
 #define AST_MAX_MANHEADER_LEN 256
+
+/* Manager Helper Function */
+typedef int (*manager_hook_t)(int, const char *, char *); 
+
+struct manager_custom_hook {
+	/*! Identifier */
+	char *file;
+	/*! helper function */
+	manager_hook_t helper;
+	/*! Linked list information */
+	AST_RWLIST_ENTRY(manager_custom_hook) list;
+};
+
+/*! Add a custom hook to be called when an event is fired */
+/*! \param hook struct manager_custom_hook object to add
+*/
+void ast_manager_register_hook(struct manager_custom_hook *hook);
+
+/*! Delete a custom hook to be called when an event is fired */
+/*! \param hook struct manager_custom_hook object to delete
+*/
+void ast_manager_unregister_hook(struct manager_custom_hook *hook);
 
 struct mansession;
 

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?rev=47229&r1=47228&r2=47229&view=diff
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Mon Nov  6 11:05:04 2006
@@ -182,6 +182,26 @@
 /*! \brief list of actions registered */
 static struct manager_action *first_action = NULL;
 AST_MUTEX_DEFINE_STATIC(actionlock);
+
+static AST_RWLIST_HEAD_STATIC(manager_hooks, manager_custom_hook);
+
+/*! \brief Add a custom hook to be called when an event is fired */
+void ast_manager_register_hook(struct manager_custom_hook *hook)
+{
+	AST_RWLIST_WRLOCK(&manager_hooks);
+	AST_RWLIST_INSERT_TAIL(&manager_hooks, hook, list);
+	AST_RWLIST_UNLOCK(&manager_hooks);
+	return;
+}
+
+/*! \brief Delete a custom hook to be called when an event is fired */
+void ast_manager_unregister_hook(struct manager_custom_hook *hook)
+{
+	AST_RWLIST_WRLOCK(&manager_hooks);
+	AST_RWLIST_REMOVE(&manager_hooks, hook, list);
+	AST_RWLIST_UNLOCK(&manager_hooks);
+	return;
+}
 
 /*! \brief
  * Event list management functions.
@@ -2213,7 +2233,9 @@
 	const char *file, int line, const char *func, const char *fmt, ...)
 {
 	struct mansession *s;
+	struct manager_custom_hook *hook;
 	char auth[80];
+	char tmp[4096] = "";
 	va_list ap;
 	struct timeval now;
 	struct ast_dynamic_str *buf;
@@ -2261,6 +2283,22 @@
 		ast_mutex_unlock(&s->__lock);
 	}
 	AST_LIST_UNLOCK(&sessions);
+
+	AST_RWLIST_RDLOCK(&manager_hooks);
+	if (!AST_RWLIST_EMPTY(&manager_hooks)) {
+		char *p;
+		int len;
+		snprintf(tmp, sizeof(tmp), "event: %s\r\nprivilege: %s\r\n", event, authority_to_str(category, tmp, sizeof(tmp)));
+                len = strlen(tmp);
+                p = tmp + len;
+                va_start(ap, fmt);
+                vsnprintf(p, sizeof(tmp) - len, fmt, ap);
+                va_end(ap);
+		AST_RWLIST_TRAVERSE(&manager_hooks, hook, list) {
+			hook->helper(category, event, tmp);
+		}
+	}
+	AST_RWLIST_UNLOCK(&manager_hooks);
 
 	return 0;
 }

Modified: trunk/utils/astman.c
URL: http://svn.digium.com/view/asterisk/trunk/utils/astman.c?rev=47229&r1=47228&r2=47229&view=diff
==============================================================================
--- trunk/utils/astman.c (original)
+++ trunk/utils/astman.c Mon Nov  6 11:05:04 2006
@@ -40,8 +40,8 @@
 #include <stdlib.h>
 
 #include "asterisk/md5.h"
+#include "asterisk/linkedlists.h"
 #include "asterisk/manager.h"
-#include "asterisk/linkedlists.h"
 
 #undef gethostbyname
 



More information about the svn-commits mailing list