Commit 9757cde2 authored by Axel Brand's avatar Axel Brand Committed by daeva

Finished Refactoring of Main-Interceptor

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches/plugins@13544 b35dd754-fafc-0310-a699-88a17e54d16e
parent bac23fdc
......@@ -7,8 +7,6 @@ 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.database.DatabaseManager;
//import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.RemoteRosterInterceptor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.*;
import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.session.Session;
......@@ -22,23 +20,17 @@ import org.xmpp.packet.Presence;
public class MainInterceptor implements PacketInterceptor {
// private DatabaseManager _db;
private static final Logger Log = LoggerFactory.getLogger(MainInterceptor.class);
private Set<String> activeTransports = new ConcurrentHashSet<String>();
private Map<String, AbstractRemoteRosterProcessor> packetProcessors = new HashMap<String, AbstractRemoteRosterProcessor>();
private String serverDomain;
//we dont need this anymore
// private RemoteRosterInterceptor interceptor;
public MainInterceptor() {
Log.debug("Started MainInterceptor for GoJara Plugin.");
XMPPServer server = XMPPServer.getInstance();
serverDomain = server.getServerInfo().getXMPPDomain();
// _db = DatabaseManager.getInstance();
// interceptor = new RemoteRosterInterceptor();
//Now we need to add the PacketProcessors.
RosterManager rosterMananger = server.getRosterManager();
AbstractRemoteRosterProcessor sendroster = new SendRosterProcessor(rosterMananger);
......@@ -82,53 +74,65 @@ public class MainInterceptor implements PacketInterceptor {
}
/*
* 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.
* so we would'nt redundantly test for cases we already checked in previous Interceptors, also we have only one big ugly If Structure
* to maintain instead of several.
* @see org.jivesoftware.openfire.interceptor.PacketInterceptor#interceptPacket(org.xmpp.packet.Packet, org.jivesoftware.openfire.session.Session, boolean, boolean)
*/
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
throws PacketRejectedException {
//We have to watch out for null else this will throw Exceptions
String from = (packet.getFrom() != null) ? packet.getFrom().toString() : "";
String to = (packet.getTo() != null) ? packet.getTo().toString() : "";
//eventually we will have to test for incoming stuff here....
//We have to watch out for null else this will throw Exceptions
String from,to;
try {
from = (packet.getFrom() != null) ? packet.getFrom().toString() : "";
to = (packet.getTo() != null) ? packet.getTo().toString() : "";
} catch (IllegalArgumentException e) {
Log.warn("There was an illegal JID while intercepting Message for GoJara! "+e.getMessage());
return;
}
//We dont want this to get too packed, so here we test only for stuff we can test on PACKET
//if to is Empty, this might be a Client to Component Update we have to forward.
if (to.isEmpty()) {
packetProcessors.get("clientToComponentUpdate").process(packet);
}
//This might be a Disco IQ from the SERVER itself, so we have to check for Acess-Restriction
else if (from.isEmpty() || from.equals(serverDomain)) {
packetProcessors.get("WhiteListProcessor").process(packet);
}
//At this Point, TO is NOT EMPTY
String to_subdomain = searchJIDforSubdomain(to);
if (!to_subdomain.isEmpty()){
// To can now be EQUAL to the subdomain or a string containing a subdomain
packetProcessors.get("IQLastProcessor").process(packet,to_subdomain);
//If TO EQUALS a watched subdomain, we test for IQRegistered Process
if (activeTransports.contains(to))
if (incoming && processed) {
//if to is Empty, this might be a Client to Component Update we have to forward.
if (to.isEmpty())
packetProcessors.get("clientToComponentUpdate").process(packet);
//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);
}
//If FROM EQUALS a watched subdomain, we test for IQ:ROSTER Payload
else if (!from.isEmpty() && activeTransports.contains(from)) {
if (packet instanceof IQ)
packetProcessors.get("iqRosterPayload").process(packet,from);
//it could also be a presence from Transport, so we test for Non-Persistancy
if (!JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false) && (packet instanceof Presence)) {
packetProcessors.get("handleNonPersistant").process(packet,from);
//If FROM EQUALS a watched subdomain, we test for IQ:ROSTER Payload, we test for "" again as we cant be sure from is not empty
else if (!from.isEmpty() && activeTransports.contains(from)) {
//If from EQUALS the subdomain, this is likely a RosterPush or Presence we have to react to.
if (packet instanceof IQ)
packetProcessors.get("iqRosterPayload").process(packet,from);
//it could also be a presence from Transport, so we test for Non-Persistancy
else if (!JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false) && (packet instanceof Presence))
packetProcessors.get("handleNonPersistant").process(packet,from);
}
//Functionality Processors for this Case are Done, now Logging. We need to be sure its not
//The Ping Spectrum send itself, and one of from or to contains a watched subdomain.
String from_s = searchJIDforSubdomain(from);
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);
}
else if (incoming && !processed) {
// 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);
}
else if(!incoming && processed) {
if (from.isEmpty() || from.equals(serverDomain))
packetProcessors.get("WhiteListProcessor").process(packet);
//If we want the StatisticsProcessor to diff between Outgoing and Incoming, it would go here
}
}
}
}
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