Browse code

script hardwired and ACK maching fixed

Bogdan-Andrei Iancu authored on 15/01/2002 17:36:44
Showing 7 changed files
... ...
@@ -18,8 +18,9 @@ struct s_table*  hash_table;
18 18
 
19 19
 
20 20
 
21
+
21 22
 /* determine timer length and put on a correct timer list */
22
-static inline void set_timer( struct s_table *hash_table, 
23
+static inline void set_timer( struct s_table *hash_table,
23 24
 	struct timer_link *new_tl, enum lists list_id )
24 25
 {
25 26
 	unsigned int timeout;
... ...
@@ -35,7 +36,7 @@ static inline void set_timer( struct s_table *hash_table,
35 35
 		return;
36 36
 	}
37 37
 	timeout = to_table[ list_id ];
38
-	add_to_tail_of_timer_list( &(hash_table->timers[ list_id ]), 
38
+	add_to_tail_of_timer_list( &(hash_table->timers[ list_id ]),
39 39
 		new_tl,get_ticks()+timeout);
40 40
 }
41 41
 
... ...
@@ -209,14 +210,14 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
209 209
 		return -1;
210 210
 	}
211 211
 
212
-	/*if it's an ACK and the status is not final or is final, but error the 
213
-     ACK is not forwarded*/
212
+	/*if it's an ACK and the status is not final or is final, but error the
213
+	ACK is not forwarded*/
214 214
 	if ( p_msg->REQ_METHOD==METHOD_ACK  && (T->status/100)!=2 ) {
215 215
 		DBG("DEBUG: t_forward: local ACK; don't forward\n");
216 216
 		return 1;
217 217
 	}
218 218
 
219
-	/* if it's forwarded for the first time ; else the request is retransmited 
219
+	/* if it's forwarded for the first time ; else the request is retransmited
220 220
 	 * from the transaction buffer
221 221
 	 * when forwarding an ACK, this condition will br all the time false because
222 222
 	 * the forwarded INVITE is in the retransmission buffer */
... ...
@@ -227,7 +228,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
227 227
 		if ( p_msg->REQ_METHOD==METHOD_CANCEL  )
228 228
 		{
229 229
 			DBG("DEBUG: t_forward: it's CANCEL\n");
230
-			/* find original cancelled transaction; if found, use its 
230
+			/* find original cancelled transaction; if found, use its
231 231
 			   next-hops; otherwise use those passed by script */
232 232
 			if ( T->T_canceled==T_UNDEFINED )
233 233
 				T->T_canceled = t_lookupOriginalT( hash_table , p_msg );
... ...
@@ -267,7 +268,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
267 267
 		/* allocates a new retrans_buff for the outbound request */
268 268
 		DBG("DEBUG: t_forward: building outbound request\n");
269 269
 		shm_lock();
270
-		T->outbound_request[branch] = rb = 
270
+		T->outbound_request[branch] = rb =
271 271
 			(struct retrans_buff*)shm_malloc_unsafe( sizeof(struct retrans_buff)  );
272 272
 		if (!rb)
273 273
 		{
... ...
@@ -277,7 +278,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
277 277
 		}
278 278
 		shbuf = (char *) shm_malloc_unsafe( len );
279 279
 		if (!shbuf)
280
-		{ 
280
+		{
281 281
 			LOG(L_ERR, "ERROR: t_forward: out of shmem buffer\n");
282 282
 			shm_unlock();
283 283
 			goto error;
... ...
@@ -305,11 +306,11 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
305 305
 
306 306
 	/* if we are forwarding an ACK*/
307 307
 	if (  p_msg->REQ_METHOD==METHOD_ACK &&
308
-		T->relaied_reply_branch>=0 && 
308
+		T->relaied_reply_branch>=0 &&
309 309
 		T->relaied_reply_branch<=T->nr_of_outgoings)
310 310
 	{
311 311
 		DBG("DEBUG: t_forward: forwarding ACK [%d]\n",T->relaied_reply_branch);
312
-		t_build_and_send_ACK( T, branch , 
312
+		t_build_and_send_ACK( T, branch ,
313 313
 			T->inbound_response[T->relaied_reply_branch] );
314 314
 		T->inbound_request_isACKed = 1;
315 315
 		return 1;
... ...
@@ -356,60 +357,13 @@ error:
356 356
  */
357 357
 int t_forward_uri( struct sip_msg* p_msg, char* foo, char* bar  )
358 358
 {
359
-   struct hostent  *nhost;
360 359
    unsigned int     ip, port;
361
-   struct sip_uri    parsed_uri;
362
-   str                      uri;
363
-   int                      err;
364
-
365
-   /* it's about the same transaction or not? */
366
-	if (t_check( p_msg  , 0 )==-1) return -1;
367
-
368
-   /*if T hasn't been found after all -> return not found (error) */
369
-   if ( !T )
370
-   {
371
-      DBG("DEBUG: t_forward_uri: no transaction found in order  to forward the request\n");
372
-      return -1;
373
-   }
374
-
375
-   /* the original uri has been changed? */
376
-   if (p_msg->new_uri.s==0 || p_msg->new_uri.len==0)
377
-     uri = p_msg->first_line.u.request.uri;
378
-   else
379
-     uri = p_msg->new_uri;
380
-
381
-   /* parsing the request uri in order to get host and port */
382
-   if (parse_uri( uri.s , uri.len , &parsed_uri )<0)
383
-   {
384
-        LOG(L_ERR, "ERROR: t_forward_uri: unable to parse destination uri\n");
385
-        return  -1;
386
-   }
387
-
388
-   /* getting host address*/
389
-   nhost = gethostbyname( parsed_uri.host.s ); 
390 360
 
391
-   if ( !nhost )
361
+   if ( get_ip_and_port_from_uri( p_msg , &ip, &port)<0 )
392 362
    {
393
-      LOG(L_ERR, "ERROR: t_forward_uri: cannot resolve host\n");
363
+      LOG( L_ERR , "ERROR: t_forward_uri: unable to extarct ip and port from uri!\n" );
394 364
       return -1;
395 365
    }
396
-   memcpy(&ip, nhost->h_addr_list[0], sizeof(unsigned int));
397
-
398
-   /* getting the port */
399
-   if ( parsed_uri.port.s==0 || parsed_uri.port.len==0 )
400
-      port = SIP_PORT;
401
-   else
402
-   {
403
-       port = str2s( parsed_uri.port.s , parsed_uri.port.len , &err );
404
-       if ( err<0 )
405
-       {
406
-           LOG(L_ERR, "ERROR: t_forward_uri: converting port from str to int failed; using default SIP port\n");
407
-           port = SIP_PORT;
408
-       }
409
-   }
410
-   port = htons( port );
411
-
412
-   free_uri( &parsed_uri );
413 366
 
414 367
    return t_forward( p_msg , ip , port );
415 368
 }
... ...
@@ -445,7 +399,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
445 445
 
446 446
 	/* we were not able to process the response due to memory
447 447
 	   shortage; simply drop it; hopefuly, we will have more
448
-           memory on the next try 
448
+           memory on the next try
449 449
 	*/
450 450
 	msg_status=p_msg->REPLY_STATUS;
451 451
 	msg_class=REPLY_CLASS(p_msg);
... ...
@@ -464,7 +418,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
464 464
 	/* stop final response timer only if I got a final response */
465 465
 	if ( msg_class>1 )
466 466
 		reset_timer( hash_table, &(rb->fr_timer));
467
-   	/* if a got the first prov. response for an INVITE -> 
467
+   	/* if a got the first prov. response for an INVITE ->
468 468
 	   change FR_TIME_OUT to INV_FR_TIME_UT */
469 469
 	if (!T->inbound_response[branch] && msg_class==1
470 470
 	 && T->inbound_request->REQ_METHOD==METHOD_INVITE )
... ...
@@ -500,7 +454,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
500 500
 		return 0;
501 501
 	}
502 502
 
503
-   	/* restart retransmission if provisional response came for a non_INVITE -> 
503
+   	/* restart retransmission if provisional response came for a non_INVITE ->
504 504
 		retrasmit at RT_T2*/
505 505
 	if ( msg_class==1 && T->inbound_request->REQ_METHOD!=METHOD_INVITE )
506 506
 	{
... ...
@@ -520,7 +474,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
520 520
 		if ( t_all_final(T) && relay_lowest_reply_upstream( T , p_msg )==-1 && clone )
521 521
 			goto error;
522 522
 	} else {
523
-		if (push_reply_from_uac_to_uas( T , branch )==-1 && clone ) 
523
+		if (push_reply_from_uac_to_uas( T , branch )==-1 && clone )
524 524
 			goto error;
525 525
    	}
526 526
 
... ...
@@ -539,6 +493,87 @@ error:
539 539
 }
540 540
 
541 541
 
542
+int t_on_request_received( struct sip_msg  *p_msg , unsigned int ip , unsigned int port)
543
+{
544
+	if ( t_check( p_msg , 0 ) )
545
+	{
546
+		if ( p_msg->first_line.u.request.method_value==METHOD_ACK )
547
+		{
548
+			LOG( L_INFO , "SER: ACK received -> t_release\n");
549
+			if ( !t_forward( p_msg , ip , port ) )
550
+			{
551
+				LOG( L_WARN, "SER: WARNING: bad forward\n");
552
+			}
553
+			if ( !t_release_transaction( p_msg ) )
554
+			{
555
+				LOG( L_WARN ,"SER: WARNING: bad t_release\n");
556
+			}
557
+		}
558
+		else
559
+		{
560
+			if ( !t_retransmit_reply( p_msg , 0, 0) )
561
+			{
562
+				LOG( L_WARN, "SER: WARNING: bad t_retransmit_reply\n");
563
+			}
564
+			LOG( L_INFO, "SER: yet another annoying retranmission\n");
565
+		}
566
+		t_unref( p_msg,0,0 );
567
+	} else {
568
+		if ( p_msg->first_line.u.request.method_value==METHOD_ACK )
569
+		{
570
+			LOG( L_INFO , "SER: forwarding ACK  statelessly\n");
571
+			/* no established transaction ... forward ACK just statelessly*/
572
+			forward_request( p_msg , mk_proxy_from_ip(ip,port) );
573
+		}
574
+		else
575
+		{
576
+			/* establish transaction*/
577
+			if ( !t_add_transaction(p_msg,0,0) )
578
+			{
579
+				LOG( L_ERR , "ERROR in ser: t_add_transaction\n");
580
+			}
581
+			/* reply */
582
+			if ( p_msg->first_line.u.request.method_value==METHOD_CANCEL)
583
+			{
584
+				LOG( L_INFO, "SER: new CANCEL\n");
585
+				if ( !t_send_reply( p_msg , 200, "glad to cancel") )
586
+				{
587
+					LOG( L_ERR ,"SER:ERROR: t_send_reply\n");
588
+				}
589
+			} else {
590
+				LOG( L_INFO, "SER: new transaction\n");
591
+				if ( !t_send_reply( p_msg , 100 , "trying -- your call is important to us") )
592
+				{
593
+					LOG( L_ERR, "SER: ERROR: t_send_reply (100)\n");
594
+				}
595
+			}
596
+			if ( !t_forward( p_msg, ip, port ) )
597
+			{
598
+				LOG( L_ERR , "SER:ERROR: t_forward \n");
599
+			}
600
+			t_unref( p_msg , 0 , 0);
601
+		}
602
+	}
603
+
604
+}
605
+
606
+
607
+
608
+
609
+int t_on_request_received_uri( struct sip_msg  *p_msg )
610
+{
611
+   unsigned int     ip, port;
612
+
613
+   if ( get_ip_and_port_from_uri( p_msg , &ip, &port)<0 )
614
+   {
615
+      LOG( L_ERR , "ERROR: t_on_request_received_uri: unable to extract ip and port from uri!\n" );
616
+      return -1;
617
+   }
618
+
619
+   return t_on_request_received( p_msg , ip , port );
620
+}
621
+
622
+
542 623
 
543 624
 
544 625
 /*   returns 1 if everything was OK or -1 for error
... ...
@@ -578,6 +613,9 @@ int t_retransmit_reply( struct sip_msg* p_msg, char* foo, char* bar  )
578 578
    return -1;
579 579
 }
580 580
 
581
+
582
+
583
+
581 584
 int t_unref( struct sip_msg* p_msg, char* foo, char* bar )
582 585
 {
583 586
 	if (T==T_UNDEFINED || T==T_NULL)
... ...
@@ -688,7 +726,7 @@ int push_reply_from_uac_to_uas( struct cell* trans , unsigned int branch )
688 688
 	if ( ! rb->retr_buffer ) {
689 689
 		/*init retrans buffer*/
690 690
 		memset( rb , 0 , sizeof (struct retrans_buff) );
691
-		if (update_sock_struct_from_via(  &(rb->to),  
691
+		if (update_sock_struct_from_via(  &(rb->to),
692 692
 			trans->inbound_response[branch]->via2 )==-1) {
693 693
 				LOG(L_ERR, "ERROR: push_reply_from_uac_to_uas: "
694 694
 					"cannot lookup reply dst: %s\n",
... ...
@@ -714,8 +752,7 @@ int push_reply_from_uac_to_uas( struct cell* trans , unsigned int branch )
714 714
 	}
715 715
 
716 716
 	/* if this is a first reply (?100), longer replies will probably follow;
717
-       try avoiding shm_resize by higher buffer size
718
-    */
717
+	try avoiding shm_resize by higher buffer size */
719 718
 	buf_len = rb->retr_buffer ? len : len + REPLY_OVERBUFFER_LEN;
720 719
 	if (! (rb->retr_buffer = (char*)shm_resize( rb->retr_buffer, buf_len )))
721 720
 	{
... ...
@@ -723,22 +760,22 @@ int push_reply_from_uac_to_uas( struct cell* trans , unsigned int branch )
723 723
 		goto error1;
724 724
 	}
725 725
 	rb->bufflen = len ;
726
-   	memcpy( rb->retr_buffer , buf , len );
727
-   	free( buf ) ;
726
+	memcpy( rb->retr_buffer , buf , len );
727
+	free( buf ) ;
728 728
 
729
-   	/* update the status*/
730
-   	trans->status = trans->inbound_response[branch]->REPLY_STATUS;
731
-   	if ( trans->inbound_response[branch]->REPLY_STATUS>=200 &&
732
-         trans->relaied_reply_branch==-1 )
733
-       		trans->relaied_reply_branch = branch;
729
+	/* update the status*/
730
+	trans->status = trans->inbound_response[branch]->REPLY_STATUS;
731
+	if ( trans->inbound_response[branch]->REPLY_STATUS>=200 &&
732
+	trans->relaied_reply_branch==-1 )
733
+		trans->relaied_reply_branch = branch;
734 734
 
735 735
 	/* start/stops the proper timers*/
736 736
 	t_update_timers_after_sending_reply( rb );
737 737
 
738
-   	/*send the reply*/
739
-   	/* t_retransmit_reply( trans->inbound_response[branch], 0 , 0 ); */
738
+	/*send the reply*/
739
+	/* t_retransmit_reply( trans->inbound_response[branch], 0 , 0 ); */
740 740
 	SEND_BUFFER( rb );
741
-   	return 1;
741
+	return 1;
742 742
 
743 743
 error1:
744 744
 	free( buf );
... ...
@@ -763,13 +800,13 @@ int t_all_final( struct cell *Trans )
763 763
 {
764 764
    unsigned int i;
765 765
 
766
-   for( i=0 ; i<Trans->nr_of_outgoings ; i++  )
767
-      if (  !Trans->inbound_response[i] ||  
768
-			Trans->inbound_response[i]->REPLY_STATUS<=200 )
769
-         return 0;
766
+	for( i=0 ; i<Trans->nr_of_outgoings ; i++  )
767
+		if (  !Trans->inbound_response[i] ||
768
+		Trans->inbound_response[i]->REPLY_STATUS<=200 )
769
+			return 0;
770 770
 
771
-  DBG("DEBUG: t_all_final: final state!!!!:)) \n");
772
-  return 1;
771
+	DBG("DEBUG: t_all_final: final state!!!!:)) \n");
772
+	return 1;
773 773
 }
774 774
 
775 775
 
... ...
@@ -810,7 +847,7 @@ int t_update_timers_after_sending_reply( struct retrans_buff *rb )
810 810
 {
811 811
 	struct cell *Trans = rb->my_T;
812 812
 
813
-	/* make sure that if we send something final upstream, everything else 
813
+	/* make sure that if we send something final upstream, everything else
814 814
 	   will be cancelled */
815 815
 	if (Trans->status>=300 && Trans->inbound_request->REQ_METHOD==METHOD_INVITE )
816 816
 	{
... ...
@@ -819,13 +856,13 @@ int t_update_timers_after_sending_reply( struct retrans_buff *rb )
819 819
 		set_timer( hash_table, &(rb->fr_timer), FR_TIMER_LIST );
820 820
    	} else if ( Trans->inbound_request->REQ_METHOD==METHOD_CANCEL ) {
821 821
 		if ( Trans->T_canceled==T_UNDEFINED )
822
-			Trans->T_canceled = t_lookupOriginalT( hash_table , 
822
+			Trans->T_canceled = t_lookupOriginalT( hash_table ,
823 823
 				Trans->inbound_request );
824 824
       		if ( Trans->T_canceled==T_NULL )
825 825
             		return 1;
826 826
       		Trans->T_canceled->T_canceler = Trans;
827 827
      		/* put CANCEL transaction on wait only if canceled transaction already
828
-        	   is in final status and there is nothing to cancel; 
828
+        	   is in final status and there is nothing to cancel;
829 829
      		*/
830 830
      		if ( Trans->T_canceled->status>=200)
831 831
             		t_put_on_wait( Trans );
... ...
@@ -837,9 +874,9 @@ int t_update_timers_after_sending_reply( struct retrans_buff *rb )
837 837
 
838 838
 
839 839
 
840
-/* Checks if the new reply (with new_code status) should be sent or not 
840
+/* Checks if the new reply (with new_code status) should be sent or not
841 841
  *  based on the current
842
-  * transactin status. 
842
+  * transactin status.
843 843
   * Returns 1 - the response can be sent
844 844
   *         0 - is not indicated to sent
845 845
   */
... ...
@@ -859,21 +896,21 @@ int t_should_relay_response( struct cell *Trans , int new_code )
859 859
 		if (new_code!=100) { /* all but "100 trying" */
860 860
 			DBG("DBG: t_should_relay: !=100 -> relay\n");
861 861
 			return 1;
862
-		} 
862
+		}
863 863
 	}
864 864
 	DBG("DBG: t_should_relay: not to be relayed\n");
865 865
 	return 0;
866 866
 
867 867
 
868 868
 /*
869
-   // have we already sent something? 
869
+   // have we already sent something?
870 870
    if ( !Trans->outbound_response.retr_buffer )
871 871
    {
872 872
       DBG("DEBUG: t_should_relay_response: %d response relayed (no previous response sent)\n",new_code);
873 873
       return 1;
874 874
    }
875 875
 
876
-   // have we sent a final response? 
876
+   // have we sent a final response?
877 877
    if ( (T_code/100)>1 )
878 878
    {  //final response was sent
879 879
       if ( new_code==200 && Trans->inbound_request->REQ_METHOD==METHOD_INVITE )
... ...
@@ -883,7 +920,7 @@ int t_should_relay_response( struct cell *Trans , int new_code )
883 883
       }
884 884
    }
885 885
    else
886
-   { // provisional response was sent 
886
+   { // provisional response was sent
887 887
       if ( new_code>T_code )
888 888
       {
889 889
          DBG("DEBUG: t_should_relay_response: %d response relayed (higher provisional response)\n",new_code);
... ...
@@ -1115,6 +1152,66 @@ void delete_cell( struct cell *p_cell )
1115 1115
 }
1116 1116
 
1117 1117
 
1118
+/* Returns  -1 = error
1119
+                    0 = OK
1120
+*/
1121
+int get_ip_and_port_from_uri( struct sip_msg* p_msg , unsigned int *param_ip, unsigned int *param_port)
1122
+{
1123
+   struct hostent  *nhost;
1124
+   unsigned int     ip, port;
1125
+   struct sip_uri    parsed_uri;
1126
+   str                      uri;
1127
+   int                      err;
1128
+
1129
+   /* the original uri has been changed? */
1130
+   if (p_msg->new_uri.s==0 || p_msg->new_uri.len==0)
1131
+     uri = p_msg->first_line.u.request.uri;
1132
+   else
1133
+     uri = p_msg->new_uri;
1134
+
1135
+   /* parsing the request uri in order to get host and port */
1136
+   if (parse_uri( uri.s , uri.len , &parsed_uri )<0)
1137
+   {
1138
+        LOG(L_ERR, "ERROR: get_ip_and_port_from_uri: unable to parse destination uri\n");
1139
+        return  -1;
1140
+   }
1141
+
1142
+   /* getting host address*/
1143
+   nhost = gethostbyname( parsed_uri.host.s );
1144
+
1145
+   if ( !nhost )
1146
+   {
1147
+      LOG(L_ERR, "ERROR: get_ip_and_port_from_uri: cannot resolve host\n");
1148
+      return -1;
1149
+   }
1150
+   memcpy(&ip, nhost->h_addr_list[0], sizeof(unsigned int));
1151
+
1152
+   /* getting the port */
1153
+   if ( parsed_uri.port.s==0 || parsed_uri.port.len==0 )
1154
+      port = SIP_PORT;
1155
+   else
1156
+   {
1157
+       port = str2s( parsed_uri.port.s , parsed_uri.port.len , &err );
1158
+       if ( err<0 )
1159
+       {
1160
+           LOG(L_ERR, "ERROR: get_ip_and_port_from_uri: converting port from str to int failed; using default SIP port\n");
1161
+           port = SIP_PORT;
1162
+       }
1163
+   }
1164
+   port = htons( port );
1165
+
1166
+   free_uri( &parsed_uri );
1167
+
1168
+   *param_ip = ip;
1169
+   *param_port = port;
1170
+   return 0;
1171
+}
1172
+
1173
+
1174
+
1175
+
1176
+
1177
+
1118 1178
 /*---------------------TIMEOUT HANDLERS--------------------------*/
1119 1179
 
1120 1180
 
... ...
@@ -13,6 +13,7 @@
13 13
 #include "../../globals.h"
14 14
 #include "../../udp_server.h"
15 15
 #include "../../msg_translator.h"
16
+#include "../../forward.h"
16 17
 #include "../../mem/mem.h"
17 18
 
18 19
 struct s_table;
... ...
@@ -162,6 +163,26 @@ int t_on_reply_received( struct sip_msg  *p_msg ) ;
162 162
 
163 163
 
164 164
 
165
+/*  This function is called whenever a request for our module is received; we need to register
166
+  *  this function on module initialization;
167
+  *  Returns :   0 - core router stops
168
+  *                    1 - core router relay statelessly
169
+  */
170
+int t_on_request_received( struct sip_msg  *p_msg , unsigned int ip, unsigned int port) ;
171
+
172
+
173
+
174
+
175
+/*  This function is called whenever a request for our module is received; we need to register
176
+  *  this function on module initialization;
177
+  *  Returns :   0 - core router stops
178
+  *                    1 - core router relay statelessly
179
+  */
180
+int t_on_request_received_uri( struct sip_msg  *p_msg ) ;
181
+
182
+
183
+
184
+
165 185
 /* returns 1 if everything was OK or -1 for error
166 186
 */
167 187
 int t_release_transaction( struct sip_msg* );
... ...
@@ -202,6 +223,7 @@ int t_put_on_wait(  struct cell  *Trans  );
202 202
 int relay_lowest_reply_upstream( struct cell *Trans , struct sip_msg *p_msg );
203 203
 int push_reply_from_uac_to_uas( struct cell* Trans , unsigned int );
204 204
 int add_branch_label( struct cell *Trans, struct sip_msg *p_msg , int branch );
205
+int get_ip_and_port_from_uri( struct sip_msg* p_msg , unsigned int *param_ip, unsigned int *param_port);
205 206
 
206 207
 void retransmission_handler( void *);
207 208
 void final_response_handler( void *);
... ...
@@ -12,6 +12,13 @@
12 12
 #include "t_funcs.h"
13 13
 #include "config.h"
14 14
 
15
+
16
+#define EQ_LEN(_hf) (t_msg->_hf->body.len==p_msg->_hf->body.len)
17
+#define EQ_STR(_hf) (memcmp(t_msg->_hf->body.s, p_msg->_hf->body.s, \
18
+		p_msg->_hf->body.len)==0)
19
+
20
+
21
+
15 22
 static int reverse_hex2int( char *c, int len )
16 23
 {
17 24
 	char *pc;
... ...
@@ -63,21 +70,19 @@ int t_lookup_request( struct sip_msg* p_msg )
63 63
    unsigned int  isACK;
64 64
    struct sip_msg	*t_msg;
65 65
 
66
-   DBG("t_lookup_request: start searching\n");
67
-
68 66
    /* parse all*/
69 67
    if (check_transaction_quadruple(p_msg)==0)
70 68
    {
71 69
       LOG(L_ERR, "ERROR: TM module: t_lookup_request: too few headers\n");
72 70
       T=0;
73
-	  /* stop processing */
71
+      /* stop processing */
74 72
       return 0;
75 73
    }
76 74
 
77 75
    /* start searching into the table */
78 76
    hash_index = hash( p_msg->callid->body , get_cseq(p_msg)->number ) ;
79 77
    isACK = p_msg->REQ_METHOD==METHOD_ACK;
80
-   DBG("t_lookup_request: continue searching;  hash=%d, isACK=%d\n",hash_index,isACK);
78
+   DBG("t_lookup_request: start searching:  hash=%d, isACK=%d\n",hash_index,isACK);
81 79
 
82 80
    /* lock the hole entry*/
83 81
    lock( hash_table->entrys[hash_index].mutex );
... ...
@@ -87,37 +92,73 @@ int t_lookup_request( struct sip_msg* p_msg )
87 87
    tmp_cell = 0;
88 88
    while( p_cell )
89 89
    {
90
+/*
90 91
 		int abba;
91 92
 
92 93
 		t_msg = p_cell->inbound_request;
93 94
 
94
-#define EQ_LEN(_hf) (t_msg->_hf->body.len==p_msg->_hf->body.len)
95
-#define EQ_STR(_hf) (memcmp(t_msg->_hf->body.s, p_msg->_hf->body.s, \
96
-		p_msg->_hf->body.len)==0)
97 95
 
98 96
 
99 97
 		if ( EQ_LEN(from) && EQ_LEN(callid) &&
100 98
 		  EQ_STR(callid) && EQ_STR(callid) &&
101 99
 		  /* we compare only numerical parts of CSEQ ...
102
-		     the method name should be the same as in first line */
103
-		  memcmp( get_cseq(t_msg)->number.s , get_cseq(p_msg)->number.s , 
100
+		     the method name should be the same as in first line
101
+		  memcmp( get_cseq(t_msg)->number.s , get_cseq(p_msg)->number.s ,
104 102
 				get_cseq(p_msg)->number.len ) ==0 )
105 103
 		{
106 104
 			if (!isACK) {
107 105
 				if (t_msg->REQ_METHOD == p_msg->REQ_METHOD &&
108 106
 					EQ_LEN(to) && EQ_STR(to))
109 107
 					goto found;
110
-			} else { /* ACK */
108
+			} else { /* ACK
111 109
 				if (t_msg->REQ_METHOD == METHOD_INVITE  &&
112 110
 					//p_cell->tag &&  p_cell->tag->len==p_msg->tag->body.len &&
113
-            		//if ( /*tag*/ memcmp( p_cell->tag->s , p_msg->tag->body.s , 
111
+            		//if ( /*tag memcmp( p_cell->tag->s , p_msg->tag->body.s ,
114 112
 					// p_msg->tag->body.len ) ==0 )
115 113
 					EQ_STR( to ) ) {
116 114
 					goto found;
117 115
 				}
118
-			} /* ACK */
119
-		} /* common HFs equal */
116
+			} /* ACK
117
+		} /* common HFs equal
118
+*/
119
+     t_msg = p_cell->inbound_request;
120 120
 
121
+      /* is it the wanted transaction ? */
122
+      if ( !isACK )
123
+      { /* is not an ACK request */
124
+         /* first only the length are checked */
125
+         if ( /*from length*/ EQ_LEN(from) )
126
+            if ( /*to length*/ EQ_LEN(to) )
127
+               if ( /*callid length*/ EQ_LEN(callid) )
128
+                  if ( /*cseq length*/ EQ_LEN(cseq) )
129
+                     /* so far the lengths are the same -> let's check the contents */
130
+                        if ( /*from*/ EQ_STR(from) )
131
+                           if ( /*to*/ EQ_STR(to) )
132
+                               if ( /*callid*/ EQ_STR(callid) )
133
+                                  if ( /*cseq*/ EQ_STR(cseq) )
134
+                                     { /* WE FOUND THE GOLDEN EGG !!!! */
135
+                                        goto found;
136
+                                     }
137
+      }
138
+      else
139
+      { /* it's a ACK request*/
140
+         /* first only the length are checked */
141
+         if ( /*from length*/ EQ_LEN(from) )
142
+            //if ( /*to length*/ p_cell->inbound_request->to->body.len == p_msg->to->body.len )
143
+               if ( /*callid length*/ EQ_LEN(callid) )
144
+                  if ( /*cseq_nr length*/ get_cseq(t_msg)->number.len == get_cseq(p_msg)->number.len )
145
+                      if ( /*cseq_method type*/ t_msg->first_line.u.request.method_value == METHOD_INVITE  )
146
+                         //if ( /*tag length*/ p_cell->tag &&  p_cell->tag->len==p_msg->tag->body.len )
147
+                            /* so far the lengths are the same -> let's check the contents */
148
+                            if ( /*from*/ EQ_STR(from) )
149
+                               //if ( /*to*/ !memcmp( p_cell->inbound_request->to->body.s , p_msg->to->body.s , p_msg->to->body.len)  )
150
+                                  //if ( /*tag*/ !memcmp( p_cell->tag->s , p_msg->tag->body.s , p_msg->tag->body.len ) )
151
+                                     if ( /*callid*/ !memcmp( t_msg->callid->body.s , p_msg->callid->body.s , p_msg->callid->body.len ) )
152
+                                        if ( /*cseq_nr*/ !memcmp( get_cseq(t_msg)->number.s , get_cseq(p_msg)->number.s , get_cseq(p_msg)->number.len ) )
153
+                                           { /* WE FOUND THE GOLDEN EGG !!!! */
154
+                                              goto found;
155
+                                           }
156
+      }
121 157
       /* next transaction */
122 158
       tmp_cell = p_cell;
123 159
       p_cell = p_cell->next_cell;
... ...
@@ -130,13 +171,12 @@ int t_lookup_request( struct sip_msg* p_msg )
130 130
    return -1;
131 131
 
132 132
 found:
133
-	T=p_cell;
134
-	/* ref_T( T ); */
135
-	T_REF( T );
136
-	DBG("DEBUG:XXXXXXXXXXXXXXXXXXXXX t_lookup_request: "
137
-			"transaction found ( T=%p , ref=%x)\n",T,T->ref_bitmap);
138
-	unlock( hash_table->entrys[hash_index].mutex );
139
-	return 1;
133
+   T=p_cell;
134
+   T_REF( T );
135
+   DBG("DEBUG:XXXXXXXXXXXXXXXXXXXXX t_lookup_request: "
136
+                   "transaction found ( T=%p , ref=%x)\n",T,T->ref_bitmap);
137
+   unlock( hash_table->entrys[hash_index].mutex );
138
+   return 1;
140 139
 }
141 140
 
142 141
 
... ...
@@ -328,21 +368,20 @@ int t_check( struct sip_msg* p_msg , int *param_branch)
328 328
 	if ( p_msg->id != global_msg_id || T==T_UNDEFINED )
329 329
 	{
330 330
 		global_msg_id = p_msg->id;
331
-		/* if ( T && T!=T_UNDEFINED ) unref_T(T); */
332
-      		T = T_UNDEFINED;
331
+		T = T_UNDEFINED;
333 332
 		/* transaction lookup */
334 333
 		if ( p_msg->first_line.type==SIP_REQUEST ) {
335 334
 
336
-   			/* force parsing all the needed headers*/
337
-   			if (parse_headers(p_msg, HDR_EOH )==-1)
338
-    				return -1;
339
-         		t_lookup_request( p_msg );
335
+			/* force parsing all the needed headers*/
336
+			if (parse_headers(p_msg, HDR_EOH )==-1)
337
+				return -1;
338
+		t_lookup_request( p_msg );
340 339
 	 	} else {
341 340
 		 	if ( parse_headers(p_msg, HDR_VIA1|HDR_VIA2|HDR_TO|HDR_CSEQ )==-1 ||
342
-        			!p_msg->via1 || !p_msg->via2 || !p_msg->to || !p_msg->cseq )
343
-    			return -1;
344
-         		t_reply_matching( p_msg , ((param_branch!=0)?(param_branch):(&local_branch)) );
345
-	 	}
341
+			!p_msg->via1 || !p_msg->via2 || !p_msg->to || !p_msg->cseq )
342
+			return -1;
343
+		t_reply_matching( p_msg , ((param_branch!=0)?(param_branch):(&local_branch)) );
344
+		}
346 345
 #		ifdef EXTRA_DEBUG
347 346
 		if ( T && T!=T_UNDEFINED && T->damocles) {
348 347
 			LOG( L_ERR, "ERROR: transaction %p scheduled for deletion "
... ...
@@ -350,10 +389,9 @@ int t_check( struct sip_msg* p_msg , int *param_branch)
350 350
 			abort();
351 351
 		}
352 352
 #		endif
353
-   		DBG("DEBUG: t_check : msg id=%d , global msg id=%d , T on finish=%p\n", 
353
+		DBG("DEBUG: t_check : msg id=%d , global msg id=%d , T on finish=%p\n",
354 354
 			p_msg->id,global_msg_id,T);
355
-
356
-   	} else {
355
+	} else {
357 356
 		if (T)
358 357
 			DBG("DEBUG: t_check: T alredy found!\n");
359 358
 		else
... ...
@@ -26,9 +26,12 @@ static int w_t_send_reply(struct sip_msg* msg, char* str, char* str2);
26 26
 static int w_t_forward(struct sip_msg* msg, char* str, char* str2);
27 27
 static int w_t_forward_def(struct sip_msg* msg, char* str, char* str2);
28 28
 static int w_t_release(struct sip_msg* msg, char* str, char* str2);
29
+static int w_t_on_request_received(struct sip_msg* msg, char* str, char* str2);
30
+static int w_t_on_request_received_uri(struct sip_msg* msg, char* str, char* str2);
29 31
 static int fixup_t_forward(void** param, int param_no);
30 32
 static int fixup_t_forward_def(void** param, int param_no);
31 33
 static int fixup_t_send_reply(void** param, int param_no);
34
+//static int fixup_t_on_request_received(void** param, int param_no);
32 35
 
33 36
 static void w_onbreak(struct sip_msg* msg) { t_unref(msg, NULL, NULL); }
34 37
 
... ...
@@ -42,7 +45,9 @@ static struct module_exports nm_exports= {
42 42
 				"t_send_reply",
43 43
 				"t_retransmit_reply",
44 44
 				"t_release",
45
-				"t_unref"
45
+				"t_unref",
46
+				"t_on_request_receive_uri",
47
+				"t_on_request_receive_to"
46 48
 			},
47 49
 	(cmd_function[]){
48 50
 					t_add_transaction,
... ...
@@ -53,7 +58,9 @@ static struct module_exports nm_exports= {
53 53
 					w_t_send_reply,
54 54
 					t_retransmit_reply,
55 55
 					w_t_release,
56
-					t_unref
56
+					t_unref,
57
+					w_t_on_request_received_uri,
58
+					w_t_on_request_received
57 59
 					},
58 60
 	(int[]){
59 61
 				0,
... ...
@@ -64,7 +71,9 @@ static struct module_exports nm_exports= {
64 64
 				2,
65 65
 				0,
66 66
 				0,
67
-				0
67
+				0,
68
+				0,
69
+				2
68 70
 			},
69 71
 	(fixup_function[]){
70 72
 				0,
... ...
@@ -76,8 +85,10 @@ static struct module_exports nm_exports= {
76 76
 				0,
77 77
 				0,
78 78
 				0,
79
+				0,
80
+				fixup_t_forward
79 81
 		},
80
-	9,
82
+	11,
81 83
 	(response_function) t_on_reply_received,
82 84
 	(destroy_function) tm_shutdown,
83 85
 	w_onbreak
... ...
@@ -237,3 +248,12 @@ static int w_t_release(struct sip_msg* msg, char* str, char* str2)
237 237
 	return t_release_transaction(msg);
238 238
 }
239 239
 
240
+static int w_t_on_request_received(struct sip_msg* msg, char* str, char* str2)
241
+{
242
+	return t_on_request_received(msg, (unsigned int) str, (unsigned int) str2);
243
+}
244
+
245
+static int w_t_on_request_received_uri(struct sip_msg* msg, char* str, char* str2)
246
+{
247
+	return t_on_request_received_uri(msg);
248
+}
... ...
@@ -154,6 +154,7 @@ error:
154 154
 
155 155
 
156 156
 
157
+
157 158
 /* same as add_proxy, but it doesn't add the proxy to the list*/
158 159
 struct proxy_l* mk_proxy(char* name, unsigned short port)
159 160
 {
... ...
@@ -164,7 +165,7 @@ struct proxy_l* mk_proxy(char* name, unsigned short port)
164 164
 	unsigned int ip;
165 165
 	int len;
166 166
 #endif
167
-	
167
+
168 168
 	p=(struct proxy_l*) malloc(sizeof(struct proxy_l));
169 169
 	if (p==0){
170 170
 		LOG(L_CRIT, "ERROR: mk_proxy: memory allocation failure\n");
... ...
@@ -204,12 +205,12 @@ struct proxy_l* mk_proxy(char* name, unsigned short port)
204 204
 		}
205 205
 		memcpy(p->host.h_addr_list[0], (char*)&ip, 4);
206 206
 		p->host.h_addr_list[0][4]=0;
207
-		
207
+
208 208
 		return p;
209 209
 	}
210 210
 #endif
211 211
 	/* fail over to normal lookup */
212
-	
212
+
213 213
 	he=gethostbyname(name);
214 214
 	if (he==0){
215 215
 		LOG(L_CRIT, "ERROR: mk_proxy: could not resolve hostname:"
... ...
@@ -229,6 +230,44 @@ error:
229 229
 
230 230
 
231 231
 
232
+/* same as mk_proxy, but get the host as an ip*/
233
+struct proxy_l* mk_proxy_from_ip(unsigned int ip, unsigned short port)
234
+{
235
+	struct proxy_l* p;
236
+	struct hostent* he;
237
+	int err;
238
+
239
+	p=(struct proxy_l*) malloc(sizeof(struct proxy_l));
240
+	if (p==0){
241
+		LOG(L_CRIT, "ERROR: mk_proxy_from_ip: memory allocation failure\n");
242
+		goto error;
243
+	}
244
+	memset(p,0,sizeof(struct proxy_l));
245
+
246
+	p->port=port;
247
+	p->host.h_addrtype=AF_INET;
248
+	p->host.h_length=4;
249
+	p->host.h_addr_list=malloc(2*sizeof(char*));
250
+	if (p->host.h_addr_list==0) goto error;
251
+	p->host.h_addr_list[1]=0;
252
+	p->host.h_addr_list[0]=malloc(5);
253
+	if (p->host.h_addr_list[0]==0){
254
+		free(p->host.h_addr_list);
255
+		goto error;
256
+	}
257
+
258
+	memcpy(p->host.h_addr_list[0], (char*)&ip, 4);
259
+	p->host.h_addr_list[0][4]=0;
260
+
261
+	return p;
262
+
263
+error:
264
+	return 0;
265
+}
266
+
267
+
268
+
269
+
232 270
 void free_proxy(struct proxy_l* p)
233 271
 {
234 272
 	if (p) free_hostent(&p->host);
... ...
@@ -29,6 +29,7 @@ extern struct proxy_l* proxies;
29 29
 
30 30
 struct proxy_l* add_proxy(char* name, unsigned short port);
31 31
 struct proxy_l* mk_proxy(char* name, unsigned short port);
32
+struct proxy_l* mk_proxy_from_ip(unsigned int ip, unsigned short port);
32 33
 void free_proxy(struct proxy_l* p);
33 34
 
34 35
 
... ...
@@ -4,25 +4,25 @@
4 4
 # $ID: $
5 5
 #
6 6
 
7
-debug=1          # debug level (cmd line: -dddddddddd)
8
-fork=yes          # (cmd. line: -D)
9
-#fork=no
7
+debug=9          # debug level (cmd line: -dddddddddd)
8
+#fork=yes          # (cmd. line: -D)
9
+fork=no
10 10
 #log_stderror=yes # (cmd line: -E)
11
-log_stderror=no	# (cmd line: -E)
11
+log_stderror=yes	# (cmd line: -E)
12 12
 
13 13
 
14
-children=8
15
-check_via=yes     # (cmd. line: -v)
16
-dns=on           # (cmd. line: -r)
17
-rev_dns=yes      # (cmd. line: -R)
18
-port=5080
14
+#children=8
15
+check_via=no     # (cmd. line: -v)
16
+#dns=on           # (cmd. line: -r)
17
+#rev_dns=yes      # (cmd. line: -R)
18
+#port=5080
19 19
 #listen=127.0.0.1
20
-listen=195.37.77.101
20
+#listen=195.37.77.101
21 21
 loop_checks=0
22 22
 # for more info: sip_router -h
23 23
 
24 24
 #modules
25
-loadmodule "modules/print/print.so"
25
+#loadmodule "modules/print/print.so"
26 26
 #loadmodule "modules/tm/tm.so"
27 27
 
28 28
 #route[0]{