Asterisk - The Open Source Telephony Project  18.5.0
Functions
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. More...
 
int ast_str_expr (struct ast_str **str, ssize_t maxlen, struct ast_channel *chan, char *expr)
 Evaluate the given expression. More...
 

Detailed Description

???????

Todo:
Explain this file!

Definition in file ast_expr.h.

Function Documentation

◆ ast_expr()

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

Evaluate the given expression.

Parameters
exprAn expression
bufResult buffer
lengthSize of the result buffer, in bytes
chanChannel to use for evaluating included dialplan functions, if any
Returns
Length of the result string, in bytes

Definition at line 2405 of file ast_expr2f.c.

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

2406 {
2407  struct parse_io io = { .string = expr, .chan = chan };
2408  int return_value = 0;
2409 
2410  ast_yylex_init(&io.scanner);
2411 
2412  ast_yy_scan_string(expr, io.scanner);
2413 
2414  ast_yyparse ((void *) &io);
2415 
2417 
2418  if (!io.val) {
2419  if (length > 1) {
2420  strcpy(buf, "0");
2421  return_value = 1;
2422  }
2423  } else {
2424  if (io.val->type == AST_EXPR_number) {
2425  int res_length;
2426 
2427  res_length = snprintf(buf, length, FP___PRINTF, io.val->u.i);
2428  return_value = (res_length <= length) ? res_length : length;
2429  } else {
2430  if (io.val->u.s)
2431 #if defined(STANDALONE) || defined(LOW_MEMORY) || defined(STANDALONE)
2432  strncpy(buf, io.val->u.s, length - 1);
2433 #else /* !STANDALONE && !LOW_MEMORY */
2434  ast_copy_string(buf, io.val->u.s, length);
2435 #endif /* STANDALONE || LOW_MEMORY */
2436  else
2437  buf[0] = 0;
2438  return_value = strlen(buf);
2439  free(io.val->u.s);
2440  }
2441  free(io.val);
2442  }
2443  return return_value;
2444 }
int ast_yyparse(void *)
#define FP___PRINTF
Definition: ast_expr2f.c:535
FP___TYPE i
Definition: ast_expr2.c:329
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
union val::@335 u
YY_BUFFER_STATE ast_yy_scan_string(yyconst char *yy_str, yyscan_t yyscanner)
Definition: ast_expr2f.c:1974
struct val * val
Definition: ast_expr2.c:351
yyscan_t scanner
Definition: ael_structs.h:78
enum valtype type
Definition: ast_expr2.c:326
char * s
Definition: ast_expr2.c:328
void free()
static struct io_context * io
Definition: chan_ooh323.c:401
int ast_yylex_init(yyscan_t *scanner)
Definition: ast_expr2f.c:2221
int ast_yylex_destroy(yyscan_t yyscanner)
Definition: ast_expr2f.c:2312
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ ast_str_expr()

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

Evaluate the given expression.

Parameters
strDynamic 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
chanChannel to use for evaluating included dialplan functions, if any
exprAn expression
Returns
Length of the result string, in bytes

Definition at line 2447 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().

2448 {
2449  struct parse_io io = { .string = expr, .chan = chan };
2450 
2451  ast_yylex_init(&io.scanner);
2452  ast_yy_scan_string(expr, io.scanner);
2453  ast_yyparse ((void *) &io);
2455 
2456  if (!io.val) {
2457  ast_str_set(str, maxlen, "0");
2458  } else {
2459  if (io.val->type == AST_EXPR_number) {
2460  ast_str_set(str, maxlen, FP___PRINTF, io.val->u.i);
2461  } else if (io.val->u.s) {
2462  ast_str_set(str, maxlen, "%s", io.val->u.s);
2463  free(io.val->u.s);
2464  }
2465  free(io.val);
2466  }
2467  return ast_str_strlen(*str);
2468 }
int ast_yyparse(void *)
#define FP___PRINTF
Definition: ast_expr2f.c:535
FP___TYPE i
Definition: ast_expr2.c:329
union val::@335 u
YY_BUFFER_STATE ast_yy_scan_string(yyconst char *yy_str, yyscan_t yyscanner)
Definition: ast_expr2f.c:1974
struct val * val
Definition: ast_expr2.c:351
yyscan_t scanner
Definition: ael_structs.h:78
enum valtype type
Definition: ast_expr2.c:326
char * s
Definition: ast_expr2.c:328
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
void free()
static struct io_context * io
Definition: chan_ooh323.c:401
int ast_yylex_init(yyscan_t *scanner)
Definition: ast_expr2f.c:2221
int ast_yylex_destroy(yyscan_t yyscanner)
Definition: ast_expr2f.c:2312
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688