Browse Source

dialog: store name of time-out route

- upon restart, if new routes where added or the order was changed,
  there was a chance that the index of the route was different
- no store the string name of route and resolve it again at startup
Daniel-Constantin Mierla 15 years ago
parent
commit
48c3a21a05

+ 2 - 2
modules_k/dialog/dialog.c

@@ -210,7 +210,7 @@ static param_export_t mod_params[]={
 	{ "to_sock_column",        STR_PARAM, &to_sock_column.s         },
 	{ "from_sock_column",      STR_PARAM, &from_sock_column.s       },
 	{ "sflags_column",         STR_PARAM, &sflags_column.s          },
-	{ "toroute_column",        STR_PARAM, &toroute_column.s         },
+	{ "toroute_name_column",   STR_PARAM, &toroute_name_column.s    },
 	{ "db_update_period",      INT_PARAM, &db_update_period         },
 	{ "db_fetch_rows",         INT_PARAM, &db_fetch_rows            },
 	{ "profiles_with_value",   STR_PARAM, &profiles_wv_s            },
@@ -424,7 +424,7 @@ static int mod_init(void)
 	to_sock_column.len = strlen(to_sock_column.s);
 	from_sock_column.len = strlen(from_sock_column.s);
 	sflags_column.len = strlen(sflags_column.s);
-	toroute_column.len = strlen(toroute_column.s);
+	toroute_name_column.len = strlen(toroute_name_column.s);
 	dialog_table_name.len = strlen(dialog_table_name.s);
 
 	/* param checkings */

+ 19 - 9
modules_k/dialog/dlg_db_handler.c

@@ -59,7 +59,7 @@ str from_contact_column		=	str_init(FROM_CONTACT_COL);
 str to_sock_column			=	str_init(TO_SOCK_COL);
 str from_sock_column		=	str_init(FROM_SOCK_COL);
 str sflags_column			=	str_init(SFLAGS_COL);
-str toroute_column			=	str_init(TOROUTE_COL);
+str toroute_name_column		=	str_init(TOROUTE_NAME_COL);
 str req_uri_column			=	str_init(REQ_URI_COL);
 str dialog_table_name		=	str_init(DIALOG_TABLE_NAME);
 int dlg_db_mode				=	DB_MODE_NONE;
@@ -197,7 +197,7 @@ static int select_entire_dialog_table(db1_res_t ** res, int fetch_num_rows)
 			&from_cseq_column,	&to_cseq_column,	&from_route_column,
 			&to_route_column, 	&from_contact_column, &to_contact_column,
 			&from_sock_column,	&to_sock_column,    &sflags_column,
-			&toroute_column,	&req_uri_column };
+			&toroute_name_column,	&req_uri_column };
 
 	if(use_dialog_table() != 0){
 		return -1;
@@ -265,6 +265,7 @@ static int load_dialog_info_from_db(int dlg_hash_size, int fetch_num_rows)
 	struct dlg_cell *dlg;
 	str callid, from_uri, to_uri, from_tag, to_tag, req_uri;
 	str cseq1, cseq2, contact1, contact2, rroute1, rroute2;
+	str toroute_name;
 	unsigned int next_id;
 	
 
@@ -366,6 +367,9 @@ static int load_dialog_info_from_db(int dlg_hash_size, int fetch_num_rows)
 			dlg->bind_addr[DLG_CALLER_LEG] = create_socket_info(values, 16);
 			dlg->bind_addr[DLG_CALLEE_LEG] = create_socket_info(values, 17);
 			
+			GET_STR_VALUE(toroute_name, values, 19, 0, 0);
+			dlg_set_toroute(dlg, &toroute_name);
+
 			/*restore the timer values */
 			if (0 != insert_dlg_timer( &(dlg->tl), (int)dlg->tl.timeout )) {
 				LM_CRIT("Unable to insert dlg %p [%u:%u] "
@@ -456,7 +460,7 @@ int update_dialog_dbinfo(struct dlg_cell * cell)
 			&start_time_column,  &state_column,       &timeout_column,
 			&from_cseq_column,   &to_cseq_column,     &from_route_column,
 			&to_route_column,    &from_contact_column,&to_contact_column,
-			&sflags_column,      &toroute_column,     &req_uri_column };
+			&sflags_column,      &toroute_name_column,     &req_uri_column };
 
 	if(use_dialog_table()!=0)
 		return -1;
@@ -473,7 +477,8 @@ int update_dialog_dbinfo(struct dlg_cell * cell)
 		VAL_TYPE(values+17) = VAL_TYPE(values+20) = DB1_STR;
 
 		SET_NULL_FLAG(values, i, DIALOG_TABLE_COL_NO-6, 0);
-		VAL_TYPE(values+18) = VAL_TYPE(values+19) = DB1_INT;
+		VAL_TYPE(values+18) = DB1_INT;
+		VAL_TYPE(values+19) = DB1_STR;
 
 		/* lock the entry */
 		entry = (d_table->entries)[cell->h_entry];
@@ -514,8 +519,9 @@ int update_dialog_dbinfo(struct dlg_cell * cell)
 
 		VAL_NULL(values+18) = 0;
 		VAL_INT(values+18)  = cell->sflags;
-		VAL_NULL(values+19) = 0;
-		VAL_INT(values+19)  = cell->toroute;
+
+		SET_STR_VALUE(values+19, cell->toroute_name);
+		SET_PROPER_NULL_FLAG(cell->toroute_name, values, 19);
 		SET_STR_VALUE(values+20, cell->req_uri);
 		SET_PROPER_NULL_FLAG(cell->req_uri, 	values, 20);
 
@@ -585,7 +591,7 @@ void dialog_update_db(unsigned int ticks, void * param)
 			&start_time_column,	&state_column,			&timeout_column,
 			&from_cseq_column,	&to_cseq_column,		&from_route_column,
 			&to_route_column, 	&from_contact_column, 	&to_contact_column,
-			&sflags_column,     &toroute_column, 		&req_uri_column };
+			&sflags_column,     &toroute_name_column, 	&req_uri_column };
 
 	if(use_dialog_table()!=0)
 		return;
