|
@@ -203,282 +203,6 @@ int t_add_transaction( struct sip_msg* p_msg )
|
|
|
|
|
|
|
|
|
|
|
|
-#ifdef _OBSOLETED_TM
|
|
|
-/* function returns:
|
|
|
- * 1 - forward successfull
|
|
|
- * -1 - error during forward
|
|
|
- */
|
|
|
-int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int dest_port_param )
|
|
|
-{
|
|
|
- unsigned int dest_ip = dest_ip_param;
|
|
|
- unsigned int dest_port = dest_port_param;
|
|
|
- int branch;
|
|
|
- unsigned int len;
|
|
|
- char *buf, *shbuf;
|
|
|
- struct retrans_buff *rb;
|
|
|
- struct cell *T_source = T;
|
|
|
-
|
|
|
- buf=NULL;
|
|
|
- shbuf = NULL;
|
|
|
- branch = 0; /* we don't do any forking right now */
|
|
|
-
|
|
|
- /*if it's an ACK and the status is not final or is final, but error the
|
|
|
- ACK is not forwarded*/
|
|
|
- if ( p_msg->REQ_METHOD==METHOD_ACK && (T->status/100)!=2 ) {
|
|
|
- DBG("DEBUG: t_forward: local ACK; don't forward\n");
|
|
|
- return 1;
|
|
|
- }
|
|
|
-
|
|
|
- /* if it's forwarded for the first time, else the request is retransmited
|
|
|
- from the transaction buffer when forwarding an ACK, this condition will
|
|
|
- be all the time false because the forwarded INVITE is in the
|
|
|
- retransmission buffer */
|
|
|
- if ( T->outbound_request[branch]==NULL )
|
|
|
- {
|
|
|
- DBG("DEBUG: t_forward: first time forwarding\n");
|
|
|
- /* special case : CANCEL */
|
|
|
- if ( p_msg->REQ_METHOD==METHOD_CANCEL )
|
|
|
- {
|
|
|
- DBG("DEBUG: t_forward: it's CANCEL\n");
|
|
|
- if (T->outgoing_cancel[branch]!=NO_CANCEL)
|
|
|
- {
|
|
|
- DBG("DEBUG: t_forward: CANCEL already send on this branch ->"
|
|
|
- " dropping current CANCEL!!\n");
|
|
|
- return 1;
|
|
|
- }
|
|
|
- /* find original cancelled transaction; if found, use its
|
|
|
- next-hops; otherwise use those passed by script */
|
|
|
- if (T->T_canceled==T_UNDEFINED)
|
|
|
- T->T_canceled = t_lookupOriginalT( hash_table , p_msg );
|
|
|
- /* if found */
|
|
|
- if ( T->T_canceled!=T_NULL )
|
|
|
- {
|
|
|
- /* if in 1xx status, send to the same destination */
|
|
|
- if ( (T->T_canceled->status/100)==1 )
|
|
|
- {
|
|
|
- DBG("DEBUG: t_forward: it's CANCEL and I will send "
|
|
|
- "to the same place where INVITE went\n");
|
|
|
- dest_ip=T->T_canceled->outbound_request[branch]->
|
|
|
- to.sin_addr.s_addr;
|
|
|
- dest_port = T->T_canceled->outbound_request[branch]->
|
|
|
- to.sin_port;
|
|
|
-#ifdef USE_SYNONIM
|
|
|
- T_source = T->T_canceled;
|
|
|
- T->label = T->T_canceled->label;
|
|
|
-#endif
|
|
|
- } else { /* transaction exists, but nothing to cancel */
|
|
|
- DBG("DEBUG: t_forward: it's CANCEL but "
|
|
|
- "I have nothing to cancel here\n");
|
|
|
- /* continue forwarding CANCEL as a stand-alone transaction */
|
|
|
- }
|
|
|
- } else { /* transaction does not exists */
|
|
|
- DBG("DEBUG: t_forward: canceled request not found! "
|
|
|
- "nothing to CANCEL\n");
|
|
|
- }
|
|
|
- }/* end special case CANCEL*/
|
|
|
-
|
|
|
- if ( add_branch_label( T_source, T->inbound_request , branch )==-1)
|
|
|
- goto error;
|
|
|
- if ( add_branch_label( T_source, p_msg , branch )==-1)
|
|
|
- goto error;
|
|
|
- if ( !(buf = build_req_buf_from_sip_req ( p_msg, &len)))
|
|
|
- goto error;
|
|
|
-
|
|
|
- /* allocates a new retrans_buff for the outbound request */
|
|
|
- DBG("DEBUG: t_forward: building outbound request\n");
|
|
|
- shm_lock();
|
|
|
- T->outbound_request[branch] = rb = (struct retrans_buff*)
|
|
|
- shm_malloc_unsafe(sizeof(struct retrans_buff));
|
|
|
- if (!rb)
|
|
|
- {
|
|
|
- LOG(L_ERR, "ERROR: t_forward: out of shmem\n");
|
|
|
- shm_unlock();
|
|
|
- goto error;
|
|
|
- }
|
|
|
- shbuf = (char *) shm_malloc_unsafe( len );
|
|
|
- if (!shbuf)
|
|
|
- {
|
|
|
- LOG(L_ERR, "ERROR: t_forward: out of shmem buffer\n");
|
|
|
- shm_unlock();
|
|
|
- goto error;
|
|
|
- }
|
|
|
- shm_unlock();
|
|
|
- memset( rb , 0 , sizeof (struct retrans_buff) );
|
|
|
- rb->retr_timer.tg=TG_RT;
|
|
|
- rb->fr_timer.tg=TG_FR;
|
|
|
- rb->retr_buffer = shbuf;
|
|
|
- rb->retr_timer.payload = rb;
|
|
|
- rb->fr_timer.payload = rb;
|
|
|
- rb->to.sin_family = AF_INET;
|
|
|
- rb->my_T = T;
|
|
|
- rb->branch = branch;
|
|
|
- T->nr_of_outgoings = 1;
|
|
|
- rb->bufflen = len ;
|
|
|
- memcpy( rb->retr_buffer , buf , len );
|
|
|
- free( buf ) ; buf=NULL;
|
|
|
-
|
|
|
- DBG("DEBUG: t_forward: starting timers (retrans and FR) %d\n",
|
|
|
- get_ticks() );
|
|
|
- /*sets and starts the FINAL RESPONSE timer */
|
|
|
- set_timer( hash_table, &(rb->fr_timer), FR_TIMER_LIST );
|
|
|
-
|
|
|
- /* sets and starts the RETRANS timer */
|
|
|
- rb->retr_list = RT_T1_TO_1;
|
|
|
- set_timer( hash_table, &(rb->retr_timer), RT_T1_TO_1 );
|
|
|
- }/* end for the first time */
|
|
|
-
|
|
|
- /* if we are forwarding an ACK*/
|
|
|
- if ( p_msg->REQ_METHOD==METHOD_ACK &&
|
|
|
- T->relaied_reply_branch>=0 &&
|
|
|
- T->relaied_reply_branch<=T->nr_of_outgoings)
|
|
|
- {
|
|
|
- DBG("DEBUG: t_forward: forwarding ACK [%d]\n",T->relaied_reply_branch);
|
|
|
- t_build_and_send_ACK( T, branch ,
|
|
|
- T->inbound_response[T->relaied_reply_branch] );
|
|
|
- T->inbound_request_isACKed = 1;
|
|
|
- return 1;
|
|
|
- } else /* if we are forwarding a CANCEL*/
|
|
|
- if ( p_msg->REQ_METHOD==METHOD_CANCEL )
|
|
|
- {
|
|
|
- DBG("DEBUG: t_forward: forwarding CANCEL \n");
|
|
|
- /* if no transaction to CANCEL
|
|
|
- or if the canceled transaction has a final status -> drop the CANCEL*/
|
|
|
- if ( T->T_canceled!=T_NULL && T->T_canceled->status>=200)
|
|
|
- {
|
|
|
- reset_timer( hash_table, &(rb->fr_timer ));
|
|
|
- reset_timer( hash_table, &(rb->retr_timer ));
|
|
|
- return 1;
|
|
|
- }
|
|
|
- T->outgoing_cancel = EXTERNAL_CANCEL;
|
|
|
- }
|
|
|
-
|
|
|
- /* send the request */
|
|
|
- /* known to be in network order */
|
|
|
- rb->to.sin_port = dest_port;
|
|
|
- rb->to.sin_addr.s_addr = dest_ip;
|
|
|
- rb->to.sin_family = AF_INET;
|
|
|
-
|
|
|
- SEND_BUFFER( rb );
|
|
|
-
|
|
|
- return 1;
|
|
|
-
|
|
|
-error:
|
|
|
- if (shbuf) shm_free(shbuf);
|
|
|
- if (rb) {
|
|
|
- shm_free(rb);
|
|
|
- T->outbound_request[branch]=NULL;
|
|
|
- }
|
|
|
- if (buf) free( buf );
|
|
|
-
|
|
|
- return -1;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-/* Forwards the inbound request to dest. from via. Returns:
|
|
|
- * 1 - forward successfull
|
|
|
- * -1 - error during forward
|
|
|
- */
|
|
|
-int t_forward_uri( struct sip_msg* p_msg )
|
|
|
-{
|
|
|
- unsigned int ip, port;
|
|
|
-
|
|
|
- if ( get_ip_and_port_from_uri( p_msg , &ip, &port)<0 )
|
|
|
- {
|
|
|
- LOG( L_ERR , "ERROR: t_forward_uri: unable to parse uri!\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- return t_forward( p_msg , ip , port );
|
|
|
-}
|
|
|
-#endif
|
|
|
-
|
|
|
-
|
|
|
-#ifdef _OBSOLETED_TM
|
|
|
-int t_on_request_received( struct sip_msg *p_msg ,
|
|
|
- unsigned int ip , unsigned int port)
|
|
|
-{
|
|
|
- if ( t_check( p_msg , 0 , 0 ) )
|
|
|
- {
|
|
|
- if ( p_msg->first_line.u.request.method_value==METHOD_ACK )
|
|
|
- {
|
|
|
- DBG( "SER: ACK received -> t_release\n");
|
|
|
- if ( !t_forward( p_msg , ip , port ) )
|
|
|
- {
|
|
|
- DBG( "SER: WARNING: bad forward\n");
|
|
|
- }
|
|
|
- if ( !t_release_transaction( p_msg ) )
|
|
|
- {
|
|
|
- DBG( "SER: WARNING: bad t_release\n");
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if ( !t_retransmit_reply( p_msg ) )
|
|
|
- {
|
|
|
- DBG( "SER: WARNING: bad t_retransmit_reply\n");
|
|
|
- }
|
|
|
- DBG( "SER: yet another annoying retranmission\n");
|
|
|
- }
|
|
|
- t_unref( /* p_msg */ );
|
|
|
- } else {
|
|
|
- if ( p_msg->first_line.u.request.method_value==METHOD_ACK )
|
|
|
- {
|
|
|
- DBG( "SER: forwarding ACK statelessly\n");
|
|
|
- /* no established transaction ... forward ACK just statelessly*/
|
|
|
- forward_request( p_msg , mk_proxy_from_ip(ip,port) );
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- /* establish transaction*/
|
|
|
- if ( !t_add_transaction(p_msg) )
|
|
|
- {
|
|
|
- DBG( "SER: ERROR in ser: t_add_transaction\n");
|
|
|
- }
|
|
|
- /* reply */
|
|
|
- if ( p_msg->first_line.u.request.method_value==METHOD_CANCEL)
|
|
|
- {
|
|
|
- DBG( "SER: new CANCEL\n");
|
|
|
- if ( !t_send_reply( p_msg , 200, "glad to cancel") )
|
|
|
- {
|
|
|
- DBG( "SER:ERROR: t_send_reply\n");
|
|
|
- }
|
|
|
- } else {
|
|
|
- DBG( "SER: new transaction\n");
|
|
|
- if ( !t_send_reply( p_msg , 100 , "trying -- your call is important to us") )
|
|
|
- {
|
|
|
- DBG( "SER: ERROR: t_send_reply (100)\n");
|
|
|
- }
|
|
|
- }
|
|
|
- if ( !t_forward( p_msg, ip, port ) )
|
|
|
- {
|
|
|
- DBG( "SER:ERROR: t_forward \n");
|
|
|
- }
|
|
|
- t_unref( /* p_msg */ );
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-int t_on_request_received_uri( struct sip_msg *p_msg )
|
|
|
-{
|
|
|
- unsigned int ip, port;
|
|
|
-
|
|
|
- if ( get_ip_and_port_from_uri( p_msg , &ip, &port)<0 )
|
|
|
- {
|
|
|
- LOG( L_ERR , "ERROR: t_on_request_received_uri: \
|
|
|
- unable to extract ip and port from uri!\n" );
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- return t_on_request_received( p_msg , ip , port );
|
|
|
-}
|
|
|
-
|
|
|
-#endif
|
|
|
-
|
|
|
|
|
|
/* returns 1 if everything was OK or -1 for error
|
|
|
*/
|