linphone_tunnel.cc 16.3 KB
Newer Older
Guillaume Beraudo's avatar
Guillaume Beraudo committed
1
/***************************************************************************
jehan's avatar
jehan committed
2
 *            linphone_tunnel.cc
Guillaume Beraudo's avatar
Guillaume Beraudo committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 *  Fri Dec 9, 2011
 *  Copyright  2011  Belledonne Communications
 *  Author: Guillaume Beraudo
 *  Email: guillaume dot beraudo at linphone dot org
 ****************************************************************************/

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "TunnelManager.hh"
27
#include "linphone/tunnel.h"
28
#include "linphone/core.h"
Guillaume Beraudo's avatar
Guillaume Beraudo committed
29
#include "private.h"
30
#include "linphone/lpconfig.h"
31
#include "c-wrapper/c-wrapper.h"
Guillaume Beraudo's avatar
Guillaume Beraudo committed
32

33
LinphoneTunnel* linphone_core_get_tunnel(const LinphoneCore *lc){
Simon Morlat's avatar
Simon Morlat committed
34 35 36
	return lc->tunnel;
}

Yann Diorcet's avatar
Yann Diorcet committed
37
struct _LinphoneTunnel {
38
	::belle_sip_object_t base;
Yann Diorcet's avatar
Yann Diorcet committed
39
	belledonnecomm::TunnelManager *manager;
40
	bctbx_list_t *config_list;
Yann Diorcet's avatar
Yann Diorcet committed
41 42
};

43 44 45
static void _linphone_tunnel_uninit(LinphoneTunnel *tunnel);

BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneTunnel);
46
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneTunnel);
47 48 49 50 51
BELLE_SIP_INSTANCIATE_VPTR(LinphoneTunnel, belle_sip_object_t,
	_linphone_tunnel_uninit, // uninit
	NULL, // clone
	NULL, // marshal
	FALSE // unowned
52
);
53

54
extern "C" LinphoneTunnel* linphone_core_tunnel_new(LinphoneCore *lc){
55
	LinphoneTunnel* tunnel = belle_sip_object_new(LinphoneTunnel);
Yann Diorcet's avatar
Yann Diorcet committed
56
	tunnel->manager = new belledonnecomm::TunnelManager(lc);
Guillaume Beraudo's avatar
Guillaume Beraudo committed
57 58 59
	return tunnel;
}

60 61 62 63 64
static void _linphone_tunnel_uninit(LinphoneTunnel *tunnel) {
	delete tunnel->manager;
	bctbx_list_free_with_data(tunnel->config_list, (bctbx_list_free_func)linphone_tunnel_config_unref);
}

65
belledonnecomm::TunnelManager *bcTunnel(const LinphoneTunnel *tunnel){
Yann Diorcet's avatar
Yann Diorcet committed
66
	return tunnel->manager;
Guillaume Beraudo's avatar
Guillaume Beraudo committed
67 68
}

69
static inline _LpConfig *config(const LinphoneTunnel *tunnel){
Yann Diorcet's avatar
Yann Diorcet committed
70
	return tunnel->manager->getLinphoneCore()->config;
Simon Morlat's avatar
Simon Morlat committed
71 72
}

73 74 75
LinphoneTunnel *linphone_tunnel_ref(LinphoneTunnel *tunnel) {
	return (LinphoneTunnel *)belle_sip_object_ref(tunnel);
}
76

77 78
void linphone_tunnel_unref(LinphoneTunnel *tunnel) {
	belle_sip_object_unref(tunnel);
Guillaume Beraudo's avatar
Guillaume Beraudo committed
79 80
}

