Browse code

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

Daniel-Constantin Mierla authored on 28/02/2011 16:17:09
Showing 2 changed files
... ...
@@ -152,10 +152,7 @@ void clean_hdr_field(struct hdr_field* hf)
152 152
 			break;
153 153
 
154 154
 		case HDR_SESSIONEXPIRES_T:
155
-			if(*h_parsed) {
156
-				((hf_parsed_t*)(*h_parsed))->hfree(*h_parsed);
157
-				*h_parsed = 0;
158
-			}
155
+			hdr_free_parsed(h_parsed);
159 156
 			break;
160 157
 
161 158
 		case HDR_SIPIFMATCH_T:
... ...
@@ -167,9 +164,7 @@ void clean_hdr_field(struct hdr_field* hf)
167 164
 			break;
168 165
 
169 166
 		case HDR_SUPPORTED_T:
170
-			if(*h_parsed) {
171
-				((hf_parsed_t*)(*h_parsed))->hfree(*h_parsed);
172
-			}
167
+			hdr_free_parsed(h_parsed);
173 168
 			break;
174 169
 
175 170
 		case HDR_TO_T:
... ...
@@ -233,6 +228,7 @@ void free_hdr_field_lst(struct hdr_field* hf)
233 228
 	}
234 229
 }
235 230
 
231
+/* print the content of hdr_field */
236 232
 void dump_hdr_field( struct hdr_field* hf )
237 233
 {
238 234
 	LOG(L_ERR, "DEBUG: dump_hdr_field: type=%d, name=%.*s, "
... ...
@@ -241,3 +237,19 @@ void dump_hdr_field( struct hdr_field* hf )
241 237
 		hf->body.len, ZSW(hf->body.s),
242 238
 		hf->parsed, hf->next );
243 239
 }
240
+
241
+/**
242
+ * free hdr parsed structure using inner free function
243
+ * - hdr parsed struct must have as first file a free function,
244
+ *   so it can be caseted to hf_parsed_t
245
+ */
246
+void hdr_free_parsed(void **h_parsed)
247
+{
248
+	if(h_parsed==NULL || *h_parsed==NULL)
249
+		return;
250
+
251
+	if(((hf_parsed_t*)(*h_parsed))->hfree) {
252
+		((hf_parsed_t*)(*h_parsed))->hfree(*h_parsed);
253
+	}
254
+	*h_parsed = 0;
255
+}
... ...
@@ -268,6 +268,14 @@ void clean_hdr_field(struct hdr_field* hf);
268 268
  */
269 269
 void free_hdr_field_lst(struct hdr_field* hf);
270 270
 
271
+/* print content of hdr_field */
271 272
 void dump_hdr_field( struct hdr_field* hf );
272 273
 
274
+/**
275
+ * free hdr parsed structure using inner free function
276
+ * - hdr parsed struct must have as first file a free function,
277
+ *   so it can be caseted to hf_parsed_t
278
+ */
279
+void hdr_free_parsed(void **h_parsed);
280
+
273 281
 #endif /* HF_H */