Data Structures | Defines | Enumerations | Functions

rvalue.h File Reference

SIP-router core :: rvalue expressionsModule: SIP-router core. More...

#include "str.h"
#include "ut.h"
#include "usr_avp.h"
#include "select.h"
#include "pvar.h"
#include "route.h"
#include "parser/msg_parser.h"
#include "action.h"
Include dependency graph for rvalue.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

Defines

Enumerations

Functions


Detailed Description

Definition in file rvalue.h.


Enumeration Type Documentation

Enumerator:
RVE_NONE_OP 

uninit / empty

RVE_RVAL_OP 

special op, means that the expr.

is in fact a rval

RVE_UMINUS_OP 

one member expression, returns -(val)

RVE_BOOL_OP 

one member evaluate as bool.

: (val!=0)

RVE_LNOT_OP 

one member evaluate as bool.

: (!val)

RVE_BNOT_OP 

one member evaluate as binary : (~ val)

RVE_MUL_OP 

2 members, returns left * right

RVE_DIV_OP 

2 members, returns left / right

RVE_MOD_OP 

2 members, returns left % right

RVE_MINUS_OP 

2 members, returns left - right

RVE_BAND_OP 

2 members, returns left | right

RVE_BOR_OP 

2 members, returns left & right

RVE_BXOR_OP 

2 members, returns left XOR right

RVE_BLSHIFT_OP 

2 members, returns left << right

RVE_BRSHIFT_OP 

2 members, returns left >> right

RVE_LAND_OP 

2 members, returns left && right

RVE_LOR_OP 

2 members, returns left || right

RVE_GT_OP 

2 members, returns left > right

RVE_GTE_OP 

2 members, returns left >= right

RVE_LT_OP 

2 members, returns left < right

RVE_LTE_OP 

2 members, returns left <= right

RVE_IEQ_OP 

2 members, int == version, returns left == right

RVE_IDIFF_OP 

2 members, int != version, returns left != right

RVE_IPLUS_OP 

2 members, integer +, returns int(a)+int(b)

RVE_PLUS_OP 

generic plus (int or str) returns left + right

RVE_EQ_OP 

2 members, returns left == right (int)

RVE_DIFF_OP 

2 members, returns left != right (int)

RVE_CONCAT_OP 

2 members, string concat, returns left .

right (str)

RVE_STRLEN_OP 

one member, string length:, returns strlen(val) (int)

RVE_STREMPTY_OP 

one member, returns val=="" (bool)

RVE_STREQ_OP 

2 members, string == , returns left == right (bool)

RVE_STRDIFF_OP 

2 members, string != , returns left != right (bool)

RVE_MATCH_OP 

2 members, string ~), returns left matches re(right)

RVE_DEFINED_OP 

one member, returns is_defined(val) (bool)

RVE_INT_OP 

one member, returns (int)val (int)

RVE_STR_OP 

one member, returns (str)val (str)

Definition at line 52 of file rvalue.h.


Function Documentation

int fix_rval_expr ( void *  p  ) 

fixes action, bexprs, resolves selects, pvars and optimizes simple sub expressions (e.g. 1+2).

Parameters:
p - pointer to a rval_expr
Returns:
0 on success, <0 on error (modifies also *(struct rval_expr*)p)

Definition at line 3778 of file rvalue.c.

Referenced by fix_match_rve().

Here is the caller graph for this function:

struct rval_expr* mk_rval_expr1 ( enum rval_expr_op  op,
struct rval_expr *  rve1,
struct cfg_pos *  pos 
) [read]

rval_expr ret= op rve1

Parameters:
op - rval expr. unary operator
rve1 - rval expr. on which the operator will act.
pos configuration position
Returns:
new pkg_malloc'ed rval_expr or 0 on error.

Definition at line 2591 of file rvalue.c.

