aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin
diff options
context:
space:
mode:
authorDanny van Heumen <danny@dannyvanheumen.nl>2014-08-31 22:55:45 +0200
committerDanny van Heumen <danny@dannyvanheumen.nl>2014-09-30 20:28:56 +0200
commitf970c50c8e0f85f8502d32e98c39d1d5b5b9f29c (patch)
tree27014fd0bc9579247ec0ed5b86ada649cc721c3a /src/net/java/sip/communicator/plugin
parent9c302d8c96897337b12b60afa9d1d0d5c633f76b (diff)
downloadjitsi-f970c50c8e0f85f8502d32e98c39d1d5b5b9f29c.zip
jitsi-f970c50c8e0f85f8502d32e98c39d1d5b5b9f29c.tar.gz
jitsi-f970c50c8e0f85f8502d32e98c39d1d5b5b9f29c.tar.bz2
Initial support for updated otr4j with support for outgoing message fragmentation.
Modifications include the following: - Updated otr4j which includes support for fragmentation of outgoing messages. The modifications to otr4j to enable outgoing message fragmentation includes breaking the API such that we are able to return more than 1 message after it has been transformed. (Corresponding modifications have been made to AbstractOperationSetBasicInstantMessaging to facilitate the new API.) - Fixed IRC implementation for OperationSetInstantMessageTransform. - Modified AbstractOperationSetBasicInstantMessaging to handle multiple Events returning from a call to messageTransform. - Modified OperationSetBasicInstantMessaging implementations to correspond to changes in AbstractOSBIM. - OTR plugin has been modified to implement the newly added getFragmenterInstructions method which is used to query instructions on desired fragmentation behaviour. - As a temporary solution, a hard dependency has been added to IRC library such that I'm able to test fragmentation behaviour in a real use case until an OperationSet is defined that can be used to query for Instant Messaging transport parameters necessary to determine appropriate fragmentation instructions.
Diffstat (limited to 'src/net/java/sip/communicator/plugin')
-rw-r--r--src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java64
-rw-r--r--src/net/java/sip/communicator/plugin/otr/ScOtrEngine.java2
-rw-r--r--src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java65
-rw-r--r--src/net/java/sip/communicator/plugin/otr/otr.manifest.mf3
4 files changed, 92 insertions, 42 deletions
diff --git a/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java b/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java
index f447de0..7c94eac 100644
--- a/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java
+++ b/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java
@@ -61,7 +61,7 @@ public class OtrTransformLayer
/*
* Implements TransformLayer#messageDeliveryPending(MessageDeliveredEvent).
*/
- public MessageDeliveredEvent messageDeliveryPending(
+ public MessageDeliveredEvent[] messageDeliveryPending(
MessageDeliveredEvent evt)
{
Contact contact = evt.getDestinationContact();
@@ -76,47 +76,57 @@ public class OtrTransformLayer
if (!policy.getEnableManual()
&& sessionStatus != ScSessionStatus.ENCRYPTED
&& sessionStatus != ScSessionStatus.FINISHED)
- return evt;
+ return new MessageDeliveredEvent[] {evt};
// If this is a message otr4j injected earlier, return the event as is.
if (OtrActivator.scOtrEngine.isMessageUIDInjected(evt
.getSourceMessage().getMessageUID()))
- return evt;
+ return new MessageDeliveredEvent[] {evt};
// Process the outgoing message.
String msgContent = evt.getSourceMessage().getContent();
- String processedMessageContent =
+ String[] processedMessageContent =
OtrActivator.scOtrEngine.transformSending(otrContact, msgContent);
if (processedMessageContent == null
- || processedMessageContent.length() < 1)
- return null;
-
- if (processedMessageContent.equals(msgContent))
- return evt;
-
- // Forge a new message based on the new contents.
- OperationSetBasicInstantMessaging imOpSet =
- contact.getProtocolProvider().getOperationSet(
- OperationSetBasicInstantMessaging.class);
- Message processedMessage =
- imOpSet.createMessage(
- processedMessageContent,
- evt.getSourceMessage().getContentType(),
- evt.getSourceMessage().getEncoding(),
- evt.getSourceMessage().getSubject());
+ || processedMessageContent.length <= 0
+ || processedMessageContent[0].length() < 1)
+ return new MessageDeliveredEvent[0];
- // Create a new event and return.
- MessageDeliveredEvent processedEvent =
- new MessageDeliveredEvent(processedMessage, contact, evt
- .getTimestamp());
+ if (processedMessageContent.length == 1
+ && processedMessageContent[0].equals(msgContent))
+ return new MessageDeliveredEvent[] {evt};
- if(processedMessage.getContent().contains(SerializationConstants.HEAD))
+ final MessageDeliveredEvent[] processedEvents =
+ new MessageDeliveredEvent[processedMessageContent.length];
+ for (int i = 0; i < processedMessageContent.length; i++)
{
- processedEvent.setMessageEncrypted(true);
+ final String fragmentContent = processedMessageContent[i];
+ // Forge a new message based on the new contents.
+ OperationSetBasicInstantMessaging imOpSet =
+ contact.getProtocolProvider().getOperationSet(
+ OperationSetBasicInstantMessaging.class);
+ Message processedMessage =
+ imOpSet.createMessage(fragmentContent, evt
+ .getSourceMessage().getContentType(), evt
+ .getSourceMessage().getEncoding(), evt.getSourceMessage()
+ .getSubject());
+
+ // Create a new event and return.
+ final MessageDeliveredEvent processedEvent =
+ new MessageDeliveredEvent(processedMessage, contact,
+ evt.getTimestamp());
+
+ if (processedMessage.getContent().contains(
+ SerializationConstants.HEAD))
+ {
+ processedEvent.setMessageEncrypted(true);
+ }
+
+ processedEvents[i] = processedEvent;
}
- return processedEvent;
+ return processedEvents;
}
/*
diff --git a/src/net/java/sip/communicator/plugin/otr/ScOtrEngine.java b/src/net/java/sip/communicator/plugin/otr/ScOtrEngine.java
index f9ee909..5bd9688 100644
--- a/src/net/java/sip/communicator/plugin/otr/ScOtrEngine.java
+++ b/src/net/java/sip/communicator/plugin/otr/ScOtrEngine.java
@@ -70,7 +70,7 @@ public interface ScOtrEngine
* @param content the original message content.
* @return the transformed message content.
*/
- public abstract String transformSending(OtrContact contact, String content);
+ public abstract String[] transformSending(OtrContact contact, String content);
/**
* Transforms an incoming message.
diff --git a/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java b/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java
index a06b61d..f14c2ec 100644
--- a/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java
+++ b/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java
@@ -14,6 +14,7 @@ import java.util.concurrent.*;
import net.java.otr4j.*;
import net.java.otr4j.crypto.*;
import net.java.otr4j.session.*;
+import net.java.sip.communicator.impl.protocol.irc.*;
import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact;
import net.java.sip.communicator.plugin.otr.authdialog.*;
import net.java.sip.communicator.service.browserlauncher.*;
@@ -420,6 +421,44 @@ public class ScOtrEngineImpl
message,
OperationSetBasicInstantMessaging.HTML_MIME_TYPE);
}
+
+ /**
+ * Provide fragmenter instructions according to the Instant Messaging
+ * transport channel of the contact's protocol.
+ */
+ @Override
+ public FragmenterInstructions getFragmenterInstructions(
+ final SessionID sessionID)
+ {
+ final OtrContact otrContact = getOtrContact(sessionID);
+ // FIXME Change this into querying an Operation Set that provides
+ // Instant Message medium/transport information that we can use to
+ // determine fragmentation parameters.
+ if (ProtocolNames.IRC.equals(otrContact.contact
+ .getProtocolProvider().getProtocolName()))
+ {
+ // :<nick>!<user>@<host> PRIVMSG <targetnick> :<message>
+ //
+ // Example:
+ // :ircotrtest!~ircotrtes@77-175-185-165.FTTH.ispfabriek.nl
+ // PRIVMSG test12345abc :
+ final String identity =
+ ((ProtocolProviderServiceIrcImpl) otrContact.contact
+ .getProtocolProvider()).getIrcStack()
+ .getIdentityString();
+ final int size =
+ 510 - (":" + identity + " PRIVMSG "
+ + otrContact.contact.getAddress() + " :").length();
+ return new FragmenterInstructions(
+ FragmenterInstructions.UNLIMITED, size);
+ }
+ else
+ {
+ return new FragmenterInstructions(
+ FragmenterInstructions.UNLIMITED,
+ FragmenterInstructions.UNLIMITED);
+ }
+ }
}
/**
@@ -510,11 +549,11 @@ public class ScOtrEngineImpl
private final OtrEngineHost otrEngineHost = new ScOtrEngineHost();
- private final OtrEngine otrEngine;
+ private final OtrSessionManager otrEngine;
public ScOtrEngineImpl()
{
- otrEngine = new OtrEngineImpl(otrEngineHost);
+ otrEngine = new OtrSessionManagerImpl(otrEngineHost);
// Clears the map after previous instance
// This is required because of OSGi restarts in the same VM on Android
@@ -539,13 +578,13 @@ public class ScOtrEngineImpl
ScSessionStatus scSessionStatus = getSessionStatus(otrContact);
String message = "";
- switch (otrEngine.getSessionStatus(sessionID))
+ final Session session = otrEngine.getSession(sessionID);
+ switch (session.getSessionStatus())
{
case ENCRYPTED:
scSessionStatus = ScSessionStatus.ENCRYPTED;
scSessionStatusMap.put(sessionID, scSessionStatus);
- PublicKey remotePubKey =
- otrEngine.getRemotePublicKey(sessionID);
+ PublicKey remotePubKey = session.getRemotePublicKey();
String remoteFingerprint = null;
try
@@ -790,7 +829,7 @@ public class ScOtrEngineImpl
{
setSessionStatus(otrContact, ScSessionStatus.PLAINTEXT);
- otrEngine.endSession(sessionID);
+ otrEngine.getSession(sessionID).endSession();
}
catch (OtrException e)
{
@@ -926,7 +965,7 @@ public class ScOtrEngineImpl
public ScSessionStatus getSessionStatus(OtrContact contact)
{
SessionID sessionID = getSessionID(contact);
- SessionStatus sessionStatus = otrEngine.getSessionStatus(sessionID);
+ SessionStatus sessionStatus = otrEngine.getSession(sessionID).getSessionStatus();
ScSessionStatus scSessionStatus = null;
if (!scSessionStatusMap.containsKey(sessionID))
{
@@ -976,7 +1015,7 @@ public class ScOtrEngineImpl
SessionID sessionID = getSessionID(otrContact);
try
{
- otrEngine.refreshSession(sessionID);
+ otrEngine.getSession(sessionID).refreshSession();
}
catch (OtrException e)
{
@@ -1112,7 +1151,7 @@ public class ScOtrEngineImpl
try
{
- otrEngine.startSession(sessionID);
+ otrEngine.getSession(sessionID).startSession();
}
catch (OtrException e)
{
@@ -1127,7 +1166,7 @@ public class ScOtrEngineImpl
SessionID sessionID = getSessionID(otrContact);
try
{
- return otrEngine.transformReceiving(sessionID, msgText);
+ return otrEngine.getSession(sessionID).transformReceiving(msgText);
}
catch (OtrException e)
{
@@ -1138,12 +1177,12 @@ public class ScOtrEngineImpl
}
@Override
- public String transformSending(OtrContact otrContact, String msgText)
+ public String[] transformSending(OtrContact otrContact, String msgText)
{
SessionID sessionID = getSessionID(otrContact);
try
{
- return otrEngine.transformSending(sessionID, msgText);
+ return otrEngine.getSession(sessionID).transformSending(msgText);
}
catch (OtrException e)
{
@@ -1280,6 +1319,6 @@ public class ScOtrEngineImpl
SessionID sessionID = getSessionID(contact);
- return otrEngine.getOutgoingSession(sessionID);
+ return otrEngine.getSession(sessionID).getOutgoingInstance();
}
}
diff --git a/src/net/java/sip/communicator/plugin/otr/otr.manifest.mf b/src/net/java/sip/communicator/plugin/otr/otr.manifest.mf
index 07807d4..0dbc565 100644
--- a/src/net/java/sip/communicator/plugin/otr/otr.manifest.mf
+++ b/src/net/java/sip/communicator/plugin/otr/otr.manifest.mf
@@ -33,4 +33,5 @@ Import-Package: org.osgi.framework,
org.bouncycastle.crypto.modes,
org.bouncycastle.util,
org.bouncycastle.util.encoders,
- net.java.sip.communicator.service.msghistory
+ net.java.sip.communicator.service.msghistory,
+ net.java.sip.communicator.impl.protocol.irc