Commit 2f67cfc1 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Fixed deadlock that could freeze entire JVM. JM-1372

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches@10437 b35dd754-fafc-0310-a699-88a17e54d16e
parent 250911dd
...@@ -223,56 +223,50 @@ public class IQAdminHandler { ...@@ -223,56 +223,50 @@ public class IQAdminHandler {
jid = room.getOccupant(nick).getUserAddress(); jid = room.getOccupant(nick).getUserAddress();
} }
room.lock.writeLock().lock(); if ("moderator".equals(target)) {
try { // Add the user as a moderator of the room based on the full JID
if ("moderator".equals(target)) { presences.add(room.addModerator(jid, senderRole));
// Add the user as a moderator of the room based on the full JID }
presences.add(room.addModerator(jid, senderRole)); else if ("participant".equals(target)) {
} // Add the user as a participant of the room based on the full JID
else if ("participant".equals(target)) { presences.add(room.addParticipant(jid,
// Add the user as a participant of the room based on the full JID item.elementTextTrim("reason"),
presences.add(room.addParticipant(jid, senderRole));
item.elementTextTrim("reason"), }
senderRole)); else if ("visitor".equals(target)) {
} // Add the user as a visitor of the room based on the full JID
else if ("visitor".equals(target)) { presences.add(room.addVisitor(jid, senderRole));
// Add the user as a visitor of the room based on the full JID }
presences.add(room.addVisitor(jid, senderRole)); else if ("member".equals(target)) {
} // Add the user as a member of the room based on the bare JID
else if ("member".equals(target)) { boolean hadAffiliation = room.getAffiliation(jid.toBareJID()) != MUCRole.Affiliation.none;
// Add the user as a member of the room based on the bare JID presences.addAll(room.addMember(jid.toBareJID(), nick, senderRole));
boolean hadAffiliation = room.getAffiliation(jid.toBareJID()) != MUCRole.Affiliation.none; // If the user had an affiliation don't send an invitation. Otherwise
presences.addAll(room.addMember(jid.toBareJID(), nick, senderRole)); // send an invitation if the room is members-only
// If the user had an affiliation don't send an invitation. Otherwise if (!hadAffiliation && room.isMembersOnly()) {
// send an invitation if the room is members-only room.sendInvitation(jid, null, senderRole, null);
if (!hadAffiliation && room.isMembersOnly()) {
room.sendInvitation(jid, null, senderRole, null);
}
}
else if ("outcast".equals(target)) {
// Add the user as an outcast of the room based on the bare JID
presences.addAll(room.addOutcast(jid.toBareJID(), item.elementTextTrim("reason"), senderRole));
} }
else if ("none".equals(target)) { }
if (hasAffiliation) { else if ("outcast".equals(target)) {
// Set that this jid has a NONE affiliation based on the bare JID // Add the user as an outcast of the room based on the bare JID
presences.addAll(room.addNone(jid.toBareJID(), senderRole)); presences.addAll(room.addOutcast(jid.toBareJID(), item.elementTextTrim("reason"), senderRole));
} }
else { else if ("none".equals(target)) {
// Kick the user from the room if (hasAffiliation) {
if (MUCRole.Role.moderator != senderRole.getRole()) { // Set that this jid has a NONE affiliation based on the bare JID
throw new ForbiddenException(); presences.addAll(room.addNone(jid.toBareJID(), senderRole));
}
presences.add(room.kickOccupant(jid, senderRole.getUserAddress(),
item.elementTextTrim("reason")));
}
} }
else { else {
reply.setError(PacketError.Condition.bad_request); // Kick the user from the room
if (MUCRole.Role.moderator != senderRole.getRole()) {
throw new ForbiddenException();
}
presences.add(room.kickOccupant(jid, senderRole.getUserAddress(),
item.elementTextTrim("reason")));
} }
} }
finally { else {
room.lock.writeLock().unlock(); reply.setError(PacketError.Condition.bad_request);
} }
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
......
...@@ -285,13 +285,7 @@ public class LocalMUCUser implements MUCUser { ...@@ -285,13 +285,7 @@ public class LocalMUCUser implements MUCUser {
// Add the user as a member of the room if the room is // Add the user as a member of the room if the room is
// members only // members only
if (room.isMembersOnly()) { if (room.isMembersOnly()) {
room.lock.writeLock().lock(); room.addMember(info.attributeValue("to"), null, role);
try {
room.addMember(info.attributeValue("to"), null, role);
}
finally {
room.lock.writeLock().unlock();
}
} }
// Send the invitation to the invitee // Send the invitation to the invitee
...@@ -560,4 +554,4 @@ public class LocalMUCUser implements MUCUser { ...@@ -560,4 +554,4 @@ public class LocalMUCUser implements MUCUser {
} }
} }
} }
} }
\ No newline at end of file
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