- added kamailio compatible fixups (e.g. fixup_str_str), which use
ser fix_param() underneath
- added kamailio compatible macros for gparam_t (which is now fparam_t)
and fixup_get_[si]value() (to get_{int,str}_value)
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,236 @@ |
1 |
+/* |
|
2 |
+ * $Id$ |
|
3 |
+ * |
|
4 |
+ * Copyright (C) 2008 iptelorg GmbH |
|
5 |
+ * |
|
6 |
+ * Permission to use, copy, modify, and distribute this software for any |
|
7 |
+ * purpose with or without fee is hereby granted, provided that the above |
|
8 |
+ * copyright notice and this permission notice appear in all copies. |
|
9 |
+ * |
|
10 |
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
11 |
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
12 |
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
13 |
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
14 |
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
15 |
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
16 |
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
17 |
+ */ |
|
18 |
+/** |
|
19 |
+ * @file mod_fix.c |
|
20 |
+ * @brief kamailio compatible fixups |
|
21 |
+ */ |
|
22 |
+/* |
|
23 |
+ * History: |
|
24 |
+ * -------- |
|
25 |
+ * 2008-11-25 initial version (andrei) |
|
26 |
+ */ |
|
27 |
+ |
|
28 |
+#include "mod_fix.h" |
|
29 |
+#include "mem/mem.h" |
|
30 |
+ |
|
31 |
+ |
|
32 |
+ |
|
33 |
+#if 0 |
|
34 |
+/* TODO: */ |
|
35 |
+int fixup_regexpNL_null(void** param, int param_no); /* not used */ |
|
36 |
+int fixup_regexpNL_none(void** param, int param_no); /* textops */ |
|
37 |
+#endif |
|
38 |
+ |
|
39 |
+ |
|
40 |
+ |
|
41 |
+#define FREE_FIXUP_FP(suffix, minp, maxp) \ |
|
42 |
+ int fixup_free_##suffix(void** param, int param_no) \ |
|
43 |
+ { \ |
|
44 |
+ if ((param_no > (maxp)) || (param_no < (minp))) \ |
|
45 |
+ return E_UNSPEC; \ |
|
46 |
+ if (*param){ \ |
|
47 |
+ fparam_free_contents((fparam_t*)*param); \ |
|
48 |
+ pkg_free(*param); \ |
|
49 |
+ *param=0; \ |
|
50 |
+ } \ |
|
51 |
+ return 0; \ |
|
52 |
+ } |
|
53 |
+ |
|
54 |
+ |
|
55 |
+/** macro for declaring a fixup and the corresponding free_fixup |
|
56 |
+ * for a function which fixes to fparam_t and expects 2 different types. |
|
57 |
+ * |
|
58 |
+ * The result (in *param) will be a fparam_t. |
|
59 |
+ * |
|
60 |
+ * @param suffix - function suffix (fixup_ will be pre-pended to it |
|
61 |
+ * @param minp - minimum parameter number acceptable |
|
62 |
+ * @param maxp - maximum parameter number |
|
63 |
+ * @param no1 - number of parameters of type1 |
|
64 |
+ * @param type1 - fix_param type for the 1st param |
|
65 |
+ * @paran type2 - fix_param type for all the other params |
|
66 |
+ */ |
|
67 |
+#define FIXUP_F2FP(suffix, minp, maxp, no1, type1, type2) \ |
|
68 |
+ int fixup_##suffix (void** param, int param_no) \ |
|
69 |
+ { \ |
|
70 |
+ if ((param_no > (maxp)) || (param_no <(minp))) \ |
|
71 |
+ return E_UNSPEC; \ |
|
72 |
+ if (param_no <= (no1)){ \ |
|
73 |
+ if (fix_param_types((type1), param)!=0) {\ |
|
74 |
+ ERR("Cannot convert function parameter %d to" #type1 "\n", \ |
|
75 |
+ param_no);\ |
|
76 |
+ return E_UNSPEC; \ |
|
77 |
+ } \ |
|
78 |
+ }else{ \ |
|
79 |
+ if (fix_param_types((type2), param)!=0) {\ |
|
80 |
+ ERR("Cannot convert function parameter %d to" #type2 "\n", \ |
|
81 |
+ param_no); \ |
|
82 |
+ return E_UNSPEC; \ |
|
83 |
+ } \ |
|
84 |
+ }\ |
|
85 |
+ return 0; \ |
|
86 |
+ } \ |
|
87 |
+ FREE_FIXUP_FP(suffix, minp, maxp) |
|
88 |
+ |
|
89 |
+ |
|
90 |
+/** macro for declaring a fixup and the corresponding free_fixup |
|
91 |
+ * for a function which fixes directly to the requested type. |
|
92 |
+ * |
|
93 |
+ * @see FIXUP_F2FP for the parameters |
|
94 |
+ * Side effect: declares also some _fp_helper functions |
|
95 |
+ */ |
|
96 |
+#define FIXUP_F2T(suffix, minp, maxp, no1, type1, type2) \ |
|
97 |
+ FIXUP_F2FP(fp_##suffix, minp, maxp, no1, type1, type2) \ |
|
98 |
+ int fixup_##suffix (void** param, int param_no) \ |
|
99 |
+ { \ |
|
100 |
+ int ret; \ |
|
101 |
+ if ((ret=fixup_fp_##suffix (param, param_no))!=0) \ |
|
102 |
+ return ret; \ |
|
103 |
+ *param=&((fparam_t*)*param)->v; \ |
|
104 |
+ return 0; \ |
|
105 |
+ } \ |
|
106 |
+ int fixup_free_##suffix (void** param, int param_no) \ |
|
107 |
+ { \ |
|
108 |
+ void* p; \ |
|
109 |
+ int ret; \ |
|
110 |
+ if (param && *param){ \ |
|
111 |
+ p=*param - (long)&((fparam_t*)0)->v; \ |
|
112 |
+ if ((ret=fixup_free_fp_##suffix(&p, param_no))==0) *param=p; \ |
|
113 |
+ return ret; \ |
|
114 |
+ } \ |
|
115 |
+ return 0; \ |
|
116 |
+ } |
|
117 |
+ |
|
118 |
+ |
|
119 |
+/** macro for declaring a fixup and the corresponding free_fixup |
|
120 |
+ * for a function expecting first no1 params as fparamt_t and the |
|
121 |
+ * rest as direct type. |
|
122 |
+ * |
|
123 |
+ * @see FIXUP_F2FP for the parameters with the exception |
|
124 |
+ * that only the first no1 parameters are converted to |
|
125 |
+ * fparamt_t and the rest directly to the correponding type |
|
126 |
+ * |
|
127 |
+ * Side effect: declares also some _fpt_helper functions |
|
128 |
+ */ |
|
129 |
+#define FIXUP_F2FP_T(suffix, minp, maxp, no1, type1, type2) \ |
|
130 |
+ FIXUP_F2FP(fpt_##suffix, minp, maxp, no1, type1, type2) \ |
|
131 |
+ int fixup_##suffix (void** param, int param_no) \ |
|
132 |
+ { \ |
|
133 |
+ int ret; \ |
|
134 |
+ if ((ret=fixup_fpt_##suffix(param, param_no))!=0) \ |
|
135 |
+ return ret; \ |
|
136 |
+ if (param_no>(no1)) *param=&((fparam_t*)*param)->v; \ |
|
137 |
+ return 0; \ |
|
138 |
+ } \ |
|
139 |
+ int fixup_free_##suffix (void** param, int param_no) \ |
|
140 |
+ { \ |
|
141 |
+ void* p; \ |
|
142 |
+ int ret; \ |
|
143 |
+ if (param && *param){ \ |
|
144 |
+ p=(param_no>(no1))? *param - (long)&((fparam_t*)0)->v : *param;\ |
|
145 |
+ if ((ret=fixup_free_fpt_##suffix(&p, param_no))==0) *param=0; \ |
|
146 |
+ return ret; \ |
|
147 |
+ } \ |
|
148 |
+ return 0; \ |
|
149 |
+ } |
|
150 |
+ |
|
151 |
+ |
|
152 |
+/** macro for declaring a fixup which fixes all the paremeters to the same |
|
153 |
+ * type. |
|
154 |
+ * |
|
155 |
+ * @see FIXUP_F2T. |
|
156 |
+ */ |
|
157 |
+#define FIXUP_F1T(suffix, minp, maxp, type) \ |
|
158 |
+ FIXUP_F2T(suffix, minp, maxp, maxp, type, 0) |
|
159 |
+ |
|
160 |
+ |
|
161 |
+ |
|
162 |
+FIXUP_F1T(str_null, 1, 1, FPARAM_STR) |
|
163 |
+FIXUP_F1T(str_str, 1, 2, FPARAM_STR) |
|
164 |
+ |
|
165 |
+/* TODO: int can be converted in place, no need for pkg_malloc'ed fparam_t*/ |
|
166 |
+FIXUP_F1T(uint_null, 1, 1, FPARAM_INT) |
|
167 |
+FIXUP_F1T(uint_uint, 1, 2, FPARAM_INT) |
|
168 |
+ |
|
169 |
+FIXUP_F1T(regexp_null, 1, 1, FPARAM_REGEX) |
|
170 |
+ |
|
171 |
+FIXUP_F1T(pvar_null, 1, 1, FPARAM_PVS) |
|
172 |
+FIXUP_F1T(pvar_pvar, 1, 2, FPARAM_PVS) |
|
173 |
+ |
|
174 |
+FIXUP_F2T(pvar_str, 1, 2, 1, FPARAM_PVS, FPARAM_STR) |
|
175 |
+FIXUP_F2T(pvar_str_str, 1, 3, 1, FPARAM_PVS, FPARAM_STR) |
|
176 |
+ |
|
177 |
+FIXUP_F2FP(igp_null, 1, 1, 1, FPARAM_INT|FPARAM_PVS, 0) |
|
178 |
+FIXUP_F2FP(igp_igp, 1, 2, 2, FPARAM_INT|FPARAM_PVS, 0) |
|
179 |
+ |
|
180 |
+FIXUP_F2FP_T(igp_pvar_pvar, 1, 3, 1, FPARAM_INT|FPARAM_PVS, FPARAM_PVS) |
|
181 |
+ |
|
182 |
+/** macro for declaring a spve fixup and the corresponding free_fixup |
|
183 |
+ * for a function expecting first no1 params as fparam converted spve |
|
184 |
+ * and the * rest as direct type. |
|
185 |
+ * |
|
186 |
+ * @see FIXUP_F2FP for the parameters with the exception |
|
187 |
+ * that the first no1 parameters are converted to fparam_t from spve |
|
188 |
+ * and the rest directly to the corresponding type |
|
189 |
+ * |
|
190 |
+ * Side effect: declares also some _spvet_helper functions |
|
191 |
+ */ |
|
192 |
+#define FIXUP_F_SPVE_T(suffix, minp, maxp, no1, type2) \ |
|
193 |
+ FIXUP_F1T(spvet_##suffix, minp, maxp, type2) \ |
|
194 |
+ int fixup_##suffix (void** param, int param_no) \ |
|
195 |
+ { \ |
|
196 |
+ int ret; \ |
|
197 |
+ char * bkp; \ |
|
198 |
+ fparam_t* fp; \ |
|
199 |
+ bkp=*param; \ |
|
200 |
+ if (param_no<=(no1)){ \ |
|
201 |
+ if ((ret=fix_param_types(FPARAM_PVE, param))<0){ \ |
|
202 |
+ ERR("Cannot convert function parameter %d to" #type2 "\n", \ |
|
203 |
+ param_no);\ |
|
204 |
+ return E_UNSPEC; \ |
|
205 |
+ } else{ \ |
|
206 |
+ fp=(fparam_t*)*param; \ |
|
207 |
+ if ((ret==0) && (fp->v.pve->spec.getf==0)){ \ |
|
208 |
+ fparam_free_contents(fp); \ |
|
209 |
+ pkg_free(fp); \ |
|
210 |
+ *param=bkp; \ |
|
211 |
+ return fix_param_types(FPARAM_STR, param); \ |
|
212 |
+ } else if (ret==1) \ |
|
213 |
+ return fix_param_types(FPARAM_STR, param); \ |
|
214 |
+ return ret; \ |
|
215 |
+ } \ |
|
216 |
+ } else return fixup_spvet_##suffix(param, param_no); \ |
|
217 |
+ return 0; \ |
|
218 |
+ } \ |
|
219 |
+ int fixup_free_##suffix (void** param, int param_no) \ |
|
220 |
+ { \ |
|
221 |
+ if (param && *param){ \ |
|
222 |
+ if (param_no<=(no1)){ \ |
|
223 |
+ fparam_free_contents((fparam_t*)*param); \ |
|
224 |
+ pkg_free(*param); \ |
|
225 |
+ *param=0; \ |
|
226 |
+ } else \ |
|
227 |
+ return fixup_free_spvet_##suffix(param, param_no); \ |
|
228 |
+ } \ |
|
229 |
+ return 0; \ |
|
230 |
+ } |
|
231 |
+ |
|
232 |
+ |
|
233 |
+FIXUP_F_SPVE_T(spve_spve, 1, 2, 2, 0) |
|
234 |
+FIXUP_F_SPVE_T(spve_uint, 1, 2, 2, FPARAM_INT) |
|
235 |
+FIXUP_F_SPVE_T(spve_str, 1, 2, 2, FPARAM_STR) |
|
236 |
+ |
0 | 237 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,123 @@ |
1 |
+/* |
|
2 |
+ * $Id$ |
|
3 |
+ * |
|
4 |
+ * Copyright (C) 2008 iptelorg GmbH |
|
5 |
+ * |
|
6 |
+ * Permission to use, copy, modify, and distribute this software for any |
|
7 |
+ * purpose with or without fee is hereby granted, provided that the above |
|
8 |
+ * copyright notice and this permission notice appear in all copies. |
|
9 |
+ * |
|
10 |
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
11 |
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
12 |
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
13 |
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
14 |
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
15 |
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
16 |
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
17 |
+ */ |
|
18 |
+/** |
|
19 |
+ * @file mod_fix.h |
|
20 |
+ * @brief Generic fixup functions for module function parameter. |
|
21 |
+ * (kamailio compatibility) |
|
22 |
+ */ |
|
23 |
+ |
|
24 |
+#ifndef _mod_fix_h_ |
|
25 |
+#define _mod_fix_h_ |
|
26 |
+ |
|
27 |
+#include "sr_module.h" |
|
28 |
+#include "pvar.h" |
|
29 |
+ |
|
30 |
+#define GPARAM_TYPE_INT FPARAM_INT |
|
31 |
+#define GPARAM_TYPE_STR FPARAM_STR |
|
32 |
+#define GPARAM_TYPE_PVS FPARAM_PVS |
|
33 |
+#define GPARAM_TYPE_PVE FPARAM_PVE |
|
34 |
+ |
|
35 |
+/** |
|
36 |
+ * generic parameter that holds a string, an int, a pseudo-variable |
|
37 |
+ * or a ser select, avp, or subst. |
|
38 |
+ * |
|
39 |
+ * Note: used only for compatibility with existing kamailio code, |
|
40 |
+ * please use fparam_t directly in the future. |
|
41 |
+ * |
|
42 |
+ * @see fparam_t |
|
43 |
+ */ |
|
44 |
+ |
|
45 |
+/* reuse ser fparam_t */ |
|
46 |
+#define gparam_t fparam_t |
|
47 |
+ |
|
48 |
+typedef gparam_t *gparam_p; |
|
49 |
+ |
|
50 |
+int fixup_get_svalue(struct sip_msg* msg, gparam_p gp, str *val); |
|
51 |
+ |
|
52 |
+/** get a string value out of a fparam_t. |
|
53 |
+ * |
|
54 |
+ * Note: this macro/function is for kamailio compatibility |
|
55 |
+ * (please use get_str_fparam() directly in the future) |
|
56 |
+ * |
|
57 |
+ * @param msg - pointer to the sip message |
|
58 |
+ * @param fp - pointer to the fparam_t |
|
59 |
+ * @param sval - pointer to str, used to store the result |
|
60 |
+ * @return 0 on success, -1 on error |
|
61 |
+ */ |
|
62 |
+#define fixup_get_svalue(msg, fp, sval) get_str_fparam(sval, msg, fp) |
|
63 |
+ |
|
64 |
+/** get an int value out of a fparam_t. |
|
65 |
+ * |
|
66 |
+ * Note: this macro/function is for kamailio compatibility |
|
67 |
+ * (please use get_int_fparam() directly in the future) |
|
68 |
+ * |
|
69 |
+ * @param msg - pointer to the sip message |
|
70 |
+ * @param fp - pointer to the fparam_t |
|
71 |
+ * @param ival - pointer to str, used to store the result |
|
72 |
+ * @return 0 on success, -1 on error |
|
73 |
+ */ |
|
74 |
+#define fixup_get_ivalue(msg, fp, ival) get_int_fparam(ival, msg, fp) |
|
75 |
+ |
|
76 |
+int fixup_str_null(void** param, int param_no); |
|
77 |
+int fixup_str_str(void** param, int param_no); |
|
78 |
+ |
|
79 |
+int fixup_free_str_null(void** param, int param_no); |
|
80 |
+int fixup_free_str_str(void** param, int param_no); |
|
81 |
+ |
|
82 |
+int fixup_uint_null(void** param, int param_no); |
|
83 |
+int fixup_uint_uint(void** param, int param_no); |
|
84 |
+ |
|
85 |
+ |
|
86 |
+int fixup_regexp_null(void** param, int param_no); |
|
87 |
+int fixup_free_regexp_null(void** param, int param_no); |
|
88 |
+int fixup_regexp_none(void** param, int param_no); |
|
89 |
+int fixup_free_regexp_none(void** param, int param_no); |
|
90 |
+#if 0 |
|
91 |
+/* not implemened yet */ |
|
92 |
+int fixup_regexpNL_null(void** param, int param_no); |
|
93 |
+int fixup_regexpNL_none(void** param, int param_no); |
|
94 |
+#endif |
|
95 |
+ |
|
96 |
+int fixup_pvar_null(void **param, int param_no); |
|
97 |
+int fixup_free_pvar_null(void** param, int param_no); |
|
98 |
+ |
|
99 |
+int fixup_pvar_pvar(void **param, int param_no); |
|
100 |
+int fixup_free_pvar_pvar(void** param, int param_no); |
|
101 |
+ |
|
102 |
+int fixup_pvar_str(void** param, int param_no); |
|
103 |
+int fixup_free_pvar_str(void** param, int param_no); |
|
104 |
+ |
|
105 |
+int fixup_pvar_str_str(void** param, int param_no); |
|
106 |
+int fixup_free_pvar_str_str(void** param, int param_no); |
|
107 |
+ |
|
108 |
+int fixup_igp_igp(void** param, int param_no); |
|
109 |
+int fixup_igp_null(void** param, int param_no); |
|
110 |
+int fixup_get_ivalue(struct sip_msg* msg, gparam_p gp, int *val); |
|
111 |
+ |
|
112 |
+int fixup_igp_pvar_pvar(void** param, int param_no); |
|
113 |
+int fixup_free_igp_pvar_pvar(void** param, int param_no); |
|
114 |
+ |
|
115 |
+int fixup_spve_spve(void** param, int param_no); |
|
116 |
+int fixup_spve_null(void** param, int param_no); |
|
117 |
+int fixup_spve_uint(void** param, int param_no); |
|
118 |
+int fixup_spve_str(void** param, int param_no); |
|
119 |
+ |
|
120 |
+ |
|
121 |
+int fixup_pvar(void **param); |
|
122 |
+ |
|
123 |
+#endif |