Commit a660277a authored by Axel Brand's avatar Axel Brand Committed by daeva

New Additions to MainInterceptor to be able to freeze it when shutting down the plugin.

Started Refactoring all Processors.



git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches/plugins@13545 b35dd754-fafc-0310-a699-88a17e54d16e
parent 9757cde2
......@@ -137,9 +137,11 @@ public class RemoteRosterPlugin implements Plugin {
// for (String key : _interceptors.keySet()) {
// _interceptors.get(key).stop();
// }
mainInterceptor.freeze();
iManager.removeInterceptor(mainInterceptor);
PropertyEventDispatcher.removeListener(_settingsObserver);
pluginManager = null;
mainInterceptor = null;
}
private void updateInterceptors(String componentJID) {
......
......@@ -7,7 +7,7 @@ import java.util.Set;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.interceptor.PacketInterceptor;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.*;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.processors.*;
import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.ConcurrentHashSet;
......@@ -25,6 +25,8 @@ public class MainInterceptor implements PacketInterceptor {
private Map<String, AbstractRemoteRosterProcessor> packetProcessors = new HashMap<String, AbstractRemoteRosterProcessor>();
private String serverDomain;
private Boolean frozen;
public MainInterceptor() {
......@@ -33,16 +35,23 @@ public class MainInterceptor implements PacketInterceptor {
serverDomain = server.getServerInfo().getXMPPDomain();
//Now we need to add the PacketProcessors.
RosterManager rosterMananger = server.getRosterManager();
AbstractRemoteRosterProcessor sendroster = new SendRosterProcessor(rosterMananger);
AbstractRemoteRosterProcessor receiveChanges = new ReceiveComponentUpdatesProcessor(rosterMananger);
AbstractRemoteRosterProcessor updateToComponent = new ClientToComponentUpdateProcessor();
AbstractRemoteRosterProcessor iqRegistered = new DiscoIQRegisteredProcessor();
AbstractRemoteRosterProcessor iqRosterPayload = new IQRosterPayloadProcessor(rosterMananger);
AbstractRemoteRosterProcessor nonPersistant = new NonPersistantRosterProcessor(rosterMananger);
AbstractRemoteRosterProcessor updateToComponent = new ClientToComponentUpdateProcessor();
packetProcessors.put("sendRoster", sendroster);
packetProcessors.put("receiveChanges", receiveChanges);
// Check if we need rostermanager for these....
AbstractRemoteRosterProcessor statisticsProcessor = new StatisticsProcessor();
AbstractRemoteRosterProcessor iqLastProcessor = new IQLastProcessor();
AbstractRemoteRosterProcessor whitelistProcessor = new WhitelistProcessor();
packetProcessors.put("clientToComponentUpdate", updateToComponent);
packetProcessors.put("sparkIQRegistered", iqRegistered);
packetProcessors.put("iqRosterPayload", iqRosterPayload);
packetProcessors.put("handleNonPersistant", nonPersistant);
packetProcessors.put("clientToComponentUpdate", updateToComponent);
packetProcessors.put("statisticsProcessor", statisticsProcessor);
packetProcessors.put("iqLastProcessor", iqLastProcessor);
packetProcessors.put("whitelistProcessor", whitelistProcessor);
frozen = false;
}
//These get called from our RemoteRosterPlugin
......@@ -61,17 +70,32 @@ public class MainInterceptor implements PacketInterceptor {
// return false;
}
//evtl noch auf bool refactoren wenni ch merke das ich das fr nichts brauche(siehe to)
//idk if this "smells" but as we still dont know why OF is not correctly shutting down our Interceptor
//better safe then sorry
public void freeze(){
frozen = true;
}
/*
As our Set of Subdomains is a Hash of Strings like icq.domain.tld, if we
want to check if a jid CONTAINS a watched subdomain we need to iterate over the set.
We also return the subdomain as a string so we can use it if we find it.
*
*/
private String searchJIDforSubdomain(String jid) {
//As our Set of Subdomains is a Hash of Strings like icq.domain.tld, if we
//want to check if a jid CONTAINS a watched subdomain we need to iterate over the set.
// We also return the subdomain as a string so we can use it if we find it.
for (String subdomain : activeTransports) {
if (subdomain.contains(jid))
return subdomain;
}
return "";
}
private String generateSubdomainString() {
String subdomainstring = "";
for (String subdomain : activeTransports) {
subdomainstring += subdomain + "#";
}
return subdomainstring;
}
/*
* This Interceptor tests if GoJara needs to process this package. We decided to do one global Interceptor
* so we would'nt redundantly test for cases we already checked in previous Interceptors, also we have only one big ugly If Structure
......@@ -80,7 +104,8 @@ public class MainInterceptor implements PacketInterceptor {
*/
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
throws PacketRejectedException {
//eventually we will have to test for incoming stuff here....
if (frozen)
return;
//We have to watch out for null else this will throw Exceptions
String from,to;
......@@ -94,10 +119,10 @@ public class MainInterceptor implements PacketInterceptor {
//We dont want this to get too packed, so here we test only for stuff we can test on PACKET
if (incoming && processed) {
Log.debug("Incoming processed Package i might be interested in. I'm "+ this.hashCode() + "\n Package: \n " + packet.toString() + "\n");
//if to is Empty, this might be a Client to Component Update we have to forward.
if (to.isEmpty())
packetProcessors.get("clientToComponentUpdate").process(packet);
packetProcessors.get("clientToComponentUpdate").process(packet, generateSubdomainString());
//This might be a Disco IQ from the SERVER itself, so we have to check for Acess-Restriction
else if (activeTransports.contains(to) && packet instanceof IQ)
packetProcessors.get("sparkIQRegistered").process(packet,to);
......@@ -116,18 +141,20 @@ public class MainInterceptor implements PacketInterceptor {
String to_s = searchJIDforSubdomain(to);
String subdomain = from_s.isEmpty() ? to_s : from_s;
if (!from.equals(to) && !subdomain.isEmpty())
packetProcessors.get("StatisticsProcessor").process(packet,subdomain);
packetProcessors.get("statisticsProcessor").process(packet,subdomain);
}
else if (incoming && !processed) {
Log.debug("Incoming unprocessed Package i might be interested in. I'm "+ this.hashCode() + "\n Package: \n " + packet.toString() + "\n");
// if to is EQUAL to the subdomain or a string containing a subdomain
String to_s = searchJIDforSubdomain(to);
if (!to_s.isEmpty())
packetProcessors.get("IQLastProcessor").process(packet,to_s);
packetProcessors.get("iqLastProcessor").process(packet,to_s);
}
else if(!incoming && processed) {
Log.debug("Outgoing processed Package i might be interested in. I'm "+ this.hashCode() + "\n Package: \n " + packet.toString() + "\n");
if (from.isEmpty() || from.equals(serverDomain))
packetProcessors.get("WhiteListProcessor").process(packet);
packetProcessors.get("whiteListProcessor").process(packet);
//If we want the StatisticsProcessor to diff between Outgoing and Incoming, it would go here
}
}
......
package org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors;
package org.jivesoftware.openfire.plugin.gojara.messagefilter.processors;
import java.util.List;
......@@ -40,7 +40,7 @@ abstract public class AbstractRemoteRosterProcessor {
* @param packet
* @throws PacketRejectedException
*/
abstract public void process(Packet packet) throws PacketRejectedException;
abstract public void process(Packet packet,String subdomain) throws PacketRejectedException;
/**
* Use this method if you want to send your own packets through openfire
......
package org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors;
package org.jivesoftware.openfire.plugin.gojara.messagefilter.processors;
import org.dom4j.Element;
import org.dom4j.Node;
......@@ -17,32 +17,46 @@ import org.xmpp.packet.Packet;
* >Here</a>
*
* @author Holger Bergunde
*
* // Our Query is now a <item jid="Example@subdomain" name="contact"><group></item>iq id="FSwIU-68" type="set" from="axel.brand@lxhamrztst02.ger.win.int.kn/Spark 2.7.0 #272">
// <query xmlns="jabber:iq:roster">
// <item jid="129443529@icq.lxhamrztst02.ger.win.int.kn" name="wulschti" subscription="both">
// <group>General</group>
// </item>
// </query>
// </iq>
*/
public class ClientToComponentUpdateProcessor extends AbstractRemoteRosterProcessor {
// private String _myDomain;
public ClientToComponentUpdateProcessor() {
Log.debug("Created ClientToComponentUpdateProcessor");
// _myDomain = mySubdomain;
}
private String searchJIDforSubdomain(String[] valid_subdomains,String jid){
for (String s : valid_subdomains){
if (jid.contains(s))
return s;
}
return "";
}
@Override
public void process(Packet packet, String subdomain) throws PacketRejectedException {
Log.debug("Processing packet in ClientToComponentUpdateProcessor for " + subdomain);
Log.debug("Processing packet in ClientToComponentUpdateProcessor");
Element query = ((IQ) packet).getChildElement();
if (query != null && query.getNamespaceURI().equals("jabber:iq:roster")) {
if (findNodesInDocument(query.getDocument(), "//roster:item").size() > 0) {
// We now know we have to check the JID of the to be added User against our valid subdomains.
String[] valid_subdomains = subdomain.split("#");
for (Node n : findNodesInDocument(query.getDocument(), "//roster:item")) {
String jid = n.valueOf("@jid");
// TODO: We ignore remove iq packets for now. There might be
// conflicts
// when we remove our legacy network registration.
if (jid.contains("@" + subdomain) && !n.valueOf("@subscription").equals("remove")) {
Log.debug("Mirroring packet from local network to legacy component " + subdomain);
String found_subdomain = searchJIDforSubdomain(valid_subdomains, jid);
if (!found_subdomain.isEmpty() && !n.valueOf("@subscription").equals("remove")) {
Log.debug("Mirroring packet from local network to legacy component " + found_subdomain);
IQ forward = (IQ) packet.createCopy();
forward.setTo(subdomain);
forward.setTo(found_subdomain);
dispatchPacket(forward);
}
}
......
package org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors;
package org.jivesoftware.openfire.plugin.gojara.messagefilter.processors;
import java.util.Timer;
import java.util.TimerTask;
......@@ -27,18 +27,15 @@ import org.xmpp.packet.Packet;
*
*/
public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor {
private boolean _isRegistered = false;
// private String _mySubdoman;
public DiscoIQRegisteredProcessor() {
Log.debug("Created DiscoIQResigteredProcessor");
// _mySubdoman = subdomain;
}
@Override
public void process(Packet packet, final String subdomain) throws PacketRejectedException {
Log.debug("Processing packet in DiscoIQResigteredProcessor for " + subdomain);
Log.debug("Processing packet in DiscoIQRegisteredProcessor for " + subdomain);
// Check if the jabber:iq:register is enabled in admin panel
boolean isFeatureEnabled = JiveGlobals.getBooleanProperty("plugin.remoteroster.sparkDiscoInfo", false);
if (!isFeatureEnabled) {
......@@ -51,7 +48,6 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor {
final InterceptorManager interceptorManager = InterceptorManager.getInstance();
final PacketInterceptor interceptor = new PacketInterceptor() {
@Override
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
throws PacketRejectedException {
if (!processed && incoming) {
......
package org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors;
package org.jivesoftware.openfire.plugin.gojara.messagefilter.processors;
import java.util.Collection;
......@@ -27,15 +27,13 @@ import org.xmpp.packet.Packet;
* @author Holger Bergunde
*
*/
public class SendRosterProcessor extends AbstractRemoteRosterProcessor {
public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor {
private RosterManager _rosterManager;
// private String _componentName;
public SendRosterProcessor(RosterManager rosterMananger) {
public IQRosterPayloadProcessor(RosterManager rosterMananger) {
Log.debug("Created SendRosterProcessor");
_rosterManager = rosterMananger;
// _componentName = componentName;
}
@Override
......
......@@ -7,6 +7,10 @@ import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.interceptor.PacketInterceptor;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.database.DatabaseManager;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.processors.AbstractRemoteRosterProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.processors.ClientToComponentUpdateProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.processors.DiscoIQRegisteredProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.processors.IQRosterPayloadProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.*;
import org.jivesoftware.openfire.plugin.gojara.utils.XpathHelper;
import org.jivesoftware.openfire.roster.RosterManager;
......@@ -45,7 +49,7 @@ public class RemoteRosterInterceptor {
Log.debug("Starting Package Interceptor for " + initialSubdomain);
XMPPServer server = XMPPServer.getInstance();
RosterManager rosterMananger = server.getRosterManager();
AbstractRemoteRosterProcessor sendroster = new SendRosterProcessor(
AbstractRemoteRosterProcessor sendroster = new IQRosterPayloadProcessor(
rosterMananger);
AbstractRemoteRosterProcessor receiveChanges = new ReceiveComponentUpdatesProcessor(rosterMananger);
AbstractRemoteRosterProcessor iqRegistered = new DiscoIQRegisteredProcessor();
......@@ -64,7 +68,7 @@ public class RemoteRosterInterceptor {
Log.debug("Starting RemoteRosterInterceptor - BINGO");
XMPPServer server = XMPPServer.getInstance();
RosterManager rosterMananger = server.getRosterManager();
AbstractRemoteRosterProcessor sendroster = new SendRosterProcessor(
AbstractRemoteRosterProcessor sendroster = new IQRosterPayloadProcessor(
rosterMananger);
AbstractRemoteRosterProcessor receiveChanges = new ReceiveComponentUpdatesProcessor(rosterMananger);
AbstractRemoteRosterProcessor iqRegistered = new DiscoIQRegisteredProcessor();
......
......@@ -4,6 +4,7 @@ import java.util.Collection;
import org.jivesoftware.openfire.SharedGroupException;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.processors.AbstractRemoteRosterProcessor;
import org.jivesoftware.openfire.roster.Roster;
import org.jivesoftware.openfire.roster.RosterItem;
import org.jivesoftware.openfire.roster.RosterManager;
......
......@@ -7,6 +7,7 @@ import org.dom4j.Node;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.interceptor.PacketInterceptor;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.processors.AbstractRemoteRosterProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.RemoteRosterInterceptor;
import org.jivesoftware.openfire.plugin.gojara.permissions.PermissionManager;
import org.jivesoftware.openfire.plugin.gojara.utils.XpathHelper;
......
......@@ -3,6 +3,7 @@ package org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.proce
import java.util.Collection;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.processors.AbstractRemoteRosterProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.RemoteRosterInterceptor;
import org.jivesoftware.openfire.roster.Roster;
import org.jivesoftware.openfire.roster.RosterItem;
......
......@@ -9,6 +9,7 @@ import org.dom4j.Node;
import org.dom4j.tree.DefaultElement;
import org.jivesoftware.openfire.SharedGroupException;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.processors.AbstractRemoteRosterProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.RemoteRosterInterceptor;
import org.jivesoftware.openfire.roster.Roster;
import org.jivesoftware.openfire.roster.RosterItem;
......
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