Yann Diorcet's avatar
Yann Diorcet committed
81 82
static char *linphone_tunnel_config_to_string(const LinphoneTunnelConfig *tunnel_config) {
	char *str = NULL;
83
	const char *host = linphone_tunnel_config_get_host(tunnel_config);
84
	const char *host2 = linphone_tunnel_config_get_host2(tunnel_config);
85 86
	if(host != NULL) {
		if(linphone_tunnel_config_get_remote_udp_mirror_port(tunnel_config) != -1) {
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
			if (host2 != NULL) {
				str = ms_strdup_printf("%s:%d:%d:%d/%s:%d",
									linphone_tunnel_config_get_host(tunnel_config),
									linphone_tunnel_config_get_port(tunnel_config),
									linphone_tunnel_config_get_remote_udp_mirror_port(tunnel_config),
									linphone_tunnel_config_get_delay(tunnel_config),
									linphone_tunnel_config_get_host2(tunnel_config),
									linphone_tunnel_config_get_port2(tunnel_config));
			} else {
				str = ms_strdup_printf("%s:%d:%d:%d",
									linphone_tunnel_config_get_host(tunnel_config),
									linphone_tunnel_config_get_port(tunnel_config),
									linphone_tunnel_config_get_remote_udp_mirror_port(tunnel_config),
									linphone_tunnel_config_get_delay(tunnel_config));
			}
102 103 104 105 106 107
		} else if (host2 != NULL) {
			str = ms_strdup_printf("%s:%d/%s:%d",
								   linphone_tunnel_config_get_host(tunnel_config),
								   linphone_tunnel_config_get_port(tunnel_config),
								   linphone_tunnel_config_get_host2(tunnel_config),
								   linphone_tunnel_config_get_port2(tunnel_config));
108 109 110 111 112
		} else {
			str = ms_strdup_printf("%s:%d",
								   linphone_tunnel_config_get_host(tunnel_config),
								   linphone_tunnel_config_get_port(tunnel_config));
		}
Yann Diorcet's avatar
Yann Diorcet committed
113 114 115 116 117 118 119 120 121 122 123 124 125
	}
	return str;
}

static LinphoneTunnelConfig *linphone_tunnel_config_from_string(const char *str) {
	LinphoneTunnelConfig *tunnel_config = NULL;
	char * dstr = ms_strdup(str);
	const char *host = NULL;
	int port = -1;
	int remote_udp_mirror_port = -1;
	int delay = -1;
	int pos = 0;
	char *pch;
126 127 128 129 130 131
	char *tok1, *tok2;
	tok1 = strtok(dstr, "/");
	tok2 = strtok(NULL, "/");
	
	pch = strtok(tok1, ":");
	while (pch != NULL) {
Yann Diorcet's avatar
Yann Diorcet committed
132 133 134 135 136 137 138 139 140 141 142 143
		switch(pos) {
		case 0:
			host = pch;
			break;
		case 1:
			port = atoi(pch);
			break;
		case 2:
			remote_udp_mirror_port = atoi(pch);
			break;
		case 3:
			delay = atoi(pch);
144
			break;
Yann Diorcet's avatar
Yann Diorcet committed
145 146 147 148
		default:
			// Abort
			pos = 0;
			break;
149

Yann Diorcet's avatar
Yann Diorcet committed
150 151 152 153
		}
		++pos;
		pch = strtok(NULL, ":");
	}
154
	if (pos >= 2) {
Yann Diorcet's avatar
Yann Diorcet committed
155
		tunnel_config = linphone_tunnel_config_new();
156
		linphone_tunnel_config_set_remote_udp_mirror_port(tunnel_config, -1);
Yann Diorcet's avatar
Yann Diorcet committed
157 158 159
		linphone_tunnel_config_set_host(tunnel_config, host);
		linphone_tunnel_config_set_port(tunnel_config, port);
	}
160
	if (pos >= 3) {
Yann Diorcet's avatar
Yann Diorcet committed
161 162
		linphone_tunnel_config_set_remote_udp_mirror_port(tunnel_config, remote_udp_mirror_port);
	}
163
	if (pos == 4) {
Yann Diorcet's avatar
Yann Diorcet committed
164 165
		linphone_tunnel_config_set_delay(tunnel_config, delay);
	}
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
	
	if (tok2) {
		pos = 0;
		pch = strtok(tok2, ":");
		while (pch != NULL) {
			switch(pos) {
			case 0:
				host = pch;
				break;
			case 1:
				port = atoi(pch);
				break;
			case 2:
				remote_udp_mirror_port = atoi(pch);
				break;
			case 3:
				delay = atoi(pch);
				break;
			default:
				// Abort
				pos = 0;
				break;

			}
			++pos;
			pch = strtok(NULL, ":");
		}
		if (pos >= 2 && tunnel_config) {
			linphone_tunnel_config_set_host2(tunnel_config, host);
			linphone_tunnel_config_set_port2(tunnel_config, port);
		}
	}
	
199
	ms_free(dstr);
Yann Diorcet's avatar
Yann Diorcet committed
200
	return tunnel_config;
Guillaume Beraudo's avatar
Guillaume Beraudo committed
201 202
}

Yann Diorcet's avatar
Yann Diorcet committed
203

