callbacks.c 34.1 KB
Newer Older
Simon Morlat's avatar
Simon Morlat committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
linphone
Copyright (C) 2010  Simon MORLAT (simon.morlat@free.fr)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/


#include "sal.h"

#include "linphonecore.h"
#include "private.h"
25
#include "mediastreamer2/mediastream.h"
26
#include "lpconfig.h"
27

jehan's avatar
jehan committed
28
static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details);
Simon Morlat's avatar
Simon Morlat committed
29

30
31
32
33
34
35
36
37
38
39
40
41
42
43
static int media_parameters_changed(LinphoneCall *call, SalMediaDescription *oldmd, SalMediaDescription *newmd) {
	if (call->params.in_conference != call->current_params.in_conference) return SAL_MEDIA_DESCRIPTION_CHANGED;
	if (call->up_bw != linphone_core_get_upload_bandwidth(call->core)) return SAL_MEDIA_DESCRIPTION_CHANGED;
	return sal_media_description_equals(oldmd, newmd);
}

void linphone_core_update_streams_destinations(LinphoneCore *lc, LinphoneCall *call, SalMediaDescription *old_md, SalMediaDescription *new_md) {
	SalStreamDescription *old_audiodesc = NULL;
	SalStreamDescription *old_videodesc = NULL;
	SalStreamDescription *new_audiodesc = NULL;
	SalStreamDescription *new_videodesc = NULL;
	char *rtp_addr, *rtcp_addr;
	int i;

44
	for (i = 0; i < old_md->n_active_streams; i++) {
45
46
47
48
49
50
		if (old_md->streams[i].type == SalAudio) {
			old_audiodesc = &old_md->streams[i];
		} else if (old_md->streams[i].type == SalVideo) {
			old_videodesc = &old_md->streams[i];
		}
	}
51
	for (i = 0; i < new_md->n_active_streams; i++) {
52
53
54
55
56
57
58
59
60
61
		if (new_md->streams[i].type == SalAudio) {
			new_audiodesc = &new_md->streams[i];
		} else if (new_md->streams[i].type == SalVideo) {
			new_videodesc = &new_md->streams[i];
		}
	}
	if (call->audiostream && new_audiodesc) {
		rtp_addr = (new_audiodesc->rtp_addr[0] != '\0') ? new_audiodesc->rtp_addr : new_md->addr;
		rtcp_addr = (new_audiodesc->rtcp_addr[0] != '\0') ? new_audiodesc->rtcp_addr : new_md->addr;
		ms_message("Change audio stream destination: RTP=%s:%d RTCP=%s:%d", rtp_addr, new_audiodesc->rtp_port, rtcp_addr, new_audiodesc->rtcp_port);
Ghislain MARY's avatar
Ghislain MARY committed
62
		rtp_session_set_remote_addr_full(call->audiostream->ms.session, rtp_addr, new_audiodesc->rtp_port, rtcp_addr, new_audiodesc->rtcp_port);
63
64
65
66
67
68
	}
#ifdef VIDEO_ENABLED
	if (call->videostream && new_videodesc) {
		rtp_addr = (new_videodesc->rtp_addr[0] != '\0') ? new_videodesc->rtp_addr : new_md->addr;
		rtcp_addr = (new_videodesc->rtcp_addr[0] != '\0') ? new_videodesc->rtcp_addr : new_md->addr;
		ms_message("Change video stream destination: RTP=%s:%d RTCP=%s:%d", rtp_addr, new_videodesc->rtp_port, rtcp_addr, new_videodesc->rtcp_port);
Ghislain MARY's avatar
Ghislain MARY committed
69
		rtp_session_set_remote_addr_full(call->videostream->ms.session, rtp_addr, new_videodesc->rtp_port, rtcp_addr, new_videodesc->rtcp_port);
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
	}
#endif

	/* Copy address and port values from new_md to old_md since we will keep old_md as resultdesc */
	strcpy(old_md->addr, new_md->addr);
	if (old_audiodesc && new_audiodesc) {
		strcpy(old_audiodesc->rtp_addr, new_audiodesc->rtp_addr);
		strcpy(old_audiodesc->rtcp_addr, new_audiodesc->rtcp_addr);
		old_audiodesc->rtp_port = new_audiodesc->rtp_port;
		old_audiodesc->rtcp_port = new_audiodesc->rtcp_port;
	}
	if (old_videodesc && new_videodesc) {
		strcpy(old_videodesc->rtp_addr, new_videodesc->rtp_addr);
		strcpy(old_videodesc->rtcp_addr, new_videodesc->rtcp_addr);
		old_videodesc->rtp_port = new_videodesc->rtp_port;
		old_videodesc->rtcp_port = new_videodesc->rtcp_port;
	}
Simon Morlat's avatar
Simon Morlat committed
87
88
}

