res_realtime.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "asterisk.h"
00031
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 165324 $")
00033
00034 #include "asterisk/file.h"
00035 #include "asterisk/channel.h"
00036 #include "asterisk/pbx.h"
00037 #include "asterisk/config.h"
00038 #include "asterisk/module.h"
00039 #include "asterisk/lock.h"
00040 #include "asterisk/cli.h"
00041
00042
00043 static char *cli_realtime_load(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
00044 {
00045 #define CRL_HEADER_FORMAT "%30s %-30s\n"
00046 struct ast_variable *var = NULL, *orig_var = NULL;
00047
00048 switch (cmd) {
00049 case CLI_INIT:
00050 e->command = "realtime load";
00051 e->usage =
00052 "Usage: realtime load <family> <colmatch> <value>\n"
00053 " Prints out a list of variables using the RealTime driver.\n"
00054 " You must supply a family name, a column to match on, and a value to match to.\n";
00055 return NULL;
00056 case CLI_GENERATE:
00057 return NULL;
00058 }
00059
00060
00061 if (a->argc < 5)
00062 return CLI_SHOWUSAGE;
00063
00064 var = ast_load_realtime_all(a->argv[2], a->argv[3], a->argv[4], SENTINEL);
00065
00066 if (var) {
00067 ast_cli(a->fd, CRL_HEADER_FORMAT, "Column Name", "Column Value");
00068 ast_cli(a->fd, CRL_HEADER_FORMAT, "--------------------", "--------------------");
00069 orig_var = var;
00070 while (var) {
00071 ast_cli(a->fd, CRL_HEADER_FORMAT, var->name, var->value);
00072 var = var->next;
00073 }
00074 } else {
00075 ast_cli(a->fd, "No rows found matching search criteria.\n");
00076 }
00077 ast_variables_destroy(orig_var);
00078 return CLI_SUCCESS;
00079 }
00080
00081 static char *cli_realtime_update(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) {
00082 int res = 0;
00083
00084 switch (cmd) {
00085 case CLI_INIT:
00086 e->command = "realtime update";
00087 e->usage =
00088 "Usage: realtime update <family> <colmatch> <valuematch> <colupdate> <newvalue>\n"
00089 " Update a single variable using the RealTime driver.\n"
00090 " You must supply a family name, a column to update on, a new value, column to match, and value to match.\n"
00091 " Ex: realtime update sipfriends name bobsphone port 4343\n"
00092 " will execute SQL as UPDATE sipfriends SET port = 4343 WHERE name = bobsphone\n";
00093 return NULL;
00094 case CLI_GENERATE:
00095 return NULL;
00096 }
00097
00098
00099 if (a->argc < 7)
00100 return CLI_SHOWUSAGE;
00101
00102 res = ast_update_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL);
00103
00104 if(res < 0) {
00105 ast_cli(a->fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
00106 return CLI_FAILURE;
00107 }
00108
00109 ast_cli(a->fd, "Updated %d RealTime record%s.\n", res, ESS(res));
00110
00111 return CLI_SUCCESS;
00112 }
00113
00114 static struct ast_cli_entry cli_realtime[] = {
00115 AST_CLI_DEFINE(cli_realtime_load, "Used to print out RealTime variables."),
00116 AST_CLI_DEFINE(cli_realtime_update, "Used to update RealTime variables."),
00117 };
00118
00119 static int unload_module(void)
00120 {
00121 ast_cli_unregister_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
00122 return 0;
00123 }
00124
00125 static int load_module(void)
00126 {
00127 ast_cli_register_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
00128 return AST_MODULE_LOAD_SUCCESS;
00129 }
00130
00131 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Realtime Data Lookup/Rewrite");