Wed Apr 6 11:29:53 2011

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

Referenced by check_pval_item(), and pbx_substitute_variables_helper_full().

02393 {
02394    struct parse_io io = { .string = expr, .chan = chan };
02395    int return_value = 0;
02396 
02397    ast_yylex_init(&io.scanner);
02398 
02399    ast_yy_scan_string(expr, io.scanner);
02400 
02401    ast_yyparse ((void *) &io);
02402 
02403    ast_yylex_destroy(io.scanner);
02404 
02405    if (!io.val) {
02406       if (length > 1) {
02407          strcpy(buf, "0");
02408          return_value = 1;
02409       }
02410    } else {
02411       if (io.val->type == AST_EXPR_number) {
02412          int res_length;
02413 
02414          res_length = snprintf(buf, length, FP___PRINTF, io.val->u.i);
02415          return_value = (res_length <= length) ? res_length : length;
02416       } else {
02417          if (io.val->u.s)
02418 #if defined(STANDALONE) || defined(LOW_MEMORY) || defined(STANDALONE)
02419             strncpy(buf, io.val->u.s, length - 1);
02420 #else /* !STANDALONE && !LOW_MEMORY */
02421             ast_copy_string(buf, io.val->u.s, length);
02422 #endif /* STANDALONE || LOW_MEMORY */
02423          else
02424             buf[0] = 0;
02425          return_value = strlen(buf);
02426          free(io.val->u.s);
02427       }
02428       free(io.val);
02429    }
02430    return return_value;
02431 }

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 2434 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(), parse_io::chan, FP___PRINTF, free, io, and str.

Referenced by ast_str_substitute_variables_full().

02435 {
02436    struct parse_io io = { .string = expr, .chan = chan };
02437 
02438    ast_yylex_init(&io.scanner);
02439    ast_yy_scan_string(expr, io.scanner);
02440    ast_yyparse ((void *) &io);
02441    ast_yylex_destroy(io.scanner);
02442 
02443    if (!io.val) {
02444       ast_str_set(str, maxlen, "0");
02445    } else {
02446       if (io.val->type == AST_EXPR_number) {
02447          int res_length;
02448          ast_str_set(str, maxlen, FP___PRINTF, io.val->u.i);
02449       } else if (io.val->u.s) {
02450          ast_str_set(str, maxlen, "%s", io.val->u.s);
02451          free(io.val->u.s);
02452       }
02453       free(io.val);
02454    }
02455    return ast_str_strlen(*str);
02456 }


Generated on Wed Apr 6 11:29:53 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7