parser/hf.c
67386619
 /*
  * $Id$
7dd0b342
  *
c32feee5
  * Copyright (C) 2001-2003 FhG Fokus
7dd0b342
  *
  * This file is part of ser, a free SIP server.
  *
  * ser is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
  * For a license to use the ser software under conditions
  * other than those described here, or to purchase support for this
  * software, please contact iptel.org by e-mail at the following addresses:
  *    info@iptel.org
  *
  * ser is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
67386619
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
7dd0b342
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
abb343de
  *
  * History:
  * -------
  * 2003-03-26 Frees also hdr->parsed for Route & Record-Route (janakj)
6b6f226f
  * 2003-04-26 ZSW (jiri)
2f43c732
  * 2003-08-05 free the parsed part of Accept header (bogdan)
2bb60634
  */
 
7dd0b342
 
2bb60634
 #include "hf.h"
 #include "parse_via.h"
 #include "parse_to.h"
 #include "parse_cseq.h"
 #include "../dprint.h"
 #include "../mem/mem.h"
 #include "parse_def.h"
8dd85148
 #include "digest/digest.h" /* free_credentials */
bc9560dd
 #include "parse_event.h"
 #include "parse_expires.h"
9200d410
 #include "parse_sipifmatch.h"
abb343de
 #include "parse_rr.h"
48862405
 #include "parse_subscription_state.h"
303ee780
 #include "contact/parse_contact.h"
432fb736
 #include "parse_disposition.h"
6b6f226f
 #include "../ut.h"
2bb60634
 
 
67386619
 /*
2bb60634
  * Frees a hdr_field structure,
  * WARNING: it frees only parsed (and not name.s, body.s)
  */
 void clean_hdr_field(struct hdr_field* hf)
 {
 	if (hf->parsed){
 		switch(hf->type){
5c28a534
 		case HDR_VIA_T:
2bb60634
 			free_via_list(hf->parsed);
 			break;
 
5c28a534
 		case HDR_TO_T:
2bb60634
 			free_to(hf->parsed);
 			break;
 
5c28a534
 		case HDR_FROM_T:
6a2b0dec
 			free_to(hf->parsed);
 			break;
 
5c28a534
 		case HDR_CSEQ_T:
2bb60634
 			free_cseq(hf->parsed);
 			break;
 
5c28a534
 		case HDR_CALLID_T:
6a2b0dec
 			break;
 
9200d410
 		case HDR_SIPIFMATCH_T:
 			free_sipifmatch((str **)(&(hf->parsed)));
 			break;
 
5c28a534
 		case HDR_CONTACT_T:
6a2b0dec
 			free_contact((contact_body_t**)(&(hf->parsed)));
 			break;
 
5c28a534
 		case HDR_MAXFORWARDS_T:
6a2b0dec
 			break;
 
5c28a534
 		case HDR_ROUTE_T:
6a2b0dec
 			free_rr((rr_t**)(&hf->parsed));
 			break;
 
5c28a534
 		case HDR_RECORDROUTE_T:
6a2b0dec
 			free_rr((rr_t**)(&hf->parsed));
 			break;
 
5c28a534
 		case HDR_CONTENTTYPE_T:
6a2b0dec
 			break;
 
5c28a534
 		case HDR_CONTENTLENGTH_T:
6a2b0dec
 			break;
 
5c28a534
 		case HDR_AUTHORIZATION_T:
b516633c
 			free_credentials((auth_body_t**)(&(hf->parsed)));
6a2b0dec
 			break;
 
5c28a534
 		case HDR_EXPIRES_T:
6a2b0dec
 			free_expires((exp_body_t**)(&(hf->parsed)));
 			break;
 
5c28a534
 		case HDR_PROXYAUTH_T:
7a212740
 			free_credentials((auth_body_t**)(&(hf->parsed)));
8dd85148
 			break;
 
5c28a534
 		case HDR_SUPPORTED_T:
6a2b0dec
 			break;
 
e696bf82
 		case HDR_REQUIRE_T:
 			break;
 			
5c28a534
 		case HDR_PROXYREQUIRE_T:
6a2b0dec
 			break;
 
5c28a534
 		case HDR_UNSUPPORTED_T:
6a2b0dec
 			break;
 
5c28a534
 		case HDR_ALLOW_T:
31a22fdd
 			break;
 
5c28a534
 		case HDR_EVENT_T:
bc9560dd
 			free_event((event_t**)(&(hf->parsed)));
 			break;
 
5c28a534
 		case HDR_ACCEPT_T:
6a2b0dec
 			pkg_free(hf->parsed);
bc9560dd
 			break;
 
5c28a534
 		case HDR_ACCEPTLANGUAGE_T:
6a2b0dec
 			break;
67386619
 
5c28a534
 		case HDR_ORGANIZATION_T:
6a2b0dec
 			break;
67386619
 
5c28a534
 		case HDR_PRIORITY_T:
303ee780
 			break;
 
5c28a534
 		case HDR_SUBJECT_T:
abb343de
 			break;
 
5c28a534
 		case HDR_USERAGENT_T:
ec147e2e
 			break;
 
5c28a534
 		case HDR_ACCEPTDISPOSITION_T:
6a2b0dec
 			break;
 
5c28a534
 		case HDR_CONTENTDISPOSITION_T:
432fb736
 			free_disposition( ((struct disposition**)(&hf->parsed)) );
2f43c732
 			break;
 
5c28a534
 		case HDR_DIVERSION_T:
dccbcda9
 			free_to(hf->parsed);
 			break;
 
5c28a534
 		case HDR_RPID_T:
dccbcda9
 			free_to(hf->parsed);
 			break;
 
5c28a534
 		case HDR_REFER_TO_T:
8b482f1a
 			free_to(hf->parsed);
 			break;
48862405
 		
 		case HDR_SUBSCRIPTION_STATE_T:
eb89b47c
 			free_subscription_state((subscription_state_t**)(&hf->parsed));
48862405
 			break;
8b482f1a
 
67386619
 		case HDR_SESSIONEXPIRES_T:
8a4f3a74
 		case HDR_MIN_SE_T:
67386619
 		case HDR_ACCEPTCONTACT_T:
 		case HDR_ALLOWEVENTS_T:
 		case HDR_CONTENTENCODING_T:
 		case HDR_REFERREDBY_T:
 		case HDR_REJECTCONTACT_T:
 		case HDR_REQUESTDISPOSITION_T:
3ed13e77
 		case HDR_WWW_AUTHENTICATE_T:
 		case HDR_PROXY_AUTHENTICATE_T:
67386619
 			break;
2bb60634
 		default:
 			LOG(L_CRIT, "BUG: clean_hdr_field: unknown header type %d\n",
 			    hf->type);
 			break;
 		}
 	}
 }
 
 
67386619
 /*
2bb60634
  * Frees a hdr_field list,
  * WARNING: frees only ->parsed and ->next*/
 void free_hdr_field_lst(struct hdr_field* hf)
 {
 	struct hdr_field* foo;
67386619
 
2bb60634
 	while(hf) {
 		foo=hf;
 		hf=hf->next;
 		clean_hdr_field(foo);
 		pkg_free(foo);
 	}
 }
caf80ae6
 
 void dump_hdr_field( struct hdr_field* hf )
 {
 	LOG(L_ERR, "DEBUG: dump_hdr_field: type=%d, name=%.*s, "
 		"body=%.*s, parsed=%p, next=%p\n",
6b6f226f
 		hf->type, hf->name.len, ZSW(hf->name.s),
 		hf->body.len, ZSW(hf->body.s),
caf80ae6
 		hf->parsed, hf->next );
 }