Skip to content

Commit

Permalink
Added sr_list_identifiers MI command
Browse files Browse the repository at this point in the history
A very simply and useful helper function for the Control Panel integration
  • Loading branch information
bogdan-iancu committed Jul 14, 2022
1 parent 3d8009c commit 5d20728
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mi/mi_core.c
Expand Up @@ -920,6 +920,14 @@ static mi_export_t mi_core_cmds[] = {
{EMPTY_MI_RECIPE}
}
},
{ "sr_list_identifiers", "list the identifiers from a group or all",
0, 0, {
{mi_sr_list_identifiers, {0}},
{mi_sr_list_identifiers, {"group",0}},
{EMPTY_MI_RECIPE}
}
},

{ "help", "prints information about MI commands usage", 0, 0, {
{w_mi_help, {0}},
{w_mi_help_1, {"mi_cmd", 0}},
Expand Down
82 changes: 82 additions & 0 deletions status_report.c
Expand Up @@ -1104,6 +1104,88 @@ mi_response_t *mi_sr_list_reports(const mi_params_t *params,

lock_stop_read( sr_lock );

return resp;
error:
lock_stop_read( sr_lock );
if (resp)
free_mi_response(resp);
return 0;
}


mi_response_t *mi_sr_list_identifiers(const mi_params_t *params,
struct mi_handler *async_hdl)
{
str group;
mi_response_t *resp;
mi_item_t *id_arr, *grp_arr, *grp_item;
sr_group *srg = NULL;
sr_identifier *sri = NULL;

if (try_get_mi_string_param(params, "group", &group.s, &group.len)==0) {

/* group provide */
if ( (srg=sr_get_group_by_name( group.s, group.len )) == NULL ) {
LM_DBG("SR group [%.*s] not found as registered\n",
group.len, group.s);
return init_mi_error(404, CHAR_INT("Group not found"));
}

}

lock_start_read( sr_lock );

if (srg) {

resp = init_mi_result_object( &grp_item);
if (!grp_item)
goto error;

if (add_mi_string( grp_item, CHAR_INT("Group"),
srg->name.s, srg->name.len)<0)
goto error;

id_arr = add_mi_array( grp_item, CHAR_INT("Identifiers"));
if (!id_arr)
goto error;

for ( sri=srg->identifiers ; sri ; sri=sri->next ) {
if (add_mi_string( id_arr, CHAR_INT("Name"),
sri->name.s, sri->name.len ) < 0 )
goto error;
}

} else {

resp = init_mi_result_array( &grp_arr);
if (!grp_arr)
goto error;

for ( srg=sr_groups ; srg ; srg=srg->next ) {

grp_item = add_mi_object(grp_arr, 0, 0);
if (!grp_item)
goto error;

if (add_mi_string( grp_item, CHAR_INT("Group"),
srg->name.s, srg->name.len)<0)
goto error;

id_arr = add_mi_array( grp_item, CHAR_INT("Identifiers"));
if (!id_arr)
goto error;

for ( sri=srg->identifiers ; sri ; sri=sri->next ) {
if (add_mi_string( id_arr, CHAR_INT("Name"),
sri->name.s, sri->name.len ) < 0 )
goto error;
}

}
}

lock_stop_read( sr_lock );

return resp;
error:
lock_stop_read( sr_lock );
Expand Down
2 changes: 2 additions & 0 deletions status_report.h
Expand Up @@ -104,6 +104,8 @@ mi_response_t *mi_sr_list_status(const mi_params_t *params,
mi_response_t *mi_sr_list_reports(const mi_params_t *params,
struct mi_handler *async_hdl);

mi_response_t *mi_sr_list_identifiers(const mi_params_t *params,
struct mi_handler *async_hdl);
#endif


0 comments on commit 5d20728

Please sign in to comment.