Commit ae0aba65 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Fixed so that only sessions whose presences are available are eligible for...

Fixed so that only sessions whose presences are available are eligible for receiving messages. JM-116


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@853 b35dd754-fafc-0310-a699-88a17e54d16e
parent 8f8909e0
...@@ -93,13 +93,9 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo { ...@@ -93,13 +93,9 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo {
// This is a workaround. Since we don't want to have an incorrect TO attribute // This is a workaround. Since we don't want to have an incorrect TO attribute
// value we need to clean up the TO attribute and send directly the response. // value we need to clean up the TO attribute and send directly the response.
// The TO attribute will contain an incorrect value since we are setting a fake // The TO attribute will contain an incorrect value since we are setting a fake
// JID until the user actually authenticates with the server. We need to send // JID until the user actually authenticates with the server.
// the response directly since SocketPacketWriterHandler requires a TO or FROM
// attribute which this response doesn't have.
if (session.getStatus() != Session.STATUS_AUTHENTICATED) { if (session.getStatus() != Session.STATUS_AUTHENTICATED) {
response.setTo((JID)null); response.setTo((JID)null);
session.getConnection().deliver(response);
return null;
} }
} }
// Otherwise set query // Otherwise set query
...@@ -138,7 +134,10 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo { ...@@ -138,7 +134,10 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo {
response = IQ.createResultIQ(packet); response = IQ.createResultIQ(packet);
response.setError(PacketError.Condition.not_authorized); response.setError(PacketError.Condition.not_authorized);
} }
deliverer.deliver(response); // Send the response directly since we want to be sure that we are sending it back
// to the correct session. Any other session of the same user but with different
// resource is incorrect.
session.getConnection().deliver(response);
} }
catch (Exception e) { catch (Exception e) {
Log.error("Error handling authentication IQ packet", e); Log.error("Error handling authentication IQ packet", e);
......
...@@ -81,7 +81,9 @@ public class SessionImpl implements Session { ...@@ -81,7 +81,9 @@ public class SessionImpl implements Session {
this.serverName = serverName; this.serverName = serverName;
String id = streamID.getID(); String id = streamID.getID();
this.address = new JID(null, serverName, id); this.address = new JID(null, serverName, id);
// Set an unavailable initial presence
presence = new Presence(); presence = new Presence();
presence.setType(Presence.Type.unavailable);
this.sessionManager = SessionManager.getInstance(); this.sessionManager = SessionManager.getInstance();
...@@ -158,7 +160,20 @@ public class SessionImpl implements Session { ...@@ -158,7 +160,20 @@ public class SessionImpl implements Session {
public Presence setPresence(Presence presence) { public Presence setPresence(Presence presence) {
Presence oldPresence = this.presence; Presence oldPresence = this.presence;
this.presence = presence; this.presence = presence;
if (oldPresence.getPriority() != this.presence.getPriority()) { if (oldPresence.isAvailable() && !this.presence.isAvailable()) {
// The client is no longer available
sessionManager.sessionUnavailable(this);
// Mark that the session is no longer initialized. This means that if the user sends
// an available presence again the session will be initialized again thus receiving
// offline messages and offline presence subscription requests
setInitialized(false);
}
else if (!oldPresence.isAvailable() && this.presence.isAvailable()) {
// The client is available
sessionManager.sessionAvailable(this);
}
else if (oldPresence.getPriority() != this.presence.getPriority()) {
// The client has changed the priority of his presence
sessionManager.changePriority(getAddress(), this.presence.getPriority()); sessionManager.changePriority(getAddress(), this.presence.getPriority());
} }
return oldPresence; return oldPresence;
......
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