├── .travis.yml ├── .gitignore ├── license-header-template.txt ├── README.txt ├── src └── main │ └── java │ └── org │ └── schwering │ └── irc │ └── lib │ ├── IRCConfig.java │ ├── IRCUser.java │ ├── IRCConnectionFactory.java │ ├── impl │ ├── package.html │ ├── DefaultIRCUser.java │ ├── SocketFactory.java │ ├── DefaultIRCSSLSupport.java │ ├── DefaultIRCRuntimeConfig.java │ ├── DefaultIRCServerConfig.java │ └── DefaultIRCConfig.java │ ├── IRCSSLSupport.java │ ├── util │ ├── LoggingReader.java │ ├── LoggingWriter.java │ ├── IRCConstants.java │ ├── CTCPCommand.java │ ├── IRCModeParser.java │ ├── IRCUtil.java │ └── IRCParser.java │ ├── IRCExceptionHandler.java │ ├── IRCTrafficLogger.java │ ├── IRCServerConfig.java │ ├── IRCRuntimeConfig.java │ ├── IRCEventAdapter.java │ ├── IRCEventListener.java │ ├── IRCConfigBuilder.java │ └── IRCConnection.java ├── checkstyle.xml ├── COPYING_AL.txt ├── COPYING_EPL.txt ├── pom.xml └── COPYING_LGPL.txt /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - openjdk6 4 | install: 5 | - mvn -version 6 | script: 7 | - mvn clean install 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # maven 2 | target/ 3 | release.properties 4 | *.versionsBackup 5 | *.releaseBackup 6 | 7 | # Eclipse 8 | bin/ 9 | /.settings/ 10 | /.project 11 | .classpath 12 | .project 13 | 14 | # Mobile Tools for Java (J2ME) 15 | .mtj.tmp/ 16 | 17 | # IntellJ Idea 18 | .idea 19 | *.iml 20 | *.ipr 21 | *.iws 22 | 23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 24 | hs_err_pid* 25 | 26 | -------------------------------------------------------------------------------- /license-header-template.txt: -------------------------------------------------------------------------------- 1 | IRClib - A Java Internet Relay Chat library 2 | Copyright (C) ${license.copyrightYears} Christoph Schwering 3 | and/or other contributors as indicated by the @author tags. 4 | 5 | This library and the accompanying materials are made available under the 6 | terms of the 7 | - GNU Lesser General Public License, 8 | - Apache License, Version 2.0 and 9 | - Eclipse Public License v1.0. 10 | This library is distributed in the hope that it will be useful, but WITHOUT 11 | ANY WARRANTY. -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | IRClib is client library for Internet Relay Chat (IRC) licensed under the 2 | * GNU Lesser General Public License (see COPYING_LGPL), 3 | * Apache License, Version 2.0 (see COPYING_AL) and 4 | * Eclipse Public License (see COPYING_EPL). 5 | 6 | IRClib requires Java Runtime Environment 1.2 or later. It requires 7 | JSSE (Java Secure Socket Extensions) until J2RE 1.3; J2RE 1.4 already 8 | includes JSSE and hence doesn't require JSSE. You can download JSSE 9 | from http://java.sun.com/products/jsse/index-103.html. 10 | 11 | Project website: http://moepii.sourceforge.net (outdated) 12 | 13 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/IRCConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib; 15 | 16 | /** 17 | * A configuration to use when creating a new {@link IRCConnection}, a union of 18 | * {@link IRCServerConfig} and {@link IRCRuntimeConfig}. 19 | * 20 | * @see IRCConnectionFactory#newConnection(IRCConfig) 21 | * @author Peter Palaga 22 | */ 23 | public interface IRCConfig extends IRCServerConfig, IRCRuntimeConfig { 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/IRCUser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib; 15 | 16 | /** 17 | * An IRC user refered to in many IRC relies. 18 | * 19 | * @author Peter Palaga 20 | */ 21 | public interface IRCUser { 22 | 23 | /** 24 | * @return The host of the line or {@code null} if it's not given. 25 | */ 26 | String getHost(); 27 | 28 | /** 29 | * @return The nickname or the servername of the line or {@code null} if no nick is given 30 | */ 31 | String getNick(); 32 | 33 | /** 34 | * @return The username of the lineor {@code null} if it's not given. 35 | */ 36 | String getUsername(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/IRCConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib; 15 | 16 | import org.schwering.irc.lib.impl.DefaultIRCConnection; 17 | 18 | /** 19 | * A factory to create new {@link IRCConnection}s. For the typical usage, see {@link IRCConnection}. 20 | * 21 | * @author Peter Palaga 22 | */ 23 | public class IRCConnectionFactory { 24 | public static IRCConnection newConnection(IRCConfig config) { 25 | return new DefaultIRCConnection(config, config); 26 | } 27 | public static IRCConnection newConnection(IRCServerConfig serverConfig, IRCRuntimeConfig runtimeConfig) { 28 | return new DefaultIRCConnection(serverConfig, runtimeConfig); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/impl/package.html: -------------------------------------------------------------------------------- 1 | 2 | IRClib is a library for the client-side of IRC (Internet Relay Chat) 3 | connections. 4 |

5 | IRClib is RFC1459 and RFC2812 compliant. It's licensed under the GNU Lesser 6 | General Public License, the Apache License 2.0 and the Eclipse Public License 7 | so that you can use and modify it for your purposes for free. 8 |

9 | By instantiating the {@link org.schwering.irc.lib.IRCConnection} 10 | class you can establish a new connection to an IRC server. The 11 | {@link org.schwering.irc.lib.IRCEventListener} informs your class 12 | about lines coming from the server which are parsed by the 13 | {@link org.schwering.irc.lib.IRCParser}. The 14 | {@link org.schwering.irc.lib.IRCModeParser} is especially made for 15 | channel-modes.
16 | To create a secure connection with SSL, instantiate the 17 | {@link org.schwering.irc.lib.ssl.SSLIRCConnection}. 18 |

19 | This project's home page is available at http://moepii.sourceforge.net. 21 |

