hf.c

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-03-26 Frees also hdr->parsed for Route & Record-Route (janakj)
00030  * 2003-04-26 ZSW (jiri)
00031  * 2003-08-05 free the parsed part of Accept header (bogdan)
00032  * 2007-01-26 HDR_DATE_T, HDR_IDENTITY_T, HDR_IDENTITY_INFO_T added (gergo)
00033  * 2007-07-27 added HDR_RETRY_AFTER_T (andrei)
00034  */
00035 
00042 #include "hf.h"
00043 #include "parse_via.h"
00044 #include "parse_to.h"
00045 #include "parse_cseq.h"
00046 #include "parse_date.h"
00047 #include "parse_identity.h"
00048 #include "parse_identityinfo.h"
00049 #include "../dprint.h"
00050 #include "../mem/mem.h"
00051 #include "parse_def.h"
00052 #include "digest/digest.h" /* free_credentials */
00053 #include "parse_event.h"
00054 #include "parse_expires.h"
00055 #include "parse_sipifmatch.h"
00056 #include "parse_rr.h"
00057 #include "parse_subscription_state.h"
00058 #include "contact/parse_contact.h"
00059 #include "parse_disposition.h"
00060 #include "parse_allow.h"
00061 #include "../ut.h"
00062 
00066 void clean_hdr_field(struct hdr_field* hf)
00067 {
00068         void** h_parsed;
00069 
00070         if (hf->parsed){
00071                 h_parsed=&hf->parsed; /* strict aliasing warnings workarround */
00072                 switch(hf->type){
00073                 /* headers with pkg alloc for parsed structure (alphabetic order) */
00074                 case HDR_ACCEPT_T:
00075                         pkg_free(hf->parsed);
00076                         break;
00077 
00078                 case HDR_ALLOW_T:
00079                         free_allow_header(hf);
00080                         break;
00081 
00082                 case HDR_AUTHORIZATION_T:
00083                         free_credentials((auth_body_t**)h_parsed);
00084                         break;
00085 
00086                 case HDR_CONTACT_T:
00087                         free_contact((contact_body_t**)h_parsed);
00088                         break;
00089 
00090                 case HDR_CONTENTDISPOSITION_T:
00091                         free_disposition( ((struct disposition**)h_parsed));
00092                         break;
00093 
00094                 case HDR_CSEQ_T:
00095                         free_cseq(hf->parsed);
00096                         break;
00097 
00098                 case HDR_DATE_T:
00099                         free_date(hf->parsed);
00100                         break;
00101 
00102                 case HDR_DIVERSION_T:
00103                         free_to(hf->parsed);
00104                         break;
00105 
00106                 case HDR_EVENT_T:
00107                         free_event((event_t**)h_parsed);
00108                         break;
00109 
00110                 case HDR_EXPIRES_T:
00111                         free_expires((exp_body_t**)h_parsed);
00112                         break;
00113 
00114                 case HDR_FROM_T:
00115                         free_to(hf->parsed);
00116                         break;
00117 
00118                 case HDR_IDENTITY_INFO_T:
00119                         free_identityinfo(hf->parsed);
00120                         break;
00121 
00122                 case HDR_IDENTITY_T:
00123                         free_identity(hf->parsed);
00124                         break;
00125 
00126                 case HDR_PAI_T:
00127                         free_to(hf->parsed);
00128                         break;
00129 
00130                 case HDR_PPI_T:
00131                         free_to(hf->parsed);
00132                         break;
00133 
00134                 case HDR_PROXYAUTH_T:
00135                         free_credentials((auth_body_t**)h_parsed);
00136                         break;
00137 
00138                 case HDR_RECORDROUTE_T:
00139                         free_rr((rr_t**)h_parsed);
00140                         break;
00141 
00142                 case HDR_REFER_TO_T:
00143                         free_to(hf->parsed);
00144                         break;
00145 
00146                 case HDR_ROUTE_T:
00147                         free_rr((rr_t**)h_parsed);
00148                         break;
00149 
00150                 case HDR_RPID_T:
00151                         free_to(hf->parsed);
00152                         break;
00153 
00154                 case HDR_SESSIONEXPIRES_T:
00155                         hdr_free_parsed(h_parsed);
00156                         break;
00157 
00158                 case HDR_SIPIFMATCH_T:
00159                         free_sipifmatch((str **)h_parsed);
00160                         break;
00161 
00162                 case HDR_SUBSCRIPTION_STATE_T:
00163                         free_subscription_state((subscription_state_t**)h_parsed);
00164                         break;
00165 
00166                 case HDR_SUPPORTED_T:
00167                         hdr_free_parsed(h_parsed);
00168                         break;
00169 
00170                 case HDR_TO_T:
00171                         free_to(hf->parsed);
00172                         break;
00173 
00174                 case HDR_VIA_T:
00175                         free_via_list(hf->parsed);
00176                         break;
00177 
00178                 /* headers with no alloc for parsed structure */
00179                 case HDR_CALLID_T:
00180                 case HDR_MAXFORWARDS_T:
00181                 case HDR_CONTENTTYPE_T:
00182                 case HDR_CONTENTLENGTH_T:
00183                 case HDR_RETRY_AFTER_T:
00184                 case HDR_REQUIRE_T:
00185                 case HDR_PROXYREQUIRE_T:
00186                 case HDR_UNSUPPORTED_T:
00187                 case HDR_ACCEPTLANGUAGE_T:
00188                 case HDR_ORGANIZATION_T:
00189                 case HDR_PRIORITY_T:
00190                 case HDR_SUBJECT_T:
00191                 case HDR_USERAGENT_T:
00192                 case HDR_SERVER_T:
00193                 case HDR_MIN_SE_T:
00194                 case HDR_ACCEPTCONTACT_T:
00195                 case HDR_ALLOWEVENTS_T:
00196                 case HDR_CONTENTENCODING_T:
00197                 case HDR_REFERREDBY_T:
00198                 case HDR_REJECTCONTACT_T:
00199                 case HDR_REQUESTDISPOSITION_T:
00200                 case HDR_WWW_AUTHENTICATE_T:
00201                 case HDR_PROXY_AUTHENTICATE_T:
00202                 case HDR_PATH_T:
00203                 case HDR_PRIVACY_T:
00204                 case HDR_REASON_T:
00205                         break;
00206 
00207                 default:
00208                         LOG(L_CRIT, "BUG: clean_hdr_field: unknown header type %d\n",
00209                             hf->type);
00210                         break;
00211                 }
00212         }
00213 }
00214 
00215 
00218 void free_hdr_field_lst(struct hdr_field* hf)
00219 {
00220         struct hdr_field* foo;
00221 
00222         while(hf) {
00223                 foo=hf;
00224                 hf=hf->next;
00225                 clean_hdr_field(foo);
00226                 pkg_free(foo);
00227         }
00228 }
00229 
00230 /* print the content of hdr_field */
00231 void dump_hdr_field( struct hdr_field* hf )
00232 {
00233         LOG(L_ERR, "DEBUG: dump_hdr_field: type=%d, name=%.*s, "
00234                 "body=%.*s, parsed=%p, next=%p\n",
00235                 hf->type, hf->name.len, ZSW(hf->name.s),
00236                 hf->body.len, ZSW(hf->body.s),
00237                 hf->parsed, hf->next );
00238 }
00239 
00245 void hdr_free_parsed(void **h_parsed)
00246 {
00247         if(h_parsed==NULL || *h_parsed==NULL)
00248                 return;
00249 
00250         if(((hf_parsed_t*)(*h_parsed))->hfree) {
00251                 ((hf_parsed_t*)(*h_parsed))->hfree(*h_parsed);
00252         }
00253         *h_parsed = 0;
00254 }