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_auto_detect(LinphoneTunnelManager *tunnel){
75 bcTunnel(tunnel)->autoDetect();
79 static inline _LpConfig *config(LinphoneTunnelManager *tunnel){
80 return ((belledonnecomm::TunnelManager *)tunnel)->getLinphoneCore()->config;
84 * Set tunnel server addresses. "host1:port1 host2:port2 host3:port3"
86 void linphone_tunnel_set_server_addresses(LinphoneTunnelManager *tunnel, const char *addresses){
87 lp_config_set_string(config(tunnel),"tunnel","server_addresses",addresses);
91 * Get tunnel server addresses. "host1:port1 host2:port2 host3:port3"
93 const char *linphone_tunnel_get_server_addresses(LinphoneTunnelManager *tunnel){
94 return lp_config_get_string(config(tunnel),"tunnel","server_addresses", NULL);
100 void linphone_tunnel_set_state(LinphoneTunnelManager *tunnel, LinphoneTunnelState state){
102 case LinphoneTunnelEnabled:
103 lp_config_set_string(config(tunnel),"tunnel","tunnel_state","enabled");
105 case LinphoneTunnelDisabled:
106 lp_config_set_string(config(tunnel),"tunnel","tunnel_state","disabled");
108 case LinphoneTunnelAuto:
109 lp_config_set_string(config(tunnel),"tunnel","tunnel_state","auto");
117 LinphoneTunnelState linphone_tunnel_get_state(LinphoneTunnelManager *tunnel){
118 const char *state=lp_config_get_string(config(tunnel),"tunnel","tunnel_state","disabled");
119 if (0==strcmp("enabled", state)){
120 return LinphoneTunnelEnabled;
121 } else if (0==strcmp("auto", state)){
122 return LinphoneTunnelAuto;
124 return LinphoneTunnelDisabled;