rem: process_lumps(msg, new_buf, &offset, &s_offset, 0);
add: process_lumps(msg, msg->add_rm, new_buf, &offset, &s_offset, 0); process_lumps(msg, msg->body_lumps, new_buf, &offset, &s_offset, 0);
context: char * build_res_buf_from_sip_res( struct sip_msg* msg,				unsigned int *returned_len){	unsigned int new_len, via_len;	char* new_buf;	unsigned offset, s_offset, via_offset;	char* buf;	unsigned int len;#ifdef USE_TCP	struct lump* anchor;	char* clen_buf;	unsigned int clen_len;		clen_buf=0;	clen_len=0;#endif	buf=msg->buf;	len=msg->len;	new_buf=0;	/* we must remove the first via */	if (msg->via1->next) {		via_len=msg->via1->bsize;		via_offset=msg->h_via1->body.s-buf;	} else {		via_len=msg->h_via1->len;		via_offset=msg->h_via1->name.s-buf;	}#ifdef USE_TCP	/* if sending proto == tcp, check if Content-Length needs to be added*/	if (msg->via2 && ((msg->via2->proto==PROTO_TCP)#ifdef USE_TLS				|| (msg->via2->proto==PROTO_TLS)#endif				)){		DBG("build_res_from_sip_res: checking content-length for \n%.*s\n",				(int)msg->len, msg->buf);		/* first of all parse content-length */		if (parse_headers(msg, HDR_CONTENTLENGTH, 0)==-1){			LOG(L_ERR, "build_res_buf_from_sip_res:"							" error parsing content-length\n");			goto skip_clen;		}		if (msg->content_length==0){			DBG("build_res_from_sip_res: no content_length hdr found\n");			/* we need to add it */			if ((clen_buf=clen_builder(msg, &clen_len))==0){				LOG(L_ERR, "build_res_buf_from_sip_res:" 								" clen_builder failed\n");				goto skip_clen;			}		}	}skip_clen:#endif		/* remove the first via*/	if (del_lump( &(msg->add_rm), via_offset, via_len, HDR_VIA)==0){		LOG(L_ERR, "build_res_buf_from_sip_res: error trying to remove first"					"via\n");		goto error;	}#ifdef USE_TCP	/* if clen needs to be added, add it */	if (clen_len){		/* msg->unparsed should point just before the final crlf,		 * parse_headers is called from clen_builder */		anchor=anchor_lump(&(msg->add_rm), msg->unparsed-buf, 0, 							HDR_CONTENTLENGTH);		DBG("build_res_from_sip_res: adding content-length: %.*s\n",				(int)clen_len, clen_buf);		if (anchor==0) goto error_clen; /* free clen_buf*/		if (insert_new_lump_after(anchor, clen_buf, clen_len,					HDR_CONTENTLENGTH)==0)			goto error_clen; /* free clen_buf*/	}#endif	new_len=len+lumps_len(msg, 0); /*FIXME: we don't know the send sock */		DBG(" old size: %d, new size: %d\n", len, new_len);	new_buf=(char*)pkg_malloc(new_len+1); /* +1 is for debugging 											 (\0 to print it )*/	if (new_buf==0){		LOG(L_ERR, "ERROR: build_res_buf_from_sip_res: out of mem\n");		goto error;	}	new_buf[new_len]=0; /* debug: print the message */	offset=s_offset=0;	process_lumps(msg, new_buf, &offset, &s_offset, 0); /*FIXME: no send sock*/	/* copy the rest of the message */	memcpy(new_buf+offset,		buf+s_offset, 		len-s_offset);	 /* send it! */	DBG("build_res_from_sip_res: copied size: orig:%d, new: %d, rest: %d"			" msg=\n%s\n", s_offset, offset, len-s_offset, new_buf);	*returned_len=new_len;	return new_buf;#ifdef USE_TCPerror_clen:	if (clen_buf) pkg_free(clen_buf);#endiferror:	*returned_len=0;	return 0;}