- 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,609 +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 :: kamailio compatible fixups |
|
20 |
- * \ingroup core |
|
21 |
- * Module: \ref core |
|
22 |
- */ |
|
23 |
- |
|
24 |
-#include "mod_fix.h" |
|
25 |
-#include "mem/mem.h" |
|
26 |
-#include "trim.h" |
|
27 |
- |
|
28 |
- |
|
29 |
- |
|
30 |
-#if 0 |
|
31 |
-/* TODO: */ |
|
32 |
-int fixup_regexpNL_null(void** param, int param_no); /* not used */ |
|
33 |
-int fixup_regexpNL_none(void** param, int param_no); /* textops */ |
|
34 |
-#endif |
|
35 |
- |
|
36 |
- |
|
37 |
- |
|
38 |
-#define FREE_FIXUP_FP(suffix, minp, maxp) \ |
|
39 |
- int fixup_free_##suffix(void** param, int param_no) \ |
|
40 |
- { \ |
|
41 |
- if ((param_no > (maxp)) || (param_no < (minp))) \ |
|
42 |
- return E_UNSPEC; \ |
|
43 |
- if (*param) \ |
|
44 |
- fparam_free_restore(param); \ |
|
45 |
- return 0; \ |
|
46 |
- } |
|
47 |
- |
|
48 |
- |
|
49 |
-/** macro for declaring a fixup and the corresponding free_fixup |
|
50 |
- * for a function which fixes to fparam_t and expects 2 different types. |
|
51 |
- * |
|
52 |
- * The result (in *param) will be a fparam_t. |
|
53 |
- * |
|
54 |
- * @param suffix - function suffix (fixup_ will be pre-pended to it |
|
55 |
- * @param minp - minimum parameter number acceptable |
|
56 |
- * @param maxp - maximum parameter number |
|
57 |
- * @param no1 - number of parameters of type1 |
|
58 |
- * @param type1 - fix_param type for the 1st param |
|
59 |
- * @param type2 - fix_param type for all the other params |
|
60 |
- */ |
|
61 |
-#define FIXUP_F2FP(suffix, minp, maxp, no1, type1, type2) \ |
|
62 |
- int fixup_##suffix (void** param, int param_no) \ |
|
63 |
- { \ |
|
64 |
- if ((param_no > (maxp)) || (param_no <(minp))) \ |
|
65 |
- return E_UNSPEC; \ |
|
66 |
- if (param_no <= (no1)){ \ |
|
67 |
- if (fix_param_types((type1), param)!=0) {\ |
|
68 |
- ERR("Cannot convert function parameter %d to" #type1 "\n", \ |
|
69 |
- param_no);\ |
|
70 |
- return E_UNSPEC; \ |
|
71 |
- } \ |
|
72 |
- }else{ \ |
|
73 |
- if (fix_param_types((type2), param)!=0) {\ |
|
74 |
- ERR("Cannot convert function parameter %d to" #type2 "\n", \ |
|
75 |
- param_no); \ |
|
76 |
- return E_UNSPEC; \ |
|
77 |
- } \ |
|
78 |
- }\ |
|
79 |
- return 0; \ |
|
80 |
- } \ |
|
81 |
- FREE_FIXUP_FP(suffix, minp, maxp) |
|
82 |
- |
|
83 |
- |
|
84 |
-/** macro for declaring a fixup and the corresponding free_fixup |
|
85 |
- * for a function which fixes directly to the requested type. |
|
86 |
- * |
|
87 |
- * @see FIXUP_F2FP for the parameters |
|
88 |
- * Side effect: declares also some _fp_helper functions |
|
89 |
- */ |
|
90 |
-#define FIXUP_F2T(suffix, minp, maxp, no1, type1, type2) \ |
|
91 |
- FIXUP_F2FP(fp_##suffix, minp, maxp, no1, type1, type2) \ |
|
92 |
- int fixup_##suffix (void** param, int param_no) \ |
|
93 |
- { \ |
|
94 |
- int ret; \ |
|
95 |
- if ((ret=fixup_fp_##suffix (param, param_no))!=0) \ |
|
96 |
- return ret; \ |
|
97 |
- *param=((fparam_t*)*param)->fixed; \ |
|
98 |
- return 0; \ |
|
99 |
- } \ |
|
100 |
- int fixup_free_##suffix (void** param, int param_no) \ |
|
101 |
- { \ |
|
102 |
- void* p; \ |
|
103 |
- int ret; \ |
|
104 |
- if (param && *param){ \ |
|
105 |
- p=*param - (long)&((fparam_t*)0)->v; \ |
|
106 |
- if ((ret=fixup_free_fp_##suffix(&p, param_no))==0) *param=p; \ |
|
107 |
- return ret; \ |
|
108 |
- } \ |
|
109 |
- return 0; \ |
|
110 |
- } |
|
111 |
- |
|
112 |
- |
|
113 |
-/** macro for declaring a fixup and the corresponding free_fixup |
|
114 |
- * for a function expecting first no1 params as fparamt_t and the |
|
115 |
- * rest as direct type. |
|
116 |
- * |
|
117 |
- * @see FIXUP_F2FP for the parameters with the exception |
|
118 |
- * that only the first no1 parameters are converted to |
|
119 |
- * fparamt_t and the rest directly to the correponding type |
|
120 |
- * |
|
121 |
- * Side effect: declares also some _fpt_helper functions |
|
122 |
- */ |
|
123 |
-#define FIXUP_F2FP_T(suffix, minp, maxp, no1, type1, type2) \ |
|
124 |
- FIXUP_F2FP(fpt_##suffix, minp, maxp, no1, type1, type2) \ |
|
125 |
- int fixup_##suffix (void** param, int param_no) \ |
|
126 |
- { \ |
|
127 |
- int ret; \ |
|
128 |
- if ((ret=fixup_fpt_##suffix(param, param_no))!=0) \ |
|
129 |
- return ret; \ |
|
130 |
- if (param_no>(no1)) *param=&((fparam_t*)*param)->v; \ |
|
131 |
- return 0; \ |
|
132 |
- } \ |
|
133 |
- int fixup_free_##suffix (void** param, int param_no) \ |
|
134 |
- { \ |
|
135 |
- void* p; \ |
|
136 |
- int ret; \ |
|
137 |
- if (param && *param){ \ |
|
138 |
- p=(param_no>(no1))? *param - (long)&((fparam_t*)0)->v : *param;\ |
|
139 |
- if ((ret=fixup_free_fpt_##suffix(&p, param_no))==0) *param=p; \ |
|
140 |
- return ret; \ |
|
141 |
- } \ |
|
142 |
- return 0; \ |
|
143 |
- } |
|
144 |
- |
|
145 |
- |
|
146 |
-/** macro for declaring a fixup which fixes all the paremeters to the same |
|
147 |
- * type. |
|
148 |
- * |
|
149 |
- * @see FIXUP_F2T. |
|
150 |
- */ |
|
151 |
-#define FIXUP_F1T(suffix, minp, maxp, type) \ |
|
152 |
- FIXUP_F2T(suffix, minp, maxp, maxp, type, 0) |
|
153 |
- |
|
154 |
- |
|
155 |
- |
|
156 |
-FIXUP_F1T(str_null, 1, 1, FPARAM_STR) |
|
157 |
-FIXUP_F1T(str_str, 1, 2, FPARAM_STR) |
|
158 |
-FIXUP_F1T(str_all, 1, 100, FPARAM_STR) |
|
159 |
- |
|
160 |
-/* |
|
161 |
- no free fixups possible for unit_* |
|
162 |
- (they overwrite the pointer with the converted number => the original |
|
163 |
- value cannot be recovered) |
|
164 |
-FIXUP_F1T(uint_null, 1, 1, FPARAM_INT) |
|
165 |
-FIXUP_F1T(uint_uint, 1, 2, FPARAM_INT) |
|
166 |
-*/ |
|
167 |
- |
|
168 |
- |
|
169 |
- |
|
170 |
-int fixup_uint_uint(void** param, int param_no) |
|
171 |
-{ |
|
172 |
- str s; |
|
173 |
- unsigned int num; |
|
174 |
- |
|
175 |
- s.s = *param; |
|
176 |
- s.len = strlen(s.s); |
|
177 |
- if (likely(str2int(&s, &num) == 0)) { |
|
178 |
- *param = (void*)(long)num; |
|
179 |
- } else |
|
180 |
- /* not a number */ |
|
181 |
- return E_UNSPEC; |
|
182 |
- return 0; |
|
183 |
-} |
|
184 |
- |
|
185 |
- |
|
186 |
- |
|
187 |
-int fixup_uint_null(void** param, int param_no) |
|
188 |
-{ |
|
189 |
- if (param_no == 1) |
|
190 |
- return fixup_uint_uint(param, param_no); |
|
191 |
- return E_UNSPEC; |
|
192 |
-} |
|
193 |
- |
|
194 |
- |
|
195 |
-/* fixup_regexp_null() has to be written "by hand", since |
|
196 |
- it needs to save the original pointer (the fixup users expects |
|
197 |
- a pointer to the regex in *param and hence the original value |
|
198 |
- needed on free cannot be recovered directly). |
|
199 |
-FIXUP_F1T(regexp_null, 1, 1, FPARAM_REGEX) |
|
200 |
-*/ |
|
201 |
- |
|
202 |
-struct regex_fixup { |
|
203 |
- regex_t regex; /* compiled regex */ |
|
204 |
- void* orig; /* original pointer */ |
|
205 |
-}; |
|
206 |
- |
|
207 |
-int fixup_regexp_null(void** param, int param_no) |
|
208 |
-{ |
|
209 |
- struct regex_fixup* re; |
|
210 |
- |
|
211 |
- if (param_no != 1) |
|
212 |
- return E_UNSPEC; |
|
213 |
- if ((re=pkg_malloc(sizeof(*re))) ==0) { |
|
214 |
- ERR("No memory left\n"); |
|
215 |
- goto error; |
|
216 |
- } |
|
217 |
- if (regcomp(&re->regex, *param, |
|
218 |
- REG_EXTENDED|REG_ICASE|REG_NEWLINE)) |
|
219 |
- goto error; |
|
220 |
- re->orig = *param; |
|
221 |
- *param = re; |
|
222 |
- return 0; |
|
223 |
-error: |
|
224 |
- if (re) |
|
225 |
- pkg_free(re); |
|
226 |
- return E_UNSPEC; |
|
227 |
-} |
|
228 |
- |
|
229 |
- |
|
230 |
-int fixup_free_regexp_null(void** param, int param_no) |
|
231 |
-{ |
|
232 |
- struct regex_fixup* re; |
|
233 |
- |
|
234 |
- if (param_no != 1) |
|
235 |
- return E_UNSPEC; |
|
236 |
- if (*param) { |
|
237 |
- re = *param; |
|
238 |
- *param = re->orig; |
|
239 |
- regfree(&re->regex); |
|
240 |
- pkg_free(re); |
|
241 |
- } |
|
242 |
- return 0; |
|
243 |
-} |
|
244 |
- |
|
245 |
-/* fixup_pvar_*() has to be written "by hand", since |
|
246 |
- it needs to save the original pointer (the fixup users expects |
|
247 |
- a pointer to the pv_spec_t in *param and hence the original value |
|
248 |
- needed on free cannot be recovered directly). |
|
249 |
-FIXUP_F1T(pvar_null, 1, 1, FPARAM_PVS) |
|
250 |
-FIXUP_F1T(pvar_pvar, 1, 2, FPARAM_PVS) |
|
251 |
-*/ |
|
252 |
- |
|
253 |
-struct pvs_fixup { |
|
254 |
- pv_spec_t pvs; /* parsed pv spec */ |
|
255 |
- void* orig; /* original pointer */ |
|
256 |
-}; |
|
257 |
- |
|
258 |
-int fixup_pvar_all(void** param, int param_no) |
|
259 |
-{ |
|
260 |
- struct pvs_fixup* pvs_f; |
|
261 |
- str name; |
|
262 |
- |
|
263 |
- pvs_f = 0; |
|
264 |
- name.s = *param; |
|
265 |
- name.len = strlen(name.s); |
|
266 |
- trim(&name); |
|
267 |
- if (name.len == 0 || name.s[0] != '$') |
|
268 |
- /* not a pvs id */ |
|
269 |
- goto error; |
|
270 |
- if ((pvs_f=pkg_malloc(sizeof(*pvs_f))) == 0) { |
|
271 |
- ERR("No memory left\n"); |
|
272 |
- goto error; |
|
273 |
- } |
|
274 |
- if (pv_parse_spec2(&name, &pvs_f->pvs, 1) == 0) |
|
275 |
- /* not a valid pvs identifier */ |
|
276 |
- goto error; |
|
277 |
- pvs_f->orig = *param; |
|
278 |
- *param = pvs_f; |
|
279 |
- return 0; |
|
280 |
-error: |
|
281 |
- if (pvs_f) |
|
282 |
- pkg_free(pvs_f); |
|
283 |
- return E_UNSPEC; |
|
284 |
-} |
|
285 |
- |
|
286 |
- |
|
287 |
- |
|
288 |
-int fixup_free_pvar_all(void** param, int param_no) |
|
289 |
-{ |
|
290 |
- struct pvs_fixup* pvs_f; |
|
291 |
- |
|
292 |
- if (*param) { |
|
293 |
- pvs_f = *param; |
|
294 |
- *param = pvs_f->orig; |
|
295 |
- /* free only the contents (don't attempt to free &pvs_f->pvs)*/ |
|
296 |
- pv_spec_destroy(&pvs_f->pvs); |
|
297 |
- /* free the whole pvs_fixup */ |
|
298 |
- pkg_free(pvs_f); |
|
299 |
- } |
|
300 |
- return 0; |
|
301 |
-} |
|
302 |
- |
|
303 |
- |
|
304 |
- |
|
305 |
-int fixup_pvar_pvar(void** param, int param_no) |
|
306 |
-{ |
|
307 |
- if (param_no > 2) |
|
308 |
- return E_UNSPEC; |
|
309 |
- return fixup_pvar_all(param, param_no); |
|
310 |
-} |
|
311 |
- |
|
312 |
- |
|
313 |
- |
|
314 |
-int fixup_free_pvar_pvar(void** param, int param_no) |
|
315 |
-{ |
|
316 |
- if (param_no > 2) |
|
317 |
- return E_UNSPEC; |
|
318 |
- return fixup_free_pvar_all(param, param_no); |
|
319 |
-} |
|
320 |
- |
|
321 |
- |
|
322 |
-int fixup_pvar_pvar_pvar(void** param, int param_no) |
|
323 |
-{ |
|
324 |
- if (param_no > 3) |
|
325 |
- return E_UNSPEC; |
|
326 |
- return fixup_pvar_all(param, param_no); |
|
327 |
-} |
|
328 |
- |
|
329 |
-int fixup_free_pvar_pvar_pvar(void** param, int param_no) |
|
330 |
-{ |
|
331 |
- if (param_no > 3) |
|
332 |
- return E_UNSPEC; |
|
333 |
- return fixup_free_pvar_all(param, param_no); |
|
334 |
-} |
|
335 |
- |
|
336 |
- |
|
337 |
-int fixup_pvar_null(void** param, int param_no) |
|
338 |
-{ |
|
339 |
- if (param_no != 1) |
|
340 |
- return E_UNSPEC; |
|
341 |
- return fixup_pvar_all(param, param_no); |
|
342 |
-} |
|
343 |
- |
|
344 |
- |
|
345 |
- |
|
346 |
-int fixup_free_pvar_null(void** param, int param_no) |
|
347 |
-{ |
|
348 |
- if (param_no != 1) |
|
349 |
- return E_UNSPEC; |
|
350 |
- return fixup_free_pvar_all(param, param_no); |
|
351 |
-} |
|
352 |
- |
|
353 |
-int fixup_pvar_none(void** param, int param_no) |
|
354 |
-{ |
|
355 |
- if (param_no == 1) |
|
356 |
- return fixup_pvar_all(param, param_no); |
|
357 |
- return 0; |
|
358 |
-} |
|
359 |
- |
|
360 |
- |
|
361 |
- |
|
362 |
-int fixup_free_pvar_none(void** param, int param_no) |
|
363 |
-{ |
|
364 |
- if (param_no == 1) |
|
365 |
- return fixup_free_pvar_all(param, param_no); |
|
366 |
- return 0; |
|
367 |
-} |
|
368 |
- |
|
369 |
- |
|
370 |
-/* must be written "by hand", see above (fixup_pvar_pvar). |
|
371 |
-FIXUP_F2T(pvar_str, 1, 2, 1, FPARAM_PVS, FPARAM_STR) |
|
372 |
-FIXUP_F2T(pvar_str_str, 1, 3, 1, FPARAM_PVS, FPARAM_STR) |
|
373 |
-*/ |
|
374 |
- |
|
375 |
-int fixup_pvar_str(void** param, int param_no) |
|
376 |
-{ |
|
377 |
- if (param_no == 1) |
|
378 |
- return fixup_pvar_all(param, param_no); |
|
379 |
- else if (param_no == 2) |
|
380 |
- return fixup_str_str(param, param_no); |
|
381 |
- return E_UNSPEC; |
|
382 |
-} |
|
383 |
- |
|
384 |
- |
|
385 |
- |
|
386 |
-int fixup_free_pvar_str(void** param, int param_no) |
|
387 |
-{ |
|
388 |
- if (param_no == 1) |
|
389 |
- return fixup_free_pvar_all(param, param_no); |
|
390 |
- else if (param_no == 2) |
|
391 |
- return fixup_free_str_str(param, param_no); |
|
392 |
- return E_UNSPEC; |
|
393 |
-} |
|
394 |
- |
|
395 |
- |
|
396 |
- |
|
397 |
-int fixup_pvar_str_str(void** param, int param_no) |
|
398 |
-{ |
|
399 |
- if (param_no == 1) |
|
400 |
- return fixup_pvar_all(param, param_no); |
|
401 |
- else if (param_no == 2 || param_no == 3) |
|
402 |
- return fixup_str_all(param, param_no); |
|
403 |
- return E_UNSPEC; |
|
404 |
-} |
|
405 |
- |
|
406 |
- |
|
407 |
- |
|
408 |
-int fixup_free_pvar_str_str(void** param, int param_no) |
|
409 |
-{ |
|
410 |
- if (param_no == 1) |
|
411 |
- return fixup_free_pvar_all(param, param_no); |
|
412 |
- else if (param_no == 2 || param_no == 3) |
|
413 |
- return fixup_free_str_all(param, param_no); |
|
414 |
- return E_UNSPEC; |
|
415 |
-} |
|
416 |
- |
|
417 |
- |
|
418 |
-int fixup_pvar_uint(void** param, int param_no) |
|
419 |
-{ |
|
420 |
- if (param_no == 1) |
|
421 |
- return fixup_pvar_all(param, param_no); |
|
422 |
- else if (param_no == 2) |
|
423 |
- return fixup_uint_uint(param, param_no); |
|
424 |
- return E_UNSPEC; |
|
425 |
-} |
|
426 |
- |
|
427 |
- |
|
428 |
-int fixup_free_pvar_uint(void** param, int param_no) |
|
429 |
-{ |
|
430 |
- if (param_no == 1) |
|
431 |
- return fixup_free_pvar_all(param, param_no); |
|
432 |
- return E_UNSPEC; |
|
433 |
-} |
|
434 |
- |
|
435 |
- |
|
436 |
-FIXUP_F2FP(igp_null, 1, 1, 1, FPARAM_INT|FPARAM_PVS, 0) |
|
437 |
-FIXUP_F2FP(igp_igp, 1, 2, 2, FPARAM_INT|FPARAM_PVS, 0) |
|
438 |
- |
|
439 |
-/* must be declared by hand, because of the pvar special handling |
|
440 |
- (see above) |
|
441 |
-FIXUP_F2FP(igp_pvar, 1, 2, 1, FPARAM_INT|FPARAM_PVS, FPARAM_PVS) |
|
442 |
-FIXUP_F2FP_T(igp_pvar_pvar, 1, 3, 1, FPARAM_INT|FPARAM_PVS, FPARAM_PVS) |
|
443 |
-*/ |
|
444 |
- |
|
445 |
-int fixup_igp_pvar(void** param, int param_no) |
|
446 |
-{ |
|
447 |
- if (param_no == 1) |
|
448 |
- return fixup_igp_null(param, param_no); |
|
449 |
- else if (param_no == 2) |
|
450 |
- return fixup_pvar_all(param, param_no); |
|
451 |
- return E_UNSPEC; |
|
452 |
-} |
|
453 |
- |
|
454 |
- |
|
455 |
- |
|
456 |
-int fixup_free_igp_pvar(void** param, int param_no) |
|
457 |
-{ |
|
458 |
- if (param_no == 1) |
|
459 |
- return fixup_free_igp_null(param, param_no); |
|
460 |
- else if (param_no == 2) |
|
461 |
- return fixup_free_pvar_all(param, param_no); |
|
462 |
- return E_UNSPEC; |
|
463 |
-} |
|
464 |
- |
|
465 |
- |
|
466 |
- |
|
467 |
-int fixup_igp_pvar_pvar(void** param, int param_no) |
|
468 |
-{ |
|
469 |
- if (param_no == 1) |
|
470 |
- return fixup_igp_null(param, param_no); |
|
471 |
- else if (param_no == 2 || param_no == 3) |
|
472 |
- return fixup_pvar_all(param, param_no); |
|
473 |
- return E_UNSPEC; |
|
474 |
-} |
|
475 |
- |
|
476 |
- |
|
477 |
- |
|
478 |
-int fixup_free_igp_pvar_pvar(void** param, int param_no) |
|
479 |
-{ |
|
480 |
- if (param_no == 1) |
|
481 |
- return fixup_free_igp_null(param, param_no); |
|
482 |
- else if (param_no == 2 || param_no == 3) |
|
483 |
- return fixup_free_pvar_all(param, param_no); |
|
484 |
- return E_UNSPEC; |
|
485 |
-} |
|
486 |
- |
|
487 |
- |
|
488 |
- |
|
489 |
-/** macro for declaring a spve fixup and the corresponding free_fixup |
|
490 |
- * for a function expecting first no1 params as fparam converted spve |
|
491 |
- * and the * rest as direct type. |
|
492 |
- * |
|
493 |
- * @see FIXUP_F2FP for the parameters with the exception |
|
494 |
- * that the first no1 parameters are converted to fparam_t from spve |
|
495 |
- * and the rest directly to the corresponding type |
|
496 |
- * |
|
497 |
- * Side effect: declares also some _spvet_helper functions |
|
498 |
- */ |
|
499 |
-#define FIXUP_F_SPVE_T(suffix, minp, maxp, no1, type2) \ |
|
500 |
- FIXUP_F1T(spvet_##suffix, minp, maxp, type2) \ |
|
501 |
- int fixup_##suffix (void** param, int param_no) \ |
|
502 |
- { \ |
|
503 |
- int ret; \ |
|
504 |
- fparam_t* fp; \ |
|
505 |
- if (param_no<=(no1)){ \ |
|
506 |
- if ((ret=fix_param_types(FPARAM_PVE, param))<0){ \ |
|
507 |
- ERR("Cannot convert function parameter %d to spve \n", \ |
|
508 |
- param_no);\ |
|
509 |
- return E_UNSPEC; \ |
|
510 |
- } else{ \ |
|
511 |
- fp=(fparam_t*)*param; \ |
|
512 |
- if ((ret==0) && (fp->v.pve->spec==0 \ |
|
513 |
- || fp->v.pve->spec->getf==0)){ \ |
|
514 |
- fparam_free_restore(param); \ |
|
515 |
- return fix_param_types(FPARAM_STR, param); \ |
|
516 |
- } else if (ret==1) \ |
|
517 |
- return fix_param_types(FPARAM_STR, param); \ |
|
518 |
- return ret; \ |
|
519 |
- } \ |
|
520 |
- } else return fixup_spvet_##suffix(param, param_no); \ |
|
521 |
- return 0; \ |
|
522 |
- } \ |
|
523 |
- int fixup_free_##suffix (void** param, int param_no) \ |
|
524 |
- { \ |
|
525 |
- if (param && *param){ \ |
|
526 |
- if (param_no<=(no1)) \ |
|
527 |
- fparam_free_restore(param); \ |
|
528 |
- else \ |
|
529 |
- return fixup_free_spvet_##suffix(param, param_no); \ |
|
530 |
- } \ |
|
531 |
- return 0; \ |
|
532 |
- } |
|
533 |
- |
|
534 |
- |
|
535 |
-/* format: name, minp, maxp, no_of_spve_params, type_for_rest_params */ |
|
536 |
-FIXUP_F_SPVE_T(spve_spve, 1, 2, 2, 0) |
|
537 |
-FIXUP_F_SPVE_T(spve_uint, 1, 2, 1, FPARAM_INT) |
|
538 |
-FIXUP_F_SPVE_T(spve_str, 1, 2, 1, FPARAM_STR) |
|
539 |
-FIXUP_F_SPVE_T(spve_null, 1, 1, 1, 0) |
|
540 |
- |
|
541 |
-/** get the corresp. fixup_free* function. |
|
542 |
- * @param f -fixup function pointer. |
|
543 |
- * @return - pointer to free_fixup function if known, 0 otherwise. |
|
544 |
- */ |
|
545 |
-free_fixup_function mod_fix_get_fixup_free(fixup_function f) |
|
546 |
-{ |
|
547 |
- if (f == fixup_str_null) return fixup_free_str_null; |
|
548 |
- if (f == fixup_str_str) return fixup_free_str_str; |
|
549 |
- /* no free fixup for fixup_uint_* (they overwrite the pointer |
|
550 |
- value with a number and the original value cannot be recovered) */ |
|
551 |
- if (f == fixup_uint_null) return 0; |
|
552 |
- if (f == fixup_uint_uint) return 0; |
|
553 |
- if (f == fixup_regexp_null) return fixup_free_regexp_null; |
|
554 |
- if (f == fixup_pvar_null) return fixup_free_pvar_null; |
|
555 |
- if (f == fixup_pvar_pvar) return fixup_free_pvar_pvar; |
|
556 |
- if (f == fixup_pvar_str) return fixup_free_pvar_str; |
|
557 |
- if (f == fixup_pvar_str_str) return fixup_free_pvar_str_str; |
|
558 |
- if (f == fixup_igp_igp) return fixup_free_igp_igp; |
|
559 |
- if (f == fixup_igp_null) return fixup_free_igp_null; |
|
560 |
- if (f == fixup_igp_pvar) return fixup_free_igp_pvar; |
|
561 |
- if (f == fixup_igp_pvar_pvar) return fixup_free_igp_pvar_pvar; |
|
562 |
- if (f == fixup_spve_spve) return fixup_free_spve_spve; |
|
563 |
- if (f == fixup_spve_null) return fixup_free_spve_null; |
|
564 |
- /* no free fixup, because of the uint part (the uint cannot be freed, |
|
565 |
- see above fixup_uint_null) */ |
|
566 |
- if (f == fixup_spve_uint) return 0; |
|
567 |
- if (f == fixup_spve_str) return fixup_free_spve_str; |
|
568 |
- return 0; |
|
569 |
-} |
|
570 |
- |
|
571 |
-/** |
|
572 |
- * |
|
573 |
- */ |
|
574 |
-int fixup_spve_all(void** param, int param_no) |
|
575 |
-{ |
|
576 |
- return fixup_spve_null(param, 1); |
|
577 |
-} |
|
578 |
- |
|
579 |
-/** |
|
580 |
- * |
|
581 |
- */ |
|
582 |
-int fixup_igp_all(void** param, int param_no) |
|
583 |
-{ |
|
584 |
- return fixup_igp_null(param, 1); |
|
585 |
-} |
|
586 |
- |
|
587 |
-/** |
|
588 |
- * |
|
589 |
- */ |
|
590 |
-int fixup_spve_igp(void** param, int param_no) |
|
591 |
-{ |
|
592 |
- if(param_no==1) |
|
593 |
- return fixup_spve_null(param, 1); |
|
594 |
- if(param_no==2) |
|
595 |
- return fixup_igp_null(param, 1); |
|
596 |
- return E_UNSPEC; |
|
597 |
-} |
|
598 |
- |
|
599 |
-/** |
|
600 |
- * |
|
601 |
- */ |
|
602 |
-int fixup_free_spve_igp(void** param, int param_no) |
|
603 |
-{ |
|
604 |
- if(param_no==1) |
|
605 |
- return fixup_free_spve_null(param, 1); |
|
606 |
- if(param_no==2) |
|
607 |
- return fixup_free_igp_null(param, 1); |
|
608 |
- return E_UNSPEC; |
|
609 |
-} |
... | ... |
@@ -319,6 +319,20 @@ int fixup_free_pvar_pvar(void** param, int param_no) |
319 | 319 |
} |
320 | 320 |
|
321 | 321 |
|
322 |
+int fixup_pvar_pvar_pvar(void** param, int param_no) |
|
323 |
+{ |
|
324 |
+ if (param_no > 3) |
|
325 |
+ return E_UNSPEC; |
|
326 |
+ return fixup_pvar_all(param, param_no); |
|
327 |
+} |
|
328 |
+ |
|
329 |
+int fixup_free_pvar_pvar_pvar(void** param, int param_no) |
|
330 |
+{ |
|
331 |
+ if (param_no > 3) |
|
332 |
+ return E_UNSPEC; |
|
333 |
+ return fixup_free_pvar_all(param, param_no); |
|
334 |
+} |
|
335 |
+ |
|
322 | 336 |
|
323 | 337 |
int fixup_pvar_null(void** param, int param_no) |
324 | 338 |
{ |
... | ... |
@@ -14,15 +14,9 @@ |
14 | 14 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | 15 |
*/ |
16 | 16 |
|
17 |
-/* |
|
18 |
- * History: |
|
19 |
- * -------- |
|
20 |
- * 2008-11-25 initial version (andrei) |
|
21 |
- */ |
|
22 |
- |
|
23 | 17 |
/*! |
24 | 18 |
* \file |
25 |
- * \brief SIP-router core :: kamailio compatible fixups |
|
19 |
+ * \brief Kamailio core :: kamailio compatible fixups |
|
26 | 20 |
* \ingroup core |
27 | 21 |
* Module: \ref core |
28 | 22 |
*/ |
- first parameter is PV and the rest are not fixed up
... | ... |
@@ -342,6 +342,23 @@ int fixup_free_pvar_null(void** param, int param_no) |
342 | 342 |
return fixup_free_pvar_all(param, param_no); |
343 | 343 |
} |
344 | 344 |
|
345 |
+int fixup_pvar_none(void** param, int param_no) |
|
346 |
+{ |
|
347 |
+ if (param_no == 1) |
|
348 |
+ return fixup_pvar_all(param, param_no); |
|
349 |
+ return 0; |
|
350 |
+} |
|
351 |
+ |
|
352 |
+ |
|
353 |
+ |
|
354 |
+int fixup_free_pvar_none(void** param, int param_no) |
|
355 |
+{ |
|
356 |
+ if (param_no == 1) |
|
357 |
+ return fixup_free_pvar_all(param, param_no); |
|
358 |
+ return 0; |
|
359 |
+} |
|
360 |
+ |
|
361 |
+ |
|
345 | 362 |
/* must be written "by hand", see above (fixup_pvar_pvar). |
346 | 363 |
FIXUP_F2T(pvar_str, 1, 2, 1, FPARAM_PVS, FPARAM_STR) |
347 | 364 |
FIXUP_F2T(pvar_str_str, 1, 3, 1, FPARAM_PVS, FPARAM_STR) |
... | ... |
@@ -484,7 +484,8 @@ int fixup_free_igp_pvar_pvar(void** param, int param_no) |
484 | 484 |
return E_UNSPEC; \ |
485 | 485 |
} else{ \ |
486 | 486 |
fp=(fparam_t*)*param; \ |
487 |
- if ((ret==0) && (fp->v.pve->spec.getf==0)){ \ |
|
487 |
+ if ((ret==0) && (fp->v.pve->spec==0 \ |
|
488 |
+ || fp->v.pve->spec->getf==0)){ \ |
|
488 | 489 |
fparam_free_restore(param); \ |
489 | 490 |
return fix_param_types(FPARAM_STR, param); \ |
490 | 491 |
} else if (ret==1) \ |
... | ... |
@@ -557,3 +557,27 @@ int fixup_igp_all(void** param, int param_no) |
557 | 557 |
{ |
558 | 558 |
return fixup_igp_null(param, 1); |
559 | 559 |
} |
560 |
+ |
|
561 |
+/** |
|
562 |
+ * |
|
563 |
+ */ |
|
564 |
+int fixup_spve_igp(void** param, int param_no) |
|
565 |
+{ |
|
566 |
+ if(param_no==1) |
|
567 |
+ return fixup_spve_null(param, 1); |
|
568 |
+ if(param_no==2) |
|
569 |
+ return fixup_igp_null(param, 1); |
|
570 |
+ return E_UNSPEC; |
|
571 |
+} |
|
572 |
+ |
|
573 |
+/** |
|
574 |
+ * |
|
575 |
+ */ |
|
576 |
+int fixup_free_spve_igp(void** param, int param_no) |
|
577 |
+{ |
|
578 |
+ if(param_no==1) |
|
579 |
+ return fixup_free_spve_null(param, 1); |
|
580 |
+ if(param_no==2) |
|
581 |
+ return fixup_free_igp_null(param, 1); |
|
582 |
+ return E_UNSPEC; |
|
583 |
+} |
... | ... |
@@ -541,3 +541,11 @@ free_fixup_function mod_fix_get_fixup_free(fixup_function f) |
541 | 541 |
if (f == fixup_spve_str) return fixup_free_spve_str; |
542 | 542 |
return 0; |
543 | 543 |
} |
544 |
+ |
|
545 |
+/** |
|
546 |
+ * |
|
547 |
+ */ |
|
548 |
+int fixup_spve_all(void** param, int param_no) |
|
549 |
+{ |
|
550 |
+ return fixup_spve_null(param, 1); |
|
551 |
+} |
... | ... |
@@ -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,7 @@ |
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 |
*/ |
18 |
-/** |
|
19 |
- * @file mod_fix.c |
|
20 |
- * @brief kamailio compatible fixups |
|
21 |
- */ |
|
16 |
+ |
|
22 | 17 |
/* |
23 | 18 |
* History: |
24 | 19 |
* -------- |
... | ... |
@@ -27,7 +22,7 @@ |
27 | 22 |
|
28 | 23 |
/*! |
29 | 24 |
* \file |
30 |
- * \brief SIP-router core :: |
|
25 |
+ * \brief SIP-router core :: kamailio compatible fixups |
|
31 | 26 |
* \ingroup core |
32 | 27 |
* Module: \ref core |
33 | 28 |
*/ |
... | ... |
@@ -67,7 +62,7 @@ int fixup_regexpNL_none(void** param, int param_no); /* textops */ |
67 | 62 |
* @param maxp - maximum parameter number |
68 | 63 |
* @param no1 - number of parameters of type1 |
69 | 64 |
* @param type1 - fix_param type for the 1st param |
70 |
- * @paran type2 - fix_param type for all the other params |
|
65 |
+ * @param type2 - fix_param type for all the other params |
|
71 | 66 |
*/ |
72 | 67 |
#define FIXUP_F2FP(suffix, minp, maxp, no1, type1, type2) \ |
73 | 68 |
int fixup_##suffix (void** param, int param_no) \ |
... | ... |
@@ -395,6 +395,23 @@ int fixup_free_pvar_str_str(void** param, int param_no) |
395 | 395 |
} |
396 | 396 |
|
397 | 397 |
|
398 |
+int fixup_pvar_uint(void** param, int param_no) |
|
399 |
+{ |
|
400 |
+ if (param_no == 1) |
|
401 |
+ return fixup_pvar_all(param, param_no); |
|
402 |
+ else if (param_no == 2) |
|
403 |
+ return fixup_uint_uint(param, param_no); |
|
404 |
+ return E_UNSPEC; |
|
405 |
+} |
|
406 |
+ |
|
407 |
+ |
|
408 |
+int fixup_free_pvar_uint(void** param, int param_no) |
|
409 |
+{ |
|
410 |
+ if (param_no == 1) |
|
411 |
+ return fixup_free_pvar_all(param, param_no); |
|
412 |
+ return E_UNSPEC; |
|
413 |
+} |
|
414 |
+ |
|
398 | 415 |
|
399 | 416 |
FIXUP_F2FP(igp_null, 1, 1, 1, FPARAM_INT|FPARAM_PVS, 0) |
400 | 417 |
FIXUP_F2FP(igp_igp, 1, 2, 2, FPARAM_INT|FPARAM_PVS, 0) |
Fix typo-bug introduced in d756b6bfb:
fixup_pvar_pvar() called fixup_free_pvar_all() instead of
fixup_pvar_all().
Reported-by: Juha Heinanen jh tutpro com
Automatic support for expressions or variables in lots of module
functions. It applies to all the module functions declared without
a fixup, with a fixup and the corresponding free_fixup function or
with a compatible ser or kamailio style standard fixup (declared
in sr_module.h or mod_fix.h).
E.g.: f($a, "b = " + $b); t_set_fr($v + 2 + $x).
t_set_fr($foo) (equivalent now with t_set_fr("$foo")).
If the expression is constant, then there is no restriction, all the
module functions can take it as parameter.
E.g.: f("7 *" +" 6 = " + 7 * 6) # equivalent to f("7 * 6 = 42")
* origin/andrei/rve_f_params: (21 commits)
NEWS: notes about expressions in function parameters
core: enable RVE fixup support when fixup_free is present
core: automatically fill known fixup_free functions
core: functions to get a fixup corresp. fixup_free function
core: k style fixup_free fixes
core: added generic fparam fixup_free functions
core: pvapi: added pv_spec_free_contents()
core: fix "unsigned" bug in sint2str*()
core: fix auto-deref. for vars in fparam fixups
perl(k): use sr31_cmd_export_t
app_python: use sr31_cmd_export_t
core: internal module interface changes
print(s): fparam fixup example
core: support for RVEs in fparam fixups
core: rval - don't use static buffer for int conversions
core: ut.* - BSD licence
core: ut.h: added sint2strbuf()
perl(k): update api calls: s/MODULE_T/MODULE2_T/
app_python: update api calls: s/MODULE_T/MODULE2_T
print(s): more module function examples
core: support for expressions/variables in function parameters
Conflicts:
NEWS
action.c
modules/app_python/python_msgobj.c
modules_k/perl/openserxs.xs
pkg/kamailio/debian-lenny
pvapi.c
route.c
route_struct.h
sr_module.c
Added functions that given a known fixup, returns its
corresponding fixup_free function.
The known fixups are the fparam style fixups and the kamailio
style fixups (from mod_fix.h).
... | ... |
@@ -497,3 +497,33 @@ FIXUP_F_SPVE_T(spve_spve, 1, 2, 2, 0) |
497 | 497 |
FIXUP_F_SPVE_T(spve_uint, 1, 2, 1, FPARAM_INT) |
498 | 498 |
FIXUP_F_SPVE_T(spve_str, 1, 2, 1, FPARAM_STR) |
499 | 499 |
FIXUP_F_SPVE_T(spve_null, 1, 1, 1, 0) |
500 |
+ |
|
501 |
+/** get the corresp. fixup_free* function. |
|
502 |
+ * @param f -fixup function pointer. |
|
503 |
+ * @return - pointer to free_fixup function if known, 0 otherwise. |
|
504 |
+ */ |
|
505 |
+free_fixup_function mod_fix_get_fixup_free(fixup_function f) |
|
506 |
+{ |
|
507 |
+ if (f == fixup_str_null) return fixup_free_str_null; |
|
508 |
+ if (f == fixup_str_str) return fixup_free_str_str; |
|
509 |
+ /* no free fixup for fixup_uint_* (they overwrite the pointer |
|
510 |
+ value with a number and the original value cannot be recovered) */ |
|
511 |
+ if (f == fixup_uint_null) return 0; |
|
512 |
+ if (f == fixup_uint_uint) return 0; |
|
513 |
+ if (f == fixup_regexp_null) return fixup_free_regexp_null; |
|
514 |
+ if (f == fixup_pvar_null) return fixup_free_pvar_null; |
|
515 |
+ if (f == fixup_pvar_pvar) return fixup_free_pvar_pvar; |
|
516 |
+ if (f == fixup_pvar_str) return fixup_free_pvar_str; |
|
517 |
+ if (f == fixup_pvar_str_str) return fixup_free_pvar_str_str; |
|
518 |
+ if (f == fixup_igp_igp) return fixup_free_igp_igp; |
|
519 |
+ if (f == fixup_igp_null) return fixup_free_igp_null; |
|
520 |
+ if (f == fixup_igp_pvar) return fixup_free_igp_pvar; |
|
521 |
+ if (f == fixup_igp_pvar_pvar) return fixup_free_igp_pvar_pvar; |
|
522 |
+ if (f == fixup_spve_spve) return fixup_free_spve_spve; |
|
523 |
+ if (f == fixup_spve_null) return fixup_free_spve_null; |
|
524 |
+ /* no free fixup, because of the uint part (the uint cannot be freed, |
|
525 |
+ see above fixup_uint_null) */ |
|
526 |
+ if (f == fixup_spve_uint) return 0; |
|
527 |
+ if (f == fixup_spve_str) return fixup_free_spve_str; |
|
528 |
+ return 0; |
|
529 |
+} |
- always restore the original parameter pointer value in
fixup_free function.
- fixup_uint_*() re-written (don't use fparam and hence avoid
a pkg_malloc()).
- remove fixup_free_uint_*(): since the fixup_uint_*() functions
replace the original string pointer directly with an integer,
it's never possible to restore the original value => it's not
possible to have a proper fixup_free_uint_*().
- fixup_regexp_null() and fixup_free_regexp_null() fixed &
re-written. fixup_regexp_null() now uses a hack to save the
original pointer so that fixup_free_regexp_null() can restore
it (now fixup_free_regexp_null() works).
- fixup_pvar_*() and fixup_free_pvar_*() fixed & re-written
(similar with fixup_regexp_null()).
- fixup_igp_pvar(), fixup_igp_pvar_pvar(), fixup_free_igp_pvar()
and fixup_free_igp_pvar_pvar() fixed & re-written
(similar with fixup_regexp_null()).
- added missing fixup_free_* declarations.
... | ... |
@@ -51,11 +51,8 @@ int fixup_regexpNL_none(void** param, int param_no); /* textops */ |
51 | 51 |
{ \ |
52 | 52 |
if ((param_no > (maxp)) || (param_no < (minp))) \ |
53 | 53 |
return E_UNSPEC; \ |
54 |
- if (*param){ \ |
|
55 |
- fparam_free_contents((fparam_t*)*param); \ |
|
56 |
- pkg_free(*param); \ |
|
57 |
- *param=0; \ |
|
58 |
- } \ |
|
54 |
+ if (*param) \ |
|
55 |
+ fparam_free_restore(param); \ |
|
59 | 56 |
return 0; \ |
60 | 57 |
} |
61 | 58 |
|
... | ... |
@@ -150,7 +147,7 @@ int fixup_regexpNL_none(void** param, int param_no); /* textops */ |
150 | 147 |
int ret; \ |
151 | 148 |
if (param && *param){ \ |
152 | 149 |
p=(param_no>(no1))? *param - (long)&((fparam_t*)0)->v : *param;\ |
153 |
- if ((ret=fixup_free_fpt_##suffix(&p, param_no))==0) *param=0; \ |
|
150 |
+ if ((ret=fixup_free_fpt_##suffix(&p, param_no))==0) *param=p; \ |
|
154 | 151 |
return ret; \ |
155 | 152 |
} \ |
156 | 153 |
return 0; \ |
... | ... |
@@ -169,24 +166,286 @@ int fixup_regexpNL_none(void** param, int param_no); /* textops */ |
169 | 166 |
|
170 | 167 |
FIXUP_F1T(str_null, 1, 1, FPARAM_STR) |
171 | 168 |
FIXUP_F1T(str_str, 1, 2, FPARAM_STR) |
169 |
+FIXUP_F1T(str_all, 1, 100, FPARAM_STR) |
|
172 | 170 |
|
173 |
-/* TODO: int can be converted in place, no need for pkg_malloc'ed fparam_t*/ |
|
171 |
+/* |
|
172 |
+ no free fixups possible for unit_* |
|
173 |
+ (they overwrite the pointer with the converted number => the original |
|
174 |
+ value cannot be recovered) |
|
174 | 175 |
FIXUP_F1T(uint_null, 1, 1, FPARAM_INT) |
175 | 176 |
FIXUP_F1T(uint_uint, 1, 2, FPARAM_INT) |
177 |
+*/ |
|
178 |
+ |
|
179 |
+ |
|
180 |
+ |
|
181 |
+int fixup_uint_uint(void** param, int param_no) |
|
182 |
+{ |
|
183 |
+ str s; |
|
184 |
+ unsigned int num; |
|
185 |
+ |
|
186 |
+ s.s = *param; |
|
187 |
+ s.len = strlen(s.s); |
|
188 |
+ if (likely(str2int(&s, &num) == 0)) { |
|
189 |
+ *param = (void*)(long)num; |
|
190 |
+ } else |
|
191 |
+ /* not a number */ |
|
192 |
+ return E_UNSPEC; |
|
193 |
+ return 0; |
|
194 |
+} |
|
195 |
+ |
|
196 |
+ |
|