- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,323 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2008 iptelorg GmbH |
|
3 |
- * |
|
4 |
- * Permission to use, copy, modify, and distribute this software for any |
|
5 |
- * purpose with or without fee is hereby granted, provided that the above |
|
6 |
- * copyright notice and this permission notice appear in all copies. |
|
7 |
- * |
|
8 |
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
9 |
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
10 |
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
11 |
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
12 |
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
13 |
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
14 |
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
15 |
- */ |
|
16 |
- |
|
17 |
-/** |
|
18 |
- * @file |
|
19 |
- * @brief Kamailio core :: rvalue expressions |
|
20 |
- * @ingroup core |
|
21 |
- * Module: \ref core |
|
22 |
- * @author andrei |
|
23 |
- */ |
|
24 |
- |
|
25 |
-#ifndef _rvalue_h_ |
|
26 |
-#define _rvalue_h_ |
|
27 |
- |
|
28 |
-#include "str.h" |
|
29 |
-#include "ut.h" |
|
30 |
-#include "usr_avp.h" |
|
31 |
-#include "select.h" |
|
32 |
-#include "pvar.h" |
|
33 |
-#include "route.h" |
|
34 |
-#include "parser/msg_parser.h" |
|
35 |
-#include "action.h" |
|
36 |
- |
|
37 |
-enum rval_type{ |
|
38 |
- RV_NONE, RV_INT, RV_STR, /* basic types */ |
|
39 |
- RV_BEXPR, RV_ACTION_ST, /* special values */ |
|
40 |
- RV_SEL, RV_AVP, RV_PVAR |
|
41 |
-}; |
|
42 |
- |
|
43 |
-enum rval_expr_op{ |
|
44 |
- RVE_NONE_OP, /**< uninit / empty */ |
|
45 |
- RVE_RVAL_OP, /**< special op, means that the expr. is in fact a rval */ |
|
46 |
- RVE_UMINUS_OP, /**< one member expression, returns -(val) */ |
|
47 |
- RVE_BOOL_OP, /**< one member evaluate as bool. : (val!=0)*/ |
|
48 |
- RVE_LNOT_OP, /**< one member evaluate as bool. : (!val)*/ |
|
49 |
- RVE_BNOT_OP, /**< one member evaluate as binary : (~ val)*/ |
|
50 |
- RVE_MUL_OP, /**< 2 members, returns left * right */ |
|
51 |
- RVE_DIV_OP, /**< 2 members, returns left / right */ |
|
52 |
- RVE_MOD_OP, /**< 2 members, returns left % right */ |
|
53 |
- RVE_MINUS_OP, /**< 2 members, returns left - right */ |
|
54 |
- RVE_BAND_OP, /**< 2 members, returns left | right */ |
|
55 |
- RVE_BOR_OP, /**< 2 members, returns left & right */ |
|
56 |
- RVE_BXOR_OP, /**< 2 members, returns left XOR right */ |
|
57 |
- RVE_BLSHIFT_OP, /**< 2 members, returns left << right */ |
|
58 |
- RVE_BRSHIFT_OP, /**< 2 members, returns left >> right */ |
|
59 |
- RVE_LAND_OP, /**< 2 members, returns left && right */ |
|
60 |
- RVE_LOR_OP, /**< 2 members, returns left || right */ |
|
61 |
- RVE_GT_OP, /**< 2 members, returns left > right */ |
|
62 |
- RVE_GTE_OP, /**< 2 members, returns left >= right */ |
|
63 |
- RVE_LT_OP, /**< 2 members, returns left < right */ |
|
64 |
- RVE_LTE_OP, /**< 2 members, returns left <= right */ |
|
65 |
- RVE_IEQ_OP, /**< 2 members, int == version, returns left == right */ |
|
66 |
- RVE_IDIFF_OP, /**< 2 members, int != version, returns left != right */ |
|
67 |
- RVE_IPLUS_OP, /**< 2 members, integer +, returns int(a)+int(b) */ |
|
68 |
- /* common int & str */ |
|
69 |
- RVE_PLUS_OP, /**< generic plus (int or str) returns left + right */ |
|
70 |
- RVE_EQ_OP, /**< 2 members, returns left == right (int)*/ |
|
71 |
- RVE_DIFF_OP, /**< 2 members, returns left != right (int)*/ |
|
72 |
- /* str only */ |
|
73 |
- RVE_CONCAT_OP, /**< 2 members, string concat, returns left . right (str)*/ |
|
74 |
- RVE_STRLEN_OP, /**< one member, string length:, returns strlen(val) (int)*/ |
|
75 |
- RVE_STREMPTY_OP, /**< one member, returns val=="" (bool) */ |
|
76 |
- RVE_STREQ_OP, /**< 2 members, string == , returns left == right (bool)*/ |
|
77 |
- RVE_STRDIFF_OP,/**< 2 members, string != , returns left != right (bool)*/ |
|
78 |
- RVE_MATCH_OP, /**< 2 members, string ~), returns left matches re(right) */ |
|
79 |
- /* avp, pvars a.s.o */ |
|
80 |
- RVE_DEFINED_OP, /**< one member, returns is_defined(val) (bool) */ |
|
81 |
- RVE_NOTDEFINED_OP, /**< one member, returns is_not_defined(val) (bool) */ |
|
82 |
- RVE_INT_OP, /**< one member, returns (int)val (int) */ |
|
83 |
- RVE_STR_OP /**< one member, returns (str)val (str) */ |
|
84 |
-}; |
|
85 |
- |
|
86 |
- |
|
87 |
-struct str_re{ |
|
88 |
- str s; |
|
89 |
- regex_t* regex; |
|
90 |
-}; |
|
91 |
- |
|
92 |
-union rval_val{ |
|
93 |
- void* p; |
|
94 |
- long l; |
|
95 |
- str s; |
|
96 |
- avp_spec_t avps; |
|
97 |
- select_t sel; |
|
98 |
- pv_spec_t pvs; |
|
99 |
- struct action* action; |
|
100 |
- struct expr* bexpr; |
|
101 |
- struct str_re re; |
|
102 |
-}; |
|
103 |
- |
|
104 |
- |
|
105 |
-struct rvalue{ |
|
106 |
- enum rval_type type; |
|
107 |
- int refcnt; /**< refcnt, on 0 the structure is destroyed */ |
|
108 |
- union rval_val v; |
|
109 |
- int bsize; /**< extra data size */ |
|
110 |
- short flags; |
|
111 |
- char buf[1]; /**< extra data, like string contents can be stored here */ |
|
112 |
-}; |
|
113 |
- |
|
114 |
- |
|
115 |
-/* rvalue flags */ |
|
116 |
-#define RV_CNT_ALLOCED_F 1 /**< free contents (pkg mem allocated) */ |
|
117 |
-#define RV_RV_ALLOCED_F 2 /**< free rv itself (pkg_free(rv)) */ |
|
118 |
-#define RV_ALL_ALLOCED_F (RV_CNT_ALLOCED|RV_RV_ALLOCED) |
|
119 |
-#define RV_RE_F 4 /**< string is a RE with a valid v->re member */ |
|
120 |
-#define RV_RE_ALLOCED_F 8 /**< v->re.regex must be freed */ |
|
121 |
- |
|
122 |
-struct rval_expr{ |
|
123 |
- enum rval_expr_op op; |
|
124 |
- union{ |
|
125 |
- struct rval_expr* rve; |
|
126 |
- struct rvalue rval; |
|
127 |
- }left; |
|
128 |
- union{ |
|
129 |
- struct rval_expr* rve; |
|
130 |
- struct rvalue rval; |
|
131 |
- }right; |
|
132 |
- struct cfg_pos fpos; |
|
133 |
-}; |
|
134 |
- |
|
135 |
- |
|
136 |
-enum rval_cache_type{ |
|
137 |
- RV_CACHE_EMPTY, |
|
138 |
- RV_CACHE_PVAR, |
|
139 |
- RV_CACHE_AVP, |
|
140 |
- RV_CACHE_SELECT, |
|
141 |
- RV_CACHE_INT2STR |
|
142 |
-}; |
|
143 |
- |
|
144 |
-/** value cache for a rvalue struct. |
|
145 |
- * Used to optimize functions that would need to |
|
146 |
- * get the value repeatedly (e.g. rval_get_btype() and then rval_get_int()) |
|
147 |
- */ |
|
148 |
-struct rval_cache{ |
|
149 |
- enum rval_cache_type cache_type; |
|
150 |
- enum rval_type val_type; |
|
151 |
- union{ |
|
152 |
- int_str avp_val; /**< avp value */ |
|
153 |
- pv_value_t pval; /**< pvar value */ |
|
154 |
- }c; |
|
155 |
- char i2s[INT2STR_MAX_LEN]; /**< space for converting an int to string*/ |
|
156 |
-}; |
|
157 |
- |
|
158 |
- |
|
159 |
- |
|
160 |
-/** allocates a new rval (should be freed by rval_destroy()). */ |
|
161 |
-struct rvalue* rval_new_empty(int extra_size); |
|
162 |
-struct rvalue* rval_new_str(str* s, int extra_size); |
|
163 |
- |
|
164 |
-/** |
|
165 |
- * @brief create a new pk_malloc'ed rvalue from a rval_val union |
|
166 |
- * @param t rvalue type |
|
167 |
- * @param v rvalue value |
|
168 |
- * @param extra_size extra space to allocate |
|
169 |
- * (so that future string operation can reuse the space) |
|
170 |
- * @return new rv or 0 on error |
|
171 |
- */ |
|
172 |
-struct rvalue* rval_new(enum rval_type t, union rval_val* v, int extra_size); |
|
173 |
- |
|
174 |
-/** inits a rvalue structure- */ |
|
175 |
-void rval_init(struct rvalue* rv, enum rval_type t, union rval_val* v, |
|
176 |
- int flags); |
|
177 |
-/** frees a rval_new(), rval_convert() or rval_expr_eval() returned rval. */ |
|
178 |
-void rval_destroy(struct rvalue* rv); |
|
179 |
- |
|
180 |
-/** frees a rval contents */ |
|
181 |
-void rval_clean(struct rvalue* rv); |
|
182 |
- |
|
183 |
-/** init a rval_cache struct */ |
|
184 |
-#define rval_cache_init(rvc) \ |
|
185 |
- do{ (rvc)->cache_type=RV_CACHE_EMPTY; (rvc)->val_type=RV_NONE; }while(0) |
|
186 |
- |
|
187 |
-/** destroy a rval_cache struct contents */ |
|
188 |
-void rval_cache_clean(struct rval_cache* rvc); |
|
189 |
- |
|
190 |
- |
|
191 |
-/** |
|
192 |
- * @brief Convert a rvalue to another rvalue, of a specific type |
|
193 |
- * |
|
194 |
- * Convert a rvalue to another rvalue, of a specific type. |
|
195 |
- * The result is read-only in most cases (can be a reference |
|
196 |
- * to another rvalue, can be checked by using rv_chg_in_place()) and |
|
197 |
- * _must_ be rval_destroy()'ed. |
|
198 |
- * |
|
199 |
- * @param h run action context |
|
200 |
- * @param msg SIP mesasge |
|
201 |
- * @param type - type to convert to |
|
202 |
- * @param v - rvalue to convert |
|
203 |
- * @param c - rval_cache (cached v value if known/filled by another |
|
204 |
- * function), can be 0 (unknown/not needed) |
|
205 |
- * @return pointer to a rvalue (reference to an existing one or a new |
|
206 |
- * one, @see rv_chg_in_place() and the above comment), or 0 on error. |
|
207 |
- */ |
|
208 |
-struct rvalue* rval_convert(struct run_act_ctx* h, struct sip_msg* msg, |
|
209 |
- enum rval_type type, struct rvalue* v, |
|
210 |
- struct rval_cache* c); |
|
211 |
- |
|
212 |
-/** get the integer value of an rvalue. */ |
|
213 |
-int rval_get_int(struct run_act_ctx* h, struct sip_msg* msg, int* i, |
|
214 |
- struct rvalue* rv, struct rval_cache* cache); |
|
215 |
-/** get the string value of an rv. */ |
|
216 |
-int rval_get_str(struct run_act_ctx* h, struct sip_msg* msg, |
|
217 |
- str* s, struct rvalue* rv, |
|
218 |
- struct rval_cache* cache); |
|
219 |
-/** get the string value of an rv in a tmp variable */ |
|
220 |
-int rval_get_tmp_str(struct run_act_ctx* h, struct sip_msg* msg, |
|
221 |
- str* tmpv, struct rvalue* rv, |
|
222 |
- struct rval_cache* cache, |
|
223 |
- struct rval_cache* tmp_cache); |
|
224 |
- |
|
225 |
-/** evals an integer expr to an int. */ |
|
226 |
-int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, |
|
227 |
- int* res, struct rval_expr* rve); |
|
228 |
- |
|
229 |
-/** |
|
230 |
- * @brief Evals a rval expression |
|
231 |
- * @warning result must be rval_destroy()'ed if non-null (it might be |
|
232 |
- * a reference to another rval). The result can be modified only |
|
233 |
- * if rv_chg_in_place() returns true. |
|
234 |
- * @param h run action context |
|
235 |
- * @param msg SIP message |
|
236 |
- * @param rve rvalue expression |
|
237 |
- * @return rvalue on success, 0 on error |
|
238 |
- */ |
|
239 |
-struct rvalue* rval_expr_eval(struct run_act_ctx* h, struct sip_msg* msg, |
|
240 |
- struct rval_expr* rve); |
|
241 |
- |
|
242 |
-/** |
|
243 |
- * @brief Evals a rval expression into an int or another rv(str) |
|
244 |
- * @warning rv result (rv_res) must be rval_destroy()'ed if non-null |
|
245 |
- * (it might be a reference to another rval). The result can be |
|
246 |
- * modified only if rv_chg_in_place() returns true. |
|
247 |
- * @param h run action context |
|
248 |
- * @param msg SIP message |
|
249 |
- * @param res_rv pointer to rvalue result, if non-null it means the |
|
250 |
- * expression evaluated to a non-int (str), which will be stored here. |
|
251 |
- * @param res_i pointer to int result, if res_rv==0 and the function |
|
252 |
- * returns success => the result is an int which will be stored here. |
|
253 |
- * @param rve expression that will be evaluated. |
|
254 |
- * @param cache write-only value cache, it might be filled if non-null and |
|
255 |
- * empty (rval_cache_init()). If non-null, it _must_ be rval_cache_clean()'ed |
|
256 |
- * when done. |
|
257 |
- * @return 0 on success, -1 on error, sets *res_rv or *res_i. |
|
258 |
- */ |
|
259 |
-int rval_expr_eval_rvint( struct run_act_ctx* h, struct sip_msg* msg, |
|
260 |
- struct rvalue** rv_res, int* i_res, |
|
261 |
- struct rval_expr* rve, struct rval_cache* cache); |
|
262 |
- |
|
263 |
- |
|
264 |
-/** guess the type of an expression. */ |
|
265 |
-enum rval_type rve_guess_type(struct rval_expr* rve); |
|
266 |
-/** returns true if expression is constant. */ |
|
267 |
-int rve_is_constant(struct rval_expr* rve); |
|
268 |
-/** returns true if the expression can have side-effect */ |
|
269 |
-int rve_has_side_effects(struct rval_expr* rve); |
|
270 |
- |
|
271 |
-/** |
|
272 |
- * @brief Returns 1 if expression is valid (type-wise) |
|
273 |
- * @param type filled with the type of the expression (RV_INT, RV_STR or |
|
274 |
- * RV_NONE if it's dynamic) |
|
275 |
- * @param rve checked expression |
|
276 |
- * @param bad_rve set on failure to the subexpression for which the |
|
277 |
- * type check failed |
|
278 |
- * @param bad_t set on failure to the type of the bad subexpression |
|
279 |
- * @param exp_t set on failure to the expected type for the bad |
|
280 |
- * subexpression |
|
281 |
- * @return 0 or 1 and sets *type to the resulting type |
|
282 |
- * (RV_INT, RV_STR or RV_NONE if it can be found only at runtime) |
|
283 |
- */ |
|
284 |
-int rve_check_type(enum rval_type* type, struct rval_expr* rve, |
|
285 |
- struct rval_expr** bad_rve, enum rval_type* bad_type, |
|
286 |
- enum rval_type* exp_type); |
|
287 |
-/** returns a string name for type (debugging).*/ |
|
288 |
-char* rval_type_name(enum rval_type type); |
|
289 |
- |
|
290 |
-/** create a RVE_RVAL_OP rval_expr, containing a single rval of the given type |
|
291 |
- */ |
|
292 |
-struct rval_expr* mk_rval_expr_v(enum rval_type rv_type, void* val, |
|
293 |
- struct cfg_pos* pos); |
|
294 |
- |
|
295 |
-/** |
|
296 |
- * @brief Create a unary op. rval_expr |
|
297 |
- * ret= op rve1 |
|
298 |
- * @param op - rval expr. unary operator |
|
299 |
- * @param rve1 - rval expr. on which the operator will act. |
|
300 |
- * @param pos configuration position |
|
301 |
- * @return new pkg_malloc'ed rval_expr or 0 on error. |
|
302 |
- */ |
|
303 |
-struct rval_expr* mk_rval_expr1(enum rval_expr_op op, struct rval_expr* rve1, |
|
304 |
- struct cfg_pos* pos); |
|
305 |
- |
|
306 |
-/** |
|
307 |
- * @brief Create a rval_expr. from 2 other rval exprs, using op |
|
308 |
- * ret = rve1 op rve2 |
|
309 |
- * @param op - rval expr. operator |
|
310 |
- * @param rve1 - rval expr. on which the operator will act. |
|
311 |
- * @param rve2 - rval expr. on which the operator will act. |
|
312 |
- * @param pos configuration position |
|
313 |
- * @return new pkg_malloc'ed rval_expr or 0 on error. |
|
314 |
- */ |
|
315 |
-struct rval_expr* mk_rval_expr2(enum rval_expr_op op, struct rval_expr* rve1, |
|
316 |
- struct rval_expr* rve2, |
|
317 |
- struct cfg_pos* pos); |
|
318 |
-/** destroys a pkg_malloc'ed rve. */ |
|
319 |
-void rve_destroy(struct rval_expr* rve); |
|
320 |
- |
|
321 |
-/** fix a rval_expr. */ |
|
322 |
-int fix_rval_expr(void* p); |
|
323 |
-#endif /* _rvalue_h */ |
... | ... |
@@ -19,18 +19,9 @@ |
19 | 19 |
* @brief SIP-router core :: rvalue expressions |
20 | 20 |
* @ingroup core |
21 | 21 |
* Module: \ref core |
22 |
+ * @author andrei |
|
22 | 23 |
*/ |
23 | 24 |
|
24 |
-/* |
|
25 |
- * History: |
|
26 |
- * -------- |
|
27 |
- * 2008-11-30 initial version (andrei) |
|
28 |
- * 2009-04-28 added string and interger versions for the EQ and DIFF |
|
29 |
- * operators (andrei) |
|
30 |
- * 2009-05-05 casts operator for int & string (andrei) |
|
31 |
- * 2010-03-16 space for an int2str result inside rval_cache (andrei) |
|
32 |
- */ |
|
33 |
- |
|
34 | 25 |
#ifndef _rvalue_h_ |
35 | 26 |
#define _rvalue_h_ |
36 | 27 |
|
- reported by Victor Seva, closes FS#358
... | ... |
@@ -87,6 +87,7 @@ enum rval_expr_op{ |
87 | 87 |
RVE_MATCH_OP, /**< 2 members, string ~), returns left matches re(right) */ |
88 | 88 |
/* avp, pvars a.s.o */ |
89 | 89 |
RVE_DEFINED_OP, /**< one member, returns is_defined(val) (bool) */ |
90 |
+ RVE_NOTDEFINED_OP, /**< one member, returns is_not_defined(val) (bool) */ |
|
90 | 91 |
RVE_INT_OP, /**< one member, returns (int)val (int) */ |
91 | 92 |
RVE_STR_OP /**< one member, returns (str)val (str) */ |
92 | 93 |
}; |
... | ... |
@@ -16,7 +16,9 @@ |
16 | 16 |
|
17 | 17 |
/** |
18 | 18 |
* @file |
19 |
- * @brief rvalue expressions |
|
19 |
+ * @brief SIP-router core :: rvalue expressions |
|
20 |
+ * @ingroup core |
|
21 |
+ * Module: \ref core |
|
20 | 22 |
*/ |
21 | 23 |
|
22 | 24 |
/* |
... | ... |
@@ -48,45 +50,45 @@ enum rval_type{ |
48 | 50 |
}; |
49 | 51 |
|
50 | 52 |
enum rval_expr_op{ |
51 |
- RVE_NONE_OP, /* uninit / empty */ |
|
52 |
- RVE_RVAL_OP, /* special op, means that the expr. is in fact a rval */ |
|
53 |
- RVE_UMINUS_OP, /* one member expression, returns -(val) */ |
|
54 |
- RVE_BOOL_OP, /* one member evaluate as bool. : (val!=0)*/ |
|
55 |
- RVE_LNOT_OP, /* one member evaluate as bool. : (!val)*/ |
|
56 |
- RVE_BNOT_OP, /* one member evaluate as binary : (~ val)*/ |
|
57 |
- RVE_MUL_OP, /* 2 members, returns left * right */ |
|
58 |
- RVE_DIV_OP, /* 2 members, returns left / right */ |
|
59 |
- RVE_MOD_OP, /* 2 members, returns left % right */ |
|
60 |
- RVE_MINUS_OP, /* 2 members, returns left - right */ |
|
61 |
- RVE_BAND_OP, /* 2 members, returns left | right */ |
|
62 |
- RVE_BOR_OP, /* 2 members, returns left & right */ |
|
63 |
- RVE_BXOR_OP, /* 2 members, returns left XOR right */ |
|
64 |
- RVE_BLSHIFT_OP, /* 2 members, returns left << right */ |
|
65 |
- RVE_BRSHIFT_OP, /* 2 members, returns left >> right */ |
|
66 |
- RVE_LAND_OP, /* 2 members, returns left && right */ |
|
67 |
- RVE_LOR_OP, /* 2 members, returns left || right */ |
|
68 |
- RVE_GT_OP, /* 2 members, returns left > right */ |
|
69 |
- RVE_GTE_OP, /* 2 members, returns left >= right */ |
|
70 |
- RVE_LT_OP, /* 2 members, returns left < right */ |
|
71 |
- RVE_LTE_OP, /* 2 members, returns left <= right */ |
|
72 |
- RVE_IEQ_OP, /* 2 members, int == version, returns left == right */ |
|
73 |
- RVE_IDIFF_OP,/* 2 members, int != version, returns left != right */ |
|
74 |
- RVE_IPLUS_OP, /* 2 members, integer +, returns int(a)+int(b) */ |
|
53 |
+ RVE_NONE_OP, /**< uninit / empty */ |
|
54 |
+ RVE_RVAL_OP, /**< special op, means that the expr. is in fact a rval */ |
|
55 |
+ RVE_UMINUS_OP, /**< one member expression, returns -(val) */ |
|
56 |
+ RVE_BOOL_OP, /**< one member evaluate as bool. : (val!=0)*/ |
|
57 |
+ RVE_LNOT_OP, /**< one member evaluate as bool. : (!val)*/ |
|
58 |
+ RVE_BNOT_OP, /**< one member evaluate as binary : (~ val)*/ |
|
59 |
+ RVE_MUL_OP, /**< 2 members, returns left * right */ |
|
60 |
+ RVE_DIV_OP, /**< 2 members, returns left / right */ |
|
61 |
+ RVE_MOD_OP, /**< 2 members, returns left % right */ |
|
62 |
+ RVE_MINUS_OP, /**< 2 members, returns left - right */ |
|
63 |
+ RVE_BAND_OP, /**< 2 members, returns left | right */ |
|
64 |
+ RVE_BOR_OP, /**< 2 members, returns left & right */ |
|
65 |
+ RVE_BXOR_OP, /**< 2 members, returns left XOR right */ |
|
66 |
+ RVE_BLSHIFT_OP, /**< 2 members, returns left << right */ |
|
67 |
+ RVE_BRSHIFT_OP, /**< 2 members, returns left >> right */ |
|
68 |
+ RVE_LAND_OP, /**< 2 members, returns left && right */ |
|
69 |
+ RVE_LOR_OP, /**< 2 members, returns left || right */ |
|
70 |
+ RVE_GT_OP, /**< 2 members, returns left > right */ |
|
71 |
+ RVE_GTE_OP, /**< 2 members, returns left >= right */ |
|
72 |
+ RVE_LT_OP, /**< 2 members, returns left < right */ |
|
73 |
+ RVE_LTE_OP, /**< 2 members, returns left <= right */ |
|
74 |
+ RVE_IEQ_OP, /**< 2 members, int == version, returns left == right */ |
|
75 |
+ RVE_IDIFF_OP, /**< 2 members, int != version, returns left != right */ |
|
76 |
+ RVE_IPLUS_OP, /**< 2 members, integer +, returns int(a)+int(b) */ |
|
75 | 77 |
/* common int & str */ |
76 |
- RVE_PLUS_OP, /* generic plus (int or str) returns left + right */ |
|
77 |
- RVE_EQ_OP, /* 2 members, returns left == right (int)*/ |
|
78 |
- RVE_DIFF_OP, /* 2 members, returns left != right (int)*/ |
|
78 |
+ RVE_PLUS_OP, /**< generic plus (int or str) returns left + right */ |
|
79 |
+ RVE_EQ_OP, /**< 2 members, returns left == right (int)*/ |
|
80 |
+ RVE_DIFF_OP, /**< 2 members, returns left != right (int)*/ |
|
79 | 81 |
/* str only */ |
80 |
- RVE_CONCAT_OP,/* 2 members, string concat, returns left . right (str)*/ |
|
81 |
- RVE_STRLEN_OP, /* one member, string length:, returns strlen(val) (int)*/ |
|
82 |
- RVE_STREMPTY_OP, /* one member, returns val=="" (bool) */ |
|
83 |
- RVE_STREQ_OP, /* 2 members, string == , returns left == right (bool)*/ |
|
84 |
- RVE_STRDIFF_OP,/* 2 members, string != , returns left != right (bool)*/ |
|
85 |
- RVE_MATCH_OP, /* 2 members, string ~), returns left matches re(right) */ |
|
82 |
+ RVE_CONCAT_OP, /**< 2 members, string concat, returns left . right (str)*/ |
|
83 |
+ RVE_STRLEN_OP, /**< one member, string length:, returns strlen(val) (int)*/ |
|
84 |
+ RVE_STREMPTY_OP, /**< one member, returns val=="" (bool) */ |
|
85 |
+ RVE_STREQ_OP, /**< 2 members, string == , returns left == right (bool)*/ |
|
86 |
+ RVE_STRDIFF_OP,/**< 2 members, string != , returns left != right (bool)*/ |
|
87 |
+ RVE_MATCH_OP, /**< 2 members, string ~), returns left matches re(right) */ |
|
86 | 88 |
/* avp, pvars a.s.o */ |
87 |
- RVE_DEFINED_OP, /* one member, returns is_defined(val) (bool) */ |
|
88 |
- RVE_INT_OP, /* one member, returns (int)val (int) */ |
|
89 |
- RVE_STR_OP /* one member, returns (str)val (str) */ |
|
89 |
+ RVE_DEFINED_OP, /**< one member, returns is_defined(val) (bool) */ |
|
90 |
+ RVE_INT_OP, /**< one member, returns (int)val (int) */ |
|
91 |
+ RVE_STR_OP /**< one member, returns (str)val (str) */ |
|
90 | 92 |
}; |
91 | 93 |
|
92 | 94 |
|
... | ... |
@@ -119,12 +121,11 @@ struct rvalue{ |
119 | 121 |
|
120 | 122 |
|
121 | 123 |
/* rvalue flags */ |
122 |
-#define RV_CNT_ALLOCED_F 1 /* free contents (pkg mem allocated) */ |
|
123 |
-#define RV_RV_ALLOCED_F 2 /* free rv itself (pkg_free(rv)) */ |
|
124 |
+#define RV_CNT_ALLOCED_F 1 /**< free contents (pkg mem allocated) */ |
|
125 |
+#define RV_RV_ALLOCED_F 2 /**< free rv itself (pkg_free(rv)) */ |
|
124 | 126 |
#define RV_ALL_ALLOCED_F (RV_CNT_ALLOCED|RV_RV_ALLOCED) |
125 |
-#define RV_RE_F 4 /* string is a RE with a valid v->re member */ |
|
126 |
-#define RV_RE_ALLOCED_F 8 /* v->re.regex must be freed */ |
|
127 |
- |
|
127 |
+#define RV_RE_F 4 /**< string is a RE with a valid v->re member */ |
|
128 |
+#define RV_RE_ALLOCED_F 8 /**< v->re.regex must be freed */ |
|
128 | 129 |
|
129 | 130 |
struct rval_expr{ |
130 | 131 |
enum rval_expr_op op; |
... | ... |
@@ -167,6 +168,15 @@ struct rval_cache{ |
167 | 168 |
/** allocates a new rval (should be freed by rval_destroy()). */ |
168 | 169 |
struct rvalue* rval_new_empty(int extra_size); |
169 | 170 |
struct rvalue* rval_new_str(str* s, int extra_size); |
171 |
+ |
|
172 |
+/** |
|
173 |
+ * @brief create a new pk_malloc'ed rvalue from a rval_val union |
|
174 |
+ * @param t rvalue type |
|
175 |
+ * @param v rvalue value |
|
176 |
+ * @param extra_size extra space to allocate |
|
177 |
+ * (so that future string operation can reuse the space) |
|
178 |
+ * @return new rv or 0 on error |
|
179 |
+ */ |
|
170 | 180 |
struct rvalue* rval_new(enum rval_type t, union rval_val* v, int extra_size); |
171 | 181 |
|
172 | 182 |
/** inits a rvalue structure- */ |
... | ... |
@@ -186,7 +196,23 @@ void rval_clean(struct rvalue* rv); |
186 | 196 |
void rval_cache_clean(struct rval_cache* rvc); |
187 | 197 |
|
188 | 198 |
|
189 |
-/** convert a rvalue to another type. */ |
|
199 |
+/** |
|
200 |
+ * @brief Convert a rvalue to another rvalue, of a specific type |
|
201 |
+ * |
|
202 |
+ * Convert a rvalue to another rvalue, of a specific type. |
|
203 |
+ * The result is read-only in most cases (can be a reference |
|
204 |
+ * to another rvalue, can be checked by using rv_chg_in_place()) and |
|
205 |
+ * _must_ be rval_destroy()'ed. |
|
206 |
+ * |
|
207 |
+ * @param h run action context |
|
208 |
+ * @param msg SIP mesasge |
|
209 |
+ * @param type - type to convert to |
|
210 |
+ * @param v - rvalue to convert |
|
211 |
+ * @param c - rval_cache (cached v value if known/filled by another |
|
212 |
+ * function), can be 0 (unknown/not needed) |
|
213 |
+ * @return pointer to a rvalue (reference to an existing one or a new |
|
214 |
+ * one, @see rv_chg_in_place() and the above comment), or 0 on error. |
|
215 |
+ */ |
|
190 | 216 |
struct rvalue* rval_convert(struct run_act_ctx* h, struct sip_msg* msg, |
191 | 217 |
enum rval_type type, struct rvalue* v, |
192 | 218 |
struct rval_cache* c); |
... | ... |
@@ -207,10 +233,37 @@ int rval_get_tmp_str(struct run_act_ctx* h, struct sip_msg* msg, |
207 | 233 |
/** evals an integer expr to an int. */ |
208 | 234 |
int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, |
209 | 235 |
int* res, struct rval_expr* rve); |
210 |
-/** evals a rval expr.. */ |
|
236 |
+ |
|
237 |
+/** |
|
238 |
+ * @brief Evals a rval expression |
|
239 |
+ * @warning result must be rval_destroy()'ed if non-null (it might be |
|
240 |
+ * a reference to another rval). The result can be modified only |
|
241 |
+ * if rv_chg_in_place() returns true. |
|
242 |
+ * @param h run action context |
|
243 |
+ * @param msg SIP message |
|
244 |
+ * @param rve rvalue expression |
|
245 |
+ * @return rvalue on success, 0 on error |
|
246 |
+ */ |
|
211 | 247 |
struct rvalue* rval_expr_eval(struct run_act_ctx* h, struct sip_msg* msg, |
212 | 248 |
struct rval_expr* rve); |
213 |
-/** evals an integer expr to an int or rvalue. */ |
|
249 |
+ |
|
250 |
+/** |
|
251 |
+ * @brief Evals a rval expression into an int or another rv(str) |
|
252 |
+ * @warning rv result (rv_res) must be rval_destroy()'ed if non-null |
|
253 |
+ * (it might be a reference to another rval). The result can be |
|
254 |
+ * modified only if rv_chg_in_place() returns true. |
|
255 |
+ * @param h run action context |
|
256 |
+ * @param msg SIP message |
|
257 |
+ * @param res_rv pointer to rvalue result, if non-null it means the |
|
258 |
+ * expression evaluated to a non-int (str), which will be stored here. |
|
259 |
+ * @param res_i pointer to int result, if res_rv==0 and the function |
|
260 |
+ * returns success => the result is an int which will be stored here. |
|
261 |
+ * @param rve expression that will be evaluated. |
|
262 |
+ * @param cache write-only value cache, it might be filled if non-null and |
|
263 |
+ * empty (rval_cache_init()). If non-null, it _must_ be rval_cache_clean()'ed |
|
264 |
+ * when done. |
|
265 |
+ * @return 0 on success, -1 on error, sets *res_rv or *res_i. |
|
266 |
+ */ |
|
214 | 267 |
int rval_expr_eval_rvint( struct run_act_ctx* h, struct sip_msg* msg, |
215 | 268 |
struct rvalue** rv_res, int* i_res, |
216 | 269 |
struct rval_expr* rve, struct rval_cache* cache); |
... | ... |
@@ -222,7 +275,20 @@ enum rval_type rve_guess_type(struct rval_expr* rve); |
222 | 275 |
int rve_is_constant(struct rval_expr* rve); |
223 | 276 |
/** returns true if the expression can have side-effect */ |
224 | 277 |
int rve_has_side_effects(struct rval_expr* rve); |
225 |
-/** returns 1 if expression is valid (type-wise).*/ |
|
278 |
+ |
|
279 |
+/** |
|
280 |
+ * @brief Returns 1 if expression is valid (type-wise) |
|
281 |
+ * @param type filled with the type of the expression (RV_INT, RV_STR or |
|
282 |
+ * RV_NONE if it's dynamic) |
|
283 |
+ * @param rve checked expression |
|
284 |
+ * @param bad_rve set on failure to the subexpression for which the |
|
285 |
+ * type check failed |
|
286 |
+ * @param bad_t set on failure to the type of the bad subexpression |
|
287 |
+ * @param exp_t set on failure to the expected type for the bad |
|
288 |
+ * subexpression |
|
289 |
+ * @return 0 or 1 and sets *type to the resulting type |
|
290 |
+ * (RV_INT, RV_STR or RV_NONE if it can be found only at runtime) |
|
291 |
+ */ |
|
226 | 292 |
int rve_check_type(enum rval_type* type, struct rval_expr* rve, |
227 | 293 |
struct rval_expr** bad_rve, enum rval_type* bad_type, |
228 | 294 |
enum rval_type* exp_type); |
... | ... |
@@ -233,10 +299,27 @@ char* rval_type_name(enum rval_type type); |
233 | 299 |
*/ |
234 | 300 |
struct rval_expr* mk_rval_expr_v(enum rval_type rv_type, void* val, |
235 | 301 |
struct cfg_pos* pos); |
236 |
-/** create a unary op. rval_expr.. */ |
|
302 |
+ |
|
303 |
+/** |
|
304 |
+ * @brief Create a unary op. rval_expr |
|
305 |
+ * ret= op rve1 |
|
306 |
+ * @param op - rval expr. unary operator |
|
307 |
+ * @param rve1 - rval expr. on which the operator will act. |
|
308 |
+ * @param pos configuration position |
|
309 |
+ * @return new pkg_malloc'ed rval_expr or 0 on error. |
|
310 |
+ */ |
|
237 | 311 |
struct rval_expr* mk_rval_expr1(enum rval_expr_op op, struct rval_expr* rve1, |
238 | 312 |
struct cfg_pos* pos); |
239 |
-/** create a rval_expr. from 2 other rval exprs, using op. */ |
|
313 |
+ |
|
314 |
+/** |
|
315 |
+ * @brief Create a rval_expr. from 2 other rval exprs, using op |
|
316 |
+ * ret = rve1 op rve2 |
|
317 |
+ * @param op - rval expr. operator |
|
318 |
+ * @param rve1 - rval expr. on which the operator will act. |
|
319 |
+ * @param rve2 - rval expr. on which the operator will act. |
|
320 |
+ * @param pos configuration position |
|
321 |
+ * @return new pkg_malloc'ed rval_expr or 0 on error. |
|
322 |
+ */ |
|
240 | 323 |
struct rval_expr* mk_rval_expr2(enum rval_expr_op op, struct rval_expr* rve1, |
241 | 324 |
struct rval_expr* rve2, |
242 | 325 |
struct cfg_pos* pos); |
... | ... |
@@ -1,6 +1,4 @@ |
1 | 1 |
/* |
2 |
- * $Id$ |
|
3 |
- * |
|
4 | 2 |
* Copyright (C) 2008 iptelorg GmbH |
5 | 3 |
* |
6 | 4 |
* Permission to use, copy, modify, and distribute this software for any |
... | ... |
@@ -15,10 +13,12 @@ |
15 | 13 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
16 | 14 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 | 15 |
*/ |
16 |
+ |
|
18 | 17 |
/** |
19 | 18 |
* @file |
20 | 19 |
* @brief rvalue expressions |
21 | 20 |
*/ |
21 |
+ |
|
22 | 22 |
/* |
23 | 23 |
* History: |
24 | 24 |
* -------- |
- not, xor, left shift and right shift
... | ... |
@@ -53,12 +53,16 @@ enum rval_expr_op{ |
53 | 53 |
RVE_UMINUS_OP, /* one member expression, returns -(val) */ |
54 | 54 |
RVE_BOOL_OP, /* one member evaluate as bool. : (val!=0)*/ |
55 | 55 |
RVE_LNOT_OP, /* one member evaluate as bool. : (!val)*/ |
56 |
+ RVE_BNOT_OP, /* one member evaluate as binary : (~ val)*/ |
|
56 | 57 |
RVE_MUL_OP, /* 2 members, returns left * right */ |
57 | 58 |
RVE_DIV_OP, /* 2 members, returns left / right */ |
58 | 59 |
RVE_MOD_OP, /* 2 members, returns left % right */ |
59 | 60 |
RVE_MINUS_OP, /* 2 members, returns left - right */ |
60 | 61 |
RVE_BAND_OP, /* 2 members, returns left | right */ |
61 | 62 |
RVE_BOR_OP, /* 2 members, returns left & right */ |
63 |
+ RVE_BXOR_OP, /* 2 members, returns left XOR right */ |
|
64 |
+ RVE_BLSHIFT_OP, /* 2 members, returns left << right */ |
|
65 |
+ RVE_BRSHIFT_OP, /* 2 members, returns left >> right */ |
|
62 | 66 |
RVE_LAND_OP, /* 2 members, returns left && right */ |
63 | 67 |
RVE_LOR_OP, /* 2 members, returns left || right */ |
64 | 68 |
RVE_GT_OP, /* 2 members, returns left > right */ |
- don't use static buffers for string conversions
(rval_get_tmp_str())
- extended rval_cache with enough space to store an int converted
to string
- switched to signed ints (until now all ints where treated as
unsigned)
... | ... |
@@ -26,12 +26,14 @@ |
26 | 26 |
* 2009-04-28 added string and interger versions for the EQ and DIFF |
27 | 27 |
* operators (andrei) |
28 | 28 |
* 2009-05-05 casts operator for int & string (andrei) |
29 |
+ * 2010-03-16 space for an int2str result inside rval_cache (andrei) |
|
29 | 30 |
*/ |
30 | 31 |
|
31 | 32 |
#ifndef _rvalue_h_ |
32 | 33 |
#define _rvalue_h_ |
33 | 34 |
|
34 | 35 |
#include "str.h" |
36 |
+#include "ut.h" |
|
35 | 37 |
#include "usr_avp.h" |
36 | 38 |
#include "select.h" |
37 | 39 |
#include "pvar.h" |
... | ... |
@@ -138,7 +140,8 @@ enum rval_cache_type{ |
138 | 140 |
RV_CACHE_EMPTY, |
139 | 141 |
RV_CACHE_PVAR, |
140 | 142 |
RV_CACHE_AVP, |
141 |
- RV_CACHE_SELECT |
|
143 |
+ RV_CACHE_SELECT, |
|
144 |
+ RV_CACHE_INT2STR |
|
142 | 145 |
}; |
143 | 146 |
|
144 | 147 |
/** value cache for a rvalue struct. |
... | ... |
@@ -152,6 +155,7 @@ struct rval_cache{ |
152 | 155 |
int_str avp_val; /**< avp value */ |
153 | 156 |
pv_value_t pval; /**< pvar value */ |
154 | 157 |
}c; |
158 |
+ char i2s[INT2STR_MAX_LEN]; /**< space for converting an int to string*/ |
|
155 | 159 |
}; |
156 | 160 |
|
157 | 161 |
|
- a mod b - return the modulo result
... | ... |
@@ -53,6 +53,7 @@ enum rval_expr_op{ |
53 | 53 |
RVE_LNOT_OP, /* one member evaluate as bool. : (!val)*/ |
54 | 54 |
RVE_MUL_OP, /* 2 members, returns left * right */ |
55 | 55 |
RVE_DIV_OP, /* 2 members, returns left / right */ |
56 |
+ RVE_MOD_OP, /* 2 members, returns left % right */ |
|
56 | 57 |
RVE_MINUS_OP, /* 2 members, returns left - right */ |
57 | 58 |
RVE_BAND_OP, /* 2 members, returns left | right */ |
58 | 59 |
RVE_BOR_OP, /* 2 members, returns left & right */ |
- new internal operators for force-casting to int or str
- fix int conversion failure for v1 str_concat v2
... | ... |
@@ -25,6 +25,7 @@ |
25 | 25 |
* 2008-11-30 initial version (andrei) |
26 | 26 |
* 2009-04-28 added string and interger versions for the EQ and DIFF |
27 | 27 |
* operators (andrei) |
28 |
+ * 2009-05-05 casts operator for int & string (andrei) |
|
28 | 29 |
*/ |
29 | 30 |
|
30 | 31 |
#ifndef _rvalue_h_ |
... | ... |
@@ -77,6 +78,8 @@ enum rval_expr_op{ |
77 | 78 |
RVE_MATCH_OP, /* 2 members, string ~), returns left matches re(right) */ |
78 | 79 |
/* avp, pvars a.s.o */ |
79 | 80 |
RVE_DEFINED_OP, /* one member, returns is_defined(val) (bool) */ |
81 |
+ RVE_INT_OP, /* one member, returns (int)val (int) */ |
|
82 |
+ RVE_STR_OP /* one member, returns (str)val (str) */ |
|
80 | 83 |
}; |
81 | 84 |
|
82 | 85 |
|
The match regular expression operator (=~) is now supported in
rval_exprs.
... | ... |
@@ -74,11 +74,17 @@ enum rval_expr_op{ |
74 | 74 |
RVE_STREMPTY_OP, /* one member, returns val=="" (bool) */ |
75 | 75 |
RVE_STREQ_OP, /* 2 members, string == , returns left == right (bool)*/ |
76 | 76 |
RVE_STRDIFF_OP,/* 2 members, string != , returns left != right (bool)*/ |
77 |
+ RVE_MATCH_OP, /* 2 members, string ~), returns left matches re(right) */ |
|
77 | 78 |
/* avp, pvars a.s.o */ |
78 | 79 |
RVE_DEFINED_OP, /* one member, returns is_defined(val) (bool) */ |
79 | 80 |
}; |
80 | 81 |
|
81 | 82 |
|
83 |
+struct str_re{ |
|
84 |
+ str s; |
|
85 |
+ regex_t* regex; |
|
86 |
+}; |
|
87 |
+ |
|
82 | 88 |
union rval_val{ |
83 | 89 |
void* p; |
84 | 90 |
long l; |
... | ... |
@@ -88,6 +94,7 @@ union rval_val{ |
88 | 94 |
pv_spec_t pvs; |
89 | 95 |
struct action* action; |
90 | 96 |
struct expr* bexpr; |
97 |
+ struct str_re re; |
|
91 | 98 |
}; |
92 | 99 |
|
93 | 100 |
|
... | ... |
@@ -105,6 +112,8 @@ struct rvalue{ |
105 | 112 |
#define RV_CNT_ALLOCED_F 1 /* free contents (pkg mem allocated) */ |
106 | 113 |
#define RV_RV_ALLOCED_F 2 /* free rv itself (pkg_free(rv)) */ |
107 | 114 |
#define RV_ALL_ALLOCED_F (RV_CNT_ALLOCED|RV_RV_ALLOCED) |
115 |
+#define RV_RE_F 4 /* string is a RE with a valid v->re member */ |
|
116 |
+#define RV_RE_ALLOCED_F 8 /* v->re.regex must be freed */ |
|
108 | 117 |
|
109 | 118 |
|
110 | 119 |
struct rval_expr{ |
- added RVE_IEQ_OP and RVE_IDIFF_OP - internal integer only
(force argument conversion to int) operators
- added RVE_STREQ and RVE_STRDIFF_OP - internal string only
(force argument conversion to str) operators
... | ... |
@@ -23,6 +23,8 @@ |
23 | 23 |
* History: |
24 | 24 |
* -------- |
25 | 25 |
* 2008-11-30 initial version (andrei) |
26 |
+ * 2009-04-28 added string and interger versions for the EQ and DIFF |
|
27 |
+ * operators (andrei) |
|
26 | 28 |
*/ |
27 | 29 |
|
28 | 30 |
#ifndef _rvalue_h_ |
... | ... |
@@ -59,6 +61,8 @@ enum rval_expr_op{ |
59 | 61 |
RVE_GTE_OP, /* 2 members, returns left >= right */ |
60 | 62 |
RVE_LT_OP, /* 2 members, returns left < right */ |
61 | 63 |
RVE_LTE_OP, /* 2 members, returns left <= right */ |
64 |
+ RVE_IEQ_OP, /* 2 members, int == version, returns left == right */ |
|
65 |
+ RVE_IDIFF_OP,/* 2 members, int != version, returns left != right */ |
|
62 | 66 |
RVE_IPLUS_OP, /* 2 members, integer +, returns int(a)+int(b) */ |
63 | 67 |
/* common int & str */ |
64 | 68 |
RVE_PLUS_OP, /* generic plus (int or str) returns left + right */ |
... | ... |
@@ -68,6 +72,8 @@ enum rval_expr_op{ |
68 | 72 |
RVE_CONCAT_OP,/* 2 members, string concat, returns left . right (str)*/ |
69 | 73 |
RVE_STRLEN_OP, /* one member, string length:, returns strlen(val) (int)*/ |
70 | 74 |
RVE_STREMPTY_OP, /* one member, returns val=="" (bool) */ |
75 |
+ RVE_STREQ_OP, /* 2 members, string == , returns left == right (bool)*/ |
|
76 |
+ RVE_STRDIFF_OP,/* 2 members, string != , returns left != right (bool)*/ |
|
71 | 77 |
/* avp, pvars a.s.o */ |
72 | 78 |
RVE_DEFINED_OP, /* one member, returns is_defined(val) (bool) */ |
73 | 79 |
}; |
- a select can now be undefined (defined @select when run_select
returns >0 or error => true)
- RV_CACHE_SELECT introduced
- added RVE_STRLEN_OP, RVE_STREMPTY_OP and RVE_DEFINED_OP
... | ... |
@@ -64,8 +64,12 @@ enum rval_expr_op{ |
64 | 64 |
RVE_PLUS_OP, /* generic plus (int or str) returns left + right */ |
65 | 65 |
RVE_EQ_OP, /* 2 members, returns left == right (int)*/ |
66 | 66 |
RVE_DIFF_OP, /* 2 members, returns left != right (int)*/ |
67 |
- RVE_CONCAT_OP,/* string concatenation, returns left . right */ |
|
68 | 67 |
/* str only */ |
68 |
+ RVE_CONCAT_OP,/* 2 members, string concat, returns left . right (str)*/ |
|
69 |
+ RVE_STRLEN_OP, /* one member, string length:, returns strlen(val) (int)*/ |
|
70 |
+ RVE_STREMPTY_OP, /* one member, returns val=="" (bool) */ |
|
71 |
+ /* avp, pvars a.s.o */ |
|
72 |
+ RVE_DEFINED_OP, /* one member, returns is_defined(val) (bool) */ |
|
69 | 73 |
}; |
70 | 74 |
|
71 | 75 |
|
- added rve_has_side_effects(), preliminary version
(for now is equivalent with !rve_is_constant())
- exported rve_destroy()
... | ... |
@@ -188,6 +188,8 @@ int rval_expr_eval_rvint( struct run_act_ctx* h, struct sip_msg* msg, |
188 | 188 |
enum rval_type rve_guess_type(struct rval_expr* rve); |
189 | 189 |
/** returns true if expression is constant. */ |
190 | 190 |
int rve_is_constant(struct rval_expr* rve); |
191 |
+/** returns true if the expression can have side-effect */ |
|
192 |
+int rve_has_side_effects(struct rval_expr* rve); |
|
191 | 193 |
/** returns 1 if expression is valid (type-wise).*/ |
192 | 194 |
int rve_check_type(enum rval_type* type, struct rval_expr* rve, |
193 | 195 |
struct rval_expr** bad_rve, enum rval_type* bad_type, |
... | ... |
@@ -206,6 +208,8 @@ struct rval_expr* mk_rval_expr1(enum rval_expr_op op, struct rval_expr* rve1, |
206 | 208 |
struct rval_expr* mk_rval_expr2(enum rval_expr_op op, struct rval_expr* rve1, |
207 | 209 |
struct rval_expr* rve2, |
208 | 210 |
struct cfg_pos* pos); |
211 |
+/** destroys a pkg_malloc'ed rve. */ |
|
212 |
+void rve_destroy(struct rval_expr* rve); |
|
209 | 213 |
|
210 | 214 |
/** fix a rval_expr. */ |
211 | 215 |
int fix_rval_expr(void** p); |
- different operators for integer + (RVE_IPLUS_OP) and str plus
(RVE_CONCAT_OP). The generic plus (RVE_PLUS_OP) is still
present, the new operators are only used in internal
optimizations (see below) for now.
- if an expression involving the generic '+' is always of type int
or str, replace the generic '+' with the interger or string
version (makes further optimizations possible).
... | ... |
@@ -59,10 +59,12 @@ enum rval_expr_op{ |
59 | 59 |
RVE_GTE_OP, /* 2 members, returns left >= right */ |
60 | 60 |
RVE_LT_OP, /* 2 members, returns left < right */ |
61 | 61 |
RVE_LTE_OP, /* 2 members, returns left <= right */ |
62 |
+ RVE_IPLUS_OP, /* 2 members, integer +, returns int(a)+int(b) */ |
|
62 | 63 |
/* common int & str */ |
63 |
- RVE_PLUS_OP, /* 2 members, returns left + right (int or str)*/ |
|
64 |
+ RVE_PLUS_OP, /* generic plus (int or str) returns left + right */ |
|
64 | 65 |
RVE_EQ_OP, /* 2 members, returns left == right (int)*/ |
65 | 66 |
RVE_DIFF_OP, /* 2 members, returns left != right (int)*/ |
67 |
+ RVE_CONCAT_OP,/* string concatenation, returns left . right */ |
|
66 | 68 |
/* str only */ |
67 | 69 |
}; |
68 | 70 |
|
- report bad expression position on type mismatch
e.g.:
*** PARSE ERROR *** (42,8-18): bad expression: type
mismatch: str instead of int at (42,16)
... | ... |
@@ -94,6 +94,7 @@ struct rvalue{ |
94 | 94 |
#define RV_RV_ALLOCED_F 2 /* free rv itself (pkg_free(rv)) */ |
95 | 95 |
#define RV_ALL_ALLOCED_F (RV_CNT_ALLOCED|RV_RV_ALLOCED) |
96 | 96 |
|
97 |
+ |
|
97 | 98 |
struct rval_expr{ |
98 | 99 |
enum rval_expr_op op; |
99 | 100 |
union{ |
... | ... |
@@ -104,6 +105,7 @@ struct rval_expr{ |
104 | 105 |
struct rval_expr* rve; |
105 | 106 |
struct rvalue rval; |
106 | 107 |
}right; |
108 |
+ struct cfg_pos fpos; |
|
107 | 109 |
}; |
108 | 110 |
|
109 | 111 |
|
... | ... |
@@ -193,12 +195,15 @@ char* rval_type_name(enum rval_type type); |
193 | 195 |
|
194 | 196 |
/** create a RVE_RVAL_OP rval_expr, containing a single rval of the given type |
195 | 197 |
*/ |
196 |
-struct rval_expr* mk_rval_expr_v(enum rval_type rv_type, void* val); |
|
198 |
+struct rval_expr* mk_rval_expr_v(enum rval_type rv_type, void* val, |
|
199 |
+ struct cfg_pos* pos); |
|
197 | 200 |
/** create a unary op. rval_expr.. */ |
198 |
-struct rval_expr* mk_rval_expr1(enum rval_expr_op op, struct rval_expr* rve1); |
|
201 |
+struct rval_expr* mk_rval_expr1(enum rval_expr_op op, struct rval_expr* rve1, |
|
202 |
+ struct cfg_pos* pos); |
|
199 | 203 |
/** create a rval_expr. from 2 other rval exprs, using op. */ |
200 | 204 |
struct rval_expr* mk_rval_expr2(enum rval_expr_op op, struct rval_expr* rve1, |
201 |
- struct rval_expr* rve2); |
|
205 |
+ struct rval_expr* rve2, |
|
206 |
+ struct cfg_pos* pos); |
|
202 | 207 |
|
203 | 208 |
/** fix a rval_expr. */ |
204 | 209 |
int fix_rval_expr(void** p); |
- extended rve_check_type() to return also the subexpression for
which the check failed, its type and the expected type.
... | ... |
@@ -185,7 +185,11 @@ enum rval_type rve_guess_type(struct rval_expr* rve); |
185 | 185 |
/** returns true if expression is constant. */ |
186 | 186 |
int rve_is_constant(struct rval_expr* rve); |
187 | 187 |
/** returns 1 if expression is valid (type-wise).*/ |
188 |
-int rve_check_type(enum rval_type* type, struct rval_expr* rve); |
|
188 |
+int rve_check_type(enum rval_type* type, struct rval_expr* rve, |
|
189 |
+ struct rval_expr** bad_rve, enum rval_type* bad_type, |
|
190 |
+ enum rval_type* exp_type); |
|
191 |
+/** returns a string name for type (debugging).*/ |
|
192 |
+char* rval_type_name(enum rval_type type); |
|
189 | 193 |
|
190 | 194 |
/** create a RVE_RVAL_OP rval_expr, containing a single rval of the given type |
191 | 195 |
*/ |
- fixed rval_str_add2()
- more functions are now "public"
- support for optimization levels
... | ... |
@@ -174,6 +174,11 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, |
174 | 174 |
/** evals a rval expr.. */ |
175 | 175 |
struct rvalue* rval_expr_eval(struct run_act_ctx* h, struct sip_msg* msg, |
176 | 176 |
struct rval_expr* rve); |
177 |
+/** evals an integer expr to an int or rvalue. */ |
|
178 |
+int rval_expr_eval_rvint( struct run_act_ctx* h, struct sip_msg* msg, |
|
179 |
+ struct rvalue** rv_res, int* i_res, |
|
180 |
+ struct rval_expr* rve, struct rval_cache* cache); |
|
181 |
+ |
|
177 | 182 |
|
178 | 183 |
/** guess the type of an expression. */ |
179 | 184 |
enum rval_type rve_guess_type(struct rval_expr* rve); |
- support for more operators
- more helper functions
- small fixes