• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

pvar.h

Go to the documentation of this file.
00001 /*
00002  * $Id: items.h 2111 2007-05-01 11:18:08Z juhe $
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of SIP-Router, a free SIP server.
00007  *
00008  * SIP-Router is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * SIP-Router is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License 
00019  * along with this program; if not, write to the Free Software 
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  */
00022 
00029 #ifndef _PVAR_H_
00030 #define _PVAR_H_
00031 
00032 #include "str.h"
00033 #include "usr_avp.h"
00034 #include "parser/msg_parser.h"
00035 
00036 #define PV_MARKER_STR   "$"
00037 #define PV_MARKER               '$'
00038 
00039 #define PV_LNBRACKET_STR        "("
00040 #define PV_LNBRACKET            '('
00041 #define PV_RNBRACKET_STR        ")"
00042 #define PV_RNBRACKET            ')'
00043 
00044 #define PV_LIBRACKET_STR        "["
00045 #define PV_LIBRACKET            '['
00046 #define PV_RIBRACKET_STR        "]"
00047 #define PV_RIBRACKET            ']'
00048 
00049 #define PV_VAL_NONE                     0
00050 #define PV_VAL_NULL                     1
00051 #define PV_VAL_EMPTY            2
00052 #define PV_VAL_STR                      4
00053 #define PV_VAL_INT                      8
00054 #define PV_TYPE_INT                     16
00055 #define PV_VAL_PKG                      32
00056 #define PV_VAL_SHM                      64
00057 
00058 #define PV_NAME_INTSTR  0
00059 #define PV_NAME_PVAR    1
00060 #define PV_NAME_OTHER   2
00061 
00062 #define PV_IDX_INT      0
00063 #define PV_IDX_PVAR     1
00064 #define PV_IDX_ALL      2
00065 
00067 #define pv_has_dname(pv) ((pv)->pvp.pvn.type==PV_NAME_PVAR)
00068 #define pv_has_iname(pv) ((pv)->pvp.pvn.type==PV_NAME_INTSTR \
00069                                                         && !((pv)->pvp.pvn.u.isname.type&AVP_NAME_STR))
00070 #define pv_has_sname(pv) ((pv)->pvp.pvn.type==PV_NAME_INTSTR \
00071                                                         && (pv)->pvp.pvn.u.isname.type&AVP_NAME_STR)
00072 #define pv_is_w(pv)     ((pv)->setf!=NULL)
00073 
00074 enum _pv_type { 
00075         PVT_NONE=0,           PVT_EMPTY,             PVT_NULL, 
00076         PVT_MARKER,           PVT_AVP,               PVT_HDR,
00077         PVT_RURI,             PVT_RURI_USERNAME,     PVT_RURI_DOMAIN,
00078         PVT_DSTURI,           PVT_COLOR,             PVT_BRANCH,
00079         PVT_FROM,             PVT_TO,                PVT_OURI,
00080         PVT_SCRIPTVAR,        PVT_MSG_BODY,          PVT_CONTEXT,
00081         PVT_OTHER,            PVT_EXTRA /* keep it last */
00082 };
00083 
00084 typedef enum _pv_type pv_type_t;
00085 typedef int pv_flags_t;
00086 
00087 typedef void (*pv_name_free_f)(void*);
00088 
00089 typedef struct _pv_value
00090 {
00091         str rs;    
00092         int ri;    
00093         int flags; 
00094 } pv_value_t, *pv_value_p;
00095 
00096 typedef struct _pv_name
00097 {
00098         int type;             
00099         pv_name_free_f nfree; 
00100         union {
00101                 struct {
00102                         int type;     
00103                         int_str name; 
00104                 } isname;
00105                 void *dname;      
00106         } u;
00107 } pv_name_t, *pv_name_p;
00108 
00109 typedef struct _pv_index
00110 {
00111         int type; 
00112         union {
00113                 int ival;   
00114                 void *dval; 
00115         } u;
00116 } pv_index_t, *pv_index_p;
00117 
00118 typedef struct _pv_param
00119 {
00120         pv_name_t    pvn; 
00121         pv_index_t   pvi; 
00122 } pv_param_t, *pv_param_p;
00123 
00124 typedef int (*pv_getf_t) (struct sip_msg*,  pv_param_t*, pv_value_t*);
00125 typedef int (*pv_setf_t) (struct sip_msg*,  pv_param_t*, int, pv_value_t*);
00126 
00127 typedef struct _pv_spec {
00128         pv_type_t    type;   
00129         pv_getf_t    getf;   
00130         pv_setf_t    setf;   
00131         pv_param_t   pvp;    
00132         void         *trans; 
00133 } pv_spec_t, *pv_spec_p;
00134 
00135 typedef int (*pv_parse_name_f)(pv_spec_p sp, str *in);
00136 typedef int (*pv_parse_index_f)(pv_spec_p sp, str *in);
00137 typedef int (*pv_init_param_f)(pv_spec_p sp, int param);
00138 
00139 #define pv_alter_context(pv)    ((pv)->type==PVT_CONTEXT \
00140                                                                         || (pv)->type==PVT_BRANCH)
00141 
00153 typedef struct _pv_export {
00154         str name;                      
00155         pv_type_t type;                
00156         pv_getf_t  getf;               
00157         pv_setf_t  setf;               
00158         pv_parse_name_f parse_name;    
00159         pv_parse_index_f parse_index;  
00160         pv_init_param_f init_param;    
00161         int iparam;                    
00162 } pv_export_t;
00163 
00164 typedef struct _pv_elem
00165 {
00166         str text;
00167         pv_spec_t spec;
00168         struct _pv_elem *next;
00169 } pv_elem_t, *pv_elem_p;
00170 
00171 char* pv_parse_spec2(str *in, pv_spec_p sp, int silent);
00172 #define pv_parse_spec(in, sp) pv_parse_spec2((in), (sp), 0)
00173 int pv_get_spec_value(struct sip_msg* msg, pv_spec_p sp, pv_value_t *value);
00174 int pv_set_spec_value(struct sip_msg* msg, pv_spec_p sp, int op,
00175                 pv_value_t *value);
00176 int pv_printf(struct sip_msg* msg, pv_elem_p list, char *buf, int *len);
00177 int pv_elem_free_all(pv_elem_p log);
00178 void pv_value_destroy(pv_value_t *val);
00179 void pv_spec_destroy(pv_spec_t *spec);
00180 void pv_spec_free(pv_spec_t *spec);
00181 int pv_spec_dbg(pv_spec_p sp);
00182 int pv_get_spec_index(struct sip_msg* msg, pv_param_p ip, int *idx, int *flags);
00183 int pv_get_avp_name(struct sip_msg* msg, pv_param_p ip, int_str *avp_name,
00184                 unsigned short *name_type);
00185 int pv_parse_avp_name(pv_spec_p sp, str *in);
00186 int pv_get_spec_name(struct sip_msg* msg, pv_param_p ip, pv_value_t *name);
00187 int pv_parse_format(str *in, pv_elem_p *el);
00188 int pv_parse_index(pv_spec_p sp, str *in);
00189 int pv_init_iname(pv_spec_p sp, int param);
00190 int pv_printf_s(struct sip_msg* msg, pv_elem_p list, str *s);
00191 
00192 typedef struct _pvname_list {
00193         pv_spec_t sname;
00194         struct _pvname_list *next;
00195 } pvname_list_t, *pvname_list_p;
00196 
00197 typedef struct pv_spec_list {
00198         pv_spec_p spec;
00199         struct pv_spec_list *next;
00200 } pv_spec_list_t, *pv_spec_list_p;
00201 
00202 pvname_list_t* parse_pvname_list(str *in, unsigned int type);
00203 
00204 int register_pvars_mod(char *mod_name, pv_export_t *items);
00205 int pv_free_extra_list(void);
00206 
00207 int pv_locate_name(str *in);
00208 pv_spec_t* pv_cache_get(str *name);
00209 
00211 int pv_get_null(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
00212 
00213 int pv_get_uintval(struct sip_msg *msg, pv_param_t *param,
00214                 pv_value_t *res, unsigned int uival);
00215 int pv_get_sintval(struct sip_msg *msg, pv_param_t *param,
00216                 pv_value_t *res, int sival);
00217 int pv_get_strval(struct sip_msg *msg, pv_param_t *param,
00218                 pv_value_t *res, str *sval);
00219 int pv_get_strintval(struct sip_msg *msg, pv_param_t *param,
00220                 pv_value_t *res, str *sval, int ival);
00221 int pv_get_intstrval(struct sip_msg *msg, pv_param_t *param,
00222                 pv_value_t *res, int ival, str *sval);
00223 
00227 #define TR_LBRACKET_STR         "{"
00228 #define TR_LBRACKET             '{'
00229 #define TR_RBRACKET_STR         "}"
00230 #define TR_RBRACKET             '}'
00231 #define TR_CLASS_MARKER         '.'
00232 #define TR_PARAM_MARKER         ','
00233 
00234 enum _tr_param_type { TR_PARAM_NONE=0, TR_PARAM_STRING, TR_PARAM_NUMBER,
00235         TR_PARAM_SPEC, TR_PARAM_SUBST, TR_PARAM_OTHER };
00236 
00237 typedef struct _tr_param {
00238         int type;
00239         union {
00240                 int n;
00241                 str s;
00242                 void *data;
00243         } v;
00244         struct _tr_param *next;
00245 } tr_param_t, *tr_param_p;
00246 
00247 typedef int (*tr_func_t) (struct sip_msg *, tr_param_t*, int, pv_value_t*);
00248 
00249 typedef struct _trans {
00250         str name;
00251         int type;
00252         int subtype;
00253         tr_func_t trf;
00254         tr_param_t *params;
00255         struct _trans *next;
00256 } trans_t, *trans_p;
00257 
00258 typedef char* (*tr_parsef_t)(str *, trans_t *);
00259 typedef struct _tr_export {
00260         str tclass;
00261         tr_parsef_t tparse; 
00262 } tr_export_t, *tr_export_p;
00263 
00264 char* tr_lookup(str *in, trans_t **tr);
00265 tr_export_t* tr_lookup_class(str *tclass);
00266 int tr_exec(struct sip_msg *msg, trans_t *t, pv_value_t *v);
00267 void tr_param_free(tr_param_t *tp);
00268 
00269 int register_trans_mod(char *mod_name, tr_export_t *items);
00270 
00271 #endif
00272 

Generated on Tue May 22 2012 13:10:13 for SIP Router by  doxygen 1.7.1