summaryrefslogtreecommitdiffstats
path: root/jingle/notifier/base/notifier_options_util.cc
blob: a8615b1a65a1cb6bfec706ab2dbbf29dae83f240 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "jingle/notifier/base/notifier_options_util.h"

#include "base/logging.h"
#include "jingle/notifier/base/const_communicator.h"
#include "jingle/notifier/base/notifier_options.h"
#include "webrtc/libjingle/xmpp/constants.h"
#include "webrtc/libjingle/xmpp/jid.h"

namespace notifier {

buzz::XmppClientSettings MakeXmppClientSettings(
    const NotifierOptions& notifier_options,
    const std::string& email, const std::string& token) {
  buzz::Jid jid = buzz::Jid(email);
  DCHECK(!jid.node().empty());
  DCHECK(jid.IsValid());

  buzz::XmppClientSettings xmpp_client_settings;
  xmpp_client_settings.set_user(jid.node());
  xmpp_client_settings.set_resource("chrome-sync");
  xmpp_client_settings.set_host(jid.domain());
  xmpp_client_settings.set_use_tls(buzz::TLS_REQUIRED);
  xmpp_client_settings.set_auth_token(notifier_options.auth_mechanism,
      notifier_options.invalidate_xmpp_login ?
      token + "bogus" : token);
  if (notifier_options.auth_mechanism == buzz::AUTH_MECHANISM_OAUTH2)
    xmpp_client_settings.set_token_service("oauth2");
  else
    xmpp_client_settings.set_token_service("chromiumsync");
  if (notifier_options.allow_insecure_connection) {
    xmpp_client_settings.set_allow_plain(true);
    xmpp_client_settings.set_use_tls(buzz::TLS_DISABLED);
  }
  return xmpp_client_settings;
}

ServerList GetServerList(
    const NotifierOptions& notifier_options) {
  ServerList servers;
  // Override the default servers with a test notification server if one was
  // provided.
  if (!notifier_options.xmpp_host_port.host().empty()) {
    servers.push_back(
        ServerInformation(notifier_options.xmpp_host_port,
                          DOES_NOT_SUPPORT_SSLTCP));
  } else {
    // The default servers support SSLTCP.
    servers.push_back(
        ServerInformation(
            net::HostPortPair("talk.google.com",
                              notifier::kDefaultXmppPort),
            SUPPORTS_SSLTCP));
    servers.push_back(
        ServerInformation(
            net::HostPortPair("talkx.l.google.com",
                              notifier::kDefaultXmppPort),
            SUPPORTS_SSLTCP));
  }
  return servers;
}

}  // namespace notifier