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