~ubuntu-branches/ubuntu/vivid/linphone/vivid

« back to all changes in this revision

Viewing changes to coreapi/linphonecore.c

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2006-11-15 10:34:50 UTC
  • mfrom: (1.2.1 upstream) (2.1.8 feisty)
  • Revision ID: james.westby@ubuntu.com-20061115103450-qgafwcks2lkhctlj
* New upstream release.
* Enable video support.
* Fix mismatched #endif in mscommon.h, closes: #398307.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
linphone
3
 
Copyright (C) 2000  Simon MORLAT (simon.morlat@free.fr)
 
3
Copyright (C) 2000  Simon MORLAT (simon.morlat@linphone.org)
4
4
 
5
5
This program is free software; you can redistribute it and/or
6
6
modify it under the terms of the GNU General Public License
18
18
*/
19
19
 
20
20
#include "linphonecore.h"
21
 
#include <mediastream.h>
22
 
#include <osipua.h>
23
 
#include "../osipua/src/sdphandler.h"
24
 
#include "gnome-config.h"
25
 
#include "misc.h"
26
 
 
27
 
#include <telephonyevents.h>
28
 
#include <utils.h>
29
 
#include "osipuacb.h"
30
 
#include "enum.h"
31
 
 
32
 
#include <net/if.h>
33
 
#include <sys/ioctl.h>
34
 
#include <sys/socket.h>
35
 
#include <netinet/in.h>
36
 
#include <arpa/inet.h>
 
21
#include "lpconfig.h"
 
22
#include "private.h"
 
23
#include "mediastreamer2/mediastream.h"
 
24
#include <eXosip.h>
 
25
#include "sdphandler.h"
 
26
 
 
27
#include <ortp/telephonyevents.h>
 
28
#include <ortp/stun.h>
 
29
#include "exevents.h"
 
30
 
37
31
 
38
32
#ifdef INET6  
 
33
#ifndef WIN32
39
34
#include <netdb.h>  
40
35
#endif
41
 
 
42
 
#define MAX_IF 20
43
 
const double bandwidths[5]=
44
 
{
45
 
        28800.0,        /*28k modem*/
46
 
        28800.0, /*56k modem*/
47
 
        64000.0, /*64k modem (numeris)*/
48
 
        128000.0,       /*adsl or cable*/
49
 
        10e6, /* ethernet */
50
 
};/* carefull: these are the upstream bandwidth !!!*/
 
36
#endif
 
37
 
 
38
#include "enum.h"
 
39
 
 
40
void linphone_core_enable_video_preview(LinphoneCore *lc, bool_t val);
 
41
bool_t linphone_core_video_preview_enabled(const LinphoneCore *lc);
 
42
void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result);
 
43
static void apply_nat_settings(LinphoneCore *lc);
51
44
 
52
45
/* relative path where is stored local ring*/
53
46
#define LOCAL_RING "rings/oldphone.wav"
56
49
#define REMOTE_RING_US "ringback.wav"
57
50
 
58
51
 
59
 
/* these are useful messages for the status */
60
 
gchar *ready;
61
 
gchar *end;
62
 
gchar *contacting;
63
 
gchar *connected;
64
 
gchar *cancel;
65
 
gchar *contacted;
66
 
 
67
 
 
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  */
 
59
};
 
60
 
 
61
void lc_callback_obj_init(LCCallbackObj *obj,LinphoneCoreCbFunc func,void* ud)
69
62
{
70
63
  obj->_func=func;
71
64
  obj->_user_data=ud;
72
65
}
73
66
 
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);
76
69
  return 0;
77
70
}
78
71
 
79
 
LinphoneDialogParams * linphone_dialog_params_new()
80
 
{
81
 
        return g_new0(LinphoneDialogParams,1);
82
 
}
83
 
 
84
 
void linphone_dialog_params_destroy(LinphoneDialogParams *obj)
85
 
{
86
 
        if (obj->profile!=&av_profile) rtp_profile_destroy(obj->profile);
87
 
        g_free(obj);
88
 
}
89
 
 
90
 
 
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>
97
 
#include <ifaddrs.h>
98
 
GList *
99
 
retrieve_if ()
100
 
{
101
 
        int i;
102
 
        struct ifaddrs *ifp;
103
 
        struct ifaddrs *ifpstart;
104
 
        GList *interfaces=NULL;
105
 
 
106
 
        if (getifaddrs (&ifpstart) < 0)
107
 
        {
108
 
                return NULL;
109
 
        }
110
 
        ifp=ifpstart;
111
 
        for (i = 0; ifp != NULL; ifp = ifp->ifa_next)
112
 
        {
113
 
                interface_t *netif;
114
 
#ifdef INET6
115
 
                char namebuf[BUFSIZ];
116
 
 
117
 
                if (!ifp->ifa_addr)
118
 
                  continue;
119
 
 
120
 
                switch (ifp->ifa_addr->sa_family) {
121
 
                case AF_INET:
122
 
                        getnameinfo(ifp->ifa_addr, sizeof (struct sockaddr_in) ,
123
 
                                    namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
124
 
                        netif=g_new0(interface_t,1);
125
 
                        netif->index=i;
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);
130
 
                        i++;
131
 
                        break;
132
 
                case AF_INET6:
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);
137
 
                          netif->index=i;
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);
142
 
                        }
143
 
                        i++;
144
 
                        break;
145
 
                default:
146
 
                        continue;
147
 
                }
148
 
#else
149
 
                if (ifp->ifa_addr->sa_family != AF_INET)
150
 
                        continue;
151
 
 
152
 
                /*printf ("ifc %s %s\n",
153
 
                        ifp->ifa_name,
154
 
                        inet_ntoa (((struct sockaddr_in *) ifp->ifa_addr)->
155
 
                                   sin_addr));*/
156
 
                        
157
 
                netif=g_new0(interface_t,1);
158
 
                netif->index=i;
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);
162
 
                i++;
163
 
#endif
164
 
        }
165
 
 
166
 
        freeifaddrs (ifpstart);
167
 
 
168
 
        return interfaces;
169
 
}
170
 
#else
171
 
 
172
 
GList * retrieve_if()
173
 
{
174
 
        int sock,err,if_count,i;
175
 
        struct ifconf netconf;
176
 
        char buffer[sizeof(struct ifreq)*MAX_IF];
177
 
        GList *interfaces=NULL;
178
 
        
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);
184
 
        close(sock);
185
 
        
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++)
189
 
        {
190
 
#ifdef INET6
191
 
                interface_t *netif;
192
 
                char namebuf[BUFSIZ];
193
 
 
194
 
                
195
 
                
196
 
 
197
 
                switch (netconf.ifc_req[i].ifr_addr.sa_family) {
198
 
                case AF_INET:
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);
202
 
                        netif->index=i;
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);
207
 
                        break;
208
 
                case AF_INET6:
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);
213
 
                                netif->index=i;
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);
218
 
                        }
219
 
                        break;
220
 
                default:
221
 
                        continue;
222
 
                }
223
 
                
224
 
#else
225
 
                interface_t *netif;
226
 
                if (netconf.ifc_req[i].ifr_addr.sa_family != AF_INET)
227
 
                        continue;
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);
231
 
                netif->index=i;
232
 
                interfaces=g_list_append(interfaces,netif);
233
 
#endif
234
 
        }
235
 
        return interfaces;
236
 
}
237
 
#endif
238
 
 
239
 
 
240
 
 
241
 
gboolean find_interface(net_config_t *config, char *ifname)
242
 
{
243
 
        GList *interfaces=config->interfaces;
244
 
        interface_t *tmpif;
245
 
#ifdef INET6
246
 
        interface_t *tmp4if = NULL;
247
 
        int checkflag = 0;
248
 
#endif
249
 
        
250
 
        tmpif=(interface_t*) interfaces->data;
251
 
        while (interfaces!=NULL){
252
 
                tmpif=(interface_t*) interfaces->data;
253
 
                if (ifname!=NULL){
254
 
                        if (strcmp(ifname,tmpif->name)==0){
255
 
#ifdef INET6
256
 
                          if (tmpif->family == AF_INET6) {
257
 
                                config->sel_if=tmpif;
258
 
                                return 1;
259
 
                          } else {
260
 
                                checkflag = 1;
261
 
                                tmp4if = tmpif;
262
 
                          }
263
 
#else
264
 
                                config->sel_if=tmpif;
265
 
                                return 1;
266
 
#endif
267
 
                        }
268
 
                }
269
 
                interfaces=g_list_next(interfaces);
270
 
        }
271
 
#ifdef INET6
272
 
        if (checkflag == 1) {
273
 
                config->sel_if=tmp4if;
274
 
                return 1;
275
 
        }
276
 
#endif
277
 
        return 0;
278
 
}
279
 
 
280
 
void find_best_interface(net_config_t *config)
281
 
{
282
 
        interface_t *tmpif;
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;
293
 
                                }
294
 
                        }
295
 
                }
296
 
        }
297
 
}
298
 
 
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);
 
77
}
 
78
 
 
79
LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, const osip_from_t *from, const osip_to_t *to)
 
80
{
 
81
        LinphoneCall *call=ms_new0(LinphoneCall,1);
 
82
        char localip[LINPHONE_IPADDR_SIZE];
 
83
        char *fromstr=NULL,*tostr=NULL;
 
84
        call->dir=LinphoneCallOutgoing;
 
85
        call->cid=-1;
 
86
        call->did=-1;
 
87
        call->core=lc;
 
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);
 
94
        return call;
 
95
}
 
96
 
 
97
 
 
98
LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, const char *from, const char *to, int cid, int did)
 
99
{
 
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;
 
104
        call->cid=cid;
 
105
        call->did=did;
 
106
        call->core=lc;
 
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));
 
110
        osip_from_free(me);
 
111
        return call;
 
112
}
 
113
 
 
114
void linphone_call_destroy(LinphoneCall *obj)
 
115
{
 
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);
 
119
        ms_free(obj);
 
120
}
 
121
 
 
122
LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, char *from, char *to){
 
123
        LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
 
124
        struct tm loctime;
 
125
        cl->lc=call->core;
 
126
        cl->dir=call->dir;
 
127
#ifdef WIN32
 
128
        loctime=*localtime(&call->start_time);
 
129
#else
 
130
        localtime_r(&call->start_time,&loctime);
 
131
#endif
 
132
        strftime(cl->start_date,sizeof(cl->start_date),"%c",&loctime);
 
133
        cl->from=from;
 
134
        cl->to=to;
 
135
        return cl;
 
136
}
 
