diff options
author | Danny van Heumen <danny@dannyvanheumen.nl> | 2014-10-18 20:17:16 +0200 |
---|---|---|
committer | Danny van Heumen <danny@dannyvanheumen.nl> | 2014-10-28 22:33:33 +0100 |
commit | dd1b9598cd3617c0d2f0ec78bcd28ae2c54d9629 (patch) | |
tree | 96c71bc4e08e50e0164f4f3fb3bee76b59970506 /src/net/java/sip/communicator | |
parent | 340dc5730a12a0fff08ece4afb8d1fbb04440f63 (diff) | |
download | jitsi-dd1b9598cd3617c0d2f0ec78bcd28ae2c54d9629.zip jitsi-dd1b9598cd3617c0d2f0ec78bcd28ae2c54d9629.tar.gz jitsi-dd1b9598cd3617c0d2f0ec78bcd28ae2c54d9629.tar.bz2 |
Added support for ISUPPORT CHANNELLEN server parameter.
Diffstat (limited to 'src/net/java/sip/communicator')
3 files changed, 71 insertions, 6 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/irc/ChannelManager.java b/src/net/java/sip/communicator/impl/protocol/irc/ChannelManager.java index 00c2ec3..b22bc28 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/ChannelManager.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/ChannelManager.java @@ -28,8 +28,6 @@ import com.ircclouds.irc.api.state.*; * * TODO Do we need to cancel any join channel operations still in progress? * - * TODO Check ISUPPORT 'CHANNELLEN' for maximum channel name length. - * * TODO Check ISUPPORT 'CHANLIMIT' for maximum number of joined channels. * * @author Danny van Heumen @@ -72,6 +70,13 @@ public class ChannelManager .synchronizedMap(new HashMap<String, ChatRoomIrcImpl>()); /** + * Maximum channel name length according to server ISUPPORT instructions. + * + * <p>This value is not guaranteed, so it may be <tt>null</tt>.</p> + */ + private final Integer isupportChannelLen; + + /** * Constructor. * @param irc thread-safe IRCApi instance * @param connectionState the connection state @@ -97,6 +102,30 @@ public class ChannelManager } this.provider = provider; this.irc.addListener(new ManagerListener()); + this.isupportChannelLen = parseISupportChannelLen(this.connectionState); + } + + /** + * Parse the ISUPPORT parameter for server's max channel name length. + * + * @param state the connection state + * @return returns instance with max channel name length or <tt>null</tt> if + * not specified. + */ + private Integer parseISupportChannelLen(final IIRCState state) + { + final String value = + state.getServerOptions().getKey(ISupport.CHANNELLEN.name()); + if (value == null) + { + return null; + } + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug("Setting ISUPPORT parameter " + + ISupport.CHANNELLEN.name() + " to " + value); + } + return new Integer(value); } /** @@ -168,6 +197,13 @@ public class ChannelManager // is required. return; } + if (this.isupportChannelLen != null + && chatRoomId.length() > this.isupportChannelLen.intValue()) + { + throw new IllegalArgumentException("the channel name must not be " + + "longer than " + this.isupportChannelLen.intValue() + + " characters according to server parameters."); + } LOGGER.trace("Start joining channel " + chatRoomId); final Result<Object, Exception> joinSignal = 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 28bbc71..42e2060 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java @@ -329,7 +329,15 @@ public class ChatRoomIrcImpl OperationFailedException.SUBSCRIPTION_ALREADY_EXISTS); } - connection.getChannelManager().join(this); + try + { + connection.getChannelManager().join(this); + } + catch (final IllegalArgumentException e) + { + throw new OperationFailedException(e.getMessage(), + OperationFailedException.CHAT_ROOM_NOT_JOINED, e); + } } /** @@ -347,9 +355,26 @@ public class ChatRoomIrcImpl this.parentProvider.getIrcStack().getConnection(); if (connection == null) { - return; + throw new OperationFailedException( + "We are currently not connected to the server.", + OperationFailedException.NETWORK_FAILURE); + } + + if (connection.getChannelManager().isJoined(this)) + { + throw new OperationFailedException("Channel is already joined.", + OperationFailedException.SUBSCRIPTION_ALREADY_EXISTS); + } + + try + { + connection.getChannelManager().join(this, password.toString()); + } + catch (final IllegalArgumentException e) + { + throw new OperationFailedException(e.getMessage(), + OperationFailedException.CHAT_ROOM_NOT_JOINED, e); } - connection.getChannelManager().join(this, password.toString()); } /** diff --git a/src/net/java/sip/communicator/impl/protocol/irc/ISupport.java b/src/net/java/sip/communicator/impl/protocol/irc/ISupport.java index 54a1ab9..c9f4f74 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/ISupport.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/ISupport.java @@ -10,5 +10,9 @@ public enum ISupport /** * Maximum nick length allowed by IRC server. */ - NICKLEN; + NICKLEN, + /** + * Maximum channel name length allowed by IRC server. + */ + CHANNELLEN; } |