rem: { if (!is_req) return 0;  if ( !msg->to && (parse_headers(msg,HDR_TO_F,0)==-1 || !msg->to)) { LOG(L_ERR,"ERROR:uac:restore_from: bad msg or missing TO hdr\n"); goto error; } ft_hdr = (struct to_body*)msg->to->parsed; for( param=ft_hdr->param_lst ; param ; param=param->next ) if (param->name.len==from_param.len && strncmp(param->name.s, from_param.s, from_param.len)==0) break; if (param==0) return 0; }
add: goto failed;
context: int restore_from( struct sip_msg *msg, int is_req){	struct to_body *ft_hdr;	struct to_param *param;	struct lump* l;	str replace;	str restore;	str del;	char *p;	/* parse original from hdr */	if (parse_from_header(msg)!=0 )	{		LOG(L_ERR,"ERROR:uac:restore_from: failed to find/parse FROM hdr\n");		goto error;	}	ft_hdr = (struct to_body*)msg->from->parsed;	/* check if it has the from param */	for( param=ft_hdr->param_lst ; param ; param=param->next )		if (param->name.len==from_param.len &&		strncmp(param->name.s, from_param.s, from_param.len)==0)			break;	if (param==0)	{		if (!is_req)			return 0;		/*if request, check also TO hdr*/		if ( !msg->to && (parse_headers(msg,HDR_TO_F,0)==-1 || !msg->to))		{			LOG(L_ERR,"ERROR:uac:restore_from: bad msg or missing TO hdr\n");			goto error;		}		ft_hdr = (struct to_body*)msg->to->parsed;		for( param=ft_hdr->param_lst ; param ; param=param->next )			if (param->name.len==from_param.len &&			strncmp(param->name.s, from_param.s, from_param.len)==0)				break;		if (param==0)			return 0;	}	/* determin what to replace */	replace.s = ft_hdr->uri.s;	replace.len = ft_hdr->uri.len;	DBG("DEBUG:uac:restore_from: replacing [%.*s]\n",		replace.len, replace.s);	/* build del/add lumps */	if ((l=del_lump( msg, replace.s-msg->buf, replace.len, 0))==0)	{		LOG(L_ERR,"ERROR:uac:restore_from: del lump failed\n");		goto error;	}	/* calculate the restore from */	if (decode_from( &param->value, &restore)<0 )	{		LOG(L_ERR,"ERROR:uac:restore_from: failed to dencode uri\n");		goto error;	}	DBG("DEBUG:uac:restore_from: replacement is [%.*s]\n",		replace.len, replace.s);	p = pkg_malloc( restore.len);	if (p==0)	{		LOG(L_ERR,"ERROR:uac:restore_from: no more pkg mem\n");		goto error;	}	memcpy( p, restore.s, restore.len);	if (insert_new_lump_after( l, p, restore.len, 0)==0)	{		LOG(L_ERR,"ERROR:uac:restore_from: insert new lump failed\n");		pkg_free(p);		goto error;	}	/* delete parameter */	del.s = param->name.s;	while ( *del.s!=';')  del.s--;	del.len = (int)(long)(param->value.s + param->value.len - del.s);	DBG("DEBUG:uac:restore_from: deleting [%.*s]\n",del.len,del.s);	if ((l=del_lump( msg, del.s-msg->buf, del.len, 0))==0) 	{		LOG(L_ERR,"ERROR:uac:restore_from: del lump failed\n");		goto error;	}	return 0;error:	return -1;}