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 36
 		return;
36 37
 	}
37 38
 	timeout = to_table[ list_id ];
38
-	add_to_tail_of_timer_list( &(hash_table->timers[ list_id ]), 
39
+	add_to_tail_of_timer_list( &(hash_table->timers[ list_id ]),
39 40
 		new_tl,get_ticks()+timeout);
40 41
 }
41 42
 
... ...
@@ -209,14 +210,14 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
209 210
 		return -1;
210 211
 	}
211 212
 
212
-	/*if it's an ACK and the status is not final or is final, but error the 
213
-     ACK is not forwarded*/
213
+	/*if it's an ACK and the status is not final or is final, but error the
214
+	ACK is not forwarded*/
214 215
 	if ( p_msg->REQ_METHOD==METHOD_ACK  && (T->status/100)!=2 ) {
215 216
 		DBG("DEBUG: t_forward: local ACK; don't forward\n");
216 217
 		return 1;
217 218
 	}
218 219
 
219
-	/* if it's forwarded for the first time ; else the request is retransmited 
220
+	/* if it's forwarded for the first time ; else the request is retransmited
220 221
 	 * from the transaction buffer
221 222
 	 * when forwarding an ACK, this condition will br all the time false because
222 223
 	 * 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 228
 		if ( p_msg->REQ_METHOD==METHOD_CANCEL  )
228 229
 		{
229 230
 			DBG("DEBUG: t_forward: it's CANCEL\n");
230
-			/* find original cancelled transaction; if found, use its 
231
+			/* find original cancelled transaction; if found, use its
231 232
 			   next-hops; otherwise use those passed by script */
232 233
 			if ( T->T_canceled==T_UNDEFINED )
233 234
 				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 268
 		/* allocates a new retrans_buff for the outbound request */
268 269
 		DBG("DEBUG: t_forward: building outbound request\n");
269 270
 		shm_lock();
270
-		T->outbound_request[branch] = rb = 
271
+		T->outbound_request[branch] = rb =
271 272
 			(struct retrans_buff*)shm_malloc_unsafe( sizeof(struct retrans_buff)  );
272 273
 		if (!rb)
273 274
 		{
... ...
@@ -277,7 +278,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
277 278
 		}
278 279
 		shbuf = (char *) shm_malloc_unsafe( len );
279 280
 		if (!shbuf)
