Browse code

presence: safety checks in timer callbacks to cope with storage modes

Daniel-Constantin Mierla authored on 22/04/2020 06:42:48
Showing 6 changed files
... ...
@@ -1269,6 +1269,10 @@ ps_presentity_t *ps_ptable_get_expired(int eval)
1269 1269
 	ps_presentity_t *pte = NULL;
1270 1270
 	int i = 0;
1271 1271
 
1272
+	if(_ps_ptable == NULL) {
1273
+		return NULL;
1274
+	}
1275
+
1272 1276
 	for(i=0; i<_ps_ptable->ssize; i++) {
1273 1277
 		lock_get(&_ps_ptable->slots[i].lock);
1274 1278
 		ptn = _ps_ptable->slots[i].plist;
... ...
@@ -448,14 +448,14 @@ static int mod_init(void)
448 448
 	pres_startup_time = (int)time(NULL);
449 449
 	if(pres_clean_period > 0) {
450 450
 		if(pres_timer_mode==0) {
451
-			register_timer(msg_presentity_clean, 0, pres_clean_period);
452
-			register_timer(msg_watchers_clean, 0, pres_clean_period);
451
+			register_timer(ps_presentity_db_timer_clean, 0, pres_clean_period);
452
+			register_timer(ps_watchers_db_timer_clean, 0, pres_clean_period);
453 453
 			if(publ_cache_mode==PS_PCACHE_RECORD) {
454 454
 				register_timer(ps_ptable_timer_clean, 0, pres_clean_period);
455 455
 			}
456 456
 		} else {
457
-			sr_wtimer_add(msg_presentity_clean, 0, pres_clean_period);
458
-			sr_wtimer_add(msg_watchers_clean, 0, pres_clean_period);
457
+			sr_wtimer_add(ps_presentity_db_timer_clean, 0, pres_clean_period);
458
+			sr_wtimer_add(ps_watchers_db_timer_clean, 0, pres_clean_period);
459 459
 			if(publ_cache_mode==PS_PCACHE_RECORD) {
460 460
 				sr_wtimer_add(ps_ptable_timer_clean, 0, pres_clean_period);
461 461
 			}
... ...
@@ -1841,8 +1841,9 @@ void rpc_presence_cleanup(rpc_t *rpc, void *c)
1841 1841
 {
1842 1842
 	LM_DBG("rpc_presence_cleanup:start\n");
1843 1843
 
1844
-	(void)msg_watchers_clean(0, 0);
1845
-	(void)msg_presentity_clean(0, 0);
1844
+	(void)ps_watchers_db_timer_clean(0, 0);
1845
+	(void)ps_presentity_db_timer_clean(0, 0);
1846
+	(void)ps_ptable_timer_clean(0, 0);
1846 1847
 	(void)timer_db_update(0, 0);
1847 1848
 
1848 1849
 	rpc->rpl_printf(c, "Reload OK");
... ...
@@ -59,7 +59,7 @@ struct p_modif
59 59
 	str uri;
60 60
 };
61 61
 
62
-void msg_presentity_clean(unsigned int ticks, void *param)
62
+void ps_presentity_db_timer_clean(unsigned int ticks, void *param)
63 63
 {
64 64
 	db_key_t db_keys[2], result_cols[4];
65 65
 	db_val_t db_vals[2], *values;
... ...
@@ -73,6 +73,10 @@ void msg_presentity_clean(unsigned int ticks, void *param)
73 73
 	str uri = {0, 0}, event, *rules_doc = NULL;
74 74
 	static str query_str;
75 75
 
76
+	if(pa_db == NULL) {
77
+		return;
78
+	}
79
+
76 80
 	LM_DBG("cleaning expired presentity information\n");
77 81
 	if(pa_dbf.use_table(pa_db, &presentity_table) < 0) {
78 82
 		LM_ERR("in use_table\n");
... ...
@@ -42,7 +42,7 @@
42 42
 #include "presentity.h"
43 43
 #include "../alias_db/alias_db.h"
44 44
 
45
-void msg_presentity_clean(unsigned int ticks, void *param);
45
+void ps_presentity_db_timer_clean(unsigned int ticks, void *param);
46 46
 void ps_ptable_timer_clean(unsigned int ticks, void *param);
47 47
 
48 48
 int w_handle_publish(struct sip_msg *msg, char *str1, char *str2);
... ...
@@ -702,12 +702,16 @@ error:
702 702
 	return -1;
703 703
 }
704 704
 
705
-void msg_watchers_clean(unsigned int ticks, void *param)
705
+void ps_watchers_db_timer_clean(unsigned int ticks, void *param)
706 706
 {
707 707
 	db_key_t db_keys[2];
708 708
 	db_val_t db_vals[2];
709 709
 	db_op_t db_ops[2];
710 710
 
711
+	if(pa_db == NULL) {
712
+		return;
713
+	}
714
+
711 715
 	LM_DBG("cleaning pending subscriptions\n");
712 716
 
713 717
 	db_keys[0] = &str_inserted_time_col;
... ...
@@ -88,9 +88,7 @@ struct subscription
88 88
 };
89 89
 typedef struct subscription subs_t;
90 90
 
91
-void msg_active_watchers_clean(unsigned int ticks, void *param);
92
-
93
-void msg_watchers_clean(unsigned int ticks, void *param);
91
+void ps_watchers_db_timer_clean(unsigned int ticks, void *param);
94 92
 
95 93
 int handle_subscribe0(struct sip_msg *);
96 94
 int w_handle_subscribe0(struct sip_msg *, char *, char *);