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