137
void linphone_call_log_completed(LinphoneCallLog *calllog, LinphoneCall *call){
 
138
        LinphoneCore *lc=call->core;
 
139
        calllog->duration=time(NULL)-call->start_time;
 
140
        switch(call->state){
 
141
                case LCStateInit:
 
142
                        calllog->status=LinphoneCallAborted;
 
143
                        break;
 
144
                case LCStateRinging:
 
145
                        if (calllog->dir==LinphoneCallIncoming){
 
146
                                char *info;
 
147
                                calllog->status=LinphoneCallMissed;
 
148
                                lc->missed_calls++;
 
149
                                info=ortp_strdup_printf(_("You have missed %i call(s)."),lc->missed_calls);
 
150
                                lc->vtable.display_status(lc,info);
 
151
                                ms_free(info);
 
152
                        }
 
153
                        else calllog->status=LinphoneCallAborted;
 
154
                        break;
 
155
                case LCStateAVRunning:
 
156
                        calllog->status=LinphoneCallSuccess;
 
157
                        break;
 
158
        }
 
159
        lc->call_logs=ms_list_append(lc->call_logs,(void *)calllog);
 
160
        if (ms_list_size(lc->call_logs)>lc->max_call_logs){
 
161
                MSList *elem;
 
162
                elem=lc->call_logs;
 
163
                linphone_call_log_destroy((LinphoneCallLog*)elem->data);
 
164
                lc->call_logs=ms_list_remove_link(lc->call_logs,elem);
 
165
        }
 
166
        if (lc->vtable.call_log_updated!=NULL){
 
167
                lc->vtable.call_log_updated(lc,calllog);
 
168
        }
 
169
}
 
170
 
 
171
char * linphone_call_log_to_str(LinphoneCallLog *cl){
 
172
        char *status;
 
173
        switch(cl->status){
 
174
                case LinphoneCallAborted:
 
175
                        status=_("aborted");
 
176
                        break;
 
177
                case LinphoneCallSuccess:
 
178
                        status=_("completed");
 
179
                        break;
 
180
                case LinphoneCallMissed:
 
181
                        status=_("missed");
 
182
                        break;
 
183
                default:
 
184
                        status="unknown";
 
185
        }
 
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"),
 
188
                        cl->start_date,
 
189
                        cl->from,
 
190
                        cl->to,
 
191
                        status,
 
192
                        cl->duration/60,
 
193
                        cl->duration%60);
 
194
}
 
195
 
 
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);
 
199
        ms_free(cl);
 
200
}
 
201
 
 
202
 
 
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);
 
208
}
 
209
 
 
210
void linphone_core_disable_logs(){
 
211
        int tl;
 
212
        for (tl=0;tl<=OSIP_INFO4;tl++) osip_trace_disable_level(tl);
 
213
        ortp_set_log_level_mask(ORTP_ERROR|ORTP_FATAL);
 
214
}
 
215
 
300
216
 
301
217
void
302
218
net_config_read (LinphoneCore *lc)
303
219
{
304
 
        gchar *ifname;
305
 
        gboolean def=FALSE;
306
 
        gchar *tmpstr;
307
 
        gint tmp;
308
 
        
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 !!");
314
 
                return;
315
 
        }
316
 
        ifname=gnome_config_get_string("net/if_name");
317
 
        if ((ifname!=NULL) && (strlen(ifname)!=0)){
318
 
                /* try to find it */
319
 
                if (!find_interface(config,ifname)){
320
 
                        g_warning("Could not find network interface %s.",ifname);
321
 
                        find_best_interface(config);
322
 
                }
323
 
        }else find_best_interface(config);
324
 
#endif /*LINPHONE_DEPRECATED*/  
 
220
        int tmp;
 
221
        const char *tmpstr;
 
222
        LpConfig *config=lc->config;
325
223
 
326
 
        tmp=gnome_config_get_int_with_default("net/con_type",&def);
327
 
#ifdef __ARM__
328
 
        if (def) tmp=CONNECTION_TYPE_ETHERNET;
329
 
#else
330
 
        if (def) tmp=CONNECTION_TYPE_56KMODEM;
331
 
#endif
332
 
        linphone_core_set_connection_type(lc,tmp);
333
 
        
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);
338
 
        if (def) tmp=0;
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);
340
235
}
341
236
 
 
237
 
342
238
void sound_config_read(LinphoneCore *lc)
343
239
{
344
 
        gboolean def;
345
 
        int devid,tmp;
346
 
        char *tmpbuf;
347
 
        SndCard *sndcard;
348
 
        devid=gnome_config_get_int_with_default("sound/dev_id",&def);
349
 
        if (def) {
350
 
                /* choose an oss card if availlable, because alsa native support is not well enough stable*/
351
 
                int i;
352
 
                char *id;
353
 
                for(i=0;i<MAX_SND_CARDS;i++){
354
 
                        sndcard=snd_card_manager_get_card(snd_card_manager,i);
355
 
                        if (sndcard==NULL){
356
 
                                devid=0;
357
 
                                break;
358
 
                        }
359
 
                        id=snd_card_get_identifier(sndcard);
360
 
                        if (strstr(id,"Open Sound System")!=0){
361
 
                                g_message("Choosing oss device %s.",id);
362
 
                                devid=i;
363
 
                                break;
364
 
                        }
365
 
                }
 
240
        /*int tmp;*/
 
241
        const char *tmpbuf;
 
242
        const char *devid;
 
243
        const MSList *elem;
 
244
        const char **devices;
 
245
        int ndev;
 
246
        int i;
 
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);
366
253
        }
367
 
        linphone_core_set_sound_device(lc,devid);
368
 
        tmp=gnome_config_get_int_with_default("sound/play_lev",&def);
369
 
        if (def) tmp=80;
 
254
        devices[ndev]=NULL;
 
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);
 
258
        
 
259
        devid=lp_config_get_string(lc->config,"sound","ringer_dev_id",NULL);
 
260
        linphone_core_set_ringer_device(lc,devid);
 
261
        
 
262
        devid=lp_config_get_string(lc->config,"sound","capture_dev_id",NULL);
 
263
        linphone_core_set_capture_device(lc,devid);
 
264
        
 
265
/*
 
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);
372
 
        if (def) tmp=80;
 
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);
375
 
        if (def) tmpbuf="m";
 
272
        tmpbuf=lp_config_get_string(lc->config,"sound","source","m");
376
273
        linphone_core_set_sound_source(lc,tmpbuf[0]);
377
 
        
378
 
        tmpbuf=gnome_config_get_string_with_default("sound/local_ring",&def);
379
 
        if (def) tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
380
 
        else {
381
 
                if (!g_file_test(tmpbuf,G_FILE_TEST_EXISTS)){
382
 
                        tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
383
 
                }
384
 
                if (strstr(tmpbuf,".wav")==NULL){
385
 
                        /* it currently uses old sound files, so replace them */
386
 
                        tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
387
 
                }
388
 
        }
 
274
*/
 
275
        
 
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;
 
280
        }
 
281
        if (strstr(tmpbuf,".wav")==NULL){
 
282
                /* it currently uses old sound files, so replace them */
 
283
                tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
 
284
        }
 
285
        
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;
392
 
        else {
393
 
                if (!g_file_test(tmpbuf,G_FILE_TEST_EXISTS)){
394
 
                        tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING_FR;
395
 
                }
396
 
                if (strstr(tmpbuf,".wav")==NULL){
397
 
                        /* it currently uses old sound files, so replace them */
398
 
                        tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING_FR;
399
 
                }
 
287
        
 
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;
 
292
        }
 
293
        if (strstr(tmpbuf,".wav")==NULL){
 
294
                /* it currently uses old sound files, so replace them */
 
295
                tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING_FR;
400
296
        }
401
297
        linphone_core_set_ringback(lc,0);
402
 
        lc->sound_conf.autokill=1;
403
298
        check_sound_device(lc);
404
 
}
 
299
        lc->sound_conf.latency=0;
405
300
 
406
 
void registrar_config_read(LinphoneCore *lc)
407
 
{
408
 
        gboolean def;
409
 
        gchar *tmpstr,*tmpstr2;
410
 
        gint tmp1,tmp2,tmp3;
411
 
        
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);
421
 
        if (def) tmp1=0;
422
 
        tmp2=gnome_config_get_int_with_default("sip/as_proxy",&def);
423
 
        if (def) tmp2=0;
424
 
        tmp3=gnome_config_get_int_with_default("sip/expires",&def);
425
 
        if (def) tmp3=15*60;
426
 
        linphone_core_set_registrar_usage(lc,tmp1,tmp2,tmp3);
427
 
        
 
301
        linphone_core_enable_echo_cancelation(lc,
 
302
                lp_config_get_int(lc->config,"sound","echocancelation",0));
428
303
}
429
304
 
430
305
void sip_config_read(LinphoneCore *lc)
431
306
{
432
 
        gboolean def;
433
 
        gchar *hostname,*username;
434
 
        gint port;
435
 
        username=gnome_config_get_string_with_default("sip/username",&def);
436
 
        if (def) {
437
 
                gchar *logname=getenv("LOGNAME");
438
 
                if (logname!=NULL)
439
 
                        username=g_strdup(logname);
440
 
                else username=g_strdup("toto");
441
 
        }
442
 
        hostname=gnome_config_get_string_with_default("sip/hostname",&def);
443
 
        if (def) {
444
 
                gchar *hostname2=getenv("HOST");
445
 
                if (hostname2!=NULL)
446
 
                        hostname=g_strdup(hostname2);
447
 
                else hostname=g_strdup("unknown-host");
448
 
        }
449
 
        port=gnome_config_get_int_with_default("sip/sip_port",&def);
450
 
        if (def){
451
 
                port=5060;
452
 
        }
 
307
        char *contact;
 
308
        const char *tmpstr;
 
309
        int port;
 
310
        int i,tmp;
 
311
        int ipv6;
 
312
        port=lp_config_get_int(lc->config,"sip","use_info",0);
 
313
        linphone_core_set_use_info_for_dtmf(lc,port);
 
314
 
 
315
        ipv6=lp_config_get_int(lc->config,"sip","use_ipv6",-1);
 
316
        if (ipv6==-1){
 
317
                ipv6=0;
 
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"));
 
320
                }
 
321
        }
 
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);
 
325
        
 
326
        tmpstr=lp_config_get_string(lc->config,"sip","contact",NULL);
 
327
        if (tmpstr==NULL) {
 
328
                char *hostname=getenv("HOST");
 
329
                char *username=getenv("USER");
 
330
                if (hostname==NULL) hostname=getenv("HOSTNAME");
 
331
                if (hostname==NULL)
 
332
                        hostname="unknown-host";
 
333
                if (username==NULL){
 
334
                        username="toto";
 
335
                }
 
336
                contact=ortp_strdup_printf("sip:%s@%s",username,hostname);
 
337
        }else contact=ms_strdup(tmpstr);
 
338
        linphone_core_set_primary_contact(lc,contact);
 
339
        ms_free(contact);
 
340
        
 
341
 
 
342
        tmp=lp_config_get_int(lc->config,"sip","guess_hostname",1);
 
343
        linphone_core_set_guess_hostname(lc,tmp);
 
344
        
 
345
        
 
346
        tmp=lp_config_get_int(lc->config,"sip","inc_timeout",15);
 
347
        linphone_core_set_inc_timeout(lc,tmp);
 
348
 
 
349
        /* get proxies config */
 
350
        for(i=0;; i++){
 
351
                LinphoneProxyConfig *cfg=linphone_proxy_config_new_from_config_file(lc->config,i);
 
352
                if (cfg!=NULL){
 
353
                        linphone_core_add_proxy_config(lc,cfg);
 
354
                }else{
 
355
                        break;
 
356
                }
 
357
        }
 
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);
 
361
        
 
362
        /* read authentication information */
 
