Selaa lähdekoodia

- added t_on_branch function

Jan Janak 20 vuotta sitten
vanhempi
commit
49a20a49bb
5 muutettua tiedostoa jossa 76 lisäystä ja 6 poistoa
  1. 2 0
      modules/tm/h_table.h
  2. 60 6
      modules/tm/t_fwd.c
  3. 2 0
      modules/tm/t_fwd.h
  4. 2 0
      modules/tm/t_lookup.c
  5. 10 0
      modules/tm/tm.c

+ 2 - 0
modules/tm/h_table.h

@@ -238,6 +238,8 @@ typedef struct cell
 	unsigned int on_negative;
 	unsigned int on_negative;
 	/* the onreply_route to be processed if registered to do so */
 	/* the onreply_route to be processed if registered to do so */
 	unsigned int on_reply;
 	unsigned int on_reply;
+	     /* The route to take for each downstream branch separately */
+	unsigned int on_branch;
 
 
 	/* MD5checksum  (meaningful only if syn_branch=0 */
 	/* MD5checksum  (meaningful only if syn_branch=0 */
 	char md5[MD5_LEN];
 	char md5[MD5_LEN];

+ 60 - 6
modules/tm/t_fwd.c

@@ -58,6 +58,8 @@
 #include "../../globals.h"
 #include "../../globals.h"
 #include "../../mem/mem.h"
 #include "../../mem/mem.h"
 #include "../../dset.h"
 #include "../../dset.h"
+#include "../../action.h"
+#include "../../data_lump.h"
 #include "t_funcs.h"
 #include "t_funcs.h"
 #include "t_hooks.h"
 #include "t_hooks.h"
 #include "t_msgbuilder.h"
 #include "t_msgbuilder.h"
@@ -68,6 +70,27 @@
 #include "fix_lumps.h"
 #include "fix_lumps.h"
 #include "config.h"
 #include "config.h"
 
 
+static int goto_on_branch = 0, branch_route = 0;
+
+void t_on_branch( unsigned int go_to )
+{
+	struct cell *t = get_t();
+
+       /* in MODE_REPLY and MODE_ONFAILURE T will be set to current transaction;
+        * in MODE_REQUEST T will be set only if the transaction was already
+        * created; if not -> use the static variable */
+	if (!t || t==T_UNDEFINED ) {
+		goto_on_branch=go_to;
+	} else {
+		get_t()->on_branch = go_to;
+	}
+}
+
+unsigned int get_on_branch(void)
+{
+	return goto_on_branch;
+}
+
 
 
 char *print_uac_request( struct cell *t, struct sip_msg *i_req,
 char *print_uac_request( struct cell *t, struct sip_msg *i_req,
 	int branch, str *uri, unsigned int *len, struct socket_info *send_sock,
 	int branch, str *uri, unsigned int *len, struct socket_info *send_sock,
@@ -75,6 +98,7 @@ char *print_uac_request( struct cell *t, struct sip_msg *i_req,
 {
 {
 	char *buf, *shbuf;
 	char *buf, *shbuf;
 	str* msg_uri;
 	str* msg_uri;
+	struct lump* add_rm_backup, *body_lumps_backup;
 
 
 	shbuf=0;
 	shbuf=0;
 
 
@@ -83,7 +107,7 @@ char *print_uac_request( struct cell *t, struct sip_msg *i_req,
 			&i_req->add_to_branch_len ))
 			&i_req->add_to_branch_len ))
 	{
 	{
 		LOG(L_ERR, "ERROR: print_uac_request: branch computation failed\n");
 		LOG(L_ERR, "ERROR: print_uac_request: branch computation failed\n");
-		goto error01;
+		goto error00;
 	}
 	}
 
 
 	/* ... update uri ... */
 	/* ... update uri ... */
@@ -93,6 +117,18 @@ char *print_uac_request( struct cell *t, struct sip_msg *i_req,
 		i_req->parsed_uri_ok=0;
 		i_req->parsed_uri_ok=0;
 	}
 	}
 
 
+	add_rm_backup = i_req->add_rm;
+	body_lumps_backup = i_req->body_lumps;
+	i_req->add_rm = dup_lump_list(i_req->add_rm);
+	i_req->body_lumps = dup_lump_list(i_req->body_lumps);
+
+	if (branch_route) {
+		     /* run branch_route actions if provided */
+		if (run_actions(branch_rlist[branch_route], i_req) < 0) {
+			LOG(L_ERR, "ERROR: print_uac_request: Error in run_actions\n");
+               }
+	}
+
 	/* run the specific callbacks for this transaction */
 	/* run the specific callbacks for this transaction */
 	run_trans_callbacks( TMCB_REQUEST_FWDED , t, i_req, 0, -i_req->REQ_METHOD);
 	run_trans_callbacks( TMCB_REQUEST_FWDED , t, i_req, 0, -i_req->REQ_METHOD);
 
 
@@ -109,11 +145,6 @@ char *print_uac_request( struct cell *t, struct sip_msg *i_req,
 		ser_error=E_OUT_OF_MEM;
 		ser_error=E_OUT_OF_MEM;
 		goto error01;
 		goto error01;
 	}
 	}
