Commit 9e57b587 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Allowes non-MUC compliant clients to create MUC rooms (will be instant rooms)....

Allowes non-MUC compliant clients to create MUC rooms (will be instant rooms). Before we returned a BAD_REQUEST error.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@174 b35dd754-fafc-0310-a699-88a17e54d16e
parent a9037b11
...@@ -495,8 +495,10 @@ public interface MUCRoom extends ChatDeliverer { ...@@ -495,8 +495,10 @@ public interface MUCRoom extends ChatDeliverer {
* Unlocks the room so that users can join the room. The room is locked when created and only * Unlocks the room so that users can join the room. The room is locked when created and only
* the owner of the room can unlock it by sending the configuration form to the Multi-User Chat * the owner of the room can unlock it by sending the configuration form to the Multi-User Chat
* service. * service.
*
* @param sendRole the role of the occupant that unlocked the room.
*/ */
public void unlockRoom(); public void unlockRoom(MUCRole sendRole);
public List addAdmins(List newAdmins, MUCRole sendRole) throws ForbiddenException, public List addAdmins(List newAdmins, MUCRole sendRole) throws ForbiddenException,
ConflictException; ConflictException;
......
...@@ -21,7 +21,6 @@ import org.jivesoftware.messenger.muc.MUCRole; ...@@ -21,7 +21,6 @@ import org.jivesoftware.messenger.muc.MUCRole;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.messenger.*; import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.spi.MessageImpl;
import org.jivesoftware.messenger.user.UserNotFoundException; import org.jivesoftware.messenger.user.UserNotFoundException;
import java.util.*; import java.util.*;
...@@ -301,14 +300,7 @@ public class IQOwnerHandler { ...@@ -301,14 +300,7 @@ public class IQOwnerHandler {
// If the room was locked, unlock it and send to the owner the "room is now unlocked" // If the room was locked, unlock it and send to the owner the "room is now unlocked"
// message // message
if (room.isLocked()) { if (room.isLocked()) {
room.unlockRoom(); room.unlockRoom(senderRole);
Message message = new MessageImpl();
message.setType(Message.GROUP_CHAT);
message.setBody(LocaleUtils.getLocalizedString("muc.unlocked"));
message.setSender(room.getRole().getRoleAddress());
message.setRecipient(senderRole.getChatUser().getAddress());
router.route(message);
} }
} }
} }
......
...@@ -457,7 +457,7 @@ class MUCPersistentRoomSurrogate implements MUCRoom, Cacheable { ...@@ -457,7 +457,7 @@ class MUCPersistentRoomSurrogate implements MUCRoom, Cacheable {
this.name = name; this.name = name;
} }
public void unlockRoom() { public void unlockRoom(MUCRole senderRole) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
......
...@@ -1740,9 +1740,16 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -1740,9 +1740,16 @@ public class MUCRoomImpl implements MUCRoom {
} }
} }
public void unlockRoom() { public void unlockRoom(MUCRole senderRole) {
roomLocked = false; roomLocked = false;
this.lockedTime = 0; this.lockedTime = 0;
// Send to the occupant the unlocked the room a message saying so
Message message = new MessageImpl();
message.setType(Message.GROUP_CHAT);
message.setBody(LocaleUtils.getLocalizedString("muc.unlocked"));
message.setSender(getRole().getRoleAddress());
message.setRecipient(senderRole.getChatUser().getAddress());
router.route(message);
} }
public List addAdmins(List newAdmins, MUCRole senderRole) throws ForbiddenException, public List addAdmins(List newAdmins, MUCRole senderRole) throws ForbiddenException,
......
...@@ -337,9 +337,8 @@ public class MUCUserImpl implements MUCUser { ...@@ -337,9 +337,8 @@ public class MUCUserImpl implements MUCUser {
else { else {
MUCRole role = roles.get(group.toLowerCase()); MUCRole role = roles.get(group.toLowerCase());
if (role == null) { if (role == null) {
// If we're not already in a room, we either are joining it // If we're not already in a room, we either are joining it or it's not
// or it's not properly addressed and we drop it silently // properly addressed and we drop it silently
// In the future, we'll need to support TYPE_IQ queries to the room for MUC
if (recipient.getResource() != null if (recipient.getResource() != null
&& recipient.getResource().trim().length() > 0) { && recipient.getResource().trim().length() > 0) {
if (packet.getType() == Presence.AVAILABLE if (packet.getType() == Presence.AVAILABLE
...@@ -348,32 +347,27 @@ public class MUCUserImpl implements MUCUser { ...@@ -348,32 +347,27 @@ public class MUCUserImpl implements MUCUser {
// Get or create the room // Get or create the room
MUCRoom room = server.getChatRoom(group, packet.getSender()); MUCRoom room = server.getChatRoom(group, packet.getSender());
// User must support MUC in order to create a room // User must support MUC in order to create a room
MetaDataFragment mucInfo = (MetaDataFragment) packet.getFragment( MetaDataFragment mucInfo = (MetaDataFragment) packet.getFragment("x",
"x",
"http://jabber.org/protocol/muc"); "http://jabber.org/protocol/muc");
HistoryRequest historyRequest = null; HistoryRequest historyRequest = null;
String password = null; String password = null;
if (room.isLocked() && mucInfo == null) { // Check for password & requested history if client supports MUC
// Only users that support MUC are allowed to create roooms if (mucInfo != null) {
// Remove the room since the intended owner doesn't support MUC password = mucInfo.getProperty("x.password");
sendErrorPacket(packet, XMPPError.Code.BAD_REQUEST); if (mucInfo.includesProperty("x.history")) {
server.removeChatRoom(group); historyRequest = new HistoryRequest(mucInfo);
}
else {
// Check for password & requested history if client supports MUC
if (mucInfo != null) {
password = mucInfo.getProperty("x.password");
if (mucInfo.includesProperty("x.history")) {
historyRequest = new HistoryRequest(mucInfo);
}
} }
// The user joins the room }
role = room.joinRoom( // The user joins the room
recipient.getResource().trim(), role = room.joinRoom(recipient.getResource().trim(),
password, password,
historyRequest, historyRequest,
this); this);
roles.put(group, role); roles.put(group, role);
// If the client that created the room is non-MUC compliant then
// unlock the room thus creating an "instant" room
if (room.isLocked() && mucInfo == null) {
room.unlockRoom(role);
} }
} }
catch (UnauthorizedException e) { catch (UnauthorizedException e) {
......
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