presence: safety checks in timer callbacks to cope with storage modes
authorDaniel-Constantin Mierla <miconda@gmail.com>
Wed, 22 Apr 2020 06:42:48 +0000 (08:42 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Wed, 22 Apr 2020 06:42:48 +0000 (08:42 +0200)
src/modules/presence/hash.c
src/modules/presence/presence.c
src/modules/presence/publish.c
src/modules/presence/publish.h
src/modules/presence/subscribe.c
src/modules/presence/subscribe.h

index 47e4f35..55b674d 100644 (file)
@@ -1269,6 +1269,10 @@ ps_presentity_t *ps_ptable_get_expired(int eval)
        ps_presentity_t *pte = NULL;
        int i = 0;
 
+       if(_ps_ptable == NULL) {
+               return NULL;
+       }
+
        for(i=0; i<_ps_ptable->ssize; i++) {
                lock_get(&_ps_ptable->slots[i].lock);
                ptn = _ps_ptable->slots[i].plist;
index 7120dd7..301113a 100644 (file)
@@ -448,14 +448,14 @@ static int mod_init(void)
        pres_startup_time = (int)time(NULL);
        if(pres_clean_period > 0) {
                if(pres_timer_mode==0) {
-                       register_timer(msg_presentity_clean, 0, pres_clean_period);
-                       register_timer(msg_watchers_clean, 0, pres_clean_period);
+                       register_timer(ps_presentity_db_timer_clean, 0, pres_clean_period);
+                       register_timer(ps_watchers_db_timer_clean, 0, pres_clean_period);
                        if(publ_cache_mode==PS_PCACHE_RECORD) {
                                register_timer(ps_ptable_timer_clean, 0, pres_clean_period);
                        }
                } else {
-                       sr_wtimer_add(msg_presentity_clean, 0, pres_clean_period);
-                       sr_wtimer_add(msg_watchers_clean, 0, pres_clean_period);
+                       sr_wtimer_add(ps_presentity_db_timer_clean, 0, pres_clean_period);
+                       sr_wtimer_add(ps_watchers_db_timer_clean, 0, pres_clean_period);
                        if(publ_cache_mode==PS_PCACHE_RECORD) {
                                sr_wtimer_add(ps_ptable_timer_clean, 0, pres_clean_period);
                        }
@@ -1841,8 +1841,9 @@ void rpc_presence_cleanup(rpc_t *rpc, void *c)
 {
        LM_DBG("rpc_presence_cleanup:start\n");
 
-       (void)msg_watchers_clean(0, 0);
-       (void)msg_presentity_clean(0, 0);
+       (void)ps_watchers_db_timer_clean(0, 0);
+       (void)ps_presentity_db_timer_clean(0, 0);
+       (void)ps_ptable_timer_clean(0, 0);
        (void)timer_db_update(0, 0);
 
        rpc->rpl_printf(c, "Reload OK");
index 31264fe..8889a2e 100644 (file)
@@ -59,7 +59,7 @@ struct p_modif
        str uri;
 };
 
-void msg_presentity_clean(unsigned int ticks, void *param)
+void ps_presentity_db_timer_clean(unsigned int ticks, void *param)
 {
        db_key_t db_keys[2], result_cols[4];
        db_val_t db_vals[2], *values;
@@ -73,6 +73,10 @@ void msg_presentity_clean(unsigned int ticks, void *param)
        str uri = {0, 0}, event, *rules_doc = NULL;
        static str query_str;
 
+       if(pa_db == NULL) {
+               return;
+       }
+
        LM_DBG("cleaning expired presentity information\n");
        if(pa_dbf.use_table(pa_db, &presentity_table) < 0) {
                LM_ERR("in use_table\n");
index c622f7e..5381d7c 100644 (file)
@@ -42,7 +42,7 @@
 #include "presentity.h"
 #include "../alias_db/alias_db.h"
 
-void msg_presentity_clean(unsigned int ticks, void *param);
+void ps_presentity_db_timer_clean(unsigned int ticks, void *param);
 void ps_ptable_timer_clean(unsigned int ticks, void *param);
 
 int w_handle_publish(struct sip_msg *msg, char *str1, char *str2);
index 5a2f741..3ab831f 100644 (file)
@@ -702,12 +702,16 @@ error:
        return -1;
 }
 
-void msg_watchers_clean(unsigned int ticks, void *param)
+void ps_watchers_db_timer_clean(unsigned int ticks, void *param)
 {
        db_key_t db_keys[2];
        db_val_t db_vals[2];
        db_op_t db_ops[2];
 
+       if(pa_db == NULL) {
+               return;
+       }
+
        LM_DBG("cleaning pending subscriptions\n");
 
        db_keys[0] = &str_inserted_time_col;
index 157bf5b..3092b10 100644 (file)
@@ -88,9 +88,7 @@ struct subscription
 };
 typedef struct subscription subs_t;
 
-void msg_active_watchers_clean(unsigned int ticks, void *param);
-
-void msg_watchers_clean(unsigned int ticks, void *param);
+void ps_watchers_db_timer_clean(unsigned int ticks, void *param);
 
 int handle_subscribe0(struct sip_msg *);
 int w_handle_subscribe0(struct sip_msg *, char *, char *);