Commit 3a389027 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Port from branch. JM-1331

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10231 b35dd754-fafc-0310-a699-88a17e54d16e
parent 7610bab6
...@@ -34,6 +34,7 @@ import org.jivesoftware.openfire.roster.RosterEventListener; ...@@ -34,6 +34,7 @@ import org.jivesoftware.openfire.roster.RosterEventListener;
import org.jivesoftware.openfire.roster.RosterItem; import org.jivesoftware.openfire.roster.RosterItem;
import org.jivesoftware.openfire.session.ClientSession; import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.user.*; import org.jivesoftware.openfire.user.*;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.xmpp.forms.DataForm; import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField; import org.xmpp.forms.FormField;
...@@ -119,16 +120,17 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -119,16 +120,17 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
// that was slowing down the server // that was slowing down the server
Thread thread = new Thread("PEP avaiable sessions handler ") { Thread thread = new Thread("PEP avaiable sessions handler ") {
public void run() { public void run() {
for (; ;) { final XMPPServer server = XMPPServer.getInstance();
while (!server.isShuttingDown()) {
try { try {
JID availableSessionJID = availableSessions.take(); JID availableSessionJID = availableSessions.take();
// Send the last published items for the contacts on availableSessionJID's roster. // Send the last published items for the contacts on availableSessionJID's roster.
try { try {
Roster roster = XMPPServer.getInstance().getRosterManager() Roster roster = server.getRosterManager().getRoster(availableSessionJID.getNode());
.getRoster(availableSessionJID.getNode());
for (RosterItem item : roster.getRosterItems()) { for (RosterItem item : roster.getRosterItems()) {
if (item.getSubStatus() == RosterItem.SUB_BOTH) { if (server.isLocal(item.getJid()) && (item.getSubStatus() == RosterItem.SUB_BOTH ||
item.getSubStatus() == RosterItem.SUB_TO)) {
PEPService pepService = getPEPService(item.getJid().toBareJID()); PEPService pepService = getPEPService(item.getJid().toBareJID());
if (pepService != null) { if (pepService != null) {
pepService.sendLastPublishedItems(availableSessionJID); pepService.sendLastPublishedItems(availableSessionJID);
...@@ -169,6 +171,15 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -169,6 +171,15 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
pubSubEngine = new PubSubEngine(server.getPacketRouter()); pubSubEngine = new PubSubEngine(server.getPacketRouter());
} }
/**
* Returns true if the PEP service is enabled in the server.
*
* @return true if the PEP service is enabled in the server.
*/
public boolean isEnabled() {
return JiveGlobals.getBooleanProperty("xmpp.pep.enabled", true);
}
/** /**
* Loads a PEP service from the database, if it exists. * Loads a PEP service from the database, if it exists.
* *
...@@ -257,6 +268,14 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -257,6 +268,14 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
@Override @Override
public IQ handleIQ(IQ packet) throws UnauthorizedException { public IQ handleIQ(IQ packet) throws UnauthorizedException {
// Do nothing if server is not enabled
if (!isEnabled()) {
IQ reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.service_unavailable);
return reply;
}
JID senderJID = packet.getFrom(); JID senderJID = packet.getFrom();
if (packet.getTo() == null) { if (packet.getTo() == null) {
if (packet.getType() == IQ.Type.set) { if (packet.getType() == IQ.Type.set) {
...@@ -367,6 +386,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -367,6 +386,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
if (pepService == null) { if (pepService == null) {
pepService = loadPEPServiceFromDB(jid); pepService = loadPEPServiceFromDB(jid);
// TODO Cache that no PEP service was found so we do not look for it again. Remove from cache when created
} }
return pepService; return pepService;
...@@ -538,6 +558,10 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -538,6 +558,10 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
} }
public void availableSession(ClientSession session, Presence presence) { public void availableSession(ClientSession session, Presence presence) {
// Do nothing if server is not enabled
if (!isEnabled()) {
return;
}
JID newlyAvailableJID = presence.getFrom(); JID newlyAvailableJID = presence.getFrom();
if (newlyAvailableJID == null) { if (newlyAvailableJID == null) {
...@@ -549,6 +573,10 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -549,6 +573,10 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
} }
public void remoteUserAvailable(Presence presence) { public void remoteUserAvailable(Presence presence) {
// Do nothing if server is not enabled
if (!isEnabled()) {
return;
}
JID jidFrom = presence.getFrom(); JID jidFrom = presence.getFrom();
JID jidTo = presence.getTo(); JID jidTo = presence.getTo();
...@@ -565,6 +593,9 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -565,6 +593,9 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
knownRemotePresences.put(jidTo.toBareJID(), remotePresenceSet); knownRemotePresences.put(jidTo.toBareJID(), remotePresenceSet);
} }
// TODO Check the roster presence subscription to allow or ignore the received presence.
// TODO Directed presences should be ignored when no presence subscription exists
// Send the presence packet recipient's last published items to the remote user. // Send the presence packet recipient's last published items to the remote user.
PEPService pepService = getPEPService(jidTo.toBareJID()); PEPService pepService = getPEPService(jidTo.toBareJID());
if (pepService != null) { if (pepService != null) {
...@@ -574,6 +605,10 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -574,6 +605,10 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
} }
public void remoteUserUnavailable(Presence presence) { public void remoteUserUnavailable(Presence presence) {
// Do nothing if server is not enabled
if (!isEnabled()) {
return;
}
JID jidFrom = presence.getFrom(); JID jidFrom = presence.getFrom();
JID jidTo = presence.getTo(); JID jidTo = presence.getTo();
......
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