Browse code

updated pvar.h file according to previous commit

- to include only PV and transformation API, no implementation
- (still learning GIT to do it in one step :-) )

Daniel-Constantin Mierla authored on 20/11/2008 12:28:35
Showing 1 changed files
... ...
@@ -1,38 +1,74 @@
1 1
 /*
2
- * $Id$
2
+ * $Id: items.h 2111 2007-05-01 11:18:08Z juhe $
3 3
  *
4
- * Copyright (C) 2008 
4
+ * Copyright (C) 2001-2003 FhG Fokus
5 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.
6
+ * This file is part of Kamailio, a free SIP server.
9 7
  *
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
- * pvar compatibility wrapper for kamailio
20
- * for now it doesn't do anything (feel free to rm & replace the file)
8
+ * Kamailio is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
12
+ *
13
+ * Kamailio is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
21 17
  *
22
- * History:
23
- * --------
24
- *  2008-11-17  initial version compatible with kamailio pvar.h (andrei)
18
+ * You should have received a copy of the GNU General Public License 
19
+ * along with this program; if not, write to the Free Software 
20
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
+ */
22
+
23
+/*!
24
+ * \file
25
+ * \brief Definitions for Pseudo-variable support
25 26
  */
26 27
 
27
-#ifndef _pvar_h_
28
-#define _pvar_h_
28
+
29
+#ifndef _PVAR_H_
30
+#define _PVAR_H_
29 31
 
30 32
 #include "str.h"
31 33
 #include "usr_avp.h"
32 34
 #include "parser/msg_parser.h"
33 35
 
36
+#define PV_MARKER_STR	"$"
37
+#define PV_MARKER		'$'
38
+
39
+#define PV_LNBRACKET_STR	"("
40
+#define PV_LNBRACKET		'('
41
+#define PV_RNBRACKET_STR	")"
42
+#define PV_RNBRACKET		')'
43
+
44
+#define PV_LIBRACKET_STR	"["
45
+#define PV_LIBRACKET		'['
46
+#define PV_RIBRACKET_STR	"]"
47
+#define PV_RIBRACKET		']'
48
+
49
+#define PV_VAL_NONE			0
50
+#define PV_VAL_NULL			1
51
+#define PV_VAL_EMPTY		2
52
+#define PV_VAL_STR			4
53
+#define PV_VAL_INT			8
54
+#define PV_TYPE_INT			16
55
+#define PV_VAL_PKG			32
56
+#define PV_VAL_SHM			64
34 57
 
58
+#define PV_NAME_INTSTR	0
59
+#define PV_NAME_PVAR	1
35 60
 
61
+#define PV_IDX_INT	0
62
+#define PV_IDX_PVAR	1
63
+#define PV_IDX_ALL	2
64
+
65
+/*! if PV name is dynamic, integer, or str */
66
+#define pv_has_dname(pv) ((pv)->pvp.pvn.type==PV_NAME_PVAR)
67
+#define pv_has_iname(pv) ((pv)->pvp.pvn.type==PV_NAME_INTSTR \
68
+							&& !((pv)->pvp.pvn.u.isname.type&AVP_NAME_STR))
69
+#define pv_has_sname(pv) ((pv)->pvp.pvn.type==PV_NAME_INTSTR \
70
+							&& (pv)->pvp.pvn.u.isname.type&AVP_NAME_STR)
71
+#define pv_is_w(pv)	((pv)->setf!=NULL)
36 72
 
