Commit e596cbfd authored by Dave Cridland's avatar Dave Cridland

Merge pull request #170 from sco0ter/of875

OF-875 Roster requests to bare JID of the user are not responded
parents 6647cf9a b77042e5
...@@ -110,19 +110,18 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider ...@@ -110,19 +110,18 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider
@Override @Override
public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException { public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
try { try {
IQ returnPacket = null; IQ returnPacket;
org.xmpp.packet.Roster roster = (org.xmpp.packet.Roster)packet; org.xmpp.packet.Roster roster = (org.xmpp.packet.Roster)packet;
JID recipientJID = packet.getTo(); JID recipientJID = packet.getTo();
// The packet is bound for the server and must be roster management // The packet is bound for the server and must be roster management
if (recipientJID == null || recipientJID.getNode() == null || if (recipientJID == null || recipientJID.equals(packet.getFrom().asBareJID())) {
!UserManager.getInstance().isRegisteredUser(recipientJID.getNode())) {
returnPacket = manageRoster(roster); returnPacket = manageRoster(roster);
} } else {
// The packet must be a roster removal from a foreign domain user. returnPacket = IQ.createResultIQ(packet);
else { returnPacket.setChildElement(packet.getChildElement().createCopy());
removeRosterItem(roster); returnPacket.setError(PacketError.Condition.service_unavailable);
} }
return returnPacket; return returnPacket;
} }
...@@ -150,37 +149,6 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider ...@@ -150,37 +149,6 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider
} }
} }
/**
* Remove a roster item. At this stage, this is recipient who has received
* a roster update. We must check that it is a removal, and if so, remove
* the roster item based on the sender's id rather than what is in the item
* listing itself.
*
* @param packet The packet suspected of containing a roster removal
*/
private void removeRosterItem(org.xmpp.packet.Roster packet) throws UnauthorizedException,
SharedGroupException {
JID recipientJID = packet.getTo();
JID senderJID = packet.getFrom();
try {
for (org.xmpp.packet.Roster.Item packetItem : packet.getItems()) {
if (packetItem.getSubscription() == org.xmpp.packet.Roster.Subscription.remove) {
Roster roster = userManager.getUser(recipientJID.getNode()).getRoster();
RosterItem item = roster.getRosterItem(senderJID);
roster.deleteRosterItem(senderJID, true);
item.setSubStatus(RosterItem.SUB_REMOVE);
item.setSubStatus(RosterItem.SUB_NONE);
Packet itemPacket = packet.createCopy();
sessionManager.userBroadcast(recipientJID.getNode(), itemPacket);
}
}
}
catch (UserNotFoundException e) {
throw new UnauthorizedException(e);
}
}
/** /**
* The packet is a typical 'set' or 'get' update targeted at the server. * The packet is a typical 'set' or 'get' update targeted at the server.
* Notice that the set could be a roster removal in which case we have to * Notice that the set could be a roster removal in which case we have to
...@@ -333,6 +301,7 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider ...@@ -333,6 +301,7 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider
return info; return info;
} }
@Override
public Iterator<String> getFeatures() { public Iterator<String> getFeatures() {
ArrayList<String> features = new ArrayList<String>(); ArrayList<String> features = new ArrayList<String>();
features.add("jabber:iq:roster"); features.add("jabber:iq:roster");
......
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