Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mod_hash: add select_limit and delete_limit to api command #2518

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/mod/applications/mod_hash/mod_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ SWITCH_STANDARD_APP(hash_function)
switch_safe_free(hash_key);
}

#define HASH_API_USAGE "insert|insert_ifempty|select|delete|delete_ifmatch/realm/key[/value]"
#define HASH_API_USAGE "insert|insert_ifempty|select|delete|delete_ifmatch|select_limit|delete_limit/realm/key[/value]"
SWITCH_STANDARD_API(hash_api_function)
{
int argc = 0;
Expand Down Expand Up @@ -547,6 +547,23 @@ SWITCH_STANDARD_API(hash_api_function)
stream->write_function(stream, "%s", value);
}
switch_thread_rwlock_unlock(globals.db_hash_rwlock);
} else if (!strcasecmp(argv[0], "select_limit")) {
limit_hash_item_t *item = NULL;
switch_thread_rwlock_rdlock(globals.limit_hash_rwlock);
if ((item = switch_core_hash_find(globals.limit_hash, hash_key))) {
stream->write_function(stream, "%d", item->total_usage);
}
switch_thread_rwlock_unlock(globals.limit_hash_rwlock);
} else if (!strcasecmp(argv[0], "delete_limit")) {
limit_hash_item_t *item = NULL;
switch_thread_rwlock_rdlock(globals.limit_hash_rwlock);
if ((item = switch_core_hash_find(globals.limit_hash, hash_key))) {
switch_core_hash_delete(globals.limit_hash, hash_key);
stream->write_function(stream, "+OK\n");
} else {
stream->write_function(stream, "-ERR Not found\n");
}
switch_thread_rwlock_unlock(globals.limit_hash_rwlock);
} else {
goto usage;
}
Expand Down