Browse Source

Merge branch 'treimann/master_tm-extend-callbacks'

* treimann/master_tm-extend-callbacks: (43 commits)
  core: new cfg parameter fork_delay
  textopsx: set the tcp clone rcvbuf on in mod init
  topoh: set the tcp clone rcvbuf on in mod init
  core: new cfg global parameter tcp_clone_rcvbuf
  app_lua: don't start if a Lua API registered module is not found
  auth: documented realm_prefix parameter
  auth: re-introduced realm_prefix parameter
  pua: is_dialog() returns 1 if there is a temporary dialog
  Makefile: added app_mono module to exclude_modules list
  app_mono: new module to run managed code embedded
  pua: check if totag len >0 before comparing it
  dispatcher: give faked msg to event routes execuition
  mediaproxy: handle DLGCB_CONFIRMED event
  pua_dialogingo: handle DLGCB_CONFIRMED_NA
  mi_rpc: fixed warning of dereferencing type-punned pointer
  modules: fixed several compile warnings
  pua(k): use dedicated function to free tm dlg
  presence(k): renamed tm dlg functions to avoid potential conflicts
  pua: free parsed rr when sending subscribes
  srdb1: schema update for address table of permissions module
  ...
Timo Reimann 13 years ago
parent
commit
00391b9f3d
8 changed files with 108 additions and 127 deletions
  1. 0 2
      modules/tm/dlg.c
  2. 3 5
      modules/tm/t_cancel.c
  3. 9 9
      modules/tm/t_fwd.c
  4. 5 5
      modules/tm/t_hooks.c
  5. 49 52
      modules/tm/t_hooks.h
  6. 37 41
      modules/tm/t_reply.c
  7. 2 4
      modules/tm/timer.c
  8. 3 9
      modules/tm/uac.c

+ 0 - 2
modules/tm/dlg.c

@@ -141,14 +141,12 @@ void run_trans_dlg_callbacks(dlg_t* dlg, struct cell* trans,
 	if (dlg->dlg_callbacks.first==0)
 	if (dlg->dlg_callbacks.first==0)
 		return;
 		return;
 	memset(&params, 0, sizeof(params));
 	memset(&params, 0, sizeof(params));
-#ifdef TMCB_ONSEND
 	if (rbuf){
 	if (rbuf){
 		params.t_rbuf=rbuf;
 		params.t_rbuf=rbuf;
 		params.dst=&rbuf->dst;
 		params.dst=&rbuf->dst;
 		params.send_buf.s=rbuf->buffer;
 		params.send_buf.s=rbuf->buffer;
 		params.send_buf.len=rbuf->buffer_len;
 		params.send_buf.len=rbuf->buffer_len;
 	}
 	}
-#endif
 	
 	
 	run_trans_callbacks_internal(&dlg->dlg_callbacks, TMCB_DLG, trans, 
 	run_trans_callbacks_internal(&dlg->dlg_callbacks, TMCB_DLG, trans, 
 									&params);
 									&params);

+ 3 - 5
modules/tm/t_cancel.c

@@ -326,14 +326,12 @@ int cancel_branch( struct cell *t, int branch,
 	crb->buffer_len = len;
 	crb->buffer_len = len;
 
 
 	DBG("DEBUG: cancel_branch: sending cancel...\n");
 	DBG("DEBUG: cancel_branch: sending cancel...\n");
-#ifdef TMCB_ONSEND
 	if (SEND_BUFFER( crb )>=0){
 	if (SEND_BUFFER( crb )>=0){
+		if (unlikely (has_tran_tmcbs(t, TMCB_REQUEST_OUT)))
+			run_trans_callbacks_with_buf(TMCB_REQUEST_OUT, crb, t->uas.request, 0, TMCB_LOCAL_F);
 		if (unlikely (has_tran_tmcbs(t, TMCB_REQUEST_SENT)))
 		if (unlikely (has_tran_tmcbs(t, TMCB_REQUEST_SENT)))
-			run_onsend_callbacks(TMCB_REQUEST_SENT, crb, 0, 0, TMCB_LOCAL_F);
+			run_trans_callbacks_with_buf(TMCB_REQUEST_SENT, crb, t->uas.request, 0, TMCB_LOCAL_F);
 	}
 	}
-#else
-	SEND_BUFFER( crb );
-#endif
 	/*sets and starts the FINAL RESPONSE timer */
 	/*sets and starts the FINAL RESPONSE timer */
 	if (start_retr( crb )!=0)
 	if (start_retr( crb )!=0)
 		LOG(L_CRIT, "BUG: cancel_branch: failed to start retransmission"
 		LOG(L_CRIT, "BUG: cancel_branch: failed to start retransmission"

+ 9 - 9
modules/tm/t_fwd.c

@@ -1192,14 +1192,12 @@ void e2e_cancel( struct sip_msg *cancel_msg,
 				if (SEND_BUFFER(&t_cancel->uac[i].request) == -1) {
 				if (SEND_BUFFER(&t_cancel->uac[i].request) == -1) {
 					LOG(L_ERR, "ERROR: e2e_cancel: send failed\n");
 					LOG(L_ERR, "ERROR: e2e_cancel: send failed\n");
 				}
 				}
-#ifdef TMCB_ONSEND
 				else{
 				else{
 					if (unlikely(has_tran_tmcbs(t_cancel, TMCB_REQUEST_SENT)))
 					if (unlikely(has_tran_tmcbs(t_cancel, TMCB_REQUEST_SENT)))
-						run_onsend_callbacks(TMCB_REQUEST_SENT, 
-												&t_cancel->uac[i].request,
-												cancel_msg, 0, TMCB_LOCAL_F);
+						run_trans_callbacks_with_buf(TMCB_REQUEST_SENT,
+						                             &t_cancel->uac[i].request,
+						                             cancel_msg, 0, TMCB_LOCAL_F);
 				}
 				}
-#endif
 				if (start_retr( &t_cancel->uac[i].request )!=0)
 				if (start_retr( &t_cancel->uac[i].request )!=0)
 					LOG(L_CRIT, "BUG: e2e_cancel: failed to start retr."
 					LOG(L_CRIT, "BUG: e2e_cancel: failed to start retr."
 							" for %p\n", &t_cancel->uac[i].request);
 							" for %p\n", &t_cancel->uac[i].request);
@@ -1386,10 +1384,8 @@ int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg ,
 		if (proxy) { proxy->errors++; proxy->ok=0; }
 		if (proxy) { proxy->errors++; proxy->ok=0; }
 		return -2;
 		return -2;
 	} else {
 	} else {
-#ifdef TMCB_ONSEND
 		if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT)))
 		if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT)))
