rem: if (l==0)
add: offset = from->uri.s - msg->buf; while( msg->buf[offset]!='<')
context: int replace_from( struct sip_msg *msg, str *from_dsp, str *from_uri){	static char buf_s[MAX_URI_SIZE];	struct to_body *from;	struct lump* l;	str replace;	char *p;	str param;	int offset;	str buf;	int i;	/* consistency check! do NOT allow from changing in sequential request*/	if ( msg->to==0 && (parse_headers(msg,HDR_TO_F,0)!=0 || msg->to==0) ) {		LOG(L_ERR,"ERROR:uac:replace_from: failed to parse TO hdr\n");		goto error;	}	if (get_to(msg)->tag_value.len!=0) {		LOG(L_ERR,"ERROR:uac:replace_from: decline FROM replacing in "			"sequential request (has TO tag)\n");		goto error;	}	/* parse original from hdr */	if (parse_from_header(msg)!=0 )	{		LOG(L_ERR,"ERROR:uac:replace_from: failed to find/parse FROM hdr\n");		goto error;	}	from = (struct to_body*)msg->from->parsed;	/* some validity checks */	if (from->param_lst==0)	{		LOG(L_ERR,"ERROR:uac:replace_from: broken FROM hdr; no tag param\n");		goto error;	}	/* first deal with display name */	if (from_dsp && from->display.len)	{		/* must be replaced/ removed */		l = 0;		/* there is already a display -> remove it */		DBG("DEBUG:uac:replace_from: removing display [%.*s]\n",			from->display.len,from->display.s);		/* build del lump */		l = del_lump( msg, from->display.s-msg->buf, from->display.len, 0);		if (l==0)		{			LOG(L_ERR,"ERROR:uac:replace_from: display del lump failed\n");			goto error;		}		/* some new display to set? */		if (from_dsp->len)		{			if (l==0)			{				/* add anchor just before uri's "<" */				offset = from->uri.s - msg->buf;				while( msg->buf[offset]!='<')				{					offset--;					if (from->body.s>msg->buf+offset)					{						LOG(L_ERR,"ERROR:uac:replace_from: no <> and there"								" is dispaly name\n");						goto error;					}				}				if ( (l=anchor_lump( msg, offset, 0, 0))==0)				{					LOG(L_ERR,"ERROR:uac:replace_from: display anchor lump "						"failed\n");					goto error;				}			}			p = pkg_malloc( from_dsp->len);			if (p==0)			{				LOG(L_ERR,"ERROR:uac:replace_from: no more pkg mem\n");				goto error;			}			memcpy( p, from_dsp->s, from_dsp->len); 			if (insert_new_lump_after( l, p, from_dsp->len, 0)==0)			{				LOG(L_ERR,"ERROR:uac:replace_from: insert new "					"display lump failed\n");				pkg_free(p);				goto error;			}		}	}	/* now handle the URI */	if (from_uri==0 || from_uri->len==0 )		/* do not touch URI part */		return 0;	DBG("DEBUG:uac:replace_from: uri to replace [%.*s]\n",		from->uri.len, from->uri.s);	DBG("DEBUG:uac:replace_from: replacement uri is [%.*s]\n",		from_uri->len, from_uri->s);	/* build del/add lumps */	if ((l=del_lump( msg, from->uri.s-msg->buf, from->uri.len, 0))==0)	{		LOG(L_ERR,"ERROR:uac:replace_from: del lump failed\n");		goto error;	}	p = pkg_malloc( from_uri->len);	if (p==0)	{		LOG(L_ERR,"ERROR:uac:replace_from: no more pkg mem\n");		goto error;	}	memcpy( p, from_uri->s, from_uri->len); 	if (insert_new_lump_after( l, p, from_uri->len, 0)==0)	{		LOG(L_ERR,"ERROR:uac:replace_from: insert new lump failed\n");		pkg_free(p);		goto error;	}	if (from_restore_mode==FROM_NO_RESTORE)		return 0;	/* build RR parameter */	buf.s = buf_s;	if ( from->uri.len>from_uri->len ) {		if (from->uri.len>MAX_URI_SIZE) {			LOG(L_ERR,"ERROR:uac:replace_from: old from uri to long\n");			goto error;		}		memcpy( buf.s, from->uri.s, from->uri.len);		for( i=0 ; i<from_uri->len ; i++ )			buf.s[i] ^=from_uri->s[i];		buf.len = from->uri.len;	} else {		if (from_uri->len>MAX_URI_SIZE) {			LOG(L_ERR,"ERROR:uac:replace_from: new from uri to long\n");			goto error;		}		memcpy( buf.s, from_uri->s, from_uri->len);		for( i=0 ; i<from->uri.len ; i++ )			buf.s[i] ^=from->uri.s[i];		buf.len = from_uri->len;	}	/* encode the param */	if (encode_from( &buf , &replace)<0 )	{		LOG(L_ERR,"ERROR:uac:replace_from: failed to encode uris\n");		goto error;	}	DBG("DEBUG:uac:replace_from: encode is=<%.*s> len=%d\n",		replace.len,replace.s,replace.len);	/* add RR parameter */	param.len = 1+rr_param.len+1+replace.len;	param.s = (char*)pkg_malloc(param.len);	if (param.s==0)	{		LOG(L_ERR,"ERROR:uac:replace_from: no more pkg mem\n");		goto error;	}	p = param.s;	*(p++) = ';';	memcpy( p, rr_param.s, rr_param.len);	p += rr_param.len;	*(p++) = '=';	memcpy( p, replace.s, replace.len);	p += replace.len;	if (uac_rrb.add_rr_param( msg, &param)!=0)	{		LOG(L_ERR,"ERROR:uac:replace_from: add_RR_param failed\n");		goto error1;	}	msg->msg_flags |= FL_USE_UAC_FROM;	/* add TM callback to restore the FROM hdr in reply */	if (uac_tmb.register_tmcb(msg,0,TMCB_RESPONSE_IN,restore_from_reply,0)!=1)	{		LOG(L_ERR,"ERROR:uac:replace_from: failed to install TM callback\n");		goto error1;	}	pkg_free(param.s);	return 0;error1:	pkg_free(param.s);error:	return -1;}