Browse code

fixups: added kamailio compatible fixups

- 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)

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