@@ -602,7 +608,8 @@ void dialog_update_db(unsigned int ticks, void * param)
 
 	SET_NULL_FLAG(values, i, DIALOG_TABLE_COL_NO-6, 0);
 
-	VAL_TYPE(values+18) = VAL_TYPE(values+19) = DB1_INT;
+	VAL_TYPE(values+18) = DB1_INT;
+	VAL_TYPE(values+19) = DB1_STR;
 
 	LM_DBG("saving current_info \n");
 	
@@ -654,7 +661,10 @@ void dialog_update_db(unsigned int ticks, void * param)
 					values, 17);
 				
 				VAL_INT(values+18)		= cell->sflags;
-				VAL_INT(values+19)		= cell->toroute;
+
+				SET_STR_VALUE(values+19, cell->toroute_name);
+				SET_PROPER_NULL_FLAG(cell->toroute_name,
+					values, 19);
 
 				SET_STR_VALUE(values+20, cell->req_uri);
 				SET_PROPER_NULL_FLAG(cell->req_uri,

+ 2 - 2
modules_k/dialog/dlg_db_handler.h

@@ -50,7 +50,7 @@
 #define FROM_SOCK_COL			"caller_sock"
 #define TO_SOCK_COL				"callee_sock"
 #define SFLAGS_COL				"sflags"
-#define TOROUTE_COL				"toroute"
+#define TOROUTE_NAME_COL		"toroute_name"
 #define REQ_URI_COL				"req_uri"
 #define DIALOG_TABLE_NAME		"dialog"
 
@@ -85,7 +85,7 @@ extern str from_contact_column;
 extern str to_sock_column;
 extern str from_sock_column;
 extern str sflags_column;
-extern str toroute_column;
+extern str toroute_name_column;
 extern str dialog_table_name;
 extern int dlg_db_mode;
 

+ 3 - 1
modules_k/dialog/dlg_handlers.c

@@ -708,7 +708,9 @@ int dlg_new_dialog(struct sip_msg *msg, struct cell *t)
 	}
 
 	dlg->lifetime = get_dlg_timeout(msg);
-	dlg->toroute = _dlg_ctx.to_route;
+	s.s   = _dlg_ctx.to_route_name;
+	s.len = strlen(s.s);
+	dlg_set_toroute(dlg, &s);
 	dlg->sflags |= _dlg_ctx.flags;
 
 	if (_dlg_ctx.to_bye!=0)

+ 26 - 0
modules_k/dialog/dlg_hash.c

