Remove central guac-dev repo reference. Refactor net.sourceforge.guacamole to org.glyptodon.guacamole. Extensions are remaining with their classes in net.sourceforge.guacamole for compatibility's sake until we have a better system for extensions.

This commit is contained in:
Michael Jumper
2013-08-25 13:39:00 -07:00
parent 4352e6d444
commit 5912ea402d
165 changed files with 652 additions and 710 deletions

View File

@@ -0,0 +1,87 @@
package org.glyptodon.guacamole.net;
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is guacamole-common.
*
* The Initial Developer of the Original Code is
* Michael Jumper.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.io.GuacamoleReader;
import org.glyptodon.guacamole.io.GuacamoleWriter;
/**
* Provides abstract socket-like access to a Guacamole connection.
*
* @author Michael Jumper
*/
public interface GuacamoleSocket {
/**
* Returns a GuacamoleReader which can be used to read from the
* Guacamole instruction stream associated with the connection
* represented by this GuacamoleSocket.
*
* @return A GuacamoleReader which can be used to read from the
* Guacamole instruction stream.
*/
public GuacamoleReader getReader();
/**
* Returns a GuacamoleWriter which can be used to write to the
* Guacamole instruction stream associated with the connection
* represented by this GuacamoleSocket.
*
* @return A GuacamoleWriter which can be used to write to the
* Guacamole instruction stream.
*/
public GuacamoleWriter getWriter();
/**
* Releases all resources in use by the connection represented by this
* GuacamoleSocket.
*
* @throws GuacamoleException If an error occurs while releasing resources.
*/
public void close() throws GuacamoleException;
/**
* Returns whether this GuacamoleSocket is open and can be used for reading
* and writing.
*
* @return true if this GuacamoleSocket is open, false otherwise.
*/
public boolean isOpen();
}

View File

@@ -0,0 +1,195 @@
package org.glyptodon.guacamole.net;
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is guacamole-common.
*
* The Initial Developer of the Original Code is
* Michael Jumper.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
import java.util.UUID;
import java.util.concurrent.locks.ReentrantLock;
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.io.GuacamoleReader;
import org.glyptodon.guacamole.io.GuacamoleWriter;
/**
* Provides a unique identifier and synchronized access to the GuacamoleReader
* and GuacamoleWriter associated with a GuacamoleSocket.
*
* @author Michael Jumper
*/
public class GuacamoleTunnel {
/**
* The UUID associated with this tunnel. Every tunnel must have a
* corresponding UUID such that tunnel read/write requests can be
* directed to the proper tunnel.
*/
private UUID uuid;
/**
* The GuacamoleSocket that tunnel should use for communication on
* behalf of the connecting user.
*/
private GuacamoleSocket socket;
/**
* Lock acquired when a read operation is in progress.
*/
private ReentrantLock readerLock;
/**
* Lock acquired when a write operation is in progress.
*/
private ReentrantLock writerLock;
/**
* Creates a new GuacamoleTunnel which synchronizes access to the
* Guacamole instruction stream associated with the given GuacamoleSocket.
*
* @param socket The GuacamoleSocket to provide synchronized access for.
*/
public GuacamoleTunnel(GuacamoleSocket socket) {
this.socket = socket;
uuid = UUID.randomUUID();
readerLock = new ReentrantLock();
writerLock = new ReentrantLock();
}
/**
* Acquires exclusive read access to the Guacamole instruction stream
* and returns a GuacamoleReader for reading from that stream.
*
* @return A GuacamoleReader for reading from the Guacamole instruction
* stream.
*/
public GuacamoleReader acquireReader() {
readerLock.lock();
return socket.getReader();
}
/**
* Relinquishes exclusive read access to the Guacamole instruction
* stream. This function should be called whenever a thread finishes using
* a GuacamoleTunnel's GuacamoleReader.
*/
public void releaseReader() {
readerLock.unlock();
}
/**
* Returns whether there are threads waiting for read access to the
* Guacamole instruction stream.
*
* @return true if threads are waiting for read access the Guacamole
* instruction stream, false otherwise.
*/
public boolean hasQueuedReaderThreads() {
return readerLock.hasQueuedThreads();
}
/**
* Acquires exclusive write access to the Guacamole instruction stream
* and returns a GuacamoleWriter for writing to that stream.
*
* @return A GuacamoleWriter for writing to the Guacamole instruction
* stream.
*/
public GuacamoleWriter acquireWriter() {
writerLock.lock();
return socket.getWriter();
}
/**
* Relinquishes exclusive write access to the Guacamole instruction
* stream. This function should be called whenever a thread finishes using
* a GuacamoleTunnel's GuacamoleWriter.
*/
public void releaseWriter() {
writerLock.unlock();
}
/**
* Returns whether there are threads waiting for write access to the
* Guacamole instruction stream.
*
* @return true if threads are waiting for write access the Guacamole
* instruction stream, false otherwise.
*/
public boolean hasQueuedWriterThreads() {
return writerLock.hasQueuedThreads();
}
/**
* Returns the unique identifier associated with this GuacamoleTunnel.
*
* @return The unique identifier associated with this GuacamoleTunnel.
*/
public UUID getUUID() {
return uuid;
}
/**
* Returns the GuacamoleSocket used by this GuacamoleTunnel for reading
* and writing.
*
* @return The GuacamoleSocket used by this GuacamoleTunnel.
*/
public GuacamoleSocket getSocket() {
return socket;
}
/**
* Release all resources allocated to this GuacamoleTunnel.
*
* @throws GuacamoleException if an error occurs while releasing
* resources.
*/
public void close() throws GuacamoleException {
socket.close();
}
/**
* Returns whether this GuacamoleTunnel is open, or has been closed.
*
* @return true if this GuacamoleTunnel is open, false if it is closed.
*/
public boolean isOpen() {
return socket.isOpen();
}
}

