Mon May 14 04:48:15 2007

Asterisk developer's documentation


func_logic.c File Reference

Conditional logic dialplan functions. More...

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

Include dependency graph for func_logic.c:

Go to the source code of this file.

Functions

static int acf_if (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Logical dialplan functions")
static int exists (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static int iftime (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static int isnull (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static int load_module (void)
static int set (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static int unload_module (void)

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.

Author:
Anthony Minessale II

Definition in file func_logic.c.


Function Documentation

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

Definition at line 93 of file func_logic.c.

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

00095 {
00096    char *expr;
00097    char *iftrue;
00098    char *iffalse;
00099 
00100    data = ast_strip_quoted(data, "\"", "\"");
00101    expr = strsep(&data, "?");
00102    iftrue = strsep(&data, ":");
00103    iffalse = data;
00104 
00105    if (ast_strlen_zero(expr) || !(iftrue || iffalse)) {
00106       ast_log(LOG_WARNING, "Syntax IF(<expr>?[<true>][:<false>])\n");
00107       return -1;
00108    }
00109 
00110    expr = ast_strip(expr);
00111    if (iftrue)
00112       iftrue = ast_strip_quoted(iftrue, "\"", "\"");
00113    if (iffalse)
00114       iffalse = ast_strip_quoted(iffalse, "\"", "\"");
00115 
00116    ast_copy_string(buf, pbx_checkcondition(expr) ? (S_OR(iftrue, "")) : (S_OR(iffalse, "")), len);
00117 
00118    return 0;
00119 }

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Logical dialplan functions"   
)

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

Definition at line 51 of file func_logic.c.

Referenced by socket_process().

00053 {
00054    strcpy(buf, data && *data ? "1" : "0");
00055 
00056    return 0;
00057 }

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

Definition at line 59 of file func_logic.c.

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

00061 {
00062    struct ast_timing timing;
00063    char *expr;
00064    char *iftrue;
00065    char *iffalse;
00066 
00067    data = ast_strip_quoted(data, "\"", "\"");
00068    expr = strsep(&data, "?");
00069    iftrue = strsep(&data, ":");
00070    iffalse = data;
00071 
00072    if (ast_strlen_zero(expr) || !(iftrue || iffalse)) {
00073       ast_log(LOG_WARNING,
00074             "Syntax IFTIME(<timespec>?[<true>][:<false>])\n");
00075       return -1;
00076    }
00077 
00078    if (!ast_build_timing(&timing, expr)) {
00079       ast_log(LOG_WARNING, "Invalid Time Spec.\n");
00080       return -1;
00081    }
00082 
00083    if (iftrue)
00084       iftrue = ast_strip_quoted(iftrue, "\"", "\"");
00085    if (iffalse)
00086       iffalse = ast_strip_quoted(iffalse, "\"", "\"");
00087 
00088    ast_copy_string(buf, ast_check_timing(&timing) ? iftrue : iffalse, len);
00089 
00090    return 0;
00091 }

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

Definition at line 43 of file func_logic.c.

00045 {
00046    strcpy(buf, data && *data ? "0" : "1");
00047 
00048    return 0;
00049 }

static int load_module ( void   )  [static]

Definition at line 193 of file func_logic.c.

References ast_custom_function_register(), exists_function, if_function, if_time_function, isnull_function, and set_function.

00194 {
00195    int res = 0;
00196 
00197    res |= ast_custom_function_register(&isnull_function);
00198    res |= ast_custom_function_register(&set_function);
00199    res |= ast_custom_function_register(&exists_function);
00200    res |= ast_custom_function_register(&if_function);
00201    res |= ast_custom_function_register(&if_time_function);
00202 
00203    return res;
00204 }

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

Definition at line 121 of file func_logic.c.

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

00123 {
00124    char *varname;
00125    char *val;
00126 
00127    varname = strsep(&data, "=");
00128    val = data;
00129 
00130    if (ast_strlen_zero(varname) || !val) {
00131       ast_log(LOG_WARNING, "Syntax SET(<varname>=[<value>])\n");
00132       return -1;
00133    }
00134 
00135    varname = ast_strip(varname);
00136    val = ast_strip(val);
00137    pbx_builtin_setvar_helper(chan, varname, val);
00138    ast_copy_string(buf, val, len);
00139 
00140    return 0;
00141 }

static int unload_module ( void   )  [static]

Definition at line 180 of file func_logic.c.

References ast_custom_function_unregister(), exists_function, if_function, if_time_function, isnull_function, and set_function.

00181 {
00182    int res = 0;
00183 
00184    res |= ast_custom_function_unregister(&isnull_function);
00185    res |= ast_custom_function_unregister(&set_function);
00186    res |= ast_custom_function_unregister(&exists_function);
00187    res |= ast_custom_function_unregister(&if_function);
00188    res |= ast_custom_function_unregister(&if_time_function);
00189 
00190    return res;
00191 }


Variable Documentation

struct ast_custom_function exists_function [static]

Definition at line 157 of file func_logic.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function if_function [static]

Definition at line 164 of file func_logic.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function if_time_function [static]

Definition at line 172 of file func_logic.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function isnull_function [static]

Definition at line 143 of file func_logic.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function set_function [static]

Definition at line 150 of file func_logic.c.

Referenced by load_module(), and unload_module().


Generated on Mon May 14 04:48:16 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1