瀏覽代碼

<backport>
- fr_*_timer_avp parameter support ID, string name or alias; AVP ID much
faster to search for
- if fr_*_timer_avp parameter is empry, the variable timer support is
completly desabled (not searching anymore for the avp) -> reduces to 0
the performace penalty if you don't set/use variable timer AVP

Bogdan-Andrei Iancu 20 年之前
父節點
當前提交
9df13da010
共有 4 個文件被更改,包括 80 次插入46 次删除
  1. 54 25
      modules/tm/t_funcs.c
  2. 15 17
      modules/tm/t_funcs.h
  3. 1 1
      modules/tm/t_reply.c
  4. 10 3
      modules/tm/tm.c

+ 54 - 25
modules/tm/t_funcs.c

@@ -40,6 +40,8 @@
  *  2003-04-26  do it (^) really really really everywhere (jiri)
  *  2003-07-07  added get_proto calls when proxy!=0 (andrei)
  *  2004-02-13  t->is_invite and t->local replaced with flags (bogdan)
+ *  2005-02-16  fr_*_timer acceps full AVP specifications; empty AVP
+ *              desable variable timer feature (bogdan)
  */
 
 #include <limits.h>
@@ -59,17 +61,13 @@
 #include "config.h"
 #include "t_stats.h"
 
-#define FR_TIMER_AVP "callee_fr_timer"
-#define FR_TIMER_AVP_LEN (sizeof(FR_TIMER_AVP) - 1)
-
-#define FR_INV_TIMER_AVP "callee_fr_inv_timer"
-#define FR_INV_TIMER_AVP_LEN (sizeof(FR_INV_TIMER_AVP) - 1)
-
-str fr_timer_param = {FR_TIMER_AVP, FR_TIMER_AVP_LEN};
-int_str fr_timer_avp;
-
-str fr_inv_timer_param = {FR_INV_TIMER_AVP, FR_INV_TIMER_AVP_LEN};
-int_str fr_inv_timer_avp;
+/* fr_timer AVP specs */
+static int     fr_timer_avp_type = 0;
+static int_str fr_timer_avp = (int_str)0;
+static str     fr_timer_str;
+static int     fr_inv_timer_avp_type = 0;
+static int_str fr_inv_timer_avp = (int_str)0;
+static str     fr_inv_timer_str;
 
 
 /* ----------------------------------------------------- */
@@ -145,7 +143,7 @@ int t_release_transaction( struct cell *trans )
 }
 
 
-/* ----------------------------HELPER FUNCTIONS-------------------------------- */
+/* -----------------------HELPER FUNCTIONS----------------------- */
 
 
 /*
@@ -329,36 +327,47 @@ done:
 
 
 
-
 /*
  * Initialize parameters containing the ID of
  * AVPs with variable timers
  */
-void init_avp_params(void)
+int init_avp_params(char *fr_timer_param, char *fr_inv_timer_param)
 {
-	fr_timer_avp.s = &fr_timer_param;
-	fr_inv_timer_avp.s = &fr_inv_timer_param;
+	if (fr_timer_param && *fr_timer_param) {
+		fr_timer_str.s = fr_timer_param;
+		fr_timer_str.len = strlen(fr_timer_str.s);
+		if (parse_avp_spec( &fr_timer_str, &fr_timer_avp_type,
+		&fr_timer_avp)<0) {
+			LOG(L_CRIT,"ERROR:tm:init_avp_params: invalid fr_timer "
+				"AVP specs \"%s\"\n", fr_timer_param);
+			return -1;
+		}
+	}
 
-	fr_timer_param.len = strlen(fr_timer_param.s);
-	fr_inv_timer_param.len = strlen(fr_inv_timer_param.s);
+	if (fr_inv_timer_param && *fr_inv_timer_param) {
+		fr_inv_timer_str.s = fr_inv_timer_param;
+		fr_inv_timer_str.len = strlen(fr_inv_timer_str.s);
+		if (parse_avp_spec( &fr_inv_timer_str, &fr_inv_timer_avp_type, 
+		&fr_inv_timer_avp)<0) {
+			LOG(L_CRIT,"ERROR:tm:init_avp_params: invalid fr_inv_timer "
+				"AVP specs \"%s\"\n", fr_inv_timer_param);
+			return -1;
+		}
+	}
+	return 0;
 }
 
 
 /*
  * Get the FR_{INV}_TIMER from corresponding AVP
  */
