diff --git a/src/mod/applications/mod_limit/mod_limit.c b/src/mod/applications/mod_limit/mod_limit.c index 0c267656ea..94015ef7d2 100644 --- a/src/mod/applications/mod_limit/mod_limit.c +++ b/src/mod/applications/mod_limit/mod_limit.c @@ -701,7 +701,7 @@ SWITCH_STANDARD_APP(group_function) } } -#define LIMIT_USAGE " [number [dialplan [context]]]" +#define LIMIT_USAGE " [ [number [dialplan [context]]]]" #define LIMIT_DESC "limit access to a resource and transfer to an extension if the limit is exceeded" static char *limit_def_xfer_exten = "limit_exceeded"; @@ -727,14 +727,23 @@ SWITCH_STANDARD_APP(limit_function) if (argc < 3) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "USAGE: limit %s\n", LIMIT_USAGE); - return; + goto done; } switch_mutex_lock(globals.mutex); realm = argv[0]; id = argv[1]; - max = atoi(argv[2]); + + if (argc > 2) { + max = atoi(argv[2]); + if (max < 0) { + max = 0; + } + } + else { + max = -1; + } if (argc >= 4) { xfer_exten = argv[3]; @@ -742,9 +751,6 @@ SWITCH_STANDARD_APP(limit_function) xfer_exten = limit_def_xfer_exten; } - if (max < 0) { - max = 0; - } new_channel = !switch_channel_get_variable(channel, "limit_realm"); switch_channel_set_variable(channel, "limit_realm", realm); @@ -758,7 +764,7 @@ SWITCH_STANDARD_APP(limit_function) switch_safe_free(sql); got = atoi(buf); - if (got + 1 > max) { + if (max > 0 && got + 1 > max) { switch_ivr_session_transfer(session, xfer_exten, argv[4], argv[5]); goto done; } @@ -771,8 +777,11 @@ SWITCH_STANDARD_APP(limit_function) switch_core_session_get_uuid(session)); limit_execute_sql(sql, NULL); switch_safe_free(sql); + + switch_channel_set_variable(channel, "limit_usage", switch_core_session_sprintf(session, "%d", ++got)); done: + switch_safe_free(mydata); switch_mutex_unlock(globals.mutex); }