Browse code

-tm patch updated to latest changes -support for multidomain added

Bogdan-Andrei Iancu authored on 13/11/2003 20:08:07
Showing 7 changed files
... ...
@@ -63,6 +63,7 @@
63 63
 
64 64
 
65 65
 #define MAX_PROXY_RECURSE  10
66
+#define MAX_USERHOST_LEN    256
66 67
 
67 68
 
68 69
 /* modules param variables */
... ...
@@ -419,7 +420,31 @@ static int cpl_exit(void)
419 420
 
420 421
 
421 422
 
422
-static inline int get_dest_user(struct sip_msg *msg, str *user)
423
+static inline int build_userhost(struct sip_uri *uri, str *uh, int flg)
424
+{
425
+	static char buf[MAX_USERHOST_LEN];
426
+
427
+	if (flg) {
428
+		uh->s = (char*)shm_malloc(uri->user.len+1+uri->host.len+1);
429
+		if (!uh->s) {
430
+			LOG(L_ERR,"ERROR:cpl-c:build_userhost: no more shm memory.\n");
431
+			return -1;
432
+		}
433
+	} else {
434
+		uh->s = buf;
435
+	}
436
+	memcpy( uh->s, uri->user.s, uri->user.len);
437
+	uh->len = uri->user.len;
438
+	uh->s[uh->len++] = '@';
439
+	memcpy( uh->s+uh->len, uri->host.s, uri->host.len);
440
+	uh->len += uri->host.len;
441
+	uh->s[uh->len++] = 0;
442
+	return 0;
443
+}
444
+
445
+
446
+
447
+static inline int get_dest_user(struct sip_msg *msg, str *uh, int flg)
423 448
 {
424 449
 	struct sip_uri uri;
425 450
 
... ...
@@ -443,13 +468,12 @@ static inline int get_dest_user(struct sip_msg *msg, str *user)
443 468
 			}
444 469
 		}
445 470
 	}
446
-	*user = uri.user;
447
-	return 0;
471
+	return build_userhost( &uri, uh, flg);
448 472
 }
449 473
 
450 474
 
451 475
 
452
-static inline int get_orig_user(struct sip_msg *msg, str *user)
476
+static inline int get_orig_user(struct sip_msg *msg, str *uh, int flg)
453 477
 {
454 478
 	struct to_body *from;
455 479
 	struct sip_uri uri;
... ...
@@ -469,8 +493,7 @@ static inline int get_orig_user(struct sip_msg *msg, str *user)
469 493
 			"from URI (From header)\n");
470 494
 		return -1;
471 495
 	}
472
-	*user = uri.user;
473
-	return 0;
496
+	return build_userhost( &uri, uh, flg);
474 497
 }
475 498
 
476 499
 
... ...
@@ -484,32 +507,33 @@ static int cpl_invoke_script(struct sip_msg* msg, char* str1, char* str2)
484 507
 	str  loc;
485 508
 	str  script;
486 509
 
487
-	script.s = 0;
488
-	cpl_intr = 0;
510
+	//script.s = 0;
511
+	//cpl_intr = 0;
489 512
 
490 513
 	/* get the user_name */
491 514
 	if ( ((unsigned int)str1)&CPL_RUN_INCOMING ) {
492 515
 		/* if it's incoming -> get the destination user name */
493
-		if (get_dest_user( msg, &user)==-1)
494
-			goto error;
516
+		if (get_dest_user( msg, &user, 1)==-1)
517
+			goto error0;
495 518
 	} else {
496 519
 		/* if it's outgoing -> get the origin user name */
497
-		if (get_orig_user( msg, &user)==-1)
498
-			goto error;
520
+		if (get_orig_user( msg, &user, 1)==-1)
521
+			goto error0;
499 522
 	}
500 523
 
501 524
 	/* get the script for this user */
502 525
 	if (get_user_script( db_hdl, &user, &script, "cpl_bin")==-1)
503
-		goto error;
526
+		goto error1;
504 527
 
505 528
 	/* has the user a non-empty script? if not, return normaly, allowing ser to
506 529
 	 * continue its script */
507 530
 	if ( !script.s || !script.len )
531
+		shm_free(user.s);
508 532
 		return 1;
509 533
 
510 534
 	/* build a new script interpreter */
511 535
 	if ( (cpl_intr=new_cpl_interpreter(msg,&script))==0 )
512
-		goto error;
536
+		goto error2;
513 537
 	/* set the flags */
514 538
 	cpl_intr->flags = ((unsigned int)str1);
515 539
 	/* attache the user */
... ...
@@ -517,17 +541,17 @@ static int cpl_invoke_script(struct sip_msg* msg, char* str1, char* str2)
517 541
 	/* for OUTGOING we need also the destination user for init. with him
518 542
 	 * the location set */
