Module: kamailio
Branch: master
Commit: 4e49312d0d7a90f0234b8a29036867452771a8b7
URL:
https://github.com/kamailio/kamailio/commit/4e49312d0d7a90f0234b8a290368674…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2016-07-13T10:18:49+02:00
core: helper functions to add headers with str parameters
---
Modified: data_lump.c
Modified: data_lump.h
---
Diff:
https://github.com/kamailio/kamailio/commit/4e49312d0d7a90f0234b8a290368674…
Patch:
https://github.com/kamailio/kamailio/commit/4e49312d0d7a90f0234b8a290368674…
---
diff --git a/data_lump.c b/data_lump.c
index 1431222..19a6b90 100644
--- a/data_lump.c
+++ b/data_lump.c
@@ -738,19 +738,12 @@ 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_add(sip_msg_t *msg, str *sname, str *sbody)
{
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.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");
@@ -763,10 +756,10 @@ int sr_hdr_add_zz(sip_msg_t *msg, char *hname, char *hbody)
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, CRLF, CRLF_LEN);
+ 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, CRLF, CRLF_LEN);
h.s[h.len] = '\0';
if (insert_new_lump_before(anchor, h.s, h.len, 0) == 0)
{
@@ -781,6 +774,35 @@ int sr_hdr_add_zz(sip_msg_t *msg, char *hname, char *hbody)
/**
*
*/
+int sr_hdr_add_zz(sip_msg_t *msg, char *hname, char *hbody)
+{
+ str sname;
+ str sbody;
+
+ sname.s = hname;
+ sname.len = strlen(sname.s);
+ sbody.s = hbody;
+ sbody.len = strlen(sbody.s);
+
+ return sr_hdr_add(msg, &sname, &sbody);
+}
+
+/**
+ *
+ */
+int sr_hdr_add_zs(sip_msg_t *msg, char *hname, str *sbody)
+{
+ str sname;
+
+ sname.s = hname;
+ sname.len = strlen(sname.s);
+
+ return sr_hdr_add(msg, &sname, sbody);
+}
+
+/**
+ *
+ */
hdr_field_t *sr_hdr_get_z(sip_msg_t *msg, char *hname)
{
hdr_field_t *hf;
diff --git a/data_lump.h b/data_lump.h
index 8cdee5b..ff129c0 100644
--- a/data_lump.h
+++ b/data_lump.h
@@ -87,7 +87,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(sip_msg_t *msg, str *sname, str *sbody);
int sr_hdr_add_zz(sip_msg_t *msg, char *hname, char *hbody);
+int sr_hdr_add_zs(sip_msg_t *msg, char *hname, str *sbody);
int sr_hdr_del_z(sip_msg_t *msg, char *hname);
hdr_field_t *sr_hdr_get_z(sip_msg_t *msg, char *hname);