Commit 386a6661 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[JM-761] [JM-769] Bug fixes, still working out session manager issues.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4509 b35dd754-fafc-0310-a699-88a17e54d16e
parent 2cb2f80b
...@@ -134,6 +134,12 @@ public abstract class BaseTransport implements Component { ...@@ -134,6 +134,12 @@ public abstract class BaseTransport implements Component {
else { else {
Log.info("Received an unhandled packet: " + packet.toString()); Log.info("Received an unhandled packet: " + packet.toString());
} }
if (reply.size() > 0) {
for (Packet p : reply) {
this.sendPacket(p);
}
}
} }
catch (Exception e) { catch (Exception e) {
Log.error("Error occured while processing packet: " + e.toString()); Log.error("Error occured while processing packet: " + e.toString());
...@@ -150,12 +156,15 @@ public abstract class BaseTransport implements Component { ...@@ -150,12 +156,15 @@ public abstract class BaseTransport implements Component {
JID from = packet.getFrom(); JID from = packet.getFrom();
JID to = packet.getTo(); JID to = packet.getTo();
Log.debug("Got Message packet: " + packet.toString());
try { try {
TransportSession session = sessionManager.getSession(from); TransportSession session = sessionManager.getSession(from);
session.sendMessage(to, packet.getBody()); session.sendMessage(to, packet.getBody());
} }
catch (NotFoundException e) { catch (NotFoundException e) {
// TODO: Should return an error packet here // TODO: Should return an error packet here
Log.debug("Unable to find session.");
} }
return reply; return reply;
...@@ -171,17 +180,20 @@ public abstract class BaseTransport implements Component { ...@@ -171,17 +180,20 @@ public abstract class BaseTransport implements Component {
JID from = packet.getFrom(); JID from = packet.getFrom();
JID to = packet.getTo(); JID to = packet.getTo();
Log.debug("Got Presence packet: " + packet.toString());
if (packet.getType() == Presence.Type.error) { if (packet.getType() == Presence.Type.error) {
// We don't want to do anything with this. Ignore it. // We don't want to do anything with this. Ignore it.
return reply; return reply;
} }
try { try {
TransportSession session = sessionManager.getSession(from);
if (to.getNode() == null) { if (to.getNode() == null) {
Log.debug("Message to gateway");
Collection<Registration> registrations = registrationManager.getRegistrations(from, this.transportType); Collection<Registration> registrations = registrationManager.getRegistrations(from, this.transportType);
if (!registrations.iterator().hasNext()) { if (!registrations.iterator().hasNext()) {
// User is not registered with us. // User is not registered with us.
Log.debug("Unable to find registration.");
return reply; return reply;
} }
Registration registration = registrations.iterator().next(); Registration registration = registrations.iterator().next();
...@@ -189,27 +201,44 @@ public abstract class BaseTransport implements Component { ...@@ -189,27 +201,44 @@ public abstract class BaseTransport implements Component {
// This packet is to the transport itself. // This packet is to the transport itself.
if (packet.getType() == null) { if (packet.getType() == null) {
// User has come online. // User has come online.
if (session == null) { Log.debug("Got available.");
TransportSession session = null;
try {
session = sessionManager.getSession(from);
// TODO: This can also represent a status change.
}
catch (NotFoundException e) {
session = this.registrationLoggedIn(registration); session = this.registrationLoggedIn(registration);
sessionManager.storeSession(registration.getJID(), session); //sessionManager.storeSession(registration.getJID(), session);
sessionManager.storeSession(from, session);
} }
// TODO: This can also represent a status change.
} }
else if (packet.getType() == Presence.Type.unavailable) { else if (packet.getType() == Presence.Type.unavailable) {
// User has gone offline. // User has gone offline.
if (session != null && session.isLoggedIn()) { Log.debug("Got unavailable.");
this.registrationLoggedOut(session); TransportSession session = null;
try {
session = sessionManager.getSession(from);
if (session.isLoggedIn()) {
this.registrationLoggedOut(session);
}
//sessionManager.removeSession(registration.getJID());
sessionManager.removeSession(from);
}
catch (NotFoundException e) {
Log.debug("Ignoring unavailable presence for inactive seession.");
} }
sessionManager.removeSession(registration.getJID());
} }
else { else {
Log.debug("Ignoring this packet.");
// Anything else we will ignore for now. // Anything else we will ignore for now.
} }
} }
else { else {
Log.debug("Message to user at gateway");
// This packet is to a user at the transport. // This packet is to a user at the transport.
TransportSession session = sessionManager.getSession(from);
if (session == null) { if (session == null) {
// We don't have a session, so stop here. // We don't have a session, so stop here.
// TODO: maybe return an error? // TODO: maybe return an error?
...@@ -228,7 +257,7 @@ public abstract class BaseTransport implements Component { ...@@ -228,7 +257,7 @@ public abstract class BaseTransport implements Component {
} }
} }
catch (NotFoundException e) { catch (NotFoundException e) {
// We don't care, we account for this later. Log.error("Exception while processing packet: " + e.toString());
} }
return reply; return reply;
...@@ -242,13 +271,15 @@ public abstract class BaseTransport implements Component { ...@@ -242,13 +271,15 @@ public abstract class BaseTransport implements Component {
private List<Packet> processPacket(IQ packet) { private List<Packet> processPacket(IQ packet) {
List<Packet> reply = new ArrayList<Packet>(); List<Packet> reply = new ArrayList<Packet>();
Log.debug("Got IQ packet: " + packet.toString());
if (packet.getType() == IQ.Type.error) { if (packet.getType() == IQ.Type.error) {
// Lets not start a loop. Ignore. // Lets not start a loop. Ignore.
return reply; return reply;
} }
Element child = packet.getChildElement();
String xmlns = null; String xmlns = null;
Element child = (packet).getChildElement();
if (child != null) { if (child != null) {
xmlns = child.getNamespaceURI(); xmlns = child.getNamespaceURI();
} }
...@@ -256,18 +287,25 @@ public abstract class BaseTransport implements Component { ...@@ -256,18 +287,25 @@ public abstract class BaseTransport implements Component {
if (xmlns == null) { if (xmlns == null) {
// No namespace defined. // No namespace defined.
// TODO: Should we return an error? // TODO: Should we return an error?
Log.debug("No XMLNS");
return reply; return reply;
} }
if (xmlns.equals(DISCO_INFO)) { if (xmlns.equals(DISCO_INFO)) {
Log.debug("Matched Disco Info");
reply.addAll(handleDiscoInfo(packet)); reply.addAll(handleDiscoInfo(packet));
} }
else if (xmlns.equals(DISCO_ITEMS)) { else if (xmlns.equals(DISCO_ITEMS)) {
Log.debug("Matched Disco Items");
reply.addAll(handleDiscoItems(packet)); reply.addAll(handleDiscoItems(packet));
} }
else if (xmlns.equals(IQ_REGISTER)) { else if (xmlns.equals(IQ_REGISTER)) {
Log.debug("Matched IQ Register");
reply.addAll(handleIQRegister(packet)); reply.addAll(handleIQRegister(packet));
} }
else {
Log.debug("Matched nothing");
}
return reply; return reply;
} }
...@@ -476,7 +514,14 @@ public abstract class BaseTransport implements Component { ...@@ -476,7 +514,14 @@ public abstract class BaseTransport implements Component {
} }
/** /**
* Returns the name(jid) of the transport. * Returns the jid of the transport.
*/
public JID getJID() {
return this.jid;
}
/**
* Returns the name (type) of the transport.
*/ */
public String getName() { public String getName() {
return transportType.toString(); return transportType.toString();
......
...@@ -59,15 +59,15 @@ public class GatewayPlugin implements Plugin { ...@@ -59,15 +59,15 @@ public class GatewayPlugin implements Plugin {
componentManager = ComponentManagerFactory.getComponentManager(); componentManager = ComponentManagerFactory.getComponentManager();
/* Set up AIM transport. */ /* Set up AIM transport. */
transports.put("aim", new TransportInstance(TransportType.aim, "AIM Transport", "org.jivesoftware.wildfire.gateway.protocols.oscar.OSCARGateway", componentManager)); transports.put("aim", new TransportInstance(TransportType.aim, "AIM Transport", "org.jivesoftware.wildfire.gateway.protocols.oscar.OSCARTransport", componentManager));
maybeStartService("aim"); maybeStartService("aim");
/* Set up ICQ transport. */ /* Set up ICQ transport. */
transports.put("icq", new TransportInstance(TransportType.icq, "ICQ Transport", "org.jivesoftware.wildfire.gateway.protocols.oscar.OSCARGateway", componentManager)); transports.put("icq", new TransportInstance(TransportType.icq, "ICQ Transport", "org.jivesoftware.wildfire.gateway.protocols.oscar.OSCARTransport", componentManager));
maybeStartService("icq"); maybeStartService("icq");
/* Set up Yahoo transport. */ /* Set up Yahoo transport. */
transports.put("yahoo", new TransportInstance(TransportType.yahoo, "Yahoo! Transport", "org.jivesoftware.wildfire.gateway.protocols.yahoo.YahooGateway", componentManager)); transports.put("yahoo", new TransportInstance(TransportType.yahoo, "Yahoo! Transport", "org.jivesoftware.wildfire.gateway.protocols.yahoo.YahooTransport", componentManager));
maybeStartService("yahoo"); maybeStartService("yahoo");
} }
......
...@@ -15,6 +15,7 @@ import org.jivesoftware.util.Log; ...@@ -15,6 +15,7 @@ import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.Registration; import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession; import org.jivesoftware.wildfire.gateway.TransportSession;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
import ymsg.network.LoginRefusedException; import ymsg.network.LoginRefusedException;
import ymsg.network.Session; import ymsg.network.Session;
...@@ -73,6 +74,11 @@ public class YahooSession extends TransportSession { ...@@ -73,6 +74,11 @@ public class YahooSession extends TransportSession {
loginAttempts++; loginAttempts++;
yahooSession.login(registration.getUsername(), registration.getPassword()); yahooSession.login(registration.getUsername(), registration.getPassword());
loggedIn = true; loggedIn = true;
Presence p = new Presence();
p.setTo(registration.getJID());
p.setFrom(getTransport().getJID());
getTransport().sendPacket(p);
} }
catch (LoginRefusedException e) { catch (LoginRefusedException e) {
yahooSession.reset(); yahooSession.reset();
...@@ -101,6 +107,10 @@ public class YahooSession extends TransportSession { ...@@ -101,6 +107,10 @@ public class YahooSession extends TransportSession {
loggedIn = false; loggedIn = false;
loggingIn = false; loggingIn = false;
loginAttempts = 0; loginAttempts = 0;
Presence p = new Presence(Presence.Type.unavailable);
p.setTo(registration.getJID());
p.setFrom(getTransport().getJID());
getTransport().sendPacket(p);
} }
/** /**
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
package org.jivesoftware.wildfire.gateway.protocols.yahoo; package org.jivesoftware.wildfire.gateway.protocols.yahoo;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.BaseTransport; import org.jivesoftware.wildfire.gateway.BaseTransport;
import org.jivesoftware.wildfire.gateway.Registration; import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession; import org.jivesoftware.wildfire.gateway.TransportSession;
...@@ -30,6 +31,7 @@ public class YahooTransport extends BaseTransport { ...@@ -30,6 +31,7 @@ public class YahooTransport extends BaseTransport {
* @param registration Registration information to be used to log in. * @param registration Registration information to be used to log in.
*/ */
public TransportSession registrationLoggedIn(Registration registration) { public TransportSession registrationLoggedIn(Registration registration) {
Log.debug("Logging in to Yahoo gateway.");
TransportSession session = new YahooSession(registration, this); TransportSession session = new YahooSession(registration, this);
session.logIn(); session.logIn();
return session; return session;
...@@ -41,6 +43,7 @@ public class YahooTransport extends BaseTransport { ...@@ -41,6 +43,7 @@ public class YahooTransport extends BaseTransport {
* @param session The session to be disconnected. * @param session The session to be disconnected.
*/ */
public void registrationLoggedOut(TransportSession session) { public void registrationLoggedOut(TransportSession session) {
Log.debug("Logging out of Yahoo gateway.");
session.logOut(); session.logOut();
} }
......
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