aboutsummaryrefslogtreecommitdiffstats
path: root/pbx.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-18 01:49:13 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-18 01:49:13 +0000
commite2c8bb9c440289d09415aa7464bdfa921b91f426 (patch)
treed354c66fada464fed80154e7002ee445c4d36d52 /pbx.c
parent6c8c36cb1296babe111fc188cf94358137df932d (diff)
Add optional call limit
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5712 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'pbx.c')
-rwxr-xr-xpbx.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/pbx.c b/pbx.c
index ebadafd36..803c3fca4 100755
--- a/pbx.c
+++ b/pbx.c
@@ -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;