Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PUA module so that it sends a final PUBLISH on expiration. #16

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions modules/pua/pua.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static int mod_init(void);
static int child_init(int);
static void destroy(void);

static int update_pua(ua_pres_t* p, unsigned int hash_code);
static int update_pua(ua_pres_t* p, unsigned int hash_code, unsigned int final);

static int db_restore(void);
static void db_update(unsigned int ticks,void *param);
Expand Down Expand Up @@ -613,7 +613,7 @@ static void hashT_clean(unsigned int ticks,void *param)
"refresh PUBLISH desired_expires=%d - expires=%d\n",
p->desired_expires, p->expires);

if(update_pua(p, i)< 0)
if(update_pua(p, i, 0)< 0)
{
LM_ERR("while updating record\n");
lock_release(&HashT->p_records[i].lock);
Expand All @@ -625,6 +625,10 @@ static void hashT_clean(unsigned int ticks,void *param)

LM_DBG("Found expired: uri= %.*s\n", p->pres_uri->len,
p->pres_uri->s);
if(update_pua(p, i, 1)< 0)
{
LM_ERR("while updating record\n");
}
/* delete it */
q = p->next;
delete_htable_safe(p, p->hash_index);
Expand All @@ -637,20 +641,27 @@ static void hashT_clean(unsigned int ticks,void *param)
}
}

int update_pua(ua_pres_t* p, unsigned int hash_code)
int update_pua(ua_pres_t* p, unsigned int hash_code, unsigned int final)
{
str* str_hdr= NULL;
int expires;
int result;

if(p->desired_expires== 0)
expires= 3600;
else
expires= p->desired_expires- (int)time(NULL);

if(expires < min_expires)
expires = min_expires;
if(final > 0)
{
expires= 0;
p->desired_expires= 0;
}
else
{
if(p->desired_expires== 0)
expires= 3600;
else
expires= p->desired_expires- (int)time(NULL);

if(expires < min_expires)
expires = min_expires;
}
if(p->watcher_uri== NULL)
{
str met= {"PUBLISH", 7};
Expand All @@ -671,7 +682,7 @@ int update_pua(ua_pres_t* p, unsigned int hash_code)
LM_ERR("while building extra_headers\n");
goto error;
}
LM_DBG("str_hdr:\n%.*s\n ", str_hdr->len, str_hdr->s);
LM_DBG("str_hdr:\n%.*s expires:%d\n ", str_hdr->len, str_hdr->s, expires);

cb_param = PRES_HASH_ID(p);

Expand Down