summaryrefslogtreecommitdiff
path: root/main/cli.c
diff options
context:
space:
mode:
authorCorey Farrell <git@cfware.com>2015-05-04 17:41:08 -0400
committerCorey Farrell <git@cfware.com>2015-05-04 20:47:18 -0400
commitdf6c1d755f39308c77f3c49ef0f5fa539e627330 (patch)
tree21f12dd8173c44ce1caa6f3797be062910db2b55 /main/cli.c
parenta8bfa9e10445744581d18819c64729844ae837fb (diff)
CLI: Enable automatic references to modules.
* Pass module to ast_cli_register and ast_cli_register_multiple. * Add a module reference before executing any CLI callback, remove the reference when complete. ASTERISK-25049 #close Reported by: Corey Farrell Change-Id: I7aafc7c9f2b912918f28fe51d51e9e8a755750e3
Diffstat (limited to 'main/cli.c')
-rw-r--r--main/cli.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/main/cli.c b/main/cli.c
index a230c20ac..eb8800f5e 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -2203,7 +2203,7 @@ static int cli_is_registered(struct ast_cli_entry *e)
return 0;
}
-static int __ast_cli_unregister(struct ast_cli_entry *e, struct ast_cli_entry *ed)
+int ast_cli_unregister(struct ast_cli_entry *e)
{
if (e->inuse) {
ast_log(LOG_WARNING, "Can't remove command that is in use\n");
@@ -2225,7 +2225,7 @@ static int __ast_cli_unregister(struct ast_cli_entry *e, struct ast_cli_entry *e
return 0;
}
-static int __ast_cli_register(struct ast_cli_entry *e, struct ast_cli_entry *ed)
+int __ast_cli_register(struct ast_cli_entry *e, struct ast_module *module)
{
struct ast_cli_entry *cur;
int i, lf, ret = -1;
@@ -2244,7 +2244,11 @@ static int __ast_cli_register(struct ast_cli_entry *e, struct ast_cli_entry *ed)
}
memset(&a, '\0', sizeof(a));
+
+ e->module = module;
+ /* No module reference needed here, the module called us. */
e->handler(e, CLI_INIT, &a);
+
/* XXX check that usage and command are filled up */
s = ast_skip_blanks(e->command);
s = e->command = ast_strdup(s);
@@ -2295,27 +2299,16 @@ done:
return ret;
}
-/* wrapper function, so we can unregister deprecated commands recursively */
-int ast_cli_unregister(struct ast_cli_entry *e)
-{
- return __ast_cli_unregister(e, NULL);
-}
-
-/* wrapper function, so we can register deprecated commands recursively */
-int ast_cli_register(struct ast_cli_entry *e)
-{
- return __ast_cli_register(e, NULL);
-}
-
/*
* register/unregister an array of entries.
*/
-int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
+int __ast_cli_register_multiple(struct ast_cli_entry *e, int len, struct ast_module *module)
{
int i, res = 0;
- for (i = 0; i < len; i++)
- res |= ast_cli_register(e + i);
+ for (i = 0; i < len; i++) {
+ res |= __ast_cli_register(e + i, module);
+ }
return res;
}
@@ -2657,7 +2650,9 @@ static char *__ast_cli_generator(const char *text, const char *word, int state,
.n = state - matchnum,
.argv = argv,
.argc = x};
+ ast_module_ref(e->module);
ret = e->handler(e, CLI_GENERATE, &a);
+ ast_module_unref(e->module);
}
if (ret)
break;
@@ -2714,7 +2709,9 @@ int ast_cli_command_full(int uid, int gid, int fd, const char *s)
*/
args[0] = (char *)e;
+ ast_module_ref(e->module);
retval = e->handler(e, CLI_HANDLER, &a);
+ ast_module_unref(e->module);
if (retval == CLI_SHOWUSAGE) {
ast_cli(fd, "%s", S_OR(e->usage, "Invalid usage, but no usage information available.\n"));