Browse Source

dialog(k): patch from FS#18

- reworked part of patch from Francisco Javier Lizaran Vilches
- add r-uri to dialog structure
- r-uri value can be specified as PV via parameter, default is $ru
- for dlg_bridge, r-uri is same as to-uri
(cherry picked from commit df950f2a01f5f3d3da04e84a4f4a1cb810def038)
Daniel-Constantin Mierla 15 năm trước cách đây
mục cha
commit
8c1b49d5fd

+ 15 - 0
modules_k/dialog/dialog.c

@@ -89,6 +89,9 @@ static int db_fetch_rows = 200;
 
 str dlg_bridge_controller = {"sip:[email protected]", 27};
 
+str ruri_pvar_param = {"$ru", 3};
+pv_elem_t * ruri_param_model = NULL;
+
 /* statistic variables */
 int dlg_enable_stats = 1;
 int active_dlgs_cnt = 0;
@@ -204,6 +207,7 @@ static param_export_t mod_params[]={
 	{ "profiles_with_value",   STR_PARAM, &profiles_wv_s            },
 	{ "profiles_no_value",     STR_PARAM, &profiles_nv_s            },
 	{ "bridge_controller",     STR_PARAM, &dlg_bridge_controller.s  },
+	{ "ruri_pvar",             STR_PARAM, &ruri_pvar_param.s        },
 	{ 0,0,0 }
 };
 
@@ -438,6 +442,17 @@ static int mod_init(void)
 		return -1;
 	}
 
+	if (ruri_pvar_param.s==NULL || *ruri_pvar_param.s=='\0') {
+		LM_ERR("invalid r-uri PV string\n");
+		return -1;
+	}
+	ruri_pvar_param.len = strlen(ruri_pvar_param.s);
+	if(pv_parse_format(&ruri_pvar_param, &ruri_param_model) < 0
+				|| ruri_param_model==NULL) {
+		LM_ERR("malformed r-uri PV string: %s\n", ruri_pvar_param.s);
+		return -1;
+	}
+
 	/* update the len of the extra headers */
 	if (dlg_extra_hdrs.s)
 		dlg_extra_hdrs.len = strlen(dlg_extra_hdrs.s);

+ 16 - 7
modules_k/dialog/dlg_db_handler.c

@@ -60,6 +60,7 @@ 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 req_uri_column			=	str_init(REQ_URI_COL);
 str dialog_table_name		=	str_init(DIALOG_TABLE_NAME);
 int dlg_db_mode				=	DB_MODE_NONE;
 
@@ -196,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 };
+			&toroute_column,	&req_uri_column };
 
 	if(use_dialog_table() != 0){
 		return -1;
@@ -262,7 +263,7 @@ static int load_dialog_info_from_db(int dlg_hash_size, int fetch_num_rows)
 	db_row_t * rows;
 	int i, nr_rows;
 	struct dlg_cell *dlg;
-	str callid, from_uri, to_uri, from_tag, to_tag;
+	str callid, from_uri, to_uri, from_tag, to_tag, req_uri;
 	str cseq1, cseq2, contact1, contact2, rroute1, rroute2;
 	unsigned int next_id;
 	
@@ -302,8 +303,10 @@ static int load_dialog_info_from_db(int dlg_hash_size, int fetch_num_rows)
 			GET_STR_VALUE(from_uri, values, 3, 1, 0);
 			GET_STR_VALUE(from_tag, values, 4, 1, 0);
 			GET_STR_VALUE(to_uri, values, 5, 1, 0);
+			GET_STR_VALUE(req_uri, values, 20, 1, 0);
 
-			if((dlg=build_new_dlg(&callid, &from_uri, &to_uri, &from_tag))==0){
+			if((dlg=build_new_dlg(&callid, &from_uri, &to_uri, &from_tag,
+							&req_uri))==0){
 				LM_ERR("failed to build new dialog\n");
 				goto error;
 			}
@@ -453,7 +456,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 };
+			&sflags_column,      &toroute_column,     &req_uri_column };
 
 	if(use_dialog_table()!=0)
 		return -1;
@@ -467,7 +470,7 @@ int update_dialog_dbinfo(struct dlg_cell * cell)
 		VAL_TYPE(values+5) = VAL_TYPE(values+6) = VAL_TYPE(values+7) = 
 		VAL_TYPE(values+8) = VAL_TYPE(values+12) = VAL_TYPE(values+13) = 
 		VAL_TYPE(values+14) = VAL_TYPE(values+15) = VAL_TYPE(values+16)=
