⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 from.c

📁 性能优秀的SIP Proxy
💻 C
📖 第 1 页 / 共 2 页
字号:
	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;	}	/* encrypt parameter ;) */	if (uac_passwd.len)		for( i=0 ; i<buf.len ; i++)			buf.s[i] ^= uac_passwd.s[i%uac_passwd.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;}/* * return  0 - restored *        -1 - not restored or error */int restore_from( struct sip_msg *msg, int *is_from ){	struct lump* l;	str param_val;	str old_uri;	str new_uri;	char *p;	int i;	int flag;	/* we should process only sequntial request, but since we are looking	 * for Route param, the test is not really required -bogdan */	DBG("DEBUG:uac:restore_from: getting '%.*s' Route param\n",		rr_param.len,rr_param.s);	/* is there something to restore ? */	if (uac_rrb.get_route_param( msg, &rr_param, &param_val)!=0) {		DBG("DEBUG:uac:restore_from: Route param '%.*s' not found\n",			rr_param.len,rr_param.s);		goto failed;	}	DBG("DEBUG:uac:restore_from: Route param is '%.*s' (len=%d)\n",		param_val.len,param_val.s,param_val.len);	/* decode the parameter val to a URI */	if (decode_from( &param_val, &new_uri)<0 ) {		LOG(L_ERR,"ERROR:uac:restore_from: failed to decode uri\n");		goto failed;	}	/* dencrypt parameter ;) */	if (uac_passwd.len)		for( i=0 ; i<new_uri.len ; i++)			new_uri.s[i] ^= uac_passwd.s[i%uac_passwd.len];	/* check the request direction */	if (uac_rrb.is_direction( msg, RR_FLOW_UPSTREAM)==0) {		/* replace the TO URI */		if ( msg->to==0 && (parse_headers(msg,HDR_TO_F,0)!=0 || msg->to==0) ) {			LOG(L_ERR,"ERROR:uac:restore_from: failed to parse TO hdr\n");			goto failed;		}		old_uri = ((struct to_body*)msg->to->parsed)->uri;		flag = FL_USE_UAC_TO;		if (is_from) *is_from = 0;	} else {		/* replace the FROM URI */		if ( parse_from_header(msg)<0 ) {			LOG(L_ERR,"ERROR:uac:restore_from: failed to find/parse "				"FROM hdr\n");			goto failed;		}		old_uri = ((struct to_body*)msg->from->parsed)->uri;		flag = FL_USE_UAC_FROM;		if (is_from) *is_from = 1;	}	/* get new uri */	if ( new_uri.len<old_uri.len ) {		LOG(L_ERR,"ERROR:uac:restore_from: new URI shorter than old URI\n");		goto failed;	}	for( i=0 ; i<old_uri.len ; i++ )		new_uri.s[i] ^= old_uri.s[i];	if (new_uri.len==old_uri.len) {		for( ; new_uri.len && (new_uri.s[new_uri.len-1]==0) ; new_uri.len-- );		if (new_uri.len==0) {			LOG(L_ERR,"ERROR:uac:restore_from: new URI got 0 len\n");			goto failed;		}	}	DBG("DEBUG:uac:restore_from: decoded uris are: new=[%.*s] old=[%.*s]\n",		new_uri.len, new_uri.s, old_uri.len, old_uri.s);	/* duplicate the decoded value */	p = pkg_malloc( new_uri.len);	if (p==0) {		LOG(L_ERR,"ERROR:uac:restore_from: no more pkg mem\n");		goto failed;	}	memcpy( p, new_uri.s, new_uri.len);	new_uri.s = p;	/* build del/add lumps */	l = del_lump( msg, old_uri.s-msg->buf, old_uri.len, 0);	if (l==0) {		LOG(L_ERR,"ERROR:uac:restore_from: del lump failed\n");		goto failed1;	}	if (insert_new_lump_after( l, new_uri.s, new_uri.len, 0)==0) {		LOG(L_ERR,"ERROR:uac:restore_from: insert new lump failed\n");		goto failed1;	}	msg->msg_flags |= flag;	return 0;failed1:	pkg_free(new_uri.s);failed:	return -1;}/************************** RRCB functions ******************************/void rr_checker(struct sip_msg *msg, str *r_param, void *cb_param){	int is_from;	is_from = 0;	/* check if the request contains the route param */	if ( restore_from( msg, &is_from)==0 ) {		/* restore in req performed -> replace in reply */		/* in callback we need TO/FROM to be parsed- it's already done 		 * by restore_from() function */		if ( uac_tmb.register_tmcb( msg, 0, TMCB_RESPONSE_IN,		is_from?restore_from_reply:restore_to_reply, 0)!=1 ) {			LOG(L_ERR,"ERROR:uac:rr_checker: failed to install TM callback\n");				return;		}	}}/************************** TMCB functions ******************************//* replace the entire from HDR with the original FROM request */void restore_from_reply(struct cell* t, int type, struct tmcb_params *p){	struct lump* l;	struct sip_msg *req;	struct sip_msg *rpl;	str new_val;	if ( !t || !t->uas.request || !p->rpl )		return;	req = t->uas.request;	rpl = p->rpl;	/* parse FROM in reply */	if (parse_from_header( p->rpl )<0 ) {		LOG(L_ERR,"ERROR:uac:restore_from_reply: failed to find/parse "			"FROM hdr\n");		return;	}	/* duplicate the new from value */	new_val.s = pkg_malloc( req->from->len );	if (p==0) {		LOG(L_ERR,"ERROR:uac:restore_from_reply: no more pkg mem\n");		return;	}	memcpy( new_val.s, req->from->name.s, req->from->len);	new_val.len = req->from->len;	DBG("DBG:uac::restore_from_reply: removing <%.*s>\n",			rpl->from->len,rpl->from->name.s);	l = del_lump( rpl, rpl->from->name.s-rpl->buf, rpl->from->len, 0);	if (l==0) {		LOG(L_ERR,"ERROR:uac:restore_from_reply: del lump failed\n");		return;	}	DBG("DBG:uac::restore_from_reply: inserting <%.*s>\n",			new_val.len,new_val.s);	if (insert_new_lump_after( l, new_val.s, new_val.len, 0)==0) {		LOG(L_ERR,"ERROR:uac:restore_from_reply: insert new lump failed\n");		return;	}}/* replace the entire from TO with the original TO request */void restore_to_reply(struct cell* t, int type, struct tmcb_params *p){	struct lump* l;	struct sip_msg *req;	struct sip_msg *rpl;	str new_val;	if ( !t || !t->uas.request || !p->rpl )		return;	req = t->uas.request;	rpl = p->rpl;	/* parse TO in reply */	if ( rpl->to==0 && (parse_headers(rpl,HDR_TO_F,0)!=0 || rpl->to==0) ) {		LOG(L_ERR,"ERROR:uac:restore_to_reply: failed to parse TO hdr\n");		return;	}	/* duplicate the new from value */	new_val.s = pkg_malloc( req->to->len );	if (p==0) {		LOG(L_ERR,"ERROR:uac:restore_from_reply: no more pkg mem\n");		return;	}	memcpy( new_val.s, req->to->name.s, req->to->len);	new_val.len = req->to->len;	DBG("DBG:uac::restore_to_reply: removing <%.*s>\n",			rpl->to->len,rpl->to->name.s);	l = del_lump( rpl, rpl->to->name.s-rpl->buf, rpl->to->len, 0);	if (l==0) {		LOG(L_ERR,"ERROR:uac:restore_to_reply: del lump failed\n");		return;	}	DBG("DBG:uac::restore_to_reply: inserting <%.*s>\n",		new_val.len, new_val.s);	if (insert_new_lump_after( l, new_val.s, new_val.len, 0)==0) {		LOG(L_ERR,"ERROR:uac:restore_to_reply: insert new lump failed\n");		return;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -