diff options
author | Mark Spencer <markster@digium.com> | 2005-05-18 01:49:13 +0000 |
---|---|---|
committer | Mark Spencer <markster@digium.com> | 2005-05-18 01:49:13 +0000 |
commit | 38b7f7b4a474cfb9cd79acd09515a84d0e6d746b (patch) | |
tree | d354c66fada464fed80154e7002ee445c4d36d52 /pbx.c | |
parent | 9f9fcca6c0a0c3579f7ef9cd81ec0ffcc748a947 (diff) |
Add optional call limit
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5712 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'pbx.c')
-rwxr-xr-x | pbx.c | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -213,6 +213,9 @@ static struct varshead globals; static int autofallthrough = 0; +AST_MUTEX_DEFINE_STATIC(maxcalllock); +static int countcalls = 0; + AST_MUTEX_DEFINE_STATIC(acflock); /* Lock for the custom function list */ static struct ast_custom_function *acf_root = NULL; @@ -2232,7 +2235,7 @@ int ast_exec_extension(struct ast_channel *c, const char *context, const char *e return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, HELPER_EXEC); } -int ast_pbx_run(struct ast_channel *c) +static int __ast_pbx_run(struct ast_channel *c) { int firstpass = 1; char digit; @@ -2497,6 +2500,34 @@ int ast_pbx_start(struct ast_channel *c) return 0; } +int ast_pbx_run(struct ast_channel *c) +{ + int res = 0; + ast_mutex_lock(&maxcalllock); + if (option_maxcalls) { + if (countcalls >= option_maxcalls) { + ast_log(LOG_NOTICE, "Maximum call limit of %d calls exceeded by '%s'!\n", option_maxcalls, c->name); + res = -1; + } + } + if (!res) + countcalls++; + ast_mutex_unlock(&maxcalllock); + if (!res) { + res = __ast_pbx_run(c); + ast_mutex_lock(&maxcalllock); + if (countcalls > 0) + countcalls--; + ast_mutex_unlock(&maxcalllock); + } + return res; +} + +int ast_active_calls(void) +{ + return countcalls; +} + int pbx_set_autofallthrough(int newval) { int oldval; |