[Asterisk-cvs] asterisk/apps app_realtime.c,1.3,1.4

markster at lists.digium.com markster at lists.digium.com
Thu Oct 14 00:17:09 CDT 2004


Update of /usr/cvsroot/asterisk/apps
In directory mongoose.digium.com:/tmp/cvs-serv9424/apps

Modified Files:
	app_realtime.c 
Log Message:
Add CLI for realtime stuff (bug #2626)


Index: app_realtime.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_realtime.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- app_realtime.c	7 Oct 2004 19:57:50 -0000	1.3
+++ app_realtime.c	14 Oct 2004 04:17:34 -0000	1.4
@@ -20,6 +20,7 @@
 #include <asterisk/config.h>
 #include <asterisk/module.h>
 #include <asterisk/lock.h>
+#include <asterisk/cli.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
@@ -45,7 +46,70 @@
 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 <family> <colmatch> <value>\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 <family> <colmatch> <value>\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 @@
 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);
 }




More information about the svn-commits mailing list