mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-12 20:47:06 +00:00
FSCORE-637 - limit - reset rate and release resource apis
Thanks Moy
This commit is contained in:
1 parent
fca93f2910
commit
a7c31e6fe9
8 files changed
+142
-12
No files matched your search
@@ -4227,7 +4227,7 @@ SWITCH_STANDARD_API(sql_escape)
|
||||
}
|
||||
|
||||
/* 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;
|
||||
@@ -4255,7 +4255,7 @@ SWITCH_STANDARD_API(limit_usage_function)
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -4279,7 +4279,7 @@ 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;
|
||||
@@ -4290,12 +4290,12 @@ SWITCH_STANDARD_API(limit_hash_usage_function)
|
||||
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;
|
||||
@@ -4310,7 +4310,7 @@ SWITCH_STANDARD_API(limit_status_function)
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -4325,7 +4325,7 @@ end:
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
#define LIMIT_RESET_USAGE "<backend>"
|
||||
#define LIMIT_RESET_SYNTAX "<backend>"
|
||||
SWITCH_STANDARD_API(limit_reset_function)
|
||||
{
|
||||
int argc = 0;
|
||||
@@ -4340,7 +4340,7 @@ SWITCH_STANDARD_API(limit_reset_function)
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -4354,6 +4354,81 @@ 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;
|
||||
@@ -4446,6 +4521,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
|
||||
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>");
|
||||
@@ -4494,6 +4570,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
|
||||
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);
|
||||
@@ -4600,6 +4677,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
|
||||
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");
|
||||
|
||||
Reference in new issue
Block a user