public void process(Presence packet) { // Ignore unavailable presences if (Presence.Type.unavailable == packet.getType()) { return; } // Examine the packet and check if it has caps info, // if not -- do nothing by returning. Element capsElement = packet.getChildElement("c", "http://jabber.org/protocol/caps"); if (capsElement == null) { return; } // Examine the packet and check if it's in legacy format (pre version 1.4 // of XEP-0115). If so, do nothing by returning. // TODO: if this packet is in legacy format, we SHOULD check the 'node', // 'ver', and 'ext' combinations as specified in the archived version // 1.3 of the specification, and cache the results. See JM-1447 final String hashAttribute = capsElement.attributeValue("hash"); if (hashAttribute == null || hashAttribute.trim().length() == 0) { return; } // Examine the packet and check if it has and a 'ver' hash // if not -- do nothing by returning. final String newVerAttribute = capsElement.attributeValue("ver"); if (newVerAttribute == null || newVerAttribute.trim().length() == 0) { return; } // Check to see if the 'ver' hash is already in our cache. if (isInCapsCache(newVerAttribute)) { // The 'ver' hash is in the cache already, so let's update the // entityCapabilitiesUserMap for the user that sent the caps // packet. entityCapabilitiesUserMap.put(packet.getFrom(), newVerAttribute); } else { // The 'ver' hash is not in the cache so send out a disco#info query // so that we may begin recognizing this 'ver' hash. IQ iq = new IQ(IQ.Type.get); iq.setTo(packet.getFrom()); String serverName = XmppServer.getInstance().getServerInfo().getXMPPDomain(); iq.setFrom(serverName); iq.setChildElement("query", "http://jabber.org/protocol/disco#info"); String packetId = iq.getID(); final EntityCapabilities caps = new EntityCapabilities(); caps.setHashAttribute(hashAttribute); caps.setVerAttribute(newVerAttribute); verAttributes.put(packetId, caps); final IQRouter iqRouter = XmppServer.getInstance().getIQRouter(); iqRouter.addIQResultListener(packetId, this); iqRouter.route(iq); } }
/** * Deletes a user from all the groups where he/she belongs. The most probable cause for this * request is that the user has been deleted from the system. * * @param user the deleted user from the system. */ public void deleteUser(User user) { JID userJID = XmppServer.getInstance().createJID(user.getUsername(), null); for (Group group : getGroups(userJID)) { if (group.getAdmins().contains(userJID)) { if (group.getAdmins().remove(userJID)) { // Remove the group from cache. groupCache.remove(group.getName()); } } else { if (group.getMembers().remove(userJID)) { // Remove the group from cache. groupCache.remove(group.getName()); } } } }
public void userDeleting(User user, Map<String, Object> params) { // Delete this user's association in entityCapabilitiesUserMap. JID jid = XmppServer.getInstance().createJID(user.getUsername(), null, true); String verHashOfUser = entityCapabilitiesUserMap.remove(jid); // If there are no other references to the deleted user's 'ver' hash, // it is safe to remove that 'ver' hash's associated entity // capabilities from the entityCapabilitiesMap cache. for (String verHash : entityCapabilitiesUserMap.values()) { if (verHash.equals(verHashOfUser)) { // A different user is making use of the deleted user's same // 'ver' hash, so let's not remove the associated entity // capabilities from the entityCapabilitiesMap. return; } } entityCapabilitiesMap.remove(verHashOfUser); }
/** * Returns an iterator for all groups that the User is a member of. * * @param user the user. * @return all groups the user belongs to. */ public Collection<Group> getGroups(User user) { return getGroups(XmppServer.getInstance().createJID(user.getUsername(), null, true)); }