Commit 1a6b6c70 authored by Axel Brand's avatar Axel Brand Committed by daeva

fixed nonpersistant mode,

Roster updates from spectrum2 now get correctly updated so users can be in mutliple groups again,
some minor structural changes to sendroster and RemoteRosterInterceptor to be more efficient and clear

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13405 b35dd754-fafc-0310-a699-88a17e54d16e
parent 972281e6
......@@ -10,15 +10,18 @@ import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.proces
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.CleanUpRosterProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.ClientToComponentUpdateProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.DiscoIQResigteredProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.NonPersistantRosterProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.ReceiveComponentUpdatesProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.SendRosterProcessor;
import org.jivesoftware.openfire.plugin.gojara.utils.XpathHelper;
import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.JiveGlobals;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
/**
* This intercepter handles the main functionality described in the XEP-xxx
......@@ -48,12 +51,12 @@ public class RemoteRosterInterceptor implements PacketInterceptor {
AbstractRemoteRosterProcessor receiveChanges = new ReceiveComponentUpdatesProcessor(rosterMananger,
_mySubdomain);
AbstractRemoteRosterProcessor iqRegistered = new DiscoIQResigteredProcessor(_mySubdomain);
AbstractRemoteRosterProcessor cleanUp = new CleanUpRosterProcessor(rosterMananger, _mySubdomain);
AbstractRemoteRosterProcessor nonPersistant = new NonPersistantRosterProcessor(rosterMananger, _mySubdomain);
AbstractRemoteRosterProcessor updateToComponent = new ClientToComponentUpdateProcessor(_mySubdomain);
_packetProcessor.put("sendRoster", sendroster);
_packetProcessor.put("receiveChanges", receiveChanges);
_packetProcessor.put("sparkIQRegistered", iqRegistered);
_packetProcessor.put("handleCleanUp", cleanUp);
_packetProcessor.put("handleNonPersistant", nonPersistant);
_packetProcessor.put("clientToComponentUpdate", updateToComponent);
}
......@@ -80,43 +83,51 @@ public class RemoteRosterInterceptor implements PacketInterceptor {
}
return;
}
@SuppressWarnings("unused")
String to = myPacket.getTo().toString();
String from = myPacket.getFrom().toString();
if (myPacket.getType().equals(IQ.Type.get) && from.equals(_mySubdomain)) {
if (XpathHelper.findNodesInDocument(myPacket.getElement().getDocument(), "//roster:*").size() == 1) {
if (from.equals(_mySubdomain)) {
if (myPacket.getType().equals(IQ.Type.get)
&& XpathHelper.findNodesInDocument(myPacket.getElement().getDocument(), "//roster:*").size() == 1) {
// This Package is a roster request by remote component
_packetProcessor.get("sendRoster").process(packet);
}
} else if (myPacket.getType().equals(IQ.Type.set) && from.equals(_mySubdomain)) {
if (XpathHelper.findNodesInDocument(myPacket.getElement().getDocument(), "//roster:item").size() >= 1) {
} else if (myPacket.getType().equals(IQ.Type.set)
&& XpathHelper.findNodesInDocument(myPacket.getElement().getDocument(), "//roster:item").size() >= 1) {
// Component sends roster update
_packetProcessor.get("receiveChanges").process(packet);
}
} else if (myPacket.getType().equals(IQ.Type.get)
&& myPacket.toString().contains("http://jabber.org/protocol/disco#info")
&& myPacket.getTo().toString().equals(_mySubdomain)) {
} else if (myPacket.getTo().toString().equals(_mySubdomain)
&& myPacket.getType().equals(IQ.Type.get)
&& myPacket.toString().contains("http://jabber.org/protocol/disco#info")) {
/*
* modify the disco#info for spark clients if enabled in
* admin panel
*/
_packetProcessor.get("sparkIQRegistered").process(packet);
} else if (myPacket.getType().equals(IQ.Type.set) && myPacket.getTo().toString().equals(_mySubdomain)) {
System.out.println("war das ein remove an mich????");
_packetProcessor.get("handleCleanUp").process(packet);
}
} else if (!JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false)) {
if (packet instanceof Presence && packet.getFrom().toString().equals(_mySubdomain)
&& !packet.getElement().getStringValue().equals("Connecting")){
System.out.println("Test for NonPersistant-Roster Cleanup!");
_packetProcessor.get("handleNonPersistant").process(packet);
}
}
// else if (packet instanceof Presence) {
// if (packet.getFrom().toString().equals(_mySubdomain)
// &&
// !JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent",
// false)) {
// System.out.println("MACH EIN CLEANUP!!!!!!");
// _packetProcessor.get("handleCleanUp").process(packet);
// }
// }
}
}
}
// currently we dont need this, and it didnt seem to occur often anyway. Will test it later.
// could potentially save some traffic
//else if (packet instanceof Presence){
// String to = packet.getTo().toString();
// if (!to.equals(_mySubdomain) && to.contains(_mySubdomain)){
//
// Presence myPacket = ((Presence) packet);
// if (myPacket.getType().equals(Presence.Type.unavailable) || myPacket.getType().equals(Presence.Type.probe) ||
// myPacket.getType().equals(null)){
// System.out.println("this presence would be wasted");
// throw new PacketRejectedException();
// }
// }
\ No newline at end of file
......@@ -14,8 +14,7 @@ import org.xmpp.packet.Presence;
* This class is a part of the command pattern used in
* {@link RemoteRosterInterceptor}. If the remote contacts should not be saved
* permanently in the users roster this command will clean up the users roster.
* If the remote contact went offline it will get removed from user's roster.
* ***
*
* @author Holger Bergunde
*
*/
......@@ -25,23 +24,21 @@ public class NonPersistantRosterProcessor extends AbstractRemoteRosterProcessor
private String _subDomain;
public NonPersistantRosterProcessor(RosterManager rostermananger, String subdomain) {
Log.debug("Created CleanUpRosterProcessor for " + subdomain);
Log.debug("Created NonPersistantProcessor for " + subdomain);
_rosterManager = rostermananger;
_subDomain = subdomain;
}
@Override
public void process(Packet packet) throws PacketRejectedException {
Log.debug("Processing packet in CleanUpRosterProcessor for " + _subDomain);
Log.debug("Processing packet in NonPersistantRosterProcessor for " + _subDomain);
Presence myPacket = (Presence) packet;
String to = myPacket.getTo().toString();
String username = getUsernameFromJid(to);
if (myPacket.getType() != null && myPacket.getType().equals(Presence.Type.unavailable)) {
try {
Roster roster = _rosterManager.getRoster(username);
Collection<RosterItem> items = roster.getRosterItems();
for (RosterItem item : items) {
String itemName = item.getJid().toString();
if (itemName.contains(_subDomain) && !itemName.equals(_subDomain)) {
......@@ -49,12 +46,12 @@ public class NonPersistantRosterProcessor extends AbstractRemoteRosterProcessor
roster.deleteRosterItem(item.getJid(), false);
}
}
} catch (Exception e) {
Log.debug("Execption occured when cleaning up the Roster.", e);
e.printStackTrace();
}
}
}
}
}
package org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.dom4j.Element;
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.remoteroster.RemoteRosterInterceptor;
import org.jivesoftware.openfire.roster.Roster;
import org.jivesoftware.openfire.roster.RosterItem;
import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.JiveGlobals;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
......@@ -42,36 +47,64 @@ public class ReceiveComponentUpdatesProcessor extends AbstractRemoteRosterProces
public void process(Packet packet) throws PacketRejectedException {
Log.debug("Processing packet in ClientToComponentUpdateProcessor for " + _mySubdomain);
IQ myPacket = (IQ) packet;
IQ response = IQ.createResultIQ(myPacket);
String to = myPacket.getTo().toString();
String username = getUsernameFromJid(to);
List<Node> nodes = findNodesInDocument(myPacket.getElement().getDocument(), "//roster:item");
for (Node n : nodes) {
Roster roster;
try {
roster = _rosterManager.getRoster(username);
String jid = n.valueOf("@jid");
String name = n.valueOf("@name");
if (jid.equals(myPacket.getFrom().toString())) {
// Do not add the component itself to the contact list
break;
String jid = n.valueOf("@jid");
String name = n.valueOf("@name");
String subvalue = n.valueOf("@subscription");
if(subvalue.equals("both")){
try {
if (jid.equals(myPacket.getFrom().toString())) {
// Do not add the component itself to the contact list
break;
}
roster = _rosterManager.getRoster(username);
List<String> grouplist = new ArrayList<String>();
List<Node> groupnodes = findNodesInDocument(n.getDocument(), "//roster:group");
for (Node ne : groupnodes) {
String groupName = ne.getText();
grouplist.add(groupName);
}
boolean rosterPersisten = JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", true);
Log.debug("Adding/Updating User " + jid + " to roster " + to);
try {
RosterItem item = roster.getRosterItem(new JID(jid));
item.setGroups(grouplist);
roster.updateRosterItem(item);
//dont send iq-result if just updating user
break;
} catch (UserNotFoundException exc) {
//Then we should add him!
}
RosterItem item = roster.createRosterItem(new JID(jid), name, grouplist, false, rosterPersisten);
item.setSubStatus(RosterItem.SUB_BOTH);
roster.updateRosterItem(item);
} catch (Exception e) {
Log.debug("Could not add user to Roster although no entry should exist..." + username, e);
e.printStackTrace();
}
List<String> grouplist = new ArrayList<String>();
List<Node> groupnodes = findNodesInDocument(n.getDocument(), "//roster:group");
for (Node ne : groupnodes) {
String groupName = ne.getText();
grouplist.add(groupName);
} else if (subvalue.equals("remove")){
try {
roster = _rosterManager.getRoster(username);
Log.debug("Removing contact " + username + " from contact list.");
roster.deleteRosterItem(new JID(jid), false);
} catch (UserNotFoundException e) {
Log.debug("Could not find user while cleaning up the roster in GoJara for user " + username, e);
response.setType(IQ.Type.error);
} catch (SharedGroupException e) {
// We should ignore this. External contacts cannot be in
// shared groups
}
boolean rosterPersisten = JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", true);
Log.debug("Adding user " + jid + " to roster " + to);
RosterItem item = roster.createRosterItem(new JID(jid), name, grouplist, false, rosterPersisten);
item.setSubStatus(RosterItem.SUB_BOTH);
roster.updateRosterItem(item);
} catch (Exception e) {
Log.debug("Could not add user to Roster " + username, e);
e.printStackTrace();
}
dispatchPacket(response);
}
}
}
......@@ -11,6 +11,7 @@ import org.jivesoftware.openfire.roster.Roster;
import org.jivesoftware.openfire.roster.RosterItem;
import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.JiveGlobals;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Packet;
......@@ -42,30 +43,33 @@ public class SendRosterProcessor extends AbstractRemoteRosterProcessor {
Log.debug("Processing packet in SendRosterProcessor for " + _componentName);
IQ myPacket = (IQ) packet;
String from = myPacket.getFrom().toString();
String username = getUsernameFromJid(from);
String user = myPacket.getTo().toString();
String username = getUsernameFromJid(user);
Roster roster;
try {
roster = _rosterManager.getRoster(username);
Collection<RosterItem> items = roster.getRosterItems();
sendRosterToComponent(packet, items);
} catch (UserNotFoundException e) {
e.printStackTrace();
if(JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false)){
try {
roster = _rosterManager.getRoster(username);
Collection<RosterItem> items = roster.getRosterItems();
sendRosterToComponent(myPacket, items);
} catch (UserNotFoundException e) {
e.printStackTrace();
}
} else {
sendEmptyRoster(myPacket);
}
}
private void sendRosterToComponent(Packet requestPacket, Collection<RosterItem> items) {
private void sendRosterToComponent(IQ requestPacket, Collection<RosterItem> items) {
Log.debug("Sending contacts from user " + requestPacket.getFrom().toString() + " to external Component");
IQ iq = (IQ) requestPacket;
IQ response = IQ.createResultIQ(iq);
IQ response = IQ.createResultIQ(requestPacket);
response.setTo(_componentName);
Element query = new DefaultElement("query");
for (RosterItem i : items) {
if (i.getJid().toString().contains(_componentName)) {
Log.debug("Roster exchange for external component " + _componentName + ". Sending user "
+ i.getJid().toString());
Element item = new DefaultElement("item");
Element item = new DefaultElement("item", null);
item.add(new DefaultAttribute("jid", i.getJid().toString()));
item.add(new DefaultAttribute("name", i.getNickname()));
item.add(new DefaultAttribute("subscription", "both"));
......@@ -78,8 +82,20 @@ public class SendRosterProcessor extends AbstractRemoteRosterProcessor {
}
}
query.addNamespace("", "jabber:iq:roster");
response.setChildElement(query);
dispatchPacket(response);
}
private void sendEmptyRoster(Packet requestPacket){
Log.debug("Sending nonpersistant-RemoteRosterResponse to external Component");
IQ iq = (IQ) requestPacket;
IQ response = IQ.createResultIQ(iq);
response.setTo(_componentName);
Element query = new DefaultElement("query");
query.addNamespace("", "jabber:iq:roster");
response.setChildElement(query);
dispatchPacket(response);
}
}
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