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);
84 int sal_message_send(SalOp *op, const char *from, const char *to, const char* content_type, const char *msg){
85 osip_message_t *sip=NULL;
89 /* we are not currently in communication with the destination */
91 sal_op_set_from(op,from);
95 sal_exosip_fix_route(op);
97 eXosip_message_build_request(&sip,"MESSAGE",sal_op_get_to(op),
98 sal_op_get_from(op),sal_op_get_route(op));
100 osip_message_set_content_type(sip,content_type);
101 if (msg) osip_message_set_body(sip,msg,strlen(msg));
102 sal_add_other(op->base.root,op,sip);
103 eXosip_message_send_request(sip);
105 ms_error("Could not build MESSAGE request !");
111 /* we are currently in communication with the destination */
113 //First we generate an INFO message to get the current call_id and a good cseq
114 eXosip_call_build_request(op->did,"MESSAGE",&sip);
117 ms_warning("could not get a build info to send MESSAGE, maybe no previous call established ?");
121 osip_message_set_content_type(sip,content_type);
122 if (msg) osip_message_set_body(sip,msg,strlen(msg));
123 eXosip_call_send_request(op->did,sip);
128 int sal_text_send(SalOp *op, const char *from, const char *to, const char *msg) {
129 return sal_message_send(op,from,to,"text/plain",msg);
131 /*presence Subscribe/notify*/
132 int sal_subscribe_presence(SalOp *op, const char *from, const char *to){
133 osip_message_t *msg=NULL;
135 sal_op_set_from(op,from);
137 sal_op_set_to(op,to);
138 sal_exosip_fix_route(op);
140 eXosip_subscribe_build_initial_request(&msg,sal_op_get_to(op),sal_op_get_from(op),
141 sal_op_get_route(op),"presence",600);
143 ms_error("Could not build subscribe request to %s",to);
147 if (op->base.contact){
148 _osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free);
149 osip_message_set_contact(msg,op->base.contact);
151 op->sid=eXosip_subscribe_send_initial_request(msg);
154 osip_message_free(msg);
157 sal_add_out_subscribe(op->base.root,op);
161 int sal_unsubscribe(SalOp *op){
162 osip_message_t *msg=NULL;
164 ms_error("cannot unsubscribe, no dialog !");
168 eXosip_subscribe_build_refresh_request(op->did,&msg);
170 osip_message_set_expires(msg,"0");
171 eXosip_subscribe_send_refresh_request(op->did,msg);
172 }else ms_error("Could not build subscribe refresh request ! op->sid=%i, op->did=%i",
178 int sal_subscribe_accept(SalOp *op){
179 osip_message_t *msg=NULL;
181 eXosip_insubscription_build_answer(op->tid,202,&msg);
183 ms_error("Fail to build answer to subscribe.");
187 if (op->base.contact){
188 _osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free);
189 osip_message_set_contact(msg,op->base.contact);
191 eXosip_insubscription_send_answer(op->tid,202,msg);
196 int sal_subscribe_decline(SalOp *op){
198 eXosip_insubscription_send_answer(op->tid,401,NULL);
203 static void mk_presence_body (const SalPresenceStatus online_status, const char *contact_info,
204 char *buf, size_t buflen, presence_type_t ptype) {
207 /* definition from http://msdn.microsoft.com/en-us/library/cc246202%28PROT.10%29.aspx */
210 if (online_status==SalPresenceOnline)
212 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
213 <!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n\
215 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
217 <address uri=\"%s\" priority=\"0.800000\">\n\
218 <status status=\"open\" />\n\
219 <msnsubstatus substatus=\"online\" />\n\
222 </presence>", contact_info, atom_id, contact_info);
225 else if (online_status == SalPresenceBusy ||
226 online_status == SalPresenceDonotdisturb)
228 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
229 <!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n\
231 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
233 <address uri=\"%s\" priority=\"0.800000\">\n\
234 <status status=\"inuse\" />\n\
235 <msnsubstatus substatus=\"busy\" />\n\
237 </atom>\n</presence>", contact_info, atom_id, contact_info);
240 else if (online_status==SalPresenceBerightback)
242 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
243 <!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n\
245 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
247 <address uri=\"%s\" priority=\"0.800000\">\n\
248 <status status=\"open\" />\n\
249 <msnsubstatus substatus=\"berightback\" />\n\
252 </presence>", contact_info, atom_id, contact_info);
255 else if (online_status == SalPresenceAway ||
256 online_status == SalPresenceMoved)
258 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
259 <!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n\
261 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
263 <address uri=\"%s\" priority=\"0.800000\">\n\
264 <status status=\"open\" />\n\
265 <msnsubstatus substatus=\"away\" />\n\
268 </presence>", contact_info, atom_id, contact_info);
271 else if (online_status==SalPresenceOnthephone)
273 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
274 <!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n\
276 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
278 <address uri=\"%s\" priority=\"0.800000\">\n\
279 <status status=\"inuse\" />\n\
280 <msnsubstatus substatus=\"onthephone\" />\n\
283 </presence>", contact_info, atom_id, contact_info);
286 else if (online_status==SalPresenceOuttolunch)
288 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
289 <!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n\
291 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
293 <address uri=\"%s\" priority=\"0.800000\">\n\
294 <status status=\"open\" />\n\
295 <msnsubstatus substatus=\"outtolunch\" />\n\
298 </presence>", contact_info, atom_id, contact_info);
303 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
304 <!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n\
306 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
308 <address uri=\"%s\" priority=\"0.800000\">\n\
309 <status status=\"closed\" />\n\
310 <msnsubstatus substatus=\"away\" />\n\
313 </presence>", contact_info, atom_id, contact_info);
318 /* Couldn't find schema http://schemas.microsoft.com/2002/09/sip/presence
319 * so messages format has been taken from Communigate that can send notify
320 * requests with this schema
324 if (online_status==SalPresenceOnline)
326 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
327 <!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n\
329 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
331 <address uri=\"%s\">\n\
332 <status status=\"open\" />\n\
333 <msnsubstatus substatus=\"online\" />\n\
336 </presence>", contact_info, atom_id, contact_info);
339 else if (online_status == SalPresenceBusy ||
340 online_status == SalPresenceDonotdisturb)
342 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
343 <!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n\
345 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
347 <address uri=\"%s\">\n\
348 <status status=\"inuse\" />\n\
349 <msnsubstatus substatus=\"busy\" />\n\
351 </atom>\n</presence>", contact_info, atom_id, contact_info);
354 else if (online_status==SalPresenceBerightback)
356 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
357 <!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n\
359 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
361 <address uri=\"%s\">\n\
362 <status status=\"inactive\" />\n\
363 <msnsubstatus substatus=\"berightback\" />\n\
366 </presence>", contact_info, atom_id, contact_info);
369 else if (online_status == SalPresenceAway ||
370 online_status == SalPresenceMoved)
372 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
373 <!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n\
375 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
377 <address uri=\"%s\">\n\
378 <status status=\"inactive\" />\n\
379 <msnsubstatus substatus=\"idle\" />\n\
382 </presence>", contact_info, atom_id, contact_info);
385 else if (online_status==SalPresenceOnthephone)
387 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
388 <!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n\
390 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
392 <address uri=\"%s\">\n\
393 <status status=\"inuse\" />\n\
394 <msnsubstatus substatus=\"onthephone\" />\n\
397 </presence>", contact_info, atom_id, contact_info);
400 else if (online_status==SalPresenceOuttolunch)
402 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
403 <!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n\
405 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
407 <address uri=\"%s\">\n\
408 <status status=\"inactive\" />\n\
409 <msnsubstatus substatus=\"outtolunch\" />\n\
412 </presence>", contact_info, atom_id, contact_info);
417 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
418 <!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n\
420 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
422 <address uri=\"%s\">\n\
423 <status status=\"closed\" />\n\
424 <msnsubstatus substatus=\"offline\" />\n\
427 </presence>", contact_info, atom_id, contact_info);
431 default: { /* use pidf+xml as default format, rfc4479, rfc4480, rfc3863 */
433 if (online_status==SalPresenceOnline)
435 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
436 <presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \
437 xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" \
438 xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" \
440 <tuple id=\"sg89ae\">\n\
441 <status><basic>open</basic></status>\n\
442 <contact priority=\"0.8\">%s</contact>\n\
445 contact_info, contact_info);
447 else if (online_status == SalPresenceBusy ||
448 online_status == SalPresenceDonotdisturb)
450 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
451 <presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \
452 xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" \
453 xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" \
455 <tuple id=\"sg89ae\">\n\
456 <status><basic>open</basic></status>\n\
457 <contact priority=\"0.8\">%s</contact>\n\
459 <dm:person id=\"sg89aep\">\n\
460 <rpid:activities><rpid:busy/></rpid:activities>\n\
463 contact_info, contact_info);
465 else if (online_status==SalPresenceBerightback)
467 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
468 <presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \
469 xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" \
470 xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" \
472 <tuple id=\"sg89ae\">\n\
473 <status><basic>open</basic></status>\n\
474 <contact priority=\"0.8\">%s</contact>\n\
476 <dm:person id=\"sg89aep\">\n\
477 <rpid:activities><rpid:in-transit/></rpid:activities>\n\
480 contact_info, contact_info);
482 else if (online_status == SalPresenceAway ||
483 online_status == SalPresenceMoved)
485 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
486 <presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \
487 xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" \
488 xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" \
490 <tuple id=\"sg89ae\">\n\
491 <status><basic>open</basic></status>\n\
492 <contact priority=\"0.8\">%s</contact>\n\
494 <dm:person id=\"sg89aep\">\n\
495 <rpid:activities><rpid:away/></rpid:activities>\n\
498 contact_info, contact_info);
500 else if (online_status==SalPresenceOnthephone)
502 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
503 <presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \
504 xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" \
505 xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" \
507 <tuple id=\"sg89ae\">\n\
508 <status><basic>open</basic></status>\n\
509 <contact priority=\"0.8\">%s</contact>\n\
511 <dm:person id=\"sg89aep\">\n\
512 <rpid:activities><rpid:on-the-phone/></rpid:activities>\n\
515 contact_info, contact_info);
517 else if (online_status==SalPresenceOuttolunch)
519 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
520 <presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \
521 xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" \
522 xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" \
524 <tuple id=\"7777\">\n\
525 <status><basic>open</basic></status>\n\
526 <contact priority=\"0.8\">%s</contact>\n\
528 <dm:person id=\"78787878\">\n\
529 <rpid:activities><rpid:meal/></rpid:activities>\n\
530 <rpid:note>Out to lunch</rpid:note> \n\
533 contact_info, contact_info);
537 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
538 <presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \
539 xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" \
540 xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" \
542 <tuple id=\"sg89ae\">\n\
543 <status><basic>closed</basic></status>\n\
544 <contact priority=\"0.8\">%s</contact>\n\
546 </presence>\n", contact_info, contact_info);
554 static void add_presence_body(osip_message_t *notify, SalPresenceStatus online_status)
559 osip_from_t *from=NULL;
560 from=osip_message_get_from(notify);
561 osip_uri_to_str(from->url,&contact_info);
563 mk_presence_body (online_status, contact_info, buf, sizeof (buf), presence_style);
565 osip_message_set_body(notify, buf, strlen(buf));
566 osip_message_set_content_type(notify,
567 presence_style ? "application/xpidf+xml" : "application/pidf+xml");
569 osip_free(contact_info);
573 int sal_notify_presence(SalOp *op, SalPresenceStatus status, const char *status_message){
574 osip_message_t *msg=NULL;
575 eXosip_ss_t ss=EXOSIP_SUBCRSTATE_ACTIVE;
577 ms_warning("Cannot notify, subscription was closed.");
582 eXosip_insubscription_build_notify(op->did,ss,DEACTIVATED,&msg);
584 const char *identity=sal_op_get_contact(op);
585 if (identity==NULL) identity=sal_op_get_to(op);
586 _osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free);
587 osip_message_set_contact(msg,identity);
588 add_presence_body(msg,status);
589 eXosip_insubscription_send_request(op->did,msg);
590 }else ms_error("could not create notify for incoming subscription.");
595 int sal_notify_close(SalOp *op){
596 osip_message_t *msg=NULL;
598 eXosip_insubscription_build_notify(op->did,EXOSIP_SUBCRSTATE_TERMINATED,DEACTIVATED,&msg);
600 const char *identity=sal_op_get_contact(op);
601 if (identity==NULL) identity=sal_op_get_to(op);
602 osip_message_set_contact(msg,identity);
603 add_presence_body(msg,SalPresenceOffline);
604 eXosip_insubscription_send_request(op->did,msg);
605 }else ms_error("sal_notify_close(): could not create notify for incoming subscription"
606 " did=%i, nid=%i",op->did,op->nid);
611 int sal_publish(SalOp *op, const char *from, const char *to, SalPresenceStatus presence_mode){
616 mk_presence_body (presence_mode, from, buf, sizeof (buf), presence_style);
618 i = eXosip_build_publish(&pub,from, to, NULL, "presence", "300",
619 presence_style ? "application/xpidf+xml" : "application/pidf+xml", buf);
621 ms_warning("Failed to build publish request.");
626 i = eXosip_publish(pub, to); /* should update the sip-if-match parameter
627 from sip-etag from last 200ok of PUBLISH */
630 ms_message("Failed to send publish request.");
633 sal_add_other(sal_op_get_sal(op),op,pub);
637 static void _sal_exosip_subscription_recv(Sal *sal, eXosip_event_t *ev){
638 SalOp *op=sal_op_new(sal);
643 osip_from_to_str(ev->request->from,&tmp);
644 sal_op_set_from(op,tmp);
646 osip_from_to_str(ev->request->to,&tmp);
647 sal_op_set_to(op,tmp);
649 sal_add_in_subscribe(sal,op,ev->request);
650 sal->callbacks.subscribe_received(op,sal_op_get_from(op));
653 void sal_exosip_subscription_recv(Sal *sal, eXosip_event_t *ev){
654 /*workaround a bug in eXosip: incoming SUBSCRIBES within dialog with expires: 0 are
655 recognized as new incoming subscribes*/
656 SalOp *op=sal_find_in_subscribe_by_call_id(sal,ev->request->call_id);
659 osip_message_header_get_byname(ev->request,"expires",0,&h);
660 if (h && h->hvalue && atoi(h->hvalue)==0){
661 ms_warning("This susbscribe is not a new one but terminates an old one.");
664 sal_exosip_subscription_closed(sal,ev);
666 osip_message_t *msg=NULL;
667 ms_warning("Probably a refresh subscribe");
669 eXosip_insubscription_build_answer(ev->tid,202,&msg);
670 eXosip_insubscription_send_answer(ev->tid,202,msg);
673 }else _sal_exosip_subscription_recv(sal,ev);
676 void sal_exosip_notify_recv(Sal *sal, eXosip_event_t *ev){
677 SalOp *op=sal_find_out_subscribe(sal,ev->sid);
679 osip_from_t *from=NULL;
680 osip_body_t *body=NULL;
681 SalPresenceStatus estatus=SalPresenceOffline;
683 ms_message("Receiving notify with sid=%i,nid=%i",ev->sid,ev->nid);
686 ms_error("No operation related to this notify !");
689 if (ev->request==NULL) return;
691 from=ev->request->from;
692 osip_message_get_body(ev->request,0,&body);
694 ms_error("No body in NOTIFY");
697 osip_from_to_str(from,&tmp);
698 if (strstr(body->body,"pending")!=NULL){
699 estatus=SalPresenceOffline;
700 }else if (strstr(body->body,"busy")!=NULL){
701 estatus=SalPresenceBusy;
702 }else if (strstr(body->body,"berightback")!=NULL
703 || strstr(body->body,"in-transit")!=NULL ){
704 estatus=SalPresenceBerightback;
705 }else if (strstr(body->body,"away")!=NULL
706 || strstr(body->body,"idle")){
707 estatus=SalPresenceAway;
708 }else if (strstr(body->body,"onthephone")!=NULL
709 || strstr(body->body,"on-the-phone")!=NULL){
710 estatus=SalPresenceOnthephone;
711 }else if (strstr(body->body,"outtolunch")!=NULL
712 || strstr(body->body,"meal")!=NULL){
713 estatus=SalPresenceOuttolunch;
714 }else if (strstr(body->body,"closed")!=NULL){
715 estatus=SalPresenceOffline;
716 }else if ((strstr(body->body,"online")!=NULL) || (strstr(body->body,"open")!=NULL)) {
717 estatus=SalPresenceOnline;
719 estatus=SalPresenceOffline;
721 ms_message("We are notified that %s has online status %i",tmp,estatus);
722 if (ev->ss_status==EXOSIP_SUBCRSTATE_TERMINATED) {
723 sal_remove_out_subscribe(sal,op);
726 ms_message("And outgoing subscription terminated by remote.");
728 sal->callbacks.notify_presence(op,op->sid!=-1 ? SalSubscribeActive : SalSubscribeTerminated, estatus,NULL);
730 /* try to detect presence message style used by server,
731 * and switch our presence messages to servers style */
732 if (strstr (body->body, "//IETF//DTD RFCxxxx XPIDF 1.0//EN") != NULL) {
733 presence_style = RFCxxxx;
734 } else if (strstr(body->body,"http://schemas.microsoft.com/2002/09/sip/presence")!=NULL) {
735 presence_style = MSOLDPRES;
741 void sal_exosip_subscription_answered(Sal *sal,eXosip_event_t *ev){
742 SalOp *op=sal_find_out_subscribe(sal,ev->sid);
744 ms_error("Subscription answered but no associated op !");
750 void sal_exosip_in_subscription_closed(Sal *sal, eXosip_event_t *ev){
751 SalOp *op=sal_find_in_subscribe(sal,ev->nid);
754 ms_error("Incoming subscription closed but no associated op !");
759 sal_remove_in_subscribe(sal,op);
763 osip_from_to_str(ev->request->from,&tmp);
764 sal->callbacks.subscribe_closed(op,tmp);
769 void sal_exosip_subscription_closed(Sal *sal,eXosip_event_t *ev){
770 SalOp *op=sal_find_out_subscribe(sal,ev->sid);
772 ms_error("Subscription closed but no associated op !");
775 sal_remove_out_subscribe(sal,op);
778 sal->callbacks.notify_presence(op,SalSubscribeTerminated, SalPresenceOffline,NULL);