int opbx_cli_command(int fd, char *s)
{
char *argv[OPBX_MAX_ARGS];
struct opbx_cli_entry *e;
int x;
char *dup;
int tws;
if ((dup = parse_args(s, &x, argv, sizeof(argv) / sizeof(argv[0]), &tws))) {
/* We need at least one entry, or ignore */
if (x > 0) {
opbx_mutex_lock(&clilock);
e = find_cli(argv, 0);
if (e)
e->inuse++;
opbx_mutex_unlock(&clilock);
if (e) {
switch(e->handler(fd, x, argv)) {
case RESULT_SHOWUSAGE:
opbx_cli(fd, "%s", e->usage);
break;
}
} else
opbx_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(argv));
if (e) {
opbx_mutex_lock(&clilock);
e->inuse--;
opbx_mutex_unlock(&clilock);
}
}
free(dup);
} else {
opbx_log(LOG_WARNING, "Out of memory\n");
return -1;
}
return 0;
}