Module: sip-router Branch: master Commit: e2f654081831dc6e291d195dca1e9fd9ce53996a URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e2f65408...
Author: Peter Dunkley peter.dunkley@crocodile-rcs.com Committer: Peter Dunkley peter.dunkley@crocodile-rcs.com Date: Wed May 9 13:59:23 2012 +0100
modules_k/presence: Fixed some issues to do with the notifier processes
- Removal of expired presentities (on a timer) didn't work right - Removal of old presentities after "closed" NOTIFY didn't work in all cases - When the same subscriber was logged in twice only one client got certain notifications.
---
modules_k/presence/notify.c | 52 ++++++++++++++++++---- modules_k/presence/presentity.c | 90 ++++++++++++++++++++++++++++---------- modules_k/presence/presentity.h | 1 + modules_k/presence/publish.c | 42 ++++++++++++------ 4 files changed, 136 insertions(+), 49 deletions(-)
diff --git a/modules_k/presence/notify.c b/modules_k/presence/notify.c index 509b3dd..3d71f43 100644 --- a/modules_k/presence/notify.c +++ b/modules_k/presence/notify.c @@ -1345,12 +1345,16 @@ int publ_notify_notifier(str pres_uri, pres_ev_t *event) goto error; }
- if(result == NULL) goto error; + if(result == NULL) + { + LM_ERR("bad result\n"); + goto error; + }
+ rows = RES_ROWS(result); for (i = 0; i <RES_ROW_N(result); i++) { - rows = RES_ROWS(result); - values = ROW_VALUES(rows); + values = ROW_VALUES(&rows[i]);
subs.callid.s = (char *) VAL_STRING(&values[r_callid_col]); subs.callid.len = strlen(subs.callid.s); @@ -2043,7 +2047,10 @@ static int unset_watchers_updated_winfo(str *pres_uri) }
if (result == NULL) - ncols = 0; + { + LM_ERR("bad result\n"); + goto error; + } else ncols = result->n;
@@ -2113,7 +2120,10 @@ static int winfo_dialog_pending(str *pres_uri) }
if (result == NULL) - ret = 0; + { + LM_ERR("bad result\n"); + goto error; + } else ret = result->n;
@@ -2169,7 +2179,10 @@ static int watchers_awaiting_update(str *pres_uri, pres_ev_t *event) }
if (result == NULL) - ret = 0; + { + LM_ERR("bad result\n"); + goto error; + } else ret = result->n;
@@ -2219,8 +2232,11 @@ int set_wipeer_subs_updated(str *pres_uri, pres_ev_t *event, int full) goto error; }
- if (result == NULL ) + if (result == NULL) + { + LM_ERR("bad result\n"); goto error; + }
if (result->n <= 0) { @@ -2393,8 +2409,11 @@ static watcher_t *build_watchers_list(subs_t *sub) goto error; }
- if (result == NULL ) + if (result == NULL) + { + LM_ERR("bad result\n"); goto error; + }
if (result->n <= 0) goto done; @@ -2450,6 +2469,19 @@ static int notifier_notify(subs_t *sub, int *updated) } else { + if (sub->event->type & PUBL_TYPE) + { + int tmp = watchers_awaiting_update(&sub->pres_uri, + sub->event); + if (tmp < 0) + { + LM_ERR("checking watchers\n"); + goto error; + } + else if (tmp == 0) + attempt_delete_presentities = 1; + } + if (sub->updated_winfo == UPDATED_TYPE && winfo_dialog_pending(&sub->pres_uri) > 0) { @@ -2509,7 +2541,7 @@ static int notifier_notify(subs_t *sub, int *updated) else if (sub->event->type & PUBL_TYPE) { int tmp = watchers_awaiting_update(&sub->pres_uri, - sub->event); + sub->event); if (tmp < 0) { LM_ERR("checking watchers\n"); @@ -2531,6 +2563,7 @@ static int notifier_notify(subs_t *sub, int *updated) goto error; }
+done: if (attempt_delete_presentities) { if (delete_offline_presentities(&sub->pres_uri, sub->event) < 0) @@ -2542,7 +2575,6 @@ static int notifier_notify(subs_t *sub, int *updated)
ret = 1;
-done: error: free_notify_body(nbody, sub->event); free_watcher_list(watchers); diff --git a/modules_k/presence/presentity.c b/modules_k/presence/presentity.c index a752ff0..4d0a02d 100644 --- a/modules_k/presence/presentity.c +++ b/modules_k/presence/presentity.c @@ -542,6 +542,7 @@ after_dialog_check: LM_ERR("updating watcher records\n"); goto error; } + if (num_watchers > 0) { if (mark_presentity_for_delete(presentity) < 0) @@ -562,17 +563,9 @@ after_dialog_check:
if (pres_notifier_processes == 0 || num_watchers == 0) { - if (pa_dbf.use_table(pa_db, &presentity_table) < 0) - { - LM_ERR("unsuccessful use table sql operation\n"); - goto error; - } - - LM_DBG("expires =0 -> deleting from database\n"); - - if(pa_dbf.delete(pa_db,query_cols,0,query_vals,n_query_cols)<0) + if (delete_presentity(presentity) < 0) { - LM_ERR("unsuccessful sql delete operation"); + LM_ERR("Deleting presentity\n"); goto error; }
@@ -757,7 +750,7 @@ after_dialog_check: send_notify:
/* send notify with presence information */ - if (pres_notifier_processes == 0 || num_watchers == 0) + if (pres_notifier_processes > 0) { if (publ_notify_notifier(pres_uri, presentity->event) < 0) { @@ -1133,6 +1126,19 @@ int mark_presentity_for_delete(presentity_t *pres) int ret = -1; str *cur_body, *new_body = NULL;
+ if (pres->event->agg_nbody == NULL) + { + /* Nothing clever to do here... just delete */ + if (delete_presentity(pres) < 0) + { + LM_ERR("deleting presentity\n"); + goto error; + } + + ret = 0; + goto done; + } + if (pa_dbf.use_table(pa_db, &presentity_table) < 0) { LM_ERR("unsuccessful use table sql operation\n"); @@ -1163,19 +1169,6 @@ int mark_presentity_for_delete(presentity_t *pres) query_vals[n_query_cols].val.str_val = pres->etag; n_query_cols++;
- if (pres->event->agg_nbody == NULL) - { - /* Nothing clever to do here... just delete */ - if(pa_dbf.delete(pa_db, query_cols, 0, query_vals, n_query_cols) < 0) - { - LM_ERR("unsuccessful sql delete operation"); - goto error; - } - - ret = 0; - goto done; - } - result_cols[0] = &str_body_col;
if (pa_dbf.query(pa_db, query_cols, 0, query_vals, result_cols, @@ -1243,6 +1236,55 @@ error: return ret; }
+int delete_presentity(presentity_t *pres) +{ + db_key_t query_cols[4]; + db_val_t query_vals[4]; + int n_query_cols = 0; + int ret = -1; + + if (pa_dbf.use_table(pa_db, &presentity_table) < 0) + { + LM_ERR("unsuccessful use table sql operation\n"); + goto error; + } + + query_cols[n_query_cols] = &str_username_col; + query_vals[n_query_cols].type = DB1_STR; + query_vals[n_query_cols].nul = 0; + query_vals[n_query_cols].val.str_val = pres->user; + n_query_cols++; + + query_cols[n_query_cols] = &str_domain_col; + query_vals[n_query_cols].type = DB1_STR; + query_vals[n_query_cols].nul = 0; + query_vals[n_query_cols].val.str_val = pres->domain; + n_query_cols++; + + query_cols[n_query_cols] = &str_event_col; + query_vals[n_query_cols].type = DB1_STR; + query_vals[n_query_cols].nul = 0; + query_vals[n_query_cols].val.str_val = pres->event->name; + n_query_cols++; + + query_cols[n_query_cols] = &str_etag_col; + query_vals[n_query_cols].type = DB1_STR; + query_vals[n_query_cols].nul = 0; + query_vals[n_query_cols].val.str_val = pres->etag; + n_query_cols++; + + if(pa_dbf.delete(pa_db, query_cols, 0, query_vals, n_query_cols) < 0) + { + LM_ERR("unsuccessful sql delete operation"); + goto error; + } + + ret = 0; + +error: + return ret; +} + int delete_offline_presentities(str *pres_uri, pres_ev_t *event) { db_key_t query_cols[4]; diff --git a/modules_k/presence/presentity.h b/modules_k/presence/presentity.h index 2b87aca..744ed6c 100644 --- a/modules_k/presence/presentity.h +++ b/modules_k/presence/presentity.h @@ -72,6 +72,7 @@ char* get_sphere(str* pres_uri); typedef char* (*pres_get_sphere_t)(str* pres_uri);
int mark_presentity_for_delete(presentity_t *pres); +int delete_presentity(presentity_t *pres); int delete_offline_presentities(str *pres_uri, pres_ev_t *event);
#endif diff --git a/modules_k/presence/publish.c b/modules_k/presence/publish.c index c1249b1..9bac8ae 100644 --- a/modules_k/presence/publish.c +++ b/modules_k/presence/publish.c @@ -76,6 +76,7 @@ void msg_presentity_clean(unsigned int ticks,void *param) db1_res_t *result = NULL; db_row_t *row ; db_val_t *row_vals ; + int n_db_cols = 0; int i =0, size= 0; struct p_modif* p= NULL; presentity_t* pres= NULL; @@ -94,17 +95,19 @@ void msg_presentity_clean(unsigned int ticks,void *param) return ; }
- db_keys[0] = &str_expires_col; - db_ops[0] = OP_LT; - db_vals[0].type = DB1_INT; - db_vals[0].nul = 0; - db_vals[0].val.int_val = (int)time(NULL); + db_keys[n_db_cols] = &str_expires_col; + db_ops[n_db_cols] = OP_LT; + db_vals[n_db_cols].type = DB1_INT; + db_vals[n_db_cols].nul = 0; + db_vals[n_db_cols].val.int_val = (int)time(NULL); + n_db_cols++;
- db_keys[1] = &str_expires_col; - db_ops[1] = OP_GT; - db_vals[1].type = DB1_INT; - db_vals[1].nul = 0; - db_vals[1].val.int_val = 0; + db_keys[n_db_cols] = &str_expires_col; + db_ops[n_db_cols] = OP_GT; + db_vals[n_db_cols].type = DB1_INT; + db_vals[n_db_cols].nul = 0; + db_vals[n_db_cols].val.int_val = 0; + n_db_cols++;
result_cols[user_col= n_result_cols++] = &str_username_col; result_cols[domain_col=n_result_cols++] = &str_domain_col; @@ -113,7 +116,7 @@ void msg_presentity_clean(unsigned int ticks,void *param)
static str query_str = str_init("username"); if(pa_dbf.query(pa_db, db_keys, db_ops, db_vals, result_cols, - 2, n_result_cols, &query_str, &result )< 0) + n_db_cols, n_result_cols, &query_str, &result )< 0) { LM_ERR("failed to query database for expired messages\n"); if(result) @@ -223,11 +226,20 @@ void msg_presentity_clean(unsigned int ticks,void *param) LM_ERR("Updating watcher records\n"); goto error; } + if (num_watchers > 0) { if (mark_presentity_for_delete(p[i].p) < 0) { - LM_ERR("Marking presentities\n"); + LM_ERR("Marking presentity\n"); + goto error; + } + } + else + { + if (delete_presentity(p[i].p) < 0) + { + LM_ERR("Deleting presentity\n"); goto error; } } @@ -269,10 +281,10 @@ void msg_presentity_clean(unsigned int ticks,void *param) goto error; }
-delete_pres: - if (pres_notifier_processes <= 0 || num_watchers == 0) + if (pres_notifier_processes == 0) { - if (pa_dbf.delete(pa_db, db_keys, db_ops, db_vals, 2) < 0) +delete_pres: + if (pa_dbf.delete(pa_db, db_keys, db_ops, db_vals, n_db_cols) < 0) LM_ERR("failed to delete expired records from DB\n"); }