Asterisk - The Open Source Telephony Project  21.4.1
Functions
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 2391 of file main/ast_expr2f.c.

Referenced by pbx_substitute_variables_helper_full_location().

2392 {
2393  struct parse_io io = { .string = expr, .chan = chan };
2394  int return_value = 0;
2395 
2396  ast_yylex_init(&io.scanner);
2397 
2398  ast_yy_scan_string(expr, io.scanner);
2399 
2400  ast_yyparse ((void *) &io);
2401 
2402  ast_yylex_destroy(io.scanner);
2403 
2404  if (!io.val) {
2405  if (length > 1) {
2406  strcpy(buf, "0");
2407  return_value = 1;
2408  }
2409  } else {
2410  if (io.val->type == AST_EXPR_number) {
2411  int res_length;
2412 
2413  res_length = snprintf(buf, length, FP___PRINTF, io.val->u.i);
2414  return_value = (res_length <= length) ? res_length : length;
2415  } else {
2416  if (io.val->u.s)
2417 #if defined(STANDALONE) || defined(LOW_MEMORY) || defined(STANDALONE)
2418  strncpy(buf, io.val->u.s, length - 1);
2419 #else /* !STANDALONE && !LOW_MEMORY */
2420  ast_copy_string(buf, io.val->u.s, length);
2421 #endif /* STANDALONE || LOW_MEMORY */
2422  else
2423  buf[0] = 0;
2424  return_value = strlen(buf);
2425  free(io.val->u.s);
2426  }
2427  free(io.val);
2428  }
2429  return return_value;
2430 }
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
YY_BUFFER_STATE ast_yy_scan_string(yyconst char *yy_str, yyscan_t yyscanner)
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 2433 of file main/ast_expr2f.c.

References ast_str_set(), ast_str_strlen(), and ast_yy_scan_string().

Referenced by ast_str_substitute_variables_full2().

2434 {
2435  struct parse_io io = { .string = expr, .chan = chan };
2436 
2437  ast_yylex_init(&io.scanner);
2438  ast_yy_scan_string(expr, io.scanner);
2439  ast_yyparse ((void *) &io);
2440  ast_yylex_destroy(io.scanner);
2441 
2442  if (!io.val) {
2443  ast_str_set(str, maxlen, "0");
2444  } else {
2445  if (io.val->type == AST_EXPR_number) {
2446  ast_str_set(str, maxlen, FP___PRINTF, io.val->u.i);
2447  } else if (io.val->u.s) {
2448  ast_str_set(str, maxlen, "%s", io.val->u.s);
2449  free(io.val->u.s);
2450  }
2451  free(io.val);
2452  }
2453  return ast_str_strlen(*str);
2454 }
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:1113
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:730
YY_BUFFER_STATE ast_yy_scan_string(yyconst char *yy_str, yyscan_t yyscanner)