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 static const char *days[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
85 static const char *months[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
87 static void msg_add_current_date(osip_message_t *msg){
89 time_t curtime=time(NULL);
93 ret=gmtime_r(&curtime,&gmt);
97 /*cannot use strftime because it is locale dependant*/
98 snprintf(tmp,sizeof(tmp)-1,"%s, %i %s %i %02i:%02i:%02i GMT",
99 days[ret->tm_wday],ret->tm_mday,months[ret->tm_mon],1900+ret->tm_year,ret->tm_hour,ret->tm_min,ret->tm_sec);
100 osip_message_replace_header(msg,"Date",tmp);
104 int sal_message_send(SalOp *op, const char *from, const char *to, const char* content_type, const char *msg){
105 osip_message_t *sip=NULL;
109 /* we are not currently in communication with the destination */
111 sal_op_set_from(op,from);
113 sal_op_set_to(op,to);
115 sal_exosip_fix_route(op);
117 eXosip_message_build_request(&sip,"MESSAGE",sal_op_get_to(op),
118 sal_op_get_from(op),sal_op_get_route(op));
120 sal_exosip_add_custom_headers(sip,op->base.custom_headers);
121 msg_add_current_date(sip);
122 osip_message_set_content_type(sip,content_type);
123 if (msg) osip_message_set_body(sip,msg,strlen(msg));
124 sal_add_other(op->base.root,op,sip);
125 eXosip_message_send_request(sip);
127 ms_error("Could not build MESSAGE request !");
133 /* we are currently in communication with the destination */
135 //First we generate an INFO message to get the current call_id and a good cseq
136 eXosip_call_build_request(op->did,"MESSAGE",&sip);
139 ms_warning("could not get a build info to send MESSAGE, maybe no previous call established ?");
143 sal_exosip_add_custom_headers(sip,op->base.custom_headers);
144 msg_add_current_date(sip);
145 osip_message_set_content_type(sip,content_type);
146 if (msg) osip_message_set_body(sip,msg,strlen(msg));
147 eXosip_call_send_request(op->did,sip);
153 int sal_text_send(SalOp *op, const char *from, const char *to, const char *msg) {
154 return sal_message_send(op,from,to,"text/plain",msg);
156 /*presence Subscribe/notify*/
157 int sal_subscribe_presence(SalOp *op, const char *from, const char *to){
158 osip_message_t *msg=NULL;
160 sal_op_set_from(op,from);
162 sal_op_set_to(op,to);
163 sal_exosip_fix_route(op);
165 eXosip_subscribe_build_initial_request(&msg,sal_op_get_to(op),sal_op_get_from(op),
166 sal_op_get_route(op),"presence",600);
168 ms_error("Could not build subscribe request to %s",to);
172 if (op->base.contact){
173 _osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free);
174 osip_message_set_contact(msg,op->base.contact);
176 op->sid=eXosip_subscribe_send_initial_request(msg);
179 osip_message_free(msg);
182 sal_add_out_subscribe(op->base.root,op);
186 int sal_unsubscribe(SalOp *op){
187 osip_message_t *msg=NULL;
189 ms_error("cannot unsubscribe, no dialog !");
193 eXosip_subscribe_build_refresh_request(op->did,&msg);
195 osip_message_set_expires(msg,"0");
196 eXosip_subscribe_send_refresh_request(op->did,msg);
197 }else ms_error("Could not build subscribe refresh request ! op->sid=%i, op->did=%i",
203 int sal_subscribe_accept(SalOp *op){
204 osip_message_t *msg=NULL;
206 eXosip_insubscription_build_answer(op->tid,202,&msg);
208 ms_error("Fail to build answer to subscribe.");
212 if (op->base.contact){
213 _osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free);
214 osip_message_set_contact(msg,op->base.contact);
216 eXosip_insubscription_send_answer(op->tid,202,msg);
221 int sal_subscribe_decline(SalOp *op){
223 eXosip_insubscription_send_answer(op->tid,401,NULL);
228 static void mk_presence_body (const SalPresenceStatus online_status, const char *contact_info,
229 char *buf, size_t buflen, presence_type_t ptype) {
232 /* definition from http://msdn.microsoft.com/en-us/library/cc246202%28PROT.10%29.aspx */
235 if (online_status==SalPresenceOnline)
237 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
238 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
240 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
242 "<address uri=\"%s\" priority=\"0.800000\">\n"
243 "<status status=\"open\" />\n"
244 "<msnsubstatus substatus=\"online\" />\n"
247 "</presence>", contact_info, atom_id, contact_info);
250 else if (online_status == SalPresenceBusy ||
251 online_status == SalPresenceDonotdisturb)
253 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
254 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
256 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
258 "<address uri=\"%s\" priority=\"0.800000\">\n"
259 "<status status=\"inuse\" />\n"
260 "<msnsubstatus substatus=\"busy\" />\n"
262 "</atom>\n</presence>", contact_info, atom_id, contact_info);
265 else if (online_status==SalPresenceBerightback)
267 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
268 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
270 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
272 "<address uri=\"%s\" priority=\"0.800000\">\n"
273 "<status status=\"open\" />\n"
274 "<msnsubstatus substatus=\"berightback\" />\n"
277 "</presence>", contact_info, atom_id, contact_info);
280 else if (online_status == SalPresenceAway ||
281 online_status == SalPresenceMoved)
283 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
284 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
286 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
288 "<address uri=\"%s\" priority=\"0.800000\">\n"
289 "<status status=\"open\" />\n"
290 "<msnsubstatus substatus=\"away\" />\n"
293 "</presence>", contact_info, atom_id, contact_info);
296 else if (online_status==SalPresenceOnthephone)
298 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
299 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
301 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
303 "<address uri=\"%s\" priority=\"0.800000\">\n"
304 "<status status=\"inuse\" />\n"
305 "<msnsubstatus substatus=\"onthephone\" />\n"
308 "</presence>", contact_info, atom_id, contact_info);
311 else if (online_status==SalPresenceOuttolunch)
313 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
314 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
316 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
318 "<address uri=\"%s\" priority=\"0.800000\">\n"
319 "<status status=\"open\" />\n"
320 "<msnsubstatus substatus=\"outtolunch\" />\n"
323 "</presence>", contact_info, atom_id, contact_info);
328 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
329 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
331 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
333 "<address uri=\"%s\" priority=\"0.800000\">\n"
334 "<status status=\"closed\" />\n"
335 "<msnsubstatus substatus=\"away\" />\n"
338 "</presence>", contact_info, atom_id, contact_info);
343 /* Couldn't find schema http://schemas.microsoft.com/2002/09/sip/presence
344 * so messages format has been taken from Communigate that can send notify
345 * requests with this schema
349 if (online_status==SalPresenceOnline)
351 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
352 "<!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n"
354 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
356 "<address uri=\"%s\">\n"
357 "<status status=\"open\" />\n"
358 "<msnsubstatus substatus=\"online\" />\n"
361 "</presence>", contact_info, atom_id, contact_info);
364 else if (online_status == SalPresenceBusy ||
365 online_status == SalPresenceDonotdisturb)
367 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
368 "<!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n"
370 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
372 "<address uri=\"%s\">\n"
373 "<status status=\"inuse\" />\n"
374 "<msnsubstatus substatus=\"busy\" />\n"
376 "</atom>\n</presence>", contact_info, atom_id, contact_info);
379 else if (online_status==SalPresenceBerightback)
381 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
382 "<!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n"
384 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
386 "<address uri=\"%s\">\n"
387 "<status status=\"inactive\" />\n"
388 "<msnsubstatus substatus=\"berightback\" />\n"
391 "</presence>", contact_info, atom_id, contact_info);
394 else if (online_status == SalPresenceAway ||
395 online_status == SalPresenceMoved)
397 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
398 "<!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n"
400 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
402 "<address uri=\"%s\">\n"
403 "<status status=\"inactive\" />\n"
404 "<msnsubstatus substatus=\"idle\" />\n"
407 "</presence>", contact_info, atom_id, contact_info);
410 else if (online_status==SalPresenceOnthephone)
412 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
413 "<!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n"
415 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
417 "<address uri=\"%s\">\n"
418 "<status status=\"inuse\" />\n"
419 "<msnsubstatus substatus=\"onthephone\" />\n"
422 "</presence>", contact_info, atom_id, contact_info);
425 else if (online_status==SalPresenceOuttolunch)
427 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
428 "<!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n"
430 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
432 "<address uri=\"%s\">\n"
433 "<status status=\"inactive\" />\n"
434 "<msnsubstatus substatus=\"outtolunch\" />\n"
437 "</presence>", contact_info, atom_id, contact_info);
442 snprintf(buf, buflen, "<?xml version=\"1.0\"?>\n"
443 "<!DOCTYPE presence SYSTEM \"http://schemas.microsoft.com/2002/09/sip/presence\">\n"
445 "<presentity uri=\"%s;method=SUBSCRIBE\" />\n"
447 "<address uri=\"%s\">\n"
448 "<status status=\"closed\" />\n"
449 "<msnsubstatus substatus=\"offline\" />\n"
452 "</presence>", contact_info, atom_id, contact_info);
456 default: { /* use pidf+xml as default format, rfc4479, rfc4480, rfc3863 */
458 if (online_status==SalPresenceOnline)
460 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
461 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" "
462 "xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" "
463 "xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" "
465 "<tuple id=\"sg89ae\">\n"
466 "<status><basic>open</basic></status>\n"
467 "<contact priority=\"0.8\">%s</contact>\n"
470 contact_info, contact_info);
472 else if (online_status == SalPresenceBusy ||
473 online_status == SalPresenceDonotdisturb)
475 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
476 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" "
477 "xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" "
478 "xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" "
480 "<tuple id=\"sg89ae\">\n"
481 "<status><basic>open</basic></status>\n"
482 "<contact priority=\"0.8\">%s</contact>\n"
484 "<dm:person id=\"sg89aep\">\n"
485 "<rpid:activities><rpid:busy/></rpid:activities>\n"
488 contact_info, contact_info);
490 else if (online_status==SalPresenceBerightback)
492 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
493 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" "
494 "xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" "
495 "xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" "
497 "<tuple id=\"sg89ae\">\n"
498 "<status><basic>open</basic></status>\n"
499 "<contact priority=\"0.8\">%s</contact>\n"
501 "<dm:person id=\"sg89aep\">\n"
502 "<rpid:activities><rpid:in-transit/></rpid:activities>\n"
505 contact_info, contact_info);
507 else if (online_status == SalPresenceAway ||
508 online_status == SalPresenceMoved)
510 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
511 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" "
512 "xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" "
513 "xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" "
515 "<tuple id=\"sg89ae\">\n"
516 "<status><basic>open</basic></status>\n"
517 "<contact priority=\"0.8\">%s</contact>\n"
519 "<dm:person id=\"sg89aep\">\n"
520 "<rpid:activities><rpid:away/></rpid:activities>\n"
523 contact_info, contact_info);
525 else if (online_status==SalPresenceOnthephone)
527 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
528 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" "
529 "xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" "
530 "xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" "
532 "<tuple id=\"sg89ae\">\n"
533 "<status><basic>open</basic></status>\n"
534 "<contact priority=\"0.8\">%s</contact>\n"
536 "<dm:person id=\"sg89aep\">\n"
537 "<rpid:activities><rpid:on-the-phone/></rpid:activities>\n"
540 contact_info, contact_info);
542 else if (online_status==SalPresenceOuttolunch)
544 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
545 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" "
546 "xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" "
547 "xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" "
549 "<tuple id=\"7777\">\n"
550 "<status><basic>open</basic></status>\n"
551 "<contact priority=\"0.8\">%s</contact>\n"
553 "<dm:person id=\"78787878\">\n"
554 "<rpid:activities><rpid:meal/></rpid:activities>\n"
555 "<rpid:note>Out to lunch</rpid:note> \n"
558 contact_info, contact_info);
562 snprintf(buf, buflen, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
563 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" "
564 "xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" "
565 "xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" "
567 "<tuple id=\"sg89ae\">\n"
568 "<status><basic>closed</basic></status>\n"
569 "<contact priority=\"0.8\">%s</contact>\n"
571 "</presence>\n", contact_info, contact_info);
579 static void add_presence_body(osip_message_t *notify, SalPresenceStatus online_status)
584 osip_from_t *from=NULL;
585 from=osip_message_get_from(notify);
586 osip_uri_to_str(from->url,&contact_info);
588 mk_presence_body (online_status, contact_info, buf, sizeof (buf), presence_style);
590 osip_message_set_body(notify, buf, strlen(buf));
591 osip_message_set_content_type(notify,
592 presence_style ? "application/xpidf+xml" : "application/pidf+xml");
594 osip_free(contact_info);
598 int sal_notify_presence(SalOp *op, SalPresenceStatus status, const char *status_message){
599 osip_message_t *msg=NULL;
600 eXosip_ss_t ss=EXOSIP_SUBCRSTATE_ACTIVE;
602 ms_warning("Cannot notify, subscription was closed.");
607 eXosip_insubscription_build_notify(op->did,ss,DEACTIVATED,&msg);
609 const char *identity=sal_op_get_contact(op);
610 if (identity==NULL) identity=sal_op_get_to(op);
611 _osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free);
612 osip_message_set_contact(msg,identity);
613 add_presence_body(msg,status);
614 eXosip_insubscription_send_request(op->did,msg);
615 }else ms_error("could not create notify for incoming subscription.");
620 int sal_notify_close(SalOp *op){
621 osip_message_t *msg=NULL;
623 eXosip_insubscription_build_notify(op->did,EXOSIP_SUBCRSTATE_TERMINATED,DEACTIVATED,&msg);
625 const char *identity=sal_op_get_contact(op);
626 if (identity==NULL) identity=sal_op_get_to(op);
627 osip_message_set_contact(msg,identity);
628 add_presence_body(msg,SalPresenceOffline);
629 eXosip_insubscription_send_request(op->did,msg);
630 }else ms_error("sal_notify_close(): could not create notify for incoming subscription"
631 " did=%i, nid=%i",op->did,op->nid);
636 int sal_publish(SalOp *op, const char *from, const char *to, SalPresenceStatus presence_mode){
640 const char *route=sal_op_get_route(op);
642 mk_presence_body (presence_mode, from, buf, sizeof (buf), presence_style);
644 i = eXosip_build_publish(&pub,to, from, NULL, "presence", "600",
645 presence_style ? "application/xpidf+xml" : "application/pidf+xml", buf);
647 ms_warning("Failed to build publish request.");
651 sal_message_add_route(pub,route);
654 i = eXosip_publish(pub, to); /* should update the sip-if-match parameter
655 from sip-etag from last 200ok of PUBLISH */
658 ms_message("Failed to send publish request.");
661 sal_add_other(sal_op_get_sal(op),op,pub);
665 static void _sal_exosip_subscription_recv(Sal *sal, eXosip_event_t *ev){
666 SalOp *op=sal_op_new(sal);
671 osip_from_to_str(ev->request->from,&tmp);
672 sal_op_set_from(op,tmp);
674 osip_from_to_str(ev->request->to,&tmp);
675 sal_op_set_to(op,tmp);
677 sal_add_in_subscribe(sal,op,ev->request);
678 sal->callbacks.subscribe_received(op,sal_op_get_from(op));
681 void sal_exosip_subscription_recv(Sal *sal, eXosip_event_t *ev){
682 /*workaround a bug in eXosip: incoming SUBSCRIBES within dialog with expires: 0 are
683 recognized as new incoming subscribes*/
684 SalOp *op=sal_find_in_subscribe_by_call_id(sal,ev->request->call_id);
687 osip_message_header_get_byname(ev->request,"expires",0,&h);
688 if (h && h->hvalue && atoi(h->hvalue)==0){
689 ms_warning("This susbscribe is not a new one but terminates an old one.");
692 sal_exosip_subscription_closed(sal,ev);
694 osip_message_t *msg=NULL;
695 ms_warning("Probably a refresh subscribe");
697 eXosip_insubscription_build_answer(ev->tid,202,&msg);
698 eXosip_insubscription_send_answer(ev->tid,202,msg);
701 }else _sal_exosip_subscription_recv(sal,ev);
704 void sal_exosip_notify_recv(Sal *sal, eXosip_event_t *ev){
705 SalOp *op=sal_find_out_subscribe(sal,ev->sid);
707 osip_from_t *from=NULL;
708 osip_body_t *body=NULL;
709 SalPresenceStatus estatus=SalPresenceOffline;
711 ms_message("Receiving notify with sid=%i,nid=%i",ev->sid,ev->nid);
714 ms_error("No operation related to this notify !");
717 if (ev->request==NULL) return;
719 from=ev->request->from;
720 osip_message_get_body(ev->request,0,&body);
722 ms_error("No body in NOTIFY");
725 osip_from_to_str(from,&tmp);
726 if (strstr(body->body,"pending")!=NULL){
727 estatus=SalPresenceOffline;
728 }else if (strstr(body->body,"busy")!=NULL){
729 estatus=SalPresenceBusy;
730 }else if (strstr(body->body,"berightback")!=NULL
731 || strstr(body->body,"in-transit")!=NULL ){
732 estatus=SalPresenceBerightback;
733 }else if (strstr(body->body,"away")!=NULL
734 || strstr(body->body,"idle")){
735 estatus=SalPresenceAway;
736 }else if (strstr(body->body,"onthephone")!=NULL
737 || strstr(body->body,"on-the-phone")!=NULL){
738 estatus=SalPresenceOnthephone;
739 }else if (strstr(body->body,"outtolunch")!=NULL
740 || strstr(body->body,"meal")!=NULL){
741 estatus=SalPresenceOuttolunch;
742 }else if (strstr(body->body,"closed")!=NULL){
743 estatus=SalPresenceOffline;
744 }else if ((strstr(body->body,"online")!=NULL) || (strstr(body->body,"open")!=NULL)) {
745 estatus=SalPresenceOnline;
747 estatus=SalPresenceOffline;
749 ms_message("We are notified that %s has online status %i",tmp,estatus);
750 if (ev->ss_status==EXOSIP_SUBCRSTATE_TERMINATED) {
751 sal_remove_out_subscribe(sal,op);
754 ms_message("And outgoing subscription terminated by remote.");
756 sal->callbacks.notify_presence(op,op->sid!=-1 ? SalSubscribeActive : SalSubscribeTerminated, estatus,NULL);
758 /* try to detect presence message style used by server,
759 * and switch our presence messages to servers style */
760 if (strstr (body->body, "//IETF//DTD RFCxxxx XPIDF 1.0//EN") != NULL) {
761 presence_style = RFCxxxx;
762 } else if (strstr(body->body,"http://schemas.microsoft.com/2002/09/sip/presence")!=NULL) {
763 presence_style = MSOLDPRES;
769 void sal_exosip_subscription_answered(Sal *sal,eXosip_event_t *ev){
770 SalOp *op=sal_find_out_subscribe(sal,ev->sid);
772 ms_error("Subscription answered but no associated op !");
778 void sal_exosip_in_subscription_closed(Sal *sal, eXosip_event_t *ev){
779 SalOp *op=sal_find_in_subscribe(sal,ev->nid);
782 ms_error("Incoming subscription closed but no associated op !");
787 sal_remove_in_subscribe(sal,op);
791 osip_from_to_str(ev->request->from,&tmp);
792 sal->callbacks.subscribe_closed(op,tmp);
797 void sal_exosip_subscription_closed(Sal *sal,eXosip_event_t *ev){
798 SalOp *op=sal_find_out_subscribe(sal,ev->sid);
800 ms_error("Subscription closed but no associated op !");
803 sal_remove_out_subscribe(sal,op);
806 sal->callbacks.notify_presence(op,SalSubscribeTerminated, SalPresenceOffline,NULL);