89
90
91
void linphone_core_update_streams(LinphoneCore *lc, LinphoneCall *call, SalMediaDescription *new_md){
	SalMediaDescription *oldmd=call->resultdesc;
	
Simon Morlat's avatar
Simon Morlat committed
92
93
94
95
	if (lc->ringstream!=NULL){
		ring_stop(lc->ringstream);
		lc->ringstream=NULL;
	}
96
97
98
99
100
101
102
	if (new_md!=NULL){
		sal_media_description_ref(new_md);
		call->media_pending=FALSE;
	}else{
		call->media_pending=TRUE;
	}
	call->resultdesc=new_md;
Ghislain MARY's avatar
Ghislain MARY committed
103
	if ((call->audiostream && call->audiostream->ms.ticker) || (call->videostream && call->videostream->ms.ticker)){
104
105
		/* we already started media: check if we really need to restart it*/
		if (oldmd){
106
			int md_changed = media_parameters_changed(call, oldmd, new_md);
107
108
109
110
111
112
113
114
115
116
117
118
119
			if ((md_changed & SAL_MEDIA_DESCRIPTION_CODEC_CHANGED) || call->playing_ringbacktone) {
				ms_message("Media descriptions are different, need to restart the streams.");
			} else {
				if (md_changed == SAL_MEDIA_DESCRIPTION_UNCHANGED) {
					/*as nothing has changed, keep the oldmd */
					call->resultdesc=oldmd;
					sal_media_description_unref(new_md);
					if (call->all_muted){
						ms_message("Early media finished, unmuting inputs...");
						/*we were in early media, now we want to enable real media */
						linphone_call_enable_camera (call,linphone_call_camera_enabled (call));
						if (call->audiostream)
							linphone_core_mute_mic (lc, linphone_core_is_mic_muted(lc));
Simon Morlat's avatar
Simon Morlat committed
120
#ifdef VIDEO_ENABLED
121
122
						if (call->videostream && call->camera_active)
							video_stream_change_camera(call->videostream,lc->video_conf.device );
Simon Morlat's avatar
Simon Morlat committed
123
#endif
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
					}
					ms_message("No need to restart streams, SDP is unchanged.");
					return;
				}
				else {
					if (md_changed & SAL_MEDIA_DESCRIPTION_NETWORK_CHANGED) {
						ms_message("Network parameters have changed, update them.");
						linphone_core_update_streams_destinations(lc, call, oldmd, new_md);
					}
					if (md_changed & SAL_MEDIA_DESCRIPTION_CRYPTO_CHANGED) {
						ms_message("Crypto parameters have changed, update them.");
						linphone_call_update_crypto_parameters(call, oldmd, new_md);
					}
					call->resultdesc = oldmd;
					sal_media_description_unref(new_md);
					return;
140
141
142
143
144
145
146
147
148
149
150
151
152
153
				}
			}
		}
		linphone_call_stop_media_streams (call);
		linphone_call_init_media_streams (call);
	}
	if (oldmd) 
		sal_media_description_unref(oldmd);
	
	if (new_md) {
		bool_t all_muted=FALSE;
		bool_t send_ringbacktone=FALSE;
		
		if (call->audiostream==NULL){
154
			/*this happens after pausing the call locally. The streams are destroyed and then we wait the 200Ok to recreate them*/
155
156
			linphone_call_init_media_streams (call);
		}
157
158
		if (call->state==LinphoneCallIncomingEarlyMedia && linphone_core_get_remote_ringback_tone (lc)!=NULL){
			send_ringbacktone=TRUE;
159
160
		}
		if (call->state==LinphoneCallIncomingEarlyMedia ||
161
162
163
164
165
		    (call->state==LinphoneCallOutgoingEarlyMedia && !call->params.real_early_media)){
			all_muted=TRUE;
		}
		linphone_call_start_media_streams(call,all_muted,send_ringbacktone);
	}
166
167
168
	if (call->state==LinphoneCallPausing && call->paused_by_app && ms_list_size(lc->calls)==1){
		linphone_core_play_named_tone(lc,LinphoneToneCallOnHold);
	}
Simon Morlat's avatar
Simon Morlat committed
169
}
170
#if 0
Simon Morlat's avatar
Simon Morlat committed
171
172
173
174
static bool_t is_duplicate_call(LinphoneCore *lc, const LinphoneAddress *from, const LinphoneAddress *to){
	MSList *elem;
	for(elem=lc->calls;elem!=NULL;elem=elem->next){
		LinphoneCall *call=(LinphoneCall*)elem->data;
175
176
		if (linphone_address_weak_equal(call->log->from,from) &&
		    linphone_address_weak_equal(call->log->to, to)){
Simon Morlat's avatar
Simon Morlat committed
177
178
179
180
181
			return TRUE;
		}
	}
	return FALSE;
}
182
183
#endif

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
static bool_t already_a_call_with_remote_address(const LinphoneCore *lc, const LinphoneAddress *remote) {
	ms_warning(" searching for already_a_call_with_remote_address.");

	MSList *elem;
	for(elem=lc->calls;elem!=NULL;elem=elem->next){
		const LinphoneCall *call=(LinphoneCall*)elem->data;
		const LinphoneAddress *cRemote=linphone_call_get_remote_address(call);
		if (linphone_address_weak_equal(cRemote,remote)) {
			ms_warning("already_a_call_with_remote_address found.");
			return TRUE;
		}
	}
	return FALSE;
}

199
200
201
202
203
204
205
206
207
208
209
210
211
212
static bool_t already_a_call_pending(LinphoneCore *lc){
	MSList *elem;
	for(elem=lc->calls;elem!=NULL;elem=elem->next){
		LinphoneCall *call=(LinphoneCall*)elem->data;
		if (call->state==LinphoneCallIncomingReceived
		    || call->state==LinphoneCallOutgoingInit
		    || call->state==LinphoneCallOutgoingProgress
		    || call->state==LinphoneCallOutgoingEarlyMedia
		    || call->state==LinphoneCallOutgoingRinging){
			return TRUE;
		}
	}
	return FALSE;
}
Simon Morlat's avatar
Simon Morlat committed
213

