diff --git a/coreapi/help/buddy_status.c b/coreapi/help/buddy_status.c
index 7ee06a8f5..1032cf17b 100644
--- a/coreapi/help/buddy_status.c
+++ b/coreapi/help/buddy_status.c
@@ -46,13 +46,13 @@ static void stop(int signum){
/**
* presence state change notification callback
*/
-static void notify_presence_recv_updated (struct _LinphoneCore *lc, LinphoneFriend *friend) {
+static void notify_presence_recv_updated (LinphoneCore *lc, LinphoneFriend *friend) {
const LinphoneAddress* friend_address = linphone_friend_get_address(friend);
printf("New state state [%s] for user id [%s] \n"
,linphone_online_status_to_string(linphone_friend_get_status(friend))
,linphone_address_as_string (friend_address));
}
-static void new_subscription_request (struct _LinphoneCore *lc, LinphoneFriend *friend, const char* url) {
+static void new_subscription_request (LinphoneCore *lc, LinphoneFriend *friend, const char* url) {
const LinphoneAddress* friend_address = linphone_friend_get_address(friend);
printf(" [%s] wants to see your status, accepting\n"
,linphone_address_as_string (friend_address));
diff --git a/coreapi/sal_eXosip2_presence.c b/coreapi/sal_eXosip2_presence.c
index 675a45117..154c8d07e 100644
--- a/coreapi/sal_eXosip2_presence.c
+++ b/coreapi/sal_eXosip2_presence.c
@@ -20,6 +20,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "sal_eXosip2.h"
+typedef enum {
+ PIDF = 0,
+ RFCxxxx = 1,
+ MSOLDPRES = 2
+} presence_type_t;
+
+/*
+ * REVISIT: this static variable forces every dialog to use the same presence description type depending
+ * on what is received on a single dialog...
+ */
+static presence_type_t presence_style = PIDF;
SalOp * sal_find_out_subscribe(Sal *sal, int sid){
const MSList *elem;
@@ -175,268 +186,372 @@ int sal_subscribe_decline(SalOp *op){
return 0;
}
-static void add_presence_body(osip_message_t *notify, SalPresenceStatus online_status)
-{
- char buf[1000];
-#ifdef SUPPORT_MSN
- int atom_id = 1000;
-#endif
- char *contact_info;
+static void mk_presence_body (const SalPresenceStatus online_status, const char *contact_info,
+ char *buf, size_t buflen, presence_type_t ptype) {
+ switch (ptype) {
+ case RFCxxxx: {
+ /* definition from http://msdn.microsoft.com/en-us/library/cc246202%28PROT.10%29.aspx */
+ int atom_id = 1000;
- osip_from_t *from=NULL;
- from=osip_message_get_from(notify);
- osip_uri_to_str(from->url,&contact_info);
-
-#ifdef SUPPORT_MSN
-
- if (online_status==SalPresenceOnline)
- {
- sprintf(buf, "\n\
-\n\
+ if (online_status==SalPresenceOnline)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
\n\
\n\
\n\
-\n\
+\n\
\n\
\n\
\n\
\n\
", contact_info, atom_id, contact_info);
- }
- else if (online_status==SalPresenceBusy)
- {
- sprintf(buf, "\n\
-\n\
+ }
+ else if (online_status == SalPresenceBusy ||
+ online_status == SalPresenceDonotdisturb)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
\n\
\n\
\n\
-\n\
+\n\
\n\
\n\
\n\
-\n\
-", contact_info, atom_id, contact_info);
+\n", contact_info, atom_id, contact_info);
- }
- else if (online_status==SalPresenceBerightback)
- {
- sprintf(buf, "\n\
-\n\
+ }
+ else if (online_status==SalPresenceBerightback)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
\n\
\n\
\n\
-\n\
-\n\
+\n\
+\n\
\n\
\n\
\n\
", contact_info, atom_id, contact_info);
- }
- else if (online_status==SalPresenceAway)
- {
- sprintf(buf, "\n\
-\n\
+ }
+ else if (online_status == SalPresenceAway ||
+ online_status == SalPresenceMoved)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
\n\
\n\
\n\
-\n\
-\n\
+\n\
+\n\
\n\
\n\
\n\
", contact_info, atom_id, contact_info);
- }
- else if (online_status==SalPresenceOnthephone)
- {
- sprintf(buf, "\n\
-\n\
+ }
+ else if (online_status==SalPresenceOnthephone)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
\n\
\n\
\n\
-\n\
+\n\
\n\
\n\
\n\
\n\
", contact_info, atom_id, contact_info);
- }
- else if (online_status==SalPresenceOuttolunch)
- {
- sprintf(buf, "\n\
-\n\
+ }
+ else if (online_status==SalPresenceOuttolunch)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
\n\
\n\
\n\
-\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+", contact_info, atom_id, contact_info);
+
+ }
+ else
+ {
+ snprintf(buf, buflen, "\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+", contact_info, atom_id, contact_info);
+ }
+ break;
+ }
+ case MSOLDPRES: {
+ /* Couldn't find schema http://schemas.microsoft.com/2002/09/sip/presence
+ * so messages format has been taken from Communigate that can send notify
+ * requests with this schema
+ */
+ int atom_id = 1000;
+
+ if (online_status==SalPresenceOnline)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+", contact_info, atom_id, contact_info);
+
+ }
+ else if (online_status == SalPresenceBusy ||
+ online_status == SalPresenceDonotdisturb)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n", contact_info, atom_id, contact_info);
+
+ }
+ else if (online_status==SalPresenceBerightback)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+", contact_info, atom_id, contact_info);
+
+ }
+ else if (online_status == SalPresenceAway ||
+ online_status == SalPresenceMoved)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+", contact_info, atom_id, contact_info);
+
+ }
+ else if (online_status==SalPresenceOnthephone)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+", contact_info, atom_id, contact_info);
+
+ }
+ else if (online_status==SalPresenceOuttolunch)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
+\n\
+\n\
+\n\
+\n\
\n\
\n\
\n\
\n\
", contact_info, atom_id, contact_info);
- }
- else
- {
- sprintf(buf, "\n\
-\n\
+ }
+ else
+ {
+ snprintf(buf, buflen, "\n\
+\n\
\n\
\n\
\n\
-\n\
-\n\
-\n\
+\n\
+\n\
+\n\
\n\
\n\
", contact_info, atom_id, contact_info);
- }
+ }
+ break;
+ }
+ default: { /* use pidf+xml as default format, rfc4479, rfc4480, rfc3863 */
- osip_message_set_body(notify, buf, strlen(buf));
- osip_message_set_content_type(notify, "application/xpidf+xml");
-#else
+ if (online_status==SalPresenceOnline)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
+\n\
+open\n\
+%s\n\
+\n\
+",
+contact_info, contact_info);
+ }
+ else if (online_status == SalPresenceBusy ||
+ online_status == SalPresenceDonotdisturb)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
+\n\
+open\n\
+%s\n\
+\n\
+\n\
+\n\
+\n\
+",
+contact_info, contact_info);
+ }
+ else if (online_status==SalPresenceBerightback)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
+\n\
+open\n\
+%s\n\
+\n\
+\n\
+\n\
+\n\
+",
+contact_info, contact_info);
+ }
+ else if (online_status == SalPresenceAway ||
+ online_status == SalPresenceMoved)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
+\n\
+open\n\
+%s\n\
+\n\
+\n\
+\n\
+\n\
+",
+contact_info, contact_info);
+ }
+ else if (online_status==SalPresenceOnthephone)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
+\n\
+open\n\
+%s\n\
+\n\
+\n\
+\n\
+\n\
+",
+contact_info, contact_info);
+ }
+ else if (online_status==SalPresenceOuttolunch)
+ {
+ snprintf(buf, buflen, "\n\
+\n\
+\n\
+open\n\
+%s\n\
+\n\
+\n\
+\n\
+Out to lunch \n\
+\n\
+",
+contact_info, contact_info);
+ }
+ else
+ {
+ snprintf(buf, buflen, "\n\
+\n\
+\n\
+closed\n\
+%s\n\
+\n\
+\n", contact_info, contact_info);
+ }
+ break;
+ }
+ } // switch
- if (online_status==SalPresenceOnline)
- {
- sprintf(buf, "\n\
-\n\
-\n\
-\n\
-open\n\
-\n\
-%s\n\
-online\n\
-\n\
-",
- contact_info, contact_info);
- }
- else if (online_status==SalPresenceBusy)
- {
- sprintf(buf, "\n\
-\n\
-\n\
-\n\
-open\n\
-\n\
- busy\n\
-\n\
-\n\
-%s\n\
-busy\n\
-\n\
-",
- contact_info, contact_info);
- }
- else if (online_status==SalPresenceBerightback)
- {
- sprintf(buf, "\n\
-\n\
-\n\
-\n\
-open\n\
-\n\
- in-transit\n\
-\n\
-\n\
-%s\n\
-be right back\n\
-\n\
-",
- contact_info, contact_info);
- }
- else if (online_status==SalPresenceAway)
- {
- sprintf(buf, "\n\
-\n\
-\n\
-\n\
-open\n\
-\n\
- away\n\
-\n\
-\n\
-%s\n\
-away\n\
-\n\
-",
- contact_info, contact_info);
- }
- else if (online_status==SalPresenceOnthephone)
- {
- sprintf(buf, "\n\
-\n\
-\n\
-\n\
-open\n\
-\n\
- on-the-phone\n\
-\n\
-\n\
-%s\n\
-on the phone\n\
-\n\
-",
- contact_info, contact_info);
- }
- else if (online_status==SalPresenceOuttolunch)
- {
- sprintf(buf, "\n\
-\n\
-\n\
-\n\
-open\n\
-\n\
- meal\n\
-\n\
-\n\
-%s\n\
-out to lunch\n\
-\n\
-",
- contact_info, contact_info);
- }
- else
- {
- /* */
- sprintf(buf, "\n\
-\n%s",
- contact_info,
-"\n\
-\n\
-closed\n\
-\n\
- permanent-absence\n\
-\n\
-\n\
-\n\
-\n\n");
- }
- osip_message_set_body(notify, buf, strlen(buf));
- osip_message_set_content_type(notify, "application/pidf+xml");
+}
+
+static void add_presence_body(osip_message_t *notify, SalPresenceStatus online_status)
+{
+ char buf[1000];
+ char *contact_info;
+
+ osip_from_t *from=NULL;
+ from=osip_message_get_from(notify);
+ osip_uri_to_str(from->url,&contact_info);
+
+ mk_presence_body (online_status, contact_info, buf, sizeof (buf), presence_style);
+
+ osip_message_set_body(notify, buf, strlen(buf));
+ osip_message_set_content_type(notify,
+ presence_style ? "application/xpidf+xml" : "application/pidf+xml");
-#endif
osip_free(contact_info);
}
@@ -483,137 +598,10 @@ int sal_publish(SalOp *op, const char *from, const char *to, SalPresenceStatus p
int i;
char buf[1024];
- if (presence_mode==SalPresenceOnline)
- {
- snprintf(buf, sizeof(buf), "\n\
- \n\
- \n\
- \n\
- open\n\
- \n\
- %s\n\
- online\n\
- \n\
- ",
- from, from);
- }
- else if (presence_mode==SalPresenceBusy
- ||presence_mode==SalPresenceDonotdisturb)
- {
- snprintf(buf, sizeof(buf), "\n\
- \n\
- \n\
- \n\
- open\n\
- \n\
- busy\n\
- \n\
- \n\
- %s\n\
- busy\n\
- \n\
- ",
- from, from);
- }
- else if (presence_mode==SalPresenceBerightback)
- {
- snprintf(buf, sizeof(buf), "\n\
- \n\
- \n\
- \n\
- open\n\
- \n\
- in-transit\n\
- \n\
- \n\
- %s\n\
- be right back\n\
- \n\
- ",
- from,from);
- }
- else if (presence_mode==SalPresenceAway
- ||presence_mode==SalPresenceMoved)
- {
- snprintf(buf, sizeof(buf), "\n\
- \n\
- \n\
- \n\
- open\n\
- \n\
- away\n\
- \n\
- \n\
- %s\n\
- away\n\
- \n\
- ",
- from, from);
- }
- else if (presence_mode==SalPresenceOnthephone)
- {
- snprintf(buf, sizeof(buf), "\n\
- \n\
- \n\
- \n\
- open\n\
- \n\
- on-the-phone\n\
- \n\
- \n\
- %s\n\
- on the phone\n\
- \n\
- ",
- from, from);
- }
- else if (presence_mode==SalPresenceOuttolunch)
- {
- snprintf(buf, sizeof(buf), "\n\
- \n\
- \n\
- \n\
- open\n\
- \n\
- meal\n\
- \n\
- \n\
- %s\n\
- out to lunch\n\
- \n\
- ",
- from, from);
- }
- else{
- /* offline */
- snprintf(buf, sizeof(buf), "\n\
- \n%s",
- from,
- "\n\
- \n\
- closed\n\
- \n\
- permanent-absence\n\
- \n\
- \n\
- \n\
- \n\n");
- }
+ mk_presence_body (presence_mode, from, buf, sizeof (buf), presence_style);
- i = eXosip_build_publish(&pub,from, to, NULL, "presence", "1800", "application/pidf+xml", buf);
+ i = eXosip_build_publish(&pub,from, to, NULL, "presence", "300",
+ presence_style ? "application/xpidf+xml" : "application/pidf+xml", buf);
if (i<0){
ms_warning("Failed to build publish request.");
return -1;
@@ -699,7 +687,8 @@ void sal_exosip_notify_recv(Sal *sal, eXosip_event_t *ev){
}else if (strstr(body->body,"berightback")!=NULL
|| strstr(body->body,"in-transit")!=NULL ){
estatus=SalPresenceBerightback;
- }else if (strstr(body->body,"away")!=NULL){
+ }else if (strstr(body->body,"away")!=NULL
+ || strstr(body->body,"idle")){
estatus=SalPresenceAway;
}else if (strstr(body->body,"onthephone")!=NULL
|| strstr(body->body,"on-the-phone")!=NULL){
@@ -722,6 +711,15 @@ void sal_exosip_notify_recv(Sal *sal, eXosip_event_t *ev){
ms_message("And outgoing subscription terminated by remote.");
}
sal->callbacks.notify_presence(op,op->sid!=-1 ? SalSubscribeActive : SalSubscribeTerminated, estatus,NULL);
+
+ /* try to detect presence message style used by server,
+ * and switch our presence messages to servers style */
+ if (strstr (body->body, "//IETF//DTD RFCxxxx XPIDF 1.0//EN") != NULL) {
+ presence_style = RFCxxxx;
+ } else if (strstr(body->body,"http://schemas.microsoft.com/2002/09/sip/presence")!=NULL) {
+ presence_style = MSOLDPRES;
+ }
+
osip_free(tmp);
}