2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Anthony Minessale <anthmct@yahoo.com>
7 * Mark Spencer <markster@digium.com>
9 * See http://www.asterisk.org for more information about
10 * the Asterisk project. Please do not directly contact
11 * any of the maintainers of this project for assistance;
12 * the project provides a web site, mailing lists and IRC
13 * channels for your use.
15 * This program is free software, distributed under the terms of
16 * the GNU General Public License Version 2. See the LICENSE file
17 * at the top of the source tree.
24 * \author Anthony Minessale <anthmct@yahoo.com>
25 * \author Mark Spencer <markster@digium.com>
27 * \ingroup applications
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
39 #include "asterisk/file.h"
40 #include "asterisk/logger.h"
41 #include "asterisk/channel.h"
42 #include "asterisk/options.h"
43 #include "asterisk/pbx.h"
44 #include "asterisk/config.h"
45 #include "asterisk/module.h"
46 #include "asterisk/lock.h"
47 #include "asterisk/cli.h"
50 static int cli_realtime_load(int fd, int argc, char **argv)
52 char *header_format = "%30s %-30s\n";
53 struct ast_variable *var=NULL;
56 ast_cli(fd, "You must supply a family name, a column to match on, and a value to match to.\n");
57 return RESULT_FAILURE;
60 var = ast_load_realtime(argv[2], argv[3], argv[4], NULL);
63 ast_cli(fd, header_format, "Column Name", "Column Value");
64 ast_cli(fd, header_format, "--------------------", "--------------------");
66 ast_cli(fd, header_format, var->name, var->value);
70 ast_cli(fd, "No rows found matching search criteria.\n");
72 return RESULT_SUCCESS;
75 static int cli_realtime_update(int fd, int argc, char **argv) {
79 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");
80 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");
81 return RESULT_FAILURE;
84 res = ast_update_realtime(argv[2], argv[3], argv[4], argv[5], argv[6], NULL);
87 ast_cli(fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
88 return RESULT_SUCCESS;
91 ast_cli(fd, "Updated %d RealTime record%s.\n", res, ESS(res));
93 return RESULT_SUCCESS;
96 static const char cli_realtime_load_usage[] =
97 "Usage: realtime load <family> <colmatch> <value>\n"
98 " Prints out a list of variables using the RealTime driver.\n";
100 static const char cli_realtime_update_usage[] =
101 "Usage: realtime update <family> <colmatch> <value>\n"
102 " Update a single variable using the RealTime driver.\n";
104 static struct ast_cli_entry cli_realtime[] = {
105 { { "realtime", "load", NULL, NULL },
106 cli_realtime_load, "Used to print out RealTime variables.",
107 cli_realtime_load_usage, NULL },
109 { { "realtime", "update", NULL, NULL },
110 cli_realtime_update, "Used to update RealTime variables.",
111 cli_realtime_update_usage, NULL },
114 static int unload_module(void)
116 ast_cli_unregister_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
117 ast_module_user_hangup_all();
121 static int load_module(void)
123 ast_cli_register_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
127 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Realtime Data Lookup/Rewrite");