int rpc_pl_list_pipe(rpc_t *rpc, void *c, pl_pipe_t *it) { str algo; void* th; if (it->algo == PIPE_ALGO_NOP) { return 0; } if (str_map_int(algo_names, it->algo, &algo)) { return -1; } /* add structure node */ if (rpc->add(c, "{", &th) < 0) { rpc->fault(c, 500, "Internal pipe structure"); return -1; } if(rpc->struct_add(th, "ssdddd", "name", it->name.s, "algorithm", algo.s, "limit", it->limit, "counter", it->counter, "last_counter", it->last_counter, "unused_intervals", it->unused_intervals)<0) { rpc->fault(c, 500, "Internal error address list structure"); return -1; } return 0; }
void rpc_pl_get_pipes(rpc_t *rpc, void *c) { int i; str algo; pl_pipe_t *it; for(i=0; i<_pl_pipes_ht->htsize; i++) { lock_get(&_pl_pipes_ht->slots[i].lock); it = _pl_pipes_ht->slots[i].first; while(it) { if (it->algo != PIPE_ALGO_NOP) { if (str_map_int(algo_names, it->algo, &algo)) { lock_release(&_pl_pipes_ht->slots[i].lock); return; } if (rpc->rpl_printf(c, "PIPE: id=%.*s algorithm=%.*s limit=%d counter=%d", it->name.len, it->name.s, algo.len, algo.s, it->limit, it->counter) < 0) { lock_release(&_pl_pipes_ht->slots[i].lock); return; } } it = it->next; } lock_release(&_pl_pipes_ht->slots[i].lock); } }
struct mi_root* mi_get_pipes(struct mi_root* cmd_tree, void* param) { struct mi_root *rpl_tree; struct mi_node *node=NULL, *rpl=NULL; struct mi_attr* attr; str algo; char* p; int i, len; rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); if (rpl_tree==0) return 0; rpl = &rpl_tree->node; LOCK_GET(rl_lock); for (i=0; i<MAX_PIPES; i++) { if (*pipes[i].algo != PIPE_ALGO_NOP) { node = add_mi_node_child(rpl, 0, "PIPE", 4, 0, 0); if(node == NULL) goto error; p = int2str((unsigned long)(i), &len); attr = add_mi_attr(node, MI_DUP_VALUE, "id" , 2, p, len); if(attr == NULL) goto error; p = int2str((unsigned long)(*pipes[i].algo), &len); if (str_map_int(algo_names, *pipes[i].algo, &algo)) goto error; attr = add_mi_attr(node, 0, "algorithm", 9, algo.s, algo.len); if(attr == NULL) goto error; p = int2str((unsigned long)(*pipes[i].limit), &len); attr = add_mi_attr(node, MI_DUP_VALUE, "limit", 5, p, len); if(attr == NULL) goto error; p = int2str((unsigned long)(*pipes[i].counter), &len); attr = add_mi_attr(node, MI_DUP_VALUE, "counter", 7, p, len); if(attr == NULL) goto error; } } LOCK_RELEASE(rl_lock); return rpl_tree; error: LOCK_RELEASE(rl_lock); LM_ERR("Unable to create reply\n"); free_mi_tree(rpl_tree); return 0; }
static void rpc_get_pipes(rpc_t *rpc, void *c) { str algo; int i; LOCK_GET(rl_lock); for (i=0; i<MAX_PIPES; i++) { if (*pipes[i].algo != PIPE_ALGO_NOP) { if (str_map_int(algo_names, *pipes[i].algo, &algo)) goto error; if (rpc->printf(c, "PIPE[%d]: %d:%.*s %d/%d (drop rate: %d) [%d]", i, *pipes[i].algo, algo.len, algo.s, *pipes[i].last_counter, *pipes[i].limit, *pipes[i].load, *pipes[i].counter) < 0) goto error; } } error: LOCK_RELEASE(rl_lock); }
struct mi_root* mi_get_pipes(struct mi_root* cmd_tree, void* param) { struct mi_root *rpl_tree; struct mi_node *node=NULL, *rpl=NULL; struct mi_attr* attr; str algo; char* p; int i, len; pl_pipe_t *it; rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); if (rpl_tree==0) return 0; rpl = &rpl_tree->node; for(i=0; i<_pl_pipes_ht->htsize; i++) { lock_get(&_pl_pipes_ht->slots[i].lock); it = _pl_pipes_ht->slots[i].first; while(it) { if (it->algo != PIPE_ALGO_NOP) { node = add_mi_node_child(rpl, 0, "PIPE", 4, 0, 0); if(node == NULL) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } attr = add_mi_attr(node, MI_DUP_VALUE, "id" , 2, it->name.s, it->name.len); if(attr == NULL) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } if (str_map_int(algo_names, it->algo, &algo)) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } attr = add_mi_attr(node, 0, "algorithm", 9, algo.s, algo.len); if(attr == NULL) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } p = int2str((unsigned long)(it->limit), &len); attr = add_mi_attr(node, MI_DUP_VALUE, "limit", 5, p, len); if(attr == NULL) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } p = int2str((unsigned long)(it->counter), &len); attr = add_mi_attr(node, MI_DUP_VALUE, "counter", 7, p, len); if(attr == NULL) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } } it = it->next; } lock_release(&_pl_pipes_ht->slots[i].lock); } return rpl_tree; error: LM_ERR("Unable to create reply\n"); free_mi_tree(rpl_tree); return 0; }