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

Function patch_content_length

modules/mangler/utils.c:67–114  ·  view source on GitHub ↗

TESTED */

Source from the content-addressed store, hash-verified

65
66/* TESTED */
67int
68patch_content_length (struct sip_msg *msg, unsigned int newValue)
69{
70
71 struct hdr_field *contentLength;
72 char *s, pos[11];
73 int len;
74
75 contentLength = msg->content_length;
76 if (contentLength == NULL) /* maybe not yet parsed */
77 {
78 if (parse_headers (msg, HDR_CONTENTLENGTH_F, 0) == -1)
79 {
80 LM_ERR("parse headers on Content-Length failed\n");
81 return -1;
82 }
83 contentLength = msg->content_length;
84 if (contentLength == NULL)
85 {
86 LM_ERR("failed to parse headers on Content-Length "
87 "succeeded but msg->content_length is still NULL\n");
88 return -2;
89 }
90 }
91 /* perhaps dangerous because buffer is static ? */
92 //pos = int2str(newValue,&len);
93 len = snprintf ((char *) pos, 10, "%u", newValue);
94 s = pkg_malloc (len);
95 if (s == NULL)
96 {
97 LM_ERR("unable to allocate %d bytes in pkg mem\n", len);
98 return -3;
99 }
100 memcpy (s, pos, len);
101 /* perhaps we made it and no one called int2str,might use sprintf */
102 if (patch
103 (msg, contentLength->body.s, contentLength->body.len, s, len) < 0)
104 {
105 pkg_free (s);
106 LM_ERR("lumping failed\n");
107 return -4;
108 }
109
110 LM_DBG ("succeeded in altering Content-Length to new value %u\n",newValue);
111
112 return 0;
113
114}

Callers 2

sdp_mangle_portFunction · 0.85
sdp_mangle_ipFunction · 0.85

Calls 1

patchFunction · 0.85

Tested by

no test coverage detected