363
        for(i=0;; i++){
 
364
                LinphoneAuthInfo *ai=linphone_auth_info_new_from_config_file(lc->config,i);
 
365
                if (ai!=NULL){
 
366
                        linphone_core_add_auth_info(lc,ai);
 
367
                }else{
 
368
                        break;
 
369
                }
 
370
        }
 
371
        
456
372
}
457
373
 
458
374
void rtp_config_read(LinphoneCore *lc)
459
375
{
460
 
        gboolean def;
461
 
        gint port;
462
 
        gint jitt_comp;
463
 
        port=gnome_config_get_int_with_default("rtp/audio_rtp_port",&def);
464
 
        if (def) port=7078;
 
376
        int port;
 
377
        int jitt_comp;
 
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);
467
 
        if (def) port=9078;
468
 
        
469
 
        jitt_comp=gnome_config_get_int_with_default("rtp/audio_jitt_comp",&def);
470
 
        if (def) jitt_comp=60;
 
380
        
 
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);
 
384
        
 
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;  
474
 
        
 
387
        jitt_comp=lp_config_get_int(lc->config,"rtp","video_jitt_comp",60);
475
388
}
476
389
 
477
390
 
478
 
PayloadType * get_codec(char* type,int index){
479
 
        gchar codeckey[50];
480
 
        gchar *mime;
481
 
        gint rate,enabled;
482
 
        gboolean def;
 
391
PayloadType * get_codec(LpConfig *config, char* type,int index){
 
392
        char codeckey[50];
 
393
        const char *mime;
 
394
        int rate,enabled;
483
395
        PayloadType *pt;
484
396
        
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;
488
400
        
489
401
        pt=payload_type_new();
490
 
        pt->mime_type=mime;
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);
 
403
        
 
404
        rate=lp_config_get_int(config,codeckey,"rate",8000);
494
405
        pt->clock_rate=rate;
495
406
        
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);
500
410
        return pt;
501
411
}
502
412
 
504
414
{
505
415
        int i;
506
416
        PayloadType *pt;
507
 
        GList *audio_codecs=NULL;
508
 
        GList *video_codecs=NULL;
 
417
        MSList *audio_codecs=NULL;
 
418
        MSList *video_codecs=NULL;
509
419
        for (i=0;;i++){
510
 
                pt=get_codec("audio_codec",i);
 
420
                pt=get_codec(lc->config,"audio_codec",i);
511
421
                if (pt==NULL) break;
512
 
                audio_codecs=g_list_append(audio_codecs,(gpointer)pt);
 
422
                audio_codecs=ms_list_append(audio_codecs,(void *)pt);
513
423
        }
514
424
        for (i=0;;i++){
515
 
                pt=get_codec("video_codec",i);
 
425
                pt=get_codec(lc->config,"video_codec",i);
516
426
                if (pt==NULL) break;
517
 
                video_codecs=g_list_append(video_codecs,(gpointer)pt);
 
427
                video_codecs=ms_list_append(video_codecs,(void *)pt);
518
428
        }
519
429
        linphone_core_set_audio_codecs(lc,audio_codecs);
520
430
        linphone_core_set_video_codecs(lc,video_codecs);
523
433
 
524
434
void video_config_read(LinphoneCore *lc)
525
435
{
526
 
        gboolean def;
527
 
        gint tmp;
528
 
        tmp=gnome_config_get_int_with_default("video/enabled",&def);
529
 
        if (def) tmp=0;
530
 
        tmp=gnome_config_get_int_with_default("video/show_local",&def);
531
 
        if (def) tmp=0;
 
436
        int tmp;
 
437
        const char *str;
 
438
        
 
439
        str=lp_config_get_string(lc->config,"video","device","/dev/video0");
 
440
        linphone_core_set_video_device(lc,NULL,str);
 
441
        
 
442
        tmp=lp_config_get_int(lc->config,"video","enabled",1);
 
443
#ifdef VIDEO_ENABLED
 
444
        linphone_core_enable_video(lc,tmp);
 
445
        linphone_core_enable_video_preview(lc,tmp);
 
446
#endif
532
447
}
533
448
 
534
449
void ui_config_read(LinphoneCore *lc)
535
450
{
536
 
        int len,tmp;
537
 
        char *ab_entry;
538
 
        GList *address_list=NULL;
539
 
        /* get address book entries*/
540
 
        len= gnome_config_get_int("address_book/entry_count");
541
 
        if (len!=-1)
542
 
        {
543
 
                for (tmp=0;tmp<len;tmp++)
544
 
                {
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));
547
 
                        g_free(ab_entry);
548
 
                }
 
451
        LinphoneFriend *lf;
 
452
        int i;
 
453
        for (i=0;(lf=linphone_friend_new_from_config_file(lc,i))!=NULL;i++){
 
454
                linphone_core_add_friend(lc,lf);
549
455
        }
550
 
        linphone_core_set_address_list(lc,address_list);
 
456
        
551
457
}
552
458
 
553
 
void autoreplier_config_init(autoreplier_config_t *config)
 
459
void autoreplier_config_init(LinphoneCore *lc)
554
460
{
555
 
        gboolean def;
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);
 
468
}
 
469
 
 
470
void linphone_core_set_download_bandwidth(LinphoneCore *lc, int bw){
 
471
        lc->net_conf.download_bw=bw;
 
472
        if (bw==0){ /*infinite*/
 
473
                lc->dw_audio_bw=-1;
 
474
                lc->dw_video_bw=-1;
 
475
                return;
 
476
        }else if (bw>=512){
 
477
                lc->dw_audio_bw=80;
 
478
        }else if (bw>=128){
 
479
                if (linphone_core_video_enabled(lc))
 
480
                        lc->dw_audio_bw=40;
 
481
                else
 
482
                        lc->dw_audio_bw=bw;
 
483
        }else{
 
484
                lc->dw_audio_bw=bw;
 
485
        }
 
486
        lc->dw_video_bw=bw-lc->dw_audio_bw;
 
487
}
 
488
 
 
489
void linphone_core_set_upload_bandwidth(LinphoneCore *lc, int bw){
 
490
        lc->net_conf.upload_bw=bw;
 
491
        if (bw==0){ /*infinite*/
 
492
                lc->up_audio_bw=-1;
 
493
                lc->up_video_bw=-1;
 
494
                return;
 
495
        }else if (bw>=512){
 
496
                lc->up_audio_bw=80;
 
497
        }else if (bw>=128){
 
498
                if (linphone_core_video_enabled(lc))
 
499
                        lc->up_audio_bw=40;
 
500
                else 
 
501
                        lc->up_audio_bw=bw;
 
502
        }else{
 
503
                lc->up_audio_bw=bw;
 
504
        }
 
505
        lc->up_video_bw=bw-lc->up_audio_bw;
 
506
}
 
507
 
 
508
int linphone_core_get_download_bandwidth(const LinphoneCore *lc){
 
509
        return lc->net_conf.download_bw;
 
510
}
 
511
 
 
512
int linphone_core_get_upload_bandwidth(const LinphoneCore *lc){
 
513
        return lc->net_conf.upload_bw;
568
514
}
569
515
 
570
516
void
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)
572
518
{
573
 
        int len,err;
574
 
        char *prim_contact;
575
 
        
576
 
        //TRACE_INITIALIZE(TRACE_LEVEL5,stdout);
577
 
        osipua_init();
578
519
        ortp_init();
579
 
        ortp_set_debug_file("oRTP",NULL);
580
 
        rtp_profile_set_payload(&av_profile,115,&lpc1015);
581
 
 
582
 
        rtp_profile_set_payload(&av_profile,110,&speex_nb);
583
 
        rtp_profile_set_payload(&av_profile,111,&speex_wb);
584
 
 
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);
 
526
        
 
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);
 
530
 
587
531
        ms_init();
588
 
        ms_speex_codec_init();
589
532
        
590
533
        memset (lc, 0, sizeof (LinphoneCore));
591
534
        lc->data=userdata;
592
 
        ready=_("Ready.");
593
 
        end=_("Communication ended.");
594
 
        contacting= _("Contacting ");
595
 
        contacted=_("is calling you.");
596
 
        connected=_("Connected.");
597
 
        cancel=_("Call cancelled.");
598
535
        
599
536
        memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable));
600
537
 
601
 
        if (config_path!=NULL){
602
 
                gnome_config_push_prefix(g_strdup_printf("=%s=",config_path));
603
 
        }else gnome_config_push_prefix("/linphone/");
604
 
        
605
 
        
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;
613
 
        
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);
619
 
        
620
 
        /* add the sdp handler to the ua */
621
 
        osip_ua_add_body_handler(lc->ua,lc->sdph);
622
 
        
623
 
        
 
538
        lc->config=lp_config_new(config_path);
 
539
 
 
540
  
 
541
#ifdef VINCENT_MAURY_RSVP
 
542
        /* default qos parameters : rsvp on, rpc off */
 
543
        lc->rsvp_enable = 1;
 
544
        lc->rpc_enable = 0;
 
545
#endif
 
546
 
624
547
        sound_config_read(lc);
625
 
        sip_config_read(lc);
626
548
        net_config_read(lc);
 
549
        sip_config_read(lc); /* this will start eXosip*/
 
550
        
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);
 
555
        
 
556
        lc->presence_mode=LINPHONE_STATUS_ONLINE;
 
557
        lc->max_call_logs=15;
631
558
        ui_config_read(lc);
632
 
        
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"));
636
561
}
637
562
 
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)
640
565
{
641
 
        LinphoneCore *core=g_new(LinphoneCore,1);
 
566
        LinphoneCore *core=ms_new(LinphoneCore,1);
642
567
        linphone_core_init(core,vtable,config_path,userdata);
643
568
        return core;
644
569
}
645
570
 
646
 
GList *linphone_core_get_audio_codecs(LinphoneCore *lc)
647
 
{
648
 
        return g_list_copy(lc->codecs_conf.audio_codecs);
649
 
}
650
 
 
651
 
GList *linphone_core_get_video_codecs(LinphoneCore *lc)
652
 
{
653
 
        return g_list_copy(lc->codecs_conf.video_codecs);
654
 
}
655
 
 
656
 
int linphone_core_set_primary_contact(LinphoneCore *lc, gchar *contact)
657
 
{
658
 
        int error=0;
659
 
        from_t *ct;
660
 
        from_init(&ct);
661
 
        if ( from_parse(ct,contact) <0){
662
 
                g_warning("Bad contact url: %s", contact);
663
 
                error=1;
664
 
                goto end;
665
 
        }
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);
669
 
        end:
670
 
                from_free(ct);
671
 
                sfree(ct);
672
 
        return error;
673
 
}
674
 
 
675
 
gchar *linphone_core_get_primary_contact(LinphoneCore *lc)
676
 
{
677
 
        return g_strdup(lc->sip_conf.contact);
678
 
}
679
 
 
680
 
from_t *linphone_core_get_primary_contact_parsed(LinphoneCore *lc)
681
 
{
 
571
const MSList *linphone_core_get_audio_codecs(const LinphoneCore *lc)
 
572
{
 
573
        return lc->codecs_conf.audio_codecs;
 
574
}
 
575
 
 
576
const MSList *linphone_core_get_video_codecs(const LinphoneCore *lc)
 
577
{
 
578
        return lc->codecs_conf.video_codecs;
 
579
}
 
580
 
 
581
int linphone_core_set_primary_contact(LinphoneCore *lc,const char *contact)
 
582
{
 
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;
 
588
        }
 
589
        return 0;
 
590
}
 
