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

usr_avp.h

00001 /*
00002  * $Id$
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of ser, a free SIP server.
00007  *
00008  * ser 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  * For a license to use the ser software under conditions
00014  * other than those described here, or to purchase support for this
00015  * software, please contact iptel.org by e-mail at the following addresses:
00016  *    info@iptel.org
00017  *
00018  * ser is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  *
00027  * History:
00028  * ---------
00029  *  2004-07-21  created (bogdan)
00030  *  2004-11-14  global aliases support added
00031  *  2005-02-14  list with FLAGS USAGE added (bogdan)
00032  */
00033 
00034 #ifndef _SER_USR_AVP_H_
00035 #define _SER_USR_AVP_H_
00036 
00037 #include <sys/types.h>
00038 #include <regex.h>
00039 
00040 
00041 /*
00042  *   LIST with the allocated flags, their meaning and owner
00043  *   flag no.    owner            description
00044  *   -------------------------------------------------------
00045  *     0        avp_core          avp has a string name
00046  *     1        avp_core          avp has a string value
00047  *     2        avp_core          regex search in progress
00048  *     3        avpops module     avp was loaded from DB
00049  *     4        lcr module        contact avp qvalue change
00050  *     5        core              avp is in user list
00051  *     6        core              avp is in domain list
00052  *     7        core              avp is in global list
00053  *     8        core              avp is in the from avp list
00054  *     9        core              avp is in the to avp list
00055  *    10        core              avp name with positive index
00056  *    11        core              avp name with negative index
00057  */
00058 
00059 #include "str.h"
00060 
00061 
00062 #define AVP_UID          "uid"           /* Unique user identifier */
00063 #define AVP_DID          "did"           /* Unique domain identifier */
00064 #define AVP_REALM        "digest_realm"  /* Digest realm */
00065 #define AVP_FR_TIMER     "fr_timer"      /* Value of final response timer */
00066 #define AVP_FR_INV_TIMER "fr_inv_timer"  /* Value of final response invite timer */
00067 #define AVP_RPID         "rpid"          /* Remote-Party-ID */
00068 #define AVP_GFLAGS       "gflags"        /* global flags */
00069 
00070 struct str_int_data {
00071         str name;
00072         int val;
00073 };
00074 
00075 struct str_str_data {
00076         str name;
00077         str val;
00078 };
00079 
00080 typedef union {
00081         int  n;
00082         str  s;
00083         regex_t* re;
00084 } int_str;
00085 
00086 #define avp_id_t        unsigned short
00087 #define avp_flags_t     unsigned int
00088 #define avp_name_t      int_str
00089 #define avp_value_t     int_str
00090 #define avp_index_t     unsigned short
00091 
00092 union usr_avp_data{
00093         void *p; /* forces alignment */
00094         long l;
00095         char data[sizeof(void*)]; /* used to access other types, var length */
00096 };
00097 
00098 typedef struct usr_avp {
00099         avp_id_t id;
00100         /* Flags that are kept for the AVP lifetime */
00101         avp_flags_t flags;
00102         struct usr_avp *next;
00103         union usr_avp_data d; /* var length */
00104 } avp_t;
00105 
00106 typedef avp_t* avp_list_t;
00107 
00108 /* AVP identification */
00109 typedef struct avp_ident {
00110         avp_flags_t flags;
00111         avp_name_t name;
00112         avp_index_t index;
00113 } avp_ident_t;
00114 
00115 /*
00116  * AVP search state
00117  */
00118 struct search_state {
00119         avp_flags_t flags;  /* Type of search and additional flags */
00120         avp_id_t id;
00121         avp_name_t name;
00122         avp_t* avp;            /* Current AVP */
00123 //      regex_t* search_re;    /* Compiled regular expression */
00124 };
00125 
00126 /* avp aliases structs*/
00127 typedef struct avp_spec {
00128         avp_flags_t type;
00129         avp_name_t name;
00130         avp_index_t index;
00131 } avp_spec_t;
00132 
00133 /* AVP types */
00134 #define AVP_NAME_STR     (1<<0)
00135 #define AVP_VAL_STR      (1<<1)
00136 #define AVP_NAME_RE      (1<<2)
00137 
00138 /* AVP classes */
00139 #define AVP_CLASS_URI    (1<<4)
00140 #define AVP_CLASS_USER   (1<<5)
00141 #define AVP_CLASS_DOMAIN (1<<6)
00142 #define AVP_CLASS_GLOBAL (1<<7)
00143 
00144 /* AVP track (either from or to) */
00145 #define AVP_TRACK_FROM   (1<<8)
00146 #define AVP_TRACK_TO     (1<<9)
00147 #define AVP_TRACK_ALL    (AVP_TRACK_FROM|AVP_TRACK_TO)
00148 
00149 #define AVP_CLASS_ALL (AVP_CLASS_URI|AVP_CLASS_USER|AVP_CLASS_DOMAIN|AVP_CLASS_GLOBAL)
00150 
00151 /* AVP name index */
00152 #define AVP_INDEX_FORWARD       (1<<10)
00153 #define AVP_INDEX_BACKWARD      (1<<11)
00154 #define AVP_INDEX_ALL           (AVP_INDEX_FORWARD | AVP_INDEX_BACKWARD)
00155 
00156 /* AVP DB flag used by avpops module - defined in avpops
00157  * - kept here for reference */
00158 // #define AVP_IS_IN_DB    (1<<12)
00159 
00160 #define AVP_CUSTOM_FLAGS        13
00161 
00162 #define GALIAS_CHAR_MARKER  '$'
00163 
00164 #define AVP_NAME_VALUE_MASK     0x0007
00165 #define AVP_CORE_MASK           0x00ff
00166 #define AVP_SCRIPT_MASK         0xff00
00167 #define avp_core_flags(f)       ((f)&0x00ff)
00168 #define avp_script_flags(f)     (((f)<<8)&0xff00)
00169 #define avp_get_script_flags(f) (((f)&0xff00)>>8)
00170 
00171 #define is_avp_str_name(a)      ((a)->flags&AVP_NAME_STR)
00172 #define is_avp_str_val(a)       ((a)->flags&AVP_VAL_STR)
00173 
00174 
00175 #define AVP_IS_ASSIGNABLE(ident) ( ((ident).flags & AVP_NAME_RE) == 0 && (((ident).flags & AVP_NAME) == 0 || (((ident)->flags & AVP_NAME) && (ident).name.s.len)) )
00176 /* Initialize memory structures */
00177 int init_avps(void);
00178 
00179 /* add avp to the list of avps */
00180 int add_avp(avp_flags_t flags, avp_name_t name, avp_value_t val);
00181 int add_avp_before(avp_t *avp, avp_flags_t flags, avp_name_t name, avp_value_t val);
00182 int add_avp_list(avp_list_t* list, avp_flags_t flags, avp_name_t name, avp_value_t val);
00183 
00184 /* Delete avps with given type and name */
00185 void delete_avp(avp_flags_t flags, avp_name_t name);
00186 
00187 int destroy_avps(avp_flags_t flags, avp_name_t name, int all);
00188 
00189 /* search functions */
00190 avp_t *search_first_avp( avp_flags_t flags, avp_name_t name,
00191                          avp_value_t *val, struct search_state* state);
00192 avp_t *search_avp_by_index( avp_flags_t flags, avp_name_t name,
00193                             avp_value_t *val, avp_index_t index);
00194 
00195 avp_t *search_avp (avp_ident_t ident, avp_value_t* val, struct search_state* state);
00196 avp_t *search_next_avp(struct search_state* state, avp_value_t *val);
00197 
00198 /* Reset one avp list */
00199 int reset_avp_list(int flags);
00200 
00201 /* free functions */
00202 void reset_avps(void);
00203 
00204 void destroy_avp(avp_t *avp);
00205 void destroy_avp_list(avp_list_t *list );
00206 void destroy_avp_list_unsafe(avp_list_t *list );
00207 
00208 /* get func */
00209 void get_avp_val(avp_t *avp, avp_value_t *val );
00210 str* get_avp_name(avp_t *avp);
00211 
00212 avp_list_t get_avp_list(avp_flags_t flags);
00213 avp_list_t* set_avp_list(avp_flags_t flags, avp_list_t* list);
00214 
00215 
00216 /* global alias functions (manipulation and parsing)*/
00217 int add_avp_galias_str(char *alias_definition);
00218 int lookup_avp_galias(str *alias, int *type, int_str *avp_name);
00219 int add_avp_galias(str *alias, int type, int_str avp_name);
00220 int parse_avp_ident( str *name, avp_ident_t* attr);
00221 int parse_avp_name( str *name, int *type, int_str *avp_name, int *index);
00222 int parse_avp_spec( str *name, int *type, int_str *avp_name, int *index);
00223 int km_parse_avp_spec( str *name, int *type, int_str *avp_name);
00224 void free_avp_name( avp_flags_t *type, int_str *avp_name);
00225 /* Free an ident obtained with parse_avp_ident() */
00226 void free_avp_ident(avp_ident_t* attr);
00227 
00228 /* AVP flags functions */
00229 #define MAX_AVPFLAG  ((unsigned int)( sizeof(avp_flags_t) * CHAR_BIT - 1 - AVP_CUSTOM_FLAGS))
00230 
00231 avp_flags_t register_avpflag(char* name);
00232 avp_flags_t get_avpflag_no(char* name);
00233 
00234 #endif

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