ProxyConfig.cpp 6.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
ProxyConfig.cpp
Copyright (C) 2015  Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
15 16 17 18 19 20
*/

#include "Core.h"
#include "ProxyConfig.h"
#include "Utils.h"

21
using namespace BelledonneCommunications::Linphone::Native;
22

23
Platform::String^ ProxyConfig::ContactParameters::get()
24 25 26 27 28
{
	API_LOCK;
	return Utils::cctops(linphone_proxy_config_get_contact_parameters(this->proxyConfig));
}

29
void ProxyConfig::ContactParameters::set(Platform::String^ params)
30 31 32 33 34 35 36
{
	API_LOCK;
	const char* cc = Utils::pstoccs(params);
	linphone_proxy_config_set_contact_parameters(this->proxyConfig, cc);
	delete(cc);
}

37
Platform::String^ ProxyConfig::ContactUriParameters::get()
38 39 40 41 42
{
	API_LOCK;
	return Utils::cctops(linphone_proxy_config_get_contact_uri_parameters(this->proxyConfig));
}

43
void ProxyConfig::ContactUriParameters::set(Platform::String^ params)
44 45 46 47 48 49 50
{
	API_LOCK;
	const char* cc = Utils::pstoccs(params);
	linphone_proxy_config_set_contact_uri_parameters(this->proxyConfig, cc);
	delete(cc);
}

51
Platform::Boolean ProxyConfig::DialEscapePlus::get()
52 53 54 55 56
{
	API_LOCK;
	return (linphone_proxy_config_get_dial_escape_plus(this->proxyConfig) == TRUE);
}

57
void ProxyConfig::DialEscapePlus::set(Platform::Boolean value)
58 59 60 61 62
{
	API_LOCK;
	linphone_proxy_config_set_dial_escape_plus(this->proxyConfig, value);
}

63
Platform::String^ ProxyConfig::DialPrefix::get()
64 65 66 67 68
{
	API_LOCK;
	return Utils::cctops(linphone_proxy_config_get_dial_prefix(this->proxyConfig));
}

69
void ProxyConfig::DialPrefix::set(Platform::String^ prefix)
70 71 72 73 74 75 76
{
	API_LOCK;
	const char* cc = Utils::pstoccs(prefix);
	linphone_proxy_config_set_dial_prefix(this->proxyConfig, cc);
	delete(cc);
}

77
Platform::String^ ProxyConfig::Domain::get()
78 79 80 81 82
{
	API_LOCK;
	return Utils::cctops(linphone_proxy_config_get_domain(this->proxyConfig));
}

83
Reason ProxyConfig::Error::get()
84 85
{
	API_LOCK;
86
	return (Reason)linphone_proxy_config_get_error(this->proxyConfig);
87 88
}

89
int ProxyConfig::Expires::get()
90 91 92 93 94
{
	API_LOCK;
	return linphone_proxy_config_get_expires(this->proxyConfig);
}

95
void ProxyConfig::Expires::set(int delay)
96 97 98 99 100
{
	API_LOCK;
	linphone_proxy_config_set_expires(this->proxyConfig, delay);
}

101
Platform::String^ ProxyConfig::Identity::get()
102 103 104 105 106
{
	API_LOCK;
	return Utils::cctops(linphone_proxy_config_get_identity(this->proxyConfig));
}

107
void ProxyConfig::Identity::set(Platform::String^ identity)
108 109 110 111 112 113 114
{
	API_LOCK;
	const char* cidentity = Utils::pstoccs(identity);
	linphone_proxy_config_set_identity(this->proxyConfig, cidentity);
	delete(cidentity);
}

115
Platform::Boolean ProxyConfig::IsAvpfEnabled::get()
116 117
{
	API_LOCK;
118 119 120
	return (linphone_proxy_config_avpf_enabled(this->proxyConfig) == TRUE);
}

121
void ProxyConfig::IsAvpfEnabled::set(Platform::Boolean enable)
122 123 124
{
	API_LOCK;
	linphone_proxy_config_enable_avpf(this->proxyConfig, enable);
125 126
}

127
Platform::Boolean ProxyConfig::IsPublishEnabled::get()
128 129 130 131 132
{
	API_LOCK;
	return (linphone_proxy_config_publish_enabled(this->proxyConfig) == TRUE);
}

