Selaa lähdekoodia

tm: added tm_ctx to collect K extension requirements

- it holds now branch index value used by $T_branch_index
- added function in TM API to access tm_ctx
Daniel-Constantin Mierla 16 vuotta sitten
vanhempi
commit
ded63f919b
6 muutettua tiedostoa jossa 58 lisäystä ja 1 poistoa
  1. 2 1
      modules/tm/t_fwd.c
  2. 21 0
      modules/tm/t_lookup.c
  3. 24 0
      modules/tm/t_lookup.h
  4. 2 0
      modules/tm/t_reply.c
  5. 4 0
      modules/tm/tm_load.c
  6. 5 0
      modules/tm/tm_load.h

+ 2 - 1
modules/tm/t_fwd.c

@@ -190,10 +190,11 @@ static char *print_uac_request( struct cell *t, struct sip_msg *i_req,
 	if (unlikely(branch_route)) {
 		     /* run branch_route actions if provided */
 		set_route_type(BRANCH_ROUTE);
-		
+		tm_ctx_set_branch_index(branch+1);
 		if (run_top_route(branch_rt.rlist[branch_route], i_req) < 0) {
 			LOG(L_ERR, "ERROR: print_uac_request: Error in run_top_route\n");
 		}
+		tm_ctx_set_branch_index(0);
 	}
 
 	/* run the specific callbacks for this transaction */

+ 21 - 0
modules/tm/t_lookup.c

@@ -1869,3 +1869,24 @@ int t_reset_max_lifetime()
 	return 1;
 }
 
+#ifdef WITH_TM_CTX
+
+tm_ctx_t _tm_ctx;
+
+tm_ctx_t* tm_ctx_get(void)
+{
+	return &_tm_ctx;
+}
+
+void tm_ctx_init(void)
+{
+	memset(&_tm_ctx, 0, sizeof(tm_ctx_t));
+}
+
+void tm_ctx_set_branch_index(int v)
+{
+	_tm_ctx.branch_index = v;
+}
+
+#endif
+

+ 24 - 0
modules/tm/t_lookup.h

@@ -123,4 +123,28 @@ typedef int (*t_get_canceled_ident_f)(struct sip_msg *msg,
 		unsigned int *hash_index, unsigned int *label);
 #endif /* WITH_AS_SUPPORT */
 
+/**
+ * required by TMX (K/O extensions)
+ */
+#define WITH_TM_CTX
+#ifdef WITH_TM_CTX
+
+typedef struct _tm_ctx {
+	int branch_index;
+} tm_ctx_t;
+
+typedef tm_ctx_t* (*tm_ctx_get_f)(void);
+
+tm_ctx_t* tm_ctx_get(void);
+void tm_ctx_init(void);
+void tm_ctx_set_branch_index(int v);
+
+#else
+
+#define tm_ctx_get()
+#define tm_ctx_init()
+#define tm_ctx_set_branch_index(v)
+
+#endif /* WITH_TM_CTX */
+
 #endif

+ 2 - 0
modules/tm/t_reply.c

@@ -1833,6 +1833,7 @@ int reply_received( struct sip_msg  *p_msg )
 	if ( (t==0)||(t==T_UNDEFINED))
 		goto trans_not_found;
 
+	tm_ctx_set_branch_index(branch);
 	cancel_bitmap=0;
 	msg_status=p_msg->REPLY_STATUS;
 
@@ -2070,6 +2071,7 @@ int reply_received( struct sip_msg  *p_msg )
 	} /* provisional replies */
 
 done:
+	tm_ctx_set_branch_index(0);
 	/* we are done with the transaction, so unref it - the reference
 	 * was incremented by t_check() function -bogdan*/
 	t_unref(p_msg);

+ 4 - 0
modules/tm/tm_load.c

@@ -233,5 +233,9 @@ int load_tm( struct tm_binds *tmb)
 	tmb->generate_fromtag = generate_fromtag;
 	tmb->t_lookup_request = t_lookup_request;
 	tmb->t_check = t_check;
+
+#ifdef WITH_TM_CTX
+	tmb->tm_ctx_get = tm_ctx_get;
+#endif
 	return 1;
 }

+ 5 - 0
modules/tm/tm_load.h

@@ -140,6 +140,11 @@ struct tm_binds {
 	generate_fromtag_f generate_fromtag;
 	tlookup_request_f t_lookup_request;
 	tcheck_f t_check;
+#ifdef WITH_TM_CTX
+	tm_ctx_get_f tm_ctx_get;
+#else
+	void* reserved5;
+#endif
 };
 
 extern int tm_init;