-			run_onsend_callbacks(TMCB_REQUEST_SENT, &uac->request, p_msg, 0,0);
-#endif
+			run_trans_callbacks_with_buf(TMCB_REQUEST_SENT, &uac->request, p_msg, 0,0);
 		/* start retr. only if the send succeeded */
 		/* start retr. only if the send succeeded */
 		if (start_retr( &uac->request )!=0){
 		if (start_retr( &uac->request )!=0){
 			LOG(L_CRIT, "BUG: t_send_branch: retr. already started for %p\n",
 			LOG(L_CRIT, "BUG: t_send_branch: retr. already started for %p\n",
@@ -1550,8 +1546,12 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
 			
 			
 			branch_ret=t_send_branch(t, i, p_msg , proxy, lock_replies);
 			branch_ret=t_send_branch(t, i, p_msg , proxy, lock_replies);
 			if (branch_ret>=0){ /* some kind of success */
 			if (branch_ret>=0){ /* some kind of success */
-				if (branch_ret==i) /* success */
+				if (branch_ret==i) { /* success */
 					success_branch++;
 					success_branch++;
+					if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_OUT)))
+						run_trans_callbacks_with_buf( TMCB_REQUEST_OUT, &t->uac[i].request,
+						                              p_msg, 0, -p_msg->REQ_METHOD);
+				}
 				else /* new branch added */
 				else /* new branch added */
 					added_branches |= 1<<branch_ret;
 					added_branches |= 1<<branch_ret;
 			}
 			}

+ 5 - 5
modules/tm/t_hooks.c

@@ -319,9 +319,9 @@ void run_trans_callbacks( int type , struct cell *trans,
 
 
 
 
 
 
-#ifdef TMCB_ONSEND
-void run_onsend_callbacks(int type, struct retr_buf* rbuf,
-					struct sip_msg* req, struct sip_msg* repl, short flags)
+void run_trans_callbacks_with_buf(int type, struct retr_buf* rbuf,
+                                  struct sip_msg* req, struct sip_msg* repl,
+                                  short flags)
 {
 {
 	struct tmcb_params params;
 	struct tmcb_params params;
 	struct cell * trans;
 	struct cell * trans;
@@ -337,7 +337,8 @@ void run_onsend_callbacks(int type, struct retr_buf* rbuf,
 }
 }
 
 
 
 
-void run_onsend_callbacks2(int type, struct cell* trans, struct tmcb_params* p)
+void run_trans_callbacks_off_params(int type, struct cell* trans,
+                                    struct tmcb_params* p)
 {
 {
 
 
 	if (p->t_rbuf==0) return;
 	if (p->t_rbuf==0) return;
@@ -347,7 +348,6 @@ void run_onsend_callbacks2(int type, struct cell* trans, struct tmcb_params* p)
 	run_trans_callbacks_internal(&trans->tmcb_hl, type, p->t_rbuf->my_T, p);
 	run_trans_callbacks_internal(&trans->tmcb_hl, type, p->t_rbuf->my_T, p);
 }
 }
 
 
-#endif
 
 
 static void run_reqin_callbacks_internal(struct tmcb_head_list* hl,
 static void run_reqin_callbacks_internal(struct tmcb_head_list* hl,
 							struct cell *trans, struct tmcb_params* params)
 							struct cell *trans, struct tmcb_params* params)

+ 49 - 52
modules/tm/t_hooks.h

@@ -46,12 +46,12 @@
 
 
 #include "defs.h"
 #include "defs.h"
 
 
-/* if defined support for ONSEND callbacks will be added and
- * the tmcb_params structure will get some additional members */
+/* TMCB_ONSEND used to enable certain callback-related features when
+ * ONSEND was set, these days it's always enabled. For compatibility
+ * reasons with modules that check ONSEND, continue to set it
+ * unconditionally*/
 #define TMCB_ONSEND
 #define TMCB_ONSEND
-#ifdef TMCB_ONSEND
 #include "../../ip_addr.h" /* dest_info */
 #include "../../ip_addr.h" /* dest_info */
-#endif
 
 
 struct sip_msg;
 struct sip_msg;
 struct cell;
 struct cell;
@@ -59,41 +59,41 @@ struct cell;
 #define TMCB_REQUEST_IN_N       0
 #define TMCB_REQUEST_IN_N       0
 #define TMCB_RESPONSE_IN_N      1
 #define TMCB_RESPONSE_IN_N      1
 #define TMCB_E2EACK_IN_N        2
 #define TMCB_E2EACK_IN_N        2
-#define TMCB_REQUEST_FWDED_N    3
-#define TMCB_RESPONSE_FWDED_N   4
-#define TMCB_ON_FAILURE_RO_N    5
-#define TMCB_ON_FAILURE_N       6
-#define TMCB_RESPONSE_OUT_N     7
-#define TMCB_LOCAL_COMPLETED_N  8
-#define TMCB_LOCAL_RESPONSE_OUT_N 9
-#define TMCB_ACK_NEG_IN_N       10
-#define TMCB_REQ_RETR_IN_N      11
-#define TMCB_LOCAL_RESPONSE_IN_N 12
-#define TMCB_LOCAL_REQUEST_IN_N  13
-#define TMCB_DLG_N              14
-#define TMCB_DESTROY_N          15  /* called on transaction destroy */
-#define TMCB_E2ECANCEL_IN_N     16
-#define TMCB_E2EACK_RETR_IN_N   17
-#define TMCB_RESPONSE_READY_N	18
+#define TMCB_REQUEST_PENDING_N  3
+#define TMCB_REQUEST_FWDED_N    4
+#define TMCB_RESPONSE_FWDED_N   5
+#define TMCB_ON_FAILURE_RO_N    6
+#define TMCB_ON_FAILURE_N       7
+#define TMCB_REQUEST_OUT_N      8
+#define TMCB_RESPONSE_OUT_N     9
+#define TMCB_LOCAL_COMPLETED_N  10
+#define TMCB_LOCAL_RESPONSE_OUT_N 11
+#define TMCB_ACK_NEG_IN_N       12
+#define TMCB_REQ_RETR_IN_N      13
+#define TMCB_LOCAL_RESPONSE_IN_N 14
+#define TMCB_LOCAL_REQUEST_IN_N  15
+#define TMCB_DLG_N              16
+#define TMCB_DESTROY_N          17  /* called on transaction destroy */
+#define TMCB_E2ECANCEL_IN_N     18
+#define TMCB_E2EACK_RETR_IN_N   19
+#define TMCB_RESPONSE_READY_N	20
 #ifdef WITH_AS_SUPPORT
 #ifdef WITH_AS_SUPPORT
-#define TMCB_DONT_ACK_N         19 /* TM shoudn't ACK a local UAC  */
-#endif
-#ifdef TMCB_ONSEND
-#define TMCB_REQUEST_SENT_N     20
-#define TMCB_RESPONSE_SENT_N    21
-#define TMCB_MAX_N              21
-#else
-#define TMCB_MAX_N              19
+#define TMCB_DONT_ACK_N         21 /* TM shoudn't ACK a local UAC  */
 #endif
 #endif
+#define TMCB_REQUEST_SENT_N     22
+#define TMCB_RESPONSE_SENT_N    23
+#define TMCB_MAX_N              23
 
 
 
 
 #define TMCB_REQUEST_IN       (1<<TMCB_REQUEST_IN_N)
 #define TMCB_REQUEST_IN       (1<<TMCB_REQUEST_IN_N)
 #define TMCB_RESPONSE_IN      (1<<TMCB_RESPONSE_IN_N)
 #define TMCB_RESPONSE_IN      (1<<TMCB_RESPONSE_IN_N)
 #define TMCB_E2EACK_IN        (1<<TMCB_E2EACK_IN_N)
 #define TMCB_E2EACK_IN        (1<<TMCB_E2EACK_IN_N)
+#define TMCB_REQUEST_PENDING  (1<<TMCB_REQUEST_PENDING_N)
 #define TMCB_REQUEST_FWDED    (1<<TMCB_REQUEST_FWDED_N)
 #define TMCB_REQUEST_FWDED    (1<<TMCB_REQUEST_FWDED_N)
 #define TMCB_RESPONSE_FWDED   (1<<TMCB_RESPONSE_FWDED_N)
 #define TMCB_RESPONSE_FWDED   (1<<TMCB_RESPONSE_FWDED_N)
 #define TMCB_ON_FAILURE_RO    (1<<TMCB_ON_FAILURE_RO_N)
 #define TMCB_ON_FAILURE_RO    (1<<TMCB_ON_FAILURE_RO_N)
 #define TMCB_ON_FAILURE       (1<<TMCB_ON_FAILURE_N)
 #define TMCB_ON_FAILURE       (1<<TMCB_ON_FAILURE_N)
+#define TMCB_REQUEST_OUT      (1<<TMCB_REQUEST_OUT_N)
 #define TMCB_RESPONSE_OUT     (1<<TMCB_RESPONSE_OUT_N)
 #define TMCB_RESPONSE_OUT     (1<<TMCB_RESPONSE_OUT_N)
 #define TMCB_LOCAL_COMPLETED  (1<<TMCB_LOCAL_COMPLETED_N)
 #define TMCB_LOCAL_COMPLETED  (1<<TMCB_LOCAL_COMPLETED_N)
 #define TMCB_LOCAL_RESPONSE_OUT (1<<TMCB_LOCAL_RESPONSE_OUT_N)
 #define TMCB_LOCAL_RESPONSE_OUT (1<<TMCB_LOCAL_RESPONSE_OUT_N)
@@ -109,10 +109,8 @@ struct cell;
 #ifdef WITH_AS_SUPPORT
 #ifdef WITH_AS_SUPPORT
 #define TMCB_DONT_ACK         (1<<TMCB_DONT_ACK_N)
 #define TMCB_DONT_ACK         (1<<TMCB_DONT_ACK_N)
 #endif
 #endif
-#ifdef TMCB_ONSEND
 #define TMCB_REQUEST_SENT      (1<<TMCB_REQUEST_SENT_N)
 #define TMCB_REQUEST_SENT      (1<<TMCB_REQUEST_SENT_N)
 #define TMCB_RESPONSE_SENT     (1<<TMCB_RESPONSE_SENT_N)
 #define TMCB_RESPONSE_SENT     (1<<TMCB_RESPONSE_SENT_N)
-#endif
 #define TMCB_MAX              ((1<<(TMCB_MAX_N+1))-1)
 #define TMCB_MAX              ((1<<(TMCB_MAX_N+1))-1)
 
 
 
 
@@ -248,6 +246,12 @@ struct cell;
  *   router (via t_relay/t_forward_nonack) and in this case the REPLY lock 
  *   router (via t_relay/t_forward_nonack) and in this case the REPLY lock 
  *   will be held.
  *   will be held.
  *
  *
+ *  TMCB_REQUEST_OUT -- request was sent out successfully.
+ *  There is nothing more you can change from the callback, it is good for
+ *  accounting-like uses.
+ *  Note: if the send fails or via cannot be resolved, this callback is
+ *  _not_ called.
+ *
  *  TMCB_LOCAL_COMPLETED -- final reply for localy initiated
  *  TMCB_LOCAL_COMPLETED -- final reply for localy initiated
  *  transaction arrived. Message may be FAKED_REPLY. Can be called multiple
  *  transaction arrived. Message may be FAKED_REPLY. Can be called multiple
  *  times, no lock is held.
  *  times, no lock is held.
@@ -294,17 +298,15 @@ struct cell;
  *  t_uac.
  *  t_uac.
  *   For a reply the code is the response status (which is always >0, e.g. 200,
  *   For a reply the code is the response status (which is always >0, e.g. 200,
  *   408, a.s.o).
  *   408, a.s.o).
- *  Note: - these callbacks can be used only if TMCB_ONSEND is defined.
  *        - the callbacks will be called sometimes with the REPLY lock held
  *        - the callbacks will be called sometimes with the REPLY lock held
  *          and sometimes without it, so trying to acquire the REPLY lock
  *          and sometimes without it, so trying to acquire the REPLY lock
  *          from these callbacks could lead to deadlocks (avoid it unless
  *          from these callbacks could lead to deadlocks (avoid it unless
  *           you really know what you're doing).
  *           you really know what you're doing).
  *
  *
- *  TMCB_REQUEST_SENT (present only if TMCB_ONSEND is defined) -- called 
- *  each time a request was sent (even for retransmissions), it includes 
- *  local and forwarded request, ser generated CANCELs and ACKs. The 
- *  tmcb_params structure will have the t_rbuf, dst, send_buf and is_retr
- *  members  filled.
+ *  TMCB_REQUEST_SENT -- called each time a request was sent (even for
+ *  retransmissions), it includes local and forwarded request, ser generated
+ *  CANCELs and ACKs. The tmcb_params structure will have the t_rbuf, dst,
+ *  send_buf and is_retr members filled.
  *  This callback is "read-only", the message was already sent and no changes
  *  This callback is "read-only", the message was already sent and no changes
  *  are allowed.
  *  are allowed.
  *  Note: send_buf can be different from t_rbuf->buffer for ACKs (in this
  *  Note: send_buf can be different from t_rbuf->buffer for ACKs (in this
@@ -312,11 +314,11 @@ struct cell;
  *   its destination). The same goes for t_rbuf->dst and tmcb->dst for local 
  *   its destination). The same goes for t_rbuf->dst and tmcb->dst for local 
  *   transactions ACKs to 2xxs.
  *   transactions ACKs to 2xxs.
  *
  *
- *  TMCB_RESPONSE_SENT  (present only if TMCB_ONSEND is defined) -- called 
- *  each time a response was sent (even for retransmissions). The tmcb_params
- *   structure will have t_rbuf set to the reply retransmission buffer and
- *   send_buf set to the data sent (in this case it will always be the same 
- *   with t_rbuf->buf). is_retr will also be set if the reply is retransmitted
+ *  TMCB_RESPONSE_SENT -- called each time a response was sent (even for
+ *  retransmissions). The tmcb_params structure will have t_rbuf set to the
+ *  reply retransmission buffer and send_buf set to the data sent (in this case
+ *  it will always be the same with t_rbuf->buf). is_retr will also be set if
+ *  the reply is retransmitted
  *   by ser.
  *   by ser.
  *  This callback is "read-only", the message was already sent and no changes
  *  This callback is "read-only", the message was already sent and no changes
  *  are allowed.
  *  are allowed.
@@ -343,10 +345,8 @@ struct cell;
 	).
 	).
 */
 */
 
 
-#ifdef TMCB_ONSEND
 #define TMCB_RETR_F 1
 #define TMCB_RETR_F 1
 #define TMCB_LOCAL_F 2
 #define TMCB_LOCAL_F 2
-#endif
 
 
 /* pack structure with all params passed to callback function */
 /* pack structure with all params passed to callback function */
 struct tmcb_params {
 struct tmcb_params {
@@ -354,7 +354,6 @@ struct tmcb_params {
 	struct sip_msg* rpl;
 	struct sip_msg* rpl;
 	void **param;
 	void **param;
 	int code;
 	int code;
-#ifdef TMCB_ONSEND
 	unsigned short flags; /* set to a combination of:
 	unsigned short flags; /* set to a combination of:
 							 TMCB_RETR_F if this is a _ser_ retransmission
 							 TMCB_RETR_F if this is a _ser_ retransmission
 							 (but not if if it's a "forwarded" retr., like a 
 							 (but not if if it's a "forwarded" retr., like a 
@@ -370,7 +369,6 @@ struct tmcb_params {
 	struct dest_info* dst; /* destination */
 	struct dest_info* dst; /* destination */
 	str send_buf; /* what was/will be sent on the net, used for ACKs
 	str send_buf; /* what was/will be sent on the net, used for ACKs
 					(which don't have a retr_buf). */
 					(which don't have a retr_buf). */
-#endif
 };
 };
 
 
 #define INIT_TMCB_PARAMS(tmcb, request, reply, r_code)\
 #define INIT_TMCB_PARAMS(tmcb, request, reply, r_code)\
@@ -380,7 +378,6 @@ do{\
 	(tmcb).code=(r_code); \
 	(tmcb).code=(r_code); \
 }while(0)
 }while(0)
 
 
-#ifdef TMCB_ONSEND
 #define INIT_TMCB_ONSEND_PARAMS(tmcb, req, repl, rbuf, dest, buf, buf_len, \
 #define INIT_TMCB_ONSEND_PARAMS(tmcb, req, repl, rbuf, dest, buf, buf_len, \
 								onsend_flags, t_branch, code) \
 								onsend_flags, t_branch, code) \
 do{ \
 do{ \
@@ -389,7 +386,6 @@ do{ \
 	tmcb.send_buf.s=(buf); tmcb.send_buf.len=(buf_len); \
 	tmcb.send_buf.s=(buf); tmcb.send_buf.len=(buf_len); \
 	tmcb.flags=(onsend_flags); tmcb.branch=(t_branch); \
 	tmcb.flags=(onsend_flags); tmcb.branch=(t_branch); \
 }while(0)
 }while(0)
-#endif
 
 
 /* callback function prototype */
 /* callback function prototype */
 typedef void (transaction_cb) (struct cell* t, int type, struct tmcb_params*);
 typedef void (transaction_cb) (struct cell* t, int type, struct tmcb_params*);
@@ -458,11 +454,12 @@ void run_reqin_callbacks( struct cell *trans, struct sip_msg *req, int code );
 void run_local_reqin_callbacks( struct cell *trans, struct sip_msg *req, 
 void run_local_reqin_callbacks( struct cell *trans, struct sip_msg *req, 
 		int code );
 		int code );
 
 
-#ifdef TMCB_ONSEND
+/* like run_trans_callbacks but provide outgoing buffer (i.e., the
+ * processed message) to callback */
+void run_trans_callbacks_with_buf(int type, struct retr_buf* rbuf, struct sip_msg* req,
+								  struct sip_msg* repl, short flags);
 
 
-void run_onsend_callbacks(int type, struct retr_buf* rbuf, struct sip_msg* req,
-									struct sip_msg* repl, short flags);
-void run_onsend_callbacks2(int type, struct cell* t, struct tmcb_params* p);
-#endif
+/* like run_trans_callbacks but tmcb_params assumed to contain data already */
+void run_trans_callbacks_off_params(int type, struct cell* t, struct tmcb_params* p);
 
 
 #endif
 #endif

+ 37 - 41
modules/tm/t_reply.c

@@ -564,9 +564,7 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len,
 	struct retr_buf *rb;
 	struct retr_buf *rb;
 	unsigned int buf_len;
 	unsigned int buf_len;
 	struct cancel_info cancel_data;
 	struct cancel_info cancel_data;
-#ifdef TMCB_ONSEND
 	struct tmcb_params onsend_params;
 	struct tmcb_params onsend_params;
-#endif
 
 
 	init_cancel_info(&cancel_data);
 	init_cancel_info(&cancel_data);
 	if (!buf)
 	if (!buf)
@@ -619,7 +617,7 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len,
 									0, FAKED_REPLY, code);
 									0, FAKED_REPLY, code);
 		} else {
 		} else {
 			if(unlikely(has_tran_tmcbs(trans, TMCB_RESPONSE_READY))) {
 			if(unlikely(has_tran_tmcbs(trans, TMCB_RESPONSE_READY))) {
-				run_trans_callbacks(TMCB_RESPONSE_READY, trans,
+				run_trans_callbacks_with_buf(TMCB_RESPONSE_READY, rb,
 					trans->uas.request, FAKED_REPLY, code);
 					trans->uas.request, FAKED_REPLY, code);
 			}
 			}
 		}
 		}
