浏览代码

modules_k/rls: Added lock for rls_update_subs() in DB only mode

- If a client updates the same resource-list document multiple times in quick
  succession rls_update_subs() might overlap for the same dialogs.
- This was causing problems in DB only mode so a lock has been added.
- Not a problem when the hash-table is used as each row has locks.
- Problem identified and fix defined by me.
- Fix implemented by Hugh Waite @ Crocodile RCS
pd 13 年之前
父节点
当前提交
ca8f2211bd
共有 3 个文件被更改,包括 28 次插入1 次删除
  1. 21 0
      modules_k/rls/rls.c
  2. 2 0
      modules_k/rls/rls.h
  3. 5 1
      modules_k/rls/subscribe.c

+ 21 - 0
modules_k/rls/rls.c

@@ -88,6 +88,10 @@ search_event_t pres_search_event;
 get_event_list_t pres_get_ev_list;
 int clean_period = 100;
 
+/* Lock for rls_update_subs */
+gen_lock_t *rls_update_subs_lock = NULL;
+
+
 /* address and port(default: 80):"http://192.168.2.132:8000/xcap-root"*/
 char* xcap_root;
 unsigned int xcap_port = 8000;
@@ -574,6 +578,17 @@ static int mod_init(void)
 		register_timer(rlsubs_table_update, 0, clean_period);
 	}
 
+	if ((rls_update_subs_lock = lock_alloc()) == NULL)
+	{
+		LM_ERR("Failed to alloc rls_updae_subs_lock\n");
+		return -1;
+	}
+	if (lock_init(rls_update_subs_lock) == NULL)
+	{
+		LM_ERR("Failed to init rls_updae_subs_lock\n");
+		return -1;
+	}
+
 	return 0;
 }
 
@@ -678,6 +693,12 @@ static void destroy(void)
 
 	if(rls2_db && rls2_dbf.close)
 		rls2_dbf.close(rls2_db);
+
+	if (rls_update_subs_lock != NULL)
+	{
+		lock_destroy(rls_update_subs_lock);
+		lock_dealloc(rls_update_subs_lock);
+	}
 }
 
 int handle_expired_record(subs_t* s)

+ 2 - 0
modules_k/rls/rls.h

@@ -103,6 +103,8 @@ extern str rls_outbound_proxy;
 extern int rls_max_notify_body_len;
 extern int rls_expires_offset;
 
+extern gen_lock_t *rls_update_subs_lock;
+
 /* database connection */
 extern db1_con_t *rls_db;
 extern db_func_t rls_dbf;

+ 5 - 1
modules_k/rls/subscribe.c

@@ -1029,7 +1029,11 @@ int rls_update_subs(struct sip_msg *msg, char *puri, char *pevent)
 
 	if (dbmode==RLS_DB_ONLY)
 	{
-		return(update_all_subs_rlsdb(&parsed_uri.user, &parsed_uri.host, &event));
+		int ret;
+		lock_get(rls_update_subs_lock);
+		ret = (update_all_subs_rlsdb(&parsed_uri.user, &parsed_uri.host, &event));
+		lock_release(rls_update_subs_lock);
+		return ret;
 	}