more command completion normalization

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@15858 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.4
Luigi Rizzo 20 years ago
parent 096bf1511f
commit e735f507b7

@ -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) { /* Command */
if (pos == 1) { return ast_cli_complete(word, cmds, state);
/* Command */ } else if (pos == 2) { /* Conference Number */
for (x = 0;x < CONF_COMMANDS; x++) {
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,10 +734,8 @@ 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);

Loading…
Cancel
Save