Commit 51af2408 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[GATE-58] Working on some 'nicer' handling of login status.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@5486 b35dd754-fafc-0310-a699-88a17e54d16e
parent b50e2f16
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.gateway;
/**
* An enumeration for different login statuses.
*
* This represents a progression of login statuses to a legacy network.
*
* @author Daniel Henninger
*/
public enum TransportLoginStatus {
/**
* Not logged in
*/
LOGGED_OUT,
/**
* Currently logging in
*/
LOGGING_IN,
/**
* Logged in
*/
LOGGED_IN,
/**
* Logging out
*/
LOGGING_OUT
}
......@@ -82,6 +82,11 @@ public abstract class TransportSession implements Runnable {
*/
public boolean validSession = true;
/**
* The current login status on the legacy network.
*/
public TransportLoginStatus loginStatus = TransportLoginStatus.LOGGED_OUT;
/**
* Associates a resource with the session, and tracks it's priority.
*/
......@@ -221,6 +226,27 @@ public abstract class TransportSession implements Runnable {
return (resources.containsValue(resource));
}
/**
* Updates the login status.
*/
public void setLoginStatus(TransportLoginStatus status) {
loginStatus = status;
}
/**
* Retrieves the current login status.
*/
public TransportLoginStatus getLoginStatus() {
return loginStatus;
}
/**
* Returns true only if we are completely logged in.
*/
public Boolean isLoggedIn() {
return (loginStatus == TransportLoginStatus.LOGGED_IN);
}
/**
* Handles monitoring of whether session is still valid.
*/
......@@ -243,13 +269,6 @@ public abstract class TransportSession implements Runnable {
*/
public abstract void updateStatus(PresenceType presenceType, String verboseStatus);
/**
* Is the legacy service account logged in?
*
* @return True or false if the legacy account is logged in.
*/
public abstract Boolean isLoggedIn();
/**
* Adds a legacy contact to the legacy service.
*
......
......@@ -19,6 +19,7 @@ import org.xmpp.packet.Presence;
import org.xmpp.packet.JID;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.PresenceType;
import org.jivesoftware.wildfire.gateway.TransportLoginStatus;
import java.util.*;
......@@ -74,6 +75,7 @@ public class IRCListener implements IRCEventListener {
getSession().getTransport().sendPacket(p);
statusCheck = new StatusCheck();
timer.schedule(statusCheck, timerInterval, timerInterval);
getSession().setLoginStatus(TransportLoginStatus.LOGGED_IN);
}
public void onDisconnected() {
......@@ -84,6 +86,7 @@ public class IRCListener implements IRCEventListener {
getSession().getTransport().sendPacket(p);
getSession().getConnection().close();
timer.cancel();
getSession().setLoginStatus(TransportLoginStatus.LOGGED_OUT);
}
public void onError(String string) {
......@@ -184,6 +187,7 @@ public class IRCListener implements IRCEventListener {
p.setFrom(getSession().getTransport().getJID());
getSession().getTransport().sendPacket(p);
getSession().getConnection().close();
getSession().setLoginStatus(TransportLoginStatus.LOGGED_OUT);
}
public void onReply(int i, String string, String string1) {
......
......@@ -92,6 +92,7 @@ public class IRCSession extends TransportSession {
* @param verboseStatus Initial full status information.
*/
public void logIn(PresenceType presenceType, String verboseStatus) {
setLoginStatus(TransportLoginStatus.LOGGED_IN);
try {
conn.connect();
}
......@@ -104,8 +105,10 @@ public class IRCSession extends TransportSession {
* Logs the session out of IRC.
*/
public void logOut() {
setLoginStatus(TransportLoginStatus.LOGGING_OUT);
ircListener.setSilenced(true);
conn.doQuit();
setLoginStatus(TransportLoginStatus.LOGGED_OUT);
}
/**
......@@ -164,13 +167,6 @@ public class IRCSession extends TransportSession {
}
}
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#isLoggedIn()
*/
public Boolean isLoggedIn() {
return conn.isConnected();
}
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#addContact(org.jivesoftware.wildfire.roster.RosterItem)
*/
......
......@@ -11,6 +11,7 @@
package org.jivesoftware.wildfire.gateway.protocols.msn;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.TransportLoginStatus;
import org.xmpp.packet.Message;
import org.xmpp.packet.Presence;
import net.sf.jml.event.MsnAdapter;
......@@ -96,7 +97,7 @@ public class MSNListener extends MsnAdapter {
*/
public void loginCompleted(MsnMessenger messenger) {
msnSession.getRegistration().setLastLogin(new Date());
msnSession.setLoginStatus(true);
msnSession.setLoginStatus(TransportLoginStatus.LOGGED_IN);
}
/**
......
......@@ -12,10 +12,7 @@ package org.jivesoftware.wildfire.gateway.protocols.msn;
import net.sf.jml.*;
import net.sf.jml.impl.MsnMessengerFactory;
import org.jivesoftware.wildfire.gateway.PresenceType;
import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession;
import org.jivesoftware.wildfire.gateway.TransportBuddy;
import org.jivesoftware.wildfire.gateway.*;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.wildfire.roster.RosterItem;
import org.jivesoftware.util.Log;
......@@ -66,11 +63,6 @@ public class MSNSession extends TransportSession {
*/
private ConcurrentHashMap<String,MsnGroup> msnGroups = new ConcurrentHashMap<String,MsnGroup>();
/**
* Login status
*/
private boolean loginStatus = false;
/**
* Log in to MSN.
*
......@@ -78,6 +70,7 @@ public class MSNSession extends TransportSession {
* @param verboseStatus Long representation of status.
*/
public void logIn(PresenceType presenceType, String verboseStatus) {
setLoginStatus(TransportLoginStatus.LOGGING_IN);
if (!this.isLoggedIn()) {
msnMessenger.getOwner().setInitStatus(((MSNTransport)getTransport()).convertJabStatusToMSN(presenceType));
msnMessenger.setLogIncoming(false);
......@@ -91,6 +84,7 @@ public class MSNSession extends TransportSession {
* Log out of MSN.
*/
public void logOut() {
setLoginStatus(TransportLoginStatus.LOGGING_OUT);
if (this.isLoggedIn()) {
msnMessenger.logout();
}
......@@ -98,7 +92,7 @@ public class MSNSession extends TransportSession {
p.setTo(getJID());
p.setFrom(getTransport().getJID());
getTransport().sendPacket(p);
loginStatus = false;
setLoginStatus(TransportLoginStatus.LOGGED_OUT);
}
/**
......@@ -108,20 +102,6 @@ public class MSNSession extends TransportSession {
return msnMessenger;
}
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#isLoggedIn()
*/
public Boolean isLoggedIn() {
return loginStatus;
}
/**
* Sets login status flag (am i logged in or not)
*/
public void setLoginStatus(Boolean status) {
loginStatus = status;
}
/**
* Records information about a person on the user's contact list.
*/
......
......@@ -28,6 +28,8 @@ import java.util.Arrays;
import java.util.List;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.TransportLoginStatus;
import org.xmpp.packet.Presence;
/**
* Handles BOS related packets.
......@@ -112,6 +114,13 @@ public class BOSConnection extends BasicFlapConnection {
if (sdc.getLastModDate() != 0) {
request(new ActivateSsiCmd());
clientReady();
Presence p = new Presence();
p.setTo(oscarSession.getJID());
p.setFrom(oscarSession.getTransport().getJID());
oscarSession.getTransport().sendPacket(p);
oscarSession.setLoginStatus(TransportLoginStatus.LOGGED_IN);
oscarSession.gotCompleteSSI();
}
}
......
......@@ -29,10 +29,7 @@ import net.kano.joscar.snaccmd.CapabilityBlock;
import net.kano.joscar.ssiitem.BuddyItem;
import net.kano.joscar.ssiitem.GroupItem;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.PresenceType;
import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportBuddy;
import org.jivesoftware.wildfire.gateway.TransportSession;
import org.jivesoftware.wildfire.gateway.*;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.wildfire.roster.RosterItem;
import org.xmpp.packet.JID;
......@@ -65,7 +62,6 @@ public class OSCARSession extends TransportSession {
private BOSConnection bosConn = null;
private Set<ServiceConnection> services = new HashSet<ServiceConnection>();
private Boolean loggedIn = false;
private PresenceType presenceType = null;
private String verboseStatus = null;
......@@ -78,39 +74,31 @@ public class OSCARSession extends TransportSession {
private Integer highestGroupId = -1;
public void logIn(PresenceType presenceType, String verboseStatus) {
setLoginStatus(TransportLoginStatus.LOGGING_IN);
if (!isLoggedIn()) {
LoginConnection loginConn = new LoginConnection(new ConnDescriptor("login.oscar.aol.com", 5190), this);
loginConn.connect();
loggedIn = true;
Presence p = new Presence();
p.setTo(getJID());
p.setFrom(getTransport().getJID());
getTransport().sendPacket(p);
this.presenceType = presenceType;
this.verboseStatus = verboseStatus;
} else {
}
else {
Log.warn(this.jid + " is already logged in");
}
}
public Boolean isLoggedIn() {
return loggedIn;
}
public synchronized void logOut() {
setLoginStatus(TransportLoginStatus.LOGGING_OUT);
if (isLoggedIn()) {
if (bosConn != null) {
bosConn.disconnect();
}
loggedIn = false;
Presence p = new Presence(Presence.Type.unavailable);
p.setTo(getJID());
p.setFrom(getTransport().getJID());
getTransport().sendPacket(p);
}
setLoginStatus(TransportLoginStatus.LOGGED_OUT);
}
/**
......@@ -178,12 +166,12 @@ public class OSCARSession extends TransportSession {
// buddies.remove(""+buddy.getGroupId()+"."+buddy.getId());
}
else if (!grouplist.contains(groups.get(buddy.getGroupId()).getGroupName())) {
Log.debug("Removing "+buddy+" because not in list of groups");
request(new DeleteItemsCmd(buddy.toSsiItem()));
buddies.remove(""+buddy.getGroupId()+"."+buddy.getId());
// Log.debug("Removing "+buddy+" because not in list of groups");
// request(new DeleteItemsCmd(buddy.toSsiItem()));
// buddies.remove(""+buddy.getGroupId()+"."+buddy.getId());
}
else {
if (!buddy.getAlias().equals(nickname)) {
if (buddy.getAlias() == null || !buddy.getAlias().equals(nickname)) {
buddy.setAlias(nickname);
request(new ModifyItemsCmd(buddy.toSsiItem()));
}
......
......@@ -61,16 +61,6 @@ public class YahooSession extends TransportSession {
*/
private PseudoRoster pseudoRoster;
/**
* Are we logged in?
*/
private Boolean loggedIn = false;
/**
* Are we trying to log in right now?
*/
private Boolean loggingIn = false;
/**
* How many attempts have been made so far?
*/
......@@ -101,14 +91,14 @@ public class YahooSession extends TransportSession {
this.presenceType = presenceType;
this.verboseStatus = verboseStatus;
final PresenceType pType = presenceType;
if (!isLoggedIn() && !loggingIn && loginAttempts <= 3) {
loggingIn = true;
if (!isLoggedIn() && getLoginStatus() != TransportLoginStatus.LOGGING_IN && loginAttempts <= 3) {
setLoginStatus(TransportLoginStatus.LOGGING_IN);
new Thread() {
public void run() {
try {
loginAttempts++;
yahooSession.login(registration.getUsername(), registration.getPassword());
loggedIn = true;
setLoginStatus(TransportLoginStatus.LOGGED_IN);
Presence p = new Presence();
p.setTo(getJID());
......@@ -128,7 +118,7 @@ public class YahooSession extends TransportSession {
catch (IOException e) {
Log.error("Yahoo login caused IO exception:", e);
}
loggingIn = false;
setLoginStatus(TransportLoginStatus.LOGGED_OUT);
}
}.run();
}
......@@ -138,9 +128,8 @@ public class YahooSession extends TransportSession {
* Log out of Yahoo.
*/
public void logOut() {
loggedIn = false;
loggingIn = false;
loginAttempts = 0;
setLoginStatus(TransportLoginStatus.LOGGED_OUT);
loginAttempts = 0;
try {
yahooSession.logout();
}
......@@ -154,13 +143,6 @@ public class YahooSession extends TransportSession {
getTransport().sendPacket(p);
}
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#isLoggedIn()
*/
public Boolean isLoggedIn() {
return loggedIn;
}
/**
* Syncs up the yahoo roster with the jabber roster.
*/
......@@ -329,7 +311,12 @@ public class YahooSession extends TransportSession {
*/
public void updateStatus(PresenceType presenceType, String verboseStatus) {
try {
yahooSession.setStatus(((YahooTransport)getTransport()).convertJabStatusToYahoo(presenceType));
if (isLoggedIn()) {
yahooSession.setStatus(((YahooTransport)getTransport()).convertJabStatusToYahoo(presenceType));
}
else {
// TODO: Should we consider auto-logging back in?
}
}
catch (Exception e) {
Log.error("Unable to set Yahoo Status:", e);
......
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