Browse Source

to_tags now generated all the time from TM

Jiri Kuthan 23 years ago
parent
commit
17045ca6d9
5 changed files with 49 additions and 7 deletions
  1. 3 0
      modules/tm/config.h
  2. 41 6
      modules/tm/t_reply.c
  3. 2 0
      modules/tm/t_reply.h
  4. 2 0
      modules/tm/tm.c
  5. 1 1
      tags.h

+ 3 - 0
modules/tm/config.h

@@ -94,4 +94,7 @@
 */
 */
 #undef ACK_FORKING_HACK
 #undef ACK_FORKING_HACK
 
 
+/* to-tag separator for stateful processing */
+#define TM_TAG_SEPARATOR '-'
+
 #endif
 #endif

+ 41 - 6
modules/tm/t_reply.c

@@ -38,6 +38,7 @@
 #include "../../error.h"
 #include "../../error.h"
 #include "../../action.h"
 #include "../../action.h"
 #include "../../dset.h"
 #include "../../dset.h"
+#include "../../tags.h"
 
 
 #include "t_hooks.h"
 #include "t_hooks.h"
 #include "t_funcs.h"
 #include "t_funcs.h"
@@ -49,6 +50,10 @@
 #include "fix_lumps.h"
 #include "fix_lumps.h"
 #include "t_stats.h"
 #include "t_stats.h"
 
 
+/* private place where we create to-tags for replies */
+static char tm_tags[TOTAG_LEN];
+static char *tm_tag_suffix;
+
 /* where to go if there is no positive reply */
 /* where to go if there is no positive reply */
 static int goto_on_negative=0;
 static int goto_on_negative=0;
 
 
@@ -74,6 +79,13 @@ unsigned int get_on_negative()
 	return goto_on_negative;
 	return goto_on_negative;
 }
 }
 
 
+void tm_init_tags()
+{
+	init_tags(tm_tags, &tm_tag_suffix, 
+		"SER-TM/tags", TM_TAG_SEPARATOR );
+}
+
+
 static char *build_ack(struct sip_msg* rpl,struct cell *trans,int branch,
 static char *build_ack(struct sip_msg* rpl,struct cell *trans,int branch,
 	unsigned int *ret_len)
 	unsigned int *ret_len)
 {
 {
@@ -336,9 +348,19 @@ static int _reply( struct cell *trans, struct sip_msg* p_msg,
 		trans->uas.tag->len, trans->uas.request,&len);
 		trans->uas.tag->len, trans->uas.request,&len);
 	*/
 	*/
 	cancel_bitmap=0;
 	cancel_bitmap=0;
-	/* compute the buffer in private memory prior to entering lock */
-	buf = build_res_buf_from_sip_req(code,text, 0,0, /* no to-tag */
-		p_msg,&len);
+	/* compute the buffer in private memory prior to entering lock;
+	 * create to-tag if needed */
+	if (code>=180 && p_msg->to 
+			&& (get_to(p_msg)->tag_value.s==0 
+			    || get_to(p_msg)->tag_value.len==0)) {
+		calc_crc_suffix( p_msg, tm_tag_suffix );
+		buf = build_res_buf_from_sip_req(code,text, 
+				tm_tags, TOTAG_LEN, 
+				p_msg,&len);
+	} else {
+		buf = build_res_buf_from_sip_req(code,text, 0,0, /* no to-tag */
+			p_msg,&len);
+	}
 	DBG("DEBUG: t_reply: buffer computed\n");
 	DBG("DEBUG: t_reply: buffer computed\n");
 	if (!buf)
 	if (!buf)
 	{
 	{
@@ -536,9 +558,22 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch,
 			tm_stats->replied_localy++;
 			tm_stats->replied_localy++;
 			relayed_code = branch==relay
 			relayed_code = branch==relay
 				? msg_status : t->uac[relay].last_received;
 				? msg_status : t->uac[relay].last_received;
-			buf = build_res_buf_from_sip_req( relayed_code,
-				error_text(relayed_code), 0,0, /* no to-tag */
-				t->uas.request, &res_len );
+
+			if (relayed_code>=180 && t->uas.request->to 
+					&& (get_to(t->uas.request)->tag_value.s==0 
+			    		|| get_to(t->uas.request)->tag_value.len==0)) {
+				calc_crc_suffix( t->uas.request, tm_tag_suffix );
+				buf = build_res_buf_from_sip_req(
+						relayed_code,
+						error_text(relayed_code),
+						tm_tags, TOTAG_LEN, 
+						t->uas.request, &res_len );
+			} else {
+				buf = build_res_buf_from_sip_req( relayed_code,
+					error_text(relayed_code), 0,0, /* no to-tag */
+					t->uas.request, &res_len );
+			}
+
 		} else {
 		} else {
 			relayed_code=relayed_msg->REPLY_STATUS;
 			relayed_code=relayed_msg->REPLY_STATUS;
 			buf = build_res_buf_from_sip_res( relayed_msg, &res_len );
 			buf = build_res_buf_from_sip_res( relayed_msg, &res_len );

+ 2 - 0
modules/tm/t_reply.h

@@ -109,5 +109,7 @@ unsigned int get_on_negative();
 
 
 int t_retransmit_reply( struct cell *t );
 int t_retransmit_reply( struct cell *t );
 
 
+void tm_init_tags();
+
 #endif
 #endif
 
 

+ 2 - 0
modules/tm/tm.c

@@ -338,6 +338,8 @@ static int mod_init(void)
 	register_script_cb( script_init, PRE_SCRIPT_CB , 
 	register_script_cb( script_init, PRE_SCRIPT_CB , 
 			0 /* empty param */ );
 			0 /* empty param */ );
 
 
+	tm_init_tags();
+
 	return 0;
 	return 0;
 }
 }
 
 

+ 1 - 1
tags.h

@@ -60,7 +60,7 @@ static inline void calc_crc_suffix( struct sip_msg *msg, char *tag_suffix)
         crcitt_string_array( tag_suffix, suffix_source, ss_nr );
         crcitt_string_array( tag_suffix, suffix_source, ss_nr );
 }
 }
 
 
-static inline init_tags( char *tag, char **suffix, 
+static void inline init_tags( char *tag, char **suffix, 
 		char *signature, char separator )
 		char *signature, char separator )
 {
 {
 	str src[3];
 	str src[3];