Mon Jun 27 16:51:20 2011

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"

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_destroy (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * cli_realtime_load (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * cli_realtime_store (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 char * cli_realtime_update2 (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_LOAD_ORDER , .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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
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 268 of file res_realtime.c.

static void __unreg_module ( void   )  [static]

Definition at line 268 of file res_realtime.c.

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

Definition at line 206 of file res_realtime.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_destroy_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.

00207 {
00208    int res = -1;
00209 
00210    switch (cmd) {
00211    case CLI_INIT:
00212       e->command = "realtime destroy";
00213       e->usage =
00214          "Usage: realtime destroy <family> <colmatch1> <valuematch1> [<colmatch2> <valuematch2> [... <colmatch5> <valuematch5>]]\n"
00215          "       Remove a stored row using the RealTime driver.\n"
00216          "       You must supply a family name and name/value pairs (up to 5).\n";
00217       return NULL;
00218    case CLI_GENERATE:
00219       return NULL;
00220    }
00221 
00222    if (a->argc < 5) {
00223       return CLI_SHOWUSAGE;
00224    } else if (a->argc == 5) {
00225       res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL);
00226    } else if (a->argc == 7) {
00227       res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL);
00228    } else if (a->argc == 9) {
00229       res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], SENTINEL);
00230    } else if (a->argc == 11) {
00231       res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], SENTINEL);
00232    } else if (a->argc == 13) {
00233       res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], SENTINEL);
00234    } else {
00235       return CLI_SHOWUSAGE;
00236    }
00237 
00238    if (res < 0) {
00239       ast_cli(a->fd, "Failed to remove record. Check the debug log for possible SQL related entries.\n");
00240       return CLI_FAILURE;
00241    }
00242 
00243    ast_cli(a->fd, "Removed %d RealTime record%s.\n", res, ESS(res));
00244 
00245    return CLI_SUCCESS;
00246 }

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, SENTINEL, ast_cli_entry::usage, 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_store ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 161 of file res_realtime.c.

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

00162 {
00163    int res = -1;
00164 
00165    switch (cmd) {
00166    case CLI_INIT:
00167       e->command = "realtime store";
00168       e->usage =
00169          "Usage: realtime store <family> <colname1> <value1> [<colname2> <value2> [... <colname5> <value5>]]\n"
00170          "       Create a stored row using the RealTime driver.\n"
00171          "       You must supply a family name and name/value pairs (up to 5).  If\n"
00172          "       you need to store more than 5 key/value pairs, start with the first\n"
00173          "       five, then use 'realtime update' or 'realtime update2' to add\n"
00174          "       additional columns.\n";
00175       return NULL;
00176    case CLI_GENERATE:
00177       return NULL;
00178    }
00179 
00180    if (a->argc < 5) {
00181       return CLI_SHOWUSAGE;
00182    } else if (a->argc == 5) {
00183       res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL);
00184    } else if (a->argc == 7) {
00185       res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL);
00186    } else if (a->argc == 9) {
00187       res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], SENTINEL);
00188    } else if (a->argc == 11) {
00189       res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], SENTINEL);
00190    } else if (a->argc == 13) {
00191       res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], SENTINEL);
00192    } else {
00193       return CLI_SHOWUSAGE;
00194    }
00195 
00196    if (res < 0) {
00197       ast_cli(a->fd, "Failed to store record. Check the debug log for possible SQL related entries.\n");
00198       return CLI_FAILURE;
00199    }
00200 
00201    ast_cli(a->fd, "Stored RealTime record.\n");
00202 
00203    return CLI_SUCCESS;
00204 }

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.

00082 {
00083    int res = 0;
00084 
00085    switch (cmd) {
00086    case CLI_INIT:
00087       e->command = "realtime update";
00088       e->usage =
00089          "Usage: realtime update <family> <colmatch> <valuematch> <colupdate> <newvalue>\n"
00090          "       Update a single variable using the RealTime driver.\n"
00091          "       You must supply a family name, a column to update on, a new value, column to match, and value to match.\n"
00092          "       Ex: realtime update sipfriends name bobsphone port 4343\n"
00093          "       will execute SQL as UPDATE sipfriends SET port = 4343 WHERE name = bobsphone\n";
00094       return NULL;
00095    case CLI_GENERATE:
00096       return NULL;
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 char* cli_realtime_update2 ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 114 of file res_realtime.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_update2_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.

00115 {
00116    int res = -1;
00117 
00118    switch (cmd) {
00119    case CLI_INIT:
00120       e->command = "realtime update2";
00121       e->usage =
00122          "Usage: realtime update2 <family> <colmatch> <valuematch> [... <colmatch5> <valuematch5>] NULL <colupdate> <newvalue>\n"
00123          "   Update a single variable, requiring one or more fields to match using the\n"
00124          "   RealTime driver.  You must supply a family name, a column to update, a new\n"
00125          "   value, and at least one column and value to match.\n"
00126          "   Ex: realtime update sipfriends name bobsphone ipaddr 127.0.0.1 NULL port 4343\n"
00127          "   will execute SQL as\n"
00128          "   UPDATE sipfriends SET port='4343' WHERE name='bobsphone' and ipaddr='127.0.0.1'\n";
00129       return NULL;
00130    case CLI_GENERATE:
00131       return NULL;
00132    }
00133 
00134    if (a->argc < 7) 
00135       return CLI_SHOWUSAGE;
00136 
00137    if (a->argc == 7) {
00138       res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL, a->argv[5], a->argv[6], SENTINEL);
00139    } else if (a->argc == 9) {
00140       res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL, a->argv[7], a->argv[8], SENTINEL);
00141    } else if (a->argc == 11) {
00142       res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], SENTINEL, a->argv[9], a->argv[10], SENTINEL);
00143    } else if (a->argc == 13) {
00144       res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], SENTINEL, a->argv[11], a->argv[12], SENTINEL);
00145    } else if (a->argc == 15) {
00146       res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], SENTINEL, a->argv[13], a->argv[14], SENTINEL);
00147    } else {
00148       return CLI_SHOWUSAGE;
00149    }
00150 
00151    if (res < 0) {
00152       ast_cli(a->fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
00153       return CLI_FAILURE;
00154    }
00155 
00156    ast_cli(a->fd, "Updated %d RealTime record%s.\n", res, ESS(res));
00157 
00158    return CLI_SUCCESS;
00159 }

static int load_module ( void   )  [static]

Definition at line 262 of file res_realtime.c.

References ARRAY_LEN, ast_cli_register_multiple(), AST_MODULE_LOAD_SUCCESS, and cli_realtime.

00263 {
00264    ast_cli_register_multiple(cli_realtime, ARRAY_LEN(cli_realtime));
00265    return AST_MODULE_LOAD_SUCCESS;
00266 }

static int unload_module ( void   )  [static]

Definition at line 256 of file res_realtime.c.

References ARRAY_LEN, ast_cli_unregister_multiple(), and cli_realtime.

00257 {
00258    ast_cli_unregister_multiple(cli_realtime, ARRAY_LEN(cli_realtime));
00259    return 0;
00260 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 268 of file res_realtime.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 268 of file res_realtime.c.

struct ast_cli_entry cli_realtime[] [static]

Definition at line 248 of file res_realtime.c.


Generated on Mon Jun 27 16:51:20 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7