Module: sip-router
Branch: master
Commit: a4485985596d64db6971b3c98a5c5e696e1e702a
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a448598…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Tue Aug 9 22:51:40 2011 +0200
core: added helper functions to return header by name
- for special cases when there is no defined type for the header
---
parser/msg_parser.c | 37 +++++++++++++++++++++++++++++++------
parser/msg_parser.h | 6 ++++--
2 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/parser/msg_parser.c b/parser/msg_parser.c
index e138c7f..705c5fb 100644
--- a/parser/msg_parser.c
+++ b/parser/msg_parser.c
@@ -825,9 +825,9 @@ void reset_path_vector(struct sip_msg* msg)
}
-struct hdr_field* get_hdr(struct sip_msg *msg, enum _hdr_types_t ht)
+hdr_field_t* get_hdr(sip_msg_t *msg, enum _hdr_types_t ht)
{
- struct hdr_field *hdr;
+ hdr_field_t *hdr;
if (msg->parsed_flag & HDR_T2F(ht))
for(hdr = msg->headers; hdr; hdr = hdr->next) {
@@ -837,12 +837,37 @@ struct hdr_field* get_hdr(struct sip_msg *msg, enum _hdr_types_t
ht)
}
-struct hdr_field* next_sibling_hdr(struct hdr_field *hf)
-{
- struct hdr_field *hdr;
-
+hdr_field_t* next_sibling_hdr(hdr_field_t *hf)
+{
+ hdr_field_t *hdr;
+
for(hdr = hf->next; hdr; hdr = hdr->next) {
if(hdr->type == hf->type) return hdr;
}
return NULL;
}
+
+hdr_field_t* get_hdr_by_name(sip_msg_t *msg, char *name, int name_len)
+{
+ hdr_field_t *hdr;
+
+ for(hdr = msg->headers; hdr; hdr = hdr->next) {
+ if(hdr->name.len == name_len && *hdr->name.s==*name
+ && strncmp(hdr->name.s, name, name_len)==0)
+ return hdr;
+ }
+ return NULL;
+}
+
+
+hdr_field_t* next_sibling_hdr_by_name(hdr_field_t *hf)
+{
+ hdr_field_t *hdr;
+
+ for(hdr = hf->next; hdr; hdr = hdr->next) {
+ if(hdr->name.len == hf->name.len && *hdr->name.s==*hf->name.s
+ && strncmp(hdr->name.s, hf->name.s, hf->name.len)==0)
+ return hdr;
+ }
+ return NULL;
+}
diff --git a/parser/msg_parser.h b/parser/msg_parser.h
index 4d8f58d..7f18eb1 100644
--- a/parser/msg_parser.h
+++ b/parser/msg_parser.h
@@ -441,8 +441,10 @@ int set_dst_uri(struct sip_msg* msg, str* uri);
/*! \brief If the dst_uri is set to an URI then reset it */
void reset_dst_uri(struct sip_msg* msg);
-struct hdr_field* get_hdr(struct sip_msg *msg, enum _hdr_types_t ht);
-struct hdr_field* next_sibling_hdr(struct hdr_field *hf);
+hdr_field_t* get_hdr(sip_msg_t *msg, enum _hdr_types_t ht);
+hdr_field_t* next_sibling_hdr(hdr_field_t *hf);
+hdr_field_t* get_hdr_by_name(sip_msg_t *msg, char *name, int name_len);
+hdr_field_t* next_sibling_hdr_by_name(hdr_field_t *hf);
int set_path_vector(struct sip_msg* msg, str* path);