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 char *cli_realtime_load(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
52 char *header_format = "%30s %-30s\n";
53 struct ast_variable *var=NULL;
57 e->command = "realtime load";
59 "Usage: realtime load <family> <colmatch> <value>\n"
60 " Prints out a list of variables using the RealTime driver.\n"
61 " You must supply a family name, a column to match on, and a value to match to.\n";
71 var = ast_load_realtime_all(a->argv[2], a->argv[3], a->argv[4], NULL);
74 ast_cli(a->fd, header_format, "Column Name", "Column Value");
75 ast_cli(a->fd, header_format, "--------------------", "--------------------");
77 ast_cli(a->fd, header_format, var->name, var->value);
81 ast_cli(a->fd, "No rows found matching search criteria.\n");
86 static char *cli_realtime_update(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) {
91 e->command = "realtime update";
93 "Usage: realtime update <family> <colupdate> <newvalue> <colmatch> <valuematch>\n"
94 " Update a single variable using the RealTime driver.\n"
95 " You must supply a family name, a column to update on, a new value, column to match, and value to match.\n"
96 " Ex: realtime update sipfriends name bobsphone port 4343\n"
97 " will execute SQL as UPDATE sipfriends SET port = 4343 WHERE name = bobsphone\n";
105 return CLI_SHOWUSAGE;
107 res = ast_update_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], NULL);
110 ast_cli(a->fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
114 ast_cli(a->fd, "Updated %d RealTime record%s.\n", res, ESS(res));
119 static struct ast_cli_entry cli_realtime[] = {
120 AST_CLI_DEFINE(cli_realtime_load, "Used to print out RealTime variables."),
121 AST_CLI_DEFINE(cli_realtime_update, "Used to update RealTime variables."),
124 static int unload_module(void)
126 ast_cli_unregister_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
130 static int load_module(void)
132 ast_cli_register_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
133 return AST_MODULE_LOAD_SUCCESS;
136 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Realtime Data Lookup/Rewrite");