Commit 00c7fd43 authored by Armando Jagucki's avatar Armando Jagucki Committed by ajagucki

Increased readability in IQPEPHandler.handleIQ().

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@9244 b35dd754-fafc-0310-a699-88a17e54d16e
parent b3a70feb
...@@ -239,74 +239,75 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -239,74 +239,75 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
@Override @Override
public IQ handleIQ(IQ packet) throws UnauthorizedException { public IQ handleIQ(IQ packet) throws UnauthorizedException {
JID senderJID = packet.getFrom(); JID senderJID = packet.getFrom();
if (packet.getTo() == null && packet.getType() == IQ.Type.set) { if (packet.getTo() == null) {
String jidFrom = senderJID.toBareJID(); if (packet.getType() == IQ.Type.set) {
String jidFrom = senderJID.toBareJID();
PEPService pepService = getPEPService(jidFrom);
PEPService pepService = getPEPService(jidFrom);
// If no service exists yet for jidFrom, create one.
if (pepService == null) { // If no service exists yet for jidFrom, create one.
// Return an error if the packet is from an anonymous, unregistered user if (pepService == null) {
// or remote user // Return an error if the packet is from an anonymous, unregistered user
if (!XMPPServer.getInstance().isLocal(senderJID) || // or remote user
!UserManager.getInstance().isRegisteredUser(senderJID.getNode())) { if (!XMPPServer.getInstance().isLocal(senderJID) ||
IQ reply = IQ.createResultIQ(packet); !UserManager.getInstance().isRegisteredUser(senderJID.getNode())) {
reply.setChildElement(packet.getChildElement().createCopy()); IQ reply = IQ.createResultIQ(packet);
reply.setError(PacketError.Condition.not_allowed); reply.setChildElement(packet.getChildElement().createCopy());
return reply; reply.setError(PacketError.Condition.not_allowed);
} return reply;
}
pepService = new PEPService(XMPPServer.getInstance(), jidFrom);
pepServices.put(jidFrom, pepService); pepService = new PEPService(XMPPServer.getInstance(), jidFrom);
pepServices.put(jidFrom, pepService);
// Probe presences
pubSubEngine.start(pepService); // Probe presences
if (Log.isDebugEnabled()) { pubSubEngine.start(pepService);
Log.debug("PEP: " + jidFrom + " had a PEPService created"); if (Log.isDebugEnabled()) {
} Log.debug("PEP: " + jidFrom + " had a PEPService created");
}
// Those who already have presence subscriptions to jidFrom
// will now automatically be subscribed to this new PEPService. // Those who already have presence subscriptions to jidFrom
try { // will now automatically be subscribed to this new PEPService.
Roster roster = XMPPServer.getInstance().getRosterManager().getRoster(senderJID.getNode()); try {
for (RosterItem item : roster.getRosterItems()) { Roster roster = XMPPServer.getInstance().getRosterManager().getRoster(senderJID.getNode());
if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM) { for (RosterItem item : roster.getRosterItems()) {
createSubscriptionToPEPService(pepService, item.getJid(), senderJID); if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM) {
createSubscriptionToPEPService(pepService, item.getJid(), senderJID);
}
} }
} }
catch (UserNotFoundException e) {
// Do nothing
}
} }
catch (UserNotFoundException e) {
// Do nothing // If publishing a node, and the node doesn't exist, create it.
} Element childElement = packet.getChildElement();
} Element publishElement = childElement.element("publish");
if (publishElement != null) {
// If publishing a node, and the node doesn't exist, create it. String nodeID = publishElement.attributeValue("node");
Element childElement = packet.getChildElement();
Element publishElement = childElement.element("publish"); // Do not allow User Avatar nodes to be created.
if (publishElement != null) { // TODO: Implement XEP-0084
String nodeID = publishElement.attributeValue("node"); if (nodeID.startsWith("http://www.xmpp.org/extensions/xep-0084.html")) {
IQ reply = IQ.createResultIQ(packet);
// Do not allow User Avatar nodes to be created. reply.setChildElement(packet.getChildElement().createCopy());
// TODO: Implement XEP-0084 reply.setError(PacketError.Condition.feature_not_implemented);
if (nodeID.startsWith("http://www.xmpp.org/extensions/xep-0084.html")) { return reply;
IQ reply = IQ.createResultIQ(packet); }
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.feature_not_implemented); if (pepService.getNode(nodeID) == null) {
return reply; // Create the node
} JID creator = new JID(jidFrom);
LeafNode newNode = new LeafNode(pepService, pepService.getRootCollectionNode(), nodeID, creator);
if (pepService.getNode(nodeID) == null) { newNode.addOwner(creator);
// Create the node newNode.saveToDB();
JID creator = new JID(jidFrom); }
LeafNode newNode = new LeafNode(pepService, pepService.getRootCollectionNode(), nodeID, creator);
newNode.addOwner(creator);
newNode.saveToDB();
} }
// Process with PubSub as usual.
pubSubEngine.process(pepService, packet);
} }
// Process with PubSub as usual.
pubSubEngine.process(pepService, packet);
} }
else if (packet.getType() == IQ.Type.get || packet.getType() == IQ.Type.set) { else if (packet.getType() == IQ.Type.get || packet.getType() == IQ.Type.set) {
String jidTo = packet.getTo().toBareJID(); String jidTo = packet.getTo().toBareJID();
...@@ -319,8 +320,8 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -319,8 +320,8 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
else { else {
// Process with PubSub using a dummyService. In the case where an IQ packet is sent to // Process with PubSub using a dummyService. In the case where an IQ packet is sent to
// a user who does not have a PEP service, we wish to utilize the error reporting flow // a user who does not have a PEP service, we wish to utilize the error reporting flow
// already present in the PubSubEngine. Hence, the sole purpose of the dummyService is // already present in the PubSubEngine. This gives the illusion that every user has a
// to forward this ill formed IQ packet to the PubSubEngine and trigger the correct error. // PEP service, as required by the specification.
PEPService dummyService = new PEPService(XMPPServer.getInstance(), senderJID.toBareJID()); PEPService dummyService = new PEPService(XMPPServer.getInstance(), senderJID.toBareJID());
pubSubEngine.process(dummyService, packet); pubSubEngine.process(dummyService, packet);
} }
...@@ -331,7 +332,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -331,7 +332,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
return null; return null;
} }
// Other error flows are handled in pubSubEngine.process(...) // Other error flows were handled in pubSubEngine.process(...)
return null; return null;
} }
......
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