Browse code

sip: timer C support.

Raphael Coeffic authored on 04/02/2012 17:10:56
Showing 3 changed files
... ...
@@ -64,7 +64,10 @@ enum sip_timer_type {
64 64
     // Transport address failover timer:
65 65
     // - used to cycle throught multiple addresses
66 66
     //   in case the R-URI resolves to multiple addresses
67
-    STIMER_M
67
+    STIMER_M,
68
+
69
+    // INVITE client transaction
70
+    STIMER_C   // Proceeding -> Terminated
68 71
 };
69 72
 
70 73
 
... ...
@@ -81,6 +84,9 @@ enum sip_timer_type {
81 84
 //type 0x02
82 85
 #define B_TIMER  64*T1_TIMER
83 86
 
87
+//type 0x0d
88
+#define C_TIMER  (3*60*1000)
89
+
84 90
 //type 0x03
85 91
 #define D_TIMER  64*T1_TIMER
86 92
 
... ...
@@ -116,6 +122,7 @@ enum sip_timer_type {
116 122
 // Transport address failover timer:
117 123
 // - used to cycle throught multiple addresses
118 124
 //   in case the R-URI resolves to multiple addresses
125
+//type 0x0c
119 126
 #define M_TIMER  (B_TIMER/4)
120 127
 
121 128
 #endif
... ...
@@ -45,7 +45,8 @@ int _timer_type_lookup[] = {
45 45
     0,1,2, // STIMER_G, STIMER_H, STIMER_I
46 46
     0,     // STIMER_J
47 47
     2,     // STIMER_L; shares the same slot as STIMER_D
48
-    2      // STIMER_M; shares the same slot as STIMER_D/STIMER_K
48
+    2,     // STIMER_M; shares the same slot as STIMER_D/STIMER_K
49
+    1,     // STIMER_C; shares the same slot at STIMER_B (INV trans only)
49 50
 };
50 51
 
51 52
 inline timer** fetch_timer(unsigned int timer_type, timer** base)
... ...
@@ -120,7 +121,7 @@ timer* sip_trans::get_timer(unsigned int timer_type)
120 121
 }
121 122
 
122 123
 
123
-char _timer_name_lookup[] = {'0','A','B','D','E','F','K','G','H','I','J','L','M'};
124
+char _timer_name_lookup[] = {'0','A','B','D','E','F','K','G','H','I','J','L','M','C'};
124 125
 #define timer_name(type) \
125 126
     (_timer_name_lookup[(type) & 0xFFFF])
126 127
 
... ...
@@ -1326,8 +1326,12 @@ int _trans_layer::update_uac_reply(trans_bucket* bucket, sip_trans* t, sip_msg*
1326 1326
 	    // fall through trap
1327 1327
 
1328 1328
 	case TS_PROCEEDING:
1329
-	    if(t->msg->u.request->method != sip_request::CANCEL)
1329
+	    if(t->msg->u.request->method != sip_request::CANCEL) {
1330
+		if(t->msg->u.request->method == sip_request::INVITE) {
1331
+		    t->reset_timer(STIMER_C, C_TIMER, bucket->get_id());
1332
+		}
1330 1333
 		goto pass_reply;
1334
+	    }
1331 1335
 	    else
1332 1336
 		goto end;
1333 1337
 
... ...
@@ -1362,7 +1366,9 @@ int _trans_layer::update_uac_reply(trans_bucket* bucket, sip_trans* t, sip_msg*
1362 1366
 		t->clear_timer(STIMER_B);
1363 1367
 
1364 1368
 	    case TS_PROCEEDING:
1365
-		
1369
+	
1370
+		t->clear_timer(STIMER_C);
1371
+
1366 1372
 		t->state = TS_COMPLETED;
1367 1373
 		send_non_200_ack(msg,t);
1368 1374
 		t->reset_timer(STIMER_D, D_TIMER, bucket->get_id());
... ...
@@ -1402,6 +1408,11 @@ int _trans_layer::update_uac_reply(trans_bucket* bucket, sip_trans* t, sip_msg*
1402 1408
 		t->clear_timer(STIMER_M);
1403 1409
 		t->clear_timer(STIMER_B);
1404 1410
 
1411
+		// Timer B & C share the same slot,
1412
+		// so it would pretty useless to clear
1413
+		// the same timer slote another time ;-)
1414
+		//t->clear_timer(STIMER_C);
1415
+
1405 1416
 		t->reset_timer(STIMER_L, L_TIMER, bucket->get_id());
1406 1417
 
1407 1418
 		if (t->to_tag.len==0) {
... ...
@@ -1707,6 +1718,31 @@ void _trans_layer::timer_expired(timer* t, trans_bucket* bucket, sip_trans* tr)
1707 1718
 	}
1708 1719
 	break;
1709 1720
 
1721
+    case STIMER_C: // Proceeding -> Terminated
1722
+	
1723
+	// Note: remember well, we first set timer C
1724
+	//       after the first provisional reply.
1725
+	tr->clear_timer(STIMER_C);
1726
+	if(tr->state != TS_PROCEEDING)
1727
+	    break; // shouldn't happen
1728
+
1729
+	bucket->unlock();
1730
+
1731
+	{
1732
+	    // send CANCEL
1733
+	    trans_ticket tt(tr,bucket);
1734
+	    cancel(&tt);
1735
+	    
1736
+	    // Now remove the transaction
1737
+	    bucket->lock();
1738
+	    if(bucket->exist(tr)) {
1739
+		// unlocks the bucket
1740
+		timeout(bucket,tr);
1741
+		return;
1742
+	    }
1743
+	}
1744
+	break;
1745
+
1710 1746
     case STIMER_F:  // Trying/Proceeding: terminate transaction
1711 1747
 	
1712 1748
 	tr->clear_timer(STIMER_F);