-		VAL_TYPE(values+17) = DB1_STR;
+		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;
@@ -513,6 +516,8 @@ int update_dialog_dbinfo(struct dlg_cell * cell)
 		VAL_INT(values+18)  = cell->sflags;
 		VAL_NULL(values+19) = 0;
 		VAL_INT(values+19)  = cell->toroute;
+		SET_STR_VALUE(values+20, cell->req_uri);
+		SET_PROPER_NULL_FLAG(cell->req_uri, 	values, 20);
 
 		if((dialog_dbf.insert(dialog_db_handle, insert_keys, values, 
 								DIALOG_TABLE_COL_NO)) !=0){
@@ -580,7 +585,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 };
+			&sflags_column,     &toroute_column, 		&req_uri_column };
 
 	if(use_dialog_table()!=0)
 		return;
@@ -593,7 +598,7 @@ void dialog_update_db(unsigned int ticks, void * param)
 	VAL_TYPE(values+5) = VAL_TYPE(values+6) = VAL_TYPE(values+7) = 
 	VAL_TYPE(values+8) = VAL_TYPE(values+12) = VAL_TYPE(values+13) = 
 	VAL_TYPE(values+14) = VAL_TYPE(values+15) = VAL_TYPE(values+16) = 
-	VAL_TYPE(values+17) = DB1_STR;
+	VAL_TYPE(values+17) = VAL_TYPE(values+20) = DB1_STR;
 
 	SET_NULL_FLAG(values, i, DIALOG_TABLE_COL_NO-6, 0);
 
@@ -651,6 +656,10 @@ void dialog_update_db(unsigned int ticks, void * param)
 				VAL_INT(values+18)		= cell->sflags;
 				VAL_INT(values+19)		= cell->toroute;
 