214
static void call_received(SalOp *h){
215
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
Simon Morlat's avatar
Simon Morlat committed
216
217
	LinphoneCall *call;
	const char *from,*to;
Simon Morlat's avatar
Simon Morlat committed
218
	LinphoneAddress *from_addr, *to_addr;
219
	bool_t prevent_colliding_calls=lp_config_get_int(lc->config,"sip","prevent_colliding_calls",TRUE);
220
	
Simon Morlat's avatar
Simon Morlat committed
221
	/* first check if we can answer successfully to this invite */
222
223
224
225
226
	if (lc->presence_mode==LinphoneStatusBusy ||
	    lc->presence_mode==LinphoneStatusOffline ||
	    lc->presence_mode==LinphoneStatusDoNotDisturb ||
	    lc->presence_mode==LinphoneStatusMoved){
		if (lc->presence_mode==LinphoneStatusBusy )
Simon Morlat's avatar
Simon Morlat committed
227
			sal_call_decline(h,SalReasonBusy,NULL);
228
		else if (lc->presence_mode==LinphoneStatusOffline)
Simon Morlat's avatar
Simon Morlat committed
229
			sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
230
		else if (lc->presence_mode==LinphoneStatusDoNotDisturb)
Simon Morlat's avatar
Simon Morlat committed
231
			sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
232
		else if (lc->alt_contact!=NULL && lc->presence_mode==LinphoneStatusMoved)
Simon Morlat's avatar
Simon Morlat committed
233
			sal_call_decline(h,SalReasonRedirect,lc->alt_contact);
234
		sal_op_release(h);
Simon Morlat's avatar
Simon Morlat committed
235
236
		return;
	}
237
	if (!linphone_core_can_we_add_call(lc)){/*busy*/
Simon Morlat's avatar
Simon Morlat committed
238
		sal_call_decline(h,SalReasonBusy,NULL);
239
		sal_op_release(h);
Simon Morlat's avatar
Simon Morlat committed
240
241
		return;
	}
242
243
	from=sal_op_get_from(h);
	to=sal_op_get_to(h);
Simon Morlat's avatar
Simon Morlat committed
244
245
246
	from_addr=linphone_address_new(from);
	to_addr=linphone_address_new(to);

247
	if ((already_a_call_with_remote_address(lc,from_addr) && prevent_colliding_calls) || already_a_call_pending(lc)){
248
		ms_warning("Receiving another call while one is ringing or initiated, refusing this one with busy message.");
Simon Morlat's avatar
Simon Morlat committed
249
		sal_call_decline(h,SalReasonBusy,NULL);
Simon Morlat's avatar
Simon Morlat committed
250
		sal_op_release(h);
Simon Morlat's avatar
Simon Morlat committed
251
252
253
254
		linphone_address_destroy(from_addr);
		linphone_address_destroy(to_addr);
		return;
	}
Simon Morlat's avatar
Simon Morlat committed
255
	
Simon Morlat's avatar
Simon Morlat committed
256
257
	call=linphone_call_new_incoming(lc,from_addr,to_addr,h);
	
Simon Morlat's avatar
Simon Morlat committed
258
	/* the call is acceptable so we can now add it to our list */
Simon Morlat's avatar
Simon Morlat committed
259
	linphone_core_add_call(lc,call);
260
	linphone_call_ref(call); /*prevent the call from being destroyed while we are notifying, if the user declines within the state callback */
261

262
	if ((linphone_core_get_firewall_policy(lc) == LinphonePolicyUseIce) && (call->ice_session != NULL)) {
263
264
265
		/* Defer ringing until the end of the ICE candidates gathering process. */
		ms_message("Defer ringing to gather ICE candidates");
		return;
266
	}
267
#ifdef BUILD_UPNP
Yann Diorcet's avatar
Yann Diorcet committed
268
269
270
271
272
	if ((linphone_core_get_firewall_policy(lc) == LinphonePolicyUseUpnp) && (call->upnp_session != NULL)) {
		/* Defer ringing until the end of the ICE candidates gathering process. */
		ms_message("Defer ringing to gather uPnP candidates");
		return;
	}
273
#endif //BUILD_UPNP
274

275
	linphone_core_notify_incoming_call(lc,call);
276
277
278
}

static void call_ringing(SalOp *h){
279
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
280
	LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(h);
Simon Morlat's avatar
Simon Morlat committed
281
	SalMediaDescription *md;
282
	
Simon Morlat's avatar
Simon Morlat committed
283
	if (call==NULL) return;
284
	
Simon Morlat's avatar
Simon Morlat committed
285
286
	if (lc->vtable.display_status)
		lc->vtable.display_status(lc,_("Remote ringing."));
287
	
Simon Morlat's avatar
Simon Morlat committed
288
289
	md=sal_call_get_final_media_description(h);
	if (md==NULL){
290
291
292
293
294
		if (lc->ringstream && lc->dmfs_playing_start_time!=0){
			ring_stop(lc->ringstream);
			lc->ringstream=NULL;
			lc->dmfs_playing_start_time=0;
		}
Simon Morlat's avatar
Simon Morlat committed
295
296
		if (lc->ringstream!=NULL) return;	/*already ringing !*/
		if (lc->sound_conf.play_sndcard!=NULL){
297
			MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
298
			if (call->localdesc->streams[0].max_rate>0) ms_snd_card_set_preferred_sample_rate(ringcard, call->localdesc->streams[0].max_rate);
Simon Morlat's avatar
Simon Morlat committed
299
300
301
			/*we release sound before playing ringback tone*/
			if (call->audiostream)
				audio_stream_unprepare_sound(call->audiostream);
302
			lc->ringstream=ring_start(lc->sound_conf.remote_ring,2000,ringcard);
Simon Morlat's avatar
Simon Morlat committed
303
		}
304
305
306
307
		ms_message("Remote ringing...");
		if (lc->vtable.display_status) 
			lc->vtable.display_status(lc,_("Remote ringing..."));
		linphone_call_set_state(call,LinphoneCallOutgoingRinging,"Remote ringing");
Simon Morlat's avatar
Simon Morlat committed
308
309
	}else{
		/*accept early media */
Simon Morlat's avatar
Simon Morlat committed
310
		if (call->audiostream && audio_stream_started(call->audiostream)){
Simon Morlat's avatar
Simon Morlat committed
311
312
313
314
315
316
317
			/*streams already started */
			ms_message("Early media already started.");
			return;
		}
		if (lc->vtable.show) lc->vtable.show(lc);
		if (lc->vtable.display_status) 
			lc->vtable.display_status(lc,_("Early media."));
318
		linphone_call_set_state(call,LinphoneCallOutgoingEarlyMedia,"Early media");
Simon Morlat's avatar
Simon Morlat committed
319
320
321
322
323
		if (lc->ringstream!=NULL){
			ring_stop(lc->ringstream);
			lc->ringstream=NULL;
		}
		ms_message("Doing early media...");
Simon Morlat's avatar
Simon Morlat committed
324
		linphone_core_update_streams(lc,call,md);
Simon Morlat's avatar
Simon Morlat committed
325
	}
326
327
}