22 | If you're using IRClib, write a mail to me 23 | so that I can put you on the using-IRClib-list! 24 | 25 | @version 1.11 26 | @author Christoph Schwering <schwering@gmail.com> 27 | 28 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/IRCSSLSupport.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib; 15 | 16 | import java.security.SecureRandom; 17 | 18 | import javax.net.ssl.KeyManager; 19 | import javax.net.ssl.SSLContext; 20 | import javax.net.ssl.TrustManager; 21 | 22 | /** 23 | * A bunch of things necessary to connect using SSL. 24 | * 25 | * @author Peter Palaga 26 | */ 27 | public interface IRCSSLSupport { 28 | 29 | /** 30 | * @return the {@link KeyManager}s to initialize {@link SSLContext} with. 31 | */ 32 | KeyManager[] getKeyManagers(); 33 | 34 | /** 35 | * @return the {@link TrustManager}s to initialize {@link SSLContext} with. 36 | */ 37 | TrustManager[] getTrustManagers(); 38 | 39 | /** 40 | * @return the {@link SecureRandom} to initialize {@link SSLContext} with. 41 | */ 42 | SecureRandom getSecureRandom(); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/util/LoggingReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib.util; 15 | 16 | import java.io.BufferedReader; 17 | import java.io.IOException; 18 | import java.io.Reader; 19 | 20 | import org.schwering.irc.lib.IRCTrafficLogger; 21 | 22 | /** 23 | * A {@link BufferedReader} that sends all read character to its {@link #trafficLogger}. 24 | */ 25 | public class LoggingReader extends BufferedReader { 26 | final IRCTrafficLogger trafficLogger; 27 | 28 | /** 29 | * @param in the reader to read from. 30 | * @param trafficLogger a logger to notify about read characters 31 | */ 32 | public LoggingReader(Reader in, IRCTrafficLogger trafficLogger) { 33 | super(in); 34 | this.trafficLogger = trafficLogger; 35 | } 36 | 37 | /** 38 | * @see java.io.BufferedReader#readLine() 39 | */ 40 | @Override 41 | public String readLine() throws IOException { 42 | String line = super.readLine(); 43 | trafficLogger.in(line); 44 | return line; 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/util/LoggingWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib.util; 15 | 16 | import java.io.PrintWriter; 17 | import java.io.Writer; 18 | 19 | import org.schwering.irc.lib.IRCTrafficLogger; 20 | 21 | /** 22 | * A {@link PrintWriter} that sends all written character also to its {@link #trafficLogger}. 23 | */ 24 | public class LoggingWriter extends PrintWriter { 25 | final IRCTrafficLogger trafficLogger; 26 | 27 | /** 28 | * @param out the {@link Writer} to write to 29 | * @param trafficLogger the logger to notify about the written characters 30 | */ 31 | public LoggingWriter(Writer out, IRCTrafficLogger trafficLogger) { 32 | super(out); 33 | this.trafficLogger = trafficLogger; 34 | } 35 | 36 | /** 37 | * @see java.io.PrintWriter#write(java.lang.String) 38 | */ 39 | @Override 40 | public void write(String s) { 41 | String trimmedLine = s; 42 | if (s != null && s.endsWith("\r\n")) { 43 | trimmedLine = s.substring(0, s.length() - 2); 44 | } 45 | trafficLogger.out(trimmedLine); 46 | super.write(s); 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/IRCExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib; 15 | 16 | /** 17 | * A handler to be notified when there occurs any exception in {@link IRCConnection}. 18 | * 19 | * @author Peter Palaga 20 | */ 21 | public interface IRCExceptionHandler { 22 | 23 | /** A handler that just prints the given exception's stack trace to stderr. */ 24 | IRCExceptionHandler PRINT_STACK_TRACE = new IRCExceptionHandler() { 25 | /** 26 | * @see org.schwering.irc.lib.IRCExceptionHandler#exception(org.schwering.irc.lib.IRCConnection, 27 | * java.lang.Throwable) 28 | */ 29 | @Override 30 | public void exception(IRCConnection connection, Throwable e) { 31 | e.printStackTrace(); 32 | } 33 | }; 34 | 35 | /** 36 | * Notified upon occurence of the given {@code exception} in the given {@code exception}. 37 | * 38 | * @param connection the connection in which the exception occured 39 | * @param exception the exception that occured 40 | */ 41 | void exception(IRCConnection connection, Throwable exception); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/IRCTrafficLogger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib; 15 | 16 | /** 17 | * A logger for both ingoing and outgoing IRC messages that the IRC client sends and receives. 18 | *

19 | * {@link #SYSTEM_OUT} is a simple {@link IRCTrafficLogger} implementation printing to {@link System#out}. 20 | * 21 | * @author Peter Palaga 22 | */ 23 | public interface IRCTrafficLogger { 24 | /** A {@link IRCTrafficLogger} implementation using {@code System.out} to output the traffic */ 25 | IRCTrafficLogger SYSTEM_OUT = new IRCTrafficLogger() { 26 | @Override 27 | public void out(String line) { 28 | System.out.println("< " + line); 29 | } 30 | 31 | @Override 32 | public void in(String line) { 33 | System.out.println("> " + line); 34 | } 35 | 36 | }; 37 | 38 | /** 39 | * Called when a {@code line} is received from the IRC server. 40 | * @param line the line received from the server 41 | */ 42 | void in(String line); 43 | 44 | /** 45 | * Called when the {@code line} is being sent to the IRC server. 46 | * @param line the line being sent to the server 47 | */ 48 | void out(String line); 49 | 50 | } -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/IRCServerConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib; 15 | 16 | /** 17 | * A typical profile for connecting to an IRC server containing host, port, nick, username, password, etc. 18 | * 19 | * @author Peter Palaga 20 | */ 21 | public interface IRCServerConfig { 22 | 23 | /** 24 | * @return the encoding to use when reading and writing IRC messages 25 | */ 26 | String getEncoding(); 27 | 28 | /** 29 | * @return hostname or IP address of the IRC server to connect to 30 | */ 31 | String getHost(); 32 | 33 | /** 34 | * @return the preffered nick for the connection 35 | */ 36 | String getNick(); 37 | 38 | /** 39 | * @return the password to connect with 40 | */ 41 | String getPassword(); 42 | 43 | /** 44 | * @param index the intex in the internal {@code ports} array 45 | * @return the port number at position {@code index} in the internal {@code ports} array 46 | */ 47 | int getPortAt(int index); 48 | 49 | /** 50 | * @return a copy of internal {@code ports} array 51 | */ 52 | int[] getPorts(); 53 | 54 | /** 55 | * @return the number of ports in the internal {@code ports} array 56 | */ 57 | int getPortsCount(); 58 | 59 | /** 60 | * @return the real name of the user that is connecting 61 | */ 62 | String getRealname(); 63 | 64 | /** 65 | * @return the username to connect with 66 | */ 67 | String getUsername(); 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/IRCRuntimeConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib; 15 | 16 | import java.net.Proxy; 17 | 18 | /** 19 | * The non-server part of the {@link IRCConnection}'s configuration. 20 | * 21 | * @see IRCServerConfig 22 | * @see IRCConfig 23 | * @author Peter Palaga 24 | */ 25 | public interface IRCRuntimeConfig { 26 | 27 | /** 28 | * @return the {@link IRCExceptionHandler} 29 | */ 30 | IRCExceptionHandler getExceptionHandler(); 31 | 32 | /** 33 | * @return the {@link Proxy} to use when connecting 34 | */ 35 | Proxy getProxy(); 36 | 37 | /** 38 | * @return a {@link IRCSSLSupport} if the {@link IRCConnection} should use 39 | * SSL, otherwise {@code null} 40 | */ 41 | IRCSSLSupport getSSLSupport(); 42 | 43 | /** 44 | * @return the socket timeout in milliseconds 45 | */ 46 | int getTimeout(); 47 | 48 | /** 49 | * @return the {@link IRCTrafficLogger} that should be notified about 50 | * incoming and outgoing messages or {@code null} if no traffic 51 | * logger should be attached to the {@link IRCConnection}. 52 | */ 53 | IRCTrafficLogger getTrafficLogger(); 54 | 55 | /** 56 | * @return {@code true} if automatic PING? PONG! is enabled or {@code false} 57 | * otherwise. 58 | */ 59 | boolean isAutoPong(); 60 | 61 | /** 62 | * @return {@code true} if mIRC colorcodes should be removed from incoming 63 | * IRC messages 64 | */ 65 | boolean isStripColorsEnabled(); 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/util/IRCConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib.util; 15 | 16 | import org.schwering.irc.lib.IRCEventListener; 17 | 18 | /** 19 | * Contains constants: reply codes, error codes and mIRC color codes. 20 | * @author Christoph Schwering <schwering@gmail.com> 21 | * @since 1.10 22 | * @see IRCEventListener#onError(int, String) 23 | * @see IRCEventListener#onReply(int, String, String) 24 | */ 25 | public interface IRCConstants { 26 | 27 | /** 28 | * This is part of the mIRC code and shows that a color-code starts / ends. 29 | * Here it is as the ASCII decimal int 3. 30 | */ 31 | char COLOR_INDICATOR = 3; // ASCII code 32 | 33 | /** 34 | * This is part of the mIRC code and shows that bold starts / ends. 35 | * Here it is as the ASCII decimal int 31. 36 | */ 37 | char BOLD_INDICATOR = 31; // ASCII code 38 | 39 | /** 40 | * This is part of the mIRC code and shows that bold starts / ends. 41 | * Here it is as the ASCII decimal int 2. 42 | */ 43 | char UNDERLINE_INDICATOR = 2; // ASCII code 44 | 45 | /** 46 | * This is part of the mIRC code and shows that bold, underline and colors 47 | * end. 48 | * Here it is as the ASCII decimal int 15. 49 | */ 50 | char COLOR_END_INDICATOR = 15; // ASCII code 51 | 52 | /** 53 | * This is part of the mIRC code and indicates that the client's colors are 54 | * reversed (background -> foreground and foreground -> background). 55 | * Here it is as the ASCII decimal int 22. 56 | */ 57 | char COLOR_REVERSE_INDICATOR = 22; // ASCII code 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/impl/DefaultIRCUser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib.impl; 15 | 16 | import org.schwering.irc.lib.IRCEventListener; 17 | import org.schwering.irc.lib.IRCUser; 18 | import org.schwering.irc.lib.util.IRCParser; 19 | 20 | /** 21 | * An immutable {@link IRCUser}. 22 | * 23 | * @author Christoph Schwering <schwering@gmail.com> 24 | * @see IRCEventListener 25 | * @see IRCParser 26 | */ 27 | public class DefaultIRCUser implements IRCUser { 28 | 29 | /** 30 | * The user's nickname. 31 | */ 32 | private final String nick; 33 | 34 | /** 35 | * The user's username. 36 | */ 37 | private final String username; 38 | 39 | /** 40 | * The user's host. 41 | */ 42 | private final String host; 43 | 44 | 45 | /** 46 | * Creates a new {@link IRCUser}. 47 | * 48 | * @param nick The user's nickname. 49 | * @param username The user's username. 50 | * @param host The user's host. 51 | */ 52 | public DefaultIRCUser(String nick, String username, String host) { 53 | this.nick = nick; 54 | this.username = username; 55 | this.host = host; 56 | } 57 | 58 | 59 | /** 60 | * @see org.schwering.irc.lib.IRCUser#getNick() 61 | */ 62 | @Override 63 | public String getNick() { 64 | return nick; 65 | } 66 | 67 | /** 68 | * @see org.schwering.irc.lib.IRCUser#getUsername() 69 | */ 70 | @Override 71 | public String getUsername() { 72 | return username; 73 | } 74 | 75 | 76 | /** 77 | * @see org.schwering.irc.lib.IRCUser#getHost() 78 | */ 79 | @Override 80 | public String getHost() { 81 | return host; 82 | } 83 | 84 | 85 | /** 86 | * @return The nickname. 87 | */ 88 | public String toString() { 89 | return getNick(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/util/CTCPCommand.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib.util; 15 | 16 | import java.util.Collections; 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | /** 21 | * An enum of Client-to-client protocol (CTCP) commands. 22 | * See http://www.irchelp.org/irchelp/rfc/ctcpspec.html 23 | * 24 | * @author Peter Palaga 25 | */ 26 | public enum CTCPCommand { 27 | ACTION, 28 | DCC, 29 | SED, 30 | FINGER, 31 | VERSION, 32 | SOURCE, 33 | USERINFO, 34 | CLIENTINFO, 35 | ERRMSG, 36 | PING, 37 | TIME; 38 | 39 | private static final Map FAST_LOOKUP; 40 | public static final int SHORTEST_COMMAND_LENGTH; 41 | public static final char QUOTE_CHAR = '\u0001'; 42 | static { 43 | int shortestLength = Integer.MAX_VALUE; 44 | Map fastLookUp = new HashMap(64); 45 | CTCPCommand[] values = values(); 46 | for (CTCPCommand value : values) { 47 | String name = value.name(); 48 | int len = name.length(); 49 | if (shortestLength > len) { 50 | shortestLength = len; 51 | } 52 | fastLookUp.put(name, value); 53 | } 54 | FAST_LOOKUP = Collections.unmodifiableMap(fastLookUp); 55 | SHORTEST_COMMAND_LENGTH = shortestLength; 56 | } 57 | 58 | /** 59 | * A {@link HashMap}-backed and {@code null}-tolerant alternative to 60 | * {@link #valueOf(String)}. The lookup is case-sensitive. 61 | * 62 | * @param command 63 | * the command as a {@link String} 64 | * @return the {@link CTCPCommand} that corresponds to the given string 65 | * {@code command} or {@code null} if no such command exists 66 | */ 67 | public static CTCPCommand fastValueOf(String command) { 68 | return FAST_LOOKUP.get(command); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 68 | 69 | 70 | 71 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/impl/SocketFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib.impl; 15 | 16 | import java.io.IOException; 17 | import java.net.InetSocketAddress; 18 | import java.net.Proxy; 19 | import java.net.Socket; 20 | import java.security.KeyManagementException; 21 | import java.security.NoSuchAlgorithmException; 22 | 23 | import javax.net.ssl.SSLContext; 24 | import javax.net.ssl.SSLSocket; 25 | import javax.net.ssl.SSLSocketFactory; 26 | 27 | import org.schwering.irc.lib.IRCSSLSupport; 28 | 29 | /** 30 | * A factory to create sockets that takes into account things such as 31 | * {@link #timeout}, {@link #proxy} and SSL support. 32 | * 33 | * @author Peter Palaga 34 | */ 35 | public class SocketFactory { 36 | 37 | /** 38 | * The {@link Proxy} to use when creating the socket. Use 39 | * {@link Proxy#NO_PROXY} reather than {@code null}. 40 | */ 41 | private final Proxy proxy; 42 | /** The {@link SSLSocketFactory} to use when creating the socket. */ 43 | private SSLSocketFactory sslSocketFactory; 44 | /** Socket timeout in milliseconds. */ 45 | private final int timeout; 46 | 47 | /** 48 | * @param timeout 49 | * im milliseconds 50 | * @param proxy 51 | * the proxy or {@code null} if no proxy is to be used 52 | * @param sslSupport 53 | * the SSL support or {@code null} if SSL should not be used 54 | * @throws KeyManagementException 55 | * rethrown from 56 | * {@link SSLContext#init(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[], 57 | * java.security.SecureRandom)} 58 | * @throws NoSuchAlgorithmException rethrown from {@link SSLContext#getInstance(String)} 59 | */ 60 | public SocketFactory(int timeout, Proxy proxy, IRCSSLSupport sslSupport) throws KeyManagementException, 61 | NoSuchAlgorithmException { 62 | super(); 63 | this.timeout = timeout; 64 | this.proxy = proxy == null ? Proxy.NO_PROXY : proxy; 65 | if (sslSupport != null) { 66 | SSLContext sslContext = SSLContext.getInstance("SSL"); 67 | sslContext.init(sslSupport.getKeyManagers(), sslSupport.getTrustManagers(), sslSupport.getSecureRandom()); 68 | this.sslSocketFactory = sslContext.getSocketFactory(); 69 | } else { 70 | this.sslSocketFactory = null; 71 | } 72 | } 73 | 74 | /** 75 | * Creates a new {@link Socket} base on the the specification passed in 76 | * through the constructor. 77 | * 78 | * @param host 79 | * the hostname or IP address to connect to 80 | * @param port 81 | * the port number on the destination host 82 | * @return a new {@link Socket} 83 | * @throws IOException rethrown from several {@link Socket} methods 84 | */ 85 | @SuppressWarnings("resource") 86 | public Socket createSocket(String host, int port) throws IOException { 87 | final Socket result; 88 | if (sslSocketFactory == null) { 89 | /* plain, optionally with proxy */ 90 | result = new Socket(proxy); 91 | result.connect(new InetSocketAddress(host, port), timeout); 92 | } else if (proxy == Proxy.NO_PROXY) { 93 | /* SSL without proxy */ 94 | SSLSocket sslResult = (SSLSocket) sslSocketFactory.createSocket(host, port); 95 | sslResult.startHandshake(); 96 | result = sslResult; 97 | } else { 98 | /* SSL with proxy */ 99 | Socket proxySocket = new Socket(proxy); 100 | SSLSocket sslResult = (SSLSocket) sslSocketFactory.createSocket(proxySocket, host, port, true); 101 | sslResult.startHandshake(); 102 | result = sslResult; 103 | } 104 | result.setSoTimeout(timeout); 105 | return result; 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/impl/DefaultIRCSSLSupport.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib.impl; 15 | 16 | import java.security.NoSuchAlgorithmException; 17 | import java.security.SecureRandom; 18 | import java.security.cert.CertificateException; 19 | import java.security.cert.X509Certificate; 20 | import java.util.Arrays; 21 | 22 | import javax.net.ssl.KeyManager; 23 | import javax.net.ssl.TrustManager; 24 | import javax.net.ssl.X509TrustManager; 25 | 26 | import org.schwering.irc.lib.IRCSSLSupport; 27 | 28 | /** 29 | * An immutable {@link IRCSSLSupport} with {@link KeyManager}s, 30 | * {@link TrustManager}s and {@link SecureRandom} configurable at creation time. 31 | * 32 | * @author Peter Palaga 33 | */ 34 | public class DefaultIRCSSLSupport implements IRCSSLSupport { 35 | 36 | protected static final X509Certificate[] EMPTY_X509_CERTIFICATES = new X509Certificate[0]; 37 | 38 | /** An insecure {@link IRCSSLSupport} instance affirming all trust requests. */ 39 | public static IRCSSLSupport INSECURE; 40 | /** 41 | * An insecure {@link X509TrustManager} instance affirming all trust 42 | * requests. 43 | */ 44 | public static final X509TrustManager INSECURE_TRUST_MANAGER; 45 | 46 | static { 47 | INSECURE_TRUST_MANAGER = new X509TrustManager() { 48 | 49 | @Override 50 | public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { 51 | 52 | } 53 | 54 | @Override 55 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { 56 | } 57 | 58 | @Override 59 | public X509Certificate[] getAcceptedIssuers() { 60 | return EMPTY_X509_CERTIFICATES; 61 | } 62 | }; 63 | try { 64 | INSECURE = new DefaultIRCSSLSupport(new KeyManager[0], new TrustManager[] { INSECURE_TRUST_MANAGER }, 65 | SecureRandom.getInstanceStrong()); 66 | } catch (NoSuchAlgorithmException e) { 67 | throw new RuntimeException(e); 68 | } 69 | 70 | } 71 | 72 | /** 73 | * @see org.schwering.irc.lib.IRCSSLSupport#getKeyManagers() 74 | */ 75 | private final KeyManager[] keyManagers; 76 | 77 | /** 78 | * @see org.schwering.irc.lib.IRCSSLSupport#getSecureRandom() 79 | */ 80 | private final SecureRandom secureRandom; 81 | 82 | /** 83 | * @see org.schwering.irc.lib.IRCSSLSupport#getTrustManagers() 84 | */ 85 | private final TrustManager[] trustManagers; 86 | 87 | public DefaultIRCSSLSupport(IRCSSLSupport sslSupport) { 88 | this(sslSupport.getKeyManagers(), sslSupport.getTrustManagers(), sslSupport.getSecureRandom()); 89 | } 90 | 91 | /** 92 | * @param keyManagers the {@link KeyManager}s 93 | * @param trustManagers the {@link TrustManager}s 94 | * @param secureRandom the {@link SecureRandom} 95 | */ 96 | public DefaultIRCSSLSupport(KeyManager[] keyManagers, TrustManager[] trustManagers, SecureRandom secureRandom) { 97 | super(); 98 | this.keyManagers = Arrays.copyOf(keyManagers, keyManagers.length); 99 | this.trustManagers = Arrays.copyOf(trustManagers, trustManagers.length); 100 | this.secureRandom = secureRandom; 101 | } 102 | 103 | /** 104 | * @see org.schwering.irc.lib.IRCSSLSupport#getKeyManagers() 105 | */ 106 | @Override 107 | public KeyManager[] getKeyManagers() { 108 | return Arrays.copyOf(this.keyManagers, this.keyManagers.length); 109 | } 110 | 111 | /** 112 | * @see org.schwering.irc.lib.IRCSSLSupport#getSecureRandom() 113 | */ 114 | @Override 115 | public SecureRandom getSecureRandom() { 116 | return this.secureRandom; 117 | } 118 | 119 | /** 120 | * @see org.schwering.irc.lib.IRCSSLSupport#getTrustManagers() 121 | */ 122 | @Override 123 | public TrustManager[] getTrustManagers() { 124 | return Arrays.copyOf(this.trustManagers, this.trustManagers.length); 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/impl/DefaultIRCRuntimeConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib.impl; 15 | 16 | import java.net.Proxy; 17 | 18 | import org.schwering.irc.lib.IRCConfigBuilder; 19 | import org.schwering.irc.lib.IRCExceptionHandler; 20 | import org.schwering.irc.lib.IRCRuntimeConfig; 21 | import org.schwering.irc.lib.IRCSSLSupport; 22 | import org.schwering.irc.lib.IRCTrafficLogger; 23 | 24 | /** 25 | * An immutable {@link IRCRuntimeConfig}. Typically created via 26 | * {@link IRCConfigBuilder}. 27 | * 28 | * @author Peter Palaga 29 | */ 30 | public class DefaultIRCRuntimeConfig implements IRCRuntimeConfig { 31 | /** 32 | * @see org.schwering.irc.lib.IRCConfig#isAutoPong() 33 | */ 34 | private final boolean autoPong; 35 | /** 36 | * @see org.schwering.irc.lib.IRCRuntimeConfig#getExceptionHandler() 37 | */ 38 | private final IRCExceptionHandler exceptionHandler; 39 | /** 40 | * @see org.schwering.irc.lib.IRCConfig#getProxy() 41 | */ 42 | private final Proxy proxy; 43 | /** 44 | * @see org.schwering.irc.lib.IRCConfig#getSSLSupport() 45 | */ 46 | private final IRCSSLSupport sslSupport; 47 | /** 48 | * @see org.schwering.irc.lib.IRCConfig#isStripColorsEnabled() 49 | */ 50 | private final boolean stripColorsEnabled; 51 | /** 52 | * @see org.schwering.irc.lib.IRCConfig#getTimeout() 53 | */ 54 | private final int timeout; 55 | /** 56 | * @see org.schwering.irc.lib.IRCConfig#getTrafficLogger() 57 | */ 58 | private final IRCTrafficLogger trafficLogger; 59 | 60 | /** 61 | * Creates a new {@link DefaultIRCRuntimeConfig} out of the individual field 62 | * values. For meanings of the parameters, see the the respective getter 63 | * methods in {@link IRCRuntimeConfig}. 64 | * 65 | * @param timeout the timeout 66 | * @param autoPong {@code PONG} will be sent authomatically if {@code true} 67 | * @param stripColorsEnabled if {@code true} color codes will be stripped 68 | * @param sslSupport the {@link IRCSSLSupport} 69 | * @param proxy the {@link Proxy} 70 | * @param trafficLogger the {@code IRCTrafficLogger} 71 | * @param exceptionHandler the {@link IRCExceptionHandler} 72 | */ 73 | public DefaultIRCRuntimeConfig(int timeout, boolean autoPong, boolean stripColorsEnabled, IRCSSLSupport sslSupport, 74 | Proxy proxy, IRCTrafficLogger trafficLogger, IRCExceptionHandler exceptionHandler) { 75 | this.timeout = timeout; 76 | this.autoPong = autoPong; 77 | this.stripColorsEnabled = stripColorsEnabled; 78 | this.sslSupport = sslSupport; 79 | this.proxy = proxy; 80 | this.trafficLogger = trafficLogger; 81 | this.exceptionHandler = exceptionHandler; 82 | } 83 | 84 | /** 85 | * Creates a new {@link DefaultIRCRuntimeConfig} using data from the given 86 | * {@link IRCRuntimeConfig}. 87 | * 88 | * @param runtimeConfig 89 | * the {@link IRCRuntimeConfig} to read field values from 90 | */ 91 | public DefaultIRCRuntimeConfig(IRCRuntimeConfig runtimeConfig) { 92 | this(runtimeConfig.getTimeout(), runtimeConfig.isAutoPong(), runtimeConfig.isStripColorsEnabled(), 93 | runtimeConfig.getSSLSupport(), runtimeConfig.getProxy(), runtimeConfig.getTrafficLogger(), 94 | runtimeConfig.getExceptionHandler()); 95 | } 96 | 97 | /** 98 | * @see org.schwering.irc.lib.IRCRuntimeConfig#getExceptionHandler() 99 | */ 100 | public IRCExceptionHandler getExceptionHandler() { 101 | return exceptionHandler; 102 | } 103 | 104 | /** 105 | * @see org.schwering.irc.lib.IRCConfig#getProxy() 106 | */ 107 | @Override 108 | public Proxy getProxy() { 109 | return proxy; 110 | } 111 | 112 | /** 113 | * @see org.schwering.irc.lib.IRCConfig#getSSLSupport() 114 | */ 115 | @Override 116 | public IRCSSLSupport getSSLSupport() { 117 | return sslSupport; 118 | } 119 | 120 | /** 121 | * @see org.schwering.irc.lib.IRCConfig#getTimeout() 122 | */ 123 | @Override 124 | public int getTimeout() { 125 | return timeout; 126 | } 127 | 128 | /** 129 | * @see org.schwering.irc.lib.IRCConfig#getTrafficLogger() 130 | */ 131 | @Override 132 | public IRCTrafficLogger getTrafficLogger() { 133 | return trafficLogger; 134 | } 135 | 136 | /** 137 | * @see org.schwering.irc.lib.IRCConfig#isAutoPong() 138 | */ 139 | @Override 140 | public boolean isAutoPong() { 141 | return autoPong; 142 | } 143 | 144 | /** 145 | * @see org.schwering.irc.lib.IRCConfig#isStripColorsEnabled() 146 | */ 147 | @Override 148 | public boolean isStripColorsEnabled() { 149 | return stripColorsEnabled; 150 | } 151 | 152 | } 153 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/impl/DefaultIRCServerConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib.impl; 15 | 16 | import java.util.Arrays; 17 | 18 | import org.schwering.irc.lib.IRCConfigBuilder; 19 | import org.schwering.irc.lib.IRCServerConfig; 20 | 21 | /** 22 | * An immutable {@link IRCServerConfig}. Typically created via 23 | * {@link IRCConfigBuilder}. 24 | * 25 | * @author Peter Palaga 26 | */ 27 | public class DefaultIRCServerConfig implements IRCServerConfig { 28 | 29 | /** 30 | * The character encoding used to both decode the incomming stream from the 31 | * IRC server and encode the outgoing stream to IRC server. The default is 32 | * UTF-8. 33 | */ 34 | private final String encoding; 35 | 36 | /** 37 | * The host of the IRC server. 38 | */ 39 | private final String host; 40 | 41 | /** 42 | * The user's nickname, which is indispensably to connect. 43 | */ 44 | private final String nick; 45 | /** 46 | * The password, which is needed to get access to the IRC server. 47 | */ 48 | private final String pass; 49 | /** 50 | * The int[] contains all ports to which we are going to try to 51 | * connect. This can be a portrange from port 6667 to 6669, for example. 52 | */ 53 | private final int[] ports; 54 | /** 55 | * The user's realname, which is indispensably to connect. 56 | */ 57 | private final String realname; 58 | /** 59 | * The user's username, which is indispensable to connect. 60 | */ 61 | private final String username; 62 | 63 | /** 64 | * Creates a new {@link DefaultIRCServerConfig} using data from the given 65 | * {@link IRCServerConfig}. 66 | * 67 | * @param serverConfig 68 | * the {@link IRCServerConfig} to read field values from 69 | */ 70 | public DefaultIRCServerConfig(IRCServerConfig serverConfig) { 71 | this(serverConfig.getHost(), serverConfig.getPorts(), serverConfig.getPassword(), serverConfig.getNick(), 72 | serverConfig.getUsername(), serverConfig.getRealname(), serverConfig.getEncoding()); 73 | } 74 | 75 | /** 76 | * Creates a new {@link DefaultIRCServerConfig} out of the individual field 77 | * values. For meanings of the parameters, see the the respective getter 78 | * methods in {@link IRCServerConfig}. 79 | * 80 | * @param host the host name or IP address 81 | * @param ports the ports to try on {@code host} 82 | * @param pass the password 83 | * @param nick the preferred nick name 84 | * @param username the username 85 | * @param realname the real name 86 | * @param encoding the encoding 87 | */ 88 | public DefaultIRCServerConfig(String host, int[] ports, String pass, String nick, String username, String realname, 89 | String encoding) { 90 | super(); 91 | if (host == null || ports == null || ports.length == 0) { 92 | throw new IllegalArgumentException("Host and ports may not be null."); 93 | } 94 | this.host = host; 95 | this.ports = ports; 96 | this.pass = (pass != null && pass.length() == 0) ? null : pass; 97 | this.nick = nick; 98 | this.username = username; 99 | this.realname = realname; 100 | this.encoding = encoding; 101 | } 102 | 103 | /** 104 | * @see org.schwering.irc.lib.IRCConfig#getEncoding() 105 | */ 106 | @Override 107 | public String getEncoding() { 108 | return encoding; 109 | } 110 | 111 | /** 112 | * @see org.schwering.irc.lib.IRCConfig#getHost() 113 | */ 114 | @Override 115 | public String getHost() { 116 | return host; 117 | } 118 | 119 | /** 120 | * @see org.schwering.irc.lib.IRCConfig#getNick() 121 | */ 122 | @Override 123 | public String getNick() { 124 | return nick; 125 | } 126 | 127 | /** 128 | * @see org.schwering.irc.lib.IRCConfig#getPassword() 129 | */ 130 | @Override 131 | public String getPassword() { 132 | return pass; 133 | } 134 | 135 | /** 136 | * @see org.schwering.irc.lib.IRCConfig#getPortAt(int) 137 | */ 138 | @Override 139 | public int getPortAt(int index) { 140 | return ports[index]; 141 | } 142 | 143 | /** 144 | * @see org.schwering.irc.lib.IRCConfig#getPorts() 145 | */ 146 | @Override 147 | public int[] getPorts() { 148 | return ports == null ? new int[0] : Arrays.copyOf(ports, ports.length); 149 | } 150 | 151 | /** 152 | * @see org.schwering.irc.lib.IRCConfig#getPortsCount() 153 | */ 154 | @Override 155 | public int getPortsCount() { 156 | return ports != null ? ports.length : 0; 157 | } 158 | 159 | /** 160 | * @see org.schwering.irc.lib.IRCConfig#getRealname() 161 | */ 162 | @Override 163 | public String getRealname() { 164 | return realname; 165 | } 166 | 167 | /** 168 | * @see org.schwering.irc.lib.IRCConfig#getUsername() 169 | */ 170 | @Override 171 | public String getUsername() { 172 | return username; 173 | } 174 | 175 | } 176 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/IRCEventAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib; 15 | 16 | import org.schwering.irc.lib.util.IRCModeParser; 17 | 18 | /** 19 | * A empty implementation if {@link IRCEventListener}. 20 | * 21 | * @author Christoph Schwering <schwering@gmail.com> 22 | * @see IRCEventListener 23 | */ 24 | public class IRCEventAdapter implements IRCEventListener { 25 | 26 | /** 27 | * The default and only constructor does nothing. 28 | */ 29 | public IRCEventAdapter() { 30 | // nothing 31 | } 32 | 33 | 34 | /** 35 | * Does nothing in this implementation. 36 | * 37 | * @see IRCEventListener#onRegistered() 38 | */ 39 | public void onRegistered() { 40 | // nothing 41 | } 42 | 43 | 44 | /** 45 | * Does nothing in this implementation. 46 | * 47 | * @see IRCEventListener#onDisconnected() 48 | */ 49 | public void onDisconnected() { 50 | // nothing 51 | } 52 | 53 | 54 | /** 55 | * Does nothing in this implementation. 56 | * 57 | * @see IRCEventListener#onError(String) 58 | */ 59 | public void onError(String msg) { 60 | // nothing 61 | } 62 | 63 | 64 | /** 65 | * Does nothing in this implementation. 66 | * 67 | * @see IRCEventListener#onError(int, String) 68 | */ 69 | public void onError(int num, String msg) { 70 | // nothing 71 | } 72 | 73 | 74 | /** 75 | * Does nothing in this implementation. 76 | * 77 | * @see IRCEventListener#onInvite(String, IRCUser, String) 78 | */ 79 | public void onInvite(String chan, IRCUser user, String passiveNick) { 80 | // nothing 81 | } 82 | 83 | 84 | /** 85 | * Does nothing in this implementation. 86 | * 87 | * @see IRCEventListener#onJoin(String, IRCUser) 88 | */ 89 | public void onJoin(String chan, IRCUser user) { 90 | // nothing 91 | } 92 | 93 | 94 | /** 95 | * Does nothing in this implementation. 96 | * 97 | * @see IRCEventListener#onKick(String, IRCUser, String, String) 98 | */ 99 | public void onKick(String chan, IRCUser user, String passiveNick, 100 | String msg) { 101 | // nothing 102 | } 103 | 104 | 105 | /** 106 | * Does nothing in this implementation. 107 | * 108 | * @see IRCEventListener#onMode(String, IRCUser, IRCModeParser) 109 | */ 110 | public void onMode(String chan, IRCUser user, IRCModeParser modeParser) { 111 | // nothing 112 | } 113 | 114 | 115 | /** 116 | * Does nothing in this implementation. 117 | * 118 | * @see IRCEventListener#onMode(IRCUser, String, String) 119 | */ 120 | public void onMode(IRCUser user, String passiveNick, String mode) { 121 | // nothing 122 | } 123 | 124 | 125 | /** 126 | * Does nothing in this implementation. 127 | * 128 | * @see IRCEventListener#onNick(IRCUser, String) 129 | */ 130 | public void onNick(IRCUser user, String newNick) { 131 | // nothing 132 | } 133 | 134 | 135 | /** 136 | * Does nothing in this implementation. 137 | * 138 | * @see IRCEventListener#onNotice(String, IRCUser, String) 139 | */ 140 | public void onNotice(String target, IRCUser user, String msg) { 141 | // nothing 142 | } 143 | 144 | 145 | /** 146 | * Does nothing in this implementation. 147 | * 148 | * @see IRCEventListener#onPart(String, IRCUser, String) 149 | */ 150 | public void onPart(String chan, IRCUser user, String msg) { 151 | // nothing 152 | } 153 | 154 | 155 | /** 156 | * Does nothing in this implementation. 157 | * 158 | * @see IRCEventListener#onPing(String) 159 | */ 160 | public void onPing(String ping) { 161 | // nothing 162 | } 163 | 164 | 165 | /** 166 | * Does nothing in this implementation. 167 | * 168 | * @see IRCEventListener#onPrivmsg(String, IRCUser, String) 169 | */ 170 | public void onPrivmsg(String target, IRCUser user, String msg) { 171 | // nothing 172 | } 173 | 174 | 175 | /** 176 | * Does nothing in this implementation. 177 | * 178 | * @see IRCEventListener#onQuit(IRCUser, String) 179 | */ 180 | public void onQuit(IRCUser user, String msg) { 181 | // nothing 182 | } 183 | 184 | 185 | /** 186 | * Does nothing in this implementation. 187 | * 188 | * @see IRCEventListener#onReply(int, String, String) 189 | */ 190 | public void onReply(int num, String value, String msg) { 191 | // nothing 192 | } 193 | 194 | 195 | /** 196 | * Does nothing in this implementation. 197 | * 198 | * @see IRCEventListener#onTopic(String, IRCUser, String) 199 | */ 200 | public void onTopic(String chan, IRCUser user, String topic) { 201 | // nothing 202 | } 203 | 204 | 205 | /** 206 | * Does nothing in this implementation. 207 | * 208 | * @see IRCEventListener#unknown(String, String, String, String) 209 | */ 210 | public void unknown(String prefix, String command, String middle, 211 | String trailing) { 212 | // nothing 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/impl/DefaultIRCConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib.impl; 15 | 16 | import java.net.Proxy; 17 | 18 | import org.schwering.irc.lib.IRCConfig; 19 | import org.schwering.irc.lib.IRCConfigBuilder; 20 | import org.schwering.irc.lib.IRCExceptionHandler; 21 | import org.schwering.irc.lib.IRCRuntimeConfig; 22 | import org.schwering.irc.lib.IRCSSLSupport; 23 | import org.schwering.irc.lib.IRCServerConfig; 24 | import org.schwering.irc.lib.IRCTrafficLogger; 25 | 26 | /** 27 | * An immutable {@link IRCConfig}. Typically created via 28 | * {@link IRCConfigBuilder}. 29 | * 30 | * @author Peter Palaga 31 | */ 32 | public class DefaultIRCConfig extends DefaultIRCServerConfig implements IRCConfig { 33 | 34 | /** 35 | * @see org.schwering.irc.lib.IRCConfig#isAutoPong() 36 | */ 37 | private final boolean autoPong; 38 | /** 39 | * @see org.schwering.irc.lib.IRCConfig#getProxy() 40 | */ 41 | private final Proxy proxy; 42 | /** 43 | * @see org.schwering.irc.lib.IRCConfig#getSSLSupport() 44 | */ 45 | private final IRCSSLSupport sslSupport; 46 | /** 47 | * @see org.schwering.irc.lib.IRCConfig#isStripColorsEnabled() 48 | */ 49 | private final boolean stripColorsEnabled; 50 | /** 51 | * @see org.schwering.irc.lib.IRCConfig#getTimeout() 52 | */ 53 | private final int timeout; 54 | /** 55 | * @see org.schwering.irc.lib.IRCConfig#getTrafficLogger() 56 | */ 57 | private final IRCTrafficLogger trafficLogger; 58 | /** 59 | * @see org.schwering.irc.lib.IRCRuntimeConfig#getExceptionHandler() 60 | */ 61 | private final IRCExceptionHandler exceptionHandler; 62 | 63 | /** 64 | * Creates a new {@link DefaultIRCConfig} using data from the given 65 | * {@link IRCConfig}. 66 | * 67 | * @param config 68 | * the {@link IRCConfig} to read field values from 69 | */ 70 | public DefaultIRCConfig(IRCConfig config) { 71 | this(config.getHost(), config.getPorts(), config.getPassword(), config.getNick(), config.getUsername(), config 72 | .getRealname(), config.getEncoding(), config.getTimeout(), config.isAutoPong(), config 73 | .isStripColorsEnabled(), new DefaultIRCSSLSupport(config.getSSLSupport()), config.getProxy(), config 74 | .getTrafficLogger(), config.getExceptionHandler()); 75 | } 76 | 77 | /** 78 | * Creates a new {@link DefaultIRCConfig} using data from the given 79 | * {@link IRCConfig}. 80 | * 81 | * @param serverConfig 82 | * the {@link IRCServerConfig} to read field values from 83 | * @param runtimeConfig 84 | * the {@link IRCRuntimeConfig} to read field values from 85 | */ 86 | public DefaultIRCConfig(IRCServerConfig serverConfig, IRCRuntimeConfig runtimeConfig) { 87 | this(serverConfig.getHost(), serverConfig.getPorts(), serverConfig.getPassword(), serverConfig.getNick(), 88 | serverConfig.getUsername(), serverConfig.getRealname(), serverConfig.getEncoding(), runtimeConfig 89 | .getTimeout(), runtimeConfig.isAutoPong(), runtimeConfig.isStripColorsEnabled(), 90 | new DefaultIRCSSLSupport(runtimeConfig.getSSLSupport()), runtimeConfig.getProxy(), runtimeConfig 91 | .getTrafficLogger(), runtimeConfig.getExceptionHandler()); 92 | } 93 | 94 | /** 95 | * Creates a new {@link DefaultIRCConfig} out of the individual field 96 | * values. For meanings of the parameters, see the the respective getter 97 | * methods in {@link IRCConfig}. 98 | * 99 | * @param host the host name or IP address 100 | * @param ports the ports to try on {@code host} 101 | * @param pass the password 102 | * @param nick the preferred nick name 103 | * @param username the username 104 | * @param realname the real name 105 | * @param encoding the encoding 106 | * @param timeout the timeout 107 | * @param autoPong {@code PONG} will be sent authomatically if {@code true} 108 | * @param stripColorsEnabled if {@code true} color codes will be stripped 109 | * @param sslSupport the {@link IRCSSLSupport} 110 | * @param proxy the {@link Proxy} 111 | * @param trafficLogger the {@code IRCTrafficLogger} 112 | * @param exceptionHandler the {@link IRCExceptionHandler} 113 | */ 114 | public DefaultIRCConfig(String host, int[] ports, String pass, String nick, String username, String realname, 115 | String encoding, int timeout, boolean autoPong, boolean stripColorsEnabled, IRCSSLSupport sslSupport, 116 | Proxy proxy, IRCTrafficLogger trafficLogger, IRCExceptionHandler exceptionHandler) { 117 | super(host, ports, pass, nick, username, realname, encoding); 118 | this.timeout = timeout; 119 | this.autoPong = autoPong; 120 | this.stripColorsEnabled = stripColorsEnabled; 121 | this.sslSupport = sslSupport; 122 | this.proxy = proxy; 123 | this.trafficLogger = trafficLogger; 124 | this.exceptionHandler = exceptionHandler; 125 | } 126 | 127 | /** 128 | * @see org.schwering.irc.lib.IRCConfig#getProxy() 129 | */ 130 | @Override 131 | public Proxy getProxy() { 132 | return proxy; 133 | } 134 | 135 | /** 136 | * @see org.schwering.irc.lib.IRCConfig#getSSLSupport() 137 | */ 138 | @Override 139 | public IRCSSLSupport getSSLSupport() { 140 | return sslSupport; 141 | } 142 | 143 | /** 144 | * @see org.schwering.irc.lib.IRCConfig#getTimeout() 145 | */ 146 | @Override 147 | public int getTimeout() { 148 | return timeout; 149 | } 150 | 151 | /** 152 | * @see org.schwering.irc.lib.IRCConfig#getTrafficLogger() 153 | */ 154 | @Override 155 | public IRCTrafficLogger getTrafficLogger() { 156 | return trafficLogger; 157 | } 158 | 159 | /** 160 | * @see org.schwering.irc.lib.IRCConfig#isAutoPong() 161 | */ 162 | @Override 163 | public boolean isAutoPong() { 164 | return autoPong; 165 | } 166 | 167 | /** 168 | * @see org.schwering.irc.lib.IRCConfig#isStripColorsEnabled() 169 | */ 170 | @Override 171 | public boolean isStripColorsEnabled() { 172 | return stripColorsEnabled; 173 | } 174 | 175 | /** 176 | * @see org.schwering.irc.lib.IRCRuntimeConfig#getExceptionHandler() 177 | */ 178 | public IRCExceptionHandler getExceptionHandler() { 179 | return exceptionHandler; 180 | } 181 | 182 | } 183 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/util/IRCModeParser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib.util; 15 | 16 | import org.schwering.irc.lib.IRCEventListener; 17 | import org.schwering.irc.lib.IRCUser; 18 | 19 | /** 20 | * Parses channel-modes. 21 | *

22 | * An instance of this class is an argument of the {@link 23 | * org.schwering.irc.lib.IRCEventListener#onMode(String chan, IRCUser user, 24 | * IRCModeParser modeParser)}. 25 | * It's intended to help the programmer to work with the modes. 26 | *

27 | * Channelmodes are: 28 | *

    29 | *
  • +/- o nick
  • 30 | *
  • +/- v nick
  • 31 | *
  • +/- b banmask
  • 32 | *
  • +/- l limit
  • 33 | *
  • +/- k key
  • 34 | *
  • +/- p
  • 35 | *
  • +/- s
  • 36 | *
  • +/- i
  • 37 | *
  • +/- t
  • 38 | *
  • +/- n
  • 39 | *
  • +/- m
  • 40 | *
41 | *

42 | * These are all channel-modes defined in RFC1459. Nevertheless, most 43 | * networks provide more channel-modes. This class can handle all modes; it's 44 | * not restricted to the rights defined in RFC1459. 45 | * @author Christoph Schwering <schwering@gmail.com> 46 | * @see IRCEventListener#onMode(String, IRCUser, IRCModeParser) 47 | * @see IRCUser 48 | */ 49 | public class IRCModeParser { 50 | 51 | /** 52 | * Represents the operators, modes and nicks as they were sent from the IRC 53 | * server. 54 | */ 55 | private String line; 56 | 57 | /** 58 | * Contains pluses (+) and minuses (-) which show 59 | * if the mode is taken or given. 60 | */ 61 | private char[] operatorsArr; 62 | 63 | /** 64 | * This array contains the modes that are set with the operator of the 65 | * operatorsArr-array. * 66 | */ 67 | private char[] modesArr; 68 | 69 | /** 70 | * Represents the parsed nicks, hostnames, limits or keys in an array of 71 | * Strings. 72 | */ 73 | private String[] argsArr; 74 | 75 | 76 | /** 77 | * Analyzes the modes and parses them into the parts operators (+ 78 | * or -), modes (one character) and optional arguments (one 79 | * word or number). 80 | * @param line The modes and the arguments; nothing more. 81 | */ 82 | public IRCModeParser(String line) { 83 | line = line.trim(); 84 | this.line = line; 85 | int index = line.indexOf(' '); 86 | if (index >= 2) { // with arguments 87 | String modes = line.substring(0, index); 88 | String args = line.substring(index + 1); 89 | parse(modes, args); // call real constructor. 90 | } else if (line.length() >= 2) { // no arguments 91 | String modes = line; 92 | String args = ""; 93 | parse(modes, args); 94 | } else { // nothing 95 | argsArr = new String[0]; 96 | operatorsArr = new char[0]; 97 | modesArr = new char[0]; 98 | } 99 | } 100 | 101 | 102 | /** 103 | * Analyzes the modes and parses them into the parts operators (+ 104 | * or -), modes (one character) and optional arguments (one 105 | * word or number). 106 | * @param modes The modes (for example +oo+m-v). 107 | * @param args The modes' arguments (for example Heinz Hans 108 | * Thomas). 109 | */ 110 | public IRCModeParser(String modes, String args) { 111 | line = modes +" "+ args; 112 | parse(modes, args); 113 | } 114 | 115 | 116 | /** 117 | * Parses the modes into two char-arrays and one 118 | * String-array. 119 | * The first one contains the operator of the mode (+ or 120 | * -) and the second one the mode (w, 121 | * i, s, o or any other mode). 122 | * The String[] contains the nicknames. 123 | * @param modes The modes (for example +oo+m-v). 124 | * @param args The modes' arguments (for example Heinz Hans 125 | * Thomas). 126 | */ 127 | private void parse(String modes, String args) { 128 | String[] argsTmp = IRCUtil.split(args, ' '); 129 | int modesLen = modes.length(); 130 | int modesCount = getModesCount(modes); 131 | char c; 132 | char operator = '+'; // any value cause it must be initialized 133 | operatorsArr = new char[modesCount]; 134 | modesArr = new char[modesCount]; 135 | argsArr = new String[modesCount]; 136 | // parse and fill the arrays 137 | for (int i = 0, j = 0, n = 0; i < modesLen; i++) { 138 | c = modes.charAt(i); 139 | if (c == '+' || c == '-') { 140 | operator = c; 141 | } else { 142 | // add the operator (which was found earlier in the loop) 143 | operatorsArr[n] = operator; 144 | modesArr[n] = c; // add the mode 145 | if ((c == 'o' || c == 'v' || c == 'b' || c == 'k') // come with arg 146 | || (c == 'l' && operator == '+')) { // key comes with arg if '+' 147 | argsArr[n] = (j < argsTmp.length) ? argsTmp[j++] : ""; 148 | } else { 149 | argsArr[n] = ""; // null if mode has no argument (for example m, p, s) 150 | } 151 | n++; // increase n, not i. n is used to fill the arrays 152 | } 153 | } 154 | } 155 | 156 | 157 | /** 158 | * Returns the amount of modes in the string. This is done by counting all 159 | * chars which are not + or -. 160 | * @param modes The modes which are to analyze. 161 | * @return The count of modes without operators. 162 | */ 163 | private int getModesCount(String modes) { 164 | int count = 0; 165 | for (int i = 0, c, len = modes.length(); i < len; i++) 166 | if ((c = modes.charAt(i)) != '+' && c != '-') 167 | count++; 168 | return count; 169 | } 170 | 171 | 172 | /** 173 | * Returns count of modes. 174 | * @return The count of modes. 175 | * @see #getOperatorAt(int) 176 | * @see #getModeAt(int) 177 | * @see #getArgAt(int) 178 | */ 179 | public int getCount() { 180 | return operatorsArr.length; 181 | } 182 | 183 | 184 | /** 185 | * Returns the operator (+ or -) of a given index. 186 | * @param i The index of the operator you want to get. The index starts 187 | * with 1 and not with 0. 188 | * @return The operator at the given index (+ or -). 189 | * @see #getCount() 190 | * @see #getModeAt(int) 191 | * @see #getArgAt(int) 192 | */ 193 | public char getOperatorAt(int i) { 194 | return operatorsArr[i - 1]; 195 | } 196 | 197 | 198 | /** 199 | * Returns the mode (for example o, v, 200 | * m, i) of a given index. 201 | * @param i The index of the mode you want to get. The index starts with 202 | * 1 and not with 0. 203 | * @return The mode of the given index (for example o, 204 | * v, m, i) 205 | * @see #getCount() 206 | * @see #getOperatorAt(int) 207 | * @see #getArgAt(int) 208 | */ 209 | public char getModeAt(int i) { 210 | return modesArr[i - 1]; 211 | } 212 | 213 | 214 | /** 215 | * Returns the nick of a given index. 216 | * @param i The index of the argument you want to get. The index starts with 217 | * 1 and not with 0. 218 | * @return The argument you requested. It's "" if there's no 219 | * argument at this index (for example +m for moderated 220 | * has never an argument). 221 | * @see #getCount() 222 | * @see #getOperatorAt(int) 223 | * @see #getModeAt(int) 224 | */ 225 | public String getArgAt(int i) { 226 | return argsArr[i - 1]; 227 | } 228 | 229 | 230 | /** 231 | * Returns the line as it was sent from the IRC server. 232 | * The line contains the the operators, the modes and the nicknames, but not 233 | * the channel or the nickname who executed the MODE command! 234 | * @return The line which was set as argument when the parser was initialized. 235 | */ 236 | public String getLine() { 237 | return line; 238 | } 239 | 240 | 241 | /** 242 | * Generates a String with some information about the instance of 243 | * IRCModeParser. 244 | * Its format is: classname[line]. 245 | * @return A String with information about the instance. 246 | */ 247 | public String toString() { 248 | return getClass().getName() +"["+ getLine() +"]"; 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/IRCEventListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib; 15 | 16 | import java.util.EventListener; 17 | 18 | import org.schwering.irc.lib.util.IRCConstants; 19 | import org.schwering.irc.lib.util.IRCModeParser; 20 | 21 | /** 22 | * Used as listener for incoming events like messages. 23 | *

24 | * The IRCEventListener is used by the 25 | * IRCConnection.addEventListener(IRCEventListener) method to add 26 | * a listener which listens to the connection for incoming IRC events like 27 | * PRIVMSGs or numeric replies. 28 | *

29 | * Supported events: 30 | *

    31 | *
  • Connect
  • 32 | *
  • Disconnect
  • 33 | *
  • Error
  • 34 | *
  • Invite
  • 35 | *
  • Join
  • 36 | *
  • Kick
  • 37 | *
  • Private Message
  • 38 | *
  • Mode (Chan)
  • 39 | *
  • Mode (User)
  • 40 | *
  • Nick
  • 41 | *
  • Notice
  • 42 | *
  • Numeric Reply
  • 43 | *
  • Numeric Error
  • 44 | *
  • Part
  • 45 | *
  • Ping
  • 46 | *
  • Quit
  • 47 | *
  • Topic
  • 48 | *
49 | *

50 | * For other, unkown events there's the unknown-method. 51 | * 52 | * @author Christoph Schwering <schwering@gmail.com> 53 | * @see IRCEventAdapter 54 | * @see IRCConnection 55 | */ 56 | public interface IRCEventListener extends EventListener, IRCConstants { 57 | 58 | /** 59 | * Fired when the own connection is successfully established. 60 | * This is the case when the first PING? is received. 61 | * This happens between the connection is opened with a socket and the 62 | * connection is registered: The client sends his information to the server 63 | * (nickname, username). The server says hello to you by sending you 64 | * some NOTICEs. And if your nickname is invalid or in use or 65 | * anything else is wrong with your nickname, it asks you for a new one. 66 | */ 67 | void onRegistered(); 68 | 69 | 70 | /** 71 | * Fired when the own connection is broken. 72 | */ 73 | void onDisconnected(); 74 | 75 | 76 | /** 77 | * Fired when an ERROR command is received. 78 | * @param msg The message of the error. 79 | */ 80 | void onError(String msg); 81 | 82 | 83 | /** 84 | * Fired when a numeric error is received. 85 | * The server often sends numeric errors (wrong nickname etc.). 86 | * The msg's format is different for every reply. All replies' 87 | * formats are described in the {@link org.schwering.irc.lib.util.IRCUtil}. 88 | * @param num The identifier (usually a 3-digit number). 89 | * @param msg The message of the error. 90 | */ 91 | void onError(int num, String msg); 92 | 93 | 94 | /** 95 | * Fired when somebody is invited to a channel. 96 | * @param chan The channel the user is invited to. 97 | * @param user The user who invites another. Contains nick, username and host. 98 | * @param passiveNick The nickname of the user who is invited by another user 99 | * (passive). 100 | */ 101 | void onInvite(String chan, IRCUser user, String passiveNick); 102 | 103 | 104 | /** 105 | * Fired when somebody joins a channel. 106 | * @param chan The channel the person joins. 107 | * @param user The user who joins. Contains nick, username and host. 108 | */ 109 | void onJoin(String chan, IRCUser user); 110 | 111 | 112 | /** 113 | * Fired when somebody is kicked from a channel. 114 | * @param chan The channel somebody is kicked from. 115 | * @param user The user who kicks another user from a channel. 116 | * Contains nick, username and host. 117 | * @param passiveNick The nickname of the user who is kicked from a channel 118 | * (passive). 119 | * @param msg The message the active user has set. This is "" if 120 | * no message was set. 121 | */ 122 | void onKick(String chan, IRCUser user, String passiveNick, String msg); 123 | 124 | 125 | /** 126 | * Fired when an operator changes the modes of a channel. 127 | * For example, he can set somebody as an operator, too, or take him the 128 | * oper-status. 129 | * Also keys, moderated and other channelmodes are fired here. 130 | * @param chan The channel in which the modes are changed. 131 | * @param user The user who changes the modes. 132 | * Contains nick, username and host. 133 | * @param modeParser The IRCModeParser object which contains the 134 | * parsed information about the modes which are changed. 135 | */ 136 | void onMode(String chan, IRCUser user, IRCModeParser modeParser); 137 | 138 | 139 | /** 140 | * Fired when somebody changes somebody's usermodes. 141 | * Note that this event is not fired when a channel-mode is set, for example 142 | * when someone sets another user as operator or the mode moderated. 143 | * @param user The user who changes the modes of another user or himself. 144 | * Contains nick, username and host. 145 | * @param passiveNick The nickname of the person whose modes are changed by 146 | * another user or himself. 147 | * @param mode The changed modes which are set. 148 | */ 149 | void onMode(IRCUser user, String passiveNick, String mode); 150 | 151 | 152 | /** 153 | * Fired when somebody changes his nickname successfully. 154 | * @param user The user who changes his nickname. 155 | * Contains nick, username and host. 156 | * @param newNick The new nickname of the user who changes his nickname. 157 | */ 158 | void onNick(IRCUser user, String newNick); 159 | 160 | 161 | /** 162 | * Fired when somebody sends a NOTICE to a user or a group. 163 | * @param target The channel or nickname the user sent a NOTICE 164 | * to. 165 | * @param user The user who notices another person or a group. 166 | * Contains nick, username and host. 167 | * @param msg The message. 168 | */ 169 | void onNotice(String target, IRCUser user, String msg); 170 | 171 | 172 | /** 173 | * Fired when somebody parts from a channel. 174 | * @param chan The channel somebody parts from. 175 | * @param user The user who parts from a channel. 176 | * Contains nick, username and host. 177 | * @param msg The part-message which is optionally. 178 | * If it's empty, msg is "". 179 | */ 180 | void onPart(String chan, IRCUser user, String msg); 181 | 182 | 183 | /** 184 | * Fired when a PING comes in. 185 | * The IRC server tests in different periods if the client is still there by 186 | * sending PING <ping>. The client must response PONG <ping>. 187 | * @param ping The ping which is received from the server. 188 | */ 189 | void onPing(String ping); 190 | 191 | 192 | /** 193 | * Fired when a user sends a PRIVMSG to a user or to a 194 | * group. 195 | * @param target The channel or nickname the user sent a PRIVMSG 196 | * to. 197 | * @param user The user who sent the PRIVMSG. 198 | * Contains nick, username and host. 199 | * @param msg The message the user transmits. 200 | */ 201 | void onPrivmsg(String target, IRCUser user, String msg); 202 | 203 | 204 | /** 205 | * Fired when somebody quits from the network. 206 | * @param user The user who quits. Contains nick, username and host. 207 | * @param msg The optional message. "" if no message is set by 208 | * the user. 209 | */ 210 | void onQuit(IRCUser user, String msg); 211 | 212 | 213 | /** 214 | * Fired when a numeric reply is received. 215 | * For example, WHOIS queries are answered by the server with 216 | * numeric replies. 217 | * The msg's format is different for every reply. All replies' 218 | * formats are described in the {@link org.schwering.irc.lib.util.IRCUtil}. 219 | * The first word in the value is always your own nickname! 220 | * @param num The numeric reply. 221 | * @param value The first part of the message. 222 | * @param msg The main part of the message. 223 | */ 224 | void onReply(int num, String value, String msg); 225 | 226 | 227 | /** 228 | * Fired when the topic is changed by operators. 229 | * Note that the topic is given as a numeric reply fired in 230 | * onReply when you join a channel. 231 | * @param chan The channel where the topic is changed. 232 | * @param user The user who changes the topic. 233 | * Contains nick, username and host. 234 | * @param topic The new topic. 235 | */ 236 | void onTopic(String chan, IRCUser user, String topic); 237 | 238 | 239 | /** 240 | * This event is fired when the incoming line can not be identified as a known 241 | * event. 242 | * @param prefix The prefix of the incoming line. 243 | * @param command The command of the incoming line. 244 | * @param middle The part until the colon (:). 245 | * @param trailing The part behind the colon (:). 246 | */ 247 | void unknown(String prefix, String command, String middle, 248 | String trailing); 249 | 250 | } 251 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/util/IRCUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib.util; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Collection; 18 | import java.util.List; 19 | 20 | import org.schwering.irc.lib.IRCEventListener; 21 | import org.schwering.irc.lib.impl.DefaultIRCConnection; 22 | 23 | /** 24 | * Contains some utilities like numeric error and reply numbers. 25 | *

26 | * The most description of the numeric errors and numeric replies are copied 27 | * from RFC1459. 28 | * @author Christoph Schwering <schwering@gmail.com> 29 | * @author Normton <normton@latinmail.com> 30 | * @see DefaultIRCConnection 31 | * @see IRCEventListener#onError(int, String) 32 | * @see IRCEventListener#onReply(int, String, String) 33 | */ 34 | public class IRCUtil implements IRCConstants { 35 | 36 | 37 | /** 38 | * This is an empty constructor, it does nothing. Nobody may instantiate this 39 | * class. 40 | */ 41 | private IRCUtil() { 42 | // nothing 43 | } 44 | 45 | 46 | /** 47 | * According to RFC2812 the channel's name may and must start with one of the 48 | * following characters. 49 | *

    50 | *
  • ! == 33 (ASCII)
  • 51 | *
  • # == 35
  • 52 | *
  • & == 38
  • 53 | *
  • + == 43
  • 54 | *
. 55 | * @param str The name to check if it's a channel. 56 | * @return true if the argument starts with one of the characters 57 | * mentioned above. 58 | */ 59 | public static boolean isChan(String str) { 60 | int c; 61 | return (str.length() >= 2) 62 | && ((c = str.charAt(0)) == '#' || c == '&' || c == '!' || c == '+'); 63 | } 64 | 65 | 66 | /** 67 | * Parses a String to an int via 68 | * Integer.parseInt but avoids the 69 | * NumberFormatException. 70 | * @param str The String to parse. 71 | * @return The parsed new int. -1 if 72 | * NumberFormatException was thrown. 73 | */ 74 | public static int parseInt(String str) { 75 | try { 76 | return Integer.parseInt(str); 77 | } catch (NumberFormatException exc) { 78 | return -1; 79 | } 80 | } 81 | 82 | 83 | /** 84 | * Erases the mIRC colorcodes from a String. 85 | * The documentation of the evil color codes is available on 86 | * http://www.mirc.co.uk/help/color.txt. 88 | *

89 | * Calling this method is equivalent to 90 | * {@code IRCUtil.stripColors(new StringBuilder(str), false).toString()}. 91 | * 92 | * @param str The line which should be parsed. 93 | * @return A line cleaned from any mIRC colorcodes. 94 | * @see #stripColorsAndCTCPDelimiters(StringBuilder) 95 | */ 96 | public static String stripColors(String str) { 97 | return stripColors(new StringBuilder(str), false).toString(); 98 | } 99 | 100 | 101 | 102 | /** 103 | * Erases the mIRC colorcodes from a StringBuilder. 104 | * The documentation of the evil color codes is available on 105 | * http://www.mirc.co.uk/help/color.txt. 107 | *

108 | * Calling this method is equivalent to 109 | * {@code IRCUtil.stripColors(buf, false)}. 110 | * 111 | * @param buf The line which should be parsed. 112 | * @return A line cleaned from any mIRC colorcodes. 113 | * @see #stripColorsAndCTCPDelimiters(StringBuilder) 114 | */ 115 | public static StringBuilder stripColors(StringBuilder buf) { 116 | return stripColors(buf, false); 117 | } 118 | 119 | /** 120 | * Erases the mIRC colorcodes and CTCP delimiters from a StringBuilder. 121 | * The documentation of the evil color codes is available on 122 | * http://www.mirc.co.uk/help/color.txt. 124 | *

125 | * Calling this method is equivalent to 126 | * {@code IRCUtil.stripColors(buf, true)}. 127 | * 128 | * @param buf The line which should be parsed. 129 | * @return A line as StringBuilder object which is cleaned from 130 | * any mIRC colorcodes. 131 | */ 132 | public static StringBuilder stripColorsAndCTCPDelimiters(StringBuilder buf) { 133 | return stripColors(buf, true); 134 | } 135 | 136 | 137 | /** 138 | * Erases the mIRC colorcodes and optionally also CTCP delimiters from a String. 139 | * The documentation of the evil color codes is available on 140 | * http://www.mirc.co.uk/help/color.txt. 142 | * 143 | * @param buf The line which should be parsed. 144 | * @param removeCTCP If false, CTCP_DELIMITERs 145 | * are left untouched in the string. 146 | * @return A line as StringBuilder object which is cleaned from 147 | * any mIRC colorcodes. 148 | */ 149 | private static StringBuilder stripColors(StringBuilder buf, 150 | boolean removeCTCP) { 151 | int len = buf.length(); 152 | char c; 153 | for (int i = 0, j = 0; i < len; i++, j = i) { 154 | c = buf.charAt(i); 155 | try { 156 | // COLORS Beginning 157 | // (format: [][[,[]] 158 | if (c == COLOR_INDICATOR) { 159 | c = buf.charAt(++j); 160 | if ('0' <= c && c <= '9') { // first int 161 | c = buf.charAt(++j); 162 | if ('0' <= c && c <= '9') 163 | c = buf.charAt(++j); // second int 164 | } 165 | if (c == ',') 166 | c = buf.charAt(++j); // comma 167 | if ('0' <= c && c <= '9') { // first int 168 | c = buf.charAt(++j); 169 | if ('0' <= c && c <= '9') 170 | c = buf.charAt(++j); // second int 171 | } 172 | // CTCP / BOLD / UNDERLINE / COLOR END 173 | // (format: / etc.) 174 | } else if ((removeCTCP && c == CTCPCommand.QUOTE_CHAR) 175 | || c == BOLD_INDICATOR 176 | || c == UNDERLINE_INDICATOR 177 | || c == COLOR_END_INDICATOR 178 | || c == COLOR_REVERSE_INDICATOR) { 179 | j++; 180 | } 181 | } catch(StringIndexOutOfBoundsException exc) { 182 | // we got the end of the string with a call to charAt(++iIndexEnd) 183 | // nothing 184 | } 185 | 186 | if (j > i) { 187 | buf = buf.delete(i, j); // remove the cars 188 | len -= (j - i); 189 | i--; 190 | } 191 | } 192 | return buf; 193 | } 194 | 195 | 196 | /** 197 | * Splits a string into substrings. 198 | * @param str The string which is to split. 199 | * @param delim The delimiter character, for example a space ' '. 200 | * @param trailing The ending which is added as a substring though it wasn't 201 | * in the str. This parameter is just for the 202 | * IRCParser class which uses this method to 203 | * split the middle part into the parameters. 204 | * But as last parameter always the trailing is 205 | * added. This is done here because it's the fastest way to 206 | * do it here. 207 | * If the end is null or 208 | * "", nothing is appended. 209 | * @return An array with all substrings. 210 | * @see #split(String, int) 211 | */ 212 | public static String[] split(String str, int delim, String trailing) { 213 | List items = new ArrayList(15); 214 | int last = 0; 215 | int index = 0; 216 | int len = str.length(); 217 | while (index < len) { 218 | if (str.charAt(index) == delim) { 219 | items.add(str.substring(last, index)); 220 | last = index + 1; 221 | } 222 | index++; 223 | } 224 | if (last != len) 225 | items.add(str.substring(last)); 226 | if (trailing != null && trailing.length() != 0) 227 | items.add(trailing); 228 | String[] result = items.toArray(new String[0]); 229 | return result; 230 | } 231 | 232 | 233 | /** 234 | * Splits a string into substrings. This method is totally equal to 235 | * split(str, delim, null). 236 | * @param str The string which is to split. 237 | * @param delim The delimiter character, for example a space ' '. 238 | * @return An array with all substrings. 239 | * @see #split(String, int, String) 240 | */ 241 | public static String[] split(String str, int delim) { 242 | return split(str, delim, null); 243 | } 244 | 245 | public static int[] toArray(Collection list) { 246 | if (list == null || list.isEmpty()) { 247 | return new int[0]; 248 | } 249 | int[] result = new int[list.size()]; 250 | int i = 0; 251 | for (int value : list) { 252 | result[i++] = value; 253 | } 254 | return result; 255 | } 256 | } 257 | -------------------------------------------------------------------------------- /COPYING_AL.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /COPYING_EPL.txt: -------------------------------------------------------------------------------- 1 | *Eclipse Public License - v 1.0* 2 | 3 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE 4 | PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF 5 | THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 6 | 7 | *1. DEFINITIONS* 8 | 9 | "Contribution" means: 10 | 11 | a) in the case of the initial Contributor, the initial code and 12 | documentation distributed under this Agreement, and 13 | b) in the case of each subsequent Contributor: 14 | 15 | i) changes to the Program, and 16 | 17 | ii) additions to the Program; 18 | 19 | where such changes and/or additions to the Program originate from and 20 | are distributed by that particular Contributor. A Contribution 21 | 'originates' from a Contributor if it was added to the Program by such 22 | Contributor itself or anyone acting on such Contributor's behalf. 23 | Contributions do not include additions to the Program which: (i) are 24 | separate modules of software distributed in conjunction with the Program 25 | under their own license agreement, and (ii) are not derivative works of 26 | the Program. 27 | 28 | "Contributor" means any person or entity that distributes the Program. 29 | 30 | "Licensed Patents " mean patent claims licensable by a Contributor which 31 | are necessarily infringed by the use or sale of its Contribution alone 32 | or when combined with the Program. 33 | 34 | "Program" means the Contributions distributed in accordance with this 35 | Agreement. 36 | 37 | "Recipient" means anyone who receives the Program under this Agreement, 38 | including all Contributors. 39 | 40 | *2. GRANT OF RIGHTS* 41 | 42 | a) Subject to the terms of this Agreement, each Contributor hereby 43 | grants Recipient a non-exclusive, worldwide, royalty-free copyright 44 | license to reproduce, prepare derivative works of, publicly display, 45 | publicly perform, distribute and sublicense the Contribution of such 46 | Contributor, if any, and such derivative works, in source code and 47 | object code form. 48 | 49 | b) Subject to the terms of this Agreement, each Contributor hereby 50 | grants Recipient a non-exclusive, worldwide, royalty-free patent license 51 | under Licensed Patents to make, use, sell, offer to sell, import and 52 | otherwise transfer the Contribution of such Contributor, if any, in 53 | source code and object code form. This patent license shall apply to the 54 | combination of the Contribution and the Program if, at the time the 55 | Contribution is added by the Contributor, such addition of the 56 | Contribution causes such combination to be covered by the Licensed 57 | Patents. The patent license shall not apply to any other combinations 58 | which include the Contribution. No hardware per se is licensed hereunder. 59 | 60 | c) Recipient understands that although each Contributor grants the 61 | licenses to its Contributions set forth herein, no assurances are 62 | provided by any Contributor that the Program does not infringe the 63 | patent or other intellectual property rights of any other entity. Each 64 | Contributor disclaims any liability to Recipient for claims brought by 65 | any other entity based on infringement of intellectual property rights 66 | or otherwise. As a condition to exercising the rights and licenses 67 | granted hereunder, each Recipient hereby assumes sole responsibility to 68 | secure any other intellectual property rights needed, if any. For 69 | example, if a third party patent license is required to allow Recipient 70 | to distribute the Program, it is Recipient's responsibility to acquire 71 | that license before distributing the Program. 72 | 73 | d) Each Contributor represents that to its knowledge it has sufficient 74 | copyright rights in its Contribution, if any, to grant the copyright 75 | license set forth in this Agreement. 76 | 77 | *3. REQUIREMENTS* 78 | 79 | A Contributor may choose to distribute the Program in object code form 80 | under its own license agreement, provided that: 81 | 82 | a) it complies with the terms and conditions of this Agreement; and 83 | 84 | b) its license agreement: 85 | 86 | i) effectively disclaims on behalf of all Contributors all warranties 87 | and conditions, express and implied, including warranties or conditions 88 | of title and non-infringement, and implied warranties or conditions of 89 | merchantability and fitness for a particular purpose; 90 | 91 | ii) effectively excludes on behalf of all Contributors all liability for 92 | damages, including direct, indirect, special, incidental and 93 | consequential damages, such as lost profits; 94 | 95 | iii) states that any provisions which differ from this Agreement are 96 | offered by that Contributor alone and not by any other party; and 97 | 98 | iv) states that source code for the Program is available from such 99 | Contributor, and informs licensees how to obtain it in a reasonable 100 | manner on or through a medium customarily used for software exchange. 101 | 102 | When the Program is made available in source code form: 103 | 104 | a) it must be made available under this Agreement; and 105 | 106 | b) a copy of this Agreement must be included with each copy of the Program. 107 | 108 | Contributors may not remove or alter any copyright notices contained 109 | within the Program. 110 | 111 | Each Contributor must identify itself as the originator of its 112 | Contribution, if any, in a manner that reasonably allows subsequent 113 | Recipients to identify the originator of the Contribution. 114 | 115 | *4. COMMERCIAL DISTRIBUTION* 116 | 117 | Commercial distributors of software may accept certain responsibilities 118 | with respect to end users, business partners and the like. While this 119 | license is intended to facilitate the commercial use of the Program, the 120 | Contributor who includes the Program in a commercial product offering 121 | should do so in a manner which does not create potential liability for 122 | other Contributors. Therefore, if a Contributor includes the Program in 123 | a commercial product offering, such Contributor ("Commercial 124 | Contributor") hereby agrees to defend and indemnify every other 125 | Contributor ("Indemnified Contributor") against any losses, damages and 126 | costs (collectively "Losses") arising from claims, lawsuits and other 127 | legal actions brought by a third party against the Indemnified 128 | Contributor to the extent caused by the acts or omissions of such 129 | Commercial Contributor in connection with its distribution of the 130 | Program in a commercial product offering. The obligations in this 131 | section do not apply to any claims or Losses relating to any actual or 132 | alleged intellectual property infringement. In order to qualify, an 133 | Indemnified Contributor must: a) promptly notify the Commercial 134 | Contributor in writing of such claim, and b) allow the Commercial 135 | Contributor to control, and cooperate with the Commercial Contributor 136 | in, the defense and any related settlement negotiations. The Indemnified 137 | Contributor may participate in any such claim at its own expense. 138 | 139 | For example, a Contributor might include the Program in a commercial 140 | product offering, Product X. That Contributor is then a Commercial 141 | Contributor. If that Commercial Contributor then makes performance 142 | claims, or offers warranties related to Product X, those performance 143 | claims and warranties are such Commercial Contributor's responsibility 144 | alone. Under this section, the Commercial Contributor would have to 145 | defend claims against the other Contributors related to those 146 | performance claims and warranties, and if a court requires any other 147 | Contributor to pay any damages as a result, the Commercial Contributor 148 | must pay those damages. 149 | 150 | *5. NO WARRANTY* 151 | 152 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED 153 | ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 154 | EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES 155 | OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR 156 | A PARTICULAR PURPOSE. Each Recipient is solely responsible for 157 | determining the appropriateness of using and distributing the Program 158 | and assumes all risks associated with its exercise of rights under this 159 | Agreement , including but not limited to the risks and costs of program 160 | errors, compliance with applicable laws, damage to or loss of data, 161 | programs or equipment, and unavailability or interruption of operations. 162 | 163 | *6. DISCLAIMER OF LIABILITY* 164 | 165 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR 166 | ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, 167 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING 168 | WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF 169 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 170 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR 171 | DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED 172 | HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 173 | 174 | *7. GENERAL* 175 | 176 | If any provision of this Agreement is invalid or unenforceable under 177 | applicable law, it shall not affect the validity or enforceability of 178 | the remainder of the terms of this Agreement, and without further action 179 | by the parties hereto, such provision shall be reformed to the minimum 180 | extent necessary to make such provision valid and enforceable. 181 | 182 | If Recipient institutes patent litigation against any entity (including 183 | a cross-claim or counterclaim in a lawsuit) alleging that the Program 184 | itself (excluding combinations of the Program with other software or 185 | hardware) infringes such Recipient's patent(s), then such Recipient's 186 | rights granted under Section 2(b) shall terminate as of the date such 187 | litigation is filed. 188 | 189 | All Recipient's rights under this Agreement shall terminate if it fails 190 | to comply with any of the material terms or conditions of this Agreement 191 | and does not cure such failure in a reasonable period of time after 192 | becoming aware of such noncompliance. If all Recipient's rights under 193 | this Agreement terminate, Recipient agrees to cease use and distribution 194 | of the Program as soon as reasonably practicable. However, Recipient's 195 | obligations under this Agreement and any licenses granted by Recipient 196 | relating to the Program shall continue and survive. 197 | 198 | Everyone is permitted to copy and distribute copies of this Agreement, 199 | but in order to avoid inconsistency the Agreement is copyrighted and may 200 | only be modified in the following manner. The Agreement Steward reserves 201 | the right to publish new versions (including revisions) of this 202 | Agreement from time to time. No one other than the Agreement Steward has 203 | the right to modify this Agreement. The Eclipse Foundation is the 204 | initial Agreement Steward. The Eclipse Foundation may assign the 205 | responsibility to serve as the Agreement Steward to a suitable separate 206 | entity. Each new version of the Agreement will be given a distinguishing 207 | version number. The Program (including Contributions) may always be 208 | distributed subject to the version of the Agreement under which it was 209 | received. In addition, after a new version of the Agreement is 210 | published, Contributor may elect to distribute the Program (including 211 | its Contributions) under the new version. Except as expressly stated in 212 | Sections 2(a) and 2(b) above, Recipient receives no rights or licenses 213 | to the intellectual property of any Contributor under this Agreement, 214 | whether expressly, by implication, estoppel or otherwise. All rights in 215 | the Program not expressly granted under this Agreement are reserved. 216 | 217 | This Agreement is governed by the laws of the State of New York and the 218 | intellectual property laws of the United States of America. No party to 219 | this Agreement will bring a legal action under this Agreement more than 220 | one year after the cause of action arose. Each party waives its rights 221 | to a jury trial in any resulting litigation. 222 | 223 | 224 | 225 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | org.schwering 21 | irclib 22 | 2.0.0.Alpha4-SNAPSHOT 23 | bundle 24 | 25 | IRClib 26 | A Java Internet Relay Chat library 27 | http://moepii.sourceforge.net/ 28 | 2006 29 | 30 | 31 | The GNU Lesser General Public License, Version 2.1 32 | http://www.gnu.org/licenses/lgpl-2.1.txt 33 | repo 34 | 35 | 36 | Apache License, Version 2.0 37 | http://www.apache.org/licenses/LICENSE-2.0.txt 38 | repo 39 | 40 | 41 | Eclipse Public License 1.0 42 | http://opensource.org/licenses/eclipse-1.0.php 43 | repo 44 | 45 | 46 | 47 | 48 | 49 | Christoph Schwering 50 | schwering@gmail.com 51 | 52 | 53 | 54 | 55 | 56 | irclib-dev 57 | irclib-dev@googlegroups.com 58 | irclib-dev-unsubscribe@googlegroups.com 59 | http://groups.google.com/group/irclib-dev/ 60 | 61 | 62 | 63 | 64 | scm:git:https://github.com/java-irclib/irclib.git 65 | scm:git:git@github.com:java-irclib/irclib.git 66 | https://github.com/java-irclib/irclib 67 | head 68 | 69 | 70 | https://github.com/java-irclib/irclib/issues 71 | GitHub Issues 72 | 73 | 74 | 75 | bintray 76 | https://api.bintray.com/maven/irclib/irclib/org.schwering:irclib 77 | 78 | 79 | 80 | 81 | UTF-8 82 | version=${project.version} 83 | 84 | org.schwering.irc.* 85 | 86 | 87 | !org.schwering.irc.*, 88 | * 89 | 90 | ${project.groupId}.${project.artifactId} 91 | 92 | ${irclib.osgi.export.pkg};${irclib.osgi.version} 93 | ${irclib.osgi.import.pkg} 94 | 95 | !* 96 | false 97 | [$(version;==;$(@)),$(version;+;$(@))) 98 | false 99 | 100 | 101 | 6.1.1 102 | 103 | checkstyle.xml 104 | true 105 | true 106 | 107 | 108 | 2.13 109 | 110 | 111 | 112 | 113 | 114 | 115 | org.apache.felix 116 | maven-bundle-plugin 117 | 2.0.1 118 | 119 | 120 | 121 | 122 | 123 | 124 | com.mycila 125 | license-maven-plugin 126 | 2.9 127 | 128 |

${basedir}/license-header-template.txt
129 | 130 | COPYING_* 131 | RFC* 132 | **/README 133 | **/README.* 134 | **/license-header-template.txt 135 | **/*.html 136 | **/*.htm 137 | 138 | 139 | SCRIPT_STYLE 140 | SCRIPT_STYLE 141 | 142 | 143 | 144 | 145 | org.hawkular 146 | hawkular-build-tools 147 | 7 148 | 149 | 150 | 151 | 152 | 153 | check 154 | 155 | 156 | 157 | 158 | 159 | 160 | maven-compiler-plugin 161 | 162 | 1.6 163 | 1.6 164 | 165 | 166 | 167 | 168 | org.apache.felix 169 | maven-bundle-plugin 170 | 171 | true 172 | 173 | ${irclib.osgi.exclude.dependencies} 174 | 175 | org.schwering.irclib 176 | ${project.version} 177 | ${project.artifactId} 178 | ${irclib.osgi.symbolic.name} 179 | ${irclib.osgi.activator} 180 | ${irclib.osgi.export} 181 | ${irclib.osgi.import} 182 | ${irclib.osgi.dynamic} 183 | ${irclib.osgi.private.pkg} 184 | <_versionpolicy>${irclib.osgi.import.default.version} 185 | <_failok>${irclib.osgi.failok} 186 | 187 | 188 | 189 | 190 | 191 | org.apache.maven.plugins 192 | maven-checkstyle-plugin 193 | ${version.maven-checkstyle-plugin} 194 | 195 | ${checkstyle.configLocation} 196 | ${checkstyle.consoleOutput} 197 | ${checkstyle.failOnError} 198 | 199 | 200 | 201 | 202 | com.puppycrawl.tools 203 | checkstyle 204 | ${version.com.puppycrawl.tools.checkstyle} 205 | 206 | 207 | 208 | 209 | check-style 210 | validate 211 | 212 | checkstyle 213 | 214 | 215 | 216 | 217 | 218 | 219 | maven-release-plugin 220 | 2.5.1 221 | 222 | true 223 | release 224 | true 225 | @{project.version} 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | release 234 | 235 | 236 | 237 | maven-source-plugin 238 | 239 | 240 | attach-sources 241 | 242 | jar 243 | 244 | 245 | 246 | 247 | 248 | maven-javadoc-plugin 249 | 250 | 251 | attach-javadocs 252 | 253 | jar 254 | 255 | 256 | 257 | 258 | 259 | org.apache.maven.plugins 260 | maven-gpg-plugin 261 | 1.5 262 | 263 | 264 | sign-artifacts 265 | verify 266 | 267 | sign 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/IRCConfigBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib; 15 | 16 | import java.net.InetSocketAddress; 17 | import java.net.Proxy; 18 | import java.net.Proxy.Type; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | import org.schwering.irc.lib.impl.DefaultIRCConfig; 23 | import org.schwering.irc.lib.util.IRCUtil; 24 | 25 | /** 26 | * A fluent builder for {@link IRCConfig}s. For the typical usage, see {@link IRCConnection}. 27 | * 28 | * @author Peter Palaga 29 | */ 30 | public final class IRCConfigBuilder { 31 | 32 | /** Default {@link #autoPong} is {@value IRCConfigBuilder#DEFAULT_AUTOPONG} */ 33 | public static final boolean DEFAULT_AUTOPONG = true; 34 | 35 | /** Default {@link #encoding} is {@value IRCConfigBuilder#DEFAULT_ENCODING} */ 36 | public static final String DEFAULT_ENCODING = "utf-8"; 37 | 38 | /** 39 | * Default {@link #stripColors} is 40 | * {@value IRCConfigBuilder#DEFAULT_STRIP_COLORS} 41 | */ 42 | public static final boolean DEFAULT_STRIP_COLORS = false; 43 | 44 | /** 45 | * Default {@link #timeout} is {@value IRCConfigBuilder#DEFAULT_TIMEOUT} 46 | * milliseconds which is 15 minutes 47 | */ 48 | public static final int DEFAULT_TIMEOUT = 1000 * 60 * 15; 49 | 50 | /** 51 | * Creates a new {@link IRCConfigBuilder} initializing the following fields 52 | * with defaults: 53 | *
    54 | *
  • {@link #autoPong(boolean)}
  • 55 | *
  • {@link #encoding(String)}
  • 56 | *
  • {@link #stripColors(boolean)}
  • 57 | *
  • {@link #timeout(int)}
  • 58 | *
59 | * Other fields are left {@code null}. 60 | * 61 | * @return new {@link IRCConfigBuilder} 62 | */ 63 | public static IRCConfigBuilder newBuilder() { 64 | return new IRCConfigBuilder(); 65 | } 66 | 67 | /** @see #autoPong(boolean) */ 68 | private boolean autoPong = DEFAULT_AUTOPONG; 69 | 70 | /** @see #encoding(String) */ 71 | private String encoding = DEFAULT_ENCODING; 72 | 73 | /** @see #exceptionHandler(IRCExceptionHandler) */ 74 | private IRCExceptionHandler exceptionHandler; 75 | 76 | /** @see #host(String) */ 77 | private String host; 78 | 79 | /** @see #nick(String) */ 80 | private String nick; 81 | 82 | /** @see #password(String) */ 83 | private String password; 84 | 85 | /** 86 | * Remote port numbers to try when connecting. 87 | * 88 | * @see #portRange(int, int) 89 | * @see #port(int) 90 | * @see #ports(int...) 91 | */ 92 | private final List ports = new ArrayList(); 93 | 94 | /** @see #socksProxy(String, int) */ 95 | private Proxy proxy; 96 | 97 | /** @see #realname(String) */ 98 | private String realname; 99 | 100 | /** @see #sslSupport(IRCSSLSupport) */ 101 | private IRCSSLSupport sslSupport; 102 | 103 | /** @see #stripColors(boolean) */ 104 | private boolean stripColors = DEFAULT_STRIP_COLORS; 105 | 106 | /** @see #timeout(int) */ 107 | private int timeout = DEFAULT_TIMEOUT; 108 | 109 | /** @see #trafficLogger(IRCTrafficLogger) */ 110 | private IRCTrafficLogger trafficLogger; 111 | 112 | /** @see #username(String) */ 113 | private String username; 114 | 115 | /** 116 | * @see #newBuilder() 117 | */ 118 | private IRCConfigBuilder() { 119 | super(); 120 | } 121 | 122 | /** 123 | * Enables or disables the automatic PING? PONG! support. If not set through 124 | * this method, the default is {@value #DEFAULT_AUTOPONG}. 125 | * 126 | * @param autoPong 127 | * true to enable automatic PONG reply, 128 | * false makes the class fire onPing 129 | * events. 130 | * @return this builder 131 | */ 132 | public IRCConfigBuilder autoPong(boolean autoPong) { 133 | this.autoPong = autoPong; 134 | return this; 135 | } 136 | 137 | /** 138 | * @return a new {@link DefaultIRCConfig} instance based on the values 139 | * stored in fields of this {@link IRCConfigBuilder}. 140 | */ 141 | public IRCConfig build() { 142 | return new DefaultIRCConfig(host, IRCUtil.toArray(ports), password, nick, username, realname, encoding, 143 | timeout, autoPong, stripColors, sslSupport, proxy, trafficLogger, exceptionHandler); 144 | } 145 | 146 | /** 147 | * Copies all available fields from the given {@code config} to this 148 | * {@link IRCConfigBuilder}. 149 | * 150 | * @param config 151 | * the {@link IRCConfig} to take the values from 152 | * @return this builder 153 | */ 154 | public IRCConfigBuilder config(IRCConfig config) { 155 | serverConfig(config); 156 | runtimeConfig(config); 157 | return this; 158 | } 159 | 160 | /** 161 | * Changes the character encoding (such as {@code "UTF-8"} or 162 | * {@code "ISO-8859-1"}) used to talk to the server. If not set through this 163 | * method, the default is {@value #DEFAULT_ENCODING}. 164 | * 165 | * @param encoding 166 | * The new encoding string, e.g. "UTF-8" 167 | * @return this builder 168 | */ 169 | public IRCConfigBuilder encoding(String encoding) { 170 | this.encoding = encoding; 171 | return this; 172 | } 173 | 174 | /** 175 | * Sets the {@link IRCExceptionHandler} that should be notified by 176 | * {@link IRCConnection} when an exception during send or receive of IRC 177 | * messages occurs. 178 | * 179 | * @param exceptionHandler the {@link IRCExceptionHandler} 180 | * @return this builder 181 | */ 182 | public IRCConfigBuilder exceptionHandler(IRCExceptionHandler exceptionHandler) { 183 | this.exceptionHandler = exceptionHandler; 184 | return this; 185 | } 186 | 187 | /** 188 | * Sets the hostname or IP address of the IRC server to connect to. 189 | * 190 | * @param host the host name or IP address 191 | * @return this builder 192 | */ 193 | public IRCConfigBuilder host(String host) { 194 | this.host = host; 195 | return this; 196 | } 197 | 198 | /** 199 | * Sets the nick name preferred by the user who is connecting. 200 | * 201 | * @param nick 202 | * the nick name 203 | * @return this builder 204 | */ 205 | public IRCConfigBuilder nick(String nick) { 206 | this.nick = nick; 207 | return this; 208 | } 209 | 210 | /** 211 | * Sets the password of the user who is connecting. 212 | * 213 | * @param password the password 214 | * @return this builder 215 | */ 216 | public IRCConfigBuilder password(String password) { 217 | this.password = password; 218 | return this; 219 | } 220 | 221 | /** 222 | * Adds the given {@code port} to the internal list of ports. 223 | * 224 | * @param port 225 | * the port or the {@link #host(String)} to connect to 226 | * @return this builder 227 | */ 228 | public IRCConfigBuilder port(int port) { 229 | this.ports.add(port); 230 | return this; 231 | } 232 | 233 | /** 234 | * Adds the port numbers from the given range to the internal list of ports. 235 | * {@code portMin} is the first (lowest) port to add whereas {@code portMax} 236 | * is the last port to add. 237 | * 238 | * @param portMin 239 | * The beginning port of the port range. 240 | * @param portMax 241 | * The ending port of the port range. 242 | * @return this builder 243 | */ 244 | public IRCConfigBuilder portRange(int portMin, int portMax) { 245 | if (portMin > portMax) { 246 | int tmp = portMin; 247 | portMin = portMax; 248 | portMax = tmp; 249 | } 250 | for (int port = portMin; port <= portMax; port++) { 251 | ports.add(port); 252 | } 253 | return this; 254 | } 255 | 256 | /** 257 | * Adds the given port numbers to the internal list of ports. 258 | * 259 | * @param port 260 | * the port numbers to add 261 | * @return this builder 262 | */ 263 | public IRCConfigBuilder ports(int... port) { 264 | for (int p : port) { 265 | ports.add(p); 266 | } 267 | return this; 268 | } 269 | 270 | /** 271 | * Sets the real name (e.g. {@code"John Doe"}) of the user who is 272 | * connecting. 273 | * 274 | * @param realname 275 | * the real name 276 | * @return this builder 277 | */ 278 | public IRCConfigBuilder realname(String realname) { 279 | this.realname = realname; 280 | return this; 281 | } 282 | 283 | /** 284 | * Copies all available fields from the given {@code runtimeConfig} to this 285 | * {@link IRCConfigBuilder}. 286 | * 287 | * @param runtimeConfig 288 | * the {@link IRCRuntimeConfig} to take the values from 289 | * @return this builder 290 | */ 291 | public IRCConfigBuilder runtimeConfig(IRCRuntimeConfig runtimeConfig) { 292 | this.timeout = runtimeConfig.getTimeout(); 293 | this.autoPong = runtimeConfig.isAutoPong(); 294 | this.stripColors = runtimeConfig.isStripColorsEnabled(); 295 | this.sslSupport = runtimeConfig.getSSLSupport(); 296 | this.proxy = runtimeConfig.getProxy(); 297 | this.trafficLogger = runtimeConfig.getTrafficLogger(); 298 | this.exceptionHandler = runtimeConfig.getExceptionHandler(); 299 | return this; 300 | } 301 | 302 | /** 303 | * Copies all available fields from the given {@code serverConfig} to this 304 | * {@link IRCConfigBuilder}. 305 | * 306 | * @param serverConfig 307 | * the {@link IRCServerConfig} to take the values from 308 | * @return this builder 309 | */ 310 | public IRCConfigBuilder serverConfig(IRCServerConfig serverConfig) { 311 | this.host = serverConfig.getHost(); 312 | ports(serverConfig.getPorts()); 313 | this.password = serverConfig.getPassword(); 314 | this.nick = serverConfig.getNick(); 315 | this.username = serverConfig.getUsername(); 316 | this.realname = serverConfig.getRealname(); 317 | this.encoding = serverConfig.getEncoding(); 318 | return this; 319 | } 320 | 321 | /** 322 | * Instructs the connection to use a SOCKS proxy with given {@code host} and 323 | * {@code port}. 324 | * 325 | * @param socksProxyHost 326 | * the hostname or IP address of the SOCKS proxy 327 | * @param socksProxyPort 328 | * the port of the SOCKS proxy 329 | * @return this builder 330 | */ 331 | public IRCConfigBuilder socksProxy(String socksProxyHost, int socksProxyPort) { 332 | if (socksProxyHost == null) { 333 | throw new IllegalArgumentException("socksProxyHost must be non-null, non-empty"); 334 | } 335 | proxy = new Proxy(Type.SOCKS, new InetSocketAddress(socksProxyHost, socksProxyPort)); 336 | return this; 337 | } 338 | 339 | /** 340 | * Sets the {@link IRCSSLSupport} containing the information the 341 | * {@link IRCConnection} should use to connect using SSL. 342 | * 343 | * @param sslSupport 344 | * the username of the user connecting to the IRC server 345 | * @return this builder 346 | */ 347 | public IRCConfigBuilder sslSupport(IRCSSLSupport sslSupport) { 348 | this.sslSupport = sslSupport; 349 | return this; 350 | } 351 | 352 | /** 353 | * Enables or disables the stripping of mIRC color codes. If not set through 354 | * this method, the default is {@value #DEFAULT_STRIP_COLORS}. 355 | * 356 | * @param stripColors 357 | * true to enable, false to disable 358 | * colors 359 | * @return this builder 360 | */ 361 | public IRCConfigBuilder stripColors(boolean stripColors) { 362 | this.stripColors = stripColors; 363 | return this; 364 | } 365 | 366 | /** 367 | * Sets the preferred connection's timeout in milliseconds. If not set 368 | * through this method, the default is {@value #DEFAULT_TIMEOUT}. 369 | * 370 | * @param millis 371 | * The socket's timeout in milliseconds. 372 | * @return this builder 373 | */ 374 | public IRCConfigBuilder timeout(int millis) { 375 | this.timeout = millis; 376 | return this; 377 | } 378 | 379 | /** 380 | * Sets the {@link IRCTrafficLogger} that should be notified by 381 | * {@link IRCConnection} about incoming and outgoing messages. 382 | * 383 | * @param trafficLogger 384 | * the {@link IRCTrafficLogger} the connection should notify 385 | * @return this builder 386 | */ 387 | public IRCConfigBuilder trafficLogger(IRCTrafficLogger trafficLogger) { 388 | this.trafficLogger = trafficLogger; 389 | return this; 390 | } 391 | 392 | /** 393 | * Sets the username of the user connecting to the IRC server. 394 | * 395 | * @param username 396 | * the username of the user connecting to the IRC server 397 | * @return this builder 398 | */ 399 | public IRCConfigBuilder username(String username) { 400 | this.username = username; 401 | return this; 402 | } 403 | } 404 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/IRCConnection.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib; 15 | 16 | import java.io.IOException; 17 | import java.net.InetAddress; 18 | import java.net.SocketException; 19 | import java.security.KeyManagementException; 20 | import java.security.NoSuchAlgorithmException; 21 | 22 | /** 23 | * A connection to an IRC server. 24 | *

25 | * Typical usage: 26 | *

 27 |  * IRCConfig config = IRCConfigBuilder.newBuilder()
 28 |  *          .host("irc.freenode.net")
 29 |  *          .port(6667)
 30 |  *          .username(System.getProperty("user.name"))
 31 |  *          .password("secret")
 32 |  *          .realname(System.getProperty("user.name"));
 33 |  * IRCConnection connection = IRCConnectionFactory.newConnection(config);
 34 |  * connection.addIRCEventListener(new IRCEventAdapter() {
 35 |  *     /* implement whatever you need */
 36 |  * });
 37 |  * connection.connect();
 38 |  * connection.doJoin("#test");
 39 |  * connection.doPrivmsg("#test", "Hello World!");
 40 |  * connection.close();
 41 |  * 
42 | * 43 | * @author Peter Palaga 44 | */ 45 | public interface IRCConnection { 46 | /** Value returned when there is no timeout to deliver. */ 47 | int INVALID_TIMEOUT = -1; 48 | 49 | /** 50 | * Adds a new {@link IRCEventListener} which listens for actions coming from 51 | * the IRC server. 52 | * 53 | * @param l 54 | * An instance of the {@link IRCEventListener} interface. 55 | * @throws IllegalArgumentException 56 | * If listener is null. 57 | */ 58 | void addIRCEventListener(IRCEventListener l); 59 | 60 | /** 61 | * Close the connection forcefully. 62 | *

63 | * This method does not send QUIT IRC command. Consider 64 | * using {@link #doQuit()} or {@link #doQuit(String)} to send the proper 65 | * QUIT command to the server. 66 | *

67 | * This method should be used only when there is a good reason for that, 68 | * e.g. that the IRC server does not react to QUIT command. 69 | *

70 | * Possibly occuring IOExceptions are handled according to the 71 | * set exception handling. 72 | * 73 | * @see #connect() 74 | * @see #doQuit 75 | * @see #doQuit(String) 76 | */ 77 | void close(); 78 | 79 | /** 80 | * Establish a connection to the server. This method must be invoked to 81 | * start a connection as the constructor does not do that. 82 | *

83 | * It tries all ports from {@link IRCConfig#getPorts()} until the connecting 84 | * succeeds. If all ports fail an IOException is thrown. 85 | *

86 | * This method can be invokde once only. 87 | * 88 | * @throws IOException 89 | * If an I/O error occurs. 90 | * @throws NoSuchAlgorithmException rethrown from the SSL layer 91 | * @throws KeyManagementException rethrown from the SSL layer 92 | * @throws SocketException 93 | * If the connect method was already invoked. 94 | * @see #isConnected() 95 | * @see #doQuit() 96 | * @see #doQuit(String) 97 | * @see #close() 98 | */ 99 | void connect() throws IOException, KeyManagementException, NoSuchAlgorithmException; 100 | 101 | /** 102 | * Removes away message. 103 | */ 104 | void doAway(); 105 | 106 | /** 107 | * Sets away message. 108 | * 109 | * @param msg 110 | * The away message. 111 | */ 112 | void doAway(String msg); 113 | 114 | /** 115 | * Invites a user to a channel. 116 | * 117 | * @param nick 118 | * The nickname of the user who should be invited. 119 | * @param chan 120 | * The channel the user should be invited to. 121 | */ 122 | void doInvite(String nick, String chan); 123 | 124 | /** 125 | * Checks if one or more nicks are used on the server. 126 | * 127 | * @param nick 128 | * The nickname of the user we search for. 129 | */ 130 | void doIson(String nick); 131 | 132 | /** 133 | * Joins a channel without a key. 134 | * 135 | * @param chan 136 | * The channel which is to join. 137 | */ 138 | void doJoin(String chan); 139 | 140 | /** 141 | * Joins a channel with a key. 142 | * 143 | * @param chan 144 | * The channel which is to join. 145 | * @param key 146 | * The key of the channel. 147 | */ 148 | void doJoin(String chan, String key); 149 | 150 | /** 151 | * Kicks a user from a channel. 152 | * 153 | * @param chan 154 | * The channel somebody should be kicked from. 155 | * @param nick 156 | * The nickname of the user who should be kicked. 157 | */ 158 | void doKick(String chan, String nick); 159 | 160 | 161 | /** 162 | * Kicks a user from a channel with a comment. 163 | * 164 | * @param chan 165 | * The channel somebody should be kicked from. 166 | * @param nick 167 | * The nickname of the user who should be kicked. 168 | * @param msg 169 | * The optional kickmessage. 170 | */ 171 | void doKick(String chan, String nick, String msg); 172 | 173 | /** 174 | * Lists all channels with their topic and status. 175 | */ 176 | void doList(); 177 | 178 | /** 179 | * Lists channel(s) with their topic and status. 180 | * 181 | * @param chan 182 | * The channel the LIST refers to. 183 | */ 184 | void doList(String chan); 185 | 186 | /** 187 | * Requests a Reply 324 for the modes of a given channel. 188 | * 189 | * @param chan 190 | * The channel the MODE request is refering to. 191 | */ 192 | void doMode(String chan); 193 | 194 | /** 195 | * Sends a mode to the server. 196 | * The first argument is a nickname (user-mode) or a channel (channel-mode). 197 | * String mode must contain the operators (+/-), the modes 198 | * (o/v/i/k/l/p/s/w) and the possibly values (nicks/banmask/limit/key). 199 | * 200 | * @param target 201 | * The nickname or channel of the user whose modes will be 202 | * changed. 203 | * @param mode 204 | * The new modes. 205 | */ 206 | void doMode(String target, String mode); 207 | 208 | /** 209 | * Lists all visible users. 210 | */ 211 | void doNames(); 212 | 213 | /** 214 | * Lists all visible users of (a) channel(s). 215 | * 216 | * @param chan 217 | * The channel the NAMES command is refering to. 218 | */ 219 | void doNames(String chan); 220 | 221 | /** 222 | * Changes the nickname. 223 | * 224 | * @param nick 225 | * The new nickname. 226 | */ 227 | void doNick(String nick); 228 | 229 | /** 230 | * Notices a message to a person or a channel. 231 | * 232 | * @param target 233 | * The nickname or channel (group) the message should be sent to. 234 | * @param msg 235 | * The message which should be transmitted. 236 | */ 237 | void doNotice(String target, String msg); 238 | 239 | /** 240 | * Parts from a given channel. 241 | * 242 | * @param chan 243 | * The channel you want to part from. 244 | */ 245 | void doPart(String chan); 246 | 247 | /** 248 | * Parts from a given channel with a given parg-msg. 249 | * 250 | * @param chan 251 | * The channel you want to part from. 252 | * @param msg 253 | * The optional partmessage. 254 | */ 255 | void doPart(String chan, String msg); 256 | 257 | /** 258 | * Quits from the IRC server with a quit-msg. 259 | * 260 | * @param ping 261 | * The ping which was received in onPing. It's a 262 | * String, because sometimes on some networks the 263 | * server-hostname (for example splatterworld.quakenet.org) is 264 | * given as parameter which would throw an Exception if we gave 265 | * the ping as long. 266 | */ 267 | void doPong(String ping); 268 | 269 | /** 270 | * Sends a message to a person or a channel. 271 | * 272 | * @param target 273 | * The nickname or channel the message should be sent to. 274 | * @param msg 275 | * The message which should be transmitted. 276 | */ 277 | void doPrivmsg(String target, String msg); 278 | 279 | /** 280 | * Quits from the IRC server. Calls the disconnect-method which 281 | * does the work actually. 282 | * 283 | * @see #isConnected() 284 | * @see #connect() 285 | * @see #doQuit(String) 286 | * @see #close() 287 | */ 288 | void doQuit(); 289 | 290 | /** 291 | * Quits from the IRC server with a quit-msg. Calls the 292 | * disconnect-method which does the work actually. 293 | * 294 | * @param msg 295 | * The optional quitmessage. 296 | * @see #isConnected() 297 | * @see #connect() 298 | * @see #doQuit() 299 | * @see #close() 300 | */ 301 | void doQuit(String msg); 302 | 303 | /** 304 | * Requests the topic of a chan. The topic is given in a numeric reply. 305 | * 306 | * @param chan 307 | * The channel which topic should be requested. 308 | */ 309 | void doTopic(String chan); 310 | 311 | /** 312 | * Changes the topic of a chan. 313 | * 314 | * @param chan 315 | * The channel which topic is changed. 316 | * @param topic 317 | * The new topic. 318 | */ 319 | void doTopic(String chan, String topic); 320 | 321 | /** 322 | * Requires host-information about up to 5 users which must be listed and 323 | * divided by spaces. 324 | * 325 | * @param nick 326 | * The nickname of the user the query is refering to. 327 | */ 328 | void doUserhost(String nick); 329 | 330 | /** 331 | * Requests information about users matching the given criteric, for example 332 | * a channel they are on. 333 | * 334 | * @param criteric 335 | * The criterics of the WHO query. 336 | */ 337 | void doWho(String criteric); 338 | 339 | /** 340 | * Requires information about an existing user. 341 | * 342 | * @param nick 343 | * The nickname of the user the query is refering to. 344 | */ 345 | void doWhois(String nick); 346 | 347 | /** 348 | * Requires host-information about a user, who is not connected anymore. 349 | * 350 | * @param nick 351 | * The nickname of the user the query is refering to. 352 | */ 353 | void doWhowas(String nick); 354 | 355 | /** 356 | * Returns the local address of the connection socket. If the connection is 357 | * not yet connected, null is returned. 358 | * 359 | * @return the local address 360 | */ 361 | InetAddress getLocalAddress(); 362 | 363 | /** 364 | * Returns the nickname of this instance. 365 | * 366 | * @return The nickname. 367 | */ 368 | String getNick(); 369 | 370 | /** 371 | * Returns the port to which the IRCConnection connected, or 372 | * 0 if the connection failed or wasn't tried yet. 373 | * 374 | * @return The port to which the IRCConnection, or 375 | * 0 if the connection failed or wasn't tried yet. 376 | */ 377 | int getPort(); 378 | 379 | /** 380 | * Returns the timeout of the socket. 381 | * If an error occurs, which is never the case, -1 is returned. 382 | * The possibly occuring IOException are handled according to 383 | * the set exception handling. 384 | * 385 | * @return The timeout. 386 | */ 387 | int getTimeout(); 388 | 389 | /** 390 | * Tells whether there's a connection to the IRC network or not. 391 | * If connect wasn't called yet, it returns false. 392 | * 393 | * @return The status of the connection; true if it's 394 | * connected. 395 | * @see #connect() 396 | * @see #doQuit() 397 | * @see #doQuit(String) 398 | * @see #close() 399 | */ 400 | boolean isConnected(); 401 | 402 | /** 403 | * @return {@code true} if the connection is using SSL 404 | */ 405 | boolean isSSL(); 406 | 407 | /** 408 | * Removes the first occurence of the given {@link IRCEventListener} from 409 | * the listener-vector. 410 | * 411 | * @param l 412 | * An instance of the {@link IRCEventListener} interface. 413 | * @return true if the listener was successfully removed; 414 | * false if it was not found. 415 | */ 416 | boolean removeIRCEventListener(IRCEventListener l); 417 | 418 | /** 419 | * Sends a String to the server. You should use this method only, if you 420 | * must do it. For most purposes, there are do* methods (like 421 | * doJoin). A carriage return line feed (\r\n) is 422 | * appended automatically. 423 | * 424 | * @param line 425 | * The line which should be send to the server without the 426 | * trailing carriage return line feed (\r\n). 427 | */ 428 | void send(String line); 429 | 430 | } 431 | -------------------------------------------------------------------------------- /src/main/java/org/schwering/irc/lib/util/IRCParser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * IRClib - A Java Internet Relay Chat library 3 | * Copyright (C) 2006-2015 Christoph Schwering 4 | * and/or other contributors as indicated by the @author tags. 5 | * 6 | * This library and the accompanying materials are made available under the 7 | * terms of the 8 | * - GNU Lesser General Public License, 9 | * - Apache License, Version 2.0 and 10 | * - Eclipse Public License v1.0. 11 | * This library is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY. 13 | */ 14 | package org.schwering.irc.lib.util; 15 | 16 | import org.schwering.irc.lib.IRCUser; 17 | import org.schwering.irc.lib.impl.DefaultIRCConnection; 18 | import org.schwering.irc.lib.impl.DefaultIRCUser; 19 | 20 | /** 21 | * Parses a line sent from the IRC server. 22 | *

23 | * Note: Probably this class is unimportant for you. It's used by the 24 | * IRCConnection to parse incoming lines. Nevertheless I declared 25 | * it as public because you might want to use it to parse IRC 26 | * command-shortcuts like MSG instead of PRIVMSG in 27 | * your client. 28 | * The following text goes on with the description of the class and what it 29 | * does. 30 | *

31 | * According with RFC1459 it divides the line into a prefix, a command and 32 | * its parameters. 33 | *

34 | * The prefix is only given if a line starts with a : (colon) 35 | * and is used to indicate from where the line is send. 36 | *

37 | * The next word in the line (if no prefix exists it is the first, else the 38 | * second word) is the command. 39 | * The command is eiter a valid IRC command or a three-digit number which 40 | * represents a numeric reply or a numeric error. 41 | *

42 | * The parameters are divided into a middle and a trailing part. 43 | * In the middle part one word means one parameter while the trailing part is 44 | * just one parameter independent from the amount of words in it. 45 | * If there is a " :" (space+colon) in the line, this point 46 | * means the beginning of the trailing. 47 | * If there is no such space+colon, the trailing is just the last word. 48 | * All words behind the space+colon mean just one parameter. 49 | * If there is only one parameter given (the parameter is the first, the last 50 | * and the only one), the parameter is available as trailing (with 51 | * getTrailing), not as middle! 52 | *

53 | * One line may have up to 15 parameters. Therefore up to 14 are middle and 54 | * one is the trailing. 55 | *

56 | * The line may have up to 510 characters plus the CR-LF (carriage return - 57 | * line feed) which trails the incoming line. 58 | *

59 | * The following extract of the RFC1459 shows the message format in BNF: 60 | * 61 | * <message>  ::= 62 | * [':' <prefix> <SPACE> ] <command> <params> 63 | * <crlf> 64 | * <prefix>   ::= 65 | * <servername> | <nick> 66 | * [ '!' <username> ] [ '@' <host> ] 67 | * 68 | * <command>  ::= 69 | * <letter> { <letter> } | <number> <number> 70 | * <number> 71 | * <SPACE>    ::= 72 | * ' ' { ' ' } 73 | * <params>   ::= 74 | * <SPACE> [ ':' <trailing> | <middle> <params> ] 75 | * <middle>   ::= 76 | * <Any *non-empty* sequence of octets not including SPACE or NUL or CR or 77 | * LF, the first of which may not be ':'> 78 | * <trailing> ::= 79 | * <Any, possibly *empty*, sequence of octets not including NUL or CR or 80 | * LF> 81 | * <crlf>     ::= 82 | * CR LF 83 | * 84 | * @author Christoph Schwering <schwering@gmail.com> 85 | * @see DefaultIRCConnection 86 | */ 87 | public class IRCParser { 88 | 89 | /** 90 | * The StringBuilder contains the line which was analyzed. 91 | */ 92 | private StringBuilder buf; 93 | 94 | /** 95 | * The length of the line. 96 | */ 97 | private int len; 98 | 99 | /** 100 | * The prefix, which is parsed out in the constructor. 101 | */ 102 | private String prefix; 103 | 104 | /** 105 | * The command, which is parsed out in the constructor. 106 | */ 107 | private String command; 108 | 109 | /** 110 | * The middle, which is parsed out in the constructor. 111 | */ 112 | private String middle; 113 | 114 | /** 115 | * The trailing, which is parsed out in the constructor. The trailing is the 116 | * part behind the colon (:) or the last parameter. 117 | */ 118 | private String trailing; 119 | 120 | /** 121 | * The parameters' array. It's not initialized in the constructor because of 122 | * rare access. The methods which use and need this parameter-array 123 | * (getParametersCount, getParameter, getParameterFrom etc.) initialize this 124 | * array by calling initParameters, if the array isn't initialized yet. 125 | */ 126 | private String[] parameters; 127 | 128 | 129 | /** 130 | * Parses the line after erasing all mIRC color codes. 131 | * This constructor is a shorthand for IRCParser(line, false). 132 | * @param line The line which will be parsed. 133 | */ 134 | public IRCParser(String line) { 135 | this(line, false); 136 | } 137 | 138 | 139 | /** 140 | * The main constructor. 141 | * Parses prefix, command, middle and trailing. 142 | * @param line The line which will be parsed. 143 | * @param stripColors If true, mIRC color codes are parsed out 144 | * by using {@link IRCUtil#stripColorsAndCTCPDelimiters(StringBuilder)} method. 145 | */ 146 | public IRCParser(String line, boolean stripColors) { 147 | int index = 0; 148 | int trail; 149 | 150 | buf = new StringBuilder(line); 151 | if (stripColors) 152 | buf = IRCUtil.stripColorsAndCTCPDelimiters(buf); 153 | len = buf.length(); 154 | 155 | // prefix 156 | if (buf.charAt(0) == ':') { 157 | prefix = buf.substring(1, (index = indexOf(' ', index))); 158 | index++; 159 | } 160 | 161 | while (buf.charAt(index) == ' ') 162 | index++; 163 | 164 | // command 165 | command = buf.substring(index, ((index = indexOf(' ', index)) != -1) 166 | ? index : (index = len)); 167 | 168 | while (index < len && buf.charAt(index) == ' ') 169 | index++; 170 | index--; 171 | 172 | // middle & trailing 173 | if ((trail = indexOf(" :", index)) != -1) 174 | trailing = buf.substring(trail + 2, len); 175 | else if ((trail = lastIndexOf(' ')) != -1 && trail >= index) 176 | trailing = buf.substring(trail + 1, len); 177 | middle = (index < trail) ? buf.substring(index + 1, trail) : ""; 178 | 179 | // save 180 | this.prefix = (prefix != null) ? prefix : ""; 181 | this.command = (command != null) ? command : ""; 182 | this.middle = (middle != null) ? middle : ""; 183 | this.trailing = (trailing != null) ? trailing : ""; 184 | } 185 | 186 | 187 | /** 188 | * Searches for a char in the StringBuilder buf from a given index 189 | * and returns its index. 190 | * @param c The char to search. 191 | * @param i The index the method will start searching at. 192 | * @return The index of the searched char. 193 | */ 194 | private int indexOf(int c, int i) { 195 | while (i < len) 196 | if (buf.charAt(i++) == c) 197 | return --i; 198 | return -1; 199 | } 200 | 201 | 202 | /** 203 | * Searches for a string in the StringBuilder buf from a given 204 | * index and returns its beginning index. 205 | * @param str The string to search. 206 | * @param i The index the method will start searching at. 207 | * @return The index of the searched string. 208 | */ 209 | private int indexOf(String str, int i) { 210 | int sublen = str.length(); 211 | int index = -1; 212 | int j; 213 | for ( ; i < len; i++) 214 | for (index = i, j = 0; i < len && j < sublen; i++, j++) 215 | if (buf.charAt(i) != str.charAt(j)) 216 | break; 217 | else if (j + 1 == sublen) 218 | return index; 219 | return -1; 220 | } 221 | 222 | 223 | /** 224 | * Searches for a given char in the StringBuilder buf. 225 | * It starts at the end. 226 | * Note: The method expects a character which is not c before 227 | * it can return an index. Thus in a string like "nick moor   228 | *   " with four trailing spaces 229 | * lastIndexOf(' ') does not return the the index of the last 230 | * space. It first waits for characters which are not a space (r, o, o, m) and 231 | * then returns the index of the next space: the space between 232 | * nick and moor. By this, also in lines with 233 | * trailing whitespace the trailing-part is correctly recognized. 234 | * @param c The char to search. 235 | * @return The last index of the searched char. 236 | */ 237 | private int lastIndexOf(int c) { 238 | int i = len; 239 | boolean ok = false; 240 | while (i > 0) 241 | if (buf.charAt(--i) != c) 242 | ok = true; 243 | else if (ok) 244 | return i; 245 | return -1; 246 | } 247 | 248 | 249 | /** 250 | * Initializes the parameters[]. 251 | * This method is called by getParam, getParamFrom 252 | * and getParamTo, if the parameters[] aren't 253 | * initialized yet. 254 | * The method splits the middle into all words using and appends 255 | * the trailing as last parameter. It uses the IRCUtil.split 256 | * method. 257 | */ 258 | private void initParameters() { 259 | parameters = IRCUtil.split(middle, ' ', trailing); 260 | } 261 | 262 | 263 | /** 264 | * Returns the line's prefix. A prefix is the part which contains information 265 | * about the sender of the line. If no prefix is set, "" is 266 | * returned; but in fact there's always a prefix. 267 | * @return The line's prefix. 268 | */ 269 | public String getPrefix() { 270 | return prefix; 271 | } 272 | 273 | 274 | /** 275 | * Returns the line's command. 276 | * @return The line's command. 277 | */ 278 | public String getCommand() { 279 | return command; 280 | } 281 | 282 | 283 | /** 284 | * Returns the line's middle. 285 | * @return The line's middle. 286 | */ 287 | public String getMiddle() { 288 | return middle; 289 | } 290 | 291 | 292 | /** 293 | * Returns the line's trailing. 294 | * @return The line's trailing. 295 | */ 296 | public String getTrailing() { 297 | return trailing; 298 | } 299 | 300 | 301 | /** 302 | * Returns the unparsed line. It looks exacttly as the server sent it, but 303 | * if colors are disabled and therefore already stripped away out by 304 | * {@link IRCUtil#stripColorsAndCTCPDelimiters(StringBuilder)}, the colors are not included in here. 305 | * @return The line. 306 | */ 307 | public String getLine() { 308 | return buf.toString(); 309 | } 310 | 311 | 312 | /** 313 | * Returns the line's parameters which consists of the middle and the 314 | * trailing. 315 | * @return The line's parameters. 316 | */ 317 | public String getParameters() { 318 | return middle + 319 | ((middle.length() != 0 && trailing.length() != 0) ? " " : "") + 320 | trailing; 321 | } 322 | 323 | 324 | /** 325 | * Returns the nickname of the person who sent the line 326 | * or the servername of the server which sent the line. 327 | * It is found in the prefix which always looks like that: 328 | * 329 | * <servername> | <nick> 330 | * [ '!' <username> ] [ '@' <host> ] 331 | * 332 | * If no prefix is given in the whole line, null is returned. 333 | * 334 | * Note: This method is totally equal to getServername! 335 | * 336 | * Note: There is also the method getUser which returns 337 | * an IRCUser object which holds the nickname, username and host. 338 | * By the way, the getUser uses the getNick, 339 | * getUsername and getHost methods to create this 340 | * object. 341 | * @return The nickname or the servername of the line. If no prefix is given, 342 | * null is returned. 343 | * @see #getServername() 344 | * @see #getUsername() 345 | * @see #getHost() 346 | * @see #getUser() 347 | */ 348 | public String getNick() { 349 | int i = prefix.indexOf('!'); 350 | if (i != -1 || (i = prefix.indexOf('@')) != -1) 351 | return prefix.substring(0, i); 352 | return (prefix.length() != 0) ? prefix : null; 353 | } 354 | 355 | 356 | /** 357 | * Returns the servername of the server which sent the line 358 | * or the nickname of the person who sent the line. 359 | * It is found in the prefix which always looks like that: 360 | * 361 | * <servername> | <nick> 362 | * [ '!' <username> ] [ '@' <host> ] 363 | * 364 | * If no prefix is given in the whole line, null is returned. 365 | * 366 | * Note: This method is totally equal to getNick! 367 | * 368 | * Note: There is also the method getUser which returns 369 | * an IRCUser object which holds the nickname, username and host. 370 | * By the way, the getUser uses the getNick, 371 | * getUsername and getHost methods to create this 372 | * object. 373 | * @return The servername or the nickname of the line. If no prefix is given, 374 | * null is returned. 375 | * @see #getNick() 376 | * @see #getUser() 377 | */ 378 | public String getServername() { 379 | return getNick(); 380 | } 381 | 382 | 383 | /** 384 | * Returns the username of the person who sent the line. 385 | * It is found in the prefix which always looks like that: 386 | * 387 | * <servername> | <nick> 388 | * [ '!' <username> ] [ '@' <host> ] 389 | * 390 | * If the username is not specified, this method returns null. 391 | * 392 | * Note: There is also the method getUser which returns 393 | * an IRCUser object which holds the nickname, username and host. 394 | * By the way, the getUser uses the getNick, 395 | * getUsername and getHost methods to create this 396 | * object. 397 | * @return The username of the line; null if it's not given. 398 | * @see #getNick() 399 | * @see #getHost() 400 | * @see #getUser() 401 | */ 402 | public String getUsername() { 403 | int i = prefix.indexOf('!') + 1; 404 | if (i != 0) { 405 | int j = prefix.indexOf('@', i); 406 | return prefix.substring(i, (j != -1) ? j : prefix.length()); 407 | } 408 | return null; 409 | } 410 | 411 | 412 | /** 413 | * Returns the host of the person who sent the line. 414 | * It is found in the prefix which always looks like that: 415 | * 416 | * <servername> | <nick> 417 | * [ '!' <username> ] [ '@' <host> ] 418 | * 419 | * If the host is not specified, this method returns null. 420 | * 421 | * Note: There is also the method getUser which returns 422 | * an IRCUser object which holds the nickname, username and host. 423 | * By the way, the getUser uses the getNick, 424 | * getUsername and getHost methods to create this 425 | * object. 426 | * @return The host of the line; null if it's not given. 427 | * @see #getNick() 428 | * @see #getUsername() 429 | * @see #getUser() 430 | */ 431 | public String getHost() { 432 | int i = prefix.indexOf('@') + 1; 433 | if (i != 0) 434 | return prefix.substring(i, prefix.length()); 435 | return null; 436 | } 437 | 438 | 439 | /** 440 | * Returns a new IRCUser object. 441 | * This method is equal to new IRCUser(IRCParser.getNick(), 442 | * IRCParser.getUsername(), IRCParser.getHost()). See those methods to 443 | * learn which value they return if they are not set. 444 | * @return A new IRCUser object with exactly those values which 445 | * are returned by the getNick, getUsername 446 | * and getHost methods. 447 | * @see #getNick() 448 | * @see #getUsername() 449 | * @see #getHost() 450 | */ 451 | public IRCUser getUser() { 452 | return new DefaultIRCUser(getNick(), getUsername(), getHost()); 453 | } 454 | 455 | 456 | /** 457 | * Gets count of parameters. 458 | * If parameters isn't initialized yet, it calls 459 | * initParameters to do that. 460 | * @return The number of parameters. 461 | */ 462 | public int getParameterCount() { 463 | if (parameters == null) 464 | initParameters(); 465 | return parameters.length; 466 | } 467 | 468 | 469 | /** 470 | * Get one parameter of the line. 471 | * If parameters isn't initialized yet, it calls 472 | * initParameters to do that. 473 | * @param i The index of the parameter you want to get. The index starts with 474 | * 1 and not with 0. 475 | * @return The ith parameter. If i is out of bounds, 476 | * "" is returned. 477 | */ 478 | public String getParameter(int i) { 479 | if (parameters == null) 480 | initParameters(); 481 | --i; 482 | if (i >= 0 && i < parameters.length) 483 | return parameters[i]; 484 | else 485 | return ""; 486 | } 487 | 488 | 489 | /** 490 | * Grabs the line's parameters from the ith to the last 491 | * parameter (including the ith). 492 | * If parameters isn't initialized yet, it calls 493 | * initParameters to do that. 494 | * @param i The index of the first parameter you want to get. 495 | * @return All parameters behind another beginning at the ith. 496 | * If i is out of bounds, "" is returned. 497 | */ 498 | public String getParametersFrom(int i) { 499 | if (parameters == null) 500 | initParameters(); 501 | StringBuilder params = new StringBuilder(); 502 | for (i--; i < parameters.length; i++) 503 | params.append(parameters[i] +" "); 504 | return params.toString(); 505 | } 506 | 507 | 508 | /** 509 | * Grabs the line's parameters from the first to the ith 510 | * parameters (including the ith). 511 | * If parameters isn't initialized yet, it calls 512 | * initParameters to do that. 513 | * @param i The index of the last parameter you want to get. 514 | * @return All parameters beginning at the first and ending at the 515 | * ith. If i is out of bounds, 516 | * "" is returned. 517 | */ 518 | public String getParametersTo(int i) { 519 | if (parameters == null) 520 | initParameters(); 521 | StringBuilder params = new StringBuilder(); 522 | int max = (i < parameters.length) ? i : parameters.length; 523 | for (i = 0; i < max; i++) 524 | params.append(parameters[i] +" "); 525 | return params.toString(); 526 | } 527 | 528 | 529 | /** 530 | * Generates a String with some information about the instance of 531 | * IRCParser. 532 | * Its format is: classname[prefix,command,middle,trailing]. 533 | * @return A String with information about the instance. 534 | */ 535 | public String toString() { 536 | return getClass().getName() +"["+ prefix +","+ command +","+ middle +","+ 537 | trailing +"]"; 538 | } 539 | } 540 | -------------------------------------------------------------------------------- /COPYING_LGPL.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS --------------------------------------------------------------------------------