2 * $Id: items.h 2111 2007-05-01 11:18:08Z juhe $
4 * Copyright (C) 2001-2003 FhG Fokus
6 * This file is part of SIP-Router, a free SIP server.
8 * SIP-Router 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
13 * SIP-Router 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.
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
25 * \brief Definitions for Pseudo-variable support
34 #include "parser/msg_parser.h"
36 #define PV_MARKER_STR "$"
39 #define PV_LNBRACKET_STR "("
40 #define PV_LNBRACKET '('
41 #define PV_RNBRACKET_STR ")"
42 #define PV_RNBRACKET ')'
44 #define PV_LIBRACKET_STR "["
45 #define PV_LIBRACKET '['
46 #define PV_RIBRACKET_STR "]"
47 #define PV_RIBRACKET ']'
51 #define PV_VAL_EMPTY 2
54 #define PV_TYPE_INT 16
58 #define PV_NAME_INTSTR 0
59 #define PV_NAME_PVAR 1
60 #define PV_NAME_OTHER 2
66 /*! if PV name is dynamic, integer, or str */
67 #define pv_has_dname(pv) ((pv)->pvp.pvn.type==PV_NAME_PVAR)
68 #define pv_has_iname(pv) ((pv)->pvp.pvn.type==PV_NAME_INTSTR \
69 && !((pv)->pvp.pvn.u.isname.type&AVP_NAME_STR))
70 #define pv_has_sname(pv) ((pv)->pvp.pvn.type==PV_NAME_INTSTR \
71 && (pv)->pvp.pvn.u.isname.type&AVP_NAME_STR)
72 #define pv_is_w(pv) ((pv)->setf!=NULL)
75 PVT_NONE=0, PVT_EMPTY, PVT_NULL,
76 PVT_MARKER, PVT_AVP, PVT_HDR,
77 PVT_RURI, PVT_RURI_USERNAME, PVT_RURI_DOMAIN,
78 PVT_DSTURI, PVT_COLOR, PVT_BRANCH,
79 PVT_FROM, PVT_TO, PVT_OURI,
80 PVT_SCRIPTVAR, PVT_MSG_BODY, PVT_CONTEXT,
81 PVT_OTHER, PVT_EXTRA /* keep it last */
84 typedef enum _pv_type pv_type_t;
85 typedef int pv_flags_t;
88 typedef struct _pv_value
90 str rs; /*!< string value */
91 int ri; /*!< integer value */
92 int flags; /*!< flags about the type of value */
93 } pv_value_t, *pv_value_p;
95 typedef struct _pv_name
97 int type; /*!< type of name */
100 int type; /*!< type of int_str name - compatibility with AVPs */
101 int_str name; /*!< the value of the name */
103 void *dname; /*!< PV value - dynamic name */
105 } pv_name_t, *pv_name_p;
107 typedef struct _pv_index
109 int type; /*!< type of PV index */
111 int ival; /*!< integer value */
112 void *dval; /*!< PV value - dynamic index */
114 } pv_index_t, *pv_index_p;
116 typedef struct _pv_param
118 pv_name_t pvn; /*!< PV name */
119 pv_index_t pvi; /*!< PV index */
120 } pv_param_t, *pv_param_p;
122 typedef int (*pv_getf_t) (struct sip_msg*, pv_param_t*, pv_value_t*);
123 typedef int (*pv_setf_t) (struct sip_msg*, pv_param_t*, int, pv_value_t*);
125 typedef struct _pv_spec {
126 pv_type_t type; /*!< type of PV */
127 pv_getf_t getf; /*!< get PV value function */
128 pv_setf_t setf; /*!< set PV value function */
129 pv_param_t pvp; /*!< parameter to be given to get/set functions */
130 void *trans; /*!< transformations */
131 } pv_spec_t, *pv_spec_p;
133 typedef int (*pv_parse_name_f)(pv_spec_p sp, str *in);
134 typedef int (*pv_parse_index_f)(pv_spec_p sp, str *in);
135 typedef int (*pv_init_param_f)(pv_spec_p sp, int param);
137 #define pv_alter_context(pv) ((pv)->type==PVT_CONTEXT \
138 || (pv)->type==PVT_BRANCH)
143 * - $class_name(inner_name)
144 * - $(class_name[index])
145 * - $(class_name(inner_name)[index])
146 * - $(class_name{transformation})
147 * - $(class_name(inner_name){transformation})
148 * - $(class_name[index]{transformation})
149 * - $(class_name(inner_name)[index]{transformation})
151 typedef struct _pv_export {
152 str name; /*!< class name of PV */
153 pv_type_t type; /*!< type of PV */
154 pv_getf_t getf; /*!< function to get the value */
155 pv_setf_t setf; /*!< function to set the value */
156 pv_parse_name_f parse_name; /*!< function to parse the inner name */
157 pv_parse_index_f parse_index; /*!< function to parse the index of PV */
158 pv_init_param_f init_param; /*!< function to init the PV spec */
159 int iparam; /*!< parameter for the init function */
162 typedef struct _pv_elem
166 struct _pv_elem *next;
167 } pv_elem_t, *pv_elem_p;
169 char* pv_parse_spec2(str *in, pv_spec_p sp, int silent);
170 #define pv_parse_spec(in, sp) pv_parse_spec2((in), (sp), 0)
171 int pv_get_spec_value(struct sip_msg* msg, pv_spec_p sp, pv_value_t *value);
172 int pv_set_spec_value(struct sip_msg* msg, pv_spec_p sp, int op,
174 int pv_printf(struct sip_msg* msg, pv_elem_p list, char *buf, int *len);
175 int pv_elem_free_all(pv_elem_p log);
176 void pv_value_destroy(pv_value_t *val);
177 void pv_spec_free(pv_spec_t *spec);
178 void pv_spec_free_contents(pv_spec_t* spec);
179 int pv_spec_dbg(pv_spec_p sp);
180 int pv_get_spec_index(struct sip_msg* msg, pv_param_p ip, int *idx, int *flags);
181 int pv_get_avp_name(struct sip_msg* msg, pv_param_p ip, int_str *avp_name,
182 unsigned short *name_type);
183 int pv_get_spec_name(struct sip_msg* msg, pv_param_p ip, pv_value_t *name);
184 int pv_parse_format(str *in, pv_elem_p *el);
185 int pv_parse_index(pv_spec_p sp, str *in);
186 int pv_init_iname(pv_spec_p sp, int param);
187 int pv_printf_s(struct sip_msg* msg, pv_elem_p list, str *s);
189 typedef struct _pvname_list {
191 struct _pvname_list *next;
192 } pvname_list_t, *pvname_list_p;
194 typedef struct pv_spec_list {
196 struct pv_spec_list *next;
197 } pv_spec_list_t, *pv_spec_list_p;
199 pvname_list_t* parse_pvname_list(str *in, unsigned int type);
201 int register_pvars_mod(char *mod_name, pv_export_t *items);
202 int pv_free_extra_list(void);
204 /*! \brief PV helper functions */
205 int pv_get_null(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
207 int pv_get_uintval(struct sip_msg *msg, pv_param_t *param,
208 pv_value_t *res, unsigned int uival);
209 int pv_get_sintval(struct sip_msg *msg, pv_param_t *param,
210 pv_value_t *res, int sival);
211 int pv_get_strval(struct sip_msg *msg, pv_param_t *param,
212 pv_value_t *res, str *sval);
213 int pv_get_strintval(struct sip_msg *msg, pv_param_t *param,
214 pv_value_t *res, str *sval, int ival);
215 int pv_get_intstrval(struct sip_msg *msg, pv_param_t *param,
216 pv_value_t *res, int ival, str *sval);
221 #define TR_LBRACKET_STR "{"
222 #define TR_LBRACKET '{'
223 #define TR_RBRACKET_STR "}"
224 #define TR_RBRACKET '}'
225 #define TR_CLASS_MARKER '.'
226 #define TR_PARAM_MARKER ','
228 enum _tr_param_type { TR_PARAM_NONE=0, TR_PARAM_STRING, TR_PARAM_NUMBER,
229 TR_PARAM_SPEC, TR_PARAM_SUBST, TR_PARAM_OTHER };
231 typedef struct _tr_param {
238 struct _tr_param *next;
239 } tr_param_t, *tr_param_p;
241 typedef int (*tr_func_t) (struct sip_msg *, tr_param_t*, int, pv_value_t*);
243 typedef struct _trans {
252 typedef char* (*tr_parsef_t)(str *, trans_t *);
253 typedef struct _tr_export {
256 } tr_export_t, *tr_export_p;
258 char* tr_lookup(str *in, trans_t **tr);
259 tr_export_t* tr_lookup_class(str *tclass);
260 int tr_exec(struct sip_msg *msg, trans_t *t, pv_value_t *v);
261 void tr_param_free(tr_param_t *tp);
263 int register_trans_mod(char *mod_name, tr_export_t *items);