References RVE_BNOT_OP, RVE_BOOL_OP, RVE_DEFINED_OP, RVE_INT_OP, RVE_LNOT_OP, RVE_STR_OP, RVE_STREMPTY_OP, RVE_STRLEN_OP, and RVE_UMINUS_OP.

struct rval_expr* mk_rval_expr2 ( enum rval_expr_op  op,
struct rval_expr *  rve1,
struct rval_expr *  rve2,
struct cfg_pos *  pos 
) [read]

from 2 other rval exprs, using op ret = rve1 op rve2

Parameters:
op - rval expr. operator
rve1 - rval expr. on which the operator will act.
rve2 - rval expr. on which the operator will act.
pos configuration position
Returns:
new pkg_malloc'ed rval_expr or 0 on error.

Definition at line 2632 of file rvalue.c.

References RVE_BAND_OP, RVE_BLSHIFT_OP, RVE_BOR_OP, RVE_BRSHIFT_OP, RVE_BXOR_OP, RVE_CONCAT_OP, RVE_DIFF_OP, RVE_DIV_OP, RVE_EQ_OP, RVE_GT_OP, RVE_GTE_OP, RVE_IDIFF_OP, RVE_IEQ_OP, RVE_IPLUS_OP, RVE_LAND_OP, RVE_LOR_OP, RVE_LT_OP, RVE_LTE_OP, RVE_MATCH_OP, RVE_MINUS_OP, RVE_MOD_OP, RVE_MUL_OP, RVE_PLUS_OP, RVE_STRDIFF_OP, and RVE_STREQ_OP.

struct rval_expr* mk_rval_expr_v ( enum rval_type  rv_type,
void *  val,
struct cfg_pos *  pos 
) [read]

create a RVE_RVAL_OP rval_expr, containing a single rval of the given type

Parameters:
rv_type - rval type
val - rval value
pos - config position
Returns:
new pkg_malloc'ed rval_expr or 0 on error.

Definition at line 2526 of file rvalue.c.

References rval_init().

Here is the call graph for this function:

struct rvalue* rval_convert ( struct run_act_ctx *  h,
struct sip_msg msg,
enum rval_type  type,
struct rvalue *  v,
struct rval_cache c 
) [read]

Convert a rvalue to another rvalue, of a specific type. The result is read-only in most cases (can be a reference to another rvalue, can be checked by using rv_chg_in_place()) and _must_ be rval_destroy()'ed.

Parameters:
h run action context
msg SIP mesasge
type - type to convert to
v - rvalue to convert
c - rval_cache (cached v value if known/filled by another function), can be 0 (unknown/not needed)
Returns:
pointer to a rvalue (reference to an existing one or a new one,
See also:
rv_chg_in_place() and the above comment), or 0 on error.

Definition at line 1294 of file rvalue.c.

References rval_cache_clean(), rval_cache_init, rval_get_int(), rval_get_tmp_str(), rval_new(), and rval_new_str().

Referenced by rval_expr_eval(), rval_int_strop1(), rval_intop1(), rval_intop2(), rval_str_add2(), and rval_str_lop2().

Here is the call graph for this function:

Here is the caller graph for this function:

void rval_destroy ( struct rvalue *  rv  ) 
struct rvalue* rval_expr_eval ( struct run_act_ctx *  h,
struct sip_msg msg,
struct rval_expr *  rve 
) [read]
Warning:
result must be rval_destroy()'ed if non-null (it might be a reference to another rval). The result can be modified only if rv_chg_in_place() returns true.
Parameters:
h run action context
msg SIP message
rve rvalue expression
Returns:
rvalue on success, 0 on error

Definition at line 2314 of file rvalue.c.