View File

@@ -0,0 +1,160 @@
package org.glyptodon.guacamole.net;
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is guacamole-common.
*
* The Initial Developer of the Original Code is
* Michael Jumper.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
import org.glyptodon.guacamole.io.GuacamoleReader;
import org.glyptodon.guacamole.io.ReaderGuacamoleReader;
import org.glyptodon.guacamole.io.WriterGuacamoleWriter;
import org.glyptodon.guacamole.io.GuacamoleWriter;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.GuacamoleServerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Provides abstract socket-like access to a Guacamole connection over a given
* hostname and port.
*
* @author Michael Jumper
*/
public class InetGuacamoleSocket implements GuacamoleSocket {
/**
* Logger for this class.
*/
private Logger logger = LoggerFactory.getLogger(InetGuacamoleSocket.class);
/**
* The GuacamoleReader this socket should read from.
*/
private GuacamoleReader reader;
/**
* The GuacamoleWriter this socket should write to.
*/
private GuacamoleWriter writer;
/**
* The number of milliseconds to wait for data on the TCP socket before
* timing out.
*/
private static final int SOCKET_TIMEOUT = 15000;
/**
* The TCP socket that the GuacamoleReader and GuacamoleWriter exposed
* by this class should affect.
*/
private Socket sock;
/**
* Creates a new InetGuacamoleSocket which reads and writes instructions
* to the Guacamole instruction stream of the Guacamole proxy server
* running at the given hostname and port.
*
* @param hostname The hostname of the Guacamole proxy server to connect to.
* @param port The port of the Guacamole proxy server to connect to.
* @throws GuacamoleException If an error occurs while connecting to the
* Guacamole proxy server.
*/
public InetGuacamoleSocket(String hostname, int port) throws GuacamoleException {
try {
logger.debug("Connecting to guacd at {}:{}.", hostname, port);
// Get address
SocketAddress address = new InetSocketAddress(
InetAddress.getByName(hostname),
port
);
// Connect with timeout
sock = new Socket();
sock.connect(address, SOCKET_TIMEOUT);
// Set read timeout
sock.setSoTimeout(SOCKET_TIMEOUT);
// On successful connect, retrieve I/O streams
reader = new ReaderGuacamoleReader(new InputStreamReader(sock.getInputStream(), "UTF-8"));
writer = new WriterGuacamoleWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF-8"));
}
catch (IOException e) {
throw new GuacamoleServerException(e);
}
}
@Override
public void close() throws GuacamoleException {
try {
logger.debug("Closing socket to guacd.");
sock.close();
}
catch (IOException e) {
throw new GuacamoleServerException(e);
}
}
@Override
public GuacamoleReader getReader() {
return reader;
}
@Override
public GuacamoleWriter getWriter() {
return writer;
}
@Override
public boolean isOpen() {
return !sock.isClosed();
}
}

