Wed Jan 8 2020 09:49:57

Asterisk developer's documentation


ast_expr.h File Reference

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

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 2396 of file ast_expr2f.c.

Referenced by check_pval_item(), and pbx_substitute_variables_helper_full().

2397 {
2398  struct parse_io io = { .string = expr, .chan = chan };
2399  int return_value = 0;
2400 
2401  ast_yylex_init(&io.scanner);
2402 
2403  ast_yy_scan_string(expr, io.scanner);
2404 
2405  ast_yyparse ((void *) &io);
2406 
2408 
2409  if (!io.val) {
2410  if (length > 1) {
2411  strcpy(buf, "0");
2412  return_value = 1;
2413  }
2414  } else {
2415  if (io.val->type == AST_EXPR_number) {
2416  int res_length;
2417 
2418  res_length = snprintf(buf, length, FP___PRINTF, io.val->u.i);
2419  return_value = (res_length <= length) ? res_length : length;
2420  } else {
2421  if (io.val->u.s)
2422 #if defined(STANDALONE) || defined(LOW_MEMORY) || defined(STANDALONE)
2423  strncpy(buf, io.val->u.s, length - 1);
2424 #else /* !STANDALONE && !LOW_MEMORY */
2425  ast_copy_string(buf, io.val->u.s, length);
2426 #endif /* STANDALONE || LOW_MEMORY */
2427  else
2428  buf[0] = 0;
2429  return_value = strlen(buf);
2430  free(io.val->u.s);
2431  }
2432  free(io.val);
2433  }
2434  return return_value;
2435 }
int ast_yyparse(void *)
#define FP___PRINTF
Definition: ast_expr2f.c:527
FP___TYPE i
Definition: ast_expr2.c:329
static struct io_context * io
Definition: chan_gtalk.c:228
YY_BUFFER_STATE ast_yy_scan_string(yyconst char *yy_str, yyscan_t yyscanner)
Definition: ast_expr2f.c:1965
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_yylex_init(yyscan_t *scanner)
Definition: ast_expr2f.c:2212
union val::@218 u
#define free(a)
Definition: astmm.h:94
int ast_yylex_destroy(yyscan_t yyscanner)
Definition: ast_expr2f.c:2303
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
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 2438 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, val::i, val::s, parse_io::scanner, parse_io::string, val::type, val::u, and parse_io::val.

Referenced by ast_str_substitute_variables_full().

2439 {
2440  struct parse_io io = { .string = expr, .chan = chan };
2441 
2442  ast_yylex_init(&io.scanner);
2443  ast_yy_scan_string(expr, io.scanner);
2444  ast_yyparse ((void *) &io);
2446 
2447  if (!io.val) {
2448  ast_str_set(str, maxlen, "0");
2449  } else {
2450  if (io.val->type == AST_EXPR_number) {
2451  int res_length;
2452  ast_str_set(str, maxlen, FP___PRINTF, io.val->u.i);
2453  } else if (io.val->u.s) {
2454  ast_str_set(str, maxlen, "%s", io.val->u.s);
2455  free(io.val->u.s);
2456  }
2457  free(io.val);
2458  }
2459  return ast_str_strlen(*str);
2460 }
int ast_yyparse(void *)
#define FP___PRINTF
Definition: ast_expr2f.c:527
FP___TYPE i
Definition: ast_expr2.c:329
static struct io_context * io
Definition: chan_gtalk.c:228
YY_BUFFER_STATE ast_yy_scan_string(yyconst char *yy_str, yyscan_t yyscanner)
Definition: ast_expr2f.c:1965
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:874
int ast_yylex_init(yyscan_t *scanner)
Definition: ast_expr2f.c:2212
union val::@218 u
#define free(a)
Definition: astmm.h:94
int ast_yylex_destroy(yyscan_t yyscanner)
Definition: ast_expr2f.c:2303
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:471