[asterisk-commits] branch oej/test-this-branch r11713 - in /team/oej/test-this-branch: ./ includ...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Mar 3 04:32:35 MST 2006


Author: oej
Date: Fri Mar  3 05:32:32 2006
New Revision: 11713

URL: http://svn.digium.com/view/asterisk?rev=11713&view=rev
Log:
Adding anthm's manager event hooks

Modified:
    team/oej/test-this-branch/README.test-this-branch
    team/oej/test-this-branch/include/asterisk/manager.h
    team/oej/test-this-branch/manager.c

Modified: team/oej/test-this-branch/README.test-this-branch
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/README.test-this-branch?rev=11713&r1=11712&r2=11713&view=diff
==============================================================================
--- team/oej/test-this-branch/README.test-this-branch (original)
+++ team/oej/test-this-branch/README.test-this-branch Fri Mar  3 05:32:32 2006
@@ -24,6 +24,7 @@
 - iptos: New IPtos support, separate audio and signalling (#6355)
 - multiparking: Multiple parking lots (#6113)
 - cdr_radius: CDR support for Radius (#6639, phsultan). See doc/cdrdriver.txt
+- amieventhook-561 rev 11712: Support for manager event hooks (#5161, anthm)
 
 And the following stand-alone patches
 - New CLI commands for global variables (oej, #6506)

Modified: team/oej/test-this-branch/include/asterisk/manager.h
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/include/asterisk/manager.h?rev=11713&r1=11712&r2=11713&view=diff
==============================================================================
--- team/oej/test-this-branch/include/asterisk/manager.h (original)
+++ team/oej/test-this-branch/include/asterisk/manager.h Fri Mar  3 05:32:32 2006
@@ -54,6 +54,72 @@
 #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 */
+
+/*! \page AMIhooks Manager event hooks 
+	\par This is a way to register your own function to be called whenever something
+	calls manager_event() making it possible to gateway events to other systems
+	without hacking the manager The backend takes the liberty of consolidating the
+	varargs printf like expression into 1 string.
+
+	\par Example Code
+	*	This is your custom function:
+	*
+	*	\code
+	*	static int verbose_manager_event(int category, char *event, char *body)
+	*	{
+    	*	ast_verbose("Manager EVENT\n%s\n", body);
+    	*	return 	0;
+	*	}
+	*	\endcode
+	*	
+	*	This is the container where the function is stored in manager's scope:
+	*	\code
+	*	static struct manager_custom_hook my_hook = {
+    	*		.file = "app_myapp",
+    	*		.helper = verbose_manager_event
+	*	};
+	*	\endcode
+	*	
+	*	This is how you register it:
+	*	\code
+	*	int load_module(void) 
+	*	{
+     	*		add_manager_hook(&my_hook);
+	*	}
+	*	\endcode
+	*	
+	*	This is how you un-register it:
+	*	\code
+	*	int unload_module(void) 
+	*	{
+     	*		del_manager_hook(&my_hook);
+	*	}
+	*	\endcode
+
+	\par Functions
+	- manager_custom_hook()
+	- add_manager_hook()
+	- del_manager_hook()
+*/
+
+/*! \brief Manager Helper Function for custom AMI hooks.  See AMIhooks */
+typedef int (*manager_hook_t)(int, char *, char *); 
+
+struct manager_custom_hook {
+	char *file;		/*!< Identifier */
+	manager_hook_t helper;	/*!< helper function */
+	struct manager_custom_hook *next;
+};
+
+/*! \brief Add a custom hook to be called when an event is fired 
+	\param hook struct manager_custom_hook object to add
+*/
+extern void add_manager_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
+*/
+extern void del_manager_hook(struct manager_custom_hook *hook);
 
 /* Export manager structures */
 #define AST_MAX_MANHEADERS 80

Modified: team/oej/test-this-branch/manager.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/manager.c?rev=11713&r1=11712&r2=11713&view=diff
==============================================================================
--- team/oej/test-this-branch/manager.c (original)
+++ team/oej/test-this-branch/manager.c Fri Mar  3 05:32:32 2006
@@ -109,6 +109,39 @@
 static struct mansession *sessions = NULL;
 static struct manager_action *first_action = NULL;
 AST_MUTEX_DEFINE_STATIC(actionlock);
+AST_MUTEX_DEFINE_STATIC(hooklock);
+
+static struct manager_custom_hook *manager_hooks = NULL;
+
+
+void add_manager_hook(struct manager_custom_hook *hook)
+{
+	ast_mutex_lock(&hooklock);
+	if (hook) {
+		hook->next = manager_hooks;
+		manager_hooks = hook;
+	}
+	ast_mutex_unlock(&hooklock);
+}
+
+void del_manager_hook(struct manager_custom_hook *hook)
+{
+	struct manager_custom_hook *hookp, *lasthook = NULL;
+
+	ast_mutex_lock(&hooklock);
+	for (hookp = manager_hooks; hookp ; hookp = hookp->next) {
+		if (hookp == hook) {
+			if (lasthook) {
+				lasthook->next = hookp->next;
+			} else {
+				manager_hooks = hookp->next;
+			}
+		}
+		lasthook = hookp;
+	}
+	ast_mutex_unlock(&hooklock);
+
+}
 
 /*! If you are calling ast_carefulwrite, it is assumed that you are calling
    it on a file descriptor that _DOES_ have NONBLOCK set.  This way,
@@ -1596,7 +1629,22 @@
 		ast_mutex_unlock(&s->__lock);
 	}
 	ast_mutex_unlock(&sessionlock);
-
+	if (manager_hooks) {
+		struct manager_custom_hook *hookp;
+		ast_mutex_lock(&hooklock);
+		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);
+		for (hookp = manager_hooks ; hookp; hookp = hookp->next) {
+				hookp->helper(category, event, tmp);
+			}
+			ast_mutex_unlock(&hooklock);
+		}
 	return 0;
 }
 



More information about the asterisk-commits mailing list