}
public void route(Packet packet) {
Set<String> remoteServers = new HashSet<String>();
List<String> targets = new ArrayList<String>();
Packet localBroadcast = packet.createCopy();
Element addresses = getAddresses(localBroadcast);
String localDomain = "@" + server.getServerInfo().getXMPPDomain();
// Build the <addresses> element to be included for local users and identify
// remote domains that should receive the packet too
for (Iterator it=addresses.elementIterator("address");it.hasNext();) {
Element address = (Element) it.next();
// Skip addresses of type noreply since they don't have any address
if (Type.noreply.toString().equals(address.attributeValue("type"))) {
continue;
}
String jid = address.attributeValue("jid");
// Only send to local users and if packet has not already been delivered
if (jid.contains(localDomain) && address.attributeValue("delivered") == null) {
targets.add(jid);
}
else if (!jid.contains(localDomain)) {
remoteServers.add(new JID(jid).getDomain());
}
// Set as delivered
address.addAttribute("delivered", "true");
// Remove bcc addresses
if (Type.bcc.toString().equals(address.attributeValue("type"))) {
it.remove();
}
}
// Send the packet to local target users
for (String jid : targets) {
localBroadcast.setTo(jid);
packetRouter.route(localBroadcast);
}
// Keep a registry of packets that should be sent to remote domains.
for (String domain : remoteServers) {