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