References int_intop2(), rval_cache_clean(), rval_cache_init, rval_convert(), rval_destroy(), rval_expr_eval(), rval_expr_eval_int(), rval_get_btype(), rval_get_int(), rval_get_int_handle_ret, rval_new(), rval_str_add2(), RVE_BAND_OP, RVE_BLSHIFT_OP, RVE_BNOT_OP, RVE_BOOL_OP, RVE_BOR_OP, RVE_BRSHIFT_OP, RVE_BXOR_OP, RVE_CONCAT_OP, RVE_DEFINED_OP, RVE_DIFF_OP, RVE_DIV_OP, RVE_EQ_OP, RVE_GT_OP, RVE_GTE_OP, RVE_IDIFF_OP, RVE_IEQ_OP, RVE_INT_OP, RVE_IPLUS_OP, RVE_LAND_OP, RVE_LNOT_OP, RVE_LOR_OP, RVE_LT_OP, RVE_LTE_OP, RVE_MATCH_OP, RVE_MINUS_OP, RVE_MOD_OP, RVE_MUL_OP, RVE_NONE_OP, RVE_PLUS_OP, RVE_RVAL_OP, RVE_STR_OP, RVE_STRDIFF_OP, RVE_STREMPTY_OP, RVE_STREQ_OP, RVE_STRLEN_OP, and RVE_UMINUS_OP.

Referenced by fix_match(), fix_match_rve(), lval_assign(), rval_expr_eval(), rval_expr_eval_int(), rval_expr_eval_new(), and rval_expr_eval_rvint().

Here is the call graph for this function:

Here is the caller graph for this function:

int rval_expr_eval_int ( struct run_act_ctx *  h,
struct sip_msg msg,
int *  res,
struct rval_expr *  rve 
)
int rval_expr_eval_rvint ( struct run_act_ctx *  h,
struct sip_msg msg,
struct rvalue **  res_rv,
int *  res_i,
struct rval_expr *  rve,
struct rval_cache cache 
)
Warning:
rv result (rv_res) must be rval_destroy()'ed if non-null (it might be a reference to another rval). The result can be modified only if rv_chg_in_place() returns true.
Parameters:
h run action context
msg SIP message
res_rv pointer to rvalue result, if non-null it means the expression evaluated to a non-int (str), which will be stored here.
res_i pointer to int result, if res_rv==0 and the function returns success => the result is an int which will be stored here.
rve expression that will be evaluated.
cache write-only value cache, it might be filled if non-null and empty (rval_cache_init()). If non-null, it _must_ be rval_cache_clean()'ed when done.
Returns:
0 on success, -1 on error, sets *res_rv or *res_i.

Definition at line 2169 of file rvalue.c.

References int_intop2(), rval_cache_clean(), rval_cache_init, rval_destroy(), rval_expr_eval(), rval_expr_eval_int(), rval_expr_eval_rvint(), rval_get_btype(), rval_get_int(), rval_get_int_handle_ret, rval_str_add2(), RVE_BAND_OP, RVE_BLSHIFT_OP, RVE_BNOT_OP, RVE_BOOL_OP, RVE_BOR_OP, RVE_BRSHIFT_OP, RVE_BXOR_OP, RVE_CONCAT_OP, RVE_DEFINED_OP, RVE_DIFF_OP, RVE_DIV_OP, RVE_EQ_OP, RVE_GT_OP, RVE_GTE_OP, RVE_IDIFF_OP, RVE_IEQ_OP, RVE_INT_OP, RVE_IPLUS_OP, RVE_LAND_OP, RVE_LNOT_OP, RVE_LOR_OP, RVE_LT_OP, RVE_LTE_OP, RVE_MATCH_OP, RVE_MINUS_OP, RVE_MOD_OP, RVE_MUL_OP, RVE_NONE_OP, RVE_PLUS_OP, RVE_RVAL_OP, RVE_STR_OP, RVE_STRDIFF_OP, RVE_STREMPTY_OP, RVE_STREQ_OP, RVE_STRLEN_OP, and RVE_UMINUS_OP.

Referenced by rval_expr_eval_int(), and rval_expr_eval_rvint().

Here is the call graph for this function:

