static int rl_map_print(void *param, str key, void *value) { struct mi_attr* attr; char* p; int len; rl_pipe_t *pipe = (rl_pipe_t *)value; struct mi_node * rpl = (struct mi_node *)param; struct mi_node * node; str *alg; if (!pipe) { LM_ERR("invalid pipe value\n"); return -1; } if (!rpl) { LM_ERR("no reply node\n"); return -1; } if (!key.len || !key.s) { LM_ERR("no key found\n"); return -1; } LM_DBG("Algorithm is %d (%p)\n", pipe->algo, pipe); /* skip if no algo */ if (pipe->algo == PIPE_ALGO_NOP) return 0; if (!(node = add_mi_node_child(rpl, 0, "PIPE", 4, 0, 0))) return -1; if (!(attr = add_mi_attr(node, MI_DUP_VALUE, "id", 2, key.s, key.len))) return -1; if (!(alg = get_rl_algo_name(pipe->algo))) { LM_ERR("[BUG] unknown algorithm %d\n", pipe->algo); return -1; } if (!(attr = add_mi_attr(node, MI_DUP_VALUE, "algorithm", 9, alg->s, alg->len))) return -1; p = int2str((unsigned long)(pipe->limit), &len); if (!(attr = add_mi_attr(node, MI_DUP_VALUE, "limit", 5, p, len))) return -1; p = int2str((unsigned long)(pipe->last_counter), &len); if (!(attr = add_mi_attr(node, MI_DUP_VALUE, "counter", 7, p, len))) return -1; return 0; }
static int rl_map_print(void *param, str key, void *value) { rl_pipe_t *pipe = (rl_pipe_t *) value; str *alg; mi_item_t *pipe_item = (mi_item_t *)param; if (!pipe) { LM_ERR("invalid pipe value\n"); return -1; } if (!pipe_item) { LM_ERR("no mi item\n"); return -1; } if (!key.len || !key.s) { LM_ERR("no key found\n"); return -1; } /* skip if no algo */ if (pipe->algo == PIPE_ALGO_NOP) return 0; if (add_mi_string(pipe_item, MI_SSTR("id"), key.s, key.len) < 0) return -1; if (!(alg = get_rl_algo_name(pipe->algo))) { LM_ERR("[BUG] unknown algorithm %d\n", pipe->algo); return -1; } if (add_mi_string(pipe_item, MI_SSTR("algorithm"), alg->s, alg->len) < 0) return -1; if (add_mi_number(pipe_item, MI_SSTR("limit"), pipe->limit) < 0) return -1; if (add_mi_number(pipe_item, MI_SSTR("counter"), pipe->last_counter) < 0) return -1; return 0; }
static int rl_map_print(void *param, str key, void *value) { struct mi_attr* attr; char* p; int len; struct rl_param_t * rl_param = (struct rl_param_t *)param; struct mi_node * rpl; rl_pipe_t *pipe = (rl_pipe_t *)value; struct mi_node * node; str *alg; if (!pipe) { LM_ERR("invalid pipe value\n"); return -1; } if (!rl_param || !rl_param->node || !rl_param->root) { LM_ERR("no reply node\n"); return -1; } rpl = rl_param->node; if (!key.len || !key.s) { LM_ERR("no key found\n"); return -1; } /* skip if no algo */ if (pipe->algo == PIPE_ALGO_NOP) return 0; if (!(node = add_mi_node_child(rpl, 0, "PIPE", 4, 0, 0))) return -1; if (!(attr = add_mi_attr(node, MI_DUP_VALUE, "id", 2, key.s, key.len))) return -1; if (!(alg = get_rl_algo_name(pipe->algo))) { LM_ERR("[BUG] unknown algorithm %d\n", pipe->algo); return -1; } if (!(attr = add_mi_attr(node, MI_DUP_VALUE, "algorithm", 9, alg->s, alg->len))) return -1; p = int2str((unsigned long)(pipe->limit), &len); if (!(attr = add_mi_attr(node, MI_DUP_VALUE, "limit", 5, p, len))) return -1; p = int2str((unsigned long)rl_get_all_counters(pipe), &len); if (!(attr = add_mi_attr(node, MI_DUP_VALUE, "counter", 7, p, len))) return -1; if ((++rl_param->counter % 50) == 0) { LM_DBG("flush mi tree - number %d\n", rl_param->counter); flush_mi_tree(rl_param->root); } return 0; }