Sat Aug 6 00:39:56 2011

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"

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int acf_if (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
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_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Logical dialplan functions" , .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 const struct ast_module_infoast_module_info = &__mod_info
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 void __reg_module ( void   )  [static]

Definition at line 214 of file func_logic.c.

static void __unreg_module ( void   )  [static]

Definition at line 214 of file func_logic.c.

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

Definition at line 91 of file func_logic.c.

References AST_APP_ARG, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, ast_strip(), ast_strlen_zero(), LOG_WARNING, pbx_checkcondition(), and S_OR.

00093 {
00094    AST_DECLARE_APP_ARGS(args1,
00095       AST_APP_ARG(expr);
00096       AST_APP_ARG(remainder);
00097    );
00098    AST_DECLARE_APP_ARGS(args2,
00099       AST_APP_ARG(iftrue);
00100       AST_APP_ARG(iffalse);
00101    );
00102    args2.iftrue = args2.iffalse = NULL; /* you have to set these, because if there is nothing after the '?',
00103                                  then args1.remainder will be NULL, not a pointer to a null string, and
00104                                  then any garbage in args2.iffalse will not be cleared, and you'll crash.
00105                                   -- and if you mod the ast_app_separate_args func instead, you'll really
00106                                  mess things up badly, because the rest of everything depends on null args
00107                                  for non-specified stuff. */
00108    
00109    AST_NONSTANDARD_APP_ARGS(args1, data, '?');
00110    AST_NONSTANDARD_APP_ARGS(args2, args1.remainder, ':');
00111 
00112    if (ast_strlen_zero(args1.expr) || !(args2.iftrue || args2.iffalse)) {
00113       ast_log(LOG_WARNING, "Syntax IF(<expr>?[<true>][:<false>])  (expr must be non-null, and either <true> or <false> must be non-null)\n");
00114       ast_log(LOG_WARNING, "      In this case, <expr>='%s', <true>='%s', and <false>='%s'\n", args1.expr, args2.iftrue, args2.iffalse);
00115       return -1;
00116    }
00117 
00118    args1.expr = ast_strip(args1.expr);
00119    if (args2.iftrue)
00120       args2.iftrue = ast_strip(args2.iftrue);
00121    if (args2.iffalse)
00122       args2.iffalse = ast_strip(args2.iffalse);
00123 
00124    ast_copy_string(buf, pbx_checkcondition(args1.expr) ? (S_OR(args2.iftrue, "")) : (S_OR(args2.iffalse, "")), len);
00125 
00126    return 0;
00127 }

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

Definition at line 49 of file func_logic.c.

Referenced by socket_process().

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

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

Definition at line 57 of file func_logic.c.

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

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

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

Definition at line 41 of file func_logic.c.

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

static int load_module ( void   )  [static]

Definition at line 201 of file func_logic.c.

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

00202 {
00203    int res = 0;
00204 
00205    res |= ast_custom_function_register(&isnull_function);
00206    res |= ast_custom_function_register(&set_function);
00207    res |= ast_custom_function_register(&exists_function);
00208    res |= ast_custom_function_register(&if_function);
00209    res |= ast_custom_function_register(&if_time_function);
00210 
00211    return res;
00212 }

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

Definition at line 129 of file func_logic.c.

References ast_copy_string(), ast_log(), ast_strip(), ast_strlen_zero(), LOG_WARNING, and pbx_builtin_setvar_helper().

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

static int unload_module ( void   )  [static]

Definition at line 188 of file func_logic.c.

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

00189 {
00190    int res = 0;
00191 
00192    res |= ast_custom_function_unregister(&isnull_function);
00193    res |= ast_custom_function_unregister(&set_function);
00194    res |= ast_custom_function_unregister(&exists_function);
00195    res |= ast_custom_function_unregister(&if_function);
00196    res |= ast_custom_function_unregister(&if_time_function);
00197 
00198    return res;
00199 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Logical dialplan functions" , .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 214 of file func_logic.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 214 of file func_logic.c.

struct ast_custom_function exists_function [static]

Definition at line 165 of file func_logic.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function if_function [static]

Definition at line 172 of file func_logic.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function if_time_function [static]

Definition at line 180 of file func_logic.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function isnull_function [static]

Definition at line 151 of file func_logic.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function set_function [static]

Definition at line 158 of file func_logic.c.

Referenced by load_module(), and unload_module().


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