Simon Morlat's avatar
Simon Morlat committed
328
329
330
331
332
/*
 * could be reach :
 *  - when the call is accepted
 *  - when a request is accepted (pause, resume)
 */
Simon Morlat's avatar
Simon Morlat committed
333
static void call_accepted(SalOp *op){
334
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
335
	LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
336
337
	SalMediaDescription *md;
	
Simon Morlat's avatar
Simon Morlat committed
338
339
	if (call==NULL){
		ms_warning("No call to accept.");
340
		return ;
Simon Morlat's avatar
Simon Morlat committed
341
	}
342

343
344
345
	/* Handle remote ICE attributes if any. */
	if (call->ice_session != NULL) {
		linphone_core_update_ice_from_remote_media_description(call, sal_call_get_remote_media_description(op));
346
	}
Yann Diorcet's avatar
Yann Diorcet committed
347
348
349
350
351
#ifdef BUILD_UPNP
	if (call->upnp_session != NULL) {
		linphone_core_update_upnp_from_remote_media_description(call, sal_call_get_remote_media_description(op));
	}
#endif //BUILD_UPNP
352

353
	md=sal_call_get_final_media_description(op);
354
	call->params.has_video &= linphone_core_media_description_contains_video_stream(md);
355
	
Simon Morlat's avatar
Simon Morlat committed
356
357
358
359
	if (call->state==LinphoneCallOutgoingProgress ||
	    call->state==LinphoneCallOutgoingRinging ||
	    call->state==LinphoneCallOutgoingEarlyMedia){
		linphone_call_set_state(call,LinphoneCallConnected,"Connected");
360
		if (call->referer) linphone_core_notify_refer_state(lc,call->referer,call);
Simon Morlat's avatar
Simon Morlat committed
361
	}
362
	if (md && !sal_media_description_empty(md) && !linphone_core_incompatible_security(lc,md)){
363
		linphone_call_update_remote_session_id_and_ver(call);
364
365
		if (sal_media_description_has_dir(md,SalStreamSendOnly) ||
		    sal_media_description_has_dir(md,SalStreamInactive)){
Simon Morlat's avatar
Simon Morlat committed
366
367
368
369
370
371
372
			if (lc->vtable.display_status){
				char *tmp=linphone_call_get_remote_address_as_string (call);
				char *msg=ms_strdup_printf(_("Call with %s is paused."),tmp);
				lc->vtable.display_status(lc,msg);
				ms_free(tmp);
				ms_free(msg);
			}
373
			linphone_core_update_streams (lc,call,md);
374
			linphone_call_set_state(call,LinphoneCallPaused,"Call paused");
375
376
			if (call->refer_pending)
				linphone_core_start_refered_call(lc,call);
377
		}else if (sal_media_description_has_dir(md,SalStreamRecvOnly)){
378
379
380
381
382
383
384
385
			/*we are put on hold when the call is initially accepted */
			if (lc->vtable.display_status){
				char *tmp=linphone_call_get_remote_address_as_string (call);
				char *msg=ms_strdup_printf(_("Call answered by %s - on hold."),tmp);
				lc->vtable.display_status(lc,msg);
				ms_free(tmp);
				ms_free(msg);
			}
386
			linphone_core_update_streams (lc,call,md);
387
			linphone_call_set_state(call,LinphoneCallPausedByRemote,"Call paused by remote");
388
		}else{
389
			if (call->state!=LinphoneCallUpdating){
Simon Morlat's avatar
Simon Morlat committed
390
391
392
393
394
395
396
397
398
399
400
401
402
				if (call->state==LinphoneCallResuming){
					if (lc->vtable.display_status){
						lc->vtable.display_status(lc,_("Call resumed."));
					}
				}else{
					if (lc->vtable.display_status){
						char *tmp=linphone_call_get_remote_address_as_string (call);
						char *msg=ms_strdup_printf(_("Call answered by %s."),tmp);
						lc->vtable.display_status(lc,msg);
						ms_free(tmp);
						ms_free(msg);
					}
				}
403
			}
404
			linphone_core_update_streams (lc,call,md);
405
406
			if (!call->current_params.in_conference)
				lc->current_call=call;
407
			linphone_call_set_state(call, LinphoneCallStreamsRunning, "Streams running");
Simon Morlat's avatar
Simon Morlat committed
408
		}
Simon Morlat's avatar
Simon Morlat committed
409
410
411
	}else{
		/*send a bye*/
		ms_error("Incompatible SDP offer received in 200Ok, need to abort the call");
412
		linphone_core_abort_call(lc,call,_("Incompatible, check codecs or security settings..."));
Simon Morlat's avatar
Simon Morlat committed
413
	}
414
415
}

416
417
static void call_ack(SalOp *op){
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
418
	LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
Simon Morlat's avatar
Simon Morlat committed
419
420
421
422
	if (call==NULL){
		ms_warning("No call to be ACK'd");
		return ;
	}
423
	if (call->media_pending){
424
425
426
		SalMediaDescription *md=sal_call_get_final_media_description(op);
		if (md && !sal_media_description_empty(md)){
			linphone_core_update_streams (lc,call,md);
Simon Morlat's avatar
bugfix    
Simon Morlat committed
427
			linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)");
428
429
430
		}else{
			/*send a bye*/
			ms_error("Incompatible SDP response received in ACK, need to abort the call");
431
432
			linphone_core_abort_call(lc,call,"No codec intersection");
			return;
433
		}
Simon Morlat's avatar
Simon Morlat committed
434
	}
435
436
}