@@ -634,6 +632,12 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len,
 		start_final_repl_retr(  trans );
 		start_final_repl_retr(  trans );
 	}
 	}
 
 
+	if (code==100) {
+		if(unlikely(has_tran_tmcbs(trans, TMCB_REQUEST_PENDING)))
+			run_trans_callbacks_with_buf(TMCB_REQUEST_PENDING, rb,
+					trans->uas.request, FAKED_REPLY, code);
+	}
+
 	/* send it out */
 	/* send it out */
 	/* first check if we managed to resolve topmost Via -- if
 	/* first check if we managed to resolve topmost Via -- if
 	   not yet, don't try to retransmit
 	   not yet, don't try to retransmit
@@ -650,18 +654,20 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len,
 	} else {
 	} else {
 		if (likely(SEND_PR_BUFFER( rb, buf, len )>=0)){
 		if (likely(SEND_PR_BUFFER( rb, buf, len )>=0)){
 			if (unlikely(code>=200 && !is_local(trans) &&
 			if (unlikely(code>=200 && !is_local(trans) &&
-						has_tran_tmcbs(trans, TMCB_RESPONSE_OUT)) )
-				run_trans_callbacks(TMCB_RESPONSE_OUT, trans,
-									trans->uas.request, FAKED_REPLY, code);
-#ifdef TMCB_ONSEND
+						has_tran_tmcbs(trans, TMCB_RESPONSE_OUT)) ){
+				INIT_TMCB_ONSEND_PARAMS(onsend_params, trans->uas.request,
+								FAKED_REPLY, rb, &rb->dst,
+								buf, len, TMCB_LOCAL_F, rb->branch, code);
+				run_trans_callbacks_off_params(TMCB_RESPONSE_OUT, trans,
+				                               &onsend_params);
+			}
 			if (unlikely(has_tran_tmcbs(trans, TMCB_RESPONSE_SENT))){
 			if (unlikely(has_tran_tmcbs(trans, TMCB_RESPONSE_SENT))){
 				INIT_TMCB_ONSEND_PARAMS(onsend_params, trans->uas.request,
 				INIT_TMCB_ONSEND_PARAMS(onsend_params, trans->uas.request,
 								FAKED_REPLY, rb, &rb->dst, 
 								FAKED_REPLY, rb, &rb->dst, 
 								buf, len, TMCB_LOCAL_F, rb->branch, code);
 								buf, len, TMCB_LOCAL_F, rb->branch, code);
-				run_onsend_callbacks2(TMCB_RESPONSE_SENT, trans,
-										&onsend_params);
+				run_trans_callbacks_off_params(TMCB_RESPONSE_SENT, trans,
+				                               &onsend_params);
 			}
 			}
-#endif /* TMCB_ONSEND */
 		}
 		}
 		DBG("DEBUG: reply sent out. buf=%p: %.20s..., shmem=%p: %.20s\n",
 		DBG("DEBUG: reply sent out. buf=%p: %.20s..., shmem=%p: %.20s\n",
 			buf, buf, rb->buffer, rb->buffer );
 			buf, buf, rb->buffer, rb->buffer );
