2005-05-16 00:35:38 +00:00
|
|
|
%{
|
2006-01-03 22:16:23 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 - 2006, Digium, Inc.
|
|
|
|
*
|
|
|
|
* Mark Spencer <markster@digium.com>
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file
|
|
|
|
*
|
2006-04-24 17:41:27 +00:00
|
|
|
* \brief Dialplan Expression Lexical Scanner
|
2006-01-03 22:16:23 +00:00
|
|
|
*/
|
|
|
|
|
2007-07-02 21:50:15 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2008-09-27 15:52:56 +00:00
|
|
|
#if !defined(STANDALONE)
|
2006-06-07 18:54:56 +00:00
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
2007-07-02 21:50:15 +00:00
|
|
|
#else
|
|
|
|
#ifndef __USE_ISOC99
|
|
|
|
#define __USE_ISOC99 1
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __USE_ISOC99
|
In regards to changes for 9508, expr2 system choking on floating point numbers, I'm adding this update to round out (no pun intended) and make this FP-capable version of the Expr2 stuff interoperate better with previous integer-only usage, by providing Functions syntax, with 20 builtin functions for floating pt to integer conversions, and some general floating point math routines that might commonly be used also. Along with this, I made it so if a function was not a builtin, it will try and find it in the ast_custom_function list, and if found, execute it and collect the results. Thus, you can call system functions like CDR(), CHANNEL(), etc, from within $\[..\] exprs, without having to wrap them in $\{...\} (curly brace) notation. Did a valgrind on the standalone and made sure there's no mem leaks. Looks good. Updated the docs, too.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@73449 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-05 18:15:22 +00:00
|
|
|
#define FP___PRINTF "%.18Lg"
|
2007-07-02 21:50:15 +00:00
|
|
|
#define FP___FMOD fmodl
|
|
|
|
#define FP___STRTOD strtold
|
|
|
|
#define FP___TYPE long double
|
|
|
|
#else
|
In regards to changes for 9508, expr2 system choking on floating point numbers, I'm adding this update to round out (no pun intended) and make this FP-capable version of the Expr2 stuff interoperate better with previous integer-only usage, by providing Functions syntax, with 20 builtin functions for floating pt to integer conversions, and some general floating point math routines that might commonly be used also. Along with this, I made it so if a function was not a builtin, it will try and find it in the ast_custom_function list, and if found, execute it and collect the results. Thus, you can call system functions like CDR(), CHANNEL(), etc, from within $\[..\] exprs, without having to wrap them in $\{...\} (curly brace) notation. Did a valgrind on the standalone and made sure there's no mem leaks. Looks good. Updated the docs, too.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@73449 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-05 18:15:22 +00:00
|
|
|
#define FP___PRINTF "%.16g"
|
2007-07-02 21:50:15 +00:00
|
|
|
#define FP___FMOD fmod
|
|
|
|
#define FP___STRTOD strtod
|
|
|
|
#define FP___TYPE double
|
2006-06-20 01:06:50 +00:00
|
|
|
#endif
|
2006-06-07 18:54:56 +00:00
|
|
|
|
2005-05-16 00:35:38 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <ctype.h>
|
2005-11-01 21:53:30 +00:00
|
|
|
#if !defined(SOLARIS) && !defined(__CYGWIN__)
|
2006-12-28 17:56:21 +00:00
|
|
|
/* #include <err.h> */
|
2005-05-20 03:18:35 +00:00
|
|
|
#else
|
2005-08-29 20:17:25 +00:00
|
|
|
#define quad_t int64_t
|
2005-05-20 03:18:35 +00:00
|
|
|
#endif
|
2005-05-16 00:35:38 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <regex.h>
|
|
|
|
#include <limits.h>
|
2006-04-24 17:11:45 +00:00
|
|
|
|
|
|
|
#include "asterisk/ast_expr.h"
|
|
|
|
#include "asterisk/logger.h"
|
In regards to changes for 9508, expr2 system choking on floating point numbers, I'm adding this update to round out (no pun intended) and make this FP-capable version of the Expr2 stuff interoperate better with previous integer-only usage, by providing Functions syntax, with 20 builtin functions for floating pt to integer conversions, and some general floating point math routines that might commonly be used also. Along with this, I made it so if a function was not a builtin, it will try and find it in the ast_custom_function list, and if found, execute it and collect the results. Thus, you can call system functions like CDR(), CHANNEL(), etc, from within $\[..\] exprs, without having to wrap them in $\{...\} (curly brace) notation. Did a valgrind on the standalone and made sure there's no mem leaks. Looks good. Updated the docs, too.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@73449 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-05 18:15:22 +00:00
|
|
|
#ifndef STANDALONE
|
2006-04-24 17:11:45 +00:00
|
|
|
#include "asterisk/strings.h"
|
In regards to changes for 9508, expr2 system choking on floating point numbers, I'm adding this update to round out (no pun intended) and make this FP-capable version of the Expr2 stuff interoperate better with previous integer-only usage, by providing Functions syntax, with 20 builtin functions for floating pt to integer conversions, and some general floating point math routines that might commonly be used also. Along with this, I made it so if a function was not a builtin, it will try and find it in the ast_custom_function list, and if found, execute it and collect the results. Thus, you can call system functions like CDR(), CHANNEL(), etc, from within $\[..\] exprs, without having to wrap them in $\{...\} (curly brace) notation. Did a valgrind on the standalone and made sure there's no mem leaks. Looks good. Updated the docs, too.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@73449 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-05 18:15:22 +00:00
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#endif
|
2005-05-16 00:35:38 +00:00
|
|
|
|
2011-03-07 01:01:08 +00:00
|
|
|
/* Conditionally redefine the macro from flex 2.5.35, in case someone uses flex <2.5.35 to regenerate this file. */
|
|
|
|
#ifndef ECHO
|
|
|
|
#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
|
2011-02-28 11:16:06 +00:00
|
|
|
#endif
|
2010-01-13 20:38:42 +00:00
|
|
|
|
2005-05-16 00:35:38 +00:00
|
|
|
enum valtype {
|
2007-07-02 21:50:15 +00:00
|
|
|
AST_EXPR_number, AST_EXPR_numeric_string, AST_EXPR_string
|
2005-05-16 00:35:38 +00:00
|
|
|
} ;
|
|
|
|
|
|
|
|
struct val {
|
|
|
|
enum valtype type;
|
|
|
|
union {
|
|
|
|
char *s;
|
2007-07-02 21:50:15 +00:00
|
|
|
FP___TYPE i; /* long double or just double if it's a bad day */
|
2005-05-16 00:35:38 +00:00
|
|
|
} u;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
#include "ast_expr2.h" /* the o/p of the bison on ast_expr2.y */
|
|
|
|
|
2006-04-28 16:39:25 +00:00
|
|
|
#define SET_COLUMNS do { \
|
|
|
|
yylloc_param->first_column = (int)(yyg->yytext_r - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf); \
|
|
|
|
yylloc_param->last_column += yyleng - 1; \
|
|
|
|
yylloc_param->first_line = yylloc_param->last_line = 1; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define SET_STRING do { \
|
|
|
|
yylval_param->val = calloc(1, sizeof(struct val)); \
|
|
|
|
yylval_param->val->type = AST_EXPR_string; \
|
|
|
|
yylval_param->val->u.s = strdup(yytext); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define SET_NUMERIC_STRING do { \
|
|
|
|
yylval_param->val = calloc(1, sizeof(struct val)); \
|
|
|
|
yylval_param->val->type = AST_EXPR_numeric_string; \
|
|
|
|
yylval_param->val->u.s = strdup(yytext); \
|
|
|
|
} while (0)
|
2005-05-16 00:35:38 +00:00
|
|
|
|
|
|
|
struct parse_io
|
|
|
|
{
|
|
|
|
char *string;
|
|
|
|
struct val *val;
|
|
|
|
yyscan_t scanner;
|
In regards to changes for 9508, expr2 system choking on floating point numbers, I'm adding this update to round out (no pun intended) and make this FP-capable version of the Expr2 stuff interoperate better with previous integer-only usage, by providing Functions syntax, with 20 builtin functions for floating pt to integer conversions, and some general floating point math routines that might commonly be used also. Along with this, I made it so if a function was not a builtin, it will try and find it in the ast_custom_function list, and if found, execute it and collect the results. Thus, you can call system functions like CDR(), CHANNEL(), etc, from within $\[..\] exprs, without having to wrap them in $\{...\} (curly brace) notation. Did a valgrind on the standalone and made sure there's no mem leaks. Looks good. Updated the docs, too.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@73449 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-05 18:15:22 +00:00
|
|
|
struct ast_channel *chan;
|
2005-05-16 00:35:38 +00:00
|
|
|
};
|
|
|
|
|
2005-08-29 22:03:37 +00:00
|
|
|
void ast_yyset_column(int column_no, yyscan_t yyscanner);
|
|
|
|
int ast_yyget_column(yyscan_t yyscanner);
|
2006-01-19 19:18:51 +00:00
|
|
|
static int curlycount = 0;
|
2007-09-21 14:40:10 +00:00
|
|
|
static char *expr2_token_subst(const char *mess);
|
2005-05-16 00:35:38 +00:00
|
|
|
%}
|
|
|
|
|
|
|
|
%option prefix="ast_yy"
|
|
|
|
%option batch
|
2007-11-28 20:33:21 +00:00
|
|
|
%option 8bit
|
2005-05-16 00:35:38 +00:00
|
|
|
%option outfile="ast_expr2f.c"
|
|
|
|
%option reentrant
|
|
|
|
%option bison-bridge
|
|
|
|
%option bison-locations
|
|
|
|
%option noyywrap
|
2008-01-10 20:45:05 +00:00
|
|
|
%option noyyfree
|
2006-01-19 19:18:51 +00:00
|
|
|
%x var trail
|
2005-05-16 00:35:38 +00:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
\| { SET_COLUMNS; SET_STRING; return TOK_OR;}
|
|
|
|
\& { SET_COLUMNS; SET_STRING; return TOK_AND;}
|
|
|
|
\= { SET_COLUMNS; SET_STRING; return TOK_EQ;}
|
2006-04-24 17:41:27 +00:00
|
|
|
\|\| { SET_COLUMNS; SET_STRING; return TOK_OR;}
|
|
|
|
\&\& { SET_COLUMNS; SET_STRING; return TOK_AND;}
|
|
|
|
\=\= { SET_COLUMNS; SET_STRING; return TOK_EQ;}
|
|
|
|
\=~ { SET_COLUMNS; SET_STRING; return TOK_EQTILDE;}
|
2008-04-21 21:13:02 +00:00
|
|
|
\~~ { SET_COLUMNS; SET_STRING; return TOK_TILDETILDE;}
|
2005-05-16 00:35:38 +00:00
|
|
|
\> { SET_COLUMNS; SET_STRING; return TOK_GT;}
|
|
|
|
\< { SET_COLUMNS; SET_STRING; return TOK_LT;}
|
|
|
|
\>\= { SET_COLUMNS; SET_STRING; return TOK_GE;}
|
|
|
|
\<\= { SET_COLUMNS; SET_STRING; return TOK_LE;}
|
|
|
|
\!\= { SET_COLUMNS; SET_STRING; return TOK_NE;}
|
|
|
|
\+ { SET_COLUMNS; SET_STRING; return TOK_PLUS;}
|
In regards to changes for 9508, expr2 system choking on floating point numbers, I'm adding this update to round out (no pun intended) and make this FP-capable version of the Expr2 stuff interoperate better with previous integer-only usage, by providing Functions syntax, with 20 builtin functions for floating pt to integer conversions, and some general floating point math routines that might commonly be used also. Along with this, I made it so if a function was not a builtin, it will try and find it in the ast_custom_function list, and if found, execute it and collect the results. Thus, you can call system functions like CDR(), CHANNEL(), etc, from within $\[..\] exprs, without having to wrap them in $\{...\} (curly brace) notation. Did a valgrind on the standalone and made sure there's no mem leaks. Looks good. Updated the docs, too.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@73449 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-05 18:15:22 +00:00
|
|
|
\, { SET_COLUMNS; SET_STRING; return TOK_COMMA;}
|
2005-05-16 00:35:38 +00:00
|
|
|
\- { SET_COLUMNS; SET_STRING; return TOK_MINUS;}
|
|
|
|
\* { SET_COLUMNS; SET_STRING; return TOK_MULT;}
|
|
|
|
\/ { SET_COLUMNS; SET_STRING; return TOK_DIV;}
|
|
|
|
\% { SET_COLUMNS; SET_STRING; return TOK_MOD;}
|
2005-06-24 02:51:47 +00:00
|
|
|
\? { SET_COLUMNS; SET_STRING; return TOK_COND;}
|
2006-04-24 17:41:27 +00:00
|
|
|
\! { SET_COLUMNS; SET_STRING; return TOK_COMPL;}
|
2005-05-16 00:35:38 +00:00
|
|
|
\: { SET_COLUMNS; SET_STRING; return TOK_COLON;}
|
2005-06-24 02:51:47 +00:00
|
|
|
\:\: { SET_COLUMNS; SET_STRING; return TOK_COLONCOLON;}
|
2005-05-16 00:35:38 +00:00
|
|
|
\( { SET_COLUMNS; SET_STRING; return TOK_LP;}
|
|
|
|
\) { SET_COLUMNS; SET_STRING; return TOK_RP;}
|
2006-04-28 16:39:25 +00:00
|
|
|
\$\{ {
|
|
|
|
/* gather the contents of ${} expressions, with trailing stuff,
|
|
|
|
* into a single TOKEN.
|
|
|
|
* They are much more complex now than they used to be
|
|
|
|
*/
|
|
|
|
curlycount = 0;
|
|
|
|
BEGIN(var);
|
|
|
|
yymore();
|
|
|
|
}
|
|
|
|
|
|
|
|
[ \t\r] {}
|
|
|
|
\"[^"]*\" {SET_COLUMNS; SET_STRING; return TOKEN;}
|
|
|
|
|
|
|
|
[\n] {/* what to do with eol */}
|
2007-07-02 21:50:15 +00:00
|
|
|
[0-9]+(\.[0-9]+)? {
|
2006-04-28 16:39:25 +00:00
|
|
|
SET_COLUMNS;
|
|
|
|
/* the original behavior of the expression parser was
|
|
|
|
* to bring in numbers as a numeric string
|
|
|
|
*/
|
|
|
|
SET_NUMERIC_STRING;
|
|
|
|
return TOKEN;
|
|
|
|
}
|
|
|
|
|
2009-03-03 22:12:02 +00:00
|
|
|
([a-zA-Z0-9\.';\\_^#@]|[\x80-\xff]|($[^{]))+ {
|
2006-04-28 16:39:25 +00:00
|
|
|
SET_COLUMNS;
|
|
|
|
SET_STRING;
|
|
|
|
return TOKEN;
|
|
|
|
}
|
|
|
|
|
2009-03-03 22:12:02 +00:00
|
|
|
([a-zA-Z0-9\.';\\_^#@]|[\x80-\xff]|($[^{]))+\$\{ {
|
|
|
|
curlycount = 0;
|
|
|
|
BEGIN(var);
|
|
|
|
yymore();
|
|
|
|
}
|
2006-04-28 16:39:25 +00:00
|
|
|
|
|
|
|
<var>[^{}]*\} {
|
|
|
|
curlycount--;
|
|
|
|
if (curlycount < 0) {
|
|
|
|
BEGIN(trail);
|
|
|
|
yymore();
|
|
|
|
} else {
|
|
|
|
yymore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
<var>[^{}]*\{ {
|
|
|
|
curlycount++;
|
|
|
|
yymore();
|
|
|
|
}
|
|
|
|
|
2006-01-19 19:18:51 +00:00
|
|
|
|
2006-04-28 16:39:25 +00:00
|
|
|
<trail>[^-\t\r \n$():?%/+=*<>!|&]* {
|
|
|
|
BEGIN(0);
|
|
|
|
SET_COLUMNS;
|
|
|
|
SET_STRING;
|
|
|
|
return TOKEN;
|
|
|
|
}
|
|
|
|
|
2009-03-03 22:12:02 +00:00
|
|
|
<trail>[^-\t\r \n$():?%/+=*<>!|&]*\$\{ {
|
|
|
|
curlycount = 0;
|
|
|
|
BEGIN(var);
|
|
|
|
yymore();
|
|
|
|
}
|
|
|
|
|
2006-04-28 16:39:25 +00:00
|
|
|
<trail>[-\t\r \n$():?%/+=*<>!|&] {
|
|
|
|
char c = yytext[yyleng-1];
|
|
|
|
BEGIN(0);
|
|
|
|
unput(c);
|
|
|
|
SET_COLUMNS;
|
|
|
|
SET_STRING;
|
|
|
|
return TOKEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
<trail><<EOF>> {
|
|
|
|
BEGIN(0);
|
|
|
|
SET_COLUMNS;
|
|
|
|
SET_STRING;
|
|
|
|
return TOKEN;
|
|
|
|
/*actually, if an expr is only a variable ref, this could happen a LOT */
|
|
|
|
}
|
2005-05-16 00:35:38 +00:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
/* I'm putting the interface routine to the whole parse here in the flexer input file
|
|
|
|
mainly because of all the flexer initialization that has to be done. Shouldn't matter
|
|
|
|
where it is, as long as it's somewhere. I didn't want to define a prototype for the
|
|
|
|
ast_yy_scan_string in the .y file, because then, I'd have to define YY_BUFFER_STATE there...
|
|
|
|
UGH! that would be inappropriate. */
|
|
|
|
|
2005-08-29 22:03:37 +00:00
|
|
|
int ast_yyparse(void *); /* need to/should define this prototype for the call to yyparse */
|
|
|
|
int ast_yyerror(const char *, YYLTYPE *, struct parse_io *); /* likewise */
|
2005-05-16 00:35:38 +00:00
|
|
|
|
2008-01-10 20:45:05 +00:00
|
|
|
void ast_yyfree(void *ptr, yyscan_t yyscanner)
|
|
|
|
{
|
2009-06-25 21:45:32 +00:00
|
|
|
/* the normal generated yyfree func just frees its first arg;
|
|
|
|
this get complaints on some systems, as sometimes this
|
|
|
|
arg is a nil ptr! It's usually not fatal, but is irritating! */
|
|
|
|
free( (char *) ptr );
|
2008-01-10 20:45:05 +00:00
|
|
|
}
|
|
|
|
|
In regards to changes for 9508, expr2 system choking on floating point numbers, I'm adding this update to round out (no pun intended) and make this FP-capable version of the Expr2 stuff interoperate better with previous integer-only usage, by providing Functions syntax, with 20 builtin functions for floating pt to integer conversions, and some general floating point math routines that might commonly be used also. Along with this, I made it so if a function was not a builtin, it will try and find it in the ast_custom_function list, and if found, execute it and collect the results. Thus, you can call system functions like CDR(), CHANNEL(), etc, from within $\[..\] exprs, without having to wrap them in $\{...\} (curly brace) notation. Did a valgrind on the standalone and made sure there's no mem leaks. Looks good. Updated the docs, too.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@73449 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-05 18:15:22 +00:00
|
|
|
int ast_expr(char *expr, char *buf, int length, struct ast_channel *chan)
|
2005-05-16 00:35:38 +00:00
|
|
|
{
|
2010-01-13 18:16:13 +00:00
|
|
|
struct parse_io io = { .string = expr, .chan = chan };
|
2006-01-03 16:39:37 +00:00
|
|
|
int return_value = 0;
|
2010-01-13 18:16:13 +00:00
|
|
|
|
2006-01-03 16:39:37 +00:00
|
|
|
ast_yylex_init(&io.scanner);
|
2010-01-13 18:16:13 +00:00
|
|
|
|
2006-01-03 16:39:37 +00:00
|
|
|
ast_yy_scan_string(expr, io.scanner);
|
2010-01-13 18:16:13 +00:00
|
|
|
|
2006-01-03 16:39:37 +00:00
|
|
|
ast_yyparse ((void *) &io);
|
2005-05-16 00:35:38 +00:00
|
|
|
|
2006-01-03 16:39:37 +00:00
|
|
|
ast_yylex_destroy(io.scanner);
|
2005-05-16 00:35:38 +00:00
|
|
|
|
2006-01-03 16:39:37 +00:00
|
|
|
if (!io.val) {
|
2005-08-29 22:03:37 +00:00
|
|
|
if (length > 1) {
|
|
|
|
strcpy(buf, "0");
|
2006-01-03 16:39:37 +00:00
|
|
|
return_value = 1;
|
2005-08-29 22:03:37 +00:00
|
|
|
}
|
2005-05-16 00:35:38 +00:00
|
|
|
} else {
|
2007-07-02 21:50:15 +00:00
|
|
|
if (io.val->type == AST_EXPR_number) {
|
2005-08-29 22:03:37 +00:00
|
|
|
int res_length;
|
|
|
|
|
2007-07-02 21:50:15 +00:00
|
|
|
res_length = snprintf(buf, length, FP___PRINTF, io.val->u.i);
|
2006-01-03 16:39:37 +00:00
|
|
|
return_value = (res_length <= length) ? res_length : length;
|
2005-08-29 22:03:37 +00:00
|
|
|
} else {
|
2007-11-06 19:40:33 +00:00
|
|
|
if (io.val->u.s)
|
2008-09-27 15:52:56 +00:00
|
|
|
#if defined(STANDALONE) || defined(LOW_MEMORY) || defined(STANDALONE)
|
2007-11-06 19:40:33 +00:00
|
|
|
strncpy(buf, io.val->u.s, length - 1);
|
2007-01-02 22:43:36 +00:00
|
|
|
#else /* !STANDALONE && !LOW_MEMORY */
|
2007-11-06 19:40:33 +00:00
|
|
|
ast_copy_string(buf, io.val->u.s, length);
|
2007-01-02 22:43:36 +00:00
|
|
|
#endif /* STANDALONE || LOW_MEMORY */
|
2007-11-06 19:40:33 +00:00
|
|
|
else
|
|
|
|
buf[0] = 0;
|
2006-01-03 16:39:37 +00:00
|
|
|
return_value = strlen(buf);
|
2009-06-25 21:45:32 +00:00
|
|
|
free(io.val->u.s);
|
2005-05-16 00:35:38 +00:00
|
|
|
}
|
2006-01-03 16:39:37 +00:00
|
|
|
free(io.val);
|
2005-05-16 00:35:38 +00:00
|
|
|
}
|
2006-01-03 16:39:37 +00:00
|
|
|
return return_value;
|
2005-05-16 00:35:38 +00:00
|
|
|
}
|
|
|
|
|
2010-01-13 18:16:13 +00:00
|
|
|
#ifndef STANDALONE
|
|
|
|
int ast_str_expr(struct ast_str **str, ssize_t maxlen, struct ast_channel *chan, char *expr)
|
|
|
|
{
|
|
|
|
struct parse_io io = { .string = expr, .chan = chan };
|
|
|
|
|
|
|
|
ast_yylex_init(&io.scanner);
|
|
|
|
ast_yy_scan_string(expr, io.scanner);
|
|
|
|
ast_yyparse ((void *) &io);
|
|
|
|
ast_yylex_destroy(io.scanner);
|
|
|
|
|
|
|
|
if (!io.val) {
|
|
|
|
ast_str_set(str, maxlen, "0");
|
|
|
|
} else {
|
|
|
|
if (io.val->type == AST_EXPR_number) {
|
|
|
|
ast_str_set(str, maxlen, FP___PRINTF, io.val->u.i);
|
|
|
|
} else if (io.val->u.s) {
|
|
|
|
ast_str_set(str, maxlen, "%s", io.val->u.s);
|
|
|
|
free(io.val->u.s);
|
|
|
|
}
|
|
|
|
free(io.val);
|
|
|
|
}
|
|
|
|
return ast_str_strlen(*str);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-04-24 17:41:27 +00:00
|
|
|
|
|
|
|
char extra_error_message[4095];
|
|
|
|
int extra_error_message_supplied = 0;
|
|
|
|
void ast_expr_register_extra_error_info(char *message);
|
|
|
|
void ast_expr_clear_extra_error_info(void);
|
|
|
|
|
|
|
|
void ast_expr_register_extra_error_info(char *message)
|
|
|
|
{
|
|
|
|
extra_error_message_supplied=1;
|
|
|
|
strcpy(extra_error_message, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ast_expr_clear_extra_error_info(void)
|
|
|
|
{
|
|
|
|
extra_error_message_supplied=0;
|
|
|
|
extra_error_message[0] = 0;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static const char * const expr2_token_equivs1[] =
|
2006-04-24 17:41:27 +00:00
|
|
|
{
|
|
|
|
"TOKEN",
|
|
|
|
"TOK_COND",
|
|
|
|
"TOK_COLONCOLON",
|
|
|
|
"TOK_OR",
|
|
|
|
"TOK_AND",
|
|
|
|
"TOK_EQ",
|
|
|
|
"TOK_GT",
|
|
|
|
"TOK_LT",
|
|
|
|
"TOK_GE",
|
|
|
|
"TOK_LE",
|
|
|
|
"TOK_NE",
|
|
|
|
"TOK_PLUS",
|
|
|
|
"TOK_MINUS",
|
|
|
|
"TOK_MULT",
|
|
|
|
"TOK_DIV",
|
|
|
|
"TOK_MOD",
|
|
|
|
"TOK_COMPL",
|
|
|
|
"TOK_COLON",
|
|
|
|
"TOK_EQTILDE",
|
In regards to changes for 9508, expr2 system choking on floating point numbers, I'm adding this update to round out (no pun intended) and make this FP-capable version of the Expr2 stuff interoperate better with previous integer-only usage, by providing Functions syntax, with 20 builtin functions for floating pt to integer conversions, and some general floating point math routines that might commonly be used also. Along with this, I made it so if a function was not a builtin, it will try and find it in the ast_custom_function list, and if found, execute it and collect the results. Thus, you can call system functions like CDR(), CHANNEL(), etc, from within $\[..\] exprs, without having to wrap them in $\{...\} (curly brace) notation. Did a valgrind on the standalone and made sure there's no mem leaks. Looks good. Updated the docs, too.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@73449 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-05 18:15:22 +00:00
|
|
|
"TOK_COMMA",
|
2006-04-24 17:41:27 +00:00
|
|
|
"TOK_RP",
|
|
|
|
"TOK_LP"
|
|
|
|
};
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static const char * const expr2_token_equivs2[] =
|
2006-04-24 17:41:27 +00:00
|
|
|
{
|
|
|
|
"<token>",
|
|
|
|
"?",
|
|
|
|
"::",
|
|
|
|
"|",
|
|
|
|
"&",
|
|
|
|
"=",
|
|
|
|
">",
|
|
|
|
"<",
|
|
|
|
">=",
|
|
|
|
"<=",
|
|
|
|
"!=",
|
|
|
|
"+",
|
|
|
|
"-",
|
|
|
|
"*",
|
|
|
|
"/",
|
|
|
|
"%",
|
|
|
|
"!",
|
|
|
|
":",
|
|
|
|
"=~",
|
In regards to changes for 9508, expr2 system choking on floating point numbers, I'm adding this update to round out (no pun intended) and make this FP-capable version of the Expr2 stuff interoperate better with previous integer-only usage, by providing Functions syntax, with 20 builtin functions for floating pt to integer conversions, and some general floating point math routines that might commonly be used also. Along with this, I made it so if a function was not a builtin, it will try and find it in the ast_custom_function list, and if found, execute it and collect the results. Thus, you can call system functions like CDR(), CHANNEL(), etc, from within $\[..\] exprs, without having to wrap them in $\{...\} (curly brace) notation. Did a valgrind on the standalone and made sure there's no mem leaks. Looks good. Updated the docs, too.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@73449 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-05 18:15:22 +00:00
|
|
|
",",
|
2006-04-24 17:41:27 +00:00
|
|
|
")",
|
|
|
|
"("
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-09-21 14:40:10 +00:00
|
|
|
static char *expr2_token_subst(const char *mess)
|
2006-04-24 17:41:27 +00:00
|
|
|
{
|
|
|
|
/* calc a length, malloc, fill, and return; yyerror had better free it! */
|
|
|
|
int len=0,i;
|
2007-09-21 14:40:10 +00:00
|
|
|
const char *p;
|
2010-01-13 18:16:13 +00:00
|
|
|
char *res, *s;
|
|
|
|
const char *t;
|
2006-04-24 17:41:27 +00:00
|
|
|
int expr2_token_equivs_entries = sizeof(expr2_token_equivs1)/sizeof(char*);
|
|
|
|
|
|
|
|
for (p=mess; *p; p++) {
|
|
|
|
for (i=0; i<expr2_token_equivs_entries; i++) {
|
|
|
|
if ( strncmp(p,expr2_token_equivs1[i],strlen(expr2_token_equivs1[i])) == 0 )
|
|
|
|
{
|
|
|
|
len+=strlen(expr2_token_equivs2[i])+2;
|
|
|
|
p += strlen(expr2_token_equivs1[i])-1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
res = (char*)malloc(len+1);
|
|
|
|
res[0] = 0;
|
|
|
|
s = res;
|
|
|
|
for (p=mess; *p;) {
|
|
|
|
int found = 0;
|
|
|
|
for (i=0; i<expr2_token_equivs_entries; i++) {
|
|
|
|
if ( strncmp(p,expr2_token_equivs1[i],strlen(expr2_token_equivs1[i])) == 0 ) {
|
|
|
|
*s++ = '\'';
|
|
|
|
for (t=expr2_token_equivs2[i]; *t;) {
|
|
|
|
*s++ = *t++;
|
|
|
|
}
|
|
|
|
*s++ = '\'';
|
|
|
|
p += strlen(expr2_token_equivs1[i]);
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( !found )
|
|
|
|
*s++ = *p++;
|
|
|
|
}
|
|
|
|
*s++ = 0;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-05-16 00:35:38 +00:00
|
|
|
int ast_yyerror (const char *s, yyltype *loc, struct parse_io *parseio )
|
2012-02-08 20:49:48 +00:00
|
|
|
{
|
2005-05-16 00:35:38 +00:00
|
|
|
struct yyguts_t * yyg = (struct yyguts_t*)(parseio->scanner);
|
|
|
|
char spacebuf[8000]; /* best safe than sorry */
|
|
|
|
int i=0;
|
2007-09-21 14:40:10 +00:00
|
|
|
char *s2 = expr2_token_subst(s);
|
2005-05-16 00:35:38 +00:00
|
|
|
spacebuf[0] = 0;
|
2012-02-08 20:49:48 +00:00
|
|
|
|
|
|
|
for (i = 0; i < (int)(yytext - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf); i++) {
|
|
|
|
spacebuf[i] = ' ';
|
|
|
|
}
|
|
|
|
/* uh... assuming yyg is defined, then I can use the yycolumn macro,
|
|
|
|
which is the same thing as... get this:
|
|
|
|
yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]->yy_bs_column
|
|
|
|
I was tempted to just use yy_buf_pos in the STATE, but..., well:
|
|
|
|
a. the yy_buf_pos is the current position in the buffer, which
|
|
|
|
may not relate to the entire string/buffer because of the
|
|
|
|
buffering.
|
|
|
|
b. but, analysis of the situation is that when you use the
|
|
|
|
yy_scan_string func, it creates a single buffer the size of
|
|
|
|
string, so the two would be the same...
|
|
|
|
so, in the end, the yycolumn macro is available, shorter, therefore easier. */
|
|
|
|
|
|
|
|
spacebuf[i++] = '^';
|
|
|
|
spacebuf[i] = 0;
|
2005-05-16 00:35:38 +00:00
|
|
|
|
2005-06-24 02:51:47 +00:00
|
|
|
#ifdef STANDALONE3
|
2005-05-16 00:35:38 +00:00
|
|
|
/* easier to read in the standalone version */
|
2012-02-08 20:49:48 +00:00
|
|
|
printf("ast_yyerror(): %s syntax error: %s; Input:\n%s\n%s\n",
|
|
|
|
(extra_error_message_supplied ? extra_error_message : ""), s2, parseio->string, spacebuf);
|
2005-05-16 00:35:38 +00:00
|
|
|
#else
|
2012-02-08 20:49:48 +00:00
|
|
|
ast_log(LOG_WARNING,"ast_yyerror(): %s syntax error: %s; Input:\n%s\n%s\n",
|
|
|
|
(extra_error_message_supplied ? extra_error_message : ""), s2, parseio->string, spacebuf);
|
2005-06-24 02:51:47 +00:00
|
|
|
#endif
|
|
|
|
#ifndef STANDALONE
|
2011-02-02 18:59:29 +00:00
|
|
|
ast_log(LOG_WARNING,"If you have questions, please refer to https://wiki.asterisk.org/wiki/display/AST/Channel+Variables\n");
|
2005-05-16 00:35:38 +00:00
|
|
|
#endif
|
2006-04-24 17:41:27 +00:00
|
|
|
free(s2);
|
2005-05-16 00:35:38 +00:00
|
|
|
return(0);
|
|
|
|
}
|