133
void ProxyConfig::IsPublishEnabled::set(Platform::Boolean enable)
134 135 136 137 138
{
	API_LOCK;
	linphone_proxy_config_enable_publish(this->proxyConfig, enable);
}

139
Platform::Boolean ProxyConfig::IsRegistered::get()
140 141 142 143 144
{
	API_LOCK;
	return (linphone_proxy_config_is_registered(this->proxyConfig) == TRUE);
}

145
Platform::Boolean ProxyConfig::IsRegisterEnabled::get()
146 147 148 149 150
{
	API_LOCK;
	return (linphone_proxy_config_register_enabled(this->proxyConfig) == TRUE);
}

151
void ProxyConfig::IsRegisterEnabled::set(Platform::Boolean enable)
152 153 154 155 156
{
	API_LOCK;
	linphone_proxy_config_enable_register(this->proxyConfig, enable);
}

157
Platform::String^ ProxyConfig::Route::get()
158 159 160 161 162
{
	API_LOCK;
	return Utils::cctops(linphone_proxy_config_get_route(this->proxyConfig));
}

163
void ProxyConfig::Route::set(Platform::String^ routeUri)
164 165 166 167 168 169 170
{
	API_LOCK;
	const char* cc = Utils::pstoccs(routeUri);
	linphone_proxy_config_set_route(this->proxyConfig, cc);
	delete(cc);
}

171
Platform::String^ ProxyConfig::ServerAddr::get()
172 173 174 175 176
{
	API_LOCK;
	return Utils::cctops(linphone_proxy_config_get_server_addr(this->proxyConfig));
}

177
void ProxyConfig::ServerAddr::set(Platform::String^ proxyUri)
178 179 180 181 182 183 184
{
	API_LOCK;
	const char* cc = Utils::pstoccs(proxyUri);
	linphone_proxy_config_set_server_addr(this->proxyConfig, cc);
	delete(cc);
}

185
RegistrationState ProxyConfig::State::get()
186 187
{
	API_LOCK;
188
	return (RegistrationState)linphone_proxy_config_get_state(this->proxyConfig);
189 190
}

191
void ProxyConfig::Done()
192 193 194 195 196
{
	API_LOCK;
	linphone_proxy_config_done(this->proxyConfig);
}

197
void ProxyConfig::Edit()
198 199 200 201 202
{
	API_LOCK;
	linphone_proxy_config_edit(this->proxyConfig);
}

203
Platform::String^ ProxyConfig::NormalizeNumber(Platform::String^ phoneNumber)
204 205 206 207 208 209 210 211
{
	API_LOCK;
	const char* cc = Utils::pstoccs(phoneNumber);
	char* result = (char*) malloc(phoneNumber->Length());
	int result_size = 0;
	linphone_proxy_config_normalize_number(this->proxyConfig, cc, result, result_size);
	Platform::String^ val = Utils::cctops(result);
	delete(cc);
212
	free(result);
213 214 215
	return val;
}

216
int ProxyConfig::LookupCccFromE164(Platform::String^ e164)
217 218
{
	API_LOCK;
219
	const char* e164char = Utils::pstoccs(e164);
220 221 222 223 224
	int ccc = linphone_dial_plan_lookup_ccc_from_e164(e164char);
	delete(e164char);
	return ccc;
}

225
int ProxyConfig::LookupCccFromIso(Platform::String^ iso)
226 227
{
	API_LOCK;
228
	const char* isochar = Utils::pstoccs(iso);
229 230 231 232 233
	int ccc = linphone_dial_plan_lookup_ccc_from_iso(isochar);
	delete(isochar);
	return ccc;
}

234
ProxyConfig::ProxyConfig(::LinphoneProxyConfig* proxyConfig)
235 236 237 238 239 240 241 242
{
	API_LOCK;
	this->proxyConfig = proxyConfig;
	RefToPtrProxy<ProxyConfig^> *proxy = new RefToPtrProxy<ProxyConfig^>(this);
	linphone_proxy_config_ref(this->proxyConfig);
	linphone_proxy_config_set_user_data(this->proxyConfig, proxy);
}

243
ProxyConfig::~ProxyConfig()
244 245 246 247 248 249
{
	API_LOCK;
	RefToPtrProxy<ProxyConfig^> *proxy = reinterpret_cast< RefToPtrProxy<ProxyConfig^> *>(linphone_proxy_config_get_user_data(this->proxyConfig));
	delete proxy;
	linphone_proxy_config_unref(this->proxyConfig);
}