[sr-dev] git:treimann/master_tm-extend-callbacks: tm: Add tm callback TMCB_RESPONSE_OUT, triggered when a

Timo Reimann timo.reimann at 1und1.de
Mon Oct 17 20:12:08 CEST 2011


Module: sip-router
Branch: treimann/master_tm-extend-callbacks
Commit: 843cf2f41e97566937fcf926333fd546c58fb0e1
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=843cf2f41e97566937fcf926333fd546c58fb0e1

Author: Timo Reimann <timo.reimann at 1und1.de>
Committer: Timo Reimann <timo.reimann at 1und1.de>
Date:   Wed Oct  5 18:39:59 2011 +0200

tm: Add tm callback TMCB_RESPONSE_OUT, triggered when a
    non-retransmitted response is sent out.

---

 modules/tm/t_cancel.c |    2 ++
 modules/tm/t_fwd.c    |    6 +++++-
 modules/tm/t_hooks.h  |   40 ++++++++++++++++++++++++----------------
 modules/tm/t_reply.c  |    3 ++-
 4 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/modules/tm/t_cancel.c b/modules/tm/t_cancel.c
index 8057ae4..7c225e8 100644
--- a/modules/tm/t_cancel.c
+++ b/modules/tm/t_cancel.c
@@ -327,6 +327,8 @@ int cancel_branch( struct cell *t, int branch,
 
 	DBG("DEBUG: cancel_branch: sending cancel...\n");
 	if (SEND_BUFFER( crb )>=0){
+		if (unlikely (has_tran_tmcbs(t, TMCB_REQUEST_OUT)))
+			run_trans_callbacks_with_buf(TMCB_REQUEST_OUT, crb, 0, 0, TMCB_LOCAL_F);
 		if (unlikely (has_tran_tmcbs(t, TMCB_REQUEST_SENT)))
 			run_trans_callbacks_with_buf(TMCB_REQUEST_SENT, crb, 0, 0, TMCB_LOCAL_F);
 	}
diff --git a/modules/tm/t_fwd.c b/modules/tm/t_fwd.c
index 819c831..604f1e3 100644
--- a/modules/tm/t_fwd.c
+++ b/modules/tm/t_fwd.c
@@ -1542,8 +1542,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);
 			if (branch_ret>=0){ /* some kind of success */
-				if (branch_ret==i) /* success */
+				if (branch_ret==i) { /* success */
 					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 */
 					added_branches |= 1<<branch_ret;
 			}
diff --git a/modules/tm/t_hooks.h b/modules/tm/t_hooks.h
index 6f4dc08..b31558e 100644
--- a/modules/tm/t_hooks.h
+++ b/modules/tm/t_hooks.h
@@ -63,24 +63,25 @@ struct cell;
 #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_OUT_N      7
+#define TMCB_RESPONSE_OUT_N     8
+#define TMCB_LOCAL_COMPLETED_N  9
+#define TMCB_LOCAL_RESPONSE_OUT_N 10
+#define TMCB_ACK_NEG_IN_N       11
+#define TMCB_REQ_RETR_IN_N      12
+#define TMCB_LOCAL_RESPONSE_IN_N 13
+#define TMCB_LOCAL_REQUEST_IN_N  14
+#define TMCB_DLG_N              15
+#define TMCB_DESTROY_N          16  /* called on transaction destroy */
+#define TMCB_E2ECANCEL_IN_N     17
+#define TMCB_E2EACK_RETR_IN_N   18
+#define TMCB_RESPONSE_READY_N	19
 #ifdef WITH_AS_SUPPORT
-#define TMCB_DONT_ACK_N         19 /* TM shoudn't ACK a local UAC  */
+#define TMCB_DONT_ACK_N         20 /* TM shoudn't ACK a local UAC  */
 #endif
-#define TMCB_REQUEST_SENT_N     20
-#define TMCB_RESPONSE_SENT_N    21
-#define TMCB_MAX_N              21
+#define TMCB_REQUEST_SENT_N     21
+#define TMCB_RESPONSE_SENT_N    22
+#define TMCB_MAX_N              22
 
 
 #define TMCB_REQUEST_IN       (1<<TMCB_REQUEST_IN_N)
@@ -90,6 +91,7 @@ struct cell;
 #define TMCB_RESPONSE_FWDED   (1<<TMCB_RESPONSE_FWDED_N)
 #define TMCB_ON_FAILURE_RO    (1<<TMCB_ON_FAILURE_RO_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_LOCAL_COMPLETED  (1<<TMCB_LOCAL_COMPLETED_N)
 #define TMCB_LOCAL_RESPONSE_OUT (1<<TMCB_LOCAL_RESPONSE_OUT_N)
@@ -242,6 +244,12 @@ struct cell;
  *   router (via t_relay/t_forward_nonack) and in this case the REPLY lock 
  *   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
  *  transaction arrived. Message may be FAKED_REPLY. Can be called multiple
  *  times, no lock is held.
diff --git a/modules/tm/t_reply.c b/modules/tm/t_reply.c
index 69c55d9..fef5e0a 100644
--- a/modules/tm/t_reply.c
+++ b/modules/tm/t_reply.c
@@ -648,12 +648,13 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len,
 	} else {
 		if (likely(SEND_PR_BUFFER( rb, buf, len )>=0)){
 			if (unlikely(code>=200 && !is_local(trans) &&
-						has_tran_tmcbs(trans, TMCB_RESPONSE_OUT)) )
+						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))){
 				INIT_TMCB_ONSEND_PARAMS(onsend_params, trans->uas.request,
 								FAKED_REPLY, rb, &rb->dst, 




More information about the sr-dev mailing list