summaryrefslogtreecommitdiff
path: root/res/res_odbc.c
diff options
context:
space:
mode:
authorJason Parker <jparker@digium.com>2007-09-18 22:43:45 +0000
committerJason Parker <jparker@digium.com>2007-09-18 22:43:45 +0000
commitc7a9ec1691ebce1ff4786e74285ceea62b6782e8 (patch)
treed49317ce7050cdca6ecef46706a320e879421c61 /res/res_odbc.c
parent0c8381a1f58c866a3a4f324509678b3983487dd4 (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: https://origsvn.digium.com/svn/asterisk/trunk@82930 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_odbc.c')
-rw-r--r--res/res_odbc.c57
1 files changed, 40 insertions, 17 deletions
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)