Wed Aug 15 01:25:14 2007

Asterisk developer's documentation


func_realtime.c File Reference

REALTIME dialplan function. More...

#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/options.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"

Include dependency graph for func_realtime.c:

Go to the source code of this file.

Functions

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Read/Write values from a RealTime repository")
static int function_realtime_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static int function_realtime_write (struct ast_channel *chan, char *cmd, char *data, const char *value)
static int load_module (void)
static int unload_module (void)

Variables

struct
ast_custom_function 
realtime_function


Detailed Description

REALTIME dialplan function.

Author:
BJ Weschke <bweschke@btwtech.com>

Definition in file func_realtime.c.


Function Documentation

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Read/Write values from a RealTime repository"   
)

static int function_realtime_read ( struct ast_channel chan,
char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 48 of file func_realtime.c.

References AST_APP_ARG, ast_build_string(), AST_DECLARE_APP_ARGS, ast_load_realtime(), ast_log(), ast_module_user_add, ast_module_user_remove, AST_STANDARD_APP_ARGS, ast_strlen_zero(), LOG_WARNING, ast_variable::name, ast_variable::next, ast_variable::value, and var.

00049 {
00050    struct ast_variable *var, *head;
00051         struct ast_module_user *u;
00052    char *results, *result_begin;
00053    size_t resultslen = 0;
00054    AST_DECLARE_APP_ARGS(args,
00055       AST_APP_ARG(family);
00056       AST_APP_ARG(fieldmatch);
00057       AST_APP_ARG(value);
00058       AST_APP_ARG(delim1);
00059       AST_APP_ARG(delim2);
00060    );
00061 
00062 
00063    if (ast_strlen_zero(data)) {
00064       ast_log(LOG_WARNING, "Syntax: REALTIME(family|fieldmatch[|value[|delim1[|delim2]]]) - missing argument!\n");
00065       return -1;
00066    }
00067 
00068    u = ast_module_user_add(chan);
00069 
00070    AST_STANDARD_APP_ARGS(args, data);
00071 
00072    if (!args.delim1)
00073       args.delim1 = "|";
00074    if (!args.delim2)
00075       args.delim2 = "=";
00076 
00077    head = ast_load_realtime(args.family, args.fieldmatch, args.value, NULL);
00078 
00079    if (!head) {
00080       ast_module_user_remove(u);
00081       return -1;
00082    }
00083    for (var = head; var; var = var->next)
00084       resultslen += strlen(var->name) + strlen(var->value) + 2;
00085 
00086    result_begin = results = alloca(resultslen);
00087    for (var = head; var; var = var->next)
00088       ast_build_string(&results, &resultslen, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1);
00089    ast_copy_string(buf, result_begin, len);
00090 
00091    ast_module_user_remove(u);
00092 
00093    return 0;
00094 }

static int function_realtime_write ( struct ast_channel chan,
char *  cmd,
char *  data,
const char *  value 
) [static]

Definition at line 96 of file func_realtime.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), ast_module_user_add, ast_module_user_remove, AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_update_realtime(), and LOG_WARNING.

00097 {
00098         struct ast_module_user *u;
00099    int res = 0;
00100    AST_DECLARE_APP_ARGS(args,
00101       AST_APP_ARG(family);
00102       AST_APP_ARG(fieldmatch);
00103       AST_APP_ARG(value);
00104       AST_APP_ARG(field);
00105    );
00106 
00107    if (ast_strlen_zero(data)) {
00108       ast_log(LOG_WARNING, "Syntax: REALTIME(family|fieldmatch|value|newcol) - missing argument!\n");
00109       return -1;
00110    }
00111 
00112    u = ast_module_user_add(chan);
00113 
00114    AST_STANDARD_APP_ARGS(args, data);
00115 
00116    res = ast_update_realtime(args.family, args.fieldmatch, args.value, args.field, (char *)value, NULL);
00117 
00118    if (res < 0) {
00119       ast_log(LOG_WARNING, "Failed to update. Check the debug log for possible data repository related entries.\n");
00120    }
00121 
00122    ast_module_user_remove(u);
00123 
00124    return 0;
00125 }

static int load_module ( void   )  [static]

Definition at line 154 of file func_realtime.c.

References ast_custom_function_register().

00155 {
00156         int res = ast_custom_function_register(&realtime_function);
00157 
00158         return res;
00159 }

static int unload_module ( void   )  [static]

Definition at line 145 of file func_realtime.c.

References ast_custom_function_unregister(), and ast_module_user_hangup_all.

00146 {
00147         int res = ast_custom_function_unregister(&realtime_function);
00148 
00149    ast_module_user_hangup_all();
00150 
00151         return res;
00152 }


Variable Documentation

struct ast_custom_function realtime_function

Definition at line 127 of file func_realtime.c.


Generated on Wed Aug 15 01:25:14 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.3