Skip to content

Commit

Permalink
Merge pull request #2731 from john08burke/dispatch_list
Browse files Browse the repository at this point in the history
dispatcher: add optional partition param to MI `ds_list`
  • Loading branch information
bogdan-iancu committed Jan 18, 2022
2 parents 09f965b + b5426d7 commit 28f7b07
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
24 changes: 20 additions & 4 deletions modules/dispatcher/dispatcher.c
Expand Up @@ -333,7 +333,9 @@ static mi_export_t mi_cmds[] = {
},
{ "ds_list", 0, 0, 0, {
{w_ds_mi_list, {0}},
{w_ds_mi_list, {"partition", 0}},
{w_ds_mi_list_1, {"full", 0}},
{w_ds_mi_list_1, {"full", "partition", 0}},
{EMPTY_MI_RECIPE}}
},
{ "ds_reload", 0, 0, mi_child_init, {
Expand Down Expand Up @@ -1281,22 +1283,36 @@ mi_response_t *ds_mi_set(const mi_params_t *params,
return init_mi_result_ok();
}

mi_response_t *ds_mi_list(int full)
mi_response_t *ds_mi_list(const mi_params_t *params, int full)
{
str partition_name;
mi_response_t *resp;
mi_item_t *resp_obj;
mi_item_t *parts_arr, *part_item;
ds_partition_t *part_it;
ds_partition_t *partition=NULL, *part_it;

resp = init_mi_result_object(&resp_obj);
if (!resp)
return 0;

if (try_get_mi_string_param(params, "partition", &partition_name.s, &partition_name.len) == 0) {
if (partition_name.s==NULL)
return init_mi_error(500, MI_SSTR("partition param not found"));

partition = find_partition_by_name(&partition_name);

if (partition == NULL)
return init_mi_error(500, MI_SSTR(MI_UNK_PARTITION));
}

parts_arr = add_mi_array(resp_obj, MI_SSTR("PARTITIONS"));
if (!parts_arr)
goto error;

for (part_it = partitions; part_it; part_it = part_it->next) {
if (partition!=NULL && partition!=part_it)
continue;

part_item = add_mi_object(parts_arr, NULL, 0);
if (!part_item)
goto error;
Expand All @@ -1319,7 +1335,7 @@ mi_response_t *ds_mi_list(int full)
mi_response_t *w_ds_mi_list(const mi_params_t *params,
struct mi_handler *async_hdl)
{
return ds_mi_list(0);
return ds_mi_list(params, 0);
}

mi_response_t *w_ds_mi_list_1(const mi_params_t *params,
Expand All @@ -1330,7 +1346,7 @@ mi_response_t *w_ds_mi_list_1(const mi_params_t *params,
if (get_mi_int_param(params, "full", &full) < 0)
return init_mi_param_error();

return ds_mi_list(full);
return ds_mi_list(params, full);
}

mi_response_t *ds_mi_reload(const mi_params_t *params,
Expand Down
4 changes: 4 additions & 0 deletions modules/dispatcher/doc/dispatcher_admin.xml
Expand Up @@ -1652,6 +1652,10 @@ opensips-cli -x mi ds_set_state a 2 sip:10.0.0.202
<emphasis>full</emphasis> (optional) - adds the weight,
priority and description fields to the listing
</para></listitem>
<listitem><para>
<emphasis>partition</emphasis> (optional) - return only
destinations and sets in the provided partition.
</para></listitem>
</itemizedlist>
<para>
MI FIFO Command Format:
Expand Down

0 comments on commit 28f7b07

Please sign in to comment.