summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
authorMichiel van Baak <michiel@vanbaak.info>2008-11-12 06:46:04 +0000
committerMichiel van Baak <michiel@vanbaak.info>2008-11-12 06:46:04 +0000
commit86f900b20105bf5e918d8347cab8557f33d5fdae (patch)
tree95cbe393b660ef9b967378388db5bd09c7a890f4 /res
parent5b25c263181989a1f86be2c2c94c4425ec30721a (diff)
This commit does two things:
- Add CLI aliases module to asterisk. - Remove all deprecated CLI commands from the code Initial work done by file. Junk-Y and lmadsen did a lot of work and testing to get the list of deprecated commands into the configuration file. Deprecated CLI commands are now handled by this new module, see cli_aliases.conf for more info about that. ok russellb@ via reviewboard (closes issue #13735) Reported by: mvanbaak git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@156120 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res')
-rw-r--r--res/res_agi.c28
-rw-r--r--res/res_clialiases.c274
-rw-r--r--res/res_jabber.c44
3 files changed, 276 insertions, 70 deletions
diff --git a/res/res_agi.c b/res/res_agi.c
index a37364923..4220e423d 100644
--- a/res/res_agi.c
+++ b/res/res_agi.c
@@ -3013,30 +3013,6 @@ static int write_htmldump(char *filename)
return 0;
}
-static char *handle_cli_agi_dumphtml_deprecated(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
- switch (cmd) {
- case CLI_INIT:
- e->command = "agi dumphtml";
- e->usage =
- "Usage: agi dumphtml <filename>\n"
- " Dumps the AGI command list in HTML format to the given\n"
- " file.\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
- if (a->argc < e->args + 1)
- return CLI_SHOWUSAGE;
-
- if (write_htmldump(a->argv[2]) < 0) {
- ast_cli(a->fd, "Could not create file '%s'\n", a->argv[2]);
- return CLI_SHOWUSAGE;
- }
- ast_cli(a->fd, "AGI HTML commands dumped to: %s\n", a->argv[2]);
- return CLI_SUCCESS;
-}
-
static char *handle_cli_agi_dump_html(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
switch (cmd) {
@@ -3164,13 +3140,11 @@ static int deadagi_exec(struct ast_channel *chan, void *data)
return agi_exec(chan, data);
}
-static struct ast_cli_entry cli_agi_dumphtml_deprecated = AST_CLI_DEFINE(handle_cli_agi_dumphtml_deprecated, "Dumps a list of AGI commands in HTML format");
-
static struct ast_cli_entry cli_agi[] = {
AST_CLI_DEFINE(handle_cli_agi_add_cmd, "Add AGI command to a channel in Async AGI"),
AST_CLI_DEFINE(handle_cli_agi_debug, "Enable/Disable AGI debugging"),
AST_CLI_DEFINE(handle_cli_agi_show, "List AGI commands or specific help"),
- AST_CLI_DEFINE(handle_cli_agi_dump_html, "Dumps a list of AGI commands in HTML format", .deprecate_cmd = &cli_agi_dumphtml_deprecated)
+ AST_CLI_DEFINE(handle_cli_agi_dump_html, "Dumps a list of AGI commands in HTML format")
};
static int unload_module(void)
diff --git a/res/res_clialiases.c b/res/res_clialiases.c
new file mode 100644
index 000000000..bc2942b00
--- /dev/null
+++ b/res/res_clialiases.c
@@ -0,0 +1,274 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2008, Digium, Inc.
+ *
+ * Joshua Colp <jcolp@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief CLI Aliases
+ *
+ * \author\verbatim Joshua Colp <jcolp@digium.com> \endverbatim
+ *
+ * This module provides the capability to create aliases to other
+ * CLI commands.
+ */
+
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/config.h"
+#include "asterisk/cli.h"
+#include "asterisk/astobj2.h"
+
+/*! Maximum number of buckets for CLI aliases */
+#define MAX_ALIAS_BUCKETS 53
+
+/*! Configuration file used for this application */
+static const char config_file[] = "cli_aliases.conf";
+
+struct cli_alias {
+ struct ast_cli_entry cli_entry; /*!< Actual CLI structure used for this alias */
+ char *alias; /*!< CLI Alias */
+ char *real_cmd; /*!< Actual CLI command it is aliased to */
+ unsigned int marked:1; /*!< Bit to indicate whether this CLI alias is marked for destruction or not */
+};
+
+static struct ao2_container *cli_aliases;
+
+/*! \brief Hashing function used for aliases */
+static int alias_hash_cb(const void *obj, const int flags)
+{
+ const struct cli_alias *alias = obj;
+ return ast_str_hash(alias->cli_entry.command);
+}
+
+/*! \brief Comparison function used for aliases */
+static int alias_cmp_cb(void *obj, void *arg, void *data, int flags)
+{
+ const struct cli_alias *alias0 = obj, *alias1 = arg;
+
+ return (alias0->cli_entry.command == alias1->cli_entry.command ? CMP_MATCH | CMP_STOP : 0);
+}
+
+/*! \brief Destruction function used for aliases */
+static void alias_destroy(void *obj)
+{
+ struct cli_alias *alias = obj;
+
+ /* Unregister the CLI entry from the core */
+ ast_cli_unregister(&alias->cli_entry);
+
+ return;
+}
+
+/*! \brief Function which passes through an aliased CLI command to the real one */
+static char *cli_alias_passthrough(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ struct cli_alias *alias;
+ struct cli_alias tmp = {
+ .cli_entry.command = e->command,
+ };
+ char *generator;
+ const char *line;
+
+ /* Try to find the alias based on the CLI entry */
+ if (!(alias = ao2_find(cli_aliases, &tmp, NULL, OBJ_POINTER))) {
+ return 0;
+ }
+
+ switch (cmd) {
+ case CLI_INIT:
+ ao2_ref(alias, -1);
+ return NULL;
+ case CLI_GENERATE:
+ line = a->line;
+ line += (strlen(alias->alias));
+ if (!ast_strlen_zero(a->word)) {
+ struct ast_str *real_cmd = ast_str_alloca(strlen(alias->real_cmd) + strlen(line) + 1);
+ ast_str_append(&real_cmd, 0, "%s%s", alias->real_cmd, line);
+ generator = ast_cli_generator(real_cmd->str, a->word, a->n);
+ } else {
+ generator = ast_cli_generator(alias->real_cmd, a->word, a->n);
+ }
+ ao2_ref(alias, -1);
+ return generator;
+ }
+
+ /* If they gave us extra arguments we need to construct a string to pass in */
+ if (a->argc != e->args) {
+ struct ast_str *real_cmd = ast_str_alloca(2048);
+ int i;
+
+ ast_str_append(&real_cmd, 0, "%s", alias->real_cmd);
+
+ /* Add the additional arguments that have been passed in */
+ for (i = e->args + 1; i <= a->argc; i++) {
+ ast_str_append(&real_cmd, 0, " %s", a->argv[i - 1]);
+ }
+
+ ast_cli_command(a->fd, real_cmd->str);
+ } else {
+ ast_cli_command(a->fd, alias->real_cmd);
+ }
+
+ ao2_ref(alias, -1);
+
+ return CLI_SUCCESS;
+}
+
+/*! \brief CLI Command to display CLI Aliases */
+static char *alias_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+#define FORMAT "%-50.50s %-50.50s\n"
+ struct cli_alias *alias;
+ struct ao2_iterator i;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "cli show aliases";
+ e->usage =
+ "Usage: cli show aliases\n"
+ " Displays a list of aliased CLI commands.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ ast_cli(a->fd, FORMAT, "Alias Command", "Real Command");
+
+ i = ao2_iterator_init(cli_aliases, 0);
+
+ for (; (alias = ao2_iterator_next(&i)); ao2_ref(alias, -1)) {
+ ast_cli(a->fd, FORMAT, alias->alias, alias->real_cmd);
+ }
+
+ return CLI_SUCCESS;
+#undef FORMAT
+}
+
+/*! \brief CLI commands to interact with things */
+static struct ast_cli_entry cli_alias[] = {
+ AST_CLI_DEFINE(alias_show, "Show CLI command aliases"),
+};
+
+/*! \brief Function called to mark an alias for destruction */
+static int alias_mark(void *obj, void *arg, void *data, int flags)
+{
+ struct cli_alias *alias = obj;
+ alias->marked = 1;
+ return 0;
+}
+
+/*! \brief Function called to see if an alias is marked for destruction */
+static int alias_marked(void *obj, void *arg, void *data, int flags)
+{
+ struct cli_alias *alias = obj;
+ return alias->marked ? CMP_MATCH : 0;
+}
+
+/*! \brief Function called to load or reload the configuration file */
+static void load_config(int reload)
+{
+ struct ast_config *cfg = NULL;
+ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+ struct cli_alias *alias;
+ struct ast_variable *v, *v1;
+
+ if (!(cfg = ast_config_load(config_file, config_flags))) {
+ ast_log(LOG_ERROR, "res_clialiases configuration file '%s' not found\n", config_file);
+ return;
+ } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
+ return;
+ }
+
+ /* Mark CLI aliases for pruning */
+ if (reload) {
+ ao2_callback(cli_aliases, OBJ_NODATA, alias_mark, NULL, NULL);
+ }
+
+ for (v = ast_variable_browse(cfg, "general"); v; v = v->next) {
+ if (strcmp(v->name, "template")) {
+ ast_log(LOG_WARNING, "%s is not a correct option in [%s]\n", v->name, "general");
+ continue;
+ }
+ /* Read in those there CLI aliases */
+ for (v1 = ast_variable_browse(cfg, v->value); v1; v1 = v1->next) {
+ if (!(alias = ao2_alloc((sizeof(*alias) + strlen(v1->name) + strlen(v1->value) + 2), alias_destroy))) {
+ continue;
+ }
+ alias->alias = ((char *) alias) + sizeof(alias);
+ alias->real_cmd = ((char *) alias) + strlen(v1->name) + 1;
+ strcpy(alias->alias, v1->name);
+ strcpy(alias->real_cmd, v1->value);
+ alias->cli_entry.handler = cli_alias_passthrough;
+ alias->cli_entry.command = alias->alias;
+ alias->cli_entry.usage = "Aliased CLI Command";
+
+ ao2_link(cli_aliases, alias);
+ ast_verbose(VERBOSE_PREFIX_2 "Aliased CLI command '%s' to '%s'\n", v1->name, v1->value);
+ ao2_ref(alias, -1);
+ }
+ }
+
+ /* Drop any CLI aliases that should no longer exist */
+ if (reload) {
+ ao2_callback(cli_aliases, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE , alias_marked, NULL, NULL);
+ }
+
+ ast_config_destroy(cfg);
+
+ return;
+}
+
+/*! \brief Function called to reload the module */
+static int reload_module(void)
+{
+ load_config(1);
+ return 0;
+}
+
+/*! \brief Function called to unload the module */
+static int unload_module(void)
+{
+ ao2_ref(cli_aliases, -1);
+
+ ast_cli_unregister_multiple(cli_alias, ARRAY_LEN(cli_alias));
+
+ return 0;
+}
+
+/*! \brief Function called to load the module */
+static int load_module(void)
+{
+ if (!(cli_aliases = ao2_container_alloc(MAX_ALIAS_BUCKETS, alias_hash_cb, alias_cmp_cb))) {
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
+ load_config(0);
+
+ ast_cli_register_multiple(cli_alias, sizeof(cli_alias) / sizeof(struct ast_cli_entry));
+
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "CLI Aliases",
+ .load = load_module,
+ .unload = unload_module,
+ .reload = reload_module,
+ );
diff --git a/res/res_jabber.c b/res/res_jabber.c
index ebb1059f5..4ee7ea9a4 100644
--- a/res/res_jabber.c
+++ b/res/res_jabber.c
@@ -96,7 +96,6 @@ static void *aji_recv_loop(void *data);
static int aji_initialize(struct aji_client *client);
static int aji_client_connect(void *data, ikspak *pak);
static void aji_set_presence(struct aji_client *client, char *to, char *from, int level, char *desc);
-static char *aji_do_debug_deprecated(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
static char *aji_do_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
static char *aji_do_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
static char *aji_show_clients(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
@@ -123,9 +122,8 @@ static int aji_register_transport(void *data, ikspak *pak);
static int aji_register_transport2(void *data, ikspak *pak);
*/
-static struct ast_cli_entry cli_aji_do_debug_deprecated = AST_CLI_DEFINE(aji_do_debug_deprecated, "Enable/disable jabber debugging");
static struct ast_cli_entry aji_cli[] = {
- AST_CLI_DEFINE(aji_do_set_debug, "Enable/Disable Jabber debug", .deprecate_cmd = &cli_aji_do_debug_deprecated),
+ AST_CLI_DEFINE(aji_do_set_debug, "Enable/Disable Jabber debug"),
AST_CLI_DEFINE(aji_do_reload, "Reload Jabber configuration"),
AST_CLI_DEFINE(aji_show_clients, "Show state of clients and components"),
AST_CLI_DEFINE(aji_show_buddies, "Show buddy lists of our clients"),
@@ -2390,46 +2388,6 @@ static char *aji_do_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_a
}
/*!
- * \brief Turn on/off console debugging (deprecated, use aji_do_set_debug).
- * \return CLI_SUCCESS.
- */
-static char *aji_do_debug_deprecated(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-
- switch (cmd) {
- case CLI_INIT:
- e->command = "jabber debug [off]";
- e->usage =
- "Usage: jabber debug [off]\n"
- " Enables/disables dumping of Jabber packets for debugging purposes.\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
-
- if (a->argc == 2) {
- ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
- ASTOBJ_RDLOCK(iterator);
- iterator->debug = 1;
- ASTOBJ_UNLOCK(iterator);
- });
- ast_cli(a->fd, "Jabber Debugging Enabled.\n");
- return CLI_SUCCESS;
- } else if (a->argc == 3) {
- if (!strncasecmp(a->argv[2], "off", 3)) {
- ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
- ASTOBJ_RDLOCK(iterator);
- iterator->debug = 0;
- ASTOBJ_UNLOCK(iterator);
- });
- ast_cli(a->fd, "Jabber Debugging Disabled.\n");
- return CLI_SUCCESS;
- }
- }
- return CLI_SHOWUSAGE; /* defaults to invalid */
-}
-
-/*!
* \brief Reload jabber module.
* \return CLI_SUCCESS.
*/