Commit 2877fba2 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[JM-770] Some mild fixes for MSN and beginnings of buddy list support.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@4625 b35dd754-fafc-0310-a699-88a17e54d16e
parent ed9be2d5
...@@ -20,11 +20,13 @@ import org.dom4j.Element; ...@@ -20,11 +20,13 @@ import org.dom4j.Element;
import org.dom4j.QName; import org.dom4j.QName;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.NotFoundException; import org.jivesoftware.util.NotFoundException;
import org.jivesoftware.wildfire.container.PluginManager;
import org.jivesoftware.wildfire.roster.Roster; import org.jivesoftware.wildfire.roster.Roster;
import org.jivesoftware.wildfire.roster.RosterItem; import org.jivesoftware.wildfire.roster.RosterItem;
import org.jivesoftware.wildfire.roster.RosterManager; import org.jivesoftware.wildfire.roster.RosterManager;
import org.jivesoftware.wildfire.user.UserNotFoundException; import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.wildfire.user.UserAlreadyExistsException; import org.jivesoftware.wildfire.user.UserAlreadyExistsException;
import org.jivesoftware.wildfire.XMPPServer;
import org.xmpp.component.Component; import org.xmpp.component.Component;
import org.xmpp.component.ComponentException; import org.xmpp.component.ComponentException;
import org.xmpp.component.ComponentManager; import org.xmpp.component.ComponentManager;
...@@ -148,7 +150,7 @@ public abstract class BaseTransport implements Component { ...@@ -148,7 +150,7 @@ public abstract class BaseTransport implements Component {
} }
} }
catch (Exception e) { catch (Exception e) {
Log.error("Error occured while processing packet: " + e.toString()); Log.error("Error occured while processing packet:", e);
} }
} }
...@@ -286,7 +288,7 @@ public abstract class BaseTransport implements Component { ...@@ -286,7 +288,7 @@ public abstract class BaseTransport implements Component {
} }
} }
catch (Exception e) { catch (Exception e) {
Log.error("Exception while processing packet: " + e.toString()); Log.error("Exception while processing packet: ", e);
} }
return reply; return reply;
...@@ -604,7 +606,7 @@ public abstract class BaseTransport implements Component { ...@@ -604,7 +606,7 @@ public abstract class BaseTransport implements Component {
IQ result = IQ.createResultIQ(packet); IQ result = IQ.createResultIQ(packet);
Element query = DocumentHelper.createElement(QName.get("query", IQ_VERSION)); Element query = DocumentHelper.createElement(QName.get("query", IQ_VERSION));
query.addElement("name").addText("Wildfire " + this.getDescription()); query.addElement("name").addText("Wildfire " + this.getDescription());
query.addElement("version").addText(this.getVersionString()); query.addElement("version").addText(XMPPServer.getInstance().getServerInfo().getVersion().getVersionString() + " - " + this.getVersionString());
query.addElement("os").addText(System.getProperty("os.name")); query.addElement("os").addText(System.getProperty("os.name"));
result.setChildElement(query); result.setChildElement(query);
reply.add(result); reply.add(result);
...@@ -677,11 +679,20 @@ public abstract class BaseTransport implements Component { ...@@ -677,11 +679,20 @@ public abstract class BaseTransport implements Component {
return componentManager; return componentManager;
} }
/**
* Retains the version string for later requests.
*/
private String versionString = null;
/** /**
* Returns the version string of the gateway. * Returns the version string of the gateway.
*/ */
public String getVersionString() { public String getVersionString() {
return "0.0.1"; if (versionString == null) {
PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
versionString = pluginManager.getVersion(pluginManager.getPlugin("gateway"));
}
return versionString;
} }
/** /**
......
...@@ -11,11 +11,18 @@ ...@@ -11,11 +11,18 @@
package org.jivesoftware.wildfire.gateway.protocols.msn; package org.jivesoftware.wildfire.gateway.protocols.msn;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.HashMap; import java.util.HashMap;
import org.hn.sleek.jmml.Contact;
import org.hn.sleek.jmml.ContactList;
import org.hn.sleek.jmml.IncomingMessageEvent; import org.hn.sleek.jmml.IncomingMessageEvent;
import org.hn.sleek.jmml.MessengerClientAdapter; import org.hn.sleek.jmml.MessengerClientAdapter;
import org.hn.sleek.jmml.MSNException;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.TransportBuddy;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.xmpp.packet.Presence;
/** /**
* MSN Listener Interface. * MSN Listener Interface.
...@@ -60,4 +67,79 @@ public class MSNListener extends MessengerClientAdapter { ...@@ -60,4 +67,79 @@ public class MSNListener extends MessengerClientAdapter {
msnSession.logOut(); msnSession.logOut();
} }
/**
* Notification of a contact that exists on user's contact list.
*
* @param contact Contact from contact list.
*/
public void contactReceived(Contact contact) {
Log.debug("Got MSN contact " + contact.toString());
try {
msnSession.getTransport().addOrUpdateRosterItem(msnSession.getJID(), msnSession.getTransport().convertIDToJID(contact.getUserName()), contact.getFriendlyName(), "MSN Transport");
}
catch (UserNotFoundException e) {
Log.error("Unable to find session associated with MSN session.");
}
}
/**
* Someone has added user to their contact list
*
* @param username Username that added this user.
*/
public void reverseListChanged(String username) {
Presence p = new Presence(Presence.Type.subscribed);
p.setTo(msnSession.getJID());
p.setFrom(msnSession.getTransport().convertIDToJID(username));
msnSession.getTransport().sendPacket(p);
}
/**
* The user's login has completed and was accepted.
*/
public void loginAccepted() {
Log.debug("MSN login accepted");
Presence p = new Presence();
p.setTo(msnSession.getJID());
p.setFrom(msnSession.getTransport().getJID());
msnSession.getTransport().sendPacket(p);
//try {
// msnSession.getManager().synchronizeContactList();
//}
//catch (MSNException e) {
// Log.error("Unable to sync MSN contact list:", e);
//}
syncUsers();
}
/**
* The user's login failed.
*/
public void loginError() {
// TODO: Handle this nicely
}
/**
* Syncs up the jabber contact list with the MSN one.
*/
public void syncUsers() {
//List<TransportBuddy> legacyusers = new ArrayList<TransportBuddy>();
//ContactList contactList = msnSession.getManager().getContactList();
//for (Contact c : contactList.getContacts()) {
// Log.debug("I found a contact for MSN!");
// //ArrayList groups = c.getGroups();
// //legacyusers.add(new TransportBuddy(c.getUserName(), c.getFriendlyName(), groups.get(0).toString()));
// legacyusers.add(new TransportBuddy(c.getUserName(), c.getFriendlyName(), "MSN Transport"));
// }
// try {
// msnSession.getTransport().syncLegacyRoster(msnSession.getJID(), legacyusers);
//}
//catch (UserNotFoundException e) {
// Log.error("Unable to sync MSN contact list for " + msnSession.getJID());
//}
return;
}
} }
...@@ -10,12 +10,18 @@ ...@@ -10,12 +10,18 @@
package org.jivesoftware.wildfire.gateway.protocols.msn; package org.jivesoftware.wildfire.gateway.protocols.msn;
import java.util.ArrayList;
import java.util.List;
import org.hn.sleek.jmml.Contact;
import org.hn.sleek.jmml.ContactList;
import org.hn.sleek.jmml.ContactStatus; import org.hn.sleek.jmml.ContactStatus;
import org.hn.sleek.jmml.MessengerServerManager; import org.hn.sleek.jmml.MessengerServerManager;
import org.hn.sleek.jmml.MSNException; import org.hn.sleek.jmml.MSNException;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.Registration; import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportBuddy;
import org.jivesoftware.wildfire.gateway.TransportSession; import org.jivesoftware.wildfire.gateway.TransportSession;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
...@@ -52,16 +58,18 @@ public class MSNSession extends TransportSession { ...@@ -52,16 +58,18 @@ public class MSNSession extends TransportSession {
public void logIn() { public void logIn() {
try { try {
msnManager.signIn(registration.getUsername(), registration.getPassword(), ContactStatus.ONLINE); msnManager.signIn(registration.getUsername(), registration.getPassword(), ContactStatus.ONLINE);
Presence p = new Presence(); Presence p = new Presence();
p.setTo(getJID()); p.setTo(getJID());
p.setFrom(getTransport().getJID()); p.setFrom(getTransport().getJID());
getTransport().sendPacket(p); getTransport().sendPacket(p);
msnManager.setStatus(ContactStatus.ONLINE); msnManager.setStatus(ContactStatus.ONLINE);
msnManager.setPrivacyMode(true); msnManager.setPrivacyMode(true);
msnManager.setReverseListBehaviour(true); msnManager.setReverseListBehaviour(true);
} }
catch (MSNException e) { catch (MSNException e) {
Log.error("MSN exception thrown while logging in: " + e.toString()); Log.error("MSN exception thrown while logging in:", e);
} }
} }
...@@ -77,7 +85,7 @@ public class MSNSession extends TransportSession { ...@@ -77,7 +85,7 @@ public class MSNSession extends TransportSession {
getTransport().sendPacket(p); getTransport().sendPacket(p);
} }
catch (MSNException e) { catch (MSNException e) {
Log.error("MSN exception thrown while logging out: " + e.toString()); Log.error("MSN exception thrown while logging out:", e);
} }
} }
...@@ -117,7 +125,7 @@ public class MSNSession extends TransportSession { ...@@ -117,7 +125,7 @@ public class MSNSession extends TransportSession {
msnManager.sendMessage(getTransport().convertJIDToID(jid), message); msnManager.sendMessage(getTransport().convertJIDToID(jid), message);
} }
catch (MSNException e) { catch (MSNException e) {
Log.error("MSN exception while sending message: " + e.toString()); Log.error("MSN exception while sending message:", e);
} }
} }
...@@ -130,4 +138,11 @@ public class MSNSession extends TransportSession { ...@@ -130,4 +138,11 @@ public class MSNSession extends TransportSession {
// TODO: yeah // TODO: yeah
} }
/**
* Retrieves the manager for this session.
*/
public MessengerServerManager getManager() {
return msnManager;
}
} }
...@@ -97,7 +97,7 @@ public class YahooSession extends TransportSession { ...@@ -97,7 +97,7 @@ public class YahooSession extends TransportSession {
Log.warn("Yahoo login failed for " + getJID()); Log.warn("Yahoo login failed for " + getJID());
} }
catch (IOException e) { catch (IOException e) {
Log.error("Yahoo login caused IO exception: " + e.toString()); Log.error("Yahoo login caused IO exception:", e);
} }
loggingIn = false; loggingIn = false;
} }
......
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