Tue Nov 4 13:20:38 2008

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"

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

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_autoservice_start(), ast_autoservice_stop(), 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(), ast_module_user::chan, LOG_WARNING, 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    if (chan)
00078       ast_autoservice_start(chan);
00079 
00080    head = ast_load_realtime(args.family, args.fieldmatch, args.value, NULL);
00081 
00082    if (!head) {
00083       ast_module_user_remove(u);
00084       if (chan)
00085          ast_autoservice_stop(chan);
00086       return -1;
00087    }
00088    for (var = head; var; var = var->next)
00089       resultslen += strlen(var->name) + strlen(var->value) + strlen(args.delim1) + strlen(args.delim2);
00090 
00091    result_begin = results = alloca(resultslen);
00092    for (var = head; var; var = var->next)
00093       ast_build_string(&results, &resultslen, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1);
00094    ast_copy_string(buf, result_begin, len);
00095 
00096    ast_module_user_remove(u);
00097 
00098    if (chan)
00099       ast_autoservice_stop(chan);
00100 
00101    return 0;
00102 }

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

Definition at line 104 of file func_realtime.c.

References AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), AST_DECLARE_APP_ARGS, ast_log(), ast_module_user_add, ast_module_user_remove, AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_update_realtime(), ast_module_user::chan, and LOG_WARNING.

00105 {
00106         struct ast_module_user *u = NULL;
00107    int res = 0;
00108    AST_DECLARE_APP_ARGS(args,
00109       AST_APP_ARG(family);
00110       AST_APP_ARG(fieldmatch);
00111       AST_APP_ARG(value);
00112       AST_APP_ARG(field);
00113    );
00114 
00115    if (ast_strlen_zero(data)) {
00116       ast_log(LOG_WARNING, "Syntax: REALTIME(family|fieldmatch|value|newcol) - missing argument!\n");
00117       return -1;
00118    }
00119 
00120    if (chan) {
00121       ast_autoservice_start(chan);
00122       u = ast_module_user_add(chan);
00123    }
00124 
00125    AST_STANDARD_APP_ARGS(args, data);
00126 
00127    res = ast_update_realtime(args.family, args.fieldmatch, args.value, args.field, (char *)value, NULL);
00128 
00129    if (res < 0) {
00130       ast_log(LOG_WARNING, "Failed to update. Check the debug log for possible data repository related entries.\n");
00131    }
00132 
00133    if (chan) {
00134       ast_module_user_remove(u);
00135       ast_autoservice_stop(chan);
00136    }
00137 
00138    return 0;
00139 }

static int load_module ( void   )  [static]

Definition at line 168 of file func_realtime.c.

References ast_custom_function_register(), and realtime_function.

00169 {
00170         int res = ast_custom_function_register(&realtime_function);
00171 
00172         return res;
00173 }

static int unload_module ( void   )  [static]

Definition at line 159 of file func_realtime.c.

References ast_custom_function_unregister(), ast_module_user_hangup_all, and realtime_function.

00160 {
00161         int res = ast_custom_function_unregister(&realtime_function);
00162 
00163    ast_module_user_hangup_all();
00164 
00165         return res;
00166 }


Variable Documentation

struct ast_custom_function realtime_function

Definition at line 141 of file func_realtime.c.

Referenced by load_module(), and unload_module().


Generated on Tue Nov 4 13:20:38 2008 for Asterisk - the Open Source PBX by  doxygen 1.4.7