519 543
 	if ( ((unsigned int)str1)&CPL_RUN_OUTGOING ) {
520
-		if (get_dest_user( msg, &loc)==-1)
521
-			goto error;
544
+		if (get_dest_user( msg, &loc,0)==-1)
545
+			goto error3;
522 546
 		if (add_location( &(cpl_intr->loc_set), &loc,10/*prio*/,1/*dup*/)==-1)
523
-			goto error;
547
+			goto error3;
524 548
 	}
525 549
 
526 550
 	/* since the script interpretation can take some time, it will be better to
527 551
 	 * send a 100 back to prevent the UAC to retransmit */
528 552
 	if ( cpl_tmb.t_reply( msg, (int)100, "Running cpl script" )!=1 ) {
529 553
 		LOG(L_ERR,"ERROR:cpl_invoke_script: unable to send 100 reply!\n");
530
-		goto error;
554
+		goto error3;
531 555
 	}
532 556
 
533 557
 	/* run the script */
... ...
@@ -541,15 +565,18 @@ static int cpl_invoke_script(struct sip_msg* msg, char* str1, char* str2)
541 565
 			return 0; /* break the SER script */
542 566
 		case SCRIPT_RUN_ERROR:
543 567
 		case SCRIPT_FORMAT_ERROR:
544
-			goto error;
568
+			goto error3;
545 569
 	}
546 570
 
547 571
 	return 1;
548
-error:
549
-	if (!cpl_intr && script.s)
550
-		shm_free(script.s);
551
-	if (cpl_intr)
552
-		free_cpl_interpreter( cpl_intr );
572
+error3:
573
+	free_cpl_interpreter( cpl_intr );
574
+	return -1;
575
+error2:
576
+	shm_free(script.s);
577
+error1:
578
+	shm_free(user.s);
579
+error0:
553 580
 	return -1;
554 581
 }
555 582
 
... ...
@@ -588,7 +615,6 @@ static inline int do_script_action(struct sip_msg *msg, int action)
588 615
 	str  user = {0,0};
589 616
 	str  bin  = {0,0};
590 617
 	str  log  = {0,0};
591
-	char foo;
592 618
 
593 619
 	/* content-length (if present) */
594 620
 	if ( (!msg->content_length && parse_headers(msg,HDR_CONTENTLENGTH,0)==-1)
... ...
@@ -600,14 +626,8 @@ static inline int do_script_action(struct sip_msg *msg, int action)
600 626
 	body.len = get_content_length( msg );
601 627
 
602 628
 	/* get the user name */
603
-	if (get_dest_user( msg, &user)==-1)
629
+	if (get_dest_user( msg, &user, 0)==-1)
604 630
 		goto error;
605
-	/* make the user zero terminated -  it's safe - it'a an incomming request,
606
-	 * so I'm the only process working with it (no sync problems) and user
607
-	 * points inside the message and all the time it's something after it (no
608
-	 * buffer overflow)*/
609
-	foo = user.s[user.len];
610
-	user.s[user.len] = 0;
611 631
 
612 632
 	/* we have the script and the user */
613 633
 	switch (action) {
... ...
@@ -654,11 +674,9 @@ static inline int do_script_action(struct sip_msg *msg, int action)
654 674
 	}
655 675
 
656 676
 	if (log.s) pkg_free( log.s );
657
-	user.s[user.len] = foo;
658 677
 	return 0;
659 678
 error_1:
660 679
 	if (log.s) pkg_free( log.s );
661
-	user.s[user.len] = foo;
662 680
 error:
663 681
 	return -1;
664 682
 }
... ...
@@ -671,7 +689,7 @@ static inline int do_script_download(struct sip_msg *msg)
671 689
 	str script = {0,0};
672 690
 
673 691
 	/* get the destination user name */
674
-	if (get_dest_user( msg, &user)==-1)
692
+	if (get_dest_user( msg, &user, 0)==-1)
675 693
 		goto error;
676 694
 
677 695
 	/* get the user's xml script from the database */
... ...
@@ -44,14 +44,7 @@ int get_user_script( db_con_t *db_hdl, str *user, str *script, char* key)
44 44
 	db_key_t   keys_ret[] = { key };
45 45
 	db_val_t   vals[1];
46 46
 	db_res_t   *res = 0 ;
47
-	char       tmp;
48
-
49
-	/* it shouldn't be aproblem overwriting a \0 at the end of user name; the
50
-	 * user name is part of the sip_msg struct received -  that is allocated in
51
-	 * process private mem - no sync problems; also there is all the time some
52
-	 * extra characters after the user name - at least the EOH */
53
-	tmp = user->s[user->len];
54
-	user->s[user->len] = 0;
47
+
55 48
 	DBG("DEBUG:get_user_script: fetching script for user <%s>\n",user->s);
