Commit 6a884e2b authored by Matt Tucker's avatar Matt Tucker Committed by matt

Final round of pubsub updates for 2.6.0.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3728 b35dd754-fafc-0310-a699-88a17e54d16e
parent e81d57d2
......@@ -724,7 +724,7 @@ public class NodeSubscription {
* @return true if the published item matches the keyword filter specified in
* the subscription.
*/
private boolean isKeywordMatched(PublishedItem publishedItem) {
boolean isKeywordMatched(PublishedItem publishedItem) {
// Check if keyword was defined and it was not matched
if (keyword != null && keyword.length() > 0 && !publishedItem.containsKeyword(keyword)) {
return false;
......
......@@ -179,7 +179,8 @@ public class PubSubEngine {
String nodeID = action.attributeValue("node");
if (nodeID == null) {
// if user is not sysadmin then return nodeid-required error
if (!service.isServiceAdmin(iq.getFrom())) {
if (!service.isServiceAdmin(iq.getFrom()) ||
!service.isCollectionNodesSupported()) {
// Configure elements must have a node attribute so answer an error
Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
......@@ -321,7 +322,7 @@ public class PubSubEngine {
// No node was specified. Return bad_request error
Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.item_not_found, pubsubError);
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
else {
......@@ -408,7 +409,7 @@ public class PubSubEngine {
// No node was specified. Return bad_request error
Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.item_not_found, pubsubError);
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
else {
......@@ -423,7 +424,6 @@ public class PubSubEngine {
// Get the items to delete
Iterator itemElements = retractElement.elementIterator("item");
if (!itemElements.hasNext()) {
// TODO Confirm that at least one item should be present in the retract element. Waiting for stpeter confirmation.
Element pubsubError = DocumentHelper.createElement(QName.get(
"item-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
......@@ -431,17 +431,21 @@ public class PubSubEngine {
}
if (node.isCollectionNode()) {
// TODO Is this the correct error to return???
// Cannot delete items from a collection node. Return an error.
sendErrorPacket(iq, PacketError.Condition.not_allowed, null);
Element pubsubError = DocumentHelper.createElement(QName.get(
"unsupported", "http://jabber.org/protocol/pubsub#errors"));
pubsubError.addAttribute("feature", "persistent-items");
sendErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError);
return;
}
LeafNode leafNode = (LeafNode) node;
if (!leafNode.isItemRequired()) {
// TODO JEP specifies to return this error if node is not persisting items but this checking makes more sense. Waiting for stpeter confirmation.
// Cannot delete items from a leaf node that doesn't handle itemIDs. Return an error.
sendErrorPacket(iq, PacketError.Condition.not_allowed, null);
Element pubsubError = DocumentHelper.createElement(QName.get(
"unsupported", "http://jabber.org/protocol/pubsub#errors"));
pubsubError.addAttribute("feature", "persistent-items");
sendErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError);
return;
}
......@@ -449,7 +453,6 @@ public class PubSubEngine {
while (itemElements.hasNext()) {
Element itemElement = (Element) itemElements.next();
String itemID = itemElement.attributeValue("id");
// TODO Return an error if no id was specified?
if (itemID != null) {
PublishedItem item = node.getPublishedItem(itemID);
if (item == null) {
......@@ -463,11 +466,18 @@ public class PubSubEngine {
}
else {
// Publisher does not have sufficient privileges to delete this item
sendErrorPacket(iq, PacketError.Condition.not_authorized, null);
sendErrorPacket(iq, PacketError.Condition.forbidden, null);
return;
}
}
}
else {
// No item ID was specified so return a bad_request error
Element pubsubError = DocumentHelper.createElement(QName.get(
"item-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
}
// Send reply with success
router.route(IQ.createResultIQ(iq));
......@@ -479,9 +489,18 @@ public class PubSubEngine {
String nodeID = subscribeElement.attributeValue("node");
Node node;
if (nodeID == null) {
if (service.isCollectionNodesSupported()) {
// Entity subscribes to root collection node
node = service.getRootCollectionNode();
}
else {
// Service does not have a root collection node so return a nodeid-required error
Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
}
else {
// Look for the specified node
node = service.getNode(nodeID);
......@@ -599,9 +618,18 @@ public class PubSubEngine {
String subID = unsubscribeElement.attributeValue("subid");
Node node;
if (nodeID == null) {
if (service.isCollectionNodesSupported()) {
// Entity unsubscribes from root collection node
node = service.getRootCollectionNode();
}
else {
// Service does not have a root collection node so return a nodeid-required error
Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
}
else {
// Look for the specified node
node = service.getNode(nodeID);
......@@ -678,9 +706,18 @@ public class PubSubEngine {
String subID = optionsElement.attributeValue("subid");
Node node;
if (nodeID == null) {
if (service.isCollectionNodesSupported()) {
// Entity requests subscription options of root collection node
node = service.getRootCollectionNode();
}
else {
// Service does not have a root collection node so return a nodeid-required error
Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
}
else {
// Look for the specified node
node = service.getNode(nodeID);
......@@ -750,9 +787,18 @@ public class PubSubEngine {
String subID = optionsElement.attributeValue("subid");
Node node;
if (nodeID == null) {
if (service.isCollectionNodesSupported()) {
// Entity submits new subscription options of root collection node
node = service.getRootCollectionNode();
}
else {
// Service does not have a root collection node so return a nodeid-required error
Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
}
else {
// Look for the specified node
node = service.getNode(nodeID);
......@@ -884,11 +930,14 @@ public class PubSubEngine {
private void getPublishedItems(IQ iq, Element itemsElement) {
String nodeID = itemsElement.attributeValue("node");
//String subID = itemsElement.attributeValue("subid");
String subID = itemsElement.attributeValue("subid");
Node node;
if (nodeID == null) {
// Entity subscribes to root collection node
node = service.getRootCollectionNode();
// User must specify a leaf node ID so return a nodeid-required error
Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
else {
// Look for the specified node
......@@ -925,8 +974,8 @@ public class PubSubEngine {
return;
}
/*// Get the user's subscription
NodeSubscription subscription;
// Get the user's subscription
NodeSubscription subscription = null;
if (node.isMultipleSubscriptionsEnabled()) {
if (subID == null) {
// No subid was specified and the node supports multiple subscriptions
......@@ -945,7 +994,15 @@ public class PubSubEngine {
return;
}
}
}*/
}
if (subscription != null && !subscription.isActive()) {
Element pubsubError = DocumentHelper.createElement(
QName.get("not-subscribed", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.not_authorized, pubsubError);
return;
}
LeafNode leafNode = (LeafNode) node;
// Get list of items to send to the user
......@@ -966,15 +1023,16 @@ public class PubSubEngine {
}
if (max_items != null) {
// Get the N most recent published items
items = leafNode.getPublishedItems(recentItems);
items = new ArrayList<PublishedItem>(leafNode.getPublishedItems(recentItems));
}
else {
List requestedItems = itemsElement.elements("item");
if (requestedItems.isEmpty()) {
// Get all the active items that were published to the node
items = leafNode.getPublishedItems();
items = new ArrayList<PublishedItem>(leafNode.getPublishedItems());
}
else {
items = new ArrayList<PublishedItem>();
// Indicate that payload should be included (if exists) no matter
// the node configuration
forceToIncludePayload = true;
......@@ -989,6 +1047,18 @@ public class PubSubEngine {
}
}
}
if (subscription != null && subscription.getKeyword() != null) {
// Filter items that do not match the subscription keyword
for (Iterator<PublishedItem> it = items.iterator(); it.hasNext();) {
PublishedItem item = it.next();
if (!subscription.isKeywordMatched(item)) {
// Remove item that does not match keyword
it.remove();
}
}
}
// Send items to the user
leafNode.sendPublishedItems(iq, items, forceToIncludePayload);
}
......
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