Convert CLI helpers list to rwlist.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@77857 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Joshua Colp
2007-08-01 15:28:02 +00:00
parent 04ca0b9728
commit 96b96a5f72

View File

@@ -121,7 +121,7 @@ unsigned int ast_verbose_get_by_file(const char *file)
return res; return res;
} }
static AST_LIST_HEAD_STATIC(helpers, ast_cli_entry); static AST_RWLIST_HEAD_STATIC(helpers, ast_cli_entry);
static const char logger_mute_help[] = static const char logger_mute_help[] =
"Usage: logger mute\n" "Usage: logger mute\n"
@@ -1347,13 +1347,13 @@ static char *find_best(char *argv[])
char *myargv[AST_MAX_CMD_LEN]; char *myargv[AST_MAX_CMD_LEN];
for (x=0;x<AST_MAX_CMD_LEN;x++) for (x=0;x<AST_MAX_CMD_LEN;x++)
myargv[x]=NULL; myargv[x]=NULL;
AST_LIST_LOCK(&helpers); AST_RWLIST_RDLOCK(&helpers);
for (x=0;argv[x];x++) { for (x=0;argv[x];x++) {
myargv[x] = argv[x]; myargv[x] = argv[x];
if (!find_cli(myargv, -1)) if (!find_cli(myargv, -1))
break; break;
} }
AST_LIST_UNLOCK(&helpers); AST_RWLIST_UNLOCK(&helpers);
ast_join(cmdline, sizeof(cmdline), myargv); ast_join(cmdline, sizeof(cmdline), myargv);
return cmdline; return cmdline;
} }
@@ -1366,9 +1366,9 @@ static int __ast_cli_unregister(struct ast_cli_entry *e, struct ast_cli_entry *e
if (e->inuse) { if (e->inuse) {
ast_log(LOG_WARNING, "Can't remove command that is in use\n"); ast_log(LOG_WARNING, "Can't remove command that is in use\n");
} else { } else {
AST_LIST_LOCK(&helpers); AST_RWLIST_WRLOCK(&helpers);
AST_LIST_REMOVE(&helpers, e, list); AST_RWLIST_REMOVE(&helpers, e, list);
AST_LIST_UNLOCK(&helpers); AST_RWLIST_UNLOCK(&helpers);
ast_free(e->_full_cmd); ast_free(e->_full_cmd);
e->_full_cmd = NULL; e->_full_cmd = NULL;
if (e->new_handler) { if (e->new_handler) {
@@ -1409,7 +1409,7 @@ static int __ast_cli_register(struct ast_cli_entry *e, struct ast_cli_entry *ed)
} }
if (set_full_cmd(e)) if (set_full_cmd(e))
goto done; goto done;
AST_LIST_LOCK(&helpers); AST_RWLIST_WRLOCK(&helpers);
if (find_cli(e->cmda, 1)) { if (find_cli(e->cmda, 1)) {
ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", e->_full_cmd); ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", e->_full_cmd);
@@ -1432,23 +1432,23 @@ static int __ast_cli_register(struct ast_cli_entry *e, struct ast_cli_entry *ed)
} }
lf = e->cmdlen; lf = e->cmdlen;
AST_LIST_TRAVERSE_SAFE_BEGIN(&helpers, cur, list) { AST_RWLIST_TRAVERSE_SAFE_BEGIN(&helpers, cur, list) {
int len = cur->cmdlen; int len = cur->cmdlen;
if (lf < len) if (lf < len)
len = lf; len = lf;
if (strncasecmp(e->_full_cmd, cur->_full_cmd, len) < 0) { if (strncasecmp(e->_full_cmd, cur->_full_cmd, len) < 0) {
AST_LIST_INSERT_BEFORE_CURRENT(&helpers, e, list); AST_RWLIST_INSERT_BEFORE_CURRENT(&helpers, e, list);
break; break;
} }
} }
AST_LIST_TRAVERSE_SAFE_END; AST_RWLIST_TRAVERSE_SAFE_END;
if (!cur) if (!cur)
AST_LIST_INSERT_TAIL(&helpers, e, list); AST_RWLIST_INSERT_TAIL(&helpers, e, list);
ret = 0; /* success */ ret = 0; /* success */
done: done:
AST_LIST_UNLOCK(&helpers); AST_RWLIST_UNLOCK(&helpers);
if (e->deprecate_cmd) { if (e->deprecate_cmd) {
/* This command deprecates another command. Register that one also. */ /* This command deprecates another command. Register that one also. */
@@ -1512,7 +1512,7 @@ static char *help1(int fd, char *match[], int locked)
len = strlen(matchstr); len = strlen(matchstr);
} }
if (!locked) if (!locked)
AST_LIST_LOCK(&helpers); AST_RWLIST_RDLOCK(&helpers);
while ( (e = cli_next(&i)) ) { while ( (e = cli_next(&i)) ) {
/* Hide commands that start with '_' */ /* Hide commands that start with '_' */
if (e->_full_cmd[0] == '_') if (e->_full_cmd[0] == '_')
@@ -1526,7 +1526,7 @@ static char *help1(int fd, char *match[], int locked)
found++; found++;
} }
if (!locked) if (!locked)
AST_LIST_UNLOCK(&helpers); AST_RWLIST_UNLOCK(&helpers);
if (!locked && !found && matchstr[0]) if (!locked && !found && matchstr[0])
ast_cli(fd, "No such command '%s'.\n", matchstr); ast_cli(fd, "No such command '%s'.\n", matchstr);
return CLI_SUCCESS; return CLI_SUCCESS;
@@ -1558,7 +1558,7 @@ static char *handle_help(struct ast_cli_entry *e, int cmd, struct ast_cli_args *
if (a->argc == 1) if (a->argc == 1)
return help1(a->fd, NULL, 0); return help1(a->fd, NULL, 0);
AST_LIST_LOCK(&helpers); AST_RWLIST_RDLOCK(&helpers);
my_e = find_cli(a->argv + 1, 1); /* try exact match first */ my_e = find_cli(a->argv + 1, 1); /* try exact match first */
if (!my_e) if (!my_e)
return help1(a->fd, a->argv + 1, 1 /* locked */); return help1(a->fd, a->argv + 1, 1 /* locked */);
@@ -1568,7 +1568,7 @@ static char *handle_help(struct ast_cli_entry *e, int cmd, struct ast_cli_args *
ast_join(fullcmd, sizeof(fullcmd), a->argv+1); ast_join(fullcmd, sizeof(fullcmd), a->argv+1);
ast_cli(a->fd, "No help text available for '%s'.\n", fullcmd); ast_cli(a->fd, "No help text available for '%s'.\n", fullcmd);
} }
AST_LIST_UNLOCK(&helpers); AST_RWLIST_UNLOCK(&helpers);
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
@@ -1744,7 +1744,7 @@ static char *__ast_cli_generator(const char *text, const char *word, int state,
matchlen++; matchlen++;
} }
if (lock) if (lock)
AST_LIST_LOCK(&helpers); AST_RWLIST_RDLOCK(&helpers);
while ( (e = cli_next(&i)) ) { while ( (e = cli_next(&i)) ) {
/* XXX repeated code */ /* XXX repeated code */
int src = 0, dst = 0, n = 0; int src = 0, dst = 0, n = 0;
@@ -1792,7 +1792,7 @@ static char *__ast_cli_generator(const char *text, const char *word, int state,
} }
} }
if (lock) if (lock)
AST_LIST_UNLOCK(&helpers); AST_RWLIST_UNLOCK(&helpers);
ast_free(dup); ast_free(dup);
return ret; return ret;
} }
@@ -1816,11 +1816,11 @@ int ast_cli_command(int fd, const char *s)
if (x < 1) /* We need at least one entry, otherwise ignore */ if (x < 1) /* We need at least one entry, otherwise ignore */
goto done; goto done;
AST_LIST_LOCK(&helpers); AST_RWLIST_RDLOCK(&helpers);
e = find_cli(args + 1, 0); e = find_cli(args + 1, 0);
if (e) if (e)
ast_atomic_fetchadd_int(&e->inuse, 1); ast_atomic_fetchadd_int(&e->inuse, 1);
AST_LIST_UNLOCK(&helpers); AST_RWLIST_UNLOCK(&helpers);
if (e == NULL) { if (e == NULL) {
ast_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(args + 1)); ast_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(args + 1));
goto done; goto done;
@@ -1848,21 +1848,21 @@ int ast_cli_command(int fd, const char *s)
switch (res) { switch (res) {
case RESULT_SHOWUSAGE: case RESULT_SHOWUSAGE:
ast_cli(fd, "%s", S_OR(e->usage, "Invalid usage, but no usage information available.\n")); ast_cli(fd, "%s", S_OR(e->usage, "Invalid usage, but no usage information available.\n"));
AST_LIST_LOCK(&helpers); AST_RWLIST_RDLOCK(&helpers);
if (e->deprecated) if (e->deprecated)
ast_cli(fd, "The '%s' command is deprecated and will be removed in a future release. Please use '%s' instead.\n", e->_full_cmd, e->_deprecated_by); ast_cli(fd, "The '%s' command is deprecated and will be removed in a future release. Please use '%s' instead.\n", e->_full_cmd, e->_deprecated_by);
AST_LIST_UNLOCK(&helpers); AST_RWLIST_UNLOCK(&helpers);
break; break;
case RESULT_FAILURE: case RESULT_FAILURE:
ast_cli(fd, "Command '%s' failed.\n", s); ast_cli(fd, "Command '%s' failed.\n", s);
/* FALLTHROUGH */ /* FALLTHROUGH */
default: default:
AST_LIST_LOCK(&helpers); AST_RWLIST_RDLOCK(&helpers);
if (e->deprecated == 1) { if (e->deprecated == 1) {
ast_cli(fd, "The '%s' command is deprecated and will be removed in a future release. Please use '%s' instead.\n", e->_full_cmd, e->_deprecated_by); ast_cli(fd, "The '%s' command is deprecated and will be removed in a future release. Please use '%s' instead.\n", e->_full_cmd, e->_deprecated_by);
e->deprecated = 2; e->deprecated = 2;
} }
AST_LIST_UNLOCK(&helpers); AST_RWLIST_UNLOCK(&helpers);
break; break;
} }
ast_atomic_fetchadd_int(&e->inuse, -1); ast_atomic_fetchadd_int(&e->inuse, -1);