#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 |
Definition in 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 93 of file func_logic.c.
References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, ast_strlen_zero(), LOG_WARNING, pbx_checkcondition(), and S_OR.
00095 { 00096 AST_DECLARE_APP_ARGS(args1, 00097 AST_APP_ARG(expr); 00098 AST_APP_ARG(remainder); 00099 ); 00100 AST_DECLARE_APP_ARGS(args2, 00101 AST_APP_ARG(iftrue); 00102 AST_APP_ARG(iffalse); 00103 ); 00104 args2.iftrue = args2.iffalse = NULL; /* you have to set these, because if there is nothing after the '?', 00105 then args1.remainder will be NULL, not a pointer to a null string, and 00106 then any garbage in args2.iffalse will not be cleared, and you'll crash. 00107 -- and if you mod the ast_app_separate_args func instead, you'll really 00108 mess things up badly, because the rest of everything depends on null args 00109 for non-specified stuff. */ 00110 00111 AST_NONSTANDARD_APP_ARGS(args1, data, '?'); 00112 AST_NONSTANDARD_APP_ARGS(args2, args1.remainder, ':'); 00113 00114 if (ast_strlen_zero(args1.expr) || !(args2.iftrue || args2.iffalse)) { 00115 ast_log(LOG_WARNING, "Syntax IF(<expr>?[<true>][:<false>]) (expr must be non-null, and either <true> or <false> must be non-null)\n"); 00116 ast_log(LOG_WARNING, " In this case, <expr>='%s', <true>='%s', and <false>='%s'\n", args1.expr, args2.iftrue, args2.iffalse); 00117 return -1; 00118 } 00119 00120 args1.expr = ast_strip(args1.expr); 00121 if (args2.iftrue) 00122 args2.iftrue = ast_strip(args2.iftrue); 00123 if (args2.iffalse) 00124 args2.iffalse = ast_strip(args2.iffalse); 00125 00126 ast_copy_string(buf, pbx_checkcondition(args1.expr) ? (S_OR(args2.iftrue, "")) : (S_OR(args2.iffalse, "")), len); 00127 00128 return 0; 00129 }
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] |
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] |
static int load_module | ( | void | ) | [static] |
Definition at line 203 of file func_logic.c.
References ast_custom_function_register(), exists_function, if_function, if_time_function, isnull_function, and set_function.
00204 { 00205 int res = 0; 00206 00207 res |= ast_custom_function_register(&isnull_function); 00208 res |= ast_custom_function_register(&set_function); 00209 res |= ast_custom_function_register(&exists_function); 00210 res |= ast_custom_function_register(&if_function); 00211 res |= ast_custom_function_register(&if_time_function); 00212 00213 return res; 00214 }
static int set | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 131 of file func_logic.c.
References ast_log(), ast_strlen_zero(), LOG_WARNING, pbx_builtin_setvar_helper(), and strsep().
00133 { 00134 char *varname; 00135 char *val; 00136 00137 varname = strsep(&data, "="); 00138 val = data; 00139 00140 if (ast_strlen_zero(varname) || !val) { 00141 ast_log(LOG_WARNING, "Syntax SET(<varname>=[<value>])\n"); 00142 return -1; 00143 } 00144 00145 varname = ast_strip(varname); 00146 val = ast_strip(val); 00147 pbx_builtin_setvar_helper(chan, varname, val); 00148 ast_copy_string(buf, val, len); 00149 00150 return 0; 00151 }
static int unload_module | ( | void | ) | [static] |
Definition at line 190 of file func_logic.c.
References ast_custom_function_unregister(), exists_function, if_function, if_time_function, isnull_function, and set_function.
00191 { 00192 int res = 0; 00193 00194 res |= ast_custom_function_unregister(&isnull_function); 00195 res |= ast_custom_function_unregister(&set_function); 00196 res |= ast_custom_function_unregister(&exists_function); 00197 res |= ast_custom_function_unregister(&if_function); 00198 res |= ast_custom_function_unregister(&if_time_function); 00199 00200 return res; 00201 }
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 [static] |