]> sjero.net Git - linphone/blob - coreapi/callbacks.c
support early media sending for outgoing calls
[linphone] / coreapi / callbacks.c
1 /*
2 linphone
3 Copyright (C) 2010  Simon MORLAT (simon.morlat@free.fr)
4
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.
9
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.
14
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.
18 */
19
20
21 #include "sal.h"
22
23 #include "linphonecore.h"
24 #include "private.h"
25 #include "mediastreamer2/mediastream.h"
26 #include "lpconfig.h"
27
28 static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details);
29
30 void linphone_core_update_streams(LinphoneCore *lc, LinphoneCall *call, SalMediaDescription *new_md){
31         SalMediaDescription *oldmd=call->resultdesc;
32         
33         if (lc->ringstream!=NULL){
34                 ring_stop(lc->ringstream);
35                 lc->ringstream=NULL;
36         }
37         if (new_md!=NULL){
38                 sal_media_description_ref(new_md);
39                 call->media_pending=FALSE;
40         }else{
41                 call->media_pending=TRUE;
42         }
43         call->resultdesc=new_md;
44         if (call->audiostream && call->audiostream->ticker){
45                 /* we already started media: check if we really need to restart it*/
46                 if (oldmd){
47                         if (sal_media_description_equals(oldmd,new_md)){
48                                 sal_media_description_unref(oldmd);
49                                 if (call->all_muted){
50                                         ms_message("Early media finished, unmuting inputs...");
51                                         /*we were in early media, now we want to enable real media */
52                                         linphone_call_enable_camera (call,linphone_call_camera_enabled (call));
53                                         if (call->audiostream)
54                                                 linphone_core_mute_mic (lc, linphone_core_is_mic_muted(lc));
55                                 }
56                                 ms_message("No need to restart streams, SDP is unchanged.");
57                                 return;
58                         }else{
59                                 ms_message("Media descriptions are different, need to restart the streams.");
60                         }
61                 }
62                 linphone_call_stop_media_streams (call);
63                 linphone_call_init_media_streams (call);
64         }
65         if (oldmd) 
66                 sal_media_description_unref(oldmd);
67         
68         if (new_md) {
69                 bool_t all_muted=FALSE;
70                 bool_t send_ringbacktone=FALSE;
71                 
72                 if (call->audiostream==NULL){
73                         /*this happens after pausing the call locally. The streams is destroyed and then we wait the 200Ok to recreate it*/
74                         linphone_call_init_media_streams (call);
75                 }
76                 if (call->state==LinphoneCallIncomingEarlyMedia ||
77                     (call->state==LinphoneCallOutgoingEarlyMedia && !call->params.real_early_media)){
78                         all_muted=TRUE;
79                 }else if (call->state==LinphoneCallIncomingEarlyMedia && linphone_core_get_remote_ringback_tone (lc)!=NULL){
80                         send_ringbacktone=TRUE;
81                 }
82                 linphone_call_start_media_streams(call,all_muted,send_ringbacktone);
83         }
84 }
85
86 static bool_t is_duplicate_call(LinphoneCore *lc, const LinphoneAddress *from, const LinphoneAddress *to){
87         MSList *elem;
88         for(elem=lc->calls;elem!=NULL;elem=elem->next){
89                 LinphoneCall *call=(LinphoneCall*)elem->data;
90                 if (linphone_address_weak_equal(call->log->from,from) &&
91                     linphone_address_weak_equal(call->log->to, to)){
92                         return TRUE;
93                 }
94         }
95         return FALSE;
96 }
97
98 static void call_received(SalOp *h){
99         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
100         char *barmesg;
101         LinphoneCall *call;
102         const char *from,*to;
103         char *tmp;
104         LinphoneAddress *from_parsed;
105         LinphoneAddress *from_addr, *to_addr;
106         SalMediaDescription *md;
107         bool_t propose_early_media=lp_config_get_int(lc->config,"sip","incoming_calls_early_media",FALSE);
108         const char *ringback_tone=linphone_core_get_remote_ringback_tone (lc);
109         
110         /* first check if we can answer successfully to this invite */
111         if (lc->presence_mode==LinphoneStatusBusy ||
112             lc->presence_mode==LinphoneStatusOffline ||
113             lc->presence_mode==LinphoneStatusDoNotDisturb ||
114             lc->presence_mode==LinphoneStatusMoved){
115                 if (lc->presence_mode==LinphoneStatusBusy )
116                         sal_call_decline(h,SalReasonBusy,NULL);
117                 else if (lc->presence_mode==LinphoneStatusOffline)
118                         sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
119                 else if (lc->presence_mode==LinphoneStatusDoNotDisturb)
120                         sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
121                 else if (lc->alt_contact!=NULL && lc->presence_mode==LinphoneStatusMoved)
122                         sal_call_decline(h,SalReasonRedirect,lc->alt_contact);
123                 sal_op_release(h);
124                 return;
125         }
126         if (!linphone_core_can_we_add_call(lc)){/*busy*/
127                 sal_call_decline(h,SalReasonBusy,NULL);
128                 sal_op_release(h);
129                 return;
130         }
131         from=sal_op_get_from(h);
132         to=sal_op_get_to(h);
133         from_addr=linphone_address_new(from);
134         to_addr=linphone_address_new(to);
135
136         if (is_duplicate_call(lc,from_addr,to_addr)){
137                 ms_warning("Receiving duplicated call, refusing this one.");
138                 sal_call_decline(h,SalReasonBusy,NULL);
139                 linphone_address_destroy(from_addr);
140                 linphone_address_destroy(to_addr);
141                 return;
142         }
143         
144         call=linphone_call_new_incoming(lc,from_addr,to_addr,h);
145         sal_call_set_local_media_description(h,call->localdesc);
146         md=sal_call_get_final_media_description(h);
147
148         if (md && sal_media_description_empty(md)){
149                 sal_call_decline(h,SalReasonMedia,NULL);
150                 linphone_call_unref(call);
151                 return;
152         }
153         
154         /* the call is acceptable so we can now add it to our list */
155         linphone_core_add_call(lc,call);
156         
157         from_parsed=linphone_address_new(sal_op_get_from(h));
158         linphone_address_clean(from_parsed);
159         tmp=linphone_address_as_string(from_parsed);
160         linphone_address_destroy(from_parsed);
161         barmesg=ortp_strdup_printf("%s %s%s",tmp,_("is contacting you"),
162             (sal_call_autoanswer_asked(h)) ?_(" and asked autoanswer."):_("."));
163         if (lc->vtable.show) lc->vtable.show(lc);
164         if (lc->vtable.display_status) 
165             lc->vtable.display_status(lc,barmesg);
166
167         /* play the ring if this is the only call*/
168         if (lc->sound_conf.ring_sndcard!=NULL && ms_list_size(lc->calls)==1){
169                 lc->current_call=call;
170                 if (lc->ringstream && lc->dmfs_playing_start_time!=0){
171                         ring_stop(lc->ringstream);
172                         lc->ringstream=NULL;
173                         lc->dmfs_playing_start_time=0;
174                 }
175                 if(lc->ringstream==NULL){
176                         MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
177                         ms_message("Starting local ring...");
178                         lc->ringstream=ring_start(lc->sound_conf.local_ring,2000,ringcard);
179                 }
180                 else
181                 {
182                         ms_message("the local ring is already started");
183                 }
184         }else{
185                 /*TODO : play a tone within the context of the current call */
186         }
187         linphone_call_set_state(call,LinphoneCallIncomingReceived,"Incoming call");
188         
189         sal_call_notify_ringing(h,propose_early_media || ringback_tone!=NULL);
190
191         if (propose_early_media || ringback_tone!=NULL){
192                 linphone_call_set_state(call,LinphoneCallIncomingEarlyMedia,"Incoming call early media");
193                 linphone_core_update_streams(lc,call,md);
194         }
195         ms_free(barmesg);
196         ms_free(tmp);
197         
198         
199         if (sal_call_get_replaces(call->op)!=NULL && lp_config_get_int(lc->config,"sip","auto_answer_replacing_calls",1)){
200                 linphone_core_accept_call(lc,call);
201         }
202 }
203
204 static void call_ringing(SalOp *h){
205         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
206         LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(h);
207         SalMediaDescription *md;
208         
209         if (call==NULL) return;
210         
211         if (lc->vtable.display_status)
212                 lc->vtable.display_status(lc,_("Remote ringing."));
213         
214         md=sal_call_get_final_media_description(h);
215         if (md==NULL){
216                 if (lc->ringstream && lc->dmfs_playing_start_time!=0){
217                         ring_stop(lc->ringstream);
218                         lc->ringstream=NULL;
219                         lc->dmfs_playing_start_time=0;
220                 }
221                 if (lc->ringstream!=NULL) return;       /*already ringing !*/
222                 if (lc->sound_conf.play_sndcard!=NULL){
223                         MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
224                         ms_message("Remote ringing...");
225                         lc->ringstream=ring_start(lc->sound_conf.remote_ring,2000,ringcard);
226                         linphone_call_set_state(call,LinphoneCallOutgoingRinging,"Remote ringing");             
227                 }
228         }else{
229                 /*accept early media */
230                 if (call->audiostream && call->audiostream->ticker!=NULL){
231                         /*streams already started */
232                         ms_message("Early media already started.");
233                         return;
234                 }
235                 if (lc->vtable.show) lc->vtable.show(lc);
236                 if (lc->vtable.display_status) 
237                         lc->vtable.display_status(lc,_("Early media."));
238                 linphone_call_set_state(call,LinphoneCallOutgoingEarlyMedia,"Early media");
239                 if (lc->ringstream!=NULL){
240                         ring_stop(lc->ringstream);
241                         lc->ringstream=NULL;
242                 }
243                 ms_message("Doing early media...");
244                 linphone_core_update_streams (lc,call,md);
245         }
246 }
247
248 /*
249  * could be reach :
250  *  - when the call is accepted
251  *  - when a request is accepted (pause, resume)
252  */
253 static void call_accepted(SalOp *op){
254         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
255         LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
256         SalMediaDescription *md;
257         
258         if (call==NULL){
259                 ms_warning("No call to accept.");
260                 return ;
261         }
262         
263         md=sal_call_get_final_media_description(op);
264         
265         if (call->state==LinphoneCallOutgoingProgress ||
266             call->state==LinphoneCallOutgoingRinging ||
267             call->state==LinphoneCallOutgoingEarlyMedia){
268                 linphone_call_set_state(call,LinphoneCallConnected,"Connected");
269         }
270         if (md && !sal_media_description_empty(md)){
271                 if (sal_media_description_has_dir(md,SalStreamSendOnly) ||
272                     sal_media_description_has_dir(md,SalStreamInactive)){
273                         if (lc->vtable.display_status){
274                                 char *tmp=linphone_call_get_remote_address_as_string (call);
275                                 char *msg=ms_strdup_printf(_("Call with %s is paused."),tmp);
276                                 lc->vtable.display_status(lc,msg);
277                                 ms_free(tmp);
278                                 ms_free(msg);
279                         }
280                         linphone_call_set_state(call,LinphoneCallPaused,"Call paused");
281                 }else if (sal_media_description_has_dir(md,SalStreamRecvOnly)){
282                         /*we are put on hold when the call is initially accepted */
283                         if (lc->vtable.display_status){
284                                 char *tmp=linphone_call_get_remote_address_as_string (call);
285                                 char *msg=ms_strdup_printf(_("Call answered by %s - on hold."),tmp);
286                                 lc->vtable.display_status(lc,msg);
287                                 ms_free(tmp);
288                                 ms_free(msg);
289                         }
290                         linphone_call_set_state(call,LinphoneCallPaused,"Call paused");
291                 }else{
292                         if (lc->vtable.display_status){
293                                 lc->vtable.display_status(lc,_("Call answered - connected."));
294                         }
295                         linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)");
296                 }
297                 linphone_core_update_streams (lc,call,md);
298         }else{
299                 /*send a bye*/
300                 ms_error("Incompatible SDP offer received in 200Ok, need to abort the call");
301                 linphone_core_abort_call(lc,call,"No codec intersection");
302         }
303 }
304
305 static void call_ack(SalOp *op){
306         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
307         LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
308         if (call==NULL){
309                 ms_warning("No call to be ACK'd");
310                 return ;
311         }
312         if (call->media_pending){
313                 SalMediaDescription *md=sal_call_get_final_media_description(op);
314                 if (md && !sal_media_description_empty(md)){
315                         linphone_core_update_streams (lc,call,md);
316                         linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)");
317                 }else{
318                         /*send a bye*/
319                         ms_error("Incompatible SDP response received in ACK, need to abort the call");
320                         linphone_core_abort_call(lc,call,"No codec intersection");
321                         return;
322                 }
323         }
324 }
325
326 /* this callback is called when an incoming re-INVITE modifies the session*/
327 static void call_updating(SalOp *op){
328         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
329         LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
330         LinphoneCallState prevstate=LinphoneCallIdle;
331         SalMediaDescription *md;
332         
333         md=sal_call_get_final_media_description(op);
334         
335         if (md && !sal_media_description_empty(md))
336         {
337                 if ((call->state==LinphoneCallPausedByRemote || call->state==LinphoneCallPaused) &&
338                     sal_media_description_has_dir(md,SalStreamSendRecv) && strcmp(md->addr,"0.0.0.0")!=0){
339                         /*make sure we can be resumed */
340                         if (lc->current_call!=NULL && lc->current_call!=call){
341                                 ms_warning("Attempt to be resumed but already in call with somebody else!");
342                                 /*we are actively running another call, reject with a busy*/
343                                 sal_call_decline (op,SalReasonBusy,NULL);
344                                 return;
345                         }
346                         if(lc->vtable.display_status)
347                                 lc->vtable.display_status(lc,_("We have been resumed..."));
348                         linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)");
349                 }
350                 else if(call->state==LinphoneCallStreamsRunning &&
351                         ( sal_media_description_has_dir(md,SalStreamRecvOnly) 
352                          || sal_media_description_has_dir(md,SalStreamInactive)
353                          || strcmp(md->addr,"0.0.0.0")==0)){
354                         if(lc->vtable.display_status)
355                                 lc->vtable.display_status(lc,_("We are being paused..."));
356                         linphone_call_set_state (call,LinphoneCallPausedByRemote,"Call paused by remote");
357                         if (lc->current_call!=call){
358                                 ms_error("Inconsitency detected: current call is %p but call %p is being paused !",lc->current_call,call);
359                         }
360                 }else{
361                         prevstate=call->state;
362                         linphone_call_set_state(call, LinphoneCallUpdatedByRemote,"Call updated by remote");
363                 }
364                 /*accept the modification (sends a 200Ok)*/
365                 sal_call_accept(op);
366                 linphone_core_update_streams (lc,call,md);
367                 if (prevstate!=LinphoneCallIdle){
368                         linphone_call_set_state (call,prevstate,"Connected (streams running)");
369                 }
370         }
371 }
372
373 static void call_terminated(SalOp *op, const char *from){
374         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
375         LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
376
377         if (call==NULL) return;
378         
379         if (linphone_call_get_state(call)==LinphoneCallEnd || linphone_call_get_state(call)==LinphoneCallError){
380                 ms_warning("call_terminated: ignoring.");
381                 return;
382         }
383         ms_message("Current call terminated...");
384         //we stop the call only if we have this current call or if we are in call
385         if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls)  == 1) || linphone_core_in_call(lc) )) {
386                 ring_stop(lc->ringstream);
387                 lc->ringstream=NULL;
388         }
389         linphone_call_stop_media_streams(call);
390         if (lc->vtable.show!=NULL)
391                 lc->vtable.show(lc);
392         if (lc->vtable.display_status!=NULL)
393                 lc->vtable.display_status(lc,_("Call terminated."));
394
395         linphone_call_set_state(call, LinphoneCallEnd,"Call ended");
396 }
397
398 static void call_failure(SalOp *op, SalError error, SalReason sr, const char *details, int code){
399         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
400         char *msg486=_("User is busy.");
401         char *msg480=_("User is temporarily unavailable.");
402         /*char *retrymsg=_("%s. Retry after %i minute(s).");*/
403         char *msg600=_("User does not want to be disturbed.");
404         char *msg603=_("Call declined.");
405         const char *msg=details;
406         LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
407
408         if (call==NULL){
409                 ms_warning("Call faillure reported on already cleaned call ?");
410                 return ;
411         }
412         
413         if (lc->vtable.show) lc->vtable.show(lc);
414
415         if (error==SalErrorNoResponse){
416                 msg=_("No response.");
417                 if (lc->vtable.display_status)
418                         lc->vtable.display_status(lc,msg);
419         }else if (error==SalErrorProtocol){
420                 msg=details ? details : _("Protocol error.");
421                 if (lc->vtable.display_status)
422                         lc->vtable.display_status(lc, msg);
423         }else if (error==SalErrorFailure){
424                 switch(sr){
425                         case SalReasonDeclined:
426                                 msg=msg603;
427                                 if (lc->vtable.display_status)
428                                         lc->vtable.display_status(lc,msg603);
429                         break;
430                         case SalReasonBusy:
431                                 msg=msg486;
432                                 if (lc->vtable.display_status)
433                                         lc->vtable.display_status(lc,msg486);
434                         break;
435                         case SalReasonRedirect:
436                                 msg=_("Redirected");
437                                 if (lc->vtable.display_status)
438                                         lc->vtable.display_status(lc,msg);
439                         break;
440                         case SalReasonTemporarilyUnavailable:
441                                 msg=msg480;
442                                 if (lc->vtable.display_status)
443                                         lc->vtable.display_status(lc,msg480);
444                         break;
445                         case SalReasonNotFound:
446                                 msg=_("Not found");
447                                 if (lc->vtable.display_status)
448                                         lc->vtable.display_status(lc,msg);
449                         break;
450                         case SalReasonDoNotDisturb:
451                                 msg=msg600;
452                                 if (lc->vtable.display_status)
453                                         lc->vtable.display_status(lc,msg600);
454                         break;
455                         case SalReasonMedia:
456                                 msg=_("No common codecs");
457                                 if (lc->vtable.display_status)
458                                         lc->vtable.display_status(lc,msg);
459                         break;
460                         default:
461                                 if (lc->vtable.display_status)
462                                         lc->vtable.display_status(lc,_("Call failed."));
463                 }
464         }
465
466         if (lc->ringstream!=NULL) {
467                 ring_stop(lc->ringstream);
468                 lc->ringstream=NULL;
469         }
470         linphone_call_stop_media_streams (call);
471         if (sr!=SalReasonDeclined) linphone_call_set_state(call,LinphoneCallError,msg);
472         else{
473                 call->reason=LinphoneReasonDeclined;
474                 linphone_call_set_state(call,LinphoneCallEnd,"Call declined.");
475         }
476 }
477
478 static void auth_requested(SalOp *h, const char *realm, const char *username){
479         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
480         LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
481         ms_message("auth_requested() for realm=%s, username=%s",realm,username);
482         if (ai && (ai->works || ai->usecount<3)){
483                 SalAuthInfo sai;
484                 sai.username=ai->username;
485                 sai.userid=ai->userid;
486                 sai.realm=ai->realm;
487                 sai.password=ai->passwd;
488                 ms_message("auth_requested(): authenticating realm=%s, username=%s",realm,username);
489                 sal_op_authenticate(h,&sai);
490                 ai->usecount++;
491         }else{
492                 if (ai && ai->works==FALSE) {
493                         register_failure(h, SalErrorFailure, SalReasonForbidden, _("Authentication failure"));
494                 } 
495                 if (lc->vtable.auth_info_requested)
496                         lc->vtable.auth_info_requested(lc,realm,username);
497         }
498 }
499
500 static void auth_success(SalOp *h, const char *realm, const char *username){
501         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
502         LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
503         if (ai){
504                 ms_message("%s/%s authentication works.",realm,username);
505                 ai->works=TRUE;
506         }
507 }
508
509 static void register_success(SalOp *op, bool_t registered){
510         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
511         LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
512         char *msg;
513         
514         cfg->registered=registered;
515         linphone_proxy_config_set_error(cfg,LinphoneReasonNone);
516         linphone_proxy_config_set_state(cfg, registered ? LinphoneRegistrationOk : LinphoneRegistrationCleared ,
517                                         registered ? "Registration sucessful" : "Unregistration done");
518         if (lc->vtable.display_status){
519                 if (cfg->registered) msg=ms_strdup_printf(_("Registration on %s successful."),sal_op_get_proxy(op));
520                 else msg=ms_strdup_printf(_("Unregistration on %s done."),sal_op_get_proxy(op));
521                 lc->vtable.display_status(lc,msg);
522                 ms_free(msg);
523         }
524         
525 }
526
527 static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details){
528         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
529         LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
530
531         if (cfg==NULL){
532                 ms_warning("Registration failed for unknown proxy config.");
533                 return ;
534         }
535         if (details==NULL)
536                 details=_("no response timeout");
537         
538         if (lc->vtable.display_status) {
539                 char *msg=ortp_strdup_printf(_("Registration on %s failed: %s"),sal_op_get_proxy(op),details  );
540                 lc->vtable.display_status(lc,msg);
541                 ms_free(msg);
542         }
543         if (error== SalErrorFailure && reason == SalReasonForbidden) {
544                 linphone_proxy_config_set_error(cfg, LinphoneReasonBadCredentials);
545         } else if (error == SalErrorNoResponse) {
546                 linphone_proxy_config_set_error(cfg, LinphoneReasonNoResponse);
547         }
548         linphone_proxy_config_set_state(cfg,LinphoneRegistrationFailed,details);
549 }
550
551 static void vfu_request(SalOp *op){
552 #ifdef VIDEO_ENABLED
553         LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
554         if (call==NULL){
555                 ms_warning("VFU request but no call !");
556                 return ;
557         }
558         if (call->videostream)
559                 video_stream_send_vfu(call->videostream);
560 #endif
561 }
562
563 static void dtmf_received(SalOp *op, char dtmf){
564         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
565         LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
566         if (lc->vtable.dtmf_received != NULL)
567                 lc->vtable.dtmf_received(lc, call, dtmf);
568 }
569
570 static void refer_received(Sal *sal, SalOp *op, const char *referto){
571         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
572         LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
573         if (call){
574                 if (call->refer_to!=NULL){
575                         ms_free(call->refer_to);
576                 }
577                 call->refer_to=ms_strdup(referto);
578                 call->refer_pending=TRUE;
579                 linphone_call_set_state(call,LinphoneCallRefered,"Refered");
580                 if (lc->vtable.display_status){
581                         char *msg=ms_strdup_printf(_("We are transferred to %s"),referto);
582                         lc->vtable.display_status(lc,msg);
583                         ms_free(msg);
584                 }
585                 if (call->state!=LinphoneCallPaused){
586                         ms_message("Automatically pausing current call to accept transfer.");
587                         linphone_core_pause_call(lc,call);
588                 }
589                 linphone_core_start_refered_call(lc,call);
590                 sal_call_accept_refer(op);
591         }else if (lc->vtable.refer_received){
592                 lc->vtable.refer_received(lc,referto);
593                 sal_call_accept_refer(op);
594         }
595 }
596
597 static void text_received(Sal *sal, const char *from, const char *msg){
598         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
599         linphone_core_text_received(lc,from,msg);
600 }
601
602 static void notify(SalOp *op, const char *from, const char *msg){
603         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
604         LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
605         ms_message("get a %s notify from %s",msg,from);
606         if(lc->vtable.notify_recv)
607                 lc->vtable.notify_recv(lc,call,from,msg);
608 }
609
610 static void notify_presence(SalOp *op, SalSubscribeState ss, SalPresenceStatus status, const char *msg){
611         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
612         linphone_notify_recv(lc,op,ss,status);
613 }
614
615 static void subscribe_received(SalOp *op, const char *from){
616         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
617         linphone_subscription_new(lc,op,from);
618 }
619
620 static void subscribe_closed(SalOp *op, const char *from){
621         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
622         linphone_subscription_closed(lc,op);
623 }
624
625 static void internal_message(Sal *sal, const char *msg){
626         LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
627         if (lc->vtable.show)
628                 lc->vtable.show(lc);
629 }
630
631 static void ping_reply(SalOp *op){
632         LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
633         ms_message("ping reply !");
634         if (call){
635                 if (call->state==LinphoneCallOutgoingInit){
636                         linphone_core_start_invite(call->core,call,NULL);
637                 }
638         }
639         else
640         {
641                 ms_warning("ping reply without call attached...");
642         }
643 }
644
645 SalCallbacks linphone_sal_callbacks={
646         call_received,
647         call_ringing,
648         call_accepted,
649         call_ack,
650         call_updating,
651         call_terminated,
652         call_failure,
653         auth_requested,
654         auth_success,
655         register_success,
656         register_failure,
657         vfu_request,
658         dtmf_received,
659         refer_received,
660         text_received,
661         notify,
662         notify_presence,
663         subscribe_received,
664         subscribe_closed,
665         internal_message,
666         ping_reply
667 };
668
669