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

Function clone_sip_msg_body

parser/parse_body.c:485–579  ·  view source on GitHub ↗

Clones the sip_msg_body structure attached to a sip msg into shm or pkg * memory. * Parameters: * * src_msg - the original sip_msg containing the sip_msg_body to be cloned * It can be in shm or pkg and it is mandatory. * * dst_msg - the destination sip_msg - this is need only when cloning into * shm, as we need to translate to this new sip msg all the *

Source from the content-addressed store, hash-verified

483 * * shared - 1 if to SHM or 0 if to PKG
484 */
485int clone_sip_msg_body(struct sip_msg *src_msg, struct sip_msg *dst_msg,
486 struct sip_msg_body **p_dst, int shared)
487{
488 struct sip_msg_body *dst, *src;
489 struct body_part *p, *np;
490 osips_malloc_f my_malloc;
491 int extra_len;
492
493 if (src_msg==NULL || src_msg->body==NULL) {
494 *p_dst = NULL;
495 return 0;
496 }
497
498 my_malloc = shared ? shm_malloc_func : pkg_malloc_func;
499 src = src_msg->body;
500
501 /* clone the SIP MSG BODY */
502 extra_len = (src->flags&SIP_BODY_FLAG_NEW) ?
503 src->first.mime_s.len+src->first.body.len : 0 ;
504 if ( (dst=func_malloc(my_malloc, sizeof(struct sip_msg_body)+extra_len))==NULL ) {
505 LM_ERR("failed to allocate new sip_msg_body clone (shared=%d)\n",
506 shared);
507 goto err;
508 }
509 memcpy( dst, src, sizeof(struct sip_msg_body)+extra_len);
510 if (shared)
511 dst->flags |= SIP_BODY_FLAG_SHM;
512 else
513 dst->flags &= ~SIP_BODY_FLAG_SHM;
514 /* update the links inside it */
515 if (dst_msg) { \
516 dst->body.s = translate_pointer(dst_msg->buf ,src_msg->buf,
517 src->body.s );
518 dst->boundary.s = translate_pointer(dst_msg->buf ,src_msg->buf,
519 src->boundary.s );
520 }
521 /* clone the body parts */
522 for( p=&src->first,np=NULL ; p ; p=p->next) {
523 if (np==NULL) { \
524 /* first body part */
525 np = &dst->first;
526 extra_len = 0;
527 } else {
528 extra_len = (p->flags&SIP_BODY_PART_FLAG_NEW) ?
529 p->mime_s.len+p->body.len+p->headers.len : 0 ;
530 if((np->next=func_malloc(my_malloc, sizeof(struct body_part)+extra_len))==NULL){
531 LM_ERR("failed to allocate new body_part clone (shared=%d)\n",
532 shared);
533 goto err;
534 } \
535 np = np->next;
536 } \
537 memcpy( np, p, sizeof(struct body_part)+extra_len);
538 /* update the links inside it */
539 if (p->flags&SIP_BODY_PART_FLAG_NEW) {
540 /* links are pointing inside the body_part structure */
541 if (p==&src->first) {
542 np->body.s = translate_pointer((char*)dst ,(char*)src,

Callers 4

fake_reqFunction · 0.85
pre_print_uac_requestFunction · 0.85
sip_msg_clonerFunction · 0.85

Calls 1

free_sip_bodyFunction · 0.85

Tested by

no test coverage detected