}
}
-#define LIMIT_USAGE "<realm> <id> <max> [number [dialplan [context]]]"
+#define LIMIT_USAGE "<realm> <id> [<max> [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";
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];
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);
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;
}
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);
}