[sr-dev] git:tirpi/script_callbacks: script callbacks: support for failure and branch routes

Miklos Tirpak miklos at iptel.org
Mon Jun 1 15:26:08 CEST 2009


Module: sip-router
Branch: tirpi/script_callbacks
Commit: b9ed8d84b2eb5a9af8b1980cea772c0290611513
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b9ed8d84b2eb5a9af8b1980cea772c0290611513

Author: Miklos Tirpak <miklos at iptel.org>
Committer: Miklos Tirpak <miklos at iptel.org>
Date:   Mon Jun  1 15:11:41 2009 +0200

script callbacks: support for failure and branch routes

- Executing pre- and post-script callbacks for failure
routes and branch routes.

---

 modules/tm/t_fwd.c     |   11 ++++++++---
 modules/tm/t_reply.c   |   21 ++++++++++++++++-----
 modules/tm/t_suspend.c |   16 ++++++++++++----
 3 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/modules/tm/t_fwd.c b/modules/tm/t_fwd.c
index 01a3699..d0dd613 100644
--- a/modules/tm/t_fwd.c
+++ b/modules/tm/t_fwd.c
@@ -78,6 +78,7 @@
  *              t saved, thus, are not available. Set reparse_on_dns_failover
  *              to 0 to revert the change. (Miklos)
  * 2008-06-04  T_CANCELED is now set each time a CANCEL is received (andrei)
+ * 2009-06-01  Pre- and post-script callbacks of branch route are executed (Miklos)
  */
 
 #include "defs.h"
@@ -98,6 +99,7 @@
 #include "../../onsend.h"
 #include "../../compiler_opt.h"
 #include "../../route.h"
+#include "../../script_cb.h"
 #include "t_funcs.h"
 #include "t_hooks.h"
 #include "t_msgbuilder.h"
@@ -191,9 +193,12 @@ static char *print_uac_request( struct cell *t, struct sip_msg *i_req,
 		     /* 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");
-		}
+		if (exec_pre_script_cb(i_req, BRANCH_CB_TYPE)>0) {
+			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");
+			}
+			exec_post_script_cb(i_req, BRANCH_CB_TYPE);
+		}		
 		tm_ctx_set_branch_index(0);
 	}
 
diff --git a/modules/tm/t_reply.c b/modules/tm/t_reply.c
index 8ab79c2..e60d046 100644
--- a/modules/tm/t_reply.c
+++ b/modules/tm/t_reply.c
@@ -89,6 +89,7 @@
  * 2008-03-12  use cancel_b_method on 6xx (andrei)
  * 2008-05-30  make sure the wait timer is started after we don't need t
  *             anymore to allow safe calls from fr_timer (andrei)
+ * 2009-06-01  Pre- and post-script callbacks of branch route are executed (Miklos)
  *
  */
 
@@ -106,6 +107,7 @@
 #include "../../timer.h"
 #include "../../error.h"
 #include "../../action.h"
+#include "../../script_cb.h"
 #include "../../dset.h"
 #include "../../tags.h"
 #include "../../route.h"
@@ -861,9 +863,12 @@ int run_failure_handlers(struct cell *t, struct sip_msg *rpl,
 		 * on failure */
 		on_failure = t->on_negative;
 		t->on_negative=0;
-		/* run a reply_route action if some was marked */
-		if (run_top_route(failure_rt.rlist[on_failure], &faked_req)<0)
-			LOG(L_ERR, "ERROR: run_failure_handlers: Error in run_top_route\n");
+		if (exec_pre_script_cb(&faked_req, FAILURE_CB_TYPE)>0) {
+			/* run a reply_route action if some was marked */
+			if (run_top_route(failure_rt.rlist[on_failure], &faked_req)<0)
+				LOG(L_ERR, "ERROR: run_failure_handlers: Error in run_top_route\n");
+			exec_post_script_cb(&faked_req, FAILURE_CB_TYPE);
+		}
 	}
 
 	/* restore original environment and free the fake msg */
@@ -1963,6 +1968,9 @@ int reply_received( struct sip_msg  *p_msg )
 		backup_domain_from = set_avp_list(AVP_TRACK_FROM | AVP_CLASS_DOMAIN, &t->domain_avps_from );
 		backup_domain_to = set_avp_list(AVP_TRACK_TO | AVP_CLASS_DOMAIN, &t->domain_avps_to );
 		setbflagsval(0, uac->branch_flags);
+		/* Pre- and post-script callbacks have already
+		 * been execueted by the core. (Miklos)
+		 */
 		if (run_top_route(onreply_rt.rlist[t->on_reply], p_msg)<0)
 			LOG(L_ERR, "ERROR: on_reply processing failed\n");
 		/* transfer current message context back to t */
@@ -2090,8 +2098,11 @@ done:
 trans_not_found:
 	/* transaction context was not found */
 	if (goto_on_sl_reply) {
-		/* the script writer has a chance to decide whether to
-		forward the reply or not */
+		/* The script writer has a chance to decide whether to
+		 * forward the reply or not.
+		 * Pre- and post-script callbacks have already
+		 * been execueted by the core. (Miklos)
+		 */
 		return run_top_route(onreply_rt.rlist[goto_on_sl_reply], p_msg);
 	} else {
 		/* let the core forward the reply */
diff --git a/modules/tm/t_suspend.c b/modules/tm/t_suspend.c
index c1dc1b1..e9802b9 100644
--- a/modules/tm/t_suspend.c
+++ b/modules/tm/t_suspend.c
@@ -27,10 +27,12 @@
  * History:
  * --------
  *  2008-11-10	Initial version (Miklos)
+ *  2009-06-01  Pre- and post-script callbacks of failure route are executed (Miklos)
  *
  */
 
-#include "../../select_buf.h" /* reset_static_buffer() */
+#include "../../action.h"
+#include "../../script_cb.h"
 
 #include "sip_msg.h"
 #include "t_reply.h"
@@ -151,9 +153,15 @@ int t_continue(unsigned int hash_index, unsigned int label,
 	}
 	faked_env( t, &faked_req);
 
-	if (run_top_route(route, &faked_req)<0)
-		LOG(L_ERR, "ERROR: t_continue: Error in run_top_route\n");
-
+	/* The sip msg is a faked msg just like in failure route
+	 * therefore execute the pre- and post-script callbacks
+	 * of failure route (Miklos)
+	 */
+	if (exec_pre_script_cb(&faked_req, FAILURE_CB_TYPE)>0) {
+		if (run_top_route(route, &faked_req)<0)
+			LOG(L_ERR, "ERROR: t_continue: Error in run_top_route\n");
+		exec_pre_script_cb(&faked_req, FAILURE_CB_TYPE);
+	}
 	/* TODO: save_msg_lumps should clone the lumps to shm mem */
 
 	/* restore original environment and free the fake msg */




More information about the sr-dev mailing list