From 98a950165a356d57906a2e3f49a80c02ffea4bd0 Mon Sep 17 00:00:00 2001 From: Rupa Schomaker Date: Mon, 28 Mar 2011 18:24:01 -0500 Subject: [PATCH] =?UTF-8?q?FS-1792=20-=20add=20API=20uuid=5Flimit=20-=20th?= =?UTF-8?q?anks=20to=20Fran=E7ois=20Delawarde?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../applications/mod_commands/mod_commands.c | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index a6df087cb0..fd2081e31d 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -4843,6 +4843,87 @@ end: return SWITCH_STATUS_SUCCESS; } +#define LIMIT_SYNTAX " [[/interval]] [number [dialplan [context]]]" +SWITCH_STANDARD_API(uuid_limit_function) +{ + int argc = 0; + char *argv[8] = { 0 }; + char *mydata = NULL; + char *realm = NULL; + char *resource = NULL; + char *xfer_exten = NULL; + int max = -1; + int interval = 0; + switch_core_session_t *sess = NULL; + switch_status_t res = SWITCH_STATUS_SUCCESS; + + if (!zstr(cmd)) { + mydata = strdup(cmd); + switch_assert(mydata); + argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); + } + + if (argc < 4) { + stream->write_function(stream, "USAGE: uuid_limit %s\n", LIMIT_SYNTAX); + goto end; + } + + realm = argv[2]; + resource = argv[3]; + + /* If max is omitted or negative, only act as a counter and skip maximum checks */ + if (argc > 4) { + if (argv[4][0] == '-') { + max = -1; + } else { + char *szinterval = NULL; + if ((szinterval = strchr(argv[4], '/'))) { + *szinterval++ = '\0'; + interval = atoi(szinterval); + } + + max = atoi(argv[4]); + + if (max < 0) { + max = 0; + } + } + } + + if (argc > 5) { + xfer_exten = argv[5]; + } else { + xfer_exten = LIMIT_DEF_XFER_EXTEN; + } + + 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; + } + + res = switch_limit_incr(argv[1], sess, realm, resource, max, interval); + + if (res != SWITCH_STATUS_SUCCESS) { + /* Limit exceeded */ + if (*xfer_exten == '!') { + switch_channel_t *channel = switch_core_session_get_channel(sess); + switch_channel_hangup(channel, switch_channel_str2cause(xfer_exten + 1)); + } else { + switch_ivr_session_transfer(sess, xfer_exten, argv[6], argv[7]); + } + } + + switch_core_session_rwunlock(sess); + + stream->write_function(stream, "+OK"); + +end: + switch_safe_free(mydata); + + return SWITCH_STATUS_SUCCESS; +} + #define LIMIT_RELEASE_SYNTAX " [realm] [resource]" SWITCH_STANDARD_API(uuid_limit_release_function) { @@ -5063,6 +5144,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", "Increase limit resource", uuid_limit_function, LIMIT_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); @@ -5181,6 +5263,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) switch_console_set_complete("add uuid_hold ::console::list_uuid"); switch_console_set_complete("add uuid_jitterbuffer ::console::list_uuid"); switch_console_set_complete("add uuid_kill ::console::list_uuid"); + switch_console_set_complete("add uuid_limit ::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");