hf.h

Go to the documentation of this file.
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  * 2003-02-28 scratchpad compatibility abandoned (jiri)
00030  * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
00031  * 2003-05-01 HDR_ACCEPT added (janakj)
00032  * 2005-02-14 hdr_flags_t && hdr_flags_f defined, split HDR_xxx into
00033  *             HDR_xxx_F & HDR_xxx_T [WARNING: don't mix them!] (andrei)
00034  * 2007-01-26 HDR_DATE_T, HDR_IDENTITY_T, HDR_IDENTITY_INFO_T added (gergo)
00035  * 2007-07-27 HDR_RETRY_AFTER_[TF] added (andrei)
00036  */
00037 
00046 #ifndef HF_H
00047 #define HF_H
00048 
00049 #include "../str.h"
00050 #include "../comp_defs.h"
00051 
00052 
00053 
00066 enum _hdr_types_t {
00067         HDR_ERROR_T                                     = -1   ,
00068         HDR_OTHER_T                                     =  0   ,
00069         HDR_VIA_T                                       =  1   ,
00070         HDR_VIA1_T                                      =  1   ,
00071         HDR_VIA2_T                                      =  2   ,
00072         HDR_TO_T                                               ,
00073         HDR_FROM_T                                             ,
00074         HDR_CSEQ_T                                             ,
00075         HDR_CALLID_T                                   ,
00076         HDR_CONTACT_T                                  ,
00077         HDR_MAXFORWARDS_T                              ,
00078         HDR_ROUTE_T                                            ,
00079         HDR_RECORDROUTE_T                              ,
00080         HDR_CONTENTTYPE_T                              ,
00081         HDR_CONTENTLENGTH_T                            ,
00082         HDR_AUTHORIZATION_T                            ,
00083         HDR_EXPIRES_T                                  ,
00084         HDR_PROXYAUTH_T                                ,
00085         HDR_SUPPORTED_T                                ,
00086         HDR_REQUIRE_T                                  ,
00087         HDR_PROXYREQUIRE_T                             ,
00088         HDR_UNSUPPORTED_T                              ,
00089         HDR_ALLOW_T                                            ,
00090         HDR_EVENT_T                                            ,
00091         HDR_ACCEPT_T                                   ,
00092         HDR_ACCEPTLANGUAGE_T                   ,
00093         HDR_ORGANIZATION_T                             ,
00094         HDR_PRIORITY_T                                 ,
00095         HDR_SUBJECT_T                                  ,
00096         HDR_USERAGENT_T                                ,
00097         HDR_SERVER_T                                   ,
00098         HDR_CONTENTDISPOSITION_T               ,
00099         HDR_DIVERSION_T                                ,
00100         HDR_RPID_T                                             ,
00101         HDR_REFER_TO_T                                 ,
00102         HDR_SIPIFMATCH_T                               ,
00103         HDR_SESSIONEXPIRES_T                   ,
00104         HDR_MIN_SE_T                                   ,
00105         HDR_SUBSCRIPTION_STATE_T               ,
00106         HDR_ACCEPTCONTACT_T                            ,
00107         HDR_ALLOWEVENTS_T                              ,
00108         HDR_CONTENTENCODING_T                  ,
00109         HDR_REFERREDBY_T                               ,
00110         HDR_REJECTCONTACT_T                            ,
00111         HDR_REQUESTDISPOSITION_T               ,
00112         HDR_WWW_AUTHENTICATE_T                 ,
00113         HDR_PROXY_AUTHENTICATE_T               ,
00114         HDR_DATE_T                             ,
00115         HDR_IDENTITY_T                         ,
00116         HDR_IDENTITY_INFO_T                    ,
00117         HDR_RETRY_AFTER_T                          ,
00118         HDR_PPI_T                          ,
00119         HDR_PAI_T                          ,
00120         HDR_PATH_T                         ,
00121         HDR_PRIVACY_T                                  ,
00122         HDR_REASON_T                                   ,
00123         HDR_EOH_T                                              
00124 };
00125 
00126 
00127 typedef unsigned long long hdr_flags_t;
00128 
00131 #define HDR_T2F(type)   \
00132                 (((type)!=HDR_EOH_T)?((hdr_flags_t)1<<(type)):(~(hdr_flags_t)0))
00133 
00135 #define HDR_F_DEF(name)         HDR_T2F(HDR_##name##_T)
00136 
00140 #define HDR_EOH_F                                       HDR_F_DEF(EOH)
00141 #define HDR_VIA_F                                       HDR_F_DEF(VIA)
00142 #define HDR_VIA1_F                                      HDR_F_DEF(VIA1)
00143 #define HDR_VIA2_F                                      HDR_F_DEF(VIA2)
00144 #define HDR_TO_F                                        HDR_F_DEF(TO)
00145 #define HDR_FROM_F                                      HDR_F_DEF(FROM)
00146 #define HDR_CSEQ_F                                      HDR_F_DEF(CSEQ)
00147 #define HDR_CALLID_F                            HDR_F_DEF(CALLID)
00148 #define HDR_CONTACT_F                           HDR_F_DEF(CONTACT)
00149 #define HDR_MAXFORWARDS_F                       HDR_F_DEF(MAXFORWARDS)
00150 #define HDR_ROUTE_F                                     HDR_F_DEF(ROUTE)
00151 #define HDR_RECORDROUTE_F                       HDR_F_DEF(RECORDROUTE)
00152 #define HDR_CONTENTTYPE_F                       HDR_F_DEF(CONTENTTYPE)
00153 #define HDR_CONTENTLENGTH_F                     HDR_F_DEF(CONTENTLENGTH)
00154 #define HDR_AUTHORIZATION_F                     HDR_F_DEF(AUTHORIZATION)
00155 #define HDR_EXPIRES_F                           HDR_F_DEF(EXPIRES)
00156 #define HDR_PROXYAUTH_F                         HDR_F_DEF(PROXYAUTH)
00157 #define HDR_SUPPORTED_F                         HDR_F_DEF(SUPPORTED)
00158 #define HDR_REQUIRE_F                           HDR_F_DEF(REQUIRE)
00159 #define HDR_PROXYREQUIRE_F                      HDR_F_DEF(PROXYREQUIRE)
00160 #define HDR_UNSUPPORTED_F                       HDR_F_DEF(UNSUPPORTED)
00161 #define HDR_ALLOW_F                                     HDR_F_DEF(ALLOW)
00162 #define HDR_EVENT_F                                     HDR_F_DEF(EVENT)
00163 #define HDR_ACCEPT_F                            HDR_F_DEF(ACCEPT)
00164 #define HDR_ACCEPTLANGUAGE_F            HDR_F_DEF(ACCEPTLANGUAGE)
00165 #define HDR_ORGANIZATION_F                      HDR_F_DEF(ORGANIZATION)
00166 #define HDR_PRIORITY_F                          HDR_F_DEF(PRIORITY)
00167 #define HDR_SUBJECT_F                           HDR_F_DEF(SUBJECT)
00168 #define HDR_USERAGENT_F                         HDR_F_DEF(USERAGENT)
00169 #define HDR_SERVER_F                            HDR_F_DEF(SERVER)
00170 #define HDR_CONTENTDISPOSITION_F        HDR_F_DEF(CONTENTDISPOSITION)
00171 #define HDR_DIVERSION_F                         HDR_F_DEF(DIVERSION)
00172 #define HDR_RPID_F                                      HDR_F_DEF(RPID)
00173 #define HDR_REFER_TO_F                          HDR_F_DEF(REFER_TO)
00174 #define HDR_SIPIFMATCH_F                        HDR_F_DEF(SIPIFMATCH)
00175 #define HDR_SESSIONEXPIRES_F            HDR_F_DEF(SESSIONEXPIRES)
00176 #define HDR_MIN_SE_F                            HDR_F_DEF(MIN_SE)
00177 #define HDR_SUBSCRIPTION_STATE_F        HDR_F_DEF(SUBSCRIPTION_STATE)
00178 #define HDR_ACCEPTCONTACT_F                     HDR_F_DEF(ACCEPTCONTACT)
00179 #define HDR_ALLOWEVENTS_F                       HDR_F_DEF(ALLOWEVENTS)
00180 #define HDR_CONTENTENCODING_F           HDR_F_DEF(CONTENTENCODING)
00181 #define HDR_REFERREDBY_F                        HDR_F_DEF(REFERREDBY)
00182 #define HDR_REJECTCONTACT_F                     HDR_F_DEF(REJECTCONTACT)
00183 #define HDR_REQUESTDISPOSITION_F        HDR_F_DEF(REQUESTDISPOSITION)
00184 #define HDR_WWW_AUTHENTICATE_F          HDR_F_DEF(WWW_AUTHENTICATE)
00185 #define HDR_PROXY_AUTHENTICATE_F        HDR_F_DEF(PROXY_AUTHENTICATE)
00186 #define HDR_DATE_F                      HDR_F_DEF(DATE)
00187 #define HDR_IDENTITY_F                  HDR_F_DEF(IDENTITY)
00188 #define HDR_IDENTITY_INFO_F             HDR_F_DEF(IDENTITY_INFO)
00189 #define HDR_RETRY_AFTER_F                       HDR_F_DEF(RETRY_AFTER)
00190 #define HDR_PPI_F                   HDR_F_DEF(PPI)
00191 #define HDR_PAI_F                   HDR_F_DEF(PAI)
00192 #define HDR_PATH_F                  HDR_F_DEF(PATH)
00193 #define HDR_PRIVACY_F               HDR_F_DEF(PRIVACY)
00194 #define HDR_REASON_F                            HDR_F_DEF(REASON)
00195 
00196 #define HDR_OTHER_F                                     HDR_F_DEF(OTHER)
00197  /* Doxygen end marker*/
00199 
00200 typedef enum _hdr_types_t hdr_types_t;
00201 
00204 typedef struct hdr_field {
00205         hdr_types_t type;       
00206         str name;               
00207         str body;               
00208         int len;                
00209         void* parsed;           
00210         struct hdr_field* next; 
00211 } hdr_field_t;
00212 
00213 
00214 /* type of the function to free the structure of parsed header field */
00215 typedef void (*hf_parsed_free_f)(void *parsed);
00216 
00217 /* structure to hold the function to free the parsed header field */
00218 typedef struct hdr_parsed {
00219         hf_parsed_free_f hfree;
00220 } hf_parsed_t;
00221 
00223 static inline int hdr_allocs_parse(struct hdr_field* hdr)
00224 {
00225         switch(hdr->type){
00226                 case HDR_ACCEPT_T:
00227                 case HDR_ALLOW_T:
00228                 case HDR_AUTHORIZATION_T:
00229                 case HDR_CONTACT_T:
00230                 case HDR_CONTENTDISPOSITION_T:
00231                 case HDR_CSEQ_T:
00232                 case HDR_DATE_T:
00233                 case HDR_DIVERSION_T:
00234                 case HDR_EVENT_T:
00235                 case HDR_EXPIRES_T:
00236                 case HDR_FROM_T:
00237                 case HDR_IDENTITY_INFO_T:
00238                 case HDR_IDENTITY_T:
00239                 case HDR_PAI_T:
00240                 case HDR_PPI_T:
00241                 case HDR_PROXYAUTH_T:
00242                 case HDR_RECORDROUTE_T:
00243                 case HDR_REFER_TO_T:
00244                 case HDR_ROUTE_T:
00245                 case HDR_RPID_T:
00246                 case HDR_SESSIONEXPIRES_T:
00247                 case HDR_SIPIFMATCH_T:
00248                 case HDR_SUBSCRIPTION_STATE_T:
00249                 case HDR_SUPPORTED_T:
00250                 case HDR_TO_T:
00251                 case HDR_VIA_T:
00252                         return 1;
00253                 default:
00254                         return 0;
00255         }
00256 }
00257 
00261 void clean_hdr_field(struct hdr_field* hf);
00262 
00263 
00267 void free_hdr_field_lst(struct hdr_field* hf);
00268 
00269 /* print content of hdr_field */
00270 void dump_hdr_field( struct hdr_field* hf );
00271 
00277 void hdr_free_parsed(void **h_parsed);
00278 
00279 #endif /* HF_H */