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 #include "webrtc/libjingle/xmpp/xmppclientsettings.h"
10 // Ideally we shouldn't include anything from talk/p2p, but we need
11 // the definition of ProtocolType. Don't use any functions from
12 // port.h, since it won't link.
13 #include "webrtc/p2p/base/port.h"
17 const uint16 kSslTcpPort
= 443;
19 ConnectionSettings::ConnectionSettings(
20 const rtc::SocketAddress
& server
,
21 SslTcpMode ssltcp_mode
,
22 SslTcpSupport ssltcp_support
)
24 ssltcp_mode(ssltcp_mode
),
25 ssltcp_support(ssltcp_support
) {}
27 ConnectionSettings::ConnectionSettings()
28 : ssltcp_mode(DO_NOT_USE_SSLTCP
),
29 ssltcp_support(DOES_NOT_SUPPORT_SSLTCP
) {}
31 ConnectionSettings::~ConnectionSettings() {}
33 bool ConnectionSettings::Equals(const ConnectionSettings
& settings
) const {
35 server
== settings
.server
&&
36 ssltcp_mode
== settings
.ssltcp_mode
&&
37 ssltcp_support
== settings
.ssltcp_support
;
42 const char* SslTcpModeToString(SslTcpMode ssltcp_mode
) {
43 return (ssltcp_mode
== USE_SSLTCP
) ? "USE_SSLTCP" : "DO_NOT_USE_SSLTCP";
46 const char* SslTcpSupportToString(SslTcpSupport ssltcp_support
) {
48 (ssltcp_support
== SUPPORTS_SSLTCP
) ?
50 "DOES_NOT_SUPPORT_SSLTCP";
55 std::string
ConnectionSettings::ToString() const {
57 server
.ToString() + ":" + SslTcpModeToString(ssltcp_mode
) + ":" +
58 SslTcpSupportToString(ssltcp_support
);
61 void ConnectionSettings::FillXmppClientSettings(
62 buzz::XmppClientSettings
* client_settings
) const {
63 client_settings
->set_protocol(
64 (ssltcp_mode
== USE_SSLTCP
) ?
65 cricket::PROTO_SSLTCP
:
67 client_settings
->set_server(server
);
70 ConnectionSettingsList
MakeConnectionSettingsList(
71 const ServerList
& servers
,
72 bool try_ssltcp_first
) {
73 ConnectionSettingsList settings_list
;
75 for (ServerList::const_iterator it
= servers
.begin();
76 it
!= servers
.end(); ++it
) {
77 const ConnectionSettings
settings(
78 rtc::SocketAddress(it
->server
.host(), it
->server
.port()),
79 DO_NOT_USE_SSLTCP
, it
->ssltcp_support
);
81 if (it
->ssltcp_support
== SUPPORTS_SSLTCP
) {
82 const ConnectionSettings
settings_with_ssltcp(
83 rtc::SocketAddress(it
->server
.host(), kSslTcpPort
),
84 USE_SSLTCP
, it
->ssltcp_support
);
86 if (try_ssltcp_first
) {
87 settings_list
.push_back(settings_with_ssltcp
);
88 settings_list
.push_back(settings
);
90 settings_list
.push_back(settings
);
91 settings_list
.push_back(settings_with_ssltcp
);
94 settings_list
.push_back(settings
);
101 } // namespace notifier