Asterisk - The Open Source Telephony Project GIT-master-f36a736
Functions
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. 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

◆ ast_expr()

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 ast_expr2f.c.

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}
int ast_yylex_destroy(yyscan_t yyscanner)
Definition: ast_expr2f.c:2298
int ast_yyparse(void *)
@ AST_EXPR_number
Definition: ast_expr2f.c:558
YY_BUFFER_STATE ast_yy_scan_string(yyconst char *yy_str, yyscan_t yyscanner)
Definition: ast_expr2f.c:1960
#define FP___PRINTF
Definition: ast_expr2f.c:526
int ast_yylex_init(yyscan_t *scanner)
Definition: ast_expr2f.c:2207
static struct io_context * io
Definition: chan_ooh323.c:401
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
void free()
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
struct ast_channel * chan
Definition: ast_expr2.c:353

References ast_copy_string(), AST_EXPR_number, ast_yy_scan_string(), ast_yylex_destroy(), ast_yylex_init(), ast_yyparse(), buf, parse_io::chan, FP___PRINTF, free(), and io.

Referenced by AST_TEST_DEFINE(), check_eval(), check_pval_item(), pbx_substitute_variables_helper_full(), and pbx_substitute_variables_helper_full_location().

◆ ast_str_expr()

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 ast_expr2f.c.

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}
const char * str
Definition: app_jack.c:147
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

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_full2().