Sat Aug 6 00:39:36 2011

Asterisk developer's documentation


app_realtime.c File Reference

RealTime App. More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/options.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 crop_data(str)   { *(str) = '\0' ; (str)++; }
#define next_one(var)   var = var->next

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int cli_realtime_load (int fd, int argc, char **argv)
static int cli_realtime_update (int fd, int argc, char **argv)
static int load_module (void)
static int realtime_exec (struct ast_channel *chan, void *data)
static int realtime_update_exec (struct ast_channel *chan, void *data)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, }
static char * app = "RealTime"
static const struct ast_module_infoast_module_info = &__mod_info
static struct ast_cli_entry cli_realtime []
static char cli_realtime_load_usage []
static char cli_realtime_update_usage []
static char * desc
static char * synopsis = "Realtime Data Lookup"
static char * uapp = "RealTimeUpdate"
static char * udesc
static char * USAGE = "RealTime(<family>|<colmatch>|<value>[|<prefix>])"
static char * usynopsis = "Realtime Data Rewrite"
static char * UUSAGE = "RealTimeUpdate(<family>|<colmatch>|<value>|<newcol>|<newval>)"


Detailed Description

RealTime App.

Author:
Anthony Minessale <anthmct@yahoo.com>

Mark Spencer <markster@digium.com>

Definition in file app_realtime.c.


Define Documentation

#define crop_data ( str   )     { *(str) = '\0' ; (str)++; }

Definition at line 50 of file app_realtime.c.

Referenced by realtime_exec(), and realtime_update_exec().

#define next_one ( var   )     var = var->next

Definition at line 49 of file app_realtime.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 263 of file app_realtime.c.

static void __unreg_module ( void   )  [static]

Definition at line 263 of file app_realtime.c.

static int cli_realtime_load ( int  fd,
int  argc,
char **  argv 
) [static]

Definition at line 72 of file app_realtime.c.

References ast_cli(), ast_load_realtime(), ast_variables_destroy(), RESULT_FAILURE, RESULT_SUCCESS, and var.

00073 {
00074    char *header_format = "%30s  %-30s\n";
00075    struct ast_variable *var = NULL, *save = NULL;
00076 
00077    if (argc < 5) {
00078       ast_cli(fd, "You must supply a family name, a column to match on, and a value to match to.\n");
00079       return RESULT_FAILURE;
00080    }
00081 
00082    var = ast_load_realtime(argv[2], argv[3], argv[4], NULL);
00083 
00084    if (var) {
00085       save = var;
00086       ast_cli(fd, header_format, "Column Name", "Column Value");
00087       ast_cli(fd, header_format, "--------------------", "--------------------");
00088       while (var) {
00089          ast_cli(fd, header_format, var->name, var->value);
00090          var = var->next;
00091       }
00092       ast_variables_destroy(save);
00093    } else {
00094       ast_cli(fd, "No rows found matching search criteria.\n");
00095    }
00096    return RESULT_SUCCESS;
00097 }

static int cli_realtime_update ( int  fd,
int  argc,
char **  argv 
) [static]

Definition at line 99 of file app_realtime.c.

References ast_cli(), ast_update_realtime(), RESULT_FAILURE, and RESULT_SUCCESS.

