diff options
author | Danny van Heumen <danny@dannyvanheumen.nl> | 2014-10-13 23:28:54 +0200 |
---|---|---|
committer | Danny van Heumen <danny@dannyvanheumen.nl> | 2014-10-28 22:33:32 +0100 |
commit | f1540021c0416c6aa09e1cdf3cf03293b44a905a (patch) | |
tree | 424ec2e3d56e2b8a7fc200f0cf09c4b691424800 /src/net/java/sip/communicator/impl/protocol/irc | |
parent | 8ec14739c1bbba18c8c1544fa3db5c7d864673f3 (diff) | |
download | jitsi-f1540021c0416c6aa09e1cdf3cf03293b44a905a.zip jitsi-f1540021c0416c6aa09e1cdf3cf03293b44a905a.tar.gz jitsi-f1540021c0416c6aa09e1cdf3cf03293b44a905a.tar.bz2 |
Support nick changes except on chat room join.
Diffstat (limited to 'src/net/java/sip/communicator/impl/protocol/irc')
4 files changed, 83 insertions, 66 deletions
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 3bca2b7..720160d 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java @@ -340,6 +340,10 @@ public class ChatRoomIrcImpl { final IrcConnection connection = this.parentProvider.getIrcStack().getConnection(); + if (connection == null) + { + return; + } connection.getChannelManager().join(this, password.toString()); } @@ -349,16 +353,20 @@ public class ChatRoomIrcImpl * contains a user with this nickname, the method would throw an * OperationFailedException with code IDENTIFICATION_CONFLICT. * + * The provided nick name is ignored, since IRC does not support nick + * changes limited to a single chat room. + * * @param nickname the nickname to use. * @throws OperationFailedException with the corresponding code if an error * occurs while joining the room. */ public void joinAs(final String nickname) throws OperationFailedException { - // TODO consider not supporting setting a nickname here, and re-enabling - // set nick name option such that it is still possible to change nick on - // demand. - this.setUserNickname(nickname); + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug("Not setting nick name upon chat room join, since a " + + "nick change is not limited to a single chat room."); + } this.join(); } @@ -368,6 +376,9 @@ public class ChatRoomIrcImpl * already contains a user with this nickname, the method would throw an * OperationFailedException with code IDENTIFICATION_CONFLICT. * + * The provided nick name is ignored, since IRC does not support nick + * changes limited to a single chat room. + * * @param nickname the nickname to use. * @param password a password necessary to authenticate when joining the * room. @@ -377,10 +388,11 @@ public class ChatRoomIrcImpl public void joinAs(final String nickname, final byte[] password) throws OperationFailedException { - // TODO consider not supporting setting a nickname here, and re-enabling - // set nick name option such that it is still possible to change nick on - // demand. - this.setUserNickname(nickname); + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug("Not setting nick name upon chat room join, since a " + + "nick change is not limited to a single chat room."); + } this.join(password); } @@ -707,14 +719,13 @@ public class ChatRoomIrcImpl public void setUserNickname(final String nickName) throws OperationFailedException { - // TODO Joining a chat room fails altogether if we throw an - // OperationFailedException here. - LOGGER.info("Setting a nick name for an individual chat room is not " - + "supported for IRC."); - // throw new OperationFailedException( - // "Nick names are managed by the connection to the IRC server. They " - // + "cannot be changed on the level of an invididual chat room.", - // OperationFailedException.NOT_SUPPORTED_OPERATION); + final IrcConnection connection = + this.parentProvider.getIrcStack().getConnection(); + if (connection == null) + { + return; + } + connection.getIdentityManager().setNick(nickName); } /** diff --git a/src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java b/src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java index 1ae842e..d5ba905 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java @@ -6,6 +6,8 @@ */ package net.java.sip.communicator.impl.protocol.irc; +import java.util.*; + import net.java.sip.communicator.util.*; import com.ircclouds.irc.api.*; @@ -33,6 +35,22 @@ public class IdentityManager .getLogger(IdentityManager.class); /** + * Reserved symbols. These symbols have special meaning and cannot be + * used to start nick names. + */ + private static final Set<Character> RESERVED; + + /** + * Initialize RESERVED symbols set. + */ + static { + final HashSet<Character> reserved = new HashSet<Character>(); + reserved.add('#'); + reserved.add('&'); + RESERVED = Collections.unmodifiableSet(reserved); + } + + /** * The IRCApi instance. * * Instance must be thread-safe! @@ -93,6 +111,41 @@ public class IdentityManager } /** + * Set a new nick name. + * + * TODO Check ISUPPORT 'NICKLEN' for maximum nick length. + * + * @param nick new nick + */ + public void setNick(final String nick) + { + this.irc.changeNick(checkNick(nick)); + } + + /** + * Verify nick name. + * + * @param nick nick name + * @return returns nick name + */ + public static String checkNick(final String nick) + { + if (nick == null) + { + throw new IllegalArgumentException( + "a nick name must be provided"); + } + // TODO Add '+' and '!' to reserved symbols too? + if (RESERVED.contains(nick.charAt(0))) + { + throw new IllegalArgumentException( + "the nick name must not start with '#' or '&' " + + "since this is reserved for IRC channels"); + } + return nick; + } + + /** * Get the current identity string, based on nick, user and host of local * user. * @@ -213,16 +266,6 @@ public class IdentityManager private String host = null; /** - * Constructor. - * - * @param user user - * @param host host - */ - private Identity() - { - } - - /** * Set user. * * @param user the new user diff --git a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java index f3a2ec7..0c1571c 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java @@ -259,22 +259,6 @@ public class IrcStack private static final int NUM_INCREMENTS_FOR_ALTERNATIVES = 10; /** - * Reserved symbols. These symbols have special meaning and cannot be - * used to start nick names. - */ - private static final Set<Character> RESERVED; - - /** - * Initialize RESERVED symbols set. - */ - static { - final HashSet<Character> reserved = new HashSet<Character>(); - reserved.add('#'); - reserved.add('&'); - RESERVED = Collections.unmodifiableSet(reserved); - } - - /** * Nick name. */ private String nick; @@ -309,7 +293,7 @@ public class IrcStack private ServerParameters(final String nickName, final String realName, final String ident, final IRCServer server) { - this.nick = checkNick(nickName); + this.nick = IdentityManager.checkNick(nickName); this.alternativeNicks.add(nickName + "_"); this.alternativeNicks.add(nickName + "__"); this.alternativeNicks.add(nickName + "___"); @@ -335,29 +319,6 @@ public class IrcStack } /** - * Verify nick name. - * - * @param nick nick name - * @return returns nick name - */ - private static String checkNick(final String nick) - { - if (nick == null) - { - throw new IllegalArgumentException( - "a nick name must be provided"); - } - // TODO Add '+' and '!' to reserved symbols too? - if (RESERVED.contains(nick.charAt(0))) - { - throw new IllegalArgumentException( - "the nick name must not start with '#' or '&' " - + "since this is reserved for IRC channels"); - } - return nick; - } - - /** * Get alternative nick names. * * @return returns list of alternatives 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 2f3c025..9559411 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java @@ -175,6 +175,8 @@ public class MessageManager } 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); } } |