+				SET_STR_VALUE(values+20, cell->req_uri);
+				SET_PROPER_NULL_FLAG(cell->req_uri,
+					values, 20);
+
 				if((dialog_dbf.insert(dialog_db_handle, insert_keys, 
 				values, DIALOG_TABLE_COL_NO)) !=0){
 					LM_ERR("could not add another dialog to db\n");

+ 3 - 2
modules_k/dialog/dlg_db_handler.h

@@ -51,9 +51,10 @@
 #define TO_SOCK_COL				"callee_sock"
 #define SFLAGS_COL				"sflags"
 #define TOROUTE_COL				"toroute"
+#define REQ_URI_COL				"req_uri"
 #define DIALOG_TABLE_NAME		"dialog"
 
-#define DLG_TABLE_VERSION		3
+#define DLG_TABLE_VERSION		4
 
 /*every minute the dialogs' information will be refreshed*/
 #define DB_DEFAULT_UPDATE_PERIOD	60
@@ -62,7 +63,7 @@
 #define DB_MODE_DELAYED				2
 #define DB_MODE_SHUTDOWN			3
 
-#define DIALOG_TABLE_COL_NO 		20
+#define DIALOG_TABLE_COL_NO 		21
 
 
 extern str call_id_column; 

+ 9 - 1
modules_k/dialog/dlg_handlers.c

@@ -93,6 +93,7 @@ extern stat_var *processed_dlgs;	/*!< number of processed dialogs */
 extern stat_var *expired_dlgs;		/*!< number of expired dialogs */
 extern stat_var *failed_dlgs;		/*!< number of failed dialogs */
 
+extern pv_elem_t *ruri_param_model;	/*!< pv-string to get r-uri */
 
 static unsigned int CURR_DLG_LIFETIME = 0;	/*!< current dialog lifetime */
 static unsigned int CURR_DLG_STATUS = 0;	/*!< current dialog state */
@@ -533,6 +534,7 @@ int dlg_new_dialog(struct sip_msg *msg, struct cell *t)
 {
 	struct dlg_cell *dlg;
 	str s;
+	str req_uri;
 
 	if((msg->to==NULL && parse_headers(msg, HDR_TO_F,0)<0) || msg->to==NULL)
 	{
@@ -559,6 +561,12 @@ int dlg_new_dialog(struct sip_msg *msg, struct cell *t)
 	s = msg->callid->body;
 	trim(&s);
 
+	if (pv_printf_s(msg, ruri_param_model, &req_uri)<0) {
+		LM_ERR("error - cannot print the r-uri format\n");
+		return -1;
+	}
+	trim(&req_uri);
+
 	/* some sanity checks */
 	if (s.len==0 || get_from(msg)->tag_value.len==0) {
 		LM_ERR("invalid request -> callid (%d) or from TAG (%d) empty\n",
@@ -568,7 +576,7 @@ int dlg_new_dialog(struct sip_msg *msg, struct cell *t)
 
 	dlg = build_new_dlg(&s /*callid*/, &(get_from(msg)->uri) /*from uri*/,
 		&(get_to(msg)->uri) /*to uri*/,
-		&(get_from(msg)->tag_value)/*from_tag*/ );
+		&(get_from(msg)->tag_value)/*from_tag*/, &req_uri /*r-uri*/ );
 	if (dlg==0) {
 		LM_ERR("failed to create new dialog\n");
 		return -1;

+ 9 - 3
modules_k/dialog/dlg_hash.c

@@ -218,17 +218,18 @@ void destroy_dlg_table(void)
  * \param from_uri dialog from uri
  * \param to_uri dialog to uri
  * \param from_tag dialog from tag
+ * \param req_uri dialog r-uri
  * \return created dialog structure on success, NULL otherwise
  */
 struct dlg_cell* build_new_dlg( str *callid, str *from_uri, str *to_uri,
-		str *from_tag)
+		str *from_tag, str *req_uri)
 {
 	struct dlg_cell *dlg;
 	int len;
 	char *p;
 
 	len = sizeof(struct dlg_cell) + callid->len + from_uri->len +
-		to_uri->len;
+		to_uri->len + req_uri->len;
 	dlg = (struct dlg_cell*)shm_malloc( len );
 	if (dlg==0) {
 		LM_ERR("no more shm mem (%d)\n",len);
@@ -256,7 +257,12 @@ struct dlg_cell* build_new_dlg( str *callid, str *from_uri, str *to_uri,
 	dlg->to_uri.s = p;
 	dlg->to_uri.len = to_uri->len;
 	memcpy( p, to_uri->s, to_uri->len);
-	p += to_uri->len;
+	p += to_uri->len; 
+
+	dlg->req_uri.s = p;
+	dlg->req_uri.len = req_uri->len;
+	memcpy( p, req_uri->s, req_uri->len);
+	p += req_uri->len;
 
 	if ( p!=(((char*)dlg)+len) ) {
 		LM_CRIT("buffer overflow\n");

+ 3 - 1
modules_k/dialog/dlg_hash.h

@@ -103,6 +103,7 @@ struct dlg_cell
 	str                  callid;		/*!< callid from SIP message */
 	str                  from_uri;		/*!< from uri from SIP message */
 	str                  to_uri;		/*!< to uri from SIP message */
+	str                  req_uri;		/*!< r-uri from SIP message */
 	str                  tag[2];		/*!< from tags of caller and to tag of callee */
 	str                  cseq[2];		/*!< CSEQ of caller and callee */
 	str                  route_set[2];	/*!< route set of caller and callee */
@@ -207,10 +208,11 @@ void destroy_dlg_table(void);
  * \param from_uri dialog from uri
  * \param to_uri dialog to uri
  * \param from_tag dialog from tag
+ * \param req_uri dialog r-uri
  * \return created dialog structure on success, NULL otherwise
  */
 struct dlg_cell* build_new_dlg(str *callid, str *from_uri,
-		str *to_uri, str *from_tag);
+		str *to_uri, str *from_tag, str *req_uri);
 
 
 /*!

+ 4 - 3
modules_k/dialog/dlg_transfer.c

@@ -241,7 +241,8 @@ void dlg_bridge_tm_callback(struct cell *t, int type, struct tmcb_params *ps)
 
 	dlg = build_new_dlg(&s /*callid*/, &(get_from(msg)->uri) /*from uri*/,
 		&(get_to(msg)->uri) /*to uri*/,
-		&(get_from(msg)->tag_value)/*from_tag*/ );
+		&(get_from(msg)->tag_value)/*from_tag*/,
+		&(get_to(msg)->uri) /*use to as r-uri*/ );
 	if (dlg==0) {
 		LM_ERR("failed to create new dialog\n");
 		goto error;
@@ -383,11 +384,11 @@ int dlg_transfer(struct dlg_cell *dlg, str *to, int side)
 	if(side==DLG_CALLER_LEG)
 		ndlg = build_new_dlg(&dlg->callid /*callid*/,
 				&dlg->to_uri /*from uri*/, &dlg->from_uri /*to uri*/,
-				&dlg->tag[side]/*from_tag*/ );
+				&dlg->tag[side]/*from_tag*/, &dlg->req_uri /*req uri */ );
 	else
 		ndlg = build_new_dlg(&dlg->callid /*callid*/,
 				&dlg->from_uri /*from uri*/, &dlg->to_uri /*to uri*/,
-				&dlg->tag[side]/*from_tag*/ );
+				&dlg->tag[side]/*from_tag*/, &dlg->req_uri /*req uri */ );
 	if (ndlg==0) {
 		LM_ERR("failed to create new dialog\n");
 		goto error;