aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-03-28 23:40:28 +0000
committerrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-03-28 23:40:28 +0000
commit14a0554a65ca5d42c48e30f65c581b39fcae8338 (patch)
tree8e1efed4fbe80acbdf96a60cffacf69acce0d351 /apps
parent9050284feaad274eb5a5057995d396ff56491ed3 (diff)
more command completion normalization
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@15858 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps')
-rw-r--r--apps/app_meetme.c44
1 files changed, 18 insertions, 26 deletions
diff --git a/apps/app_meetme.c b/apps/app_meetme.c
index 22ee8df7b..f1e213885 100644
--- a/apps/app_meetme.c
+++ b/apps/app_meetme.c
@@ -685,42 +685,36 @@ static int conf_cmd(int fd, int argc, char **argv) {
return 0;
}
-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 *complete_confcmd(const char *line, const char *word, int pos, int state)
+{
+ static char *cmds[] = {"lock", "unlock", "mute", "unmute", "kick", "list", NULL};
+
+ int len = strlen(word);
+ int which = 0;
struct ast_conference *cnf = NULL;
struct ast_conf_user *usr = NULL;
char *confno = NULL;
char usrno[50] = "";
- char cmds[CONF_COMMANDS][20] = {"lock", "unlock", "mute", "unmute", "kick", "list"};
- char *myline;
+ char *myline, *ret = NULL;
- if (pos == 1) {
- /* Command */
- 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 */
+ if (pos == 1) { /* Command */
+ return ast_cli_complete(word, cmds, state);
+ } else if (pos == 2) { /* Conference Number */
AST_LIST_LOCK(&confs);
AST_LIST_TRAVERSE(&confs, cnf, list) {
- if (!strncasecmp(word, cnf->confno, strlen(word))) {
- if (++which > state)
- break;
+ if (!strncasecmp(word, cnf->confno, len) && ++which > state) {
+ ret = cnf->confno;
+ break;
}
}
+ ret = ast_strdup(ret); /* dup before releasing the lock */
AST_LIST_UNLOCK(&confs);
- return cnf ? strdup(cnf->confno) : NULL;
+ return ret;
} else if (pos == 3) {
/* User Number || Conf Command option*/
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");
- }
which++;
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 */
for (usr = cnf->firstuser; usr; usr = usr->nextuser) {
snprintf(usrno, sizeof(usrno), "%d", usr->user_no);
- if (!strncasecmp(word, usrno, strlen(word))) {
- if (++which > state)
- break;
- }
+ if (!strncasecmp(word, usrno, len) && ++which > state)
+ break;
}
}
AST_LIST_UNLOCK(&confs);