MT#59038 refactor CLI parsing

More flexible code. Functional no-op.

Change-Id: Ic7de8b2d718b176e40524cd4e59120ee3f616db1
pull/1802/head
Richard Fuchs 1 year ago
parent 4f14413526
commit b6b9395fd5

@ -731,38 +731,46 @@ static void cli_list_tag_info(struct cli_writer *cw, struct call_monologue *ml)
static void cli_incoming_list_sessions(str *instr, struct cli_writer *cw) {
size_t found = 0;
bool all = false, own = false;
bool found = false;
enum { all, own, foreign } which = -1;
static const char* LIST_ALL = "all";
static const char* LIST_OWN = "own";
static const char* LIST_FOREIGN = "foreign";
static const char *keywords[] = {
[all] = "all",
[own] = "own",
[foreign] = "foreign",
};
if (str_shift(instr, 1)) {
cw->cw_printf(cw, "%s\n", "More parameters required.");
return;
}
if (str_cmp(instr, LIST_ALL) == 0)
all = true;
else if (str_cmp(instr, LIST_OWN) == 0)
own = true;
else if (str_cmp(instr, LIST_FOREIGN) == 0)
{ } // default
else {
for (unsigned int i = 0; i < G_N_ELEMENTS(keywords); i++) {
if (str_cmp(instr, keywords[i]) == 0) {
which = i;
break;
}
}
if (which == -1) {
// list session for callid
cli_incoming_list_callid(instr, cw);
return;
}
ITERATE_CALL_LIST_START(CALL_ITERATOR_MAIN, call);
if (!all) {
if (IS_FOREIGN_CALL(call) && own)
goto next;
if (!IS_FOREIGN_CALL(call) && !own)
goto next;
switch (which) {
case all:
break;
case foreign:
if (!IS_FOREIGN_CALL(call))
goto next;
break;
case own:
if (IS_FOREIGN_CALL(call))
goto next;
break;
}
found++;
found = true;
cw->cw_printf(cw, "ID: %60s | del:%s | creat:%12li | prx:%s | redis:%2i | frgn:%s\n",
call->callid.s, call->ml_deleted ? "y" : "n",
@ -774,12 +782,10 @@ next:;
ITERATE_CALL_LIST_NEXT_END(call);
if (!found) {
if (all)
if (which == all)
cw->cw_printf(cw, "No sessions on this media relay.\n");
else if (own)
cw->cw_printf(cw, "No own sessions on this media relay.\n");
else
cw->cw_printf(cw, "No foreign sessions on this media relay.\n");
cw->cw_printf(cw, "No %s sessions on this media relay.\n", keywords[which]);
}
return;

Loading…
Cancel
Save