Mon Oct 8 12:39:28 2012

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 = "ac1f6a56484a8820659555499174e588" , .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 272 of file res_realtime.c.

static void __unreg_module ( void   )  [static]

Definition at line 272 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 210 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.

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

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

Definition at line 47 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.

00048 {
00049 #define CRL_HEADER_FORMAT "%30s  %-30s\n"
00050    struct ast_variable *var = NULL, *orig_var = NULL;
00051 
00052    switch (cmd) {
00053    case CLI_INIT:
00054       e->command = "realtime load";
00055       e->usage =
00056          "Usage: realtime load <family> <colmatch> <value>\n"
00057          "       Prints out a list of variables using the RealTime driver.\n"
00058          "       You must supply a family name, a column to match on, and a value to match to.\n";
00059       return NULL;
00060    case CLI_GENERATE:
00061       return NULL;
00062    }
00063 
00064 
00065    if (a->argc < 5) 
00066       return CLI_SHOWUSAGE;
00067 
00068    var = ast_load_realtime_all(a->argv[2], a->argv[3], a->argv[4], SENTINEL);
00069 
00070    if (var) {
00071       ast_cli(a->fd, CRL_HEADER_FORMAT, "Column Name", "Column Value");
00072       ast_cli(a->fd, CRL_HEADER_FORMAT, "--------------------", "--------------------");
00073       orig_var = var;
00074       while (var) {
00075          ast_cli(a->fd, CRL_HEADER_FORMAT, var->name, var->value);
00076          var = var->next;
00077       }
00078    } else {
00079       ast_cli(a->fd, "No rows found matching search criteria.\n");
00080    }
00081    ast_variables_destroy(orig_var);
00082    return CLI_SUCCESS;
00083 }

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

Definition at line 165 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.

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

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

Definition at line 85 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.

00086 {
00087    int res = 0;
00088 
00089    switch (cmd) {
00090    case CLI_INIT:
00091       e->command = "realtime update";
00092       e->usage =
00093          "Usage: realtime update <family> <colmatch> <valuematch> <colupdate> <newvalue>\n"
00094          "       Update a single variable using the RealTime driver.\n"
00095          "       You must supply a family name, a column to update on, a new value, column to match, and value to match.\n"
00096          "       Ex: realtime update sippeers name bobsphone port 4343\n"
00097          "       will execute SQL as UPDATE sippeers SET port = 4343 WHERE name = bobsphone\n";
00098       return NULL;
00099    case CLI_GENERATE:
00100       return NULL;
00101    }
00102 
00103    if (a->argc < 7) 
00104       return CLI_SHOWUSAGE;
00105 
00106    res = ast_update_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL);
00107 
00108    if (res < 0) {
00109       ast_cli(a->fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
00110       return CLI_FAILURE;
00111    }
00112 
00113    ast_cli(a->fd, "Updated %d RealTime record%s.\n", res, ESS(res));
00114 
00115    return CLI_SUCCESS;
00116 }

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

Definition at line 118 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.

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

static int load_module ( void   )  [static]

Definition at line 266 of file res_realtime.c.

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

00267 {
00268    ast_cli_register_multiple(cli_realtime, ARRAY_LEN(cli_realtime));
00269    return AST_MODULE_LOAD_SUCCESS;
00270 }

static int unload_module ( void   )  [static]

Definition at line 260 of file res_realtime.c.

References ARRAY_LEN, ast_cli_unregister_multiple(), and cli_realtime.

00261 {
00262    ast_cli_unregister_multiple(cli_realtime, ARRAY_LEN(cli_realtime));
00263    return 0;
00264 }


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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 272 of file res_realtime.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 272 of file res_realtime.c.

struct ast_cli_entry cli_realtime[] [static]

Definition at line 252 of file res_realtime.c.


Generated on Mon Oct 8 12:39:28 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7