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)){
110 static void call_received(SalOp *h){
111 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
114 const char *from,*to;
116 LinphoneAddress *from_parsed;
117 LinphoneAddress *from_addr, *to_addr;
118 SalMediaDescription *md;
119 bool_t propose_early_media=lp_config_get_int(lc->config,"sip","incoming_calls_early_media",FALSE);
120 const char *ringback_tone=linphone_core_get_remote_ringback_tone (lc);
122 /* first check if we can answer successfully to this invite */
123 if (lc->presence_mode==LinphoneStatusBusy ||
124 lc->presence_mode==LinphoneStatusOffline ||
125 lc->presence_mode==LinphoneStatusDoNotDisturb ||
126 lc->presence_mode==LinphoneStatusMoved){
127 if (lc->presence_mode==LinphoneStatusBusy )
128 sal_call_decline(h,SalReasonBusy,NULL);
129 else if (lc->presence_mode==LinphoneStatusOffline)
130 sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
131 else if (lc->presence_mode==LinphoneStatusDoNotDisturb)
132 sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
133 else if (lc->alt_contact!=NULL && lc->presence_mode==LinphoneStatusMoved)
134 sal_call_decline(h,SalReasonRedirect,lc->alt_contact);
138 if (!linphone_core_can_we_add_call(lc)){/*busy*/
139 sal_call_decline(h,SalReasonBusy,NULL);
143 from=sal_op_get_from(h);
145 from_addr=linphone_address_new(from);
146 to_addr=linphone_address_new(to);
148 if (is_duplicate_call(lc,from_addr,to_addr)){
149 ms_warning("Receiving duplicated call, refusing this one.");
150 sal_call_decline(h,SalReasonBusy,NULL);
152 linphone_address_destroy(from_addr);
153 linphone_address_destroy(to_addr);
157 call=linphone_call_new_incoming(lc,from_addr,to_addr,h);
158 sal_call_set_local_media_description(h,call->localdesc);
159 md=sal_call_get_final_media_description(h);
161 if (md && sal_media_description_empty(md)){
162 sal_call_decline(h,SalReasonMedia,NULL);
163 linphone_call_unref(call);
167 /* the call is acceptable so we can now add it to our list */
168 linphone_core_add_call(lc,call);
170 from_parsed=linphone_address_new(sal_op_get_from(h));
171 linphone_address_clean(from_parsed);
172 tmp=linphone_address_as_string(from_parsed);
173 linphone_address_destroy(from_parsed);
174 barmesg=ortp_strdup_printf("%s %s%s",tmp,_("is contacting you"),
175 (sal_call_autoanswer_asked(h)) ?_(" and asked autoanswer."):_("."));
176 if (lc->vtable.show) lc->vtable.show(lc);
177 if (lc->vtable.display_status)
178 lc->vtable.display_status(lc,barmesg);
180 /* play the ring if this is the only call*/
181 if (lc->sound_conf.ring_sndcard!=NULL && ms_list_size(lc->calls)==1){
182 lc->current_call=call;
183 if (lc->ringstream && lc->dmfs_playing_start_time!=0){
184 ring_stop(lc->ringstream);
186 lc->dmfs_playing_start_time=0;
188 if(lc->ringstream==NULL && lc->sound_conf.local_ring){
189 MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
190 ms_message("Starting local ring...");
191 lc->ringstream=ring_start(lc->sound_conf.local_ring,2000,ringcard);
195 ms_message("the local ring is already started");
198 /* play a tone within the context of the current call */
199 linphone_core_play_tone(lc);
203 linphone_call_ref(call); /*prevent the call from being destroyed while we are notifying, if the user declines within the state callback */
204 linphone_call_set_state(call,LinphoneCallIncomingReceived,"Incoming call");
206 if (call->state==LinphoneCallIncomingReceived){
207 sal_call_notify_ringing(h,propose_early_media || ringback_tone!=NULL);
209 if (propose_early_media || ringback_tone!=NULL){
210 linphone_call_set_state(call,LinphoneCallIncomingEarlyMedia,"Incoming call early media");
211 linphone_core_update_streams(lc,call,md);
213 if (sal_call_get_replaces(call->op)!=NULL && lp_config_get_int(lc->config,"sip","auto_answer_replacing_calls",1)){
214 linphone_core_accept_call(lc,call);
217 linphone_call_unref(call);
223 static void call_ringing(SalOp *h){
224 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
225 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(h);
226 SalMediaDescription *md;
228 if (call==NULL) return;
230 if (lc->vtable.display_status)
231 lc->vtable.display_status(lc,_("Remote ringing."));
233 md=sal_call_get_final_media_description(h);
235 if (lc->ringstream && lc->dmfs_playing_start_time!=0){
236 ring_stop(lc->ringstream);
238 lc->dmfs_playing_start_time=0;
240 if (lc->ringstream!=NULL) return; /*already ringing !*/
241 if (lc->sound_conf.play_sndcard!=NULL){
242 MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
243 lc->ringstream=ring_start(lc->sound_conf.remote_ring,2000,ringcard);
245 ms_message("Remote ringing...");
246 if (lc->vtable.display_status)
247 lc->vtable.display_status(lc,_("Remote ringing..."));
248 linphone_call_set_state(call,LinphoneCallOutgoingRinging,"Remote ringing");
250 /*accept early media */
251 if (call->audiostream && call->audiostream->ticker!=NULL){
252 /*streams already started */
253 ms_message("Early media already started.");
256 if (lc->vtable.show) lc->vtable.show(lc);
257 if (lc->vtable.display_status)
258 lc->vtable.display_status(lc,_("Early media."));
259 linphone_call_set_state(call,LinphoneCallOutgoingEarlyMedia,"Early media");
260 if (lc->ringstream!=NULL){
261 ring_stop(lc->ringstream);
264 ms_message("Doing early media...");
265 linphone_core_update_streams (lc,call,md);
271 * - when the call is accepted
272 * - when a request is accepted (pause, resume)
274 static void call_accepted(SalOp *op){
275 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
276 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
277 SalMediaDescription *md;
280 ms_warning("No call to accept.");
284 md=sal_call_get_final_media_description(op);
286 if (call->state==LinphoneCallOutgoingProgress ||
287 call->state==LinphoneCallOutgoingRinging ||
288 call->state==LinphoneCallOutgoingEarlyMedia){
289 linphone_call_set_state(call,LinphoneCallConnected,"Connected");
291 if (md && !sal_media_description_empty(md)){
292 if (sal_media_description_has_dir(md,SalStreamSendOnly) ||
293 sal_media_description_has_dir(md,SalStreamInactive)){
294 if (lc->vtable.display_status){
295 char *tmp=linphone_call_get_remote_address_as_string (call);
296 char *msg=ms_strdup_printf(_("Call with %s is paused."),tmp);
297 lc->vtable.display_status(lc,msg);
301 linphone_core_update_streams (lc,call,md);
302 linphone_call_set_state(call,LinphoneCallPaused,"Call paused");
303 }else if (sal_media_description_has_dir(md,SalStreamRecvOnly)){
304 /*we are put on hold when the call is initially accepted */
305 if (lc->vtable.display_status){
306 char *tmp=linphone_call_get_remote_address_as_string (call);
307 char *msg=ms_strdup_printf(_("Call answered by %s - on hold."),tmp);
308 lc->vtable.display_status(lc,msg);
312 linphone_core_update_streams (lc,call,md);
313 linphone_call_set_state(call,LinphoneCallPausedByRemote,"Call paused by remote");
315 if (call->state==LinphoneCallStreamsRunning){
316 /*media was running before, the remote as acceted a call modification (that is
317 a reinvite made by us. We must notify the application this reinvite was accepted*/
318 linphone_call_set_state(call, LinphoneCallUpdated, "Call updated");
320 if (call->state==LinphoneCallResuming){
321 if (lc->vtable.display_status){
322 lc->vtable.display_status(lc,_("Call resumed."));
325 if (lc->vtable.display_status){
326 char *tmp=linphone_call_get_remote_address_as_string (call);
327 char *msg=ms_strdup_printf(_("Call answered by %s."),tmp);
328 lc->vtable.display_status(lc,msg);
334 linphone_core_update_streams (lc,call,md);
335 linphone_call_set_state(call, LinphoneCallStreamsRunning, "Streams running");
336 if (!call->current_params.in_conference)
337 lc->current_call=call;
341 ms_error("Incompatible SDP offer received in 200Ok, need to abort the call");
342 linphone_core_abort_call(lc,call,"No codec intersection");
346 static void call_ack(SalOp *op){
347 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
348 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
350 ms_warning("No call to be ACK'd");
353 if (call->media_pending){
354 SalMediaDescription *md=sal_call_get_final_media_description(op);
355 if (md && !sal_media_description_empty(md)){
356 if (call->state==LinphoneCallStreamsRunning){
357 /*media was running before, the remote as acceted a call modification (that is
358 a reinvite made by us. We must notify the application this reinvite was accepted*/
359 linphone_call_set_state(call, LinphoneCallUpdated, "Call updated");
361 linphone_core_update_streams (lc,call,md);
362 linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)");
365 ms_error("Incompatible SDP response received in ACK, need to abort the call");
366 linphone_core_abort_call(lc,call,"No codec intersection");
373 /* this callback is called when an incoming re-INVITE modifies the session*/
374 static void call_updating(SalOp *op){
375 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
376 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
377 LinphoneCallState prevstate=LinphoneCallIdle;
378 SalMediaDescription *md;
380 md=sal_call_get_final_media_description(op);
382 if (md && !sal_media_description_empty(md))
384 if (sal_media_description_has_dir(call->localdesc,SalStreamSendRecv)){
385 ms_message("Our local status is SalStreamSendRecv");
386 if (sal_media_description_has_dir (md,SalStreamRecvOnly) || sal_media_description_has_dir(md,SalStreamInactive)){
387 /* we are being paused */
388 if(lc->vtable.display_status)
389 lc->vtable.display_status(lc,_("We are being paused..."));
390 linphone_call_set_state (call,LinphoneCallPausedByRemote,"Call paused by remote");
391 }else if (!sal_media_description_has_dir(call->resultdesc,SalStreamSendRecv) && sal_media_description_has_dir(md,SalStreamSendRecv)){
392 if(lc->vtable.display_status)
393 lc->vtable.display_status(lc,_("We have been resumed..."));
394 linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)");
395 if (!call->current_params.in_conference)
396 lc->current_call=call;
398 prevstate=call->state;
399 linphone_call_set_state(call, LinphoneCallUpdatedByRemote,"Call updated by remote");
402 /*accept the modification (sends a 200Ok)*/
404 linphone_core_update_streams (lc,call,md);
405 if (prevstate!=LinphoneCallIdle){
406 linphone_call_set_state (call,prevstate,"Connected (streams running)");
411 static void call_terminated(SalOp *op, const char *from){
412 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
413 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
415 if (call==NULL) return;
417 if (linphone_call_get_state(call)==LinphoneCallEnd || linphone_call_get_state(call)==LinphoneCallError){
418 ms_warning("call_terminated: ignoring.");
421 ms_message("Current call terminated...");
422 //we stop the call only if we have this current call or if we are in call
423 if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls) == 1) || linphone_core_in_call(lc) )) {
424 ring_stop(lc->ringstream);
427 linphone_call_stop_media_streams(call);
428 if (lc->vtable.show!=NULL)
430 if (lc->vtable.display_status!=NULL)
431 lc->vtable.display_status(lc,_("Call terminated."));
433 linphone_call_set_state(call, LinphoneCallEnd,"Call ended");
436 static void call_failure(SalOp *op, SalError error, SalReason sr, const char *details, int code){
437 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
438 char *msg486=_("User is busy.");
439 char *msg480=_("User is temporarily unavailable.");
440 /*char *retrymsg=_("%s. Retry after %i minute(s).");*/
441 char *msg600=_("User does not want to be disturbed.");
442 char *msg603=_("Call declined.");
443 const char *msg=details;
444 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
447 ms_warning("Call faillure reported on already cleaned call ?");
451 if (lc->vtable.show) lc->vtable.show(lc);
453 if (error==SalErrorNoResponse){
454 msg=_("No response.");
455 if (lc->vtable.display_status)
456 lc->vtable.display_status(lc,msg);
457 }else if (error==SalErrorProtocol){
458 msg=details ? details : _("Protocol error.");
459 if (lc->vtable.display_status)
460 lc->vtable.display_status(lc, msg);
461 }else if (error==SalErrorFailure){
463 case SalReasonDeclined:
465 if (lc->vtable.display_status)
466 lc->vtable.display_status(lc,msg603);
470 if (lc->vtable.display_status)
471 lc->vtable.display_status(lc,msg486);
473 case SalReasonRedirect:
475 if (lc->vtable.display_status)
476 lc->vtable.display_status(lc,msg);
478 case SalReasonTemporarilyUnavailable:
480 if (lc->vtable.display_status)
481 lc->vtable.display_status(lc,msg480);
483 case SalReasonNotFound:
485 if (lc->vtable.display_status)
486 lc->vtable.display_status(lc,msg);
488 case SalReasonDoNotDisturb:
490 if (lc->vtable.display_status)
491 lc->vtable.display_status(lc,msg600);
494 //media_encryption_mandatory
495 if (call->params.media_encryption == LinphoneMediaEncryptionSRTP &&
496 !linphone_core_is_media_encryption_mandatory(lc)) {
498 ms_message("Outgoing call failed with SRTP (SAVP) enabled - retrying with AVP");
499 /* clear SRTP local params */
500 call->params.media_encryption = LinphoneMediaEncryptionNone;
501 for(i=0; i<call->localdesc->nstreams; i++) {
502 call->localdesc->streams[i].proto = SalProtoRtpAvp;
503 memset(call->localdesc->streams[i].crypto, 0, sizeof(call->localdesc->streams[i].crypto));
505 linphone_core_start_invite(lc, call, NULL);
508 msg=_("No common codecs");
509 if (lc->vtable.display_status)
510 lc->vtable.display_status(lc,msg);
513 if (lc->vtable.display_status)
514 lc->vtable.display_status(lc,_("Call failed."));
518 if (lc->ringstream!=NULL) {
519 ring_stop(lc->ringstream);
522 linphone_call_stop_media_streams (call);
523 if (sr!=SalReasonDeclined) linphone_call_set_state(call,LinphoneCallError,msg);
525 call->reason=LinphoneReasonDeclined;
526 linphone_call_set_state(call,LinphoneCallEnd,"Call declined.");
530 static void call_released(SalOp *op){
531 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
533 linphone_call_set_state(call,LinphoneCallReleased,"Call released");
534 }else ms_error("call_released() for already destroyed call ?");
537 static void auth_requested(SalOp *h, const char *realm, const char *username){
538 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
539 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
540 ms_message("auth_requested() for realm=%s, username=%s",realm,username);
542 if (ai && ai->works==FALSE && ai->usecount>=3){
543 /*case we tried 3 times to authenticate, without success */
544 /*Better is to stop (implemeted below in else statement), and retry later*/
545 if (ms_time(NULL)-ai->last_use_time>30){
546 ai->usecount=0; /*so that we can allow to retry */
550 if (ai && (ai->works || ai->usecount<3)){
552 sai.username=ai->username;
553 sai.userid=ai->userid;
555 sai.password=ai->passwd;
556 ms_message("auth_requested(): authenticating realm=%s, username=%s",realm,username);
557 sal_op_authenticate(h,&sai);
559 ai->last_use_time=ms_time(NULL);
561 if (ai && ai->works==FALSE) {
562 sal_op_cancel_authentication(h);
564 if (lc->vtable.auth_info_requested)
565 lc->vtable.auth_info_requested(lc,realm,username);
569 static void auth_success(SalOp *h, const char *realm, const char *username){
570 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
571 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
573 ms_message("%s/%s authentication works.",realm,username);
578 static void register_success(SalOp *op, bool_t registered){
579 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
580 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
583 cfg->registered=registered;
584 linphone_proxy_config_set_error(cfg,LinphoneReasonNone);
585 linphone_proxy_config_set_state(cfg, registered ? LinphoneRegistrationOk : LinphoneRegistrationCleared ,
586 registered ? "Registration sucessful" : "Unregistration done");
587 if (lc->vtable.display_status){
588 if (cfg->registered) msg=ms_strdup_printf(_("Registration on %s successful."),sal_op_get_proxy(op));
589 else msg=ms_strdup_printf(_("Unregistration on %s done."),sal_op_get_proxy(op));
590 lc->vtable.display_status(lc,msg);
596 static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details){
597 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
598 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
601 ms_warning("Registration failed for unknown proxy config.");
605 details=_("no response timeout");
607 if (lc->vtable.display_status) {
608 char *msg=ortp_strdup_printf(_("Registration on %s failed: %s"),sal_op_get_proxy(op),details );
609 lc->vtable.display_status(lc,msg);
612 if (error== SalErrorFailure && reason == SalReasonForbidden) {
613 linphone_proxy_config_set_error(cfg, LinphoneReasonBadCredentials);
614 } else if (error == SalErrorNoResponse) {
615 linphone_proxy_config_set_error(cfg, LinphoneReasonNoResponse);
617 linphone_proxy_config_set_state(cfg,LinphoneRegistrationFailed,details);
618 if (error== SalErrorFailure && reason == SalReasonForbidden) {
619 const char *realm=NULL,*username=NULL;
620 if (sal_op_get_auth_requested(op,&realm,&username)==0){
621 if (lc->vtable.auth_info_requested)
622 lc->vtable.auth_info_requested(lc,realm,username);
627 static void vfu_request(SalOp *op){
629 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
631 ms_warning("VFU request but no call !");
634 if (call->videostream)
635 video_stream_send_vfu(call->videostream);
639 static void dtmf_received(SalOp *op, char dtmf){
640 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
641 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
642 if (lc->vtable.dtmf_received != NULL)
643 lc->vtable.dtmf_received(lc, call, dtmf);
646 static void refer_received(Sal *sal, SalOp *op, const char *referto){
647 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
648 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
650 if (call->refer_to!=NULL){
651 ms_free(call->refer_to);
653 call->refer_to=ms_strdup(referto);
654 call->refer_pending=TRUE;
655 linphone_call_set_state(call,LinphoneCallRefered,"Refered");
656 if (lc->vtable.display_status){
657 char *msg=ms_strdup_printf(_("We are transferred to %s"),referto);
658 lc->vtable.display_status(lc,msg);
661 if (call->state!=LinphoneCallPaused){
662 ms_message("Automatically pausing current call to accept transfer.");
663 linphone_core_pause_call(lc,call);
665 linphone_core_start_refered_call(lc,call);
666 sal_call_accept_refer(op);
667 }else if (lc->vtable.refer_received){
668 lc->vtable.refer_received(lc,referto);
669 sal_call_accept_refer(op);
673 static void text_received(Sal *sal, const char *from, const char *msg){
674 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
675 linphone_core_text_received(lc,from,msg);
678 static void notify(SalOp *op, const char *from, const char *msg){
679 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
680 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
681 ms_message("get a %s notify from %s",msg,from);
682 if(lc->vtable.notify_recv)
683 lc->vtable.notify_recv(lc,call,from,msg);
686 static void notify_presence(SalOp *op, SalSubscribeState ss, SalPresenceStatus status, const char *msg){
687 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
688 linphone_notify_recv(lc,op,ss,status);
691 static void subscribe_received(SalOp *op, const char *from){
692 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
693 linphone_subscription_new(lc,op,from);
696 static void subscribe_closed(SalOp *op, const char *from){
697 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
698 linphone_subscription_closed(lc,op);
701 static void ping_reply(SalOp *op){
702 LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
703 ms_message("ping reply !");
705 if (call->state==LinphoneCallOutgoingInit){
706 linphone_core_start_invite(call->core,call,NULL);
711 ms_warning("ping reply without call attached...");
715 SalCallbacks linphone_sal_callbacks={