Skip to content

Commit a899792

Browse files
committed
mi: have which return all functions within a module
1 parent 28d0b7b commit a899792

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

mi/mi_core.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,20 +213,48 @@ static mi_response_t *mi_which_cmd(const mi_params_t *params,
213213
{
214214
mi_item_t *resp_arr, *cmd_arr;
215215
mi_response_t *resp;
216+
struct mi_cmd *cmds;
216217
struct mi_cmd *cmd;
217218
str cmd_str;
219+
int found;
220+
int size;
218221
int i, j;
219222

223+
if (get_mi_string_param(params, "command", &cmd_str.s, &cmd_str.len) < 0)
224+
return init_mi_param_error();
225+
220226
resp = init_mi_result_array(&resp_arr);
221227
if (!resp)
222228
return 0;
223229

224-
if (get_mi_string_param(params, "command", &cmd_str.s, &cmd_str.len) < 0)
225-
return init_mi_param_error();
230+
if (cmd_str.len > 0 && cmd_str.s[cmd_str.len - 1] == ':') {
231+
found = 0;
232+
get_mi_cmds(&cmds, &size);
233+
for (i = 0; i < size; i++) {
234+
if (cmds[i].name.len < cmd_str.len ||
235+
memcmp(cmds[i].name.s, cmd_str.s, cmd_str.len) != 0)
236+
continue;
237+
found = 1;
238+
if (add_mi_string(resp_arr, 0, 0,
239+
cmds[i].name.s, cmds[i].name.len) < 0) {
240+
LM_ERR("failed to add mi item\n");
241+
free_mi_response(resp);
242+
return 0;
243+
}
244+
}
245+
246+
if (found)
247+
return resp;
248+
249+
free_mi_response(resp);
250+
return init_mi_error(404, MI_SSTR("unknown MI command"));
251+
}
226252

227253
cmd = lookup_mi_cmd(cmd_str.s, cmd_str.len);
228-
if (!cmd)
254+
if (!cmd) {
255+
free_mi_response(resp);
229256
return init_mi_error(404, MI_SSTR("unknown MI command"));
257+
}
230258
for (i = 0; i < MAX_MI_RECIPES && cmd->recipes[i].cmd; i++) {
231259
cmd_arr = add_mi_array(resp_arr, NULL, 0);
232260
if (! cmd_arr) {

0 commit comments

Comments
 (0)