Skip to content

Commit

Permalink
ratelimit MI rl_list: Improve handling for non-existing pipes
Browse files Browse the repository at this point in the history
Fixes #1863

(cherry picked from commit b0aa68e)
  • Loading branch information
liviuchircu committed Jan 17, 2020
1 parent 88624ba commit 4e3d09b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions modules/ratelimit/ratelimit.c
Expand Up @@ -629,7 +629,7 @@ mi_response_t *mi_stats(const mi_params_t *params,
if (!resp)
return 0;

if (rl_stats(resp_obj, NULL)) {
if (rl_stats(resp_obj, NULL) < 0) {
LM_ERR("cannot mi print values\n");
goto free;
}
Expand All @@ -654,6 +654,7 @@ mi_response_t *mi_stats_1(const mi_params_t *params,
mi_response_t *resp;
mi_item_t *resp_obj;
str pipe_name;
int rc;

resp = init_mi_result_object(&resp_obj);
if (!resp)
Expand All @@ -662,9 +663,12 @@ mi_response_t *mi_stats_1(const mi_params_t *params,
if (get_mi_string_param(params, "pipe", &pipe_name.s, &pipe_name.len) < 0)
return init_mi_param_error();

if (rl_stats(resp_obj, &pipe_name)) {
rc = rl_stats(resp_obj, &pipe_name);
if (rc < 0) {
LM_ERR("cannot mi print values\n");
goto free;
} else if (rc == 1) {
return init_mi_error(404, MI_SSTR("Pipe Not Found"));
}

LOCK_GET(rl_lock);
Expand Down
3 changes: 2 additions & 1 deletion modules/ratelimit/ratelimit_helper.c
Expand Up @@ -594,7 +594,8 @@ int rl_stats(mi_item_t *resp_obj, str * value)
pipe = RL_FIND_PIPE(i, *value);
if (!pipe || !*pipe) {
LM_DBG("pipe %.*s not found\n", value->len, value->s);
goto error;
RL_RELEASE_LOCK(i);
return 1;
}
pipe_item = add_mi_object(resp_obj, MI_SSTR("Pipe"));
if (!pipe_item)
Expand Down

0 comments on commit 4e3d09b

Please sign in to comment.