/** * Handles the IQ packet sent by an owner of the room. Possible actions are: * * <ul> * <li>Return the list of owners * <li>Return the list of admins * <li>Change user's affiliation to owner * <li>Change user's affiliation to admin * <li>Change user's affiliation to member * <li>Change user's affiliation to none * <li>Destroy the room * <li>Return the room configuration within a dataform * <li>Update the room configuration based on the sent dataform * </ul> * * @param packet the IQ packet sent by an owner of the room. * @param role the role of the user that sent the packet. * @throws ForbiddenException if the user does not have enough permissions (ie. is not an owner). * @throws ConflictException If the room was going to lose all of its owners. */ @SuppressWarnings("unchecked") public void handleIQ(IQ packet, MUCRole role) throws ForbiddenException, ConflictException, CannotBeInvitedException { // Only owners can send packets with the namespace "http://jabber.org/protocol/muc#owner" if (MUCRole.Affiliation.owner != role.getAffiliation()) { throw new ForbiddenException(); } IQ reply = IQ.createResultIQ(packet); Element element = packet.getChildElement(); // Analyze the action to perform based on the included element Element formElement = element.element(QName.get("x", "jabber:x:data")); if (formElement != null) { handleDataFormElement(role, formElement); } else { Element destroyElement = element.element("destroy"); if (destroyElement != null) { if (((MultiUserChatServiceImpl) room.getMUCService()).getMUCDelegate() != null) { if (!((MultiUserChatServiceImpl) room.getMUCService()) .getMUCDelegate() .destroyingRoom(room.getName(), role.getUserAddress())) { // Delegate said no, reject destroy request. throw new ForbiddenException(); } } JID alternateJID = null; final String jid = destroyElement.attributeValue("jid"); if (jid != null) { alternateJID = new JID(jid); } room.destroyRoom(alternateJID, destroyElement.elementTextTrim("reason")); } else { // If no element was included in the query element then answer the // configuration form if (!element.elementIterator().hasNext()) { refreshConfigurationFormValues(); reply.setChildElement(probeResult.createCopy()); } // An unknown and possibly incorrect element was included in the query // element so answer a BAD_REQUEST error else { reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.bad_request); } } } if (reply.getTo() != null) { // Send a reply only if the sender of the original packet was from a real JID. (i.e. not // a packet generated locally) router.route(reply); } }