aboutsummaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authorqwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-09-18 22:43:45 +0000
committerqwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-09-18 22:43:45 +0000
commitab51c0d7fad1957b36454533cd8e786ed66efa61 (patch)
treed49317ce7050cdca6ecef46706a320e879421c61 /res
parentcedd5ba68f094ce4082e42b47674c0f1c01d447d (diff)
(issue #10724)
Reported by: eliel Patches: res_features.c.patch uploaded by eliel (license 64) res_agi.c.patch uploaded by seanbright (license 71) res_musiconhold.c.patch uploaded by seanbright (license 71) pbx.c.patch uploaded by moy (license 222) logger.c.patch uploaded by moy (license 222) frame.c.patch uploaded by moy (license 222) manager.c.patch uploaded by moy (license 222) http.c.patch uploaded by moy (license 222) dnsmgr.c.patch uploaded by moy (license 222) res_realtime.c.patch uploaded by eliel (license 64) res_odbc.c.patch uploaded by seanbright (license 71) res_jabber.c.patch uploaded by eliel (license 64) chan_local.c.patch uploaded by eliel (license 64) chan_agent.c.patch uploaded by eliel (license 64) chan_alsa.c.patch uploaded by eliel (license 64) chan_features.c.patch uploaded by eliel (license 64) chan_sip.c.patch uploaded by eliel (license 64) RollUp.1.patch (includes all of the above patches) uploaded by seanbright (license 71) Convert many CLI commands to the NEW_CLI format. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@82930 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rw-r--r--res/res_agi.c173
-rw-r--r--res/res_features.c67
-rw-r--r--res/res_jabber.c190
-rw-r--r--res/res_musiconhold.c92
-rw-r--r--res/res_odbc.c57
-rw-r--r--res/res_realtime.c84
6 files changed, 377 insertions, 286 deletions
diff --git a/res/res_agi.c b/res/res_agi.c
index d72c01d3a..8bc3295cd 100644
--- a/res/res_agi.c
+++ b/res/res_agi.c
@@ -1300,30 +1300,33 @@ static int handle_dbdeltree(struct ast_channel *chan, AGI *agi, int argc, char *
return RESULT_SUCCESS;
}
-static const char debug_usage[] =
-"Usage: agi debug\n"
-" Enables dumping of AGI transactions for debugging purposes\n";
-
-static const char no_debug_usage[] =
-"Usage: agi debug off\n"
-" Disables dumping of AGI transactions for debugging purposes\n";
-
-static int agi_do_debug(int fd, int argc, char *argv[])
+static char *handle_cli_agi_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- agidebug = 1;
- ast_cli(fd, "AGI Debugging Enabled\n");
- return RESULT_SUCCESS;
-}
-
-static int agi_no_debug(int fd, int argc, char *argv[])
-{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- agidebug = 0;
- ast_cli(fd, "AGI Debugging Disabled\n");
- return RESULT_SUCCESS;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "agi debug [off]";
+ e->usage =
+ "Usage: agi debug [off]\n"
+ " Enables/disables dumping of AGI transactions for\n"
+ " debugging purposes.\n";
+ return NULL;
+
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc < e->args - 1 || a->argc > e->args )
+ return CLI_SHOWUSAGE;
+ if (a->argc == e->args - 1) {
+ agidebug = 1;
+ } else {
+ if (strncasecmp(a->argv[e->args - 1], "off", 3) == 0) {
+ agidebug = 0;
+ } else {
+ return CLI_SHOWUSAGE;
+ }
+ }
+ ast_cli(a->fd, "AGI Debugging %sabled\n", agidebug ? "En" : "Dis");
+ return CLI_SUCCESS;
}
static int handle_noop(struct ast_channel *chan, AGI *agi, int arg, char *argv[])
@@ -1634,7 +1637,7 @@ static struct agi_command commands[] = {
static AST_RWLIST_HEAD_STATIC(agi_commands, agi_command);
-static int help_workhorse(int fd, char *match[])
+static char *help_workhorse(int fd, char *match[])
{
char fullcmd[80], matchstr[80];
struct agi_command *e;
@@ -1656,7 +1659,8 @@ static int help_workhorse(int fd, char *match[])
ast_cli(fd, "%5.5s %20.20s %s\n", e->dead ? "Yes" : "No" , fullcmd, e->summary);
}
AST_RWLIST_UNLOCK(&agi_commands);
- return 0;
+
+ return CLI_SUCCESS;
}
int ast_agi_register(struct ast_module *mod, agi_command *cmd)
@@ -1951,31 +1955,42 @@ static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi
return returnstatus;
}
-static int handle_showagi(int fd, int argc, char *argv[])
+static char *handle_cli_agi_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- struct agi_command *e;
+ struct agi_command *command;
char fullcmd[80];
- if ((argc < 2))
- return RESULT_SHOWUSAGE;
-
- if (argc > 2) {
- e = find_command(argv + 2, 1);
- if (e) {
- ast_cli(fd, e->usage);
- ast_cli(fd, " Runs Dead : %s\n", e->dead ? "Yes" : "No");
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "agi show";
+ e->usage =
+ "Usage: agi show [topic]\n"
+ " When called with a topic as an argument, displays usage\n"
+ " information on the given command. If called without a\n"
+ " topic, it provides a list of AGI commands.\n";
+ break;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc < e->args)
+ return CLI_SHOWUSAGE;
+ if (a->argc > e->args) {
+ command = find_command(a->argv + e->args, 1);
+ if (command) {
+ ast_cli(a->fd, command->usage);
+ ast_cli(a->fd, " Runs Dead : %s\n", command->dead ? "Yes" : "No");
} else {
- if (find_command(argv + 2, -1)) {
- return help_workhorse(fd, argv + 2);
+ if (find_command(a->argv + e->args, -1)) {
+ return help_workhorse(a->fd, a->argv + e->args);
} else {
- ast_join(fullcmd, sizeof(fullcmd), argv + 2);
- ast_cli(fd, "No such command '%s'.\n", fullcmd);
+ ast_join(fullcmd, sizeof(fullcmd), a->argv + e->args);
+ ast_cli(a->fd, "No such command '%s'.\n", fullcmd);
}
}
} else {
- return help_workhorse(fd, NULL);
+ return help_workhorse(a->fd, NULL);
}
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
/*! \brief Convert string to use HTML escaped characters
@@ -2009,49 +2024,57 @@ static void write_html_escaped(FILE *htmlfile, char *str)
return;
}
-static int handle_agidumphtml(int fd, int argc, char *argv[])
+static char *handle_cli_agi_dumphtml(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- struct agi_command *e;
+ struct agi_command *command;
char fullcmd[80];
FILE *htmlfile;
- if ((argc < 3))
- return RESULT_SHOWUSAGE;
+ 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 (!(htmlfile = fopen(argv[2], "wt"))) {
- ast_cli(fd, "Could not create file '%s'\n", argv[2]);
- return RESULT_SHOWUSAGE;
+ if (!(htmlfile = fopen(a->argv[2], "wt"))) {
+ ast_cli(a->fd, "Could not create file '%s'\n", a->argv[2]);
+ return CLI_SHOWUSAGE;
}
fprintf(htmlfile, "<HTML>\n<HEAD>\n<TITLE>AGI Commands</TITLE>\n</HEAD>\n");
fprintf(htmlfile, "<BODY>\n<CENTER><B><H1>AGI Commands</H1></B></CENTER>\n\n");
-
-
fprintf(htmlfile, "<TABLE BORDER=\"0\" CELLSPACING=\"10\">\n");
AST_RWLIST_RDLOCK(&agi_commands);
- AST_RWLIST_TRAVERSE(&agi_commands, e, list) {
+ AST_RWLIST_TRAVERSE(&agi_commands, command, list) {
char *stringp, *tempstr;
- if (!e->cmda[0]) /* end ? */
+ if (!command->cmda[0]) /* end ? */
break;
/* Hide commands that start with '_' */
- if ((e->cmda[0])[0] == '_')
+ if ((command->cmda[0])[0] == '_')
continue;
- ast_join(fullcmd, sizeof(fullcmd), e->cmda);
+ ast_join(fullcmd, sizeof(fullcmd), command->cmda);
fprintf(htmlfile, "<TR><TD><TABLE BORDER=\"1\" CELLPADDING=\"5\" WIDTH=\"100%%\">\n");
- fprintf(htmlfile, "<TR><TH ALIGN=\"CENTER\"><B>%s - %s</B></TH></TR>\n", fullcmd,e->summary);
+ fprintf(htmlfile, "<TR><TH ALIGN=\"CENTER\"><B>%s - %s</B></TH></TR>\n", fullcmd, command->summary);
- stringp=e->usage;
+ stringp = command->usage;
tempstr = strsep(&stringp, "\n");
fprintf(htmlfile, "<TR><TD ALIGN=\"CENTER\">");
write_html_escaped(htmlfile, tempstr);
fprintf(htmlfile, "</TD></TR>\n");
-
-
fprintf(htmlfile, "<TR><TD ALIGN=\"CENTER\">\n");
+
while ((tempstr = strsep(&stringp, "\n")) != NULL) {
write_html_escaped(htmlfile, tempstr);
fprintf(htmlfile, "<BR>\n");
@@ -2062,8 +2085,8 @@ static int handle_agidumphtml(int fd, int argc, char *argv[])
AST_RWLIST_UNLOCK(&agi_commands);
fprintf(htmlfile, "</TABLE>\n</BODY>\n</HTML>\n");
fclose(htmlfile);
- ast_cli(fd, "AGI HTML Commands Dumped to: %s\n", argv[2]);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "AGI HTML commands dumped to: %s\n", a->argv[2]);
+ return CLI_SUCCESS;
}
static int agi_exec_full(struct ast_channel *chan, void *data, int enhanced, int dead)
@@ -2170,38 +2193,14 @@ static int deadagi_exec(struct ast_channel *chan, void *data)
return agi_exec(chan, data);
}
-static char showagi_help[] =
-"Usage: agi show [topic]\n"
-" When called with a topic as an argument, displays usage\n"
-" information on the given command. If called without a\n"
-" topic, it provides a list of AGI commands.\n";
-
-
-static char dumpagihtml_help[] =
-"Usage: agi dumphtml <filename>\n"
-" Dumps the agi command list in html format to given filename\n";
-
static struct ast_cli_entry cli_agi[] = {
- { { "agi", "debug", NULL },
- agi_do_debug, "Enable AGI debugging",
- debug_usage },
-
- { { "agi", "debug", "off", NULL },
- agi_no_debug, "Disable AGI debugging",
- no_debug_usage },
-
- { { "agi", "show", NULL },
- handle_showagi, "List AGI commands or specific help",
- showagi_help },
-
- { { "agi", "dumphtml", NULL },
- handle_agidumphtml, "Dumps a list of agi commands in html format",
- dumpagihtml_help },
+ NEW_CLI(handle_cli_agi_debug, "Enable/Disable AGI debugging"),
+ NEW_CLI(handle_cli_agi_show, "List AGI commands or specific help"),
+ NEW_CLI(handle_cli_agi_dumphtml, "Dumps a list of AGI commands in HTML format")
};
static int unload_module(void)
{
-
ast_cli_unregister_multiple(cli_agi, sizeof(cli_agi) / sizeof(struct ast_cli_entry));
ast_agi_unregister_multiple(ast_module_info->self, commands, sizeof(commands) / sizeof(struct agi_command));
ast_unregister_application(eapp);
diff --git a/res/res_features.c b/res/res_features.c
index d0a177794..71c5addb1 100644
--- a/res/res_features.c
+++ b/res/res_features.c
@@ -2364,41 +2364,61 @@ static int park_exec(struct ast_channel *chan, void *data)
return res;
}
-static int handle_showfeatures(int fd, int argc, char *argv[])
-{
+/*!
+ * \brief CLI command to list configured features
+ * \param e
+ * \param cmd
+ * \param a
+ *
+ * \retval CLI_SUCCESS on success.
+ * \retval NULL when tab completion is used.
+ */
+static char *handle_feature_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) {
int i;
struct ast_call_feature *feature;
char format[] = "%-25s %-7s %-7s\n";
- ast_cli(fd, format, "Builtin Feature", "Default", "Current");
- ast_cli(fd, format, "---------------", "-------", "-------");
+ switch (cmd) {
+
+ case CLI_INIT:
+ e->command = "features show";
+ e->usage =
+ "Usage: features show\n"
+ " Lists configured features\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ ast_cli(a->fd, format, "Builtin Feature", "Default", "Current");
+ ast_cli(a->fd, format, "---------------", "-------", "-------");
- ast_cli(fd, format, "Pickup", "*8", ast_pickup_ext()); /* default hardcoded above, so we'll hardcode it here */
+ ast_cli(a->fd, format, "Pickup", "*8", ast_pickup_ext()); /* default hardcoded above, so we'll hardcode it here */
ast_rwlock_rdlock(&features_lock);
for (i = 0; i < FEATURES_COUNT; i++)
- ast_cli(fd, format, builtin_features[i].fname, builtin_features[i].default_exten, builtin_features[i].exten);
+ ast_cli(a->fd, format, builtin_features[i].fname, builtin_features[i].default_exten, builtin_features[i].exten);
ast_rwlock_unlock(&features_lock);
- ast_cli(fd, "\n");
- ast_cli(fd, format, "Dynamic Feature", "Default", "Current");
- ast_cli(fd, format, "---------------", "-------", "-------");
+ ast_cli(a->fd, "\n");
+ ast_cli(a->fd, format, "Dynamic Feature", "Default", "Current");
+ ast_cli(a->fd, format, "---------------", "-------", "-------");
if (AST_LIST_EMPTY(&feature_list))
- ast_cli(fd, "(none)\n");
+ ast_cli(a->fd, "(none)\n");
else {
AST_LIST_LOCK(&feature_list);
AST_LIST_TRAVERSE(&feature_list, feature, feature_entry)
- ast_cli(fd, format, feature->sname, "no def", feature->exten);
+ ast_cli(a->fd, format, feature->sname, "no def", feature->exten);
AST_LIST_UNLOCK(&feature_list);
}
- ast_cli(fd, "\nCall parking\n");
- ast_cli(fd, "------------\n");
- ast_cli(fd,"%-20s: %s\n", "Parking extension", parking_ext);
- ast_cli(fd,"%-20s: %s\n", "Parking context", parking_con);
- ast_cli(fd,"%-20s: %d-%d\n", "Parked call extensions", parking_start, parking_stop);
- ast_cli(fd,"\n");
-
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "\nCall parking\n");
+ ast_cli(a->fd, "------------\n");
+ ast_cli(a->fd,"%-20s: %s\n", "Parking extension", parking_ext);
+ ast_cli(a->fd,"%-20s: %s\n", "Parking context", parking_con);
+ ast_cli(a->fd,"%-20s: %d-%d\n", "Parked call extensions", parking_start, parking_stop);
+ ast_cli(a->fd,"\n");
+
+ return CLI_SUCCESS;
}
static char mandescr_bridge[] =
@@ -2542,10 +2562,6 @@ static int action_bridge(struct mansession *s, const struct message *m)
return 0;
}
-static char showfeatures_help[] =
-"Usage: feature list\n"
-" Lists currently configured features.\n";
-
/*!
* \brief CLI command to list parked calls
* \param e
@@ -2605,10 +2621,7 @@ static char *handle_parkedcalls_deprecated(struct ast_cli_entry *e, int cmd, str
static struct ast_cli_entry cli_show_parkedcalls_deprecated = NEW_CLI(handle_parkedcalls_deprecated, "List currently parked calls.");
static struct ast_cli_entry cli_features[] = {
- { { "feature", "show", NULL },
- handle_showfeatures, "Lists configured features",
- showfeatures_help },
-
+ NEW_CLI(handle_feature_show, "Lists configured features"),
NEW_CLI(handle_parkedcalls, "List currently parked calls", .deprecate_cmd = &cli_show_parkedcalls_deprecated),
};
diff --git a/res/res_jabber.c b/res/res_jabber.c
index eba4f620d..b673cb17d 100644
--- a/res/res_jabber.c
+++ b/res/res_jabber.c
@@ -87,11 +87,11 @@ 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 int aji_do_debug(int fd, int argc, char *argv[]);
-static int aji_do_reload(int fd, int argc, char *argv[]);
-static int aji_no_debug(int fd, int argc, char *argv[]);
-static int aji_test(int fd, int argc, char *argv[]);
-static int aji_show_clients(int fd, int argc, char *argv[]);
+static char *aji_do_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_no_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
+static char *aji_test(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);
static int aji_create_client(char *label, struct ast_variable *var, int debug);
static int aji_create_buddy(char *label, struct aji_client *client);
static int aji_reload(int reload);
@@ -113,43 +113,12 @@ static int aji_register_transport(void *data, ikspak *pak);
static int aji_register_transport2(void *data, ikspak *pak);
*/
-static const char debug_usage[] =
-"Usage: jabber debug\n"
-" Enables dumping of Jabber packets for debugging purposes.\n";
-
-static const char no_debug_usage[] =
-"Usage: jabber debug off\n"
-" Disables dumping of Jabber packets for debugging purposes.\n";
-
-static const char reload_usage[] =
-"Usage: jabber reload\n"
-" Enables reloading of Jabber module.\n";
-
-static const char test_usage[] =
-"Usage: jabber test [client]\n"
-" Sends test message for debugging purposes. A specific client\n"
-" as configured in jabber.conf can be optionally specified.\n";
-
static struct ast_cli_entry aji_cli[] = {
- { { "jabber", "debug", NULL},
- aji_do_debug, "Enable Jabber debugging",
- debug_usage },
-
- { { "jabber", "reload", NULL},
- aji_do_reload, "Reload Jabber configuration",
- reload_usage },
-
- { { "jabber", "show", "connected", NULL},
- aji_show_clients, "Show state of clients and components",
- debug_usage },
-
- { { "jabber", "debug", "off", NULL},
- aji_no_debug, "Disable Jabber debug",
- no_debug_usage },
-
- { { "jabber", "test", NULL},
- aji_test, "Shows roster, but is generally used for mog's debugging.",
- test_usage },
+ NEW_CLI(aji_do_debug, "Enable jabber debugging"),
+ NEW_CLI(aji_no_debug, "Disable Jabber debug"),
+ NEW_CLI(aji_do_reload, "Reload Jabber configuration"),
+ NEW_CLI(aji_show_clients, "Show state of clients and components"),
+ NEW_CLI(aji_test, "Shows roster, but is generally used for mog's debugging."),
};
static char *app_ajisend = "JabberSend";
@@ -2037,67 +2006,101 @@ static void aji_set_presence(struct aji_client *client, char *to, char *from, in
}
/*!
- * \brief turnon console debugging.
- * \param fd
- * \param argc Integer. Number of args
- * \param argv List of arguements
- * \return RESULT_SUCCESS.
+ * \brief Turn on console debugging.
+ * \return CLI_SUCCESS.
*/
-static int aji_do_debug(int fd, int argc, char *argv[])
+static char *aji_do_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "jabber debug";
+ e->usage =
+ "Usage: jabber debug\n"
+ " Enables dumping of Jabber packets for debugging purposes.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
ASTOBJ_RDLOCK(iterator);
iterator->debug = 1;
ASTOBJ_UNLOCK(iterator);
});
- ast_cli(fd, "Jabber Debugging Enabled.\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Jabber Debugging Enabled.\n");
+ return CLI_SUCCESS;
}
/*!
- * \brief reload jabber module.
- * \param fd
- * \param argc no of args
- * \param argv list of arguements
- * \return RESULT_SUCCESS.
+ * \brief Reload jabber module.
+ * \return CLI_SUCCESS.
*/
-static int aji_do_reload(int fd, int argc, char *argv[])
+static char *aji_do_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "jabber reload";
+ e->usage =
+ "Usage: jabber reload\n"
+ " Reloads the Jabber module.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
aji_reload(1);
- ast_cli(fd, "Jabber Reloaded.\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Jabber Reloaded.\n");
+ return CLI_SUCCESS;
}
/*!
- * \brief turnoff console debugging.
- * \param fd
- * \param argc Integer. number of args
- * \param argv list of arguements
- * \return RESULT_SUCCESS.
+ * \brief Turn off console debugging.
+ * \return CLI_SUCCESS.
*/
-static int aji_no_debug(int fd, int argc, char *argv[])
+static char *aji_no_debug(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"
+ " Disables dumping of Jabber packets for debugging purposes.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
ASTOBJ_RDLOCK(iterator);
iterator->debug = 0;
ASTOBJ_UNLOCK(iterator);
});
- ast_cli(fd, "Jabber Debugging Disabled.\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Jabber Debugging Disabled.\n");
+ return CLI_SUCCESS;
}
/*!
- * \brief show client status.
- * \param fd
- * \param argc Integer. number of args
- * \param argv list of arguements
- * \return RESULT_SUCCESS.
+ * \brief Show client status.
+ * \return CLI_SUCCESS.
*/
-static int aji_show_clients(int fd, int argc, char *argv[])
+static char *aji_show_clients(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
char *status;
int count = 0;
- ast_cli(fd, "Jabber Users and their status:\n");
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "jabber show connected";
+ e->usage =
+ "Usage: jabber show connected\n"
+ " Shows state of clients and components\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ ast_cli(a->fd, "Jabber Users and their status:\n");
ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
ASTOBJ_RDLOCK(iterator);
count++;
@@ -2114,36 +2117,45 @@ static int aji_show_clients(int fd, int argc, char *argv[])
default:
status = "Unknown";
}
- ast_cli(fd, " User: %s - %s\n", iterator->user, status);
+ ast_cli(a->fd, " User: %s - %s\n", iterator->user, status);
ASTOBJ_UNLOCK(iterator);
});
- ast_cli(fd, "----\n");
- ast_cli(fd, " Number of users: %d\n", count);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "----\n");
+ ast_cli(a->fd, " Number of users: %d\n", count);
+ return CLI_SUCCESS;
}
/*!
- * \brief send test message for debugging.
- * \param fd
- * \param argc Integer. number of args
- * \param argv list of arguements
- * \return RESULT_SUCCESS,RESULT_FAILURE.
+ * \brief Send test message for debugging.
+ * \return CLI_SUCCESS,CLI_FAILURE.
*/
-static int aji_test(int fd, int argc, char *argv[])
+static char *aji_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct aji_client *client;
struct aji_resource *resource;
const char *name = "asterisk";
struct aji_message *tmp;
- if (argc > 3)
- return RESULT_SHOWUSAGE;
- else if (argc == 3)
- name = argv[2];
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "jabber test";
+ e->usage =
+ "Usage: jabber test [client]\n"
+ " Sends test message for debugging purposes. A specific client\n"
+ " as configured in jabber.conf can be optionally specified.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc > 3)
+ return CLI_SHOWUSAGE;
+ else if (a->argc == 3)
+ name = a->argv[2];
if (!(client = ASTOBJ_CONTAINER_FIND(&clients, name))) {
- ast_cli(fd, "Unable to find client '%s'!\n", name);
- return RESULT_FAILURE;
+ ast_cli(a->fd, "Unable to find client '%s'!\n", name);
+ return CLI_FAILURE;
}
/* XXX Does Matt really want everyone to use his personal address for tests? */ /* XXX yes he does */
@@ -2172,7 +2184,7 @@ static int aji_test(int fd, int argc, char *argv[])
AST_LIST_UNLOCK(&client->messages);
ASTOBJ_UNREF(client, aji_client_destroy);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
/*!
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index 047cf3cce..5c6490fcc 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -854,10 +854,8 @@ static int moh_scan_files(struct mohclass *class) {
if (!S_ISREG(statbuf.st_mode))
continue;
- if ((ext = strrchr(filepath, '.'))) {
+ if ((ext = strrchr(filepath, '.')))
*ext = '\0';
- ext++;
- }
/* if the file is present in multiple formats, ensure we only put it into the list once */
for (i = 0; i < class->total_files; i++)
@@ -1147,66 +1145,102 @@ static void ast_moh_destroy(void)
AST_RWLIST_UNLOCK(&mohclasses);
}
-static int moh_cli(int fd, int argc, char *argv[])
+static char *handle_cli_moh_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "moh reload";
+ e->usage =
+ "Usage: moh reload\n"
+ " Reloads the MusicOnHold module.\n"
+ " Alias for 'module reload res_musiconhold.so'\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != e->args)
+ return CLI_SHOWUSAGE;
+
reload();
- return 0;
+ return CLI_SUCCESS;
}
-static int cli_files_show(int fd, int argc, char *argv[])
+static char *handle_cli_moh_show_files(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int i;
struct mohclass *class;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "moh show files";
+ e->usage =
+ "Usage: moh show files\n"
+ " Lists all loaded file-based MusicOnHold classes and their\n"
+ " files.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != e->args)
+ return CLI_SHOWUSAGE;
+
AST_RWLIST_RDLOCK(&mohclasses);
AST_RWLIST_TRAVERSE(&mohclasses, class, list) {
if (!class->total_files)
continue;
- ast_cli(fd, "Class: %s\n", class->name);
+ ast_cli(a->fd, "Class: %s\n", class->name);
for (i = 0; i < class->total_files; i++)
- ast_cli(fd, "\tFile: %s\n", class->filearray[i]);
+ ast_cli(a->fd, "\tFile: %s\n", class->filearray[i]);
}
AST_RWLIST_UNLOCK(&mohclasses);
- return 0;
+ return CLI_SUCCESS;
}
-static int moh_classes_show(int fd, int argc, char *argv[])
+static char *handle_cli_moh_show_classes(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct mohclass *class;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "moh show classes";
+ e->usage =
+ "Usage: moh show classes\n"
+ " Lists all MusicOnHold classes.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != e->args)
+ return CLI_SHOWUSAGE;
+
AST_RWLIST_RDLOCK(&mohclasses);
AST_RWLIST_TRAVERSE(&mohclasses, class, list) {
- ast_cli(fd, "Class: %s\n", class->name);
- ast_cli(fd, "\tMode: %s\n", S_OR(class->mode, "<none>"));
- ast_cli(fd, "\tDirectory: %s\n", S_OR(class->dir, "<none>"));
- ast_cli(fd, "\tUse Count: %d\n", class->inuse);
+ ast_cli(a->fd, "Class: %s\n", class->name);
+ ast_cli(a->fd, "\tMode: %s\n", S_OR(class->mode, "<none>"));
+ ast_cli(a->fd, "\tDirectory: %s\n", S_OR(class->dir, "<none>"));
+ ast_cli(a->fd, "\tUse Count: %d\n", class->inuse);
if (class->digit)
- ast_cli(fd, "\tDigit: %c\n", class->digit);
+ ast_cli(a->fd, "\tDigit: %c\n", class->digit);
if (ast_test_flag(class, MOH_CUSTOM))
- ast_cli(fd, "\tApplication: %s\n", S_OR(class->args, "<none>"));
+ ast_cli(a->fd, "\tApplication: %s\n", S_OR(class->args, "<none>"));
if (strcasecmp(class->mode, "files"))
- ast_cli(fd, "\tFormat: %s\n", ast_getformatname(class->format));
+ ast_cli(a->fd, "\tFormat: %s\n", ast_getformatname(class->format));
}
AST_RWLIST_UNLOCK(&mohclasses);
- return 0;
+ return CLI_SUCCESS;
}
static struct ast_cli_entry cli_moh[] = {
- { { "moh", "reload"},
- moh_cli, "Music On Hold",
- "Music On Hold" },
-
- { { "moh", "show", "classes"},
- moh_classes_show, "List MOH classes",
- "Lists all MOH classes" },
-
- { { "moh", "show", "files"},
- cli_files_show, "List MOH file-based classes",
- "Lists all loaded file-based MOH classes and their files" },
+ NEW_CLI(handle_cli_moh_reload, "Reload MusicOnHold"),
+ NEW_CLI(handle_cli_moh_show_classes, "List MusicOnHold classes"),
+ NEW_CLI(handle_cli_moh_show_files, "List MusicOnHold file-based classes")
};
static int init_classes(int reload)
diff --git a/res/res_odbc.c b/res/res_odbc.c
index 2fd4c02cf..18627d4d2 100644
--- a/res/res_odbc.c
+++ b/res/res_odbc.c
@@ -333,47 +333,70 @@ static int load_odbc_config(void)
return res;
}
-static int odbc_show_command(int fd, int argc, char **argv)
+static char *handle_cli_odbc_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct odbc_class *class;
struct odbc_obj *current;
+ int length = 0;
+ int which = 0;
+ char *ret = NULL;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "odbc show";
+ e->usage =
+ "Usage: odbc show [class]\n"
+ " List settings of a particular ODBC class or,\n"
+ " if not specified, all classes.\n";
+ return NULL;
+ case CLI_GENERATE:
+ if (a->pos != 2)
+ return NULL;
+ length = strlen(a->word);
+ AST_LIST_LOCK(&odbc_list);
+ AST_LIST_TRAVERSE(&odbc_list, class, list) {
+ if (!strncasecmp(a->word, class->name, length) && ++which > a->n) {
+ ret = ast_strdup(class->name);
+ break;
+ }
+ }
+ if (!ret && !strncasecmp(a->word, "all", length) && ++which > a->n) {
+ ret = ast_strdup("all");
+ }
+ AST_LIST_UNLOCK(&odbc_list);
+ return ret;
+ }
+ ast_cli(a->fd, "\nODBC DSN Settings\n");
+ ast_cli(a->fd, "-----------------\n\n");
AST_LIST_LOCK(&odbc_list);
AST_LIST_TRAVERSE(&odbc_list, class, list) {
- if ((argc == 2) || (argc == 3 && !strcmp(argv[2], "all")) || (!strcmp(argv[2], class->name))) {
+ if ((a->argc == 2) || (a->argc == 3 && !strcmp(a->argv[2], "all")) || (!strcmp(a->argv[2], class->name))) {
int count = 0;
- ast_cli(fd, "Name: %s\nDSN: %s\n", class->name, class->dsn);
+ ast_cli(a->fd, " Name: %s\n DSN: %s\n", class->name, class->dsn);
if (class->haspool) {
- ast_cli(fd, "Pooled: yes\nLimit: %d\nConnections in use: %d\n", class->limit, class->count);
+ ast_cli(a->fd, " Pooled: Yes\n Limit: %d\n Connections in use: %d\n", class->limit, class->count);
AST_LIST_TRAVERSE(&(class->odbc_obj), current, list) {
- ast_cli(fd, " Connection %d: %s\n", ++count, current->up && ast_odbc_sanity_check(current) ? "connected" : "disconnected");
+ ast_cli(a->fd, " - Connection %d: %s\n", ++count, current->up && ast_odbc_sanity_check(current) ? "Connected" : "Disconnected");
}
} else {
/* Should only ever be one of these */
AST_LIST_TRAVERSE(&(class->odbc_obj), current, list) {
- ast_cli(fd, "Pooled: no\nConnected: %s\n", current->up && ast_odbc_sanity_check(current) ? "yes" : "no");
+ ast_cli(a->fd, " Pooled: No\n Connected: %s\n", current->up && ast_odbc_sanity_check(current) ? "Yes" : "No");
}
}
-
- ast_cli(fd, "\n");
+ ast_cli(a->fd, "\n");
}
}
AST_LIST_UNLOCK(&odbc_list);
- return 0;
+ return CLI_SUCCESS;
}
-static const char show_usage[] =
-"Usage: odbc show [<class>]\n"
-" List settings of a particular ODBC class.\n"
-" or, if not specified, all classes.\n";
-
static struct ast_cli_entry cli_odbc[] = {
- { { "odbc", "show", NULL },
- odbc_show_command, "List ODBC DSN(s)",
- show_usage },
+ NEW_CLI(handle_cli_odbc_show, "List ODBC DSN(s)")
};
static int odbc_register_class(struct odbc_class *class, int connect)
diff --git a/res/res_realtime.c b/res/res_realtime.c
index 3981e74f1..e560e02a3 100644
--- a/res/res_realtime.c
+++ b/res/res_realtime.c
@@ -47,68 +47,78 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/cli.h"
-static int cli_realtime_load(int fd, int argc, char **argv)
+static char *cli_realtime_load(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
char *header_format = "%30s %-30s\n";
struct ast_variable *var=NULL;
- if(argc<5) {
- ast_cli(fd, "You must supply a family name, a column to match on, and a value to match to.\n");
- return RESULT_FAILURE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "realtime load";
+ e->usage =
+ "Usage: realtime load <family> <colmatch> <value>\n"
+ " Prints out a list of variables using the RealTime driver.\n"
+ " You must supply a family name, a column to match on, and a value to match to.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
}
- var = ast_load_realtime_all(argv[2], argv[3], argv[4], NULL);
- if(var) {
- ast_cli(fd, header_format, "Column Name", "Column Value");
- ast_cli(fd, header_format, "--------------------", "--------------------");
- while(var) {
- ast_cli(fd, header_format, var->name, var->value);
+ if (a->argc < 5)
+ return CLI_SHOWUSAGE;
+
+ var = ast_load_realtime_all(a->argv[2], a->argv[3], a->argv[4], NULL);
+
+ if (var) {
+ ast_cli(a->fd, header_format, "Column Name", "Column Value");
+ ast_cli(a->fd, header_format, "--------------------", "--------------------");
+ while (var) {
+ ast_cli(a->fd, header_format, var->name, var->value);
var = var->next;
}
} else {
- ast_cli(fd, "No rows found matching search criteria.\n");
+ ast_cli(a->fd, "No rows found matching search criteria.\n");
}
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static int cli_realtime_update(int fd, int argc, char **argv) {
+static char *cli_realtime_update(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) {
int res = 0;
- if(argc<7) {
- ast_cli(fd, "You must supply a family name, a column to update on, a new value, column to match, and value to to match.\n");
- ast_cli(fd, "Ex: realtime update sipfriends name bobsphone port 4343\n will execute SQL as UPDATE sipfriends SET port = 4343 WHERE name = bobsphone\n");
- return RESULT_FAILURE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "realtime update";
+ e->usage =
+ "Usage: realtime update <family> <colupdate> <newvalue> <colmatch> <valuematch>\n"
+ " Update a single variable using the RealTime driver.\n"
+ " You must supply a family name, a column to update on, a new value, column to match, and value to match.\n"
+ " Ex: realtime update sipfriends name bobsphone port 4343\n"
+ " will execute SQL as UPDATE sipfriends SET port = 4343 WHERE name = bobsphone\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
}
- res = ast_update_realtime(argv[2], argv[3], argv[4], argv[5], argv[6], NULL);
+
+ if (a->argc < 7)
+ return CLI_SHOWUSAGE;
+
+ res = ast_update_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], NULL);
if(res < 0) {
- ast_cli(fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
+ return CLI_FAILURE;
}
- ast_cli(fd, "Updated %d RealTime record%s.\n", res, ESS(res));
+ ast_cli(a->fd, "Updated %d RealTime record%s.\n", res, ESS(res));
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static const char cli_realtime_load_usage[] =
-"Usage: realtime load <family> <colmatch> <value>\n"
-" Prints out a list of variables using the RealTime driver.\n";
-
-static const char cli_realtime_update_usage[] =
-"Usage: realtime update <family> <colmatch> <value>\n"
-" Update a single variable using the RealTime driver.\n";
-
static struct ast_cli_entry cli_realtime[] = {
- { { "realtime", "load", NULL, NULL },
- cli_realtime_load, "Used to print out RealTime variables.",
- cli_realtime_load_usage, NULL },
-
- { { "realtime", "update", NULL, NULL },
- cli_realtime_update, "Used to update RealTime variables.",
- cli_realtime_update_usage, NULL },
+ NEW_CLI(cli_realtime_load, "Used to print out RealTime variables."),
+ NEW_CLI(cli_realtime_update, "Used to update RealTime variables."),
};
static int unload_module(void)