ast_expr.h File Reference

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

Go to the source code of this file.

Functions

int ast_expr (char *expr, char *buf, int length, struct ast_channel *chan)
 Evaluate the given expression.
int ast_str_expr (struct ast_str **str, ssize_t maxlen, struct ast_channel *chan, char *expr)
 Evaluate the given expression.


Detailed Description

???????
Todo:
Explain this file!

Definition in file ast_expr.h.


Function Documentation

int ast_expr ( char *  expr,
char *  buf,
int  length,
struct ast_channel chan 
)

Evaluate the given expression.

Parameters:
expr An expression
buf Result buffer
length Size of the result buffer, in bytes
chan Channel to use for evaluating included dialplan functions, if any
Returns:
Length of the result string, in bytes

Definition at line 2407 of file ast_expr2f.c.

Referenced by AST_TEST_DEFINE(), check_eval(), check_pval_item(), and pbx_substitute_variables_helper_full().

02408 {
02409    struct parse_io io = { .string = expr, .chan = chan };
02410    int return_value = 0;
02411 
02412    ast_yylex_init(&io.scanner);
02413 
02414    ast_yy_scan_string(expr, io.scanner);
02415 
02416    ast_yyparse ((void *) &io);
02417 
02418    ast_yylex_destroy(io.scanner);
02419 
02420    if (!io.val) {
02421       if (length > 1) {
02422          strcpy(buf, "0");
02423          return_value = 1;
02424       }
02425    } else {
02426       if (io.val->type == AST_EXPR_number) {
02427          int res_length;
02428 
02429          res_length = snprintf(buf, length, FP___PRINTF, io.val->u.i);
02430          return_value = (res_length <= length) ? res_length : length;
02431       } else {
02432          if (io.val->u.s)
02433 #if defined(STANDALONE) || defined(LOW_MEMORY) || defined(STANDALONE)
02434             strncpy(buf, io.val->u.s, length - 1);
02435 #else /* !STANDALONE && !LOW_MEMORY */
02436             ast_copy_string(buf, io.val->u.s, length);
02437 #endif /* STANDALONE || LOW_MEMORY */
02438          else
02439             buf[0] = 0;
02440          return_value = strlen(buf);
02441          free(io.val->u.s);
02442       }
02443       free(io.val);
02444    }
02445    return return_value;
02446 }

int ast_str_expr ( struct ast_str **  str,
ssize_t  maxlen,
struct ast_channel chan,
char *  expr 
)

Evaluate the given expression.

Parameters:
str Dynamic result buffer
maxlen <0 if the size of the buffer should remain constant, >0 if the size of the buffer should expand to that many bytes, maximum, or 0 for unlimited expansion of the result buffer
chan Channel to use for evaluating included dialplan functions, if any
expr An expression
Returns:
Length of the result string, in bytes

Definition at line 2449 of file ast_expr2f.c.

References AST_EXPR_number, ast_str_set(), ast_str_strlen(), ast_yy_scan_string(), ast_yylex_destroy(), ast_yylex_init(), ast_yyparse(), FP___PRINTF, free, parse_io::scanner, and parse_io::string.

Referenced by ast_str_substitute_variables_full().

02450 {
02451    struct parse_io io = { .string = expr, .chan = chan };
02452 
02453    ast_yylex_init(&io.scanner);
02454    ast_yy_scan_string(expr, io.scanner);
02455    ast_yyparse ((void *) &io);
02456    ast_yylex_destroy(io.scanner);
02457 
02458    if (!io.val) {
02459       ast_str_set(str, maxlen, "0");
02460    } else {
02461       if (io.val->type == AST_EXPR_number) {
02462          ast_str_set(str, maxlen, FP___PRINTF, io.val->u.i);
02463       } else if (io.val->u.s) {
02464          ast_str_set(str, maxlen, "%s", io.val->u.s);
02465          free(io.val->u.s);
02466       }
02467       free(io.val);
02468    }
02469    return ast_str_strlen(*str);
02470 }


Generated on Thu Apr 16 06:28:54 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6