@@ -1457,14 +1463,12 @@ int t_retransmit_reply( struct cell *t )
 	memcpy( b, t->uas.response.buffer, len );
 	memcpy( b, t->uas.response.buffer, len );
 	UNLOCK_REPLIES( t );
 	UNLOCK_REPLIES( t );
 	SEND_PR_BUFFER( & t->uas.response, b, len );
 	SEND_PR_BUFFER( & t->uas.response, b, len );
-#ifdef TMCB_ONSEND
 	if (unlikely(has_tran_tmcbs(t, TMCB_RESPONSE_SENT))){ 
 	if (unlikely(has_tran_tmcbs(t, TMCB_RESPONSE_SENT))){ 
 		/* we don't know if it's a retransmission of a local reply or a 
 		/* we don't know if it's a retransmission of a local reply or a 
 		 * forwarded reply */
 		 * forwarded reply */
-		run_onsend_callbacks(TMCB_RESPONSE_SENT, &t->uas.response, 0, 0,
-								TMCB_RETR_F);
+		run_trans_callbacks_with_buf(TMCB_RESPONSE_SENT, &t->uas.response, 0, 0,
+		                             TMCB_RETR_F);
 	}
 	}
-#endif
 	DBG("DEBUG: reply retransmitted. buf=%p: %.9s..., shmem=%p: %.9s\n",
 	DBG("DEBUG: reply retransmitted. buf=%p: %.9s..., shmem=%p: %.9s\n",
 		b, b, t->uas.response.buffer, t->uas.response.buffer );
 		b, b, t->uas.response.buffer, t->uas.response.buffer );
 	return 1;
 	return 1;