437
438
static void call_accept_update(LinphoneCore *lc, LinphoneCall *call){
	SalMediaDescription *md;
439
440
441
442
443
	SalMediaDescription *rmd=sal_call_get_remote_media_description(call->op);
	if ((rmd!=NULL) && (call->ice_session!=NULL)) {
		linphone_core_update_ice_from_remote_media_description(call,rmd);
		linphone_core_update_local_media_description_from_ice(call->localdesc,call->ice_session);
	}
Yann Diorcet's avatar
Yann Diorcet committed
444
445
#ifdef BUILD_UPNP
	if(call->upnp_session != NULL) {
Yann Diorcet's avatar
Yann Diorcet committed
446
		linphone_core_update_upnp_from_remote_media_description(call, rmd);
Yann Diorcet's avatar
Yann Diorcet committed
447
448
		linphone_core_update_local_media_description_from_upnp(call->localdesc,call->upnp_session);
	}
449
#endif //BUILD_UPNP
450
	linphone_call_update_remote_session_id_and_ver(call);
451
452
453
454
455
456
457
458
459
460
461
	sal_call_accept(call->op);
	md=sal_call_get_final_media_description(call->op);
	if (md && !sal_media_description_empty(md))
		linphone_core_update_streams(lc,call,md);
}

static void call_resumed(LinphoneCore *lc, LinphoneCall *call){
	call_accept_update(lc,call);
	if(lc->vtable.display_status)
		lc->vtable.display_status(lc,_("We have been resumed."));
	linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)");
462
	linphone_call_set_transfer_state(call, LinphoneCallIdle);
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
}

static void call_paused_by_remote(LinphoneCore *lc, LinphoneCall *call){
	call_accept_update(lc,call);
	/* we are being paused */
	if(lc->vtable.display_status)
		lc->vtable.display_status(lc,_("We are paused by other party."));
	linphone_call_set_state (call,LinphoneCallPausedByRemote,"Call paused by remote");
}

static void call_updated_by_remote(LinphoneCore *lc, LinphoneCall *call){
	if(lc->vtable.display_status)
		lc->vtable.display_status(lc,_("Call is updated by remote."));
	call->defer_update=FALSE;
	linphone_call_set_state(call, LinphoneCallUpdatedByRemote,"Call updated by remote");
	if (call->defer_update==FALSE){
		linphone_core_accept_call_update(lc,call,NULL);
	}
}
482

483
/* this callback is called when an incoming re-INVITE modifies the session*/
484
static void call_updating(SalOp *op){
485
486
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
	LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
487
	SalMediaDescription *rmd=sal_call_get_remote_media_description(op);
488

489
490
491
492
493
494
495
	if (rmd==NULL){
		/* case of a reINVITE without SDP */
		call_accept_update(lc,call);
		call->media_pending=TRUE;
		return;
	}

496
497
498
499
	switch(call->state){
		case LinphoneCallPausedByRemote:
			if (sal_media_description_has_dir(rmd,SalStreamSendRecv) || sal_media_description_has_dir(rmd,SalStreamRecvOnly)){
				call_resumed(lc,call);
500
			}else call_paused_by_remote(lc,call);
501
502
503
504
505
		break;
		case LinphoneCallStreamsRunning:
		case LinphoneCallConnected:
			if (sal_media_description_has_dir(rmd,SalStreamSendOnly) || sal_media_description_has_dir(rmd,SalStreamInactive)){
				call_paused_by_remote(lc,call);
506
			}else{
507
				call_updated_by_remote(lc,call);
508
			}
509
510
511
		break;
		default:
			call_accept_update(lc,call);
Simon Morlat's avatar
Simon Morlat committed
512
	}
513
514
}

515
516
static void call_terminated(SalOp *op, const char *from){
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
517
	LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
Simon Morlat's avatar
Simon Morlat committed
518
519

	if (call==NULL) return;
520
	
521
522
523
524
525
526
527
528
529
530
531
532
	switch(linphone_call_get_state(call)){
		case LinphoneCallEnd:
		case LinphoneCallError:
			ms_warning("call_terminated: ignoring.");
			return;
		break;
		case LinphoneCallIncomingReceived:
		case LinphoneCallIncomingEarlyMedia:
			call->reason=LinphoneReasonNotAnswered;
		break;
		default:
		break;
Simon Morlat's avatar
Simon Morlat committed
533
534
	}
	ms_message("Current call terminated...");
Simon Morlat's avatar
Simon Morlat committed
535
536
	//we stop the call only if we have this current call or if we are in call
	if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls)  == 1) || linphone_core_in_call(lc) )) {
Simon Morlat's avatar
Simon Morlat committed
537
538
539
		ring_stop(lc->ringstream);
		lc->ringstream=NULL;
	}
540
	linphone_call_stop_media_streams(call);
Simon Morlat's avatar
Simon Morlat committed
541
542
543
544
	if (lc->vtable.show!=NULL)
		lc->vtable.show(lc);
	if (lc->vtable.display_status!=NULL)
		lc->vtable.display_status(lc,_("Call terminated."));
545

Yann Diorcet's avatar
Yann Diorcet committed
546
547
548
549
#ifdef BUILD_UPNP
	linphone_call_delete_upnp_session(call);
#endif //BUILD_UPNP

550
	linphone_call_set_state(call, LinphoneCallEnd,"Call ended");
551
552
}

553
static void call_failure(SalOp *op, SalError error, SalReason sr, const char *details, int code){
554
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
Simon Morlat's avatar
Simon Morlat committed
555
556
557
558
559
	char *msg486=_("User is busy.");
	char *msg480=_("User is temporarily unavailable.");
	/*char *retrymsg=_("%s. Retry after %i minute(s).");*/
	char *msg600=_("User does not want to be disturbed.");
	char *msg603=_("Call declined.");
560
	const char *msg=details;
561
	LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
562

563
564
565
566
567
	if (call==NULL){
		ms_warning("Call faillure reported on already cleaned call ?");
		return ;
	}
	
Simon Morlat's avatar
Simon Morlat committed
568
569
570
	if (lc->vtable.show) lc->vtable.show(lc);

	if (error==SalErrorNoResponse){
571
		msg=_("No response.");
572
		if (lc->vtable.display_status)
573
			lc->vtable.display_status(lc,msg);
Simon Morlat's avatar
Simon Morlat committed
574
	}else if (error==SalErrorProtocol){
575
		msg=details ? details : _("Protocol error.");
576
		if (lc->vtable.display_status)
577
			lc->vtable.display_status(lc, msg);
Simon Morlat's avatar
Simon Morlat committed
578
579
580
	}else if (error==SalErrorFailure){
		switch(sr){
			case SalReasonDeclined:
Simon Morlat's avatar
Simon Morlat committed
581
				msg=msg603;
Simon Morlat's avatar
Simon Morlat committed
582
583
584
585
				if (lc->vtable.display_status)
					lc->vtable.display_status(lc,msg603);
			break;
			case SalReasonBusy:
Simon Morlat's avatar
Simon Morlat committed
586
				msg=msg486;
Simon Morlat's avatar
Simon Morlat committed
587
588
589
590
				if (lc->vtable.display_status)
					lc->vtable.display_status(lc,msg486);
			break;
			case SalReasonRedirect:
Simon Morlat's avatar
Simon Morlat committed
591
				msg=_("Redirected");
Simon Morlat's avatar
Simon Morlat committed
592
				if (lc->vtable.display_status)
Simon Morlat's avatar
Simon Morlat committed
593
					lc->vtable.display_status(lc,msg);
Simon Morlat's avatar
Simon Morlat committed
594
595
			break;
			case SalReasonTemporarilyUnavailable:
Simon Morlat's avatar
Simon Morlat committed
596
				msg=msg480;
Simon Morlat's avatar
Simon Morlat committed
597
598
599
600
601
				if (lc->vtable.display_status)
					lc->vtable.display_status(lc,msg480);
			break;
			case SalReasonNotFound:
				if (lc->vtable.display_status)
Simon Morlat's avatar
Simon Morlat committed
602
					lc->vtable.display_status(lc,msg);
Simon Morlat's avatar
Simon Morlat committed
603
604
			break;
			case SalReasonDoNotDisturb:
Simon Morlat's avatar
Simon Morlat committed
605
				msg=msg600;
Simon Morlat's avatar
Simon Morlat committed
606
607
608
609
				if (lc->vtable.display_status)
					lc->vtable.display_status(lc,msg600);
			break;
			case SalReasonMedia:
610
611
612
613
614
			//media_encryption_mandatory
				if (call->params.media_encryption == LinphoneMediaEncryptionSRTP && 
					!linphone_core_is_media_encryption_mandatory(lc)) {
					int i;
					ms_message("Outgoing call failed with SRTP (SAVP) enabled - retrying with AVP");
615
					linphone_call_stop_media_streams(call);
616
617
618
					if (call->state==LinphoneCallOutgoingInit || call->state==LinphoneCallOutgoingProgress){
						/* clear SRTP local params */
						call->params.media_encryption = LinphoneMediaEncryptionNone;
619
						for(i=0; i<call->localdesc->n_active_streams; i++) {
620
621
622
							call->localdesc->streams[i].proto = SalProtoRtpAvp;
							memset(call->localdesc->streams[i].crypto, 0, sizeof(call->localdesc->streams[i].crypto));
						}
623
						linphone_core_start_invite(lc, call);
624
625
626
					}
					return;
				}
627
				msg=_("Incompatible media parameters.");
Simon Morlat's avatar
Simon Morlat committed
628
				if (lc->vtable.display_status)
Simon Morlat's avatar
Simon Morlat committed
629
					lc->vtable.display_status(lc,msg);
Simon Morlat's avatar
Simon Morlat committed
630
631
632
633
634
635
			break;
			default:
				if (lc->vtable.display_status)
					lc->vtable.display_status(lc,_("Call failed."));
		}
	}
636

Simon Morlat's avatar
Simon Morlat committed
637
638
639
640
	if (lc->ringstream!=NULL) {
		ring_stop(lc->ringstream);
		lc->ringstream=NULL;
	}
641
	linphone_call_stop_media_streams (call);
642
643
644
645
	if (call->referer && linphone_call_get_state(call->referer)==LinphoneCallPaused && call->referer->was_automatically_paused){
		/*resume to the call that send us the refer automatically*/
		linphone_core_resume_call(lc,call->referer);
	}
646
647
648
649
650

#ifdef BUILD_UPNP
	linphone_call_delete_upnp_session(call);
#endif //BUILD_UPNP

651
	if (sr == SalReasonDeclined) {
652
653
		call->reason=LinphoneReasonDeclined;
		linphone_call_set_state(call,LinphoneCallEnd,"Call declined.");
654
655
656
	} else if (sr == SalReasonNotFound) {
		call->reason=LinphoneReasonNotFound;
		linphone_call_set_state(call,LinphoneCallError,"User not found.");
657
658
659
	} else if (sr == SalReasonBusy) {
		call->reason=LinphoneReasonBusy;
		linphone_call_set_state(call,LinphoneCallError,"User is busy.");
660
		linphone_core_play_named_tone(lc,LinphoneToneBusy);
661
662
	} else {
		linphone_call_set_state(call,LinphoneCallError,msg);
663
	}
664
665
}

666
667
static void call_released(SalOp *op){
	LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
668
669
670
	if (call!=NULL){
		linphone_call_set_state(call,LinphoneCallReleased,"Call released");
	}else ms_error("call_released() for already destroyed call ?");
671
672
}

