diff options
author | Danny van Heumen <danny@dannyvanheumen.nl> | 2013-11-12 23:03:30 +0100 |
---|---|---|
committer | Danny van Heumen <danny@dannyvanheumen.nl> | 2014-07-30 18:29:57 +0200 |
commit | 91b93500cc4a4c1a41ebf7375941e363306fb12c (patch) | |
tree | 8237d6e73928c8103ffe750af6352839e23cc648 | |
parent | 4dab0a4d3133e05dc0cace395fcffdeaee0415a5 (diff) | |
download | jitsi-91b93500cc4a4c1a41ebf7375941e363306fb12c.zip jitsi-91b93500cc4a4c1a41ebf7375941e363306fb12c.tar.gz jitsi-91b93500cc4a4c1a41ebf7375941e363306fb12c.tar.bz2 |
Minimal IRC stack set-up.
-rw-r--r-- | build.xml | 6 | ||||
-rw-r--r-- | lib/installer-exclude/irc-api-1.0.jar | bin | 0 -> 175417 bytes | |||
-rw-r--r-- | lib/installer-exclude/slf4j-api-1.7.5.jar | bin | 0 -> 26084 bytes | |||
-rw-r--r-- | lib/installer-exclude/slf4j-simple-1.7.5.jar | bin | 0 -> 10680 bytes | |||
-rw-r--r-- | src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java | 187 | ||||
-rw-r--r-- | src/net/java/sip/communicator/impl/protocol/irc/irc.provider.manifest.mf | 3 |
6 files changed, 177 insertions, 19 deletions
@@ -2092,6 +2092,12 @@ javax.swing.event, javax.swing.border"/> manifest="${src}/net/java/sip/communicator/impl/protocol/irc/irc.provider.manifest.mf"> <zipfileset dir="${dest}/net/java/sip/communicator/impl/protocol/irc" prefix="net/java/sip/communicator/impl/protocol/irc"/> + <zipfileset src="${lib.noinst}/irc-api-1.0.jar" + prefix="" /> + <zipfileset src="${lib.noinst}/slf4j-api-1.7.5.jar" + prefix="" /> + <zipfileset src="${lib.noinst}/slf4j-simple-1.7.5.jar" + prefix="" /> </jar> </target> diff --git a/lib/installer-exclude/irc-api-1.0.jar b/lib/installer-exclude/irc-api-1.0.jar Binary files differnew file mode 100644 index 0000000..ab49b1b --- /dev/null +++ b/lib/installer-exclude/irc-api-1.0.jar diff --git a/lib/installer-exclude/slf4j-api-1.7.5.jar b/lib/installer-exclude/slf4j-api-1.7.5.jar Binary files differnew file mode 100644 index 0000000..8766455 --- /dev/null +++ b/lib/installer-exclude/slf4j-api-1.7.5.jar diff --git a/lib/installer-exclude/slf4j-simple-1.7.5.jar b/lib/installer-exclude/slf4j-simple-1.7.5.jar Binary files differnew file mode 100644 index 0000000..9dece31 --- /dev/null +++ b/lib/installer-exclude/slf4j-simple-1.7.5.jar 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 7f85df3..6d245bb 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java @@ -8,6 +8,13 @@ package net.java.sip.communicator.impl.protocol.irc; import java.util.*; +import com.ircclouds.irc.api.Callback; +import com.ircclouds.irc.api.IRCApi; +import com.ircclouds.irc.api.IRCApiImpl; +import com.ircclouds.irc.api.IServerParameters; +import com.ircclouds.irc.api.domain.IRCServer; +import com.ircclouds.irc.api.state.IIRCState; + import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.*; @@ -16,53 +23,118 @@ import net.java.sip.communicator.util.*; */ public class IrcStack { - private static final Logger logger = Logger.getLogger(IrcStack.class); + private static final Logger LOGGER = Logger.getLogger(IrcStack.class); - /** - * Timeout for server response. - */ - private static final int TIMEOUT = 10000; + private final ProtocolProviderServiceIrcImpl provider; + + private final IRCApi irc = new IRCApiImpl(true); + + private final ServerParameters params; - public IrcStack(ProtocolProviderServiceIrcImpl parentProvider, String nick, String login, String version, String finger) + private IIRCState connectionState; + + public IrcStack(final ProtocolProviderServiceIrcImpl parentProvider, final String nick, final String login, final String version, final String finger) { - //TODO Implement this. + if (parentProvider == null) + { + throw new NullPointerException("parentProvider cannot be null"); + } + this.provider = parentProvider; + this.params = new IrcStack.ServerParameters(nick, "", finger, null); } public boolean isConnected() { - //TODO Implement this. - return false; + return (this.connectionState != null && this.connectionState.isConnected()); } public void connect(String host, int port, String password, boolean autoNickChange) { - //TODO Implement this. + this.params.setServer(new IRCServer(host, port, password, false)); + synchronized(this.irc) + { + // start connecting to the specified server ... + this.irc.connect(this.params, new Callback<IIRCState>() + { + + @Override + public void onSuccess(IIRCState state) + { + synchronized(IrcStack.this.irc) + { + System.out.println("IRC connected successfully!"); + IrcStack.this.connectionState = state; + IrcStack.this.irc.notifyAll(); + } + } + + @Override + public void onFailure(Exception e) + { + synchronized(IrcStack.this.irc) + { + System.out.println("IRC connection FAILED!"); + e.printStackTrace(); + IrcStack.this.connectionState = null; + IrcStack.this.irc.notifyAll(); + } + } + }); + + // wait while the irc connection is being established ... + try + { + System.out.println("Waiting for a connection ..."); + this.irc.wait(); + } + catch (InterruptedException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + //TODO do something on connection fail! + } } public void disconnect() { - //TODO Implement this. + if(this.connectionState != null) + { + this.irc.disconnect(); + this.connectionState = null; + } } public void dispose() { - //TODO Implement this. + disconnect(); } public String getNick() { - //TODO Implement this. - return ""; + return (this.connectionState == null) ? this.params.getNickname() : this.connectionState.getNickname(); } public void setUserNickname(String nick) { - //TODO Implement this. + if (this.connectionState == null) + { + this.params.setNickname(nick); + } + else + { + this.irc.changeNick(nick); + } } public void setSubject(ChatRoomIrcImpl chatroom, String subject) { - //TODO Implement this. + if (this.connectionState == null) + throw new IllegalStateException("Please connect to an IRC server first."); + if (chatroom == null) + throw new IllegalArgumentException("Cannot have a null chatroom"); + this.irc.changeTopic(chatroom.getName(), subject == null ? "" : subject); } public boolean isJoined(ChatRoomIrcImpl chatroom) @@ -79,12 +151,18 @@ public class IrcStack public void join(ChatRoomIrcImpl chatroom) { - //TODO Implement this. + join(chatroom, "".getBytes()); } public void join(ChatRoomIrcImpl chatroom, byte[] password) { - //TODO Implement this. + //TODO password as String + if (chatroom == null) + throw new IllegalArgumentException("chatroom cannot be null"); + if (password == null) + throw new IllegalArgumentException("password cannot be null"); + //TODO add chatroom listener + this.irc.joinChannel(chatroom.getName(), password.toString()); } public void leave(ChatRoomIrcImpl chatroom) @@ -116,4 +194,77 @@ public class IrcStack { //TODO Implement this. } + + private static class ServerParameters implements IServerParameters { + + private String nick; + private List<String> alternativeNicks = new ArrayList<String>(); + private String real; + private String ident; + private IRCServer server; + + private ServerParameters(String nickName, String realName, String ident, IRCServer server) + { + this.nick = nickName; + this.alternativeNicks.add(nickName+"_"); + this.real = realName; + this.ident = ident; + this.server = server; + } + + @Override + public String getNickname() + { + return this.nick; + } + + public void setNickname(String nick) + { + this.nick = nick; + } + + @Override + public List<String> getAlternativeNicknames() + { + return this.alternativeNicks; + } + + public void setAlternativeNicknames(List<String> names) + { + this.alternativeNicks = names; + } + + @Override + public String getIdent() + { + return this.ident; + } + + public void setIdent(String ident) + { + this.ident = ident; + } + + @Override + public String getRealname() + { + return this.real; + } + + public void setRealname(String realname) + { + this.real = realname; + } + + @Override + public IRCServer getServer() + { + return this.server; + } + + public void setServer(IRCServer server) + { + this.server = server; + } + } } diff --git a/src/net/java/sip/communicator/impl/protocol/irc/irc.provider.manifest.mf b/src/net/java/sip/communicator/impl/protocol/irc/irc.provider.manifest.mf index b7ef354..f50530d 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/irc.provider.manifest.mf +++ b/src/net/java/sip/communicator/impl/protocol/irc/irc.provider.manifest.mf @@ -6,7 +6,8 @@ Bundle-Version: 0.0.1 Bundle-SymbolicName: net.java.sip.communicator.protocol.irc Import-Package: org.osgi.framework, org.jitsi.service.configuration, - org.jitsi.service.resources, net.java.sip.communicator.service.resources, + org.jitsi.service.resources, + net.java.sip.communicator.service.resources, net.java.sip.communicator.util, net.java.sip.communicator.service.protocol, net.java.sip.communicator.service.protocol.event |