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

Function parse_sip_body

parser/parse_body.c:233–345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231
232
233int parse_sip_body(struct sip_msg * msg)
234{
235 char *start, *end;
236 int type = 0, new_sdp = 0;
237 struct body_part *part, *last;
238 str delimiter, body;
239
240 /* is body already parsed ? */
241 if (msg->body) {
242 if (!have_sdp_ops(msg))
243 return 0;
244
245 free_sip_body(msg->body);
246 msg->body = NULL;
247 }
248
249 if ( get_body(msg,&body)!=0 || body.len==0)
250 return 0;
251
252 type = parse_content_type_hdr(msg);
253 if (type <= 0) {
254 if (!msg->sdp_ops || msg->sdp_ops->sdp.len == 0)
255 return 0;
256 type = (TYPE_APPLICATION<<16) + SUBTYPE_SDP;
257 new_sdp = 1;
258 }
259
260 msg->body = pkg_malloc(sizeof (struct sip_msg_body));
261 if (msg->body == 0)
262 {
263 LM_ERR("Unable to allocate memory\n");
264 return -1;
265 }
266 memset(msg->body, 0, sizeof (struct sip_msg_body));
267
268 msg->body->body = body;
269
270 if (!new_sdp)
271 msg->body->boundary = ((content_t *) msg->content_type->parsed)->boundary;
272
273 if ((type >> 16) == TYPE_MULTIPART)
274 {
275 msg->body->flags |= SIP_BODY_RCV_MULTIPART;
276 delimiter = ((content_t*) msg->content_type->parsed)->boundary;
277
278 LM_DBG("Starting parsing with boundary = [%.*s]\n",
279 delimiter.len, delimiter.s);
280
281 start = find_line_delimiter( body.s, body.s + body.len, delimiter);
282 if (start == NULL) {
283 LM_ERR("Unable to parse multipart type:"
284 " malformed - missing start delimiters\n");
285 goto out_free;
286 }
287
288 /* mark as first part (no previous one) */
289 last = NULL;
290

Callers 15

pv_set_sdpFunction · 0.85
pv_get_sdp_lineFunction · 0.85
pv_set_sdp_lineFunction · 0.85
pv_get_sdp_streamFunction · 0.85
pv_set_sdp_streamFunction · 0.85
pv_get_sdp_stream_idxFunction · 0.85
pv_get_sdp_sessionFunction · 0.85
pv_set_sdp_sessionFunction · 0.85
pv_get_content_typeFunction · 0.85
pv_get_msg_bodyFunction · 0.85
has_body_fFunction · 0.85
remove_body_part_fFunction · 0.85

Calls 7

have_sdp_opsFunction · 0.85
free_sip_bodyFunction · 0.85
get_bodyFunction · 0.85
parse_content_type_hdrFunction · 0.85
find_line_delimiterFunction · 0.85
new_partFunction · 0.85
parse_single_partFunction · 0.85

Tested by

no test coverage detected