@@ -175,6 +175,9 @@ inline void destroy_dlg(struct dlg_cell *dlg)
 	if (dlg->cseq[DLG_CALLEE_LEG].s)
 		shm_free(dlg->cseq[DLG_CALLEE_LEG].s);
 
+	if (dlg->toroute_name.s)
+		shm_free(dlg->toroute_name.s);
+
 	shm_free(dlg);
 	dlg = 0;
 }
@@ -759,6 +762,29 @@ void next_state_dlg(struct dlg_cell *dlg, int event,
 		"state %d, due event %d\n",dlg,*old_state,*new_state,event);
 }
 
+/**
+ *
+ */
+int dlg_set_toroute(struct dlg_cell *dlg, str *route)
+{
+	if(dlg==NULL || route==NULL || route->len<=0)
+		return 0;
+	if(dlg->toroute_name.s!=NULL) {
+		shm_free(dlg->toroute_name.s);
+		dlg->toroute_name.s = NULL;
+		dlg->toroute_name.len = 0;
+	}
+	dlg->toroute_name.s = (char*)shm_malloc((route->len+1)*sizeof(char));
+	if(dlg->toroute_name.s!=NULL) {
+		LM_ERR("no more shared memory\n");
+		return -1;
+	}
+	memcpy(dlg->toroute_name.s, route->s, route->len);
+	dlg->toroute_name.len = route->len;
+	dlg->toroute_name.s[dlg->toroute_name.len] = '\0';
+	dlg->toroute = route_lookup(&main_rt, dlg->toroute_name.s);
+	return 0;
+}
 
 /**************************** MI functions ******************************/
 /*!

+ 9 - 0
modules_k/dialog/dlg_hash.h

@@ -98,6 +98,7 @@ struct dlg_cell
 	unsigned int         dflags;		/*!< internal dialog flags */
 	unsigned int         sflags;		/*!< script dialog flags */
 	unsigned int         toroute;		/*!< index of route that is executed on timeout */
+	str                  toroute_name;	/*!< name of route that is executed on timeout */
 	unsigned int         from_rr_nb;	/*!< information from record routing */
 	struct dlg_tl        tl;		/*!< dialog timer list */
 	str                  callid;		/*!< callid from SIP message */
@@ -238,6 +239,14 @@ int dlg_set_leg_info(struct dlg_cell *dlg, str* tag, str *rr, str *contact,
  */
 int dlg_update_cseq(struct dlg_cell *dlg, unsigned int leg, str *cseq);
 
+/*!
+ * \brief Set time-out route
+ * \param dlg dialog
+ * \param route name of route
+ * \return 0 on success, -1 on failure
+ */
+int dlg_set_toroute(struct dlg_cell *dlg, str *route);
+
 
 /*!
  * \brief Lookup a dialog in the global list

+ 5 - 2
modules_k/dialog/dlg_var.c

@@ -93,13 +93,16 @@ int pv_set_dlg_ctx(struct sip_msg* msg, pv_param_t *param,
 		break;
 		case 4:
 			if(val->flags&PV_VAL_STR) {
-				if(val->rs.s[val->rs.len]=='\0')
+				if(val->rs.s[val->rs.len]=='\0'
+						&& val->rs.len<DLG_TOROUTE_SIZE) {
 					_dlg_ctx.to_route = route_lookup(&main_rt, val->rs.s);
-				else _dlg_ctx.to_route = 0;
+					strcpy(_dlg_ctx.to_route_name, val->rs.s);
+				} else _dlg_ctx.to_route = 0;
 			} else {
 				if(n!=0) {
 					rtp = int2str(n, NULL);
 					_dlg_ctx.to_route = route_lookup(&main_rt, rtp);
+					strcpy(_dlg_ctx.to_route_name, rtp);
 				} else _dlg_ctx.to_route = 0;
 			}
 			if(_dlg_ctx.to_route <0) _dlg_ctx.to_route = 0;

+ 2 - 0
modules_k/dialog/dlg_var.h

@@ -26,11 +26,13 @@
 #include "../../pvar.h"
 #include "dlg_hash.h"
 
+#define DLG_TOROUTE_SIZE	32
 /*! dialog context */
 typedef struct _dlg_ctx {
 	int on;
 	unsigned int flags;
 	int to_route;
+	char to_route_name[DLG_TOROUTE_SIZE];
 	int to_bye;
 	int timeout;
 	struct dlg_cell *dlg;