Address.cpp 3.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
Address.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
*/

#include "ApiLock.h"
#include "Address.h"

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

Platform::String^ Address::DisplayName::get()
23 24
{
	API_LOCK;
25
	return Utils::cctops(linphone_address_get_display_name(this->address));
26 27
}

28
void Address::DisplayName::set(Platform::String^ name)
29 30
{
	API_LOCK;
31
	const char *cc = Utils::pstoccs(name);
32 33 34 35
	linphone_address_set_display_name(this->address, cc);
	delete(cc);
}

36
Platform::String^ Address::Domain::get()
37 38
{
	API_LOCK;
39
	return Utils::cctops(linphone_address_get_domain(this->address));
40 41
}

42
void Address::Domain::set(Platform::String^ domain)
43 44
{
	API_LOCK;
45
	const char *cc = Utils::pstoccs(domain);
46 47 48 49
	linphone_address_set_domain(this->address, cc);
	delete(cc);
}

50
int Address::Port::get()
51 52 53 54 55
{
	API_LOCK;
	return linphone_address_get_port(this->address);
}

56
void Address::Port::set(int port)
57 58 59 60 61
{
	API_LOCK;
	linphone_address_set_port(this->address, port);
}

62
Platform::String^ Address::Scheme::get()
63 64
{
	API_LOCK;
65
	return Utils::cctops(linphone_address_get_scheme(this->address));
66 67
}

68
Transport Address::Transport::get()
69 70 71 72 73 74 75
{
	API_LOCK;
	::LinphoneTransportType transport = linphone_address_get_transport(this->address);
	switch (transport)
	{
	default:
	case LinphoneTransportUdp:
76
		return BelledonneCommunications::Linphone::Native::Transport::UDP;
77
	case LinphoneTransportTcp:
78
		return BelledonneCommunications::Linphone::Native::Transport::TCP;
79
	case LinphoneTransportTls:
80
		return BelledonneCommunications::Linphone::Native::Transport::TLS;
81
	case LinphoneTransportDtls:
82
		return BelledonneCommunications::Linphone::Native::Transport::DTLS;
83 84 85
	}
}

86
void Address::Transport::set(BelledonneCommunications::Linphone::Native::Transport transport)
87 88 89
{
	API_LOCK;
	::LinphoneTransportType transportType = LinphoneTransportUdp;
90
	if (transport == BelledonneCommunications::Linphone::Native::Transport::TCP)
91 92 93
	{
		transportType = LinphoneTransportTcp;
	}
94
	else if (transport == BelledonneCommunications::Linphone::Native::Transport::TLS)
95 96 97
	{
		transportType = LinphoneTransportTls;
	}
98
	else if (transport == BelledonneCommunications::Linphone::Native::Transport::DTLS)
99 100 101 102 103 104 105
	{
		transportType = LinphoneTransportDtls;
	}

	linphone_address_set_transport(this->address, transportType);
}

106
Platform::String^ Address::UserName::get()
107 108
{
	API_LOCK;
109
	return Utils::cctops(linphone_address_get_username(this->address));
110 111
}

112
void Address::UserName::set(Platform::String^ username)
113 114
{
	API_LOCK;
115
	const char *cc = Utils::pstoccs(username);
116 117 118 119
	linphone_address_set_username(this->address, cc);
	delete(cc);
}

120
Platform::String^ Address::AsString()
121 122
{
	API_LOCK;
123
	return Utils::cctops(linphone_address_as_string(this->address));
124 125
}

126
Platform::String^ Address::AsStringUriOnly()
127 128
{
	API_LOCK;
129
	return Utils::cctops(linphone_address_as_string_uri_only(this->address));
130 131
}

132
void Address::Clean()
133 134 135 136 137
{
	API_LOCK;
	linphone_address_clean(this->address);
}

138
Platform::String^ Address::ToString()
139 140 141 142
{
	return this->AsString();
}

143
Address::Address(::LinphoneAddress *addr) :
144 145 146 147 148
	address(addr)
{
	linphone_address_ref(this->address);
}

149
Address::Address(const char *uri)
150 151 152 153 154 155 156
{
	this->address = linphone_address_new(uri);
	if (this->address != nullptr) {
		linphone_address_ref(this->address);
	}
}

157
Address::~Address()
158 159 160 161 162
{
	if (this->address != nullptr) {
		linphone_address_unref(this->address);
	}
}