591
 
 
592
static bool_t stun_get_localip(LinphoneCore *lc, char *result){
 
593
        const char *server=linphone_core_get_stun_server(lc);
 
594
        StunAddress4 addr;
 
595
        StunAddress4 mapped;
 
596
        StunAddress4 changed;
 
597
        if (server!=NULL){
 
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;
 
603
                                char *tmp;
 
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);
 
610
                                return TRUE;
 
611
                        }else{
 
612
                                ms_warning("stun lookup failed.");
 
613
                        }
 
614
                }else{
 
615
                        ms_warning("Fail to resolv or parse %s",server);
 
616
                }
 
617
        }
 
618
        return FALSE;
 
619
}
 
620
 
 
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){
 
623
        char *tmp=NULL;
 
624
        if (lc->apply_nat_settings){
 
625
                apply_nat_settings(lc);
 
626
                lc->apply_nat_settings=false;
 
627
        }
 
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);
 
630
                return;
 
631
        }
 
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");
 
635
                }else{
 
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);
 
640
                                return;
 
641
                        }
 
642
                        ms_warning("stun lookup failed, falling back to a local interface...");
 
643
                }
 
644
                
 
645
        }
 
646
        if (dest==NULL){
 
647
                /* try a public address */
 
648
                if (!lc->sip_conf.ipv6_enabled){
 
649
                        dest="15.128.128.93";
 
650
                }else{
 
651
                        dest="3ffe:4015:bbbb:70d0:201:2ff:fe09:81b1";
 
652
                }
 
653
        }
 
654
        eXosip_get_localip_for((char*)dest,&tmp);
 
655
        eXosip_set_firewallip("");
 
656
        strncpy(result,tmp,LINPHONE_IPADDR_SIZE);
 
657
        osip_free(tmp);
 
658
}
 
659
 
 
660
const char *linphone_core_get_primary_contact(LinphoneCore *lc)
 
661
{
 
662
        char *identity;
 
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){
 
666
                        char *guessed=NULL;
 
667
                        osip_from_t *url;
 
668
                        if (lc->sip_conf.guessed_contact!=NULL){
 
669
                                ms_free(lc->sip_conf.guessed_contact);
 
670
                                lc->sip_conf.guessed_contact=NULL;
 
671
                        }
 
672
                        
 
673
                        osip_from_init(&url);
 
674
                        if (osip_from_parse(url,lc->sip_conf.contact)==0){
 
675
                                
 
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);
 
686
                                url->url->port=NULL;
 
687
                        }
 
688
                        if (lc->sip_conf.sip_port!=5060){
 
689
                                url->url->port=ortp_strdup_printf("%i",lc->sip_conf.sip_port);
 
690
                        }
 
691
                        osip_from_to_str(url,&guessed);
 
692
                        lc->sip_conf.guessed_contact=guessed;
 
693
                        
 
694
                        osip_from_free(url);
 
695
                        
 
696
                }
 
697
                identity=lc->sip_conf.guessed_contact;
 
698
        }else{
 
699
                identity=lc->sip_conf.contact;
 
700
        }
 
701
        return identity;
 
702
}
 
703
 
 
704
void linphone_core_set_guess_hostname(LinphoneCore *lc, bool_t val){
 
705
        lc->sip_conf.guess_hostname=val;
 
706
}
 
707
        
 
708
bool_t linphone_core_get_guess_hostname(LinphoneCore *lc){
 
709
        return lc->sip_conf.guess_hostname;
 
710
}
 
711
 
 
712
osip_from_t *linphone_core_get_primary_contact_parsed(LinphoneCore *lc){
682
713
        int err;
683
 
        from_t *contact;
684
 
        from_init(&contact);
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));
686
717
        if (err<0) {
687
 
                from_free(contact);
688
 
                sfree(contact);
 
718
                osip_from_free(contact);
689
719
                return NULL;
690
720
        }
691
721
        return contact;
692
722
}
693
723
 
694
 
int linphone_core_set_audio_codecs(LinphoneCore *lc, GList *codecs)
 
724
int linphone_core_set_audio_codecs(LinphoneCore *lc, MSList *codecs)
695
725
{
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;
698
728
        return 0;
699
729
}
700
730
 
701
 
int linphone_core_set_video_codecs(LinphoneCore *lc, GList *codecs)
 
731
int linphone_core_set_video_codecs(LinphoneCore *lc, MSList *codecs)
702
732
{
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;
705
735
        return 0;
706
736
}
707
737
 
708
 
GList * linphone_core_get_address_list(LinphoneCore *lc)
709
 
{
710
 
        return g_list_copy(lc->ui_conf.address_list);
711
 
}
712
 
 
713
 
int linphone_core_set_address_list(LinphoneCore *lc, GList *addresses)
714
 
{
715
 
        if (lc->ui_conf.address_list!=NULL) g_list_free(lc->ui_conf.address_list);
716
 
        lc->ui_conf.address_list=addresses;
717
 
        return 0;
718
 
}
719
 
 
720
 
char *linphone_core_get_registrar_addr(LinphoneCore *lc)
721
 
{
722
 
        return g_strdup(lc->sip_conf.reg_conf.registrar);
723
 
}
724
 
 
725
 
int linphone_core_set_registrar_addr(LinphoneCore *lc,char *url,char *addr_of_rec)
726
 
{
727
 
        url_t *surl=NULL,*surl2=NULL;
728
 
        int err=0;
729
 
        if (url==NULL || strlen(url)==0) return 0;
730
 
        url_init(&surl);
731
 
        err=url_parse(surl,url);
732
 
        if (err<0){
733
 
                g_warning("Bad proxy or registrar url:%s",url);
734
 
                goto end;
735
 
        }
736
 
        if (addr_of_rec!=NULL){
737
 
                url_init(&surl2);
738
 
                err=url_parse(surl2,addr_of_rec);
739
 
                if (err<0){
740
 
                        g_warning("Bad address of record:%s",addr_of_rec);
741
 
                        goto end;
742
 
                }
743
 
        }
744
 
        if (lc->sip_conf.reg_conf.registrar!=NULL){
745
 
                g_free(lc->sip_conf.reg_conf.registrar);
746
 
        }
747
 
        lc->sip_conf.reg_conf.registrar=g_strdup(url);
748
 
        
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);
752
 
                }
753
 
                lc->sip_conf.reg_conf.addr_of_rec=g_strdup(addr_of_rec);
754
 
        }else{
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);
761
 
        }
762
 
        end:
763
 
                url_free(surl);
764
 
                sfree(surl);
765
 
                if (surl2!=NULL){
766
 
                        url_free(surl2);
767
 
                        sfree(surl2);
768
 
                }
769
 
        return err;
770
 
}
771
 
 
772
 
char *linphone_core_get_addr_of_rec(LinphoneCore *lc)
773
 
{
774
 
        return g_strdup(lc->sip_conf.reg_conf.addr_of_rec);
775
 
}
776
 
 
777
 
char *linphone_core_get_registrar_passwd(LinphoneCore *lc)
778
 
{
779
 
        return g_strdup(lc->sip_conf.reg_conf.passwd);
780
 
}
781
 
 
782
 
void linphone_core_set_registrar_passwd(LinphoneCore *lc, gchar *passwd)
783
 
{
784
 
        gchar *tmp=NULL;
785
 
        if (passwd!=NULL){
786
 
                tmp=g_strdup(passwd);
787
 
        }
788
 
        if (lc->sip_conf.reg_conf.passwd!=NULL){
789
 
                g_free(lc->sip_conf.reg_conf.passwd);
790
 
        }
791
 
        lc->sip_conf.reg_conf.passwd=tmp;
792
 
}
793
 
 
794
 
 
795
 
int linphone_core_register(LinphoneCore *lc, char *url){
796
 
        if (url!=NULL){
797
 
                linphone_core_set_registrar_addr(lc,url,NULL);
798
 
        }
799
 
        do_registration(lc,1);
800
 
        return 0;
801
 
}
802
 
 
803
 
void linphone_core_get_registrar_usage(LinphoneCore *lc,gboolean *reg, gboolean *proxy, gint *expires)
804
 
{
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;
808
 
}
809
 
 
810
 
 
811
 
 
812
 
void linphone_core_set_registrar_usage(LinphoneCore *lc, gboolean use, gboolean outbound_proxy,gint expires)
813
 
{
814
 
        if (lc->sip_conf.reg_conf.timer==NULL){
815
 
                GTimer *timer;
816
 
                timer=g_timer_new();
817
 
                g_timer_start(timer);
818
 
                lc->sip_conf.reg_conf.timer=timer;
819
 
        }
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)){
823
 
                if (use){
824
 
                        if (outbound_proxy)
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 */
829
 
                }else{
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);
834
 
                        }
835
 
                }
836
 
        }
837
 
        lc->sip_conf.reg_conf.use_registrar=use;
838
 
        lc->sip_conf.reg_conf.as_proxy=outbound_proxy;
839
 
}
840
 
 
841
 
GList * linphone_core_get_net_interfaces(LinphoneCore *lc)
842
 
{
843
 
        return g_list_copy(lc->net_conf.interfaces);
844
 
}
845
 
 
846
 
interface_t * linphone_core_get_selected_interface(LinphoneCore *lc)
847
 
{
848
 
        return lc->net_conf.sel_if;
849
 
}
850
 
 
851
 
#ifdef INET6
852
 
void linphone_core_select_net_interface(LinphoneCore *lc, gint index)
853
 
#else
854
 
void linphone_core_select_net_interface(LinphoneCore *lc, gchar *ifname)
855
 
#endif
856
 
