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

📄 tm.c

📁 SIP Express Router, Linux下的SIP代理服务器,小巧实用,开发测试VoIP设备和应用的必备.
💻 C
📖 第 1 页 / 共 2 页
字号:
	   maximum number of  branches */	if (MAX_BRANCHES+1>31) {		LOG(L_CRIT, "Too many max UACs for UAC branch_bm_t bitmap: %d\n",			MAX_BRANCHES );		return -1;	}	if (init_callid() < 0) {		LOG(L_CRIT, "Error while initializing Call-ID generator\n");		return -1;	}	if (register_fifo_cmd(fifo_uac, "t_uac_dlg", 0) < 0) {		LOG(L_CRIT, "cannot register fifo t_uac\n");		return -1;	}	if (register_fifo_cmd(fifo_uac_cancel, "t_uac_cancel", 0) < 0) {		LOG(L_CRIT, "cannot register fifo t_uac_cancel\n");		return -1;	}	if (register_fifo_cmd(fifo_hash, "t_hash", 0)<0) {		LOG(L_CRIT, "cannot register hash\n");		return -1;	}	if (register_fifo_cmd(fifo_t_reply, "t_reply", 0)<0) {		LOG(L_CRIT, "cannot register t_reply\n");		return -1;	}	if (unixsock_register_cmd("t_uac_dlg", unixsock_uac) < 0) {		LOG(L_CRIT, "cannot register t_uac with the unix server\n");		return -1;	}	if (unixsock_register_cmd("t_uac_cancel", unixsock_uac_cancel) < 0) {		LOG(L_CRIT, "cannot register t_uac_cancel with the unix server\n");		return -1;	}	if (unixsock_register_cmd("t_hash", unixsock_hash) < 0) {		LOG(L_CRIT, "cannot register t_hash with the unix server\n");		return -1;	}	if (unixsock_register_cmd("t_reply", unixsock_t_reply) < 0) {		LOG(L_CRIT, "cannot register t_reply with the unix server\n");		return -1;	}	/* building the hash table*/	if (!init_hash_table()) {		LOG(L_ERR, "ERROR: mod_init: initializing hash_table failed\n");		return -1;	}	/* init static hidden values */	init_t();	if (!tm_init_timers()) {		LOG(L_ERR, "ERROR: mod_init: timer init failed\n");		return -1;	}	/* register the timer function */	register_timer( timer_routine , 0 /* empty attr */, 1 );	/* init_tm_stats calls process_count, which should	 * NOT be called from mod_init, because one does not	 * now, if a timer is used and thus how many processes	 * will be started; however we started already our	 * timers, so we know and process_count should not	 * change any more	 */		if (init_tm_stats()<0) {		LOG(L_CRIT, "ERROR: mod_init: failed to init stats\n");		return -1;	}	if (uac_init()==-1) {		LOG(L_ERR, "ERROR: mod_init: uac_init failed\n");		return -1;	}	if (init_tmcb_lists()!=1) {		LOG(L_CRIT, "ERROR:tm:mod_init: failed to init tmcb lists\n");		return -1;	}	tm_init_tags();	init_twrite_lines();	if (init_twrite_sock() < 0) {		LOG(L_ERR, "ERROR:tm:mod_init: Unable to create socket\n");		return -1;	}	/* register post-script clean-up function */	register_script_cb( w_t_unref, POST_SCRIPT_CB, 			0 /* empty param */ );	register_script_cb( script_init, PRE_SCRIPT_CB , 			0 /* empty param */ );	if (init_avp_params( fr_timer_param, fr_inv_timer_param)<0 ){		LOG(L_ERR,"ERROR:tm:mod_init: failed to process timer AVPs\n");		return -1;	}	return 0;}static int child_init(int rank) {	if (child_init_callid(rank) < 0) {		LOG(L_ERR, "ERROR: child_init: Error while initializing Call-ID generator\n");		return -2;	}	return 0;}/**************************** wrapper functions ***************************/static int t_check_status(struct sip_msg* msg, char *regexp, char *foo){	regmatch_t pmatch;	struct cell *t;	char *status;	char backup;	int lowest_status;	int n;	/* first get the transaction */	if (t_check( msg , 0 )==-1) return -1;	if ( (t=get_t())==0) {		LOG(L_ERR, "ERROR: t_check_status: cannot check status for a reply "			"which has no T-state established\n");		return -1;	}	backup = 0;	switch (rmode) {		case MODE_REQUEST:			/* use the status of the last sent reply */			status = int2str( t->uas.status, 0);			break;		case MODE_ONREPLY:			/* use the status of the current reply */			status = msg->first_line.u.reply.status.s;			backup = status[msg->first_line.u.reply.status.len];			status[msg->first_line.u.reply.status.len] = 0;			break;		case MODE_ONFAILURE:			/* use the status of the winning reply */			if (t_pick_branch( -1, 0, t, &lowest_status)<0 ) {				LOG(L_CRIT,"BUG:t_check_status: t_pick_branch failed to get "					" a final response in MODE_ONFAILURE\n");				return -1;			}			status = int2str( lowest_status , 0);			break;		default:			LOG(L_ERR,"ERROR:t_check_status: unsupported mode %d\n",rmode);			return -1;	}	DBG("DEBUG:t_check_status: checked status is <%s>\n",status);	/* do the checking */	n = regexec((regex_t*)regexp, status, 1, &pmatch, 0);	if (backup) status[msg->first_line.u.reply.status.len] = backup;	if (n!=0) return -1;	return 1;}inline static int w_t_check(struct sip_msg* msg, char* str, char* str2){	return t_check( msg , 0  ) ? 1 : -1;}inline static int _w_t_forward_nonack(struct sip_msg* msg, char* proxy,																	int proto){	struct cell *t;	if (t_check( msg , 0 )==-1) {		LOG(L_ERR, "ERROR: forward_nonack: "				"can't forward when no transaction was set up\n");		return -1;	}	t=get_t();	if ( t && t!=T_UNDEFINED ) {		if (msg->REQ_METHOD==METHOD_ACK) {			LOG(L_WARN,"WARNING: you don't really want to fwd hbh ACK\n");			return -1;		}		return t_forward_nonack(t, msg, ( struct proxy_l *) proxy, proto );	} else {		DBG("DEBUG: forward_nonack: no transaction found\n");		return -1;	}}inline static int w_t_forward_nonack( struct sip_msg* msg, char* proxy,										char* foo){	return _w_t_forward_nonack(msg, proxy, PROTO_NONE);}inline static int w_t_forward_nonack_uri(struct sip_msg* msg, char *foo,																	char *bar){	return _w_t_forward_nonack(msg, 0, PROTO_NONE);}inline static int w_t_forward_nonack_udp( struct sip_msg* msg, char* proxy,										char* foo){	return _w_t_forward_nonack(msg, proxy, PROTO_UDP);}#ifdef USE_TCPinline static int w_t_forward_nonack_tcp( struct sip_msg* msg, char* proxy,										char* foo){	return _w_t_forward_nonack(msg, proxy, PROTO_TCP);}#endif#ifdef USE_TLSinline static int w_t_forward_nonack_tls( struct sip_msg* msg, char* proxy,										char* foo){	return _w_t_forward_nonack(msg, proxy, PROTO_TLS);}#endifinline static int w_t_reply(struct sip_msg* msg, char* str, char* str2){	struct cell *t;	if (msg->REQ_METHOD==METHOD_ACK) {		LOG(L_WARN, "WARNING: t_reply: ACKs are not replied\n");		return -1;	}	if (t_check( msg , 0 )==-1) return -1;	t=get_t();	if (!t) {		LOG(L_ERR, "ERROR: t_reply: cannot send a t_reply to a message "			"for which no T-state has been established\n");		return -1;	}	/* if called from reply_route, make sure that unsafe version	 * is called; we are already in a mutex and another mutex in	 * the safe version would lead to a deadlock	 */	if (rmode==MODE_ONFAILURE) { 		DBG("DEBUG: t_reply_unsafe called from w_t_reply\n");		return t_reply_unsafe(t, msg, (unsigned int)(long) str, str2);	} else if (rmode==MODE_REQUEST) {		return t_reply( t, msg, (unsigned int)(long) str, str2);	} else {		LOG(L_CRIT, "BUG: w_t_reply entered in unsupported mode\n");		return -1;	}}inline static int w_t_release(struct sip_msg* msg, char* str, char* str2){	struct cell *t;	if (t_check( msg  , 0  )==-1) return -1;	t=get_t();	if ( t && t!=T_UNDEFINED ) 		return t_release_transaction( t );	return 1;}inline static int w_t_retransmit_reply( struct sip_msg* p_msg, char* foo, char* bar){	struct cell *t;	if (t_check( p_msg  , 0 )==-1) 		return 1;	t=get_t();	if (t) {		if (p_msg->REQ_METHOD==METHOD_ACK) {			LOG(L_WARN, "WARNING: : ACKs transmit_replies not replied\n");			return -1;		}		return t_retransmit_reply( t );	} else 		return -1;}inline static int w_t_newtran( struct sip_msg* p_msg, char* foo, char* bar ) {	/* t_newtran returns 0 on error (negative value means	   'transaction exists' */	return t_newtran( p_msg );}inline static int w_t_on_negative( struct sip_msg* msg, char *go_to, char *foo){	t_on_negative( (unsigned int )(long) go_to );	return 1;}inline static int w_t_on_reply( struct sip_msg* msg, char *go_to, char *foo ){	t_on_reply( (unsigned int )(long) go_to );	return 1;}inline static int _w_t_relay_to( struct sip_msg  *p_msg , 	struct proxy_l *proxy ){	struct cell *t;	if (rmode==MODE_ONFAILURE) { 		t=get_t();		if (!t || t==T_UNDEFINED) {			LOG(L_CRIT, "BUG: w_t_relay_to: undefined T\n");			return -1;		}		if (t_forward_nonack(t, p_msg, proxy, PROTO_NONE)<=0 ) {			LOG(L_ERR, "ERROR: w_t_relay_to: t_relay_to failed\n");			return -1;		}		return 1;	}	if (rmode==MODE_REQUEST) 		return t_relay_to( p_msg, proxy, PROTO_NONE,			0 /* no replication */ );	LOG(L_CRIT, "ERROR: w_t_relay_to: unsupported mode: %d\n", rmode);	return 0;}inline static int w_t_relay_to_udp( struct sip_msg  *p_msg , 	char *proxy, /* struct proxy_l *proxy expected */	char *_foo       /* nothing expected */ ){	((struct proxy_l *)proxy)->proto=PROTO_UDP;	return _w_t_relay_to( p_msg, ( struct proxy_l *) proxy);}#ifdef USE_TCPinline static int w_t_relay_to_tcp( struct sip_msg  *p_msg , 	char *proxy, /* struct proxy_l *proxy expected */	char *_foo       /* nothing expected */ ){	((struct proxy_l *)proxy)->proto=PROTO_TCP;	return _w_t_relay_to( p_msg, ( struct proxy_l *) proxy);}#endif#ifdef USE_TLSinline static int w_t_relay_to_tls( struct sip_msg  *p_msg , 	char *proxy, /* struct proxy_l *proxy expected */	char *_foo       /* nothing expected */ ){	((struct proxy_l *)proxy)->proto=PROTO_TLS;	return _w_t_relay_to( p_msg, ( struct proxy_l *) proxy);}#endifinline static int w_t_replicate( struct sip_msg  *p_msg , 	char *proxy, /* struct proxy_l *proxy expected */	char *_foo       /* nothing expected */ ){	return t_replicate(p_msg, ( struct proxy_l *) proxy, p_msg->rcv.proto );}inline static int w_t_replicate_udp( struct sip_msg  *p_msg , 	char *proxy, /* struct proxy_l *proxy expected */	char *_foo       /* nothing expected */ ){	return t_replicate(p_msg, ( struct proxy_l *) proxy, PROTO_UDP );}#ifdef USE_TCPinline static int w_t_replicate_tcp( struct sip_msg  *p_msg , 	char *proxy, /* struct proxy_l *proxy expected */	char *_foo       /* nothing expected */ ){	return t_replicate(p_msg, ( struct proxy_l *) proxy, PROTO_TCP );}#endif#ifdef USE_TLSinline static int w_t_replicate_tls( struct sip_msg  *p_msg , 	char *proxy, /* struct proxy_l *proxy expected */	char *_foo       /* nothing expected */ ){	return t_replicate(p_msg, ( struct proxy_l *) proxy, PROTO_TLS );}#endifinline static int w_t_relay( struct sip_msg  *p_msg , 						char *_foo, char *_bar){	struct cell *t;	if (rmode==MODE_ONFAILURE) { 		t=get_t();		if (!t || t==T_UNDEFINED) {			LOG(L_CRIT, "BUG: w_t_relay: undefined T\n");			return -1;		} 		if (t_forward_nonack(t, p_msg, ( struct proxy_l *) 0, PROTO_NONE)<=0) {			LOG(L_ERR, "ERROR: w_t_relay (failure mode): forwarding failed\n");			return -1;		}		return 1;	}	if (rmode==MODE_REQUEST) 		return t_relay_to( p_msg, 		(struct proxy_l *) 0 /* no proxy */, PROTO_NONE,		0 /* no replication */ );	LOG(L_CRIT, "ERROR: w_t_relay_to: unsupported mode: %d\n", rmode);	return 0;}

⌨️ 快捷键说明

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