}
/* LIMIT Stuff */
-#define LIMIT_USAGE_USAGE "<backend> <realm> <id> [rate]"
+#define LIMIT_USAGE_SYNTAX "<backend> <realm> <id> [rate]"
SWITCH_STANDARD_API(limit_usage_function)
{
int argc = 0;
}
if (argc < 3) {
- stream->write_function(stream, "USAGE: limit_usage %s\n", LIMIT_USAGE_USAGE);
+ stream->write_function(stream, "USAGE: limit_usage %s\n", LIMIT_USAGE_SYNTAX);
goto end;
}
return SWITCH_STATUS_SUCCESS;
}
-#define LIMIT_HASH_USAGE_USAGE "<realm> <id> [rate] (Using deprecated limit api, check limit_usage with backend param)"
+#define LIMIT_HASH_USAGE_SYNTAX "<realm> <id> [rate] (Using deprecated limit api, check limit_usage with backend param)"
SWITCH_STANDARD_API(limit_hash_usage_function)
{
char *mydata = NULL;
switch_safe_free(mydata);
return ret;
} else {
- stream->write_function(stream, "USAGE: limit_hash_usage %s\n", LIMIT_HASH_USAGE_USAGE);
+ stream->write_function(stream, "USAGE: limit_hash_usage %s\n", LIMIT_HASH_USAGE_SYNTAX);
return SWITCH_STATUS_SUCCESS;
}
}
-#define LIMIT_STATUS_USAGE "<backend>"
+#define LIMIT_STATUS_SYNTAX "<backend>"
SWITCH_STANDARD_API(limit_status_function)
{
int argc = 0;
}
if (argc < 1) {
- stream->write_function(stream, "USAGE: limit_status %s\n", LIMIT_STATUS_USAGE);
+ stream->write_function(stream, "USAGE: limit_status %s\n", LIMIT_STATUS_SYNTAX);
goto end;
}
return SWITCH_STATUS_SUCCESS;
}
-#define LIMIT_RESET_USAGE "<backend>"
+#define LIMIT_RESET_SYNTAX "<backend>"
SWITCH_STANDARD_API(limit_reset_function)
{
int argc = 0;
}
if (argc < 1) {
- stream->write_function(stream, "USAGE: limit_reset %s\n", LIMIT_RESET_USAGE);
+ stream->write_function(stream, "USAGE: limit_reset %s\n", LIMIT_RESET_SYNTAX);
goto end;
}
return SWITCH_STATUS_SUCCESS;
}
+#define LIMIT_RELEASE_SYNTAX "<uuid> <backend> [realm] [resource]"
+SWITCH_STANDARD_API(uuid_limit_release_function)
+{
+ int argc = 0;
+ char *argv[5] = { 0 };
+ char *mydata = NULL;
+ char *realm = NULL;
+ char *resource = NULL;
+ switch_core_session_t *sess = NULL;
+
+ if (!zstr(cmd)) {
+ mydata = strdup(cmd);
+ switch_assert(mydata);
+ argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+ }
+
+ if (argc < 2) {
+ stream->write_function(stream, "USAGE: uuid_limit_release %s\n", LIMIT_RELEASE_SYNTAX);
+ goto end;
+ }
+
+ if (argc > 2) {
+ realm = argv[2];
+ }
+
+ if (argc > 3) {
+ resource = argv[3];
+ }
+
+ sess = switch_core_session_locate(argv[0]);
+ if (!sess) {
+ stream->write_function(stream, "-ERR did not find a session with uuid %s\n", argv[0]);
+ goto end;
+ }
+
+ switch_limit_release(argv[1], sess, realm, resource);
+
+ switch_core_session_rwunlock(sess);
+
+ stream->write_function(stream, "+OK");
+
+end:
+ switch_safe_free(mydata);
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+#define LIMIT_INTERVAL_RESET_SYNTAX "<backend> <realm> <resource>"
+SWITCH_STANDARD_API(limit_interval_reset_function)
+{
+ int argc = 0;
+ char *argv[5] = { 0 };
+ char *mydata = NULL;
+
+ if (!zstr(cmd)) {
+ mydata = strdup(cmd);
+ switch_assert(mydata);
+ argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+ }
+
+ if (argc < 3) {
+ stream->write_function(stream, "USAGE: limit_interval_reset %s\n", LIMIT_INTERVAL_RESET_SYNTAX);
+ goto end;
+ }
+
+ switch_limit_interval_reset(argv[0], argv[1], argv[2]);
+
+ stream->write_function(stream, "+OK");
+
+end:
+ switch_safe_free(mydata);
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_commands_shutdown)
{
int x;
SWITCH_ADD_API(commands_api_interface, "limit_hash_usage", "Deprecated: gets the usage count of a limited resource", limit_hash_usage_function, "<realm> <id>");
SWITCH_ADD_API(commands_api_interface, "limit_status", "Gets the status of a limit backend", limit_status_function, "<backend>");
SWITCH_ADD_API(commands_api_interface, "limit_reset", "Reset the counters of a limit backend", limit_reset_function, "<backend>");
+ SWITCH_ADD_API(commands_api_interface, "limit_interval_reset", "Reset the interval counter for a limited resource", limit_interval_reset_function, LIMIT_INTERVAL_RESET_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "load", "Load Module", load_function, LOAD_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "log", "Log", log_function, LOG_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "md5", "md5", md5_function, "<data>");
SWITCH_ADD_API(commands_api_interface, "uuid_getvar", "uuid_getvar", uuid_getvar_function, GETVAR_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_hold", "hold", uuid_hold_function, HOLD_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_kill", "Kill Channel", kill_function, KILL_SYNTAX);
+ SWITCH_ADD_API(commands_api_interface, "uuid_limit_release", "Release limit resource", uuid_limit_release_function, LIMIT_RELEASE_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_loglevel", "set loglevel on session", uuid_loglevel, UUID_LOGLEVEL_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_media", "media", uuid_media_function, MEDIA_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_park", "Park Channel", park_function, PARK_SYNTAX);
switch_console_set_complete("add uuid_getvar ::console::list_uuid");
switch_console_set_complete("add uuid_hold ::console::list_uuid");
switch_console_set_complete("add uuid_kill ::console::list_uuid");
+ switch_console_set_complete("add uuid_limit_release ::console::list_uuid");
switch_console_set_complete("add uuid_loglevel ::console::list_uuid console");
switch_console_set_complete("add uuid_loglevel ::console::list_uuid alert");
switch_console_set_complete("add uuid_loglevel ::console::list_uuid crit");
return SWITCH_STATUS_GENERR;
}
+SWITCH_LIMIT_INTERVAL_RESET(limit_interval_reset_hash)
+{
+ char *hash_key = NULL;
+ limit_hash_item_t *item = NULL;
+
+ switch_thread_rwlock_rdlock(globals.limit_hash_rwlock);
+
+ hash_key = switch_mprintf("%s_%s", realm, resource);
+ if ((item = switch_core_hash_find(globals.limit_hash, hash_key))) {
+ item->rate_usage = 0;
+ item->last_check = switch_epoch_time_now(NULL);
+ }
+
+ switch_safe_free(hash_key);
+ switch_thread_rwlock_unlock(globals.limit_hash_rwlock);
+ return SWITCH_STATUS_SUCCESS;
+}
+
SWITCH_LIMIT_STATUS(limit_status_hash)
{
/*
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
/* register limit interfaces */
- SWITCH_ADD_LIMIT(limit_interface, "hash", limit_incr_hash, limit_release_hash, limit_usage_hash, limit_reset_hash, limit_status_hash);
+ SWITCH_ADD_LIMIT(limit_interface, "hash", limit_incr_hash, limit_release_hash, limit_usage_hash, limit_reset_hash, limit_status_hash, limit_interval_reset_hash);
switch_scheduler_add_task(switch_epoch_time_now(NULL) + LIMIT_HASH_CLEANUP_INTERVAL, limit_hash_cleanup_callback, "limit_hash_cleanup", "mod_hash", 0, NULL,
SSHF_NONE);