Module: sip-router Branch: 3.3 Commit: 2778f4126fdd48f4573f008726b3a3868c3d69c1 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=2778f412...
Author: Peter Dunkley peter.dunkley@crocodile-rcs.com Committer: Peter Dunkley peter.dunkley@crocodile-rcs.com Date: Tue Sep 11 13:05:15 2012 +0100
modules_k/rls: Fixed issues to do with expiry and rls_expires_offset
- These cause particular problems on multi-server systems. - Found and fixed by Hugh Waite @ Crocodile RCS Ltd (cherry picked from commit 6eccc8b61e848977012d6efa1fb5aae61f8d441e)
---
modules_k/rls/resource_notify.c | 21 ++++++++------------- modules_k/rls/subscribe.c | 5 ++++- 2 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/modules_k/rls/resource_notify.c b/modules_k/rls/resource_notify.c index 8937131..1285925 100644 --- a/modules_k/rls/resource_notify.c +++ b/modules_k/rls/resource_notify.c @@ -129,15 +129,14 @@ void get_dialog_from_did(char* did, subs_t **dialog, unsigned int *hash_code) *dialog= pres_copy_subs(s, PKG_MEM_TYPE); }
- if(*dialog== NULL) - { - LM_ERR("while copying subs_t structure\n"); - } + if ((*dialog)->expires < (int)time(NULL)) + (*dialog)->expires = 0; + else + (*dialog)->expires -= (int)time(NULL);
if (dbmode != RLS_DB_ONLY) lock_release(&rls_table[*hash_code].lock);
- (*dialog)->expires -= (int)time(NULL); }
int send_notify(xmlDocPtr * rlmi_doc, char * buf, int buf_len, @@ -994,15 +993,10 @@ static void timer_send_full_state_notifies(int round) sub.remote_cseq = VAL_INT(&values[rcseq_col]); sub.status = VAL_INT(&values[status_col]); sub.version = VAL_INT(&values[version_col]); - if (VAL_INT(&values[expires_col]) > now) + if (VAL_INT(&values[expires_col]) > now + rls_expires_offset) + { sub.expires = VAL_INT(&values[expires_col]) - now; - else - sub.expires = 0; - - if (sub.expires < rls_expires_offset) sub.expires = 0;
- if (sub.expires != 0) - { if (rls_get_service_list(&sub.pres_uri, &sub.watcher_user, &sub.watcher_domain, &service_node, &doc) < 0) { @@ -1026,6 +1020,7 @@ static void timer_send_full_state_notifies(int round) } else { + sub.expires = 0; rls_send_notify(&sub, NULL, NULL, NULL); delete_rlsdb(&sub.callid, &sub.to_tag, &sub.from_tag); } @@ -1153,7 +1148,7 @@ void rls_presentity_clean(unsigned int ticks,void *param) query_ops[0]= OP_LT; query_vals[0].nul= 0; query_vals[0].type= DB1_INT; - query_vals[0].val.int_val= (int)time(NULL) - 10; + query_vals[0].val.int_val= (int)time(NULL) - rls_expires_offset;
if (rlpres_dbf.use_table(rlpres_db, &rlpres_table) < 0) { diff --git a/modules_k/rls/subscribe.c b/modules_k/rls/subscribe.c index f719754..c9577de 100644 --- a/modules_k/rls/subscribe.c +++ b/modules_k/rls/subscribe.c @@ -1111,13 +1111,16 @@ void update_a_sub(subs_t *subs_copy) { xmlDocPtr doc = NULL; xmlNodePtr service_node = NULL; + int now = (int)time(NULL);
- if ((subs_copy->expires -= (int)time(NULL)) <= 0) + if (subs_copy->expires < now) { + subs_copy->expires = 0; LM_WARN("found expired subscription for: %.*s\n", subs_copy->pres_uri.len, subs_copy->pres_uri.s); goto done; } + subs_copy->expires -= now;
if(rls_get_service_list(&subs_copy->pres_uri, &subs_copy->watcher_user, &subs_copy->watcher_domain, &service_node, &doc)<0)