Commit 0444da04 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Back ported fix from 3.0 branch. JM-742 JM-726

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/branches/2_6_branch@4311 b35dd754-fafc-0310-a699-88a17e54d16e
parent 3e28caf3
...@@ -12,12 +12,13 @@ ...@@ -12,12 +12,13 @@
package org.jivesoftware.wildfire.privacy; package org.jivesoftware.wildfire.privacy;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.util.CacheSizes;
import org.jivesoftware.util.Cacheable;
import org.jivesoftware.wildfire.roster.Roster; import org.jivesoftware.wildfire.roster.Roster;
import org.jivesoftware.wildfire.roster.RosterItem; import org.jivesoftware.wildfire.roster.RosterItem;
import org.jivesoftware.wildfire.user.UserNotFoundException; import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.packet.*; import org.xmpp.packet.*;
import java.io.Serializable;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
...@@ -26,7 +27,7 @@ import java.util.Collections; ...@@ -26,7 +27,7 @@ import java.util.Collections;
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
class PrivacyItem implements Serializable, Comparable { class PrivacyItem implements Cacheable, Comparable {
private int order; private int order;
private boolean allow; private boolean allow;
...@@ -123,7 +124,7 @@ class PrivacyItem implements Serializable, Comparable { ...@@ -123,7 +124,7 @@ class PrivacyItem implements Serializable, Comparable {
* @return true if the packet to analyze matches the condition defined by this rule. * @return true if the packet to analyze matches the condition defined by this rule.
*/ */
boolean matchesCondition(Packet packet, Roster roster, JID userJID) { boolean matchesCondition(Packet packet, Roster roster, JID userJID) {
return matchesPacketSenderCondition(packet, roster) && return matchesPacketSenderCondition(packet, roster, userJID) &&
matchesPacketTypeCondition(packet, userJID); matchesPacketTypeCondition(packet, userJID);
} }
...@@ -131,25 +132,33 @@ class PrivacyItem implements Serializable, Comparable { ...@@ -131,25 +132,33 @@ class PrivacyItem implements Serializable, Comparable {
return allow; return allow;
} }
private boolean matchesPacketSenderCondition(Packet packet, Roster roster) { private boolean matchesPacketSenderCondition(Packet packet, Roster roster, JID userJID) {
if (type == null) { if (type == null) {
// This is the "fall-through" case // This is the "fall-through" case
return true; return true;
} }
boolean isPresence = packet.getClass().equals(Presence.class); boolean isPresence = packet.getClass().equals(Presence.class);
boolean incoming = true;
if (packet.getFrom() != null) {
incoming = !userJID.toBareJID().equals(packet.getFrom().toBareJID());
}
boolean matches = false; boolean matches = false;
if (isPresence && (filterEverything || filterPresence_out)) { if (isPresence && !incoming && (filterEverything || filterPresence_out)) {
// If this is an outgoing presence and we are filtering by outgoing presence // If this is an outgoing presence and we are filtering by outgoing presence
// notification then use the receipient of the packet in the analysis // notification then use the receipient of the packet in the analysis
matches = verifyJID(packet.getTo(), roster); matches = verifyJID(packet.getTo(), roster);
} }
if (!matches && (filterEverything || filterPresence_in || filterIQ || filterMessage)) { if (!matches && incoming &&
(filterEverything || filterPresence_in || filterIQ || filterMessage)) {
matches = verifyJID(packet.getFrom(), roster); matches = verifyJID(packet.getFrom(), roster);
} }
return matches; return matches;
} }
private boolean verifyJID(JID jid, Roster roster) { private boolean verifyJID(JID jid, Roster roster) {
if (jid == null) {
return false;
}
if (type == Type.jid) { if (type == Type.jid) {
if (jidValue.getResource() != null) { if (jidValue.getResource() != null) {
// Rule is filtering by exact resource match // Rule is filtering by exact resource match
...@@ -166,7 +175,7 @@ class PrivacyItem implements Serializable, Comparable { ...@@ -166,7 +175,7 @@ class PrivacyItem implements Serializable, Comparable {
} }
} }
else if (type == Type.group) { else if (type == Type.group) {
Collection<String> contactGroups = null; Collection<String> contactGroups;
try { try {
// Get the groups where the contact belongs // Get the groups where the contact belongs
RosterItem item = roster.getRosterItem(jid); RosterItem item = roster.getRosterItem(jid);
...@@ -225,6 +234,29 @@ class PrivacyItem implements Serializable, Comparable { ...@@ -225,6 +234,29 @@ class PrivacyItem implements Serializable, Comparable {
return false; return false;
} }
public int getCachedSize() {
// Approximate the size of the object in bytes by calculating the size
// of each field.
int size = 0;
size += CacheSizes.sizeOfObject(); // overhead of object
size += CacheSizes.sizeOfInt(); // order
size += CacheSizes.sizeOfBoolean(); // allow
//size += CacheSizes.sizeOfString(jidValue.toString()); // type
if (jidValue != null ) {
size += CacheSizes.sizeOfString(jidValue.toString()); // jidValue
}
//size += CacheSizes.sizeOfString(name); // subscriptionValue
if (groupValue != null) {
size += CacheSizes.sizeOfString(groupValue); // groupValue
}
size += CacheSizes.sizeOfBoolean(); // filterEverything
size += CacheSizes.sizeOfBoolean(); // filterIQ
size += CacheSizes.sizeOfBoolean(); // filterMessage
size += CacheSizes.sizeOfBoolean(); // filterPresence_in
size += CacheSizes.sizeOfBoolean(); // filterPresence_out
return size;
}
/** /**
* Type defines if the rule is based on JIDs, roster groups or presence subscription types. * Type defines if the rule is based on JIDs, roster groups or presence subscription types.
*/ */
...@@ -241,6 +273,6 @@ class PrivacyItem implements Serializable, Comparable { ...@@ -241,6 +273,6 @@ class PrivacyItem implements Serializable, Comparable {
* JID being analyzed should belong to a contact present in the owner's roster with * JID being analyzed should belong to a contact present in the owner's roster with
* the specified subscription status. * the specified subscription status.
*/ */
subscription; subscription
} }
} }
...@@ -13,6 +13,8 @@ package org.jivesoftware.wildfire.privacy; ...@@ -13,6 +13,8 @@ package org.jivesoftware.wildfire.privacy;
import org.dom4j.DocumentFactory; import org.dom4j.DocumentFactory;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.util.CacheSizes;
import org.jivesoftware.util.Cacheable;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.XMPPServer; import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.roster.Roster; import org.jivesoftware.wildfire.roster.Roster;
...@@ -20,7 +22,6 @@ import org.jivesoftware.wildfire.user.UserNotFoundException; ...@@ -20,7 +22,6 @@ import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
...@@ -37,7 +38,7 @@ import java.util.List; ...@@ -37,7 +38,7 @@ import java.util.List;
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class PrivacyList implements Serializable { public class PrivacyList implements Cacheable {
private JID userJID; private JID userJID;
private String name; private String name;
...@@ -158,6 +159,21 @@ public class PrivacyList implements Serializable { ...@@ -158,6 +159,21 @@ public class PrivacyList implements Serializable {
Collections.sort(items); Collections.sort(items);
} }
public int getCachedSize() {
// Approximate the size of the object in bytes by calculating the size
// of each field.
int size = 0;
size += CacheSizes.sizeOfObject(); // overhead of object
size += CacheSizes.sizeOfString(userJID.toString()); // userJID
size += CacheSizes.sizeOfString(name); // name
size += CacheSizes.sizeOfBoolean(); // isDefault
size += CacheSizes.sizeOfCollection(items); // items of the list
if (roster != null) {
size += roster.getCachedSize(); // add size of roster
}
return size;
}
public int hashCode() { public int hashCode() {
return name.hashCode(); return name.hashCode();
} }
......
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