diff --git a/src/modules/presence/bind_presence.c b/src/modules/presence/bind_presence.c index 33ed1f7ce83..c0a64d5414f 100644 --- a/src/modules/presence/bind_presence.c +++ b/src/modules/presence/bind_presence.c @@ -68,6 +68,8 @@ int bind_presence(presence_api_t* api) api->handle_publish= w_handle_publish; api->handle_subscribe0= handle_subscribe0; api->handle_subscribe= handle_subscribe; + api->update_presentity = _api_update_presentity; + api->pres_refresh_watchers = _api_pres_refresh_watchers; return 0; } diff --git a/src/modules/presence/bind_presence.h b/src/modules/presence/bind_presence.h index e5dd72fbd32..31ffdc420ba 100644 --- a/src/modules/presence/bind_presence.h +++ b/src/modules/presence/bind_presence.h @@ -42,6 +42,9 @@ typedef int (*pres_auth_status_t)(struct sip_msg* msg, str watcher_uri, str pres 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); +typedef int (*pres_refresh_watchers_t)(str *pres, str *event, int type); typedef struct presence_api { add_event_t add_event; @@ -66,6 +69,8 @@ typedef struct presence_api { pres_handle_publish_t handle_publish; pres_handle_subscribe0_t handle_subscribe0; pres_handle_subscribe_t handle_subscribe; + pres_update_presentity_t update_presentity; + pres_refresh_watchers_t pres_refresh_watchers; } presence_api_t; int bind_presence(presence_api_t* api); diff --git a/src/modules/presence/presence.c b/src/modules/presence/presence.c index 4ba309d6b9e..721506292bb 100644 --- a/src/modules/presence/presence.c +++ b/src/modules/presence/presence.c @@ -694,6 +694,11 @@ int pres_refresh_watchers(str *pres, str *event, int type, str *file_uri, str *f return -1; } +int _api_pres_refresh_watchers(str *pres, str *event, int type) +{ + return pres_refresh_watchers(pres, event, type, NULL, NULL); +} + int ki_pres_refresh_watchers(sip_msg_t *msg, str *pres, str *event, int type) { return pres_refresh_watchers(pres, event, type, NULL, NULL); diff --git a/src/modules/presence/presence.h b/src/modules/presence/presence.h index 6e1e1cd249a..bdce11ef0d9 100644 --- a/src/modules/presence/presence.h +++ b/src/modules/presence/presence.h @@ -106,6 +106,7 @@ extern db_locking_t db_table_lock; int update_watchers_status(str pres_uri, pres_ev_t* ev, str* rules_doc); int pres_auth_status(struct sip_msg* msg, str watcher_uri, str presentity_uri); +int _api_pres_refresh_watchers(str *pres, str *event, int type); typedef int (*sip_uri_match_f) (str* s1, str* s2); extern sip_uri_match_f presence_sip_uri_match; diff --git a/src/modules/presence/presentity.c b/src/modules/presence/presentity.c index c2a4d5a56cc..a824bd0a209 100644 --- a/src/modules/presence/presentity.c +++ b/src/modules/presence/presentity.c @@ -1915,3 +1915,33 @@ int delete_offline_presentities(str *pres_uri, pres_ev_t *event) error: return -1; } + +// 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) +{ + int ret; + presentity_t *pres = NULL; + pres_ev_t *ev; + char *sphere = NULL; + + ev = contains_event(event, NULL); + if(ev == NULL) { + LM_ERR("wrong event parameter\n"); + return -1; + } + + pres = new_presentity(realm, user, expires, ev, etag, sender); + + if(sphere_enable) { + sphere = extract_sphere(*body); + } + ret = update_presentity(NULL, pres, body, new_t, NULL, sphere, NULL, NULL); + + if(pres) + pkg_free(pres); + if(sphere) + pkg_free(sphere); + + return ret; +} diff --git a/src/modules/presence/presentity.h b/src/modules/presence/presentity.h index 8a6a16eecfe..c225580ed35 100644 --- a/src/modules/presence/presentity.h +++ b/src/modules/presence/presentity.h @@ -57,8 +57,12 @@ presentity_t* new_presentity( str* domain,str* user,int expires, 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); +/* 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); + /* free memory */ -void free_presentity(presentity_t* p); +void free_presentity(presentity_t *p); char* generate_ETag(int publ_count);