Browse code

dialog: more safety checks to detect if dialog is gone after event route execution

- avoid execution of script callbacks for event route
- related to GH #1059 and #1069

Daniel-Constantin Mierla authored on 21/04/2017 19:39:22
Showing 5 changed files
... ...
@@ -455,7 +455,11 @@ static void dlg_onreply(struct cell* t, int type, struct tmcb_params *param)
455 455
 		event = DLG_EVENT_RPL3xx;
456 456
 
457 457
 	next_state_dlg( dlg, event, &old_state, &new_state, &unref);
458
-	dlg_run_event_route(dlg, (rpl==FAKED_REPLY)?NULL:rpl, old_state, new_state);
458
+	if(dlg_run_event_route(dlg, (rpl==FAKED_REPLY)?NULL:rpl, old_state,
459
+			new_state)<0) {
460
+		/* dialog is gone */
461
+		return;
462
+	}
459 463
 
460 464
 	if (new_state==DLG_STATE_EARLY) {
461 465
 		run_dlg_callbacks(DLGCB_EARLY, dlg, req, rpl, DLG_DIR_UPSTREAM, 0);
... ...
@@ -1227,7 +1231,6 @@ dlg_cell_t *dlg_get_msg_dialog(sip_msg_t *msg)
1227 1227
 void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
1228 1228
 {
1229 1229
 	dlg_cell_t *dlg = NULL;
1230
-	dlg_cell_t *dlg0 = NULL;
1231 1230
 	dlg_iuid_t *iuid = NULL;
1232 1231
 	str val, callid, ftag, ttag;
1233 1232
 	int h_entry=0, h_id=0, new_state=0, old_state=0;
... ...
@@ -1366,15 +1369,9 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
1366 1366
 	CURR_DLG_LIFETIME = (unsigned int)(time(0))-dlg->start_ts;
1367 1367
 	CURR_DLG_STATUS = new_state;
1368 1368
 
1369
-	dlg_run_event_route(dlg, req, old_state, new_state);
1370
-
1371
-	dlg0 = dlg_lookup(h_entry, h_id);
1372
-	if (dlg0==0) {
1373
-		LM_ALERT("after event route - dialog not found [%u:%u] (%d/%d) (%p)\n",
1374
-				h_entry, h_id, old_state, new_state, dlg);
1369
+	if(dlg_run_event_route(dlg, req, old_state, new_state)<0) {
1370
+		/* dialog is gone */
1375 1371
 		return;
1376
-	} else {
1377
-		dlg_release(dlg0);
1378 1372
 	}
1379 1373
 
1380 1374
 	/* delay deletion of dialog until transaction has died off in order
... ...
@@ -1589,7 +1586,10 @@ void dlg_ontimeout(struct dlg_tl *tl)
1589 1589
 		timeout_cb = (void *)CONFIRMED_DIALOG_STATE;
1590 1590
 	}
1591 1591
 
1592
-	dlg_run_event_route(dlg, NULL, old_state, new_state);
1592
+	if(dlg_run_event_route(dlg, NULL, old_state, new_state)<0) {
1593
+		/* dialog is gone */
1594
+		return;
1595
+	}
1593 1596
 
1594 1597
 	if (new_state==DLG_STATE_DELETED && old_state!=DLG_STATE_DELETED) {
1595 1598
 		LM_WARN("timeout for dlg with CallID '%.*s' and tags '%.*s' '%.*s'\n",
... ...
@@ -1680,20 +1680,24 @@ int pv_get_dlg_status(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
1680 1680
 
1681 1681
 /*!
1682 1682
  * \brief Execute event routes based on new state
1683
- *
1683
+ * - returns: -1 if dialog doesn't exist after event route execution
1684
+ *             0 if all ok
1684 1685
  */
1685
-void dlg_run_event_route(dlg_cell_t *dlg, sip_msg_t *msg, int ostate, int nstate)
1686
+int dlg_run_event_route(dlg_cell_t *dlg, sip_msg_t *msg, int ostate, int nstate)
1686 1687
 {
1687 1688
 	sip_msg_t *fmsg;
1688 1689
 	int rt;
1689 1690
 	int bkroute;
1690 1691
 	sr_kemi_eng_t *keng = NULL;
1691
-	str evname;
1692
+	str evname = str_init("unknown");
1693
+	int h_entry=0;
1694
+	int h_id=0;
1695
+	dlg_cell_t *dlg0 = NULL;
1692 1696
 
1693 1697
 	if(dlg==NULL)
1694
-		return;
1698
+		return -1;
1695 1699
 	if(ostate==nstate)
1696
-		return;
1700
+		return 0;
1697 1701
 
1698 1702
 	rt = -1;
1699 1703
 	if(dlg_event_callback.s==NULL || dlg_event_callback.len<=0) {
... ...
@@ -1713,13 +1717,13 @@ void dlg_run_event_route(dlg_cell_t *dlg, sip_msg_t *msg, int ostate, int nstate
1713 1713
 			}
1714 1714
 		}
1715 1715
 		if(rt==-1 || event_rt.rlist[rt]==NULL)
1716
-			return;
1716
+			return 0;
1717 1717
 	}  else {
1718 1718
 		keng = sr_kemi_eng_get();
1719 1719
 		if(keng==NULL) {
1720 1720
 			LM_DBG("event callback (%s) set, but no cfg engine\n",
1721 1721
 					dlg_event_callback.s);
1722
-			return;
1722
+			return 0;
1723 1723
 		}
1724 1724
 	}
1725 1725
 
... ...
@@ -1730,9 +1734,11 @@ void dlg_run_event_route(dlg_cell_t *dlg, sip_msg_t *msg, int ostate, int nstate
1730 1730
 			fmsg = msg;
1731 1731
 
1732 1732
 		if (exec_pre_script_cb(fmsg, LOCAL_CB_TYPE)<=0)
1733
-			return;
1733
+			return 0;
1734 1734
 
1735 1735
 		dlg_ref(dlg, 1);
1736
+		h_entry = dlg->h_entry;
1737
+		h_id = dlg->h_id;
1736 1738
 		dlg_set_ctx_iuid(dlg);
1737 1739
 		LM_DBG("executing event_route %d on state %d\n", rt, nstate);
1738 1740
 		bkroute = get_route_type();
... ...
@@ -1750,9 +1756,19 @@ void dlg_run_event_route(dlg_cell_t *dlg, sip_msg_t *msg, int ostate, int nstate
1750 1750
 		}
1751 1751
 		dlg_reset_ctx_iuid();
1752 1752
 		exec_post_script_cb(fmsg, LOCAL_CB_TYPE);
1753
-		dlg_unref(dlg, 1);
1754 1753
 		set_route_type(bkroute);
1754
+		/* re-lookup the dialog, execution of the route could take long time */
1755
+		dlg0 = dlg_lookup(h_entry, h_id);
1756
+		if (dlg0==0) {
1757
+			LM_ALERT("after event route - dialog not found [%u:%u] (%d/%d) (%p) (%.*s)\n",
1758
+					h_entry, h_id, ostate, nstate, dlg, evname.len, evname.s);
1759
+			return -1;
1760
+		} else {
1761
+			dlg_release(dlg0);
1762
+			dlg_unref(dlg, 1);
1763
+		}
1755 1764
 	}
1765
+	return 0;
1756 1766
 }
1757 1767
 
1758 1768
 int dlg_manage(sip_msg_t *msg)
... ...
@@ -561,7 +561,7 @@ static inline int match_downstream_dialog(dlg_cell_t *dlg, str *callid, str *fta
561 561
 /*!
562 562
  *
563 563
  */
564
-void dlg_run_event_route(dlg_cell_t *dlg, sip_msg_t *msg, int ostate, int nstate);
564
+int dlg_run_event_route(dlg_cell_t *dlg, sip_msg_t *msg, int ostate, int nstate);
565 565
 
566 566
 
567 567
 int dlg_ka_add(dlg_cell_t *dlg);
... ...
@@ -203,7 +203,7 @@ static struct dlg_profile_table* new_dlg_profile( str *name, unsigned int size,
203 203
 
204 204
 	/* set inner pointers */
205 205
 	profile->entries = (struct dlg_profile_entry*)(profile + 1);
206
-	profile->name.s = ((char*)profile->entries) + 
206
+	profile->name.s = ((char*)profile->entries) +
207 207
 		size*sizeof(struct dlg_profile_entry);
208 208
 
209 209
 	/* copy the name of the profile */
... ...
@@ -258,7 +258,7 @@ void destroy_dlg_profiles(void)
258 258
 /*!
259 259
  * \brief Destroy dialog linkers
260 260
  * \param linker dialog linker
261
- */ 
261
+ */
262 262
 void destroy_linkers(struct dlg_profile_link *linker)
263 263
 {
264 264
 	struct dlg_profile_entry *p_entry;
... ...
@@ -437,6 +437,10 @@ int profile_cleanup( struct sip_msg *msg, unsigned int flags, void *param )
437 437
 {
438 438
 	dlg_cell_t *dlg;
439 439
 
440
+	if(get_route_type()==LOCAL_ROUTE) {
441
+		return 1;
442
+	}
443
+
440 444
 	current_dlg_msg_id = 0;
441 445
 	current_dlg_msg_pid = 0;
442 446
 	dlg = dlg_get_ctx_dialog();
... ...
@@ -481,7 +485,7 @@ static void link_profile(struct dlg_profile_link *linker, str *vkey)
481 481
 		p_entry->first->prev->next = &linker->hash_linker;
482 482
 		p_entry->first->prev = &linker->hash_linker;
483 483
 	} else {
484
-		p_entry->first = linker->hash_linker.next 
484
+		p_entry->first = linker->hash_linker.next
485 485
 			= linker->hash_linker.prev = &linker->hash_linker;
486 486
 	}
487 487
 	p_entry->content ++;
... ...
@@ -847,7 +851,7 @@ int	is_known_dlg(struct sip_msg *msg) {
847 847
 	dlg_cell_t *dlg;
848 848
 
849 849
 	dlg = dlg_get_msg_dialog(msg);
850
-	
850
+
851 851
 	if(dlg == NULL)
852 852
 		return -1;
853 853
 
... ...
@@ -863,14 +867,14 @@ int	is_known_dlg(struct sip_msg *msg) {
863 863
  * \param timeout The dialog timeout to apply.
864 864
  */
865 865
 
866
-int	dlg_set_timeout_by_profile(struct dlg_profile_table *profile, 
867
-				   str *value, int timeout) 
866
+int	dlg_set_timeout_by_profile(struct dlg_profile_table *profile,
867
+				   str *value, int timeout)
868 868
 {
869 869
 	unsigned int		i = 0;
870 870
 	dlg_cell_t		*this_dlg = NULL;
871 871
 	struct dlg_profile_hash	*ph = NULL;
872 872
 
873
-	/* Private structure necessary for manipulating dialog 
873
+	/* Private structure necessary for manipulating dialog
874 874
          * timeouts outside of profile locks.  Admittedly, an
875 875
          * ugly hack, but avoids some concurrency issues.
876 876
          */
... ...
@@ -883,7 +887,7 @@ int	dlg_set_timeout_by_profile(struct dlg_profile_table *profile,
883 883
 
884 884
 	map_head = NULL;
885 885
 
886
-	/* If the profile has no value, iterate through every 
886
+	/* If the profile has no value, iterate through every
887 887
 	 * node and set its timeout.
888 888
 	 */
889 889
 
... ...
@@ -894,8 +898,8 @@ int	dlg_set_timeout_by_profile(struct dlg_profile_table *profile,
894 894
 			ph = profile->entries[i].first;
895 895
 
896 896
 			if(!ph) continue;
897
-			
898
-			do { 
897
+
898
+			do {
899 899
 				struct dlg_map_list *d = malloc(sizeof(struct dlg_map_list));
900 900
 
901 901
 				if(!d)
... ...
@@ -912,10 +916,10 @@ int	dlg_set_timeout_by_profile(struct dlg_profile_table *profile,
912 912
 					d->next = map_head;
913 913
 					map_head = d;
914 914
 				}
915
-	
915
+
916 916
 				ph = ph->next;
917 917
 			} while(ph != profile->entries[i].first);
918
-		} 
918
+		}
919 919
 
920 920
 		lock_release(&profile->lock);
921 921
 	}
... ...
@@ -957,7 +961,7 @@ int	dlg_set_timeout_by_profile(struct dlg_profile_table *profile,
957 957
 	}
958 958
 
959 959
 	/* Walk the list and bulk-set the timeout */
960
-	
960
+
961 961
 	for(map_scan = map_head; map_scan != NULL; map_scan = map_scan_next) {
962 962
 		map_scan_next = map_scan->next;
963 963
 
... ...
@@ -965,7 +969,7 @@ int	dlg_set_timeout_by_profile(struct dlg_profile_table *profile,
965 965
 
966 966
 		if(!this_dlg) {
967 967
 			LM_CRIT("Unable to find dialog %d:%d\n", map_scan->h_entry, map_scan->h_id);
968
-		} else if(this_dlg->state >= DLG_STATE_EARLY) {	
968
+		} else if(this_dlg->state >= DLG_STATE_EARLY) {
969 969
 			if(update_dlg_timeout(this_dlg, timeout) < 0) {
970 970
                			LM_ERR("Unable to set timeout on %d:%d\n", map_scan->h_entry,
971 971
 					map_scan->h_id);
... ...
@@ -48,6 +48,9 @@ int msg_id;
48 48
 int dlg_cfg_cb(sip_msg_t *msg, unsigned int flags, void *cbp)
49 49
 {
50 50
 	dlg_cell_t *dlg;
51
+	if(get_route_type()==LOCAL_ROUTE) {
52
+		return 1;
53
+	}
51 54
 	if(flags&POST_SCRIPT_CB) {
52 55
 		dlg = dlg_get_ctx_dialog();
53 56
 		if(dlg!=NULL) {
... ...
@@ -77,6 +80,10 @@ int dlg_cfg_cb(sip_msg_t *msg, unsigned int flags, void *cbp)
77 77
 
78 78
 int cb_dlg_cfg_reset(sip_msg_t *msg, unsigned int flags, void *cbp)
79 79
 {
80
+	if(get_route_type()==LOCAL_ROUTE) {
81
+		return 1;
82
+	}
83
+
80 84
 	memset(&_dlg_ctx, 0, sizeof(dlg_ctx_t));
81 85
 
82 86
 	return 1;
... ...
@@ -84,6 +91,9 @@ int cb_dlg_cfg_reset(sip_msg_t *msg, unsigned int flags, void *cbp)
84 84
 
85 85
 int cb_dlg_locals_reset(sip_msg_t *msg, unsigned int flags, void *cbp)
86 86
 {
87
+	if(get_route_type()==LOCAL_ROUTE) {
88
+		return 1;
89
+	}
87 90
 	LM_DBG("resetting the local dialog shortcuts on script callback: %u\n", flags);
88 91
 	cb_dlg_cfg_reset(msg, flags, cbp);
89 92
 	cb_profile_reset(msg, flags, cbp);
... ...
@@ -106,7 +116,7 @@ static inline struct dlg_var *new_dlg_var(str *key, str *val)
106 106
 	var->key.len = key->len;
107 107
 	var->key.s = (char*)shm_malloc(var->key.len+1);
108 108
 	if (var->key.s==NULL) {
109
-		shm_free(var);			
109
+		shm_free(var);
110 110
 		LM_ERR("no more shm mem\n");
111 111
 		return NULL;
112 112
 	}
... ...
@@ -116,8 +126,8 @@ static inline struct dlg_var *new_dlg_var(str *key, str *val)
116 116
 	var->value.len = val->len;
117 117
 	var->value.s = (char*)shm_malloc(var->value.len+1);
118 118
 	if (var->value.s==NULL) {
119
-		shm_free(var->key.s);			
120
-		shm_free(var);			
119
+		shm_free(var->key.s);
120
+		shm_free(var);
121 121
 		LM_ERR("no more shm mem\n");
122 122
 		return NULL;
123 123
 	}
... ...
@@ -160,10 +170,10 @@ int set_dlg_variable_unsafe(struct dlg_cell *dlg, str *key, str *val)
160 160
 	struct dlg_var * it;
161 161
 	struct dlg_var * it_prev;
162 162
 	struct dlg_var ** var_list;
163
-	
164
-	if (dlg) 
163
+
164
+	if (dlg)
165 165
 		var_list = &dlg->vars;
166
-	else 
166
+	else
167 167
 		var_list = &_dlg_var_table;
168 168
 
169 169
 	if ( val && (var=new_dlg_var(key, val))==NULL) {
... ...
@@ -188,7 +198,7 @@ int set_dlg_variable_unsafe(struct dlg_cell *dlg, str *key, str *val)
188 188
 				/* Take the previous vflags: */
189 189
 				var->vflags = it->vflags | DLG_FLAG_CHANGED;
190 190
 				if (it_prev) it_prev->next = var;
191
-				else *var_list = var;				  
191
+				else *var_list = var;
192 192
 			}
193 193
 
194 194
 			/* Free this var: */
... ...
@@ -216,7 +226,7 @@ str * get_dlg_variable_unsafe(struct dlg_cell *dlg, str *key)
216 216
 {
217 217
 	struct dlg_var *var, *var_list;
218 218
 
219
-	if (dlg) 
219
+	if (dlg)
220 220
 		var_list = dlg->vars;
221 221
 	else
222 222
 		var_list = _dlg_var_table;
... ...
@@ -385,7 +395,7 @@ int pv_set_dlg_variable(struct sip_msg* msg, pv_param_t *param, int op, pv_value
385 385
 
386 386
 	/* Retrieve the dialog for current message */
387 387
 	dlg=dlg_get_msg_dialog( msg);
388
-	
388
+
389 389
 	if (dlg) {
390 390
 		/* Lock the dialog */
391 391
 		dlg_lock(d_table, &(d_table->entries[dlg->h_entry]));
... ...
@@ -816,24 +826,24 @@ int pv_parse_dlg_name(pv_spec_p sp, str *in)
816 816
 
817 817
 	switch(in->len)
818 818
 	{
819
-		case 3: 
819
+		case 3:
820 820
 			if(strncmp(in->s, "ref", 3)==0)
821 821
 				sp->pvp.pvn.u.isname.name.n = 0;
822 822
 			else goto error;
823 823
 		break;
824
-		case 4: 
824
+		case 4:
825 825
 			if(strncmp(in->s, "h_id", 4)==0)
826 826
 				sp->pvp.pvn.u.isname.name.n = 1;
827 827
 			else goto error;
828 828
 		break;
829
-		case 5: 
829
+		case 5:
830 830
 			if(strncmp(in->s, "state", 5)==0)
831 831
 				sp->pvp.pvn.u.isname.name.n = 2;
832 832
 			else if(strncmp(in->s, "to_rs", 5)==0)
833 833
 				sp->pvp.pvn.u.isname.name.n = 3;
834 834
 			else goto error;
835 835
 		break;
836
-		case 6: 
836
+		case 6:
837 837
 			if(strncmp(in->s, "dflags", 6)==0)
838 838
 				sp->pvp.pvn.u.isname.name.n = 4;
839 839
 			else if(strncmp(in->s, "sflags", 6)==0)
... ...
@@ -846,7 +856,7 @@ int pv_parse_dlg_name(pv_spec_p sp, str *in)
846 846
 				sp->pvp.pvn.u.isname.name.n = 8;
847 847
 			else goto error;
848 848
 		break;
849
-		case 7: 
849
+		case 7:
850 850
 			if(strncmp(in->s, "toroute", 7)==0)
851 851
 				sp->pvp.pvn.u.isname.name.n = 9;
852 852
 			else if(strncmp(in->s, "to_cseq", 7)==0)
... ...
@@ -857,7 +867,7 @@ int pv_parse_dlg_name(pv_spec_p sp, str *in)
857 857
 				sp->pvp.pvn.u.isname.name.n = 21;
858 858
 			else goto error;
859 859
 		break;
860
-		case 8: 
860
+		case 8:
861 861
 			if(strncmp(in->s, "from_uri", 8)==0)
862 862
 				sp->pvp.pvn.u.isname.name.n = 12;
863 863
 			else if(strncmp(in->s, "from_tag", 8)==0)
... ...
@@ -868,27 +878,27 @@ int pv_parse_dlg_name(pv_spec_p sp, str *in)
868 868
 				sp->pvp.pvn.u.isname.name.n = 15;
869 869
 			else goto error;
870 870
 		break;
871
-		case 9: 
871
+		case 9:
872 872
 			if(strncmp(in->s, "from_cseq", 9)==0)
873 873
 				sp->pvp.pvn.u.isname.name.n = 16;
874 874
 			else goto error;
875 875
 		break;
876
-		case 10: 
876
+		case 10:
877 877
 			if(strncmp(in->s, "to_contact", 10)==0)
878 878
 				sp->pvp.pvn.u.isname.name.n = 17;
879 879
 			else goto error;
880 880
 		break;
881
-		case 11: 
881
+		case 11:
882 882
 			if(strncmp(in->s, "to_bindaddr", 11)==0)
883 883
 				sp->pvp.pvn.u.isname.name.n = 18;
884 884
 			else goto error;
885 885
 		break;
886
-		case 12: 
886
+		case 12:
887 887
 			if(strncmp(in->s, "from_contact", 12)==0)
888 888
 				sp->pvp.pvn.u.isname.name.n = 19;
889 889
 			else goto error;
890 890
 		break;
891
-		case 13: 
891
+		case 13:
892 892
 			if(strncmp(in->s, "from_bindaddr", 13)==0)
893 893
 				sp->pvp.pvn.u.isname.name.n = 20;
894 894
 			else goto error;
... ...
@@ -930,6 +940,9 @@ dlg_ctx_t* dlg_get_dlg_ctx(void)
930 930
 
931 931
 int spiral_detect_reset(struct sip_msg *foo, unsigned int flags, void *bar)
932 932
 {
933
+	if(get_route_type()==LOCAL_ROUTE) {
934
+		return 1;
935
+	}
933 936
 	spiral_detected = -1;
934 937
 
935 938
 	return 0;
... ...
@@ -20,7 +20,7 @@
20 20
  * along with this program; if not, write to the Free Software
21 21
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 22
  */
23
-		       
23
+
24 24
 #include "../../core/route.h"
25 25
 #include "../../core/pvapi.h"
26 26
 
... ...
@@ -40,7 +40,10 @@ int msg_id;
40 40
 
41 41
 int dlg_cfg_cb(struct sip_msg *foo, unsigned int flags, void *bar)
42 42
 {
43
-        memset(&_dlg_ctx, 0, sizeof(dlg_ctx_t));
43
+	if(get_route_type()==LOCAL_ROUTE) {
44
+		return 1;
45
+	}
46
+	memset(&_dlg_ctx, 0, sizeof(dlg_ctx_t));
44 47
 	return 1;
45 48
 }
46 49
 
... ...
@@ -60,7 +63,7 @@ static inline struct dlg_var *new_dlg_var(str *key, str *val)
60 60
 	var->key.len = key->len;
61 61
 	var->key.s = (char*)shm_malloc(var->key.len);
62 62
 	if (var->key.s==NULL) {
63
-		shm_free(var);			
63
+		shm_free(var);
64 64
 		LM_ERR("no more shm mem\n");
65 65
 		return NULL;
66 66
 	}
... ...
@@ -69,8 +72,8 @@ static inline struct dlg_var *new_dlg_var(str *key, str *val)
69 69
 	var->value.len = val->len;
70 70
 	var->value.s = (char*)shm_malloc(var->value.len);
71 71
 	if (var->value.s==NULL) {
72
-		shm_free(var->key.s);			
73
-		shm_free(var);			
72
+		shm_free(var->key.s);
73
+		shm_free(var);
74 74
 		LM_ERR("no more shm mem\n");
75 75
 		return NULL;
76 76
 	}
... ...
@@ -111,10 +114,10 @@ int set_dlg_variable_unsafe(struct dlg_cell *dlg, str *key, str *val)
111 111
 	struct dlg_var * it;
112 112
 	struct dlg_var * it_prev;
113 113
 	struct dlg_var ** var_list;
114
-	
115
-	if (dlg) 
114
+
115
+	if (dlg)
116 116
 		var_list = &dlg->vars;
117
-	else 
117
+	else
118 118
 		var_list = &var_table;
119 119
 
120 120
 	if ( val && (var=new_dlg_var(key, val))==NULL) {
... ...
@@ -139,7 +142,7 @@ int set_dlg_variable_unsafe(struct dlg_cell *dlg, str *key, str *val)
139 139
 				/* Take the previous vflags: */
140 140
 				var->vflags = it->vflags & DLG_FLAG_CHANGED;
141 141
 				if (it_prev) it_prev->next = var;
142
-				else *var_list = var;				  
142
+				else *var_list = var;
143 143
 			}
144 144
 
145 145
 			/* Free this var: */
... ...
@@ -167,7 +170,7 @@ str * get_dlg_variable_unsafe(struct dlg_cell *dlg, str *key)
167 167
 {
168 168
 	struct dlg_var *var, *var_list;
169 169
 
170
-	if (dlg) 
170
+	if (dlg)
171 171
 		var_list = dlg->vars;
172 172
 	else
173 173
 		var_list = var_table;
... ...
@@ -222,17 +225,17 @@ void print_lists(struct dlg_cell *dlg) {
222 222
 
223 223
 str * api_get_dlg_variable(str *callid, str *ftag, str *ttag, str *key) {
224 224
     struct dlg_cell *dlg;
225
-    
225
+
226 226
     unsigned int dir = DLG_DIR_NONE;
227 227
     dlg = get_dlg(callid, ftag, ttag, &dir); //increments ref count!
228
-    
228
+
229 229
     if (!dlg) {
230 230
         LM_ERR("Asked to tear down non existent dialog\n");
231 231
         return NULL;
232 232
     }
233
-    
233
+
234 234
     unref_dlg(dlg, 1);
235
-    
235
+
236 236
     return get_dlg_variable(dlg, key);
237 237
 }
238 238
 
... ...
@@ -256,20 +259,20 @@ str * get_dlg_variable(struct dlg_cell *dlg, str *key)
256 256
 
257 257
 int api_set_dlg_variable(str *callid, str *ftag, str *ttag, str *key, str *val) {
258 258
     struct dlg_cell *dlg;
259
-    
259
+
260 260
     unsigned int dir = DLG_DIR_NONE;
261 261
     dlg = get_dlg(callid, ftag, ttag, &dir); //increments ref count!
262
-    
262
+
263 263
     if (!dlg) {
264 264
         LM_ERR("Asked to tear down non existent dialog\n");
265 265
         return -1;
266 266
     }
267
-    
267
+
268 268
     unref_dlg(dlg, 1);
269
-     
269
+
270 270
     return set_dlg_variable(dlg, key, val);
271
-    
272
-   
271
+
272
+
273 273
 }
274 274
 
275 275
 int set_dlg_variable(struct dlg_cell *dlg, str *key, str *val)
... ...
@@ -380,7 +383,7 @@ int pv_set_dlg_variable(struct sip_msg* msg, pv_param_t *param, int op, pv_value
380 380
 
381 381
 	/* Retrieve the dialog for current message */
382 382
 	dlg=dlg_get_msg_dialog( msg);
383
-	
383
+
384 384
 	if (dlg) {
385 385
 		/* Lock the dialog */
386 386
 		dlg_lock(d_table, &(d_table->entries[dlg->h_entry]));
... ...
@@ -521,29 +524,29 @@ int pv_parse_dlg_ctx_name(pv_spec_p sp, str *in)
521 521
 
522 522
 	switch(in->len)
523 523
 	{
524
-		case 2: 
524
+		case 2:
525 525
 			if(strncmp(in->s, "on", 2)==0)
526 526
 				sp->pvp.pvn.u.isname.name.n = 0;
527 527
 			else goto error;
528 528
 		break;
529
-		case 3: 
529
+		case 3:
530 530
 			if(strncmp(in->s, "set", 3)==0)
531 531
 				sp->pvp.pvn.u.isname.name.n = 5;
532 532
 			else if(strncmp(in->s, "dir", 3)==0)
533 533
 				sp->pvp.pvn.u.isname.name.n = 6;
534 534
 			else goto error;
535 535
 		break;
536
-		case 5: 
536
+		case 5:
537 537
 			if(strncmp(in->s, "flags", 6)==0)
538 538
 				sp->pvp.pvn.u.isname.name.n = 1;
539 539
 			else goto error;
540 540
 		break;
541
-		case 7: 
541
+		case 7:
542 542
 			if(strncmp(in->s, "timeout", 7)==0)
543 543
 				sp->pvp.pvn.u.isname.name.n = 2;
544 544
 			else goto error;
545 545
 		break;
546
-		case 11: 
546
+		case 11:
547 547
 			if(strncmp(in->s, "timeout_bye", 11)==0)
548 548
 				sp->pvp.pvn.u.isname.name.n = 3;
549 549
 			else goto error;
... ...
@@ -691,24 +694,24 @@ int pv_parse_dlg_name(pv_spec_p sp, str *in)
691 691
 
692 692
 	switch(in->len)
693 693
 	{
694
-		case 3: 
694
+		case 3:
695 695
 			if(strncmp(in->s, "ref", 3)==0)
696 696
 				sp->pvp.pvn.u.isname.name.n = 0;
697 697
 			else goto error;
698 698
 		break;
699
-		case 4: 
699
+		case 4:
700 700
 			if(strncmp(in->s, "h_id", 4)==0)
701 701
 				sp->pvp.pvn.u.isname.name.n = 1;
702 702
 			else goto error;
703 703
 		break;
704
-		case 5: 
704
+		case 5:
705 705
 			if(strncmp(in->s, "state", 5)==0)
706 706
 				sp->pvp.pvn.u.isname.name.n = 2;
707 707
 			else if(strncmp(in->s, "to_rs", 5)==0)
708 708
 				sp->pvp.pvn.u.isname.name.n = 3;
709 709
 			else goto error;
710 710
 		break;
711
-		case 6: 
711
+		case 6:
712 712
 			if(strncmp(in->s, "dflags", 6)==0)
713 713
 				sp->pvp.pvn.u.isname.name.n = 4;
714 714
 			else if(strncmp(in->s, "sflags", 6)==0)
... ...
@@ -721,7 +724,7 @@ int pv_parse_dlg_name(pv_spec_p sp, str *in)
721 721
 				sp->pvp.pvn.u.isname.name.n = 8;
722 722
 			else goto error;
723 723
 		break;
724
-		case 7: 
724
+		case 7:
725 725
 			if(strncmp(in->s, "toroute", 7)==0)
726 726
 				sp->pvp.pvn.u.isname.name.n = 9;
727 727
 			else if(strncmp(in->s, "to_cseq", 7)==0)
... ...
@@ -732,7 +735,7 @@ int pv_parse_dlg_name(pv_spec_p sp, str *in)
732 732
 				sp->pvp.pvn.u.isname.name.n = 21;
733 733
 			else goto error;
734 734
 		break;
735
-		case 8: 
735
+		case 8:
736 736
 			if(strncmp(in->s, "from_uri", 8)==0)
737 737
 				sp->pvp.pvn.u.isname.name.n = 12;
738 738
 			else if(strncmp(in->s, "from_tag", 8)==0)
... ...
@@ -743,27 +746,27 @@ int pv_parse_dlg_name(pv_spec_p sp, str *in)
743 743
 				sp->pvp.pvn.u.isname.name.n = 15;
744 744
 			else goto error;
745 745
 		break;
746
-		case 9: 
746
+		case 9:
747 747
 			if(strncmp(in->s, "from_cseq", 9)==0)
748 748
 				sp->pvp.pvn.u.isname.name.n = 16;
749 749
 			else goto error;
750 750
 		break;
751
-		case 10: 
751
+		case 10:
752 752
 			if(strncmp(in->s, "to_contact", 10)==0)
753 753
 				sp->pvp.pvn.u.isname.name.n = 17;
754 754
 			else goto error;
755 755
 		break;
756
-		case 11: 
756
+		case 11:
757 757
 			if(strncmp(in->s, "to_bindaddr", 11)==0)
758 758
 				sp->pvp.pvn.u.isname.name.n = 18;
759 759
 			else goto error;
760 760
 		break;
761
-		case 12: 
761
+		case 12:
762 762
 			if(strncmp(in->s, "from_contact", 12)==0)
763 763
 				sp->pvp.pvn.u.isname.name.n = 19;
764 764
 			else goto error;
765 765
 		break;
766
-		case 13: 
766
+		case 13:
767 767
 			if(strncmp(in->s, "from_bindaddr", 20)==0)
768 768
 				sp->pvp.pvn.u.isname.name.n = 2;
769 769
 			else goto error;