[sr-dev] git:master:aaec020b: core: helper functions for header management with strz values

Daniel-Constantin Mierla miconda at gmail.com
Wed Jul 6 17:00:32 CEST 2016


Module: kamailio
Branch: master
Commit: aaec020b5cd033a7d7821dd4a3e447405bbbecad
URL: https://github.com/kamailio/kamailio/commit/aaec020b5cd033a7d7821dd4a3e447405bbbecad

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2016-07-06T16:51:37+02:00

core: helper functions for header management with strz values

---

Modified: data_lump.c
Modified: data_lump.h

---

Diff:  https://github.com/kamailio/kamailio/commit/aaec020b5cd033a7d7821dd4a3e447405bbbecad.diff
Patch: https://github.com/kamailio/kamailio/commit/aaec020b5cd033a7d7821dd4a3e447405bbbecad.patch

---

diff --git a/data_lump.c b/data_lump.c
index daab9aa..afd1704 100644
--- a/data_lump.c
+++ b/data_lump.c
@@ -734,3 +734,95 @@ int remove_lump(sip_msg_t *msg, struct lump *l)
 	}
 	return 0;
 }
+
+/**
+ *
+ */
+int sr_hdr_add_zz(sip_msg_t *msg, char *hname, char *hbody)
+{
+	struct lump* anchor;
+	str h;
+	str sname;
+	str sbody;
+
+	sname.s = hname;
+	sname.len = strlen(sname.s);
+	sbody.s = hbody;
+	sbody.len = strlen(sbody.s);
+
+	h.len = sname.len + 2 + sbody.len + 1 + CRLF_LEN;
+	h.s = (char*)pkg_malloc(h.len+1);
+	if(h.s == 0) {
+		LM_ERR("no more pkg\n");
+		return -1;
+	}
+	anchor = anchor_lump(msg, msg->unparsed - msg->buf, 0, 0);
+	if(anchor == 0)
+	{
+		LM_ERR("cannot get the anchor\n");
+		pkg_free(h.s);
+		return -1;
+	}
+	memcpy(h.s, sname.s, sname.len);
+	memcpy(h.s+sname.len, ": ", 2);
+	memcpy(h.s+sname.len+2, sbody.s, sbody.len);
+	memcpy(h.s+sname.len+2+sbody.len+1, CRLF, CRLF_LEN);
+	h.s[h.len] = '\0';
+	if (insert_new_lump_before(anchor, h.s, h.len, 0) == 0)
+	{
+		LM_ERR("cannot insert lump\n");
+		pkg_free(h.s);
+		return -1;
+	}
+	LM_DBG("added new header [%s]\n", h.s);
+	return 0;
+}
+
+/**
+ *
+ */
+hdr_field_t *sr_hdr_get_z(sip_msg_t *msg, char *hname)
+{
+	hdr_field_t *hf;
+	str sname;
+
+	sname.s = hname;
+	sname.len = strlen(sname.s);
+
+	for (hf=msg->headers; hf; hf=hf->next) {
+		if (hf->name.len==sname.len
+				&& strncasecmp(hf->name.s, sname.s,
+					sname.len)==0) {
+			return hf;
+
+		}
+	}
+	return NULL;
+}
+
+/**
+ *
+ */
+int sr_hdr_del_z(sip_msg_t *msg, char *hname)
+{
+	hdr_field_t *hf;
+	struct lump* l;
+	str sname;
+
+	sname.s = hname;
+	sname.len = strlen(sname.s);
+
+	for (hf=msg->headers; hf; hf=hf->next) {
+		if (hf->name.len==sname.len
+				&& strncasecmp(hf->name.s, sname.s,
+					sname.len)==0) {
+			l=del_lump(msg, hf->name.s-msg->buf, hf->len, 0);
+			if (l==0) {
+				LM_ERR("unable to delete cookie header\n");
+				return -1;
+			}
+			return 0;
+		}
+	}
+	return 0;
+}
diff --git a/data_lump.h b/data_lump.h
index 72d664b..8cdee5b 100644
--- a/data_lump.h
+++ b/data_lump.h
@@ -86,4 +86,9 @@ void del_nonshm_lump( struct lump** lump_list );
 
 /*! \brief remove the lump from the internal lists */
 int remove_lump(sip_msg_t *msg, struct lump *l);
+
+int sr_hdr_add_zz(sip_msg_t *msg, char *hname, char *hbody);
+int sr_hdr_del_z(sip_msg_t *msg, char *hname);
+hdr_field_t *sr_hdr_get_z(sip_msg_t *msg, char *hname);
+
 #endif




More information about the sr-dev mailing list