Browse code

to_tags now generated all the time from TM

Jiri Kuthan authored on 21/10/2002 21:24:43
Showing 5 changed files
... ...
@@ -94,4 +94,7 @@
94 94
 */
95 95
 #undef ACK_FORKING_HACK
96 96
 
97
+/* to-tag separator for stateful processing */
98
+#define TM_TAG_SEPARATOR '-'
99
+
97 100
 #endif
... ...
@@ -38,6 +38,7 @@
38 38
 #include "../../error.h"
39 39
 #include "../../action.h"
40 40
 #include "../../dset.h"
41
+#include "../../tags.h"
41 42
 
42 43
 #include "t_hooks.h"
43 44
 #include "t_funcs.h"
... ...
@@ -49,6 +50,10 @@
49 50
 #include "fix_lumps.h"
50 51
 #include "t_stats.h"
51 52
 
53
+/* private place where we create to-tags for replies */
54
+static char tm_tags[TOTAG_LEN];
55
+static char *tm_tag_suffix;
56
+
52 57
 /* where to go if there is no positive reply */
53 58
 static int goto_on_negative=0;
54 59
 
... ...
@@ -74,6 +79,13 @@ unsigned int get_on_negative()
74 79
 	return goto_on_negative;
75 80
 }
76 81
 
82
+void tm_init_tags()
83
+{
84
+	init_tags(tm_tags, &tm_tag_suffix, 
85
+		"SER-TM/tags", TM_TAG_SEPARATOR );
86
+}
87
+
88
+
77 89
 static char *build_ack(struct sip_msg* rpl,struct cell *trans,int branch,
78 90
 	unsigned int *ret_len)
79 91
 {
... ...
@@ -336,9 +348,19 @@ static int _reply( struct cell *trans, struct sip_msg* p_msg,
336 348
 		trans->uas.tag->len, trans->uas.request,&len);
337 349
 	*/
338 350
 	cancel_bitmap=0;
339
-	/* compute the buffer in private memory prior to entering lock */
340
-	buf = build_res_buf_from_sip_req(code,text, 0,0, /* no to-tag */
341
-		p_msg,&len);
351
+	/* compute the buffer in private memory prior to entering lock;
352
+	 * create to-tag if needed */
353
+	if (code>=180 && p_msg->to 
354
+			&& (get_to(p_msg)->tag_value.s==0 
355
+			    || get_to(p_msg)->tag_value.len==0)) {
356
+		calc_crc_suffix( p_msg, tm_tag_suffix );
357
+		buf = build_res_buf_from_sip_req(code,text, 
358
+				tm_tags, TOTAG_LEN, 
359
+				p_msg,&len);
360
+	} else {
361
+		buf = build_res_buf_from_sip_req(code,text, 0,0, /* no to-tag */
362
+			p_msg,&len);
363
+	}
342 364
 	DBG("DEBUG: t_reply: buffer computed\n");
343 365
 	if (!buf)
344 366
 	{
... ...
@@ -536,9 +558,22 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch,
536 558
 			tm_stats->replied_localy++;
537 559
 			relayed_code = branch==relay
538 560
 				? msg_status : t->uac[relay].last_received;
539
-			buf = build_res_buf_from_sip_req( relayed_code,
540
-				error_text(relayed_code), 0,0, /* no to-tag */
541
-				t->uas.request, &res_len );
561
+
562
+			if (relayed_code>=180 && t->uas.request->to 
563
+					&& (get_to(t->uas.request)->tag_value.s==0 
564
+			    		|| get_to(t->uas.request)->tag_value.len==0)) {
565
+				calc_crc_suffix( t->uas.request, tm_tag_suffix );
566
+				buf = build_res_buf_from_sip_req(
567
+						relayed_code,
568
+						error_text(relayed_code),
569
+						tm_tags, TOTAG_LEN, 
570
+						t->uas.request, &res_len );
571
+			} else {
572
+				buf = build_res_buf_from_sip_req( relayed_code,
573
+					error_text(relayed_code), 0,0, /* no to-tag */
574
+					t->uas.request, &res_len );
575
+			}
576
+
542 577
 		} else {
543 578
 			relayed_code=relayed_msg->REPLY_STATUS;
544 579
 			buf = build_res_buf_from_sip_res( relayed_msg, &res_len );
... ...
@@ -109,5 +109,7 @@ unsigned int get_on_negative();
109 109
 
110 110
 int t_retransmit_reply( struct cell *t );
111 111
 
112
+void tm_init_tags();
113
+
112 114
 #endif
113 115
 
... ...
@@ -338,6 +338,8 @@ static int mod_init(void)
338 338
 	register_script_cb( script_init, PRE_SCRIPT_CB , 
339 339
 			0 /* empty param */ );
340 340
 
341
+	tm_init_tags();
342
+
341 343
 	return 0;
342 344
 }
343 345
 
... ...
@@ -60,7 +60,7 @@ static inline void calc_crc_suffix( struct sip_msg *msg, char *tag_suffix)
60 60
         crcitt_string_array( tag_suffix, suffix_source, ss_nr );
61 61
 }
62 62
 
63
-static inline init_tags( char *tag, char **suffix, 
63
+static void inline init_tags( char *tag, char **suffix, 
64 64
 		char *signature, char separator )
65 65
 {
66 66
 	str src[3];