56 49
 	vals[0].type = DB_STRING;
57 50
 	vals[0].nul  = 0;
... ...
@@ -60,7 +53,6 @@ int get_user_script( db_con_t *db_hdl, str *user, str *script, char* key)
60 53
 		LOG(L_ERR,"ERROR:cpl-c:get_user_script: db_query failed\n");
61 54
 		goto error;
62 55
 	}
63
-	user->s[user->len] = tmp;
64 56
 
65 57
 	if (res->n==0) {
66 58
 		DBG("DEBUG:get_user_script: user <%.*s> not found in db -> probably "
... ...
@@ -379,12 +379,7 @@ static inline char *run_proxy( struct cpl_interpreter *intr )
379 379
 	/* if it's the first execution of a proxy node, force parsing of the needed
380 380
 	 * headers and duplicate them in shared memory */
381 381
 	if (!(intr->flags&CPL_PROXY_DONE)) {
382
-		/* save the user name - we will need it */
383
-		if ( (p=(char*)shm_malloc( intr->user.len ))==0)
384
-			goto mem_error;
385
-		memcpy( p, intr->user.s, intr->user.len);
386
-		intr->user.s = p;
387
-		intr->flags |= CPL_USER_DUPLICATED;
382
+		/* user name is already in shared memory */
388 383
 		/* requested URI - mandatory in SIP msg (cannot be STR_NOT_FOUND) */
389 384
 		s = GET_RURI( intr->msg );
390 385
 		duplicate_str( s , intr->ruri );
... ...
@@ -147,10 +147,10 @@ error:
147 147
 void free_cpl_interpreter(struct cpl_interpreter *intr)
148 148
 {
149 149
 	if (intr) {
150
+		empty_location_set( &(intr->loc_set) );
150 151
 		if (intr->script.s)
151 152
 			shm_free( intr->script.s);
152
-		empty_location_set( &(intr->loc_set) );
153
-		if (intr->flags&CPL_USER_DUPLICATED)
153
+		if (intr->user.s)
154 154
 			shm_free(intr->user.s);
155 155
 		if (intr->flags&CPL_RURI_DUPLICATED)
156 156
 			shm_free(intr->ruri);
... ...
@@ -42,7 +42,6 @@
42 42
 #define CPL_RUN_INCOMING               (1<<1)
43 43
 #define CPL_LOC_SET_MODIFIED           (1<<2)
44 44
 #define CPL_PROXY_DONE                 (1<<3)
45
-#define CPL_USER_DUPLICATED            (1<<4)
46 45
 #define CPL_RURI_DUPLICATED            (1<<5)
47 46
 #define CPL_TO_DUPLICATED              (1<<6)
48 47
 #define CPL_FROM_DUPLICATED            (1<<7)
... ...
@@ -98,7 +98,7 @@ static inline int add_location(struct location **loc_set, str *uri,
98 98
 		/* insert after bar, before foo  */
99 99
 		loc->next = foo;
100 100
 		bar->next = loc;
101
-	 }
101
+	}
102 102
 
103 103
 	return 0;
104 104
 }
... ...
@@ -1,5 +1,5 @@
1
-diff -ruib sip_router/modules/tm/h_table.c sip_router_md/modules/tm/h_table.c
1
+diff -ruib sip_router_head/modules/tm/h_table.c sip_router_md/modules/tm/h_table.c
2
+--- sip_router_head/modules/tm/h_table.c	2003-09-19 21:02:08.000000000 +0200
2 3
 +++ sip_router_md/modules/tm/h_table.c	2003-09-26 18:00:19.000000000 +0200
3 4
 @@ -106,6 +106,7 @@
4 5
  	int i;
... ...
@@ -43,8 +43,8 @@ diff -ruib sip_router/modules/tm/h_table.c sip_router_md/modules/tm/h_table.c
43 43
  
44 44
  	if (p_msg) {
45 45
  		new_cell->uas.request = sip_msg_cloner(p_msg);
46
-diff -ruib sip_router/modules/tm/h_table.h sip_router_md/modules/tm/h_table.h
46
+diff -ruib sip_router_head/modules/tm/h_table.h sip_router_md/modules/tm/h_table.h
47
+--- sip_router_head/modules/tm/h_table.h	2003-04-07 08:36:56.000000000 +0200
47 48
 +++ sip_router_md/modules/tm/h_table.h	2003-08-06 17:41:47.000000000 +0200
48 49
 @@ -189,6 +189,9 @@
49 50
  	   during freeing transaction too
... ...
@@ -56,8 +56,8 @@ diff -ruib sip_router/modules/tm/h_table.h sip_router_md/modules/tm/h_table.h
56 56
  
57 57
  	/* how many processes are currently processing this transaction ;
58 58
  	   note that only processes working on a request/reply belonging
59
-diff -ruib sip_router/modules/tm/t_fwd.c sip_router_md/modules/tm/t_fwd.c
59
+diff -ruib sip_router_head/modules/tm/t_fwd.c sip_router_md/modules/tm/t_fwd.c
60
+--- sip_router_head/modules/tm/t_fwd.c	2003-07-08 14:39:13.000000000 +0200
60 61
 +++ sip_router_md/modules/tm/t_fwd.c	2003-08-06 16:34:12.000000000 +0200
61 62
 @@ -83,8 +83,12 @@
62 63
  	/* ... update uri ... */
... ...
@@ -72,8 +72,8 @@ diff -ruib sip_router/modules/tm/t_fwd.c sip_router_md/modules/tm/t_fwd.c
72 72
  
73 73
  	/* ... and build it now */
74 74
  	buf=build_req_buf_from_sip_req( i_req, len, send_sock, proto );
75
-diff -ruib sip_router/modules/tm/t_hooks.c sip_router_md/modules/tm/t_hooks.c
75
+diff -ruib sip_router_head/modules/tm/t_hooks.c sip_router_md/modules/tm/t_hooks.c
76
+--- sip_router_head/modules/tm/t_hooks.c	2003-03-19 19:40:09.000000000 +0100
76 77
 +++ sip_router_md/modules/tm/t_hooks.c	2003-08-19 19:02:47.000000000 +0200
77 78
 @@ -38,6 +38,11 @@
78 79
  #include "../../error.h"
... ...
@@ -166,8 +166,8 @@ diff -ruib sip_router/modules/tm/t_hooks.c sip_router_md/modules/tm/t_hooks.c
166 166
 +}
167 167
 +
168 168
 +
169
-diff -ruib sip_router/modules/tm/t_hooks.h sip_router_md/modules/tm/t_hooks.h
169
+diff -ruib sip_router_head/modules/tm/t_hooks.h sip_router_md/modules/tm/t_hooks.h
170
+--- sip_router_head/modules/tm/t_hooks.h	2003-07-08 17:24:27.000000000 +0200
170 171
 +++ sip_router_md/modules/tm/t_hooks.h	2003-08-06 21:13:41.000000000 +0200
171 172
 @@ -36,7 +36,6 @@
172 173
  
... ...
@@ -204,8 +204,8 @@ diff -ruib sip_router/modules/tm/t_hooks.h sip_router_md/modules/tm/t_hooks.h
204 204
 +												struct sip_msg *msg, int code );
205 205
  
206 206
  #endif
207
-diff -ruib sip_router/modules/tm/t_lookup.c sip_router_md/modules/tm/t_lookup.c
207
+diff -ruib sip_router_head/modules/tm/t_lookup.c sip_router_md/modules/tm/t_lookup.c
208
+--- sip_router_head/modules/tm/t_lookup.c	2003-08-21 21:36:39.000000000 +0200
208 209
 +++ sip_router_md/modules/tm/t_lookup.c	2003-09-03 17:52:50.000000000 +0200
209 210
 @@ -785,15 +785,29 @@
210 211
  		if (p_cell->is_invite && p_msg->REPLY_STATUS>=200 
... ...
@@ -268,10 +268,10 @@ diff -ruib sip_router/modules/tm/t_lookup.c sip_router_md/modules/tm/t_lookup.c
268 268
  		}
269 269
  		UNREF(t_ack);
270 270
  		return 1;
271
-diff -ruib sip_router/modules/tm/t_reply.c sip_router_md/modules/tm/t_reply.c
272
-+++ sip_router_md/modules/tm/t_reply.c	2003-10-27 15:16:39.000000000 +0100
273
-@@ -306,11 +306,17 @@
271
+diff -ruib sip_router_head/modules/tm/t_reply.c sip_router_md/modules/tm/t_reply.c
272
+--- sip_router_head/modules/tm/t_reply.c	2003-11-11 20:37:16.000000000 +0100
273
+@@ -309,11 +309,17 @@
274 274
  	if (code>=200) {
275 275
  		if (trans->local) {
276 276
  			DBG("DEBUG: local transaction completed from _reply\n");
... ...
@@ -289,7 +289,7 @@ diff -ruib sip_router/modules/tm/t_reply.c sip_router_md/modules/tm/t_reply.c
289 289
  		}
290 290
  
291 291
  		cleanup_uac_timers( trans );
292
-@@ -377,45 +383,15 @@
292
+@@ -380,45 +386,15 @@
293 293
  }
294 294
  
295 295
  
... ...
@@ -339,33 +339,91 @@ diff -ruib sip_router/modules/tm/t_reply.c sip_router_md/modules/tm/t_reply.c
339 339
  	/* remember we are back in request processing, but process
340 340
  	 * a shmem-ed replica of the request; advertise it in rmode;
341 341
  	 * for example t_reply needs to know that
342
-@@ -432,81 +408,90 @@
342
+@@ -435,90 +411,95 @@
343 343
  	backup_t=get_t();
344 344
  	backup_msgid=global_msg_id;
345 345
  	/* fake transaction and message id */
346 346
 -	global_msg_id=fake->id;
347 347
 -	set_t(_t);
348
+-
349
+-	/* environment is set up now, try to fake the message */
350
+-
351
+-	/* new_uri can change -- make a private copy */
352
+-	if (shmem_msg->new_uri.s!=0 && shmem_msg->new_uri.len!=0) {
353
+-		fake->new_uri.s=pkg_malloc(shmem_msg->new_uri.len+1);
354
+-		if (!fake->new_uri.s) {
355
+-			LOG(L_ERR, "ERROR: faked_env: no uri/pkg mem\n");
356
+-			goto restore;
357
+-		}
358
+-		fake->new_uri.len=shmem_msg->new_uri.len;
359
+-		memcpy( fake->new_uri.s, shmem_msg->new_uri.s, 
360
+-			fake->new_uri.len);
361
+-		fake->new_uri.s[fake->new_uri.len]=0;
362
+-	} 
363
+-
364
+-	/* create a duplicated lump list to which actions can add
365
+-	 * new pkg items 
366
+-	 */
367
+-	if (shmem_msg->add_rm) {
368
+-		fake->add_rm=dup_lump_list(shmem_msg->add_rm);
369
+-		if (!fake->add_rm) { /* non_emty->empty ... failure */
370
+-			LOG(L_ERR, "ERROR: on_negative_reply: lump dup failed\n");
371
+-			goto restore;
372
+-		}
373
+-	}
374
+-
375
+-	if (shmem_msg->body_lumps) {
376
+-		fake->body_lumps=dup_lump_list(shmem_msg->body_lumps);
377
+-		if (!fake->body_lumps) { /* non_empty->empty ... failure */
378
+-			LOG(L_ERR, "ERROR: on_negative_reply: lump dup failed\n");
379
+-			goto restore;
380
+-		}
381
+-	}
382
+-	
383
+-	/* success */
384
+-	return 1;
385
+-
386
+-restore:
387
+-	/* restore original environment and destroy faked message */
388
+-	free_duped_lump_list(fake->add_rm);
389
+-	free_duped_lump_list(fake->body_lumps);
390
+-	if (fake->new_uri.s) pkg_free(fake->new_uri.s);
348 391
 +		global_msg_id=msg->id;
349 392
 +		set_t(t);
350 393
 +	} else {
351 394
 +		/* restore original environment */
352
-+		set_t(backup_t);
353
-+		global_msg_id=backup_msgid;
354
-+		rmode=backup_mode;
395
+ 	set_t(backup_t);
396
+ 	global_msg_id=backup_msgid;
397
+ 	rmode=backup_mode;
398
+-	/* if failure handler changed flag, update transaction context */
399
+-	shmem_msg->flags=fake->flags;
400
+-	return 0;
355 401
 +	}
356
-+}
402
+ }
357 403
  
