diff options
author | Vitaly Buka <vitalybuka@google.com> | 2016-02-04 15:42:04 -0800 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2016-02-05 17:58:53 +0000 |
commit | 3b8fbc546262ac5335e9ddfd219c195b224a4427 (patch) | |
tree | 51c5c53ae18af9fda1ca151fb1479dd4e6a076e6 /src/notification | |
parent | 15888c7a2f77789961eb613de0d775bdf761aceb (diff) | |
download | libweave-3b8fbc546262ac5335e9ddfd219c195b224a4427.tar.gz |
Add customizable settings option for xmpp_endpoint
BUG:26525138
Change-Id: I8b198c5d7b29fdc11940443710c64731b1025066
Reviewed-on: https://weave-review.googlesource.com/2487
Reviewed-by: Alex Vakulenko <avakulenko@google.com>
Diffstat (limited to 'src/notification')
-rw-r--r-- | src/notification/xmpp_channel.cc | 19 | ||||
-rw-r--r-- | src/notification/xmpp_channel.h | 10 | ||||
-rw-r--r-- | src/notification/xmpp_channel_unittest.cc | 6 |
3 files changed, 24 insertions, 11 deletions
diff --git a/src/notification/xmpp_channel.cc b/src/notification/xmpp_channel.cc index ceb45ed..f9d7924 100644 --- a/src/notification/xmpp_channel.cc +++ b/src/notification/xmpp_channel.cc @@ -7,6 +7,7 @@ #include <string> #include <base/bind.h> +#include <base/strings/string_number_conversions.h> #include <weave/provider/network.h> #include <weave/provider/task_runner.h> @@ -16,6 +17,7 @@ #include "src/notification/notification_parser.h" #include "src/notification/xml_node.h" #include "src/privet/openssl_utils.h" +#include "src/string_utils.h" #include "src/utils.h" namespace weave { @@ -74,9 +76,6 @@ const BackoffEntry::Policy kDefaultBackoffPolicy = { false, }; -const char kDefaultXmppHost[] = "talk.google.com"; -const uint16_t kDefaultXmppPort = 5223; - // Used for keeping connection alive. const int kRegularPingIntervalSeconds = 60; const int kRegularPingTimeoutSeconds = 30; @@ -91,10 +90,12 @@ const int kConnectingTimeoutAfterNetChangeSeconds = 30; XmppChannel::XmppChannel(const std::string& account, const std::string& access_token, + const std::string& xmpp_endpoint, provider::TaskRunner* task_runner, provider::Network* network) : account_{account}, access_token_{access_token}, + xmpp_endpoint_{xmpp_endpoint}, network_{network}, backoff_entry_{&kDefaultBackoffPolicy}, task_runner_{task_runner}, @@ -285,10 +286,16 @@ void XmppChannel::HandleMessageStanza(std::unique_ptr<XmlNode> stanza) { void XmppChannel::CreateSslSocket() { CHECK(!stream_); state_ = XmppState::kConnecting; - LOG(INFO) << "Starting XMPP connection to " << kDefaultXmppHost << ":" - << kDefaultXmppPort; + LOG(INFO) << "Starting XMPP connection to: " << xmpp_endpoint_; + + std::pair<std::string, std::string> host_port = + SplitAtFirst(xmpp_endpoint_, ":", true); + CHECK(!host_port.first.empty()); + CHECK(!host_port.second.empty()); + uint32_t port = 0; + CHECK(base::StringToUint(host_port.second, &port)) << xmpp_endpoint_; - network_->OpenSslSocket(kDefaultXmppHost, kDefaultXmppPort, + network_->OpenSslSocket(host_port.first, port, base::Bind(&XmppChannel::OnSslSocketReady, task_ptr_factory_.GetWeakPtr())); } diff --git a/src/notification/xmpp_channel.h b/src/notification/xmpp_channel.h index 50e84d2..b0a4468 100644 --- a/src/notification/xmpp_channel.h +++ b/src/notification/xmpp_channel.h @@ -45,6 +45,7 @@ class XmppChannel : public NotificationChannel, // so you will need to reset the XmppClient every time this happens. XmppChannel(const std::string& account, const std::string& access_token, + const std::string& xmpp_endpoint, provider::TaskRunner* task_runner, provider::Network* network); ~XmppChannel() override = default; @@ -124,12 +125,15 @@ class XmppChannel : public NotificationChannel, // Robot account name for the device. std::string account_; - // Full JID of this device. - std::string jid_; - // OAuth access token for the account. Expires fairly frequently. std::string access_token_; + // Xmpp endpoint. + std::string xmpp_endpoint_; + + // Full JID of this device. + std::string jid_; + provider::Network* network_{nullptr}; std::unique_ptr<Stream> stream_; diff --git a/src/notification/xmpp_channel_unittest.cc b/src/notification/xmpp_channel_unittest.cc index 674fe22..dfa2a79 100644 --- a/src/notification/xmpp_channel_unittest.cc +++ b/src/notification/xmpp_channel_unittest.cc @@ -26,6 +26,7 @@ namespace { constexpr char kAccountName[] = "Account@Name"; constexpr char kAccessToken[] = "AccessToken"; +constexpr char kEndpoint[] = "endpoint:456"; constexpr char kStartStreamMessage[] = "<stream:stream to='clouddevices.gserviceaccount.com' " @@ -84,7 +85,8 @@ class FakeXmppChannel : public XmppChannel { public: explicit FakeXmppChannel(provider::TaskRunner* task_runner, provider::Network* network) - : XmppChannel{kAccountName, kAccessToken, task_runner, network}, + : XmppChannel{kAccountName, kAccessToken, kEndpoint, task_runner, + network}, stream_{new test::FakeStream{task_runner_}}, fake_stream_{stream_.get()} {} @@ -122,7 +124,7 @@ class MockNetwork : public provider::test::MockNetwork { class XmppChannelTest : public ::testing::Test { protected: XmppChannelTest() { - EXPECT_CALL(network_, OpenSslSocket("talk.google.com", 5223, _)) + EXPECT_CALL(network_, OpenSslSocket("endpoint", 456, _)) .WillOnce( WithArgs<2>(Invoke(&xmpp_client_, &FakeXmppChannel::Connect))); } |