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. |
Definition in file ast_expr.h.
int ast_expr | ( | char * | expr, | |
char * | buf, | |||
int | length, | |||
struct ast_channel * | chan | |||
) |
Evaluate the given expression.
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 |
Definition at line 2406 of file ast_expr2f.c.
Referenced by check_pval_item(), and pbx_substitute_variables_helper_full().
02407 { 02408 struct parse_io io = { .string = expr, .chan = chan }; 02409 int return_value = 0; 02410 02411 ast_yylex_init(&io.scanner); 02412 02413 ast_yy_scan_string(expr, io.scanner); 02414 02415 ast_yyparse ((void *) &io); 02416 02417 ast_yylex_destroy(io.scanner); 02418 02419 if (!io.val) { 02420 if (length > 1) { 02421 strcpy(buf, "0"); 02422 return_value = 1; 02423 } 02424 } else { 02425 if (io.val->type == AST_EXPR_number) { 02426 int res_length; 02427 02428 res_length = snprintf(buf, length, FP___PRINTF, io.val->u.i); 02429 return_value = (res_length <= length) ? res_length : length; 02430 } else { 02431 if (io.val->u.s) 02432 #if defined(STANDALONE) || defined(LOW_MEMORY) || defined(STANDALONE) 02433 strncpy(buf, io.val->u.s, length - 1); 02434 #else /* !STANDALONE && !LOW_MEMORY */ 02435 ast_copy_string(buf, io.val->u.s, length); 02436 #endif /* STANDALONE || LOW_MEMORY */ 02437 else 02438 buf[0] = 0; 02439 return_value = strlen(buf); 02440 free(io.val->u.s); 02441 } 02442 free(io.val); 02443 } 02444 return return_value; 02445 }
int ast_str_expr | ( | struct ast_str ** | str, | |
ssize_t | maxlen, | |||
struct ast_channel * | chan, | |||
char * | expr | |||
) |
Evaluate the given expression.
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 |
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(), parse_io::chan, FP___PRINTF, free, io, and str.
Referenced by ast_str_substitute_variables_full().
02449 { 02450 struct parse_io io = { .string = expr, .chan = chan }; 02451 02452 ast_yylex_init(&io.scanner); 02453 ast_yy_scan_string(expr, io.scanner); 02454 ast_yyparse ((void *) &io); 02455 ast_yylex_destroy(io.scanner); 02456 02457 if (!io.val) { 02458 ast_str_set(str, maxlen, "0"); 02459 } else { 02460 if (io.val->type == AST_EXPR_number) { 02461 int res_length; 02462 ast_str_set(str, maxlen, FP___PRINTF, io.val->u.i); 02463 } else if (io.val->u.s) { 02464 ast_str_set(str, maxlen, "%s", io.val->u.s); 02465 free(io.val->u.s); 02466 } 02467 free(io.val); 02468 } 02469 return ast_str_strlen(*str); 02470 }