src/net/java/otr4j/session/SessionImpl.java
changeset 815 ca323cff3ac9
parent 810 0ff0059f2ec3
--- a/src/net/java/otr4j/session/SessionImpl.java	Mon Dec 06 01:06:44 2010 +0100
+++ b/src/net/java/otr4j/session/SessionImpl.java	Tue Dec 07 22:57:56 2010 +0100
@@ -44,11 +44,6 @@
  */
 public class SessionImpl implements Session {
 
-	/**
-	 * 
-	 * @author George Politis
-	 * 
-	 */
 	class TLV {
 		public TLV(int type, byte[] value) {
 			this.setType(type);
@@ -76,7 +71,7 @@
 	}
 
 	private SessionID sessionID;
-	private OtrEngineHost listener;
+	private OtrEngineHost host;
 	private SessionStatus sessionStatus;
 	private AuthContext authContext;
 	private SessionKeys[][] sessionKeys;
@@ -87,7 +82,7 @@
 	public SessionImpl(SessionID sessionID, OtrEngineHost listener) {
 
 		this.setSessionID(sessionID);
-		this.setListener(listener);
+		this.setHost(listener);
 
 		// client application calls OtrEngine.getSessionStatus()
 		// -> create new session if it does not exist, end up here
@@ -274,12 +269,12 @@
 		return sessionID;
 	}
 
-	private void setListener(OtrEngineHost listener) {
-		this.listener = listener;
+	private void setHost(OtrEngineHost host) {
+		this.host = host;
 	}
 
-	private OtrEngineHost getListener() {
-		return listener;
+	private OtrEngineHost getHost() {
+		return host;
 	}
 
 	private SessionKeys[][] getSessionKeys() {
@@ -320,6 +315,9 @@
 		} catch (IOException e) {
 			throw new OtrException(e);
 		}
+		
+		if (m == null)
+			return msgText; // Propably null or empty.
 
 		switch (m.messageType) {
 		case AbstractEncodedMessage.MESSAGE_DATA:
@@ -375,7 +373,7 @@
 				+ getSessionID().getUserID() + " throught "
 				+ getSessionID().getUserID() + ".");
 
-		getListener().showError(this.getSessionID(), errorMessage.error);
+		getHost().showError(this.getSessionID(), errorMessage.error);
 
 		OtrPolicy policy = getSessionPolicy();
 		if (policy.getErrorStartAKE()) {
@@ -506,7 +504,7 @@
 
 		case FINISHED:
 		case PLAINTEXT:
-			getListener().showWarning(this.getSessionID(),
+			getHost().showWarning(this.getSessionID(),
 					"Unreadable encrypted message was received.");
 
 			injectMessage(new ErrorMessage(AbstractMessage.MESSAGE_ERROR,
@@ -524,7 +522,7 @@
 		} catch (IOException e) {
 			throw new OtrException(e);
 		}
-		getListener().injectMessage(getSessionID(), msg);
+		getHost().injectMessage(getSessionID(), msg);
 	}
 
 	private String handlePlainTextMessage(PlainTextMessage plainTextMessage)
@@ -544,7 +542,7 @@
 			case FINISHED:
 				// Display the message to the user, but warn him that the
 				// message was received unencrypted.
-				getListener().showWarning(this.getSessionID(),
+				getHost().showWarning(this.getSessionID(),
 						"The message was received unencrypted.");
 				return plainTextMessage.cleanText;
 			case PLAINTEXT:
@@ -553,7 +551,7 @@
 				// is set, warn him that the message was received
 				// unencrypted.
 				if (policy.getRequireEncryption()) {
-					getListener().showWarning(this.getSessionID(),
+					getHost().showWarning(this.getSessionID(),
 							"The message was received unencrypted.");
 				}
 				return plainTextMessage.cleanText;
@@ -567,7 +565,7 @@
 				// Remove the whitespace tag and display the message to the
 				// user, but warn him that the message was received
 				// unencrypted.
-				getListener().showWarning(this.getSessionID(),
+				getHost().showWarning(this.getSessionID(),
 						"The message was received unencrypted.");
 			case PLAINTEXT:
 				// Remove the whitespace tag and display the message to the
@@ -575,7 +573,7 @@
 				// message
 				// was received unencrypted.
 				if (policy.getRequireEncryption())
-					getListener().showWarning(this.getSessionID(),
+					getHost().showWarning(this.getSessionID(),
 							"The message was received unencrypted.");
 			}
 
@@ -696,7 +694,7 @@
 			}
 		case FINISHED:
 			this.lastSentMessage = msgText;
-			getListener()
+			getHost()
 					.showError(
 							sessionID,
 							"Your message to "
@@ -737,7 +735,7 @@
 			tlvs.add(new TLV(1, null));
 
 			String msg = this.transformSending(null, tlvs);
-			getListener().injectMessage(getSessionID(), msg);
+			getHost().injectMessage(getSessionID(), msg);
 			this.setSessionStatus(SessionStatus.PLAINTEXT);
 			break;
 		case FINISHED:
@@ -776,7 +774,6 @@
 			if (!listeners.contains(l))
 				listeners.add(l);
 		}
-
 	}
 
 	public void removeOtrEngineListener(OtrEngineListener l) {
@@ -786,10 +783,10 @@
 	}
 
 	public OtrPolicy getSessionPolicy() {
-		return getListener().getSessionPolicy(getSessionID());
+		return getHost().getSessionPolicy(getSessionID());
 	}
 
 	public KeyPair getLocalKeyPair() {
-		return getListener().getKeyPair(this.getSessionID());
+		return getHost().getKeyPair(this.getSessionID());
 	}
 }