1 /***************************************************************************
2 * linphone_tunnel_manager.cc
5 * Copyright 2011 Belledonne Communications
6 * Author: Guillaume Beraudo
7 * Email: guillaume dot beraudo at linphone dot org
8 ****************************************************************************/
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include "linphone_tunnel_manager.h"
28 #include "TunnelManager.hh"
29 #include "linphonecore.h"
33 static inline belledonnecomm::TunnelManager *bcTunnel(LinphoneTunnelManager *tunnel){
34 return (belledonnecomm::TunnelManager *)tunnel;
37 extern "C" LinphoneTunnelManager* linphone_core_tunnel_new(LinphoneCore *lc){
38 LinphoneTunnelManager* tunnel= (LinphoneTunnelManager*) new belledonnecomm::TunnelManager(lc);
42 LinphoneTunnelManager* linphone_tunnel_get(LinphoneCore *lc){
46 void linphone_tunnel_destroy(LinphoneTunnelManager *tunnel){
47 delete bcTunnel(tunnel);
50 void linphone_tunnel_add_server(LinphoneTunnelManager *tunnel, const char *host, int port){
51 bcTunnel(tunnel)->addServer(host, port);
54 void linphone_tunnel_add_server_and_mirror(LinphoneTunnelManager *tunnel, const char *host, int port, int remote_udp_mirror, int delay){
55 bcTunnel(tunnel)->addServer(host, port, remote_udp_mirror, delay);
58 void linphone_tunnel_clean_servers(LinphoneTunnelManager *tunnel){
59 bcTunnel(tunnel)->cleanServers();
62 void linphone_tunnel_enable(LinphoneTunnelManager *tunnel, bool_t enabled){
63 bcTunnel(tunnel)->enable(enabled);
66 bool_t linphone_tunnel_enabled(LinphoneTunnelManager *tunnel){
67 return bcTunnel(tunnel)->isEnabled();
70 void linphone_tunnel_enable_logs(LinphoneTunnelManager *tunnel, bool_t enabled){
71 bcTunnel(tunnel)->enableLogs(enabled);
74 void linphone_tunnel_enable_logs_with_handler(LinphoneTunnelManager *tunnel, bool_t enabled, LogHandler logHandler){
75 bcTunnel(tunnel)->enableLogs(enabled, logHandler);
78 void linphone_tunnel_set_http_proxy_auth_info(LinphoneTunnelManager *tunnel, const char* username,const char* passwd){
79 bcTunnel(tunnel)->setHttpProxyAuthInfo(username, passwd);
82 void linphone_tunnel_reconnect(LinphoneTunnelManager *tunnel){
83 bcTunnel(tunnel)->reconnect();
86 void linphone_tunnel_auto_detect(LinphoneTunnelManager *tunnel){
87 bcTunnel(tunnel)->autoDetect();
91 static inline _LpConfig *config(LinphoneTunnelManager *tunnel){
92 return ((belledonnecomm::TunnelManager *)tunnel)->getLinphoneCore()->config;
96 * Set tunnel server addresses. "host1:port1 host2:port2 host3:port3"
98 void linphone_tunnel_set_server_addresses(LinphoneTunnelManager *tunnel, const char *addresses){
99 lp_config_set_string(config(tunnel),"tunnel","server_addresses",addresses);
103 * Get tunnel server addresses. "host1:port1 host2:port2 host3:port3"
105 const char *linphone_tunnel_get_server_addresses(LinphoneTunnelManager *tunnel){
106 return lp_config_get_string(config(tunnel),"tunnel","server_addresses", NULL);
112 void linphone_tunnel_set_state(LinphoneTunnelManager *tunnel, LinphoneTunnelState state){
114 case LinphoneTunnelEnabled:
115 lp_config_set_string(config(tunnel),"tunnel","tunnel_state","enabled");
117 case LinphoneTunnelDisabled:
118 lp_config_set_string(config(tunnel),"tunnel","tunnel_state","disabled");
120 case LinphoneTunnelAuto:
121 lp_config_set_string(config(tunnel),"tunnel","tunnel_state","auto");
129 LinphoneTunnelState linphone_tunnel_get_state(LinphoneTunnelManager *tunnel){
130 const char *state=lp_config_get_string(config(tunnel),"tunnel","tunnel_state","disabled");
131 if (0==strcmp("enabled", state)){
132 return LinphoneTunnelEnabled;
133 } else if (0==strcmp("auto", state)){
134 return LinphoneTunnelAuto;
136 return LinphoneTunnelDisabled;