View File

@@ -0,0 +1,164 @@
package org.glyptodon.guacamole.net;
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is guacamole-common.
*
* The Initial Developer of the Original Code is
* Michael Jumper.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import javax.net.SocketFactory;
import javax.net.ssl.SSLSocketFactory;
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.GuacamoleServerException;
import org.glyptodon.guacamole.io.GuacamoleReader;
import org.glyptodon.guacamole.io.GuacamoleWriter;
import org.glyptodon.guacamole.io.ReaderGuacamoleReader;
import org.glyptodon.guacamole.io.WriterGuacamoleWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Provides abstract socket-like access to a Guacamole connection over SSL to
* a given hostname and port.
*
* @author Michael Jumper
*/
public class SSLGuacamoleSocket implements GuacamoleSocket {
/**
* Logger for this class.
*/
private Logger logger = LoggerFactory.getLogger(SSLGuacamoleSocket.class);
/**
* The GuacamoleReader this socket should read from.
*/
private GuacamoleReader reader;
/**
* The GuacamoleWriter this socket should write to.
*/
private GuacamoleWriter writer;
/**
* The number of milliseconds to wait for data on the TCP socket before
* timing out.
*/
private static final int SOCKET_TIMEOUT = 15000;
/**
* The TCP socket that the GuacamoleReader and GuacamoleWriter exposed
* by this class should affect.
*/
private Socket sock;
/**
* Creates a new SSLGuacamoleSocket which reads and writes instructions
* to the Guacamole instruction stream of the Guacamole proxy server
* running at the given hostname and port using SSL.
*
* @param hostname The hostname of the Guacamole proxy server to connect to.
* @param port The port of the Guacamole proxy server to connect to.
* @throws GuacamoleException If an error occurs while connecting to the
* Guacamole proxy server.
*/
public SSLGuacamoleSocket(String hostname, int port) throws GuacamoleException {
// Get factory for SSL sockets
SocketFactory socket_factory = SSLSocketFactory.getDefault();
try {
logger.debug("Connecting to guacd at {}:{} via SSL/TLS.",
hostname, port);
// Get address
SocketAddress address = new InetSocketAddress(
InetAddress.getByName(hostname),
port
);
// Connect with timeout
sock = socket_factory.createSocket();
sock.connect(address, SOCKET_TIMEOUT);
// Set read timeout
sock.setSoTimeout(SOCKET_TIMEOUT);
// On successful connect, retrieve I/O streams
reader = new ReaderGuacamoleReader(new InputStreamReader(sock.getInputStream(), "UTF-8"));
writer = new WriterGuacamoleWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF-8"));
}
catch (IOException e) {
throw new GuacamoleServerException(e);
}
}
@Override
public void close() throws GuacamoleException {
try {
logger.debug("Closing socket to guacd.");
sock.close();
}
catch (IOException e) {
throw new GuacamoleServerException(e);
}
}
@Override
public GuacamoleReader getReader() {
return reader;
}
@Override
public GuacamoleWriter getWriter() {
return writer;
}
@Override
public boolean isOpen() {
return !sock.isClosed();
}
}

View File

@@ -0,0 +1,7 @@
/**
* Classes which apply to network-specific concepts, such as low-level sockets
* and tunnels.
*/
package org.glyptodon.guacamole.net;