You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by jm...@apache.org on 2017/07/06 02:59:35 UTC

[01/13] incubator-guacamole-server git commit: GUACAMOLE-337: Remove unnecessary link to libguac-common for libguacd.

Repository: incubator-guacamole-server
Updated Branches:
  refs/heads/master 3fdd1e973 -> 6236eb8f9


GUACAMOLE-337: Remove unnecessary link to libguac-common for libguacd.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/a56a7207
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/a56a7207
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/a56a7207

Branch: refs/heads/master
Commit: a56a7207acfa54bea90404e34e890ed46262a972
Parents: 836fc3e
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Jun 10 14:14:42 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jul 1 16:04:52 2017 -0700

----------------------------------------------------------------------
 src/libguacd/Makefile.am | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/a56a7207/src/libguacd/Makefile.am
----------------------------------------------------------------------
diff --git a/src/libguacd/Makefile.am b/src/libguacd/Makefile.am
index 23cab3b..82c0888 100644
--- a/src/libguacd/Makefile.am
+++ b/src/libguacd/Makefile.am
@@ -31,11 +31,9 @@ libguacd_la_SOURCES = \
 
 libguacd_la_CFLAGS =        \
     -Werror -Wall -pedantic \
-    @COMMON_INCLUDE@        \
     @LIBGUAC_INCLUDE@
 
 libguacd_la_LIBADD = \
-    @COMMON_LTLIB@   \
     @LIBGUAC_LTLIB@
 
 libguacd_la_LDFLAGS = \


[05/13] incubator-guacamole-server git commit: GUACAMOLE-337: Do not include config.h in libguacd public headers.

Posted by jm...@apache.org.
GUACAMOLE-337: Do not include config.h in libguacd public headers.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/3a46fffe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/3a46fffe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/3a46fffe

Branch: refs/heads/master
Commit: 3a46fffe444a04af2f14c74f3cfe9b7195cb5696
Parents: 6c484c1
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Jun 10 19:17:57 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jul 1 16:05:14 2017 -0700

----------------------------------------------------------------------
 src/libguacd/libguacd/socket-ssl.h | 2 --
 src/libguacd/libguacd/user.h       | 2 --
 2 files changed, 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/3a46fffe/src/libguacd/libguacd/socket-ssl.h
----------------------------------------------------------------------
diff --git a/src/libguacd/libguacd/socket-ssl.h b/src/libguacd/libguacd/socket-ssl.h
index e1a341e..715db5b 100644
--- a/src/libguacd/libguacd/socket-ssl.h
+++ b/src/libguacd/libguacd/socket-ssl.h
@@ -21,8 +21,6 @@
 #ifndef __GUACD_SOCKET_SSL_H
 #define __GUACD_SOCKET_SSL_H
 
-#include "config.h"
-
 #include <guacamole/socket.h>
 #include <openssl/ssl.h>
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/3a46fffe/src/libguacd/libguacd/user.h
----------------------------------------------------------------------
diff --git a/src/libguacd/libguacd/user.h b/src/libguacd/libguacd/user.h
index 8c1db68..805cef5 100644
--- a/src/libguacd/libguacd/user.h
+++ b/src/libguacd/libguacd/user.h
@@ -21,8 +21,6 @@
 #ifndef LIBGUACD_USER_H
 #define LIBGUACD_USER_H
 
-#include "config.h"
-
 #include <guacamole/parser.h>
 #include <guacamole/socket.h>
 #include <guacamole/user.h>


[11/13] incubator-guacamole-server git commit: GUACAMOLE-337: Document that socket-ssl.h is not guaranteed to be present.

Posted by jm...@apache.org.
GUACAMOLE-337: Document that socket-ssl.h is not guaranteed to be present.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/60141175
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/60141175
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/60141175

Branch: refs/heads/master
Commit: 60141175ddb2a7ced91a154232eca314efdf8a2d
Parents: f504b1a
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Jul 1 18:55:20 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jul 1 18:55:20 2017 -0700

----------------------------------------------------------------------
 src/libguac/guacamole/socket-ssl.h | 7 +++++++
 1 file changed, 7 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/60141175/src/libguac/guacamole/socket-ssl.h
----------------------------------------------------------------------
diff --git a/src/libguac/guacamole/socket-ssl.h b/src/libguac/guacamole/socket-ssl.h
index c7a14df..7c72695 100644
--- a/src/libguac/guacamole/socket-ssl.h
+++ b/src/libguac/guacamole/socket-ssl.h
@@ -21,6 +21,13 @@
 #ifndef __GUACD_SOCKET_SSL_H
 #define __GUACD_SOCKET_SSL_H
 
+/**
+ * Provides an SSL/TLS implementation of guac_socket. This header will only be
+ * available if libguac was built with SSL support.
+ *
+ * @file socket-ssl.h
+ */
+
 #include "socket-types.h"
 
 #include <openssl/ssl.h>


[09/13] incubator-guacamole-server git commit: GUACAMOLE-337: Move libguacd functionality into libguac.

Posted by jm...@apache.org.
GUACAMOLE-337: Move libguacd functionality into libguac.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/f504b1a5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/f504b1a5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/f504b1a5

Branch: refs/heads/master
Commit: f504b1a5e883ac99a6c3f4058a150fb8c2b59c52
Parents: 5b748a4
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Jul 1 15:51:15 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jul 1 18:50:03 2017 -0700

----------------------------------------------------------------------
 Makefile.am                  |   2 -
 configure.ac                 |   5 -
 src/guacd/Makefile.am        |   2 -
 src/guacd/connection.c       |   1 -
 src/guacd/daemon.c           |   1 -
 src/guacd/proc-map.c         |   1 -
 src/guacd/proc-map.h         |   1 -
 src/guacd/proc.c             |   3 +-
 src/libguac/Makefile.am      |   3 +-
 src/libguac/guacamole/user.h |  24 +++
 src/libguac/user-handshake.c | 437 ++++++++++++++++++++++++++++++++++++++
 src/libguacd/Makefile.am     |  47 ----
 src/libguacd/libguacd/user.h |  48 -----
 src/libguacd/log.c           |  71 -------
 src/libguacd/log.h           |  42 ----
 src/libguacd/user.c          | 380 ---------------------------------
 16 files changed, 464 insertions(+), 604 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/Makefile.am
----------------------------------------------------------------------
diff --git a/Makefile.am b/Makefile.am
index d67db2a..3ba1e34 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -22,7 +22,6 @@ ACLOCAL_AMFLAGS = -I m4
 # Subprojects
 DIST_SUBDIRS =           \
     src/libguac          \
-    src/libguacd         \
     src/common           \
     src/common-ssh       \
     src/terminal         \
@@ -38,7 +37,6 @@ DIST_SUBDIRS =           \
 SUBDIRS =        \
     src/libguac  \
     src/common   \
-    src/libguacd \
     tests
 
 if ENABLE_COMMON_SSH

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index b4cc2d3..0800250 100644
--- a/configure.ac
+++ b/configure.ac
@@ -123,10 +123,6 @@ AC_SUBST([COMMON_INCLUDE], '-I$(top_srcdir)/src/common')
 AC_SUBST([PULSE_LTLIB],   '$(top_builddir)/src/pulse/libguac_pulse.la')
 AC_SUBST([PULSE_INCLUDE], '-I$(top_srcdir)/src/pulse')
 
-# Common utility library for guacd implementations
-AC_SUBST([LIBGUACD_LTLIB],   '$(top_builddir)/src/libguacd/libguacd.la')
-AC_SUBST([LIBGUACD_INCLUDE], '-I$(top_srcdir)/src/libguacd')
-
 # Common base SSH client
 AC_SUBST([COMMON_SSH_LTLIB],   '$(top_builddir)/src/common-ssh/libguac_common_ssh.la')
 AC_SUBST([COMMON_SSH_INCLUDE], '-I$(top_srcdir)/src/common-ssh')
