int rl_get_counter_value(str *key) { unsigned int hash_idx; rl_pipe_t **pipe; int ret = -1; hash_idx = RL_GET_INDEX(*key); RL_GET_LOCK(hash_idx); /* try to get the value */ pipe = RL_FIND_PIPE(hash_idx, *key); if (!pipe || !*pipe) { LM_DBG("cannot find any pipe named %.*s\n", key->len, key->s); goto release; } if (RL_USE_CDB(*pipe)) { if (rl_get_counter(key, *pipe) < 0) { LM_ERR("cannot get the counter's value\n"); goto release; } } ret = rl_get_all_counters(*pipe); release: RL_RELEASE_LOCK(hash_idx); return ret; }
int rl_stats(struct mi_node *rpl, str * value) { rl_pipe_t **pipe; int i; if (value && value->s && value->len) { i = RL_GET_INDEX(*value); RL_GET_LOCK(i); pipe = RL_FIND_PIPE(i, *value); if (!pipe || !*pipe) { LM_DBG("pipe %.*s not found\n", value->len, value->s); goto error; } if (rl_map_print(rpl, *value, *pipe)) { LM_ERR("cannot print value for key %.*s\n", value->len, value->s); goto error; } RL_RELEASE_LOCK(i); } else { /* iterate through each map */ for (i = 0; i < rl_htable.size; i++) { RL_GET_LOCK(i); if (map_for_each(rl_htable.maps[i], rl_map_print, rpl)) { LM_ERR("cannot print values\n"); goto error; } RL_RELEASE_LOCK(i); } } return 0; error: RL_RELEASE_LOCK(i); return -1; }
int rl_stats(mi_item_t *resp_obj, str * value) { mi_item_t *pipe_item, *pipe_arr; rl_pipe_t **pipe; int i; if (value && value->s && value->len) { i = RL_GET_INDEX(*value); RL_GET_LOCK(i); pipe = RL_FIND_PIPE(i, *value); if (!pipe || !*pipe) { LM_DBG("pipe %.*s not found\n", value->len, value->s); goto error; } pipe_item = add_mi_object(resp_obj, MI_SSTR("Pipe")); if (!pipe_item) goto error; if (rl_map_print(pipe_item, *value, *pipe)) { LM_ERR("cannot print value for key %.*s\n", value->len, value->s); goto error; } RL_RELEASE_LOCK(i); } else { /* iterate through each map */ pipe_arr = add_mi_array(resp_obj, MI_SSTR("Pipes")); if (!pipe_arr) return -1; for (i = 0; i < rl_htable.size; i++) { pipe_item = add_mi_object(pipe_arr, NULL, 0); if (!pipe_item) return -1; RL_GET_LOCK(i); if (map_for_each(rl_htable.maps[i], rl_map_print, pipe_item)) { LM_ERR("cannot print values\n"); goto error; } RL_RELEASE_LOCK(i); } } return 0; error: RL_RELEASE_LOCK(i); return -1; }
int rl_stats(struct mi_root *rpl_tree, str * value) { rl_pipe_t **pipe; struct rl_param_t param; int i; memset(¶m, 0, sizeof(struct rl_param_t)); param.node = &rpl_tree->node; param.root = rpl_tree; if (value && value->s && value->len) { i = RL_GET_INDEX(*value); RL_GET_LOCK(i); pipe = RL_FIND_PIPE(i, *value); if (!pipe || !*pipe) { LM_DBG("pipe %.*s not found\n", value->len, value->s); goto error; } if (rl_map_print(¶m, *value, *pipe)) { LM_ERR("cannot print value for key %.*s\n", value->len, value->s); goto error; } RL_RELEASE_LOCK(i); } else { /* iterate through each map */ for (i = 0; i < rl_htable.size; i++) { RL_GET_LOCK(i); if (map_for_each(rl_htable.maps[i], rl_map_print, ¶m)) { LM_ERR("cannot print values\n"); goto error; } RL_RELEASE_LOCK(i); } } return 0; error: RL_RELEASE_LOCK(i); return -1; }
int w_rl_set_count(str key, int val) { unsigned int hash_idx; int ret = -1; rl_pipe_t **pipe; hash_idx = RL_GET_INDEX(key); RL_GET_LOCK(hash_idx); /* try to get the value */ pipe = RL_FIND_PIPE(hash_idx, key); if (!pipe || !*pipe) { LM_DBG("cannot find any pipe named %.*s\n", key.len, key.s); goto release; } if (RL_USE_CDB(*pipe)) { if (rl_change_counter(&key, *pipe, val) < 0) { LM_ERR("cannot decrease counter\n"); goto release; } } else if ((*pipe)->algo == PIPE_ALGO_HISTORY) { hist_set_count(*pipe, val); } else { if (val && (val + (*pipe)->counter >= 0)) { (*pipe)->counter += val; } else { (*pipe)->counter = 0; } } LM_DBG("new counter for key %.*s is %d\n", key.len, key.s, (*pipe)->counter); ret = 0; release: RL_RELEASE_LOCK(hash_idx); return ret; }