Added changes to irc-api NOTICE + feedback changes

fix-message-formatting
Danny van Heumen 12 years ago
parent f2ea6fc71b
commit 29191bb349

@ -2,3 +2,177 @@ http://irc-api.googlecode.com/svn/trunk@179
Additional modifications: Additional modifications:
------------------------- -------------------------
commit 99062b621dcf6722fc0b8c868abc806092369086
Author: Danny van Heumen <danny@dannyvanheumen.nl>
Date: Sun Jan 26 22:46:28 2014 +0100
Added support for providing custom SSLContext.
diff --git a/src/main/java/com/ircclouds/irc/api/AbstractIRCSession.java b/src/main/java/com/ircclouds/irc/api/AbstractIRCSession.java
index 67bdecd..08b5030 100644
--- a/src/main/java/com/ircclouds/irc/api/AbstractIRCSession.java
+++ b/src/main/java/com/ircclouds/irc/api/AbstractIRCSession.java
@@ -2,6 +2,8 @@ package com.ircclouds.irc.api;
import java.io.*;
+import javax.net.ssl.*;
+
import com.ircclouds.irc.api.commands.*;
import com.ircclouds.irc.api.comms.*;
import com.ircclouds.irc.api.domain.*;
@@ -90,7 +92,7 @@ public abstract class AbstractIRCSession implements IIRCSession
}
@Override
- public boolean open(IRCServer aServer) throws IOException
+ public boolean open(IRCServer aServer, SSLContext aCustomContext) throws IOException
{
if (!aServer.isSSL())
{
@@ -98,7 +100,7 @@ public abstract class AbstractIRCSession implements IIRCSession
}
else
{
- conn = new SSLSocketChannelConnection();
+ conn = new SSLSocketChannelConnection(aCustomContext);
}
if (conn.open(aServer.getHostname(), aServer.getPort()))
diff --git a/src/main/java/com/ircclouds/irc/api/IIRCSession.java b/src/main/java/com/ircclouds/irc/api/IIRCSession.java
index eafb171..b17f1ae 100644
--- a/src/main/java/com/ircclouds/irc/api/IIRCSession.java
+++ b/src/main/java/com/ircclouds/irc/api/IIRCSession.java
@@ -2,6 +2,8 @@ package com.ircclouds.irc.api;
import java.io.*;
+import javax.net.ssl.*;
+
import com.ircclouds.irc.api.domain.*;
import com.ircclouds.irc.api.filters.*;
import com.ircclouds.irc.api.listeners.*;
@@ -14,7 +16,7 @@ public interface IIRCSession
void removeListener(IMessageListener aListener);
- boolean open(IRCServer aServer) throws IOException;
+ boolean open(IRCServer aServer, SSLContext aCustomContext) throws IOException;
void close() throws IOException;
diff --git a/src/main/java/com/ircclouds/irc/api/IRCApiImpl.java b/src/main/java/com/ircclouds/irc/api/IRCApiImpl.java
index 8b60c05..4bb1408 100644
--- a/src/main/java/com/ircclouds/irc/api/IRCApiImpl.java
+++ b/src/main/java/com/ircclouds/irc/api/IRCApiImpl.java
@@ -96,7 +96,7 @@ public class IRCApiImpl implements IRCApi
boolean _isOpen = false;
try
{
- if (_isOpen = session.open(aServerParameters.getServer()))
+ if (_isOpen = session.open(aServerParameters.getServer(), aServerParameters.getCustomContext()))
{
executeAsync(new ConnectCmd(aServerParameters), aCallback, _d);
}
diff --git a/src/main/java/com/ircclouds/irc/api/IServerParameters.java b/src/main/java/com/ircclouds/irc/api/IServerParameters.java
index b3bc942..2338ed5 100644
--- a/src/main/java/com/ircclouds/irc/api/IServerParameters.java
+++ b/src/main/java/com/ircclouds/irc/api/IServerParameters.java
@@ -2,6 +2,8 @@ package com.ircclouds.irc.api;
import java.util.*;
+import javax.net.ssl.*;
+
import com.ircclouds.irc.api.domain.*;
/**
@@ -41,4 +43,10 @@ public interface IServerParameters
* @return
*/
IRCServer getServer();
+
+ /**
+ * Returns the custom SSL context if it is specified, or null otherwise.
+ * @return returns SSLContext instance or null
+ */
+ SSLContext getCustomContext();
}
diff --git a/src/main/java/com/ircclouds/irc/api/comms/SSLSocketChannelConnection.java b/src/main/java/com/ircclouds/irc/api/comms/SSLSocketChannelConnection.java
index c9096ac..abec187 100644
--- a/src/main/java/com/ircclouds/irc/api/comms/SSLSocketChannelConnection.java
+++ b/src/main/java/com/ircclouds/irc/api/comms/SSLSocketChannelConnection.java
@@ -14,7 +14,8 @@ import org.slf4j.*;
public class SSLSocketChannelConnection implements IConnection
{
private static final Logger LOG = LoggerFactory.getLogger(SSLSocketChannelConnection.class);
-
+
+ private final SSLContext customContext;
private SocketChannel sChannel;
private SSLEngine sslEngine;
@@ -25,12 +26,23 @@ public class SSLSocketChannelConnection implements IConnection
private HandshakeStatus hStatus;
private int remaingUnwraps;
+
+ public SSLSocketChannelConnection(SSLContext customContext)
+ {
+ this.customContext = customContext;
+ }
public boolean open(String aHostname, int aPort) throws IOException
{
try
{
- sslEngine = getInitializedSSLContext().createSSLEngine(aHostname, aPort);
+ SSLContext context = this.customContext;
+ if (context == null)
+ {
+ // initialize default SSLContext
+ context = getInitializedSSLContext();
+ }
+ sslEngine = context.createSSLEngine(aHostname, aPort);
sslEngine.setNeedClientAuth(false);
sslEngine.setUseClientMode(true);
sslEngine.beginHandshake();
diff --git a/src/test/java/com/ircclouds/irc/api/MockServerParametersImpl.java b/src/test/java/com/ircclouds/irc/api/MockServerParametersImpl.java
index 105b509..68dd46b 100644
--- a/src/test/java/com/ircclouds/irc/api/MockServerParametersImpl.java
+++ b/src/test/java/com/ircclouds/irc/api/MockServerParametersImpl.java
@@ -2,6 +2,8 @@ package com.ircclouds.irc.api;
import java.util.*;
+import javax.net.ssl.*;
+
import com.ircclouds.irc.api.domain.*;
class MockServerParametersImpl implements IServerParameters
@@ -11,6 +13,7 @@ class MockServerParametersImpl implements IServerParameters
private String ident;
private String realname;
private IRCServer server;
+ private SSLContext customContext;
public MockServerParametersImpl(String aNickname, List<String> aAltNicks, String aIdent, String aRealname, IRCServer aServer)
{
@@ -19,6 +22,7 @@ class MockServerParametersImpl implements IServerParameters
ident = aIdent;
realname = aRealname;
server = aServer;
+ customContext = null;
}
@Override
@@ -51,4 +55,9 @@ class MockServerParametersImpl implements IServerParameters
return server;
}
+ @Override
+ public SSLContext getCustomContext()
+ {
+ return customContext;
+ }
}

@ -128,6 +128,7 @@ public static BundleContext getBundleContext()
{ {
return bundleContext; return bundleContext;
} }
/** /**
* Return the certificate verification service impl. * Return the certificate verification service impl.
* *

@ -103,8 +103,8 @@ public IrcStack(final ProtocolProviderServiceIrcImpl parentProvider,
*/ */
public boolean isConnected() public boolean isConnected()
{ {
return (this.irc != null && this.connectionState != null && this.connectionState return (this.irc != null && this.connectionState != null
.isConnected()); && this.connectionState.isConnected());
} }
/** /**
@ -192,7 +192,8 @@ public void onFailure(Exception e)
while (!result.isDone()) while (!result.isDone())
{ {
LOGGER LOGGER
.trace("Waiting for the connection to be established ..."); .trace("Waiting for the connection to be established "
+ "...");
result.wait(); result.wait();
} }
@ -203,15 +204,16 @@ public void onFailure(Exception e)
&& this.connectionState.isConnected()) && this.connectionState.isConnected())
{ {
// if connecting succeeded, set state to registered // if connecting succeeded, set state to registered
this.provider this.provider.setCurrentRegistrationState(
.setCurrentRegistrationState(RegistrationState.REGISTERED); RegistrationState.REGISTERED);
} }
else else
{ {
// if connecting failed, set state to unregistered and throw // if connecting failed, set state to unregistered and throw
// the exception if one exists // the exception if one exists
this.provider this.provider
.setCurrentRegistrationState(RegistrationState.UNREGISTERED); .setCurrentRegistrationState(
RegistrationState.UNREGISTERED);
Exception e = result.getException(); Exception e = result.getException();
if (e != null) if (e != null)
throw e; throw e;
@ -220,13 +222,15 @@ public void onFailure(Exception e)
catch (IOException e) catch (IOException e)
{ {
this.provider this.provider
.setCurrentRegistrationState(RegistrationState.UNREGISTERED); .setCurrentRegistrationState(
RegistrationState.UNREGISTERED);
throw e; throw e;
} }
catch (InterruptedException e) catch (InterruptedException e)
{ {
this.provider this.provider
.setCurrentRegistrationState(RegistrationState.UNREGISTERED); .setCurrentRegistrationState(
RegistrationState.UNREGISTERED);
throw e; throw e;
} }
} }
@ -336,7 +340,8 @@ public void setSubject(ChatRoomIrcImpl chatroom, String subject)
throw new IllegalArgumentException("Cannot have a null chatroom"); throw new IllegalArgumentException("Cannot have a null chatroom");
LOGGER.trace("Setting chat room topic to '" + subject + "'"); LOGGER.trace("Setting chat room topic to '" + subject + "'");
this.irc this.irc
.changeTopic(chatroom.getIdentifier(), subject == null ? "" : subject); .changeTopic(chatroom.getIdentifier(),
subject == null ? "" : subject);
} }
/** /**
@ -442,7 +447,8 @@ public void join(final ChatRoomIrcImpl chatroom, final String password)
synchronized (joinSignal) synchronized (joinSignal)
{ {
LOGGER LOGGER
.trace("Issue join channel command to IRC library and wait for join operation to complete (un)successfully."); .trace("Issue join channel command to IRC library and wait "
+ "for join operation to complete (un)successfully.");
// TODO Refactor this ridiculous nesting of functions and // TODO Refactor this ridiculous nesting of functions and
// classes. // classes.
this.irc.joinChannel(chatroom.getIdentifier(), password, this.irc.joinChannel(chatroom.getIdentifier(), password,
@ -453,7 +459,8 @@ public void join(final ChatRoomIrcImpl chatroom, final String password)
public void onSuccess(IRCChannel channel) public void onSuccess(IRCChannel channel)
{ {
LOGGER LOGGER
.trace("Started callback for successful join of channel '" .trace("Started callback for successful join of "
+ "channel '"
+ chatroom.getIdentifier() + "'."); + chatroom.getIdentifier() + "'.");
ChatRoomIrcImpl actualChatRoom = chatroom; ChatRoomIrcImpl actualChatRoom = chatroom;
synchronized (joinSignal) synchronized (joinSignal)
@ -482,7 +489,8 @@ public void onSuccess(IRCChannel channel)
message, message,
null, null,
new Date(), new Date(),
MessageReceivedEvent.SYSTEM_MESSAGE_RECEIVED); MessageReceivedEvent
.SYSTEM_MESSAGE_RECEIVED);
} }
IrcStack.this.joined.put( IrcStack.this.joined.put(
@ -536,10 +544,12 @@ public void onSuccess(IRCChannel channel)
.getMUC() .getMUC()
.fireLocalUserPresenceEvent( .fireLocalUserPresenceEvent(
actualChatRoom, actualChatRoom,
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_JOINED, LocalUserChatRoomPresenceChangeEvent
.LOCAL_USER_JOINED,
null); null);
LOGGER LOGGER
.trace("Finished successful join callback for channel '" .trace("Finished successful join callback "
+ "for channel '"
+ chatroom.getIdentifier() + chatroom.getIdentifier()
+ "'. Waking up original thread."); + "'. Waking up original thread.");
// Notify waiting threads of finished // Notify waiting threads of finished
@ -554,8 +564,9 @@ public void onSuccess(IRCChannel channel)
public void onFailure(Exception e) public void onFailure(Exception e)
{ {
LOGGER LOGGER
.trace("Started callback for failed attempt to join channel '" .trace("Started callback for failed attempt to "
+ chatroom.getIdentifier() + "'."); + "join channel '" + chatroom.getIdentifier()
+ "'.");
// TODO how should we communicate a failed attempt // TODO how should we communicate a failed attempt
// at joining the channel? (System messages don't // at joining the channel? (System messages don't
// seem to show if there is no actual chat room // seem to show if there is no actual chat room
@ -569,18 +580,21 @@ public void onFailure(Exception e)
"Failed to join channel " "Failed to join channel "
+ chatroom.getIdentifier() + " (" + chatroom.getIdentifier() + " ("
+ e.getMessage() + ")", + e.getMessage() + ")",
"text/plain", "UTF-8", "Failed to join"); "text/plain", "UTF-8",
"Failed to join");
chatroom chatroom
.fireMessageReceivedEvent( .fireMessageReceivedEvent(
message, message,
null, null,
new Date(), new Date(),
MessageReceivedEvent.SYSTEM_MESSAGE_RECEIVED); MessageReceivedEvent
.SYSTEM_MESSAGE_RECEIVED);
} }
finally finally
{ {
LOGGER LOGGER
.trace("Finished callback for failed attempt to join channel '" .trace("Finished callback for failed "
+ "attempt to join channel '"
+ chatroom.getIdentifier() + chatroom.getIdentifier()
+ "'. Waking up original thread."); + "'. Waking up original thread.");
// Notify waiting threads of finished // Notify waiting threads of finished
@ -957,7 +971,8 @@ public void onChannelPart(ChanPartMessage msg)
{ {
LOGGER LOGGER
.warn( .warn(
"This should not have happened. Please report this as it is a bug.", "This should not have happened. Please report this "
+ "as it is a bug.",
e); e);
} }
} }

Loading…
Cancel
Save