358
--	/* environment is set up now, try to fake the message */
359 404
 +
360
-+/* return 1 if a failure_route processes */
405
+ /* return 1 if a failure_route processes */
406
+-int failure_route(struct cell *t)
361 407
 +static inline int run_failure_route(struct cell *t)
362
-+{
408
+ {
409
+-	struct sip_msg faked_msg;
410
+-	struct sip_msg *orig_request;
363 411
 +	struct sip_msg fake;
364 412
 +	struct sip_msg *shmem_msg = t->uas.request;
365
-+
366
-+	/* don't do anything if we don't have to */
367
-+	if (!t->on_negative) return 0;
368
-+
413
+ 
414
+ 	/* don't do anything if we don't have to */
415
+ 	if (!t->on_negative) return 0;
416
+-	orig_request=t->uas.request;
417
+ 	/* failure_route for a local UAC? */
418
+-	if (!orig_request) {
419
++	if (!shmem_msg) {
420
+ 		LOG(L_WARN, "Warning: failure_route: no UAC support\n");
421
+ 		return 0;
422
+ 	}
423
+ 
424
+-	/* if fake message creation failes, return error too */
425
+-	if (!faked_env(&faked_msg, t, orig_request, 0 /* create fake */ )) {
426
+-		LOG(L_ERR, "ERROR: on_negative_reply: faked_env failed\n");
369 427
 +	/* on_negative_reply faked msg now copied from shmem msg (as opposed
370 428
 +	 * to zero-ing) -- more "read-only" actions (exec in particular) will
371 429
 +	 * work from reply_route as they will see msg->from, etc.; caution,
... ...
@@ -376,18 +434,9 @@ diff -ruib sip_router/modules/tm/t_reply.c sip_router_md/modules/tm/t_reply.c
376 434
 +	/* if we set msg_id to something different from current's message
377 435
 +	 * id, the first t_fork will properly clean new branch URIs */
378 436
 +	fake.id=shmem_msg->id-1;
379
- 
380
- 	/* new_uri can change -- make a private copy */
381
- 	if (shmem_msg->new_uri.s!=0 && shmem_msg->new_uri.len!=0) {
382
--		fake->new_uri.s=pkg_malloc(shmem_msg->new_uri.len+1);
383
--		if (!fake->new_uri.s) {
384
--			LOG(L_ERR, "ERROR: faked_env: no uri/pkg mem\n");
385
--			goto restore;
386
--		}
387
--		fake->new_uri.len=shmem_msg->new_uri.len;
388
--		memcpy( fake->new_uri.s, shmem_msg->new_uri.s, 
389
--			fake->new_uri.len);
390
--		fake->new_uri.s[fake->new_uri.len]=0;
437
++
438
++	/* new_uri can change -- make a private copy */
439
++	if (shmem_msg->new_uri.s!=0 && shmem_msg->new_uri.len!=0) {
391 440
 +		fake.new_uri.s=pkg_malloc(shmem_msg->new_uri.len+1);
392 441
 +		if (!fake.new_uri.s) {
393 442
 +			LOG(L_ERR, "ERROR: run_failure_route: no uri/pkg mem\n");
... ...
@@ -397,66 +446,30 @@ diff -ruib sip_router/modules/tm/t_reply.c sip_router_md/modules/tm/t_reply.c
397 446
 +		memcpy( fake.new_uri.s, shmem_msg->new_uri.s, 
398 447
 +			fake.new_uri.len);
399 448
 +		fake.new_uri.s[fake.new_uri.len]=0;
400
- 	} 
401
- 
402
- 	/* create a duplicated lump list to which actions can add
403
--	 * new pkg items 
404
--	 */
449
++	}
450
++
451
++	/* create a duplicated lump list to which actions can add
405 452
 +	 * new pkg items  */
406
- 	if (shmem_msg->add_rm) {
407
--		fake->add_rm=dup_lump_list(shmem_msg->add_rm);
408
--		if (!fake->add_rm) { /* non_emty->empty ... failure */
409
--			LOG(L_ERR, "ERROR: on_negative_reply: lump dup failed\n");
410
--			goto restore;
453
++	if (shmem_msg->add_rm) {
411 454
 +		fake.add_rm=dup_lump_list(shmem_msg->add_rm);
412 455
 +		if (!fake.add_rm) { /* non_emty->empty ... failure */
413 456
 +			LOG(L_ERR, "ERROR: run_failure_route: lump dup failed\n");
414 457
 +			if (fake.new_uri.s) pkg_free(fake.new_uri.s);
415 458
 +			return 0;
416
- 		}
417
- 	}
418
- 
459
++		}
460
++	}
461
++
419 462
 +	/* same for the body lumps */
420
- 	if (shmem_msg->body_lumps) {
421
--		fake->body_lumps=dup_lump_list(shmem_msg->body_lumps);
422
--		if (!fake->body_lumps) { /* non_empty->empty ... failure */
463
++	if (shmem_msg->body_lumps) {
423 464
 +		fake.body_lumps=dup_lump_list(shmem_msg->body_lumps);
424 465
 +		if (!fake.body_lumps) { /* non_empty->empty ... failure */
425
- 			LOG(L_ERR, "ERROR: on_negative_reply: lump dup failed\n");
426
--			goto restore;
466
++			LOG(L_ERR, "ERROR: on_negative_reply: lump dup failed\n");
427 467
 +			free_duped_lump_list(fake.add_rm);
428 468
 +			if (fake.new_uri.s) pkg_free(fake.new_uri.s);
429
-+			return 0;
430
- 		}
469
+ 		return 0;
431 470
  	}
432
- 	
433
--	/* success */
434
--	return 1;
435
--
436
--restore:
437
--	/* restore original environment and destroy faked message */
438
--	free_duped_lump_list(fake->add_rm);
439
--	free_duped_lump_list(fake->body_lumps);
440
--	if (fake->new_uri.s) pkg_free(fake->new_uri.s);
441
--	set_t(backup_t);
442
--	global_msg_id=backup_msgid;
443
--	rmode=backup_mode;
444
--	return 0;
445
--}
446
--
447
--/* return 1 if a failure_route processes */
448
--int failure_route(struct cell *t)
449
--{
450
--	struct sip_msg faked_msg;
451
--
452
--	/* don't do anything if we don't have to */
453
--	if (!t->on_negative) return 0;
454
--
455
--	/* if fake message creation failes, return error too */
456
--	if (!faked_env(&faked_msg, t, t->uas.request, 0 /* create fake */ )) {
457
--		LOG(L_ERR, "ERROR: on_negative_reply: faked_env failed\n");
458
--		return 0;
459
--	}
471
++	}
472
++
460 473
 +	/* fake also the env. conforming to the fake msg */
461 474
 +	faked_env( t, &fake);
462 475
 +	/* DONE with faking ;-) -> run the route */
... ...
@@ -470,7 +483,7 @@ diff -ruib sip_router/modules/tm/t_reply.c sip_router_md/modules/tm/t_reply.c
470 483
 -		LOG(L_ERR, "ERROR: on_negative_reply: "
471 484
 -			"Error in do_action\n");
472 485
 -	/* restore original environment */
473
--	faked_env(&faked_msg, 0, 0, 1 );
486
+-	faked_env(&faked_msg, 0, orig_request, 1 );
474 487
 +	if (run_actions(failure_rlist[t->on_negative], &fake)<0)
475 488
 +		LOG(L_ERR, "ERROR: run_failure_route: Error in do_action\n");
476 489
 +
... ...
@@ -483,7 +496,7 @@ diff -ruib sip_router/modules/tm/t_reply.c sip_router_md/modules/tm/t_reply.c
483 496
  	return 1;
484 497
  }
485 498
  
486
-@@ -561,7 +546,6 @@
499
+@@ -573,7 +554,6 @@
487 500
  	int branch , int *should_store, int *should_relay,
488 501
  	branch_bm_t *cancel_bitmap, struct sip_msg *reply )
489 502
  {
... ...
@@ -491,7 +504,7 @@ diff -ruib sip_router/modules/tm/t_reply.c sip_router_md/modules/tm/t_reply.c
491 504
  	int branch_cnt;
492 505
  	int picked_branch;
493 506
  	int picked_code;
494
-@@ -619,15 +603,32 @@
507
+@@ -631,15 +611,32 @@
495 508
  
496 509
  		/* no more pending branches -- try if that changes after
497 510
  		   a callback; save banch count to be able to determine
... ...
@@ -529,7 +542,7 @@ diff -ruib sip_router/modules/tm/t_reply.c sip_router_md/modules/tm/t_reply.c
529 542
  
530 543
  		/* look if the callback perhaps replied transaction; it also
531 544
  		   covers the case in which a transaction is replied localy
532
-@@ -864,7 +865,10 @@
545
+@@ -876,7 +873,10 @@
533 546
  		   anyway 
534 547
          */
535 548
  		if (msg_status<300 && branch==relay) {
... ...
@@ -540,7 +553,7 @@ diff -ruib sip_router/modules/tm/t_reply.c sip_router_md/modules/tm/t_reply.c
540 553
  		}
541 554
  		/* try bulding the outbound reply from either the current
542 555
  	       or a stored message */
543
-@@ -932,8 +936,11 @@
556
+@@ -944,8 +944,11 @@
544 557
  
545 558
  		if (t->is_invite && relayed_msg!=FAKED_REPLY
546 559
  				&& relayed_code>=200 && relayed_code < 300
... ...
@@ -554,7 +567,7 @@ diff -ruib sip_router/modules/tm/t_reply.c sip_router_md/modules/tm/t_reply.c
554 567
  			totag_retr=update_totag_set(t, relayed_msg);
555 568
  		}
556 569
  	}; /* if relay ... */
557
-@@ -945,8 +952,12 @@
570
+@@ -957,8 +960,12 @@
558 571
  		SEND_PR_BUFFER( uas_rb, buf, res_len );
559 572
  		DBG("DEBUG: reply relayed. buf=%p: %.9s..., shmem=%p: %.9s\n", 
560 573
  			buf, buf, uas_rb->buffer, uas_rb->buffer );
... ...
@@ -568,7 +581,7 @@ diff -ruib sip_router/modules/tm/t_reply.c sip_router_md/modules/tm/t_reply.c
568 581
  		pkg_free( buf );
569 582
  	}
570 583
  
571
-@@ -1017,8 +1028,11 @@
584
+@@ -1029,8 +1036,11 @@
572 585
  		update_reply_stats( winning_code );
573 586
  		if (t->is_invite && winning_msg!=FAKED_REPLY 
574 587
  				&& winning_code>=200 && winning_code <300
... ...
@@ -582,7 +595,7 @@ diff -ruib sip_router/modules/tm/t_reply.c sip_router_md/modules/tm/t_reply.c
582 595
  			totag_retr=update_totag_set(t, winning_msg);
583 596
  		}
584 597
  		
585
-@@ -1027,8 +1041,12 @@
598
+@@ -1039,8 +1049,12 @@
586 599
  	if (local_winner>=0 && winning_code>=200 ) {
587 600
  		DBG("DEBUG: local transaction completed\n");
588 601
  		if (!totag_retr) {
... ...
@@ -595,10 +608,10 @@ diff -ruib sip_router/modules/tm/t_reply.c sip_router_md/modules/tm/t_reply.c
595 608
  			if (t->completion_cb) t->completion_cb( t, winning_msg, 
596 609
  						winning_code, t->cbp);
597 610
  		}
598
-diff -ruib sip_router/modules/tm/tm.c sip_router_md/modules/tm/tm.c
599
-+++ sip_router_md/modules/tm/tm.c	2003-09-26 18:25:32.000000000 +0200
600
-@@ -195,9 +195,13 @@
611
+diff -ruib sip_router_head/modules/tm/tm.c sip_router_md/modules/tm/tm.c
612
+--- sip_router_head/modules/tm/tm.c	2003-10-30 12:56:44.000000000 +0100
613
+@@ -195,7 +195,10 @@
601 614
  	{"t_on_reply",         w_t_on_reply,            1, fixup_str2int,
602 615
  			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
603 616
  	/* not applicable from the script */
... ...
@@ -608,13 +621,10 @@ diff -ruib sip_router/modules/tm/tm.c sip_router_md/modules/tm/tm.c
608 621
 +	{"register_req_cb",    (cmd_function)register_req_cb,   NO_SCRIPT,    0, 0},
609 622
  	{"load_tm",            (cmd_function)load_tm,           NO_SCRIPT,     0, 0},
610 623
  	{T_REPLY_WB,           (cmd_function)t_reply_with_body, NO_SCRIPT,     0, 0},
611
-+	{T_REPLY_UNSAFE,       (cmd_function)t_reply_unsafe,    NO_SCRIPT,    0, 0},
612 624
  	{T_IS_LOCAL,           (cmd_function)t_is_local,        NO_SCRIPT,     0, 0},
613
- 	{T_GET_TI,             (cmd_function)t_get_trans_ident, NO_SCRIPT,     0, 0},
614
- 	{T_LOOKUP_IDENT,       (cmd_function)t_lookup_ident,    NO_SCRIPT,     0, 0},
615
-diff -ruib sip_router/modules/tm/tm_load.c sip_router_md/modules/tm/tm_load.c
616
-+++ sip_router_md/modules/tm/tm_load.c	2003-09-26 18:29:45.000000000 +0200
625
+diff -ruib sip_router_head/modules/tm/tm_load.c sip_router_md/modules/tm/tm_load.c
626
+--- sip_router_head/modules/tm/tm_load.c	2003-10-30 12:56:44.000000000 +0100
617 627
 @@ -40,12 +40,18 @@
618 628
  
619 629
  int load_tm( struct tm_binds *tmb)
... ...
@@ -635,9 +645,9 @@ diff -ruib sip_router/modules/tm/tm_load.c sip_router_md/modules/tm/tm_load.c
635 645
  	if (!( tmb->t_relay_to_tcp=find_export(T_RELAY_TO_TCP, 2, 0)) ) {
636 646
  		LOG(L_ERR, LOAD_ERROR "'t_relay_to_tcp' not found\n");
637 647
  		return -1;
638
-diff -ruib sip_router/modules/tm/tm_load.h sip_router_md/modules/tm/tm_load.h
639
-+++ sip_router_md/modules/tm/tm_load.h	2003-09-26 18:31:30.000000000 +0200
648
+diff -ruib sip_router_head/modules/tm/tm_load.h sip_router_md/modules/tm/tm_load.h
649
+--- sip_router_head/modules/tm/tm_load.h	2003-11-11 16:32:36.000000000 +0100
640 650
 @@ -56,6 +56,7 @@
641 651
  #define T_RELAY              "t_relay"
642 652
  #define T_REPLY              "t_reply"
... ...
@@ -646,7 +656,7 @@ diff -ruib sip_router/modules/tm/tm_load.h sip_router_md/modules/tm/tm_load.h
646 656
  #define T_ADDBLIND           "t_add_blind"
647 657
  #define T_REPLY_UNSAFE       "t_reply_unsafe"
648 658
  #define T_FORWARD_NONACK     "t_forward_nonack"
649
-@@ -72,7 +73,10 @@
659
+@@ -73,7 +74,10 @@
650 660
  
651 661
  
652 662
  struct tm_binds {