Here is the caller graph for this function:

int rval_get_int ( struct run_act_ctx *  h,
struct sip_msg msg,
int *  i,
struct rvalue *  rv,
struct rval_cache cache 
)

*i=(int)rv if rv == undefined select, avp or pvar, return 0. if an error occurs while evaluating a select, avp or pvar, behave as for the undefined case (and return success).

Parameters:
h - script context handle
msg - sip msg
i - pointer to int, where the conversion result will be stored
rv - rvalue to be converted
cache - cached rv value (read-only), can be 0
Returns:
0 on success, <0 on error and EXPR_DROP on drop

Definition at line 889 of file rvalue.c.

References rval_cache::avp_val, _str::len, rval_cache::pval, run_actions_safe(), and _str::s.

Referenced by rval_convert(), rval_expr_eval(), rval_expr_eval_int(), rval_expr_eval_rvint(), and rve_replace_with_ct_rv().

Here is the call graph for this function:

Here is the caller graph for this function:

int rval_get_str ( struct run_act_ctx *  h,
struct sip_msg msg,
str s,
struct rvalue *  rv,
struct rval_cache cache 
)

*s=(str)rv The result is pkg malloc'ed (so it should be pkg_free()'ed when finished.

Returns:
0 on success, <0 on error and EXPR_DROP on drop

Definition at line 1250 of file rvalue.c.

References _str::len, rval_cache_clean(), rval_cache_init, rval_get_tmp_str(), and _str::s.

Referenced by fix_match(), fix_match_rve(), and rve_replace_with_ct_rv().

Here is the call graph for this function:

Here is the caller graph for this function:

int rval_get_tmp_str ( struct run_act_ctx *  h,
struct sip_msg msg,
str tmpv,
struct rvalue *  rv,
struct rval_cache cache,
struct rval_cache tmp_cache 
)

get the string value of an rv in a tmp variable

if an error occurs while evaluating a select, avp or pvar, behave as for the undefined case (and return success). The result points either inside the passed rv, inside new_cache or inside an avp. new_cache must be non zero, initialized previously and it _must_ be rval_cache_clean(...)'ed when done. WARNING: it's not intended for general use. It might return a pointer inside rv so the result _must_ be treated as read-only. rv and new_cache must not be released/freed until the result is no longer needed. For general use see rval_get_str().

Parameters:
h - script context handle
msg - sip msg
tmpv - str return value (pointer to a str struct that will be be filled with the conversion result)
rv - rvalue to be converted
cache - cached rv value (read-only), can be 0
tmp_cache - used for temporary storage (so that tmpv will not point to possible freed data), it must be non-null, initialized and cleaned afterwards.
Returns:
0 on success, <0 on error and EXPR_DROP on drop

Definition at line 1102 of file rvalue.c.

References rval_cache::avp_val, rval_cache::i2s, _str::len, rval_cache::pval, run_actions_safe(), _str::s, and sint2strbuf().

Referenced by rval_convert(), and rval_get_str().

Here is the call graph for this function:

Here is the caller graph for this function:

void rval_init ( struct rvalue *  rv,
enum rval_type  t,
union rval_val *  v,
int  flags 
)

inits a rvalue structure-

Note: not needed if the structure is allocate with one of the rval_new* functions

Definition at line 208 of file rvalue.c.

Referenced by mk_rval_expr_v(), and rve_replace_with_val().

Here is the caller graph for this function:

struct rvalue* rval_new ( enum rval_type  t,
union rval_val *  v,
int  extra_size 
) [read]
Parameters:
t rvalue type
v rvalue value
extra_size extra space to allocate (so that future string operation can reuse the space)
Returns:
new rv or 0 on error

Definition at line 351 of file rvalue.c.

References rval_new_empty(), and rval_new_str().

Referenced by rval_convert(), rval_expr_eval(), rval_expr_eval_new(), rval_intop1(), rval_intop2(), and rval_str_add2().

