Skip to content

Commit

Permalink
Fix the structure of MI tree (output).
Browse files Browse the repository at this point in the history
Mark the nodes that contain arrays of subnodes (versus list of differente nodes). This is a must in order to properly structure the MI output via the json backend.

(cherry picked from commit 34576f5)
  • Loading branch information
bogdan-iancu committed May 7, 2014
1 parent ccbe2e2 commit 492f939
Show file tree
Hide file tree
Showing 29 changed files with 151 additions and 70 deletions.
6 changes: 5 additions & 1 deletion evi/event_interface.c
Expand Up @@ -486,6 +486,8 @@ struct mi_root * mi_events_list(struct mi_root *cmd_tree, void *param)
if (rpl_tree==0)
return 0;
rpl = &rpl_tree->node;
rpl->flags |= MI_IS_ARRAY;

for (i = 0; i < events_no; i++) {
node = add_mi_node_child(rpl, 0, "Event", 5,
events[i].name.s, events[i].name.len);
Expand Down Expand Up @@ -564,7 +566,8 @@ static int evi_print_event(struct evi_mi_param *param,
if (!subs && !ev->subscribers)
return 0;

node = add_mi_node_child(rpl, 0, "Event", 5, ev->name.s, ev->name.len);
node = add_mi_node_child(rpl, MI_IS_ARRAY, "Event", 5,
ev->name.s, ev->name.len);
if(node == NULL)
goto error;

Expand Down Expand Up @@ -651,6 +654,7 @@ struct mi_root * mi_subscribers_list(struct mi_root *cmd_tree, void *param)
memset(&prm, 0, sizeof(struct evi_mi_param));

rpl = &rpl_tree->node;
rpl->flags |= MI_IS_ARRAY;
node = cmd_tree->node.kids;
prm.node = rpl;
prm.root = rpl_tree;
Expand Down
3 changes: 3 additions & 0 deletions mi/mi_core.c
Expand Up @@ -186,6 +186,7 @@ static struct mi_root *mi_arg(struct mi_root *cmd, void *param)
if (rpl_tree==0)
return 0;
rpl = &rpl_tree->node;
rpl->flags |= MI_IS_ARRAY;

for ( n=0; n<my_argc ; n++ ) {
node = add_mi_node_child(rpl, 0, 0, 0, my_argv[n], strlen(my_argv[n]));
Expand Down Expand Up @@ -214,6 +215,7 @@ static struct mi_root *mi_which(struct mi_root *cmd, void *param)
if (rpl_tree==0)
return 0;
rpl = &rpl_tree->node;
rpl->flags |= MI_IS_ARRAY;

get_mi_cmds( &cmds, &size);
for ( i=0 ; i<size ; i++ ) {
Expand Down Expand Up @@ -245,6 +247,7 @@ static struct mi_root *mi_ps(struct mi_root *cmd, void *param)
if (rpl_tree==0)
return 0;
rpl = &rpl_tree->node;
rpl->flags |= MI_IS_ARRAY;

for ( i=0 ; i<counted_processes ; i++ ) {
node = add_mi_node_child(rpl, 0, MI_SSTR("Process"), 0, 0 );
Expand Down
3 changes: 2 additions & 1 deletion mi/tree.h
Expand Up @@ -48,7 +48,8 @@ struct mi_handler;
#define MI_DUP_NAME (1<<0)
#define MI_DUP_VALUE (1<<1)
#define MI_NOT_COMPLETED (1<<2)
#define MI_WRITTEN (1<<3)
#define MI_WRITTEN (1<<3)
#define MI_IS_ARRAY (1<<4)

#define MI_OK_S "OK"
#define MI_OK_LEN (sizeof(MI_OK_S)-1)
Expand Down
46 changes: 25 additions & 21 deletions modules/b2b_entities/b2b_entities.c
Expand Up @@ -499,7 +499,7 @@ static inline int mi_print_b2be_dlg(struct mi_node *rpl, b2b_table htable, unsig
char* p;
b2b_dlg_t* dlg;
dlg_leg_t* leg;
struct mi_node *node=NULL, *node1=NULL;
struct mi_node *node=NULL, *node1=NULL, *node_l=NULL;
struct mi_attr* attr;

for(i = 0; i< hsize; i++)
Expand Down Expand Up @@ -625,29 +625,32 @@ static inline int mi_print_b2be_dlg(struct mi_node *rpl, b2b_table htable, unsig
if(attr == NULL) goto error;
}

leg=dlg->legs;
while(leg)
{
p = int2str((unsigned long)(leg->id), &len);
node1 = add_mi_node_child(node, MI_DUP_VALUE, "leg", 3, p, len);
if(node1 == NULL) goto error;
attr = add_mi_attr(node1, MI_DUP_VALUE, "tag", 3,
leg->tag.s, leg->tag.len);
if(attr == NULL) goto error;
p = int2str((unsigned long)(leg->cseq), &len);
attr = add_mi_attr(node1, MI_DUP_VALUE, "cseq", 4, p, len);
if(attr == NULL) goto error;
attr = add_mi_attr(node1, MI_DUP_VALUE, "contact", 7,
leg->contact.s, leg->contact.len);
if(attr == NULL) goto error;
if(leg->route_set.len)
if ( (leg=dlg->legs)!=NULL ) {
node_l = add_mi_node_child(node, MI_IS_ARRAY, "LEGS", 4, NULL, 0);
if(node_l == NULL) goto error;
while(leg)
{
attr = add_mi_attr(node1, MI_DUP_VALUE, "route_set", 8,
leg->route_set.s, leg->route_set.len);
p = int2str((unsigned long)(leg->id), &len);
node1 = add_mi_node_child(node_l, MI_DUP_VALUE, "leg", 3, p, len);
if(node1 == NULL) goto error;
attr = add_mi_attr(node1, MI_DUP_VALUE, "tag", 3,
leg->tag.s, leg->tag.len);
if(attr == NULL) goto error;
p = int2str((unsigned long)(leg->cseq), &len);
attr = add_mi_attr(node1, MI_DUP_VALUE, "cseq", 4, p, len);
if(attr == NULL) goto error;
attr = add_mi_attr(node1, MI_DUP_VALUE, "contact", 7,
leg->contact.s, leg->contact.len);
if(attr == NULL) goto error;
if(leg->route_set.len)
{
attr = add_mi_attr(node1, MI_DUP_VALUE, "route_set", 8,
leg->route_set.s, leg->route_set.len);
if(attr == NULL) goto error;
}

leg=leg->next;
}

leg=leg->next;
}

dlg = dlg->next;
Expand All @@ -669,6 +672,7 @@ static struct mi_root* mi_b2be_list(struct mi_root* cmd, void* param)
rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
if (rpl_tree==NULL) return NULL;
rpl = &rpl_tree->node;
rpl->flags |= MI_IS_ARRAY;

if (server_htable)
if (mi_print_b2be_dlg(rpl, server_htable, server_hsize)!=0)
Expand Down
36 changes: 26 additions & 10 deletions modules/b2b_logic/b2b_logic.c
Expand Up @@ -1460,12 +1460,13 @@ static struct mi_root* mi_b2b_list(struct mi_root* cmd, void* param)
char* p;
b2bl_tuple_t* tuple;
struct mi_root *rpl_tree;
struct mi_node *node=NULL, *node1=NULL, *rpl=NULL;
struct mi_node *node=NULL, *node1=NULL, *rpl=NULL, *node_a=NULL;
struct mi_attr* attr;

rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
if (rpl_tree==NULL) return NULL;
rpl = &rpl_tree->node;
rpl->flags |= MI_IS_ARRAY;

for(i = 0; i< b2bl_hsize; i++)
{
Expand Down Expand Up @@ -1500,39 +1501,54 @@ static struct mi_root* mi_b2b_list(struct mi_root* cmd, void* param)
if(attr == NULL) goto error;
}

for (index = 0; index < MAX_B2BL_ENT; index++)
for (node_a=NULL,index=0; index < MAX_B2BL_ENT; index++)
{
if (tuple->servers[index] != NULL)
{
if (node_a==NULL) {
node_a = add_mi_node_child(node, MI_IS_ARRAY,
"SERVERS", 7, NULL, 0);
if (node_a==NULL) goto error;
}
p = int2str((unsigned long)(index), &len);
node1 = add_mi_node_child(node, MI_DUP_VALUE,
"servers", 7, p, len);
node1 = add_mi_node_child(node_a, MI_DUP_VALUE,
"server", 6, p, len);
if(node1 == NULL) goto error;
if (internal_mi_print_b2bl_entity_id(node1,
tuple->servers[index])!=0)
goto error;
}
}
for (index = 0; index < MAX_B2BL_ENT; index++)
for (node_a=NULL,index=0; index < MAX_B2BL_ENT; index++)
{
if (tuple->clients[index] != NULL)
{
if (node_a==NULL) {
node_a = add_mi_node_child(node, MI_IS_ARRAY,
"CLIENTS", 7, NULL, 0);
if (node_a==NULL) goto error;
}
p = int2str((unsigned long)(index), &len);
node1 = add_mi_node_child(node, MI_DUP_VALUE,
"clients", 7, p, len);
node1 = add_mi_node_child(node_a, MI_DUP_VALUE,
"client", 6, p, len);
if(node1 == NULL) goto error;
if (internal_mi_print_b2bl_entity_id(node1,
tuple->clients[index])!=0)
goto error;
}
}
for (index = 0; index < MAX_BRIDGE_ENT; index++)
for (node_a=NULL,index=0; index < MAX_BRIDGE_ENT; index++)
{
if (tuple->bridge_entities[index] != NULL)
{
if (node_a==NULL) {
node_a = add_mi_node_child(node, MI_IS_ARRAY,
"BRIDGE_ENTITIES", 15, NULL, 0);
if (node_a==NULL) goto error;
}
p = int2str((unsigned long)(index), &len);
node1 = add_mi_node_child(node, MI_DUP_VALUE,
"bridge_entities", 15, p, len);
node1 = add_mi_node_child(node_a, MI_DUP_VALUE,
"bridge_entitie", 14, p, len);
if(node1 == NULL) goto error;
if (internal_mi_print_b2bl_entity_id(node1,
tuple->bridge_entities[index])!=0)
Expand Down
11 changes: 6 additions & 5 deletions modules/b2b_sca/b2b_sca.c
Expand Up @@ -155,13 +155,13 @@ static param_export_t params[]=
{"app10_call_info_uri_column", STR_PARAM,&app_call_info_uri_column[9].s },
{"app10_call_info_appearance_uri_column",STR_PARAM,&app_call_info_appearance_uri_column[9].s},
{"app10_b2bl_key_column", STR_PARAM,&app_b2bl_key_column[9].s },
{0, 0, 0 }
{0, 0, 0 }
};

/** MI commands */
static mi_export_t mi_cmds[] = {
{ "sca_list", 0, mi_sca_list, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0}
{ "sca_list", 0, mi_sca_list, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0}
};

/** Module interface */
Expand Down Expand Up @@ -480,13 +480,14 @@ static struct mi_root* mi_sca_list(struct mi_root* cmd, void* param)
rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
if (rpl_tree==NULL) return NULL;
rpl = &rpl_tree->node;
rpl->flags |= MI_IS_ARRAY;

for(index = 0; index<b2b_sca_hsize; index++) {
lock_get(&b2b_sca_htable[index].lock);
rec = b2b_sca_htable[index].first;
while(rec) {
node = add_mi_node_child(rpl, MI_DUP_VALUE, "shared_line", 11,
rec->shared_line.s, rec->shared_line.len);
node = add_mi_node_child(rpl, MI_IS_ARRAY|MI_DUP_VALUE,
"shared_line", 11,rec->shared_line.s, rec->shared_line.len);
if(node == NULL) goto error;
watcher = rec->watchers;
while (watcher) {
Expand Down
1 change: 1 addition & 0 deletions modules/benchmark/benchmark.c
Expand Up @@ -677,6 +677,7 @@ static struct mi_root* mi_bm_poll_results(struct mi_root *cmd, void *param)
LM_ERR("Could not allocate the reply mi tree");
return NULL;
}
rpl_tree->node.flags |= MI_IS_ARRAY;

for(bmt = bm_mycfg->timers; bmt!=NULL; bmt=bmt->next) {
lock_get(bmt->lock);
Expand Down
4 changes: 4 additions & 0 deletions modules/call_center/call_center.c
Expand Up @@ -1038,6 +1038,7 @@ static struct mi_root* mi_cc_list_flows(struct mi_root *cmd, void *param)
if ( rpl_tree==NULL)
return NULL;
rpl = &rpl_tree->node;
rpl->flags |= MI_IS_ARRAY;

/* block access to data */
lock_get( data->lock );
Expand Down Expand Up @@ -1105,6 +1106,7 @@ static struct mi_root* mi_cc_list_agents(struct mi_root *cmd_tree, void *param)
if ( rpl_tree==NULL)
return NULL;
rpl = &rpl_tree->node;
rpl->flags |= MI_IS_ARRAY;

/* block access to data */
lock_get( data->lock );
Expand Down Expand Up @@ -1172,6 +1174,7 @@ static struct mi_root* mi_cc_list_calls(struct mi_root *cmd_tree, void *param)
if ( rpl_tree==NULL)
return NULL;
rpl = &rpl_tree->node;
rpl->flags |= MI_IS_ARRAY;

/* block access to data */
lock_get( data->lock );
Expand Down Expand Up @@ -1348,6 +1351,7 @@ static struct mi_root* mi_cc_list_queue(struct mi_root *cmd_tree, void *param)
if ( rpl_tree==NULL)
return NULL;
rpl = &rpl_tree->node;
rpl->flags |= MI_IS_ARRAY;

n = 0;
now = get_ticks();
Expand Down
1 change: 1 addition & 0 deletions modules/carrierroute/route_fifo.c
Expand Up @@ -132,6 +132,7 @@ struct mi_root* dump_fifo (struct mi_root* cmd_tree, void *param) {
rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
if(rpl_tree == NULL)
return 0;
rpl_tree->node.flags |= MI_IS_ARRAY;
node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "Printing routing information:");
if(node == NULL)
goto error;
Expand Down
3 changes: 2 additions & 1 deletion modules/db_virtual/db_virtual.c
Expand Up @@ -479,10 +479,11 @@ struct mi_root *db_get_info(struct mi_root *cmd, void *param){
if (rpl_tree==0)
return 0;
rpl = &rpl_tree->node;
rpl->flags |= MI_IS_ARRAY;


for(i=0; i < global->size; i++ ){
node = add_mi_node_child(rpl, 0, MI_SSTR("SET"), 0, 0 );
node = add_mi_node_child(rpl, MI_IS_ARRAY, MI_SSTR("SET"), 0, 0 );
if (node==0)
goto error;

Expand Down
35 changes: 22 additions & 13 deletions modules/dialog/dlg_hash.c
Expand Up @@ -1039,38 +1039,46 @@ static inline int internal_mi_print_dlg(struct mi_node *rpl,
goto error;
}

node1 = add_mi_node_child(node, MI_IS_ARRAY, "CALLEES", 7, NULL, 0);
if(node1 == 0)
goto error;

for( i=1 ; i < dlg->legs_no[DLG_LEGS_USED] ; i++ ) {

node1 = add_mi_node_child(node, MI_DUP_VALUE, "callee_tag", 10,
node2 = add_mi_node_child(node1, 0, "callee", 6, NULL, 0);
if(node2 == 0)
goto error;

node3 = add_mi_node_child(node2, MI_DUP_VALUE, "callee_tag", 10,
dlg->legs[i].tag.s, dlg->legs[i].tag.len);
if(node1 == 0)
if(node3 == 0)
goto error;

node1 = add_mi_node_child(node, MI_DUP_VALUE, "callee_contact", 14,
node3 = add_mi_node_child(node2, MI_DUP_VALUE, "callee_contact", 14,
dlg->legs[i].contact.s, dlg->legs[i].contact.len);
if(node1 == 0)
if(node3 == 0)
goto error;

node1 = add_mi_node_child(node, MI_DUP_VALUE, "caller_cseq", 11,
node3 = add_mi_node_child(node2, MI_DUP_VALUE, "caller_cseq", 11,
dlg->legs[i].r_cseq.s, dlg->legs[i].r_cseq.len);
if(node1 == 0)
if(node3 == 0)
goto error;

node1 = add_mi_node_child(node, MI_DUP_VALUE,"callee_route_set",16,
node3 = add_mi_node_child(node2, MI_DUP_VALUE,"callee_route_set",16,
dlg->legs[i].route_set.s, dlg->legs[i].route_set.len);
if(node1 == 0)
if(node3 == 0)
goto error;

if (dlg->legs[i].bind_addr) {
node1 = add_mi_node_child(node, 0,
node3 = add_mi_node_child(node2, 0,
"callee_bind_addr",16,
dlg->legs[i].bind_addr->sock_str.s,
dlg->legs[i].bind_addr->sock_str.len);
} else {
node1 = add_mi_node_child(node, 0,
node3 = add_mi_node_child(node2, 0,
"callee_bind_addr",16,0,0);
}
if(node1 == 0)
if(node3 == 0)
goto error;
}

Expand All @@ -1079,7 +1087,7 @@ static inline int internal_mi_print_dlg(struct mi_node *rpl,
if(node1 == 0)
goto error;
if (dlg->vals) {
node2 = add_mi_node_child(node1, 0, "values", 6, 0, 0);
node2 = add_mi_node_child(node1, MI_IS_ARRAY, "values", 6, 0, 0);
if(node2 == 0)
goto error;
/* print dlg values -> iterate the list */
Expand Down Expand Up @@ -1116,7 +1124,7 @@ static inline int internal_mi_print_dlg(struct mi_node *rpl,
}
/* print dlg profiles */
if (dlg->profile_links) {
node3 = add_mi_node_child(node1, 0, "profiles", 8, 0, 0);
node3 = add_mi_node_child(node1, MI_IS_ARRAY, "profiles", 8, 0, 0);
if(node3 == 0)
goto error;
for( dl=dlg->profile_links ; dl ; dl=dl->next) {
Expand Down Expand Up @@ -1286,6 +1294,7 @@ struct mi_root * mi_print_dlgs(struct mi_root *cmd_tree, void *param )
if (rpl_tree==0)
goto error;
rpl = &rpl_tree->node;
rpl->flags |= MI_IS_ARRAY;

if (dlg==NULL) {
if ( internal_mi_print_dlgs(rpl_tree, rpl, 0, idx, cnt)!=0 )
Expand Down

0 comments on commit 492f939

Please sign in to comment.