• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

rvalue.h

Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2008 iptelorg GmbH
00003  *
00004  * Permission to use, copy, modify, and distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00009  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00010  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00011  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00012  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00013  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00014  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00015  */
00016  
00024 /* 
00025  * History:
00026  * --------
00027  *  2008-11-30  initial version (andrei)
00028  *  2009-04-28  added string and interger versions for the EQ and DIFF
00029  *              operators (andrei)
00030  *  2009-05-05  casts operator for int & string (andrei)
00031  *  2010-03-16  space for an int2str result inside rval_cache (andrei)
00032  */
00033 
00034 #ifndef _rvalue_h_
00035 #define _rvalue_h_
00036 
00037 #include "str.h"
00038 #include "ut.h"
00039 #include "usr_avp.h"
00040 #include "select.h"
00041 #include "pvar.h"
00042 #include "route.h"
00043 #include "parser/msg_parser.h"
00044 #include "action.h"
00045 
00046 enum rval_type{
00047         RV_NONE, RV_INT, RV_STR, /* basic types */
00048         RV_BEXPR, RV_ACTION_ST,  /* special values */
00049         RV_SEL, RV_AVP, RV_PVAR
00050 };
00051 
00052 enum rval_expr_op{
00053         RVE_NONE_OP,  
00054         RVE_RVAL_OP,  
00055         RVE_UMINUS_OP, 
00056         RVE_BOOL_OP,  
00057         RVE_LNOT_OP,  
00058         RVE_BNOT_OP,  
00059         RVE_MUL_OP,   
00060         RVE_DIV_OP,   
00061         RVE_MOD_OP,   
00062         RVE_MINUS_OP, 
00063         RVE_BAND_OP,  
00064         RVE_BOR_OP,   
00065         RVE_BXOR_OP,   
00066         RVE_BLSHIFT_OP, 
00067         RVE_BRSHIFT_OP, 
00068         RVE_LAND_OP,  
00069         RVE_LOR_OP,   
00070         RVE_GT_OP,    
00071         RVE_GTE_OP,   
00072         RVE_LT_OP,    
00073         RVE_LTE_OP,   
00074         RVE_IEQ_OP,   
00075         RVE_IDIFF_OP, 
00076         RVE_IPLUS_OP, 
00077         /* common int & str */
00078         RVE_PLUS_OP,  
00079         RVE_EQ_OP,    
00080         RVE_DIFF_OP,  
00081         /* str only */
00082         RVE_CONCAT_OP, 
00083         RVE_STRLEN_OP, 
00084         RVE_STREMPTY_OP, 
00085         RVE_STREQ_OP,  
00086         RVE_STRDIFF_OP,
00087         RVE_MATCH_OP,  
00088         /* avp, pvars a.s.o */
00089         RVE_DEFINED_OP, 
00090         RVE_INT_OP,   
00091         RVE_STR_OP    
00092 };
00093 
00094 
00095 struct str_re{
00096         str s;
00097         regex_t* regex;
00098 };
00099 
00100 union rval_val{
00101         void* p;
00102         long  l;
00103         str s;
00104         avp_spec_t avps;
00105         select_t sel;
00106         pv_spec_t pvs;
00107         struct action* action;
00108         struct expr* bexpr;
00109         struct str_re re;
00110 };
00111 
00112 
00113 struct rvalue{
00114         enum rval_type type;
00115         int refcnt; 
00116         union rval_val v;
00117         int bsize; 
00118         short flags;
00119         char buf[1]; 
00120 };
00121 
00122 
00123 /* rvalue flags */
00124 #define RV_CNT_ALLOCED_F  1  
00125 #define RV_RV_ALLOCED_F   2  
00126 #define RV_ALL_ALLOCED_F  (RV_CNT_ALLOCED|RV_RV_ALLOCED)
00127 #define RV_RE_F  4 
00128 #define RV_RE_ALLOCED_F 8 
00130 struct rval_expr{
00131         enum rval_expr_op op;
00132         union{
00133                 struct rval_expr* rve;
00134                 struct rvalue rval;
00135         }left;
00136         union{
00137                 struct rval_expr* rve;
00138                 struct rvalue rval;
00139         }right;
00140         struct cfg_pos fpos;
00141 };
00142 
00143 
00144 enum rval_cache_type{
00145         RV_CACHE_EMPTY,
00146         RV_CACHE_PVAR,
00147         RV_CACHE_AVP,
00148         RV_CACHE_SELECT,
00149         RV_CACHE_INT2STR
00150 };
00151 
00156 struct rval_cache{
00157         enum rval_cache_type cache_type;
00158         enum rval_type val_type;
00159         union{
00160                 int_str avp_val; 
00161                 pv_value_t pval; 
00162         }c;
00163         char i2s[INT2STR_MAX_LEN]; 
00164 };
00165 
00166 
00167 
00169 struct rvalue* rval_new_empty(int extra_size);
00170 struct rvalue* rval_new_str(str* s, int extra_size);
00171 
00180 struct rvalue* rval_new(enum rval_type t, union rval_val* v, int extra_size);
00181 
00183 void rval_init(struct rvalue* rv, enum rval_type t, union rval_val* v,
00184                                         int flags);
00186 void rval_destroy(struct rvalue* rv);
00187 
00189 void rval_clean(struct rvalue* rv);
00190 
00192 #define rval_cache_init(rvc) \
00193         do{ (rvc)->cache_type=RV_CACHE_EMPTY; (rvc)->val_type=RV_NONE; }while(0)
00194 
00196 void rval_cache_clean(struct rval_cache* rvc);
00197 
00198 
00216 struct rvalue* rval_convert(struct run_act_ctx* h, struct sip_msg* msg, 
00217                                                         enum rval_type type, struct rvalue* v,
00218                                                         struct rval_cache* c);
00219 
00221 int rval_get_int(struct run_act_ctx* h, struct sip_msg* msg, int* i, 
00222                                 struct rvalue* rv, struct rval_cache* cache);
00224 int rval_get_str(struct run_act_ctx* h, struct sip_msg* msg,
00225                                                                 str* s, struct rvalue* rv,
00226                                                                 struct rval_cache* cache);
00228 int rval_get_tmp_str(struct run_act_ctx* h, struct sip_msg* msg,
00229                                                                 str* tmpv, struct rvalue* rv,
00230                                                                 struct rval_cache* cache,
00231                                                                 struct rval_cache* tmp_cache);
00232 
00234 int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg,
00235                                                 int* res, struct rval_expr* rve);
00236 
00247 struct rvalue* rval_expr_eval(struct run_act_ctx* h, struct sip_msg* msg,
00248                                                                 struct rval_expr* rve);
00249 
00267 int rval_expr_eval_rvint( struct run_act_ctx* h, struct sip_msg* msg,
00268                                                  struct rvalue** rv_res, int* i_res,
00269                                                  struct rval_expr* rve, struct rval_cache* cache);
00270 
00271 
00273 enum rval_type rve_guess_type(struct rval_expr* rve);
00275 int rve_is_constant(struct rval_expr* rve);
00277 int rve_has_side_effects(struct rval_expr* rve);
00278 
00292 int rve_check_type(enum rval_type* type, struct rval_expr* rve,
00293                                         struct rval_expr** bad_rve, enum rval_type* bad_type,
00294                                         enum rval_type* exp_type);
00296 char* rval_type_name(enum rval_type type);
00297 
00300 struct rval_expr* mk_rval_expr_v(enum rval_type rv_type, void* val,
00301                                                                         struct cfg_pos* pos);
00302 
00311 struct rval_expr* mk_rval_expr1(enum rval_expr_op op, struct rval_expr* rve1,
00312                                                                         struct cfg_pos* pos);
00313 
00323 struct rval_expr* mk_rval_expr2(enum rval_expr_op op, struct rval_expr* rve1,
00324                                                                                                           struct rval_expr* rve2,
00325                                                                                                           struct cfg_pos* pos);
00327 void rve_destroy(struct rval_expr* rve);
00328 
00330 int fix_rval_expr(void* p);
00331 #endif /* _rvalue_h */

Generated on Tue May 22 2012 13:10:14 for SIP Router by  doxygen 1.7.1