1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "jingle/notifier/communicator/connection_settings.h"
7 #include "base/logging.h"
9 // Ideally we shouldn't include anything from talk/p2p, but we need
10 // the definition of ProtocolType. Don't use any functions from
11 // port.h, since it won't link.
12 #include "talk/p2p/base/port.h"
14 #include "talk/xmpp/xmppclientsettings.h"
18 const uint16 kSslTcpPort
= 443;
20 ConnectionSettings::ConnectionSettings(
21 const rtc::SocketAddress
& server
,
22 SslTcpMode ssltcp_mode
,
23 SslTcpSupport ssltcp_support
)
25 ssltcp_mode(ssltcp_mode
),
26 ssltcp_support(ssltcp_support
) {}
28 ConnectionSettings::ConnectionSettings()
29 : ssltcp_mode(DO_NOT_USE_SSLTCP
),
30 ssltcp_support(DOES_NOT_SUPPORT_SSLTCP
) {}
32 ConnectionSettings::~ConnectionSettings() {}
34 bool ConnectionSettings::Equals(const ConnectionSettings
& settings
) const {
36 server
== settings
.server
&&
37 ssltcp_mode
== settings
.ssltcp_mode
&&
38 ssltcp_support
== settings
.ssltcp_support
;
43 const char* SslTcpModeToString(SslTcpMode ssltcp_mode
) {
44 return (ssltcp_mode
== USE_SSLTCP
) ? "USE_SSLTCP" : "DO_NOT_USE_SSLTCP";
47 const char* SslTcpSupportToString(SslTcpSupport ssltcp_support
) {
49 (ssltcp_support
== SUPPORTS_SSLTCP
) ?
51 "DOES_NOT_SUPPORT_SSLTCP";
56 std::string
ConnectionSettings::ToString() const {
58 server
.ToString() + ":" + SslTcpModeToString(ssltcp_mode
) + ":" +
59 SslTcpSupportToString(ssltcp_support
);
62 void ConnectionSettings::FillXmppClientSettings(
63 buzz::XmppClientSettings
* client_settings
) const {
64 client_settings
->set_protocol(
65 (ssltcp_mode
== USE_SSLTCP
) ?
66 cricket::PROTO_SSLTCP
:
68 client_settings
->set_server(server
);
71 ConnectionSettingsList
MakeConnectionSettingsList(
72 const ServerList
& servers
,
73 bool try_ssltcp_first
) {
74 ConnectionSettingsList settings_list
;
76 for (ServerList::const_iterator it
= servers
.begin();
77 it
!= servers
.end(); ++it
) {
78 const ConnectionSettings
settings(
79 rtc::SocketAddress(it
->server
.host(), it
->server
.port()),
80 DO_NOT_USE_SSLTCP
, it
->ssltcp_support
);
82 if (it
->ssltcp_support
== SUPPORTS_SSLTCP
) {
83 const ConnectionSettings
settings_with_ssltcp(
84 rtc::SocketAddress(it
->server
.host(), kSslTcpPort
),
85 USE_SSLTCP
, it
->ssltcp_support
);
87 if (try_ssltcp_first
) {
88 settings_list
.push_back(settings_with_ssltcp
);
89 settings_list
.push_back(settings
);
91 settings_list
.push_back(settings
);
92 settings_list
.push_back(settings_with_ssltcp
);
95 settings_list
.push_back(settings
);
102 } // namespace notifier