-int avp2timer(unsigned int* timer, int_str param)
+static inline int avp2timer(unsigned int* timer, int type, int_str name)
 {
 	struct usr_avp *avp;
 	int_str val_istr;
 	int err;
 
-	if (!timer) {
-		LOG(L_ERR, "avp2timer: Invalid parameter value\n");
-		return -1;
-	}
-
-	avp = search_first_avp(AVP_VAL_STR | AVP_NAME_STR, param, &val_istr);
+	avp = search_first_avp( type, name, &val_istr);
 	if (!avp) {
 		/*
 		 DBG("avp2timer: AVP '%.*s' not found\n", param.s->len, ZSW(param.s->s));
@@ -378,3 +387,23 @@ int avp2timer(unsigned int* timer, int_str param)
 
 	return 0;
 }
+
+
+int fr_avp2timer(unsigned int* timer)
+{
+	if (fr_timer_avp.n!=0)
+		return avp2timer( timer, fr_timer_avp_type, fr_timer_avp);
+	else
+		return 1;
+}
+
+
+int fr_inv_avp2timer(unsigned int* timer)
+{
+	if (fr_inv_timer_avp.n!=0)
+		return avp2timer( timer, fr_inv_timer_avp_type, fr_inv_timer_avp);
+	else
+		return 1;
+}
+
+

+ 15 - 17
modules/tm/t_funcs.h

@@ -65,12 +65,6 @@
 #include "h_table.h"
 #include "ut.h"
 
-extern str fr_timer_param; /* AVP containing the fr_timer */
-extern int_str fr_timer_avp;
-extern str fr_inv_timer_param; /* AVP containing the fr_inv_timer */
-extern int_str fr_inv_timer_avp;
-
-
 struct s_table;
 struct timer;
 struct entry;
@@ -79,6 +73,11 @@ struct cell;
 extern int noisy_ctimer;
 
 
+/* default names for timer's AVPs  */
+#define FR_TIMER_AVP      "callee_fr_timer"
+#define FR_INV_TIMER_AVP  "callee_fr_inv_timer"
+
+
 /* send a private buffer: utilize a retransmission structure
    but take a separate buffer not referred by it; healthy
    for reducing time spend in REPLIES locks
@@ -112,10 +111,18 @@ int send_pr_buffer( struct retr_buf *rb, void *buf, int len);
 #define INIT_REF_UNSAFE(_T_cell) ((_T_cell)->ref_count=1)
 #define IS_REFFED_UNSAFE(_T_cell) ((_T_cell)->ref_count!=0)
 
+/*
+ * Parse and fixup the fr_*_timer AVP specs
+ */
+int init_avp_params(char *fr_timer_param, char *fr_inv_timer_param);
+
+
 /*
  * Get the FR_{INV}_TIMER from corresponding AVP
  */
-int avp2timer(unsigned int* timer, int_str param);
+int fr_avp2timer(unsigned int* timer);
+int fr_inv_avp2timer(unsigned int* timer);
+
 
 
 static void inline _set_fr_retr( struct retr_buf *rb, int retr )
@@ -127,7 +134,7 @@ static void inline _set_fr_retr( struct retr_buf *rb, int retr )
 		set_timer( &rb->retr_timer, RT_T1_TO_1, 0 );
 	}
 
-	if (!avp2timer(&timer, fr_timer_avp)) {
+	if (!fr_avp2timer(&timer)) {
 		DBG("_set_fr_retr: FR_TIMER = %d\n", timer);
 		set_timer(&rb->fr_timer, FR_TIMER_LIST, &timer);
 	} else {
@@ -175,14 +182,5 @@ void cleanup_localcancel_timers( struct cell *t );
 int t_relay_to( struct sip_msg  *p_msg ,
 	struct proxy_l *proxy, int proto, int replicate ) ;
 
-
-void init_avp_params(void);
-
-
-/*
- * Get the FR_TIMER from corresponding AVP
- */
-int avp2fr_timer(int* timer, struct sip_msg* msg);
-
 #endif
 

+ 1 - 1
modules/tm/t_reply.c

@@ -1315,7 +1315,7 @@ int reply_received( struct sip_msg  *p_msg )
 			*/
 
 			backup_list = set_avp_list( &t->user_avps );
-			if (!avp2timer(&timer, fr_inv_timer_avp)) {
+			if (!fr_inv_avp2timer(&timer)) {
 				DBG("reply_received: FR_INV_TIMER = %d\n", timer);
 				set_timer( & uac->request.fr_timer,
 					   FR_INV_TIMER_LIST, &timer );

+ 10 - 3
modules/tm/tm.c

@@ -170,6 +170,10 @@ 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);
 
 
+static char *fr_timer_param = FR_TIMER_AVP;
+static char *fr_inv_timer_param = FR_INV_TIMER_AVP;
+
+
 static cmd_export_t cmds[]={
 	{"t_newtran",          w_t_newtran,             0, 0,
 			REQUEST_ROUTE},
@@ -267,8 +271,8 @@ static param_export_t params[]={
 	{"uac_from",            STR_PARAM, &uac_from                             },
 	{"unix_tx_timeout",     INT_PARAM, &tm_unix_tx_timeout                   },
 	{"restart_fr_on_each_reply", INT_PARAM, &restart_fr_on_each_reply        },
-	{"fr_timer_avp",        STR_PARAM, &fr_timer_param.s                     },
-	{"fr_inv_timer_avp",    STR_PARAM, &fr_inv_timer_param.s                 },
+	{"fr_timer_avp",        STR_PARAM, &fr_timer_param                       },
+	{"fr_inv_timer_avp",    STR_PARAM, &fr_inv_timer_param                   },
 	{"tw_append",           STR_PARAM|USE_FUNC_PARAM, (void*)parse_tw_append },
 	{0,0,0}
 };
@@ -545,7 +549,10 @@ static int mod_init(void)
 	register_script_cb( script_init, PRE_SCRIPT_CB , 
 			0 /* empty param */ );
 
-	init_avp_params();
+	if (init_avp_params( fr_timer_param, fr_inv_timer_param)<0 ){
+		LOG(L_ERR,"ERROR:tm:mod_init: failed to process timer AVPs\n");
+		return -1;
+	}
 
 	return 0;
 }