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==LinphoneCallStreamsRunning){
306 /*media was running before, the remote as acceted a call modification (that is
307 a reinvite made by us. We must notify the application this reinvite was accepted*/
308 linphone_call_set_state(call, LinphoneCallUpdated, "Call updated");
310 if (call->state==LinphoneCallResuming){
311 if (lc->vtable.display_status){
312 lc->vtable.display_status(lc,_("Call resumed."));
315 if (lc->vtable.display_status){
316 char *tmp=linphone_call_get_remote_address_as_string (call);
317 char *msg=ms_strdup_printf(_("Call answered by %s."),tmp);
318 lc->vtable.display_status(lc,msg);
324 linphone_core_update_streams (lc,call,md);
325 if (!call->current_params.in_conference)
326 lc->current_call=call;
327 linphone_call_set_state(call, LinphoneCallStreamsRunning, "Streams running");
331 ms_error("Incompatible SDP offer received in 200Ok, need to abort the call");
332 linphone_core_abort_call(lc,call,_("Incompatible, check codecs..."));
336 static void call_ack(SalOp *op){
337 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
338 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
340 ms_warning("No call to be ACK'd");
343 if (call->media_pending){
344 SalMediaDescription *md=sal_call_get_final_media_description(op);
345 if (md && !sal_media_description_empty(md)){
346 if (call->state==LinphoneCallStreamsRunning){
347 /*media was running before, the remote as acceted a call modification (that is
348 a reinvite made by us. We must notify the application this reinvite was accepted*/
349 linphone_call_set_state(call, LinphoneCallUpdated, "Call updated");
351 linphone_core_update_streams (lc,call,md);
352 linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)");
355 ms_error("Incompatible SDP response received in ACK, need to abort the call");
356 linphone_core_abort_call(lc,call,"No codec intersection");
362 static void call_accept_update(LinphoneCore *lc, LinphoneCall *call){
363 SalMediaDescription *md;
364 SalMediaDescription *rmd=sal_call_get_remote_media_description(call->op);
365 if ((rmd!=NULL) && (call->ice_session!=NULL)) {
366 linphone_core_update_ice_from_remote_media_description(call,rmd);
367 linphone_core_update_local_media_description_from_ice(call->localdesc,call->ice_session);
369 sal_call_accept(call->op);
370 md=sal_call_get_final_media_description(call->op);
371 if (md && !sal_media_description_empty(md))
372 linphone_core_update_streams(lc,call,md);
375 static void call_resumed(LinphoneCore *lc, LinphoneCall *call){
376 call_accept_update(lc,call);
377 if(lc->vtable.display_status)
378 lc->vtable.display_status(lc,_("We have been resumed."));
379 linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)");
380 linphone_call_set_transfer_state(call, LinphoneCallIdle);
383 static void call_paused_by_remote(LinphoneCore *lc, LinphoneCall *call){
384 call_accept_update(lc,call);
385 /* we are being paused */
386 if(lc->vtable.display_status)
387 lc->vtable.display_status(lc,_("We are paused by other party."));
388 linphone_call_set_state (call,LinphoneCallPausedByRemote,"Call paused by remote");
391 static void call_updated_by_remote(LinphoneCore *lc, LinphoneCall *call){
392 if(lc->vtable.display_status)
393 lc->vtable.display_status(lc,_("Call is updated by remote."));
394 call->defer_update=FALSE;
395 linphone_call_set_state(call, LinphoneCallUpdatedByRemote,"Call updated by remote");
396 if (call->defer_update==FALSE){
397 linphone_core_accept_call_update(lc,call,NULL);
401 /* this callback is called when an incoming re-INVITE modifies the session*/
402 static void call_updating(SalOp *op){
403 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
404 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
405 SalMediaDescription *rmd=sal_call_get_remote_media_description(op);
408 /* case of a reINVITE without SDP */
409 call_accept_update(lc,call);
410 call->media_pending=TRUE;
415 case LinphoneCallPausedByRemote:
416 if (sal_media_description_has_dir(rmd,SalStreamSendRecv) || sal_media_description_has_dir(rmd,SalStreamRecvOnly)){
417 call_resumed(lc,call);
418 }else call_paused_by_remote(lc,call);
420 case LinphoneCallStreamsRunning:
421 case LinphoneCallConnected:
422 if (sal_media_description_has_dir(rmd,SalStreamSendOnly) || sal_media_description_has_dir(rmd,SalStreamInactive)){
423 call_paused_by_remote(lc,call);
425 call_updated_by_remote(lc,call);
429 call_accept_update(lc,call);
433 static void call_terminated(SalOp *op, const char *from){
434 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
435 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
437 if (call==NULL) return;
439 switch(linphone_call_get_state(call)){
440 case LinphoneCallEnd:
441 case LinphoneCallError:
442 ms_warning("call_terminated: ignoring.");
445 case LinphoneCallIncomingReceived:
446 case LinphoneCallIncomingEarlyMedia:
447 call->reason=LinphoneReasonNotAnswered;
452 ms_message("Current call terminated...");
453 //we stop the call only if we have this current call or if we are in call
454 if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls) == 1) || linphone_core_in_call(lc) )) {
455 ring_stop(lc->ringstream);
458 linphone_call_stop_media_streams(call);
459 if (lc->vtable.show!=NULL)
461 if (lc->vtable.display_status!=NULL)
462 lc->vtable.display_status(lc,_("Call terminated."));
464 linphone_call_set_state(call, LinphoneCallEnd,"Call ended");
467 static void call_failure(SalOp *op, SalError error, SalReason sr, const char *details, int code){
468 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
469 char *msg486=_("User is busy.");
470 char *msg480=_("User is temporarily unavailable.");
471 /*char *retrymsg=_("%s. Retry after %i minute(s).");*/
472 char *msg600=_("User does not want to be disturbed.");
473 char *msg603=_("Call declined.");
474 const char *msg=details;
475 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
478 ms_warning("Call faillure reported on already cleaned call ?");
482 if (lc->vtable.show) lc->vtable.show(lc);
484 if (error==SalErrorNoResponse){
485 msg=_("No response.");
486 if (lc->vtable.display_status)
487 lc->vtable.display_status(lc,msg);
488 }else if (error==SalErrorProtocol){
489 msg=details ? details : _("Protocol error.");
490 if (lc->vtable.display_status)
491 lc->vtable.display_status(lc, msg);
492 }else if (error==SalErrorFailure){
494 case SalReasonDeclined:
496 if (lc->vtable.display_status)
497 lc->vtable.display_status(lc,msg603);
501 if (lc->vtable.display_status)
502 lc->vtable.display_status(lc,msg486);
504 case SalReasonRedirect:
506 if (lc->vtable.display_status)
507 lc->vtable.display_status(lc,msg);
509 case SalReasonTemporarilyUnavailable:
511 if (lc->vtable.display_status)
512 lc->vtable.display_status(lc,msg480);
514 case SalReasonNotFound:
515 if (lc->vtable.display_status)
516 lc->vtable.display_status(lc,msg);
518 case SalReasonDoNotDisturb:
520 if (lc->vtable.display_status)
521 lc->vtable.display_status(lc,msg600);
524 //media_encryption_mandatory
525 if (call->params.media_encryption == LinphoneMediaEncryptionSRTP &&
526 !linphone_core_is_media_encryption_mandatory(lc)) {
528 ms_message("Outgoing call failed with SRTP (SAVP) enabled - retrying with AVP");
529 linphone_call_stop_media_streams(call);
530 if (call->state==LinphoneCallOutgoingInit || call->state==LinphoneCallOutgoingProgress){
531 /* clear SRTP local params */
532 call->params.media_encryption = LinphoneMediaEncryptionNone;
533 for(i=0; i<call->localdesc->nstreams; i++) {
534 call->localdesc->streams[i].proto = SalProtoRtpAvp;
535 memset(call->localdesc->streams[i].crypto, 0, sizeof(call->localdesc->streams[i].crypto));
537 linphone_core_start_invite(lc, call);
541 msg=_("Incompatible media parameters.");
542 if (lc->vtable.display_status)
543 lc->vtable.display_status(lc,msg);
546 if (lc->vtable.display_status)
547 lc->vtable.display_status(lc,_("Call failed."));
551 if (lc->ringstream!=NULL) {
552 ring_stop(lc->ringstream);
555 linphone_call_stop_media_streams (call);
556 if (call->referer && linphone_call_get_state(call->referer)==LinphoneCallPaused && call->referer->was_automatically_paused){
557 /*resume to the call that send us the refer automatically*/
558 linphone_core_resume_call(lc,call->referer);
560 if (sr == SalReasonDeclined) {
561 call->reason=LinphoneReasonDeclined;
562 linphone_call_set_state(call,LinphoneCallEnd,"Call declined.");
563 } else if (sr == SalReasonNotFound) {
564 call->reason=LinphoneReasonNotFound;
565 linphone_call_set_state(call,LinphoneCallError,"User not found.");
567 linphone_call_set_state(call,LinphoneCallError,msg);
571 static void call_released(SalOp *op){
572 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
574 linphone_call_set_state(call,LinphoneCallReleased,"Call released");
575 }else ms_error("call_released() for already destroyed call ?");
578 static void auth_requested(SalOp *h, const char *realm, const char *username){
579 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
580 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
581 LinphoneCall *call=is_a_linphone_call(sal_op_get_user_pointer(h));
583 if (call && call->ping_op==h){
584 /*don't request authentication for ping requests. Their purpose is just to get any
585 * answer to get the Via's received and rport parameters.
587 ms_message("auth_requested(): ignored for ping request.");
591 ms_message("auth_requested() for realm=%s, username=%s",realm,username);
593 if (ai && ai->works==FALSE && ai->usecount>=3){
594 /*case we tried 3 times to authenticate, without success */
595 /*Better is to stop (implemeted below in else statement), and retry later*/
596 if (ms_time(NULL)-ai->last_use_time>30){
597 ai->usecount=0; /*so that we can allow to retry */
601 if (ai && (ai->works || ai->usecount<3)){
603 sai.username=ai->username;
604 sai.userid=ai->userid;
606 sai.password=ai->passwd;
607 ms_message("auth_requested(): authenticating realm=%s, username=%s",realm,username);
608 sal_op_authenticate(h,&sai);
610 ai->last_use_time=ms_time(NULL);
612 if (ai && ai->works==FALSE) {
613 sal_op_cancel_authentication(h);
615 if (lc->vtable.auth_info_requested)
616 lc->vtable.auth_info_requested(lc,realm,username);
620 static void auth_success(SalOp *h, const char *realm, const char *username){
621 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
622 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
624 ms_message("%s/%s authentication works.",realm,username);
629 static void register_success(SalOp *op, bool_t registered){
630 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
631 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
634 if (cfg->deletion_date!=0){
635 ms_message("Registration success for removed proxy config, ignored");
638 linphone_proxy_config_set_error(cfg,LinphoneReasonNone);
639 linphone_proxy_config_set_state(cfg, registered ? LinphoneRegistrationOk : LinphoneRegistrationCleared ,
640 registered ? "Registration sucessful" : "Unregistration done");
641 if (lc->vtable.display_status){
642 if (registered) msg=ms_strdup_printf(_("Registration on %s successful."),sal_op_get_proxy(op));
643 else msg=ms_strdup_printf(_("Unregistration on %s done."),sal_op_get_proxy(op));
644 lc->vtable.display_status(lc,msg);
650 static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details){
651 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
652 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
655 ms_warning("Registration failed for unknown proxy config.");
658 if (cfg->deletion_date!=0){
659 ms_message("Registration failed for removed proxy config, ignored");
663 details=_("no response timeout");
665 if (lc->vtable.display_status) {
666 char *msg=ortp_strdup_printf(_("Registration on %s failed: %s"),sal_op_get_proxy(op),details );
667 lc->vtable.display_status(lc,msg);
670 if (error== SalErrorFailure && reason == SalReasonForbidden) {
671 linphone_proxy_config_set_error(cfg, LinphoneReasonBadCredentials);
672 } else if (error == SalErrorNoResponse) {
673 linphone_proxy_config_set_error(cfg, LinphoneReasonNoResponse);
675 linphone_proxy_config_set_state(cfg,LinphoneRegistrationFailed,details);
676 if (error== SalErrorFailure && reason == SalReasonForbidden) {
677 const char *realm=NULL,*username=NULL;
678 if (sal_op_get_auth_requested(op,&realm,&username)==0){
679 if (lc->vtable.auth_info_requested)
680 lc->vtable.auth_info_requested(lc,realm,username);
685 static void vfu_request(SalOp *op){
687 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
689 ms_warning("VFU request but no call !");
692 if (call->videostream)
693 video_stream_send_vfu(call->videostream);
697 static void dtmf_received(SalOp *op, char dtmf){
698 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
699 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
700 if (lc->vtable.dtmf_received != NULL)
701 lc->vtable.dtmf_received(lc, call, dtmf);
704 static void refer_received(Sal *sal, SalOp *op, const char *referto){
705 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
706 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
708 if (call->refer_to!=NULL){
709 ms_free(call->refer_to);
711 call->refer_to=ms_strdup(referto);
712 call->refer_pending=TRUE;
713 linphone_call_set_state(call,LinphoneCallRefered,"Refered");
714 if (lc->vtable.display_status){
715 char *msg=ms_strdup_printf(_("We are transferred to %s"),referto);
716 lc->vtable.display_status(lc,msg);
719 if (call->state!=LinphoneCallPaused){
720 ms_message("Automatically pausing current call to accept transfer.");
721 linphone_core_pause_call(lc,call);
722 call->was_automatically_paused=TRUE;
723 /*then we will start the refered when the pause is accepted, in order to serialize transactions within the dialog.
724 * Indeed we need to avoid to send a NOTIFY to inform about of state of the refered call while the pause isn't completed.
726 }else linphone_core_start_refered_call(lc,call);
727 }else if (lc->vtable.refer_received){
728 lc->vtable.refer_received(lc,referto);
732 static void text_received(Sal *sal, const char *from, const char *msg){
733 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
734 linphone_core_message_received(lc,from,msg,NULL);
736 void message_external_body_received(Sal *sal, const char *from, const char *url) {
737 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
738 linphone_core_message_received(lc,from,NULL,url);
740 static void notify(SalOp *op, const char *from, const char *msg){
741 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
742 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
743 ms_message("get a %s notify from %s",msg,from);
744 if(lc->vtable.notify_recv)
745 lc->vtable.notify_recv(lc,call,from,msg);
748 static void notify_presence(SalOp *op, SalSubscribeStatus ss, SalPresenceStatus status, const char *msg){
749 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
750 linphone_notify_recv(lc,op,ss,status);
753 static void subscribe_received(SalOp *op, const char *from){
754 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
755 linphone_subscription_new(lc,op,from);
758 static void subscribe_closed(SalOp *op, const char *from){
759 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
760 linphone_subscription_closed(lc,op);
763 static void ping_reply(SalOp *op){
764 LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
765 ms_message("ping reply !");
767 if (call->state==LinphoneCallOutgoingInit){
768 call->ping_replied=TRUE;
769 linphone_core_proceed_with_invite_if_ready(call->core,call,NULL);
774 ms_warning("ping reply without call attached...");
778 static void notify_refer(SalOp *op, SalReferStatus status){
779 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
780 LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
781 LinphoneCallState cstate;
783 ms_warning("Receiving notify_refer for unknown call.");
788 cstate=LinphoneCallOutgoingProgress;
790 case SalReferSuccess:
791 cstate=LinphoneCallConnected;
794 cstate=LinphoneCallError;
797 cstate=LinphoneCallError;
799 linphone_call_set_transfer_state(call, cstate);
800 if (cstate==LinphoneCallConnected){
801 /*automatically terminate the call as the transfer is complete.*/
802 linphone_core_terminate_call(lc,call);
806 static LinphoneChatMessageState chatStatusSal2Linphone(SalTextDeliveryStatus status){
808 case SalTextDeliveryInProgress:
809 return LinphoneChatMessageStateInProgress;
810 case SalTextDeliveryDone:
811 return LinphoneChatMessageStateDelivered;
812 case SalTextDeliveryFailed:
813 return LinphoneChatMessageStateNotDelivered;
815 return LinphoneChatMessageStateIdle;
818 static void text_delivery_update(SalOp *op, SalTextDeliveryStatus status){
819 LinphoneChatMessage *chat_msg=(LinphoneChatMessage* )sal_op_get_user_pointer(op);
820 if (chat_msg && chat_msg->cb) {
821 chat_msg->cb(chat_msg
822 ,chatStatusSal2Linphone(status)
825 linphone_chat_message_destroy(chat_msg);
828 SalCallbacks linphone_sal_callbacks={
845 message_external_body_received,
846 text_delivery_update,