MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / ospAppendHeader

Function ospAppendHeader

modules/osp/sipheader.c:985–1023  ·  view source on GitHub ↗

* Append header to SIP message * param msg SIP message * param header Header to be appended * return 0 success, -1 failure */

Source from the content-addressed store, hash-verified

983 * return 0 success, -1 failure
984 */
985static int ospAppendHeader(
986 struct sip_msg* msg,
987 str* header)
988{
989 char* s;
990 struct lump* anchor;
991
992 if((msg == 0) || (header == 0) || (header->s == 0) || (header->len <= 0)) {
993 LM_ERR("bad parameters for appending header\n");
994 return -1;
995 }
996
997 if (parse_headers(msg, HDR_EOH_F, 0) == -1) {
998 LM_ERR("failed to parse message\n");
999 return -1;
1000 }
1001
1002 anchor = anchor_lump(msg, msg->unparsed - msg->buf, 0);
1003 if (anchor == 0) {
1004 LM_ERR("failed to get anchor\n");
1005 return -1;
1006 }
1007
1008 s = (char*)pkg_malloc(header->len);
1009 if (s == 0) {
1010 LM_ERR("no pkg memory\n");
1011 return -1;
1012 }
1013
1014 memcpy(s, header->s, header->len);
1015
1016 if (insert_new_lump_before(anchor, s, header->len, 0) == 0) {
1017 LM_ERR("failed to insert lump\n");
1018 pkg_free(s);
1019 return -1;
1020 }
1021
1022 return 0;
1023}
1024
1025/*
1026 * Add OSP token header to SIP message

Callers 1

ospAddOspTokenFunction · 0.85

Calls 2

anchor_lumpFunction · 0.85
insert_new_lump_beforeFunction · 0.85

Tested by

no test coverage detected