{
857
 
        GList *elem=lc->net_conf.interfaces;
858
 
        while(elem!=NULL){
859
 
                interface_t *iface=(interface_t *)elem->data;
860
 
#ifdef INET6
861
 
                if (index == iface->index) {
862
 
#else
863
 
                if (strcmp(ifname,iface->name)==0){
864
 
#endif
865
 
                        lc->net_conf.sel_if=iface;
866
 
                        linphone_core_update_contact_info(lc);
867
 
                        return;
868
 
                }
869
 
                elem=g_list_next(elem);
870
 
        }
871
 
#ifdef INET6
872
 
        g_warning("Could not select interface (index: %d): non existent.",index);
873
 
#else
874
 
        g_warning("Could not select interface %s: non existent.",ifname);
875
 
#endif
876
 
}
877
 
 
878
 
void linphone_core_set_connection_type(LinphoneCore *lc, int type)
879
 
{
880
 
        lc->net_conf.con_type=type;
881
 
        lc->net_conf.bandwidth=bandwidths[type];
882
 
        linphone_core_check_codecs_for_bandwidth(lc);
883
 
}
884
 
 
885
 
int linphone_core_get_connection_type(LinphoneCore *lc)
886
 
{
887
 
        return lc->net_conf.con_type;
 
738
MSList * linphone_core_get_friend_list(LinphoneCore *lc)
 
739
{
 
740
        return lc->friends;
888
741
}
889
742
 
890
743
int linphone_core_get_audio_jittcomp(LinphoneCore *lc)
892
745
        return lc->rtp_conf.audio_jitt_comp;
893
746
}
894
747
 
895
 
int linphone_core_get_audio_port(LinphoneCore *lc)
 
748
int linphone_core_get_audio_port(const LinphoneCore *lc)
896
749
{
897
750
        return lc->rtp_conf.audio_rtp_port;
898
751
}
899
752
 
 
753
int linphone_core_get_video_port(const LinphoneCore *lc){
 
754
        return lc->rtp_conf.video_rtp_port;
 
755
}
 
756
 
900
757
void linphone_core_set_audio_jittcomp(LinphoneCore *lc, int value)
901
758
{
902
759
        lc->rtp_conf.audio_jitt_comp=value;
907
764
        lc->rtp_conf.audio_rtp_port=port;
908
765
}
909
766
 
 
767
void linphone_core_set_video_port(LinphoneCore *lc, int port){
 
768
        lc->rtp_conf.video_rtp_port=port;
 
769
}
 
770
 
 
771
bool_t linphone_core_get_use_info_for_dtmf(LinphoneCore *lc)
 
772
{
 
773
        return lc->sip_conf.use_info;
 
774
}
 
775
 
 
776
void linphone_core_set_use_info_for_dtmf(LinphoneCore *lc,bool_t use_info)
 
777
{
 
778
        lc->sip_conf.use_info=use_info;
 
779
}
 
780
 
910
781
int linphone_core_get_sip_port(LinphoneCore *lc)
911
782
{
912
783
        return lc->sip_conf.sip_port;
913
784
}
914
785
 
 
786
static bool_t exosip_running=FALSE;
 
787
 
915
788
void linphone_core_set_sip_port(LinphoneCore *lc,int port)
916
789
{
 
790
        int err=0;
 
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);
 
795
        if (err<0){
 
796
                char *msg=ortp_strdup_printf("UDP port %i seems already in use ! Cannot initialize.",port);
 
797
                ms_warning(msg);
 
798
                lc->vtable.display_warning(lc,msg);
 
799
                ms_free(msg);
 
800
                return;
 
801
        }
 
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);
 
806
#endif
 
807
        eXosip_set_user_agent("Linphone-" LINPHONE_VERSION "/eXosip");
 
808
        exosip_running=TRUE;
 
809
}
 
810
 
 
811
bool_t linphone_core_ipv6_enabled(LinphoneCore *lc){
 
812
        return lc->sip_conf.ipv6_enabled;
 
813
}
 
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);
 
818
                if (exosip_running){
 
819
                        /* we need to restart eXosip */
 
820
                        linphone_core_set_sip_port(lc, lc->sip_conf.sip_port);
 
821
                }
 
822
        }
 
823
}
 
824
 
 
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);
919
831
}
920
832
 
921
833
void linphone_core_iterate(LinphoneCore *lc)
922
834
{
923
 
        check_for_registration(lc);
924
 
  if (lc->preview_finished){
925
 
    lc->preview_finished=0;
926
 
    ring_stop(lc->ringstream);
927
 
    lc->ringstream=NULL;
928
 
    lc_callback_obj_invoke(&lc->preview_finished_cb,lc);
929
 
  }
930
 
}
931
 
 
932
 
gboolean sipurl_check(gchar *url)
933
 
{
934
 
        from_t *surl;
935
 
        int err,ret;
936
 
        if (url==NULL) return FALSE;
 
835
        eXosip_event_t *ev;
 
836
#ifdef AMD
 
837
        printf("entering linphone_core_iterate()\n");
 
838
#endif
 
839
        if (lc->preview_finished){
 
840
                lc->preview_finished=0;
 
841
                ring_stop(lc->ringstream);
 
842
                lc->ringstream=NULL;
 
843
                lc_callback_obj_invoke(&lc->preview_finished_cb,lc);
 
844
        }
 
845
#ifdef AMD
 
846
        printf("getting eXosip event...\n");
 
847
#endif
937
848
        
938
 
        from_init(&surl);
939
 
        err=from_parse(surl,url);
940
 
        if (err<0) ret=FALSE;
941
 
        else ret=TRUE;
942
 
        from_free(surl);
943
 
        sfree(surl);
 
849
        if (exosip_running){
 
850
                while((ev=eXosip_event_wait(0,0))!=NULL){
 
851
                        linphone_core_process_event(lc,ev);
 
852
                }
 
853
                linphone_core_update_proxy_register(lc);
 
854
                linphone_core_refresh_subscribes(lc);
 
855
        }
 
856
        if (lc->call!=NULL){
 
857
                LinphoneCall *call=lc->call;
 
858
                int elapsed;
 
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);
 
865
                        }
 
866
                }else if (call->state==LCStateAVRunning){
 
867
                        elapsed=curtime-lc->prevtime;
 
868
                        if (elapsed>=1){
 
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);
 
876
                        }
 
877
                }
 
878
        }
 
879
 
 
880
#ifdef AMD
 
881
        printf("iterate done...\n");
 
882
#endif
 
883
}
 
884
 
 
885
 
 
886
bool_t linphone_core_is_in_main_thread(LinphoneCore *lc){
 
887
        return TRUE;
 
888
}
 
889
 
 
890
static osip_to_t *osip_to_create(const char *to){
 
891
        osip_to_t *ret;
 
892
        osip_to_init(&ret);
 
893
        if (osip_to_parse(ret,to)<0){
 
894
                osip_to_free(ret);
 
895
                return NULL;
 
896
        }
944
897
        return ret;
945
898
}
946
899
 
947
 
int linphone_core_invite(LinphoneCore *lc, char *url)
948
 
{
949
 
        gchar *barmsg;
950
 
        gint err;
 
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;
952
 
        gchar *enum_domain;
953
 
        
954
 
        linphone_core_lock(lc);
 
902
        osip_to_t *parsed_url=NULL;
 
903
        char *enum_domain=NULL;
 
904
        LinphoneProxyConfig *proxy;
 
905
        char *tmpurl;
 
906
        
 
907
        if (real_url!=NULL) *real_url=NULL;
 
908
        if (real_parsed_url!=NULL) *real_parsed_url=NULL;
 
909
        
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."));
959
 
                        g_free(enum_domain);
960
 
                        linphone_core_unlock(lc);
961
 
                        return -1;
962
 
                }
963
 
                g_free(enum_domain);
964
 
                url=enumres->sip_address[0];
965
 
        }else{
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);
969
 
                        return -1;
970
 
                }
971
 
        }
 
914
                        ms_free(enum_domain);
 
915
                        return FALSE;
 
916
                }
 
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);
 
922
                return TRUE;
 
923
        }
 
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;
 
928
                if (proxy!=NULL){
 
929
                        /* append the proxy suffix */
 
930
                        osip_uri_t *proxy_uri;
 
931
                        char *sipaddr;
 
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);
 
936
                                return FALSE;
 
937
                        }
 
938
                        if (proxy_uri->port!=NULL)
 
939
                                sipaddr=ortp_strdup_printf("sip:%s@%s:%s",url,proxy_uri->host,proxy_uri->port);
 
940
                        else
 
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);
 
945
                        return TRUE;
 
946
                }
 
947
        }
 
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);
 
953
                return TRUE;
 
954
        }
 
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"));
 
958
        }
 
959
        return FALSE;
 
960
}
 
961
 
 
962
const char * linphone_core_get_identity(LinphoneCore *lc){
 
963
        LinphoneProxyConfig *proxy=NULL;
 
964
        const char *from;
 
965
        linphone_core_get_default_proxy(lc,&proxy);
 
966
        if (proxy!=NULL) {
 
967
                from=linphone_proxy_config_get_identity(proxy);
 
968
        }else from=linphone_core_get_primary_contact(lc);
 
969
        return from;
 
970
}
 
971
 
 
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);
 
976
        if (proxy!=NULL) {
 
977
                route=linphone_proxy_config_get_route(proxy);
 
978
        }
 
979
        return route;
 
980
}
 
981
 
 
982
int linphone_core_invite(LinphoneCore *lc, const char *url)
 
983
{
 
984
        char *barmsg;
 
985
        int err=0;
 
986
        char *sdpmesg=NULL;
 
987
        char *route=NULL;
 
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;
 
994
        char *real_url=NULL;
972
995
        
973
 
        barmsg=g_malloc(strlen(url)+strlen(contacting)+2);
974
 
        sprintf(barmsg,"%s %s",contacting,url);
 
996
        if (lc->call!=NULL){
 
997
                lc->vtable.display_warning(lc,_("Sorry, having multiple simultaneous calls is not supported yet !"));
 
998
        }
 
999
 
 
1000
        linphone_core_get_default_proxy(lc,&proxy);
 
1001
        if (!linphone_core_interpret_url(lc,url,&real_url,&real_parsed_url)){
 
1002
                /* bad url */
 
1003
                return -1;
 
1004
        }
 
1005
        barmsg=ortp_strdup_printf("%s %s", _("Contacting"), real_url);
975
1006
        lc->vtable.display_status(lc,barmsg);
976
 
        
977
 
        lc->call=osip_dialog_new(lc->ua);
978
 
        err=osip_dialog_invite(lc->call,url,"application/sdp");
979
 
        if (err!=0){
980
 
                g_warning("error in invite: %s (%i)\n",strerror(err),err);
981
 
                lc->vtable.display_status(lc,ready);
982
 
        }
983
 
        if (enumres!=0) enum_lookup_res_free(enumres);
984
 
        linphone_core_unlock(lc);
985
 
        return 0;
986
 
}
987
 
 
988
 
gboolean linphone_core_inc_invite_pending(LinphoneCore*lc){
989
 
        if (lc->call==NULL){
990
 
                return 0;
991
 
        }
992
 
        linphone_core_lock(lc);
993
 
        if (lc->call->status==DIALOG_INVITED){
994
 
                linphone_core_unlock(lc);
995
 
                return 1;
996
 
        }
997
 
        return 0;
998
 
}
999
 
 
1000
 
int linphone_core_accept_dialog(LinphoneCore *lc, const char *url)
1001
 
{
1002
 
        LinphoneDialogParams *diaparams;
1003
 
        StreamParams *audio_params;
1004
 
        int pos;
1005
 
        gint jitt_comp;
1006
 
        
1007
 
        if (lc->call==NULL){
1008
 
                return -1;
1009
 
        }
1010
 
        linphone_core_lock(lc);
1011
 
        if (lc->call->status!=DIALOG_INVITED){
1012
 
                g_warning("No dialog to accept.");
1013
 
                linphone_core_unlock(lc);
1014
 
                return -1;
1015
 
        }
1016
 
        diaparams=(LinphoneDialogParams *)lc->call->data;
1017
 
        audio_params=&diaparams->audio_params;
 
1007
        ms_free(barmsg);
 
1008
        if (proxy!=NULL) {
 
1009
                route=linphone_proxy_config_get_route(proxy);
 
1010
                from=linphone_proxy_config_get_identity(proxy);
 
1011
        }
 
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);
 
1014
 
 
1015
        err=eXosip_build_initial_invite(&invite,(char*)real_url,(char*)from,
 
1016
                                                                (char*)route,"Phone call");
 
1017
 
 
1018
        if (err<0){
 
1019
                ms_warning("Could not build initial invite");
 
1020
                goto end;
 
1021
        }
 
1022
        /* make sdp message */
 
