Index: manager.c =================================================================== --- manager.c (revision 9029) +++ manager.c (working copy) @@ -108,7 +108,40 @@ 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, there is only one system call made to do a write, unless we actually @@ -1560,7 +1593,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; } Index: include/asterisk/manager.h =================================================================== --- include/asterisk/manager.h (revision 9029) +++ include/asterisk/manager.h (working copy) @@ -55,6 +55,27 @@ #define EVENT_FLAG_AGENT (1 << 5) /* Ability to read/set agent info */ #define EVENT_FLAG_USER (1 << 6) /* Ability to read/set user info */ +/* Manager Helper Function */ +typedef int (*manager_hook_t)(int, char *, char *); + +struct manager_custom_hook { + /*! Identifier */ + char *file; + /*! helper function */ + manager_hook_t helper; + struct manager_custom_hook *next; +}; + +/*! 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 MAX_HEADERS 80 #define MAX_LEN 256