280
-		{ 
281
+		{
281 282
 			LOG(L_ERR, "ERROR: t_forward: out of shmem buffer\n");
282 283
 			shm_unlock();
283 284
 			goto error;
... ...
@@ -305,11 +306,11 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
305 306
 
306 307
 	/* if we are forwarding an ACK*/
307 308
 	if (  p_msg->REQ_METHOD==METHOD_ACK &&
308
-		T->relaied_reply_branch>=0 && 
309
+		T->relaied_reply_branch>=0 &&
309 310
 		T->relaied_reply_branch<=T->nr_of_outgoings)
310 311
 	{
311 312
 		DBG("DEBUG: t_forward: forwarding ACK [%d]\n",T->relaied_reply_branch);
312
-		t_build_and_send_ACK( T, branch , 
313
+		t_build_and_send_ACK( T, branch ,
313 314
 			T->inbound_response[T->relaied_reply_branch] );
314 315
 		T->inbound_request_isACKed = 1;
315 316
 		return 1;
... ...
@@ -356,60 +357,13 @@ error:
356 357
  */
357 358
 int t_forward_uri( struct sip_msg* p_msg, char* foo, char* bar  )
358 359
 {
359
-   struct hostent  *nhost;
360 360
    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 361
 
391
-   if ( !nhost )
362
+   if ( get_ip_and_port_from_uri( p_msg , &ip, &port)<0 )
392 363
    {
393
-      LOG(L_ERR, "ERROR: t_forward_uri: cannot resolve host\n");
364
+      LOG( L_ERR , "ERROR: t_forward_uri: unable to extarct ip and port from uri!\n" );
394 365
       return -1;
395 366
    }
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 367
 
414 368
    return t_forward( p_msg , ip , port );
415 369
 }
... ...
@@ -445,7 +399,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
445 399
 
446 400
 	/* we were not able to process the response due to memory
447 401
 	   shortage; simply drop it; hopefuly, we will have more
448
-           memory on the next try 
402
+           memory on the next try
449 403
 	*/
450 404
 	msg_status=p_msg->REPLY_STATUS;
451 405
 	msg_class=REPLY_CLASS(p_msg);
... ...
@@ -464,7 +418,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
464 418
 	/* stop final response timer only if I got a final response */
465 419
 	if ( msg_class>1 )
466 420
 		reset_timer( hash_table, &(rb->fr_timer));
467
-   	/* if a got the first prov. response for an INVITE -> 
421
+   	/* if a got the first prov. response for an INVITE ->
468 422
 	   change FR_TIME_OUT to INV_FR_TIME_UT */
469 423
 	if (!T->inbound_response[branch] && msg_class==1
470 424
 	 && T->inbound_request->REQ_METHOD==METHOD_INVITE )
... ...
@@ -500,7 +454,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
500 454
 		return 0;
501 455
 	}
502 456
 
503
-   	/* restart retransmission if provisional response came for a non_INVITE -> 
457
+   	/* restart retransmission if provisional response came for a non_INVITE ->
504 458
 		retrasmit at RT_T2*/
505 459
 	if ( msg_class==1 && T->inbound_request->REQ_METHOD!=METHOD_INVITE )
506 460
 	{
... ...
@@ -520,7 +474,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
520 474
 		if ( t_all_final(T) && relay_lowest_reply_upstream( T , p_msg )==-1 && clone )
521 475
 			goto error;
522 476
 	} else {
523
-		if (push_reply_from_uac_to_uas( T , branch )==-1 && clone ) 
477
+		if (push_reply_from_uac_to_uas( T , branch )==-1 && clone )
524 478
 			goto error;
525 479
    	}
526 480
 
... ...
@@ -539,6 +493,87 @@ error:
539 493
 }
540 494
 
541 495
 
496
+int t_on_request_received( struct sip_msg  *p_msg , unsigned int ip , unsigned int port)
497
+{
498
+	if ( t_check( p_msg , 0 ) )
499
+	{
500
+		if ( p_msg->first_line.u.request.method_value==METHOD_ACK )
501
+		{
502
+			LOG( L_INFO , "SER: ACK received -> t_release\n");
503
+			if ( !t_forward( p_msg , ip , port ) )
504
+			{
505
+				LOG( L_WARN, "SER: WARNING: bad forward\n");
506
+			}
507
+			if ( !t_release_transaction( p_msg ) )
508
+			{
509
+				LOG( L_WARN ,"SER: WARNING: bad t_release\n");
510
+			}
511
+		}
512
+		else
513
+		{
514
+			if ( !t_retransmit_reply( p_msg , 0, 0) )
515
+			{
516
+				LOG( L_WARN, "SER: WARNING: bad t_retransmit_reply\n");
517
+			}
518
+			LOG( L_INFO, "SER: yet another annoying retranmission\n");
519
+		}
520
+		t_unref( p_msg,0,0 );
521
+	} else {
522
+		if ( p_msg->first_line.u.request.method_value==METHOD_ACK )
523
+		{
524
+			LOG( L_INFO , "SER: forwarding ACK  statelessly\n");
525
+			/* no established transaction ... forward ACK just statelessly*/
526
+			forward_request( p_msg , mk_proxy_from_ip(ip,port) );
527
+		}
528
+		else
529
+		{
530
+			/* establish transaction*/
531
+			if ( !t_add_transaction(p_msg,0,0) )
532
+			{
533
+				LOG( L_ERR , "ERROR in ser: t_add_transaction\n");
534
+			}
535
+			/* reply */
536
+			if ( p_msg->first_line.u.request.method_value==METHOD_CANCEL)
537
+			{
538
+				LOG( L_INFO, "SER: new CANCEL\n");
539
+				if ( !t_send_reply( p_msg , 200, "glad to cancel") )
540
+				{
541
+					LOG( L_ERR ,"SER:ERROR: t_send_reply\n");
542
+				}
543
+			} else {
544
+				LOG( L_INFO, "SER: new transaction\n");
545
+				if ( !t_send_reply( p_msg , 100 , "trying -- your call is important to us") )
546
+				{
547
+					LOG( L_ERR, "SER: ERROR: t_send_reply (100)\n");
548
+				}
549
+			}
550
+			if ( !t_forward( p_msg, ip, port ) )
551
+			{
552
+				LOG( L_ERR , "SER:ERROR: t_forward \n");
553
+			}
554
+			t_unref( p_msg , 0 , 0);
555
+		}
556
+	}
557
+
558
+}
559
+
560
+
561
+
562
+
563
+int t_on_request_received_uri( struct sip_msg  *p_msg )
564
+{
565
+   unsigned int     ip, port;
566
+
567
+   if ( get_ip_and_port_from_uri( p_msg , &ip, &port)<0 )
568
+   {
569
+      LOG( L_ERR , "ERROR: t_on_request_received_uri: unable to extract ip and port from uri!\n" );
570
+      return -1;
571
+   }
572
+
573
+   return t_on_request_received( p_msg , ip , port );
574
+}
575
+
576
+
542 577
 
543 578
 
544 579
 /*   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 613
    return -1;
579 614
 }
580 615
 
616
+
617
+
618
+
581 619
 int t_unref( struct sip_msg* p_msg, char* foo, char* bar )
582 620
 {
583 621
 	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 726
 	if ( ! rb->retr_buffer ) {
689 727
 		/*init retrans buffer*/
690 728
 		memset( rb , 0 , sizeof (struct retrans_buff) );
691
-		if (update_sock_struct_from_via(  &(rb->to),  
729
+		if (update_sock_struct_from_via(  &(rb->to),
692 730
 			trans->inbound_response[branch]->via2 )==-1) {
693 731
 				LOG(L_ERR, "ERROR: push_reply_from_uac_to_uas: "
694 732
 					"cannot lookup reply dst: %s\n",
... ...
@@ -714,8 +752,7 @@ int push_reply_from_uac_to_uas( struct cell* trans , unsigned int branch )
714 752
 	}
715 753
 
716 754
 	/* if this is a first reply (?100), longer replies will probably follow;
717
-       try avoiding shm_resize by higher buffer size
718
-    */
755
+	try avoiding shm_resize by higher buffer size */
719 756
 	buf_len = rb->retr_buffer ? len : len + REPLY_OVERBUFFER_LEN;
720 757
 	if (! (rb->retr_buffer = (char*)shm_resize( rb->retr_buffer, buf_len )))
721 758
 	{
... ...
@@ -723,22 +760,22 @@ int push_reply_from_uac_to_uas( struct cell* trans , unsigned int branch )
723 760
 		goto error1;
724 761
 	}
725 762
 	rb->bufflen = len ;
726
-   	memcpy( rb->retr_buffer , buf , len );
727
-   	free( buf ) ;
763
+	memcpy( rb->retr_buffer , buf , len );
764
+	free( buf ) ;
728 765
 
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;
766
+	/* update the status*/
767
+	trans->status = trans->inbound_response[branch]->REPLY_STATUS;
768
+	if ( trans->inbound_response[branch]->REPLY_STATUS>=200 &&
769
+	trans->relaied_reply_branch==-1 )
770
+		trans->relaied_reply_branch = branch;
734 771
 
735 772
 	/* start/stops the proper timers*/
736 773
 	t_update_timers_after_sending_reply( rb );
737 774
 
738
-   	/*send the reply*/
739
-   	/* t_retransmit_reply( trans->inbound_response[branch], 0 , 0 ); */
775
+	/*send the reply*/
776
+	/* t_retransmit_reply( trans->inbound_response[branch], 0 , 0 ); */
740 777
 	SEND_BUFFER( rb );
741
-   	return 1;
778
+	return 1;
742 779
 
743 780
 error1:
744 781
 	free( buf );
... ...
@@ -763,13 +800,13 @@ int t_all_final( struct cell *Trans )
763 800
 {
764 801
    unsigned int i;
765 802
 
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;
803
+	for( i=0 ; i<Trans->nr_of_outgoings ; i++  )
804
+		if (  !Trans->inbound_response[i] ||
805
+		Trans->inbound_response[i]->REPLY_STATUS<=200 )
806
+			return 0;
770 807
 
771
-  DBG("DEBUG: t_all_final: final state!!!!:)) \n");
772
-  return 1;
808
+	DBG("DEBUG: t_all_final: final state!!!!:)) \n");
809
+	return 1;
773 810
 }
774 811
 
775 812
 
... ...
@@ -810,7 +847,7 @@ int t_update_timers_after_sending_reply( struct retrans_buff *rb )
810 847
 {
811 848
 	struct cell *Trans = rb->my_T;
812 849
 
813
-	/* make sure that if we send something final upstream, everything else 
850
+	/* make sure that if we send something final upstream, everything else
814 851
 	   will be cancelled */
815 852
 	if (Trans->status>=300 && Trans->inbound_request->REQ_METHOD==METHOD_INVITE )
816 853
 	{
... ...
@@ -819,13 +856,13 @@ int t_update_timers_after_sending_reply( struct retrans_buff *rb )
819 856
 		set_timer( hash_table, &(rb->fr_timer), FR_TIMER_LIST );
820 857
    	} else if ( Trans->inbound_request->REQ_METHOD==METHOD_CANCEL ) {
821 858
 		if ( Trans->T_canceled==T_UNDEFINED )
822
-			Trans->T_canceled = t_lookupOriginalT( hash_table , 
859
+			Trans->T_canceled = t_lookupOriginalT( hash_table ,
823 860
 				Trans->inbound_request );
824 861
       		if ( Trans->T_canceled==T_NULL )
825 862
             		return 1;
826 863
       		Trans->T_canceled->T_canceler = Trans;
827 864
      		/* put CANCEL transaction on wait only if canceled transaction already
828
-        	   is in final status and there is nothing to cancel; 
865
+        	   is in final status and there is nothing to cancel;
829 866
      		*/
830 867
      		if ( Trans->T_canceled->status>=200)
831 868
             		t_put_on_wait( Trans );
... ...
@@ -837,9 +874,9 @@ int t_update_timers_after_sending_reply( struct retrans_buff *rb )
837 874
 
838 875
 
839 876
 
840
-/* Checks if the new reply (with new_code status) should be sent or not 
877
+/* Checks if the new reply (with new_code status) should be sent or not
841 878
  *  based on the current
842
-  * transactin status. 
879
+  * transactin status.
843 880
   * Returns 1 - the response can be sent
844 881
   *         0 - is not indicated to sent
845 882
   */
... ...
@@ -859,21 +896,21 @@ int t_should_relay_response( struct cell *Trans , int new_code )
859 896
 		if (new_code!=100) { /* all but "100 trying" */
860 897
 			DBG("DBG: t_should_relay: !=100 -> relay\n");
861 898
 			return 1;
862
-		} 
899
+		}
863 900
 	}
864 901
 	DBG("DBG: t_should_relay: not to be relayed\n");
865 902
 	return 0;
866 903
 
867 904
 
868 905
 /*
869
-   // have we already sent something? 
906
+   // have we already sent something?
870 907
    if ( !Trans->outbound_response.retr_buffer )
871 908
    {
872 909
       DBG("DEBUG: t_should_relay_response: %d response relayed (no previous response sent)\n",new_code);
873 910
       return 1;
874 911
    }
875 912
 
876
-   // have we sent a final response? 
913
+   // have we sent a final response?
877 914
    if ( (T_code/100)>1 )
878 915
    {  //final response was sent
879 916
       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 920
       }
884 921
    }
885 922
    else
886
-   { // provisional response was sent 
923
+   { // provisional response was sent
887 924
       if ( new_code>T_code )
888 925
       {
889 926
          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 1152
 }
1116 1153
 
1117 1154
 
1155
+/* Returns  -1 = error
1156
+                    0 = OK
1157
+*/
1158
+int get_ip_and_port_from_uri( struct sip_msg* p_msg , unsigned int *param_ip, unsigned int *param_port)
1159
+{
1160
+   struct hostent  *nhost;
1161
+   unsigned int     ip, port;
1162
+   struct sip_uri    parsed_uri;
1163
+   str                      uri;
1164
+   int                      err;
1165
+
1166
+   /* the original uri has been changed? */
1167
+   if (p_msg->new_uri.s==0 || p_msg->new_uri.len==0)
1168
+     uri = p_msg->first_line.u.request.uri;
1169
+   else
1170
+     uri = p_msg->new_uri;
1171
+
1172
+   /* parsing the request uri in order to get host and port */
1173
+   if (parse_uri( uri.s , uri.len , &parsed_uri )<0)
1174
+   {
1175
+        LOG(L_ERR, "ERROR: get_ip_and_port_from_uri: unable to parse destination uri\n");
1176
+        return  -1;
1177
+   }
1178
+
1179
+   /* getting host address*/
1180
+   nhost = gethostbyname( parsed_uri.host.s );
1181
+
1182
+   if ( !nhost )
1183
+   {
1184
+      LOG(L_ERR, "ERROR: get_ip_and_port_from_uri: cannot resolve host\n");
1185
+      return -1;
1186
+   }
1187
+   memcpy(&ip, nhost->h_addr_list[0], sizeof(unsigned int));
1188
+
1189
+   /* getting the port */
1190
+   if ( parsed_uri.port.s==0 || parsed_uri.port.len==0 )
1191
+      port = SIP_PORT;
1192
+   else
1193
+   {
1194
+       port = str2s( parsed_uri.port.s , parsed_uri.port.len , &err );
1195
+       if ( err<0 )
1196
+       {
1197
+           LOG(L_ERR, "ERROR: get_ip_and_port_from_uri: converting port from str to int failed; using default SIP port\n");
1198
+           port = SIP_PORT;
1199
+       }
1200
+   }
1201
+   port = htons( port );
1202
+
1203
+   free_uri( &parsed_uri );
1204
+
1205
+   *param_ip = ip;
1206
+   *param_port = port;
1207
+   return 0;
1208
+}
1209
+
1210
+
1211
+
1212
+
1213
+
1214
+
1118 1215
 /*---------------------TIMEOUT HANDLERS--------------------------*/
1119 1216
 
1120 1217
 
... ...
@@ -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 163
 
163 164
 
164 165
 
166
+/*  This function is called whenever a request for our module is received; we need to register
167
+  *  this function on module initialization;
168
+  *  Returns :   0 - core router stops
169
+  *                    1 - core router relay statelessly
170
+  */
171
+int t_on_request_received( struct sip_msg  *p_msg , unsigned int ip, unsigned int port) ;
172
+
173
+
174
+
175
+
176
+/*  This function is called whenever a request for our module is received; we need to register
177
+  *  this function on module initialization;
178
+  *  Returns :   0 - core router stops
179
+  *                    1 - core router relay statelessly
180
+  */
181
+int t_on_request_received_uri( struct sip_msg  *p_msg ) ;
182
+
183
+
184
+
185
+
165 186
 /* returns 1 if everything was OK or -1 for error
166 187
 */
167 188
 int t_release_transaction( struct sip_msg* );
... ...
@@ -202,6 +223,7 @@ int t_put_on_wait(  struct cell  *Trans  );
202 223
 int relay_lowest_reply_upstream( struct cell *Trans , struct sip_msg *p_msg );
203 224
 int push_reply_from_uac_to_uas( struct cell* Trans , unsigned int );
204 225
 int add_branch_label( struct cell *Trans, struct sip_msg *p_msg , int branch );
226
+int get_ip_and_port_from_uri( struct sip_msg* p_msg , unsigned int *param_ip, unsigned int *param_port);
205 227
 
206 228
 void retransmission_handler( void *);
207 229
 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 70
    unsigned int  isACK;
64 71
    struct sip_msg	*t_msg;
65 72
 
66
-   DBG("t_lookup_request: start searching\n");
67
-
68 73
    /* parse all*/
69 74
    if (check_transaction_quadruple(p_msg)==0)
70 75
    {
71 76
       LOG(L_ERR, "ERROR: TM module: t_lookup_request: too few headers\n");
72 77
       T=0;
73
-	  /* stop processing */
78
+      /* stop processing */
74 79
       return 0;
75 80
    }
76 81
 
77 82
    /* start searching into the table */
78 83
    hash_index = hash( p_msg->callid->body , get_cseq(p_msg)->number ) ;
79 84
    isACK = p_msg->REQ_METHOD==METHOD_ACK;
80
-   DBG("t_lookup_request: continue searching;  hash=%d, isACK=%d\n",hash_index,isACK);
85
+   DBG("t_lookup_request: start searching:  hash=%d, isACK=%d\n",hash_index,isACK);
81 86
 
82 87
    /* lock the hole entry*/
83 88
    lock( hash_table->entrys[hash_index].mutex );
... ...
@@ -87,37 +92,73 @@ int t_lookup_request( struct sip_msg* p_msg )
87 92
    tmp_cell = 0;
88 93
    while( p_cell )
89 94
    {
95
+/*
90 96
 		int abba;
91 97
 
92 98
 		t_msg = p_cell->inbound_request;
93 99
 
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 100
 
98 101
 
99 102
 		if ( EQ_LEN(from) && EQ_LEN(callid) &&
100 103
 		  EQ_STR(callid) && EQ_STR(callid) &&
101 104
 		  /* 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 , 
105
+		     the method name should be the same as in first line
106
+		  memcmp( get_cseq(t_msg)->number.s , get_cseq(p_msg)->number.s ,
104 107
 				get_cseq(p_msg)->number.len ) ==0 )
105 108
 		{
106 109
 			if (!isACK) {
107 110
 				if (t_msg->REQ_METHOD == p_msg->REQ_METHOD &&
108 111
 					EQ_LEN(to) && EQ_STR(to))
109 112
 					goto found;
110
-			} else { /* ACK */
113
+			} else { /* ACK
111 114
 				if (t_msg->REQ_METHOD == METHOD_INVITE  &&
112 115
 					//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 , 
116
+            		//if ( /*tag memcmp( p_cell->tag->s , p_msg->tag->body.s ,
114 117
 					// p_msg->tag->body.len ) ==0 )
115 118
 					EQ_STR( to ) ) {
116 119
 					goto found;
117 120
 				}
118
-			} /* ACK */
119
-		} /* common HFs equal */
121
+			} /* ACK
122
+		} /* common HFs equal
123
+*/
124
+     t_msg = p_cell->inbound_request;
120 125
 
126
+      /* is it the wanted transaction ? */
127
+      if ( !isACK )
128
+      { /* is not an ACK request */
129
+         /* first only the length are checked */
130
+         if ( /*from length*/ EQ_LEN(from) )
131
+            if ( /*to length*/ EQ_LEN(to) )
132
+               if ( /*callid length*/ EQ_LEN(callid) )
133
+                  if ( /*cseq length*/ EQ_LEN(cseq) )
134
+                     /* so far the lengths are the same -> let's check the contents */
135
+                        if ( /*from*/ EQ_STR(from) )
136
+                           if ( /*to*/ EQ_STR(to) )
137
+                               if ( /*callid*/ EQ_STR(callid) )
138
+                                  if ( /*cseq*/ EQ_STR(cseq) )
139
+                                     { /* WE FOUND THE GOLDEN EGG !!!! */
140
+                                        goto found;
141
+                                     }
142
+      }
143
+      else
144
+      { /* it's a ACK request*/
145
+         /* first only the length are checked */
146
+         if ( /*from length*/ EQ_LEN(from) )
147
+            //if ( /*to length*/ p_cell->inbound_request->to->body.len == p_msg->to->body.len )
148
+               if ( /*callid length*/ EQ_LEN(callid) )
149
+                  if ( /*cseq_nr length*/ get_cseq(t_msg)->number.len == get_cseq(p_msg)->number.len )
150
+                      if ( /*cseq_method type*/ t_msg->first_line.u.request.method_value == METHOD_INVITE  )
151
+                         //if ( /*tag length*/ p_cell->tag &&  p_cell->tag->len==p_msg->tag->body.len )
152
+                            /* so far the lengths are the same -> let's check the contents */
153
+                            if ( /*from*/ EQ_STR(from) )
154
+                               //if ( /*to*/ !memcmp( p_cell->inbound_request->to->body.s , p_msg->to->body.s , p_msg->to->body.len)  )
155
+                                  //if ( /*tag*/ !memcmp( p_cell->tag->s , p_msg->tag->body.s , p_msg->tag->body.len ) )
156
+                                     if ( /*callid*/ !memcmp( t_msg->callid->body.s , p_msg->callid->body.s , p_msg->callid->body.len ) )
157
+                                        if ( /*cseq_nr*/ !memcmp( get_cseq(t_msg)->number.s , get_cseq(p_msg)->number.s , get_cseq(p_msg)->number.len ) )
158
+                                           { /* WE FOUND THE GOLDEN EGG !!!! */
159
+                                              goto found;
160
+                                           }
161
+      }
121 162
       /* next transaction */
122 163
       tmp_cell = p_cell;
123 164
       p_cell = p_cell->next_cell;
... ...
@@ -130,13 +171,12 @@ int t_lookup_request( struct sip_msg* p_msg )
130 171
    return -1;
131 172
 
132 173
 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;
174
+   T=p_cell;
175
+   T_REF( T );
176
+   DBG("DEBUG:XXXXXXXXXXXXXXXXXXXXX t_lookup_request: "
177
+                   "transaction found ( T=%p , ref=%x)\n",T,T->ref_bitmap);
178
+   unlock( hash_table->entrys[hash_index].mutex );
179
+   return 1;
140 180
 }
141 181
 
142 182
 
... ...
@@ -328,21 +368,20 @@ int t_check( struct sip_msg* p_msg , int *param_branch)
328 368
 	if ( p_msg->id != global_msg_id || T==T_UNDEFINED )
329 369
 	{
330 370
 		global_msg_id = p_msg->id;
331
-		/* if ( T && T!=T_UNDEFINED ) unref_T(T); */
332
-      		T = T_UNDEFINED;
371
+		T = T_UNDEFINED;
333 372
 		/* transaction lookup */
334 373
 		if ( p_msg->first_line.type==SIP_REQUEST ) {
335 374
 
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 );
375
+			/* force parsing all the needed headers*/
376
+			if (parse_headers(p_msg, HDR_EOH )==-1)
377
+				return -1;
378
+		t_lookup_request( p_msg );
340 379
 	 	} else {
341 380
 		 	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
-	 	}
381
+			!p_msg->via1 || !p_msg->via2 || !p_msg->to || !p_msg->cseq )
382
+			return -1;
383
+		t_reply_matching( p_msg , ((param_branch!=0)?(param_branch):(&local_branch)) );
384
+		}
346 385
 #		ifdef EXTRA_DEBUG
347 386
 		if ( T && T!=T_UNDEFINED && T->damocles) {
348 387
 			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 389
 			abort();
351 390
 		}
352 391
 #		endif
353
-   		DBG("DEBUG: t_check : msg id=%d , global msg id=%d , T on finish=%p\n", 
392
+		DBG("DEBUG: t_check : msg id=%d , global msg id=%d , T on finish=%p\n",
354 393
 			p_msg->id,global_msg_id,T);
355
-
356
-   	} else {
394
+	} else {
357 395
 		if (T)
358 396
 			DBG("DEBUG: t_check: T alredy found!\n");
359 397
 		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 45
 				"t_send_reply",
43 46
 				"t_retransmit_reply",
44 47
 				"t_release",
45
-				"t_unref"
48
+				"t_unref",
49
+				"t_on_request_receive_uri",
50
+				"t_on_request_receive_to"
46 51
 			},
47 52
 	(cmd_function[]){
48 53
 					t_add_transaction,
... ...
@@ -53,7 +58,9 @@ static struct module_exports nm_exports= {
53 58
 					w_t_send_reply,
54 59
 					t_retransmit_reply,
55 60
 					w_t_release,
56
-					t_unref
61
+					t_unref,
62
+					w_t_on_request_received_uri,
63
+					w_t_on_request_received
57 64
 					},
58 65
 	(int[]){
59 66
 				0,
... ...
@@ -64,7 +71,9 @@ static struct module_exports nm_exports= {
64 71
 				2,
65 72
 				0,
66 73
 				0,
67
-				0
74
+				0,
75
+				0,
76
+				2
68 77
 			},
69 78
 	(fixup_function[]){
70 79
 				0,
... ...
@@ -76,8 +85,10 @@ static struct module_exports nm_exports= {
76 85
 				0,
77 86
 				0,
78 87
 				0,
88
+				0,
89
+				fixup_t_forward
79 90
 		},
80
-	9,
91
+	11,
81 92
 	(response_function) t_on_reply_received,
82 93
 	(destroy_function) tm_shutdown,
83 94
 	w_onbreak
... ...
@@ -237,3 +248,12 @@ static int w_t_release(struct sip_msg* msg, char* str, char* str2)
237 248
 	return t_release_transaction(msg);
238 249
 }
239 250
 
251
+static int w_t_on_request_received(struct sip_msg* msg, char* str, char* str2)
252
+{
253
+	return t_on_request_received(msg, (unsigned int) str, (unsigned int) str2);
254
+}
255
+
256
+static int w_t_on_request_received_uri(struct sip_msg* msg, char* str, char* str2)
257
+{
258
+	return t_on_request_received_uri(msg);
259
+}
... ...
@@ -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 165
 	unsigned int ip;
165 166
 	int len;
166 167
 #endif
167
-	
168
+
168 169
 	p=(struct proxy_l*) malloc(sizeof(struct proxy_l));
169 170
 	if (p==0){
170 171
 		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 205
 		}
205 206
 		memcpy(p->host.h_addr_list[0], (char*)&ip, 4);
206 207
 		p->host.h_addr_list[0][4]=0;
207
-		
208
+
208 209
 		return p;
209 210
 	}
210 211
 #endif
211 212
 	/* fail over to normal lookup */
212
-	
213
+
213 214
 	he=gethostbyname(name);
214 215
 	if (he==0){
215 216
 		LOG(L_CRIT, "ERROR: mk_proxy: could not resolve hostname:"
... ...
@@ -229,6 +230,44 @@ error:
229 230
 
230 231
 
231 232
 
233
+/* same as mk_proxy, but get the host as an ip*/
234
+struct proxy_l* mk_proxy_from_ip(unsigned int ip, unsigned short port)
235
+{
236
+	struct proxy_l* p;
237
+	struct hostent* he;
238
+	int err;
239
+
240
+	p=(struct proxy_l*) malloc(sizeof(struct proxy_l));
241
+	if (p==0){
242
+		LOG(L_CRIT, "ERROR: mk_proxy_from_ip: memory allocation failure\n");
243
+		goto error;
244
+	}
245
+	memset(p,0,sizeof(struct proxy_l));
246
+
247
+	p->port=port;
248
+	p->host.h_addrtype=AF_INET;
249
+	p->host.h_length=4;
250
+	p->host.h_addr_list=malloc(2*sizeof(char*));
251
+	if (p->host.h_addr_list==0) goto error;
252
+	p->host.h_addr_list[1]=0;
253
+	p->host.h_addr_list[0]=malloc(5);
254
+	if (p->host.h_addr_list[0]==0){
255
+		free(p->host.h_addr_list);
256
+		goto error;
257
+	}
258
+
259
+	memcpy(p->host.h_addr_list[0], (char*)&ip, 4);
260
+	p->host.h_addr_list[0][4]=0;
261
+
262
+	return p;
263
+
264
+error:
265
+	return 0;
266
+}
267
+
268
+
269
+
270
+
232 271
 void free_proxy(struct proxy_l* p)
233 272
 {
234 273
 	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]{