mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-16 17:53:15 +00:00
more command completion normalization
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@15858 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -685,42 +685,36 @@ static int conf_cmd(int fd, int argc, char **argv) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *complete_confcmd(const char *line, const char *word, int pos, int state) {
|
static char *complete_confcmd(const char *line, const char *word, int pos, int state)
|
||||||
#define CONF_COMMANDS 6
|
{
|
||||||
int which = 0, x = 0;
|
static char *cmds[] = {"lock", "unlock", "mute", "unmute", "kick", "list", NULL};
|
||||||
|
|
||||||
|
int len = strlen(word);
|
||||||
|
int which = 0;
|
||||||
struct ast_conference *cnf = NULL;
|
struct ast_conference *cnf = NULL;
|
||||||
struct ast_conf_user *usr = NULL;
|
struct ast_conf_user *usr = NULL;
|
||||||
char *confno = NULL;
|
char *confno = NULL;
|
||||||
char usrno[50] = "";
|
char usrno[50] = "";
|
||||||
char cmds[CONF_COMMANDS][20] = {"lock", "unlock", "mute", "unmute", "kick", "list"};
|
char *myline, *ret = NULL;
|
||||||
char *myline;
|
|
||||||
|
|
||||||
if (pos == 1) {
|
if (pos == 1) { /* Command */
|
||||||
/* Command */
|
return ast_cli_complete(word, cmds, state);
|
||||||
for (x = 0;x < CONF_COMMANDS; x++) {
|
} else if (pos == 2) { /* Conference Number */
|
||||||
if (!strncasecmp(cmds[x], word, strlen(word))) {
|
|
||||||
if (++which > state) {
|
|
||||||
return strdup(cmds[x]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (pos == 2) {
|
|
||||||
/* Conference Number */
|
|
||||||
AST_LIST_LOCK(&confs);
|
AST_LIST_LOCK(&confs);
|
||||||
AST_LIST_TRAVERSE(&confs, cnf, list) {
|
AST_LIST_TRAVERSE(&confs, cnf, list) {
|
||||||
if (!strncasecmp(word, cnf->confno, strlen(word))) {
|
if (!strncasecmp(word, cnf->confno, len) && ++which > state) {
|
||||||
if (++which > state)
|
ret = cnf->confno;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ret = ast_strdup(ret); /* dup before releasing the lock */
|
||||||
AST_LIST_UNLOCK(&confs);
|
AST_LIST_UNLOCK(&confs);
|
||||||
return cnf ? strdup(cnf->confno) : NULL;
|
return ret;
|
||||||
} else if (pos == 3) {
|
} else if (pos == 3) {
|
||||||
/* User Number || Conf Command option*/
|
/* User Number || Conf Command option*/
|
||||||
if (strstr(line, "mute") || strstr(line, "kick")) {
|
if (strstr(line, "mute") || strstr(line, "kick")) {
|
||||||
if ((state == 0) && (strstr(line, "kick") || strstr(line,"mute")) && !(strncasecmp(word, "all", strlen(word)))) {
|
if (state == 0 && (strstr(line, "kick") || strstr(line,"mute")) && !strncasecmp(word, "all", len))
|
||||||
return strdup("all");
|
return strdup("all");
|
||||||
}
|
|
||||||
which++;
|
which++;
|
||||||
AST_LIST_LOCK(&confs);
|
AST_LIST_LOCK(&confs);
|
||||||
|
|
||||||
@@ -740,12 +734,10 @@ static char *complete_confcmd(const char *line, const char *word, int pos, int s
|
|||||||
/* Search for the user */
|
/* Search for the user */
|
||||||
for (usr = cnf->firstuser; usr; usr = usr->nextuser) {
|
for (usr = cnf->firstuser; usr; usr = usr->nextuser) {
|
||||||
snprintf(usrno, sizeof(usrno), "%d", usr->user_no);
|
snprintf(usrno, sizeof(usrno), "%d", usr->user_no);
|
||||||
if (!strncasecmp(word, usrno, strlen(word))) {
|
if (!strncasecmp(word, usrno, len) && ++which > state)
|
||||||
if (++which > state)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
AST_LIST_UNLOCK(&confs);
|
AST_LIST_UNLOCK(&confs);
|
||||||
return usr ? strdup(usrno) : NULL;
|
return usr ? strdup(usrno) : NULL;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user