use of net.java.otr4j.io.messages.AbstractMessage in project Zom-Android by zom.
the class SessionImpl method transformReceiving.
/*
* (non-Javadoc)
*
* @see
* net.java.otr4j.session.ISession#handleReceivingMessage(java.lang.String)
*/
public String transformReceiving(String msgText, List<TLV> tlvs) throws OtrException, NullPointerException {
OtrPolicy policy = getSessionPolicy();
if (!policy.getAllowV1() && !policy.getAllowV2()) {
if (DEBUG_ENABLED)
Log.d(LOG_TAG, "Policy does not allow neither V1 not V2, ignoring message.");
return msgText;
}
try {
msgText = assembler.accumulate(msgText);
} catch (ProtocolException e) {
if (DEBUG_ENABLED)
Log.d(LOG_TAG, "An invalid message fragment was discarded.");
return null;
}
if (msgText == null)
// Not a complete message (yet).
return null;
AbstractMessage m;
try {
m = SerializationUtils.toMessage(msgText);
} catch (IOException e) {
throw new OtrException(e);
}
if (m == null)
// msgText; // Propably null or empty.
return null;
switch(m.messageType) {
case AbstractEncodedMessage.MESSAGE_DATA:
return handleDataMessage((DataMessage) m, tlvs);
case AbstractMessage.MESSAGE_ERROR:
handleErrorMessage((ErrorMessage) m);
return null;
case AbstractMessage.MESSAGE_PLAINTEXT:
return handlePlainTextMessage((PlainTextMessage) m);
case AbstractMessage.MESSAGE_QUERY:
handleQueryMessage((QueryMessage) m);
return null;
case AbstractEncodedMessage.MESSAGE_DH_COMMIT:
case AbstractEncodedMessage.MESSAGE_DHKEY:
case AbstractEncodedMessage.MESSAGE_REVEALSIG:
case AbstractEncodedMessage.MESSAGE_SIGNATURE:
AuthContext auth = this.getAuthContext(false);
auth.handleReceivingMessage(m);
if (auth.getIsSecure()) {
this.setSessionStatus(SessionStatus.ENCRYPTED);
if (DEBUG_ENABLED)
Log.d(LOG_TAG, "Gone Secure.");
}
return null;
default:
throw new UnsupportedOperationException("Received an unknown message type.");
}
}
Aggregations