Module: sip-router
Branch: master
Commit: ca8f2211bd1c4bebe083a07b3afe7107254e6bea
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ca8f221…
Author: pd <peter.dunkley(a)crocodile-rcs.com>
Committer: pd <peter.dunkley(a)crocodile-rcs.com>
Date: Thu Dec 8 21:50:05 2011 +0000
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
---
modules_k/rls/rls.c | 21 +++++++++++++++++++++
modules_k/rls/rls.h | 2 ++
modules_k/rls/subscribe.c | 6 +++++-
3 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/modules_k/rls/rls.c b/modules_k/rls/rls.c
index c482af2..c8d54eb 100644
--- a/modules_k/rls/rls.c
+++ b/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)
diff --git a/modules_k/rls/rls.h b/modules_k/rls/rls.h
index 12e98c8..055d674 100644
--- a/modules_k/rls/rls.h
+++ b/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;
diff --git a/modules_k/rls/subscribe.c b/modules_k/rls/subscribe.c
index 92f34de..cab70ff 100644
--- a/modules_k/rls/subscribe.c
+++ b/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;
}