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->ice_session != NULL) {
50 linphone_core_deactivate_ice_for_deactivated_media_streams(call, call->resultdesc);
52 if ((call->audiostream && call->audiostream->ticker) || (call->videostream && call->videostream->ticker)){
53 /* we already started media: check if we really need to restart it*/
55 if (!media_parameters_changed(call,oldmd,new_md) && !call->playing_ringbacktone){
56 /*as nothing has changed, keep the oldmd */
57 call->resultdesc=oldmd;
58 sal_media_description_unref(new_md);
60 ms_message("Early media finished, unmuting inputs...");
61 /*we were in early media, now we want to enable real media */
62 linphone_call_enable_camera (call,linphone_call_camera_enabled (call));
63 if (call->audiostream)
64 linphone_core_mute_mic (lc, linphone_core_is_mic_muted(lc));
66 if (call->videostream && call->camera_active)
67 video_stream_change_camera(call->videostream,lc->video_conf.device );
70 ms_message("No need to restart streams, SDP is unchanged.");
73 ms_message("Media descriptions are different, need to restart the streams.");
76 linphone_call_stop_media_streams (call);
77 linphone_call_init_media_streams (call);
80 sal_media_description_unref(oldmd);
83 bool_t all_muted=FALSE;
84 bool_t send_ringbacktone=FALSE;
86 if (call->audiostream==NULL){
87 /*this happens after pausing the call locally. The streams is destroyed and then we wait the 200Ok to recreate it*/
88 linphone_call_init_media_streams (call);
90 if (call->state==LinphoneCallIncomingEarlyMedia && linphone_core_get_remote_ringback_tone (lc)!=NULL){
91 send_ringbacktone=TRUE;
93 if (call->state==LinphoneCallIncomingEarlyMedia ||
94 (call->state==LinphoneCallOutgoingEarlyMedia && !call->params.real_early_media)){
97 linphone_call_start_media_streams(call,all_muted,send_ringbacktone);
101 static bool_t is_duplicate_call(LinphoneCore *lc, const LinphoneAddress *from, const LinphoneAddress *to){
103 for(elem=lc->calls;elem!=NULL;elem=elem->next){
104 LinphoneCall *call=(LinphoneCall*)elem->data;
105 if (linphone_address_weak_equal(call->log->from,from) &&
106 linphone_address_weak_equal(call->log->to, to)){
114 static bool_t already_a_call_with_remote_address(const LinphoneCore *lc, const LinphoneAddress *remote) {
115 ms_warning(" searching for already_a_call_with_remote_address.");
118 for(elem=lc->calls;elem!=NULL;elem=elem->next){
119 const LinphoneCall *call=(LinphoneCall*)elem->data;
120 const LinphoneAddress *cRemote=linphone_call_get_remote_address(call);
121 if (linphone_address_weak_equal(cRemote,remote)) {
122 ms_warning("already_a_call_with_remote_address found.");
129 static bool_t already_a_call_pending(LinphoneCore *lc){
131 for(elem=lc->calls;elem!=NULL;elem=elem->next){
132 LinphoneCall *call=(LinphoneCall*)elem->data;
133 if (call->state==LinphoneCallIncomingReceived
134 || call->state==LinphoneCallOutgoingInit
135 || call->state==LinphoneCallOutgoingProgress
136 || call->state==LinphoneCallOutgoingEarlyMedia
137 || call->state==LinphoneCallOutgoingRinging){
144 static void call_received(SalOp *h){
145 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
147 const char *from,*to;
148 LinphoneAddress *from_addr, *to_addr;
149 bool_t prevent_colliding_calls=lp_config_get_int(lc->config,"sip","prevent_colliding_calls",TRUE);
151 /* first check if we can answer successfully to this invite */
152 if (lc->presence_mode==LinphoneStatusBusy ||
153 lc->presence_mode==LinphoneStatusOffline ||
154 lc->presence_mode==LinphoneStatusDoNotDisturb ||
155 lc->presence_mode==LinphoneStatusMoved){
156 if (lc->presence_mode==LinphoneStatusBusy )
157 sal_call_decline(h,SalReasonBusy,NULL);
158 else if (lc->presence_mode==LinphoneStatusOffline)
159 sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
160 else if (lc->presence_mode==LinphoneStatusDoNotDisturb)
161 sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
162 else if (lc->alt_contact!=NULL && lc->presence_mode==LinphoneStatusMoved)
163 sal_call_decline(h,SalReasonRedirect,lc->alt_contact);
167 if (!linphone_core_can_we_add_call(lc)){/*busy*/
168 sal_call_decline(h,SalReasonBusy,NULL);
172 from=sal_op_get_from(h);
174 from_addr=linphone_address_new(from);
175 to_addr=linphone_address_new(to);
177 if ((already_a_call_with_remote_address(lc,from_addr) && prevent_colliding_calls) || already_a_call_pending(lc)){
178 ms_warning("Receiving another call while one is ringing or initiated, refusing this one with busy message.");
179 sal_call_decline(h,SalReasonBusy,NULL);
181 linphone_address_destroy(from_addr);
182 linphone_address_destroy(to_addr);
186 call=linphone_call_new_incoming(lc,from_addr,to_addr,h);
188 /* the call is acceptable so we can now add it to our list */
189 linphone_core_add_call(lc,call);
190 linphone_call_ref(call); /*prevent the call from being destroyed while we are notifying, if the user declines within the state callback */
192 if ((linphone_core_get_firewall_policy(lc) == LinphonePolicyUseIce) && (call->ice_session != NULL)) {
193 /* Defer ringing until the end of the ICE candidates gathering process. */
194 ms_message("Defer ringing to gather ICE candidates");
198 linphone_core_notify_incoming_call(lc,call);
201 static void call_ringing(SalOp *h){
202 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
203 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(h);
204 SalMediaDescription *md;
206 if (call==NULL) return;
208 if (lc->vtable.display_status)
209 lc->vtable.display_status(lc,_("Remote ringing."));
211 md=sal_call_get_final_media_description(h);
213 if (lc->ringstream && lc->dmfs_playing_start_time!=0){
214 ring_stop(lc->ringstream);
216 lc->dmfs_playing_start_time=0;
218 if (lc->ringstream!=NULL) return; /*already ringing !*/
219 if (lc->sound_conf.play_sndcard!=NULL){
220 MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
221 if (call->localdesc->streams[0].max_rate>0) ms_snd_card_set_preferred_sample_rate(ringcard, call->localdesc->streams[0].max_rate);
222 /*we release sound before playing ringback tone*/
223 if (call->audiostream)
224 audio_stream_unprepare_sound(call->audiostream);
225 lc->ringstream=ring_start(lc->sound_conf.remote_ring,2000,ringcard);
227 ms_message("Remote ringing...");
228 if (lc->vtable.display_status)
229 lc->vtable.display_status(lc,_("Remote ringing..."));
230 linphone_call_set_state(call,LinphoneCallOutgoingRinging,"Remote ringing");
232 /*accept early media */
233 if (call->audiostream && audio_stream_started(call->audiostream)){
234 /*streams already started */
235 ms_message("Early media already started.");
238 if (lc->vtable.show) lc->vtable.show(lc);
239 if (lc->vtable.display_status)
240 lc->vtable.display_status(lc,_("Early media."));
241 linphone_call_set_state(call,LinphoneCallOutgoingEarlyMedia,"Early media");
242 if (lc->ringstream!=NULL){
243 ring_stop(lc->ringstream);
246 ms_message("Doing early media...");
247 linphone_core_update_streams(lc,call,md);
253 * - when the call is accepted
254 * - when a request is accepted (pause, resume)
256 static void call_accepted(SalOp *op){
257 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
258 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
259 SalMediaDescription *md;
262 ms_warning("No call to accept.");
266 /* Handle remote ICE attributes if any. */
267 if (call->ice_session != NULL) {
268 linphone_core_update_ice_from_remote_media_description(call, sal_call_get_remote_media_description(op));
271 md=sal_call_get_final_media_description(op);
273 if (call->state==LinphoneCallOutgoingProgress ||
274 call->state==LinphoneCallOutgoingRinging ||
275 call->state==LinphoneCallOutgoingEarlyMedia){
276 linphone_call_set_state(call,LinphoneCallConnected,"Connected");
277 if (call->referer) linphone_core_notify_refer_state(lc,call->referer,call);
279 if (md && !sal_media_description_empty(md)){
280 if (sal_media_description_has_dir(md,SalStreamSendOnly) ||
281 sal_media_description_has_dir(md,SalStreamInactive)){
282 if (lc->vtable.display_status){
283 char *tmp=linphone_call_get_remote_address_as_string (call);
284 char *msg=ms_strdup_printf(_("Call with %s is paused."),tmp);
285 lc->vtable.display_status(lc,msg);
289 linphone_core_update_streams (lc,call,md);
290 linphone_call_set_state(call,LinphoneCallPaused,"Call paused");
291 if (call->refer_pending)
292 linphone_core_start_refered_call(lc,call);
293 }else if (sal_media_description_has_dir(md,SalStreamRecvOnly)){
294 /*we are put on hold when the call is initially accepted */
295 if (lc->vtable.display_status){
296 char *tmp=linphone_call_get_remote_address_as_string (call);
297 char *msg=ms_strdup_printf(_("Call answered by %s - on hold."),tmp);
298 lc->vtable.display_status(lc,msg);
302 linphone_core_update_streams (lc,call,md);
303 linphone_call_set_state(call,LinphoneCallPausedByRemote,"Call paused by remote");
305 if (call->state!=LinphoneCallUpdating){
306 if (call->state==LinphoneCallResuming){
307 if (lc->vtable.display_status){
308 lc->vtable.display_status(lc,_("Call resumed."));
311 if (lc->vtable.display_status){
312 char *tmp=linphone_call_get_remote_address_as_string (call);
313 char *msg=ms_strdup_printf(_("Call answered by %s."),tmp);
314 lc->vtable.display_status(lc,msg);
320 linphone_core_update_streams (lc,call,md);
321 if (!call->current_params.in_conference)
322 lc->current_call=call;
323 linphone_call_set_state(call, LinphoneCallStreamsRunning, "Streams running");
327 ms_error("Incompatible SDP offer received in 200Ok, need to abort the call");
328 linphone_core_abort_call(lc,call,_("Incompatible, check codecs..."));
332 static void call_ack(SalOp *op){
333 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
334 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
336 ms_warning("No call to be ACK'd");
339 if (call->media_pending){
340 SalMediaDescription *md=sal_call_get_final_media_description(op);
341 if (md && !sal_media_description_empty(md)){
342 linphone_core_update_streams (lc,call,md);
343 linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)");
346 ms_error("Incompatible SDP response received in ACK, need to abort the call");
347 linphone_core_abort_call(lc,call,"No codec intersection");
353 static void call_accept_update(LinphoneCore *lc, LinphoneCall *call){
354 SalMediaDescription *md;
355 SalMediaDescription *rmd=sal_call_get_remote_media_description(call->op);
356 if ((rmd!=NULL) && (call->ice_session!=NULL)) {
357 linphone_core_update_ice_from_remote_media_description(call,rmd);
358 linphone_core_update_local_media_description_from_ice(call->localdesc,call->ice_session);
360 sal_call_accept(call->op);
361 md=sal_call_get_final_media_description(call->op);
362 if (md && !sal_media_description_empty(md))
363 linphone_core_update_streams(lc,call,md);
366 static void call_resumed(LinphoneCore *lc, LinphoneCall *call){
367 call_accept_update(lc,call);
368 if(lc->vtable.display_status)
369 lc->vtable.display_status(lc,_("We have been resumed."));
370 linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)");
371 linphone_call_set_transfer_state(call, LinphoneCallIdle);
374 static void call_paused_by_remote(LinphoneCore *lc, LinphoneCall *call){
375 call_accept_update(lc,call);
376 /* we are being paused */
377 if(lc->vtable.display_status)
378 lc->vtable.display_status(lc,_("We are paused by other party."));
379 linphone_call_set_state (call,LinphoneCallPausedByRemote,"Call paused by remote");
382 static void call_updated_by_remote(LinphoneCore *lc, LinphoneCall *call){
383 if(lc->vtable.display_status)
384 lc->vtable.display_status(lc,_("Call is updated by remote."));
385 call->defer_update=FALSE;
386 linphone_call_set_state(call, LinphoneCallUpdatedByRemote,"Call updated by remote");
387 if (call->defer_update==FALSE){
388 linphone_core_accept_call_update(lc,call,NULL);
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 SalMediaDescription *rmd=sal_call_get_remote_media_description(op);
399 /* case of a reINVITE without SDP */
400 call_accept_update(lc,call);
401 call->media_pending=TRUE;
406 case LinphoneCallPausedByRemote:
407 if (sal_media_description_has_dir(rmd,SalStreamSendRecv) || sal_media_description_has_dir(rmd,SalStreamRecvOnly)){
408 call_resumed(lc,call);
409 }else call_paused_by_remote(lc,call);
411 case LinphoneCallStreamsRunning:
412 case LinphoneCallConnected:
413 if (sal_media_description_has_dir(rmd,SalStreamSendOnly) || sal_media_description_has_dir(rmd,SalStreamInactive)){
414 call_paused_by_remote(lc,call);
416 call_updated_by_remote(lc,call);
420 call_accept_update(lc,call);
424 static void call_terminated(SalOp *op, const char *from){
425 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
426 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
428 if (call==NULL) return;
430 switch(linphone_call_get_state(call)){
431 case LinphoneCallEnd:
432 case LinphoneCallError:
433 ms_warning("call_terminated: ignoring.");
436 case LinphoneCallIncomingReceived:
437 case LinphoneCallIncomingEarlyMedia:
438 call->reason=LinphoneReasonNotAnswered;
443 ms_message("Current call terminated...");
444 //we stop the call only if we have this current call or if we are in call
445 if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls) == 1) || linphone_core_in_call(lc) )) {
446 ring_stop(lc->ringstream);
449 linphone_call_stop_media_streams(call);
450 if (lc->vtable.show!=NULL)
452 if (lc->vtable.display_status!=NULL)
453 lc->vtable.display_status(lc,_("Call terminated."));
455 linphone_call_set_state(call, LinphoneCallEnd,"Call ended");
458 static void call_failure(SalOp *op, SalError error, SalReason sr, const char *details, int code){
459 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
460 char *msg486=_("User is busy.");
461 char *msg480=_("User is temporarily unavailable.");
462 /*char *retrymsg=_("%s. Retry after %i minute(s).");*/
463 char *msg600=_("User does not want to be disturbed.");
464 char *msg603=_("Call declined.");
465 const char *msg=details;
466 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
469 ms_warning("Call faillure reported on already cleaned call ?");
473 if (lc->vtable.show) lc->vtable.show(lc);
475 if (error==SalErrorNoResponse){
476 msg=_("No response.");
477 if (lc->vtable.display_status)
478 lc->vtable.display_status(lc,msg);
479 }else if (error==SalErrorProtocol){
480 msg=details ? details : _("Protocol error.");
481 if (lc->vtable.display_status)
482 lc->vtable.display_status(lc, msg);
483 }else if (error==SalErrorFailure){
485 case SalReasonDeclined:
487 if (lc->vtable.display_status)
488 lc->vtable.display_status(lc,msg603);
492 if (lc->vtable.display_status)
493 lc->vtable.display_status(lc,msg486);
495 case SalReasonRedirect:
497 if (lc->vtable.display_status)
498 lc->vtable.display_status(lc,msg);
500 case SalReasonTemporarilyUnavailable:
502 if (lc->vtable.display_status)
503 lc->vtable.display_status(lc,msg480);
505 case SalReasonNotFound:
506 if (lc->vtable.display_status)
507 lc->vtable.display_status(lc,msg);
509 case SalReasonDoNotDisturb:
511 if (lc->vtable.display_status)
512 lc->vtable.display_status(lc,msg600);
515 //media_encryption_mandatory
516 if (call->params.media_encryption == LinphoneMediaEncryptionSRTP &&
517 !linphone_core_is_media_encryption_mandatory(lc)) {
519 ms_message("Outgoing call failed with SRTP (SAVP) enabled - retrying with AVP");
520 linphone_call_stop_media_streams(call);
521 if (call->state==LinphoneCallOutgoingInit || call->state==LinphoneCallOutgoingProgress){
522 /* clear SRTP local params */
523 call->params.media_encryption = LinphoneMediaEncryptionNone;
524 for(i=0; i<call->localdesc->nstreams; i++) {
525 call->localdesc->streams[i].proto = SalProtoRtpAvp;
526 memset(call->localdesc->streams[i].crypto, 0, sizeof(call->localdesc->streams[i].crypto));
528 linphone_core_start_invite(lc, call);
532 msg=_("Incompatible media parameters.");
533 if (lc->vtable.display_status)
534 lc->vtable.display_status(lc,msg);
537 if (lc->vtable.display_status)
538 lc->vtable.display_status(lc,_("Call failed."));
542 if (lc->ringstream!=NULL) {
543 ring_stop(lc->ringstream);
546 linphone_call_stop_media_streams (call);
547 if (call->referer && linphone_call_get_state(call->referer)==LinphoneCallPaused && call->referer->was_automatically_paused){
548 /*resume to the call that send us the refer automatically*/
549 linphone_core_resume_call(lc,call->referer);
551 if (sr == SalReasonDeclined) {
552 call->reason=LinphoneReasonDeclined;
553 linphone_call_set_state(call,LinphoneCallEnd,"Call declined.");
554 } else if (sr == SalReasonNotFound) {
555 call->reason=LinphoneReasonNotFound;
556 linphone_call_set_state(call,LinphoneCallError,"User not found.");
558 linphone_call_set_state(call,LinphoneCallError,msg);
562 static void call_released(SalOp *op){
563 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
565 linphone_call_set_state(call,LinphoneCallReleased,"Call released");
566 }else ms_error("call_released() for already destroyed call ?");
569 static void auth_requested(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);
572 LinphoneCall *call=is_a_linphone_call(sal_op_get_user_pointer(h));
574 if (call && call->ping_op==h){
575 /*don't request authentication for ping requests. Their purpose is just to get any
576 * answer to get the Via's received and rport parameters.
578 ms_message("auth_requested(): ignored for ping request.");
582 ms_message("auth_requested() for realm=%s, username=%s",realm,username);
584 if (ai && ai->works==FALSE && ai->usecount>=3){
585 /*case we tried 3 times to authenticate, without success */
586 /*Better is to stop (implemeted below in else statement), and retry later*/
587 if (ms_time(NULL)-ai->last_use_time>30){
588 ai->usecount=0; /*so that we can allow to retry */
592 if (ai && (ai->works || ai->usecount<3)){
594 sai.username=ai->username;
595 sai.userid=ai->userid;
597 sai.password=ai->passwd;
598 ms_message("auth_requested(): authenticating realm=%s, username=%s",realm,username);
599 sal_op_authenticate(h,&sai);
601 ai->last_use_time=ms_time(NULL);
603 if (ai && ai->works==FALSE) {
604 sal_op_cancel_authentication(h);
606 if (lc->vtable.auth_info_requested)
607 lc->vtable.auth_info_requested(lc,realm,username);
611 static void auth_success(SalOp *h, const char *realm, const char *username){
612 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
613 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
615 ms_message("%s/%s authentication works.",realm,username);
620 static void register_success(SalOp *op, bool_t registered){
621 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
622 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
625 if (cfg->deletion_date!=0){
626 ms_message("Registration success for removed proxy config, ignored");
629 linphone_proxy_config_set_error(cfg,LinphoneReasonNone);
630 linphone_proxy_config_set_state(cfg, registered ? LinphoneRegistrationOk : LinphoneRegistrationCleared ,
631 registered ? "Registration sucessful" : "Unregistration done");
632 if (lc->vtable.display_status){
633 if (registered) msg=ms_strdup_printf(_("Registration on %s successful."),sal_op_get_proxy(op));
634 else msg=ms_strdup_printf(_("Unregistration on %s done."),sal_op_get_proxy(op));
635 lc->vtable.display_status(lc,msg);
641 static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details){
642 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
643 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
646 ms_warning("Registration failed for unknown proxy config.");
649 if (cfg->deletion_date!=0){
650 ms_message("Registration failed for removed proxy config, ignored");
654 details=_("no response timeout");
656 if (lc->vtable.display_status) {
657 char *msg=ortp_strdup_printf(_("Registration on %s failed: %s"),sal_op_get_proxy(op),details );
658 lc->vtable.display_status(lc,msg);
661 if (error== SalErrorFailure && reason == SalReasonForbidden) {
662 linphone_proxy_config_set_error(cfg, LinphoneReasonBadCredentials);
663 } else if (error == SalErrorNoResponse) {
664 linphone_proxy_config_set_error(cfg, LinphoneReasonNoResponse);
666 linphone_proxy_config_set_state(cfg,LinphoneRegistrationFailed,details);
667 if (error== SalErrorFailure && reason == SalReasonForbidden) {
668 const char *realm=NULL,*username=NULL;
669 if (sal_op_get_auth_requested(op,&realm,&username)==0){
670 if (lc->vtable.auth_info_requested)
671 lc->vtable.auth_info_requested(lc,realm,username);
676 static void vfu_request(SalOp *op){
678 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
680 ms_warning("VFU request but no call !");
683 if (call->videostream)
684 video_stream_send_vfu(call->videostream);
688 static void dtmf_received(SalOp *op, char dtmf){
689 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
690 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
691 if (lc->vtable.dtmf_received != NULL)
692 lc->vtable.dtmf_received(lc, call, dtmf);
695 static void refer_received(Sal *sal, SalOp *op, const char *referto){
696 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
697 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
699 if (call->refer_to!=NULL){
700 ms_free(call->refer_to);
702 call->refer_to=ms_strdup(referto);
703 call->refer_pending=TRUE;
704 linphone_call_set_state(call,LinphoneCallRefered,"Refered");
705 if (lc->vtable.display_status){
706 char *msg=ms_strdup_printf(_("We are transferred to %s"),referto);
707 lc->vtable.display_status(lc,msg);
710 if (call->state!=LinphoneCallPaused){
711 ms_message("Automatically pausing current call to accept transfer.");
712 linphone_core_pause_call(lc,call);
713 call->was_automatically_paused=TRUE;
714 /*then we will start the refered when the pause is accepted, in order to serialize transactions within the dialog.
715 * Indeed we need to avoid to send a NOTIFY to inform about of state of the refered call while the pause isn't completed.
717 }else linphone_core_start_refered_call(lc,call);
718 }else if (lc->vtable.refer_received){
719 lc->vtable.refer_received(lc,referto);
723 static void text_received(Sal *sal, const char *from, const char *msg){
724 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
725 linphone_core_message_received(lc,from,msg,NULL);
727 void message_external_body_received(Sal *sal, const char *from, const char *url) {
728 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
729 linphone_core_message_received(lc,from,NULL,url);
731 static void notify(SalOp *op, const char *from, const char *msg){
732 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
733 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
734 ms_message("get a %s notify from %s",msg,from);
735 if(lc->vtable.notify_recv)
736 lc->vtable.notify_recv(lc,call,from,msg);
739 static void notify_presence(SalOp *op, SalSubscribeStatus ss, SalPresenceStatus status, const char *msg){
740 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
741 linphone_notify_recv(lc,op,ss,status);
744 static void subscribe_received(SalOp *op, const char *from){
745 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
746 linphone_subscription_new(lc,op,from);
749 static void subscribe_closed(SalOp *op, const char *from){
750 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
751 linphone_subscription_closed(lc,op);
754 static void ping_reply(SalOp *op){
755 LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
756 ms_message("ping reply !");
758 if (call->state==LinphoneCallOutgoingInit){
759 call->ping_replied=TRUE;
760 linphone_core_proceed_with_invite_if_ready(call->core,call,NULL);
765 ms_warning("ping reply without call attached...");
769 static void notify_refer(SalOp *op, SalReferStatus status){
770 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
771 LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
772 LinphoneCallState cstate;
774 ms_warning("Receiving notify_refer for unknown call.");
779 cstate=LinphoneCallOutgoingProgress;
781 case SalReferSuccess:
782 cstate=LinphoneCallConnected;
785 cstate=LinphoneCallError;
788 cstate=LinphoneCallError;
790 linphone_call_set_transfer_state(call, cstate);
791 if (cstate==LinphoneCallConnected){
792 /*automatically terminate the call as the transfer is complete.*/
793 linphone_core_terminate_call(lc,call);
797 static LinphoneChatMessageState chatStatusSal2Linphone(SalTextDeliveryStatus status){
799 case SalTextDeliveryInProgress:
800 return LinphoneChatMessageStateInProgress;
801 case SalTextDeliveryDone:
802 return LinphoneChatMessageStateDelivered;
803 case SalTextDeliveryFailed:
804 return LinphoneChatMessageStateNotDelivered;
806 return LinphoneChatMessageStateIdle;
809 static void text_delivery_update(SalOp *op, SalTextDeliveryStatus status){
810 LinphoneChatMessage *chat_msg=(LinphoneChatMessage* )sal_op_get_user_pointer(op);
811 if (chat_msg && chat_msg->cb) {
812 chat_msg->cb(chat_msg
813 ,chatStatusSal2Linphone(status)
816 linphone_chat_message_destroy(chat_msg);
819 SalCallbacks linphone_sal_callbacks={
836 message_external_body_received,
837 text_delivery_update,