Module: sip-router
Branch: 3.1
Commit: a088c048179762f051efb36d45ba68eec17d05aa
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a088c04…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Mon Feb 28 17:17:09 2011 +0100
core: helper function to free parsed header struct with inner free function
(cherry picked from commit ad8c9360348d111085a8e01a277e6b718ef803ad)
---
parser/hf.c | 26 +++++++++++++++++++-------
parser/hf.h | 8 ++++++++
2 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/parser/hf.c b/parser/hf.c
index d094785..4d6de0b 100644
--- a/parser/hf.c
+++ b/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;
+}
diff --git a/parser/hf.h b/parser/hf.h
index e880987..a373836 100644
--- a/parser/hf.h
+++ b/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 */