@@ -1648,9 +1652,7 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch,
 	struct retr_buf *uas_rb;
 	struct retr_buf *uas_rb;
 	str* to_tag;
 	str* to_tag;
 	str reason;
 	str reason;
-#ifdef TMCB_ONSEND
 	struct tmcb_params onsend_params;
 	struct tmcb_params onsend_params;
-#endif
 
 
 	/* keep compiler warnings about use of uninit vars silent */
 	/* keep compiler warnings about use of uninit vars silent */
 	res_len=0;
 	res_len=0;
@@ -1824,7 +1826,7 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch,
 	/* send it now (from the private buffer) */
 	/* send it now (from the private buffer) */
 	if (relay >= 0) {
 	if (relay >= 0) {
 		if (unlikely(!totag_retr && has_tran_tmcbs(t, TMCB_RESPONSE_READY))){
 		if (unlikely(!totag_retr && has_tran_tmcbs(t, TMCB_RESPONSE_READY))){
-			run_trans_callbacks(TMCB_RESPONSE_READY, t,
+			run_trans_callbacks_with_buf(TMCB_RESPONSE_READY, uas_rb,
 					t->uas.request, relayed_msg, relayed_code);
 					t->uas.request, relayed_msg, relayed_code);
 		}
 		}
 		/* Set retransmission timer before the reply is sent out to avoid
 		/* Set retransmission timer before the reply is sent out to avoid
@@ -1841,19 +1843,17 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch,
 		if (likely(uas_rb->dst.send_sock &&
 		if (likely(uas_rb->dst.send_sock &&
 					SEND_PR_BUFFER( uas_rb, buf, res_len ) >= 0)){
 					SEND_PR_BUFFER( uas_rb, buf, res_len ) >= 0)){
 			if (unlikely(!totag_retr && has_tran_tmcbs(t, TMCB_RESPONSE_OUT))){
 			if (unlikely(!totag_retr && has_tran_tmcbs(t, TMCB_RESPONSE_OUT))){
-				run_trans_callbacks( TMCB_RESPONSE_OUT, t, t->uas.request,
-					relayed_msg, relayed_code);
+				run_trans_callbacks_with_buf( TMCB_RESPONSE_OUT, uas_rb, t->uas.request,
+				                              relayed_msg, relayed_code);
 			}
 			}
-#ifdef TMCB_ONSEND
 			if (unlikely(has_tran_tmcbs(t, TMCB_RESPONSE_SENT))){
 			if (unlikely(has_tran_tmcbs(t, TMCB_RESPONSE_SENT))){
 				INIT_TMCB_ONSEND_PARAMS(onsend_params, t->uas.request,
 				INIT_TMCB_ONSEND_PARAMS(onsend_params, t->uas.request,
 									relayed_msg, uas_rb, &uas_rb->dst, buf,
 									relayed_msg, uas_rb, &uas_rb->dst, buf,
 									res_len,
 									res_len,
 									(relayed_msg==FAKED_REPLY)?TMCB_LOCAL_F:0,
 									(relayed_msg==FAKED_REPLY)?TMCB_LOCAL_F:0,
 									uas_rb->branch, relayed_code);
 									uas_rb->branch, relayed_code);
-				run_onsend_callbacks2(TMCB_RESPONSE_SENT, t, &onsend_params);
+				run_trans_callbacks_off_params(TMCB_RESPONSE_SENT, t, &onsend_params);
 			}
 			}
-#endif
 		} else if (unlikely(uas_rb->dst.send_sock == 0))
 		} else if (unlikely(uas_rb->dst.send_sock == 0))
 			ERR("no resolved dst to send reply to\n");
 			ERR("no resolved dst to send reply to\n");
 		/* Call put_on_wait() only if we really send out
 		/* Call put_on_wait() only if we really send out
@@ -2026,9 +2026,7 @@ int reply_received( struct sip_msg  *p_msg )
 	int blst_503_timeout;
 	int blst_503_timeout;
 	struct hdr_field* hf;
 	struct hdr_field* hf;
 #endif
 #endif
-#ifdef TMCB_ONSEND
 	struct tmcb_params onsend_params;
 	struct tmcb_params onsend_params;
-#endif
 	struct run_act_ctx ctx;
 	struct run_act_ctx ctx;
 
 
 	/* make sure we know the associated transaction ... */
 	/* make sure we know the associated transaction ... */
@@ -2087,19 +2085,23 @@ int reply_received( struct sip_msg  *p_msg )
 			if (msg_status >= 300) {
 			if (msg_status >= 300) {
 				ack = build_ack(p_msg, t, branch, &ack_len);
 				ack = build_ack(p_msg, t, branch, &ack_len);
 				if (ack) {
 				if (ack) {
-#ifdef	TMCB_ONSEND
 					if (SEND_PR_BUFFER(&uac->request, ack, ack_len)>=0)
 					if (SEND_PR_BUFFER(&uac->request, ack, ack_len)>=0)
 						if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))){ 
 						if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))){ 
 							INIT_TMCB_ONSEND_PARAMS(onsend_params, 
 							INIT_TMCB_ONSEND_PARAMS(onsend_params, 
 									t->uas.request, p_msg, &uac->request,
 									t->uas.request, p_msg, &uac->request,
 									&uac->request.dst, ack, ack_len,
 									&uac->request.dst, ack, ack_len,
 									TMCB_LOCAL_F, branch, TYPE_LOCAL_ACK);
 									TMCB_LOCAL_F, branch, TYPE_LOCAL_ACK);
-							run_onsend_callbacks2(TMCB_REQUEST_SENT, t,
-													&onsend_params);
+							run_trans_callbacks_off_params(TMCB_REQUEST_SENT, t,
+							                               &onsend_params);
+						}
+						if (unlikely(has_tran_tmcbs(t, TMCB_ACK_NEG_IN))){
+							INIT_TMCB_ONSEND_PARAMS(onsend_params,
+									t->uas.request, p_msg, &uac->request,
+									&uac->request.dst, ack, ack_len,
+									TMCB_LOCAL_F, branch, TYPE_LOCAL_ACK);
+							run_trans_callbacks_off_params(TMCB_ACK_NEG_IN, t,
+							                               &onsend_params);
 						}
 						}
