1 /***************************************************************************
2  *            linphone_tunnel_config.c
3  *
4  *  Copyright  2012  Belledonne Communications
5  ****************************************************************************/
6 
7 /*
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */
22 
23 #include "linphone/tunnel.h"
24 #include "private.h"
25 
26 
27 struct _LinphoneTunnelConfig {
28 	belle_sip_object_t base;
29 	char *host;
30 	int port;
31 	int remote_udp_mirror_port;
32 	int delay;
33 	void *user_data;
34 	char *host2;
35 	int port2;
36 };
37 
linphone_tunnel_config_new()38 LinphoneTunnelConfig *linphone_tunnel_config_new() {
39 	LinphoneTunnelConfig *ltc = belle_sip_object_new(LinphoneTunnelConfig);
40 	ltc->remote_udp_mirror_port = 12345;
41 	ltc->delay = 1000;
42 	ltc->port = 443;
43 	ltc->host2 = NULL;
44 	ltc->port2 = 0;
45 	return ltc;
46 }
47 
linphone_tunnel_config_set_host(LinphoneTunnelConfig * tunnel,const char * host)48 void linphone_tunnel_config_set_host(LinphoneTunnelConfig *tunnel, const char *host) {
49 	if(tunnel->host != NULL) {
50 		ms_free(tunnel->host);
51 		tunnel->host = NULL;
52 	}
53 	if(host != NULL && strlen(host)) {
54 		tunnel->host = ms_strdup(host);
55 	}
56 }
57 
linphone_tunnel_config_get_host(const LinphoneTunnelConfig * tunnel)58 const char *linphone_tunnel_config_get_host(const LinphoneTunnelConfig *tunnel) {
59 	return tunnel->host;
60 }
61 
linphone_tunnel_config_set_port(LinphoneTunnelConfig * tunnel,int port)62 void linphone_tunnel_config_set_port(LinphoneTunnelConfig *tunnel, int port) {
63 	tunnel->port = port;
64 }
65 
linphone_tunnel_config_get_port(const LinphoneTunnelConfig * tunnel)66 int linphone_tunnel_config_get_port(const LinphoneTunnelConfig *tunnel) {
67 	return tunnel->port;
68 }
69 
linphone_tunnel_config_set_host2(LinphoneTunnelConfig * tunnel,const char * host)70 void linphone_tunnel_config_set_host2(LinphoneTunnelConfig *tunnel, const char *host) {
71 	if(tunnel->host2 != NULL) {
72 		ms_free(tunnel->host2);
73 		tunnel->host2 = NULL;
74 	}
75 	if(host != NULL && strlen(host)) {
76 		tunnel->host2 = ms_strdup(host);
77 	}
78 }
79 
linphone_tunnel_config_get_host2(const LinphoneTunnelConfig * tunnel)80 const char *linphone_tunnel_config_get_host2(const LinphoneTunnelConfig *tunnel) {
81 	return tunnel->host2;
82 }
83 
linphone_tunnel_config_set_port2(LinphoneTunnelConfig * tunnel,int port)84 void linphone_tunnel_config_set_port2(LinphoneTunnelConfig *tunnel, int port) {
85 	tunnel->port2 = port;
86 }
87 
linphone_tunnel_config_get_port2(const LinphoneTunnelConfig * tunnel)88 int linphone_tunnel_config_get_port2(const LinphoneTunnelConfig *tunnel) {
89 	return tunnel->port2;
90 }
91 
linphone_tunnel_config_set_remote_udp_mirror_port(LinphoneTunnelConfig * tunnel,int remote_udp_mirror_port)92 void linphone_tunnel_config_set_remote_udp_mirror_port(LinphoneTunnelConfig *tunnel, int remote_udp_mirror_port) {
93 	tunnel->remote_udp_mirror_port = remote_udp_mirror_port;
94 }
95 
linphone_tunnel_config_get_remote_udp_mirror_port(const LinphoneTunnelConfig * tunnel)96 int linphone_tunnel_config_get_remote_udp_mirror_port(const LinphoneTunnelConfig *tunnel) {
97 	return tunnel->remote_udp_mirror_port;
98 }
99 
linphone_tunnel_config_set_delay(LinphoneTunnelConfig * tunnel,int delay)100 void linphone_tunnel_config_set_delay(LinphoneTunnelConfig *tunnel, int delay) {
101 	tunnel->delay = delay;
102 }
103 
linphone_tunnel_config_get_delay(const LinphoneTunnelConfig * tunnel)104 int linphone_tunnel_config_get_delay(const LinphoneTunnelConfig *tunnel) {
105 	return tunnel->delay;
106 }
107 
_linphone_tunnel_config_destroy(LinphoneTunnelConfig * tunnel)108 static void _linphone_tunnel_config_destroy(LinphoneTunnelConfig *tunnel) {
109 	if(tunnel->host != NULL) {
110 		ms_free(tunnel->host);
111 	}
112 }
113 
linphone_tunnel_config_ref(LinphoneTunnelConfig * cfg)114 LinphoneTunnelConfig * linphone_tunnel_config_ref(LinphoneTunnelConfig *cfg){
115 	return (LinphoneTunnelConfig*)belle_sip_object_ref(cfg);
116 }
117 
linphone_tunnel_config_unref(LinphoneTunnelConfig * cfg)118 void linphone_tunnel_config_unref(LinphoneTunnelConfig *cfg){
119 	belle_sip_object_unref(cfg);
120 }
121 
linphone_tunnel_config_destroy(LinphoneTunnelConfig * tunnel)122 void linphone_tunnel_config_destroy(LinphoneTunnelConfig *tunnel){
123 	linphone_tunnel_config_unref(tunnel);
124 }
125 
linphone_tunnel_config_set_user_data(LinphoneTunnelConfig * cfg,void * ud)126 void linphone_tunnel_config_set_user_data(LinphoneTunnelConfig *cfg, void *ud){
127 	cfg->user_data = ud;
128 }
129 
linphone_tunnel_config_get_user_data(LinphoneTunnelConfig * cfg)130 void *linphone_tunnel_config_get_user_data(LinphoneTunnelConfig *cfg){
131 	return cfg->user_data;
132 }
133 
134 BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneTunnelConfig);
135 
136 BELLE_SIP_INSTANCIATE_VPTR(LinphoneTunnelConfig, belle_sip_object_t,
137 	(belle_sip_object_destroy_t)_linphone_tunnel_config_destroy,
138 	NULL, // clone
139 	NULL, // marshal
140 	FALSE
141 );
142 
143 
144 
145