Sat Apr 26 2014 22:01:55

Asterisk developer's documentation


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

Referenced by check_pval_item(), and pbx_substitute_variables_helper_full().

{
   struct parse_io io = { .string = expr, .chan = chan };
   int return_value = 0;

   ast_yylex_init(&io.scanner);

   ast_yy_scan_string(expr, io.scanner);

   ast_yyparse ((void *) &io);

   ast_yylex_destroy(io.scanner);

   if (!io.val) {
      if (length > 1) {
         strcpy(buf, "0");
         return_value = 1;
      }
   } else {
      if (io.val->type == AST_EXPR_number) {
         int res_length;

         res_length = snprintf(buf, length, FP___PRINTF, io.val->u.i);
         return_value = (res_length <= length) ? res_length : length;
      } else {
         if (io.val->u.s)
#if defined(STANDALONE) || defined(LOW_MEMORY) || defined(STANDALONE)
            strncpy(buf, io.val->u.s, length - 1);
#else /* !STANDALONE && !LOW_MEMORY */
            ast_copy_string(buf, io.val->u.s, length);
#endif /* STANDALONE || LOW_MEMORY */
         else
            buf[0] = 0;
         return_value = strlen(buf);
         free(io.val->u.s);
      }
      free(io.val);
   }
   return return_value;
}
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 2448 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().

{
   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);
}