Commit 0375bf46 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

Converted to JML, can log in, but not particularly functional yet. "it's a start"

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@4892 b35dd754-fafc-0310-a699-88a17e54d16e
parent 65c078b1
...@@ -10,15 +10,14 @@ ...@@ -10,15 +10,14 @@
package org.jivesoftware.wildfire.gateway.protocols.msn; package org.jivesoftware.wildfire.gateway.protocols.msn;
import org.hn.sleek.jmml.Contact;
import org.hn.sleek.jmml.ContactChangeEvent;
import org.hn.sleek.jmml.ContactStatus;
import org.hn.sleek.jmml.IncomingMessageEvent;
import org.hn.sleek.jmml.MessengerClientAdapter;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
import net.sf.jml.event.MsnAdapter;
import net.sf.jml.MsnSwitchboard;
import net.sf.jml.MsnContact;
import net.sf.jml.MsnMessenger;
import net.sf.jml.message.MsnInstantMessage;
/** /**
* MSN Listener Interface. * MSN Listener Interface.
...@@ -28,7 +27,7 @@ import org.xmpp.packet.Presence; ...@@ -28,7 +27,7 @@ import org.xmpp.packet.Presence;
* *
* @author Daniel Henninger * @author Daniel Henninger
*/ */
public class MSNListener extends MessengerClientAdapter { public class MSNListener extends MsnAdapter {
/** /**
* Creates the MSN Listener instance. * Creates the MSN Listener instance.
...@@ -47,136 +46,26 @@ public class MSNListener extends MessengerClientAdapter { ...@@ -47,136 +46,26 @@ public class MSNListener extends MessengerClientAdapter {
/** /**
* Handles incoming messages from MSN. * Handles incoming messages from MSN.
*/ */
public void incomingMessage(IncomingMessageEvent event) { public void instantMessageReceived(MsnSwitchboard switchboard, MsnInstantMessage message, MsnContact friend) {
Log.debug("MSN: Received im to " + switchboard + " from " + friend + ": " + message.toString());
Message m = new Message(); Message m = new Message();
m.setType(Message.Type.chat); m.setType(Message.Type.chat);
m.setTo(msnSession.getJIDWithHighestPriority()); m.setTo(msnSession.getJIDWithHighestPriority());
m.setFrom(msnSession.getTransport().convertIDToJID(event.getUserName())); m.setFrom(msnSession.getTransport().convertIDToJID(friend.getEmail().toString()));
m.setBody(event.getMessage()); m.setBody(message.toString());
msnSession.getTransport().sendPacket(m); msnSession.getTransport().sendPacket(m);
} }
/**
* Deals with a server disconnection.
*/
public void serverDisconnected() {
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.");
}
}
/**
* A property of a contact has changed.
*
* This can be a myriad of things that have changed.
*
* @param event An event instance for the change.
*/
public void contactPropertyChanged(ContactChangeEvent event) {
int propid = event.getProperty();
if (propid == Contact.STATUS) {
String newstatus = (String)event.getNewValue();
Presence p = new Presence();
p.setTo(msnSession.getJID());
p.setFrom(msnSession.getTransport().convertIDToJID(event.getUserName()));
if (newstatus.equals(ContactStatus.ONLINE)) {
// We're good, send as is..
}
else if (newstatus.equals(ContactStatus.AWAY)) {
p.setShow(Presence.Show.away);
}
else if (newstatus.equals(ContactStatus.BE_RIGHT_BACK)) {
p.setShow(Presence.Show.away);
}
else if (newstatus.equals(ContactStatus.BUSY)) {
p.setShow(Presence.Show.dnd);
}
else if (newstatus.equals(ContactStatus.IDLE)) {
p.setShow(Presence.Show.away);
}
else if (newstatus.equals(ContactStatus.OFFLINE)) {
p.setType(Presence.Type.unavailable);
}
else if (newstatus.equals(ContactStatus.ON_THE_PHONE)) {
p.setShow(Presence.Show.dnd);
}
else if (newstatus.equals(ContactStatus.OUT_TO_LUNCH)) {
p.setShow(Presence.Show.xa);
}
msnSession.getTransport().sendPacket(p);
}
}
/**
* 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. * The user's login has completed and was accepted.
*/ */
public void loginAccepted() { public void loginCompleted(MsnMessenger messenger) {
Log.debug("MSN login accepted"); Log.debug("MSN login completed");
Presence p = new Presence(); Presence p = new Presence();
p.setTo(msnSession.getJID()); p.setTo(msnSession.getJID());
p.setFrom(msnSession.getTransport().getJID()); p.setFrom(msnSession.getTransport().getJID());
msnSession.getTransport().sendPacket(p); 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());
//}
} }
} }
...@@ -11,9 +11,10 @@ ...@@ -11,9 +11,10 @@
package org.jivesoftware.wildfire.gateway.protocols.msn; package org.jivesoftware.wildfire.gateway.protocols.msn;
import java.util.Date; import java.util.Date;
import org.hn.sleek.jmml.MessengerServerManager; import net.sf.jml.MsnMessenger;
import org.hn.sleek.jmml.MSNException; import net.sf.jml.MsnProtocol;
import org.jivesoftware.util.Log; import net.sf.jml.Email;
import net.sf.jml.impl.MsnMessengerFactory;
import org.jivesoftware.wildfire.gateway.PresenceType; import org.jivesoftware.wildfire.gateway.PresenceType;
import org.jivesoftware.wildfire.gateway.Registration; import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession; import org.jivesoftware.wildfire.gateway.TransportSession;
...@@ -38,14 +39,19 @@ public class MSNSession extends TransportSession { ...@@ -38,14 +39,19 @@ public class MSNSession extends TransportSession {
public MSNSession(Registration registration, JID jid, MSNTransport transport) { public MSNSession(Registration registration, JID jid, MSNTransport transport) {
super(registration, jid, transport); super(registration, jid, transport);
msnManager = MessengerServerManager.getInstance(); msnMessenger = MsnMessengerFactory.createMsnMessenger(registration.getUsername(), registration.getPassword());
msnManager.addMessengerClientListener(new MSNListener(this)); msnMessenger.setSupportedProtocol(new MsnProtocol[] { MsnProtocol.MSNP11 });
} }
/** /**
* MSN session * MSN session
*/ */
private MessengerServerManager msnManager = null; private MsnMessenger msnMessenger = null;
/**
* Login status
*/
private boolean loginStatus = false;
/** /**
* Log in to MSN. * Log in to MSN.
...@@ -55,22 +61,20 @@ public class MSNSession extends TransportSession { ...@@ -55,22 +61,20 @@ public class MSNSession extends TransportSession {
*/ */
public void logIn(PresenceType presenceType, String verboseStatus) { public void logIn(PresenceType presenceType, String verboseStatus) {
if (!this.isLoggedIn()) { if (!this.isLoggedIn()) {
try { msnMessenger.getOwner().setInitStatus(((MSNTransport)getTransport()).convertJabStatusToMSN(presenceType));
msnManager.signIn(registration.getUsername(), registration.getPassword(), ((MSNTransport)getTransport()).convertJabStatusToMSN(presenceType)); msnMessenger.setLogIncoming(true);
msnMessenger.setLogOutgoing(true);
Presence p = new Presence(); msnMessenger.addListener(new MSNListener(this));
p.setTo(getJID()); msnMessenger.login();
p.setFrom(getTransport().getJID());
getTransport().sendPacket(p); Presence p = new Presence();
p.setTo(getJID());
msnManager.setPrivacyMode(true); p.setFrom(getTransport().getJID());
msnManager.setReverseListBehaviour(true); getTransport().sendPacket(p);
getRegistration().setLastLogin(new Date()); getRegistration().setLastLogin(new Date());
}
catch (MSNException e) { loginStatus = true;
Log.error("MSN exception thrown while logging in:", e);
}
} }
} }
...@@ -79,31 +83,27 @@ public class MSNSession extends TransportSession { ...@@ -79,31 +83,27 @@ public class MSNSession extends TransportSession {
*/ */
public void logOut() { public void logOut() {
if (this.isLoggedIn()) { if (this.isLoggedIn()) {
try { msnMessenger.logout();
msnManager.signOut(); Presence p = new Presence(Presence.Type.unavailable);
Presence p = new Presence(Presence.Type.unavailable); p.setTo(getJID());
p.setTo(getJID()); p.setFrom(getTransport().getJID());
p.setFrom(getTransport().getJID()); getTransport().sendPacket(p);
getTransport().sendPacket(p); loginStatus = false;
}
catch (MSNException e) {
Log.error("MSN exception thrown while logging out:", e);
}
} }
} }
/** /**
* Retrieves the manager for this session. * Retrieves the manager for this session.
*/ */
public MessengerServerManager getManager() { public MsnMessenger getManager() {
return msnManager; return msnMessenger;
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#isLoggedIn() * @see org.jivesoftware.wildfire.gateway.TransportSession#isLoggedIn()
*/ */
public Boolean isLoggedIn() { public Boolean isLoggedIn() {
return msnManager.isConnected(); return loginStatus;
} }
/** /**
...@@ -124,12 +124,7 @@ public class MSNSession extends TransportSession { ...@@ -124,12 +124,7 @@ public class MSNSession extends TransportSession {
* @see org.jivesoftware.wildfire.gateway.TransportSession#sendMessage(org.xmpp.packet.JID, String) * @see org.jivesoftware.wildfire.gateway.TransportSession#sendMessage(org.xmpp.packet.JID, String)
*/ */
public void sendMessage(JID jid, String message) { public void sendMessage(JID jid, String message) {
try { msnMessenger.sendText(Email.parseStr(getTransport().convertJIDToID(jid)), message);
msnManager.sendMessage(getTransport().convertJIDToID(jid), message);
}
catch (MSNException e) {
Log.error("MSN exception while sending message:", e);
}
} }
/** /**
...@@ -143,12 +138,7 @@ public class MSNSession extends TransportSession { ...@@ -143,12 +138,7 @@ public class MSNSession extends TransportSession {
* @see org.jivesoftware.wildfire.gateway.TransportSession#updateStatus(org.jivesoftware.wildfire.gateway.PresenceType, String) * @see org.jivesoftware.wildfire.gateway.TransportSession#updateStatus(org.jivesoftware.wildfire.gateway.PresenceType, String)
*/ */
public void updateStatus(PresenceType presenceType, String verboseStatus) { public void updateStatus(PresenceType presenceType, String verboseStatus) {
try { // @todo need to implement this
msnManager.setStatus(((MSNTransport)getTransport()).convertJabStatusToMSN(presenceType));
}
catch (MSNException e) {
Log.error("MSN exception while setting status:", e);
}
} }
/** /**
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
package org.jivesoftware.wildfire.gateway.protocols.msn; package org.jivesoftware.wildfire.gateway.protocols.msn;
import org.hn.sleek.jmml.ContactStatus;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.BaseTransport; import org.jivesoftware.wildfire.gateway.BaseTransport;
import org.jivesoftware.wildfire.gateway.PresenceType; import org.jivesoftware.wildfire.gateway.PresenceType;
...@@ -18,6 +17,7 @@ import org.jivesoftware.wildfire.gateway.Registration; ...@@ -18,6 +17,7 @@ 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 org.xmpp.packet.Presence;
import net.sf.jml.MsnUserStatus;
/** /**
* MSN Transport Interface. * MSN Transport Interface.
...@@ -61,27 +61,27 @@ public class MSNTransport extends BaseTransport { ...@@ -61,27 +61,27 @@ public class MSNTransport extends BaseTransport {
* *
* @param jabStatus Jabber presence type. * @param jabStatus Jabber presence type.
*/ */
public String convertJabStatusToMSN(PresenceType jabStatus) { public MsnUserStatus convertJabStatusToMSN(PresenceType jabStatus) {
if (jabStatus == PresenceType.available) { if (jabStatus == PresenceType.available) {
return ContactStatus.ONLINE; return MsnUserStatus.ONLINE;
} }
else if (jabStatus == PresenceType.away) { else if (jabStatus == PresenceType.away) {
return ContactStatus.AWAY; return MsnUserStatus.AWAY;
} }
else if (jabStatus == PresenceType.xa) { else if (jabStatus == PresenceType.xa) {
return ContactStatus.AWAY; return MsnUserStatus.AWAY;
} }
else if (jabStatus == PresenceType.dnd) { else if (jabStatus == PresenceType.dnd) {
return ContactStatus.BUSY; return MsnUserStatus.BUSY;
} }
else if (jabStatus == PresenceType.chat) { else if (jabStatus == PresenceType.chat) {
return ContactStatus.ONLINE; return MsnUserStatus.ONLINE;
} }
else if (jabStatus == PresenceType.unavailable) { else if (jabStatus == PresenceType.unavailable) {
return ContactStatus.OFFLINE; return MsnUserStatus.OFFLINE;
} }
else { else {
return ContactStatus.ONLINE; return MsnUserStatus.ONLINE;
} }
} }
...@@ -91,28 +91,28 @@ public class MSNTransport extends BaseTransport { ...@@ -91,28 +91,28 @@ public class MSNTransport extends BaseTransport {
* @param msnStatus MSN ContactStatus constant. * @param msnStatus MSN ContactStatus constant.
*/ */
public void setUpPresencePacket(Presence packet, String msnStatus) { public void setUpPresencePacket(Presence packet, String msnStatus) {
if (msnStatus.equals(ContactStatus.ONLINE)) { if (msnStatus.equals(MsnUserStatus.ONLINE)) {
// We're good, send as is.. // We're good, send as is..
} }
else if (msnStatus.equals(ContactStatus.AWAY)) { else if (msnStatus.equals(MsnUserStatus.AWAY)) {
packet.setShow(Presence.Show.away); packet.setShow(Presence.Show.away);
} }
else if (msnStatus.equals(ContactStatus.BE_RIGHT_BACK)) { else if (msnStatus.equals(MsnUserStatus.BE_RIGHT_BACK)) {
packet.setShow(Presence.Show.away); packet.setShow(Presence.Show.away);
} }
else if (msnStatus.equals(ContactStatus.BUSY)) { else if (msnStatus.equals(MsnUserStatus.BUSY)) {
packet.setShow(Presence.Show.dnd); packet.setShow(Presence.Show.dnd);
} }
else if (msnStatus.equals(ContactStatus.IDLE)) { else if (msnStatus.equals(MsnUserStatus.IDLE)) {
packet.setShow(Presence.Show.away); packet.setShow(Presence.Show.away);
} }
else if (msnStatus.equals(ContactStatus.OFFLINE)) { else if (msnStatus.equals(MsnUserStatus.OFFLINE)) {
packet.setType(Presence.Type.unavailable); packet.setType(Presence.Type.unavailable);
} }
else if (msnStatus.equals(ContactStatus.ON_THE_PHONE)) { else if (msnStatus.equals(MsnUserStatus.ON_THE_PHONE)) {
packet.setShow(Presence.Show.dnd); packet.setShow(Presence.Show.dnd);
} }
else if (msnStatus.equals(ContactStatus.OUT_TO_LUNCH)) { else if (msnStatus.equals(MsnUserStatus.OUT_TO_LUNCH)) {
packet.setShow(Presence.Show.xa); packet.setShow(Presence.Show.xa);
} }
} }
......
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