673
static void auth_requested(SalOp *h, const char *realm, const char *username){
674
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
675
	LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
676
677
678
679
680
681
682
683
684
685
	LinphoneCall *call=is_a_linphone_call(sal_op_get_user_pointer(h));

	if (call && call->ping_op==h){
		/*don't request authentication for ping requests. Their purpose is just to get any
		 * answer to get the Via's received and rport parameters.
		 */
		ms_message("auth_requested(): ignored for ping request.");
		return;
	}
	
686
	ms_message("auth_requested() for realm=%s, username=%s",realm,username);
687
688
689
690
691
692
693
694
695

	if (ai && ai->works==FALSE && ai->usecount>=3){
		/*case we tried 3 times to authenticate, without success */
		/*Better is to stop (implemeted below in else statement), and retry later*/
		if (ms_time(NULL)-ai->last_use_time>30){
			ai->usecount=0; /*so that we can allow to retry */
		}
	}
	
696
697
698
699
700
701
	if (ai && (ai->works || ai->usecount<3)){
		SalAuthInfo sai;
		sai.username=ai->username;
		sai.userid=ai->userid;
		sai.realm=ai->realm;
		sai.password=ai->passwd;
702
		ms_message("auth_requested(): authenticating realm=%s, username=%s",realm,username);
703
704
		sal_op_authenticate(h,&sai);
		ai->usecount++;
705
		ai->last_use_time=ms_time(NULL);
706
	}else{
jehan's avatar
jehan committed
707
		if (ai && ai->works==FALSE) {
jehan's avatar
jehan committed
708
			sal_op_cancel_authentication(h);
jehan's avatar
jehan committed
709
		} 
710
711
712
		if (lc->vtable.auth_info_requested)
			lc->vtable.auth_info_requested(lc,realm,username);
	}
713
714
715
}

static void auth_success(SalOp *h, const char *realm, const char *username){
716
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
717
	LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
718
719
	if (ai){
		ms_message("%s/%s authentication works.",realm,username);
720
		ai->works=TRUE;
721
	}
722
723
724
}

static void register_success(SalOp *op, bool_t registered){
725
726
727
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
	LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
	char *msg;
728
	
729
730
731
732
	if (cfg->deletion_date!=0){
		ms_message("Registration success for removed proxy config, ignored");
		return;
	}
733
	linphone_proxy_config_set_error(cfg,LinphoneReasonNone);
734
735
736
	linphone_proxy_config_set_state(cfg, registered ? LinphoneRegistrationOk : LinphoneRegistrationCleared ,
	                                registered ? "Registration sucessful" : "Unregistration done");
	if (lc->vtable.display_status){
737
		if (registered) msg=ms_strdup_printf(_("Registration on %s successful."),sal_op_get_proxy(op));
738
		else msg=ms_strdup_printf(_("Unregistration on %s done."),sal_op_get_proxy(op));
739
		lc->vtable.display_status(lc,msg);
740
741
742
		ms_free(msg);
	}
	
743
744
745
}

static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details){
746
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
747
748
749
750
751
752
	LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);

	if (cfg==NULL){
		ms_warning("Registration failed for unknown proxy config.");
		return ;
	}
753
754
755
756
	if (cfg->deletion_date!=0){
		ms_message("Registration failed for removed proxy config, ignored");
		return;
	}
757
758
759
760
761
762
763
764
	if (details==NULL)
		details=_("no response timeout");
	
	if (lc->vtable.display_status) {
		char *msg=ortp_strdup_printf(_("Registration on %s failed: %s"),sal_op_get_proxy(op),details  );
		lc->vtable.display_status(lc,msg);
		ms_free(msg);
	}
jehan's avatar
jehan committed
765
	if (error== SalErrorFailure && reason == SalReasonForbidden) {
766
		linphone_proxy_config_set_error(cfg, LinphoneReasonBadCredentials);
jehan's avatar
jehan committed
767
	} else if (error == SalErrorNoResponse) {
768
		linphone_proxy_config_set_error(cfg, LinphoneReasonNoResponse);
jehan's avatar
jehan committed
769
	}
770
	linphone_proxy_config_set_state(cfg,LinphoneRegistrationFailed,details);
771
772
773
774
775
776
777
	if (error== SalErrorFailure && reason == SalReasonForbidden) {
		const char *realm=NULL,*username=NULL;
		if (sal_op_get_auth_requested(op,&realm,&username)==0){
			if (lc->vtable.auth_info_requested)
				lc->vtable.auth_info_requested(lc,realm,username);
		}
	}
778
779
780
}

static void vfu_request(SalOp *op){
781
#ifdef VIDEO_ENABLED
782
	LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
783
784
785
786
787
788
	if (call==NULL){
		ms_warning("VFU request but no call !");
		return ;
	}
	if (call->videostream)
		video_stream_send_vfu(call->videostream);
789
#endif
790
791
792
}

static void dtmf_received(SalOp *op, char dtmf){
793
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
794
	LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
795
	if (lc->vtable.dtmf_received != NULL)
796
		lc->vtable.dtmf_received(lc, call, dtmf);
797
798
}

799
800
static void refer_received(Sal *sal, SalOp *op, const char *referto){
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
801
	LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
Simon Morlat's avatar
Simon Morlat committed
802
	if (call){
803
804
805
806
807
		if (call->refer_to!=NULL){
			ms_free(call->refer_to);
		}
		call->refer_to=ms_strdup(referto);
		call->refer_pending=TRUE;
Simon Morlat's avatar
Simon Morlat committed
808
809
810
811
812
813
		linphone_call_set_state(call,LinphoneCallRefered,"Refered");
		if (lc->vtable.display_status){
			char *msg=ms_strdup_printf(_("We are transferred to %s"),referto);
			lc->vtable.display_status(lc,msg);
			ms_free(msg);
		}
Simon Morlat's avatar
Simon Morlat committed
814
815
		if (call->state!=LinphoneCallPaused){
			ms_message("Automatically pausing current call to accept transfer.");
816
			_linphone_core_pause_call(lc,call);
817
			call->was_automatically_paused=TRUE;
818
819
820
821
			/*then we will start the refered when the pause is accepted, in order to serialize transactions within the dialog.
			 * Indeed we need to avoid to send a NOTIFY to inform about of state of the refered call while the pause isn't completed.
			**/
		}else linphone_core_start_refered_call(lc,call);
Simon Morlat's avatar
Simon Morlat committed
822
823
	}else if (lc->vtable.refer_received){
		lc->vtable.refer_received(lc,referto);
824
	}
825
826
}

