[SR-Dev] git:master: dialog: fix dlg flags and profile issues

Daniel-Constantin Mierla miconda at gmail.com
Mon Apr 20 12:25:10 CEST 2009


Module: sip-router
Branch: master
Commit: 5d131fe7d5ca78526372bab26af27c7501326f57
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5d131fe7d5ca78526372bab26af27c7501326f57

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Mon Apr 20 12:23:06 2009 +0200

dialog: fix dlg flags and profile issues

- reported by Alex Balasov and Inaki Baz Castillo
- flags operations were not taken in account
- profiles without name were buggy

---

 modules_k/dialog/dialog.c         |   35 +++++++++++++++++++++++------------
 modules_k/dialog/dlg_db_handler.c |    6 ++++--
 modules_k/dialog/dlg_handlers.c   |    2 +-
 modules_k/dialog/dlg_var.c        |    4 ++++
 modules_k/dialog/dlg_var.h        |    2 ++
 5 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/modules_k/dialog/dialog.c b/modules_k/dialog/dialog.c
index bbb8565..d97bd52 100644
--- a/modules_k/dialog/dialog.c
+++ b/modules_k/dialog/dialog.c
@@ -682,9 +682,14 @@ static int w_get_profile_size(struct sip_msg *msg, char *profile,
 	unsigned int size;
 	pv_value_t val;
 
-	pve = (pv_elem_t *)value;
-	sp_dest = (pv_spec_t *)result;
-
+	if(result!=NULL)
+	{
+		pve = (pv_elem_t *)value;
+		sp_dest = (pv_spec_t *)result;
+	} else {
+		pve = NULL;
+		sp_dest = (pv_spec_t *)value;
+	}
 	if ( pve!=NULL && ((struct dlg_profile_table*)profile)->has_value) {
 		if ( pv_printf_s(msg, pve, &val_s)!=0 || 
 		val_s.len == 0 || val_s.s == NULL) {
@@ -711,7 +716,7 @@ static int w_get_profile_size(struct sip_msg *msg, char *profile,
 
 static int w_dlg_setflag(struct sip_msg *msg, char *flag, char *s2)
 {
-	struct dlg_cell *dlg;
+	dlg_ctx_t *dctx;
 	int val;
 
 	if(fixup_get_ivalue(msg, (gparam_p)flag, &val)!=0)
@@ -721,17 +726,19 @@ static int w_dlg_setflag(struct sip_msg *msg, char *flag, char *s2)
 	}
 	if(val<0 || val>31)
 		return -1;
-	if ( (dlg=dlg_get_ctx_dialog())==NULL )
+	if ( (dctx=dlg_get_dlg_ctx())==NULL )
 		return -1;
 
-	dlg->sflags |= 1<<val;
+	dctx->flags |= 1<<val;
+	if(dctx->dlg)
+		dctx->dlg->sflags |= 1<<val;
 	return 1;
 }
 
 
 static int w_dlg_resetflag(struct sip_msg *msg, char *flag, str *s2)
 {
-	struct dlg_cell *dlg;
+	dlg_ctx_t *dctx;
 	int val;
 
 	if(fixup_get_ivalue(msg, (gparam_p)flag, &val)!=0)
@@ -742,17 +749,19 @@ static int w_dlg_resetflag(struct sip_msg *msg, char *flag, str *s2)
 	if(val<0 || val>31)
 		return -1;
 
-	if ( (dlg=dlg_get_ctx_dialog())==NULL )
+	if ( (dctx=dlg_get_dlg_ctx())==NULL )
 		return -1;
 
-	dlg->sflags &= ~(1<<val);
+	dctx->flags &= ~(1<<val);
+	if(dctx->dlg)
+		dctx->dlg->sflags &= ~(1<<val);
 	return 1;
 }
 
 
 static int w_dlg_isflagset(struct sip_msg *msg, char *flag, str *s2)
 {
-	struct dlg_cell *dlg;
+	dlg_ctx_t *dctx;
 	int val;
 
 	if(fixup_get_ivalue(msg, (gparam_p)flag, &val)!=0)
@@ -763,10 +772,12 @@ static int w_dlg_isflagset(struct sip_msg *msg, char *flag, str *s2)
 	if(val<0 || val>31)
 		return -1;
 
-	if ( (dlg=dlg_get_ctx_dialog())==NULL )
+	if ( (dctx=dlg_get_dlg_ctx())==NULL )
 		return -1;
 
-	return (dlg->sflags&(1<<val))?1:-1;
+	if(dctx->dlg)
+		return (dctx->dlg->sflags&(1<<val))?1:-1;
+	return (dctx->flags&(1<<val))?1:-1;
 }
 
 static int w_dlg_manage(struct sip_msg *msg, char *s1, char *s2)
diff --git a/modules_k/dialog/dlg_db_handler.c b/modules_k/dialog/dlg_db_handler.c
index 61b99e9..1d39d08 100644
--- a/modules_k/dialog/dlg_db_handler.c
+++ b/modules_k/dialog/dlg_db_handler.c
@@ -509,8 +509,10 @@ int update_dialog_dbinfo(struct dlg_cell * cell)
 		SET_PROPER_NULL_FLAG(cell->contact[DLG_CALLER_LEG], 	values, 16);
 		SET_PROPER_NULL_FLAG(cell->contact[DLG_CALLEE_LEG], 	values, 17);
 
-		VAL_INT(values+18)		= cell->sflags;
-		VAL_INT(values+19)		= cell->toroute;
+		VAL_NULL(values+18) = 0;
+		VAL_INT(values+18)  = cell->sflags;
+		VAL_NULL(values+19) = 0;
+		VAL_INT(values+19)  = cell->toroute;
 
 		if((dialog_dbf.insert(dialog_db_handle, insert_keys, values, 
 								DIALOG_TABLE_COL_NO)) !=0){
diff --git a/modules_k/dialog/dlg_handlers.c b/modules_k/dialog/dlg_handlers.c
index fb53bd4..082e835 100644
--- a/modules_k/dialog/dlg_handlers.c
+++ b/modules_k/dialog/dlg_handlers.c
@@ -485,7 +485,7 @@ int dlg_new_dialog(struct sip_msg *msg, struct cell *t)
 		return -1;
 	}
 
-	current_dlg_pointer = dlg;
+	set_current_dialog(msg, dlg);
 	_dlg_ctx.dlg = dlg;
 
 	link_dlg(dlg, 2/* extra ref for the callback and current dlg hook */);
diff --git a/modules_k/dialog/dlg_var.c b/modules_k/dialog/dlg_var.c
index 482ca1f..588e231 100644
--- a/modules_k/dialog/dlg_var.c
+++ b/modules_k/dialog/dlg_var.c
@@ -372,3 +372,7 @@ struct dlg_cell* dlg_get_ctx_dialog(void)
 	return _dlg_ctx.dlg;
 }
 
+dlg_ctx_t* dlg_get_dlg_ctx(void)
+{
+	return &_dlg_ctx;
+}
diff --git a/modules_k/dialog/dlg_var.h b/modules_k/dialog/dlg_var.h
index 27f5305..a1813f8 100644
--- a/modules_k/dialog/dlg_var.h
+++ b/modules_k/dialog/dlg_var.h
@@ -54,4 +54,6 @@ int dlg_cfg_cb(struct sip_msg *foo, void *bar);
 void dlg_set_ctx_dialog(struct dlg_cell *dlg);
 struct dlg_cell* dlg_get_ctx_dialog(void);
 
+dlg_ctx_t* dlg_get_dlg_ctx(void);
+
 #endif




More information about the sr-dev mailing list