Browse code

tm: restrict tm onreply_route commands to tm reply routes only

- most tm onreply functions restricted to tm onreply routes only.
They cannot be executed anymore from the main/core
onreply_route (some of them won't work and others would leave the
transaction referenced).
- don't access route_type directly, but via get_route_type()

Andrei Pelinescu-Onciul authored on 22/02/2010 15:41:59
Showing 3 changed files
... ...
@@ -705,7 +705,7 @@ void faked_env( struct cell *t, struct sip_msg *msg)
705 705
 		 * a shmem-ed replica of the request; advertise it in route type;
706 706
 		 * for example t_reply needs to know that
707 707
 		 */
708
-		backup_route_type=route_type;
708
+		backup_route_type=get_route_type();
709 709
 		set_route_type(FAILURE_ROUTE);
710 710
 		/* also, tm actions look in beginning whether transaction is
711 711
 		 * set -- whether we are called from a reply-processing
... ...
@@ -420,7 +420,7 @@ int t_next_contacts(struct sip_msg* msg, char* key, char* value)
420 420
 
421 421
 		/* no transaction yet => load Request-URI and branches */
422 422
 
423
-		if (route_type == FAILURE_ROUTE) {
423
+		if (is_route_type(FAILURE_ROUTE)) {
424 424
 			LM_CRIT("BUG - undefined transaction in failure route\n");
425 425
 			return -1;
426 426
 		}
... ...
@@ -397,9 +397,9 @@ static cmd_export_t cmds[]={
397 397
 	{"t_relay_cancel",     w_t_relay_cancel,        0, 0,
398 398
 			REQUEST_ROUTE},
399 399
 	{"t_on_failure",       w_t_on_negative,         1, fixup_on_failure,
400
-			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
400
+			REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE },
401 401
 	{"t_on_reply",         w_t_on_reply,            1, fixup_on_reply,
402
-			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
402
+			REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE },
403 403
 	{"t_on_branch",       w_t_on_branch,         1, fixup_on_branch,
404 404
 			REQUEST_ROUTE | FAILURE_ROUTE },
405 405
 	{"t_check_status",     t_check_status,          1, fixup_t_check_status,
... ...
@@ -409,37 +409,37 @@ static cmd_export_t cmds[]={
409 409
 	{"t_write_unix",      t_write_unix,             2, fixup_t_write,
410 410
 	                REQUEST_ROUTE | FAILURE_ROUTE },
411 411
 	{"t_set_fr",          t_set_fr_inv,             1, fixup_var_int_1,
412
-			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
412
+			REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
413 413
 	{"t_set_fr",          t_set_fr_all,             2, fixup_var_int_12,
414
-			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
414
+			REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
415 415
 	{"t_reset_fr",        w_t_reset_fr,             0, 0,
416
-			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
416
+			REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
417 417
 	{"t_set_retr",        w_t_set_retr,               2, fixup_var_int_12,
418
-			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
418
+			REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
419 419
 	{"t_reset_retr",      w_t_reset_retr,           0, 0,
420
-			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
420
+			REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
421 421
 	{"t_set_max_lifetime", w_t_set_max_lifetime,      2, fixup_var_int_12,
422
-			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
422
+			REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
423 423
 	{"t_reset_max_lifetime", w_t_reset_max_lifetime, 0, 0,
424
-			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
424
+			REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
425 425
 	{"t_set_auto_inv_100", t_set_auto_inv_100,       1, fixup_var_int_1,
426 426
 													  REQUEST_ROUTE},
427 427
 	{"t_set_disable_6xx", t_set_disable_6xx,         1, fixup_var_int_1,
428
-			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
428
+			REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
429 429
 	{"t_set_disable_failover", t_set_disable_failover, 1, fixup_var_int_1,
430
-			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
430
+			REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
431 431
 	{"t_branch_timeout",  t_branch_timeout,         0, 0,  FAILURE_ROUTE},
432 432
 	{"t_branch_replied",  t_branch_replied,         0, 0,  FAILURE_ROUTE},
433 433
 	{"t_any_timeout",     t_any_timeout,            0, 0, 
434
-			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
434
+			REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
435 435
 	{"t_any_replied",     t_any_replied,            0, 0, 
436
-			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
436
+			REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
437 437
 	{"t_is_canceled",     t_is_canceled,            0, 0,
438
-			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
438
+			REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
439 439
 	{"t_is_expired",      t_is_expired,             0, 0,
440
-			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
440
+			REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
441 441
 	{"t_grep_status",     t_grep_status,            1, fixup_var_int_1, 
442
-			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
442
+			REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
443 443
 	{"t_drop_replies",    w_t_drop_replies,         0, 0,
444 444
 			FAILURE_ROUTE},
445 445
 	{"t_drop_replies",    w_t_drop_replies,         1, 0,
... ...
@@ -447,7 +447,7 @@ static cmd_export_t cmds[]={
447 447
 	{"t_save_lumps",      w_t_save_lumps,           0, 0,
448 448
 			REQUEST_ROUTE},
449 449
 	{"t_check_trans",	t_check_trans,				0, 0,
450
-			REQUEST_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE },
450
+			REQUEST_ROUTE|TM_ONREPLY_ROUTE|BRANCH_ROUTE },
451 451
 
452 452
 	{"t_load_contacts", t_load_contacts,            0, 0,
453 453
 			REQUEST_ROUTE | FAILURE_ROUTE},
... ...
@@ -940,13 +940,14 @@ static int t_check_status(struct sip_msg* msg, char *p1, char *foo)
940 940
 		break;
941 941
 	}
942 942
 	
943
-	switch(route_type) {
943
+	switch(get_route_type()) {
944 944
 	case REQUEST_ROUTE:
945 945
 		/* use the status of the last sent reply */
946 946
 		status = int2str( t->uas.status, 0);
947 947
 		break;
948 948
 		
949
-	case ONREPLY_ROUTE:
949
+	case TM_ONREPLY_ROUTE:
950
+	case CORE_ONREPLY_ROUTE:
950 951
 		/* use the status of the current reply */
951 952
 		status = msg->first_line.u.reply.status.s;
952 953
 		backup = status[msg->first_line.u.reply.status.len];
... ...
@@ -973,7 +974,8 @@ static int t_check_status(struct sip_msg* msg, char *p1, char *foo)
973 973
 		break;
974 974
 
975 975
 	default:
976
-		LOG(L_ERR,"ERROR:t_check_status: unsupported route type %d\n",route_type);
976
+		LOG(L_ERR,"ERROR:t_check_status: unsupported route type %d\n",
977
+				get_route_type());
977 978
 		goto error;
978 979
 	}
979 980
 
... ...
@@ -1355,8 +1357,9 @@ inline static int _w_t_relay_to(struct sip_msg  *p_msg ,
1355 1355
 	}
1356 1356
 	if (is_route_type(REQUEST_ROUTE))
1357 1357
 		return t_relay_to( p_msg, proxy, force_proto,
1358
-			0 /* no replication */ );
1359
-	LOG(L_CRIT, "ERROR: w_t_relay_to: unsupported route type: %d\n", route_type);
1358
+							0 /* no replication */ );
1359
+	LOG(L_CRIT, "ERROR: w_t_relay_to: unsupported route type: %d\n",
1360
+			get_route_type());
1360 1361
 	return 0;
1361 1362
 }
1362 1363