Browse code

topoh: discover local request direction from th cookie

- l can be used to mark local requests for topoh handling

Daniel-Constantin Mierla authored on 04/01/2015 22:54:23
Showing 2 changed files
... ...
@@ -1002,6 +1002,15 @@ int th_del_cookie(sip_msg_t *msg)
1002 1002
 }
1003 1003
 
1004 1004
 
1005
+/**
1006
+ * return the special topoh cookie
1007
+ * - TH header of TH Via parame
1008
+ * - value is 3 chars
1009
+ *   [0] - direction:    d - downstream; u - upstream
1010
+ *   [1] - request type: i - initial; c - in-dialog; l - local in-dialog
1011
+ *   [2] - location:     h - header; v - via param
1012
+ * - if not found, returns 'xxx'
1013
+ */
1005 1014
 char* th_get_cookie(sip_msg_t *msg, int *clen)
1006 1015
 {
1007 1016
 	hdr_field_t *hf;
... ...
@@ -401,13 +401,24 @@ int th_msg_sent(void *data)
401 401
 	{
402 402
 		direction = (th_cookie_value.s[0]=='u')?1:0; /* upstream/downstram */
403 403
 		dialog = (get_to(&msg)->tag_value.len>0)?1:0;
404
-		local = (th_cookie_value.s[0]!='d'&&th_cookie_value.s[0]!='u')?1:0;
404
+
405
+		if(msg.via2==0) {
406
+			local = 1;
407
+			if(direction==0 && th_cookie_value.s[1]=='l') {
408
+				/* downstream local request (e.g., dlg bye) */
409
+				local = 2;
410
+			}
411
+		} else {
412
+			/* more than one Via, but no received th cookie */
413
+			local = (th_cookie_value.s[0]!='d' && th_cookie_value.s[0]!='u')?1:0;
414
+		}
405 415
 		/* local generated requests */
406 416
 		if(local)
407 417
 		{
408 418
 			/* ACK and CANCEL go downstream */
409 419
 			if(get_cseq(&msg)->method_id==METHOD_ACK
410
-					|| get_cseq(&msg)->method_id==METHOD_CANCEL)
420
+					|| get_cseq(&msg)->method_id==METHOD_CANCEL
421
+					|| local==2)
411 422
 			{
412 423
 				th_mask_callid(&msg);
413 424
 				goto ready;