@@ -1172,7 +1168,6 @@ AC_CONFIG_FILES([Makefile
                  src/common-ssh/Makefile
                  src/terminal/Makefile
                  src/libguac/Makefile
-                 src/libguacd/Makefile
                  src/guacd/Makefile
                  src/guacenc/Makefile
                  src/pulse/Makefile

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/src/guacd/Makefile.am
----------------------------------------------------------------------
diff --git a/src/guacd/Makefile.am b/src/guacd/Makefile.am
index b9433e8..14ab5db 100644
--- a/src/guacd/Makefile.am
+++ b/src/guacd/Makefile.am
@@ -49,12 +49,10 @@ guacd_SOURCES =  \
 guacd_CFLAGS =              \
     -Werror -Wall -pedantic \
     @COMMON_INCLUDE@        \
-    @LIBGUACD_INCLUDE@      \
     @LIBGUAC_INCLUDE@
 
 guacd_LDADD =        \
     @COMMON_LTLIB@   \
-    @LIBGUACD_LTLIB@ \
     @LIBGUAC_LTLIB@
 
 guacd_LDFLAGS =    \

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/src/guacd/connection.c
----------------------------------------------------------------------
diff --git a/src/guacd/connection.c b/src/guacd/connection.c
index 6c517bf..ef767ac 100644
--- a/src/guacd/connection.c
+++ b/src/guacd/connection.c
@@ -22,7 +22,6 @@
 #include "connection.h"
 #include "log.h"
 #include "move-fd.h"
-#include "libguacd/user.h"
 #include "proc.h"
 #include "proc-map.h"
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/src/guacd/daemon.c
----------------------------------------------------------------------
diff --git a/src/guacd/daemon.c b/src/guacd/daemon.c
index 3adf433..2e80ef3 100644
--- a/src/guacd/daemon.c
+++ b/src/guacd/daemon.c
@@ -22,7 +22,6 @@
 #include "connection.h"
 #include "conf-args.h"
 #include "conf-file.h"
-#include "libguacd/user.h"
 #include "log.h"
 #include "proc-map.h"
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/src/guacd/proc-map.c
----------------------------------------------------------------------
diff --git a/src/guacd/proc-map.c b/src/guacd/proc-map.c
index bbe50b3..ac87196 100644
--- a/src/guacd/proc-map.c
+++ b/src/guacd/proc-map.c
@@ -19,7 +19,6 @@
 
 #include "config.h"
 #include "common/list.h"
-#include "libguacd/user.h"
 #include "proc.h"
 #include "proc-map.h"
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/src/guacd/proc-map.h
----------------------------------------------------------------------
diff --git a/src/guacd/proc-map.h b/src/guacd/proc-map.h
index 5d8ce97..a242188 100644
--- a/src/guacd/proc-map.h
+++ b/src/guacd/proc-map.h
@@ -23,7 +23,6 @@
 
 #include "config.h"
 #include "common/list.h"
-#include "libguacd/user.h"
 #include "proc.h"
 
 #include <guacamole/client.h>

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/src/guacd/proc.c
----------------------------------------------------------------------
diff --git a/src/guacd/proc.c b/src/guacd/proc.c
index e5e9586..0a35910 100644
--- a/src/guacd/proc.c
+++ b/src/guacd/proc.c
@@ -19,7 +19,6 @@
 
 #include "config.h"
 
-#include "libguacd/user.h"
 #include "log.h"
 #include "move-fd.h"
 #include "proc.h"
@@ -92,7 +91,7 @@ static void* guacd_user_thread(void* data) {
     user->owner  = params->owner;
 
     /* Handle user connection from handshake until disconnect/completion */
-    guacd_handle_user(user, GUACD_USEC_TIMEOUT);
+    guac_user_handle_connection(user, GUACD_USEC_TIMEOUT);
 
     /* Stop client and prevent future users if all users are disconnected */
     if (client->connected_users == 0) {

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/src/libguac/Makefile.am
----------------------------------------------------------------------
diff --git a/src/libguac/Makefile.am b/src/libguac/Makefile.am
index 0bfa409..a1f47ed 100644
--- a/src/libguac/Makefile.am
+++ b/src/libguac/Makefile.am
@@ -91,7 +91,8 @@ libguac_la_SOURCES =   \
     timestamp.c        \
     unicode.c          \
     user.c             \
-    user-handlers.c
+    user-handlers.c    \
+    user-handshake.c
 
 # Compile WebP support if available
 if ENABLE_WEBP

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/src/libguac/guacamole/user.h
----------------------------------------------------------------------
diff --git a/src/libguac/guacamole/user.h b/src/libguac/guacamole/user.h
index c791c2d..b445f62 100644
--- a/src/libguac/guacamole/user.h
+++ b/src/libguac/guacamole/user.h
@@ -493,6 +493,30 @@ guac_user* guac_user_alloc();
 void guac_user_free(guac_user* user);
 
 /**
+ * Handles the portion of a user's Guacamole protocol handshake following the
+ * "select" instruction all subsequent I/O, automatically populating the
+ * handshake-related properties of the given guac_user and invoking
+ * guac_user_handle_instruction() for received instructions after the handshake
+ * has completed. This function blocks until the connection/user is aborted or
+ * the user disconnects.
+ *
+ * @param user
+ *     The user whose handshake and entire Guacamole protocol exchange should
+ *     be handled. The user must already be associated with a guac_socket and
+ *     guac_client, and the guac_client must already be fully initialized.
+ *
+ * @param usec_timeout
+ *     The number of microseconds to wait for instructions from the given
+ *     user before closing the connection with an error.
+ *
+ * @return
+ *     Zero if the user's Guacamole connection was successfully handled and
+ *     the user has disconnected, or non-zero if an error prevented the user's
+ *     connection from being handled properly.
+ */
+int guac_user_handle_connection(guac_user* user, int usec_timeout);
+
+/**
  * Call the appropriate handler defined by the given user for the given
  * instruction. A comparison is made between the instruction opcode and the
  * initial handler lookup table defined in user-handlers.c. The intial handlers

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/src/libguac/user-handshake.c
----------------------------------------------------------------------
diff --git a/src/libguac/user-handshake.c b/src/libguac/user-handshake.c
new file mode 100644
index 0000000..b601888
--- /dev/null
+++ b/src/libguac/user-handshake.c
@@ -0,0 +1,437 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "config.h"
+
+#include "client.h"
+#include "error.h"
+#include "parser.h"
+#include "protocol.h"
+#include "socket.h"
+#include "user.h"
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <string.h>
+
+/**
+ * Parameters required by the user input thread.
+ */
+typedef struct guac_user_input_thread_params {
+
+    /**
+     * The parser which will be used throughout the user's session.
+     */
+    guac_parser* parser;
+
+    /**
+     * A reference to the connected user.
+     */
+    guac_user* user;
+
+    /**
+     * The number of microseconds to wait for instructions from a connected
+     * user before closing the connection with an error.
+     */
+    int usec_timeout;
+
+} guac_user_input_thread_params;
+
+/**
+ * Prints an error message using the logging facilities of the given user,
+ * automatically including any information present in guac_error.
+ *
+ * @param user
+ *     The guac_user associated with the error that occurred.
+ *
+ * @param level
+ *     The level at which to log this message.
+ *
+ * @param message
+ *     The message to log.
+ */
+static void guac_user_log_guac_error(guac_user* user,
+        guac_client_log_level level, const char* message) {
+
+    if (guac_error != GUAC_STATUS_SUCCESS) {
+
+        /* If error message provided, include in log */
+        if (guac_error_message != NULL)
+            guac_user_log(user, level, "%s: %s", message,
+                    guac_error_message);
+
+        /* Otherwise just log with standard status string */
+        else
+            guac_user_log(user, level, "%s: %s", message,
+                    guac_status_string(guac_error));
+
+    }
+
+    /* Just log message if no status code */
+    else
+        guac_user_log(user, level, "%s", message);
+
+}
+
+/**
+ * Logs a reasonable explanatory message regarding handshake failure based on
+ * the current value of guac_error.
+ *
+ * @param user
+ *     The guac_user associated with the failed Guacamole protocol handshake.
+ */
+static void guac_user_log_handshake_failure(guac_user* user) {
+
+    if (guac_error == GUAC_STATUS_CLOSED)
+        guac_user_log(user, GUAC_LOG_INFO,
+                "Guacamole connection closed during handshake");
+    else if (guac_error == GUAC_STATUS_PROTOCOL_ERROR)
+        guac_user_log(user, GUAC_LOG_ERROR,
+                "Guacamole protocol violation. Perhaps the version of "
+                "guacamole-client is incompatible with this version of "
+                "libguac?");
+    else
+        guac_user_log(user, GUAC_LOG_WARNING,
+                "Guacamole handshake failed: %s",
+                guac_status_string(guac_error));
+
+}
+
+/**
+ * Copies the given array of mimetypes (strings) into a newly-allocated NULL-
+ * terminated array of strings. Both the array and the strings within the array
+ * are newly-allocated and must be later freed via guac_free_mimetypes().
+ *
+ * @param mimetypes
+ *     The array of mimetypes to copy.
+ *
+ * @param count
+ *     The number of mimetypes in the given array.
+ *
+ * @return
+ *     A newly-allocated, NULL-terminated array containing newly-allocated
+ *     copies of each of the mimetypes provided in the original mimetypes
+ *     array.
+ */
+static char** guac_copy_mimetypes(char** mimetypes, int count) {
+
+    int i;
+
+    /* Allocate sufficient space for NULL-terminated array of mimetypes */
+    char** mimetypes_copy = malloc(sizeof(char*) * (count+1));
+
+    /* Copy each provided mimetype */
+    for (i = 0; i < count; i++)
+        mimetypes_copy[i] = strdup(mimetypes[i]);
+
+    /* Terminate with NULL */
+    mimetypes_copy[count] = NULL;
+
+    return mimetypes_copy;
+
+}
+
+/**
+ * Frees the given array of mimetypes, including the space allocated to each
+ * mimetype string within the array. The provided array of mimetypes MUST have
+ * been allocated with guac_copy_mimetypes().
+ *
+ * @param mimetypes
+ *     The NULL-terminated array of mimetypes to free. This array MUST have
+ *     been previously allocated with guac_copy_mimetypes().
+ */
+static void guac_free_mimetypes(char** mimetypes) {
+
+    char** current_mimetype = mimetypes;
+
+    /* Free all strings within NULL-terminated mimetype array */
+    while (*current_mimetype != NULL) {
+        free(*current_mimetype);
+        current_mimetype++;
+    }
+
+    /* Free the array itself, now that its contents have been freed */
+    free(mimetypes);
+
+}
+
+/**
+ * The thread which handles all user input, calling event handlers for received
+ * instructions.
+ *
+ * @param data
+ *     A pointer to a guac_user_input_thread_params structure describing the
+ *     user whose input is being handled and the guac_parser with which to
+ *     handle it.
+ *
+ * @return
+ *     Always NULL.
+ */
+static void* guac_user_input_thread(void* data) {
+
+    guac_user_input_thread_params* params =
+        (guac_user_input_thread_params*) data;
+
+    int usec_timeout = params->usec_timeout;
+    guac_user* user = params->user;
+    guac_parser* parser = params->parser;
+    guac_client* client = user->client;
+    guac_socket* socket = user->socket;
+
+    /* Guacamole user input loop */
+    while (client->state == GUAC_CLIENT_RUNNING && user->active) {
+
+        /* Read instruction, stop on error */
+        if (guac_parser_read(parser, socket, usec_timeout)) {
+
+            if (guac_error == GUAC_STATUS_TIMEOUT)
+                guac_user_abort(user, GUAC_PROTOCOL_STATUS_CLIENT_TIMEOUT, "User is not responding.");
+
+            else {
+                if (guac_error != GUAC_STATUS_CLOSED)
+                    guac_user_log_guac_error(user, GUAC_LOG_WARNING,
+                            "Guacamole connection failure");
+                guac_user_stop(user);
+            }
+
+            return NULL;
+        }
+
+        /* Reset guac_error and guac_error_message (user/client handlers are not
+         * guaranteed to set these) */
+        guac_error = GUAC_STATUS_SUCCESS;
+        guac_error_message = NULL;
+
+        /* Call handler, stop on error */
+        if (guac_user_handle_instruction(user, parser->opcode, parser->argc, parser->argv) < 0) {
+
+            /* Log error */
+            guac_user_log_guac_error(user, GUAC_LOG_WARNING,
+                    "User connection aborted");
+
+            /* Log handler details */
+            guac_user_log(user, GUAC_LOG_DEBUG, "Failing instruction handler in user was \"%s\"", parser->opcode);
+
+            guac_user_stop(user);
+            return NULL;
+        }
+
+    }
+
+    return NULL;
+
+}
+
+/**
+ * Starts the input/output threads of a new user. This function will block
+ * until the user disconnects. If an error prevents the input/output threads
+ * from starting, guac_user_stop() will be invoked on the given user.
+ *
+ * @param parser
+ *     The guac_parser to use to handle all input from the given user.
+ *
+ * @param user
+ *     The user whose associated I/O transfer threads should be started.
+ *
+ * @param usec_timeout
+ *     The number of microseconds to wait for instructions from the given
+ *     user before closing the connection with an error.
+ *
+ * @return
+ *     Zero if the I/O threads started successfully and user has disconnected,
+ *     or non-zero if the I/O threads could not be started.
+ */
+static int guac_user_start(guac_parser* parser, guac_user* user,
+        int usec_timeout) {
+
+    guac_user_input_thread_params params = {
+        .parser = parser,
+        .user = user,
+        .usec_timeout = usec_timeout
+    };
+
+    pthread_t input_thread;
+
+    if (pthread_create(&input_thread, NULL, guac_user_input_thread, (void*) &params)) {
+        guac_user_log(user, GUAC_LOG_ERROR, "Unable to start input thread");
+        guac_user_stop(user);
+        return -1;
+    }
+
+    /* Wait for I/O threads */
+    pthread_join(input_thread, NULL);
+
+    /* Explicitly signal disconnect */
+    guac_protocol_send_disconnect(user->socket);
+    guac_socket_flush(user->socket);
+
+    /* Done */
+    return 0;
+
+}
+
+int guac_user_handle_connection(guac_user* user, int usec_timeout) {
+
+    guac_socket* socket = user->socket;
+    guac_client* client = user->client;
+
+    /* Send args */
+    if (guac_protocol_send_args(socket, client->args)
+            || guac_socket_flush(socket)) {
+
+        /* Log error */
+        guac_user_log_handshake_failure(user);
+        guac_user_log_guac_error(user, GUAC_LOG_DEBUG,
+                "Error sending \"args\" to new user");
+
+        return 1;
+    }
+
+    guac_parser* parser = guac_parser_alloc();
+
+    /* Get optimal screen size */
+    if (guac_parser_expect(parser, socket, usec_timeout, "size")) {
+
+        /* Log error */
+        guac_user_log_handshake_failure(user);
+        guac_user_log_guac_error(user, GUAC_LOG_DEBUG,
+                "Error reading \"size\"");
+
+        guac_parser_free(parser);
+        return 1;
+    }
+
+    /* Validate content of size instruction */
+    if (parser->argc < 2) {
+        guac_user_log(user, GUAC_LOG_ERROR, "Received \"size\" "
+                "instruction lacked required arguments.");
+        guac_parser_free(parser);
+        return 1;
+    }
+
+    /* Parse optimal screen dimensions from size instruction */
+    user->info.optimal_width  = atoi(parser->argv[0]);
+    user->info.optimal_height = atoi(parser->argv[1]);
+
+    /* If DPI given, set the user resolution */
+    if (parser->argc >= 3)
+        user->info.optimal_resolution = atoi(parser->argv[2]);
+
+    /* Otherwise, use a safe default for rough backwards compatibility */
+    else
+        user->info.optimal_resolution = 96;
+
+    /* Get supported audio formats */
+    if (guac_parser_expect(parser, socket, usec_timeout, "audio")) {
+
+        /* Log error */
+        guac_user_log_handshake_failure(user);
+        guac_user_log_guac_error(user, GUAC_LOG_DEBUG,
+                "Error reading \"audio\"");
+
+        guac_parser_free(parser);
+        return 1;
+    }
+
+    /* Store audio mimetypes */
+    char** audio_mimetypes = guac_copy_mimetypes(parser->argv, parser->argc);
+    user->info.audio_mimetypes = (const char**) audio_mimetypes;
+
+    /* Get supported video formats */
+    if (guac_parser_expect(parser, socket, usec_timeout, "video")) {
+
+        /* Log error */
+        guac_user_log_handshake_failure(user);
+        guac_user_log_guac_error(user, GUAC_LOG_DEBUG,
+                "Error reading \"video\"");
+
+        guac_parser_free(parser);
+        return 1;
+    }
+
+    /* Store video mimetypes */
+    char** video_mimetypes = guac_copy_mimetypes(parser->argv, parser->argc);
+    user->info.video_mimetypes = (const char**) video_mimetypes;
+
+    /* Get supported image formats */
+    if (guac_parser_expect(parser, socket, usec_timeout, "image")) {
+
+        /* Log error */
+        guac_user_log_handshake_failure(user);
+        guac_user_log_guac_error(user, GUAC_LOG_DEBUG,
+                "Error reading \"image\"");
+
+        guac_parser_free(parser);
+        return 1;
+    }
+
+    /* Store image mimetypes */
+    char** image_mimetypes = guac_copy_mimetypes(parser->argv, parser->argc);
+    user->info.image_mimetypes = (const char**) image_mimetypes;
+
+    /* Get args from connect instruction */
+    if (guac_parser_expect(parser, socket, usec_timeout, "connect")) {
+
+        /* Log error */
+        guac_user_log_handshake_failure(user);
+        guac_user_log_guac_error(user, GUAC_LOG_DEBUG,
+                "Error reading \"connect\"");
+
+        guac_parser_free(parser);
+        return 1;
+    }
+
+    /* Acknowledge connection availability */
+    guac_protocol_send_ready(socket, client->connection_id);
+    guac_socket_flush(socket);
+
+    /* Attempt join */
+    if (guac_client_add_user(client, user, parser->argc, parser->argv))
+        guac_client_log(client, GUAC_LOG_ERROR, "User \"%s\" could NOT "
+                "join connection \"%s\"", user->user_id, client->connection_id);
+
+    /* Begin user connection if join successful */
+    else {
+
+        guac_client_log(client, GUAC_LOG_INFO, "User \"%s\" joined connection "
+                "\"%s\" (%i users now present)", user->user_id,
+                client->connection_id, client->connected_users);
+
+        /* Handle user I/O, wait for connection to terminate */
+        guac_user_start(parser, user, usec_timeout);
+
+        /* Remove/free user */
+        guac_client_remove_user(client, user);
+        guac_client_log(client, GUAC_LOG_INFO, "User \"%s\" disconnected (%i "
+                "users remain)", user->user_id, client->connected_users);
+
+    }
+
+    /* Free mimetype lists */
+    guac_free_mimetypes(audio_mimetypes);
+    guac_free_mimetypes(video_mimetypes);
+    guac_free_mimetypes(image_mimetypes);
+
+    guac_parser_free(parser);
+
+    /* Successful disconnect */
+    return 0;
+
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/src/libguacd/Makefile.am
----------------------------------------------------------------------
diff --git a/src/libguacd/Makefile.am b/src/libguacd/Makefile.am
deleted file mode 100644
index c0373f1..0000000
--- a/src/libguacd/Makefile.am
+++ /dev/null
@@ -1,47 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-AUTOMAKE_OPTIONS = foreign 
-
-lib_LTLIBRARIES = libguacd.la
-
-libguacdincdir = $(includedir)/libguacd
-
-libguacdinc_HEADERS = \
-    libguacd/user.h
-
-noinst_HEADERS = \
-    log.h
-
-libguacd_la_SOURCES = \
-    log.c             \
-    user.c
-
-libguacd_la_CFLAGS =        \
-    -Werror -Wall -pedantic \
-    @LIBGUAC_INCLUDE@
-
-libguacd_la_LIBADD = \
-    @LIBGUAC_LTLIB@
-
-libguacd_la_LDFLAGS =    \
-    -version-info 0:0:0  \
-    -no-undefined        \
-    @PTHREAD_LIBS@
-

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/src/libguacd/libguacd/user.h
----------------------------------------------------------------------
diff --git a/src/libguacd/libguacd/user.h b/src/libguacd/libguacd/user.h
deleted file mode 100644
index 4404a6c..0000000
--- a/src/libguacd/libguacd/user.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-#ifndef LIBGUACD_USER_H
-#define LIBGUACD_USER_H
-
-#include <guacamole/parser.h>
-#include <guacamole/socket.h>
-#include <guacamole/user.h>
-
-/**
- * Handles the initial handshake of a user and all subsequent I/O. This
- * function blocks until the user disconnects.
- *
- * @param user
- *     The user whose handshake and entire Guacamole protocol exchange should
- *     be handled.
- *
- * @param usec_timeout
- *     The number of microseconds to wait for instructions from the given
- *     user before closing the connection with an error.
- *
- * @return
- *     Zero if the user's Guacamole connection was successfully handled and
- *     the user has disconnected, or non-zero if an error prevented the user's
- *     connection from being handled properly.
- */
-int guacd_handle_user(guac_user* user, int usec_timeout);
-
-#endif
-

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/src/libguacd/log.c
----------------------------------------------------------------------
diff --git a/src/libguacd/log.c b/src/libguacd/log.c
deleted file mode 100644
index 180cc97..0000000
--- a/src/libguacd/log.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include "config.h"
-#include "log.h"
-
-#include <guacamole/client.h>
-#include <guacamole/error.h>
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <unistd.h>
-
-void guacd_client_log_guac_error(guac_client* client,
-        guac_client_log_level level, const char* message) {
-
-    if (guac_error != GUAC_STATUS_SUCCESS) {
-
-        /* If error message provided, include in log */
-        if (guac_error_message != NULL)
-            guac_client_log(client, level, "%s: %s",
-                    message,
-                    guac_error_message);
-
-        /* Otherwise just log with standard status string */
-        else
-            guac_client_log(client, level, "%s: %s",
-                    message,
-                    guac_status_string(guac_error));
-
-    }
-
-    /* Just log message if no status code */
-    else
-        guac_client_log(client, level, "%s", message);
-
-}
-
-void guacd_client_log_handshake_failure(guac_client* client) {
-
-    if (guac_error == GUAC_STATUS_CLOSED)
-        guac_client_log(client, GUAC_LOG_INFO,
-                "Guacamole connection closed during handshake");
-    else if (guac_error == GUAC_STATUS_PROTOCOL_ERROR)
-        guac_client_log(client, GUAC_LOG_ERROR,
-                "Guacamole protocol violation. Perhaps the version of "
-                "guacamole-client is incompatible with this version of "
-                "guacd?");
-    else
-        guac_client_log(client, GUAC_LOG_WARNING,
-                "Guacamole handshake failed: %s",
-                guac_status_string(guac_error));
-
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/src/libguacd/log.h
----------------------------------------------------------------------
diff --git a/src/libguacd/log.h b/src/libguacd/log.h
deleted file mode 100644
index 76509e3..0000000
--- a/src/libguacd/log.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef LIBGUACD_LOG_H
-#define LIBGUACD_LOG_H
-
-#include "config.h"
-
-#include <guacamole/client.h>
-
-/**
- * Prints an error message using the logging facilities of the given client,
- * automatically including any information present in guac_error. This function
- * accepts parameters identically to printf.
- */
-void guacd_client_log_guac_error(guac_client* client,
-        guac_client_log_level level, const char* message);
-
-/**
- * Logs a reasonable explanatory message regarding handshake failure based on
- * the current value of guac_error.
- */
-void guacd_client_log_handshake_failure(guac_client* client);
-
-#endif
-

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f504b1a5/src/libguacd/user.c
----------------------------------------------------------------------
diff --git a/src/libguacd/user.c b/src/libguacd/user.c
deleted file mode 100644
index 04f0f49..0000000
--- a/src/libguacd/user.c
+++ /dev/null
@@ -1,380 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include "config.h"
-
-#include "libguacd/user.h"
-#include "log.h"
-
-#include <guacamole/client.h>
-#include <guacamole/error.h>
-#include <guacamole/parser.h>
-#include <guacamole/protocol.h>
-#include <guacamole/socket.h>
-#include <guacamole/user.h>
-
-#include <pthread.h>
-#include <stdlib.h>
-#include <string.h>
-
-/**
- * Parameters required by the user input thread.
- */
-typedef struct guacd_user_input_thread_params {
-
-    /**
-     * The parser which will be used throughout the user's session.
-     */
-    guac_parser* parser;
-
-    /**
-     * A reference to the connected user.
-     */
-    guac_user* user;
-
-    /**
-     * The number of microseconds to wait for instructions from a connected
-     * user before closing the connection with an error.
-     */
-    int usec_timeout;
-
-} guacd_user_input_thread_params;
-
-/**
- * Copies the given array of mimetypes (strings) into a newly-allocated NULL-
- * terminated array of strings. Both the array and the strings within the array
- * are newly-allocated and must be later freed via guacd_free_mimetypes().
- *
- * @param mimetypes
- *     The array of mimetypes to copy.
- *
- * @param count
- *     The number of mimetypes in the given array.
- *
- * @return
- *     A newly-allocated, NULL-terminated array containing newly-allocated
- *     copies of each of the mimetypes provided in the original mimetypes
- *     array.
- */
-static char** guacd_copy_mimetypes(char** mimetypes, int count) {
-
-    int i;
-
-    /* Allocate sufficient space for NULL-terminated array of mimetypes */
-    char** mimetypes_copy = malloc(sizeof(char*) * (count+1));
-
-    /* Copy each provided mimetype */
-    for (i = 0; i < count; i++)
-        mimetypes_copy[i] = strdup(mimetypes[i]);
-
-    /* Terminate with NULL */
-    mimetypes_copy[count] = NULL;
-
-    return mimetypes_copy;
-
-}
-
-/**
- * Frees the given array of mimetypes, including the space allocated to each
- * mimetype string within the array. The provided array of mimetypes MUST have
- * been allocated with guacd_copy_mimetypes().
- *
- * @param mimetypes
- *     The NULL-terminated array of mimetypes to free. This array MUST have
- *     been previously allocated with guacd_copy_mimetypes().
- */
-static void guacd_free_mimetypes(char** mimetypes) {
-
-    char** current_mimetype = mimetypes;
-
-    /* Free all strings within NULL-terminated mimetype array */
-    while (*current_mimetype != NULL) {
-        free(*current_mimetype);
-        current_mimetype++;
-    }
-
-    /* Free the array itself, now that its contents have been freed */
-    free(mimetypes);
-
-}
-
-/**
- * The thread which handles all user input, calling event handlers for received
- * instructions.
- *
- * @param data
- *     A pointer to a guacd_user_input_thread_params structure describing the
- *     user whose input is being handled and the guac_parser with which to
- *     handle it.
- *
- * @return
- *     Always NULL.
- */
-static void* guacd_user_input_thread(void* data) {
-
-    guacd_user_input_thread_params* params =
-        (guacd_user_input_thread_params*) data;
-
-    int usec_timeout = params->usec_timeout;
-    guac_user* user = params->user;
-    guac_parser* parser = params->parser;
-    guac_client* client = user->client;
-    guac_socket* socket = user->socket;
-
-    /* Guacamole user input loop */
-    while (client->state == GUAC_CLIENT_RUNNING && user->active) {
-
-        /* Read instruction, stop on error */
-        if (guac_parser_read(parser, socket, usec_timeout)) {
-
-            if (guac_error == GUAC_STATUS_TIMEOUT)
-                guac_user_abort(user, GUAC_PROTOCOL_STATUS_CLIENT_TIMEOUT, "User is not responding.");
-
-            else {
-                if (guac_error != GUAC_STATUS_CLOSED)
-                    guacd_client_log_guac_error(client, GUAC_LOG_WARNING,
-                            "Guacamole connection failure");
-                guac_user_stop(user);
-            }
-
-            return NULL;
-        }
-
-        /* Reset guac_error and guac_error_message (user/client handlers are not
-         * guaranteed to set these) */
-        guac_error = GUAC_STATUS_SUCCESS;
-        guac_error_message = NULL;
-
-        /* Call handler, stop on error */
-        if (guac_user_handle_instruction(user, parser->opcode, parser->argc, parser->argv) < 0) {
-
-            /* Log error */
-            guacd_client_log_guac_error(client, GUAC_LOG_WARNING,
-                    "User connection aborted");
-
-            /* Log handler details */
-            guac_user_log(user, GUAC_LOG_DEBUG, "Failing instruction handler in user was \"%s\"", parser->opcode);
-
-            guac_user_stop(user);
-            return NULL;
-        }
-
-    }
-
-    return NULL;
-
-}
-
-/**
- * Starts the input/output threads of a new user. This function will block
- * until the user disconnects. If an error prevents the input/output threads
- * from starting, guac_user_stop() will be invoked on the given user.
- *
- * @param parser
- *     The guac_parser to use to handle all input from the given user.
- *
- * @param user
- *     The user whose associated I/O transfer threads should be started.
- *
- * @param usec_timeout
- *     The number of microseconds to wait for instructions from the given
- *     user before closing the connection with an error.
- *
- * @return
- *     Zero if the I/O threads started successfully and user has disconnected,
- *     or non-zero if the I/O threads could not be started.
- */
-static int guacd_user_start(guac_parser* parser, guac_user* user,
-        int usec_timeout) {
-
-    guacd_user_input_thread_params params = {
-        .parser = parser,
-        .user = user,
-        .usec_timeout = usec_timeout
-    };
-
-    pthread_t input_thread;
-
-    if (pthread_create(&input_thread, NULL, guacd_user_input_thread, (void*) &params)) {
-        guac_user_log(user, GUAC_LOG_ERROR, "Unable to start input thread");
-        guac_user_stop(user);
-        return -1;
-    }
-
-    /* Wait for I/O threads */
-    pthread_join(input_thread, NULL);
-
-    /* Explicitly signal disconnect */
-    guac_protocol_send_disconnect(user->socket);
-    guac_socket_flush(user->socket);
-
-    /* Done */
-    return 0;
-
-}
-
-int guacd_handle_user(guac_user* user, int usec_timeout) {
-
-    guac_socket* socket = user->socket;
-    guac_client* client = user->client;
-
-    /* Send args */
-    if (guac_protocol_send_args(socket, client->args)
-            || guac_socket_flush(socket)) {
-
-        /* Log error */
-        guacd_client_log_handshake_failure(client);
-        guacd_client_log_guac_error(client, GUAC_LOG_DEBUG,
-                "Error sending \"args\" to new user");
-
-        return 1;
-    }
-
-    guac_parser* parser = guac_parser_alloc();
-
-    /* Get optimal screen size */
-    if (guac_parser_expect(parser, socket, usec_timeout, "size")) {
-
-        /* Log error */
-        guacd_client_log_handshake_failure(client);
-        guacd_client_log_guac_error(client, GUAC_LOG_DEBUG,
-                "Error reading \"size\"");
-
-        guac_parser_free(parser);
-        return 1;
-    }
-
-    /* Validate content of size instruction */
-    if (parser->argc < 2) {
-        guac_client_log(client, GUAC_LOG_ERROR, "Received \"size\" "
-                "instruction lacked required arguments.");
-        guac_parser_free(parser);
-        return 1;
-    }
-
-    /* Parse optimal screen dimensions from size instruction */
-    user->info.optimal_width  = atoi(parser->argv[0]);
-    user->info.optimal_height = atoi(parser->argv[1]);
-
-    /* If DPI given, set the client resolution */
-    if (parser->argc >= 3)
-        user->info.optimal_resolution = atoi(parser->argv[2]);
-
-    /* Otherwise, use a safe default for rough backwards compatibility */
-    else
-        user->info.optimal_resolution = 96;
-
-    /* Get supported audio formats */
-    if (guac_parser_expect(parser, socket, usec_timeout, "audio")) {
-
-        /* Log error */
-        guacd_client_log_handshake_failure(client);
-        guacd_client_log_guac_error(client, GUAC_LOG_DEBUG,
-                "Error reading \"audio\"");
-
-        guac_parser_free(parser);
-        return 1;
-    }
-
-    /* Store audio mimetypes */
-    char** audio_mimetypes = guacd_copy_mimetypes(parser->argv, parser->argc);
-    user->info.audio_mimetypes = (const char**) audio_mimetypes;
-
-    /* Get supported video formats */
-    if (guac_parser_expect(parser, socket, usec_timeout, "video")) {
-
-        /* Log error */
-        guacd_client_log_handshake_failure(client);
-        guacd_client_log_guac_error(client, GUAC_LOG_DEBUG,
-                "Error reading \"video\"");
-
-        guac_parser_free(parser);
-        return 1;
-    }
-
-    /* Store video mimetypes */
-    char** video_mimetypes = guacd_copy_mimetypes(parser->argv, parser->argc);
-    user->info.video_mimetypes = (const char**) video_mimetypes;
-
-    /* Get supported image formats */
-    if (guac_parser_expect(parser, socket, usec_timeout, "image")) {
-
-        /* Log error */
-        guacd_client_log_handshake_failure(client);
-        guacd_client_log_guac_error(client, GUAC_LOG_DEBUG,
-                "Error reading \"image\"");
-
-        guac_parser_free(parser);
-        return 1;
-    }
-
-    /* Store image mimetypes */
-    char** image_mimetypes = guacd_copy_mimetypes(parser->argv, parser->argc);
-    user->info.image_mimetypes = (const char**) image_mimetypes;
-
-    /* Get args from connect instruction */
-    if (guac_parser_expect(parser, socket, usec_timeout, "connect")) {
-
-        /* Log error */
-        guacd_client_log_handshake_failure(client);
-        guacd_client_log_guac_error(client, GUAC_LOG_DEBUG,
-                "Error reading \"connect\"");
-
-        guac_parser_free(parser);
-        return 1;
-    }
-
-    /* Acknowledge connection availability */
-    guac_protocol_send_ready(socket, client->connection_id);
-    guac_socket_flush(socket);
-
-    /* Attempt join */
-    if (guac_client_add_user(client, user, parser->argc, parser->argv))
-        guac_client_log(client, GUAC_LOG_ERROR, "User \"%s\" could NOT "
-                "join connection \"%s\"", user->user_id, client->connection_id);
-
-    /* Begin user connection if join successful */
-    else {
-
-        guac_client_log(client, GUAC_LOG_INFO, "User \"%s\" joined connection "
-                "\"%s\" (%i users now present)", user->user_id,
-                client->connection_id, client->connected_users);
-
-        /* Handle user I/O, wait for connection to terminate */
-        guacd_user_start(parser, user, usec_timeout);
-
-        /* Remove/free user */
-        guac_client_remove_user(client, user);
-        guac_client_log(client, GUAC_LOG_INFO, "User \"%s\" disconnected (%i "
-                "users remain)", user->user_id, client->connected_users);
-
-    }
-
-    /* Free mimetype lists */
-    guacd_free_mimetypes(audio_mimetypes);
-    guacd_free_mimetypes(video_mimetypes);
-    guacd_free_mimetypes(image_mimetypes);
-
-    guac_parser_free(parser);
-
-    /* Successful disconnect */
-    return 0;
-
-}
-



[10/13] incubator-guacamole-server git commit: GUACAMOLE-337: Separate definition of guacd read timeout from libguacd.

Posted by jm...@apache.org.
GUACAMOLE-337: Separate definition of guacd read timeout from libguacd.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/5b748a4b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/5b748a4b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/5b748a4b

Branch: refs/heads/master
Commit: 5b748a4b4267afe9d6ca38467abcc03a2df7acc9
Parents: 06a5043
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Jul 1 15:24:20 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jul 1 18:50:03 2017 -0700

----------------------------------------------------------------------
 src/guacd/proc-map.h         |  6 ++++++
 src/guacd/proc.c             |  2 +-
 src/guacd/proc.h             | 13 +++++++++++++
 src/libguacd/libguacd/user.h | 25 +++++--------------------
 src/libguacd/user.c          | 37 ++++++++++++++++++++++++++-----------
 5 files changed, 51 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/5b748a4b/src/guacd/proc-map.h
----------------------------------------------------------------------
diff --git a/src/guacd/proc-map.h b/src/guacd/proc-map.h
index 7313244..5d8ce97 100644
--- a/src/guacd/proc-map.h
+++ b/src/guacd/proc-map.h
@@ -29,6 +29,12 @@
 #include <guacamole/client.h>
 
 /**
+ * The maximum number of concurrent connections to a single instance
+ * of guacd.
+ */
+#define GUACD_CLIENT_MAX_CONNECTIONS 65536
+
+/**
  * The number of hash buckets in each process map.
  */
 #define GUACD_PROC_MAP_BUCKETS GUACD_CLIENT_MAX_CONNECTIONS*2

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/5b748a4b/src/guacd/proc.c
----------------------------------------------------------------------
diff --git a/src/guacd/proc.c b/src/guacd/proc.c
index 74ba146..e5e9586 100644
--- a/src/guacd/proc.c
+++ b/src/guacd/proc.c
@@ -92,7 +92,7 @@ static void* guacd_user_thread(void* data) {
     user->owner  = params->owner;
 
     /* Handle user connection from handshake until disconnect/completion */
-    guacd_handle_user(user);
+    guacd_handle_user(user, GUACD_USEC_TIMEOUT);
 
     /* Stop client and prevent future users if all users are disconnected */
     if (client->connected_users == 0) {

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/5b748a4b/src/guacd/proc.h
----------------------------------------------------------------------
diff --git a/src/guacd/proc.h b/src/guacd/proc.h
index 23eaa31..13bd9f8 100644
--- a/src/guacd/proc.h
+++ b/src/guacd/proc.h
@@ -28,6 +28,19 @@
 #include <unistd.h>
 
 /**
+ * The number of milliseconds to wait for messages in any phase before
+ * timing out and closing the connection with an error.
+ */
+#define GUACD_TIMEOUT 15000
+
+/**
+ * The number of microseconds to wait for messages in any phase before
+ * timing out and closing the conncetion with an error. This is always
+ * equal to GUACD_TIMEOUT * 1000.
+ */
+#define GUACD_USEC_TIMEOUT (GUACD_TIMEOUT*1000)
+
+/**
  * Process information of the internal remote desktop client.
  */
 typedef struct guacd_proc {

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/5b748a4b/src/libguacd/libguacd/user.h
----------------------------------------------------------------------
diff --git a/src/libguacd/libguacd/user.h b/src/libguacd/libguacd/user.h
index 805cef5..4404a6c 100644
--- a/src/libguacd/libguacd/user.h
+++ b/src/libguacd/libguacd/user.h
@@ -26,25 +26,6 @@
 #include <guacamole/user.h>
 
 /**
- * The number of milliseconds to wait for messages in any phase before
- * timing out and closing the connection with an error.
- */
-#define GUACD_TIMEOUT      15000
-
-/**
- * The number of microseconds to wait for messages in any phase before
- * timing out and closing the conncetion with an error. This is always
- * equal to GUACD_TIMEOUT * 1000.
- */
-#define GUACD_USEC_TIMEOUT (GUACD_TIMEOUT*1000)
-
-/**
- * The maximum number of concurrent connections to a single instance
- * of guacd.
- */
-#define GUACD_CLIENT_MAX_CONNECTIONS 65536
-
-/**
  * Handles the initial handshake of a user and all subsequent I/O. This
  * function blocks until the user disconnects.
  *
@@ -52,12 +33,16 @@
  *     The user whose handshake and entire Guacamole protocol exchange should
  *     be handled.
  *
+ * @param usec_timeout
+ *     The number of microseconds to wait for instructions from the given
+ *     user before closing the connection with an error.
+ *
  * @return
  *     Zero if the user's Guacamole connection was successfully handled and
  *     the user has disconnected, or non-zero if an error prevented the user's
  *     connection from being handled properly.
  */
-int guacd_handle_user(guac_user* user);
+int guacd_handle_user(guac_user* user, int usec_timeout);
 
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/5b748a4b/src/libguacd/user.c
----------------------------------------------------------------------
diff --git a/src/libguacd/user.c b/src/libguacd/user.c
index a0c1759..04f0f49 100644
--- a/src/libguacd/user.c
+++ b/src/libguacd/user.c
@@ -48,6 +48,12 @@ typedef struct guacd_user_input_thread_params {
      */
     guac_user* user;
 
+    /**
+     * The number of microseconds to wait for instructions from a connected
+     * user before closing the connection with an error.
+     */
+    int usec_timeout;
+
 } guacd_user_input_thread_params;
 
 /**
@@ -122,7 +128,10 @@ static void guacd_free_mimetypes(char** mimetypes) {
  */
 static void* guacd_user_input_thread(void* data) {
 
-    guacd_user_input_thread_params* params = (guacd_user_input_thread_params*) data;
+    guacd_user_input_thread_params* params =
+        (guacd_user_input_thread_params*) data;
+
+    int usec_timeout = params->usec_timeout;
     guac_user* user = params->user;
     guac_parser* parser = params->parser;
     guac_client* client = user->client;
@@ -132,7 +141,7 @@ static void* guacd_user_input_thread(void* data) {
     while (client->state == GUAC_CLIENT_RUNNING && user->active) {
 
         /* Read instruction, stop on error */
-        if (guac_parser_read(parser, socket, GUACD_USEC_TIMEOUT)) {
+        if (guac_parser_read(parser, socket, usec_timeout)) {
 
             if (guac_error == GUAC_STATUS_TIMEOUT)
                 guac_user_abort(user, GUAC_PROTOCOL_STATUS_CLIENT_TIMEOUT, "User is not responding.");
@@ -183,15 +192,21 @@ static void* guacd_user_input_thread(void* data) {
  * @param user
  *     The user whose associated I/O transfer threads should be started.
  *
+ * @param usec_timeout
+ *     The number of microseconds to wait for instructions from the given
+ *     user before closing the connection with an error.
+ *
  * @return
  *     Zero if the I/O threads started successfully and user has disconnected,
  *     or non-zero if the I/O threads could not be started.
  */
-static int guacd_user_start(guac_parser* parser, guac_user* user) {
+static int guacd_user_start(guac_parser* parser, guac_user* user,
+        int usec_timeout) {
 
     guacd_user_input_thread_params params = {
         .parser = parser,
-        .user = user
+        .user = user,
+        .usec_timeout = usec_timeout
     };
 
     pthread_t input_thread;
@@ -214,7 +229,7 @@ static int guacd_user_start(guac_parser* parser, guac_user* user) {
 
 }
 
-int guacd_handle_user(guac_user* user) {
+int guacd_handle_user(guac_user* user, int usec_timeout) {
 
     guac_socket* socket = user->socket;
     guac_client* client = user->client;
@@ -234,7 +249,7 @@ int guacd_handle_user(guac_user* user) {
     guac_parser* parser = guac_parser_alloc();
 
     /* Get optimal screen size */
-    if (guac_parser_expect(parser, socket, GUACD_USEC_TIMEOUT, "size")) {
+    if (guac_parser_expect(parser, socket, usec_timeout, "size")) {
 
         /* Log error */
         guacd_client_log_handshake_failure(client);
@@ -266,7 +281,7 @@ int guacd_handle_user(guac_user* user) {
         user->info.optimal_resolution = 96;
 
     /* Get supported audio formats */
-    if (guac_parser_expect(parser, socket, GUACD_USEC_TIMEOUT, "audio")) {
+    if (guac_parser_expect(parser, socket, usec_timeout, "audio")) {
 
         /* Log error */
         guacd_client_log_handshake_failure(client);
@@ -282,7 +297,7 @@ int guacd_handle_user(guac_user* user) {
     user->info.audio_mimetypes = (const char**) audio_mimetypes;
 
     /* Get supported video formats */
-    if (guac_parser_expect(parser, socket, GUACD_USEC_TIMEOUT, "video")) {
+    if (guac_parser_expect(parser, socket, usec_timeout, "video")) {
 
         /* Log error */
         guacd_client_log_handshake_failure(client);
@@ -298,7 +313,7 @@ int guacd_handle_user(guac_user* user) {
     user->info.video_mimetypes = (const char**) video_mimetypes;
 
     /* Get supported image formats */
-    if (guac_parser_expect(parser, socket, GUACD_USEC_TIMEOUT, "image")) {
+    if (guac_parser_expect(parser, socket, usec_timeout, "image")) {
 
         /* Log error */
         guacd_client_log_handshake_failure(client);
@@ -314,7 +329,7 @@ int guacd_handle_user(guac_user* user) {
     user->info.image_mimetypes = (const char**) image_mimetypes;
 
     /* Get args from connect instruction */
-    if (guac_parser_expect(parser, socket, GUACD_USEC_TIMEOUT, "connect")) {
+    if (guac_parser_expect(parser, socket, usec_timeout, "connect")) {
 
         /* Log error */
         guacd_client_log_handshake_failure(client);
@@ -342,7 +357,7 @@ int guacd_handle_user(guac_user* user) {
                 client->connection_id, client->connected_users);
 
         /* Handle user I/O, wait for connection to terminate */
-        guacd_user_start(parser, user);
+        guacd_user_start(parser, user, usec_timeout);
 
         /* Remove/free user */
         guac_client_remove_user(client, user);


[08/13] incubator-guacamole-server git commit: GUACAMOLE-337: Include only *-types.h headers when only types are needed.

Posted by jm...@apache.org.
GUACAMOLE-337: Include only *-types.h headers when only types are needed.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/06a50434
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/06a50434
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/06a50434

Branch: refs/heads/master
Commit: 06a5043442ee71a7e289169967aa6526bf202d70
Parents: f311c23
Author: Michael Jumper <mj...@apache.org>
Authored: Mon Jun 12 14:36:20 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jul 1 18:50:03 2017 -0700

----------------------------------------------------------------------
 src/libguac/guacamole/socket-ssl.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/06a50434/src/libguac/guacamole/socket-ssl.h
----------------------------------------------------------------------
diff --git a/src/libguac/guacamole/socket-ssl.h b/src/libguac/guacamole/socket-ssl.h
index 715db5b..c7a14df 100644
--- a/src/libguac/guacamole/socket-ssl.h
+++ b/src/libguac/guacamole/socket-ssl.h
@@ -21,7 +21,8 @@
 #ifndef __GUACD_SOCKET_SSL_H
 #define __GUACD_SOCKET_SSL_H
 
-#include <guacamole/socket.h>
+#include "socket-types.h"
+
 #include <openssl/ssl.h>
 
 /**


[07/13] incubator-guacamole-server git commit: GUACAMOLE-337: Move SSL socket into libguac.

Posted by jm...@apache.org.
GUACAMOLE-337: Move SSL socket into libguac.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/f311c23f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/f311c23f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/f311c23f

Branch: refs/heads/master
Commit: f311c23ffa4f8a015ddfe55866a27204d389075d
Parents: 78dbf64
Author: Michael Jumper <mj...@apache.org>
Authored: Mon Jun 12 14:06:47 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jul 1 18:50:03 2017 -0700

----------------------------------------------------------------------
 src/guacd/connection.c             |   2 +-
 src/libguac/Makefile.am            |   6 ++
 src/libguac/guacamole/socket-ssl.h |  69 ++++++++++++++
 src/libguac/socket-ssl.c           | 160 ++++++++++++++++++++++++++++++++
 src/libguacd/Makefile.am           |   9 +-
 src/libguacd/libguacd/socket-ssl.h |  69 --------------
 src/libguacd/socket-ssl.c          | 160 --------------------------------
 7 files changed, 237 insertions(+), 238 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f311c23f/src/guacd/connection.c
----------------------------------------------------------------------
diff --git a/src/guacd/connection.c b/src/guacd/connection.c
index 87efc5a..6c517bf 100644
--- a/src/guacd/connection.c
+++ b/src/guacd/connection.c
@@ -36,7 +36,7 @@
 
 #ifdef ENABLE_SSL
 #include <openssl/ssl.h>
-#include "libguacd/socket-ssl.h"
+#include <guacamole/socket-ssl.h>
 #endif
 
 #include <errno.h>

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f311c23f/src/libguac/Makefile.am
----------------------------------------------------------------------
diff --git a/src/libguac/Makefile.am b/src/libguac/Makefile.am
index 4590e9f..0bfa409 100644
--- a/src/libguac/Makefile.am
+++ b/src/libguac/Makefile.am
@@ -99,6 +99,11 @@ libguac_la_SOURCES += encode-webp.c
 noinst_HEADERS += encode-webp.h
 endif
 
+# SSL support
+if ENABLE_SSL
+libguac_la_SOURCES += socket-ssl.c
+libguacinc_HEADERS += guacamole/socket-ssl.h
+endif
 
 libguac_la_CFLAGS = \
     -Werror -Wall -pedantic -Iguacamole
@@ -109,6 +114,7 @@ libguac_la_LDFLAGS =     \
     @JPEG_LIBS@          \
     @PNG_LIBS@           \
     @PTHREAD_LIBS@       \
+    @SSL_LIBS@           \
     @UUID_LIBS@          \
     @VORBIS_LIBS@        \
     @WEBP_LIBS@

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f311c23f/src/libguac/guacamole/socket-ssl.h
----------------------------------------------------------------------
diff --git a/src/libguac/guacamole/socket-ssl.h b/src/libguac/guacamole/socket-ssl.h
new file mode 100644
index 0000000..715db5b
--- /dev/null
+++ b/src/libguac/guacamole/socket-ssl.h
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+#ifndef __GUACD_SOCKET_SSL_H
+#define __GUACD_SOCKET_SSL_H
+
+#include <guacamole/socket.h>
+#include <openssl/ssl.h>
+
+/**
+ * SSL socket-specific data.
+ */
+typedef struct guac_socket_ssl_data {
+
+    /**
+     * The file descriptor that SSL communication will take place
+     * over.
+     */
+    int fd;
+
+    /**
+     * The current SSL context.
+     */
+    SSL_CTX* context;
+
+    /**
+     * The SSL connection, created automatically via
+     * guac_socket_open_secure().
+     */
+    SSL* ssl;
+
+} guac_socket_ssl_data;
+
+/**
+ * Creates a new guac_socket which will use SSL for all communication. Freeing
+ * this guac_socket will automatically close the associated file descriptor.
+ *
+ * @param context
+ *     The SSL_CTX structure describing the desired SSL configuration.
+ *
+ * @param fd
+ *     The file descriptor to use for the SSL connection underlying the
+ *     created guac_socket.
+ *
+ * @return
+ *     A newly-allocated guac_socket which will transparently use SSL for
+ *     all communication.
+ */
+guac_socket* guac_socket_open_secure(SSL_CTX* context, int fd);
+
+#endif
+

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f311c23f/src/libguac/socket-ssl.c
----------------------------------------------------------------------
diff --git a/src/libguac/socket-ssl.c b/src/libguac/socket-ssl.c
new file mode 100644
index 0000000..f8f3f87
--- /dev/null
+++ b/src/libguac/socket-ssl.c
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "config.h"
+
+#include "error.h"
+#include "socket-ssl.h"
+#include "socket.h"
+
+#include <poll.h>
+#include <stdlib.h>
+
+#include <openssl/ssl.h>
+
+static ssize_t __guac_socket_ssl_read_handler(guac_socket* socket,
+        void* buf, size_t count) {
+
+    /* Read from socket */
+    guac_socket_ssl_data* data = (guac_socket_ssl_data*) socket->data;
+    int retval;
+
+    retval = SSL_read(data->ssl, buf, count);
+
+    /* Record errors in guac_error */
+    if (retval <= 0) {
+        guac_error = GUAC_STATUS_SEE_ERRNO;
+        guac_error_message = "Error reading data from secure socket";
+    }
+
+    return retval;
+
+}
+
+static ssize_t __guac_socket_ssl_write_handler(guac_socket* socket,
+        const void* buf, size_t count) {
+
+    /* Write data to socket */
+    guac_socket_ssl_data* data = (guac_socket_ssl_data*) socket->data;
+    int retval;
+
+    retval = SSL_write(data->ssl, buf, count);
+
+    /* Record errors in guac_error */
+    if (retval <= 0) {
+        guac_error = GUAC_STATUS_SEE_ERRNO;
+        guac_error_message = "Error writing data to secure socket";
+    }
+
+    return retval;
+
+}
+
+static int __guac_socket_ssl_select_handler(guac_socket* socket, int usec_timeout) {
+
+    guac_socket_ssl_data* data = (guac_socket_ssl_data*) socket->data;
+
+    int retval;
+
+    /* Initialize with single underlying file descriptor */
+    struct pollfd fds[1] = {{
+        .fd      = data->fd,
+        .events  = POLLIN,
+        .revents = 0,
+    }};
+
+    /* No timeout if usec_timeout is negative */
+    if (usec_timeout < 0)
+        retval = poll(fds, 1, -1);
+
+    /* Handle timeout if specified, rounding up to poll()'s granularity */
+    else
+        retval = poll(fds, 1, (usec_timeout + 999) / 1000);
+
+    /* Properly set guac_error */
+    if (retval <  0) {
+        guac_error = GUAC_STATUS_SEE_ERRNO;
+        guac_error_message = "Error while waiting for data on secure socket";
+    }
+
+    else if (retval == 0) {
+        guac_error = GUAC_STATUS_TIMEOUT;
+        guac_error_message = "Timeout while waiting for data on secure socket";
+    }
+
+    return retval;
+
+}
+
+static int __guac_socket_ssl_free_handler(guac_socket* socket) {
+
+    /* Shutdown SSL */
+    guac_socket_ssl_data* data = (guac_socket_ssl_data*) socket->data;
+    SSL_shutdown(data->ssl);
+    SSL_free(data->ssl);
+
+    /* Close file descriptor */
+    close(data->fd);
+
+    free(data);
+    return 0;
+}
+
+guac_socket* guac_socket_open_secure(SSL_CTX* context, int fd) {
+
+    /* Create new SSL structure */
+    SSL* ssl = SSL_new(context);
+    if (ssl == NULL)
+        return NULL;
+
+    /* Allocate socket and associated data */
+    guac_socket* socket = guac_socket_alloc();
+    guac_socket_ssl_data* data = malloc(sizeof(guac_socket_ssl_data));
+
+    /* Init SSL */
+    data->context = context;
+    data->ssl = ssl;
+    SSL_set_fd(data->ssl, fd);
+
+    /* Accept SSL connection, handle errors */
+    if (SSL_accept(ssl) <= 0) {
+
+        guac_error = GUAC_STATUS_INTERNAL_ERROR;
+        guac_error_message = "SSL accept failed";
+
+        free(data);
+        guac_socket_free(socket);
+        SSL_free(ssl);
+        return NULL;
+    }
+
+    /* Store file descriptor as socket data */
+    data->fd = fd;
+    socket->data = data;
+
+    /* Set read/write handlers */
+    socket->read_handler   = __guac_socket_ssl_read_handler;
+    socket->write_handler  = __guac_socket_ssl_write_handler;
+    socket->select_handler = __guac_socket_ssl_select_handler;
+    socket->free_handler   = __guac_socket_ssl_free_handler;
+
+    return socket;
+
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f311c23f/src/libguacd/Makefile.am
----------------------------------------------------------------------
diff --git a/src/libguacd/Makefile.am b/src/libguacd/Makefile.am
index 35eeaf9..c0373f1 100644
--- a/src/libguacd/Makefile.am
+++ b/src/libguacd/Makefile.am
@@ -43,12 +43,5 @@ libguacd_la_LIBADD = \
 libguacd_la_LDFLAGS =    \
     -version-info 0:0:0  \
     -no-undefined        \
-    @PTHREAD_LIBS@       \
-    @SSL_LIBS@
-
-# SSL support
-if ENABLE_SSL
-libguacdinc_HEADERS += libguacd/socket-ssl.h
-libguacd_la_SOURCES += socket-ssl.c
-endif
+    @PTHREAD_LIBS@
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f311c23f/src/libguacd/libguacd/socket-ssl.h
----------------------------------------------------------------------
diff --git a/src/libguacd/libguacd/socket-ssl.h b/src/libguacd/libguacd/socket-ssl.h
deleted file mode 100644
index 715db5b..0000000
--- a/src/libguacd/libguacd/socket-ssl.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-#ifndef __GUACD_SOCKET_SSL_H
-#define __GUACD_SOCKET_SSL_H
-
-#include <guacamole/socket.h>
-#include <openssl/ssl.h>
-
-/**
- * SSL socket-specific data.
- */
-typedef struct guac_socket_ssl_data {
-
-    /**
-     * The file descriptor that SSL communication will take place
-     * over.
-     */
-    int fd;
-
-    /**
-     * The current SSL context.
-     */
-    SSL_CTX* context;
-
-    /**
-     * The SSL connection, created automatically via
-     * guac_socket_open_secure().
-     */
-    SSL* ssl;
-
-} guac_socket_ssl_data;
-
-/**
- * Creates a new guac_socket which will use SSL for all communication. Freeing
- * this guac_socket will automatically close the associated file descriptor.
- *
- * @param context
- *     The SSL_CTX structure describing the desired SSL configuration.
- *
- * @param fd
- *     The file descriptor to use for the SSL connection underlying the
- *     created guac_socket.
- *
- * @return
- *     A newly-allocated guac_socket which will transparently use SSL for
- *     all communication.
- */
-guac_socket* guac_socket_open_secure(SSL_CTX* context, int fd);
-
-#endif
-

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f311c23f/src/libguacd/socket-ssl.c
----------------------------------------------------------------------
diff --git a/src/libguacd/socket-ssl.c b/src/libguacd/socket-ssl.c
deleted file mode 100644
index cfd2f66..0000000
--- a/src/libguacd/socket-ssl.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include "config.h"
-
-#include "libguacd/socket-ssl.h"
-
-#include <poll.h>
-#include <stdlib.h>
-
-#include <guacamole/error.h>
-#include <guacamole/socket.h>
-#include <openssl/ssl.h>
-
-static ssize_t __guac_socket_ssl_read_handler(guac_socket* socket,
-        void* buf, size_t count) {
-
-    /* Read from socket */
-    guac_socket_ssl_data* data = (guac_socket_ssl_data*) socket->data;
-    int retval;
-
-    retval = SSL_read(data->ssl, buf, count);
-
-    /* Record errors in guac_error */
-    if (retval <= 0) {
-        guac_error = GUAC_STATUS_SEE_ERRNO;
-        guac_error_message = "Error reading data from secure socket";
-    }
-
-    return retval;
-
-}
-
-static ssize_t __guac_socket_ssl_write_handler(guac_socket* socket,
-        const void* buf, size_t count) {
-
-    /* Write data to socket */
-    guac_socket_ssl_data* data = (guac_socket_ssl_data*) socket->data;
-    int retval;
-
-    retval = SSL_write(data->ssl, buf, count);
-
-    /* Record errors in guac_error */
-    if (retval <= 0) {
-        guac_error = GUAC_STATUS_SEE_ERRNO;
-        guac_error_message = "Error writing data to secure socket";
-    }
-
-    return retval;
-
-}
-
-static int __guac_socket_ssl_select_handler(guac_socket* socket, int usec_timeout) {
-
-    guac_socket_ssl_data* data = (guac_socket_ssl_data*) socket->data;
-
-    int retval;
-
-    /* Initialize with single underlying file descriptor */
-    struct pollfd fds[1] = {{
-        .fd      = data->fd,
-        .events  = POLLIN,
-        .revents = 0,
-    }};
-
-    /* No timeout if usec_timeout is negative */
-    if (usec_timeout < 0)
-        retval = poll(fds, 1, -1);
-
-    /* Handle timeout if specified, rounding up to poll()'s granularity */
-    else
-        retval = poll(fds, 1, (usec_timeout + 999) / 1000);
-
-    /* Properly set guac_error */
-    if (retval <  0) {
-        guac_error = GUAC_STATUS_SEE_ERRNO;
-        guac_error_message = "Error while waiting for data on secure socket";
-    }
-
-    if (retval == 0) {
-        guac_error = GUAC_STATUS_TIMEOUT;
-        guac_error_message = "Timeout while waiting for data on secure socket";
-    }
-
-    return retval;
-
-}
-
-static int __guac_socket_ssl_free_handler(guac_socket* socket) {
-
-    /* Shutdown SSL */
-    guac_socket_ssl_data* data = (guac_socket_ssl_data*) socket->data;
-    SSL_shutdown(data->ssl);
-    SSL_free(data->ssl);
-
-    /* Close file descriptor */
-    close(data->fd);
-
-    free(data);
-    return 0;
-}
-
-guac_socket* guac_socket_open_secure(SSL_CTX* context, int fd) {
-
-    /* Create new SSL structure */
-    SSL* ssl = SSL_new(context);
-    if (ssl == NULL)
-        return NULL;
-
-    /* Allocate socket and associated data */
-    guac_socket* socket = guac_socket_alloc();
-    guac_socket_ssl_data* data = malloc(sizeof(guac_socket_ssl_data));
-
-    /* Init SSL */
-    data->context = context;
-    data->ssl = ssl;
-    SSL_set_fd(data->ssl, fd);
-
-    /* Accept SSL connection, handle errors */
-    if (SSL_accept(ssl) <= 0) {
-
-        guac_error = GUAC_STATUS_INTERNAL_ERROR;
-        guac_error_message = "SSL accept failed";
-
-        free(data);
-        guac_socket_free(socket);
-        SSL_free(ssl);
-        return NULL;
-    }
-
-    /* Store file descriptor as socket data */
-    data->fd = fd;
-    socket->data = data;
-
-    /* Set read/write handlers */
-    socket->read_handler   = __guac_socket_ssl_read_handler;
-    socket->write_handler  = __guac_socket_ssl_write_handler;
-    socket->select_handler = __guac_socket_ssl_select_handler;
-    socket->free_handler   = __guac_socket_ssl_free_handler;
-
-    return socket;
-
-}
-


[02/13] incubator-guacamole-server git commit: GUACAMOLE-337: Remove unnecessary include of syslog.h by libguacd.

Posted by jm...@apache.org.
GUACAMOLE-337: Remove unnecessary include of syslog.h by libguacd.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/69d8d87e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/69d8d87e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/69d8d87e

Branch: refs/heads/master
Commit: 69d8d87ec9a8525957df37ee264558b685ccabc2
Parents: a56a720
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Jun 10 14:14:57 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jul 1 16:05:08 2017 -0700

----------------------------------------------------------------------
 src/libguacd/log.c | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/69d8d87e/src/libguacd/log.c
----------------------------------------------------------------------
diff --git a/src/libguacd/log.c b/src/libguacd/log.c
index e746373..76d4974 100644
--- a/src/libguacd/log.c
+++ b/src/libguacd/log.c
@@ -25,7 +25,6 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include <syslog.h>
 #include <unistd.h>
 
 void guacd_client_log_guac_error(guac_client* client,


[12/13] incubator-guacamole-server git commit: GUACAMOLE-337: Clarify behavior of guac_user_handle_connection().

Posted by jm...@apache.org.
GUACAMOLE-337: Clarify behavior of guac_user_handle_connection().


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/b608d226
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/b608d226
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/b608d226

Branch: refs/heads/master
Commit: b608d2266b35e20dc603dd2abbb7d676fcf50305
Parents: 6014117
Author: Michael Jumper <mj...@apache.org>
Authored: Wed Jul 5 19:54:06 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Wed Jul 5 19:54:06 2017 -0700

----------------------------------------------------------------------
 src/libguac/guacamole/user.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/b608d226/src/libguac/guacamole/user.h
----------------------------------------------------------------------
diff --git a/src/libguac/guacamole/user.h b/src/libguac/guacamole/user.h
index b445f62..f89f807 100644
--- a/src/libguac/guacamole/user.h
+++ b/src/libguac/guacamole/user.h
@@ -493,12 +493,12 @@ guac_user* guac_user_alloc();
 void guac_user_free(guac_user* user);
 
 /**
- * Handles the portion of a user's Guacamole protocol handshake following the
- * "select" instruction all subsequent I/O, automatically populating the
- * handshake-related properties of the given guac_user and invoking
- * guac_user_handle_instruction() for received instructions after the handshake
- * has completed. This function blocks until the connection/user is aborted or
- * the user disconnects.
+ * Handles all I/O for the portion of a user's Guacamole connection following
+ * the initial "select" instruction, including the rest of the handshake. The
+ * handshake-related properties of the given guac_user are automatically
+ * populated, and guac_user_handle_instruction() is invoked for all
+ * instructions received after the handshake has completed. This function
+ * blocks until the connection/user is aborted or the user disconnects.
  *
  * @param user
  *     The user whose handshake and entire Guacamole protocol exchange should


[03/13] incubator-guacamole-server git commit: GUACAMOLE-337: Install libguacd as a normal library.

Posted by jm...@apache.org.
GUACAMOLE-337: Install libguacd as a normal library.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/7f3b985c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/7f3b985c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/7f3b985c

Branch: refs/heads/master
Commit: 7f3b985cc6597d60507a74e33efd197e1c27c283
Parents: 69d8d87
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Jun 10 19:11:52 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jul 1 16:05:11 2017 -0700

----------------------------------------------------------------------
 src/libguacd/Makefile.am | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/7f3b985c/src/libguacd/Makefile.am
----------------------------------------------------------------------
diff --git a/src/libguacd/Makefile.am b/src/libguacd/Makefile.am
index 82c0888..a8d2a9f 100644
--- a/src/libguacd/Makefile.am
+++ b/src/libguacd/Makefile.am
@@ -19,10 +19,12 @@
 
 AUTOMAKE_OPTIONS = foreign 
 
-noinst_LTLIBRARIES = libguacd.la
+lib_LTLIBRARIES = libguacd.la
 
-noinst_HEADERS =    \
-    libguacd/log.h  \
+libguacdincdir = $(includedir)/libguacd
+
+libguacdinc_HEADERS =    \
+    libguacd/log.h       \
     libguacd/user.h
 
 libguacd_la_SOURCES = \
@@ -42,7 +44,7 @@ libguacd_la_LDFLAGS = \
 
 # SSL support
 if ENABLE_SSL
-noinst_HEADERS      += libguacd/socket-ssl.h
+libguacdinc_HEADERS += libguacd/socket-ssl.h
 libguacd_la_SOURCES += socket-ssl.c
 endif
 


[04/13] incubator-guacamole-server git commit: GUACAMOLE-337: Limit public libguacd API to simply user handshake handling and SSL/TLS sockets.

Posted by jm...@apache.org.
GUACAMOLE-337: Limit public libguacd API to simply user handshake handling and SSL/TLS sockets.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/6c484c1e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/6c484c1e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/6c484c1e

Branch: refs/heads/master
Commit: 6c484c1efdcf525e97d4b7167123cbbb4e7471f6
Parents: 7f3b985
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Jun 10 19:16:22 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jul 1 16:05:12 2017 -0700

----------------------------------------------------------------------
 src/libguacd/Makefile.am     |  6 +++--
 src/libguacd/libguacd/log.h  | 42 --------------------------------
 src/libguacd/libguacd/user.h | 48 -------------------------------------
 src/libguacd/log.c           |  2 +-
 src/libguacd/log.h           | 42 ++++++++++++++++++++++++++++++++
 src/libguacd/user.c          | 50 ++++++++++++++++++++++++++++++++++++---
 6 files changed, 94 insertions(+), 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/6c484c1e/src/libguacd/Makefile.am
----------------------------------------------------------------------
diff --git a/src/libguacd/Makefile.am b/src/libguacd/Makefile.am
index a8d2a9f..6018b97 100644
--- a/src/libguacd/Makefile.am
+++ b/src/libguacd/Makefile.am
@@ -23,10 +23,12 @@ lib_LTLIBRARIES = libguacd.la
 
 libguacdincdir = $(includedir)/libguacd
 
-libguacdinc_HEADERS =    \
-    libguacd/log.h       \
+libguacdinc_HEADERS = \
     libguacd/user.h
 
+noinst_HEADERS = \
+    log.h
+
 libguacd_la_SOURCES = \
     log.c             \
     user.c

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/6c484c1e/src/libguacd/libguacd/log.h
----------------------------------------------------------------------
diff --git a/src/libguacd/libguacd/log.h b/src/libguacd/libguacd/log.h
deleted file mode 100644
index 76509e3..0000000
--- a/src/libguacd/libguacd/log.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef LIBGUACD_LOG_H
-#define LIBGUACD_LOG_H
-
-#include "config.h"
-
-#include <guacamole/client.h>
-
-/**
- * Prints an error message using the logging facilities of the given client,
- * automatically including any information present in guac_error. This function
- * accepts parameters identically to printf.
- */
-void guacd_client_log_guac_error(guac_client* client,
-        guac_client_log_level level, const char* message);
-
-/**
- * Logs a reasonable explanatory message regarding handshake failure based on
- * the current value of guac_error.
- */
-void guacd_client_log_handshake_failure(guac_client* client);
-
-#endif
-

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/6c484c1e/src/libguacd/libguacd/user.h
----------------------------------------------------------------------
diff --git a/src/libguacd/libguacd/user.h b/src/libguacd/libguacd/user.h
index cb2a8b3..8c1db68 100644
--- a/src/libguacd/libguacd/user.h
+++ b/src/libguacd/libguacd/user.h
@@ -47,40 +47,6 @@
 #define GUACD_CLIENT_MAX_CONNECTIONS 65536
 
 /**
- * Parameters required by the user input thread.
- */
-typedef struct guacd_user_input_thread_params {
-
-    /**
-     * The parser which will be used throughout the user's session.
-     */
-    guac_parser* parser;
-
-    /**
-     * A reference to the connected user.
-     */
-    guac_user* user;
-
-} guacd_user_input_thread_params;
-
-/**
- * Starts the input/output threads of a new user. This function will block
- * until the user disconnects. If an error prevents the input/output threads
- * from starting, guac_user_stop() will be invoked on the given user.
- *
- * @param parser
- *     The guac_parser to use to handle all input from the given user.
- *
- * @param user
- *     The user whose associated I/O transfer threads should be started.
- *
- * @return
- *     Zero if the I/O threads started successfully and user has disconnected,
- *     or non-zero if the I/O threads could not be started.
- */
-int guacd_user_start(guac_parser* parser, guac_user* user);
-
-/**
  * Handles the initial handshake of a user and all subsequent I/O. This
  * function blocks until the user disconnects.
  *
@@ -95,19 +61,5 @@ int guacd_user_start(guac_parser* parser, guac_user* user);
  */
 int guacd_handle_user(guac_user* user);
 
-/**
- * The thread which handles all user input, calling event handlers for received
- * instructions.
- *
- * @param data
- *     A pointer to a guacd_user_input_thread_params structure describing the
- *     user whose input is being handled and the guac_parser with which to
- *     handle it.
- *
- * @return
- *     Always NULL.
- */
-void* guacd_user_input_thread(void* data);
-
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/6c484c1e/src/libguacd/log.c
----------------------------------------------------------------------
diff --git a/src/libguacd/log.c b/src/libguacd/log.c
index 76d4974..180cc97 100644
--- a/src/libguacd/log.c
+++ b/src/libguacd/log.c
@@ -18,7 +18,7 @@
  */
 
 #include "config.h"
-#include "libguacd/log.h"
+#include "log.h"
 
 #include <guacamole/client.h>
 #include <guacamole/error.h>

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/6c484c1e/src/libguacd/log.h
----------------------------------------------------------------------
diff --git a/src/libguacd/log.h b/src/libguacd/log.h
new file mode 100644
index 0000000..76509e3
--- /dev/null
+++ b/src/libguacd/log.h
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef LIBGUACD_LOG_H
+#define LIBGUACD_LOG_H
+
+#include "config.h"
+
+#include <guacamole/client.h>
+
+/**
+ * Prints an error message using the logging facilities of the given client,
+ * automatically including any information present in guac_error. This function
+ * accepts parameters identically to printf.
+ */
+void guacd_client_log_guac_error(guac_client* client,
+        guac_client_log_level level, const char* message);
+
+/**
+ * Logs a reasonable explanatory message regarding handshake failure based on
+ * the current value of guac_error.
+ */
+void guacd_client_log_handshake_failure(guac_client* client);
+
+#endif
+

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/6c484c1e/src/libguacd/user.c
----------------------------------------------------------------------
diff --git a/src/libguacd/user.c b/src/libguacd/user.c
index db39fce..a0c1759 100644
--- a/src/libguacd/user.c
+++ b/src/libguacd/user.c
@@ -19,8 +19,8 @@
 
 #include "config.h"
 
-#include "libguacd/log.h"
 #include "libguacd/user.h"
+#include "log.h"
 
 #include <guacamole/client.h>
 #include <guacamole/error.h>
@@ -34,6 +34,23 @@
 #include <string.h>
 
 /**
+ * Parameters required by the user input thread.
+ */
+typedef struct guacd_user_input_thread_params {
+
+    /**
+     * The parser which will be used throughout the user's session.
+     */
+    guac_parser* parser;
+
+    /**
+     * A reference to the connected user.
+     */
+    guac_user* user;
+
+} guacd_user_input_thread_params;
+
+/**
  * Copies the given array of mimetypes (strings) into a newly-allocated NULL-
  * terminated array of strings. Both the array and the strings within the array
  * are newly-allocated and must be later freed via guacd_free_mimetypes().
@@ -91,7 +108,19 @@ static void guacd_free_mimetypes(char** mimetypes) {
 
 }
 
-void* guacd_user_input_thread(void* data) {
+/**
+ * The thread which handles all user input, calling event handlers for received
+ * instructions.
+ *
+ * @param data
+ *     A pointer to a guacd_user_input_thread_params structure describing the
+ *     user whose input is being handled and the guac_parser with which to
+ *     handle it.
+ *
+ * @return
+ *     Always NULL.
+ */
+static void* guacd_user_input_thread(void* data) {
 
     guacd_user_input_thread_params* params = (guacd_user_input_thread_params*) data;
     guac_user* user = params->user;
@@ -143,7 +172,22 @@ void* guacd_user_input_thread(void* data) {
 
 }
 
-int guacd_user_start(guac_parser* parser, guac_user* user) {
+/**
+ * Starts the input/output threads of a new user. This function will block
+ * until the user disconnects. If an error prevents the input/output threads
+ * from starting, guac_user_stop() will be invoked on the given user.
+ *
+ * @param parser
+ *     The guac_parser to use to handle all input from the given user.
+ *
+ * @param user
+ *     The user whose associated I/O transfer threads should be started.
+ *
+ * @return
+ *     Zero if the I/O threads started successfully and user has disconnected,
+ *     or non-zero if the I/O threads could not be started.
+ */
+static int guacd_user_start(guac_parser* parser, guac_user* user) {
 
     guacd_user_input_thread_params params = {
         .parser = parser,


[13/13] incubator-guacamole-server git commit: GUACAMOLE-337: Merge move of libguacd code into public libguac API.

Posted by jm...@apache.org.
GUACAMOLE-337: Merge move of libguacd code into public libguac API.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/6236eb8f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/6236eb8f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/6236eb8f

Branch: refs/heads/master
Commit: 6236eb8f98ff96c495ae94cb4fe3279c202db465
Parents: 3fdd1e9 b608d22
Author: James Muehlner <ja...@guac-dev.org>
Authored: Wed Jul 5 19:56:06 2017 -0700
Committer: James Muehlner <ja...@guac-dev.org>
Committed: Wed Jul 5 19:56:06 2017 -0700

----------------------------------------------------------------------
 Makefile.am                        |   2 -
 configure.ac                       |   5 -
 src/guacd/Makefile.am              |   2 -
 src/guacd/connection.c             |   3 +-
 src/guacd/daemon.c                 |   1 -
 src/guacd/proc-map.c               |   1 -
 src/guacd/proc-map.h               |   7 +-
 src/guacd/proc.c                   |   3 +-
 src/guacd/proc.h                   |  13 +
 src/libguac/Makefile.am            |   9 +-
 src/libguac/guacamole/socket-ssl.h |  77 ++++++
 src/libguac/guacamole/user.h       |  24 ++
 src/libguac/socket-ssl.c           | 160 ++++++++++++
 src/libguac/user-handshake.c       | 437 ++++++++++++++++++++++++++++++++
 src/libguacd/Makefile.am           |  50 ----
 src/libguacd/libguacd/log.h        |  42 ---
 src/libguacd/libguacd/socket-ssl.h |  71 ------
 src/libguacd/libguacd/user.h       | 113 ---------
 src/libguacd/log.c                 |  72 ------
 src/libguacd/socket-ssl.c          | 160 ------------
 src/libguacd/user.c                | 321 -----------------------
 21 files changed, 727 insertions(+), 846 deletions(-)
----------------------------------------------------------------------



[06/13] incubator-guacamole-server git commit: GUACAMOLE-337: Add missing libtool flags for libguacd.

Posted by jm...@apache.org.
GUACAMOLE-337: Add missing libtool flags for libguacd.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/78dbf644
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/78dbf644
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/78dbf644

Branch: refs/heads/master
Commit: 78dbf64416d6a8fc44ccfceb4bf4f3ba62eea8c3
Parents: 3a46fff
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Jun 10 19:19:43 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jul 1 16:05:17 2017 -0700

----------------------------------------------------------------------
 src/libguacd/Makefile.am | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/78dbf644/src/libguacd/Makefile.am
----------------------------------------------------------------------
diff --git a/src/libguacd/Makefile.am b/src/libguacd/Makefile.am
index 6018b97..35eeaf9 100644
--- a/src/libguacd/Makefile.am
+++ b/src/libguacd/Makefile.am
@@ -40,8 +40,10 @@ libguacd_la_CFLAGS =        \
 libguacd_la_LIBADD = \
     @LIBGUAC_LTLIB@
 
-libguacd_la_LDFLAGS = \
-    @PTHREAD_LIBS@    \
+libguacd_la_LDFLAGS =    \
+    -version-info 0:0:0  \
+    -no-undefined        \
+    @PTHREAD_LIBS@       \
     @SSL_LIBS@
 
 # SSL support