204
static void linphone_tunnel_save_config(const LinphoneTunnel *tunnel) {
205
	bctbx_list_t *elem = NULL;
Yann Diorcet's avatar
Yann Diorcet committed
206
	char *tmp = NULL, *old_tmp = NULL, *tc_str = NULL;
207
	for(elem = tunnel->config_list; elem != NULL; elem = elem->next) {
Yann Diorcet's avatar
Yann Diorcet committed
208 209
		LinphoneTunnelConfig *tunnel_config = (LinphoneTunnelConfig *)elem->data;
		tc_str = linphone_tunnel_config_to_string(tunnel_config);
210 211 212 213 214 215 216 217 218
		if(tc_str != NULL) {
			if(tmp != NULL) {
				old_tmp = tmp;
				tmp = ms_strdup_printf("%s %s", old_tmp, tc_str);
				ms_free(old_tmp);
				ms_free(tc_str);
			} else {
				tmp = tc_str;
			}
Yann Diorcet's avatar
Yann Diorcet committed
219 220 221 222 223 224 225 226 227 228
		}
	}
	lp_config_set_string(config(tunnel), "tunnel", "server_addresses", tmp);
	if(tmp != NULL) {
		ms_free(tmp);
	}
}


static void linphone_tunnel_add_server_intern(LinphoneTunnel *tunnel, LinphoneTunnelConfig *tunnel_config) {
229 230 231 232 233 234
	if (linphone_tunnel_config_get_remote_udp_mirror_port(tunnel_config) != -1) {
		if (linphone_tunnel_config_get_host2(tunnel_config) != NULL) {
			bcTunnel(tunnel)->addServerPair(linphone_tunnel_config_get_host(tunnel_config),
				linphone_tunnel_config_get_port(tunnel_config),
				linphone_tunnel_config_get_host2(tunnel_config),
				linphone_tunnel_config_get_port2(tunnel_config),
235 236
				(unsigned int)linphone_tunnel_config_get_remote_udp_mirror_port(tunnel_config),
				(unsigned int)linphone_tunnel_config_get_delay(tunnel_config));
237 238 239
		} else {
			bcTunnel(tunnel)->addServer(linphone_tunnel_config_get_host(tunnel_config),
				linphone_tunnel_config_get_port(tunnel_config),
240 241
				(unsigned int)linphone_tunnel_config_get_remote_udp_mirror_port(tunnel_config),
				(unsigned int)linphone_tunnel_config_get_delay(tunnel_config));
242
		}
243 244 245 246 247 248 249 250
	} else if (linphone_tunnel_config_get_host2(tunnel_config) != NULL) {
		bcTunnel(tunnel)->addServerPair(linphone_tunnel_config_get_host(tunnel_config),
			linphone_tunnel_config_get_port(tunnel_config),
			linphone_tunnel_config_get_host2(tunnel_config),
			linphone_tunnel_config_get_port2(tunnel_config));
	} else {
		bcTunnel(tunnel)->addServer(linphone_tunnel_config_get_host(tunnel_config),
			linphone_tunnel_config_get_port(tunnel_config));
Yann Diorcet's avatar
Yann Diorcet committed
251
	}
252
	tunnel->config_list = bctbx_list_append(tunnel->config_list, linphone_tunnel_config_ref(tunnel_config));
Guillaume Beraudo's avatar
Guillaume Beraudo committed
253 254
}

Yann Diorcet's avatar
Yann Diorcet committed
255 256 257

static void linphone_tunnel_load_config(LinphoneTunnel *tunnel){
	const char * confaddress = lp_config_get_string(config(tunnel), "tunnel", "server_addresses", NULL);
Simon Morlat's avatar
Simon Morlat committed
258
	char *tmp;
Yann Diorcet's avatar
Yann Diorcet committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
	const char *it;
	LinphoneTunnelConfig *tunnel_config;
	int adv;
	if(confaddress != NULL) {
		tmp = ms_strdup(confaddress);
		it = confaddress;
		while(confaddress[0] != '\0') {
			int ret = sscanf(it,"%s%n", tmp, &adv);
			if (ret >= 1){
				it += adv;
				tunnel_config = linphone_tunnel_config_from_string(tmp);
				if(tunnel_config != NULL) {
					linphone_tunnel_add_server_intern(tunnel, tunnel_config);
				} else {
					ms_error("Tunnel server address incorrectly specified from config file: %s", tmp);
				}
			} else break;
		}
		ms_free(tmp);
	}
Simon Morlat's avatar
Simon Morlat committed
279 280
}