-#else
-					SEND_PR_BUFFER(&uac->request, ack, ack_len);
-#endif
 					shm_free(ack);
 					shm_free(ack);
 				}
 				}
 			} else if (is_local(t) /*&& 200 <= msg_status < 300*/) {
 			} else if (is_local(t) /*&& 200 <= msg_status < 300*/) {
@@ -2107,16 +2109,14 @@ int reply_received( struct sip_msg  *p_msg )
 				if (ack) {
 				if (ack) {
 					if (msg_send(&lack_dst, ack, ack_len)<0)
 					if (msg_send(&lack_dst, ack, ack_len)<0)
 						LOG(L_ERR, "Error while sending local ACK\n");
 						LOG(L_ERR, "Error while sending local ACK\n");
-#ifdef	TMCB_ONSEND
 					else if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))){
 					else if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))){
 							INIT_TMCB_ONSEND_PARAMS(onsend_params, 
 							INIT_TMCB_ONSEND_PARAMS(onsend_params, 
 									t->uas.request, p_msg, &uac->request,
 									t->uas.request, p_msg, &uac->request,
 									&lack_dst, ack, ack_len, TMCB_LOCAL_F,
 									&lack_dst, ack, ack_len, TMCB_LOCAL_F,
 									branch, TYPE_LOCAL_ACK);
 									branch, TYPE_LOCAL_ACK);
-							run_onsend_callbacks2(TMCB_REQUEST_SENT, t,
-													&onsend_params);
+							run_trans_callbacks_off_params(TMCB_REQUEST_SENT, t,
+							                               &onsend_params);
 					}
 					}
