3 Copyright (C) 2010 Simon MORLAT (simon.morlat@free.fr)
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "sal_eXosip2.h"
30 * REVISIT: this static variable forces every dialog to use the same presence description type depending
31 * on what is received on a single dialog...
33 static presence_type_t presence_style = PIDF;
35 SalOp * sal_find_out_subscribe(Sal *sal, int sid){
38 for(elem=sal->out_subscribes;elem!=NULL;elem=elem->next){
39 op=(SalOp*)elem->data;
40 if (op->sid==sid) return op;
42 ms_message("No op for sid %i",sid);
46 static void sal_add_out_subscribe(Sal *sal, SalOp *op){
47 sal->out_subscribes=ms_list_append(sal->out_subscribes,op);
50 void sal_remove_out_subscribe(Sal *sal, SalOp *op){
51 sal->out_subscribes=ms_list_remove(sal->out_subscribes,op);
54 SalOp * sal_find_in_subscribe(Sal *sal, int nid){
57 for(elem=sal->in_subscribes;elem!=NULL;elem=elem->next){
58 op=(SalOp*)elem->data;
59 if (op->nid==nid) return op;
64 static SalOp * sal_find_in_subscribe_by_call_id(Sal *sal, osip_call_id_t *call_id){
67 for(elem=sal->in_subscribes;elem!=NULL;elem=elem->next){
68 op=(SalOp*)elem->data;
69 if (op->call_id && osip_call_id_match(op->call_id,call_id)==0)
75 static void sal_add_in_subscribe(Sal *sal, SalOp *op, osip_message_t *subs){
76 osip_call_id_clone(subs->call_id,&op->call_id);
77 sal->in_subscribes=ms_list_append(sal->in_subscribes,op);
80 void sal_remove_in_subscribe(Sal *sal, SalOp *op){
81 sal->in_subscribes=ms_list_remove(sal->in_subscribes,op);
86 static inline char *my_ctime_r(const time_t *t, char *buf){
92 #define my_ctime_r ctime_r
95 int sal_message_send(SalOp *op, const char *from, const char *to, const char* content_type, const char *msg){
96 osip_message_t *sip=NULL;
98 time_t curtime=time(NULL);
100 my_ctime_r(&curtime,t);
104 /* we are not currently in communication with the destination */
106 sal_op_set_from(op,from);
108 sal_op_set_to(op,to);
110 sal_exosip_fix_route(op);
112 eXosip_message_build_request(&sip,"MESSAGE",sal_op_get_to(op),
113 sal_op_get_from(op),sal_op_get_route(op));
115 sal_exosip_add_custom_headers(sip,op->base.custom_headers);
116 osip_message_set_date(sip,t);
117 osip_message_set_content_type(sip,content_type);
118 if (msg) osip_message_set_body(sip,msg,strlen(msg));
119 sal_add_other(op->base.root,op,sip);
120 eXosip_message_send_request(sip);
122 ms_error("Could not build MESSAGE request !");
128 /* we are currently in communication with the destination */
130 //First we generate an INFO message to get the current call_id and a good cseq
131 eXosip_call_build_request(op->did,"MESSAGE",&sip);
134 ms_warning("could not get a build info to send MESSAGE, maybe no previous call established ?");
138 sal_exosip_add_custom_headers(sip,op->base.custom_headers);
139 osip_message_set_date(sip,t);
140 osip_message_set_content_type(sip,content_type);
141 if (msg) osip_message_set_body(sip,msg,strlen(msg));
142 eXosip_call_send_request(op->did,sip);
148 int sal_text_send(SalOp *op, const char *from, const char *to, const char *msg) {
149 return sal_message_send(op,from,to,"text/plain",msg);
151 /*presence Subscribe/notify*/
152 int sal_subscribe_presence(SalOp *op, const char *from, const char *to){
153 osip_message_t *msg=NULL;
155 sal_op_set_from(op,from);
157 sal_op_set_to(op,to);
158 sal_exosip_fix_route(op);
160 eXosip_subscribe_build_initial_request(&msg,sal_op_get_to(op),sal_op_get_from(op),
161 sal_op_get_route(op),"presence",600);
163 ms_error("Could not build subscribe request to %s",to);
167 if (op->base.contact){
168 _osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free);
169 osip_message_set_contact(msg,op->base.contact);
171 op->sid=eXosip_subscribe_send_initial_request(msg);
174 osip_message_free(msg);
177 sal_add_out_subscribe(op->base.root,op);
181 int sal_unsubscribe(SalOp *op){
182 osip_message_t *msg=NULL;
184 ms_error("cannot unsubscribe, no dialog !");
188 eXosip_subscribe_build_refresh_request(op->did,&msg);
190 osip_message_set_expires(msg,"0");
191 eXosip_subscribe_send_refresh_request(op->did,msg);
192 }else ms_error("Could not build subscribe refresh request ! op->sid=%i, op->did=%i",
198 int sal_subscribe_accept(SalOp *op){
199 osip_message_t *msg=NULL;
201 eXosip_insubscription_build_answer(op->tid,202,&msg);
203 ms_error("Fail to build answer to subscribe.");
207 if (op->base.contact){
208 _osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free);
209 osip_message_set_contact(msg,op->base.contact);
211 eXosip_insubscription_send_answer(op->tid,202,msg);
216 int sal_subscribe_decline(SalOp *op){
218 eXosip_insubscription_send_answer(op->tid,401,NULL);
223 static void mk_presence_body (const SalPresenceStatus online_status, const char *contact_info,
224 char *buf, size_t buflen, presence_type_t ptype) {
227 /* definition from http://msdn.microsoft.com/en-us/library/cc246202%28PROT.10%29.aspx */
230 if (online_status==SalPresenceOnline)
232 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
233 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
235 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
237 "<address uri=\"%s\" priority=\"0.800000\">\n"
238 "<status status=\"open\" />\n"
239 "<msnsubstatus substatus=\"online\" />\n"
242 "</presence>", contact_info, atom_id, contact_info);
245 else if (online_status == SalPresenceBusy ||
246 online_status == SalPresenceDonotdisturb)
248 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
249 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
251 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
253 "<address uri=\"%s\" priority=\"0.800000\">\n"
254 "<status status=\"inuse\" />\n"
255 "<msnsubstatus substatus=\"busy\" />\n"
257 "</atom>\n</presence>", contact_info, atom_id, contact_info);
260 else if (online_status==SalPresenceBerightback)
262 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
263 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
265 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
267 "<address uri=\"%s\" priority=\"0.800000\">\n"
268 "<status status=\"open\" />\n"
269 "<msnsubstatus substatus=\"berightback\" />\n"
272 "</presence>", contact_info, atom_id, contact_info);
275 else if (online_status == SalPresenceAway ||
276 online_status == SalPresenceMoved)
278 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
279 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
281 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
283 "<address uri=\"%s\" priority=\"0.800000\">\n"
284 "<status status=\"open\" />\n"
285 "<msnsubstatus substatus=\"away\" />\n"
288 "</presence>", contact_info, atom_id, contact_info);
291 else if (online_status==SalPresenceOnthephone)
293 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
294 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
296 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
298 "<address uri=\"%s\" priority=\"0.800000\">\n"
299 "<status status=\"inuse\" />\n"
300 "<msnsubstatus substatus=\"onthephone\" />\n"
303 "</presence>", contact_info, atom_id, contact_info);
306 else if (online_status==SalPresenceOuttolunch)
308 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
309 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
311 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
313 "<address uri=\"%s\" priority=\"0.800000\">\n"
314 "<status status=\"open\" />\n"
315 "<msnsubstatus substatus=\"outtolunch\" />\n"
318 "</presence>", contact_info, atom_id, contact_info);
323 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
324 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
326 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
328 "<address uri=\"%s\" priority=\"0.800000\">\n"
329 "<status status=\"closed\" />\n"
330 "<msnsubstatus substatus=\"away\" />\n"
333 "</presence>", contact_info, atom_id, contact_info);
338 /* Couldn't find schema http://schemas.microsoft.com/2002/09/sip/presence
339 * so messages format has been taken from Communigate that can send notify
340 * requests with this schema
344 if (online_status==SalPresenceOnline)
346 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
347 "<!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n"
349 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
351 "<address uri=\"%s\">\n"
352 "<status status=\"open\" />\n"
353 "<msnsubstatus substatus=\"online\" />\n"
356 "</presence>", contact_info, atom_id, contact_info);
359 else if (online_status == SalPresenceBusy ||
360 online_status == SalPresenceDonotdisturb)
362 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
363 "<!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n"
365 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
367 "<address uri=\"%s\">\n"
368 "<status status=\"inuse\" />\n"
369 "<msnsubstatus substatus=\"busy\" />\n"
371 "</atom>\n</presence>", contact_info, atom_id, contact_info);
374 else if (online_status==SalPresenceBerightback)
376 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
377 "<!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n"
379 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
381 "<address uri=\"%s\">\n"
382 "<status status=\"inactive\" />\n"
383 "<msnsubstatus substatus=\"berightback\" />\n"
386 "</presence>", contact_info, atom_id, contact_info);
389 else if (online_status == SalPresenceAway ||
390 online_status == SalPresenceMoved)
392 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
393 "<!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n"
395 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
397 "<address uri=\"%s\">\n"
398 "<status status=\"inactive\" />\n"
399 "<msnsubstatus substatus=\"idle\" />\n"
402 "</presence>", contact_info, atom_id, contact_info);
405 else if (online_status==SalPresenceOnthephone)
407 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
408 "<!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n"
410 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
412 "<address uri=\"%s\">\n"
413 "<status status=\"inuse\" />\n"
414 "<msnsubstatus substatus=\"onthephone\" />\n"
417 "</presence>", contact_info, atom_id, contact_info);
420 else if (online_status==SalPresenceOuttolunch)
422 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
423 "<!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n"
425 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
427 "<address uri=\"%s\">\n"
428 "<status status=\"inactive\" />\n"
429 "<msnsubstatus substatus=\"outtolunch\" />\n"
432 "</presence>", contact_info, atom_id, contact_info);
437 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
438 "<!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n"
440 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
442 "<address uri=\"%s\">\n"
443 "<status status=\"closed\" />\n"
444 "<msnsubstatus substatus=\"offline\" />\n"
447 "</presence>", contact_info, atom_id, contact_info);
451 default: { /* use pidf+xml as default format, rfc4479, rfc4480, rfc3863 */
453 if (online_status==SalPresenceOnline)
455 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
456 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" "
457 "xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" "
458 "xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" "
460 "<tuple id=\"sg89ae\">\n"
461 "<status><basic>open</basic></status>\n"
462 "<contact priority=\"0.8\">%s</contact>\n"
465 contact_info, contact_info);
467 else if (online_status == SalPresenceBusy ||
468 online_status == SalPresenceDonotdisturb)
470 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
471 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" "
472 "xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" "
473 "xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" "
475 "<tuple id=\"sg89ae\">\n"
476 "<status><basic>open</basic></status>\n"
477 "<contact priority=\"0.8\">%s</contact>\n"
479 "<dm:person id=\"sg89aep\">\n"
480 "<rpid:activities><rpid:busy/></rpid:activities>\n"
483 contact_info, contact_info);
485 else if (online_status==SalPresenceBerightback)
487 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
488 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" "
489 "xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" "
490 "xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" "
492 "<tuple id=\"sg89ae\">\n"
493 "<status><basic>open</basic></status>\n"
494 "<contact priority=\"0.8\">%s</contact>\n"
496 "<dm:person id=\"sg89aep\">\n"
497 "<rpid:activities><rpid:in-transit/></rpid:activities>\n"
500 contact_info, contact_info);
502 else if (online_status == SalPresenceAway ||
503 online_status == SalPresenceMoved)
505 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
506 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" "
507 "xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" "
508 "xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" "
510 "<tuple id=\"sg89ae\">\n"
511 "<status><basic>open</basic></status>\n"
512 "<contact priority=\"0.8\">%s</contact>\n"
514 "<dm:person id=\"sg89aep\">\n"
515 "<rpid:activities><rpid:away/></rpid:activities>\n"
518 contact_info, contact_info);
520 else if (online_status==SalPresenceOnthephone)
522 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
523 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" "
524 "xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" "
525 "xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" "
527 "<tuple id=\"sg89ae\">\n"
528 "<status><basic>open</basic></status>\n"
529 "<contact priority=\"0.8\">%s</contact>\n"
531 "<dm:person id=\"sg89aep\">\n"
532 "<rpid:activities><rpid:on-the-phone/></rpid:activities>\n"
535 contact_info, contact_info);
537 else if (online_status==SalPresenceOuttolunch)
539 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
540 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" "
541 "xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" "
542 "xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" "
544 "<tuple id=\"7777\">\n"
545 "<status><basic>open</basic></status>\n"
546 "<contact priority=\"0.8\">%s</contact>\n"
548 "<dm:person id=\"78787878\">\n"
549 "<rpid:activities><rpid:meal/></rpid:activities>\n"
550 "<rpid:note>Out to lunch</rpid:note> \n"
553 contact_info, contact_info);
557 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
558 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" "
559 "xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" "
560 "xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" "
562 "<tuple id=\"sg89ae\">\n"
563 "<status><basic>closed</basic></status>\n"
564 "<contact priority=\"0.8\">%s</contact>\n"
566 "</presence>\n", contact_info, contact_info);
574 static void add_presence_body(osip_message_t *notify, SalPresenceStatus online_status)
579 osip_from_t *from=NULL;
580 from=osip_message_get_from(notify);
581 osip_uri_to_str(from->url,&contact_info);
583 mk_presence_body (online_status, contact_info, buf, sizeof (buf), presence_style);
585 osip_message_set_body(notify, buf, strlen(buf));
586 osip_message_set_content_type(notify,
587 presence_style ? "application/xpidf+xml" : "application/pidf+xml");
589 osip_free(contact_info);
593 int sal_notify_presence(SalOp *op, SalPresenceStatus status, const char *status_message){
594 osip_message_t *msg=NULL;
595 eXosip_ss_t ss=EXOSIP_SUBCRSTATE_ACTIVE;
597 ms_warning("Cannot notify, subscription was closed.");
602 eXosip_insubscription_build_notify(op->did,ss,DEACTIVATED,&msg);
604 const char *identity=sal_op_get_contact(op);
605 if (identity==NULL) identity=sal_op_get_to(op);
606 _osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free);
607 osip_message_set_contact(msg,identity);
608 add_presence_body(msg,status);
609 eXosip_insubscription_send_request(op->did,msg);
610 }else ms_error("could not create notify for incoming subscription.");
615 int sal_notify_close(SalOp *op){
616 osip_message_t *msg=NULL;
618 eXosip_insubscription_build_notify(op->did,EXOSIP_SUBCRSTATE_TERMINATED,DEACTIVATED,&msg);
620 const char *identity=sal_op_get_contact(op);
621 if (identity==NULL) identity=sal_op_get_to(op);
622 osip_message_set_contact(msg,identity);
623 add_presence_body(msg,SalPresenceOffline);
624 eXosip_insubscription_send_request(op->did,msg);
625 }else ms_error("sal_notify_close(): could not create notify for incoming subscription"
626 " did=%i, nid=%i",op->did,op->nid);
631 int sal_publish(SalOp *op, const char *from, const char *to, SalPresenceStatus presence_mode){
636 mk_presence_body (presence_mode, from, buf, sizeof (buf), presence_style);
638 i = eXosip_build_publish(&pub,from, to, sal_op_get_route(op), "presence", "300",
639 presence_style ? "application/xpidf+xml" : "application/pidf+xml", buf);
641 ms_warning("Failed to build publish request.");
646 i = eXosip_publish(pub, to); /* should update the sip-if-match parameter
647 from sip-etag from last 200ok of PUBLISH */
650 ms_message("Failed to send publish request.");
653 sal_add_other(sal_op_get_sal(op),op,pub);
657 static void _sal_exosip_subscription_recv(Sal *sal, eXosip_event_t *ev){
658 SalOp *op=sal_op_new(sal);
663 osip_from_to_str(ev->request->from,&tmp);
664 sal_op_set_from(op,tmp);
666 osip_from_to_str(ev->request->to,&tmp);
667 sal_op_set_to(op,tmp);
669 sal_add_in_subscribe(sal,op,ev->request);
670 sal->callbacks.subscribe_received(op,sal_op_get_from(op));
673 void sal_exosip_subscription_recv(Sal *sal, eXosip_event_t *ev){
674 /*workaround a bug in eXosip: incoming SUBSCRIBES within dialog with expires: 0 are
675 recognized as new incoming subscribes*/
676 SalOp *op=sal_find_in_subscribe_by_call_id(sal,ev->request->call_id);
679 osip_message_header_get_byname(ev->request,"expires",0,&h);
680 if (h && h->hvalue && atoi(h->hvalue)==0){
681 ms_warning("This susbscribe is not a new one but terminates an old one.");
684 sal_exosip_subscription_closed(sal,ev);
686 osip_message_t *msg=NULL;
687 ms_warning("Probably a refresh subscribe");
689 eXosip_insubscription_build_answer(ev->tid,202,&msg);
690 eXosip_insubscription_send_answer(ev->tid,202,msg);
693 }else _sal_exosip_subscription_recv(sal,ev);
696 void sal_exosip_notify_recv(Sal *sal, eXosip_event_t *ev){
697 SalOp *op=sal_find_out_subscribe(sal,ev->sid);
699 osip_from_t *from=NULL;
700 osip_body_t *body=NULL;
701 SalPresenceStatus estatus=SalPresenceOffline;
703 ms_message("Receiving notify with sid=%i,nid=%i",ev->sid,ev->nid);
706 ms_error("No operation related to this notify !");
709 if (ev->request==NULL) return;
711 from=ev->request->from;
712 osip_message_get_body(ev->request,0,&body);
714 ms_error("No body in NOTIFY");
717 osip_from_to_str(from,&tmp);
718 if (strstr(body->body,"pending")!=NULL){
719 estatus=SalPresenceOffline;
720 }else if (strstr(body->body,"busy")!=NULL){
721 estatus=SalPresenceBusy;
722 }else if (strstr(body->body,"berightback")!=NULL
723 || strstr(body->body,"in-transit")!=NULL ){
724 estatus=SalPresenceBerightback;
725 }else if (strstr(body->body,"away")!=NULL
726 || strstr(body->body,"idle")){
727 estatus=SalPresenceAway;
728 }else if (strstr(body->body,"onthephone")!=NULL
729 || strstr(body->body,"on-the-phone")!=NULL){
730 estatus=SalPresenceOnthephone;
731 }else if (strstr(body->body,"outtolunch")!=NULL
732 || strstr(body->body,"meal")!=NULL){
733 estatus=SalPresenceOuttolunch;
734 }else if (strstr(body->body,"closed")!=NULL){
735 estatus=SalPresenceOffline;
736 }else if ((strstr(body->body,"online")!=NULL) || (strstr(body->body,"open")!=NULL)) {
737 estatus=SalPresenceOnline;
739 estatus=SalPresenceOffline;
741 ms_message("We are notified that %s has online status %i",tmp,estatus);
742 if (ev->ss_status==EXOSIP_SUBCRSTATE_TERMINATED) {
743 sal_remove_out_subscribe(sal,op);
746 ms_message("And outgoing subscription terminated by remote.");
748 sal->callbacks.notify_presence(op,op->sid!=-1 ? SalSubscribeActive : SalSubscribeTerminated, estatus,NULL);
750 /* try to detect presence message style used by server,
751 * and switch our presence messages to servers style */
752 if (strstr (body->body, "//IETF//DTD RFCxxxx XPIDF 1.0//EN") != NULL) {
753 presence_style = RFCxxxx;
754 } else if (strstr(body->body,"http://schemas.microsoft.com/2002/09/sip/presence")!=NULL) {
755 presence_style = MSOLDPRES;
761 void sal_exosip_subscription_answered(Sal *sal,eXosip_event_t *ev){
762 SalOp *op=sal_find_out_subscribe(sal,ev->sid);
764 ms_error("Subscription answered but no associated op !");
770 void sal_exosip_in_subscription_closed(Sal *sal, eXosip_event_t *ev){
771 SalOp *op=sal_find_in_subscribe(sal,ev->nid);
774 ms_error("Incoming subscription closed but no associated op !");
779 sal_remove_in_subscribe(sal,op);
783 osip_from_to_str(ev->request->from,&tmp);
784 sal->callbacks.subscribe_closed(op,tmp);
789 void sal_exosip_subscription_closed(Sal *sal,eXosip_event_t *ev){
790 SalOp *op=sal_find_out_subscribe(sal,ev->sid);
792 ms_error("Subscription closed but no associated op !");
795 sal_remove_out_subscribe(sal,op);
798 sal->callbacks.notify_presence(op,SalSubscribeTerminated, SalPresenceOffline,NULL);