aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanny van Heumen <danny@dannyvanheumen.nl>2014-10-14 23:32:26 +0200
committerDanny van Heumen <danny@dannyvanheumen.nl>2014-10-28 22:33:32 +0100
commitb6c43dac746ed2425e16173bc69838a436f3094d (patch)
treebe9fa7a6025530fc1a712d1619fff0c1dc8dbae0
parent06d5ccc2f34b1b2de7e7353dc62d948187fc8350 (diff)
downloadjitsi-b6c43dac746ed2425e16173bc69838a436f3094d.zip
jitsi-b6c43dac746ed2425e16173bc69838a436f3094d.tar.gz
jitsi-b6c43dac746ed2425e16173bc69838a436f3094d.tar.bz2
Unknown commands now result in failed message delivery.
To, for one, protect users from accidents and, for two, don't accidentally send "stupid messages" we do no longer send any messages starting with '/'. Instead it shows a message delivery failed message for error UNSUPPORTED_OPERATION. Reasoning is that the intended operation is either unsupported or unknown. In both cases there is no support for it, so let the user know.
-rw-r--r--resources/languages/resources.properties1
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/chat/conference/ConferenceChatManager.java13
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPane.java6
-rw-r--r--src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java24
-rw-r--r--src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java9
-rw-r--r--src/net/java/sip/communicator/impl/protocol/irc/OperationSetBasicInstantMessagingIrcImpl.java15
-rw-r--r--src/net/java/sip/communicator/impl/protocol/irc/exception/UnsupportedCommandException.java48
-rw-r--r--src/net/java/sip/communicator/impl/protocol/irc/exception/package-info.java4
-rw-r--r--src/net/java/sip/communicator/service/protocol/event/ChatRoomMessageDeliveryFailedEvent.java7
-rw-r--r--src/net/java/sip/communicator/service/protocol/event/MessageDeliveryFailedEvent.java62
10 files changed, 151 insertions, 38 deletions
diff --git a/resources/languages/resources.properties b/resources/languages/resources.properties
index 65e1d81..01354e7 100644
--- a/resources/languages/resources.properties
+++ b/resources/languages/resources.properties
@@ -366,6 +366,7 @@ protocol or wait until he/she becomes online.
service.gui.MSG_DELIVERY_INTERNAL_ERROR=An internal error occurred. This is most probably a bug. Please report it here: https://jitsi.org/Development/BugsAndIssues.
service.gui.MSG_DELIVERY_ERROR=Failed to deliver message.
service.gui.MSG_DELIVERY_UNKNOWN_ERROR=Unknown error has occurred while delivering your message.
+service.gui.MSG_DELIVERY_UNSUPPORTED_OPERATION=Unsupported operation.
service.gui.MSG_NOT_DELIVERED=A network problem occurred. Please check your network configuration and try again.
service.gui.MSG_NOT_POSSIBLE=Messaging is not possible for this contact (it is not supported by the protocol)
service.gui.MSG_RECEIVED={0} wrote
diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ConferenceChatManager.java b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ConferenceChatManager.java
index b4f2abd..016a663 100644
--- a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ConferenceChatManager.java
+++ b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ConferenceChatManager.java
@@ -367,6 +367,13 @@ public class ConferenceChatManager
errorMsg = GuiActivator.getResources().getI18NString(
"service.gui.CHAT_ROOM_SEND_MSG_FORBIDDEN");
}
+ else if (evt.getErrorCode()
+ == ChatRoomMessageDeliveryFailedEvent.UNSUPPORTED_OPERATION)
+ {
+ errorMsg =
+ GuiActivator.getResources().getI18NString(
+ "service.gui.MSG_DELIVERY_UNSUPPORTED_OPERATION");
+ }
else
{
errorMsg = GuiActivator.getResources().getI18NString(
@@ -1278,6 +1285,12 @@ public class ConferenceChatManager
errorMsg = GuiActivator.getResources().getI18NString(
"service.gui.MSG_DELIVERY_INTERNAL_ERROR");
}
+ else if (evt.getErrorCode()
+ == MessageDeliveryFailedEvent.UNSUPPORTED_OPERATION)
+ {
+ errorMsg = GuiActivator.getResources().getI18NString(
+ "service.gui.MSG_DELIVERY_UNSUPPORTED_OPERATION");
+ }
else
{
errorMsg = GuiActivator.getResources().getI18NString(
diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPane.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPane.java
index fd598df..c157904 100644
--- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPane.java
+++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPane.java
@@ -556,6 +556,12 @@ public class ContactListPane
errorMsg = GuiActivator.getResources().getI18NString(
"service.gui.MSG_DELIVERY_INTERNAL_ERROR");
}
+ else if (evt.getErrorCode()
+ == MessageDeliveryFailedEvent.UNSUPPORTED_OPERATION)
+ {
+ errorMsg = GuiActivator.getResources().getI18NString(
+ "service.gui.MSG_DELIVERY_UNSUPPORTED_OPERATION");
+ }
else
{
errorMsg = GuiActivator.getResources().getI18NString(
diff --git a/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java b/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java
index 720160d..697a995 100644
--- a/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java
@@ -10,6 +10,7 @@ import java.beans.*;
import java.io.*;
import java.util.*;
+import net.java.sip.communicator.impl.protocol.irc.exception.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
@@ -936,16 +937,29 @@ public class ChatRoomIrcImpl
this.parentProvider.getIrcStack().getConnection();
if (((MessageIrcImpl) message).isCommand())
{
- connection.getMessageManager().command(this, messagePortion);
+ try
+ {
+ connection.getMessageManager()
+ .command(this, messagePortion);
+ this.fireMessageReceivedEvent(message, this.user,
+ new Date(),
+ ChatRoomMessageReceivedEvent.SYSTEM_MESSAGE_RECEIVED);
+ }
+ catch (final UnsupportedCommandException e)
+ {
+ this.fireMessageDeliveryFailedEvent(
+ ChatRoomMessageDeliveryFailedEvent
+ .UNSUPPORTED_OPERATION,
+ e.getMessage(), new Date(), message);
+ }
}
else
{
connection.getMessageManager().message(this, messagePortion);
+ this.fireMessageDeliveredEvent(new MessageIrcImpl(
+ messagePortion, message.getContentType(), message
+ .getEncoding(), message.getSubject()));
}
-
- this.fireMessageDeliveredEvent(new MessageIrcImpl(messagePortion,
- message.getContentType(), message.getEncoding(), message
- .getSubject()));
}
}
diff --git a/src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java b/src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java
index 92b1e71..a120c4e 100644
--- a/src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java
+++ b/src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java
@@ -6,6 +6,7 @@
*/
package net.java.sip.communicator.impl.protocol.irc;
+import net.java.sip.communicator.impl.protocol.irc.exception.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
@@ -173,12 +174,12 @@ public class MessageManager
this.irc.joinChannel(channel, password);
}
}
- // TODO add /nick command for nick changing
+ // FIXME add /nick command for nick changing
else
{
- // FIXME don't send as normal message just in case it contains
- // valuable/vulnerable information (or if simply wasn't intended)
- this.irc.message(source, message);
+ final int index = msg.indexOf(' ');
+ final int end = index <= -1 ? msg.length() : index;
+ throw new UnsupportedCommandException(msg.substring(1, end));
}
}
diff --git a/src/net/java/sip/communicator/impl/protocol/irc/OperationSetBasicInstantMessagingIrcImpl.java b/src/net/java/sip/communicator/impl/protocol/irc/OperationSetBasicInstantMessagingIrcImpl.java
index 9e548f4..e101736 100644
--- a/src/net/java/sip/communicator/impl/protocol/irc/OperationSetBasicInstantMessagingIrcImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/irc/OperationSetBasicInstantMessagingIrcImpl.java
@@ -10,6 +10,7 @@
*/
package net.java.sip.communicator.impl.protocol.irc;
+import net.java.sip.communicator.impl.protocol.irc.exception.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
@@ -123,11 +124,22 @@ public class OperationSetBasicInstantMessagingIrcImpl
{
if (!event.isMessageEncrypted() && message.isCommand())
{
- connection.getMessageManager().command(to, message);
+ try
+ {
+ connection.getMessageManager().command(to, message);
+ fireMessageDelivered(original, to);
+ }
+ catch (final UnsupportedCommandException e)
+ {
+ fireMessageDeliveryFailed(message, to,
+ MessageDeliveryFailedEvent
+ .UNSUPPORTED_OPERATION);
+ }
}
else
{
connection.getMessageManager().message(to, message);
+ fireMessageDelivered(original, to);
}
}
catch (RuntimeException e)
@@ -136,7 +148,6 @@ public class OperationSetBasicInstantMessagingIrcImpl
throw e;
}
}
- fireMessageDelivered(original, to);
}
catch (RuntimeException e)
{
diff --git a/src/net/java/sip/communicator/impl/protocol/irc/exception/UnsupportedCommandException.java b/src/net/java/sip/communicator/impl/protocol/irc/exception/UnsupportedCommandException.java
new file mode 100644
index 0000000..414b7f3
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/protocol/irc/exception/UnsupportedCommandException.java
@@ -0,0 +1,48 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.impl.protocol.irc.exception;
+
+/**
+ * Exception indicating that a certain command is unsupported or unknown.
+ * (Either way it is not being handled.)
+ *
+ * @author Danny van Heumen
+ */
+public class UnsupportedCommandException
+ extends IllegalArgumentException
+{
+ /**
+ * Serialization version.
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The command.
+ */
+ private final String command;
+
+ /**
+ * Constructor.
+ *
+ * @param command the command
+ */
+ public UnsupportedCommandException(final String command)
+ {
+ super("Command '" + command + "' is unknown or unsupported.");
+ this.command = command;
+ }
+
+ /**
+ * The unsupported command that is the reason for this exception.
+ *
+ * @return returns command that is unsupported
+ */
+ public String getCommand()
+ {
+ return this.command;
+ }
+}
diff --git a/src/net/java/sip/communicator/impl/protocol/irc/exception/package-info.java b/src/net/java/sip/communicator/impl/protocol/irc/exception/package-info.java
new file mode 100644
index 0000000..4bbd97b
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/protocol/irc/exception/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Specialized exceptions for IRC.
+ */
+package net.java.sip.communicator.impl.protocol.irc.exception;
diff --git a/src/net/java/sip/communicator/service/protocol/event/ChatRoomMessageDeliveryFailedEvent.java b/src/net/java/sip/communicator/service/protocol/event/ChatRoomMessageDeliveryFailedEvent.java
index 2ac7fcf..0d86d76 100644
--- a/src/net/java/sip/communicator/service/protocol/event/ChatRoomMessageDeliveryFailedEvent.java
+++ b/src/net/java/sip/communicator/service/protocol/event/ChatRoomMessageDeliveryFailedEvent.java
@@ -66,6 +66,13 @@ public class ChatRoomMessageDeliveryFailedEvent
public static final int FORBIDDEN = 6;
/**
+ * Set when delivery fails because of dependency on an operation that is
+ * unsupported. For example, because it is unknown or not supported at that
+ * particular moment.
+ */
+ public static final int UNSUPPORTED_OPERATION = 7;
+
+ /**
* An error code indicating the reason for the failure of this delivery.
*/
private int errorCode = UNKNOWN_ERROR;
diff --git a/src/net/java/sip/communicator/service/protocol/event/MessageDeliveryFailedEvent.java b/src/net/java/sip/communicator/service/protocol/event/MessageDeliveryFailedEvent.java
index 85fc5e8..fc973b5 100644
--- a/src/net/java/sip/communicator/service/protocol/event/MessageDeliveryFailedEvent.java
+++ b/src/net/java/sip/communicator/service/protocol/event/MessageDeliveryFailedEvent.java
@@ -25,38 +25,46 @@ public class MessageDeliveryFailedEvent
private static final long serialVersionUID = 0L;
/**
- * The contact that this message has been sent to.
- */
- private Contact to = null;
+ * The contact that this message has been sent to.
+ */
+ private Contact to = null;
- /**
- * Set when no other error code can describe the exception that occurred.
- */
- public static final int UNKNOWN_ERROR = 1;
+ /**
+ * Set when no other error code can describe the exception that occurred.
+ */
+ public static final int UNKNOWN_ERROR = 1;
- /**
- * Set when delivery fails due to a failure in network communications or
- * a transport error.
- */
- public static final int NETWORK_FAILURE = 2;
+ /**
+ * Set when delivery fails due to a failure in network communications or
+ * a transport error.
+ */
+ public static final int NETWORK_FAILURE = 2;
- /**
- * Set to indicate that delivery has failed because the provider was not
- * registered.
- */
- public static final int PROVIDER_NOT_REGISTERED = 3;
+ /**
+ * Set to indicate that delivery has failed because the provider was not
+ * registered.
+ */
+ public static final int PROVIDER_NOT_REGISTERED = 3;
- /**
- * Set when delivery fails for implementation specific reasons.
- */
- public static final int INTERNAL_ERROR = 4;
+ /**
+ * Set when delivery fails for implementation specific reasons.
+ */
+ public static final int INTERNAL_ERROR = 4;
- /**
- * Set when delivery fails because we're trying to send a message to a
- * contact that is currently offline and the server does not support
- * offline messages.
- */
- public static final int OFFLINE_MESSAGES_NOT_SUPPORTED = 5;
+ /**
+ * Set when delivery fails because we're trying to send a message to a
+ * contact that is currently offline and the server does not support
+ * offline messages.
+ */
+ public static final int OFFLINE_MESSAGES_NOT_SUPPORTED = 5;
+
+ /**
+ * Set when delivery fails because of dependency on an operation that is
+ * unsupported. For example, because it is unknown or not supported at that
+ * particular moment. (Skipped value 6 just in case, since it is used in
+ * ChatRoomMessageDeliveryFailedEvent.)
+ */
+ public static final int UNSUPPORTED_OPERATION = 7;
/**
* An error code indicating the reason for the failure of this delivery.