Commit 660e1c3c authored by Matt Tucker's avatar Matt Tucker Committed by matt

Numerous bug fixes.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@816 b35dd754-fafc-0310-a699-88a17e54d16e
parent f90eb5c2
...@@ -14,9 +14,15 @@ package org.jivesoftware.messenger.plugin; ...@@ -14,9 +14,15 @@ package org.jivesoftware.messenger.plugin;
import org.jivesoftware.messenger.container.Plugin; import org.jivesoftware.messenger.container.Plugin;
import org.jivesoftware.messenger.container.PluginManager; import org.jivesoftware.messenger.container.PluginManager;
import org.jivesoftware.messenger.*; import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.group.GroupManager;
import org.jivesoftware.messenger.group.Group;
import org.jivesoftware.messenger.group.GroupNotFoundException;
import org.jivesoftware.util.Log;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
import org.xmpp.packet.JID;
import java.io.File; import java.io.File;
import java.util.Collection; import java.util.Collection;
...@@ -36,6 +42,7 @@ public class BroadcastPlugin implements Plugin, Component { ...@@ -36,6 +42,7 @@ public class BroadcastPlugin implements Plugin, Component {
private String serviceName; private String serviceName;
private SessionManager sessionManager; private SessionManager sessionManager;
private GroupManager groupManager;
private List<String> allowedUsers; private List<String> allowedUsers;
private boolean groupMembersAllowed; private boolean groupMembersAllowed;
...@@ -45,7 +52,7 @@ public class BroadcastPlugin implements Plugin, Component { ...@@ -45,7 +52,7 @@ public class BroadcastPlugin implements Plugin, Component {
public BroadcastPlugin() { public BroadcastPlugin() {
serviceName = JiveGlobals.getProperty("plugin.broadcast.serviceName", "broadcast"); serviceName = JiveGlobals.getProperty("plugin.broadcast.serviceName", "broadcast");
groupMembersAllowed = JiveGlobals.getBooleanProperty( groupMembersAllowed = JiveGlobals.getBooleanProperty(
"plugin.broadcast.groupMembersAllowed"); "plugin.broadcast.groupMembersAllowed", true);
allowedUsers = new ArrayList<String>(); allowedUsers = new ArrayList<String>();
} }
...@@ -69,6 +76,7 @@ public class BroadcastPlugin implements Plugin, Component { ...@@ -69,6 +76,7 @@ public class BroadcastPlugin implements Plugin, Component {
public void initialize(PluginManager manager, File pluginDirectory) { public void initialize(PluginManager manager, File pluginDirectory) {
sessionManager = SessionManager.getInstance(); sessionManager = SessionManager.getInstance();
groupManager = GroupManager.getInstance();
// Register as a component. // Register as a component.
ComponentManager.getInstance().addComponent(serviceName, this); ComponentManager.getInstance().addComponent(serviceName, this);
...@@ -86,9 +94,10 @@ public class BroadcastPlugin implements Plugin, Component { ...@@ -86,9 +94,10 @@ public class BroadcastPlugin implements Plugin, Component {
// Only respond to incoming messages. TODO: handle disco, presence, etc. // Only respond to incoming messages. TODO: handle disco, presence, etc.
if (packet instanceof Message) { if (packet instanceof Message) {
Message message = (Message)packet; Message message = (Message)packet;
String name = message.getTo().getNode(); String toNode = message.getTo().getNode();
String fromNode = message.getFrom().getNode();
// Check to see if trying to broadcast to all connected users. // Check to see if trying to broadcast to all connected users.
if ("all".equals(name)) { if ("all".equals(toNode)) {
if (allowedUsers.size() > 0) { if (allowedUsers.size() > 0) {
// See if the user is allowed to send the message. // See if the user is allowed to send the message.
String address = message.getFrom().toBareJID(); String address = message.getFrom().toBareJID();
...@@ -106,12 +115,29 @@ public class BroadcastPlugin implements Plugin, Component { ...@@ -106,12 +115,29 @@ public class BroadcastPlugin implements Plugin, Component {
return; return;
} }
} }
sessionManager.sendServerMessage(message.getSubject(), message.getBody()); try {
sessionManager.broadcast(message);
}
catch (UnauthorizedException ue) {
Log.error(ue);
}
} }
// See if the name is a group. // See if the name is a group.
// Otherwise, the address is recognized so send an error message back.
else { else {
try {
Group group = groupManager.getGroup(toNode);
if ((groupMembersAllowed && group.isUser(fromNode)) ||
group.getAdmins().contains(fromNode))
{
for (String user : group.getMembers()) {
Message newMessage = message.createCopy();
JID userJID = XMPPServer.getInstance().createJID(user, null);
newMessage.setTo(userJID);
ComponentManager.getInstance().sendPacket(newMessage);
}
}
else {
// Otherwise, the address is recognized so send an error message back.
Message error = new Message(); Message error = new Message();
if (message.getID() != null) { if (message.getID() != null) {
error.setID(message.getID()); error.setID(message.getID());
...@@ -124,6 +150,21 @@ public class BroadcastPlugin implements Plugin, Component { ...@@ -124,6 +150,21 @@ public class BroadcastPlugin implements Plugin, Component {
ComponentManager.getInstance().sendPacket(error); ComponentManager.getInstance().sendPacket(error);
} }
} }
catch (GroupNotFoundException gnfe) {
// Otherwise, the address is recognized so send an error message back.
Message error = new Message();
if (message.getID() != null) {
error.setID(message.getID());
}
error.setTo(message.getFrom());
error.setError(PacketError.Condition.not_allowed);
error.setSubject("Error sending broadcast message");
error.setBody("Address not valid: " +
message.getTo());
ComponentManager.getInstance().sendPacket(error);
}
}
}
} }
// Other Methods // Other Methods
......
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