Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:00:54 2007

Asterisk developer's documentation :: Codename Pineapple


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: 49808 $")
00033 
00034 #include <stdlib.h>
00035 #include <stdio.h>
00036 #include <string.h>
00037 #include <unistd.h>
00038 
00039 #include "asterisk/file.h"
00040 #include "asterisk/logger.h"
00041 #include "asterisk/channel.h"
00042 #include "asterisk/options.h"
00043 #include "asterisk/pbx.h"
00044 #include "asterisk/config.h"
00045 #include "asterisk/module.h"
00046 #include "asterisk/lock.h"
00047 #include "asterisk/cli.h"
00048 
00049 
00050 static int cli_realtime_load(int fd, int argc, char **argv) 
00051 {
00052    char *header_format = "%30s  %-30s\n";
00053    struct ast_variable *var=NULL;
00054 
00055    if(argc<5) {
00056       ast_cli(fd, "You must supply a family name, a column to match on, and a value to match to.\n");
00057       return RESULT_FAILURE;
00058    }
00059 
00060    var = ast_load_realtime_all(argv[2], argv[3], argv[4], NULL);
00061 
00062    if(var) {
00063       ast_cli(fd, header_format, "Column Name", "Column Value");
00064       ast_cli(fd, header_format, "--------------------", "--------------------");
00065       while(var) {
00066          ast_cli(fd, header_format, var->name, var->value);
00067          var = var->next;
00068       }
00069    } else {
00070       ast_cli(fd, "No rows found matching search criteria.\n");
00071    }
00072    return RESULT_SUCCESS;
00073 }
00074 
00075 static int cli_realtime_update(int fd, int argc, char **argv) {
00076    int res = 0;
00077 
00078    if(argc<7) {
00079       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");
00080       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");
00081       return RESULT_FAILURE;
00082    }
00083 
00084    res = ast_update_realtime(argv[2], argv[3], argv[4], argv[5], argv[6], NULL);
00085 
00086    if(res < 0) {
00087       ast_cli(fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
00088       return RESULT_SUCCESS;
00089    }
00090 
00091        ast_cli(fd, "Updated %d RealTime record%s.\n", res, ESS(res));
00092 
00093    return RESULT_SUCCESS;
00094 }
00095 
00096 static const char cli_realtime_load_usage[] =
00097 "Usage: realtime load <family> <colmatch> <value>\n"
00098 "       Prints out a list of variables using the RealTime driver.\n";
00099 
00100 static const char cli_realtime_update_usage[] =
00101 "Usage: realtime update <family> <colmatch> <value>\n"
00102 "       Update a single variable using the RealTime driver.\n";
00103 
00104 static struct ast_cli_entry cli_realtime[] = {
00105    { { "realtime", "load", NULL, NULL },
00106    cli_realtime_load, "Used to print out RealTime variables.",
00107    cli_realtime_load_usage, NULL },
00108 
00109    { { "realtime", "update", NULL, NULL },
00110    cli_realtime_update, "Used to update RealTime variables.",
00111    cli_realtime_update_usage, NULL },
00112 };
00113 
00114 static int unload_module(void)
00115 {
00116    ast_cli_unregister_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
00117    ast_module_user_hangup_all();
00118    return 0;
00119 }
00120 
00121 static int load_module(void)
00122 {
00123    ast_cli_register_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
00124    return 0;
00125 }
00126 
00127 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Realtime Data Lookup/Rewrite");

Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen