parser/hf.c
67386619
 /*
c32feee5
  * Copyright (C) 2001-2003 FhG Fokus
7dd0b342
  *
07ca8c05
  * This file is part of Kamailio, a free SIP server.
7dd0b342
  *
07ca8c05
  * Kamailio is free software; you can redistribute it and/or modify
7dd0b342
  * 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
  *
07ca8c05
  * Kamailio is distributed in the hope that it will be useful,
7dd0b342
  * 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
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
abb343de
  *
2bb60634
  */
 
14babe14
 /** Parser :: parse header files
  * @file
  * @ingroup parser
8c4ed5f0
  */
 
7dd0b342
 
2bb60634
 #include "hf.h"
 #include "parse_via.h"
 #include "parse_to.h"
 #include "parse_cseq.h"
e7317b87
 #include "parse_date.h"
52553188
 #include "parse_identity.h"
 #include "parse_identityinfo.h"
2bb60634
 #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"
0d54a775
 #include "parse_allow.h"
6b6f226f
 #include "../ut.h"
09441e89
 #include "parse_ppi_pai.h"
2bb60634
 
14babe14
 /** Frees a hdr_field structure.
2bb60634
  * WARNING: it frees only parsed (and not name.s, body.s)
  */
f7b97e8a
 void clean_hdr_field(struct hdr_field* const hf)
2bb60634
 {
8768defd
 	void** h_parsed;
e7317b87
 
2bb60634
 	if (hf->parsed){
2316acaa
 		h_parsed=&hf->parsed; /* strict aliasing warnings workarround */
2bb60634
 		switch(hf->type){
2316acaa
 		/* headers with pkg alloc for parsed structure (alphabetic order) */
 		case HDR_ACCEPT_T:
 			pkg_free(hf->parsed);
2bb60634
 			break;
 
2316acaa
 		case HDR_ALLOW_T:
 			free_allow_header(hf);
6a2b0dec
 			break;
 
2316acaa
 		case HDR_AUTHORIZATION_T:
 			free_credentials((auth_body_t**)h_parsed);
9200d410
 			break;
 
5c28a534
 		case HDR_CONTACT_T:
8768defd
 			free_contact((contact_body_t**)h_parsed);
6a2b0dec
 			break;
 
2316acaa
 		case HDR_CONTENTDISPOSITION_T:
 			free_disposition( ((struct disposition**)h_parsed));
6a2b0dec
 			break;
 
2316acaa
 		case HDR_CSEQ_T:
 			free_cseq(hf->parsed);
6a2b0dec
 			break;
 
2316acaa
 		case HDR_DATE_T:
 			free_date(hf->parsed);
6a2b0dec
 			break;
 
2316acaa
 		case HDR_DIVERSION_T:
 			free_to(hf->parsed);
b861de9c
 			break;
 
2316acaa
 		case HDR_EVENT_T:
 			free_event((event_t**)h_parsed);
6a2b0dec
 			break;
 
5c28a534
 		case HDR_EXPIRES_T:
8768defd
 			free_expires((exp_body_t**)h_parsed);
6a2b0dec
 			break;
 
2316acaa
 		case HDR_FROM_T:
 			free_to(hf->parsed);
bc9560dd
 			break;
 
2316acaa
 		case HDR_IDENTITY_INFO_T:
 			free_identityinfo(hf->parsed);
6a2b0dec
 			break;
67386619
 
2316acaa
 		case HDR_IDENTITY_T:
 			free_identity(hf->parsed);
6a2b0dec
 			break;
67386619
 
2316acaa
 		case HDR_PAI_T:
09441e89
 			free_pai_ppi_body(hf->parsed);
303ee780
 			break;
 
2316acaa
 		case HDR_PPI_T:
09441e89
 			free_pai_ppi_body(hf->parsed);
abb343de
 			break;
 
2316acaa
 		case HDR_PROXYAUTH_T:
 			free_credentials((auth_body_t**)h_parsed);
ec147e2e
 			break;
 
2316acaa
 		case HDR_RECORDROUTE_T:
 			free_rr((rr_t**)h_parsed);
fbac8f84
 			break;
 
2316acaa
 		case HDR_REFER_TO_T:
 			free_to(hf->parsed);
6a2b0dec
 			break;
 
2316acaa
 		case HDR_ROUTE_T:
 			free_rr((rr_t**)h_parsed);
2f43c732
 			break;
 
2316acaa
 		case HDR_RPID_T:
dccbcda9
 			free_to(hf->parsed);
 			break;
 
2316acaa
 		case HDR_SESSIONEXPIRES_T:
ad8c9360
 			hdr_free_parsed(h_parsed);
dccbcda9
 			break;
 
2316acaa
 		case HDR_SIPIFMATCH_T:
 			free_sipifmatch((str **)h_parsed);
8b482f1a
 			break;
e7317b87
 
48862405
 		case HDR_SUBSCRIPTION_STATE_T:
8768defd
 			free_subscription_state((subscription_state_t**)h_parsed);
48862405
 			break;
8b482f1a
 
2316acaa
 		case HDR_SUPPORTED_T:
ad8c9360
 			hdr_free_parsed(h_parsed);
e7317b87
 			break;
 
2316acaa
 		case HDR_TO_T:
 			free_to(hf->parsed);
e7317b87
 			break;
 
2316acaa
 		case HDR_VIA_T:
 			free_via_list(hf->parsed);
469650e0
 			break;
 
2316acaa
 		/* headers with no alloc for parsed structure */
 		case HDR_CALLID_T:
 		case HDR_MAXFORWARDS_T:
 		case HDR_CONTENTTYPE_T:
 		case HDR_CONTENTLENGTH_T:
 		case HDR_RETRY_AFTER_T:
 		case HDR_REQUIRE_T:
 		case HDR_PROXYREQUIRE_T:
 		case HDR_UNSUPPORTED_T:
 		case HDR_ACCEPTLANGUAGE_T:
 		case HDR_ORGANIZATION_T:
 		case HDR_PRIORITY_T:
 		case HDR_SUBJECT_T:
 		case HDR_USERAGENT_T:
 		case HDR_SERVER_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:
e430fa02
 		case HDR_PATH_T:
87d84978
 		case HDR_PRIVACY_T:
14babe14
 		case HDR_REASON_T:
67386619
 			break;
2163a7f7
 
2bb60634
 		default:
 			LOG(L_CRIT, "BUG: clean_hdr_field: unknown header type %d\n",
 			    hf->type);
 			break;
 		}
 	}
 }
 
 
14babe14
 /** Frees a hdr_field list.
2bb60634
  * 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
 
ad8c9360
 /* print the content of hdr_field */
f7b97e8a
 void dump_hdr_field(struct hdr_field const* const hf )
caf80ae6
 {
 	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 );
 }
ad8c9360
 
 /**
  * free hdr parsed structure using inner free function
  * - hdr parsed struct must have as first file a free function,
  *   so it can be caseted to hf_parsed_t
  */
 void hdr_free_parsed(void **h_parsed)
 {
 	if(h_parsed==NULL || *h_parsed==NULL)
 		return;
 
 	if(((hf_parsed_t*)(*h_parsed))->hfree) {
 		((hf_parsed_t*)(*h_parsed))->hfree(*h_parsed);
 	}
 	*h_parsed = 0;
 }