1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

Make IQReplyFilter aware of user-less connection state

SMACK-533
This commit is contained in:
Florian Schmaus 2014-03-09 15:36:02 +01:00
parent a7ec0338bc
commit 1f2183605c

View file

@ -80,7 +80,13 @@ public class IQReplyFilter implements PacketFilter {
*/ */
public IQReplyFilter(IQ iqPacket, Connection conn) { public IQReplyFilter(IQ iqPacket, Connection conn) {
to = iqPacket.getTo(); to = iqPacket.getTo();
if (conn.getUser() == null) {
// We have not yet been assigned a username, this can happen if the connection is
// in an early stage, i.e. when performing the SASL auth.
local = null;
} else {
local = conn.getUser().toLowerCase(); local = conn.getUser().toLowerCase();
}
server = conn.getServiceName().toLowerCase(); server = conn.getServiceName().toLowerCase();
packetId = iqPacket.getPacketID(); packetId = iqPacket.getPacketID();
@ -89,10 +95,11 @@ public class IQReplyFilter implements PacketFilter {
OrFilter fromFilter = new OrFilter(); OrFilter fromFilter = new OrFilter();
fromFilter.addFilter(FromMatchesFilter.createFull(to)); fromFilter.addFilter(FromMatchesFilter.createFull(to));
if (to == null) { if (to == null) {
if (local != null)
fromFilter.addFilter(FromMatchesFilter.createBare(local)); fromFilter.addFilter(FromMatchesFilter.createBare(local));
fromFilter.addFilter(FromMatchesFilter.createFull(server)); fromFilter.addFilter(FromMatchesFilter.createFull(server));
} }
else if (to.toLowerCase().equals(StringUtils.parseBareAddress(local))) { else if (local != null && to.toLowerCase().equals(StringUtils.parseBareAddress(local))) {
fromFilter.addFilter(FromMatchesFilter.createFull(null)); fromFilter.addFilter(FromMatchesFilter.createFull(null));
} }
filter = new AndFilter(fromFilter, iqFilter, idFilter); filter = new AndFilter(fromFilter, iqFilter, idFilter);