From 407d85be91b16035d01fb357d8a26de51c4018d0 Mon Sep 17 00:00:00 2001 From: Emmanuel Schmidbauer Date: Thu, 1 Feb 2018 10:13:49 -0700 Subject: [PATCH] presence: pass `replace` parameter to force hard presentity update --- src/modules/presence/bind_presence.h | 2 +- src/modules/presence/presence_dmq.c | 2 +- src/modules/presence/presentity.c | 17 ++++++++++++----- src/modules/presence/presentity.h | 4 ++-- src/modules/presence/publish.c | 4 ++-- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/modules/presence/bind_presence.h b/src/modules/presence/bind_presence.h index 31ffdc420ba..5500c09e477 100644 --- a/src/modules/presence/bind_presence.h +++ b/src/modules/presence/bind_presence.h @@ -43,7 +43,7 @@ typedef int (*pres_handle_publish_t)(struct sip_msg* msg, char *str1, char* str2 typedef int (*pres_handle_subscribe0_t)(struct sip_msg* msg); typedef int (*pres_handle_subscribe_t)(struct sip_msg* msg, str watcher_user, str watcher_domain); typedef int (*pres_update_presentity_t)(str *event, str *realm, str *user, str *etag, - str *sender, str *body, int expires, int new_t); + str *sender, str *body, int expires, int new_t, int replace); typedef int (*pres_refresh_watchers_t)(str *pres, str *event, int type); typedef struct presence_api { diff --git a/src/modules/presence/presence_dmq.c b/src/modules/presence/presence_dmq.c index 05f95e85ed1..4cba168a559 100644 --- a/src/modules/presence/presence_dmq.c +++ b/src/modules/presence/presence_dmq.c @@ -302,7 +302,7 @@ int pres_dmq_handle_msg( switch(action) { case PRES_DMQ_UPDATE_PRESENTITY: if(update_presentity(NULL, presentity, &p_body, t_new, &sent_reply, - sphere, &cur_etag, &ruid) + sphere, &cur_etag, &ruid, 0) < 0) { goto error; } diff --git a/src/modules/presence/presentity.c b/src/modules/presence/presentity.c index a824bd0a209..eab2318b7dd 100644 --- a/src/modules/presence/presentity.c +++ b/src/modules/presence/presentity.c @@ -281,7 +281,7 @@ int check_if_dialog(str body, int *is_dialog, char **dialog_id) doc = xmlParseMemory(body.s, body.len); if(doc== NULL) { - LM_ERR("failed to parse xml document\n"); + LM_INFO("failed to parse xml document\n"); return -1; } @@ -556,7 +556,7 @@ int is_dialog_terminated(presentity_t* presentity) } int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, - int new_t, int* sent_reply, char* sphere, str* etag_override, str* ruid) + int new_t, int* sent_reply, char* sphere, str* etag_override, str* ruid, int replace) { db_key_t query_cols[14], rquery_cols[2], update_keys[9], result_cols[7]; db_op_t query_ops[14], rquery_ops[2]; @@ -658,6 +658,9 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, } LM_DBG("new htable record added\n"); + if (presentity->expires == -1) { + replace = 1; + } /* insert new record into database */ query_cols[n_query_cols] = &str_sender_col; @@ -697,7 +700,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, query_vals[n_query_cols].val.str_val = p_ruid; n_query_cols++; - if (presentity->expires != -1) + if (!replace) { /* A real PUBLISH */ query_cols[n_query_cols] = &str_expires_col; @@ -748,6 +751,10 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, query_vals[n_query_cols].type = DB1_INT; query_vals[n_query_cols].nul = 0; query_vals[n_query_cols].val.int_val = -1; + if(presentity->expires != -1) { + query_vals[n_query_cols].val.int_val = + presentity->expires + (int)time(NULL); + } n_query_cols++; if (pa_dbf.use_table(pa_db, &presentity_table) < 0) @@ -1918,7 +1925,7 @@ int delete_offline_presentities(str *pres_uri, pres_ev_t *event) // used for API updates to the presentity table int _api_update_presentity(str *event, str *realm, str *user, str *etag, - str *sender, str *body, int expires, int new_t) + str *sender, str *body, int expires, int new_t, int replace) { int ret; presentity_t *pres = NULL; @@ -1936,7 +1943,7 @@ int _api_update_presentity(str *event, str *realm, str *user, str *etag, if(sphere_enable) { sphere = extract_sphere(*body); } - ret = update_presentity(NULL, pres, body, new_t, NULL, sphere, NULL, NULL); + ret = update_presentity(NULL, pres, body, new_t, NULL, sphere, NULL, NULL, replace); if(pres) pkg_free(pres); diff --git a/src/modules/presence/presentity.h b/src/modules/presence/presentity.h index c225580ed35..8fe75cf642c 100644 --- a/src/modules/presence/presentity.h +++ b/src/modules/presence/presentity.h @@ -55,11 +55,11 @@ presentity_t* new_presentity( str* domain,str* user,int expires, /* update presentity in database */ int update_presentity(struct sip_msg* msg,presentity_t* p,str* body,int t_new, - int* sent_reply, char* sphere, str* etag_override, str* ruid); + int* sent_reply, char* sphere, str* etag_override, str* ruid, int replace); /* update presentity in database using API */ int _api_update_presentity(str *event, str *realm, str *user, str *etag, - str *sender, str *body, int expires, int reset); + str *sender, str *body, int expires, int new_t, int replace); /* free memory */ void free_presentity(presentity_t *p); diff --git a/src/modules/presence/publish.c b/src/modules/presence/publish.c index 69533b0e39e..e16f6ce62e9 100644 --- a/src/modules/presence/publish.c +++ b/src/modules/presence/publish.c @@ -494,7 +494,7 @@ int ki_handle_publish_uri(struct sip_msg* msg, str* sender_uri) } /* querry the database and update or insert */ - if(update_presentity(msg, presentity, &body, etag_gen, &sent_reply, sphere, NULL, NULL) <0) + if(update_presentity(msg, presentity, &body, etag_gen, &sent_reply, sphere, NULL, NULL, 0) <0) { LM_ERR("when updating presentity\n"); goto error; @@ -635,7 +635,7 @@ int update_hard_presentity(str *pres_uri, pres_ev_t *event, str *file_uri, str * goto done; } - if (update_presentity(NULL, pres, pidf_doc, new_t, NULL, sphere, NULL, NULL) < 0) + if (update_presentity(NULL, pres, pidf_doc, new_t, NULL, sphere, NULL, NULL, 0) < 0) { LM_ERR("updating presentity\n"); goto done;