mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-14 16:15:04 +00:00
mod_limit is now a backwards compatible shim
This commit is contained in:
parent
4c6a030a84
commit
cb6f978d93
@ -4240,6 +4240,7 @@ SWITCH_STANDARD_API(limit_usage_function)
|
|||||||
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* backwards compat version */
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
switch_safe_free(mydata);
|
switch_safe_free(mydata);
|
||||||
/* allocate space for "db " */
|
/* allocate space for "db " */
|
||||||
@ -4250,7 +4251,6 @@ SWITCH_STANDARD_API(limit_usage_function)
|
|||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Using deprecated limit api: Please specify backend. Defaulting to 'db' backend.\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Using deprecated limit api: Please specify backend. Defaulting to 'db' backend.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* backwards compat version */
|
|
||||||
if (argc < 3) {
|
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_USAGE);
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -3030,22 +3030,29 @@ SWITCH_STANDARD_APP(limit_function)
|
|||||||
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 3) {
|
backend = argv[0];
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "USAGE: limit %s\n", LIMIT_USAGE);
|
|
||||||
|
/* must have at least one item */
|
||||||
|
if (argc < 1) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "USAGE: limit %s\n", LIMIT_USAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
backend = argv[0];
|
|
||||||
|
|
||||||
/* if this is an invalid backend, fallback to db backend */
|
/* if this is an invalid backend, fallback to db backend */
|
||||||
/* TODO: remove this when we can! */
|
/* TODO: remove this when we can! */
|
||||||
if (!(limit = switch_loadable_module_get_limit_interface(backend))) {
|
if (switch_true(switch_channel_get_variable(channel, "switch_limit_backwards_compat_flag")) &&
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unknown backend '%s'. To maintain backwards compatability, falling back on db backend and shifting argumens. Either update your diaplan to include the backend, fix the typo, or load the appropriate limit implementation module.", backend);
|
!(limit = switch_loadable_module_get_limit_interface(backend))) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unknown backend '%s'. To maintain backwards compatability, falling back on db backend and shifting argumens. Either update your diaplan to include the backend, fix the typo, or load the appropriate limit implementation module.\n", backend);
|
||||||
mydata = switch_core_session_sprintf(session, "db %s", data);
|
mydata = switch_core_session_sprintf(session, "db %s", data);
|
||||||
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||||
backend = argv[0];
|
backend = argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (argc < 3) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "USAGE: limit %s\n", LIMIT_USAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
realm = argv[1];
|
realm = argv[1];
|
||||||
id = argv[2];
|
id = argv[2];
|
||||||
|
|
||||||
@ -3089,9 +3096,15 @@ SWITCH_STANDARD_APP(limit_function)
|
|||||||
SWITCH_STANDARD_APP(limit_hash_function)
|
SWITCH_STANDARD_APP(limit_hash_function)
|
||||||
{
|
{
|
||||||
char *mydata = NULL;
|
char *mydata = NULL;
|
||||||
mydata = switch_core_session_sprintf(session, "hash %s", data);
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Using deprecated 'limit_hash' api: Please use 'limit hash'.\n");
|
|
||||||
limit_function(session, mydata);
|
if (switch_true(switch_channel_get_variable(channel, "switch_limit_backwards_compat_flag"))) {
|
||||||
|
mydata = switch_core_session_sprintf(session, "hash %s", data);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Using deprecated 'limit_hash' api: Please use 'limit hash'.\n");
|
||||||
|
limit_function(session, mydata);
|
||||||
|
} else {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "'limit_hash' (deprecated) is only available after loading mod_limit.\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LIMITEXECUTE_USAGE "<backend> <realm> <id> <max>[/interval] <application> [application arguments]"
|
#define LIMITEXECUTE_USAGE "<backend> <realm> <id> <max>[/interval] <application> [application arguments]"
|
||||||
@ -3108,6 +3121,7 @@ SWITCH_STANDARD_APP(limit_execute_function)
|
|||||||
char *app_arg = NULL;
|
char *app_arg = NULL;
|
||||||
int max = -1;
|
int max = -1;
|
||||||
int interval = 0;
|
int interval = 0;
|
||||||
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||||
|
|
||||||
/* Parse application data */
|
/* Parse application data */
|
||||||
if (!zstr(data)) {
|
if (!zstr(data)) {
|
||||||
@ -3116,14 +3130,15 @@ SWITCH_STANDARD_APP(limit_execute_function)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* backwards compat version, if we have 5, just prepend with db and reparse */
|
/* backwards compat version, if we have 5, just prepend with db and reparse */
|
||||||
if (argc == 5) {
|
if (switch_true(switch_channel_get_variable(channel, "switch_limit_backwards_compat_flag")) &&
|
||||||
|
argc == 5) {
|
||||||
mydata = switch_core_session_sprintf(session, "db %s", data);
|
mydata = switch_core_session_sprintf(session, "db %s", data);
|
||||||
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Using deprecated limit api: Please specify backend. Defaulting to 'db' backend.\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Using deprecated limit api: Please specify backend. Defaulting to 'db' backend.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 6) {
|
if (argc < 6) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "USAGE: limit_execute %s\n", LIMITEXECUTE_USAGE);
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "USAGE: limit_execute %s\n", LIMITEXECUTE_USAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3172,9 +3187,15 @@ SWITCH_STANDARD_APP(limit_execute_function)
|
|||||||
SWITCH_STANDARD_APP(limit_hash_execute_function)
|
SWITCH_STANDARD_APP(limit_hash_execute_function)
|
||||||
{
|
{
|
||||||
char *mydata = NULL;
|
char *mydata = NULL;
|
||||||
mydata = switch_core_session_sprintf(session, "hash %s", data);
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Using deprecated 'limit_hash_execute' api: Please use 'limit_execute hash'.\n");
|
|
||||||
limit_execute_function(session, mydata);
|
if (switch_true(switch_channel_get_variable(channel, "switch_limit_backwards_compat_flag"))) {
|
||||||
|
mydata = switch_core_session_sprintf(session, "hash %s", data);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Using deprecated 'limit_hash_execute' api: Please use 'limit_execute hash'.\n");
|
||||||
|
limit_execute_function(session, mydata);
|
||||||
|
} else {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "'limit_hash_execute' (deprecated) is only available after loading mod_limit.\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SPEAK_DESC "Speak text to a channel via the tts interface"
|
#define SPEAK_DESC "Speak text to a channel via the tts interface"
|
||||||
|
@ -61,6 +61,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_limit_load)
|
|||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to load mod_db (%s)!\n", err);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to load mod_db (%s)!\n", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set compat flag */
|
||||||
|
switch_core_set_variable("switch_limit_backwards_compat_flag", "true");
|
||||||
|
|
||||||
/* indicate that the module should continue to be loaded */
|
/* indicate that the module should continue to be loaded */
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
@ -68,6 +71,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_limit_load)
|
|||||||
|
|
||||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_limit_shutdown)
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_limit_shutdown)
|
||||||
{
|
{
|
||||||
|
switch_core_set_variable("switch_limit_backwards_compat_flag", "false");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user