1023
        
 
1024
        osip_from_init(&parsed_url2);
 
1025
        osip_from_parse(parsed_url2,from);
 
1026
        
 
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);
 
1030
        eXosip_lock();
 
1031
        err=eXosip_initiate_call_with_body(invite,"application/sdp",sdpmesg,(void*)lc->call);
 
1032
        lc->call->cid=err;
 
1033
        eXosip_unlock();
 
1034
        if (err<0){
 
1035
                ms_warning("Could not initiate call.");
 
1036
                lc->vtable.display_status(lc,_("could not call"));
 
1037
                linphone_call_destroy(lc->call);
 
1038
                lc->call=NULL;
 
1039
        }
 
1040
        
 
1041
        goto end;
 
1042
        end:
 
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;
 
1047
}
 
1048
 
 
1049
int linphone_core_refer(LinphoneCore *lc, const char *url)
 
1050
{
 
1051
    char *real_url=NULL;
 
1052
    osip_to_t *real_parsed_url=NULL;
 
1053
    LinphoneCall *call;
 
1054
    if (!linphone_core_interpret_url(lc,url,&real_url,&real_parsed_url)){
 
1055
        /* bad url */
 
1056
        return -1;
 
1057
    }
 
1058
    call=lc->call;
 
1059
    if (call==NULL){
 
1060
        ms_warning("No established call to refer.");
 
1061
        return -1;
 
1062
    }
 
1063
    lc->call=NULL;
 
1064
    
 
1065
    eXosip_lock();
 
1066
    eXosip_transfer_call(call->did, real_url);
 
1067
    eXosip_unlock();
 
1068
    return 0;
 
1069
}    
 
1070
 
 
1071
bool_t linphone_core_inc_invite_pending(LinphoneCore*lc){
 
1072
        if (lc->call==NULL){
 
1073
                return FALSE;
 
1074
        }
 
1075
        return TRUE;
 
1076
}
 
1077
 
 
1078
#ifdef VINCENT_MAURY_RSVP
 
1079
/* on=1 for RPC_ENABLE=1...*/
 
1080
int linphone_core_set_rpc_mode(LinphoneCore *lc, int on)
 
1081
{
 
1082
        if (on==1)
 
1083
                printf("RPC_ENABLE set on\n");
 
1084
        else 
 
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)
 
1089
                return -1;
 
1090
        return 0;
 
1091
}
 
1092
 
 
1093
/* on=1 for RSVP_ENABLE=1...*/
 
1094
int linphone_core_set_rsvp_mode(LinphoneCore *lc, int on)
 
1095
{
 
1096
        if (on==1)
 
1097
                printf("RSVP_ENABLE set on\n");
 
1098
        else 
 
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)
 
1103
                return -1;
 
1104
        return 0;
 
1105
}
 
1106
 
 
1107
/* answer : 1 for yes, 0 for no */
 
1108
int linphone_core_change_qos(LinphoneCore *lc, int answer)
 
1109
{
 
1110
        char *sdpmesg;
 
1111
        if (lc->call==NULL){
 
1112
                return -1;
 
1113
        }
 
1114
        
 
1115
        if (lc->rsvp_enable && answer==1)
 
1116
        {
 
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);
 
1122
                /* send 180 */
 
1123
                eXosip_lock();
 
1124
                eXosip_answer_call(lc->call->did,180,NULL);
 
1125
                eXosip_unlock();
 
1126
                /* play the ring */
 
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));
 
1130
        }
 
1131
        else if (!lc->rsvp_enable && answer==1)
 
1132
        {
 
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;
 
1138
                eXosip_lock();
 
1139
                eXosip_answer_call_with_body(lc->call->did,183,"application/sdp",sdpmesg);
 
1140
                eXosip_unlock();
 
1141
        }
 
1142
        else
 
1143
        {
 
1144
                /* decline offer (603) */
 
1145
                linphone_core_terminate_call(lc, NULL);
 
1146
        }
 
1147
        return 0;
 
1148
}
 
1149
#endif
 
1150
 
 
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);
 
1155
        {
 
1156
                int jitt_comp;
 
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 !");
 
1163
                                goto end;
 
1164
                        }
 
1165
                        if (captcard==NULL) {
 
1166
                                ms_warning("No card defined for capture !");
 
1167
                                goto end;
 
1168
                        }
 
1169
                        
 
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(
 
1173
                                call->profile,
 
1174
                                audio_params->localport,
 
1175
                                audio_params->remoteaddr,
 
1176
                                audio_params->remoteport,
 
1177
                                audio_params->pt,
 
1178
                                jitt_comp,
 
1179
                                playcard,
 
1180
                                captcard,
 
1181
                                linphone_core_echo_cancelation_enabled(lc));
 
1182
                }else{
 
1183
                        lc->audiostream=audio_stream_start_with_files(
 
1184
                                call->profile,
 
1185
                                audio_params->localport,
 
1186
                                audio_params->remoteaddr,
 
1187
                                audio_params->remoteport,
 
1188
                                audio_params->pt,
 
1189
                                100,
 
1190
                                lc->play_file,
 
1191
                                lc->rec_file);
 
1192
                }
 
1193
                if (lc->audiostream==NULL){
 
1194
                        /* should terminate call */
 
1195
                }
 
1196
                else{
 
1197
                        audio_stream_set_rtcp_information(lc->audiostream, cname, tool);
 
1198
                }
 
1199
        }
 
1200
#ifdef VIDEO_ENABLED
 
1201
        {
 
1202
                /* shutdown preview */
 
1203
                if (lc->previewstream!=NULL) {
 
1204
                        video_preview_stop(lc->previewstream);
 
1205
                        lc->previewstream=NULL;
 
1206
                }
 
1207
                if (lc->video_conf.enabled){
 
1208
                        int jitt_comp;
 
1209
                        StreamParams *video_params=&call->video_params;
 
1210
                        
 
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);
 
1218
                        }
 
1219
                }
 
1220
        }
 
1221
#endif
 
1222
        goto end;
 
1223
        end:
 
1224
        ms_free(cname);
 
1225
        osip_from_free(me);
 
1226
        lc->call->state=LCStateAVRunning;
 
1227
}
 
1228
 
 
1229
void linphone_core_stop_media_streams(LinphoneCore *lc){
 
1230
        if (lc->audiostream!=NULL) {
 
1231
                audio_stream_stop(lc->audiostream);
 
1232
                lc->audiostream=NULL;
 
1233
        }
 
1234
#ifdef VIDEO_ENABLED
 
1235
        if (lc->videostream!=NULL){
 
1236
                video_stream_stop(lc->videostream);
 
1237
                lc->videostream=NULL;
 
1238
        }
 
1239
        if (linphone_core_video_preview_enabled(lc)){
 
1240
                if (lc->previewstream==NULL){
 
1241
                        lc->previewstream=video_preview_start(lc->video_conf.device);
 
1242
                }
 
1243
        }
 
1244
#endif
 
1245
}
 
1246
 
 
1247
int linphone_core_accept_call(LinphoneCore *lc, const char *url)
 
1248
{
 
1249
        char *sdpmesg;
 
1250
        
 
1251
        if (lc->call==NULL){
 
1252
                return -1;
 
1253
        }
 
1254
        
 
1255
        if (lc->call->state==LCStateAVRunning){
 
1256
                /*call already accepted*/
 
1257
                return -1;
 
1258
        }
1018
1259
        
1019
1260
        /*stop ringing */
1020
1261
        if (lc->ringstream!=NULL) {
1022
1263
                lc->ringstream=NULL;
1023
1264
        }
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*/
 
1267
        eXosip_lock();
 
1268
        eXosip_answer_call_with_body(lc->call->did,200,"application/sdp",sdpmesg);
 
1269
        eXosip_unlock();
 
1270
        lc->vtable.display_status(lc,_("Connected."));
1027
1271
        
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);
1034
 
        }
1035
 
        linphone_core_unlock(lc);
 
1272
        linphone_core_start_media_streams(lc, lc->call);
1036
1273
        return 0;
1037
1274
}
1038
1275
 
1039
 
int linphone_core_terminate_dialog(LinphoneCore *lc, const char *url)
 
1276
int linphone_core_terminate_call(LinphoneCore *lc, const char *url)
1040
1277
{
1041
 
        OsipDialog *call=lc->call;
1042
 
        LinphoneDialogParams *diaparams;
 
1278
        LinphoneCall *call=lc->call;
1043
1279
        if (call==NULL){
1044
1280
                return -1;
1045
1281
        }
1046
 
        
1047
 
        linphone_core_lock(lc);
1048
 
        diaparams=(LinphoneDialogParams*)call->data;
1049
1282
        lc->call=NULL;
1050
1283
        
1051
 
        if (call->status==DIALOG_INVITED )
1052
 
    {
1053
 
       /*stop ringing*/
1054
 
                if (lc->ringstream!=NULL) {
1055
 
                        ring_stop(lc->ringstream);
1056
 
                        lc->ringstream=NULL;
1057
 
                        restore_sound_daemons();
1058
 
                }
1059
 
                /* decline the invitation */
1060
 
                osip_dialog_reject_invite(call);
1061
 
                lc->vtable.display_status(lc,end);
1062
 
    }
1063
 
        else if (call->status==DIALOG_ESTABLISHED)
1064
 
        {
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();
1070
 
                }
1071
 
                osip_dialog_bye(call);
1072
 
                lc->vtable.display_status(lc,end);
1073
 
        }
1074
 
        else if (call->status==DIALOG_INVITING)
1075
 
        {
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();
1081
 
                }
1082
 
                osip_dialog_bye(call);
1083
 
                lc->vtable.display_status(lc,cancel);
1084
 
        }
1085
 
        if (diaparams!=NULL) {
1086
 
                call->data=NULL;
1087
 
                linphone_dialog_params_destroy(diaparams);
1088
 
        }
1089
 
        linphone_core_unlock(lc);
1090
 
        return 0;
1091
 
}
1092
 
 
1093
 
void linphone_core_set_presence_info(LinphoneCore *lc,gint minutes_away,
1094
 
                                                                                                        gchar *contact,
1095
 
                                                                                                        int presence_mode)
 
1284
        eXosip_lock();
 
1285
        eXosip_terminate_call(call->cid,call->did);
 
1286
        eXosip_unlock();
 
1287
        
 
1288
        /*stop ringing*/
 
1289
        if (lc->ringstream!=NULL) {
 
1290
                ring_stop(lc->ringstream);
 
1291
                lc->ringstream=NULL;
 
1292
        }
 
1293
        linphone_core_stop_media_streams(lc);
 
1294
        lc->vtable.display_status(lc,_("Call ended") );
 
1295
        linphone_call_destroy(call);
 
1296
        return 0;
 
1297
}
 
1298
 
 
1299
int linphone_core_send_publish(LinphoneCore *lc,
 
1300
                               LinphoneOnlineStatus presence_mode)
 
1301
{
 
1302
        const MSList *elem;
 
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);
 
1306
        }
 
1307
        return 0;
 
1308
}
 
1309
 
 
1310
void linphone_core_set_inc_timeout(LinphoneCore *lc, int seconds){
 
1311
        lc->sip_conf.inc_timeout=seconds;
 
1312
}
 
