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;
398 SalMediaDescription *old_md=call->resultdesc;
400 sal_media_description_ref(old_md);
402 md=sal_call_get_final_media_description(op);
404 /*accept the modification (sends a 200Ok)*/
407 if (md && !sal_media_description_empty(md))
409 linphone_core_update_streams (lc,call,md);
411 if (sal_media_description_has_dir(call->localdesc,SalStreamSendRecv)){
412 ms_message("Our local status is SalStreamSendRecv");
413 if (sal_media_description_has_dir (md,SalStreamRecvOnly) || sal_media_description_has_dir(md,SalStreamInactive)){
414 /* we are being paused */
415 if(lc->vtable.display_status)
416 lc->vtable.display_status(lc,_("We are being paused..."));
417 linphone_call_set_state (call,LinphoneCallPausedByRemote,"Call paused by remote");
418 }else if (!sal_media_description_has_dir(old_md,SalStreamSendRecv) && sal_media_description_has_dir(md,SalStreamSendRecv)){
419 if(lc->vtable.display_status)
420 lc->vtable.display_status(lc,_("We have been resumed..."));
421 linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)");
423 prevstate=call->state;
424 if(lc->vtable.display_status)
425 lc->vtable.display_status(lc,_("Call has been updated by remote..."));
426 linphone_call_set_state(call, LinphoneCallUpdatedByRemote,"Call updated by remote");
430 if (prevstate!=LinphoneCallIdle){
431 linphone_call_set_state (call,prevstate,"Connected (streams running)");
434 sal_media_description_unref(old_md);
437 static void call_terminated(SalOp *op, const char *from){
438 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
439 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
441 if (call==NULL) return;
443 if (linphone_call_get_state(call)==LinphoneCallEnd || linphone_call_get_state(call)==LinphoneCallError){
444 ms_warning("call_terminated: ignoring.");
447 ms_message("Current call terminated...");
448 //we stop the call only if we have this current call or if we are in call
449 if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls) == 1) || linphone_core_in_call(lc) )) {
450 ring_stop(lc->ringstream);
453 linphone_call_stop_media_streams(call);
454 if (lc->vtable.show!=NULL)
456 if (lc->vtable.display_status!=NULL)
457 lc->vtable.display_status(lc,_("Call terminated."));
459 linphone_call_set_state(call, LinphoneCallEnd,"Call ended");
462 static void call_failure(SalOp *op, SalError error, SalReason sr, const char *details, int code){
463 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
464 char *msg486=_("User is busy.");
465 char *msg480=_("User is temporarily unavailable.");
466 /*char *retrymsg=_("%s. Retry after %i minute(s).");*/
467 char *msg600=_("User does not want to be disturbed.");
468 char *msg603=_("Call declined.");
469 const char *msg=details;
470 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
473 ms_warning("Call faillure reported on already cleaned call ?");
477 if (lc->vtable.show) lc->vtable.show(lc);
479 if (error==SalErrorNoResponse){
480 msg=_("No response.");
481 if (lc->vtable.display_status)
482 lc->vtable.display_status(lc,msg);
483 }else if (error==SalErrorProtocol){
484 msg=details ? details : _("Protocol error.");
485 if (lc->vtable.display_status)
486 lc->vtable.display_status(lc, msg);
487 }else if (error==SalErrorFailure){
489 case SalReasonDeclined:
491 if (lc->vtable.display_status)
492 lc->vtable.display_status(lc,msg603);
496 if (lc->vtable.display_status)
497 lc->vtable.display_status(lc,msg486);
499 case SalReasonRedirect:
501 if (lc->vtable.display_status)
502 lc->vtable.display_status(lc,msg);
504 case SalReasonTemporarilyUnavailable:
506 if (lc->vtable.display_status)
507 lc->vtable.display_status(lc,msg480);
509 case SalReasonNotFound:
511 if (lc->vtable.display_status)
512 lc->vtable.display_status(lc,msg);
514 case SalReasonDoNotDisturb:
516 if (lc->vtable.display_status)
517 lc->vtable.display_status(lc,msg600);
520 msg=_("No common codecs");
521 if (lc->vtable.display_status)
522 lc->vtable.display_status(lc,msg);
525 if (lc->vtable.display_status)
526 lc->vtable.display_status(lc,_("Call failed."));
530 if (lc->ringstream!=NULL) {
531 ring_stop(lc->ringstream);
534 linphone_call_stop_media_streams (call);
535 if (sr!=SalReasonDeclined) linphone_call_set_state(call,LinphoneCallError,msg);
537 call->reason=LinphoneReasonDeclined;
538 linphone_call_set_state(call,LinphoneCallEnd,"Call declined.");
542 static void call_released(SalOp *op){
543 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
545 linphone_call_set_state(call,LinphoneCallReleased,"Call released");
546 }else ms_error("call_released() for already destroyed call ?");
549 static void auth_requested(SalOp *h, const char *realm, const char *username){
550 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
551 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
552 ms_message("auth_requested() for realm=%s, username=%s",realm,username);
554 if (ai && ai->works==FALSE && ai->usecount>=3){
555 /*case we tried 3 times to authenticate, without success */
556 /*Better is to stop (implemeted below in else statement), and retry later*/
557 if (ms_time(NULL)-ai->last_use_time>30){
558 ai->usecount=0; /*so that we can allow to retry */
562 if (ai && (ai->works || ai->usecount<3)){
564 sai.username=ai->username;
565 sai.userid=ai->userid;
567 sai.password=ai->passwd;
568 ms_message("auth_requested(): authenticating realm=%s, username=%s",realm,username);
569 sal_op_authenticate(h,&sai);
571 ai->last_use_time=ms_time(NULL);
573 if (ai && ai->works==FALSE) {
574 sal_op_cancel_authentication(h);
576 if (lc->vtable.auth_info_requested)
577 lc->vtable.auth_info_requested(lc,realm,username);
581 static void auth_success(SalOp *h, const char *realm, const char *username){
582 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
583 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
585 ms_message("%s/%s authentication works.",realm,username);
590 static void register_success(SalOp *op, bool_t registered){
591 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
592 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
595 cfg->registered=registered;
596 linphone_proxy_config_set_error(cfg,LinphoneReasonNone);
597 linphone_proxy_config_set_state(cfg, registered ? LinphoneRegistrationOk : LinphoneRegistrationCleared ,
598 registered ? "Registration sucessful" : "Unregistration done");
599 if (lc->vtable.display_status){
600 if (cfg->registered) msg=ms_strdup_printf(_("Registration on %s successful."),sal_op_get_proxy(op));
601 else msg=ms_strdup_printf(_("Unregistration on %s done."),sal_op_get_proxy(op));
602 lc->vtable.display_status(lc,msg);
608 static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details){
609 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
610 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
613 ms_warning("Registration failed for unknown proxy config.");
617 details=_("no response timeout");
619 if (lc->vtable.display_status) {
620 char *msg=ortp_strdup_printf(_("Registration on %s failed: %s"),sal_op_get_proxy(op),details );
621 lc->vtable.display_status(lc,msg);
624 if (error== SalErrorFailure && reason == SalReasonForbidden) {
625 linphone_proxy_config_set_error(cfg, LinphoneReasonBadCredentials);
626 } else if (error == SalErrorNoResponse) {
627 linphone_proxy_config_set_error(cfg, LinphoneReasonNoResponse);
629 linphone_proxy_config_set_state(cfg,LinphoneRegistrationFailed,details);
630 if (error== SalErrorFailure && reason == SalReasonForbidden) {
631 const char *realm=NULL,*username=NULL;
632 if (sal_op_get_auth_requested(op,&realm,&username)==0){
633 if (lc->vtable.auth_info_requested)
634 lc->vtable.auth_info_requested(lc,realm,username);
639 static void vfu_request(SalOp *op){
641 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
643 ms_warning("VFU request but no call !");
646 if (call->videostream)
647 video_stream_send_vfu(call->videostream);
651 static void dtmf_received(SalOp *op, char dtmf){
652 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
653 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
654 if (lc->vtable.dtmf_received != NULL)
655 lc->vtable.dtmf_received(lc, call, dtmf);
658 static void refer_received(Sal *sal, SalOp *op, const char *referto){
659 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
660 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
662 if (call->refer_to!=NULL){
663 ms_free(call->refer_to);
665 call->refer_to=ms_strdup(referto);
666 call->refer_pending=TRUE;
667 linphone_call_set_state(call,LinphoneCallRefered,"Refered");
668 if (lc->vtable.display_status){
669 char *msg=ms_strdup_printf(_("We are transferred to %s"),referto);
670 lc->vtable.display_status(lc,msg);
673 if (call->state!=LinphoneCallPaused){
674 ms_message("Automatically pausing current call to accept transfer.");
675 linphone_core_pause_call(lc,call);
677 linphone_core_start_refered_call(lc,call);
678 sal_call_accept_refer(op);
679 }else if (lc->vtable.refer_received){
680 lc->vtable.refer_received(lc,referto);
681 sal_call_accept_refer(op);
685 static void text_received(Sal *sal, const char *from, const char *msg){
686 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
687 linphone_core_text_received(lc,from,msg);
690 static void notify(SalOp *op, const char *from, const char *msg){
691 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
692 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
693 ms_message("get a %s notify from %s",msg,from);
694 if(lc->vtable.notify_recv)
695 lc->vtable.notify_recv(lc,call,from,msg);
698 static void notify_presence(SalOp *op, SalSubscribeState ss, SalPresenceStatus status, const char *msg){
699 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
700 linphone_notify_recv(lc,op,ss,status);
703 static void subscribe_received(SalOp *op, const char *from){
704 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
705 linphone_subscription_new(lc,op,from);
708 static void subscribe_closed(SalOp *op, const char *from){
709 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
710 linphone_subscription_closed(lc,op);
713 static void ping_reply(SalOp *op){
714 LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
715 ms_message("ping reply !");
717 if (call->state==LinphoneCallOutgoingInit){
718 linphone_core_start_invite(call->core,call,NULL);
723 ms_warning("ping reply without call attached...");
727 SalCallbacks linphone_sal_callbacks={