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_with_remote_address(const LinphoneCore *lc, const LinphoneAddress *remote) {
112 ms_warning(" searching for already_a_call_with_remote_address.");
115 for(elem=lc->calls;elem!=NULL;elem=elem->next){
116 const LinphoneCall *call=(LinphoneCall*)elem->data;
117 const LinphoneAddress *cRemote=linphone_call_get_remote_address(call);
118 if (linphone_address_weak_equal(cRemote,remote)) {
119 ms_warning("already_a_call_with_remote_address found.");
126 static bool_t already_a_call_pending(LinphoneCore *lc){
128 for(elem=lc->calls;elem!=NULL;elem=elem->next){
129 LinphoneCall *call=(LinphoneCall*)elem->data;
130 if (call->state==LinphoneCallIncomingReceived
131 || call->state==LinphoneCallOutgoingInit
132 || call->state==LinphoneCallOutgoingProgress
133 || call->state==LinphoneCallOutgoingEarlyMedia
134 || call->state==LinphoneCallOutgoingRinging){
141 static void call_received(SalOp *h){
142 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
144 const char *from,*to;
145 LinphoneAddress *from_addr, *to_addr;
146 bool_t prevent_colliding_calls=lp_config_get_int(lc->config,"sip","prevent_colliding_calls",TRUE);
148 /* first check if we can answer successfully to this invite */
149 if (lc->presence_mode==LinphoneStatusBusy ||
150 lc->presence_mode==LinphoneStatusOffline ||
151 lc->presence_mode==LinphoneStatusDoNotDisturb ||
152 lc->presence_mode==LinphoneStatusMoved){
153 if (lc->presence_mode==LinphoneStatusBusy )
154 sal_call_decline(h,SalReasonBusy,NULL);
155 else if (lc->presence_mode==LinphoneStatusOffline)
156 sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
157 else if (lc->presence_mode==LinphoneStatusDoNotDisturb)
158 sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
159 else if (lc->alt_contact!=NULL && lc->presence_mode==LinphoneStatusMoved)
160 sal_call_decline(h,SalReasonRedirect,lc->alt_contact);
164 if (!linphone_core_can_we_add_call(lc)){/*busy*/
165 sal_call_decline(h,SalReasonBusy,NULL);
169 from=sal_op_get_from(h);
171 from_addr=linphone_address_new(from);
172 to_addr=linphone_address_new(to);
174 if ((already_a_call_with_remote_address(lc,from_addr) && prevent_colliding_calls) || already_a_call_pending(lc)){
175 ms_warning("Receiving another call while one is ringing or initiated, refusing this one with busy message.");
176 sal_call_decline(h,SalReasonBusy,NULL);
178 linphone_address_destroy(from_addr);
179 linphone_address_destroy(to_addr);
183 call=linphone_call_new_incoming(lc,from_addr,to_addr,h);
184 sal_call_set_local_media_description(h,call->localdesc);
186 /* the call is acceptable so we can now add it to our list */
187 linphone_core_add_call(lc,call);
188 linphone_call_ref(call); /*prevent the call from being destroyed while we are notifying, if the user declines within the state callback */
190 if ((linphone_core_get_firewall_policy(lc) == LinphonePolicyUseIce) && (call->ice_session != NULL)) {
191 /* Defer ringing until the end of the ICE candidates gathering process. */
192 ms_message("Defer ringing to gather ICE candidates");
196 linphone_core_notify_incoming_call(lc,call);
199 static void call_ringing(SalOp *h){
200 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
201 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(h);
202 SalMediaDescription *md;
204 if (call==NULL) return;
206 if (lc->vtable.display_status)
207 lc->vtable.display_status(lc,_("Remote ringing."));
209 md=sal_call_get_final_media_description(h);
211 if (lc->ringstream && lc->dmfs_playing_start_time!=0){
212 ring_stop(lc->ringstream);
214 lc->dmfs_playing_start_time=0;
216 if (lc->ringstream!=NULL) return; /*already ringing !*/
217 if (lc->sound_conf.play_sndcard!=NULL){
218 MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
219 if (call->localdesc->streams[0].max_rate>0) ms_snd_card_set_preferred_sample_rate(ringcard, call->localdesc->streams[0].max_rate);
220 /*we release sound before playing ringback tone*/
221 if (call->audiostream)
222 audio_stream_unprepare_sound(call->audiostream);
223 lc->ringstream=ring_start(lc->sound_conf.remote_ring,2000,ringcard);
225 ms_message("Remote ringing...");
226 if (lc->vtable.display_status)
227 lc->vtable.display_status(lc,_("Remote ringing..."));
228 linphone_call_set_state(call,LinphoneCallOutgoingRinging,"Remote ringing");
230 /*accept early media */
231 if (call->audiostream && audio_stream_started(call->audiostream)){
232 /*streams already started */
233 ms_message("Early media already started.");
236 if (lc->vtable.show) lc->vtable.show(lc);
237 if (lc->vtable.display_status)
238 lc->vtable.display_status(lc,_("Early media."));
239 linphone_call_set_state(call,LinphoneCallOutgoingEarlyMedia,"Early media");
240 if (lc->ringstream!=NULL){
241 ring_stop(lc->ringstream);
244 ms_message("Doing early media...");
245 linphone_core_update_streams(lc,call,md);
251 * - when the call is accepted
252 * - when a request is accepted (pause, resume)
254 static void call_accepted(SalOp *op){
255 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
256 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
257 SalMediaDescription *md;
260 ms_warning("No call to accept.");
264 /* Handle remote ICE attributes if any. */
265 if (call->ice_session != NULL) {
266 linphone_core_update_ice_from_remote_media_description(call, sal_call_get_remote_media_description(op));
269 md=sal_call_get_final_media_description(op);
271 if (call->state==LinphoneCallOutgoingProgress ||
272 call->state==LinphoneCallOutgoingRinging ||
273 call->state==LinphoneCallOutgoingEarlyMedia){
274 linphone_call_set_state(call,LinphoneCallConnected,"Connected");
275 if (call->referer) linphone_core_notify_refer_state(lc,call->referer,call);
277 if (md && !sal_media_description_empty(md)){
278 if (sal_media_description_has_dir(md,SalStreamSendOnly) ||
279 sal_media_description_has_dir(md,SalStreamInactive)){
280 if (lc->vtable.display_status){
281 char *tmp=linphone_call_get_remote_address_as_string (call);
282 char *msg=ms_strdup_printf(_("Call with %s is paused."),tmp);
283 lc->vtable.display_status(lc,msg);
287 linphone_core_update_streams (lc,call,md);
288 linphone_call_set_state(call,LinphoneCallPaused,"Call paused");
289 if (call->refer_pending)
290 linphone_core_start_refered_call(lc,call);
291 }else if (sal_media_description_has_dir(md,SalStreamRecvOnly)){
292 /*we are put on hold when the call is initially accepted */
293 if (lc->vtable.display_status){
294 char *tmp=linphone_call_get_remote_address_as_string (call);
295 char *msg=ms_strdup_printf(_("Call answered by %s - on hold."),tmp);
296 lc->vtable.display_status(lc,msg);
300 linphone_core_update_streams (lc,call,md);
301 linphone_call_set_state(call,LinphoneCallPausedByRemote,"Call paused by remote");
303 if (call->state==LinphoneCallStreamsRunning){
304 /*media was running before, the remote as acceted a call modification (that is
305 a reinvite made by us. We must notify the application this reinvite was accepted*/
306 linphone_call_set_state(call, LinphoneCallUpdated, "Call updated");
308 if (call->state==LinphoneCallResuming){
309 if (lc->vtable.display_status){
310 lc->vtable.display_status(lc,_("Call resumed."));
313 if (lc->vtable.display_status){
314 char *tmp=linphone_call_get_remote_address_as_string (call);
315 char *msg=ms_strdup_printf(_("Call answered by %s."),tmp);
316 lc->vtable.display_status(lc,msg);
322 linphone_core_update_streams (lc,call,md);
323 if (!call->current_params.in_conference)
324 lc->current_call=call;
325 linphone_call_set_state(call, LinphoneCallStreamsRunning, "Streams running");
329 ms_error("Incompatible SDP offer received in 200Ok, need to abort the call");
330 linphone_core_abort_call(lc,call,_("Incompatible, check codecs..."));
334 static void call_ack(SalOp *op){
335 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
336 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
338 ms_warning("No call to be ACK'd");
341 if (call->media_pending){
342 SalMediaDescription *md=sal_call_get_final_media_description(op);
343 if (md && !sal_media_description_empty(md)){
344 if (call->state==LinphoneCallStreamsRunning){
345 /*media was running before, the remote as acceted a call modification (that is
346 a reinvite made by us. We must notify the application this reinvite was accepted*/
347 linphone_call_set_state(call, LinphoneCallUpdated, "Call updated");
349 linphone_core_update_streams (lc,call,md);
350 linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)");
353 ms_error("Incompatible SDP response received in ACK, need to abort the call");
354 linphone_core_abort_call(lc,call,"No codec intersection");
360 static void call_accept_update(LinphoneCore *lc, LinphoneCall *call){
361 SalMediaDescription *md;
362 SalMediaDescription *rmd=sal_call_get_remote_media_description(call->op);
363 if ((rmd!=NULL) && (call->ice_session!=NULL)) {
364 linphone_core_update_ice_from_remote_media_description(call,rmd);
365 linphone_core_update_local_media_description_from_ice(call->localdesc,call->ice_session);
367 sal_call_accept(call->op);
368 md=sal_call_get_final_media_description(call->op);
369 if (md && !sal_media_description_empty(md))
370 linphone_core_update_streams(lc,call,md);
373 static void call_resumed(LinphoneCore *lc, LinphoneCall *call){
374 call_accept_update(lc,call);
375 if(lc->vtable.display_status)
376 lc->vtable.display_status(lc,_("We have been resumed."));
377 linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)");
378 linphone_call_set_transfer_state(call, LinphoneCallIdle);
381 static void call_paused_by_remote(LinphoneCore *lc, LinphoneCall *call){
382 call_accept_update(lc,call);
383 /* we are being paused */
384 if(lc->vtable.display_status)
385 lc->vtable.display_status(lc,_("We are paused by other party."));
386 linphone_call_set_state (call,LinphoneCallPausedByRemote,"Call paused by remote");
389 static void call_updated_by_remote(LinphoneCore *lc, LinphoneCall *call){
390 if(lc->vtable.display_status)
391 lc->vtable.display_status(lc,_("Call is updated by remote."));
392 call->defer_update=FALSE;
393 linphone_call_set_state(call, LinphoneCallUpdatedByRemote,"Call updated by remote");
394 if (call->defer_update==FALSE){
395 linphone_core_accept_call_update(lc,call,NULL);
399 /* this callback is called when an incoming re-INVITE modifies the session*/
400 static void call_updating(SalOp *op){
401 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
402 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
403 SalMediaDescription *rmd=sal_call_get_remote_media_description(op);
406 /* case of a reINVITE without SDP */
407 call_accept_update(lc,call);
408 call->media_pending=TRUE;
413 case LinphoneCallPausedByRemote:
414 if (sal_media_description_has_dir(rmd,SalStreamSendRecv) || sal_media_description_has_dir(rmd,SalStreamRecvOnly)){
415 call_resumed(lc,call);
416 }else call_paused_by_remote(lc,call);
418 case LinphoneCallStreamsRunning:
419 case LinphoneCallConnected:
420 if (sal_media_description_has_dir(rmd,SalStreamSendOnly) || sal_media_description_has_dir(rmd,SalStreamInactive)){
421 call_paused_by_remote(lc,call);
423 call_updated_by_remote(lc,call);
427 call_accept_update(lc,call);
431 static void call_terminated(SalOp *op, const char *from){
432 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
433 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
435 if (call==NULL) return;
437 switch(linphone_call_get_state(call)){
438 case LinphoneCallEnd:
439 case LinphoneCallError:
440 ms_warning("call_terminated: ignoring.");
443 case LinphoneCallIncomingReceived:
444 case LinphoneCallIncomingEarlyMedia:
445 call->reason=LinphoneReasonNotAnswered;
450 ms_message("Current call terminated...");
451 //we stop the call only if we have this current call or if we are in call
452 if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls) == 1) || linphone_core_in_call(lc) )) {
453 ring_stop(lc->ringstream);
456 linphone_call_stop_media_streams(call);
457 if (lc->vtable.show!=NULL)
459 if (lc->vtable.display_status!=NULL)
460 lc->vtable.display_status(lc,_("Call terminated."));
462 linphone_call_set_state(call, LinphoneCallEnd,"Call ended");
465 static void call_failure(SalOp *op, SalError error, SalReason sr, const char *details, int code){
466 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
467 char *msg486=_("User is busy.");
468 char *msg480=_("User is temporarily unavailable.");
469 /*char *retrymsg=_("%s. Retry after %i minute(s).");*/
470 char *msg600=_("User does not want to be disturbed.");
471 char *msg603=_("Call declined.");
472 const char *msg=details;
473 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
476 ms_warning("Call faillure reported on already cleaned call ?");
480 if (lc->vtable.show) lc->vtable.show(lc);
482 if (error==SalErrorNoResponse){
483 msg=_("No response.");
484 if (lc->vtable.display_status)
485 lc->vtable.display_status(lc,msg);
486 }else if (error==SalErrorProtocol){
487 msg=details ? details : _("Protocol error.");
488 if (lc->vtable.display_status)
489 lc->vtable.display_status(lc, msg);
490 }else if (error==SalErrorFailure){
492 case SalReasonDeclined:
494 if (lc->vtable.display_status)
495 lc->vtable.display_status(lc,msg603);
499 if (lc->vtable.display_status)
500 lc->vtable.display_status(lc,msg486);
502 case SalReasonRedirect:
504 if (lc->vtable.display_status)
505 lc->vtable.display_status(lc,msg);
507 case SalReasonTemporarilyUnavailable:
509 if (lc->vtable.display_status)
510 lc->vtable.display_status(lc,msg480);
512 case SalReasonNotFound:
513 if (lc->vtable.display_status)
514 lc->vtable.display_status(lc,msg);
516 case SalReasonDoNotDisturb:
518 if (lc->vtable.display_status)
519 lc->vtable.display_status(lc,msg600);
522 //media_encryption_mandatory
523 if (call->params.media_encryption == LinphoneMediaEncryptionSRTP &&
524 !linphone_core_is_media_encryption_mandatory(lc)) {
526 ms_message("Outgoing call failed with SRTP (SAVP) enabled - retrying with AVP");
527 linphone_call_stop_media_streams(call);
528 if (call->state==LinphoneCallOutgoingInit || call->state==LinphoneCallOutgoingProgress){
529 /* clear SRTP local params */
530 call->params.media_encryption = LinphoneMediaEncryptionNone;
531 for(i=0; i<call->localdesc->nstreams; i++) {
532 call->localdesc->streams[i].proto = SalProtoRtpAvp;
533 memset(call->localdesc->streams[i].crypto, 0, sizeof(call->localdesc->streams[i].crypto));
535 linphone_core_start_invite(lc, call, NULL);
539 msg=_("Incompatible media parameters.");
540 if (lc->vtable.display_status)
541 lc->vtable.display_status(lc,msg);
544 if (lc->vtable.display_status)
545 lc->vtable.display_status(lc,_("Call failed."));
549 if (lc->ringstream!=NULL) {
550 ring_stop(lc->ringstream);
553 linphone_call_stop_media_streams (call);
554 if (call->referer && linphone_call_get_state(call->referer)==LinphoneCallPaused && call->referer->was_automatically_paused){
555 /*resume to the call that send us the refer automatically*/
556 linphone_core_resume_call(lc,call->referer);
558 if (sr == SalReasonDeclined) {
559 call->reason=LinphoneReasonDeclined;
560 linphone_call_set_state(call,LinphoneCallEnd,"Call declined.");
561 } else if (sr == SalReasonNotFound) {
562 call->reason=LinphoneReasonNotFound;
563 linphone_call_set_state(call,LinphoneCallError,"User not found.");
565 linphone_call_set_state(call,LinphoneCallError,msg);
569 static void call_released(SalOp *op){
570 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
572 linphone_call_set_state(call,LinphoneCallReleased,"Call released");
573 }else ms_error("call_released() for already destroyed call ?");
576 static void auth_requested(SalOp *h, const char *realm, const char *username){
577 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
578 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
579 LinphoneCall *call=is_a_linphone_call(sal_op_get_user_pointer(h));
581 if (call && call->ping_op==h){
582 /*don't request authentication for ping requests. Their purpose is just to get any
583 * answer to get the Via's received and rport parameters.
585 ms_message("auth_requested(): ignored for ping request.");
589 ms_message("auth_requested() for realm=%s, username=%s",realm,username);
591 if (ai && ai->works==FALSE && ai->usecount>=3){
592 /*case we tried 3 times to authenticate, without success */
593 /*Better is to stop (implemeted below in else statement), and retry later*/
594 if (ms_time(NULL)-ai->last_use_time>30){
595 ai->usecount=0; /*so that we can allow to retry */
599 if (ai && (ai->works || ai->usecount<3)){
601 sai.username=ai->username;
602 sai.userid=ai->userid;
604 sai.password=ai->passwd;
605 ms_message("auth_requested(): authenticating realm=%s, username=%s",realm,username);
606 sal_op_authenticate(h,&sai);
608 ai->last_use_time=ms_time(NULL);
610 if (ai && ai->works==FALSE) {
611 sal_op_cancel_authentication(h);
613 if (lc->vtable.auth_info_requested)
614 lc->vtable.auth_info_requested(lc,realm,username);
618 static void auth_success(SalOp *h, const char *realm, const char *username){
619 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
620 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
622 ms_message("%s/%s authentication works.",realm,username);
627 static void register_success(SalOp *op, bool_t registered){
628 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
629 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
632 if (cfg->deletion_date!=0){
633 ms_message("Registration success for removed proxy config, ignored");
636 linphone_proxy_config_set_error(cfg,LinphoneReasonNone);
637 linphone_proxy_config_set_state(cfg, registered ? LinphoneRegistrationOk : LinphoneRegistrationCleared ,
638 registered ? "Registration sucessful" : "Unregistration done");
639 if (lc->vtable.display_status){
640 if (registered) msg=ms_strdup_printf(_("Registration on %s successful."),sal_op_get_proxy(op));
641 else msg=ms_strdup_printf(_("Unregistration on %s done."),sal_op_get_proxy(op));
642 lc->vtable.display_status(lc,msg);
648 static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details){
649 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
650 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
653 ms_warning("Registration failed for unknown proxy config.");
656 if (cfg->deletion_date!=0){
657 ms_message("Registration failed for removed proxy config, ignored");
661 details=_("no response timeout");
663 if (lc->vtable.display_status) {
664 char *msg=ortp_strdup_printf(_("Registration on %s failed: %s"),sal_op_get_proxy(op),details );
665 lc->vtable.display_status(lc,msg);
668 if (error== SalErrorFailure && reason == SalReasonForbidden) {
669 linphone_proxy_config_set_error(cfg, LinphoneReasonBadCredentials);
670 } else if (error == SalErrorNoResponse) {
671 linphone_proxy_config_set_error(cfg, LinphoneReasonNoResponse);
673 linphone_proxy_config_set_state(cfg,LinphoneRegistrationFailed,details);
674 if (error== SalErrorFailure && reason == SalReasonForbidden) {
675 const char *realm=NULL,*username=NULL;
676 if (sal_op_get_auth_requested(op,&realm,&username)==0){
677 if (lc->vtable.auth_info_requested)
678 lc->vtable.auth_info_requested(lc,realm,username);
683 static void vfu_request(SalOp *op){
685 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
687 ms_warning("VFU request but no call !");
690 if (call->videostream)
691 video_stream_send_vfu(call->videostream);
695 static void dtmf_received(SalOp *op, char dtmf){
696 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
697 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
698 if (lc->vtable.dtmf_received != NULL)
699 lc->vtable.dtmf_received(lc, call, dtmf);
702 static void refer_received(Sal *sal, SalOp *op, const char *referto){
703 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
704 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
706 if (call->refer_to!=NULL){
707 ms_free(call->refer_to);
709 call->refer_to=ms_strdup(referto);
710 call->refer_pending=TRUE;
711 linphone_call_set_state(call,LinphoneCallRefered,"Refered");
712 if (lc->vtable.display_status){
713 char *msg=ms_strdup_printf(_("We are transferred to %s"),referto);
714 lc->vtable.display_status(lc,msg);
717 if (call->state!=LinphoneCallPaused){
718 ms_message("Automatically pausing current call to accept transfer.");
719 linphone_core_pause_call(lc,call);
720 call->was_automatically_paused=TRUE;
721 /*then we will start the refered when the pause is accepted, in order to serialize transactions within the dialog.
722 * Indeed we need to avoid to send a NOTIFY to inform about of state of the refered call while the pause isn't completed.
724 }else linphone_core_start_refered_call(lc,call);
725 }else if (lc->vtable.refer_received){
726 lc->vtable.refer_received(lc,referto);
730 static void text_received(Sal *sal, const char *from, const char *msg){
731 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
732 linphone_core_text_received(lc,from,msg);
735 static void notify(SalOp *op, const char *from, const char *msg){
736 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
737 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
738 ms_message("get a %s notify from %s",msg,from);
739 if(lc->vtable.notify_recv)
740 lc->vtable.notify_recv(lc,call,from,msg);
743 static void notify_presence(SalOp *op, SalSubscribeStatus ss, SalPresenceStatus status, const char *msg){
744 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
745 linphone_notify_recv(lc,op,ss,status);
748 static void subscribe_received(SalOp *op, const char *from){
749 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
750 linphone_subscription_new(lc,op,from);
753 static void subscribe_closed(SalOp *op, const char *from){
754 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
755 linphone_subscription_closed(lc,op);
758 static void ping_reply(SalOp *op){
759 LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
760 ms_message("ping reply !");
762 if (call->state==LinphoneCallOutgoingInit){
763 call->ping_replied=TRUE;
764 linphone_core_proceed_with_invite_if_ready(call->core,call,NULL);
769 ms_warning("ping reply without call attached...");
773 static void notify_refer(SalOp *op, SalReferStatus status){
774 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
775 LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
776 LinphoneCallState cstate;
778 ms_warning("Receiving notify_refer for unknown call.");
783 cstate=LinphoneCallOutgoingProgress;
785 case SalReferSuccess:
786 cstate=LinphoneCallConnected;
789 cstate=LinphoneCallError;
792 cstate=LinphoneCallError;
794 linphone_call_set_transfer_state(call, cstate);
795 if (cstate==LinphoneCallConnected){
796 /*automatically terminate the call as the transfer is complete.*/
797 linphone_core_terminate_call(lc,call);
801 SalCallbacks linphone_sal_callbacks={