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
@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
try {
IQ returnPacket = null;
IQ returnPacket;
org.xmpp.packet.Roster roster = (org.xmpp.packet.Roster)packet;
JID recipientJID = packet.getTo();
// The packet is bound for the server and must be roster management
if (recipientJID == null || recipientJID.getNode() == null ||
!UserManager.getInstance().isRegisteredUser(recipientJID.getNode())) {
if (recipientJID == null || recipientJID.equals(packet.getFrom().asBareJID())) {
returnPacket = manageRoster(roster);
}
// The packet must be a roster removal from a foreign domain user.
else {
removeRosterItem(roster);
} else {
returnPacket = IQ.createResultIQ(packet);
returnPacket.setChildElement(packet.getChildElement().createCopy());
returnPacket.setError(PacketError.Condition.service_unavailable);
}
return returnPacket;
}
......@@ -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.
* 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
return info;
}
@Override
public Iterator<String> getFeatures() {
ArrayList<String> features = new ArrayList<String>();
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