Skip to content

Commit

Permalink
core: kemi - simplified anchor location for hdr append and insert fun…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
miconda committed Nov 19, 2017
1 parent 0df4055 commit 7ab180c
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/core/kemi.c
Expand Up @@ -634,7 +634,6 @@ static sr_kemi_t _sr_kemi_core[] = {
static int sr_kemi_hdr_append(sip_msg_t *msg, str *txt)
{
struct lump* anchor;
struct hdr_field *hf;
char *hdr;

if(txt==NULL || txt->s==NULL || msg==NULL)
Expand All @@ -646,14 +645,14 @@ static int sr_kemi_hdr_append(sip_msg_t *msg, str *txt)
return -1;
}

hf = msg->last_header;
hdr = (char*)pkg_malloc(txt->len);
if(hdr==NULL) {
LM_ERR("no pkg memory left\n");
return -1;
}
memcpy(hdr, txt->s, txt->len);
anchor = anchor_lump(msg, hf->name.s + hf->len - msg->buf, 0, 0);
/* anchor after last header */
anchor = anchor_lump(msg, msg->unparsed - msg->buf, 0, 0);
if(insert_new_lump_before(anchor, hdr, txt->len, 0) == 0) {
LM_ERR("can't insert lump\n");
pkg_free(hdr);
Expand Down Expand Up @@ -766,21 +765,20 @@ static int sr_kemi_hdr_remove(sip_msg_t *msg, str *txt)
static int sr_kemi_hdr_insert(sip_msg_t *msg, str *txt)
{
struct lump* anchor;
struct hdr_field *hf;
char *hdr;

if(txt==NULL || txt->s==NULL || msg==NULL)
return -1;

LM_DBG("insert hf: %.*s\n", txt->len, txt->s);
hf = msg->headers;
hdr = (char*)pkg_malloc(txt->len);
if(hdr==NULL) {
LM_ERR("no pkg memory left\n");
return -1;
}
memcpy(hdr, txt->s, txt->len);
anchor = anchor_lump(msg, hf->name.s + hf->len - msg->buf, 0, 0);
/* anchor before first header */
anchor = anchor_lump(msg, msg->headers->name.s - msg->buf, 0, 0);
if(insert_new_lump_before(anchor, hdr, txt->len, 0) == 0) {
LM_ERR("can't insert lump\n");
pkg_free(hdr);
Expand Down

0 comments on commit 7ab180c

Please sign in to comment.