Here is the call graph for this function:

Here is the caller graph for this function:

struct rvalue* rval_new_empty ( int  extra_size  )  [read]

allocates a new rval (should be freed by rval_destroy()).

Parameters:
extra_size - extra space to allocate (e.g.: so that future string operation can reuse the space)
Returns:
new rv or 0 on error

Definition at line 230 of file rvalue.c.

Referenced by rval_new(), rval_new_re(), and rval_new_str().

Here is the caller graph for this function:

struct rvalue* rval_new_str ( str s,
int  extra_size 
) [read]
Parameters:
s - pointer to str, must be non-null
extra_size - extra space to allocate (so that future string operation can reuse the space)
Returns:
new rv or 0 on error

Definition at line 256 of file rvalue.c.

References _str::len, rval_new_empty(), and _str::s.

Referenced by rval_convert(), and rval_new().

Here is the call graph for this function:

Here is the caller graph for this function:

char* rval_type_name ( enum rval_type  type  ) 

returns a string name for type (debugging).

Returns:
- null terminated name of the type

Definition at line 317 of file rvalue.c.

int rve_check_type ( enum rval_type *  type,
struct rval_expr *  rve,
struct rval_expr **  bad_rve,
enum rval_type *  bad_t,
enum rval_type *  exp_t 
)
Parameters:
type filled with the type of the expression (RV_INT, RV_STR or RV_NONE if it's dynamic)
rve checked expression
bad_rve set on failure to the subexpression for which the type check failed
bad_t set on failure to the type of the bad subexpression
exp_t set on failure to the expected type for the bad subexpression
Returns:
0 or 1 and sets *type to the resulting type (RV_INT, RV_STR or RV_NONE if it can be found only at runtime)

Definition at line 690 of file rvalue.c.

References RVE_BAND_OP, RVE_BLSHIFT_OP, RVE_BNOT_OP, RVE_BOOL_OP, RVE_BOR_OP, RVE_BRSHIFT_OP, RVE_BXOR_OP, rve_check_type(), RVE_CONCAT_OP, RVE_DEFINED_OP, RVE_DIFF_OP, RVE_DIV_OP, RVE_EQ_OP, RVE_GT_OP, RVE_GTE_OP, rve_guess_type(), RVE_IDIFF_OP, RVE_IEQ_OP, RVE_INT_OP, RVE_IPLUS_OP, RVE_LAND_OP, RVE_LNOT_OP, RVE_LOR_OP, RVE_LT_OP, RVE_LTE_OP, RVE_MATCH_OP, RVE_MINUS_OP, RVE_MOD_OP, RVE_MUL_OP, RVE_NONE_OP, RVE_PLUS_OP, RVE_RVAL_OP, RVE_STR_OP, RVE_STRDIFF_OP, RVE_STREMPTY_OP, RVE_STREQ_OP, RVE_STRLEN_OP, and RVE_UMINUS_OP.

Referenced by rve_check_type().

Here is the call graph for this function:

Here is the caller graph for this function:

void rve_destroy ( struct rval_expr *  rve  ) 

Definition at line 156 of file rvalue.c.

References rval_destroy(), rve_destroy(), and RVE_RVAL_OP.

Referenced by fix_match(), fix_switch(), rve_destroy(), rve_opt_01(), and rve_replace_with_val().

Here is the call graph for this function:

Here is the caller graph for this function:

enum rval_type rve_guess_type ( struct rval_expr *  rve  ) 
int rve_has_side_effects ( struct rval_expr *  rve  ) 

returns true if the expression can have side-effect

Returns:
1 for possible side-effects, 0 for no side-effects TODO: add better checks

Definition at line 617 of file rvalue.c.

References rve_is_constant().

Referenced by fix_match(), and fix_switch().

Here is the call graph for this function:

Here is the caller graph for this function:

int rve_is_constant ( struct rval_expr *  rve  )