]> sjero.net Git - linphone/blob - coreapi/linphone_tunnel.cc
Merge branch 'master' of git.linphone.org:linphone
[linphone] / coreapi / linphone_tunnel.cc
1 /***************************************************************************
2  *            linphone_tunnel.cc
3  *
4  *  Fri Dec 9, 2011
5  *  Copyright  2011  Belledonne Communications
6  *  Author: Guillaume Beraudo
7  *  Email: guillaume dot beraudo at linphone dot org
8  ****************************************************************************/
9
10 /*
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.
15  *
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.
20  *
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.
24  */
25
26
27 #include "linphone_tunnel.h"
28 #include "TunnelManager.hh"
29 #include "linphonecore.h"
30 #include "private.h"
31 #include "lpconfig.h"
32
33 static inline belledonnecomm::TunnelManager *bcTunnel(LinphoneTunnel *tunnel){
34         return (belledonnecomm::TunnelManager *)tunnel;
35 }
36
37 extern "C" LinphoneTunnel* linphone_core_tunnel_new(LinphoneCore *lc){
38         LinphoneTunnel* tunnel= (LinphoneTunnel*) new belledonnecomm::TunnelManager(lc);
39         return tunnel;
40 }
41
42 LinphoneTunnel* linphone_core_get_tunnel(LinphoneCore *lc){
43         return lc->tunnel;
44 }
45
46 void linphone_tunnel_destroy(LinphoneTunnel *tunnel){
47         delete bcTunnel(tunnel);
48 }
49
50 void linphone_tunnel_add_server(LinphoneTunnel *tunnel, const char *host, int port){
51         bcTunnel(tunnel)->addServer(host, port);
52 }
53
54 void linphone_tunnel_add_server_and_mirror(LinphoneTunnel *tunnel, const char *host, int port, int remote_udp_mirror, int delay){
55         bcTunnel(tunnel)->addServer(host, port, remote_udp_mirror, delay);
56 }
57
58 void linphone_tunnel_clean_servers(LinphoneTunnel *tunnel){
59         bcTunnel(tunnel)->cleanServers();
60 }
61
62 void linphone_tunnel_enable(LinphoneTunnel *tunnel, bool_t enabled){
63         bcTunnel(tunnel)->enable(enabled);
64 }
65
66 bool_t linphone_tunnel_enabled(LinphoneTunnel *tunnel){
67         return bcTunnel(tunnel)->isEnabled();
68 }
69
70 void linphone_tunnel_enable_logs(LinphoneTunnel *tunnel, bool_t enabled){
71         bcTunnel(tunnel)->enableLogs(enabled);
72 }
73
74 void linphone_tunnel_enable_logs_with_handler(LinphoneTunnel *tunnel, bool_t enabled, LogHandler logHandler){
75         bcTunnel(tunnel)->enableLogs(enabled, logHandler);
76 }
77
78 void linphone_tunnel_set_http_proxy_auth_info(LinphoneTunnel *tunnel, const char* username,const char* passwd){
79         bcTunnel(tunnel)->setHttpProxyAuthInfo(username, passwd);
80 }
81
82 void linphone_tunnel_reconnect(LinphoneTunnel *tunnel){
83         bcTunnel(tunnel)->reconnect();
84 }
85
86 void linphone_tunnel_auto_detect(LinphoneTunnel *tunnel){
87         bcTunnel(tunnel)->autoDetect();
88 }
89
90
91 static inline _LpConfig *config(LinphoneTunnel *tunnel){
92         return ((belledonnecomm::TunnelManager *)tunnel)->getLinphoneCore()->config;
93 }
94
95 /**
96  * Set tunnel server addresses. "host1:port1 host2:port2 host3:port3"
97 **/
98 void linphone_tunnel_set_server_addresses(LinphoneTunnel *tunnel, const char *addresses){
99         lp_config_set_string(config(tunnel),"tunnel","server_addresses",addresses);
100 }
101
102 /**
103  * Get tunnel server addresses. "host1:port1 host2:port2 host3:port3"
104 **/
105 const char *linphone_tunnel_get_server_addresses(LinphoneTunnel *tunnel){
106         return lp_config_get_string(config(tunnel),"tunnel","server_addresses", NULL);
107 }
108
109 /**
110  * Set tunnel state.
111 **/
112 void linphone_tunnel_set_state(LinphoneTunnel *tunnel, LinphoneTunnelState state){
113         switch (state) {
114                 case LinphoneTunnelEnabled:
115                         lp_config_set_string(config(tunnel),"tunnel","tunnel_state","enabled");
116                         break;
117                 case LinphoneTunnelDisabled:
118                         lp_config_set_string(config(tunnel),"tunnel","tunnel_state","disabled");
119                         break;
120                 case LinphoneTunnelAuto:
121                         lp_config_set_string(config(tunnel),"tunnel","tunnel_state","auto");
122                         break;
123         }
124 }
125
126 /**
127  * Get tunnel state.
128 **/
129 LinphoneTunnelState linphone_tunnel_get_state(LinphoneTunnel *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;
135         } else {
136                 return LinphoneTunnelDisabled;
137         }
138 }