Fri Sep 29 11:14:14 2006

Asterisk developer's documentation


func_logic.c File Reference

Conditional logic dialplan functions. More...

#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "asterisk.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/config.h"

Include dependency graph for func_logic.c:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static char * builtin_function_exists (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static char * builtin_function_if (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static char * builtin_function_iftime (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static char * builtin_function_isnull (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static char * builtin_function_set (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)

Variables

static struct ast_custom_function exists_function
static struct ast_custom_function if_function
static struct ast_custom_function if_time_function
static struct ast_custom_function isnull_function
static struct ast_custom_function set_function


Detailed Description

Conditional logic dialplan functions.

Definition in file func_logic.c.


Function Documentation

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

Definition at line 44 of file func_logic.c.

00045 {
00046    return data && *data ? "1" : "0";
00047 }

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

Definition at line 90 of file func_logic.c.

References ast_log(), ast_strdupa, ast_strip_quoted(), ast_strlen_zero(), LOG_WARNING, pbx_checkcondition(), and strsep().

00091 {
00092    char *ret;
00093    char *expr;
00094    char *iftrue;
00095    char *iffalse;
00096 
00097    if (!(data = ast_strdupa(data))) {
00098       ast_log(LOG_WARNING, "Memory Error!\n");
00099       return NULL;
00100    }
00101 
00102    data = ast_strip_quoted(data, "\"", "\"");
00103    expr = strsep(&data, "?");
00104    iftrue = strsep(&data, ":");
00105    iffalse = data;
00106 
00107    if (ast_strlen_zero(expr) || !(iftrue || iffalse)) {
00108       ast_log(LOG_WARNING, "Syntax IF(<expr>?[<true>][:<false>])\n");
00109       return NULL;
00110    }
00111 
00112    expr = ast_strip(expr);
00113    if (iftrue)
00114       iftrue = ast_strip_quoted(iftrue, "\"", "\"");
00115    if (iffalse)
00116       iffalse = ast_strip_quoted(iffalse, "\"", "\"");
00117 
00118    if ((ret = pbx_checkcondition(expr) ? iftrue : iffalse)) {
00119       ast_copy_string(buf, ret, len);
00120       ret = buf;
00121    } 
00122    
00123    return ret;
00124 }

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

Definition at line 49 of file func_logic.c.

References ast_build_timing(), ast_check_timing(), ast_log(), ast_strdupa, ast_strip_quoted(), ast_strlen_zero(), LOG_WARNING, and strsep().

00050 {
00051    struct ast_timing timing;
00052    char *ret;
00053    char *expr;
00054    char *iftrue;
00055    char *iffalse;
00056 
00057    if (!(data = ast_strdupa(data))) {
00058       ast_log(LOG_WARNING, "Memory Error!\n");
00059       return NULL;
00060    }
00061 
00062    data = ast_strip_quoted(data, "\"", "\"");
00063    expr = strsep(&data, "?");
00064    iftrue = strsep(&data, ":");
00065    iffalse = data;
00066 
00067    if (ast_strlen_zero(expr) || !(iftrue || iffalse)) {
00068       ast_log(LOG_WARNING, "Syntax IFTIME(<timespec>?[<true>][:<false>])\n");
00069       return NULL;
00070    }
00071 
00072    if (!ast_build_timing(&timing, expr)) {
00073       ast_log(LOG_WARNING, "Invalid Time Spec.\n");
00074       return NULL;
00075    }
00076 
00077    if (iftrue)
00078       iftrue = ast_strip_quoted(iftrue, "\"", "\"");
00079    if (iffalse)
00080       iffalse = ast_strip_quoted(iffalse, "\"", "\"");
00081 
00082    if ((ret = ast_check_timing(&timing) ? iftrue : iffalse)) {
00083       ast_copy_string(buf, ret, len);
00084       ret = buf;
00085    } 
00086    
00087    return ret;
00088 }

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

Definition at line 39 of file func_logic.c.

00040 {
00041    return data && *data ? "0" : "1";
00042 }

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

Definition at line 126 of file func_logic.c.

References ast_log(), ast_strdupa, ast_strlen_zero(), LOG_WARNING, pbx_builtin_setvar_helper(), and strsep().

00127 {
00128    char *varname;
00129    char *val;
00130 
00131    if (!(data = ast_strdupa(data))) {
00132       ast_log(LOG_WARNING, "Memory Error!\n");
00133       return NULL;
00134    }
00135 
00136    varname = strsep(&data, "=");
00137    val = data;
00138 
00139    if (ast_strlen_zero(varname) || !val) {
00140       ast_log(LOG_WARNING, "Syntax SET(<varname>=[<value>])\n");
00141       return NULL;
00142    }
00143 
00144    varname = ast_strip(varname);
00145    val = ast_strip(val);
00146    pbx_builtin_setvar_helper(chan, varname, val);
00147    ast_copy_string(buf, val, len);
00148 
00149    return buf;
00150 }


Variable Documentation

struct ast_custom_function exists_function [static]

Definition at line 175 of file func_logic.c.

struct ast_custom_function if_function [static]

Definition at line 185 of file func_logic.c.

struct ast_custom_function if_time_function [static]

Definition at line 196 of file func_logic.c.

struct ast_custom_function isnull_function [static]

Definition at line 155 of file func_logic.c.

struct ast_custom_function set_function [static]

Definition at line 165 of file func_logic.c.


Generated on Fri Sep 29 11:14:14 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.7