37 73
 enum _pv_type { 
38 74
 	PVT_NONE=0,           PVT_EMPTY,             PVT_NULL, 
... ...
@@ -63,12 +99,14 @@ enum _pv_type {
63 63
 	PVT_ERR_INFO,         PVT_ERR_RCODE,         PVT_ERR_RREASON,
64 64
 	PVT_SCRIPTVAR,        PVT_PROTO,             PVT_AUTH_USERNAME_WHOLE,
65 65
 	PVT_AUTH_DURI,        PVT_DIV_REASON,        PVT_DIV_PRIVACY,
66
-	PVT_AUTH_DOMAIN,      PVT_EXTRA /* keep it last */
66
+	PVT_AUTH_DOMAIN,      PVT_OTHER,
67
+	PVT_EXTRA /* keep it last */
67 68
 };
68 69
 
69 70
 typedef enum _pv_type pv_type_t;
70 71
 typedef int pv_flags_t;
71 72
 
73
+
72 74
 typedef struct _pv_value
73 75
 {
74 76
 	str rs;    /*!< string value */
... ...
@@ -114,8 +152,6 @@ typedef struct _pv_spec {
114 114
 	void         *trans; /*!< transformations */
115 115
 } pv_spec_t, *pv_spec_p;
116 116
 
117
-
118
-
119 117
 typedef int (*pv_parse_name_f)(pv_spec_p sp, str *in);
120 118
 typedef int (*pv_parse_index_f)(pv_spec_p sp, str *in);
121 119
 typedef int (*pv_init_param_f)(pv_spec_p sp, int param);
... ...
@@ -142,4 +178,103 @@ typedef struct _pv_export {
142 142
 	int iparam;                    /*!< parameter for the init function */
143 143
 } pv_export_t;
144 144
 
145
-#endif /* _pvar_h_ */
145
+typedef struct _pv_elem
146
+{
147
+	str text;
148
+	pv_spec_t spec;
149
+	struct _pv_elem *next;
150
+} pv_elem_t, *pv_elem_p;
151
+
152
+char* pv_parse_spec(str *in, pv_spec_p sp);
153
+int pv_get_spec_value(struct sip_msg* msg, pv_spec_p sp, pv_value_t *value);
154
+int pv_print_spec(struct sip_msg* msg, pv_spec_p sp, char *buf, int *len);
155
+int pv_printf(struct sip_msg* msg, pv_elem_p list, char *buf, int *len);
156
+int pv_elem_free_all(pv_elem_p log);
157
+void pv_value_destroy(pv_value_t *val);
158
+void pv_spec_free(pv_spec_t *spec);
159
+int pv_spec_dbg(pv_spec_p sp);
160
+int pv_get_spec_index(struct sip_msg* msg, pv_param_p ip, int *idx, int *flags);
161
+int pv_get_avp_name(struct sip_msg* msg, pv_param_p ip, int_str *avp_name,
162
+		unsigned short *name_type);
163
+int pv_get_spec_name(struct sip_msg* msg, pv_param_p ip, pv_value_t *name);
164
+int pv_parse_format(str *in, pv_elem_p *el);
165
+int pv_init_iname(pv_spec_p sp, int param);
166
+int pv_printf_s(struct sip_msg* msg, pv_elem_p list, str *s);
167
+
168
+typedef struct _pvname_list {
169
+	pv_spec_t sname;
170
+	struct _pvname_list *next;
171
+} pvname_list_t, *pvname_list_p;
172
+
173
+typedef struct pv_spec_list {
174
+	pv_spec_p spec;
175
+	struct pv_spec_list *next;
176
+} pv_spec_list_t, *pv_spec_list_p;
177
+
178
+pvname_list_t* parse_pvname_list(str *in, unsigned int type);
179
+
180
+int register_pvars_mod(char *mod_name, pv_export_t *items);
181
+int pv_free_extra_list(void);
182
+
183
+/*! \brief PV helper functions */
184
+int pv_parse_index(pv_spec_p sp, str *in);
185
+
186
+int pv_get_null(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
187
+int pv_update_time(struct sip_msg *msg, time_t *t);
188
+
189
+int pv_get_uintval(struct sip_msg *msg, pv_param_t *param,
190
+		pv_value_t *res, unsigned int uival);
191
+int pv_get_sintval(struct sip_msg *msg, pv_param_t *param,
192
+		pv_value_t *res, int sival);
193
+int pv_get_strval(struct sip_msg *msg, pv_param_t *param,
194
+		pv_value_t *res, str *sval);
195
+int pv_get_strintval(struct sip_msg *msg, pv_param_t *param,
196
+		pv_value_t *res, str *sval, int ival);
197
+int pv_get_intstrval(struct sip_msg *msg, pv_param_t *param,
198
+		pv_value_t *res, int ival, str *sval);
199
+
200
+/**
201
+ * Transformations
202
+ */
203
+#define TR_LBRACKET_STR		"{"
204
+#define TR_LBRACKET		'{'
205
+#define TR_RBRACKET_STR		"}"
206
+#define TR_RBRACKET		'}'
207
+#define TR_CLASS_MARKER		'.'
208
+#define TR_PARAM_MARKER		','
209
+
210
+enum _tr_param_type { TR_PARAM_NONE=0, TR_PARAM_STRING, TR_PARAM_NUMBER,
211
+	TR_PARAM_SPEC };
212
+
213
+typedef struct _tr_param {
214
+	int type;
215
+	union {
216
+		int n;
217
+		str s;
218
+		void *data;
219
+	} v;
220
+	struct _tr_param *next;
221
+} tr_param_t, *tr_param_p;
222
+
223
+typedef int (*tr_func_t) (struct sip_msg *, tr_param_t*, int, pv_value_t*);
224
+
225
+typedef struct _trans {
226
+	str name;
227
+	int type;
228
+	int subtype;
229
+	tr_func_t trf;
230
+	tr_param_t *params;
231
+	struct _trans *next;
232
+} trans_t, *trans_p;
233
+
234
+typedef char* (*tr_parsef_t)(str *, trans_t *);
235
+typedef struct _tr_export {
236
+	str tclass;
237
+	tr_parsef_t tparse; 
238
+} tr_export_t, *tr_export_p;
239
+
240
+char* tr_lookup(str *in, trans_t **tr);
241
+tr_export_t* tr_lookup_class(str *tclass);
242
+
243
+#endif
244
+