-#endif
 #ifndef WITH_AS_SUPPORT
 #ifndef WITH_AS_SUPPORT
 					shm_free(ack);
 					shm_free(ack);
 #endif
 #endif
@@ -2132,16 +2132,12 @@ int reply_received( struct sip_msg  *p_msg )
 								  local_cancel */
 								  local_cancel */
 				/* re-transmit if cancel already built */
 				/* re-transmit if cancel already built */
 				DBG("tm: reply_received: branch CANCEL retransmit\n");
 				DBG("tm: reply_received: branch CANCEL retransmit\n");
-#ifdef TMCB_ONSEND
 				if (SEND_BUFFER( &uac->local_cancel)>=0){
 				if (SEND_BUFFER( &uac->local_cancel)>=0){
 					if (unlikely (has_tran_tmcbs(t, TMCB_REQUEST_SENT)))
 					if (unlikely (has_tran_tmcbs(t, TMCB_REQUEST_SENT)))
-						run_onsend_callbacks(TMCB_REQUEST_SENT,
-											&uac->local_cancel,
-											0, 0, TMCB_LOCAL_F);
+						run_trans_callbacks_with_buf(TMCB_REQUEST_SENT,
+						                             &uac->local_cancel,
+						                             0, 0, TMCB_LOCAL_F);
 				}
 				}
