Browse Source

core: helper function to free parsed header struct with inner free function

Daniel-Constantin Mierla 14 years ago
parent
commit
ad8c936034
2 changed files with 27 additions and 7 deletions
  1. 19 7
      parser/hf.c
  2. 8 0
      parser/hf.h

+ 19 - 7
parser/hf.c

@@ -152,10 +152,7 @@ void clean_hdr_field(struct hdr_field* hf)
 			break;
 
 		case HDR_SESSIONEXPIRES_T:
-			if(*h_parsed) {
-				((hf_parsed_t*)(*h_parsed))->hfree(*h_parsed);
-				*h_parsed = 0;
-			}
+			hdr_free_parsed(h_parsed);
 			break;
 
 		case HDR_SIPIFMATCH_T:
@@ -167,9 +164,7 @@ void clean_hdr_field(struct hdr_field* hf)
 			break;
 
 		case HDR_SUPPORTED_T:
-			if(*h_parsed) {
-				((hf_parsed_t*)(*h_parsed))->hfree(*h_parsed);
-			}
+			hdr_free_parsed(h_parsed);
 			break;
 
 		case HDR_TO_T:
@@ -233,6 +228,7 @@ void free_hdr_field_lst(struct hdr_field* hf)
 	}
 }
 
+/* print the content of hdr_field */
 void dump_hdr_field( struct hdr_field* hf )
 {
 	LOG(L_ERR, "DEBUG: dump_hdr_field: type=%d, name=%.*s, "
@@ -241,3 +237,19 @@ void dump_hdr_field( struct hdr_field* hf )
 		hf->body.len, ZSW(hf->body.s),
 		hf->parsed, hf->next );
 }
+
+/**
+ * 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;
+}

+ 8 - 0
parser/hf.h

@@ -268,6 +268,14 @@ void clean_hdr_field(struct hdr_field* hf);
  */
 void free_hdr_field_lst(struct hdr_field* hf);
 
+/* print content of hdr_field */
 void dump_hdr_field( struct hdr_field* hf );
 
+/**
+ * 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);
+
 #endif /* HF_H */