-	/*	clean Via's we created now -- they would accumulate for
-		other branches  and for  shmem i_req they would mix up
-	 	shmem with pkg_mem
-	*/
-	free_via_clen_lump(&i_req->add_rm);
 
 
 	shbuf=(char *)shm_malloc(*len);
 	shbuf=(char *)shm_malloc(*len);
 	if (!shbuf) {
 	if (!shbuf) {
@@ -126,6 +157,18 @@ char *print_uac_request( struct cell *t, struct sip_msg *i_req,
 error02:
 error02:
 	pkg_free( buf );
 	pkg_free( buf );
 error01:
 error01:
+	     /* Delete the duplicated lump lists, this will also delete
+	      * all lumps created here, such as lumps created in per-branch
+	      * routing sections, Via, and Content-Length headers created in
+	      * build_req_buf_from_sip_req
+	      */
+	free_duped_lump_list(i_req->add_rm);
+	free_duped_lump_list(i_req->body_lumps);
+	     /* Restore the lists from backups */
+	i_req->add_rm = add_rm_backup;
+	i_req->body_lumps = body_lumps_backup;
+
+ error00:
 	return shbuf;
 	return shbuf;
 }
 }
 
 
@@ -451,6 +494,17 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
 	/* branch to begin with */
 	/* branch to begin with */
 	first_branch=t->nr_of_outgoings;
 	first_branch=t->nr_of_outgoings;
 
 
+	if (t->on_branch) {
+		/* tell add_uac that it should run branch route actions */
+		branch_route = t->on_branch;
+		/* reset the flag before running the actions (so that it
+		 * could be set again in branch_route if needed
+		 */
+		t_on_branch(0);
+	} else {
+		branch_route = 0;
+	}
+	
 	/* on first-time forwarding, use current uri, later only what
 	/* on first-time forwarding, use current uri, later only what
 	   is in additional branches (which may be continuously refilled
 	   is in additional branches (which may be continuously refilled
 	*/
 	*/

+ 2 - 0
modules/tm/t_fwd.h

@@ -42,6 +42,8 @@
 typedef int (*tfwd_f)(struct sip_msg* p_msg , struct proxy_l * proxy );
 typedef int (*tfwd_f)(struct sip_msg* p_msg , struct proxy_l * proxy );
 typedef int (*taddblind_f)( /*struct cell *t */ );
 typedef int (*taddblind_f)( /*struct cell *t */ );
 
 
+void t_on_branch(unsigned int go_to);
+unsigned int get_on_branch();
 int t_replicate(struct sip_msg *p_msg, struct proxy_l * proxy, int proto);
 int t_replicate(struct sip_msg *p_msg, struct proxy_l * proxy, int proto);
 char *print_uac_request( struct cell *t, struct sip_msg *i_req,
 char *print_uac_request( struct cell *t, struct sip_msg *i_req,
     int branch, str *uri, unsigned int *len, struct socket_info *send_sock,
     int branch, str *uri, unsigned int *len, struct socket_info *send_sock,

+ 2 - 0
modules/tm/t_lookup.c

@@ -99,6 +99,7 @@
 #include "config.h"
 #include "config.h"
 #include "sip_msg.h"
 #include "sip_msg.h"
 #include "t_hooks.h"
 #include "t_hooks.h"
+#include "t_fwd.h"
 #include "t_lookup.h"
 #include "t_lookup.h"
 #include "dlg.h" /* for t_lookup_callid */
 #include "dlg.h" /* for t_lookup_callid */
 #include "t_msgbuilder.h" /* for t_lookup_callid */
 #include "t_msgbuilder.h" /* for t_lookup_callid */
@@ -999,6 +1000,7 @@ static inline void init_new_t(struct cell *new_cell, struct sip_msg *p_msg)
 	if (p_msg->REQ_METHOD==METHOD_INVITE) new_cell->flags |= T_IS_INVITE_FLAG;
 	if (p_msg->REQ_METHOD==METHOD_INVITE) new_cell->flags |= T_IS_INVITE_FLAG;
 	new_cell->on_negative=get_on_negative();
 	new_cell->on_negative=get_on_negative();
 	new_cell->on_reply=get_on_reply();
 	new_cell->on_reply=get_on_reply();
+	new_cell->on_branch=get_on_branch();
 }
 }
 
 
 static inline int new_t(struct sip_msg *p_msg)
 static inline int new_t(struct sip_msg *p_msg)

+ 10 - 0
modules/tm/tm.c

@@ -166,6 +166,7 @@ inline static int w_t_forward_nonack_tcp(struct sip_msg* msg, char* str,char*);
 inline static int w_t_forward_nonack_tls(struct sip_msg* msg, char* str,char*);
 inline static int w_t_forward_nonack_tls(struct sip_msg* msg, char* str,char*);
 #endif
 #endif
 inline static int w_t_on_negative(struct sip_msg* msg, char *go_to, char *foo);
 inline static int w_t_on_negative(struct sip_msg* msg, char *go_to, char *foo);
+inline static int w_t_on_branch(struct sip_msg* msg, char *go_to, char *foo);
 inline static int w_t_on_reply(struct sip_msg* msg, char *go_to, char *foo );
 inline static int w_t_on_reply(struct sip_msg* msg, char *go_to, char *foo );
 inline static int t_check_status(struct sip_msg* msg, char *regexp, char *foo);
 inline static int t_check_status(struct sip_msg* msg, char *regexp, char *foo);
 
 
@@ -227,6 +228,8 @@ static cmd_export_t cmds[]={
 			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
 			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
 	{"t_on_reply",         w_t_on_reply,            1, fixup_str2int,
 	{"t_on_reply",         w_t_on_reply,            1, fixup_str2int,
 			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
 			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
+	{"t_on_branch",       w_t_on_branch,         1, fixup_str2int,
+			REQUEST_ROUTE | FAILURE_ROUTE },
 	{"t_check_status",     t_check_status,          1, fixup_str2regexp,
 	{"t_check_status",     t_check_status,          1, fixup_str2regexp,
 			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
 			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
 	{"t_write_req",       t_write_req,              2, fixup_t_write,
 	{"t_write_req",       t_write_req,              2, fixup_t_write,
@@ -430,6 +433,7 @@ static int script_init( struct sip_msg *foo, void *bar)
 	*/
 	*/
 	t_on_negative( 0 );
 	t_on_negative( 0 );
 	t_on_reply(0);
 	t_on_reply(0);
+	t_on_branch(0);
 	/* reset the kr status */
 	/* reset the kr status */
 	set_kr(0);
 	set_kr(0);
 	/* set request mode so that multiple-mode actions know
 	/* set request mode so that multiple-mode actions know
@@ -771,6 +775,12 @@ inline static int w_t_on_negative( struct sip_msg* msg, char *go_to, char *foo)
 	return 1;
 	return 1;
 }
 }
 
 
+inline static int w_t_on_branch( struct sip_msg* msg, char *go_to, char *foo)
+{
+	t_on_branch( (unsigned int )(long) go_to );
+	return 1;
+}
+
 
 
 inline static int w_t_on_reply( struct sip_msg* msg, char *go_to, char *foo )
 inline static int w_t_on_reply( struct sip_msg* msg, char *go_to, char *foo )
 {
 {