From 0134b03b770f385d4b326d71536f5a0538502fcc Mon Sep 17 00:00:00 2001 From: Mark Spencer Date: Thu, 14 Oct 2004 04:17:34 +0000 Subject: Add CLI for realtime stuff (bug #2626) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3995 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- apps/app_realtime.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) (limited to 'apps/app_realtime.c') diff --git a/apps/app_realtime.c b/apps/app_realtime.c index 53f2fac8e..74ff6db36 100755 --- a/apps/app_realtime.c +++ b/apps/app_realtime.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,70 @@ static char *udesc = "Use the RealTime config handler system to update a value\n STANDARD_LOCAL_USER; LOCAL_USER_DECL; -static int realtime_update_exec(struct ast_channel *chan, void *data) { +static int cli_load_realtime(int fd, int argc, char **argv) +{ + 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; + } + + var = ast_load_realtime(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); + var = var->next; + } + } else { + ast_cli(fd, "No rows found matching search criteria.\n"); + } + return RESULT_SUCCESS; +} + +static int cli_update_realtime(int fd, int argc, char **argv) { + 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; + } + + res = ast_update_realtime(argv[2], argv[3], argv[4], argv[5], 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(fd, "Updated RealTime record.\n"); + + return RESULT_SUCCESS; +} + +static char cli_load_realtime_usage[] = +"Usage: realtime load \n" +" Prints out a list of variables using the RealTime driver.\n"; + +static struct ast_cli_entry cli_load_realtime_cmd = { + { "realtime", "load", NULL, NULL }, cli_load_realtime, + "Used to print out RealTime variables.", cli_load_realtime_usage, NULL }; + +static char cli_update_realtime_usage[] = +"Usage: realtime update \n" +" Update a single variable using the RealTime driver.\n"; + +static struct ast_cli_entry cli_update_realtime_cmd = { + { "realtime", "update", NULL, NULL }, cli_update_realtime, + "Used to update RealTime variables.", cli_update_realtime_usage, NULL }; + +static int realtime_update_exec(struct ast_channel *chan, void *data) +{ char *family=NULL, *colmatch=NULL, *value=NULL, *newcol=NULL, *newval=NULL; struct localuser *u; int res = 0; @@ -133,12 +197,16 @@ static int realtime_exec(struct ast_channel *chan, void *data) int unload_module(void) { STANDARD_HANGUP_LOCALUSERS; + ast_cli_unregister(&cli_load_realtime_cmd); + ast_cli_unregister(&cli_update_realtime_cmd); ast_unregister_application(uapp); return ast_unregister_application(app); } int load_module(void) { + ast_cli_register(&cli_load_realtime_cmd); + ast_cli_register(&cli_update_realtime_cmd); ast_register_application(uapp, realtime_update_exec, usynopsis, udesc); return ast_register_application(app, realtime_exec, synopsis, desc); } -- cgit v1.2.3