1313
 
 
1314
int linphone_core_get_inc_timeout(LinphoneCore *lc){
 
1315
        return lc->sip_conf.inc_timeout;
 
1316
}
 
1317
 
 
1318
void linphone_core_set_presence_info(LinphoneCore *lc,int minutes_away,
 
1319
                                                                                                        const char *contact,
 
1320
                                                                                                        LinphoneOnlineStatus presence_mode)
1096
1321
{
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) {
1100
 
                from_t *url;
1101
 
                
1102
 
                from_init(&url);
1103
 
                contactok=from_parse(url,contact);
 
1325
                osip_from_t *url;
 
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.");
1107
1330
                }
1108
 
                from_free(url);
1109
 
                sfree(url);
1110
 
        }
1111
 
        if (contactok<0 && (presence_mode==302 || presence_mode==380)){
1112
 
                return;
1113
 
        }
 
1331
                osip_from_free(url);
 
1332
                
 
1333
        }
 
1334
        if (contactok>=0){
 
1335
                if (lc->alt_contact!=NULL) ms_free(lc->alt_contact);
 
1336
                lc->alt_contact=ms_strdup(contact);
 
1337
        }
 
1338
        if (lc->presence_mode!=presence_mode){
 
1339
                linphone_core_notify_all_friends(lc,presence_mode);
 
1340
                /* 
 
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.
 
1344
                 */
 
1345
                linphone_core_send_publish(lc,presence_mode);
 
1346
        }
 
1347
        lc->presence_mode=presence_mode;
1114
1348
        
1115
 
        osip_ua_set_presence_mode(lc->ua,presence_mode);
1116
1349
}
1117
1350
 
1118
1351
/* sound functions */
1119
 
gint linphone_core_get_play_level(LinphoneCore *lc)
 
1352
int linphone_core_get_play_level(LinphoneCore *lc)
1120
1353
{
1121
1354
        return lc->sound_conf.play_lev;
1122
1355
}
1123
 
gint linphone_core_get_rec_level(LinphoneCore *lc){
 
1356
int linphone_core_get_ring_level(LinphoneCore *lc)
 
1357
{
 
1358
        return lc->sound_conf.ring_lev;
 
1359
}
 
1360
int linphone_core_get_rec_level(LinphoneCore *lc){
1124
1361
        return lc->sound_conf.rec_lev;
1125
1362
}
1126
 
void linphone_core_set_play_level(LinphoneCore *lc, gint level){
 
1363
void linphone_core_set_ring_level(LinphoneCore *lc, int level){
 
1364
        MSSndCard *sndcard;
 
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);
 
1368
}
 
1369
 
 
1370
void linphone_core_set_play_level(LinphoneCore *lc, int level){
 
1371
        MSSndCard *sndcard;
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);
1130
1375
}
1131
1376
 
1132
 
void linphone_core_set_rec_level(LinphoneCore *lc, gint level)
 
1377
void linphone_core_set_rec_level(LinphoneCore *lc, int level)
1133
1378
{
 
1379
        MSSndCard *sndcard;
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);
1137
 
}
1138
 
gint linphone_core_set_sound_device(LinphoneCore *lc, gint devid)
1139
 
{
1140
 
        SndCard *sndcard;
1141
 
        int tmp;
1142
 
        if (devid<0){
1143
 
                g_warning("Bad devid value: %i",devid);
1144
 
                devid=0;
1145
 
        }
1146
 
        sndcard=snd_card_manager_get_card(snd_card_manager,devid);
1147
 
        if (sndcard==NULL){
1148
 
                g_warning("Sound card with index %i does not exist.");
1149
 
                devid=0;
1150
 
        }
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;
1155
 
        return 0;
1156
 
}
1157
 
 
1158
 
gint linphone_core_set_sound_device_from_name(LinphoneCore *lc,gchar *name)
1159
 
{
1160
 
        SndCard *card;
1161
 
        gint index;
1162
 
        card=snd_card_manager_get_card_with_string(snd_card_manager,name,&index);
1163
 
        if (card!=NULL){
1164
 
                g_message("Setting card with id=%i",index);
1165
 
                lc->sound_conf.dev_id=index;
1166
 
                lc->sound_conf.sndcard=card;
1167
 
                return 0;
1168
 
        }
1169
 
        return -1;
1170
 
}
1171
 
 
1172
 
gint linphone_core_get_sound_device(LinphoneCore *lc)
1173
 
{
1174
 
        return lc->sound_conf.dev_id;
1175
 
}
1176
 
 
1177
 
SndCardManager * linphone_core_get_card_manager(LinphoneCore *lc){
1178
 
        return snd_card_manager;
1179
 
}
1180
 
 
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);
 
1383
}
 
1384
 
 
1385
static MSSndCard *get_card_from_string_id(const char *devid){
 
1386
        MSSndCard *sndcard=NULL;
 
1387
        if (devid!=NULL){
 
1388
                sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
 
1389
        }
 
1390
        if (sndcard==NULL) sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
 
1391
        return sndcard;
 
1392
}
 
1393
 
 
1394
int linphone_core_set_ringer_device(LinphoneCore *lc, const char * devid){
 
1395
        lc->sound_conf.ring_sndcard=get_card_from_string_id(devid);
 
1396
        return 0;
 
1397
}
 
1398
 
 
1399
int linphone_core_set_playback_device(LinphoneCore *lc, const char * devid){
 
1400
        lc->sound_conf.play_sndcard=get_card_from_string_id(devid);
 
1401
        return 0;
 
1402
}
 
1403
 
 
1404
int linphone_core_set_capture_device(LinphoneCore *lc, const char * devid){
 
1405
        lc->sound_conf.capt_sndcard=get_card_from_string_id(devid);
 
1406
        return 0;
 
1407
}
 
1408
 
 
1409
const char * linphone_core_get_ringer_device(LinphoneCore *lc)
 
1410
{
 
1411
        return ms_snd_card_get_string_id(lc->sound_conf.ring_sndcard);
 
1412
}
 
1413
 
 
1414
const char * linphone_core_get_playback_device(LinphoneCore *lc)
 
1415
{
 
1416
        return ms_snd_card_get_string_id(lc->sound_conf.play_sndcard);
 
1417
}
 
1418
 
 
1419
const char * linphone_core_get_capture_device(LinphoneCore *lc)
 
1420
{
 
1421
        return ms_snd_card_get_string_id(lc->sound_conf.capt_sndcard);
 
1422
}
 
1423
 
 
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;
 
1427
}
 
1428
 
 
1429
char linphone_core_get_sound_source(LinphoneCore *lc)
1182
1430
{
1183
1431
        return lc->sound_conf.source;
1184
1432
}
1185
 
void linphone_core_set_sound_source(LinphoneCore *lc, gchar source)
 
1433
 
 
1434
void linphone_core_set_sound_source(LinphoneCore *lc, char source)
1186
1435
{
 
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);
 
1438
        switch(source){
 
1439
                case 'm':
 
1440
                        ms_snd_card_set_capture(sndcard,MS_SND_CARD_MIC);
 
1441
                        break;
 
1442
                case 'l':
 
1443
                        ms_snd_card_set_capture(sndcard,MS_SND_CARD_LINE);
 
1444
                        break;
 
1445
        }
 
1446
        
1190
1447
}
1191
1448
 
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);
1195
1452
        }
1196
 
        lc->sound_conf.local_ring=g_strdup(path);
 
1453
        lc->sound_conf.local_ring=ms_strdup(path);
1197
1454
}
1198
 
gchar *linphone_core_get_ring(LinphoneCore *lc){
 
1455
char *linphone_core_get_ring(LinphoneCore *lc){
1199
1456
        return lc->sound_conf.local_ring;
1200
1457
}
1201
1458
 
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;
1205
1462
}
1206
1463
 
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)
1208
1465
{
1209
 
  if (lc->ringstream!=0){
1210
 
    g_warning("Cannot start ring now,there's already a ring being played");
1211
 
    return -1;
1212
 
  }
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);
1217
 
  return 0;
 
1466
        if (lc->ringstream!=0){
 
1467
                ms_warning("Cannot start ring now,there's already a ring being played");
 
1468
                return -1;
 
1469
        }
 
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);
 
1474
        return 0;
1218
1475
}
1219
1476
 
1220
1477
 
1230
1487
}
1231
1488
RingBackType linphone_core_get_ringback(LinphoneCore *lc);
1232
1489
 
1233
 
void linphone_core_send_dtmf(LinphoneCore *lc,gchar dtmf)
1234
 
{
1235
 
        if (lc->audiostream!=NULL){
1236
 
                send_dtmf(lc->audiostream,dtmf);
1237
 
        }
1238
 
}
1239
 
void linphone_core_force_ip_address(LinphoneCore *lc, gchar *ipaddr)
1240
 
{
1241
 
        linphone_core_set_nat_address(lc,ipaddr,1);
1242
 
}
1243
 
 
1244
 
 
1245
 
void linphone_core_set_nat_address(LinphoneCore *lc, gchar *addr, gboolean use)
1246
 
{
1247
 
        gchar *tmp=NULL;
1248
 
        gint err;
 
1490
void linphone_core_enable_echo_cancelation(LinphoneCore *lc, bool_t val){
 
1491
        lc->sound_conf.ec=val;
 
1492
}
 
1493
 
 
1494
bool_t linphone_core_echo_cancelation_enabled(LinphoneCore *lc){
 
1495
        return lc->sound_conf.ec;
 
1496
}
 
1497
 
 
1498
 
 
1499
void linphone_core_send_dtmf(LinphoneCore *lc,char dtmf)
 
1500
{
 
1501
  if (linphone_core_get_use_info_for_dtmf(lc)==0){
 
1502
    /* In Band DTMF */
 
1503
    if (lc->audiostream!=NULL){
 
1504
      audio_stream_send_dtmf(lc->audiostream,dtmf);
 
1505
    }
 
1506
  }
 
1507
  else{
 
1508
        char dtmf_body[1000];
 
1509
    /* Out of Band DTMF (use INFO method) */
 
1510
    LinphoneCall *call=lc->call;
 
1511
    if (call==NULL){
 
1512
      return;
 
1513
    }
 
1514
    
 
1515
    
 
1516
    snprintf(dtmf_body, 999, "Signal=%c\r\nDuration=250\r\n", dtmf);
 
1517
    eXosip_lock();
 
1518
    eXosip_info_call(call->did, "application/dtmf-relay", dtmf_body);
 
1519
    eXosip_unlock();
 
1520
  }
 
1521
}
 
1522
 
 
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);
 
1526
        if (server)
 
1527
                lc->net_conf.stun_server=ms_strdup(server);
 
1528
        else lc->net_conf.stun_server=NULL;
 
1529
        lc->apply_nat_settings=TRUE;
 
1530
}
 
1531
 
 
1532
const char * linphone_core_get_stun_server(const LinphoneCore *lc){
 
1533
        return lc->net_conf.stun_server;
 
1534
}
 
