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.
23 #include "linphonecore.h"
25 #include "mediastreamer2/mediastream.h"
28 static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details);
30 static bool_t media_parameters_changed(LinphoneCall *call, SalMediaDescription *oldmd, SalMediaDescription *newmd){
31 if (call->params.in_conference!=call->current_params.in_conference) return TRUE;
32 return !sal_media_description_equals(oldmd,newmd) || call->up_bw!=linphone_core_get_upload_bandwidth(call->core);
35 void linphone_core_update_streams(LinphoneCore *lc, LinphoneCall *call, SalMediaDescription *new_md){
36 SalMediaDescription *oldmd=call->resultdesc;
38 if (lc->ringstream!=NULL){
39 ring_stop(lc->ringstream);
43 sal_media_description_ref(new_md);
44 call->media_pending=FALSE;
46 call->media_pending=TRUE;
48 call->resultdesc=new_md;
49 if (call->audiostream && call->audiostream->ticker){
50 /* we already started media: check if we really need to restart it*/
52 if (!media_parameters_changed(call,oldmd,new_md) && !call->playing_ringbacktone){
53 /*as nothing has changed, keep the oldmd */
54 call->resultdesc=oldmd;
55 sal_media_description_unref(new_md);
57 ms_message("Early media finished, unmuting inputs...");
58 /*we were in early media, now we want to enable real media */
59 linphone_call_enable_camera (call,linphone_call_camera_enabled (call));
60 if (call->audiostream)
61 linphone_core_mute_mic (lc, linphone_core_is_mic_muted(lc));
63 if (call->videostream && call->camera_active)
64 video_stream_change_camera(call->videostream,lc->video_conf.device );
67 ms_message("No need to restart streams, SDP is unchanged.");
70 ms_message("Media descriptions are different, need to restart the streams.");
73 linphone_call_stop_media_streams (call);
74 linphone_call_init_media_streams (call);
77 sal_media_description_unref(oldmd);
80 bool_t all_muted=FALSE;
81 bool_t send_ringbacktone=FALSE;
83 if (call->audiostream==NULL){
84 /*this happens after pausing the call locally. The streams is destroyed and then we wait the 200Ok to recreate it*/
85 linphone_call_init_media_streams (call);
87 if (call->state==LinphoneCallIncomingEarlyMedia && linphone_core_get_remote_ringback_tone (lc)!=NULL){
88 send_ringbacktone=TRUE;
90 if (call->state==LinphoneCallIncomingEarlyMedia ||
91 (call->state==LinphoneCallOutgoingEarlyMedia && !call->params.real_early_media)){
94 linphone_call_start_media_streams(call,all_muted,send_ringbacktone);
98 static bool_t is_duplicate_call(LinphoneCore *lc, const LinphoneAddress *from, const LinphoneAddress *to){
100 for(elem=lc->calls;elem!=NULL;elem=elem->next){
101 LinphoneCall *call=(LinphoneCall*)elem->data;
102 if (linphone_address_weak_equal(call->log->from,from) &&
103 linphone_address_weak_equal(call->log->to, to)){
111 static bool_t already_a_call_pending(LinphoneCore *lc){
113 for(elem=lc->calls;elem!=NULL;elem=elem->next){
114 LinphoneCall *call=(LinphoneCall*)elem->data;
115 if (call->state==LinphoneCallIncomingReceived
116 || call->state==LinphoneCallOutgoingInit
117 || call->state==LinphoneCallOutgoingProgress
118 || call->state==LinphoneCallOutgoingEarlyMedia
119 || call->state==LinphoneCallOutgoingRinging){
126 static void call_received(SalOp *h){
127 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
130 const char *from,*to;
132 LinphoneAddress *from_parsed;
133 LinphoneAddress *from_addr, *to_addr;
134 SalMediaDescription *md;
135 bool_t propose_early_media=lp_config_get_int(lc->config,"sip","incoming_calls_early_media",FALSE);
136 const char *ringback_tone=linphone_core_get_remote_ringback_tone (lc);
138 /* first check if we can answer successfully to this invite */
139 if (lc->presence_mode==LinphoneStatusBusy ||
140 lc->presence_mode==LinphoneStatusOffline ||
141 lc->presence_mode==LinphoneStatusDoNotDisturb ||
142 lc->presence_mode==LinphoneStatusMoved){
143 if (lc->presence_mode==LinphoneStatusBusy )
144 sal_call_decline(h,SalReasonBusy,NULL);
145 else if (lc->presence_mode==LinphoneStatusOffline)
146 sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
147 else if (lc->presence_mode==LinphoneStatusDoNotDisturb)
148 sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
149 else if (lc->alt_contact!=NULL && lc->presence_mode==LinphoneStatusMoved)
150 sal_call_decline(h,SalReasonRedirect,lc->alt_contact);
154 if (!linphone_core_can_we_add_call(lc)){/*busy*/
155 sal_call_decline(h,SalReasonBusy,NULL);
159 from=sal_op_get_from(h);
161 from_addr=linphone_address_new(from);
162 to_addr=linphone_address_new(to);
164 if (already_a_call_pending(lc)){
165 ms_warning("Receiving another call while one is ringing or initiated, refusing this one with busy message.");
166 sal_call_decline(h,SalReasonBusy,NULL);
168 linphone_address_destroy(from_addr);
169 linphone_address_destroy(to_addr);
173 call=linphone_call_new_incoming(lc,from_addr,to_addr,h);
174 sal_call_set_local_media_description(h,call->localdesc);
175 md=sal_call_get_final_media_description(h);
177 if (md && sal_media_description_empty(md)){
178 sal_call_decline(h,SalReasonMedia,NULL);
179 linphone_call_unref(call);
183 /* the call is acceptable so we can now add it to our list */
184 linphone_core_add_call(lc,call);
186 from_parsed=linphone_address_new(sal_op_get_from(h));
187 linphone_address_clean(from_parsed);
188 tmp=linphone_address_as_string(from_parsed);
189 linphone_address_destroy(from_parsed);
190 barmesg=ortp_strdup_printf("%s %s%s",tmp,_("is contacting you"),
191 (sal_call_autoanswer_asked(h)) ?_(" and asked autoanswer."):_("."));
192 if (lc->vtable.show) lc->vtable.show(lc);
193 if (lc->vtable.display_status)
194 lc->vtable.display_status(lc,barmesg);
196 /* play the ring if this is the only call*/
197 if (ms_list_size(lc->calls)==1){
198 lc->current_call=call;
199 if (lc->ringstream && lc->dmfs_playing_start_time!=0){
200 ring_stop(lc->ringstream);
202 lc->dmfs_playing_start_time=0;
204 if (lc->sound_conf.ring_sndcard!=NULL){
205 if(lc->ringstream==NULL && lc->sound_conf.local_ring){
206 MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
207 ms_message("Starting local ring...");
208 lc->ringstream=ring_start(lc->sound_conf.local_ring,2000,ringcard);
212 ms_message("the local ring is already started");
216 /* else play a tone within the context of the current call */
217 call->ringing_beep=TRUE;
218 linphone_core_play_tone(lc);
222 linphone_call_ref(call); /*prevent the call from being destroyed while we are notifying, if the user declines within the state callback */
223 linphone_call_set_state(call,LinphoneCallIncomingReceived,"Incoming call");
225 if (call->state==LinphoneCallIncomingReceived){
226 sal_call_notify_ringing(h,propose_early_media || ringback_tone!=NULL);
228 if (propose_early_media || ringback_tone!=NULL){
229 linphone_call_set_state(call,LinphoneCallIncomingEarlyMedia,"Incoming call early media");
230 linphone_core_update_streams(lc,call,md);
232 if (sal_call_get_replaces(call->op)!=NULL && lp_config_get_int(lc->config,"sip","auto_answer_replacing_calls",1)){
233 linphone_core_accept_call(lc,call);
236 linphone_call_unref(call);
242 static void call_ringing(SalOp *h){
243 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
244 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(h);
245 SalMediaDescription *md;
247 if (call==NULL) return;
249 if (lc->vtable.display_status)
250 lc->vtable.display_status(lc,_("Remote ringing."));
252 md=sal_call_get_final_media_description(h);
254 if (lc->ringstream && lc->dmfs_playing_start_time!=0){
255 ring_stop(lc->ringstream);
257 lc->dmfs_playing_start_time=0;
259 if (lc->ringstream!=NULL) return; /*already ringing !*/
260 if (lc->sound_conf.play_sndcard!=NULL){
261 MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
262 lc->ringstream=ring_start(lc->sound_conf.remote_ring,2000,ringcard);
264 ms_message("Remote ringing...");
265 if (lc->vtable.display_status)
266 lc->vtable.display_status(lc,_("Remote ringing..."));
267 linphone_call_set_state(call,LinphoneCallOutgoingRinging,"Remote ringing");
269 /*accept early media */
270 if (call->audiostream && call->audiostream->ticker!=NULL){
271 /*streams already started */
272 ms_message("Early media already started.");
275 if (lc->vtable.show) lc->vtable.show(lc);
276 if (lc->vtable.display_status)
277 lc->vtable.display_status(lc,_("Early media."));
278 linphone_call_set_state(call,LinphoneCallOutgoingEarlyMedia,"Early media");
279 if (lc->ringstream!=NULL){
280 ring_stop(lc->ringstream);
283 ms_message("Doing early media...");
284 linphone_core_update_streams (lc,call,md);
290 * - when the call is accepted
291 * - when a request is accepted (pause, resume)
293 static void call_accepted(SalOp *op){
294 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
295 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
296 SalMediaDescription *md;
299 ms_warning("No call to accept.");
303 md=sal_call_get_final_media_description(op);
305 if (call->state==LinphoneCallOutgoingProgress ||
306 call->state==LinphoneCallOutgoingRinging ||
307 call->state==LinphoneCallOutgoingEarlyMedia){
308 linphone_call_set_state(call,LinphoneCallConnected,"Connected");
310 if (md && !sal_media_description_empty(md)){
311 if (sal_media_description_has_dir(md,SalStreamSendOnly) ||
312 sal_media_description_has_dir(md,SalStreamInactive)){
313 if (lc->vtable.display_status){
314 char *tmp=linphone_call_get_remote_address_as_string (call);
315 char *msg=ms_strdup_printf(_("Call with %s is paused."),tmp);
316 lc->vtable.display_status(lc,msg);
320 linphone_core_update_streams (lc,call,md);
321 linphone_call_set_state(call,LinphoneCallPaused,"Call paused");
322 }else if (sal_media_description_has_dir(md,SalStreamRecvOnly)){
323 /*we are put on hold when the call is initially accepted */
324 if (lc->vtable.display_status){
325 char *tmp=linphone_call_get_remote_address_as_string (call);
326 char *msg=ms_strdup_printf(_("Call answered by %s - on hold."),tmp);
327 lc->vtable.display_status(lc,msg);
331 linphone_core_update_streams (lc,call,md);
332 linphone_call_set_state(call,LinphoneCallPausedByRemote,"Call paused by remote");
334 if (call->state==LinphoneCallStreamsRunning){
335 /*media was running before, the remote as acceted a call modification (that is
336 a reinvite made by us. We must notify the application this reinvite was accepted*/
337 linphone_call_set_state(call, LinphoneCallUpdated, "Call updated");
339 if (call->state==LinphoneCallResuming){
340 if (lc->vtable.display_status){
341 lc->vtable.display_status(lc,_("Call resumed."));
344 if (lc->vtable.display_status){
345 char *tmp=linphone_call_get_remote_address_as_string (call);
346 char *msg=ms_strdup_printf(_("Call answered by %s."),tmp);
347 lc->vtable.display_status(lc,msg);
353 linphone_core_update_streams (lc,call,md);
354 linphone_call_set_state(call, LinphoneCallStreamsRunning, "Streams running");
355 if (!call->current_params.in_conference)
356 lc->current_call=call;
360 ms_error("Incompatible SDP offer received in 200Ok, need to abort the call");
361 linphone_core_abort_call(lc,call,"No codec intersection");
365 static void call_ack(SalOp *op){
366 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
367 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
369 ms_warning("No call to be ACK'd");
372 if (call->media_pending){
373 SalMediaDescription *md=sal_call_get_final_media_description(op);
374 if (md && !sal_media_description_empty(md)){
375 if (call->state==LinphoneCallStreamsRunning){
376 /*media was running before, the remote as acceted a call modification (that is
377 a reinvite made by us. We must notify the application this reinvite was accepted*/
378 linphone_call_set_state(call, LinphoneCallUpdated, "Call updated");
380 linphone_core_update_streams (lc,call,md);
381 linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)");
384 ms_error("Incompatible SDP response received in ACK, need to abort the call");
385 linphone_core_abort_call(lc,call,"No codec intersection");
392 /* this callback is called when an incoming re-INVITE modifies the session*/
393 static void call_updating(SalOp *op){
394 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
395 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
396 LinphoneCallState prevstate=LinphoneCallIdle;
397 SalMediaDescription *md;
399 md=sal_call_get_final_media_description(op);
401 if (md && !sal_media_description_empty(md))
403 if (sal_media_description_has_dir(call->localdesc,SalStreamSendRecv)){
404 ms_message("Our local status is SalStreamSendRecv");
405 if (sal_media_description_has_dir (md,SalStreamRecvOnly) || sal_media_description_has_dir(md,SalStreamInactive)){
406 /* we are being paused */
407 if(lc->vtable.display_status)
408 lc->vtable.display_status(lc,_("We are being paused..."));
409 linphone_call_set_state (call,LinphoneCallPausedByRemote,"Call paused by remote");
410 }else if (!sal_media_description_has_dir(call->resultdesc,SalStreamSendRecv) && sal_media_description_has_dir(md,SalStreamSendRecv)){
411 if(lc->vtable.display_status)
412 lc->vtable.display_status(lc,_("We have been resumed..."));
413 linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)");
414 if (!call->current_params.in_conference)
415 lc->current_call=call;
417 prevstate=call->state;
418 linphone_call_set_state(call, LinphoneCallUpdatedByRemote,"Call updated by remote");
421 /*accept the modification (sends a 200Ok)*/
423 linphone_core_update_streams (lc,call,md);
424 if (prevstate!=LinphoneCallIdle){
425 linphone_call_set_state (call,prevstate,"Connected (streams running)");
430 static void call_terminated(SalOp *op, const char *from){
431 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
432 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
434 if (call==NULL) return;
436 if (linphone_call_get_state(call)==LinphoneCallEnd || linphone_call_get_state(call)==LinphoneCallError){
437 ms_warning("call_terminated: ignoring.");
440 ms_message("Current call terminated...");
441 //we stop the call only if we have this current call or if we are in call
442 if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls) == 1) || linphone_core_in_call(lc) )) {
443 ring_stop(lc->ringstream);
446 linphone_call_stop_media_streams(call);
447 if (lc->vtable.show!=NULL)
449 if (lc->vtable.display_status!=NULL)
450 lc->vtable.display_status(lc,_("Call terminated."));
452 linphone_call_set_state(call, LinphoneCallEnd,"Call ended");
455 static void call_failure(SalOp *op, SalError error, SalReason sr, const char *details, int code){
456 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
457 char *msg486=_("User is busy.");
458 char *msg480=_("User is temporarily unavailable.");
459 /*char *retrymsg=_("%s. Retry after %i minute(s).");*/
460 char *msg600=_("User does not want to be disturbed.");
461 char *msg603=_("Call declined.");
462 const char *msg=details;
463 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
466 ms_warning("Call faillure reported on already cleaned call ?");
470 if (lc->vtable.show) lc->vtable.show(lc);
472 if (error==SalErrorNoResponse){
473 msg=_("No response.");
474 if (lc->vtable.display_status)
475 lc->vtable.display_status(lc,msg);
476 }else if (error==SalErrorProtocol){
477 msg=details ? details : _("Protocol error.");
478 if (lc->vtable.display_status)
479 lc->vtable.display_status(lc, msg);
480 }else if (error==SalErrorFailure){
482 case SalReasonDeclined:
484 if (lc->vtable.display_status)
485 lc->vtable.display_status(lc,msg603);
489 if (lc->vtable.display_status)
490 lc->vtable.display_status(lc,msg486);
492 case SalReasonRedirect:
494 if (lc->vtable.display_status)
495 lc->vtable.display_status(lc,msg);
497 case SalReasonTemporarilyUnavailable:
499 if (lc->vtable.display_status)
500 lc->vtable.display_status(lc,msg480);
502 case SalReasonNotFound:
504 if (lc->vtable.display_status)
505 lc->vtable.display_status(lc,msg);
507 case SalReasonDoNotDisturb:
509 if (lc->vtable.display_status)
510 lc->vtable.display_status(lc,msg600);
513 msg=_("No common codecs");
514 if (lc->vtable.display_status)
515 lc->vtable.display_status(lc,msg);
518 if (lc->vtable.display_status)
519 lc->vtable.display_status(lc,_("Call failed."));
523 if (lc->ringstream!=NULL) {
524 ring_stop(lc->ringstream);
527 linphone_call_stop_media_streams (call);
528 if (sr!=SalReasonDeclined) linphone_call_set_state(call,LinphoneCallError,msg);
530 call->reason=LinphoneReasonDeclined;
531 linphone_call_set_state(call,LinphoneCallEnd,"Call declined.");
535 static void call_released(SalOp *op){
536 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
538 linphone_call_set_state(call,LinphoneCallReleased,"Call released");
539 }else ms_error("call_released() for already destroyed call ?");
542 static void auth_requested(SalOp *h, const char *realm, const char *username){
543 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
544 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
545 ms_message("auth_requested() for realm=%s, username=%s",realm,username);
547 if (ai && ai->works==FALSE && ai->usecount>=3){
548 /*case we tried 3 times to authenticate, without success */
549 /*Better is to stop (implemeted below in else statement), and retry later*/
550 if (ms_time(NULL)-ai->last_use_time>30){
551 ai->usecount=0; /*so that we can allow to retry */
555 if (ai && (ai->works || ai->usecount<3)){
557 sai.username=ai->username;
558 sai.userid=ai->userid;
560 sai.password=ai->passwd;
561 ms_message("auth_requested(): authenticating realm=%s, username=%s",realm,username);
562 sal_op_authenticate(h,&sai);
564 ai->last_use_time=ms_time(NULL);
566 if (ai && ai->works==FALSE) {
567 sal_op_cancel_authentication(h);
569 if (lc->vtable.auth_info_requested)
570 lc->vtable.auth_info_requested(lc,realm,username);
574 static void auth_success(SalOp *h, const char *realm, const char *username){
575 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
576 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
578 ms_message("%s/%s authentication works.",realm,username);
583 static void register_success(SalOp *op, bool_t registered){
584 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
585 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
588 cfg->registered=registered;
589 linphone_proxy_config_set_error(cfg,LinphoneReasonNone);
590 linphone_proxy_config_set_state(cfg, registered ? LinphoneRegistrationOk : LinphoneRegistrationCleared ,
591 registered ? "Registration sucessful" : "Unregistration done");
592 if (lc->vtable.display_status){
593 if (cfg->registered) msg=ms_strdup_printf(_("Registration on %s successful."),sal_op_get_proxy(op));
594 else msg=ms_strdup_printf(_("Unregistration on %s done."),sal_op_get_proxy(op));
595 lc->vtable.display_status(lc,msg);
601 static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details){
602 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
603 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
606 ms_warning("Registration failed for unknown proxy config.");
610 details=_("no response timeout");
612 if (lc->vtable.display_status) {
613 char *msg=ortp_strdup_printf(_("Registration on %s failed: %s"),sal_op_get_proxy(op),details );
614 lc->vtable.display_status(lc,msg);
617 if (error== SalErrorFailure && reason == SalReasonForbidden) {
618 linphone_proxy_config_set_error(cfg, LinphoneReasonBadCredentials);
619 } else if (error == SalErrorNoResponse) {
620 linphone_proxy_config_set_error(cfg, LinphoneReasonNoResponse);
622 linphone_proxy_config_set_state(cfg,LinphoneRegistrationFailed,details);
623 if (error== SalErrorFailure && reason == SalReasonForbidden) {
624 const char *realm=NULL,*username=NULL;
625 if (sal_op_get_auth_requested(op,&realm,&username)==0){
626 if (lc->vtable.auth_info_requested)
627 lc->vtable.auth_info_requested(lc,realm,username);
632 static void vfu_request(SalOp *op){
634 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
636 ms_warning("VFU request but no call !");
639 if (call->videostream)
640 video_stream_send_vfu(call->videostream);
644 static void dtmf_received(SalOp *op, char dtmf){
645 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
646 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
647 if (lc->vtable.dtmf_received != NULL)
648 lc->vtable.dtmf_received(lc, call, dtmf);
651 static void refer_received(Sal *sal, SalOp *op, const char *referto){
652 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
653 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
655 if (call->refer_to!=NULL){
656 ms_free(call->refer_to);
658 call->refer_to=ms_strdup(referto);
659 call->refer_pending=TRUE;
660 linphone_call_set_state(call,LinphoneCallRefered,"Refered");
661 if (lc->vtable.display_status){
662 char *msg=ms_strdup_printf(_("We are transferred to %s"),referto);
663 lc->vtable.display_status(lc,msg);
666 if (call->state!=LinphoneCallPaused){
667 ms_message("Automatically pausing current call to accept transfer.");
668 linphone_core_pause_call(lc,call);
670 linphone_core_start_refered_call(lc,call);
671 sal_call_accept_refer(op);
672 }else if (lc->vtable.refer_received){
673 lc->vtable.refer_received(lc,referto);
674 sal_call_accept_refer(op);
678 static void text_received(Sal *sal, const char *from, const char *msg){
679 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
680 linphone_core_text_received(lc,from,msg);
683 static void notify(SalOp *op, const char *from, const char *msg){
684 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
685 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
686 ms_message("get a %s notify from %s",msg,from);
687 if(lc->vtable.notify_recv)
688 lc->vtable.notify_recv(lc,call,from,msg);
691 static void notify_presence(SalOp *op, SalSubscribeState ss, SalPresenceStatus status, const char *msg){
692 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
693 linphone_notify_recv(lc,op,ss,status);
696 static void subscribe_received(SalOp *op, const char *from){
697 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
698 linphone_subscription_new(lc,op,from);
701 static void subscribe_closed(SalOp *op, const char *from){
702 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
703 linphone_subscription_closed(lc,op);
706 static void ping_reply(SalOp *op){
707 LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
708 ms_message("ping reply !");
710 if (call->state==LinphoneCallOutgoingInit){
711 linphone_core_start_invite(call->core,call,NULL);
716 ms_warning("ping reply without call attached...");
720 SalCallbacks linphone_sal_callbacks={