[sr-dev] git:tmp/tm_async_reply_support: modules/tm: Cleaned up async_response code to use new faked async env

Richard Good richard.good at smilecoms.com
Fri Jul 12 17:50:00 CEST 2013


Module: sip-router
Branch: tmp/tm_async_reply_support
Commit: 997feed460ea53c926f8e42d5b46d304cba7dce5
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=997feed460ea53c926f8e42d5b46d304cba7dce5

Author: Richard Good <richard.good at smilecoms.com>
Committer: Richard Good <richard.good at smilecoms.com>
Date:   Fri Jul 12 17:46:58 2013 +0200

modules/tm: Cleaned up async_response code to use new faked async env
	-Use new faked_env_async method -instead of duplicating with faked_env_resp
	-Also use new async lock on continue

---

 modules/tm/t_reply.c   |   92 ------------------------------------------------
 modules/tm/t_reply.h   |    1 -
 modules/tm/t_suspend.c |   13 +++++--
 3 files changed, 9 insertions(+), 97 deletions(-)

diff --git a/modules/tm/t_reply.c b/modules/tm/t_reply.c
index 2a45188..8542340 100644
--- a/modules/tm/t_reply.c
+++ b/modules/tm/t_reply.c
@@ -859,98 +859,6 @@ void free_faked_resp(struct sip_msg *faked_resp, struct cell *t, int branch)
 	}
 }
 
