00001 /* 00002 * $Id: usr_avp.h 5299 2008-12-04 18:12:33Z henningw $ 00003 * 00004 * Copyright (C) 2001-2003 FhG Fokus 00005 * 00006 * This file is part of Kamailio, a free SIP server. 00007 * 00008 * Kamailio 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 * Kamailio 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 * History: 00023 * --------- 00024 * 2004-07-21 created (bogdan) 00025 * 2004-11-14 global aliases support added (bogdan) 00026 * 2005-02-14 list with FLAGS USAGE added (bogdan) 00027 */ 00028 00029 00030 /*! 00031 * \file 00032 * \brief AVP handling functions 00033 * - \ref AVPFlagsText 00034 * \todo 1) int_str -> (int,str), 2) avp is double linked list (faster at delete and insert) 00035 */ 00036 00037 /*! 00038 * \page AVPFlagsText AVP flags and their meaning and owner 00039 * 00040 * List with the allocated flags, their meaning and owner. 00041 * [0-7] - internal flags; [8-15] - to be used by script 00042 * flag no. owner description 00043 * ------------------------------------------------------- 00044 * 0 avp_core avp has a string name 00045 * 1 avp_core avp has a string value 00046 * 2 core contact avp qvalue change 00047 * 7 avpops module avp was loaded from DB 00048 */ 00049 00050 #ifndef _SER_URS_AVP_H_ 00051 #define _SER_URS_AVP_H_ 00052 00053 00054 #include "str.h" 00055 00056 00057 /*! basic data type for AVPs */ 00058 typedef union { 00059 int n; 00060 str s; 00061 } int_str; 00062 00063 00064 /*! AVP values and list */ 00065 struct usr_avp { 00066 unsigned short id; 00067 unsigned short flags; 00068 struct usr_avp *next; 00069 void *data; 00070 }; 00071 00072 00073 /*! delimiter between data type and name */ 00074 #define AVP_NAME_DELIM ':' 00075 00076 #define AVP_NAME_VALUE_MASK 0x0003 00077 #define AVP_CORE_MASK 0x00ff 00078 #define AVP_SCRIPT_MASK 0xff00 00079 #define avp_core_flags(f) ((f)&0x00ff) 00080 #define avp_script_flags(f) (((f)<<8)&0xff00) 00081 #define avp_get_script_flags(f) (((f)&0xff00)>>8) 00082 00083 #define AVP_NAME_STR (1<<0) 00084 #define AVP_VAL_STR (1<<1) 00085 00086 #define is_avp_str_name(a) (a->flags&AVP_NAME_STR) 00087 #define is_avp_str_val(a) (a->flags&AVP_VAL_STR) 00088 00089 00090 /*! 00091 * \brief Add an AVP to the global list 00092 * \param flags AVP flags 00093 * \param name AVP name 00094 * \param val AVP value 00095 * \return 0 on success, -1 on failure 00096 */ 00097 int add_avp( unsigned short flags, int_str name, int_str val); 00098 00099 00100 /*! 00101 * \brief Search the first matching AVP in the global list 00102 * 00103 * Search the first AVP in the global list that matches to the given parameter. 00104 * \param flags AVP flags 00105 * \param name AVP name 00106 * \param val AVP value 00107 * \param start start the search at start->next, if NULL start from the head of the global list 00108 * \return found AVP, or NULL on failure 00109 */ 00110 struct usr_avp *search_first_avp( unsigned short flags, int_str name, 00111 int_str *val, struct usr_avp *start); 00112 00113 00114 /*! 00115 * \brief Search the next AVP in the given AVP list 00116 * 00117 * Search the next AVP in the given AVP list, that is returned from search_first_avp 00118 * \param avp AVP list 00119 * \param val AVP value 00120 * \return found AVP, or NULL on failure 00121 */ 00122 struct usr_avp *search_next_avp( struct usr_avp *avp, int_str *val ); 00123 00124 00125 /*! 00126 * \brief Destroy global AVP list 00127 */ 00128 void reset_avps(void); 00129 00130 00131 /*! 00132 * \brief Search AVP in list and delete it 00133 * \param avp searched AVP 00134 */ 00135 void destroy_avp( struct usr_avp *avp); 00136 00137 00138 /*! 00139 * \brief Search AVP(s) in list and destroy them 00140 * \param flags AVP flags 00141 * \param name AVP name 00142 * \param all set to 1 to delete all matching AVPs, 0 to delete only the first 00143 * \return the number of AVPs that were deleted 00144 */ 00145 int destroy_avps( unsigned short flags, int_str name, int all); 00146 00147 00148 /*! 00149 * \brief Free an AVP list in shared memory with memory locking 00150 * \param list AVP list 00151 */ 00152 void destroy_avp_list( struct usr_avp **list ); 00153 00154 00155 /*! 00156 * \brief Free an AVP list in shared memory without memory locking 00157 * \param list AVP list 00158 */ 00159 void destroy_avp_list_unsafe( struct usr_avp **list ); 00160 00161 00162 /*! 00163 * \brief Get AVP value 00164 * \param avp inspected AVP 00165 * \param val returned value 00166 */ 00167 void get_avp_val(struct usr_avp *avp, int_str *val ); 00168 00169 00170 /*! 00171 * \brief Get AVP name 00172 * \param avp inspected AVP 00173 * \return pointer to the name, 0 on error 00174 */ 00175 str* get_avp_name(struct usr_avp *avp); 00176 00177 00178 /*! 00179 * \brief Set global AVP list, assert that old list is not null 00180 * \param list new AVP list 00181 * \return pointer to old list 00182 */ 00183 struct usr_avp** set_avp_list( struct usr_avp **list ); 00184 00185 00186 /*! 00187 * \brief Return global AVP list, assert that is not null 00188 * \return global AVP list 00189 */ 00190 struct usr_avp** get_avp_list(void); 00191 00192 00193 /*! 00194 * \brief Add global alias 00195 * \param alias_definition alias definition, including the AVP 00196 * \return 0 on success, -1 on error 00197 */ 00198 int add_avp_galias_str(char *alias_definition); 00199 00200 00201 /*! 00202 * \brief Lookup global AVP alias 00203 * \param alias alias string 00204 * \param type AVP type 00205 * \param avp_name AVP name 00206 * \return 0 if alias to specified AVP could be found, -1 if not found 00207 */ 00208 int lookup_avp_galias(str *alias, int *type, int_str *avp_name); 00209 00210 00211 /*! 00212 * \brief Add global AVP alias to the list, allocate private memory 00213 * \param alias alias string 00214 * \param type AVP type 00215 * \param avp_name AVP name 00216 * \return 0 on success, -1 on failure 00217 */ 00218 int add_avp_galias(str *alias, int type, int_str avp_name); 00219 00220 00221 /*! 00222 * \brief Parse an AVP name (as string) and set type and name 00223 * \param name AVP name 00224 * \param type AVP type 00225 * \param avp_name AVP name 00226 * \return 0 on success, -1 on failure 00227 */ 00228 int parse_avp_name( str *name, int *type, int_str *avp_name); 00229 00230 00231 /*! 00232 * \brief Parse AVP specification (alias or AVP) and set type and name 00233 * \param name AVP name 00234 * \param type AVP type 00235 * \param avp_name 00236 * \return 0 on success, -1 on failure 00237 */ 00238 int parse_avp_spec( str *name, int *type, int_str *avp_name); 00239 00240 #endif
1.5.6