This source file includes following definitions.
- ssltcp_support
- ssltcp_support
- Equals
- SslTcpModeToString
- SslTcpSupportToString
- ToString
- FillXmppClientSettings
- MakeConnectionSettingsList
#include "jingle/notifier/communicator/connection_settings.h"
#include "base/logging.h"
#include "talk/p2p/base/port.h"
#include "talk/xmpp/xmppclientsettings.h"
namespace notifier {
const uint16 kSslTcpPort = 443;
ConnectionSettings::ConnectionSettings(
const talk_base::SocketAddress& server,
SslTcpMode ssltcp_mode,
SslTcpSupport ssltcp_support)
: server(server),
ssltcp_mode(ssltcp_mode),
ssltcp_support(ssltcp_support) {}
ConnectionSettings::ConnectionSettings()
: ssltcp_mode(DO_NOT_USE_SSLTCP),
ssltcp_support(DOES_NOT_SUPPORT_SSLTCP) {}
ConnectionSettings::~ConnectionSettings() {}
bool ConnectionSettings::Equals(const ConnectionSettings& settings) const {
return
server == settings.server &&
ssltcp_mode == settings.ssltcp_mode &&
ssltcp_support == settings.ssltcp_support;
}
namespace {
const char* SslTcpModeToString(SslTcpMode ssltcp_mode) {
return (ssltcp_mode == USE_SSLTCP) ? "USE_SSLTCP" : "DO_NOT_USE_SSLTCP";
}
const char* SslTcpSupportToString(SslTcpSupport ssltcp_support) {
return
(ssltcp_support == SUPPORTS_SSLTCP) ?
"SUPPORTS_SSLTCP" :
"DOES_NOT_SUPPORT_SSLTCP";
}
}
std::string ConnectionSettings::ToString() const {
return
server.ToString() + ":" + SslTcpModeToString(ssltcp_mode) + ":" +
SslTcpSupportToString(ssltcp_support);
}
void ConnectionSettings::FillXmppClientSettings(
buzz::XmppClientSettings* client_settings) const {
client_settings->set_protocol(
(ssltcp_mode == USE_SSLTCP) ?
cricket::PROTO_SSLTCP :
cricket::PROTO_TCP);
client_settings->set_server(server);
}
ConnectionSettingsList MakeConnectionSettingsList(
const ServerList& servers,
bool try_ssltcp_first) {
ConnectionSettingsList settings_list;
for (ServerList::const_iterator it = servers.begin();
it != servers.end(); ++it) {
const ConnectionSettings settings(
talk_base::SocketAddress(it->server.host(), it->server.port()),
DO_NOT_USE_SSLTCP, it->ssltcp_support);
if (it->ssltcp_support == SUPPORTS_SSLTCP) {
const ConnectionSettings settings_with_ssltcp(
talk_base::SocketAddress(it->server.host(), kSslTcpPort),
USE_SSLTCP, it->ssltcp_support);
if (try_ssltcp_first) {
settings_list.push_back(settings_with_ssltcp);
settings_list.push_back(settings);
} else {
settings_list.push_back(settings);
settings_list.push_back(settings_with_ssltcp);
}
} else {
settings_list.push_back(settings);
}
}
return settings_list;
}
}