Yann Diorcet's avatar
Yann Diorcet committed
281
static void linphone_tunnel_refresh_config(LinphoneTunnel *tunnel) {
282
	bctbx_list_t *old_list = tunnel->config_list;
Yann Diorcet's avatar
Yann Diorcet committed
283 284 285 286 287
	tunnel->config_list = NULL;
	bcTunnel(tunnel)->cleanServers();
	while(old_list != NULL) {
		LinphoneTunnelConfig *tunnel_config = (LinphoneTunnelConfig *)old_list->data;
		linphone_tunnel_add_server_intern(tunnel, tunnel_config);
288
		linphone_tunnel_config_unref(tunnel_config);
Yann Diorcet's avatar
Yann Diorcet committed
289 290
		old_list = old_list->next;
	}
Simon Morlat's avatar
Simon Morlat committed
291 292
}

Yann Diorcet's avatar
Yann Diorcet committed
293 294 295
void linphone_tunnel_add_server(LinphoneTunnel *tunnel, LinphoneTunnelConfig *tunnel_config) {
	linphone_tunnel_add_server_intern(tunnel, tunnel_config);
	linphone_tunnel_save_config(tunnel);
Guillaume Beraudo's avatar
Guillaume Beraudo committed
296 297
}

Yann Diorcet's avatar
Yann Diorcet committed
298
void linphone_tunnel_remove_server(LinphoneTunnel *tunnel, LinphoneTunnelConfig *tunnel_config) {
299
	bctbx_list_t *elem = bctbx_list_find(tunnel->config_list, tunnel_config);
Yann Diorcet's avatar
Yann Diorcet committed
300
	if(elem != NULL) {
301
		tunnel->config_list = bctbx_list_remove(tunnel->config_list, tunnel_config);
302
		linphone_tunnel_config_unref(tunnel_config);
Yann Diorcet's avatar
Yann Diorcet committed
303 304
		linphone_tunnel_refresh_config(tunnel);
		linphone_tunnel_save_config(tunnel);
305
	}
Simon Morlat's avatar
Simon Morlat committed
306 307
}

308
const bctbx_list_t *linphone_tunnel_get_servers(const LinphoneTunnel *tunnel){
Yann Diorcet's avatar
Yann Diorcet committed
309
	return tunnel->config_list;
Guillaume Beraudo's avatar
Guillaume Beraudo committed
310 311
}

312
void linphone_tunnel_clean_servers(LinphoneTunnel *tunnel){
Guillaume Beraudo's avatar
Guillaume Beraudo committed
313
	bcTunnel(tunnel)->cleanServers();
314

Yann Diorcet's avatar
Yann Diorcet committed
315
	/* Free the list */
316
	bctbx_list_free_with_data(tunnel->config_list, (void (*)(void *))linphone_tunnel_config_destroy);
317 318
	tunnel->config_list = NULL;

Yann Diorcet's avatar
Yann Diorcet committed
319
	linphone_tunnel_save_config(tunnel);
Guillaume Beraudo's avatar
Guillaume Beraudo committed
320 321
}

322
void linphone_tunnel_set_mode(LinphoneTunnel *tunnel, LinphoneTunnelMode mode){
323
	lp_config_set_string(config(tunnel),"tunnel","mode", linphone_tunnel_mode_to_string(mode));
324
	bcTunnel(tunnel)->setMode(mode);
Guillaume Beraudo's avatar
Guillaume Beraudo committed
325 326
}

327 328
LinphoneTunnelMode linphone_tunnel_get_mode(const LinphoneTunnel *tunnel){
	return bcTunnel(tunnel)->getMode();
Guillaume Beraudo's avatar
Guillaume Beraudo committed
329 330
}

Sylvain Berfini's avatar
Sylvain Berfini committed
331
void linphone_tunnel_enable_dual_mode(LinphoneTunnel *tunnel, bool_t dual_mode_enabled) {
332
	lp_config_set_int(config(tunnel), "tunnel", "dual_mode", (dual_mode_enabled ? TRUE : FALSE));
333 334 335
	bcTunnel(tunnel)->enableDualMode(dual_mode_enabled);
}

Sylvain Berfini's avatar
Sylvain Berfini committed
336
bool_t linphone_tunnel_dual_mode_enabled(const LinphoneTunnel *tunnel) {
337 338 339
	return bcTunnel(tunnel)->isDualModeEnabled();
}

340
bool_t linphone_tunnel_connected(const LinphoneTunnel *tunnel){
341
	return bcTunnel(tunnel)->isConnected();
342 343
}

