Wed Aug 18 22:33:55 2010

Asterisk developer's documentation


res_realtime.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Anthony Minessale <anthmct@yahoo.com>
00007  * Mark Spencer <markster@digium.com>
00008  *
00009  * See http://www.asterisk.org for more information about
00010  * the Asterisk project. Please do not directly contact
00011  * any of the maintainers of this project for assistance;
00012  * the project provides a web site, mailing lists and IRC
00013  * channels for your use.
00014  *
00015  * This program is free software, distributed under the terms of
00016  * the GNU General Public License Version 2. See the LICENSE file
00017  * at the top of the source tree.
00018  */
00019 
00020 /*! \file
00021  *
00022  * \brief RealTime CLI
00023  *
00024  * \author Anthony Minessale <anthmct@yahoo.com>
00025  * \author Mark Spencer <markster@digium.com>
00026  * 
00027  * \ingroup applications
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");

Generated on Wed Aug 18 22:33:55 2010 for Asterisk - the Open Source PBX by  doxygen 1.4.7