1535
 
 
1536
static void apply_nat_settings(LinphoneCore *lc){
 
1537
        char *wmsg;
 
1538
        char *tmp=NULL;
 
1539
        int err;
1249
1540
        struct addrinfo hints,*res;
 
1541
        const char *addr=lc->net_conf.nat_address;
1250
1542
        
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;
 
1548
                else 
 
1549
                        hints.ai_family=AF_INET;
1254
1550
                hints.ai_socktype = SOCK_DGRAM;
1255
1551
                err=getaddrinfo(addr,NULL,&hints,&res);
1256
 
                if (err==0){
1257
 
                        tmp=g_strdup(addr);
 
1552
                if (err!=0){
 
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);
 
1557
                        ms_free(wmsg);
 
1558
                        linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_NO_FIREWALL);
 
1559
                        return;
 
1560
                }
 
1561
                /*now get it as an numeric ip address */
 
1562
                tmp=ms_malloc0(50);
 
1563
                err=getnameinfo(res->ai_addr,res->ai_addrlen,tmp,50,NULL,0,NI_NUMERICHOST);
 
1564
                if (err!=0){
 
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);
 
1569
                        ms_free(wmsg);
 
1570
                        ms_free(tmp);
1258
1571
                        freeaddrinfo(res);
1259
 
                }else {
1260
 
                        g_warning("Invalid nat address %s",addr);
 
1572
                        linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_NO_FIREWALL);
1261
1573
                        return;
1262
1574
                }
1263
 
        }
 
1575
                freeaddrinfo(res);
 
1576
        }
 
1577
 
 
1578
        if (lc->net_conf.firewall_policy==LINPHONE_POLICY_USE_NAT_ADDRESS){
 
1579
                if (tmp!=NULL){
 
1580
                        if (!lc->net_conf.nat_sdp_only)
 
1581
                                eXosip_set_firewallip(tmp);
 
1582
                        ms_free(tmp);
 
1583
                }
 
1584
                else 
 
1585
                        eXosip_set_firewallip("");
 
1586
        }
 
1587
        else {
 
1588
                eXosip_set_firewallip("");      
 
1589
        }
 
1590
}
 
1591
 
 
1592
 
 
1593
void linphone_core_set_nat_address(LinphoneCore *lc, const char *addr)
 
1594
{
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);
1266
1597
        }
1267
 
        lc->net_conf.nat_address=tmp;
1268
 
        if (use && (tmp!=NULL)){
1269
 
                gchar *ct;
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;
 
1601
}
 
1602
 
 
1603
const char *linphone_core_get_nat_address(const LinphoneCore *lc)
 
1604
{
 
1605
        return lc->net_conf.nat_address;
 
1606
}
 
1607
 
 
1608
void linphone_core_set_firewall_policy(LinphoneCore *lc, LinphoneFirewallPolicy pol){
 
1609
        lc->net_conf.firewall_policy=pol;
 
1610
        lc->apply_nat_settings=TRUE;
 
1611
}
 
1612
 
 
1613
LinphoneFirewallPolicy linphone_core_get_firewall_policy(const LinphoneCore *lc){
 
1614
        return lc->net_conf.firewall_policy;
 
1615
}
 
1616
 
 
1617
MSList * linphone_core_get_call_logs(LinphoneCore *lc){
 
1618
        lc->missed_calls=0;
 
1619
        return lc->call_logs;
 
1620
}
 
1621
 
 
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){
 
1626
                if (val){
 
1627
                        if (lc->previewstream==NULL){
 
1628
                                lc->previewstream=video_preview_start(lc->video_conf.device);
 
1629
                        }
1273
1630
                }else{
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;
 
1634
                        }
1276
1635
                }
1277
 
                osip_ua_set_contact(lc->ua,ct);
1278
 
                g_free(ct);
1279
 
                lc->net_conf.use_nat=TRUE;
1280
 
        }
1281
 
        else {
1282
 
                lc->net_conf.use_nat=FALSE;
1283
 
                linphone_core_update_contact_info(lc);
1284
 
        }
1285
 
}
1286
 
 
1287
 
gchar *linphone_core_get_nat_address(LinphoneCore *lc, gboolean *use)
1288
 
{
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);
1291
 
        else return NULL;
1292
 
}
1293
 
 
1294
 
void net_config_uninit(net_config_t *config)
1295
 
{
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;
1301
 
#endif
1302
 
        gnome_config_set_int("net/con_type",config->con_type);
 
1636
        }
 
1637
#endif
 
1638
}
 
1639
 
 
1640
void linphone_core_enable_video(LinphoneCore *lc, bool_t val){
 
1641
#ifndef VIDEO_ENABLED
 
1642
        if (val)
 
1643
                ms_warning("This version of linphone was built without video support.");
 
1644
#endif
 
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));
 
1652
}
 
1653
 
 
1654
bool_t linphone_core_video_enabled(LinphoneCore *lc){
 
1655
        return lc->video_conf.enabled;
 
1656
}
 
1657
 
 
1658
 
 
1659
bool_t linphone_core_video_preview_enabled(const LinphoneCore *lc){
 
1660
        return lc->video_conf.show_local;
 
1661
}
 
1662
 
 
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;
 
1667
        }
 
1668
        if (device!=NULL)
 
1669
                lc->video_conf.device=ms_strdup(device);
 
1670
        return 0;
 
1671
}
 
1672
 
 
1673
void linphone_core_use_files(LinphoneCore *lc, bool_t yesno){
 
1674
        lc->use_files=yesno;
 
1675
}
 
1676
 
 
1677
void linphone_core_set_play_file(LinphoneCore *lc, const char *file){
 
1678
        if (lc->play_file!=NULL){
 
1679
                ms_free(lc->play_file);
 
1680
                lc->play_file=NULL;
 
1681
        }
 
1682
        if (file!=NULL) {
 
1683
                lc->play_file=ms_strdup(file);
 
1684
                if (lc->audiostream)
 
1685
                        audio_stream_play(lc->audiostream,file);
 
1686
        }
 
1687
}
 
1688
 
 
1689
void linphone_core_set_record_file(LinphoneCore *lc, const char *file){
 
1690
        if (lc->rec_file!=NULL){
 
1691
                ms_free(lc->rec_file);
 
1692
                lc->rec_file=NULL;
 
1693
        }
 
1694
        if (file!=NULL) {
 
1695
                lc->rec_file=ms_strdup(file);
 
1696
                if (lc->audiostream) 
 
1697
                        audio_stream_record(lc->audiostream,file);
 
1698
        }
 
1699
}
 
1700
 
 
1701
 
 
1702
void *linphone_core_get_user_data(LinphoneCore *lc){
 
1703
        return lc->data;
 
1704
}
 
1705
 
 
1706
void net_config_uninit(LinphoneCore *lc)
 
1707
{
 
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);
1303
1711
        
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);
1307
 
        
1308
 
}
1309
 
 
1310
 
void registrar_config_uninit(registrar_config_t *config)
1311
 
{
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);
1322
 
}
1323
 
void sip_config_uninit(sip_config_t *config)
1324
 
{
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);
1329
 
}
1330
 
 
1331
 
void rtp_config_uninit(rtp_config_t *config)
1332
 
{
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);
1337
 
}
1338
 
 
1339
 
void sound_config_uninit(sound_config_t *config)
1340
 
{
1341
 
        char tmpbuf[2];
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);
 
1717
}
 
1718
 
 
1719
 
 
1720
void sip_config_uninit(LinphoneCore *lc)
 
1721
{
 
1722
        MSList *elem;
 
1723
        int i;
 
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 */
 
1735
        }
 
1736
 
 
1737
        if (exosip_running)
 
1738
          {
 
1739
            int i;
 
1740
            for (i=0;i<20;i++)
 
1741
              {
 
1742
                eXosip_event_t *ev;
 
1743
                while((ev=eXosip_event_wait(0,0))!=NULL){
 
1744
                  linphone_core_process_event(lc,ev);
 
1745
                }
 
1746
#ifndef WIN32
 
1747
                usleep(100000);
 
1748
#else
 
1749
        Sleep(100);
 
1750
#endif
 
1751
              }
 
1752
          }
 
1753
        
 
1754
        linphone_proxy_config_write_to_config_file(lc->config,NULL,i);  /*mark the end */
 
1755
        
 
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);
 
1759
        }
 
1760
        linphone_auth_info_write_config(lc->config,NULL,i); /* mark the end */
 
1761
}
 
1762
 
 
1763
void rtp_config_uninit(LinphoneCore *lc)
 
1764
{
 
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);
 
1770
}
 
1771
 
 
1772
void sound_config_uninit(LinphoneCore *lc)
 
1773
{
 
1774
        /*char tmpbuf[2];*/
 
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);
 
1780
        /*
 
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);
 
1787
        */
 
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);
1350
1791
}
1351
1792
 
1352
 
void video_config_uninit(video_config_t *config)
 
1793
void video_config_uninit(LinphoneCore *lc)
1353
1794
{
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);
1356
1798
}
1357
1799
 
1358
 
void codecs_config_uninit(codecs_config_t *config)
 
1800
void codecs_config_uninit(LinphoneCore *lc)
1359
1801
{
1360
1802
        PayloadType *pt;
1361
 
        GList *node;
1362
 
        gchar key[50];
1363
 
        gint index;
 
1803
        codecs_config_t *config=&lc->codecs_conf;
 
1804
        MSList *node;
 
1805
        char key[50];
 
1806
        int index;
1364
1807
        index=0;
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));
1373
1814
                index++;
1374
1815
        }
1375
1816
        index=0;
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));
1384
1823
                index++;
1385
1824
        }
1386
1825
}
1387
1826
 
1388
 
void ui_config_uninit(ui_config_t *config)
 
1827
void ui_config_uninit(LinphoneCore* lc)
1389
1828
{
1390
 
        int len;
1391
 
        GList *elem;
1392
 
        gchar ab_entry[100];
1393
 
        /* record address book entries*/
1394
 
        len=0;
1395
 
        elem=config->address_list;
1396
 
        while(elem!=NULL)
1397
 
        {
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);
1401
 
                len++;
 
1829
        MSList *elem;
 
1830
        int i;
 
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);
1402
1834
        }
1403
 
        gnome_config_set_int("address_book/entry_count",len);
1404
 
}
 
1835
        linphone_friend_write_to_config_file(lc->config,NULL,i);        /* set the end */
 
1836
        ms_list_free(lc->friends);
 
1837
        lc->friends=NULL;
 
1838
}
 
1839
 
 
1840
LpConfig *linphone_core_get_config(LinphoneCore *lc){
 
1841
        return lc->config;
 
1842
}
 
1843
 
1405
1844
void linphone_core_uninit(LinphoneCore *lc)
1406
1845
{
1407
 
        /* unregister if necessary*/
1408
 
        if (lc->sip_conf.reg_conf.use_registrar){
1409
 
                do_registration(lc,0);
1410
 
                sleep(1);
 
1846
#ifdef VIDEO_ENABLED
 
1847
        if (lc->previewstream!=NULL){
 
1848
                video_preview_stop(lc->previewstream);
 
1849
                lc->previewstream=NULL;
1411
1850
        }
 
1851
#endif
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);
1421
1863
        
1422
1864
        ortp_exit();
1423
 
        osipua_exit();
 
1865
        eXosip_quit();
 
1866
        exosip_running=FALSE;
1424
1867
}
1425
1868
 
1426
1869
void linphone_core_destroy(LinphoneCore *lc){
1427
1870
        linphone_core_uninit(lc);
1428
 
        g_free(lc);
 
1871
        ms_free(lc);
1429
1872
}