X-Git-Url: http://sjero.net/git/?p=linphone;a=blobdiff_plain;f=coreapi%2Fsal_eXosip2_presence.c;h=c8191098649343f2bb6ebf8689d06e881efd557f;hp=33034ed1c47c493d018db23f33051f519152d1b5;hb=bf492b4278d1c68b2da55c65da173a33aec32ea1;hpb=aadd9b0b02898e573d6e357f807d95df916e5a16
diff --git a/coreapi/sal_eXosip2_presence.c b/coreapi/sal_eXosip2_presence.c
index 33034ed1..c8191098 100644
--- a/coreapi/sal_eXosip2_presence.c
+++ b/coreapi/sal_eXosip2_presence.c
@@ -81,7 +81,27 @@ void sal_remove_in_subscribe(Sal *sal, SalOp *op){
sal->in_subscribes=ms_list_remove(sal->in_subscribes,op);
}
-int sal_text_send(SalOp *op, const char *from, const char *to, const char *msg){
+static const char *days[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
+static const char *months[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
+
+static void msg_add_current_date(osip_message_t *msg){
+ char tmp[64]={0};
+ time_t curtime=time(NULL);
+ struct tm *ret;
+#ifndef WIN32
+ struct tm gmt;
+ ret=gmtime_r(&curtime,&gmt);
+#else
+ ret=gmtime(&curtime);
+#endif
+ /*cannot use strftime because it is locale dependant*/
+ snprintf(tmp,sizeof(tmp)-1,"%s, %i %s %i %02i:%02i:%02i GMT",
+ days[ret->tm_wday],ret->tm_mday,months[ret->tm_mon],1900+ret->tm_year,ret->tm_hour,ret->tm_min,ret->tm_sec);
+ osip_message_replace_header(msg,"Date",tmp);
+}
+
+
+int sal_message_send(SalOp *op, const char *from, const char *to, const char* content_type, const char *msg){
osip_message_t *sip=NULL;
if(op->cid == -1)
@@ -92,12 +112,15 @@ int sal_text_send(SalOp *op, const char *from, const char *to, const char *msg){
if (to)
sal_op_set_to(op,to);
+ sal_exosip_fix_route(op);
eXosip_lock();
eXosip_message_build_request(&sip,"MESSAGE",sal_op_get_to(op),
sal_op_get_from(op),sal_op_get_route(op));
if (sip!=NULL){
- osip_message_set_content_type(sip,"text/plain");
- osip_message_set_body(sip,msg,strlen(msg));
+ sal_exosip_add_custom_headers(sip,op->base.custom_headers);
+ msg_add_current_date(sip);
+ osip_message_set_content_type(sip,content_type);
+ if (msg) osip_message_set_body(sip,msg,strlen(msg));
sal_add_other(op->base.root,op,sip);
eXosip_message_send_request(sip);
}else{
@@ -117,17 +140,22 @@ int sal_text_send(SalOp *op, const char *from, const char *to, const char *msg){
eXosip_unlock();
return -1;
}
- osip_message_set_content_type(sip,"text/plain");
- osip_message_set_body(sip,msg,strlen(msg));
+ sal_exosip_add_custom_headers(sip,op->base.custom_headers);
+ msg_add_current_date(sip);
+ osip_message_set_content_type(sip,content_type);
+ if (msg) osip_message_set_body(sip,msg,strlen(msg));
eXosip_call_send_request(op->did,sip);
eXosip_unlock();
}
return 0;
}
+int sal_text_send(SalOp *op, const char *from, const char *to, const char *msg) {
+ return sal_message_send(op,from,to,"text/plain",msg);
+}
/*presence Subscribe/notify*/
int sal_subscribe_presence(SalOp *op, const char *from, const char *to){
- osip_message_t *msg;
+ osip_message_t *msg=NULL;
if (from)
sal_op_set_from(op,from);
if (to)
@@ -136,6 +164,11 @@ int sal_subscribe_presence(SalOp *op, const char *from, const char *to){
eXosip_lock();
eXosip_subscribe_build_initial_request(&msg,sal_op_get_to(op),sal_op_get_from(op),
sal_op_get_route(op),"presence",600);
+ if (msg==NULL){
+ ms_error("Could not build subscribe request to %s",to);
+ eXosip_unlock();
+ return -1;
+ }
if (op->base.contact){
_osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free);
osip_message_set_contact(msg,op->base.contact);
@@ -168,9 +201,14 @@ int sal_unsubscribe(SalOp *op){
}
int sal_subscribe_accept(SalOp *op){
- osip_message_t *msg;
+ osip_message_t *msg=NULL;
eXosip_lock();
eXosip_insubscription_build_answer(op->tid,202,&msg);
+ if (msg==NULL){
+ ms_error("Fail to build answer to subscribe.");
+ eXosip_unlock();
+ return -1;
+ }
if (op->base.contact){
_osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free);
osip_message_set_contact(msg,op->base.contact);
@@ -196,108 +234,108 @@ static void mk_presence_body (const SalPresenceStatus online_status, const char
if (online_status==SalPresenceOnline)
{
- snprintf(buf, buflen, "\n\
-\n\
-\n\
-\n\
-\n\
-\n\
-\n\
-\n\
-\n\
-\n\
-", contact_info, atom_id, contact_info);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ snprintf(buf, buflen, "\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);
+ snprintf(buf, buflen, "\n"
+"\n"
+"\n"
+"\n"
+"\n"
+"\n"
+"\n"
+"\n"
+"\n"
+"\n"
+"", contact_info, atom_id, contact_info);
}
break;
}
@@ -310,108 +348,108 @@ static void mk_presence_body (const SalPresenceStatus online_status, const char
if (online_status==SalPresenceOnline)
{
- snprintf(buf, buflen, "\n\
-\n\
-\n\
-\n\
-\n\
-\n\
-\n\
-\n\
-\n\
-\n\
-", contact_info, atom_id, contact_info);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ snprintf(buf, buflen, "\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);
+ snprintf(buf, buflen, "\n"
+"\n"
+"\n"
+"\n"
+"\n"
+"\n"
+"\n"
+"\n"
+"\n"
+"\n"
+"", contact_info, atom_id, contact_info);
}
break;
}
@@ -419,118 +457,118 @@ static void mk_presence_body (const SalPresenceStatus online_status, const char
if (online_status==SalPresenceOnline)
{
- snprintf(buf, buflen, "\n\
-\n\
-\n\
-open\n\
-%s\n\
-\n\
-",
+ 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\
-",
+ 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\
-",
+ 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\
-",
+ 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\
-",
+ 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\
-",
+ 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);
+ snprintf(buf, buflen, "\n"
+"\n"
+"\n"
+"closed\n"
+"%s\n"
+"\n"
+"\n", contact_info, contact_info);
}
break;
}
@@ -558,7 +596,7 @@ static void add_presence_body(osip_message_t *notify, SalPresenceStatus online_s
int sal_notify_presence(SalOp *op, SalPresenceStatus status, const char *status_message){
- osip_message_t *msg;
+ osip_message_t *msg=NULL;
eXosip_ss_t ss=EXOSIP_SUBCRSTATE_ACTIVE;
if (op->nid==-1){
ms_warning("Cannot notify, subscription was closed.");
@@ -599,23 +637,26 @@ int sal_publish(SalOp *op, const char *from, const char *to, SalPresenceStatus p
osip_message_t *pub;
int i;
char buf[1024];
+ const char *route=sal_op_get_route(op);
mk_presence_body (presence_mode, from, buf, sizeof (buf), presence_style);
- i = eXosip_build_publish(&pub,from, to, NULL, "presence", "300",
+ i = eXosip_build_publish(&pub,to, from, NULL, "presence", "600",
presence_style ? "application/xpidf+xml" : "application/pidf+xml", buf);
if (i<0){
ms_warning("Failed to build publish request.");
return -1;
}
-
+ if (route)
+ sal_message_add_route(pub,route);
+
eXosip_lock();
i = eXosip_publish(pub, to); /* should update the sip-if-match parameter
from sip-etag from last 200ok of PUBLISH */
eXosip_unlock();
if (i<0){
- ms_message("Failed to send publish request.");
- return -1;
+ ms_message("Failed to send publish request.");
+ return -1;
}
sal_add_other(sal_op_get_sal(op),op,pub);
return 0;