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$")
34 #include "asterisk/file.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/pbx.h"
37 #include "asterisk/config.h"
38 #include "asterisk/module.h"
39 #include "asterisk/lock.h"
40 #include "asterisk/cli.h"
43 static char *cli_realtime_load(struct ast_cli_entry
*e
, int cmd
, struct ast_cli_args
*a
)
45 #define CRL_HEADER_FORMAT "%30s %-30s\n"
46 struct ast_variable
*var
=NULL
;
50 e
->command
= "realtime load";
52 "Usage: realtime load <family> <colmatch> <value>\n"
53 " Prints out a list of variables using the RealTime driver.\n"
54 " You must supply a family name, a column to match on, and a value to match to.\n";
64 var
= ast_load_realtime_all(a
->argv
[2], a
->argv
[3], a
->argv
[4], SENTINEL
);
67 ast_cli(a
->fd
, CRL_HEADER_FORMAT
, "Column Name", "Column Value");
68 ast_cli(a
->fd
, CRL_HEADER_FORMAT
, "--------------------", "--------------------");
70 ast_cli(a
->fd
, CRL_HEADER_FORMAT
, var
->name
, var
->value
);
74 ast_cli(a
->fd
, "No rows found matching search criteria.\n");
79 static char *cli_realtime_update(struct ast_cli_entry
*e
, int cmd
, struct ast_cli_args
*a
) {
84 e
->command
= "realtime update";
86 "Usage: realtime update <family> <colupdate> <newvalue> <colmatch> <valuematch>\n"
87 " Update a single variable using the RealTime driver.\n"
88 " You must supply a family name, a column to update on, a new value, column to match, and value to match.\n"
89 " Ex: realtime update sipfriends name bobsphone port 4343\n"
90 " will execute SQL as UPDATE sipfriends SET port = 4343 WHERE name = bobsphone\n";
100 res
= ast_update_realtime(a
->argv
[2], a
->argv
[3], a
->argv
[4], a
->argv
[5], a
->argv
[6], SENTINEL
);
103 ast_cli(a
->fd
, "Failed to update. Check the debug log for possible SQL related entries.\n");
107 ast_cli(a
->fd
, "Updated %d RealTime record%s.\n", res
, ESS(res
));
112 static struct ast_cli_entry cli_realtime
[] = {
113 AST_CLI_DEFINE(cli_realtime_load
, "Used to print out RealTime variables."),
114 AST_CLI_DEFINE(cli_realtime_update
, "Used to update RealTime variables."),
117 static int unload_module(void)
119 ast_cli_unregister_multiple(cli_realtime
, sizeof(cli_realtime
) / sizeof(struct ast_cli_entry
));
123 static int load_module(void)
125 ast_cli_register_multiple(cli_realtime
, sizeof(cli_realtime
) / sizeof(struct ast_cli_entry
));
126 return AST_MODULE_LOAD_SUCCESS
;
129 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Realtime Data Lookup/Rewrite");