-/** create or restore a "fake environment" for running a TM_ONREPLY_ROUTE.
- * This used for suspending and continuing on SIP replies
- *if msg is set -> it will fake the env. vars conforming with the msg; if NULL
- * the env. will be restore to original.
- * Side-effect: mark_ruri_consumed().
- */
-void faked_env_resp( struct cell *t, struct sip_msg *msg)
-{
-        static int backup_route_type;
-	static struct cell *backup_t;
-	static int backup_branch;
-	static unsigned int backup_msgid;
-	static avp_list_t* backup_user_from, *backup_user_to;
-	static avp_list_t* backup_domain_from, *backup_domain_to;
-	static avp_list_t* backup_uri_from, *backup_uri_to;
-#ifdef WITH_XAVP
-	static sr_xavp_t **backup_xavps;
-#endif
-	static struct socket_info* backup_si;
-
-	static struct lump *backup_add_rm;
-	static struct lump *backup_body_lumps;
-	static struct lump_rpl *backup_reply_lump;
-
-
-	if (msg) {
-		/* remember we are back in reply processing, but process
-		 * a shmem-ed replica of the reply; advertise it in route type;
-		 * for example t_reply needs to know that
-		 */
-		backup_route_type=get_route_type();
-                
-                /*This is response so route type is TM_ONREPLY_ROUTE*/
-		set_route_type(TM_ONREPLY_ROUTE);
-		/* don't bother backing up ruri state, since failure route
-		   is called either on reply or on timer and in both cases
-		   the ruri should not be used again for forking */
-		ruri_mark_consumed(); /* in failure route we assume ruri should not be used again for forking */
-		/* also, tm actions look in beginning whether transaction is
-		 * set -- whether we are called from a reply-processing
-		 * or a timer process, we need to set current transaction;
-		 * otherwise the actions would attempt to look the transaction
-		 * up (unnecessary overhead, refcounting)
-		 */
-		/* backup */
-		backup_t=get_t();
-		backup_branch=get_t_branch();
-		backup_msgid=global_msg_id;
-		/* fake transaction and message id */
-		global_msg_id=msg->id;
-		set_t(t, T_BR_UNDEFINED);
-		/* make available the avp list from transaction */
-
-		backup_uri_from = set_avp_list(AVP_TRACK_FROM | AVP_CLASS_URI, &t->uri_avps_from );
-		backup_uri_to = set_avp_list(AVP_TRACK_TO | AVP_CLASS_URI, &t->uri_avps_to );
-		backup_user_from = set_avp_list(AVP_TRACK_FROM | AVP_CLASS_USER, &t->user_avps_from );
-		backup_user_to = set_avp_list(AVP_TRACK_TO | AVP_CLASS_USER, &t->user_avps_to );
-		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 );
-#ifdef WITH_XAVP
-		backup_xavps = xavp_set_list(&t->xavps_list);
-#endif
-		/* set default send address to the saved value */
-		backup_si=bind_address;
-		bind_address=t->uac[0].request.dst.send_sock;
-		/* backup lump lists */
-		backup_add_rm = t->uas.request->add_rm;
-		backup_body_lumps = t->uas.request->body_lumps;
-		backup_reply_lump = t->uas.request->reply_lump;
-	} else {
-		/* restore original environment */
-		set_t(backup_t, backup_branch);
-		global_msg_id=backup_msgid;
-		set_route_type(backup_route_type);
-		/* restore original avp list */
-		set_avp_list(AVP_TRACK_FROM | AVP_CLASS_USER, backup_user_from );
-		set_avp_list(AVP_TRACK_TO | AVP_CLASS_USER, backup_user_to );
-		set_avp_list(AVP_TRACK_FROM | AVP_CLASS_DOMAIN, backup_domain_from );
-		set_avp_list(AVP_TRACK_TO | AVP_CLASS_DOMAIN, backup_domain_to );
-		set_avp_list(AVP_TRACK_FROM | AVP_CLASS_URI, backup_uri_from );
-		set_avp_list(AVP_TRACK_TO | AVP_CLASS_URI, backup_uri_to );
-#ifdef WITH_XAVP
-		xavp_set_list(backup_xavps);
-#endif
-		bind_address=backup_si;
-		/* restore lump lists */
-		t->uas.request->add_rm = backup_add_rm;
-		t->uas.request->body_lumps = backup_body_lumps;
-		t->uas.request->reply_lump = backup_reply_lump;
-	}
-}
-
 void faked_env_async( struct cell *t, struct sip_msg *msg) {
 
 	if (msg) {
diff --git a/modules/tm/t_reply.h b/modules/tm/t_reply.h
index d2f1370..51e4634 100644
--- a/modules/tm/t_reply.h
+++ b/modules/tm/t_reply.h
@@ -239,7 +239,6 @@ void rpc_reply(rpc_t* rpc, void* c);
 
 void faked_env( struct cell *t,struct sip_msg *msg);
 void faked_env_async( struct cell *t, struct sip_msg *msg);
-void faked_env_resp( struct cell *t,struct sip_msg *msg);
 
 int fake_req(struct sip_msg *faked_req,
 		struct sip_msg *shmem_msg, int extra_flags, struct ua_client *uac);
diff --git a/modules/tm/t_suspend.c b/modules/tm/t_suspend.c
index b9c92e6..eb5b1a5 100644
--- a/modules/tm/t_suspend.c
+++ b/modules/tm/t_suspend.c
@@ -355,8 +355,8 @@ int t_continue_reply(unsigned int hash_index, unsigned int label,
         init_cancel_info(&cancel_data);
 
 	/* The transaction has to be locked to protect it
-	 * form calling t_continue_reply() multiple times simultaneously */
-	LOCK_REPLIES(t);
+	 * form calling t_continue() multiple times simultaneously */
+	LOCK_ASYNC_CONTINUE(t);
 
         LOG(L_DBG,"DEBUG: t_continue_reply: This a continue from a reply suspend\n");
         /* this is a continue from a reply suspend */
@@ -371,7 +371,7 @@ int t_continue_reply(unsigned int hash_index, unsigned int label,
 		return 0;
 	}
         
-        faked_env_resp( t, &faked_resp);
+        faked_env_async( t, &faked_resp);
         
         LOG(L_DBG,"DEBUG: Running pre script\n");
         if (exec_pre_script_cb(&faked_resp, ONREPLY_CB_TYPE)>0) {
@@ -383,10 +383,13 @@ int t_continue_reply(unsigned int hash_index, unsigned int label,
         }
 
         LOG(L_DBG,"DEBUG: t_continue_reply: Restoring previous environment");
-        faked_env_resp( t, 0);
+        faked_env_async( t, 0);
 	free_faked_resp(&faked_resp, t, branch);
         
         int reply_status;
+        
+        /*lock transaction replies - will be unlocked when reply is relayed*/
+        LOCK_REPLIES( t );
         if ( is_local(t) ) {
                 LOG(L_DBG,"DEBUG: t_continue_reply: t is local sending local reply with status code: [%d]\n", t->uac[branch].reply->first_line.u.reply.statuscode);
                 reply_status = local_reply( t, t->uac[branch].reply, branch, t->uac[branch].reply->first_line.u.reply.statuscode, &cancel_data );
@@ -455,6 +458,8 @@ int t_continue_reply(unsigned int hash_index, unsigned int label,
         
 done:
         
+        UNLOCK_ASYNC_CONTINUE(t);
+                    
         tm_ctx_set_branch_index(T_BR_UNDEFINED);        
         /* unref the transaction */
         t_unref(t->uac[branch].reply);




More information about the sr-dev mailing list