00099                                                               {
00100    int res = 0;
00101 
00102    if(argc<7) {
00103       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");
00104       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");
00105       return RESULT_FAILURE;
00106    }
00107 
00108    res = ast_update_realtime(argv[2], argv[3], argv[4], argv[5], argv[6], NULL);
00109 
00110    if(res < 0) {
00111       ast_cli(fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
00112       return RESULT_SUCCESS;
00113    }
00114 
00115        ast_cli(fd, "Updated %d RealTime record%s.\n", res, (res != 1) ? "s" : "");
00116 
00117    return RESULT_SUCCESS;
00118 }

static int load_module ( void   )  [static]

Definition at line 252 of file app_realtime.c.

References ast_cli_register_multiple(), ast_register_application(), cli_realtime, realtime_exec(), and realtime_update_exec().

00253 {
00254    int res;
00255 
00256    ast_cli_register_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
00257    res = ast_register_application(uapp, realtime_update_exec, usynopsis, udesc);
00258    res |= ast_register_application(app, realtime_exec, synopsis, desc);
00259 
00260    return res;
00261 }

static int realtime_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 182 of file app_realtime.c.

References ast_load_realtime(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_strdupa, ast_strlen_zero(), ast_variables_destroy(), ast_verbose(), crop_data, len(), LOG_ERROR, LOG_WARNING, ast_variable::name, ast_variable::next, option_verbose, pbx_builtin_setvar_helper(), prefix, ast_variable::value, var, and VERBOSE_PREFIX_4.

Referenced by load_module().

00183 {
00184    int res=0, count=0;
00185    struct ast_module_user *u;
00186    struct ast_variable *var, *itt;
00187    char *family=NULL, *colmatch=NULL, *value=NULL, *prefix=NULL, *vname=NULL;
00188    char countc[13];
00189    size_t len;
00190       
00191         ast_log(LOG_WARNING, "The RealTime application has been deprecated in favor of the REALTIME dialplan function.\n");
00192 
00193    if (ast_strlen_zero(data)) {
00194       ast_log(LOG_ERROR,"Invalid input: usage %s\n",USAGE);
00195       return -1;
00196    }
00197    
00198    u = ast_module_user_add(chan);
00199 
00200    family = ast_strdupa(data);
00201    if ((colmatch = strchr(family,'|'))) {
00202       crop_data(colmatch);
00203       if ((value = strchr(colmatch,'|'))) {
00204          crop_data(value);
00205          if ((prefix = strchr(value,'|')))
00206             crop_data(prefix);
00207       }
00208    }
00209    if (! (family && value && colmatch) ) {
00210       ast_log(LOG_ERROR,"Invalid input: usage %s\n",USAGE);
00211       res = -1;
00212    } else {
00213       if (option_verbose > 3)
00214          ast_verbose(VERBOSE_PREFIX_4"Realtime Lookup: family:'%s' colmatch:'%s' value:'%s'\n",family,colmatch,value);
00215       if ((var = ast_load_realtime(family, colmatch, value, NULL))) {
00216          for (itt = var; itt; itt = itt->next) {
00217             if(prefix) {
00218                len = strlen(prefix) + strlen(itt->name) + 2;
00219                vname = alloca(len);
00220                snprintf(vname,len,"%s%s",prefix,itt->name);
00221                
00222             } else 
00223                vname = itt->name;
00224 
00225             pbx_builtin_setvar_helper(chan, vname, itt->value);
00226             count++;
00227          }
00228          ast_variables_destroy(var);
00229       } else if (option_verbose > 3)
00230          ast_verbose(VERBOSE_PREFIX_4"No Realtime Matches Found.\n");
00231    }
00232    snprintf(countc, sizeof(countc), "%d", count);
00233    pbx_builtin_setvar_helper(chan, "REALTIMECOUNT", countc);
00234    
00235    ast_module_user_remove(u);
00236    return res;
00237 }

static int realtime_update_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 138 of file app_realtime.c.

References ast_log(), ast_module_user_add, ast_module_user_remove, ast_strdupa, ast_strlen_zero(), ast_update_realtime(), ast_module_user::chan, crop_data, LOG_ERROR, LOG_WARNING, and pbx_builtin_setvar_helper().

Referenced by load_module().

00139 {
00140    char *family=NULL, *colmatch=NULL, *value=NULL, *newcol=NULL, *newval=NULL;
00141    struct ast_module_user *u;
00142    int res = 0, count = 0;
00143    char countc[13];
00144 
00145         ast_log(LOG_WARNING, "The RealTimeUpdate application has been deprecated in favor of the REALTIME dialplan function.\n");
00146 
00147    if (ast_strlen_zero(data)) {
00148       ast_log(LOG_ERROR,"Invalid input: usage %s\n",UUSAGE);
00149       return -1;
00150    }
00151    
00152    u = ast_module_user_add(chan);
00153 
00154    family = ast_strdupa(data);
00155    if ((colmatch = strchr(family,'|'))) {
00156       crop_data(colmatch);
00157       if ((value = strchr(colmatch,'|'))) {
00158          crop_data(value);
00159          if ((newcol = strchr(value,'|'))) {
00160             crop_data(newcol);
00161             if ((newval = strchr(newcol,'|'))) 
00162                crop_data(newval);
00163          }
00164       }
00165    }
00166    if (! (family && value && colmatch && newcol && newval) ) {
00167       ast_log(LOG_ERROR,"Invalid input: usage %s\n",UUSAGE);
00168       res = -1;
00169    } else {
00170       count = ast_update_realtime(family,colmatch,value,newcol,newval,NULL);
00171    }
00172 
00173    snprintf(countc, sizeof(countc), "%d", count);
00174    pbx_builtin_setvar_helper(chan, "REALTIMECOUNT", countc);
00175 
00176    ast_module_user_remove(u);
00177    
00178    return res;
00179 }

static int unload_module ( void   )  [static]

Definition at line 239 of file app_realtime.c.

References ast_cli_unregister_multiple(), ast_module_user_hangup_all, ast_unregister_application(), and cli_realtime.

00240 {
00241    int res;
00242 
00243    ast_cli_unregister_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
00244    res = ast_unregister_application(uapp);
00245    res |= ast_unregister_application(app);
00246 
00247    ast_module_user_hangup_all();
00248 
00249    return res;
00250 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static]

Definition at line 263 of file app_realtime.c.

char* app = "RealTime" [static]

Definition at line 52 of file app_realtime.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 263 of file app_realtime.c.

struct ast_cli_entry cli_realtime[] [static]

Definition at line 128 of file app_realtime.c.

Referenced by load_module(), and unload_module().

char cli_realtime_load_usage[] [static]

Initial value:

"Usage: realtime load <family> <colmatch> <value>\n"
"       Prints out a list of variables using the RealTime driver.\n"

Definition at line 120 of file app_realtime.c.

char cli_realtime_update_usage[] [static]

Initial value:

"Usage: realtime update <family> <colmatch> <value>\n"
"       Update a single variable using the RealTime driver.\n"

Definition at line 124 of file app_realtime.c.

char* desc [static]

Definition at line 58 of file app_realtime.c.

char* synopsis = "Realtime Data Lookup" [static]

Definition at line 54 of file app_realtime.c.

char* uapp = "RealTimeUpdate" [static]

Definition at line 53 of file app_realtime.c.

char* udesc [static]

Initial value:

 "Use the RealTime config handler system to update a value\n"
"RealTimeUpdate(<family>|<colmatch>|<value>|<newcol>|<newval>)\n\n"
"The column <newcol> in 'family' matching column <colmatch>=<value> will be\n"
"updated to <newval>.  REALTIMECOUNT will be set with the number of rows\n"
"updated or -1 if an error occurs.\n"

Definition at line 65 of file app_realtime.c.

char* USAGE = "RealTime(<family>|<colmatch>|<value>[|<prefix>])" [static]

Definition at line 56 of file app_realtime.c.

char* usynopsis = "Realtime Data Rewrite" [static]

Definition at line 55 of file app_realtime.c.

char* UUSAGE = "RealTimeUpdate(<family>|<colmatch>|<value>|<newcol>|<newval>)" [static]

Definition at line 57 of file app_realtime.c.


Generated on Sat Aug 6 00:39:36 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7