827
828
static bool_t is_duplicate_msg(LinphoneCore *lc, const char *msg_id){
	MSList *elem=lc->last_recv_msg_ids;
829
	MSList *tail=NULL;
830
831
832
833
834
835
	int i;
	bool_t is_duplicate=FALSE;
	for(i=0;elem!=NULL;elem=elem->next,i++){
		if (strcmp((const char*)elem->data,msg_id)==0){
			is_duplicate=TRUE;
		}
836
		tail=elem;
837
838
839
840
841
	}
	if (!is_duplicate){
		lc->last_recv_msg_ids=ms_list_prepend(lc->last_recv_msg_ids,ms_strdup(msg_id));
	}
	if (i>=10){
842
843
		ms_free(tail->data);
		lc->last_recv_msg_ids=ms_list_remove_link(lc->last_recv_msg_ids,tail);
844
845
	}
	return is_duplicate;
846
}
847
848


849
850
static void text_received(SalOp *op, const SalMessage *msg){
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
851
	if (is_duplicate_msg(lc,msg->message_id)==FALSE){
Simon Morlat's avatar
Simon Morlat committed
852
		linphone_core_message_received(lc,op,msg);
853
	}
854
}
855

856
857
static void notify(SalOp *op, const char *from, const char *msg){
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
858
	LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
859
860
	ms_message("get a %s notify from %s",msg,from);
	if(lc->vtable.notify_recv)
861
		lc->vtable.notify_recv(lc,call,from,msg);
862
863
}

864
static void notify_presence(SalOp *op, SalSubscribeStatus ss, SalPresenceStatus status, const char *msg){
865
866
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
	linphone_notify_recv(lc,op,ss,status);
867
868
869
}

static void subscribe_received(SalOp *op, const char *from){
870
871
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
	linphone_subscription_new(lc,op,from);
872
873
}

874
875
876
static void subscribe_closed(SalOp *op, const char *from){
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
	linphone_subscription_closed(lc,op);
877
878
}

879
880
881
882
static void ping_reply(SalOp *op){
	LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
	ms_message("ping reply !");
	if (call){
883
		if (call->state==LinphoneCallOutgoingInit){
884
885
			call->ping_replied=TRUE;
			linphone_core_proceed_with_invite_if_ready(call->core,call,NULL);
886
887
		}
	}
Simon Morlat's avatar
Simon Morlat committed
888
889
890
891
	else
	{
		ms_warning("ping reply without call attached...");
	}
892
893
}

894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
static void notify_refer(SalOp *op, SalReferStatus status){
	LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
	LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
	LinphoneCallState cstate;
	if (call==NULL) {
		ms_warning("Receiving notify_refer for unknown call.");
		return ;
	}
	switch(status){
		case SalReferTrying:
			cstate=LinphoneCallOutgoingProgress;
		break;
		case SalReferSuccess:
			cstate=LinphoneCallConnected;
		break;
		case SalReferFailed:
			cstate=LinphoneCallError;
		break;
		default:
			cstate=LinphoneCallError;
	}
915
	linphone_call_set_transfer_state(call, cstate);
916
917
918
919
920
921
	if (cstate==LinphoneCallConnected){
		/*automatically terminate the call as the transfer is complete.*/
		linphone_core_terminate_call(lc,call);
	}
}

922
923
924
925
926
927
928
929
930
931
932
933
static LinphoneChatMessageState chatStatusSal2Linphone(SalTextDeliveryStatus status){
	switch(status){
		case SalTextDeliveryInProgress:
			return LinphoneChatMessageStateInProgress;
		case SalTextDeliveryDone:
			return LinphoneChatMessageStateDelivered;
		case SalTextDeliveryFailed:
			return LinphoneChatMessageStateNotDelivered;
	}
	return LinphoneChatMessageStateIdle;
}

jehan's avatar
jehan committed
934
935
936
static int op_equals(LinphoneCall *a, SalOp *b) {
	return a->op !=b; /*return 0 if equals*/
}
937
938
static void text_delivery_update(SalOp *op, SalTextDeliveryStatus status){
	LinphoneChatMessage *chat_msg=(LinphoneChatMessage* )sal_op_get_user_pointer(op);
jehan's avatar
jehan committed
939
940
	const MSList* calls = linphone_core_get_calls(chat_msg->chat_room->lc);
	
Simon Morlat's avatar
Simon Morlat committed
941
942
	chat_msg->state=chatStatusSal2Linphone(status);
	linphone_chat_message_store_state(chat_msg);
943
944
	if (chat_msg && chat_msg->cb) {
		chat_msg->cb(chat_msg
Simon Morlat's avatar
Simon Morlat committed
945
			,chat_msg->state
946
947
948
			,chat_msg->cb_ud);
	}
	linphone_chat_message_destroy(chat_msg);
jehan's avatar
jehan committed
949
950
951
952
953
	
	if (!ms_list_find_custom((MSList*)calls, (MSCompareFunc) op_equals, op)) {
		/*op was only create for messaging purpose, destroying*/
		sal_op_release(op);
	}
954
955
}

956
957
958
959
960
SalCallbacks linphone_sal_callbacks={
	call_received,
	call_ringing,
	call_accepted,
	call_ack,
961
	call_updating,
962
963
	call_terminated,
	call_failure,
964
	call_released,
965
966
967
968
969
970
971
972
	auth_requested,
	auth_success,
	register_success,
	register_failure,
	vfu_request,
	dtmf_received,
	refer_received,
	text_received,
973
	text_delivery_update,
974
	notify,
975
	notify_presence,
976
	notify_refer,
977
	subscribe_received,
978
	subscribe_closed,
979
	ping_reply,
980
981
982
};