344 345 346 347
bool_t linphone_tunnel_get_activated(const LinphoneTunnel *tunnel){
	return bcTunnel(tunnel)->isActivated();
}

Simon Morlat's avatar
Simon Morlat committed
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
static OrtpLogFunc tunnelOrtpLogHandler=NULL;

/*
#define TUNNEL_DEBUG (1)
#define TUNNEL_INFO  (1<<1)
#define TUNNEL_NOTICE (1<<2)
#define TUNNEL_WARN  (1<<3)
#define TUNNEL_ERROR (1<<4)
#define TUNNEL_ALERT (1<<5)
#define TUNNEL_FATAL (1<<6)
*/

static void tunnelLogHandler(int level, const char *fmt, va_list l){
	if (tunnelOrtpLogHandler){
		OrtpLogLevel ortp_level=ORTP_DEBUG;
		switch(level){
			case TUNNEL_DEBUG:
				ortp_level=ORTP_DEBUG;
			break;
			case TUNNEL_INFO:
				ortp_level=ORTP_MESSAGE;
			break;
			case TUNNEL_NOTICE:
				ortp_level=ORTP_MESSAGE;
			break;
			case TUNNEL_WARN:
				ortp_level=ORTP_WARNING;
			break;
			case TUNNEL_ERROR:
				ortp_level=ORTP_ERROR;
			break;
			case TUNNEL_ALERT:
				ortp_level=ORTP_ERROR;
			break;
			case TUNNEL_FATAL:
				ortp_level=ORTP_FATAL;
			break;
			default:
				ms_fatal("Unexepcted tunnel log %i: %s",level,fmt);
			break;
		}
Simon Morlat's avatar
Simon Morlat committed
389
		tunnelOrtpLogHandler("tunnel", ortp_level,fmt,l);
Simon Morlat's avatar
Simon Morlat committed
390
	}
Guillaume Beraudo's avatar
Guillaume Beraudo committed
391 392
}

Simon Morlat's avatar
Simon Morlat committed
393 394
void linphone_tunnel_enable_logs_with_handler(LinphoneTunnel *tunnel, bool_t enabled, OrtpLogFunc logHandler){
	tunnelOrtpLogHandler=logHandler;
395
	bcTunnel(tunnel)->enableLogs(enabled == FALSE ? false : true, tunnelLogHandler);
396 397
}

398
void linphone_tunnel_set_http_proxy_auth_info(LinphoneTunnel *tunnel, const char* username,const char* passwd){
399 400 401
	bcTunnel(tunnel)->setHttpProxyAuthInfo(username, passwd);
}

Simon Morlat's avatar
Simon Morlat committed
402 403
void linphone_tunnel_set_http_proxy(LinphoneTunnel*tunnel, const char *host, int port, const char* username,const char* passwd){
	bcTunnel(tunnel)->setHttpProxy(host, port, username, passwd);
404 405 406 407 408 409 410 411 412 413 414
	lp_config_set_string(config(tunnel),"tunnel","http_proxy_host",host);
	lp_config_set_int(config(tunnel),"tunnel","http_proxy_port",port);
	lp_config_set_string(config(tunnel),"tunnel","http_proxy_username",username);
	lp_config_set_string(config(tunnel),"tunnel","http_proxy_password",passwd);
}

void linphone_tunnel_get_http_proxy(LinphoneTunnel*tunnel,const char **host, int *port, const char **username, const char **passwd){
	if (host) *host=lp_config_get_string(config(tunnel),"tunnel","http_proxy_host",NULL);
	if (port) *port=lp_config_get_int(config(tunnel),"tunnel","http_proxy_port",0);
	if (username) *username=lp_config_get_string(config(tunnel),"tunnel","http_proxy_username",NULL);
	if (passwd) *passwd=lp_config_get_string(config(tunnel),"tunnel","http_proxy_password",NULL);
Simon Morlat's avatar
Simon Morlat committed
415 416
}

417
void linphone_tunnel_reconnect(LinphoneTunnel *tunnel){
418 419 420
	bcTunnel(tunnel)->reconnect();
}

421
void linphone_tunnel_enable_sip(LinphoneTunnel *tunnel, bool_t enable) {
422
	bcTunnel(tunnel)->tunnelizeSipPackets(enable == FALSE ? false : true);
423
	lp_config_set_int(config(tunnel), "tunnel", "sip", (enable ? TRUE : FALSE));
424 425
}

