Commit 84bb2b20 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

Lots more debugging for MSN pieces, mods for unit test. Most work thanks to sk_lionheart.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@5656 b35dd754-fafc-0310-a699-88a17e54d16e
parent 814ac9e9
......@@ -57,6 +57,7 @@ public class Registration {
private String nickname;
private Date registrationDate;
private Date lastLogin;
private boolean disconnectedMode = false;
/**
* Creates a new registration.
......@@ -86,6 +87,38 @@ public class Registration {
}
}
/**
* Creates a new registration in disconnected (test) mode.
*
* Passing false for disconnectedMode is the same as the previous constructor.
*
* @param jid the JID of the user making the registration.
* @param transportType the type of the transport.
* @param username the username on the transport.
* @param password the password on the transport.
* @param nickname the nickname on the transport.
* @param disconnectedMode True or false if we are in disconnected mode.
*/
public Registration(JID jid, TransportType transportType, String username, String password, String nickname, Boolean disconnectedMode) {
if (jid == null || transportType == null || username == null) {
throw new NullPointerException("Arguments cannot be null.");
}
this.disconnectedMode = disconnectedMode;
// Ensure that we store the bare JID.
this.jid = new JID(jid.toBareJID());
this.transportType = transportType;
this.username = username;
this.password = password;
this.nickname = nickname;
this.registrationDate = new Date();
try {
insertIntoDb();
}
catch (Exception e) {
Log.error(e);
}
}
/**
* Loads an existing registration.
*
......@@ -160,6 +193,7 @@ public class Registration {
*/
public void setPassword(String password) {
this.password = password;
if (disconnectedMode) { return; }
// The password is stored in encrypted form for improved security.
String encryptedPassword = AuthFactory.encryptPassword(password);
Connection con = null;
......@@ -194,6 +228,7 @@ public class Registration {
throw new NullPointerException("Arguments cannot be null.");
}
this.username = username;
if (disconnectedMode) { return; }
Connection con = null;
PreparedStatement pstmt = null;
try {
......@@ -218,6 +253,7 @@ public class Registration {
*/
public void setNickname(String nickname) {
this.nickname = nickname;
if (disconnectedMode) { return; }
Connection con = null;
PreparedStatement pstmt = null;
try {
......@@ -266,6 +302,7 @@ public class Registration {
*/
public void setLastLogin(Date lastLogin) {
this.lastLogin = lastLogin;
if (disconnectedMode) { return; }
Connection con = null;
PreparedStatement pstmt = null;
try {
......@@ -293,6 +330,7 @@ public class Registration {
* @throws SQLException if the SQL statement is wrong for whatever reason.
*/
private void insertIntoDb() throws SQLException {
if (disconnectedMode) { return; }
this.registrationID = SequenceManager.nextID(this);
Connection con = null;
PreparedStatement pstmt = null;
......@@ -336,6 +374,7 @@ public class Registration {
* @throws NotFoundException if registration was not found in database.
*/
private void loadFromDb() throws NotFoundException {
if (disconnectedMode) { return; }
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
......
......@@ -99,6 +99,7 @@ public class MSNListener extends MsnAdapter {
* The user's login has completed and was accepted.
*/
public void loginCompleted(MsnMessenger messenger) {
Log.debug("MSN: Login completed for "+messenger.getOwner().getEmail());
msnSession.getRegistration().setLastLogin(new Date());
msnSession.setLoginStatus(TransportLoginStatus.LOGGED_IN);
}
......@@ -108,7 +109,7 @@ public class MSNListener extends MsnAdapter {
*/
public void contactListInitCompleted(MsnMessenger messenger) {
for (MsnContact msnContact : messenger.getContactList().getContacts()) {
Log.debug("Got contact "+msnContact);
Log.debug("MSN: Got contact "+msnContact);
if (msnContact.isInList(MsnList.FL) && msnContact.getEmail() != null) {
msnSession.storeFriend(msnContact);
}
......@@ -123,6 +124,7 @@ public class MSNListener extends MsnAdapter {
* Contact list has been synced.
*/
public void contactListSyncCompleted(MsnMessenger messenger) {
Log.debug("MSN: Contact list sync for "+messenger.getOwner().getEmail());
}
/**
......@@ -156,6 +158,7 @@ public class MSNListener extends MsnAdapter {
* Catches MSN exceptions.
*/
public void exceptionCaught(MsnMessenger messenger, Throwable throwable) {
Log.debug("MSN: Exception occurred for "+messenger.getOwner().getEmail()+" : "+throwable);
if (throwable.getClass().getName().equals("net.sf.jml.exception.IncorrectPasswordException")) {
Message m = new Message();
m.setType(Message.Type.error);
......
......@@ -12,6 +12,7 @@ package org.jivesoftware.wildfire.gateway.protocols.msn;
import net.sf.jml.*;
import net.sf.jml.impl.MsnMessengerFactory;
import net.sf.jml.impl.BasicMessenger;
import org.jivesoftware.wildfire.gateway.*;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.wildfire.roster.RosterItem;
......@@ -44,7 +45,9 @@ public class MSNSession extends TransportSession {
public MSNSession(Registration registration, JID jid, MSNTransport transport, Integer priority) {
super(registration, jid, transport, priority);
Log.debug("Creating MSN session for " + registration.getUsername());
msnMessenger = MsnMessengerFactory.createMsnMessenger(registration.getUsername(), registration.getPassword());
((BasicMessenger)msnMessenger).addSessionListener(new MsnSessionListener(this));
msnMessenger.setSupportedProtocol(MsnProtocol.getAllSupportedProtocol());
}
......@@ -71,12 +74,18 @@ public class MSNSession extends TransportSession {
*/
public void logIn(PresenceType presenceType, String verboseStatus) {
if (!this.isLoggedIn()) {
setLoginStatus(TransportLoginStatus.LOGGING_IN);
msnMessenger.getOwner().setInitStatus(((MSNTransport)getTransport()).convertJabStatusToMSN(presenceType));
msnMessenger.setLogIncoming(false);
msnMessenger.setLogOutgoing(false);
msnMessenger.addListener(new MSNListener(this));
msnMessenger.login();
try {
Log.debug("Logging in to MSN session for " + msnMessenger.getOwner().getEmail());
setLoginStatus(TransportLoginStatus.LOGGING_IN);
msnMessenger.getOwner().setInitStatus(((MSNTransport)getTransport()).convertJabStatusToMSN(presenceType));
msnMessenger.setLogIncoming(false);
msnMessenger.setLogOutgoing(false);
msnMessenger.addListener(new MSNListener(this));
msnMessenger.login();
}
catch (Exception e) {
Log.error("MSN user is not able to log in: " + msnMessenger.getOwner().getEmail(), e);
}
}
}
......
/**
* $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.protocols.msn;
import net.sf.cindy.SessionAdapter;
import net.sf.cindy.Session;
import net.sf.cindy.Message;
import org.jivesoftware.util.Log;
/**
* MSN Session Listener Interface.
*
* This handles listening to session activities.
*
* @author lionheart@clansk.org
* @author Daniel Henninger
*/
public class MsnSessionListener extends SessionAdapter {
public MsnSessionListener(MSNSession msnSession) {
this.msnSession = msnSession;
}
/**
* The session this listener is associated with.
*/
public MSNSession msnSession = null;
public void exceptionCaught(Session arg0, Throwable t) throws Exception{
Log.debug("MSN: Session exceptionCaught for "+msnSession.getRegistration().getUsername()+" : "+t);
}
public void messageReceived(Session arg0, Message message) throws Exception {
Log.debug("MSN: Session messageReceived for "+msnSession.getRegistration().getUsername()+" : "+message);
}
public void messageSent(Session arg0, Message message) throws Exception {
Log.debug("MSN: Session messageSent for "+msnSession.getRegistration().getUsername()+" : "+message);
}
public void sessionIdle(Session session) throws Exception {
}
public void sessionEstablished(Session session) {
Log.debug("MSN: Session established for "+msnSession.getRegistration().getUsername());
}
public void sessionTimeout(Session session) {
Log.debug("MSN: Session timeout for "+msnSession.getRegistration().getUsername());
}
public void sessionClosed(Session session) {
Log.debug("MSN: Session closed for "+msnSession.getRegistration().getUsername());
}
}
......@@ -5,29 +5,29 @@ import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession;
import org.jivesoftware.wildfire.gateway.TransportType;
import org.xmpp.packet.JID;
import org.jivesoftware.wildfire.gateway.protocols.msn.MSNSession;
import org.jivesoftware.wildfire.gateway.protocols.msn.MSNTransport;
public class MSNTransportTest
{
/**
* @param args
* @param args Arguments passed to program.
*/
public static void main(String[] args)
{
if (args.length!=4)
{
System.out.println("Syntaxe : java MSNTransportTest user password nickname jid");
System.out.println("Syntax: java MSNTransportTest user password nickname jid");
System.exit(0);
}
Log.setDebugEnabled(true);
JID jid = new JID(args[3]);
Registration registration = new Registration(jid, TransportType.msn, args[0], args[1], args[2],true);
Registration registration = new Registration(jid, TransportType.msn, args[0], args[1], args[2], true);
MSNTransport transport = new MSNTransport();
transport.jid = jid;
transport.setup(TransportType.msn, "MSN");
TransportSession session = transport.registrationLoggedIn(registration,jid,PresenceType.available,"online",new Integer(1));
}
transport.registrationLoggedOut(session);
}
}
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