Commit dc13563e authored by Armando Jagucki's avatar Armando Jagucki Committed by ajagucki

PEP: A cleaner cleaner solution to the retract bug that revision 8903 fixed.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches@8904 b35dd754-fafc-0310-a699-88a17e54d16e
parent ae822683
...@@ -349,49 +349,35 @@ public class PEPService implements PubSubService { ...@@ -349,49 +349,35 @@ public class PEPService implements PubSubService {
} }
for (JID recipientFullJID : recipientFullJIDs) { for (JID recipientFullJID : recipientFullJIDs) {
message.setTo(recipientFullJID);
// Include an Extended Stanza Addressing "replyto" extension specifying the publishing // Include an Extended Stanza Addressing "replyto" extension specifying the publishing
// resource. However, only include the extension if the receiver has a presence subscription // resource. However, only include the extension if the receiver has a presence subscription
// to the service owner. // to the service owner.
try { try {
JID publisher = null; JID publisher = null;
// Get the nodeIDPublishedTo // Get the ID of the node that had an item published to or retracted from.
Element eventElement = message.getElement().element("event"); Element itemsElement = message.getElement().element("event").element("items");
if (eventElement == null) { String nodeID = itemsElement.attributeValue("node");
router.route(message);
continue; // Get the ID of the item that was published or retracted.
}
Element itemsElement = eventElement.element("items");
if (itemsElement == null) {
router.route(message);
continue;
}
String nodeIDPublishedTo = itemsElement.attributeValue("node");
// Get the itemID
String itemID = null; String itemID = null;
Element retractElement = itemsElement.element("retract"); Element itemElement = itemsElement.element("item");
if (retractElement == null) { if (itemElement == null) {
Element itemElement = itemsElement.element("item"); Element retractElement = itemsElement.element("retract");
if (itemElement == null) { if (retractElement != null) {
router.route(message); itemID = retractElement.attributeValue("id");
continue;
} }
itemID = itemElement.attributeValue("id");
} }
else { else {
itemID = retractElement.attributeValue("id"); itemID = itemElement.attributeValue("id");
} }
// Check if the recipientFullJID is interested in notifications for this node. // Check if the recipientFullJID is interested in notifications for this node.
// If the recipient has not yet requested any notification filtering, continue and send // If the recipient has not yet requested any notification filtering, continue and send
// the notification. // the notification.
Map<String, HashSet<String>> filteredNodesMap = XMPPServer.getInstance().getIQPEPHandler().getFilteredNodesMap(); Map<String, HashSet<String>> filteredNodesMap = XMPPServer.getInstance().getIQPEPHandler().getFilteredNodesMap();
HashSet<String> filteredNodesSet = filteredNodesMap.get(recipientFullJID.toString()); HashSet<String> filteredNodesSet = filteredNodesMap.get(recipientFullJID.toString());
if (filteredNodesSet != null && !filteredNodesSet.contains(nodeIDPublishedTo + "+notify")) { if (filteredNodesSet != null && !filteredNodesSet.contains(nodeID + "+notify")) {
return; return;
} }
...@@ -399,15 +385,8 @@ public class PEPService implements PubSubService { ...@@ -399,15 +385,8 @@ public class PEPService implements PubSubService {
// This full JID will be used as the "replyto" address in the addressing extension. // This full JID will be used as the "replyto" address in the addressing extension.
if (node.isCollectionNode()) { if (node.isCollectionNode()) {
for (Node leafNode : node.getNodes()) { for (Node leafNode : node.getNodes()) {
if (leafNode.getNodeID().equals(nodeIDPublishedTo)) { if (leafNode.getNodeID().equals(nodeID)) {
PublishedItem publishedItem = leafNode.getPublishedItem(itemID); publisher = leafNode.getPublishedItem(itemID).getPublisher();
if (publishedItem != null) {
publisher = publishedItem.getPublisher();
}
else {
router.route(message);
break;
}
// Ensure the recipientJID has access to receive notifications for items published to the leaf node. // Ensure the recipientJID has access to receive notifications for items published to the leaf node.
AccessModel accessModel = leafNode.getAccessModel(); AccessModel accessModel = leafNode.getAccessModel();
...@@ -418,26 +397,13 @@ public class PEPService implements PubSubService { ...@@ -418,26 +397,13 @@ public class PEPService implements PubSubService {
break; break;
} }
} }
if (publisher == null) {
continue;
}
} }
else { else {
PublishedItem publishedItem = node.getPublishedItem(itemID); publisher = node.getPublishedItem(itemID).getPublisher();
if (publishedItem != null) {
publisher = publishedItem.getPublisher();
}
else {
router.route(message);
continue;
}
} }
// Ensure the recipient is subscribed to the service owner's (publisher's) presence. // Ensure the recipient is subscribed to the service owner's (publisher's) presence.
Roster roster = XMPPServer.getInstance().getRosterManager().getRoster(publisher.getNode()); if (canProbePresence(publisher, recipientFullJID)) {
RosterItem item = roster.getRosterItem(recipientFullJID);
if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM) {
Element addresses = DocumentHelper.createElement(QName.get("addresses", "http://jabber.org/protocol/address")); Element addresses = DocumentHelper.createElement(QName.get("addresses", "http://jabber.org/protocol/address"));
Element address = addresses.addElement("address"); Element address = addresses.addElement("address");
address.addAttribute("type", "replyto"); address.addAttribute("type", "replyto");
...@@ -446,6 +412,7 @@ public class PEPService implements PubSubService { ...@@ -446,6 +412,7 @@ public class PEPService implements PubSubService {
Message extendedMessage = message.createCopy(); Message extendedMessage = message.createCopy();
extendedMessage.addExtension(new PacketExtension(addresses)); extendedMessage.addExtension(new PacketExtension(addresses));
extendedMessage.setTo(recipientFullJID);
router.route(extendedMessage); router.route(extendedMessage);
} }
} }
...@@ -454,12 +421,18 @@ public class PEPService implements PubSubService { ...@@ -454,12 +421,18 @@ public class PEPService implements PubSubService {
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
// Do not add addressing extension to message. // Do not add addressing extension to message.
message.setTo(recipientJID);
router.route(message); router.route(message);
break;
} }
catch (NullPointerException e) { catch (NullPointerException e) {
// Do not add addressing extension to message. try {
if (canProbePresence(getAddress(), recipientFullJID)) {
message.setTo(recipientFullJID);
}
}
catch (UserNotFoundException e1) {
// Do nothing
}
router.route(message);
} }
} }
} }
...@@ -553,5 +526,26 @@ public class PEPService implements PubSubService { ...@@ -553,5 +526,26 @@ public class PEPService implements PubSubService {
// Send the event notification to the subscriber // Send the event notification to the subscriber
this.sendNotification(subscription.getNode(), notification, subscription.getJID()); this.sendNotification(subscription.getNode(), notification, subscription.getJID());
} }
/**
* Returns true if the the prober is allowed to see the presence of the probee.
*
* @param prober the user that is trying to probe the presence of another user.
* @param probee the username of the uset that is being probed.
* @return true if the the prober is allowed to see the presence of the probee.
* @throws UserNotFoundException If the probee does not exist in the local server or the prober
* is not present in the roster of the probee.
*/
private boolean canProbePresence(JID prober, JID probee) throws UserNotFoundException {
Roster roster;
roster = XMPPServer.getInstance().getRosterManager().getRoster(prober.getNode());
RosterItem item = roster.getRosterItem(probee);
if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM) {
return true;
}
return false;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment