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.
4
5#include "jingle/notifier/base/notifier_options_util.h"
6
7#include "base/logging.h"
8#include "jingle/notifier/base/const_communicator.h"
9#include "jingle/notifier/base/notifier_options.h"
10#include "talk/xmpp/constants.h"
11#include "talk/xmpp/jid.h"
12
13namespace notifier {
14
15buzz::XmppClientSettings MakeXmppClientSettings(
16    const NotifierOptions& notifier_options,
17    const std::string& email, const std::string& token) {
18  buzz::Jid jid = buzz::Jid(email);
19  DCHECK(!jid.node().empty());
20  DCHECK(jid.IsValid());
21
22  buzz::XmppClientSettings xmpp_client_settings;
23  xmpp_client_settings.set_user(jid.node());
24  xmpp_client_settings.set_resource("chrome-sync");
25  xmpp_client_settings.set_host(jid.domain());
26  xmpp_client_settings.set_use_tls(buzz::TLS_ENABLED);
27  xmpp_client_settings.set_auth_token(notifier_options.auth_mechanism,
28      notifier_options.invalidate_xmpp_login ?
29      token + "bogus" : token);
30  if (notifier_options.auth_mechanism == buzz::AUTH_MECHANISM_OAUTH2)
31    xmpp_client_settings.set_token_service("oauth2");
32  else
33    xmpp_client_settings.set_token_service("chromiumsync");
34  if (notifier_options.allow_insecure_connection) {
35    xmpp_client_settings.set_allow_plain(true);
36    xmpp_client_settings.set_use_tls(buzz::TLS_DISABLED);
37  }
38  return xmpp_client_settings;
39}
40
41ServerList GetServerList(
42    const NotifierOptions& notifier_options) {
43  ServerList servers;
44  // Override the default servers with a test notification server if one was
45  // provided.
46  if (!notifier_options.xmpp_host_port.host().empty()) {
47    servers.push_back(
48        ServerInformation(notifier_options.xmpp_host_port,
49                          DOES_NOT_SUPPORT_SSLTCP));
50  } else {
51    // The default servers support SSLTCP.
52    servers.push_back(
53        ServerInformation(
54            net::HostPortPair("talk.google.com",
55                              notifier::kDefaultXmppPort),
56            SUPPORTS_SSLTCP));
57    servers.push_back(
58        ServerInformation(
59            net::HostPortPair("talkx.l.google.com",
60                              notifier::kDefaultXmppPort),
61            SUPPORTS_SSLTCP));
62  }
63  return servers;
64}
65
66}  // namespace notifier
67