426
bool_t linphone_tunnel_sip_enabled(const LinphoneTunnel *tunnel) {
427 428 429
	return bcTunnel(tunnel)->tunnelizeSipPacketsEnabled() ? TRUE : FALSE;
}

430
void linphone_tunnel_verify_server_certificate(LinphoneTunnel *tunnel, bool_t enable) {
431
	bcTunnel(tunnel)->verifyServerCertificate(enable == FALSE ? false : true);
432
	lp_config_set_int(config(tunnel), "tunnel", "verify_cert", (enable ? TRUE : FALSE));
433 434 435 436 437 438
}

bool_t linphone_tunnel_verify_server_certificate_enabled(const LinphoneTunnel *tunnel) {
	return bcTunnel(tunnel)->verifyServerCertificateEnabled() ? TRUE : FALSE;
}

Simon Morlat's avatar
Simon Morlat committed
439 440
static void my_ortp_logv(const char *domain, OrtpLogLevel level, const char *fmt, va_list args){
	ortp_logv(domain, level,fmt,args);
Simon Morlat's avatar
Simon Morlat committed
441 442
}

443

444
/**
Simon Morlat's avatar
Simon Morlat committed
445 446
 * Startup tunnel using configuration.
 * Called internally from linphonecore at startup.
447
 */
Simon Morlat's avatar
Simon Morlat committed
448
void linphone_tunnel_configure(LinphoneTunnel *tunnel){
449
	LinphoneTunnelMode mode = linphone_tunnel_mode_from_string(lp_config_get_string(config(tunnel), "tunnel", "mode", NULL));
450
	bool_t tunnelizeSIPPackets = (bool_t)lp_config_get_int(config(tunnel), "tunnel", "sip", TRUE);
451
	bool_t tunnelVerifyServerCertificate = (bool_t)lp_config_get_int(config(tunnel), "tunnel", "verify_cert", FALSE);
452
	bool_t useDualMode = (bool_t)lp_config_get_int(config(tunnel), "tunnel", "dual_mode", FALSE);
453 454 455 456 457
	const char *http_host, *http_username, *http_passwd;
	int http_port;
	linphone_tunnel_get_http_proxy(tunnel,&http_host, &http_port, &http_username, &http_passwd);
	bcTunnel(tunnel)->setHttpProxy(http_host, http_port, http_username, http_passwd);
	
Sylvain Berfini's avatar
Sylvain Berfini committed
458
	linphone_tunnel_enable_dual_mode(tunnel, useDualMode);
Simon Morlat's avatar
Simon Morlat committed
459
	linphone_tunnel_enable_logs_with_handler(tunnel,TRUE,my_ortp_logv);
Yann Diorcet's avatar
Yann Diorcet committed
460
	linphone_tunnel_load_config(tunnel);
461
	linphone_tunnel_enable_sip(tunnel, tunnelizeSIPPackets);
462
	linphone_tunnel_verify_server_certificate(tunnel, tunnelVerifyServerCertificate);
463
	
464 465 466
	/*Tunnel is started here if mode equals true*/
	linphone_tunnel_set_mode(tunnel, mode);

467 468 469 470
}

/* Deprecated functions */
void linphone_tunnel_enable(LinphoneTunnel *tunnel, bool_t enabled) {
471
	ms_warning("linphone_tunnel_enable is deprecated - please use linphone_tunnel_set_mode instead.");
472 473 474 475 476 477 478 479 480 481 482 483 484 485
	if(enabled) linphone_tunnel_set_mode(tunnel, LinphoneTunnelModeEnable);
	else linphone_tunnel_set_mode(tunnel, LinphoneTunnelModeDisable);
}

bool_t linphone_tunnel_enabled(const LinphoneTunnel *tunnel) {
	return linphone_tunnel_get_mode(tunnel) == LinphoneTunnelModeEnable;
}

void linphone_tunnel_auto_detect(LinphoneTunnel *tunnel) {
	linphone_tunnel_set_mode(tunnel, LinphoneTunnelModeAuto);
}

bool_t linphone_tunnel_auto_detect_enabled(LinphoneTunnel *tunnel) {
	return linphone_tunnel_get_mode(tunnel) == LinphoneTunnelModeAuto;
486
}
487 488

void linphone_tunnel_simulate_udp_loss(LinphoneTunnel *tunnel, bool_t enabled) {
489
	bcTunnel(tunnel)->simulateUdpLoss(enabled == FALSE ? false : true);
490
}