Wed Oct 28 11:53:09 2009

Asterisk developer's documentation


res_realtime.c File Reference

RealTime CLI. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/cli.h"

Include dependency graph for res_realtime.c:

Go to the source code of this file.

Defines

#define CRL_HEADER_FORMAT   "%30s %-30s\n"

Functions

static void __reg_module (void)
static void __unreg_module (void)
static char * cli_realtime_load (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * cli_realtime_update (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int load_module (void)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Realtime Data Lookup/Rewrite" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, }
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_cli_entry cli_realtime []


Detailed Description

RealTime CLI.

Author:
Anthony Minessale <anthmct@yahoo.com>

Mark Spencer <markster@digium.com>

Definition in file res_realtime.c.


Define Documentation

#define CRL_HEADER_FORMAT   "%30s %-30s\n"

Referenced by cli_realtime_load().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 131 of file res_realtime.c.

static void __unreg_module ( void   )  [static]

Definition at line 131 of file res_realtime.c.

static char* cli_realtime_load ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 43 of file res_realtime.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_load_realtime_all(), ast_variables_destroy(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, CRL_HEADER_FORMAT, ast_cli_args::fd, ast_variable::name, ast_variable::next, SENTINEL, ast_cli_entry::usage, ast_variable::value, and var.

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 }

static char* cli_realtime_update ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 81 of file res_realtime.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_update_realtime(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ESS, ast_cli_args::fd, SENTINEL, and ast_cli_entry::usage.

00081                                                                                            {
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 }

static int load_module ( void   )  [static]

Definition at line 125 of file res_realtime.c.

References ast_cli_register_multiple(), and AST_MODULE_LOAD_SUCCESS.

00126 {
00127    ast_cli_register_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
00128    return AST_MODULE_LOAD_SUCCESS;
00129 }

static int unload_module ( void   )  [static]

Definition at line 119 of file res_realtime.c.

References ast_cli_unregister_multiple().

00120 {
00121    ast_cli_unregister_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
00122    return 0;
00123 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Realtime Data Lookup/Rewrite" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static]

Definition at line 131 of file res_realtime.c.

Definition at line 131 of file res_realtime.c.

struct ast_cli_entry cli_realtime[] [static]

Initial value:

 {
   AST_CLI_DEFINE(cli_realtime_load, "Used to print out RealTime variables."),
   AST_CLI_DEFINE(cli_realtime_update, "Used to update RealTime variables."),
}

Definition at line 114 of file res_realtime.c.


Generated on Wed Oct 28 11:53:10 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6