-#else
-				SEND_BUFFER( &uac->local_cancel );
-#endif
 				/* retrs. should be already started so do nothing */
 				/* retrs. should be already started so do nothing */
 			}else if (atomic_cmpxchg_long((void*)&uac->local_cancel.buffer, 0,
 			}else if (atomic_cmpxchg_long((void*)&uac->local_cancel.buffer, 0,
 										(long)BUSY_BUFFER)==0){
 										(long)BUSY_BUFFER)==0){

+ 2 - 4
modules/tm/timer.c

@@ -392,11 +392,9 @@ inline static ticks_t retransmission_handler( struct retr_buf *r_buf )
 				fake_reply(r_buf->my_T, r_buf->branch, 503 );
 				fake_reply(r_buf->my_T, r_buf->branch, 503 );
 				return (ticks_t)-1;
 				return (ticks_t)-1;
 			}
 			}
-#ifdef TMCB_ONSEND
 			if (unlikely(has_tran_tmcbs(r_buf->my_T, TMCB_REQUEST_SENT))) 
 			if (unlikely(has_tran_tmcbs(r_buf->my_T, TMCB_REQUEST_SENT))) 
-				run_onsend_callbacks(TMCB_REQUEST_SENT, r_buf, 
-										0, 0, TMCB_RETR_F);
-#endif
+				run_trans_callbacks_with_buf(TMCB_REQUEST_SENT, r_buf, 
+				0, 0, TMCB_RETR_F);
 	} else {
 	} else {
 #ifdef EXTRA_DEBUG
 #ifdef EXTRA_DEBUG
 			DBG("DEBUG: retransmission_handler : "
 			DBG("DEBUG: retransmission_handler : "

+ 3 - 9
modules/tm/uac.c

@@ -495,12 +495,10 @@ static inline void send_prepared_request_impl(struct retr_buf *request, int retr
 	if (SEND_BUFFER(request) == -1) {
 	if (SEND_BUFFER(request) == -1) {
 		LOG(L_ERR, "t_uac: Attempt to send to precreated request failed\n");
 		LOG(L_ERR, "t_uac: Attempt to send to precreated request failed\n");
 	}
 	}
-#ifdef TMCB_ONSEND
 	else if (unlikely(has_tran_tmcbs(request->my_T, TMCB_REQUEST_SENT)))
 	else if (unlikely(has_tran_tmcbs(request->my_T, TMCB_REQUEST_SENT)))
 		/* we don't know the method here */
 		/* we don't know the method here */
-			run_onsend_callbacks(TMCB_REQUEST_SENT, request, 0, 0,
-									TMCB_LOCAL_F);
-#endif
+			run_trans_callbacks_with_buf(TMCB_REQUEST_SENT, request, 0, 0,
+			TMCB_LOCAL_F);
 	
 	
 	if (retransmit && (start_retr(request)!=0))
 	if (retransmit && (start_retr(request)!=0))
 		LOG(L_CRIT, "BUG: t_uac: failed to start retr. for %p\n", request);
 		LOG(L_CRIT, "BUG: t_uac: failed to start retr. for %p\n", request);
@@ -599,9 +597,7 @@ int ack_local_uac(struct cell *trans, str *hdrs, str *body)
 {
 {
 	struct retr_buf *local_ack, *old_lack;
 	struct retr_buf *local_ack, *old_lack;
 	int ret;
 	int ret;
-#ifdef	TMCB_ONSEND
 	struct tmcb_params onsend_params;
 	struct tmcb_params onsend_params;
-#endif
 
 
 	/* sanity checks */
 	/* sanity checks */
 
 
@@ -661,15 +657,13 @@ int ack_local_uac(struct cell *trans, str *hdrs, str *body)
 		ret = -1;
 		ret = -1;
 		goto fin;
 		goto fin;
 	}
 	}
-#ifdef	TMCB_ONSEND
 	else {
 	else {
 		INIT_TMCB_ONSEND_PARAMS(onsend_params, 0, 0, &trans->uac[0].request,
 		INIT_TMCB_ONSEND_PARAMS(onsend_params, 0, 0, &trans->uac[0].request,
 								&local_ack->dst,
 								&local_ack->dst,
 								local_ack->buffer, local_ack->buffer_len,
 								local_ack->buffer, local_ack->buffer_len,
 								TMCB_LOCAL_F, 0 /* branch */, TYPE_LOCAL_ACK);
 								TMCB_LOCAL_F, 0 /* branch */, TYPE_LOCAL_ACK);
-		run_onsend_callbacks2(TMCB_REQUEST_SENT, trans, &onsend_params);
+		run_trans_callbacks_off_params(TMCB_REQUEST_SENT, trans, &onsend_params);
 	}
 	}
-#endif
 
 
 	ret = 0;
 	ret = 0;
 fin:
 fin: