| 231 | |
| 232 | |
| 233 | int 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 |
no test coverage detected