Skip to content

Commit

Permalink
presence: add API endpoints to update presentity and notify watchers
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Schmidbauer committed Jan 30, 2018
1 parent 00da053 commit 4853c38
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/modules/presence/bind_presence.c
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions src/modules/presence/bind_presence.h
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/modules/presence/presence.c
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/modules/presence/presence.h
Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions src/modules/presence/presentity.c
Expand Up @@ -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;
}
6 changes: 5 additions & 1 deletion src/modules/presence/presentity.h
Expand Up @@ -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);

Expand Down

0 comments on commit 4853c38

Please sign in to comment.