diff options
author | file <file@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-11-06 17:05:04 +0000 |
---|---|---|
committer | file <file@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-11-06 17:05:04 +0000 |
commit | fd703bef541d89327d78d7835badb5523a0455fb (patch) | |
tree | f61cd111a6a675726f8487828ff37160b7fdf4cf /main | |
parent | 7fe9db16b5ccc8ad82618c2e52b5876ce4d5bf0a (diff) |
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)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@47229 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r-- | main/manager.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/main/manager.c b/main/manager.c index 666cf2848..80cfb07ad 100644 --- a/main/manager.c +++ b/main/manager.c @@ -183,6 +183,26 @@ static AST_LIST_HEAD_STATIC(users, ast_manager_user); 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. * We assume that the event list always has at least one element, @@ -2213,7 +2233,9 @@ int __manager_event(int category, const char *event, 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; @@ -2262,6 +2284,22 @@ int __manager_event(int category, const char *event, } 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; } |