summaryrefslogtreecommitdiffstats
path: root/jingle
diff options
context:
space:
mode:
Diffstat (limited to 'jingle')
-rw-r--r--jingle/notifier/listener/push_notifications_listen_task.cc51
-rw-r--r--jingle/notifier/listener/push_notifications_send_update_task.cc11
-rw-r--r--jingle/notifier/listener/push_notifications_send_update_task_unittest.cc2
3 files changed, 32 insertions, 32 deletions
diff --git a/jingle/notifier/listener/push_notifications_listen_task.cc b/jingle/notifier/listener/push_notifications_listen_task.cc
index 8617f84..328bbe2 100644
--- a/jingle/notifier/listener/push_notifications_listen_task.cc
+++ b/jingle/notifier/listener/push_notifications_listen_task.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -29,16 +29,17 @@ PushNotificationsListenTask::~PushNotificationsListenTask() {
}
int PushNotificationsListenTask::ProcessStart() {
- VLOG(1) << "Push notifications: Listener task started.";
return STATE_RESPONSE;
}
int PushNotificationsListenTask::ProcessResponse() {
- VLOG(1) << "Push notifications: Listener response received.";
const buzz::XmlElement* stanza = NextStanza();
if (stanza == NULL) {
return STATE_BLOCKED;
}
+
+ VLOG(1) << "Received stanza " << XmlElementToString(*stanza);
+
// The push notifications service does not need us to acknowledge receipt of
// the notification to the buzz server.
@@ -46,36 +47,41 @@ int PushNotificationsListenTask::ProcessResponse() {
// Extract the service URL and service-specific data from the stanza.
// Note that we treat the channel name as service URL.
// The response stanza has the following format.
- // <message from=�someservice.google.com� to={full_jid}>
- // <push xmlns=�google:push� channel={channel name}>
- // <recipient to={bare_jid}>{base-64 encoded data}</recipient>
- // <data>{base-64 data}</data>
+ // <message from="{url or bare jid}" to={full jid}>
+ // <push xmlns="google:push" channel={channel name}>
+ // <recipient to={bare jid}>{base-64 encoded data}</recipient>
+ // <data>{base-64 encoded data}</data>
// </push>
// </message>
- const buzz::XmlElement* push_element =
- stanza->FirstNamed(buzz::QName(kPushNotificationsNamespace, "push"));
+ const buzz::QName kQnPush(kPushNotificationsNamespace, "push");
+ const buzz::QName kQnChannel(buzz::STR_EMPTY, "channel");
+ const buzz::QName kQnData(kPushNotificationsNamespace, "data");
+
+ const buzz::XmlElement* push_element = stanza->FirstNamed(kQnPush);
if (push_element) {
Notification notification;
- notification.channel =
- push_element->Attr(buzz::QName(buzz::STR_EMPTY, "channel"));
- const buzz::XmlElement* data_element = push_element->FirstNamed(
- buzz::QName(kPushNotificationsNamespace, "data"));
+ notification.channel = push_element->Attr(kQnChannel);
+ const buzz::XmlElement* data_element = push_element->FirstNamed(kQnData);
if (data_element) {
- base::Base64Decode(data_element->BodyText(),
- &notification.data);
+ const std::string& base64_encoded_data = data_element->BodyText();
+ if (!base::Base64Decode(base64_encoded_data, &notification.data)) {
+ LOG(WARNING) << "Could not base64-decode " << base64_encoded_data;
+ }
+ } else {
+ LOG(WARNING) << "No data element found in push element "
+ << XmlElementToString(*push_element);
}
+ VLOG(1) << "Received notification " << notification.ToString();
delegate_->OnNotificationReceived(notification);
} else {
- LOG(WARNING) <<
- "Push notifications: No push element found in response stanza";
+ LOG(WARNING) << "No push element found in stanza "
+ << XmlElementToString(*stanza);
}
return STATE_RESPONSE;
}
bool PushNotificationsListenTask::HandleStanza(const buzz::XmlElement* stanza) {
- VLOG(1) << "Push notifications: Stanza received: "
- << XmlElementToString(*stanza);
if (IsValidNotification(stanza)) {
QueueStanza(stanza);
return true;
@@ -85,13 +91,6 @@ bool PushNotificationsListenTask::HandleStanza(const buzz::XmlElement* stanza) {
bool PushNotificationsListenTask::IsValidNotification(
const buzz::XmlElement* stanza) {
- // An update notification has the following form.
- // <message from=�someservice.google.com� to={full_jid}>
- // <push xmlns=�google:push� channel={channel name}>
- // <recipient to={bare_jid}>{base-64 encoded data}</recipient>
- // <data>{base-64 data}</data>
- // </push>
- // </message>
// We don't do much validation here, just check if the stanza is a message
// stanza.
return (stanza->Name() == buzz::QN_MESSAGE);
diff --git a/jingle/notifier/listener/push_notifications_send_update_task.cc b/jingle/notifier/listener/push_notifications_send_update_task.cc
index 3e05a31..5cef1b5 100644
--- a/jingle/notifier/listener/push_notifications_send_update_task.cc
+++ b/jingle/notifier/listener/push_notifications_send_update_task.cc
@@ -29,9 +29,10 @@ int PushNotificationsSendUpdateTask::ProcessStart() {
scoped_ptr<buzz::XmlElement> stanza(
MakeUpdateMessage(notification_,
GetClient()->jid().BareJid()));
- VLOG(1) << "P2P: Sending notification: " << XmlElementToString(*stanza);
+ VLOG(1) << "Sending notification " << notification_.ToString()
+ << " as stanza " << XmlElementToString(*stanza);
if (SendStanza(stanza.get()) != buzz::XMPP_RETURN_OK) {
- LOG(WARNING) << "Could not send: " << XmlElementToString(*stanza);
+ LOG(WARNING) << "Could not send stanza " << XmlElementToString(*stanza);
}
return STATE_DONE;
}
@@ -42,10 +43,10 @@ buzz::XmlElement* PushNotificationsSendUpdateTask::MakeUpdateMessage(
DCHECK(to_jid_bare.IsBare());
const buzz::QName kQnPush(kPushNotificationsNamespace, "push");
const buzz::QName kQnChannel(buzz::STR_EMPTY, "channel");
- const buzz::QName kQnData(buzz::STR_EMPTY, "data");
+ const buzz::QName kQnData(kPushNotificationsNamespace, "data");
// Create our update stanza. The message is constructed as:
- // <message from='{fullJid}' to='{bareJid}' type='headline'>
+ // <message from='{full jid}' to='{bare jid}' type='headline'>
// <push xmlns='google:push' channel='{channel}'>
// <data>{base-64 encoded data}</data>
// </push>
@@ -62,7 +63,7 @@ buzz::XmlElement* PushNotificationsSendUpdateTask::MakeUpdateMessage(
buzz::XmlElement* data = new buzz::XmlElement(kQnData, true);
std::string base64_data;
if (!base::Base64Encode(notification.data, &base64_data)) {
- LOG(WARNING) << "Could not encode data: " << notification.data;
+ LOG(WARNING) << "Could not encode data " << notification.data;
}
data->SetBodyText(base64_data);
push->AddElement(data);
diff --git a/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc b/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc
index 811b888..3fa424ee 100644
--- a/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc
+++ b/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc
@@ -47,7 +47,7 @@ TEST_F(PushNotificationsSendUpdateTaskTest, MakeUpdateMessage) {
"<cli:message to=\"%s\" type=\"headline\" "
"xmlns:cli=\"jabber:client\">"
"<push xmlns=\"google:push\" channel=\"%s\">"
- "<data xmlns=\"\">%s</data>"
+ "<data xmlns=\"google:push\">%s</data>"
"</push>"
"</cli:message>",
to_jid_bare_.Str().c_str(), notification.channel.c_str(),