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

Loading…
Cancel
Save