Forráskód Böngészése

Merge pull request #1417 from kamailio/presence-api

presence: add API endpoints to update presentity and notify watchers
Emmanuel Schmidbauer 7 éve
szülő
commit
793a566351

+ 2 - 0
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_publish= w_handle_publish;
 	api->handle_subscribe0= handle_subscribe0;
 	api->handle_subscribe0= handle_subscribe0;
 	api->handle_subscribe= handle_subscribe;
 	api->handle_subscribe= handle_subscribe;
+	api->update_presentity = _api_update_presentity;
+	api->pres_refresh_watchers = _api_pres_refresh_watchers;
 	return 0;
 	return 0;
 }
 }
 
 

+ 5 - 0
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_publish_t)(struct sip_msg* msg, char *str1, char* str2);
 typedef int (*pres_handle_subscribe0_t)(struct sip_msg* msg);
 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_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 {
 typedef struct presence_api {
 	add_event_t add_event;
 	add_event_t add_event;
@@ -66,6 +69,8 @@ typedef struct presence_api {
 	pres_handle_publish_t handle_publish;
 	pres_handle_publish_t handle_publish;
 	pres_handle_subscribe0_t handle_subscribe0;
 	pres_handle_subscribe0_t handle_subscribe0;
 	pres_handle_subscribe_t handle_subscribe;
 	pres_handle_subscribe_t handle_subscribe;
+	pres_update_presentity_t update_presentity;
+	pres_refresh_watchers_t pres_refresh_watchers;
 } presence_api_t;
 } presence_api_t;
 
 
 int bind_presence(presence_api_t* api);
 int bind_presence(presence_api_t* api);

+ 5 - 0
src/modules/presence/presence.c

@@ -694,6 +694,11 @@ error:
 	return -1;
 	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)
 int ki_pres_refresh_watchers(sip_msg_t *msg, str *pres, str *event, int type)
 {
 {
 	return pres_refresh_watchers(pres, event, type, NULL, NULL);
 	return pres_refresh_watchers(pres, event, type, NULL, NULL);

+ 1 - 0
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 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 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);
 typedef int (*sip_uri_match_f) (str* s1, str* s2);
 extern sip_uri_match_f presence_sip_uri_match;
 extern sip_uri_match_f presence_sip_uri_match;

+ 30 - 0
src/modules/presence/presentity.c

@@ -1915,3 +1915,33 @@ int delete_offline_presentities(str *pres_uri, pres_ev_t *event)
 error:
 error:
 	return -1;
 	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;
+}

+ 5 - 1
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 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);
 
 
+/* 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 */
 /* free memory */
-void free_presentity(presentity_t* p);
+void free_presentity(presentity_t *p);
 
 
 char* generate_ETag(int publ_count);
 char* generate_ETag(int publ_count);