Skip to content

Commit

Permalink
Presence: Fix startup inconsistency in presentity hash table
Browse files Browse the repository at this point in the history
pres_htable_restore(): Remove check of expired presentity entries when
initially filling the hash table to represent the number of expired +
valid entries. Because hash.c::delete_phtable() decrements publ_count on
removal of _every_ expired DB entry.
get_p_notify_body(): Compensate the fix on hash table restore by
checking for the expires time on building the NOTIFY. This also fixes a
problem when a SUBSCRIBE is received for an expired entry before the
cleaner can remove the entry from the DB.
  • Loading branch information
Chocolatbuddha committed Oct 17, 2016
1 parent 44b80de commit 1dceaa2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
17 changes: 14 additions & 3 deletions modules/presence/notify.c
Expand Up @@ -584,8 +584,9 @@ str* build_empty_bla_body(str pres_uri)
str* get_p_notify_body(str pres_uri, pres_ev_t* event, str* etag,
str* contact)
{
db_key_t query_cols[3];
db_val_t query_vals[3];
db_key_t query_cols[4];
db_val_t query_vals[4];
db_op_t query_ops[4];
db_key_t result_cols[3];
db1_res_t *result = NULL;
int body_col, etag_col= 0, sender_col;
Expand Down Expand Up @@ -635,18 +636,28 @@ str* get_p_notify_body(str pres_uri, pres_ev_t* event, str* etag,
query_vals[n_query_cols].type = DB1_STR;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.str_val = uri.host;
query_ops[n_query_cols] = OP_EQ;
n_query_cols++;

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 = uri.user;
query_ops[n_query_cols] = OP_EQ;
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= event->name;
query_ops[n_query_cols] = OP_EQ;
n_query_cols++;

query_cols[n_query_cols] = &str_expires_col;
query_vals[n_query_cols].type = DB1_INT;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.int_val= (int)time(NULL);
query_ops[n_query_cols] = OP_GT;
n_query_cols++;

result_cols[body_col=n_result_cols++] = &str_body_col;
Expand All @@ -664,7 +675,7 @@ str* get_p_notify_body(str pres_uri, pres_ev_t* event, str* etag,
} else {
query_str = str_received_time_col;
}
if (pa_dbf.query (pa_db, query_cols, 0, query_vals,
if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals,
result_cols, n_query_cols, n_result_cols, &query_str , &result) < 0)
{
LM_ERR("failed to query %.*s table\n", presentity_table.len, presentity_table.s);
Expand Down
3 changes: 0 additions & 3 deletions modules/presence/presentity.c
Expand Up @@ -1231,9 +1231,6 @@ int pres_htable_restore(void)
row = &result->rows[i];
row_vals = ROW_VALUES(row);

if(row_vals[expires_col].val.int_val< (int)time(NULL))
continue;

sphere= NULL;
user.s= (char*)row_vals[user_col].val.string_val;
user.len= strlen(user.s);
Expand Down

0 comments on commit 1dceaa2

Please sign in to comment.