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));
145 const char *from,*to;
147 LinphoneAddress *from_parsed;
148 LinphoneAddress *from_addr, *to_addr;
149 SalMediaDescription *md;
150 bool_t propose_early_media=lp_config_get_int(lc->config,"sip","incoming_calls_early_media",FALSE);
151 bool_t prevent_colliding_calls=lp_config_get_int(lc->config,"sip","prevent_colliding_calls",TRUE);
152 const char *ringback_tone=linphone_core_get_remote_ringback_tone (lc);
154 /* first check if we can answer successfully to this invite */
155 if (lc->presence_mode==LinphoneStatusBusy ||
156 lc->presence_mode==LinphoneStatusOffline ||
157 lc->presence_mode==LinphoneStatusDoNotDisturb ||
158 lc->presence_mode==LinphoneStatusMoved){
159 if (lc->presence_mode==LinphoneStatusBusy )
160 sal_call_decline(h,SalReasonBusy,NULL);
161 else if (lc->presence_mode==LinphoneStatusOffline)
162 sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
163 else if (lc->presence_mode==LinphoneStatusDoNotDisturb)
164 sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
165 else if (lc->alt_contact!=NULL && lc->presence_mode==LinphoneStatusMoved)
166 sal_call_decline(h,SalReasonRedirect,lc->alt_contact);
170 if (!linphone_core_can_we_add_call(lc)){/*busy*/
171 sal_call_decline(h,SalReasonBusy,NULL);
175 from=sal_op_get_from(h);
177 from_addr=linphone_address_new(from);
178 to_addr=linphone_address_new(to);
180 if ((already_a_call_with_remote_address(lc,from_addr) && prevent_colliding_calls) || already_a_call_pending(lc)){
181 ms_warning("Receiving another call while one is ringing or initiated, refusing this one with busy message.");
182 sal_call_decline(h,SalReasonBusy,NULL);
184 linphone_address_destroy(from_addr);
185 linphone_address_destroy(to_addr);
189 call=linphone_call_new_incoming(lc,from_addr,to_addr,h);
190 sal_call_set_local_media_description(h,call->localdesc);
191 md=sal_call_get_final_media_description(h);
193 if (md && sal_media_description_empty(md)){
194 sal_call_decline(h,SalReasonMedia,NULL);
195 linphone_call_unref(call);
199 /* the call is acceptable so we can now add it to our list */
200 linphone_core_add_call(lc,call);
202 from_parsed=linphone_address_new(sal_op_get_from(h));
203 linphone_address_clean(from_parsed);
204 tmp=linphone_address_as_string(from_parsed);
205 linphone_address_destroy(from_parsed);
206 barmesg=ortp_strdup_printf("%s %s%s",tmp,_("is contacting you"),
207 (sal_call_autoanswer_asked(h)) ?_(" and asked autoanswer."):_("."));
208 if (lc->vtable.show) lc->vtable.show(lc);
209 if (lc->vtable.display_status)
210 lc->vtable.display_status(lc,barmesg);
212 /* play the ring if this is the only call*/
213 if (ms_list_size(lc->calls)==1){
214 lc->current_call=call;
215 if (lc->ringstream && lc->dmfs_playing_start_time!=0){
216 ring_stop(lc->ringstream);
218 lc->dmfs_playing_start_time=0;
220 if (lc->sound_conf.ring_sndcard!=NULL){
221 if(lc->ringstream==NULL && lc->sound_conf.local_ring){
222 MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
223 ms_message("Starting local ring...");
224 lc->ringstream=ring_start(lc->sound_conf.local_ring,2000,ringcard);
228 ms_message("the local ring is already started");
232 /* else play a tone within the context of the current call */
233 call->ringing_beep=TRUE;
234 linphone_core_play_tone(lc);
238 linphone_call_ref(call); /*prevent the call from being destroyed while we are notifying, if the user declines within the state callback */
239 linphone_call_set_state(call,LinphoneCallIncomingReceived,"Incoming call");
241 if (call->state==LinphoneCallIncomingReceived){
242 sal_call_notify_ringing(h,propose_early_media || ringback_tone!=NULL);
244 if (propose_early_media || ringback_tone!=NULL){
245 linphone_call_set_state(call,LinphoneCallIncomingEarlyMedia,"Incoming call early media");
246 md=sal_call_get_final_media_description(h);
247 linphone_core_update_streams(lc,call,md);
249 if (sal_call_get_replaces(call->op)!=NULL && lp_config_get_int(lc->config,"sip","auto_answer_replacing_calls",1)){
250 linphone_core_accept_call(lc,call);
253 linphone_call_unref(call);
259 static void call_ringing(SalOp *h){
260 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
261 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(h);
262 SalMediaDescription *md;
264 if (call==NULL) return;
266 if (lc->vtable.display_status)
267 lc->vtable.display_status(lc,_("Remote ringing."));
269 md=sal_call_get_final_media_description(h);
271 if (lc->ringstream && lc->dmfs_playing_start_time!=0){
272 ring_stop(lc->ringstream);
274 lc->dmfs_playing_start_time=0;
276 if (lc->ringstream!=NULL) return; /*already ringing !*/
277 if (lc->sound_conf.play_sndcard!=NULL){
278 MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
279 if (call->localdesc->streams[0].max_rate>0) ms_snd_card_set_preferred_sample_rate(ringcard, call->localdesc->streams[0].max_rate);
280 /*we release sound before playing ringback tone*/
281 if (call->audiostream)
282 audio_stream_unprepare_sound(call->audiostream);
283 lc->ringstream=ring_start(lc->sound_conf.remote_ring,2000,ringcard);
285 ms_message("Remote ringing...");
286 if (lc->vtable.display_status)
287 lc->vtable.display_status(lc,_("Remote ringing..."));
288 linphone_call_set_state(call,LinphoneCallOutgoingRinging,"Remote ringing");
290 /*accept early media */
291 if (call->audiostream && audio_stream_started(call->audiostream)){
292 /*streams already started */
293 ms_message("Early media already started.");
296 if (lc->vtable.show) lc->vtable.show(lc);
297 if (lc->vtable.display_status)
298 lc->vtable.display_status(lc,_("Early media."));
299 linphone_call_set_state(call,LinphoneCallOutgoingEarlyMedia,"Early media");
300 if (lc->ringstream!=NULL){
301 ring_stop(lc->ringstream);
304 ms_message("Doing early media...");
305 linphone_core_update_streams(lc,call,md);
311 * - when the call is accepted
312 * - when a request is accepted (pause, resume)
314 static void call_accepted(SalOp *op){
315 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
316 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
317 SalMediaDescription *md;
320 ms_warning("No call to accept.");
324 md=sal_call_get_final_media_description(op);
326 if (call->state==LinphoneCallOutgoingProgress ||
327 call->state==LinphoneCallOutgoingRinging ||
328 call->state==LinphoneCallOutgoingEarlyMedia){
329 linphone_call_set_state(call,LinphoneCallConnected,"Connected");
330 if (call->referer) linphone_core_notify_refer_state(lc,call->referer,call);
332 if (md && !sal_media_description_empty(md)){
333 if (sal_media_description_has_dir(md,SalStreamSendOnly) ||
334 sal_media_description_has_dir(md,SalStreamInactive)){
335 if (lc->vtable.display_status){
336 char *tmp=linphone_call_get_remote_address_as_string (call);
337 char *msg=ms_strdup_printf(_("Call with %s is paused."),tmp);
338 lc->vtable.display_status(lc,msg);
342 linphone_core_update_streams (lc,call,md);
343 linphone_call_set_state(call,LinphoneCallPaused,"Call paused");
344 if (call->refer_pending)
345 linphone_core_start_refered_call(lc,call);
346 }else if (sal_media_description_has_dir(md,SalStreamRecvOnly)){
347 /*we are put on hold when the call is initially accepted */
348 if (lc->vtable.display_status){
349 char *tmp=linphone_call_get_remote_address_as_string (call);
350 char *msg=ms_strdup_printf(_("Call answered by %s - on hold."),tmp);
351 lc->vtable.display_status(lc,msg);
355 linphone_core_update_streams (lc,call,md);
356 linphone_call_set_state(call,LinphoneCallPausedByRemote,"Call paused by remote");
358 if (call->state==LinphoneCallStreamsRunning){
359 /*media was running before, the remote as acceted a call modification (that is
360 a reinvite made by us. We must notify the application this reinvite was accepted*/
361 linphone_call_set_state(call, LinphoneCallUpdated, "Call updated");
363 if (call->state==LinphoneCallResuming){
364 if (lc->vtable.display_status){
365 lc->vtable.display_status(lc,_("Call resumed."));
368 if (lc->vtable.display_status){
369 char *tmp=linphone_call_get_remote_address_as_string (call);
370 char *msg=ms_strdup_printf(_("Call answered by %s."),tmp);
371 lc->vtable.display_status(lc,msg);
377 linphone_core_update_streams (lc,call,md);
378 if (!call->current_params.in_conference)
379 lc->current_call=call;
380 linphone_call_set_state(call, LinphoneCallStreamsRunning, "Streams running");
384 ms_error("Incompatible SDP offer received in 200Ok, need to abort the call");
385 linphone_core_abort_call(lc,call,_("Incompatible, check codecs..."));
389 static void call_ack(SalOp *op){
390 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
391 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
393 ms_warning("No call to be ACK'd");
396 if (call->media_pending){
397 SalMediaDescription *md=sal_call_get_final_media_description(op);
398 if (md && !sal_media_description_empty(md)){
399 if (call->state==LinphoneCallStreamsRunning){
400 /*media was running before, the remote as acceted a call modification (that is
401 a reinvite made by us. We must notify the application this reinvite was accepted*/
402 linphone_call_set_state(call, LinphoneCallUpdated, "Call updated");
404 linphone_core_update_streams (lc,call,md);
405 linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)");
408 ms_error("Incompatible SDP response received in ACK, need to abort the call");
409 linphone_core_abort_call(lc,call,"No codec intersection");
415 static void call_accept_update(LinphoneCore *lc, LinphoneCall *call){
416 SalMediaDescription *md;
417 sal_call_accept(call->op);
418 md=sal_call_get_final_media_description(call->op);
419 if (md && !sal_media_description_empty(md))
420 linphone_core_update_streams(lc,call,md);
423 static void call_resumed(LinphoneCore *lc, LinphoneCall *call){
424 call_accept_update(lc,call);
425 if(lc->vtable.display_status)
426 lc->vtable.display_status(lc,_("We have been resumed."));
427 linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)");
428 linphone_call_set_transfer_state(call, LinphoneCallIdle);
431 static void call_paused_by_remote(LinphoneCore *lc, LinphoneCall *call){
432 call_accept_update(lc,call);
433 /* we are being paused */
434 if(lc->vtable.display_status)
435 lc->vtable.display_status(lc,_("We are paused by other party."));
436 linphone_call_set_state (call,LinphoneCallPausedByRemote,"Call paused by remote");
439 static void call_updated_by_remote(LinphoneCore *lc, LinphoneCall *call){
440 if(lc->vtable.display_status)
441 lc->vtable.display_status(lc,_("Call is updated by remote."));
442 call->defer_update=FALSE;
443 linphone_call_set_state(call, LinphoneCallUpdatedByRemote,"Call updated by remote");
444 if (call->defer_update==FALSE){
445 linphone_core_accept_call_update(lc,call,NULL);
449 /* this callback is called when an incoming re-INVITE modifies the session*/
450 static void call_updating(SalOp *op){
451 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
452 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
453 SalMediaDescription *rmd=sal_call_get_remote_media_description(op);
456 /* case of a reINVITE without SDP */
457 call_accept_update(lc,call);
458 call->media_pending=TRUE;
463 case LinphoneCallPausedByRemote:
464 if (sal_media_description_has_dir(rmd,SalStreamSendRecv) || sal_media_description_has_dir(rmd,SalStreamRecvOnly)){
465 call_resumed(lc,call);
468 case LinphoneCallStreamsRunning:
469 case LinphoneCallConnected:
470 if (sal_media_description_has_dir(rmd,SalStreamSendOnly) || sal_media_description_has_dir(rmd,SalStreamInactive)){
471 call_paused_by_remote(lc,call);
473 call_updated_by_remote(lc,call);
477 call_accept_update(lc,call);
481 static void call_terminated(SalOp *op, const char *from){
482 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
483 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
485 if (call==NULL) return;
487 if (linphone_call_get_state(call)==LinphoneCallEnd || linphone_call_get_state(call)==LinphoneCallError){
488 ms_warning("call_terminated: ignoring.");
491 ms_message("Current call terminated...");
492 //we stop the call only if we have this current call or if we are in call
493 if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls) == 1) || linphone_core_in_call(lc) )) {
494 ring_stop(lc->ringstream);
497 linphone_call_stop_media_streams(call);
498 if (lc->vtable.show!=NULL)
500 if (lc->vtable.display_status!=NULL)
501 lc->vtable.display_status(lc,_("Call terminated."));
503 linphone_call_set_state(call, LinphoneCallEnd,"Call ended");
506 static void call_failure(SalOp *op, SalError error, SalReason sr, const char *details, int code){
507 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
508 char *msg486=_("User is busy.");
509 char *msg480=_("User is temporarily unavailable.");
510 /*char *retrymsg=_("%s. Retry after %i minute(s).");*/
511 char *msg600=_("User does not want to be disturbed.");
512 char *msg603=_("Call declined.");
513 const char *msg=details;
514 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
517 ms_warning("Call faillure reported on already cleaned call ?");
521 if (lc->vtable.show) lc->vtable.show(lc);
523 if (error==SalErrorNoResponse){
524 msg=_("No response.");
525 if (lc->vtable.display_status)
526 lc->vtable.display_status(lc,msg);
527 }else if (error==SalErrorProtocol){
528 msg=details ? details : _("Protocol error.");
529 if (lc->vtable.display_status)
530 lc->vtable.display_status(lc, msg);
531 }else if (error==SalErrorFailure){
533 case SalReasonDeclined:
535 if (lc->vtable.display_status)
536 lc->vtable.display_status(lc,msg603);
540 if (lc->vtable.display_status)
541 lc->vtable.display_status(lc,msg486);
543 case SalReasonRedirect:
545 if (lc->vtable.display_status)
546 lc->vtable.display_status(lc,msg);
548 case SalReasonTemporarilyUnavailable:
550 if (lc->vtable.display_status)
551 lc->vtable.display_status(lc,msg480);
553 case SalReasonNotFound:
554 if (lc->vtable.display_status)
555 lc->vtable.display_status(lc,msg);
557 case SalReasonDoNotDisturb:
559 if (lc->vtable.display_status)
560 lc->vtable.display_status(lc,msg600);
563 //media_encryption_mandatory
564 if (call->params.media_encryption == LinphoneMediaEncryptionSRTP &&
565 !linphone_core_is_media_encryption_mandatory(lc)) {
567 ms_message("Outgoing call failed with SRTP (SAVP) enabled - retrying with AVP");
568 linphone_call_stop_media_streams(call);
569 if (call->state==LinphoneCallOutgoingInit || call->state==LinphoneCallOutgoingProgress){
570 /* clear SRTP local params */
571 call->params.media_encryption = LinphoneMediaEncryptionNone;
572 for(i=0; i<call->localdesc->nstreams; i++) {
573 call->localdesc->streams[i].proto = SalProtoRtpAvp;
574 memset(call->localdesc->streams[i].crypto, 0, sizeof(call->localdesc->streams[i].crypto));
576 linphone_core_start_invite(lc, call, NULL);
580 msg=_("Incompatible media parameters.");
581 if (lc->vtable.display_status)
582 lc->vtable.display_status(lc,msg);
585 if (lc->vtable.display_status)
586 lc->vtable.display_status(lc,_("Call failed."));
590 if (lc->ringstream!=NULL) {
591 ring_stop(lc->ringstream);
594 linphone_call_stop_media_streams (call);
595 if (call->referer && linphone_call_get_state(call->referer)==LinphoneCallPaused && call->referer->was_automatically_paused){
596 /*resume to the call that send us the refer automatically*/
597 linphone_core_resume_call(lc,call->referer);
599 if (sr == SalReasonDeclined) {
600 call->reason=LinphoneReasonDeclined;
601 linphone_call_set_state(call,LinphoneCallEnd,"Call declined.");
602 } else if (sr == SalReasonNotFound) {
603 call->reason=LinphoneReasonNotFound;
604 linphone_call_set_state(call,LinphoneCallError,"User not found.");
606 linphone_call_set_state(call,LinphoneCallError,msg);
610 static void call_released(SalOp *op){
611 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
613 linphone_call_set_state(call,LinphoneCallReleased,"Call released");
614 }else ms_error("call_released() for already destroyed call ?");
617 static void auth_requested(SalOp *h, const char *realm, const char *username){
618 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
619 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
620 LinphoneCall *call=is_a_linphone_call(sal_op_get_user_pointer(h));
622 if (call && call->ping_op==h){
623 /*don't request authentication for ping requests. Their purpose is just to get any
624 * answer to get the Via's received and rport parameters.
626 ms_message("auth_requested(): ignored for ping request.");
630 ms_message("auth_requested() for realm=%s, username=%s",realm,username);
632 if (ai && ai->works==FALSE && ai->usecount>=3){
633 /*case we tried 3 times to authenticate, without success */
634 /*Better is to stop (implemeted below in else statement), and retry later*/
635 if (ms_time(NULL)-ai->last_use_time>30){
636 ai->usecount=0; /*so that we can allow to retry */
640 if (ai && (ai->works || ai->usecount<3)){
642 sai.username=ai->username;
643 sai.userid=ai->userid;
645 sai.password=ai->passwd;
646 ms_message("auth_requested(): authenticating realm=%s, username=%s",realm,username);
647 sal_op_authenticate(h,&sai);
649 ai->last_use_time=ms_time(NULL);
651 if (ai && ai->works==FALSE) {
652 sal_op_cancel_authentication(h);
654 if (lc->vtable.auth_info_requested)
655 lc->vtable.auth_info_requested(lc,realm,username);
659 static void auth_success(SalOp *h, const char *realm, const char *username){
660 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
661 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
663 ms_message("%s/%s authentication works.",realm,username);
668 static void register_success(SalOp *op, bool_t registered){
669 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
670 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
673 if (cfg->deletion_date!=0){
674 ms_message("Registration success for removed proxy config, ignored");
677 linphone_proxy_config_set_error(cfg,LinphoneReasonNone);
678 linphone_proxy_config_set_state(cfg, registered ? LinphoneRegistrationOk : LinphoneRegistrationCleared ,
679 registered ? "Registration sucessful" : "Unregistration done");
680 if (lc->vtable.display_status){
681 if (registered) msg=ms_strdup_printf(_("Registration on %s successful."),sal_op_get_proxy(op));
682 else msg=ms_strdup_printf(_("Unregistration on %s done."),sal_op_get_proxy(op));
683 lc->vtable.display_status(lc,msg);
689 static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details){
690 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
691 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
694 ms_warning("Registration failed for unknown proxy config.");
697 if (cfg->deletion_date!=0){
698 ms_message("Registration failed for removed proxy config, ignored");
702 details=_("no response timeout");
704 if (lc->vtable.display_status) {
705 char *msg=ortp_strdup_printf(_("Registration on %s failed: %s"),sal_op_get_proxy(op),details );
706 lc->vtable.display_status(lc,msg);
709 if (error== SalErrorFailure && reason == SalReasonForbidden) {
710 linphone_proxy_config_set_error(cfg, LinphoneReasonBadCredentials);
711 } else if (error == SalErrorNoResponse) {
712 linphone_proxy_config_set_error(cfg, LinphoneReasonNoResponse);
714 linphone_proxy_config_set_state(cfg,LinphoneRegistrationFailed,details);
715 if (error== SalErrorFailure && reason == SalReasonForbidden) {
716 const char *realm=NULL,*username=NULL;
717 if (sal_op_get_auth_requested(op,&realm,&username)==0){
718 if (lc->vtable.auth_info_requested)
719 lc->vtable.auth_info_requested(lc,realm,username);
724 static void vfu_request(SalOp *op){
726 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
728 ms_warning("VFU request but no call !");
731 if (call->videostream)
732 video_stream_send_vfu(call->videostream);
736 static void dtmf_received(SalOp *op, char dtmf){
737 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
738 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
739 if (lc->vtable.dtmf_received != NULL)
740 lc->vtable.dtmf_received(lc, call, dtmf);
743 static void refer_received(Sal *sal, SalOp *op, const char *referto){
744 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
745 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
747 if (call->refer_to!=NULL){
748 ms_free(call->refer_to);
750 call->refer_to=ms_strdup(referto);
751 call->refer_pending=TRUE;
752 linphone_call_set_state(call,LinphoneCallRefered,"Refered");
753 if (lc->vtable.display_status){
754 char *msg=ms_strdup_printf(_("We are transferred to %s"),referto);
755 lc->vtable.display_status(lc,msg);
758 if (call->state!=LinphoneCallPaused){
759 ms_message("Automatically pausing current call to accept transfer.");
760 linphone_core_pause_call(lc,call);
761 call->was_automatically_paused=TRUE;
762 /*then we will start the refered when the pause is accepted, in order to serialize transactions within the dialog.
763 * Indeed we need to avoid to send a NOTIFY to inform about of state of the refered call while the pause isn't completed.
765 }else linphone_core_start_refered_call(lc,call);
766 }else if (lc->vtable.refer_received){
767 lc->vtable.refer_received(lc,referto);
771 static void text_received(Sal *sal, const char *from, const char *msg){
772 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
773 linphone_core_text_received(lc,from,msg);
776 static void notify(SalOp *op, const char *from, const char *msg){
777 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
778 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
779 ms_message("get a %s notify from %s",msg,from);
780 if(lc->vtable.notify_recv)
781 lc->vtable.notify_recv(lc,call,from,msg);
784 static void notify_presence(SalOp *op, SalSubscribeStatus ss, SalPresenceStatus status, const char *msg){
785 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
786 linphone_notify_recv(lc,op,ss,status);
789 static void subscribe_received(SalOp *op, const char *from){
790 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
791 linphone_subscription_new(lc,op,from);
794 static void subscribe_closed(SalOp *op, const char *from){
795 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
796 linphone_subscription_closed(lc,op);
799 static void ping_reply(SalOp *op){
800 LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
801 ms_message("ping reply !");
803 if (call->state==LinphoneCallOutgoingInit){
804 linphone_core_start_invite(call->core,call,NULL);
809 ms_warning("ping reply without call attached...");
813 static void notify_refer(SalOp *op, SalReferStatus status){
814 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
815 LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
816 LinphoneCallState cstate;
818 ms_warning("Receiving notify_refer for unknown call.");
823 cstate=LinphoneCallOutgoingProgress;
825 case SalReferSuccess:
826 cstate=LinphoneCallConnected;
829 cstate=LinphoneCallError;
832 cstate=LinphoneCallError;
834 linphone_call_set_transfer_state(call, cstate);
835 if (cstate==LinphoneCallConnected){
836 /*automatically terminate the call as the transfer is complete.*/
837 linphone_core_terminate_call(lc,call);
841 SalCallbacks linphone_sal_callbacks={