56
49
#define REMOTE_RING_US "ringback.wav"
59
/* these are useful messages for the status */
68
void lc_callback_obj_init(LCCallbackObj *obj,LinphoneCoreCbFunc func,gpointer ud)
52
sdp_handler_t linphone_sdphandler={
53
linphone_accept_audio_offer, /*from remote sdp */
54
linphone_accept_video_offer, /*from remote sdp */
55
linphone_set_audio_offer, /*to local sdp */
56
linphone_set_video_offer, /*to local sdp */
57
linphone_read_audio_answer, /*from incoming answer */
58
linphone_read_video_answer /*from incoming answer */
61
void lc_callback_obj_init(LCCallbackObj *obj,LinphoneCoreCbFunc func,void* ud)
71
64
obj->_user_data=ud;
74
gint lc_callback_obj_invoke(LCCallbackObj *obj, LinphoneCore *lc){
67
int lc_callback_obj_invoke(LCCallbackObj *obj, LinphoneCore *lc){
75
68
if (obj->_func!=NULL) obj->_func(lc,obj->_user_data);
79
LinphoneDialogParams * linphone_dialog_params_new()
81
return g_new0(LinphoneDialogParams,1);
84
void linphone_dialog_params_destroy(LinphoneDialogParams *obj)
86
if (obj->profile!=&av_profile) rtp_profile_destroy(obj->profile);
91
#ifdef LINPHONE_DEPRECATED
92
/* this is the retrieve_if function for FreeBSD. It uses getifaddrs system call instead of ioctl in order to get interface names and address.*/
93
/* Thanks to Wolfgang for this .*/
94
#ifdef HAVE_GETIFADDRS
95
#include <sys/types.h>
96
#include <sys/socket.h>
103
struct ifaddrs *ifpstart;
104
GList *interfaces=NULL;
106
if (getifaddrs (&ifpstart) < 0)
111
for (i = 0; ifp != NULL; ifp = ifp->ifa_next)
115
char namebuf[BUFSIZ];
120
switch (ifp->ifa_addr->sa_family) {
122
getnameinfo(ifp->ifa_addr, sizeof (struct sockaddr_in) ,
123
namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
124
netif=g_new0(interface_t,1);
126
netif->family = AF_INET;
127
strncpy (netif->name, ifp->ifa_name,20);
128
strncpy (netif->ipaddr, namebuf,20);
129
interfaces=g_list_append(interfaces,netif);
133
getnameinfo(ifp->ifa_addr, sizeof (struct sockaddr_in6) ,
134
namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
135
if (strchr(namebuf, '%') == NULL) {
136
netif=g_new0(interface_t,1);
138
netif->family = AF_INET6;
139
strncpy (netif->name, ifp->ifa_name,20);
140
strncpy (netif->ipaddr, namebuf, 40);
141
interfaces=g_list_append(interfaces,netif);
149
if (ifp->ifa_addr->sa_family != AF_INET)
152
/*printf ("ifc %s %s\n",
154
inet_ntoa (((struct sockaddr_in *) ifp->ifa_addr)->
157
netif=g_new0(interface_t,1);
159
strncpy (netif->name, ifp->ifa_name,20);
160
strncpy (netif->ip4addr, inet_ntoa (((struct sockaddr_in *) ifp->ifa_addr)->sin_addr),20);
161
interfaces=g_list_append(interfaces,netif);
166
freeifaddrs (ifpstart);
172
GList * retrieve_if()
174
int sock,err,if_count,i;
175
struct ifconf netconf;
176
char buffer[sizeof(struct ifreq)*MAX_IF];
177
GList *interfaces=NULL;
179
netconf.ifc_len=sizeof(struct ifreq)*MAX_IF;
180
netconf.ifc_buf=buffer;
181
sock=socket(PF_INET, SOCK_DGRAM,0);
182
err=ioctl(sock,SIOCGIFCONF,&netconf);
183
if (err<0) printf("Error in ioctl: %i.\n",errno);
186
if_count=netconf.ifc_len/sizeof(struct ifreq);
187
g_message("Found %i interfaces.\n",if_count);
188
for (i=0;i<if_count;i++)
192
char namebuf[BUFSIZ];
197
switch (netconf.ifc_req[i].ifr_addr.sa_family) {
199
getnameinfo(&netconf.ifc_req[i].ifr_addr, sizeof (struct sockaddr_in) ,
200
namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
201
netif=g_new0(interface_t,1);
203
netif->family = AF_INET;
204
strncpy (netif->name, netconf.ifc_req[i].ifr_name,20);
205
strncpy (netif->ipaddr, namebuf,20);
206
interfaces=g_list_append(interfaces,netif);
209
getnameinfo(&netconf.ifc_req[i].ifr_addr, sizeof (struct sockaddr_in6) ,
210
namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
211
if (strchr(namebuf, '%') == NULL) {
212
netif=g_new0(interface_t,1);
214
netif->family = AF_INET6;
215
strncpy (netif->name, netconf.ifc_req[i].ifr_name,20);
216
strncpy (netif->ipaddr, namebuf, 40);
217
interfaces=g_list_append(interfaces,netif);
226
if (netconf.ifc_req[i].ifr_addr.sa_family != AF_INET)
228
netif=g_new0(interface_t,1);
229
strncpy(netif->name,netconf.ifc_req[i].ifr_name,20);
230
strncpy(netif->ip4addr,inet_ntoa(((struct sockaddr_in*)(&netconf.ifc_req[i].ifr_addr))->sin_addr),20);
232
interfaces=g_list_append(interfaces,netif);
241
gboolean find_interface(net_config_t *config, char *ifname)
243
GList *interfaces=config->interfaces;
246
interface_t *tmp4if = NULL;
250
tmpif=(interface_t*) interfaces->data;
251
while (interfaces!=NULL){
252
tmpif=(interface_t*) interfaces->data;
254
if (strcmp(ifname,tmpif->name)==0){
256
if (tmpif->family == AF_INET6) {
257
config->sel_if=tmpif;
264
config->sel_if=tmpif;
269
interfaces=g_list_next(interfaces);
272
if (checkflag == 1) {
273
config->sel_if=tmp4if;
280
void find_best_interface(net_config_t *config)
283
tmpif=(interface_t*) config->interfaces->data;
284
if (!find_interface(config,"ppp0")){
285
/* if ppp0 is not found, then default to eth0 */
286
if (!find_interface(config,"eth0")){
287
/* if eth0 is not found, try ed0 (used on FreeBsd) */
288
if (!find_interface(config,"ed0")){
289
/* if eth0 is not found, then default to lo */
290
if (!find_interface(config,"lo")){
291
/* if lo is not found, default to first interface in the list */
292
config->sel_if=tmpif;
299
#endif /*LINPHONE_DEPRECATED*/
72
static void linphone_call_init_common(LinphoneCall *call, char *from, char *to){
73
sdp_context_set_user_pointer(call->sdpctx,(void*)call);
74
call->state=LCStateInit;
75
call->start_time=time(NULL);
76
call->log=linphone_call_log_new(call, from, to);
79
LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, const osip_from_t *from, const osip_to_t *to)
81
LinphoneCall *call=ms_new0(LinphoneCall,1);
82
char localip[LINPHONE_IPADDR_SIZE];
83
char *fromstr=NULL,*tostr=NULL;
84
call->dir=LinphoneCallOutgoing;
88
linphone_core_get_local_ip(lc,to->url->host,localip);
89
call->sdpctx=sdp_handler_create_context(&linphone_sdphandler,localip,from->url->username);
90
call->profile=lc->local_profile; /*use the readonly local profile*/
91
osip_from_to_str(from,&fromstr);
92
osip_to_to_str(to,&tostr);
93
linphone_call_init_common(call,fromstr,tostr);
98
LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, const char *from, const char *to, int cid, int did)
100
char localip[LINPHONE_IPADDR_SIZE];
101
LinphoneCall *call=ms_new0(LinphoneCall,1);
102
osip_from_t *me= linphone_core_get_primary_contact_parsed(lc);
103
call->dir=LinphoneCallIncoming;
107
linphone_core_get_local_ip(lc,NULL,localip);
108
call->sdpctx=sdp_handler_create_context(&linphone_sdphandler,localip,me->url->username);
109
linphone_call_init_common(call, osip_strdup(from), osip_strdup(to));
114
void linphone_call_destroy(LinphoneCall *obj)
116
linphone_call_log_completed(obj->log,obj);
117
if (obj->profile!=NULL && obj->profile!=obj->core->local_profile) rtp_profile_destroy(obj->profile);
118
if (obj->sdpctx!=NULL) sdp_context_free(obj->sdpctx);
122
LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, char *from, char *to){
123
LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
128
loctime=*localtime(&call->start_time);
130
localtime_r(&call->start_time,&loctime);
132
strftime(cl->start_date,sizeof(cl->start_date),"%c",&loctime);
137
void linphone_call_log_completed(LinphoneCallLog *calllog, LinphoneCall *call){
138
LinphoneCore *lc=call->core;
139
calllog->duration=time(NULL)-call->start_time;
142
calllog->status=LinphoneCallAborted;
145
if (calllog->dir==LinphoneCallIncoming){
147
calllog->status=LinphoneCallMissed;
149
info=ortp_strdup_printf(_("You have missed %i call(s)."),lc->missed_calls);
150
lc->vtable.display_status(lc,info);
153
else calllog->status=LinphoneCallAborted;
155
case LCStateAVRunning:
156
calllog->status=LinphoneCallSuccess;
159
lc->call_logs=ms_list_append(lc->call_logs,(void *)calllog);
160
if (ms_list_size(lc->call_logs)>lc->max_call_logs){
163
linphone_call_log_destroy((LinphoneCallLog*)elem->data);
164
lc->call_logs=ms_list_remove_link(lc->call_logs,elem);
166
if (lc->vtable.call_log_updated!=NULL){
167
lc->vtable.call_log_updated(lc,calllog);
171
char * linphone_call_log_to_str(LinphoneCallLog *cl){
174
case LinphoneCallAborted:
177
case LinphoneCallSuccess:
178
status=_("completed");
180
case LinphoneCallMissed:
186
return ortp_strdup_printf(_("%s at %s\nFrom: %s\nTo: %s\nStatus: %s\nDuration: %i mn %i sec\n"),
187
(cl->dir==LinphoneCallIncoming) ? _("Incoming call") : _("Outgoing call"),
196
void linphone_call_log_destroy(LinphoneCallLog *cl){
197
if (cl->from!=NULL) osip_free(cl->from);
198
if (cl->to!=NULL) osip_free(cl->to);
203
void linphone_core_enable_logs(FILE *file){
204
if (file==NULL) file=stdout;
205
ortp_set_log_file(file);
206
ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
207
osip_trace_initialize (OSIP_INFO4, file);
210
void linphone_core_disable_logs(){
212
for (tl=0;tl<=OSIP_INFO4;tl++) osip_trace_disable_level(tl);
213
ortp_set_log_level_mask(ORTP_ERROR|ORTP_FATAL);
302
218
net_config_read (LinphoneCore *lc)
309
#ifdef LINPHONE_DEPRECATED
310
config->interfaces=retrieve_if();
311
/* select the best interface, not lo */
312
if (config->interfaces==NULL) {
313
g_error("Could not get network interfaces !!");
316
ifname=gnome_config_get_string("net/if_name");
317
if ((ifname!=NULL) && (strlen(ifname)!=0)){
319
if (!find_interface(config,ifname)){
320
g_warning("Could not find network interface %s.",ifname);
321
find_best_interface(config);
323
}else find_best_interface(config);
324
#endif /*LINPHONE_DEPRECATED*/
222
LpConfig *config=lc->config;
326
tmp=gnome_config_get_int_with_default("net/con_type",&def);
328
if (def) tmp=CONNECTION_TYPE_ETHERNET;
330
if (def) tmp=CONNECTION_TYPE_56KMODEM;
332
linphone_core_set_connection_type(lc,tmp);
334
tmpstr=gnome_config_get_string_with_default("net/nat_address",&def);
335
if (def) tmpstr=NULL;
224
tmp=lp_config_get_int(config,"net","download_bw",0);
225
linphone_core_set_download_bandwidth(lc,tmp);
226
tmp=lp_config_get_int(config,"net","upload_bw",0);
227
linphone_core_set_upload_bandwidth(lc,tmp);
228
linphone_core_set_stun_server(lc,lp_config_get_string(config,"net","stun_server",NULL));
229
tmpstr=lp_config_get_string(lc->config,"net","nat_address",NULL);
336
230
if (tmpstr!=NULL && (strlen(tmpstr)<1)) tmpstr=NULL;
337
tmp=gnome_config_get_int_with_default("net/use_nat",&def);
339
linphone_core_set_nat_address(lc,tmpstr,tmp);
231
linphone_core_set_nat_address(lc,tmpstr);
232
tmp=lp_config_get_int(lc->config,"net","firewall_policy",0);
233
linphone_core_set_firewall_policy(lc,tmp);
234
tmp=lp_config_get_int(lc->config,"net","nat_sdp_only",0);
342
238
void sound_config_read(LinphoneCore *lc)
348
devid=gnome_config_get_int_with_default("sound/dev_id",&def);
350
/* choose an oss card if availlable, because alsa native support is not well enough stable*/
353
for(i=0;i<MAX_SND_CARDS;i++){
354
sndcard=snd_card_manager_get_card(snd_card_manager,i);
359
id=snd_card_get_identifier(sndcard);
360
if (strstr(id,"Open Sound System")!=0){
361
g_message("Choosing oss device %s.",id);
244
const char **devices;
247
/* retrieve all sound devices */
248
elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
249
ndev=ms_list_size(elem);
250
devices=ms_malloc((ndev+1)*sizeof(const char *));
251
for (i=0;elem!=NULL;elem=elem->next,i++){
252
devices[i]=ms_snd_card_get_string_id((MSSndCard *)elem->data);
367
linphone_core_set_sound_device(lc,devid);
368
tmp=gnome_config_get_int_with_default("sound/play_lev",&def);
255
lc->sound_conf.cards=devices;
256
devid=lp_config_get_string(lc->config,"sound","playback_dev_id",NULL);
257
linphone_core_set_playback_device(lc,devid);
259
devid=lp_config_get_string(lc->config,"sound","ringer_dev_id",NULL);
260
linphone_core_set_ringer_device(lc,devid);
262
devid=lp_config_get_string(lc->config,"sound","capture_dev_id",NULL);
263
linphone_core_set_capture_device(lc,devid);
266
tmp=lp_config_get_int(lc->config,"sound","play_lev",80);
370
267
linphone_core_set_play_level(lc,tmp);
371
tmp=gnome_config_get_int_with_default("sound/rec_lev",&def);
268
tmp=lp_config_get_int(lc->config,"sound","ring_lev",80);
269
linphone_core_set_ring_level(lc,tmp);
270
tmp=lp_config_get_int(lc->config,"sound","rec_lev",80);
373
271
linphone_core_set_rec_level(lc,tmp);
374
tmpbuf=gnome_config_get_string_with_default("sound/source",&def);
272
tmpbuf=lp_config_get_string(lc->config,"sound","source","m");
376
273
linphone_core_set_sound_source(lc,tmpbuf[0]);
378
tmpbuf=gnome_config_get_string_with_default("sound/local_ring",&def);
379
if (def) tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
381
if (!g_file_test(tmpbuf,G_FILE_TEST_EXISTS)){
382
tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
384
if (strstr(tmpbuf,".wav")==NULL){
385
/* it currently uses old sound files, so replace them */
386
tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
276
tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
277
tmpbuf=lp_config_get_string(lc->config,"sound","local_ring",tmpbuf);
278
if (access(tmpbuf,F_OK)==0) {
279
tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
281
if (strstr(tmpbuf,".wav")==NULL){
282
/* it currently uses old sound files, so replace them */
283
tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
389
286
linphone_core_set_ring(lc,tmpbuf);
390
tmpbuf=gnome_config_get_string_with_default("sound/remote_ring",&def);
391
if (def) tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING_FR;
393
if (!g_file_test(tmpbuf,G_FILE_TEST_EXISTS)){
394
tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING_FR;
396
if (strstr(tmpbuf,".wav")==NULL){
397
/* it currently uses old sound files, so replace them */
398
tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING_FR;
288
tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING_FR;
289
tmpbuf=lp_config_get_string(lc->config,"sound","remote_ring",tmpbuf);
290
if (access(tmpbuf,F_OK)==0){
291
tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING_FR;
293
if (strstr(tmpbuf,".wav")==NULL){
294
/* it currently uses old sound files, so replace them */
295
tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING_FR;
401
297
linphone_core_set_ringback(lc,0);
402
lc->sound_conf.autokill=1;
403
298
check_sound_device(lc);
299
lc->sound_conf.latency=0;
406
void registrar_config_read(LinphoneCore *lc)
409
gchar *tmpstr,*tmpstr2;
412
tmpstr=gnome_config_get_string_with_default("sip/registrar",&def);
413
if (def) tmpstr=NULL;
414
tmpstr2=gnome_config_get_string_with_default("sip/addr_of_rec",&def);
415
if (def) tmpstr2=NULL;
416
linphone_core_set_registrar_addr(lc,tmpstr,tmpstr2);
417
tmpstr=gnome_config_get_string_with_default("sip/passwd",&def);
418
if (def) tmpstr=NULL;
419
linphone_core_set_registrar_passwd(lc,tmpstr);
420
tmp1=gnome_config_get_int_with_default("sip/use_registrar",&def);
422
tmp2=gnome_config_get_int_with_default("sip/as_proxy",&def);
424
tmp3=gnome_config_get_int_with_default("sip/expires",&def);
426
linphone_core_set_registrar_usage(lc,tmp1,tmp2,tmp3);
301
linphone_core_enable_echo_cancelation(lc,
302
lp_config_get_int(lc->config,"sound","echocancelation",0));
430
305
void sip_config_read(LinphoneCore *lc)
433
gchar *hostname,*username;
435
username=gnome_config_get_string_with_default("sip/username",&def);
437
gchar *logname=getenv("LOGNAME");
439
username=g_strdup(logname);
440
else username=g_strdup("toto");
442
hostname=gnome_config_get_string_with_default("sip/hostname",&def);
444
gchar *hostname2=getenv("HOST");
446
hostname=g_strdup(hostname2);
447
else hostname=g_strdup("unknown-host");
449
port=gnome_config_get_int_with_default("sip/sip_port",&def);
312
port=lp_config_get_int(lc->config,"sip","use_info",0);
313
linphone_core_set_use_info_for_dtmf(lc,port);
315
ipv6=lp_config_get_int(lc->config,"sip","use_ipv6",-1);
318
if (host_has_ipv6_network()){
319
lc->vtable.display_message(lc,_("Your machine appears to be connected to an IPv6 network. By default linphone always uses IPv4. Please update your configuration if you want to use IPv6"));
322
linphone_core_enable_ipv6(lc,ipv6);
323
port=lp_config_get_int(lc->config,"sip","sip_port",5060);
453
324
linphone_core_set_sip_port(lc,port);
454
linphone_core_set_primary_contact(lc,g_strdup_printf("sip:%s@%s",username,hostname));
455
registrar_config_read(lc);
326
tmpstr=lp_config_get_string(lc->config,"sip","contact",NULL);
328
char *hostname=getenv("HOST");
329
char *username=getenv("USER");
330
if (hostname==NULL) hostname=getenv("HOSTNAME");
332
hostname="unknown-host";
336
contact=ortp_strdup_printf("sip:%s@%s",username,hostname);
337
}else contact=ms_strdup(tmpstr);
338
linphone_core_set_primary_contact(lc,contact);
342
tmp=lp_config_get_int(lc->config,"sip","guess_hostname",1);
343
linphone_core_set_guess_hostname(lc,tmp);
346
tmp=lp_config_get_int(lc->config,"sip","inc_timeout",15);
347
linphone_core_set_inc_timeout(lc,tmp);
349
/* get proxies config */
351
LinphoneProxyConfig *cfg=linphone_proxy_config_new_from_config_file(lc->config,i);
353
linphone_core_add_proxy_config(lc,cfg);
358
/* get the default proxy */
359
tmp=lp_config_get_int(lc->config,"sip","default_proxy",-1);
360
linphone_core_set_default_proxy_index(lc,tmp);
362
/* read authentication information */
364
LinphoneAuthInfo *ai=linphone_auth_info_new_from_config_file(lc->config,i);
366
linphone_core_add_auth_info(lc,ai);
458
374
void rtp_config_read(LinphoneCore *lc)
463
port=gnome_config_get_int_with_default("rtp/audio_rtp_port",&def);
378
port=lp_config_get_int(lc->config,"rtp","audio_rtp_port",7078);
465
379
linphone_core_set_audio_port(lc,port);
466
port=gnome_config_get_int_with_default("rtp/video_rtp_port",&def);
469
jitt_comp=gnome_config_get_int_with_default("rtp/audio_jitt_comp",&def);
470
if (def) jitt_comp=60;
381
port=lp_config_get_int(lc->config,"rtp","video_rtp_port",9078);
382
if (port==0) port=9078;
383
linphone_core_set_video_port(lc,port);
385
jitt_comp=lp_config_get_int(lc->config,"rtp","audio_jitt_comp",60);
471
386
linphone_core_set_audio_jittcomp(lc,jitt_comp);
472
jitt_comp=gnome_config_get_int_with_default("rtp/video_jitt_comp",&def);
473
if (def) jitt_comp=60;
387
jitt_comp=lp_config_get_int(lc->config,"rtp","video_jitt_comp",60);
478
PayloadType * get_codec(char* type,int index){
391
PayloadType * get_codec(LpConfig *config, char* type,int index){
485
snprintf(codeckey,50,"%s_%i/mime",type,index);
486
mime=gnome_config_get_string_with_default(codeckey,&def);
487
if (def) return NULL;
397
snprintf(codeckey,50,"%s_%i",type,index);
398
mime=lp_config_get_string(config,codeckey,"mime",NULL);
399
if (mime==NULL || strlen(mime)==0 ) return NULL;
489
401
pt=payload_type_new();
491
snprintf(codeckey,50,"%s_%i/rate",type,index);
492
rate=gnome_config_get_int_with_default(codeckey,&def);
493
if (def) rate=8000; // ??
402
pt->mime_type=ms_strdup(mime);
404
rate=lp_config_get_int(config,codeckey,"rate",8000);
494
405
pt->clock_rate=rate;
496
snprintf(codeckey,50,"%s_%i/enabled",type,index);
497
enabled=gnome_config_get_int_with_default(codeckey,&def);
498
if (enabled || def) pt->flags|=PAYLOAD_TYPE_ENABLED;
499
//g_message("Found codec %s/%i",pt->mime_type,pt->clock_rate);
407
enabled=lp_config_get_int(config,codeckey,"enabled",1);
408
if (enabled ) pt->flags|=PAYLOAD_TYPE_ENABLED;
409
//ms_message("Found codec %s/%i",pt->mime_type,pt->clock_rate);
524
434
void video_config_read(LinphoneCore *lc)
528
tmp=gnome_config_get_int_with_default("video/enabled",&def);
530
tmp=gnome_config_get_int_with_default("video/show_local",&def);
439
str=lp_config_get_string(lc->config,"video","device","/dev/video0");
440
linphone_core_set_video_device(lc,NULL,str);
442
tmp=lp_config_get_int(lc->config,"video","enabled",1);
444
linphone_core_enable_video(lc,tmp);
445
linphone_core_enable_video_preview(lc,tmp);
534
449
void ui_config_read(LinphoneCore *lc)
538
GList *address_list=NULL;
539
/* get address book entries*/
540
len= gnome_config_get_int("address_book/entry_count");
543
for (tmp=0;tmp<len;tmp++)
545
ab_entry=g_strdup_printf("address_book/entry%i",tmp);
546
address_list=g_list_append(address_list,(gpointer)gnome_config_get_string(ab_entry));
453
for (i=0;(lf=linphone_friend_new_from_config_file(lc,i))!=NULL;i++){
454
linphone_core_add_friend(lc,lf);
550
linphone_core_set_address_list(lc,address_list);
553
void autoreplier_config_init(autoreplier_config_t *config)
459
void autoreplier_config_init(LinphoneCore *lc)
556
config->enabled=gnome_config_get_int_with_default("autoreplier/enabled",&def);
557
if (def) config->enabled=0;
558
config->after_seconds=gnome_config_get_int_with_default("autoreplier/after_seconds",&def);
559
if (def) config->after_seconds=6;
560
config->max_users=gnome_config_get_int_with_default("autoreplier/max_users",&def);
561
if (def) config->max_users=1;
562
config->max_rec_time=gnome_config_get_int_with_default("autoreplier/max_rec_time",&def);
563
if (def) config->max_rec_time=0;
564
config->max_rec_msg=gnome_config_get_int_with_default("autoreplier/max_rec_msg",&def);
565
if (def) config->max_rec_msg=0;
566
config->message=gnome_config_get_string_with_default("autoreplier/message",&def);
567
if (def) config->message=NULL;
461
autoreplier_config_t *config=&lc->autoreplier_conf;
462
config->enabled=lp_config_get_int(lc->config,"autoreplier","enabled",0);
463
config->after_seconds=lp_config_get_int(lc->config,"autoreplier","after_seconds",6);
464
config->max_users=lp_config_get_int(lc->config,"autoreplier","max_users",1);
465
config->max_rec_time=lp_config_get_int(lc->config,"autoreplier","max_rec_time",60);
466
config->max_rec_msg=lp_config_get_int(lc->config,"autoreplier","max_rec_msg",10);
467
config->message=lp_config_get_string(lc->config,"autoreplier","message",NULL);
470
void linphone_core_set_download_bandwidth(LinphoneCore *lc, int bw){
471
lc->net_conf.download_bw=bw;
472
if (bw==0){ /*infinite*/
479
if (linphone_core_video_enabled(lc))
486
lc->dw_video_bw=bw-lc->dw_audio_bw;
489
void linphone_core_set_upload_bandwidth(LinphoneCore *lc, int bw){
490
lc->net_conf.upload_bw=bw;
491
if (bw==0){ /*infinite*/
498
if (linphone_core_video_enabled(lc))
505
lc->up_video_bw=bw-lc->up_audio_bw;
508
int linphone_core_get_download_bandwidth(const LinphoneCore *lc){
509
return lc->net_conf.download_bw;
512
int linphone_core_get_upload_bandwidth(const LinphoneCore *lc){
513
return lc->net_conf.upload_bw;
571
linphone_core_init (LinphoneCore * lc,LinphoneCoreVTable *vtable, gchar *config_path, gpointer userdata)
517
linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, const char *config_path, void * userdata)
576
//TRACE_INITIALIZE(TRACE_LEVEL5,stdout);
579
ortp_set_debug_file("oRTP",NULL);
580
rtp_profile_set_payload(&av_profile,115,&lpc1015);
582
rtp_profile_set_payload(&av_profile,110,&speex_nb);
583
rtp_profile_set_payload(&av_profile,111,&speex_wb);
585
rtp_profile_set_payload(&av_profile,116,&truespeech);
586
rtp_profile_set_payload(&av_profile,101,&telephone_event);
520
rtp_profile_set_payload(&av_profile,115,&payload_type_lpc1015);
521
rtp_profile_set_payload(&av_profile,110,&payload_type_speex_nb);
522
rtp_profile_set_payload(&av_profile,111,&payload_type_speex_wb);
523
rtp_profile_set_payload(&av_profile,112,&payload_type_ilbc);
524
rtp_profile_set_payload(&av_profile,116,&payload_type_truespeech);
525
rtp_profile_set_payload(&av_profile,101,&payload_type_telephone_event);
527
rtp_profile_set_payload(&av_profile,97,&payload_type_theora);
528
rtp_profile_set_payload(&av_profile,98,&payload_type_h263_1998);
529
rtp_profile_set_payload(&av_profile,99,&payload_type_mp4v);
588
ms_speex_codec_init();
590
533
memset (lc, 0, sizeof (LinphoneCore));
591
534
lc->data=userdata;
593
end=_("Communication ended.");
594
contacting= _("Contacting ");
595
contacted=_("is calling you.");
596
connected=_("Connected.");
597
cancel=_("Call cancelled.");
599
536
memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable));
601
if (config_path!=NULL){
602
gnome_config_push_prefix(g_strdup_printf("=%s=",config_path));
603
}else gnome_config_push_prefix("/linphone/");
606
lc->ua=osip_ua_new();
607
err=osip_ua_signal_connect(lc->ua,"INVITE_ACCEPTED",invite_accepted_cb);
608
err=osip_ua_signal_connect(lc->ua,"BYE",bye_cb);
609
err=osip_ua_signal_connect(lc->ua,"FAILLURE",faillure_cb);
610
err=osip_ua_signal_connect(lc->ua,"INVITE",invite_cb);
611
err=osip_ua_signal_connect(lc->ua,"INFORMATIVE",informative_cb);
612
lc->ua->data=(void*)lc;
614
/* create a sdp handler */
615
lc->sdph=sdp_handler_new();
616
sdp_handler_set_write_offer_fcn(SDP_HANDLER(lc->sdph),set_audio_offer,set_video_offer);
617
sdp_handler_set_accept_offer_fcn(SDP_HANDLER(lc->sdph),accept_audio_offer,accept_video_offer);
618
sdp_handler_set_read_answer_fcn(SDP_HANDLER(lc->sdph),read_audio_answer,read_video_answer);
620
/* add the sdp handler to the ua */
621
osip_ua_add_body_handler(lc->ua,lc->sdph);
538
lc->config=lp_config_new(config_path);
541
#ifdef VINCENT_MAURY_RSVP
542
/* default qos parameters : rsvp on, rpc off */
624
547
sound_config_read(lc);
626
548
net_config_read(lc);
549
sip_config_read(lc); /* this will start eXosip*/
627
551
rtp_config_read(lc);
628
552
codecs_config_read(lc);
629
553
video_config_read(lc);
630
554
//autoreplier_config_init(&lc->autoreplier_conf);
556
lc->presence_mode=LINPHONE_STATUS_ONLINE;
557
lc->max_call_logs=15;
631
558
ui_config_read(lc);
633
lc->in_main_thread=1;
634
lc->lock=g_mutex_new();
635
lc->vtable.display_status(lc,ready);
559
ms_mutex_init(&lc->lock,NULL);
560
lc->vtable.display_status(lc,_("Ready"));
638
LinphoneCore *linphone_core_new(LinphoneCoreVTable *vtable,
639
gchar *config_path, gpointer userdata)
563
LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable,
564
const char *config_path, void * userdata)
641
LinphoneCore *core=g_new(LinphoneCore,1);
566
LinphoneCore *core=ms_new(LinphoneCore,1);
642
567
linphone_core_init(core,vtable,config_path,userdata);
646
GList *linphone_core_get_audio_codecs(LinphoneCore *lc)
648
return g_list_copy(lc->codecs_conf.audio_codecs);
651
GList *linphone_core_get_video_codecs(LinphoneCore *lc)
653
return g_list_copy(lc->codecs_conf.video_codecs);
656
int linphone_core_set_primary_contact(LinphoneCore *lc, gchar *contact)
661
if ( from_parse(ct,contact) <0){
662
g_warning("Bad contact url: %s", contact);
666
lc->sip_conf.username=g_strdup(ct->url->username);
667
lc->sip_conf.hostname=g_strdup(ct->url->host);
668
linphone_core_update_contact_info(lc);
675
gchar *linphone_core_get_primary_contact(LinphoneCore *lc)
677
return g_strdup(lc->sip_conf.contact);
680
from_t *linphone_core_get_primary_contact_parsed(LinphoneCore *lc)
571
const MSList *linphone_core_get_audio_codecs(const LinphoneCore *lc)
573
return lc->codecs_conf.audio_codecs;
576
const MSList *linphone_core_get_video_codecs(const LinphoneCore *lc)
578
return lc->codecs_conf.video_codecs;
581
int linphone_core_set_primary_contact(LinphoneCore *lc,const char *contact)
583
if (lc->sip_conf.contact!=NULL) ms_free(lc->sip_conf.contact);
584
lc->sip_conf.contact=ms_strdup(contact);
585
if (lc->sip_conf.guessed_contact!=NULL){
586
ms_free(lc->sip_conf.guessed_contact);
587
lc->sip_conf.guessed_contact=NULL;
592
static bool_t stun_get_localip(LinphoneCore *lc, char *result){
593
const char *server=linphone_core_get_stun_server(lc);
596
StunAddress4 changed;
598
if (stunParseServerName((char*)server,&addr)){
599
if (lc->vtable.display_status!=NULL)
600
lc->vtable.display_status(lc,_("Stun lookup in progress..."));
601
if (stunTest(&addr,1,TRUE,NULL,&mapped,&changed)==0){
602
struct in_addr inaddr;
604
inaddr.s_addr=ntohl(mapped.addr);
605
tmp=inet_ntoa(inaddr);
606
strncpy(result,tmp,LINPHONE_IPADDR_SIZE);
607
if (lc->vtable.display_status!=NULL)
608
lc->vtable.display_status(lc,_("Stun lookup done..."));
609
ms_message("Stun server says we have address %s",result);
612
ms_warning("stun lookup failed.");
615
ms_warning("Fail to resolv or parse %s",server);
621
/*result must be an array of chars at least LINPHONE_IPADDR_SIZE */
622
void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result){
624
if (lc->apply_nat_settings){
625
apply_nat_settings(lc);
626
lc->apply_nat_settings=false;
628
if (linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS){
629
strncpy(result,linphone_core_get_nat_address(lc),LINPHONE_IPADDR_SIZE);
632
if (linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_STUN) {
633
if (lc->sip_conf.ipv6_enabled){
634
ms_warning("stun support is not implemented for ipv6");
636
ms_message("doing stun lookup for local address...");
637
if (stun_get_localip(lc,result)){
638
if (!lc->net_conf.nat_sdp_only)
639
eXosip_set_firewallip(result);
642
ms_warning("stun lookup failed, falling back to a local interface...");
647
/* try a public address */
648
if (!lc->sip_conf.ipv6_enabled){
649
dest="15.128.128.93";
651
dest="3ffe:4015:bbbb:70d0:201:2ff:fe09:81b1";
654
eXosip_get_localip_for((char*)dest,&tmp);
655
eXosip_set_firewallip("");
656
strncpy(result,tmp,LINPHONE_IPADDR_SIZE);
660
const char *linphone_core_get_primary_contact(LinphoneCore *lc)
663
char tmp[LINPHONE_IPADDR_SIZE];
664
if (lc->sip_conf.guess_hostname){
665
if (lc->sip_conf.guessed_contact==NULL || lc->sip_conf.loopback_only){
668
if (lc->sip_conf.guessed_contact!=NULL){
669
ms_free(lc->sip_conf.guessed_contact);
670
lc->sip_conf.guessed_contact=NULL;
673
osip_from_init(&url);
674
if (osip_from_parse(url,lc->sip_conf.contact)==0){
676
}else ms_error("Could not parse identity contact !");
677
linphone_core_get_local_ip(lc, NULL, tmp);
678
if (strcmp(tmp,"127.0.0.1")==0 || strcmp(tmp,"::1")==0 ){
679
ms_warning("Local loopback network only !");
680
lc->sip_conf.loopback_only=TRUE;
681
}else lc->sip_conf.loopback_only=FALSE;
682
osip_free(url->url->host);
683
url->url->host=osip_strdup(tmp);
684
if (url->url->port!=NULL){
685
osip_free(url->url->port);
688
if (lc->sip_conf.sip_port!=5060){
689
url->url->port=ortp_strdup_printf("%i",lc->sip_conf.sip_port);
691
osip_from_to_str(url,&guessed);
692
lc->sip_conf.guessed_contact=guessed;
697
identity=lc->sip_conf.guessed_contact;
699
identity=lc->sip_conf.contact;
704
void linphone_core_set_guess_hostname(LinphoneCore *lc, bool_t val){
705
lc->sip_conf.guess_hostname=val;
708
bool_t linphone_core_get_guess_hostname(LinphoneCore *lc){
709
return lc->sip_conf.guess_hostname;
712
osip_from_t *linphone_core_get_primary_contact_parsed(LinphoneCore *lc){
685
err=from_parse(contact,lc->sip_conf.contact);
714
osip_from_t *contact;
715
osip_from_init(&contact);
716
err=osip_from_parse(contact,linphone_core_get_primary_contact(lc));
718
osip_from_free(contact);
694
int linphone_core_set_audio_codecs(LinphoneCore *lc, GList *codecs)
724
int linphone_core_set_audio_codecs(LinphoneCore *lc, MSList *codecs)
696
if (lc->codecs_conf.audio_codecs!=NULL) g_list_free(lc->codecs_conf.audio_codecs);
726
if (lc->codecs_conf.audio_codecs!=NULL) ms_list_free(lc->codecs_conf.audio_codecs);
697
727
lc->codecs_conf.audio_codecs=codecs;
701
int linphone_core_set_video_codecs(LinphoneCore *lc, GList *codecs)
731
int linphone_core_set_video_codecs(LinphoneCore *lc, MSList *codecs)
703
if (lc->codecs_conf.video_codecs!=NULL) g_list_free(lc->codecs_conf.video_codecs);
733
if (lc->codecs_conf.video_codecs!=NULL) ms_list_free(lc->codecs_conf.video_codecs);
704
734
lc->codecs_conf.video_codecs=codecs;
708
GList * linphone_core_get_address_list(LinphoneCore *lc)
710
return g_list_copy(lc->ui_conf.address_list);
713
int linphone_core_set_address_list(LinphoneCore *lc, GList *addresses)
715
if (lc->ui_conf.address_list!=NULL) g_list_free(lc->ui_conf.address_list);
716
lc->ui_conf.address_list=addresses;
720
char *linphone_core_get_registrar_addr(LinphoneCore *lc)
722
return g_strdup(lc->sip_conf.reg_conf.registrar);
725
int linphone_core_set_registrar_addr(LinphoneCore *lc,char *url,char *addr_of_rec)
727
url_t *surl=NULL,*surl2=NULL;
729
if (url==NULL || strlen(url)==0) return 0;
731
err=url_parse(surl,url);
733
g_warning("Bad proxy or registrar url:%s",url);
736
if (addr_of_rec!=NULL){
738
err=url_parse(surl2,addr_of_rec);
740
g_warning("Bad address of record:%s",addr_of_rec);
744
if (lc->sip_conf.reg_conf.registrar!=NULL){
745
g_free(lc->sip_conf.reg_conf.registrar);
747
lc->sip_conf.reg_conf.registrar=g_strdup(url);
749
if (addr_of_rec!=NULL){
750
if (lc->sip_conf.reg_conf.addr_of_rec!=NULL){
751
g_free(lc->sip_conf.reg_conf.addr_of_rec);
753
lc->sip_conf.reg_conf.addr_of_rec=g_strdup(addr_of_rec);
755
/* guess a valid address of record */
756
if (surl->port!=NULL)
757
lc->sip_conf.reg_conf.addr_of_rec=g_strdup_printf("sip:%s@%s:%s",
758
lc->sip_conf.username,surl->host,surl->port);
759
else lc->sip_conf.reg_conf.addr_of_rec=g_strdup_printf("sip:%s@%s",
760
lc->sip_conf.username,surl->host);
772
char *linphone_core_get_addr_of_rec(LinphoneCore *lc)
774
return g_strdup(lc->sip_conf.reg_conf.addr_of_rec);
777
char *linphone_core_get_registrar_passwd(LinphoneCore *lc)
779
return g_strdup(lc->sip_conf.reg_conf.passwd);
782
void linphone_core_set_registrar_passwd(LinphoneCore *lc, gchar *passwd)
786
tmp=g_strdup(passwd);
788
if (lc->sip_conf.reg_conf.passwd!=NULL){
789
g_free(lc->sip_conf.reg_conf.passwd);
791
lc->sip_conf.reg_conf.passwd=tmp;
795
int linphone_core_register(LinphoneCore *lc, char *url){
797
linphone_core_set_registrar_addr(lc,url,NULL);
799
do_registration(lc,1);
803
void linphone_core_get_registrar_usage(LinphoneCore *lc,gboolean *reg, gboolean *proxy, gint *expires)
805
if (reg!=NULL) *reg= lc->sip_conf.reg_conf.use_registrar;
806
if (proxy!=NULL) *proxy=lc->sip_conf.reg_conf.as_proxy;
807
if (expires!=NULL) *expires=lc->sip_conf.reg_conf.expires;
812
void linphone_core_set_registrar_usage(LinphoneCore *lc, gboolean use, gboolean outbound_proxy,gint expires)
814
if (lc->sip_conf.reg_conf.timer==NULL){
817
g_timer_start(timer);
818
lc->sip_conf.reg_conf.timer=timer;
820
if (expires<=0) lc->sip_conf.reg_conf.expires=15*60;
821
else lc->sip_conf.reg_conf.expires=expires;
822
if ((lc->sip_conf.reg_conf.registrar!=NULL) && (strlen(lc->sip_conf.reg_conf.registrar)!=0)){
825
osip_ua_set_outbound_proxy(lc->ua,lc->sip_conf.reg_conf.registrar,lc->sip_conf.reg_conf.passwd);
826
else osip_ua_set_outbound_proxy(lc->ua,NULL,NULL);
827
do_registration(lc,1);
828
/* TODO: setup a timeout to re-register after expires */
830
osip_ua_set_outbound_proxy(lc->ua,NULL,NULL);
831
if (lc->sip_conf.reg_conf.use_registrar){
832
/* the proxy is no more used, we need to unregister */
833
do_registration(lc,0);
837
lc->sip_conf.reg_conf.use_registrar=use;
838
lc->sip_conf.reg_conf.as_proxy=outbound_proxy;
841
GList * linphone_core_get_net_interfaces(LinphoneCore *lc)
843
return g_list_copy(lc->net_conf.interfaces);
846
interface_t * linphone_core_get_selected_interface(LinphoneCore *lc)
848
return lc->net_conf.sel_if;
852
void linphone_core_select_net_interface(LinphoneCore *lc, gint index)
854
void linphone_core_select_net_interface(LinphoneCore *lc, gchar *ifname)
857
GList *elem=lc->net_conf.interfaces;
859
interface_t *iface=(interface_t *)elem->data;
861
if (index == iface->index) {
863
if (strcmp(ifname,iface->name)==0){
865
lc->net_conf.sel_if=iface;
866
linphone_core_update_contact_info(lc);
869
elem=g_list_next(elem);
872
g_warning("Could not select interface (index: %d): non existent.",index);
874
g_warning("Could not select interface %s: non existent.",ifname);
878
void linphone_core_set_connection_type(LinphoneCore *lc, int type)
880
lc->net_conf.con_type=type;
881
lc->net_conf.bandwidth=bandwidths[type];
882
linphone_core_check_codecs_for_bandwidth(lc);
885
int linphone_core_get_connection_type(LinphoneCore *lc)
887
return lc->net_conf.con_type;
738
MSList * linphone_core_get_friend_list(LinphoneCore *lc)
890
743
int linphone_core_get_audio_jittcomp(LinphoneCore *lc)
907
764
lc->rtp_conf.audio_rtp_port=port;
767
void linphone_core_set_video_port(LinphoneCore *lc, int port){
768
lc->rtp_conf.video_rtp_port=port;
771
bool_t linphone_core_get_use_info_for_dtmf(LinphoneCore *lc)
773
return lc->sip_conf.use_info;
776
void linphone_core_set_use_info_for_dtmf(LinphoneCore *lc,bool_t use_info)
778
lc->sip_conf.use_info=use_info;
910
781
int linphone_core_get_sip_port(LinphoneCore *lc)
912
783
return lc->sip_conf.sip_port;
786
static bool_t exosip_running=FALSE;
915
788
void linphone_core_set_sip_port(LinphoneCore *lc,int port)
791
if (port==lc->sip_conf.sip_port) return;
917
792
lc->sip_conf.sip_port=port;
918
linphone_core_update_contact_info(lc);
793
if (exosip_running) eXosip_quit();
794
err=eXosip_init(NULL,stdout,port);
796
char *msg=ortp_strdup_printf("UDP port %i seems already in use ! Cannot initialize.",port);
798
lc->vtable.display_warning(lc,msg);
802
#ifdef VINCENT_MAURY_RSVP
803
/* tell exosip the qos settings according to default linphone parameters */
804
eXosip_set_rsvp_mode (lc->rsvp_enable);
805
eXosip_set_rpc_mode (lc->rpc_enable);
807
eXosip_set_user_agent("Linphone-" LINPHONE_VERSION "/eXosip");
811
bool_t linphone_core_ipv6_enabled(LinphoneCore *lc){
812
return lc->sip_conf.ipv6_enabled;
814
void linphone_core_enable_ipv6(LinphoneCore *lc, bool_t val){
815
if (lc->sip_conf.ipv6_enabled!=val){
816
lc->sip_conf.ipv6_enabled=val;
817
eXosip_enable_ipv6(val);
819
/* we need to restart eXosip */
820
linphone_core_set_sip_port(lc, lc->sip_conf.sip_port);
825
static void display_bandwidth(RtpSession *as, RtpSession *vs){
826
ms_message("bandwidth usage: audio=[d=%.1f,u=%.1f] video=[d=%.1f,u=%.1f] kbit/sec",
827
(as!=NULL) ? (rtp_session_compute_recv_bandwidth(as)*1e-3) : 0,
828
(as!=NULL) ? (rtp_session_compute_send_bandwidth(as)*1e-3) : 0,
829
(vs!=NULL) ? (rtp_session_compute_recv_bandwidth(vs)*1e-3) : 0,
830
(vs!=NULL) ? (rtp_session_compute_send_bandwidth(vs)*1e-3) : 0);
921
833
void linphone_core_iterate(LinphoneCore *lc)
923
check_for_registration(lc);
924
if (lc->preview_finished){
925
lc->preview_finished=0;
926
ring_stop(lc->ringstream);
928
lc_callback_obj_invoke(&lc->preview_finished_cb,lc);
932
gboolean sipurl_check(gchar *url)
936
if (url==NULL) return FALSE;
837
printf("entering linphone_core_iterate()\n");
839
if (lc->preview_finished){
840
lc->preview_finished=0;
841
ring_stop(lc->ringstream);
843
lc_callback_obj_invoke(&lc->preview_finished_cb,lc);
846
printf("getting eXosip event...\n");
939
err=from_parse(surl,url);
940
if (err<0) ret=FALSE;
850
while((ev=eXosip_event_wait(0,0))!=NULL){
851
linphone_core_process_event(lc,ev);
853
linphone_core_update_proxy_register(lc);
854
linphone_core_refresh_subscribes(lc);
857
LinphoneCall *call=lc->call;
859
time_t curtime=time(NULL);
860
if (call->dir==LinphoneCallIncoming && call->state==LCStateRinging){
861
elapsed=curtime-call->start_time;
862
ms_message("incoming call ringing for %i seconds",elapsed);
863
if (elapsed>lc->sip_conf.inc_timeout){
864
linphone_core_terminate_call(lc,NULL);
866
}else if (call->state==LCStateAVRunning){
867
elapsed=curtime-lc->prevtime;
869
RtpSession *as=NULL,*vs=NULL;
870
lc->prevtime=curtime;
871
if (lc->audiostream!=NULL)
872
as=lc->audiostream->session;
873
if (lc->videostream!=NULL)
874
vs=lc->videostream->session;
875
display_bandwidth(as,vs);
881
printf("iterate done...\n");
886
bool_t linphone_core_is_in_main_thread(LinphoneCore *lc){
890
static osip_to_t *osip_to_create(const char *to){
893
if (osip_to_parse(ret,to)<0){
947
int linphone_core_invite(LinphoneCore *lc, char *url)
900
bool_t linphone_core_interpret_url(LinphoneCore *lc, const char *url, char **real_url, osip_to_t **real_parsed_url){
951
901
enum_lookup_res_t *enumres=NULL;
954
linphone_core_lock(lc);
902
osip_to_t *parsed_url=NULL;
903
char *enum_domain=NULL;
904
LinphoneProxyConfig *proxy;
907
if (real_url!=NULL) *real_url=NULL;
908
if (real_parsed_url!=NULL) *real_parsed_url=NULL;
955
910
if (is_enum(url,&enum_domain)){
956
911
lc->vtable.display_status(lc,_("Looking for telephone number destination..."));
957
912
if (enum_lookup(enum_domain,&enumres)<0){
958
913
lc->vtable.display_status(lc,_("Could not resolve this number."));
960
linphone_core_unlock(lc);
964
url=enumres->sip_address[0];
966
if (!sipurl_check(url) ){
967
lc->vtable.display_warning(lc,_("Bad formuled sip address. A sip address looks like <sip:username@domainname>"));
968
linphone_core_unlock(lc);
914
ms_free(enum_domain);
917
ms_free(enum_domain);
918
tmpurl=enumres->sip_address[0];
919
if (real_url!=NULL) *real_url=ms_strdup(tmpurl);
920
if (real_parsed_url!=NULL) *real_parsed_url=osip_to_create(tmpurl);
921
enum_lookup_res_free(enumres);
924
/* check if we have a "sip:" */
925
if (strstr(url,"sip:")==NULL){
926
/* this doesn't look like a true sip uri */
927
proxy=lc->default_proxy;
929
/* append the proxy suffix */
930
osip_uri_t *proxy_uri;
932
const char *proxy_addr=linphone_proxy_config_get_addr(proxy);
933
osip_uri_init(&proxy_uri);
934
if (osip_uri_parse(proxy_uri,proxy_addr)<0){
935
osip_uri_free(proxy_uri);
938
if (proxy_uri->port!=NULL)
939
sipaddr=ortp_strdup_printf("sip:%s@%s:%s",url,proxy_uri->host,proxy_uri->port);
941
sipaddr=ortp_strdup_printf("sip:%s@%s",url,proxy_uri->host);
942
if (real_parsed_url!=NULL) *real_parsed_url=osip_to_create(sipaddr);
943
if (real_url!=NULL) *real_url=sipaddr;
944
else ms_free(sipaddr);
948
parsed_url=osip_to_create(url);
949
if (parsed_url!=NULL){
950
if (real_url!=NULL) *real_url=ms_strdup(url);
951
if (real_parsed_url!=NULL) *real_parsed_url=parsed_url;
952
else osip_to_free(parsed_url);
955
/* else we could not do anything with url given by user, so display an error */
956
if (lc->vtable.display_warning!=NULL){
957
lc->vtable.display_warning(lc,_("Could not parse given sip address. A sip url usually looks like sip:user@domain"));
962
const char * linphone_core_get_identity(LinphoneCore *lc){
963
LinphoneProxyConfig *proxy=NULL;
965
linphone_core_get_default_proxy(lc,&proxy);
967
from=linphone_proxy_config_get_identity(proxy);
968
}else from=linphone_core_get_primary_contact(lc);
972
const char * linphone_core_get_route(LinphoneCore *lc){
973
LinphoneProxyConfig *proxy=NULL;
974
const char *route=NULL;
975
linphone_core_get_default_proxy(lc,&proxy);
977
route=linphone_proxy_config_get_route(proxy);
982
int linphone_core_invite(LinphoneCore *lc, const char *url)
988
const char *from=NULL;
989
osip_message_t *invite=NULL;
990
sdp_context_t *ctx=NULL;
991
LinphoneProxyConfig *proxy=NULL;
992
osip_from_t *parsed_url2=NULL;
993
osip_to_t *real_parsed_url=NULL;
973
barmsg=g_malloc(strlen(url)+strlen(contacting)+2);
974
sprintf(barmsg,"%s %s",contacting,url);
997
lc->vtable.display_warning(lc,_("Sorry, having multiple simultaneous calls is not supported yet !"));
1000
linphone_core_get_default_proxy(lc,&proxy);
1001
if (!linphone_core_interpret_url(lc,url,&real_url,&real_parsed_url)){
1005
barmsg=ortp_strdup_printf("%s %s", _("Contacting"), real_url);
975
1006
lc->vtable.display_status(lc,barmsg);
977
lc->call=osip_dialog_new(lc->ua);
978
err=osip_dialog_invite(lc->call,url,"application/sdp");
980
g_warning("error in invite: %s (%i)\n",strerror(err),err);
981
lc->vtable.display_status(lc,ready);
983
if (enumres!=0) enum_lookup_res_free(enumres);
984
linphone_core_unlock(lc);
988
gboolean linphone_core_inc_invite_pending(LinphoneCore*lc){
992
linphone_core_lock(lc);
993
if (lc->call->status==DIALOG_INVITED){
994
linphone_core_unlock(lc);
1000
int linphone_core_accept_dialog(LinphoneCore *lc, const char *url)
1002
LinphoneDialogParams *diaparams;
1003
StreamParams *audio_params;
1007
if (lc->call==NULL){
1010
linphone_core_lock(lc);
1011
if (lc->call->status!=DIALOG_INVITED){
1012
g_warning("No dialog to accept.");
1013
linphone_core_unlock(lc);
1016
diaparams=(LinphoneDialogParams *)lc->call->data;
1017
audio_params=&diaparams->audio_params;
1009
route=linphone_proxy_config_get_route(proxy);
1010
from=linphone_proxy_config_get_identity(proxy);
1012
/* if no proxy or no identity defined for this proxy, default to primary contact*/
1013
if (from==NULL) from=linphone_core_get_primary_contact(lc);
1015
err=eXosip_build_initial_invite(&invite,(char*)real_url,(char*)from,
1016
(char*)route,"Phone call");
1019
ms_warning("Could not build initial invite");
1022
/* make sdp message */
1024
osip_from_init(&parsed_url2);
1025
osip_from_parse(parsed_url2,from);
1027
lc->call=linphone_call_new_outgoing(lc,parsed_url2,real_parsed_url);
1028
ctx=lc->call->sdpctx;
1029
sdpmesg=sdp_context_get_offer(ctx);
1031
err=eXosip_initiate_call_with_body(invite,"application/sdp",sdpmesg,(void*)lc->call);
1035
ms_warning("Could not initiate call.");
1036
lc->vtable.display_status(lc,_("could not call"));
1037
linphone_call_destroy(lc->call);
1043
if (real_url!=NULL) ms_free(real_url);
1044
if (real_parsed_url!=NULL) osip_to_free(real_parsed_url);
1045
if (parsed_url2!=NULL) osip_from_free(parsed_url2);
1046
return (err<0) ? -1 : 0;
1049
int linphone_core_refer(LinphoneCore *lc, const char *url)
1051
char *real_url=NULL;
1052
osip_to_t *real_parsed_url=NULL;
1054
if (!linphone_core_interpret_url(lc,url,&real_url,&real_parsed_url)){
1060
ms_warning("No established call to refer.");
1066
eXosip_transfer_call(call->did, real_url);
1071
bool_t linphone_core_inc_invite_pending(LinphoneCore*lc){
1072
if (lc->call==NULL){
1078
#ifdef VINCENT_MAURY_RSVP
1079
/* on=1 for RPC_ENABLE=1...*/
1080
int linphone_core_set_rpc_mode(LinphoneCore *lc, int on)
1083
printf("RPC_ENABLE set on\n");
1085
printf("RPC_ENABLE set off\n");
1086
lc->rpc_enable = (on==1);
1087
/* need to tell eXosip the new setting */
1088
if (eXosip_set_rpc_mode (lc->rpc_enable)!=0)
1093
/* on=1 for RSVP_ENABLE=1...*/
1094
int linphone_core_set_rsvp_mode(LinphoneCore *lc, int on)
1097
printf("RSVP_ENABLE set on\n");
1099
printf("RSVP_ENABLE set off\n");
1100
lc->rsvp_enable = (on==1);
1101
/* need to tell eXosip the new setting */
1102
if (eXosip_set_rsvp_mode (lc->rsvp_enable)!=0)
1107
/* answer : 1 for yes, 0 for no */
1108
int linphone_core_change_qos(LinphoneCore *lc, int answer)
1111
if (lc->call==NULL){
1115
if (lc->rsvp_enable && answer==1)
1117
/* answer is yes, local setting is with qos, so
1118
* the user chose to continue with no qos ! */
1119
/* so switch in normal mode : ring and 180 */
1120
lc->rsvp_enable = 0; /* no more rsvp */
1121
eXosip_set_rsvp_mode (lc->rsvp_enable);
1124
eXosip_answer_call(lc->call->did,180,NULL);
1127
ms_message("Starting local ring...");
1128
lc->ringstream=ring_start(lc->sound_conf.local_ring,
1129
2000,ms_snd_card_manager_get_card(ms_snd_card_manager_get(),lc->sound_conf.ring_sndcard));
1131
else if (!lc->rsvp_enable && answer==1)
1133
/* switch to QoS mode on : answer 183 session progress */
1134
lc->rsvp_enable = 1;
1135
eXosip_set_rsvp_mode (lc->rsvp_enable);
1136
/* take the sdp already computed, see osipuacb.c */
1137
sdpmesg=lc->call->sdpctx->answerstr;
1139
eXosip_answer_call_with_body(lc->call->did,183,"application/sdp",sdpmesg);
1144
/* decline offer (603) */
1145
linphone_core_terminate_call(lc, NULL);
1151
void linphone_core_start_media_streams(LinphoneCore *lc, LinphoneCall *call){
1152
osip_from_t *me=linphone_core_get_primary_contact_parsed(lc);
1153
const char *tool="linphone-" LINPHONE_VERSION;
1154
char *cname=ortp_strdup_printf("%s@%s",me->url->username,me->url->host);
1157
StreamParams *audio_params=&call->audio_params;
1158
if (!lc->use_files){
1159
MSSndCard *playcard=lc->sound_conf.play_sndcard;
1160
MSSndCard *captcard=lc->sound_conf.capt_sndcard;
1161
if (playcard==NULL) {
1162
ms_warning("No card defined for playback !");
1165
if (captcard==NULL) {
1166
ms_warning("No card defined for capture !");
1170
/* adjust rtp jitter compensation. It must be at least the latency of the sound card */
1171
jitt_comp=MAX(lc->sound_conf.latency,lc->rtp_conf.audio_jitt_comp);
1172
lc->audiostream=audio_stream_start_with_sndcards(
1174
audio_params->localport,
1175
audio_params->remoteaddr,
1176
audio_params->remoteport,
1181
linphone_core_echo_cancelation_enabled(lc));
1183
lc->audiostream=audio_stream_start_with_files(
1185
audio_params->localport,
1186
audio_params->remoteaddr,
1187
audio_params->remoteport,
1193
if (lc->audiostream==NULL){
1194
/* should terminate call */
1197
audio_stream_set_rtcp_information(lc->audiostream, cname, tool);
1200
#ifdef VIDEO_ENABLED
1202
/* shutdown preview */
1203
if (lc->previewstream!=NULL) {
1204
video_preview_stop(lc->previewstream);
1205
lc->previewstream=NULL;
1207
if (lc->video_conf.enabled){
1209
StreamParams *video_params=&call->video_params;
1211
if (video_params->remoteport>0){
1212
/* adjust rtp jitter compensation. It must be at least the latency of the sound card */
1213
jitt_comp=MAX(lc->sound_conf.latency,lc->rtp_conf.audio_jitt_comp);
1214
lc->videostream=video_stream_start(call->profile,video_params->localport,
1215
video_params->remoteaddr,video_params->remoteport,
1216
video_params->pt,jitt_comp, lc->video_conf.device);
1217
video_stream_set_rtcp_information(lc->videostream, cname,tool);
1226
lc->call->state=LCStateAVRunning;
1229
void linphone_core_stop_media_streams(LinphoneCore *lc){
1230
if (lc->audiostream!=NULL) {
1231
audio_stream_stop(lc->audiostream);
1232
lc->audiostream=NULL;
1234
#ifdef VIDEO_ENABLED
1235
if (lc->videostream!=NULL){
1236
video_stream_stop(lc->videostream);
1237
lc->videostream=NULL;
1239
if (linphone_core_video_preview_enabled(lc)){
1240
if (lc->previewstream==NULL){
1241
lc->previewstream=video_preview_start(lc->video_conf.device);
1247
int linphone_core_accept_call(LinphoneCore *lc, const char *url)
1251
if (lc->call==NULL){
1255
if (lc->call->state==LCStateAVRunning){
1256
/*call already accepted*/
1019
1260
/*stop ringing */
1020
1261
if (lc->ringstream!=NULL) {
1022
1263
lc->ringstream=NULL;
1024
1265
/* sends a 200 OK */
1025
osip_dialog_accept_invite(lc->call,lc->current_trn);
1026
lc->vtable.display_status(lc,connected);
1266
sdpmesg=lc->call->sdpctx->answerstr; /* takes the sdp already computed*/
1268
eXosip_answer_call_with_body(lc->call->did,200,"application/sdp",sdpmesg);
1270
lc->vtable.display_status(lc,_("Connected."));
1028
if (try_open_dsp(lc)){
1029
/* adjust rtp jitter compensation. It must be at least the latency of the sound card */
1030
jitt_comp=MAX(lc->sound_conf.latency,lc->rtp_conf.audio_jitt_comp);
1031
lc->audiostream=audio_stream_start_with_sndcard(diaparams->profile,audio_params->localport,
1032
audio_params->remoteaddr,audio_params->remoteport,
1033
audio_params->pt,jitt_comp,lc->sound_conf.sndcard);
1035
linphone_core_unlock(lc);
1272
linphone_core_start_media_streams(lc, lc->call);
1039
int linphone_core_terminate_dialog(LinphoneCore *lc, const char *url)
1276
int linphone_core_terminate_call(LinphoneCore *lc, const char *url)
1041
OsipDialog *call=lc->call;
1042
LinphoneDialogParams *diaparams;
1278
LinphoneCall *call=lc->call;
1043
1279
if (call==NULL){
1047
linphone_core_lock(lc);
1048
diaparams=(LinphoneDialogParams*)call->data;
1051
if (call->status==DIALOG_INVITED )
1054
if (lc->ringstream!=NULL) {
1055
ring_stop(lc->ringstream);
1056
lc->ringstream=NULL;
1057
restore_sound_daemons();
1059
/* decline the invitation */
1060
osip_dialog_reject_invite(call);
1061
lc->vtable.display_status(lc,end);
1063
else if (call->status==DIALOG_ESTABLISHED)
1065
/* sends a bye, the call is terminated */
1066
if (lc->audiostream!=NULL) {
1067
audio_stream_stop(lc->audiostream);
1068
lc->audiostream=NULL;
1069
restore_sound_daemons();
1071
osip_dialog_bye(call);
1072
lc->vtable.display_status(lc,end);
1074
else if (call->status==DIALOG_INVITING)
1076
/*sends a cancel or a bye ???*/
1077
if (lc->ringstream!=NULL) {
1078
ring_stop(lc->ringstream);
1079
lc->ringstream=NULL;
1080
restore_sound_daemons();
1082
osip_dialog_bye(call);
1083
lc->vtable.display_status(lc,cancel);
1085
if (diaparams!=NULL) {
1087
linphone_dialog_params_destroy(diaparams);
1089
linphone_core_unlock(lc);
1093
void linphone_core_set_presence_info(LinphoneCore *lc,gint minutes_away,
1285
eXosip_terminate_call(call->cid,call->did);
1289
if (lc->ringstream!=NULL) {
1290
ring_stop(lc->ringstream);
1291
lc->ringstream=NULL;
1293
linphone_core_stop_media_streams(lc);
1294
lc->vtable.display_status(lc,_("Call ended") );
1295
linphone_call_destroy(call);
1299
int linphone_core_send_publish(LinphoneCore *lc,
1300
LinphoneOnlineStatus presence_mode)
1303
for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=ms_list_next(elem)){
1304
LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
1305
if (cfg->publish) linphone_proxy_config_send_publish(cfg,presence_mode);
1310
void linphone_core_set_inc_timeout(LinphoneCore *lc, int seconds){
1311
lc->sip_conf.inc_timeout=seconds;
1314
int linphone_core_get_inc_timeout(LinphoneCore *lc){
1315
return lc->sip_conf.inc_timeout;
1318
void linphone_core_set_presence_info(LinphoneCore *lc,int minutes_away,
1319
const char *contact,
1320
LinphoneOnlineStatus presence_mode)
1097
1322
int contactok=-1;
1098
if (minutes_away>0) osip_ua_set_presence_delay(lc->ua,minutes_away*60);
1323
if (minutes_away>0) lc->minutes_away=minutes_away;
1099
1324
if (contact!=NULL) {
1103
contactok=from_parse(url,contact);
1326
osip_from_init(&url);
1327
contactok=osip_from_parse(url,contact);
1104
1328
if (contactok>=0) {
1105
osip_ua_set_presence_contact_url(lc->ua,contact);
1106
g_message("contact url is correct.");
1329
ms_message("contact url is correct.");
1111
if (contactok<0 && (presence_mode==302 || presence_mode==380)){
1331
osip_from_free(url);
1335
if (lc->alt_contact!=NULL) ms_free(lc->alt_contact);
1336
lc->alt_contact=ms_strdup(contact);
1338
if (lc->presence_mode!=presence_mode){
1339
linphone_core_notify_all_friends(lc,presence_mode);
1341
Improve the use of all LINPHONE_STATUS available.
1342
!TODO Do not mix "presence status" with "answer status code"..
1343
Use correct parameter to follow sip_if_match/sip_etag.
1345
linphone_core_send_publish(lc,presence_mode);
1347
lc->presence_mode=presence_mode;
1115
osip_ua_set_presence_mode(lc->ua,presence_mode);
1118
1351
/* sound functions */
1119
gint linphone_core_get_play_level(LinphoneCore *lc)
1352
int linphone_core_get_play_level(LinphoneCore *lc)
1121
1354
return lc->sound_conf.play_lev;
1123
gint linphone_core_get_rec_level(LinphoneCore *lc){
1356
int linphone_core_get_ring_level(LinphoneCore *lc)
1358
return lc->sound_conf.ring_lev;
1360
int linphone_core_get_rec_level(LinphoneCore *lc){
1124
1361
return lc->sound_conf.rec_lev;
1126
void linphone_core_set_play_level(LinphoneCore *lc, gint level){
1363
void linphone_core_set_ring_level(LinphoneCore *lc, int level){
1365
lc->sound_conf.ring_lev=level;
1366
sndcard=lc->sound_conf.ring_sndcard;
1367
if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
1370
void linphone_core_set_play_level(LinphoneCore *lc, int level){
1127
1372
lc->sound_conf.play_lev=level;
1128
g_return_if_fail(lc->sound_conf.sndcard!=NULL);
1129
snd_card_set_level(lc->sound_conf.sndcard,SND_CARD_LEVEL_OUTPUT,level);
1373
sndcard=lc->sound_conf.play_sndcard;
1374
if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
1132
void linphone_core_set_rec_level(LinphoneCore *lc, gint level)
1377
void linphone_core_set_rec_level(LinphoneCore *lc, int level)
1134
1380
lc->sound_conf.rec_lev=level;
1135
g_return_if_fail(lc->sound_conf.sndcard!=NULL);
1136
snd_card_set_level(lc->sound_conf.sndcard,SND_CARD_LEVEL_INPUT,level);
1138
gint linphone_core_set_sound_device(LinphoneCore *lc, gint devid)
1143
g_warning("Bad devid value: %i",devid);
1146
sndcard=snd_card_manager_get_card(snd_card_manager,devid);
1148
g_warning("Sound card with index %i does not exist.");
1151
lc->sound_conf.dev_id=devid;
1152
lc->sound_conf.sndcard=sndcard;
1153
tmp=test_audio_dev(devid);
1154
if (tmp>0) lc->sound_conf.latency=tmp;
1158
gint linphone_core_set_sound_device_from_name(LinphoneCore *lc,gchar *name)
1162
card=snd_card_manager_get_card_with_string(snd_card_manager,name,&index);
1164
g_message("Setting card with id=%i",index);
1165
lc->sound_conf.dev_id=index;
1166
lc->sound_conf.sndcard=card;
1172
gint linphone_core_get_sound_device(LinphoneCore *lc)
1174
return lc->sound_conf.dev_id;
1177
SndCardManager * linphone_core_get_card_manager(LinphoneCore *lc){
1178
return snd_card_manager;
1181
gchar linphone_core_get_sound_source(LinphoneCore *lc)
1381
sndcard=lc->sound_conf.capt_sndcard;
1382
if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_CAPTURE,level);
1385
static MSSndCard *get_card_from_string_id(const char *devid){
1386
MSSndCard *sndcard=NULL;
1388
sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
1390
if (sndcard==NULL) sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
1394
int linphone_core_set_ringer_device(LinphoneCore *lc, const char * devid){
1395
lc->sound_conf.ring_sndcard=get_card_from_string_id(devid);
1399
int linphone_core_set_playback_device(LinphoneCore *lc, const char * devid){
1400
lc->sound_conf.play_sndcard=get_card_from_string_id(devid);
1404
int linphone_core_set_capture_device(LinphoneCore *lc, const char * devid){
1405
lc->sound_conf.capt_sndcard=get_card_from_string_id(devid);
1409
const char * linphone_core_get_ringer_device(LinphoneCore *lc)
1411
return ms_snd_card_get_string_id(lc->sound_conf.ring_sndcard);
1414
const char * linphone_core_get_playback_device(LinphoneCore *lc)
1416
return ms_snd_card_get_string_id(lc->sound_conf.play_sndcard);
1419
const char * linphone_core_get_capture_device(LinphoneCore *lc)
1421
return ms_snd_card_get_string_id(lc->sound_conf.capt_sndcard);
1424
/* returns a static array of string describing the sound devices */
1425
const char** linphone_core_get_sound_devices(LinphoneCore *lc){
1426
return lc->sound_conf.cards;
1429
char linphone_core_get_sound_source(LinphoneCore *lc)
1183
1431
return lc->sound_conf.source;
1185
void linphone_core_set_sound_source(LinphoneCore *lc, gchar source)
1434
void linphone_core_set_sound_source(LinphoneCore *lc, char source)
1436
MSSndCard *sndcard=lc->sound_conf.capt_sndcard;
1187
1437
lc->sound_conf.source=source;
1188
g_return_if_fail(lc->sound_conf.sndcard!=NULL);
1189
snd_card_set_rec_source(lc->sound_conf.sndcard,source);
1440
ms_snd_card_set_capture(sndcard,MS_SND_CARD_MIC);
1443
ms_snd_card_set_capture(sndcard,MS_SND_CARD_LINE);
1192
void linphone_core_set_ring(LinphoneCore *lc,gchar *path){
1449
void linphone_core_set_ring(LinphoneCore *lc,const char *path){
1193
1450
if (lc->sound_conf.local_ring!=0){
1194
g_free(lc->sound_conf.local_ring);
1451
ms_free(lc->sound_conf.local_ring);
1196
lc->sound_conf.local_ring=g_strdup(path);
1453
lc->sound_conf.local_ring=ms_strdup(path);
1198
gchar *linphone_core_get_ring(LinphoneCore *lc){
1455
char *linphone_core_get_ring(LinphoneCore *lc){
1199
1456
return lc->sound_conf.local_ring;
1202
static void notify_end_of_ring(MSFilter *f,gint event, gpointer value,gpointer user_data){
1203
LinphoneCore *lc=(LinphoneCore*)user_data;
1204
lc->preview_finished=1;
1459
static void notify_end_of_ring(void *ud ,unsigned int event, void * arg){
1460
LinphoneCore *lc=(LinphoneCore*)ud;
1461
lc->preview_finished=1;
1207
gint linphone_core_preview_ring(LinphoneCore *lc, const gchar *ring,LinphoneCoreCbFunc func,gpointer userdata)
1464
int linphone_core_preview_ring(LinphoneCore *lc, const char *ring,LinphoneCoreCbFunc func,void * userdata)
1209
if (lc->ringstream!=0){
1210
g_warning("Cannot start ring now,there's already a ring being played");
1213
lc_callback_obj_init(&lc->preview_finished_cb,func,userdata);
1214
lc->preview_finished=0;
1215
if (try_open_dsp(lc)<0) return;
1216
lc->ringstream=ring_start_with_cb((char*)ring,2,lc->sound_conf.sndcard,(MSFilterNotifyFunc)notify_end_of_ring,(gpointer)lc);
1466
if (lc->ringstream!=0){
1467
ms_warning("Cannot start ring now,there's already a ring being played");
1470
lc_callback_obj_init(&lc->preview_finished_cb,func,userdata);
1471
lc->preview_finished=0;
1472
if (lc->sound_conf.ring_sndcard!=NULL)
1473
lc->ringstream=ring_start_with_cb((char*)ring,2000,lc->sound_conf.ring_sndcard,notify_end_of_ring,(void *)lc);
1231
1488
RingBackType linphone_core_get_ringback(LinphoneCore *lc);
1233
void linphone_core_send_dtmf(LinphoneCore *lc,gchar dtmf)
1235
if (lc->audiostream!=NULL){
1236
send_dtmf(lc->audiostream,dtmf);
1239
void linphone_core_force_ip_address(LinphoneCore *lc, gchar *ipaddr)
1241
linphone_core_set_nat_address(lc,ipaddr,1);
1245
void linphone_core_set_nat_address(LinphoneCore *lc, gchar *addr, gboolean use)
1490
void linphone_core_enable_echo_cancelation(LinphoneCore *lc, bool_t val){
1491
lc->sound_conf.ec=val;
1494
bool_t linphone_core_echo_cancelation_enabled(LinphoneCore *lc){
1495
return lc->sound_conf.ec;
1499
void linphone_core_send_dtmf(LinphoneCore *lc,char dtmf)
1501
if (linphone_core_get_use_info_for_dtmf(lc)==0){
1503
if (lc->audiostream!=NULL){
1504
audio_stream_send_dtmf(lc->audiostream,dtmf);
1508
char dtmf_body[1000];
1509
/* Out of Band DTMF (use INFO method) */
1510
LinphoneCall *call=lc->call;
1516
snprintf(dtmf_body, 999, "Signal=%c\r\nDuration=250\r\n", dtmf);
1518
eXosip_info_call(call->did, "application/dtmf-relay", dtmf_body);
1523
void linphone_core_set_stun_server(LinphoneCore *lc, const char *server){
1524
if (lc->net_conf.stun_server!=NULL)
1525
ms_free(lc->net_conf.stun_server);
1527
lc->net_conf.stun_server=ms_strdup(server);
1528
else lc->net_conf.stun_server=NULL;
1529
lc->apply_nat_settings=TRUE;
1532
const char * linphone_core_get_stun_server(const LinphoneCore *lc){
1533
return lc->net_conf.stun_server;
1536
static void apply_nat_settings(LinphoneCore *lc){
1249
1540
struct addrinfo hints,*res;
1541
const char *addr=lc->net_conf.nat_address;
1251
if (addr!=NULL && use){
1543
if (lc->net_conf.firewall_policy==LINPHONE_POLICY_USE_NAT_ADDRESS && addr!=NULL && strlen(addr)>0){
1544
/*check the ip address given */
1252
1545
memset(&hints,0,sizeof(struct addrinfo));
1253
hints.ai_family=PF_UNSPEC;
1546
if (lc->sip_conf.ipv6_enabled)
1547
hints.ai_family=AF_INET6;
1549
hints.ai_family=AF_INET;
1254
1550
hints.ai_socktype = SOCK_DGRAM;
1255
1551
err=getaddrinfo(addr,NULL,&hints,&res);
1553
wmsg=ortp_strdup_printf(_("Invalid nat address '%s' : %s"),
1554
addr, gai_strerror(err));
1555
ms_warning(wmsg); // what is this for ?
1556
lc->vtable.display_warning(lc, wmsg);
1558
linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_NO_FIREWALL);
1561
/*now get it as an numeric ip address */
1563
err=getnameinfo(res->ai_addr,res->ai_addrlen,tmp,50,NULL,0,NI_NUMERICHOST);
1565
wmsg=ortp_strdup_printf(_("Invalid nat address '%s' : %s"),
1566
addr, gai_strerror(err));
1567
ms_warning(wmsg); // what is this for ?
1568
lc->vtable.display_warning(lc, wmsg);
1258
1571
freeaddrinfo(res);
1260
g_warning("Invalid nat address %s",addr);
1572
linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_NO_FIREWALL);
1578
if (lc->net_conf.firewall_policy==LINPHONE_POLICY_USE_NAT_ADDRESS){
1580
if (!lc->net_conf.nat_sdp_only)
1581
eXosip_set_firewallip(tmp);
1585
eXosip_set_firewallip("");
1588
eXosip_set_firewallip("");
1593
void linphone_core_set_nat_address(LinphoneCore *lc, const char *addr)
1264
1595
if (lc->net_conf.nat_address!=NULL){
1265
g_free(lc->net_conf.nat_address);
1596
ms_free(lc->net_conf.nat_address);
1267
lc->net_conf.nat_address=tmp;
1268
if (use && (tmp!=NULL)){
1270
/* change OsipUA object main contact */
1271
if (lc->sip_conf.sip_port==5060){
1272
ct=g_strdup_printf("sip:%s@%s",lc->sip_conf.username,tmp);
1598
if (addr!=NULL) lc->net_conf.nat_address=ms_strdup(addr);
1599
else lc->net_conf.nat_address=NULL;
1600
lc->apply_nat_settings=TRUE;
1603
const char *linphone_core_get_nat_address(const LinphoneCore *lc)
1605
return lc->net_conf.nat_address;
1608
void linphone_core_set_firewall_policy(LinphoneCore *lc, LinphoneFirewallPolicy pol){
1609
lc->net_conf.firewall_policy=pol;
1610
lc->apply_nat_settings=TRUE;
1613
LinphoneFirewallPolicy linphone_core_get_firewall_policy(const LinphoneCore *lc){
1614
return lc->net_conf.firewall_policy;
1617
MSList * linphone_core_get_call_logs(LinphoneCore *lc){
1619
return lc->call_logs;
1622
void linphone_core_enable_video_preview(LinphoneCore *lc, bool_t val){
1623
lc->video_conf.show_local=val;
1624
#ifdef VIDEO_ENABLED
1625
if (lc->videostream==NULL){
1627
if (lc->previewstream==NULL){
1628
lc->previewstream=video_preview_start(lc->video_conf.device);
1274
ct=g_strdup_printf("sip:%s@%s:%i",lc->sip_conf.username,tmp,
1275
lc->sip_conf.sip_port);
1631
if (lc->previewstream!=NULL){
1632
video_preview_stop(lc->previewstream);
1633
lc->previewstream=NULL;
1277
osip_ua_set_contact(lc->ua,ct);
1279
lc->net_conf.use_nat=TRUE;
1282
lc->net_conf.use_nat=FALSE;
1283
linphone_core_update_contact_info(lc);
1287
gchar *linphone_core_get_nat_address(LinphoneCore *lc, gboolean *use)
1289
if (use!=NULL) *use=lc->net_conf.use_nat;
1290
if (lc->net_conf.nat_address!=NULL) return g_strdup(lc->net_conf.nat_address);
1294
void net_config_uninit(net_config_t *config)
1296
#ifdef LINPHONE_DEPRECATED
1297
gnome_config_set_string("net/if_name",config->sel_if->name);
1298
g_list_foreach(config->interfaces,(GFunc)g_free,NULL);
1299
g_list_free(config->interfaces);
1300
config->interfaces=NULL;
1302
gnome_config_set_int("net/con_type",config->con_type);
1640
void linphone_core_enable_video(LinphoneCore *lc, bool_t val){
1641
#ifndef VIDEO_ENABLED
1643
ms_warning("This version of linphone was built without video support.");
1645
lc->video_conf.enabled=val;
1646
linphone_core_enable_video_preview(lc,val);
1647
/* need to re-apply network bandwidth settings*/
1648
linphone_core_set_download_bandwidth(lc,
1649
linphone_core_get_download_bandwidth(lc));
1650
linphone_core_set_upload_bandwidth(lc,
1651
linphone_core_get_upload_bandwidth(lc));
1654
bool_t linphone_core_video_enabled(LinphoneCore *lc){
1655
return lc->video_conf.enabled;
1659
bool_t linphone_core_video_preview_enabled(const LinphoneCore *lc){
1660
return lc->video_conf.show_local;
1663
int linphone_core_set_video_device(LinphoneCore *lc, const char *method, const char *device){
1664
if (lc->video_conf.device!=NULL){
1665
ms_free(lc->video_conf.device);
1666
lc->video_conf.device=NULL;
1669
lc->video_conf.device=ms_strdup(device);
1673
void linphone_core_use_files(LinphoneCore *lc, bool_t yesno){
1674
lc->use_files=yesno;
1677
void linphone_core_set_play_file(LinphoneCore *lc, const char *file){
1678
if (lc->play_file!=NULL){
1679
ms_free(lc->play_file);
1683
lc->play_file=ms_strdup(file);
1684
if (lc->audiostream)
1685
audio_stream_play(lc->audiostream,file);
1689
void linphone_core_set_record_file(LinphoneCore *lc, const char *file){
1690
if (lc->rec_file!=NULL){
1691
ms_free(lc->rec_file);
1695
lc->rec_file=ms_strdup(file);
1696
if (lc->audiostream)
1697
audio_stream_record(lc->audiostream,file);
1702
void *linphone_core_get_user_data(LinphoneCore *lc){
1706
void net_config_uninit(LinphoneCore *lc)
1708
net_config_t *config=&lc->net_conf;
1709
lp_config_set_int(lc->config,"net","download_bw",config->download_bw);
1710
lp_config_set_int(lc->config,"net","upload_bw",config->upload_bw);
1304
gnome_config_set_int("net/use_nat",config->use_nat);
1712
if (config->stun_server!=NULL)
1713
lp_config_set_string(lc->config,"net","stun_server",config->stun_server);
1305
1714
if (config->nat_address!=NULL)
1306
gnome_config_set_string("net/nat_address",config->nat_address);
1310
void registrar_config_uninit(registrar_config_t *config)
1312
gnome_config_set_int("sip/use_registrar",config->use_registrar);
1313
gnome_config_set_int("sip/as_proxy",config->as_proxy);
1314
if (config->registrar!=NULL)
1315
gnome_config_set_string("sip/registrar",config->registrar);
1316
if (config->passwd!=NULL)
1317
gnome_config_set_string("sip/passwd",config->passwd);
1318
if (config->addr_of_rec!=NULL)
1319
gnome_config_set_string("sip/addr_of_rec",config->addr_of_rec);
1320
gnome_config_set_int("sip/expires",config->expires);
1321
g_timer_destroy(config->timer);
1323
void sip_config_uninit(sip_config_t *config)
1325
gnome_config_set_string("sip/username",config->username);
1326
gnome_config_set_string("sip/hostname", config->hostname);
1327
gnome_config_set_int("sip/sip_port",config->sip_port);
1328
registrar_config_uninit(&config->reg_conf);
1331
void rtp_config_uninit(rtp_config_t *config)
1333
gnome_config_set_int("rtp/audio_rtp_port",config->audio_rtp_port);
1334
gnome_config_set_int("rtp/video_rtp_port",config->video_rtp_port);
1335
gnome_config_set_int("rtp/audio_jitt_comp",config->audio_jitt_comp);
1336
gnome_config_set_int("rtp/video_jitt_comp",config->audio_jitt_comp);
1339
void sound_config_uninit(sound_config_t *config)
1342
gnome_config_set_int("sound/dev_id",config->dev_id);
1343
gnome_config_set_int("sound/rec_lev",config->rec_lev);
1344
gnome_config_set_int("sound/play_lev",config->play_lev);
1715
lp_config_set_string(lc->config,"net","nat_address",config->nat_address);
1716
lp_config_set_int(lc->config,"net","firewall_policy",config->firewall_policy);
1720
void sip_config_uninit(LinphoneCore *lc)
1724
sip_config_t *config=&lc->sip_conf;
1725
lp_config_set_int(lc->config,"sip","sip_port",config->sip_port);
1726
lp_config_set_int(lc->config,"sip","guess_hostname",config->guess_hostname);
1727
lp_config_set_string(lc->config,"sip","contact",config->contact);
1728
lp_config_set_int(lc->config,"sip","inc_timeout",config->inc_timeout);
1729
lp_config_set_int(lc->config,"sip","use_info",config->use_info);
1730
lp_config_set_int(lc->config,"sip","use_ipv6",config->ipv6_enabled);
1731
for(elem=config->proxies,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
1732
LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)(elem->data);
1733
linphone_proxy_config_write_to_config_file(lc->config,cfg,i);
1734
linphone_proxy_config_edit(cfg); /* to unregister */
1743
while((ev=eXosip_event_wait(0,0))!=NULL){
1744
linphone_core_process_event(lc,ev);
1754
linphone_proxy_config_write_to_config_file(lc->config,NULL,i); /*mark the end */
1756
for(elem=lc->auth_info,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
1757
LinphoneAuthInfo *ai=(LinphoneAuthInfo*)(elem->data);
1758
linphone_auth_info_write_config(lc->config,ai,i);
1760
linphone_auth_info_write_config(lc->config,NULL,i); /* mark the end */
1763
void rtp_config_uninit(LinphoneCore *lc)
1765
rtp_config_t *config=&lc->rtp_conf;
1766
lp_config_set_int(lc->config,"rtp","audio_rtp_port",config->audio_rtp_port);
1767
lp_config_set_int(lc->config,"rtp","video_rtp_port",config->video_rtp_port);
1768
lp_config_set_int(lc->config,"rtp","audio_jitt_comp",config->audio_jitt_comp);
1769
lp_config_set_int(lc->config,"rtp","video_jitt_comp",config->audio_jitt_comp);
1772
void sound_config_uninit(LinphoneCore *lc)
1775
sound_config_t *config=&lc->sound_conf;
1776
lp_config_set_string(lc->config,"sound","playback_dev_id",ms_snd_card_get_string_id(config->play_sndcard));
1777
lp_config_set_string(lc->config,"sound","ringer_dev_id",ms_snd_card_get_string_id(config->ring_sndcard));
1778
lp_config_set_string(lc->config,"sound","capture_dev_id",ms_snd_card_get_string_id(config->capt_sndcard));
1779
ms_free(config->cards);
1781
lp_config_set_int(lc->config,"sound","rec_lev",config->rec_lev);
1782
lp_config_set_int(lc->config,"sound","play_lev",config->play_lev);
1783
lp_config_set_int(lc->config,"sound","ring_lev",config->ring_lev);
1345
1784
tmpbuf[0]=config->source;
1346
1785
tmpbuf[1]='\0';
1347
gnome_config_set_string("sound/source",tmpbuf);
1348
gnome_config_set_string("sound/local_ring",config->local_ring);
1349
gnome_config_set_string("sound/remote_ring",config->remote_ring);
1786
lp_config_set_string(lc->config,"sound","source",tmpbuf);
1788
lp_config_set_string(lc->config,"sound","local_ring",config->local_ring);
1789
lp_config_set_string(lc->config,"sound","remote_ring",config->remote_ring);
1790
lp_config_set_int(lc->config,"sound","echocancelation",config->ec);
1352
void video_config_uninit(video_config_t *config)
1793
void video_config_uninit(LinphoneCore *lc)
1354
gnome_config_set_int("video/enabled",config->enabled);
1355
gnome_config_set_int("video/show_local",config->show_local);
1795
video_config_t *config=&lc->video_conf;
1796
lp_config_set_int(lc->config,"video","enabled",config->enabled);
1797
lp_config_set_int(lc->config,"video","show_local",config->show_local);
1358
void codecs_config_uninit(codecs_config_t *config)
1800
void codecs_config_uninit(LinphoneCore *lc)
1360
1802
PayloadType *pt;
1803
codecs_config_t *config=&lc->codecs_conf;
1365
for(node=config->audio_codecs;node!=NULL;node=g_list_next(node)){
1808
for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
1366
1809
pt=(PayloadType*)(node->data);
1367
sprintf(key,"audio_codec_%i/mime",index);
1368
gnome_config_set_string(key,pt->mime_type);
1369
sprintf(key,"audio_codec_%i/rate",index);
1370
gnome_config_set_int(key,pt->clock_rate);
1371
sprintf(key,"audio_codec_%i/enabled",index);
1372
gnome_config_set_int(key,payload_type_enabled(pt));
1810
sprintf(key,"audio_codec_%i",index);
1811
lp_config_set_string(lc->config,key,"mime",pt->mime_type);
1812
lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
1813
lp_config_set_int(lc->config,key,"enabled",payload_type_enabled(pt));
1376
for(node=config->video_codecs;node!=NULL;node=g_list_next(node)){
1817
for(node=config->video_codecs;node!=NULL;node=ms_list_next(node)){
1377
1818
pt=(PayloadType*)(node->data);
1378
sprintf(key,"video_codec_%i/mime",index);
1379
gnome_config_set_string(key,pt->mime_type);
1380
sprintf(key,"video_codec_%i/rate",index);
1381
gnome_config_set_int(key,pt->clock_rate);
1382
sprintf(key,"video_codec_%i/enabled",index);
1383
gnome_config_set_int(key,payload_type_enabled(pt));
1819
sprintf(key,"video_codec_%i",index);
1820
lp_config_set_string(lc->config,key,"mime",pt->mime_type);
1821
lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
1822
lp_config_set_int(lc->config,key,"enabled",payload_type_enabled(pt));
1388
void ui_config_uninit(ui_config_t *config)
1827
void ui_config_uninit(LinphoneCore* lc)
1392
gchar ab_entry[100];
1393
/* record address book entries*/
1395
elem=config->address_list;
1398
snprintf(ab_entry,100,"address_book/entry%i",len);
1399
gnome_config_set_string(ab_entry,(gchar*)(elem->data));
1400
elem=g_list_next(elem);
1831
for (elem=lc->friends,i=0; elem!=NULL; elem=ms_list_next(elem),i++){
1832
linphone_friend_write_to_config_file(lc->config,(LinphoneFriend*)elem->data,i);
1833
linphone_friend_destroy(elem->data);
1403
gnome_config_set_int("address_book/entry_count",len);
1835
linphone_friend_write_to_config_file(lc->config,NULL,i); /* set the end */
1836
ms_list_free(lc->friends);
1840
LpConfig *linphone_core_get_config(LinphoneCore *lc){
1405
1844
void linphone_core_uninit(LinphoneCore *lc)
1407
/* unregister if necessary*/
1408
if (lc->sip_conf.reg_conf.use_registrar){
1409
do_registration(lc,0);
1846
#ifdef VIDEO_ENABLED
1847
if (lc->previewstream!=NULL){
1848
video_preview_stop(lc->previewstream);
1849
lc->previewstream=NULL;
1412
1852
/* save all config */
1413
net_config_uninit(&lc->net_conf);
1414
sip_config_uninit(&lc->sip_conf);
1415
rtp_config_uninit(&lc->rtp_conf);
1416
sound_config_uninit(&lc->sound_conf);
1417
video_config_uninit(&lc->video_conf);
1418
codecs_config_uninit(&lc->codecs_conf);
1419
ui_config_uninit(&lc->ui_conf);
1420
gnome_config_sync();
1853
net_config_uninit(lc);
1854
sip_config_uninit(lc);
1855
lp_config_set_int(lc->config,"sip","default_proxy",linphone_core_get_default_proxy(lc,NULL));
1856
rtp_config_uninit(lc);
1857
sound_config_uninit(lc);
1858
video_config_uninit(lc);
1859
codecs_config_uninit(lc);
1860
ui_config_uninit(lc);
1861
lp_config_sync(lc->config);
1862
lp_config_destroy(lc->config);
1866
exosip_running=FALSE;
1426
1869
void linphone_core_destroy(LinphoneCore *lc){
1427
1870
linphone_core_uninit(lc);