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_text_send(SalOp *op, const char *from, const char *to, 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);
96 eXosip_message_build_request(&sip,"MESSAGE",sal_op_get_to(op),
97 sal_op_get_from(op),sal_op_get_route(op));
99 osip_message_set_content_type(sip,"text/plain");
100 osip_message_set_body(sip,msg,strlen(msg));
101 sal_add_other(op->base.root,op,sip);
102 eXosip_message_send_request(sip);
104 ms_error("Could not build MESSAGE request !");
110 /* we are currently in communication with the destination */
112 //First we generate an INFO message to get the current call_id and a good cseq
113 eXosip_call_build_request(op->did,"MESSAGE",&sip);
116 ms_warning("could not get a build info to send MESSAGE, maybe no previous call established ?");
120 osip_message_set_content_type(sip,"text/plain");
121 osip_message_set_body(sip,msg,strlen(msg));
122 eXosip_call_send_request(op->did,sip);
128 /*presence Subscribe/notify*/
129 int sal_subscribe_presence(SalOp *op, const char *from, const char *to){
130 osip_message_t *msg=NULL;
132 sal_op_set_from(op,from);
134 sal_op_set_to(op,to);
135 sal_exosip_fix_route(op);
137 eXosip_subscribe_build_initial_request(&msg,sal_op_get_to(op),sal_op_get_from(op),
138 sal_op_get_route(op),"presence",600);
140 ms_error("Could not build subscribe request to %s",to);
144 if (op->base.contact){
145 _osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free);
146 osip_message_set_contact(msg,op->base.contact);
148 op->sid=eXosip_subscribe_send_initial_request(msg);
151 osip_message_free(msg);
154 sal_add_out_subscribe(op->base.root,op);
158 int sal_unsubscribe(SalOp *op){
159 osip_message_t *msg=NULL;
161 ms_error("cannot unsubscribe, no dialog !");
165 eXosip_subscribe_build_refresh_request(op->did,&msg);
167 osip_message_set_expires(msg,"0");
168 eXosip_subscribe_send_refresh_request(op->did,msg);
169 }else ms_error("Could not build subscribe refresh request ! op->sid=%i, op->did=%i",
175 int sal_subscribe_accept(SalOp *op){
176 osip_message_t *msg=NULL;
178 eXosip_insubscription_build_answer(op->tid,202,&msg);
180 ms_error("Fail to build answer to subscribe.");
184 if (op->base.contact){
185 _osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free);
186 osip_message_set_contact(msg,op->base.contact);
188 eXosip_insubscription_send_answer(op->tid,202,msg);
193 int sal_subscribe_decline(SalOp *op){
195 eXosip_insubscription_send_answer(op->tid,401,NULL);
200 static void mk_presence_body (const SalPresenceStatus online_status, const char *contact_info,
201 char *buf, size_t buflen, presence_type_t ptype) {
204 /* definition from http://msdn.microsoft.com/en-us/library/cc246202%28PROT.10%29.aspx */
207 if (online_status==SalPresenceOnline)
209 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
210 <!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n\
212 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
214 <address uri=\"%s\" priority=\"0.800000\">\n\
215 <status status=\"open\" />\n\
216 <msnsubstatus substatus=\"online\" />\n\
219 </presence>", contact_info, atom_id, contact_info);
222 else if (online_status == SalPresenceBusy ||
223 online_status == SalPresenceDonotdisturb)
225 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
226 <!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n\
228 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
230 <address uri=\"%s\" priority=\"0.800000\">\n\
231 <status status=\"inuse\" />\n\
232 <msnsubstatus substatus=\"busy\" />\n\
234 </atom>\n</presence>", contact_info, atom_id, contact_info);
237 else if (online_status==SalPresenceBerightback)
239 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
240 <!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n\
242 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
244 <address uri=\"%s\" priority=\"0.800000\">\n\
245 <status status=\"open\" />\n\
246 <msnsubstatus substatus=\"berightback\" />\n\
249 </presence>", contact_info, atom_id, contact_info);
252 else if (online_status == SalPresenceAway ||
253 online_status == SalPresenceMoved)
255 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
256 <!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n\
258 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
260 <address uri=\"%s\" priority=\"0.800000\">\n\
261 <status status=\"open\" />\n\
262 <msnsubstatus substatus=\"away\" />\n\
265 </presence>", contact_info, atom_id, contact_info);
268 else if (online_status==SalPresenceOnthephone)
270 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
271 <!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n\
273 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
275 <address uri=\"%s\" priority=\"0.800000\">\n\
276 <status status=\"inuse\" />\n\
277 <msnsubstatus substatus=\"onthephone\" />\n\
280 </presence>", contact_info, atom_id, contact_info);
283 else if (online_status==SalPresenceOuttolunch)
285 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
286 <!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n\
288 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
290 <address uri=\"%s\" priority=\"0.800000\">\n\
291 <status status=\"open\" />\n\
292 <msnsubstatus substatus=\"outtolunch\" />\n\
295 </presence>", contact_info, atom_id, contact_info);
300 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
301 <!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n\
303 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
305 <address uri=\"%s\" priority=\"0.800000\">\n\
306 <status status=\"closed\" />\n\
307 <msnsubstatus substatus=\"away\" />\n\
310 </presence>", contact_info, atom_id, contact_info);
315 /* Couldn't find schema http://schemas.microsoft.com/2002/09/sip/presence
316 * so messages format has been taken from Communigate that can send notify
317 * requests with this schema
321 if (online_status==SalPresenceOnline)
323 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
324 <!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n\
326 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
328 <address uri=\"%s\">\n\
329 <status status=\"open\" />\n\
330 <msnsubstatus substatus=\"online\" />\n\
333 </presence>", contact_info, atom_id, contact_info);
336 else if (online_status == SalPresenceBusy ||
337 online_status == SalPresenceDonotdisturb)
339 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
340 <!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n\
342 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
344 <address uri=\"%s\">\n\
345 <status status=\"inuse\" />\n\
346 <msnsubstatus substatus=\"busy\" />\n\
348 </atom>\n</presence>", contact_info, atom_id, contact_info);
351 else if (online_status==SalPresenceBerightback)
353 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
354 <!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n\
356 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
358 <address uri=\"%s\">\n\
359 <status status=\"inactive\" />\n\
360 <msnsubstatus substatus=\"berightback\" />\n\
363 </presence>", contact_info, atom_id, contact_info);
366 else if (online_status == SalPresenceAway ||
367 online_status == SalPresenceMoved)
369 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
370 <!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n\
372 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
374 <address uri=\"%s\">\n\
375 <status status=\"inactive\" />\n\
376 <msnsubstatus substatus=\"idle\" />\n\
379 </presence>", contact_info, atom_id, contact_info);
382 else if (online_status==SalPresenceOnthephone)
384 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
385 <!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n\
387 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
389 <address uri=\"%s\">\n\
390 <status status=\"inuse\" />\n\
391 <msnsubstatus substatus=\"onthephone\" />\n\
394 </presence>", contact_info, atom_id, contact_info);
397 else if (online_status==SalPresenceOuttolunch)
399 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
400 <!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n\
402 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
404 <address uri=\"%s\">\n\
405 <status status=\"inactive\" />\n\
406 <msnsubstatus substatus=\"outtolunch\" />\n\
409 </presence>", contact_info, atom_id, contact_info);
414 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n\
415 <!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n\
417 <presentity uri=\"%s;method=SUBSCRIBE\" />\n\
419 <address uri=\"%s\">\n\
420 <status status=\"closed\" />\n\
421 <msnsubstatus substatus=\"offline\" />\n\
424 </presence>", contact_info, atom_id, contact_info);
428 default: { /* use pidf+xml as default format, rfc4479, rfc4480, rfc3863 */
430 if (online_status==SalPresenceOnline)
432 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
433 <presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \
434 xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" \
435 xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" \
437 <tuple id=\"sg89ae\">\n\
438 <status><basic>open</basic></status>\n\
439 <contact priority=\"0.8\">%s</contact>\n\
442 contact_info, contact_info);
444 else if (online_status == SalPresenceBusy ||
445 online_status == SalPresenceDonotdisturb)
447 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
448 <presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \
449 xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" \
450 xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" \
452 <tuple id=\"sg89ae\">\n\
453 <status><basic>open</basic></status>\n\
454 <contact priority=\"0.8\">%s</contact>\n\
456 <dm:person id=\"sg89aep\">\n\
457 <rpid:activities><rpid:busy/></rpid:activities>\n\
460 contact_info, contact_info);
462 else if (online_status==SalPresenceBerightback)
464 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
465 <presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \
466 xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" \
467 xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" \
469 <tuple id=\"sg89ae\">\n\
470 <status><basic>open</basic></status>\n\
471 <contact priority=\"0.8\">%s</contact>\n\
473 <dm:person id=\"sg89aep\">\n\
474 <rpid:activities><rpid:in-transit/></rpid:activities>\n\
477 contact_info, contact_info);
479 else if (online_status == SalPresenceAway ||
480 online_status == SalPresenceMoved)
482 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
483 <presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \
484 xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" \
485 xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" \
487 <tuple id=\"sg89ae\">\n\
488 <status><basic>open</basic></status>\n\
489 <contact priority=\"0.8\">%s</contact>\n\
491 <dm:person id=\"sg89aep\">\n\
492 <rpid:activities><rpid:away/></rpid:activities>\n\
495 contact_info, contact_info);
497 else if (online_status==SalPresenceOnthephone)
499 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
500 <presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \
501 xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" \
502 xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" \
504 <tuple id=\"sg89ae\">\n\
505 <status><basic>open</basic></status>\n\
506 <contact priority=\"0.8\">%s</contact>\n\
508 <dm:person id=\"sg89aep\">\n\
509 <rpid:activities><rpid:on-the-phone/></rpid:activities>\n\
512 contact_info, contact_info);
514 else if (online_status==SalPresenceOuttolunch)
516 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
517 <presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \
518 xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" \
519 xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" \
521 <tuple id=\"7777\">\n\
522 <status><basic>open</basic></status>\n\
523 <contact priority=\"0.8\">%s</contact>\n\
525 <dm:person id=\"78787878\">\n\
526 <rpid:activities><rpid:meal/></rpid:activities>\n\
527 <rpid:note>Out to lunch</rpid:note> \n\
530 contact_info, contact_info);
534 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
535 <presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \
536 xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" \
537 xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" \
539 <tuple id=\"sg89ae\">\n\
540 <status><basic>closed</basic></status>\n\
541 <contact priority=\"0.8\">%s</contact>\n\
543 </presence>\n", contact_info, contact_info);
551 static void add_presence_body(osip_message_t *notify, SalPresenceStatus online_status)
556 osip_from_t *from=NULL;
557 from=osip_message_get_from(notify);
558 osip_uri_to_str(from->url,&contact_info);
560 mk_presence_body (online_status, contact_info, buf, sizeof (buf), presence_style);
562 osip_message_set_body(notify, buf, strlen(buf));
563 osip_message_set_content_type(notify,
564 presence_style ? "application/xpidf+xml" : "application/pidf+xml");
566 osip_free(contact_info);
570 int sal_notify_presence(SalOp *op, SalPresenceStatus status, const char *status_message){
571 osip_message_t *msg=NULL;
572 eXosip_ss_t ss=EXOSIP_SUBCRSTATE_ACTIVE;
574 ms_warning("Cannot notify, subscription was closed.");
579 eXosip_insubscription_build_notify(op->did,ss,DEACTIVATED,&msg);
581 const char *identity=sal_op_get_contact(op);
582 if (identity==NULL) identity=sal_op_get_to(op);
583 _osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free);
584 osip_message_set_contact(msg,identity);
585 add_presence_body(msg,status);
586 eXosip_insubscription_send_request(op->did,msg);
587 }else ms_error("could not create notify for incoming subscription.");
592 int sal_notify_close(SalOp *op){
593 osip_message_t *msg=NULL;
595 eXosip_insubscription_build_notify(op->did,EXOSIP_SUBCRSTATE_TERMINATED,DEACTIVATED,&msg);
597 const char *identity=sal_op_get_contact(op);
598 if (identity==NULL) identity=sal_op_get_to(op);
599 osip_message_set_contact(msg,identity);
600 add_presence_body(msg,SalPresenceOffline);
601 eXosip_insubscription_send_request(op->did,msg);
602 }else ms_error("sal_notify_close(): could not create notify for incoming subscription"
603 " did=%i, nid=%i",op->did,op->nid);
608 int sal_publish(SalOp *op, const char *from, const char *to, SalPresenceStatus presence_mode){
613 mk_presence_body (presence_mode, from, buf, sizeof (buf), presence_style);
615 i = eXosip_build_publish(&pub,from, to, NULL, "presence", "300",
616 presence_style ? "application/xpidf+xml" : "application/pidf+xml", buf);
618 ms_warning("Failed to build publish request.");
623 i = eXosip_publish(pub, to); /* should update the sip-if-match parameter
624 from sip-etag from last 200ok of PUBLISH */
627 ms_message("Failed to send publish request.");
630 sal_add_other(sal_op_get_sal(op),op,pub);
634 static void _sal_exosip_subscription_recv(Sal *sal, eXosip_event_t *ev){
635 SalOp *op=sal_op_new(sal);
640 osip_from_to_str(ev->request->from,&tmp);
641 sal_op_set_from(op,tmp);
643 osip_from_to_str(ev->request->to,&tmp);
644 sal_op_set_to(op,tmp);
646 sal_add_in_subscribe(sal,op,ev->request);
647 sal->callbacks.subscribe_received(op,sal_op_get_from(op));
650 void sal_exosip_subscription_recv(Sal *sal, eXosip_event_t *ev){
651 /*workaround a bug in eXosip: incoming SUBSCRIBES within dialog with expires: 0 are
652 recognized as new incoming subscribes*/
653 SalOp *op=sal_find_in_subscribe_by_call_id(sal,ev->request->call_id);
656 osip_message_header_get_byname(ev->request,"expires",0,&h);
657 if (h && h->hvalue && atoi(h->hvalue)==0){
658 ms_warning("This susbscribe is not a new one but terminates an old one.");
661 sal_exosip_subscription_closed(sal,ev);
663 osip_message_t *msg=NULL;
664 ms_warning("Probably a refresh subscribe");
666 eXosip_insubscription_build_answer(ev->tid,202,&msg);
667 eXosip_insubscription_send_answer(ev->tid,202,msg);
670 }else _sal_exosip_subscription_recv(sal,ev);
673 void sal_exosip_notify_recv(Sal *sal, eXosip_event_t *ev){
674 SalOp *op=sal_find_out_subscribe(sal,ev->sid);
676 osip_from_t *from=NULL;
677 osip_body_t *body=NULL;
678 SalPresenceStatus estatus=SalPresenceOffline;
680 ms_message("Receiving notify with sid=%i,nid=%i",ev->sid,ev->nid);
683 ms_error("No operation related to this notify !");
686 if (ev->request==NULL) return;
688 from=ev->request->from;
689 osip_message_get_body(ev->request,0,&body);
691 ms_error("No body in NOTIFY");
694 osip_from_to_str(from,&tmp);
695 if (strstr(body->body,"pending")!=NULL){
696 estatus=SalPresenceOffline;
697 }else if (strstr(body->body,"busy")!=NULL){
698 estatus=SalPresenceBusy;
699 }else if (strstr(body->body,"berightback")!=NULL
700 || strstr(body->body,"in-transit")!=NULL ){
701 estatus=SalPresenceBerightback;
702 }else if (strstr(body->body,"away")!=NULL
703 || strstr(body->body,"idle")){
704 estatus=SalPresenceAway;
705 }else if (strstr(body->body,"onthephone")!=NULL
706 || strstr(body->body,"on-the-phone")!=NULL){
707 estatus=SalPresenceOnthephone;
708 }else if (strstr(body->body,"outtolunch")!=NULL
709 || strstr(body->body,"meal")!=NULL){
710 estatus=SalPresenceOuttolunch;
711 }else if (strstr(body->body,"closed")!=NULL){
712 estatus=SalPresenceOffline;
713 }else if ((strstr(body->body,"online")!=NULL) || (strstr(body->body,"open")!=NULL)) {
714 estatus=SalPresenceOnline;
716 estatus=SalPresenceOffline;
718 ms_message("We are notified that %s has online status %i",tmp,estatus);
719 if (ev->ss_status==EXOSIP_SUBCRSTATE_TERMINATED) {
720 sal_remove_out_subscribe(sal,op);
723 ms_message("And outgoing subscription terminated by remote.");
725 sal->callbacks.notify_presence(op,op->sid!=-1 ? SalSubscribeActive : SalSubscribeTerminated, estatus,NULL);
727 /* try to detect presence message style used by server,
728 * and switch our presence messages to servers style */
729 if (strstr (body->body, "//IETF//DTD RFCxxxx XPIDF 1.0//EN") != NULL) {
730 presence_style = RFCxxxx;
731 } else if (strstr(body->body,"http://schemas.microsoft.com/2002/09/sip/presence")!=NULL) {
732 presence_style = MSOLDPRES;
738 void sal_exosip_subscription_answered(Sal *sal,eXosip_event_t *ev){
739 SalOp *op=sal_find_out_subscribe(sal,ev->sid);
741 ms_error("Subscription answered but no associated op !");
747 void sal_exosip_in_subscription_closed(Sal *sal, eXosip_event_t *ev){
748 SalOp *op=sal_find_in_subscribe(sal,ev->nid);
751 ms_error("Incoming subscription closed but no associated op !");
756 sal_remove_in_subscribe(sal,op);
760 osip_from_to_str(ev->request->from,&tmp);
761 sal->callbacks.subscribe_closed(op,tmp);
766 void sal_exosip_subscription_closed(Sal *sal,eXosip_event_t *ev){
767 SalOp *op=sal_find_out_subscribe(sal,ev->sid);
769 ms_error("Subscription closed but no associated op !");
772 sal_remove_out_subscribe(sal,op);
775 sal->callbacks.notify_presence(op,SalSubscribeTerminated, SalPresenceOffline,NULL);