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);
187 sal_call_set_local_media_description(h,call->localdesc);
189 /* the call is acceptable so we can now add it to our list */
190 linphone_core_add_call(lc,call);
191 linphone_call_ref(call); /*prevent the call from being destroyed while we are notifying, if the user declines within the state callback */
193 if ((linphone_core_get_firewall_policy(lc) == LinphonePolicyUseIce) && (call->ice_session != NULL)) {
194 /* Defer ringing until the end of the ICE candidates gathering process. */
195 ms_message("Defer ringing to gather ICE candidates");
199 linphone_core_notify_incoming_call(lc,call);
202 static void call_ringing(SalOp *h){
203 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
204 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(h);
205 SalMediaDescription *md;
207 if (call==NULL) return;
209 if (lc->vtable.display_status)
210 lc->vtable.display_status(lc,_("Remote ringing."));
212 md=sal_call_get_final_media_description(h);
214 if (lc->ringstream && lc->dmfs_playing_start_time!=0){
215 ring_stop(lc->ringstream);
217 lc->dmfs_playing_start_time=0;
219 if (lc->ringstream!=NULL) return; /*already ringing !*/
220 if (lc->sound_conf.play_sndcard!=NULL){
221 MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
222 if (call->localdesc->streams[0].max_rate>0) ms_snd_card_set_preferred_sample_rate(ringcard, call->localdesc->streams[0].max_rate);
223 /*we release sound before playing ringback tone*/
224 if (call->audiostream)
225 audio_stream_unprepare_sound(call->audiostream);
226 lc->ringstream=ring_start(lc->sound_conf.remote_ring,2000,ringcard);
228 ms_message("Remote ringing...");
229 if (lc->vtable.display_status)
230 lc->vtable.display_status(lc,_("Remote ringing..."));
231 linphone_call_set_state(call,LinphoneCallOutgoingRinging,"Remote ringing");
233 /*accept early media */
234 if (call->audiostream && audio_stream_started(call->audiostream)){
235 /*streams already started */
236 ms_message("Early media already started.");
239 if (lc->vtable.show) lc->vtable.show(lc);
240 if (lc->vtable.display_status)
241 lc->vtable.display_status(lc,_("Early media."));
242 linphone_call_set_state(call,LinphoneCallOutgoingEarlyMedia,"Early media");
243 if (lc->ringstream!=NULL){
244 ring_stop(lc->ringstream);
247 ms_message("Doing early media...");
248 linphone_core_update_streams(lc,call,md);
254 * - when the call is accepted
255 * - when a request is accepted (pause, resume)
257 static void call_accepted(SalOp *op){
258 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
259 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
260 SalMediaDescription *md;
263 ms_warning("No call to accept.");
267 /* Handle remote ICE attributes if any. */
268 if (call->ice_session != NULL) {
269 linphone_core_update_ice_from_remote_media_description(call, sal_call_get_remote_media_description(op));
272 md=sal_call_get_final_media_description(op);
274 if (call->state==LinphoneCallOutgoingProgress ||
275 call->state==LinphoneCallOutgoingRinging ||
276 call->state==LinphoneCallOutgoingEarlyMedia){
277 linphone_call_set_state(call,LinphoneCallConnected,"Connected");
278 if (call->referer) linphone_core_notify_refer_state(lc,call->referer,call);
280 if (md && !sal_media_description_empty(md)){
281 if (sal_media_description_has_dir(md,SalStreamSendOnly) ||
282 sal_media_description_has_dir(md,SalStreamInactive)){
283 if (lc->vtable.display_status){
284 char *tmp=linphone_call_get_remote_address_as_string (call);
285 char *msg=ms_strdup_printf(_("Call with %s is paused."),tmp);
286 lc->vtable.display_status(lc,msg);
290 linphone_core_update_streams (lc,call,md);
291 linphone_call_set_state(call,LinphoneCallPaused,"Call paused");
292 if (call->refer_pending)
293 linphone_core_start_refered_call(lc,call);
294 }else if (sal_media_description_has_dir(md,SalStreamRecvOnly)){
295 /*we are put on hold when the call is initially accepted */
296 if (lc->vtable.display_status){
297 char *tmp=linphone_call_get_remote_address_as_string (call);
298 char *msg=ms_strdup_printf(_("Call answered by %s - on hold."),tmp);
299 lc->vtable.display_status(lc,msg);
303 linphone_core_update_streams (lc,call,md);
304 linphone_call_set_state(call,LinphoneCallPausedByRemote,"Call paused by remote");
306 if (call->state==LinphoneCallStreamsRunning){
307 /*media was running before, the remote as acceted a call modification (that is
308 a reinvite made by us. We must notify the application this reinvite was accepted*/
309 linphone_call_set_state(call, LinphoneCallUpdated, "Call updated");
311 if (call->state==LinphoneCallResuming){
312 if (lc->vtable.display_status){
313 lc->vtable.display_status(lc,_("Call resumed."));
316 if (lc->vtable.display_status){
317 char *tmp=linphone_call_get_remote_address_as_string (call);
318 char *msg=ms_strdup_printf(_("Call answered by %s."),tmp);
319 lc->vtable.display_status(lc,msg);
325 linphone_core_update_streams (lc,call,md);
326 if (!call->current_params.in_conference)
327 lc->current_call=call;
328 linphone_call_set_state(call, LinphoneCallStreamsRunning, "Streams running");
332 ms_error("Incompatible SDP offer received in 200Ok, need to abort the call");
333 linphone_core_abort_call(lc,call,_("Incompatible, check codecs..."));
337 static void call_ack(SalOp *op){
338 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
339 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
341 ms_warning("No call to be ACK'd");
344 if (call->media_pending){
345 SalMediaDescription *md=sal_call_get_final_media_description(op);
346 if (md && !sal_media_description_empty(md)){
347 if (call->state==LinphoneCallStreamsRunning){
348 /*media was running before, the remote as acceted a call modification (that is
349 a reinvite made by us. We must notify the application this reinvite was accepted*/
350 linphone_call_set_state(call, LinphoneCallUpdated, "Call updated");
352 linphone_core_update_streams (lc,call,md);
353 linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)");
356 ms_error("Incompatible SDP response received in ACK, need to abort the call");
357 linphone_core_abort_call(lc,call,"No codec intersection");
363 static void call_accept_update(LinphoneCore *lc, LinphoneCall *call){
364 SalMediaDescription *md;
365 SalMediaDescription *rmd=sal_call_get_remote_media_description(call->op);
366 if ((rmd!=NULL) && (call->ice_session!=NULL)) {
367 linphone_core_update_ice_from_remote_media_description(call,rmd);
368 linphone_core_update_local_media_description_from_ice(call->localdesc,call->ice_session);
370 sal_call_accept(call->op);
371 md=sal_call_get_final_media_description(call->op);
372 if (md && !sal_media_description_empty(md))
373 linphone_core_update_streams(lc,call,md);
376 static void call_resumed(LinphoneCore *lc, LinphoneCall *call){
377 call_accept_update(lc,call);
378 if(lc->vtable.display_status)
379 lc->vtable.display_status(lc,_("We have been resumed."));
380 linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)");
381 linphone_call_set_transfer_state(call, LinphoneCallIdle);
384 static void call_paused_by_remote(LinphoneCore *lc, LinphoneCall *call){
385 call_accept_update(lc,call);
386 /* we are being paused */
387 if(lc->vtable.display_status)
388 lc->vtable.display_status(lc,_("We are paused by other party."));
389 linphone_call_set_state (call,LinphoneCallPausedByRemote,"Call paused by remote");
392 static void call_updated_by_remote(LinphoneCore *lc, LinphoneCall *call){
393 if(lc->vtable.display_status)
394 lc->vtable.display_status(lc,_("Call is updated by remote."));
395 call->defer_update=FALSE;
396 linphone_call_set_state(call, LinphoneCallUpdatedByRemote,"Call updated by remote");
397 if (call->defer_update==FALSE){
398 linphone_core_accept_call_update(lc,call,NULL);
402 /* this callback is called when an incoming re-INVITE modifies the session*/
403 static void call_updating(SalOp *op){
404 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
405 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
406 SalMediaDescription *rmd=sal_call_get_remote_media_description(op);
409 /* case of a reINVITE without SDP */
410 call_accept_update(lc,call);
411 call->media_pending=TRUE;
416 case LinphoneCallPausedByRemote:
417 if (sal_media_description_has_dir(rmd,SalStreamSendRecv) || sal_media_description_has_dir(rmd,SalStreamRecvOnly)){
418 call_resumed(lc,call);
419 }else call_paused_by_remote(lc,call);
421 case LinphoneCallStreamsRunning:
422 case LinphoneCallConnected:
423 if (sal_media_description_has_dir(rmd,SalStreamSendOnly) || sal_media_description_has_dir(rmd,SalStreamInactive)){
424 call_paused_by_remote(lc,call);
426 call_updated_by_remote(lc,call);
430 call_accept_update(lc,call);
434 static void call_terminated(SalOp *op, const char *from){
435 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
436 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
438 if (call==NULL) return;
440 switch(linphone_call_get_state(call)){
441 case LinphoneCallEnd:
442 case LinphoneCallError:
443 ms_warning("call_terminated: ignoring.");
446 case LinphoneCallIncomingReceived:
447 case LinphoneCallIncomingEarlyMedia:
448 call->reason=LinphoneReasonNotAnswered;
453 ms_message("Current call terminated...");
454 //we stop the call only if we have this current call or if we are in call
455 if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls) == 1) || linphone_core_in_call(lc) )) {
456 ring_stop(lc->ringstream);
459 linphone_call_stop_media_streams(call);
460 if (lc->vtable.show!=NULL)
462 if (lc->vtable.display_status!=NULL)
463 lc->vtable.display_status(lc,_("Call terminated."));
465 linphone_call_set_state(call, LinphoneCallEnd,"Call ended");
468 static void call_failure(SalOp *op, SalError error, SalReason sr, const char *details, int code){
469 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
470 char *msg486=_("User is busy.");
471 char *msg480=_("User is temporarily unavailable.");
472 /*char *retrymsg=_("%s. Retry after %i minute(s).");*/
473 char *msg600=_("User does not want to be disturbed.");
474 char *msg603=_("Call declined.");
475 const char *msg=details;
476 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
479 ms_warning("Call faillure reported on already cleaned call ?");
483 if (lc->vtable.show) lc->vtable.show(lc);
485 if (error==SalErrorNoResponse){
486 msg=_("No response.");
487 if (lc->vtable.display_status)
488 lc->vtable.display_status(lc,msg);
489 }else if (error==SalErrorProtocol){
490 msg=details ? details : _("Protocol error.");
491 if (lc->vtable.display_status)
492 lc->vtable.display_status(lc, msg);
493 }else if (error==SalErrorFailure){
495 case SalReasonDeclined:
497 if (lc->vtable.display_status)
498 lc->vtable.display_status(lc,msg603);
502 if (lc->vtable.display_status)
503 lc->vtable.display_status(lc,msg486);
505 case SalReasonRedirect:
507 if (lc->vtable.display_status)
508 lc->vtable.display_status(lc,msg);
510 case SalReasonTemporarilyUnavailable:
512 if (lc->vtable.display_status)
513 lc->vtable.display_status(lc,msg480);
515 case SalReasonNotFound:
516 if (lc->vtable.display_status)
517 lc->vtable.display_status(lc,msg);
519 case SalReasonDoNotDisturb:
521 if (lc->vtable.display_status)
522 lc->vtable.display_status(lc,msg600);
525 //media_encryption_mandatory
526 if (call->params.media_encryption == LinphoneMediaEncryptionSRTP &&
527 !linphone_core_is_media_encryption_mandatory(lc)) {
529 ms_message("Outgoing call failed with SRTP (SAVP) enabled - retrying with AVP");
530 linphone_call_stop_media_streams(call);
531 if (call->state==LinphoneCallOutgoingInit || call->state==LinphoneCallOutgoingProgress){
532 /* clear SRTP local params */
533 call->params.media_encryption = LinphoneMediaEncryptionNone;
534 for(i=0; i<call->localdesc->nstreams; i++) {
535 call->localdesc->streams[i].proto = SalProtoRtpAvp;
536 memset(call->localdesc->streams[i].crypto, 0, sizeof(call->localdesc->streams[i].crypto));
538 linphone_core_start_invite(lc, call, NULL);
542 msg=_("Incompatible media parameters.");
543 if (lc->vtable.display_status)
544 lc->vtable.display_status(lc,msg);
547 if (lc->vtable.display_status)
548 lc->vtable.display_status(lc,_("Call failed."));
552 if (lc->ringstream!=NULL) {
553 ring_stop(lc->ringstream);
556 linphone_call_stop_media_streams (call);
557 if (call->referer && linphone_call_get_state(call->referer)==LinphoneCallPaused && call->referer->was_automatically_paused){
558 /*resume to the call that send us the refer automatically*/
559 linphone_core_resume_call(lc,call->referer);
561 if (sr == SalReasonDeclined) {
562 call->reason=LinphoneReasonDeclined;
563 linphone_call_set_state(call,LinphoneCallEnd,"Call declined.");
564 } else if (sr == SalReasonNotFound) {
565 call->reason=LinphoneReasonNotFound;
566 linphone_call_set_state(call,LinphoneCallError,"User not found.");
568 linphone_call_set_state(call,LinphoneCallError,msg);
572 static void call_released(SalOp *op){
573 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
575 linphone_call_set_state(call,LinphoneCallReleased,"Call released");
576 }else ms_error("call_released() for already destroyed call ?");
579 static void auth_requested(SalOp *h, const char *realm, const char *username){
580 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
581 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
582 LinphoneCall *call=is_a_linphone_call(sal_op_get_user_pointer(h));
584 if (call && call->ping_op==h){
585 /*don't request authentication for ping requests. Their purpose is just to get any
586 * answer to get the Via's received and rport parameters.
588 ms_message("auth_requested(): ignored for ping request.");
592 ms_message("auth_requested() for realm=%s, username=%s",realm,username);
594 if (ai && ai->works==FALSE && ai->usecount>=3){
595 /*case we tried 3 times to authenticate, without success */
596 /*Better is to stop (implemeted below in else statement), and retry later*/
597 if (ms_time(NULL)-ai->last_use_time>30){
598 ai->usecount=0; /*so that we can allow to retry */
602 if (ai && (ai->works || ai->usecount<3)){
604 sai.username=ai->username;
605 sai.userid=ai->userid;
607 sai.password=ai->passwd;
608 ms_message("auth_requested(): authenticating realm=%s, username=%s",realm,username);
609 sal_op_authenticate(h,&sai);
611 ai->last_use_time=ms_time(NULL);
613 if (ai && ai->works==FALSE) {
614 sal_op_cancel_authentication(h);
616 if (lc->vtable.auth_info_requested)
617 lc->vtable.auth_info_requested(lc,realm,username);
621 static void auth_success(SalOp *h, const char *realm, const char *username){
622 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
623 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
625 ms_message("%s/%s authentication works.",realm,username);
630 static void register_success(SalOp *op, bool_t registered){
631 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
632 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
635 if (cfg->deletion_date!=0){
636 ms_message("Registration success for removed proxy config, ignored");
639 linphone_proxy_config_set_error(cfg,LinphoneReasonNone);
640 linphone_proxy_config_set_state(cfg, registered ? LinphoneRegistrationOk : LinphoneRegistrationCleared ,
641 registered ? "Registration sucessful" : "Unregistration done");
642 if (lc->vtable.display_status){
643 if (registered) msg=ms_strdup_printf(_("Registration on %s successful."),sal_op_get_proxy(op));
644 else msg=ms_strdup_printf(_("Unregistration on %s done."),sal_op_get_proxy(op));
645 lc->vtable.display_status(lc,msg);
651 static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details){
652 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
653 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
656 ms_warning("Registration failed for unknown proxy config.");
659 if (cfg->deletion_date!=0){
660 ms_message("Registration failed for removed proxy config, ignored");
664 details=_("no response timeout");
666 if (lc->vtable.display_status) {
667 char *msg=ortp_strdup_printf(_("Registration on %s failed: %s"),sal_op_get_proxy(op),details );
668 lc->vtable.display_status(lc,msg);
671 if (error== SalErrorFailure && reason == SalReasonForbidden) {
672 linphone_proxy_config_set_error(cfg, LinphoneReasonBadCredentials);
673 } else if (error == SalErrorNoResponse) {
674 linphone_proxy_config_set_error(cfg, LinphoneReasonNoResponse);
676 linphone_proxy_config_set_state(cfg,LinphoneRegistrationFailed,details);
677 if (error== SalErrorFailure && reason == SalReasonForbidden) {
678 const char *realm=NULL,*username=NULL;
679 if (sal_op_get_auth_requested(op,&realm,&username)==0){
680 if (lc->vtable.auth_info_requested)
681 lc->vtable.auth_info_requested(lc,realm,username);
686 static void vfu_request(SalOp *op){
688 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
690 ms_warning("VFU request but no call !");
693 if (call->videostream)
694 video_stream_send_vfu(call->videostream);
698 static void dtmf_received(SalOp *op, char dtmf){
699 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
700 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
701 if (lc->vtable.dtmf_received != NULL)
702 lc->vtable.dtmf_received(lc, call, dtmf);
705 static void refer_received(Sal *sal, SalOp *op, const char *referto){
706 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
707 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
709 if (call->refer_to!=NULL){
710 ms_free(call->refer_to);
712 call->refer_to=ms_strdup(referto);
713 call->refer_pending=TRUE;
714 linphone_call_set_state(call,LinphoneCallRefered,"Refered");
715 if (lc->vtable.display_status){
716 char *msg=ms_strdup_printf(_("We are transferred to %s"),referto);
717 lc->vtable.display_status(lc,msg);
720 if (call->state!=LinphoneCallPaused){
721 ms_message("Automatically pausing current call to accept transfer.");
722 linphone_core_pause_call(lc,call);
723 call->was_automatically_paused=TRUE;
724 /*then we will start the refered when the pause is accepted, in order to serialize transactions within the dialog.
725 * Indeed we need to avoid to send a NOTIFY to inform about of state of the refered call while the pause isn't completed.
727 }else linphone_core_start_refered_call(lc,call);
728 }else if (lc->vtable.refer_received){
729 lc->vtable.refer_received(lc,referto);
733 static void text_received(Sal *sal, const char *from, const char *msg){
734 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
735 linphone_core_text_received(lc,from,msg);
738 static void notify(SalOp *op, const char *from, const char *msg){
739 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
740 LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
741 ms_message("get a %s notify from %s",msg,from);
742 if(lc->vtable.notify_recv)
743 lc->vtable.notify_recv(lc,call,from,msg);
746 static void notify_presence(SalOp *op, SalSubscribeStatus ss, SalPresenceStatus status, const char *msg){
747 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
748 linphone_notify_recv(lc,op,ss,status);
751 static void subscribe_received(SalOp *op, const char *from){
752 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
753 linphone_subscription_new(lc,op,from);
756 static void subscribe_closed(SalOp *op, const char *from){
757 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
758 linphone_subscription_closed(lc,op);
761 static void ping_reply(SalOp *op){
762 LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
763 ms_message("ping reply !");
765 if (call->state==LinphoneCallOutgoingInit){
766 call->ping_replied=TRUE;
767 linphone_core_proceed_with_invite_if_ready(call->core,call,NULL);
772 ms_warning("ping reply without call attached...");
776 static void notify_refer(SalOp *op, SalReferStatus status){
777 LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
778 LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
779 LinphoneCallState cstate;
781 ms_warning("Receiving notify_refer for unknown call.");
786 cstate=LinphoneCallOutgoingProgress;
788 case SalReferSuccess:
789 cstate=LinphoneCallConnected;
792 cstate=LinphoneCallError;
795 cstate=LinphoneCallError;
797 linphone_call_set_transfer_state(call, cstate);
798 if (cstate==LinphoneCallConnected){
799 /*automatically terminate the call as the transfer is complete.*/
800 linphone_core_terminate_call(lc,call);
804 static LinphoneChatMessageState chatStatusSal2Linphone(SalTextDeliveryStatus status){
806 case SalTextDeliveryInProgress:
807 return LinphoneChatMessageStateInProgress;
808 case SalTextDeliveryDone:
809 return LinphoneChatMessageStateDelivered;
810 case SalTextDeliveryFailed:
811 return LinphoneChatMessageStateNotDelivered;
813 return LinphoneChatMessageStateIdle;
816 static void text_delivery_update(SalOp *op, SalTextDeliveryStatus status){
817 LinphoneChatMessage *chat_msg=(LinphoneChatMessage* )sal_op_get_user_pointer(op);
818 if (chat_msg && chat_msg->cb) {
819 chat_msg->cb(chat_msg
820 ,chatStatusSal2Linphone(status)
823 linphone_chat_message_destroy(chat_msg);
826 SalCallbacks linphone_sal_callbacks={
843 text_delivery_update,