You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by vn...@apache.org on 2018/11/10 15:46:37 UTC

[1/6] guacamole-server git commit: GUACAMOLE-630: Do not entirely reset terminal state when color scheme is changed.

Repository: guacamole-server
Updated Branches:
  refs/heads/master e132c7934 -> d2cb7a9ce


GUACAMOLE-630: Do not entirely reset terminal state when color scheme is changed.


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

Branch: refs/heads/master
Commit: f293c5e9c076d583f2f513a7673928da4395814c
Parents: dcab540
Author: Michael Jumper <mj...@apache.org>
Authored: Mon Sep 24 01:28:30 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Mon Oct 22 23:23:27 2018 -0700

----------------------------------------------------------------------
 src/terminal/terminal.c          | 9 +++++----
 src/terminal/terminal/terminal.h | 5 ++---
 2 files changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/f293c5e9/src/terminal/terminal.c
----------------------------------------------------------------------
diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c
index c12df4b..1984185 100644
--- a/src/terminal/terminal.c
+++ b/src/terminal/terminal.c
@@ -1954,15 +1954,16 @@ void guac_terminal_apply_color_scheme(guac_terminal* terminal,
         display->default_palette);
 
     /* Reinitialize default attributes of buffer and display */
-    terminal->buffer->default_character = *default_char;
+    guac_terminal_display_reset_palette(display);
     display->default_foreground = default_char->attributes.foreground;
     display->default_background = default_char->attributes.background;
 
-    /* Redraw background with new color */
+    /* Redraw terminal text and background */
     guac_terminal_repaint_default_layer(terminal, client->socket);
+    __guac_terminal_redraw_rect(terminal, 0, 0,
+            terminal->term_height - 1,
+            terminal->term_width - 1);
 
-    /* Force reset of terminal state */
-    guac_terminal_reset(terminal);
     guac_terminal_notify(terminal);
 
 }

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/f293c5e9/src/terminal/terminal/terminal.h
----------------------------------------------------------------------
diff --git a/src/terminal/terminal/terminal.h b/src/terminal/terminal/terminal.h
index 6de984b..28085f6 100644
--- a/src/terminal/terminal/terminal.h
+++ b/src/terminal/terminal/terminal.h
@@ -1074,9 +1074,8 @@ int guac_terminal_available_scroll(guac_terminal* term);
 
 /**
  * Immediately applies the given color scheme to the given terminal, overriding
- * the color scheme provided when the terminal was created. Applying the color
- * scheme implicitly clears the display and resets the terminal state. Valid
- * color schemes are those accepted by guac_terminal_parse_color_scheme().
+ * the color scheme provided when the terminal was created. Valid color schemes
+ * are those accepted by guac_terminal_parse_color_scheme().
  *
  * @param terminal
  *     The terminal to apply the color scheme to.


[4/6] guacamole-server git commit: GUACAMOLE-630: Allow color scheme to be changed from webapp via argv streams.

Posted by vn...@apache.org.
GUACAMOLE-630: Allow color scheme to be changed from webapp via argv streams.


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

Branch: refs/heads/master
Commit: 2f16eadb358362d1925da343e530ab73417d4f55
Parents: 6f9f218
Author: Michael Jumper <mj...@apache.org>
Authored: Sun Sep 23 00:24:19 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Mon Oct 22 23:23:27 2018 -0700

----------------------------------------------------------------------
 src/protocols/ssh/Makefile.am    |   2 +
 src/protocols/ssh/argv.c         | 128 ++++++++++++++++++++++++++++++++++
 src/protocols/ssh/argv.h         |  35 ++++++++++
 src/protocols/ssh/user.c         |   4 ++
 src/protocols/telnet/Makefile.am |   2 +
 src/protocols/telnet/argv.c      | 128 ++++++++++++++++++++++++++++++++++
 src/protocols/telnet/argv.h      |  35 ++++++++++
 src/protocols/telnet/user.c      |   4 ++
 src/terminal/display.c           |   4 +-
 src/terminal/terminal.c          |  29 +++++++-
 src/terminal/terminal/display.h  |   4 +-
 src/terminal/terminal/terminal.h |  15 ++++
 12 files changed, 385 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/2f16eadb/src/protocols/ssh/Makefile.am
----------------------------------------------------------------------
diff --git a/src/protocols/ssh/Makefile.am b/src/protocols/ssh/Makefile.am
index d60cf00..7bb1e34 100644
--- a/src/protocols/ssh/Makefile.am
+++ b/src/protocols/ssh/Makefile.am
@@ -29,6 +29,7 @@ ACLOCAL_AMFLAGS = -I m4
 lib_LTLIBRARIES = libguac-client-ssh.la
 
 libguac_client_ssh_la_SOURCES = \
+    argv.c                      \
     client.c                    \
     clipboard.c                 \
     input.c                     \
@@ -40,6 +41,7 @@ libguac_client_ssh_la_SOURCES = \
     user.c
 
 noinst_HEADERS =                \
+    argv.h                      \
     client.h                    \
     clipboard.h                 \
     input.h                     \

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/2f16eadb/src/protocols/ssh/argv.c
----------------------------------------------------------------------
diff --git a/src/protocols/ssh/argv.c b/src/protocols/ssh/argv.c
new file mode 100644
index 0000000..85dca94
--- /dev/null
+++ b/src/protocols/ssh/argv.c
@@ -0,0 +1,128 @@
+/*
+ * 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 "argv.h"
+#include "ssh.h"
+#include "terminal/terminal.h"
+
+#include <guacamole/protocol.h>
+#include <guacamole/socket.h>
+#include <guacamole/user.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+/**
+ * The value or current status of a connection parameter received over an
+ * "argv" stream.
+ */
+typedef struct guac_ssh_argv {
+
+    /**
+     * Buffer space for containing the received argument value.
+     */
+    char buffer[16384];
+
+    /**
+     * The number of bytes received so far.
+     */
+    int length;
+
+} guac_ssh_argv;
+
+/**
+ * Handler for "blob" instructions which appends the data from received blobs
+ * to the end of the in-progress argument value buffer.
+ *
+ * @see guac_user_blob_handler
+ */
+static int guac_ssh_argv_blob_handler(guac_user* user,
+        guac_stream* stream, void* data, int length) {
+
+    guac_ssh_argv* argv = (guac_ssh_argv*) stream->data;
+
+    /* Calculate buffer size remaining, including space for null terminator,
+     * adjusting received length accordingly */
+    int remaining = sizeof(argv->buffer) - argv->length - 1;
+    if (length > remaining)
+        length = remaining;
+
+    /* Append received data to end of buffer */
+    memcpy(argv->buffer + argv->length, data, length);
+    argv->length += length;
+
+    return 0;
+
+}
+
+/**
+ * Handler for "end" instructions which applies the changes specified by the
+ * argument value buffer associated with the stream.
+ *
+ * @see guac_user_end_handler
+ */
+static int guac_ssh_argv_end_handler(guac_user* user,
+        guac_stream* stream) {
+
+    guac_client* client = user->client;
+    guac_ssh_client* telnet_client = (guac_ssh_client*) client->data;
+    guac_terminal* terminal = telnet_client->term;
+
+    /* Append null terminator to value */
+    guac_ssh_argv* argv = (guac_ssh_argv*) stream->data;
+    argv->buffer[argv->length] = '\0';
+
+    /* Update color scheme */
+    guac_terminal_apply_color_scheme(terminal, argv->buffer);
+    free(argv);
+    return 0;
+
+}
+
+int guac_ssh_argv_handler(guac_user* user, guac_stream* stream,
+        char* mimetype, char* name) {
+
+    /* Allow users to update the color scheme */
+    if (strcmp(name, "color-scheme") == 0) {
+
+        guac_ssh_argv* argv = malloc(sizeof(guac_ssh_argv));
+        argv->length = 0;
+
+        /* Prepare stream to receive argument value */
+        stream->blob_handler = guac_ssh_argv_blob_handler;
+        stream->end_handler = guac_ssh_argv_end_handler;
+        stream->data = argv;
+
+        /* Signal stream is ready */
+        guac_protocol_send_ack(user->socket, stream, "Ready for color "
+                "scheme.", GUAC_PROTOCOL_STATUS_SUCCESS);
+        guac_socket_flush(user->socket);
+        return 0;
+
+    }
+
+    /* No other connection parameters may be updated */
+    guac_protocol_send_ack(user->socket, stream, "Not allowed.",
+            GUAC_PROTOCOL_STATUS_CLIENT_FORBIDDEN);
+    guac_socket_flush(user->socket);
+    return 0;
+
+}
+

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/2f16eadb/src/protocols/ssh/argv.h
----------------------------------------------------------------------
diff --git a/src/protocols/ssh/argv.h b/src/protocols/ssh/argv.h
new file mode 100644
index 0000000..27b08cb
--- /dev/null
+++ b/src/protocols/ssh/argv.h
@@ -0,0 +1,35 @@
+/*
+ * 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 GUAC_SSH_ARGV_H
+#define GUAC_SSH_ARGV_H
+
+#include "config.h"
+
+#include <guacamole/user.h>
+
+/**
+ * Handles an incoming stream from a Guacamole "argv" instruction, updating the
+ * given connection parameter if that parameter is allowed to be updated.
+ */
+guac_user_argv_handler guac_ssh_argv_handler;
+
+#endif
+

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/2f16eadb/src/protocols/ssh/user.c
----------------------------------------------------------------------
diff --git a/src/protocols/ssh/user.c b/src/protocols/ssh/user.c
index e4dda40..97ed87c 100644
--- a/src/protocols/ssh/user.c
+++ b/src/protocols/ssh/user.c
@@ -19,6 +19,7 @@
 
 #include "config.h"
 
+#include "argv.h"
 #include "clipboard.h"
 #include "common/display.h"
 #include "input.h"
@@ -87,6 +88,9 @@ int guac_ssh_user_join_handler(guac_user* user, int argc, char** argv) {
         /* STDIN redirection */
         user->pipe_handler = guac_ssh_pipe_handler;
 
+        /* Updates to connection parameters */
+        user->argv_handler = guac_ssh_argv_handler;
+
         /* Display size change events */
         user->size_handler = guac_ssh_user_size_handler;
 

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/2f16eadb/src/protocols/telnet/Makefile.am
----------------------------------------------------------------------
diff --git a/src/protocols/telnet/Makefile.am b/src/protocols/telnet/Makefile.am
index bec0e95..d0264f6 100644
--- a/src/protocols/telnet/Makefile.am
+++ b/src/protocols/telnet/Makefile.am
@@ -29,6 +29,7 @@ ACLOCAL_AMFLAGS = -I m4
 lib_LTLIBRARIES = libguac-client-telnet.la
 
 libguac_client_telnet_la_SOURCES = \
+    argv.c                         \
     client.c                       \
     clipboard.c                    \
     input.c                        \
@@ -38,6 +39,7 @@ libguac_client_telnet_la_SOURCES = \
     user.c
 
 noinst_HEADERS = \
+    argv.h       \
     client.h     \
     clipboard.h  \
     input.h      \

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/2f16eadb/src/protocols/telnet/argv.c
----------------------------------------------------------------------
diff --git a/src/protocols/telnet/argv.c b/src/protocols/telnet/argv.c
new file mode 100644
index 0000000..da405aa
--- /dev/null
+++ b/src/protocols/telnet/argv.c
@@ -0,0 +1,128 @@
+/*
+ * 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 "argv.h"
+#include "telnet.h"
+#include "terminal/terminal.h"
+
+#include <guacamole/protocol.h>
+#include <guacamole/socket.h>
+#include <guacamole/user.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+/**
+ * The value or current status of a connection parameter received over an
+ * "argv" stream.
+ */
+typedef struct guac_telnet_argv {
+
+    /**
+     * Buffer space for containing the received argument value.
+     */
+    char buffer[16384];
+
+    /**
+     * The number of bytes received so far.
+     */
+    int length;
+
+} guac_telnet_argv;
+
+/**
+ * Handler for "blob" instructions which appends the data from received blobs
+ * to the end of the in-progress argument value buffer.
+ *
+ * @see guac_user_blob_handler
+ */
+static int guac_telnet_argv_blob_handler(guac_user* user,
+        guac_stream* stream, void* data, int length) {
+
+    guac_telnet_argv* argv = (guac_telnet_argv*) stream->data;
+
+    /* Calculate buffer size remaining, including space for null terminator,
+     * adjusting received length accordingly */
+    int remaining = sizeof(argv->buffer) - argv->length - 1;
+    if (length > remaining)
+        length = remaining;
+
+    /* Append received data to end of buffer */
+    memcpy(argv->buffer + argv->length, data, length);
+    argv->length += length;
+
+    return 0;
+
+}
+
+/**
+ * Handler for "end" instructions which applies the changes specified by the
+ * argument value buffer associated with the stream.
+ *
+ * @see guac_user_end_handler
+ */
+static int guac_telnet_argv_end_handler(guac_user* user,
+        guac_stream* stream) {
+
+    guac_client* client = user->client;
+    guac_telnet_client* telnet_client = (guac_telnet_client*) client->data;
+    guac_terminal* terminal = telnet_client->term;
+
+    /* Append null terminator to value */
+    guac_telnet_argv* argv = (guac_telnet_argv*) stream->data;
+    argv->buffer[argv->length] = '\0';
+
+    /* Update color scheme */
+    guac_terminal_apply_color_scheme(terminal, argv->buffer);
+    free(argv);
+    return 0;
+
+}
+
+int guac_telnet_argv_handler(guac_user* user, guac_stream* stream,
+        char* mimetype, char* name) {
+
+    /* Allow users to update the color scheme */
+    if (strcmp(name, "color-scheme") == 0) {
+
+        guac_telnet_argv* argv = malloc(sizeof(guac_telnet_argv));
+        argv->length = 0;
+
+        /* Prepare stream to receive argument value */
+        stream->blob_handler = guac_telnet_argv_blob_handler;
+        stream->end_handler = guac_telnet_argv_end_handler;
+        stream->data = argv;
+
+        /* Signal stream is ready */
+        guac_protocol_send_ack(user->socket, stream, "Ready for color "
+                "scheme.", GUAC_PROTOCOL_STATUS_SUCCESS);
+        guac_socket_flush(user->socket);
+        return 0;
+
+    }
+
+    /* No other connection parameters may be updated */
+    guac_protocol_send_ack(user->socket, stream, "Not allowed.",
+            GUAC_PROTOCOL_STATUS_CLIENT_FORBIDDEN);
+    guac_socket_flush(user->socket);
+    return 0;
+
+}
+

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/2f16eadb/src/protocols/telnet/argv.h
----------------------------------------------------------------------
diff --git a/src/protocols/telnet/argv.h b/src/protocols/telnet/argv.h
new file mode 100644
index 0000000..b1567ea
--- /dev/null
+++ b/src/protocols/telnet/argv.h
@@ -0,0 +1,35 @@
+/*
+ * 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 GUAC_TELNET_ARGV_H
+#define GUAC_TELNET_ARGV_H
+
+#include "config.h"
+
+#include <guacamole/user.h>
+
+/**
+ * Handles an incoming stream from a Guacamole "argv" instruction, updating the
+ * given connection parameter if that parameter is allowed to be updated.
+ */
+guac_user_argv_handler guac_telnet_argv_handler;
+
+#endif
+

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/2f16eadb/src/protocols/telnet/user.c
----------------------------------------------------------------------
diff --git a/src/protocols/telnet/user.c b/src/protocols/telnet/user.c
index 2e34f78..44ef9b5 100644
--- a/src/protocols/telnet/user.c
+++ b/src/protocols/telnet/user.c
@@ -19,6 +19,7 @@
 
 #include "config.h"
 
+#include "argv.h"
 #include "clipboard.h"
 #include "input.h"
 #include "pipe.h"
@@ -86,6 +87,9 @@ int guac_telnet_user_join_handler(guac_user* user, int argc, char** argv) {
         /* STDIN redirection */
         user->pipe_handler = guac_telnet_pipe_handler;
 
+        /* Updates to connection parameters */
+        user->argv_handler = guac_telnet_argv_handler;
+
         /* Display size change events */
         user->size_handler = guac_telnet_user_size_handler;
 

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/2f16eadb/src/terminal/display.c
----------------------------------------------------------------------
diff --git a/src/terminal/display.c b/src/terminal/display.c
index c4c7471..480e839 100644
--- a/src/terminal/display.c
+++ b/src/terminal/display.c
@@ -199,7 +199,7 @@ int __guac_terminal_set(guac_terminal_display* display, int row, int col, int co
 guac_terminal_display* guac_terminal_display_alloc(guac_client* client,
         const char* font_name, int font_size, int dpi,
         guac_terminal_color* foreground, guac_terminal_color* background,
-        const guac_terminal_color (*palette)[256]) {
+        guac_terminal_color (*palette)[256]) {
 
     PangoFontMap* font_map;
     PangoFont* font;
@@ -271,7 +271,7 @@ guac_terminal_display* guac_terminal_display_alloc(guac_client* client,
 void guac_terminal_display_free(guac_terminal_display* display) {
 
     /* Free default palette. */
-    free((void*) display->default_palette);
+    free(display->default_palette);
 
     /* Free operations buffers */
     free(display->operations);

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/2f16eadb/src/terminal/terminal.c
----------------------------------------------------------------------
diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c
index a99bfb0..c12df4b 100644
--- a/src/terminal/terminal.c
+++ b/src/terminal/terminal.c
@@ -384,7 +384,7 @@ guac_terminal* guac_terminal_create(guac_client* client,
             font_name, font_size, dpi,
             &default_char.attributes.foreground,
             &default_char.attributes.background,
-            (const guac_terminal_color(*)[256]) default_palette);
+            (guac_terminal_color(*)[256]) default_palette);
 
     /* Fail if display init failed */
     if (term->display == NULL) {
@@ -1940,3 +1940,30 @@ void guac_terminal_dup(guac_terminal* term, guac_user* user,
 
 }
 
+void guac_terminal_apply_color_scheme(guac_terminal* terminal,
+        const char* color_scheme) {
+
+    guac_client* client = terminal->client;
+    guac_terminal_char* default_char = &terminal->default_char;
+    guac_terminal_display* display = terminal->display;
+
+    /* Reinitialize default terminal colors with values from color scheme */
+    guac_terminal_parse_color_scheme(client, color_scheme,
+        &default_char->attributes.foreground,
+        &default_char->attributes.background,
+        display->default_palette);
+
+    /* Reinitialize default attributes of buffer and display */
+    terminal->buffer->default_character = *default_char;
+    display->default_foreground = default_char->attributes.foreground;
+    display->default_background = default_char->attributes.background;
+
+    /* Redraw background with new color */
+    guac_terminal_repaint_default_layer(terminal, client->socket);
+
+    /* Force reset of terminal state */
+    guac_terminal_reset(terminal);
+    guac_terminal_notify(terminal);
+
+}
+

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/2f16eadb/src/terminal/terminal/display.h
----------------------------------------------------------------------
diff --git a/src/terminal/terminal/display.h b/src/terminal/terminal/display.h
index e54003b..b127423 100644
--- a/src/terminal/terminal/display.h
+++ b/src/terminal/terminal/display.h
@@ -142,7 +142,7 @@ typedef struct guac_terminal_display {
      * The default palette. Use GUAC_TERMINAL_INITIAL_PALETTE if null.
      * Must free on destruction if not null.
      */
-    const guac_terminal_color (*default_palette)[256];
+    guac_terminal_color (*default_palette)[256];
 
     /**
      * Default foreground color for all glyphs.
@@ -215,7 +215,7 @@ typedef struct guac_terminal_display {
 guac_terminal_display* guac_terminal_display_alloc(guac_client* client,
         const char* font_name, int font_size, int dpi,
         guac_terminal_color* foreground, guac_terminal_color* background,
-        const guac_terminal_color (*palette)[256]);
+        guac_terminal_color (*palette)[256]);
 
 /**
  * Frees the given display.

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/2f16eadb/src/terminal/terminal/terminal.h
----------------------------------------------------------------------
diff --git a/src/terminal/terminal/terminal.h b/src/terminal/terminal/terminal.h
index aee7742..6de984b 100644
--- a/src/terminal/terminal/terminal.h
+++ b/src/terminal/terminal/terminal.h
@@ -1072,5 +1072,20 @@ int guac_terminal_create_typescript(guac_terminal* term, const char* path,
  */
 int guac_terminal_available_scroll(guac_terminal* term);
 
+/**
+ * Immediately applies the given color scheme to the given terminal, overriding
+ * the color scheme provided when the terminal was created. Applying the color
+ * scheme implicitly clears the display and resets the terminal state. Valid
+ * color schemes are those accepted by guac_terminal_parse_color_scheme().
+ *
+ * @param terminal
+ *     The terminal to apply the color scheme to.
+ *
+ * @param color_scheme
+ *     The color scheme to apply.
+ */
+void guac_terminal_apply_color_scheme(guac_terminal* terminal,
+        const char* color_scheme);
+
 #endif
 


[6/6] guacamole-server git commit: GUACAMOLE-630: Merge allow color scheme of active terminals to be changed.

Posted by vn...@apache.org.
GUACAMOLE-630: Merge allow color scheme of active terminals to be changed.


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

Branch: refs/heads/master
Commit: d2cb7a9ce9b4062d7af125d1b9cfed175c57f19b
Parents: e132c79 0cf2421
Author: Nick Couchman <vn...@apache.org>
Authored: Sat Nov 10 10:45:56 2018 -0500
Committer: Nick Couchman <vn...@apache.org>
Committed: Sat Nov 10 10:45:56 2018 -0500

----------------------------------------------------------------------
 src/protocols/ssh/Makefile.am        |   2 +
 src/protocols/ssh/argv.c             | 128 ++++++++++++++
 src/protocols/ssh/argv.h             |  41 +++++
 src/protocols/ssh/user.c             |   4 +
 src/protocols/telnet/Makefile.am     |   2 +
 src/protocols/telnet/argv.c          | 128 ++++++++++++++
 src/protocols/telnet/argv.h          |  41 +++++
 src/protocols/telnet/user.c          |   4 +
 src/terminal/Makefile.am             |   2 +
 src/terminal/color-scheme.c          | 256 ++++++++++++++++++++++++++++
 src/terminal/display.c               |  37 +++-
 src/terminal/palette.c               |   4 +
 src/terminal/terminal.c              | 273 ++++--------------------------
 src/terminal/terminal/color-scheme.h |  95 +++++++++++
 src/terminal/terminal/display.h      |   4 +-
 src/terminal/terminal/palette.h      |  14 ++
 src/terminal/terminal/terminal.h     |  49 ++----
 17 files changed, 796 insertions(+), 288 deletions(-)
----------------------------------------------------------------------



[5/6] guacamole-server git commit: GUACAMOLE-630: Define maximum "argv" stream length for SSH and telnet with symbolic constants.

Posted by vn...@apache.org.
GUACAMOLE-630: Define maximum "argv" stream length for SSH and telnet with symbolic constants.


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

Branch: refs/heads/master
Commit: 0cf24219d83dd9b9b68e7456400f58087f3815d8
Parents: f293c5e
Author: Michael Jumper <mj...@apache.org>
Authored: Fri Nov 9 20:27:28 2018 -0800
Committer: Michael Jumper <mj...@apache.org>
Committed: Fri Nov 9 20:27:28 2018 -0800

----------------------------------------------------------------------
 src/protocols/ssh/argv.c    | 2 +-
 src/protocols/ssh/argv.h    | 6 ++++++
 src/protocols/telnet/argv.c | 2 +-
 src/protocols/telnet/argv.h | 6 ++++++
 4 files changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/0cf24219/src/protocols/ssh/argv.c
----------------------------------------------------------------------
diff --git a/src/protocols/ssh/argv.c b/src/protocols/ssh/argv.c
index 85dca94..00a2cbb 100644
--- a/src/protocols/ssh/argv.c
+++ b/src/protocols/ssh/argv.c
@@ -38,7 +38,7 @@ typedef struct guac_ssh_argv {
     /**
      * Buffer space for containing the received argument value.
      */
-    char buffer[16384];
+    char buffer[GUAC_SSH_ARGV_MAX_LENGTH];
 
     /**
      * The number of bytes received so far.

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/0cf24219/src/protocols/ssh/argv.h
----------------------------------------------------------------------
diff --git a/src/protocols/ssh/argv.h b/src/protocols/ssh/argv.h
index 27b08cb..88cf8e9 100644
--- a/src/protocols/ssh/argv.h
+++ b/src/protocols/ssh/argv.h
@@ -26,6 +26,12 @@
 #include <guacamole/user.h>
 
 /**
+ * The maximum number of bytes to allow for any argument value received via an
+ * argv stream, including null terminator.
+ */
+#define GUAC_SSH_ARGV_MAX_LENGTH 16384
+
+/**
  * Handles an incoming stream from a Guacamole "argv" instruction, updating the
  * given connection parameter if that parameter is allowed to be updated.
  */

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/0cf24219/src/protocols/telnet/argv.c
----------------------------------------------------------------------
diff --git a/src/protocols/telnet/argv.c b/src/protocols/telnet/argv.c
index da405aa..0735928 100644
--- a/src/protocols/telnet/argv.c
+++ b/src/protocols/telnet/argv.c
@@ -38,7 +38,7 @@ typedef struct guac_telnet_argv {
     /**
      * Buffer space for containing the received argument value.
      */
-    char buffer[16384];
+    char buffer[GUAC_TELNET_ARGV_MAX_LENGTH];
 
     /**
      * The number of bytes received so far.

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/0cf24219/src/protocols/telnet/argv.h
----------------------------------------------------------------------
diff --git a/src/protocols/telnet/argv.h b/src/protocols/telnet/argv.h
index b1567ea..aa13dda 100644
--- a/src/protocols/telnet/argv.h
+++ b/src/protocols/telnet/argv.h
@@ -26,6 +26,12 @@
 #include <guacamole/user.h>
 
 /**
+ * The maximum number of bytes to allow for any argument value received via an
+ * argv stream, including null terminator.
+ */
+#define GUAC_TELNET_ARGV_MAX_LENGTH 16384
+
+/**
  * Handles an incoming stream from a Guacamole "argv" instruction, updating the
  * given connection parameter if that parameter is allowed to be updated.
  */


[3/6] guacamole-server git commit: GUACAMOLE-630: Persist semantics of default foreground/background with dedicated palette pseudo-indexes.

Posted by vn...@apache.org.
GUACAMOLE-630: Persist semantics of default foreground/background with dedicated palette pseudo-indexes.


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

Branch: refs/heads/master
Commit: dcab540839f46aa3dbe919929e4b999c713bee5d
Parents: 2f16ead
Author: Michael Jumper <mj...@apache.org>
Authored: Mon Sep 24 01:25:30 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Mon Oct 22 23:23:27 2018 -0700

----------------------------------------------------------------------
 src/terminal/color-scheme.c     |  5 +++++
 src/terminal/display.c          | 33 +++++++++++++++++++++++++++------
 src/terminal/palette.c          |  4 ++++
 src/terminal/terminal/palette.h | 14 ++++++++++++++
 4 files changed, 50 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/dcab5408/src/terminal/color-scheme.c
----------------------------------------------------------------------
diff --git a/src/terminal/color-scheme.c b/src/terminal/color-scheme.c
index 2799aac..f430019 100644
--- a/src/terminal/color-scheme.c
+++ b/src/terminal/color-scheme.c
@@ -247,5 +247,10 @@ void guac_terminal_parse_color_scheme(guac_client* client,
                 (const guac_terminal_color(*)[256]) palette, color_target))
             return; /* Parsing failed. */
     }
+
+    /* Persist pseudo-index for foreground/background colors */
+    foreground->palette_index = GUAC_TERMINAL_COLOR_FOREGROUND;
+    background->palette_index = GUAC_TERMINAL_COLOR_BACKGROUND;
+
 }
 

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/dcab5408/src/terminal/display.c
----------------------------------------------------------------------
diff --git a/src/terminal/display.c b/src/terminal/display.c
index 480e839..1c803b4 100644
--- a/src/terminal/display.c
+++ b/src/terminal/display.c
@@ -78,7 +78,12 @@ int __guac_terminal_set_colors(guac_terminal_display* display,
     }
 
     display->glyph_foreground = *foreground;
+    guac_terminal_display_lookup_color(display,
+            foreground->palette_index, &display->glyph_foreground);
+
     display->glyph_background = *background;
+    guac_terminal_display_lookup_color(display,
+            background->palette_index, &display->glyph_background);
 
     /* Modify color if half-bright (low intensity) */
     if (attributes->half_bright && !attributes->bold) {
@@ -315,6 +320,18 @@ int guac_terminal_display_assign_color(guac_terminal_display* display,
 int guac_terminal_display_lookup_color(guac_terminal_display* display,
         int index, guac_terminal_color* color) {
 
+    /* Use default foreground if foreground pseudo-index is given */
+    if (index == GUAC_TERMINAL_COLOR_FOREGROUND) {
+        *color = display->default_foreground;
+        return 0;
+    }
+
+    /* Use default background if background pseudo-index is given */
+    if (index == GUAC_TERMINAL_COLOR_BACKGROUND) {
+        *color = display->default_background;
+        return 0;
+    }
+
     /* Lookup fails if out-of-bounds */
     if (index < 0 || index > 255)
         return 1;
@@ -658,11 +675,15 @@ void __guac_terminal_display_flush_clear(guac_terminal_display* display) {
                 int rect_width, rect_height;
 
                 /* Color of the rectangle to draw */
-                const guac_terminal_color* color;
+                guac_terminal_color color;
                 if (current->character.attributes.reverse != current->character.attributes.cursor)
-                   color = &current->character.attributes.foreground;
+                   color = current->character.attributes.foreground;
                 else
-                   color = &current->character.attributes.background;
+                   color = current->character.attributes.background;
+
+                /* Rely only on palette index if defined */
+                guac_terminal_display_lookup_color(display,
+                        color.palette_index, &color);
 
                 /* Current row within a subrect */
                 guac_terminal_operation* rect_current_row;
@@ -685,7 +706,7 @@ void __guac_terminal_display_flush_clear(guac_terminal_display* display) {
                         /* If not identical operation, stop */
                         if (rect_current->type != GUAC_CHAR_SET
                                 || guac_terminal_has_glyph(rect_current->character.value)
-                                || guac_terminal_colorcmp(joining_color, color) != 0)
+                                || guac_terminal_colorcmp(joining_color, &color) != 0)
                             break;
 
                         /* Next column */
@@ -730,7 +751,7 @@ void __guac_terminal_display_flush_clear(guac_terminal_display* display) {
                         /* Mark clear operations as NOP */
                         if (rect_current->type == GUAC_CHAR_SET
                                 && !guac_terminal_has_glyph(rect_current->character.value)
-                                && guac_terminal_colorcmp(joining_color, color) == 0)
+                                && guac_terminal_colorcmp(joining_color, &color) == 0)
                             rect_current->type = GUAC_CHAR_NOP;
 
                         /* Next column */
@@ -750,7 +771,7 @@ void __guac_terminal_display_flush_clear(guac_terminal_display* display) {
                         row * display->char_height,
                         rect_width * display->char_width,
                         rect_height * display->char_height,
-                        color->red, color->green, color->blue,
+                        color.red, color.green, color.blue,
                         0xFF);
 
             } /* end if clear operation */

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/dcab5408/src/terminal/palette.c
----------------------------------------------------------------------
diff --git a/src/terminal/palette.c b/src/terminal/palette.c
index cdbe415..a6b2d5a 100644
--- a/src/terminal/palette.c
+++ b/src/terminal/palette.c
@@ -289,6 +289,10 @@ const guac_terminal_color GUAC_TERMINAL_INITIAL_PALETTE[256] = {
 int guac_terminal_colorcmp(const guac_terminal_color* a,
         const guac_terminal_color* b) {
 
+    /* Compare palette index alone if not unknown */
+    if (a->palette_index != -1 && b->palette_index != -1)
+        return a->palette_index - b->palette_index;
+
     /* Consider red component highest order ... */
     if (a->red != b->red)
         return a->red - b->red;

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/dcab5408/src/terminal/terminal/palette.h
----------------------------------------------------------------------
diff --git a/src/terminal/terminal/palette.h b/src/terminal/terminal/palette.h
index 7f46725..b1524b5 100644
--- a/src/terminal/terminal/palette.h
+++ b/src/terminal/terminal/palette.h
@@ -25,6 +25,20 @@
 #include <stdint.h>
 
 /**
+ * The pseudo-index of the color set as the the default foreground color for
+ * the terminal. Regardless of what changes are made to the palette, this index
+ * will always return the current default foreground color.
+ */
+#define GUAC_TERMINAL_COLOR_FOREGROUND -2
+
+/**
+ * The pseudo-index of the color set as the the default background color for
+ * the terminal. Regardless of what changes are made to the palette, this index
+ * will always return the current default background color.
+ */
+#define GUAC_TERMINAL_COLOR_BACKGROUND -3
+
+/**
  * The index of black within the terminal color palette.
  */
 #define GUAC_TERMINAL_COLOR_BLACK 0


[2/6] guacamole-server git commit: GUACAMOLE-630: Separate color scheme parsing into own files.

Posted by vn...@apache.org.
GUACAMOLE-630: Separate color scheme parsing into own files.


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

Branch: refs/heads/master
Commit: 6f9f2189f278e75e0a3e89851827f317757ee16e
Parents: 6f49194
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Sep 22 16:07:42 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Mon Oct 22 23:23:27 2018 -0700

----------------------------------------------------------------------
 src/terminal/Makefile.am             |   2 +
 src/terminal/color-scheme.c          | 251 ++++++++++++++++++++++++++++++
 src/terminal/terminal.c              | 243 +----------------------------
 src/terminal/terminal/color-scheme.h |  95 +++++++++++
 src/terminal/terminal/terminal.h     |  35 -----
 5 files changed, 349 insertions(+), 277 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/6f9f2189/src/terminal/Makefile.am
----------------------------------------------------------------------
diff --git a/src/terminal/Makefile.am b/src/terminal/Makefile.am
index 9fce9dc..a886479 100644
--- a/src/terminal/Makefile.am
+++ b/src/terminal/Makefile.am
@@ -32,6 +32,7 @@ noinst_HEADERS =                 \
     terminal/buffer.h            \
     terminal/char_mappings.h     \
     terminal/common.h            \
+    terminal/color-scheme.h      \
     terminal/display.h           \
     terminal/named-colors.h      \
     terminal/palette.h           \
@@ -46,6 +47,7 @@ noinst_HEADERS =                 \
 libguac_terminal_la_SOURCES =   \
     buffer.c                    \
     char_mappings.c             \
+    color-scheme.c              \
     common.c                    \
     display.c                   \
     named-colors.c              \

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/6f9f2189/src/terminal/color-scheme.c
----------------------------------------------------------------------
diff --git a/src/terminal/color-scheme.c b/src/terminal/color-scheme.c
new file mode 100644
index 0000000..2799aac
--- /dev/null
+++ b/src/terminal/color-scheme.c
@@ -0,0 +1,251 @@
+/*
+ * 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 "terminal/color-scheme.h"
+#include "terminal/palette.h"
+#include "terminal/xparsecolor.h"
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <guacamole/client.h>
+
+/**
+ * Compare a non-null-terminated string to a null-terminated literal, in the
+ * same manner as strcmp().
+ *
+ * @param str_start
+ *     Start of the non-null-terminated string.
+ *
+ * @param str_end
+ *     End of the non-null-terminated string, after the last character.
+ *
+ * @param literal
+ *     The null-terminated literal to compare against.
+ *
+ * @return
+ *     Zero if the two strings are equal and non-zero otherwise.
+ */
+static int guac_terminal_color_scheme_compare_token(const char* str_start,
+        const char* str_end, const char* literal) {
+
+    const int result = strncmp(literal, str_start, str_end - str_start);
+    if (result != 0)
+        return result;
+
+    /* At this point, literal is same length or longer than
+     * | str_end - str_start |, so if the two are equal, literal should
+     * have its null-terminator at | str_end - str_start |. */
+    return (int) (unsigned char) literal[str_end - str_start];
+}
+
+/**
+ * Strip the leading and trailing spaces of a bounded string.
+ *
+ * @param[in,out] str_start
+ *     Address of a pointer to the start of the string. On return, the pointer
+ *     is advanced to after any leading spaces.
+ *
+ * @param[in,out] str_end
+ *     Address of a pointer to the end of the string, after the last character.
+ *     On return, the pointer is moved back to before any trailing spaces.
+ */
+static void guac_terminal_color_scheme_strip_spaces(const char** str_start,
+        const char** str_end) {
+
+    /* Strip leading spaces. */
+    while (*str_start < *str_end && isspace(**str_start))
+        (*str_start)++;
+
+    /* Strip trailing spaces. */
+    while (*str_end > *str_start && isspace(*(*str_end - 1)))
+        (*str_end)--;
+}
+
+/**
+ * Parse the name part of the name-value pair within the color-scheme
+ * configuration.
+ *
+ * @param client
+ *     The client that the terminal is connected to.
+ *
+ * @param name_start
+ *     Start of the name string.
+ *
+ * @param name_end
+ *     End of the name string, after the last character.
+ *
+ * @param foreground
+ *     Pointer to the foreground color.
+ *
+ * @param background
+ *     Pointer to the background color.
+ *
+ * @param palette
+ *     Pointer to the palette array.
+ *
+ * @param[out] target
+ *     On return, pointer to the color struct that corresponds to the name.
+ *
+ * @return
+ *     Zero if successful or non-zero otherwise.
+ */
+static int guac_terminal_parse_color_scheme_name(guac_client* client,
+        const char* name_start, const char* name_end,
+        guac_terminal_color* foreground, guac_terminal_color* background,
+        guac_terminal_color (*palette)[256],
+        guac_terminal_color** target) {
+
+    guac_terminal_color_scheme_strip_spaces(&name_start, &name_end);
+
+    if (!guac_terminal_color_scheme_compare_token(
+            name_start, name_end, GUAC_TERMINAL_SCHEME_FOREGROUND)) {
+        *target = foreground;
+        return 0;
+    }
+
+    if (!guac_terminal_color_scheme_compare_token(
+            name_start, name_end, GUAC_TERMINAL_SCHEME_BACKGROUND)) {
+        *target = background;
+        return 0;
+    }
+
+    /* Parse color<n> value. */
+    int index = -1;
+    if (sscanf(name_start, GUAC_TERMINAL_SCHEME_NUMBERED "%d", &index) &&
+            index >= 0 && index <= 255) {
+        *target = &(*palette)[index];
+        return 0;
+    }
+
+    guac_client_log(client, GUAC_LOG_WARNING,
+                    "Unknown color name: \"%.*s\".",
+                    name_end - name_start, name_start);
+    return 1;
+}
+
+/**
+ * Parse the value part of the name-value pair within the color-scheme
+ * configuration.
+ *
+ * @param client
+ *     The client that the terminal is connected to.
+ *
+ * @param value_start
+ *     Start of the value string.
+ *
+ * @param value_end
+ *     End of the value string, after the last character.
+ *
+ * @param palette
+ *     The current color palette.
+ *
+ * @param[out] target
+ *     On return, the parsed color.
+ *
+ * @return
+ *     Zero if successful or non-zero otherwise.
+ */
+static int guac_terminal_parse_color_scheme_value(guac_client* client,
+        const char* value_start, const char* value_end,
+        const guac_terminal_color (*palette)[256],
+        guac_terminal_color* target) {
+
+    guac_terminal_color_scheme_strip_spaces(&value_start, &value_end);
+
+    /* Parse color<n> value. */
+    int index = -1;
+    if (sscanf(value_start, GUAC_TERMINAL_SCHEME_NUMBERED "%d", &index) &&
+            index >= 0 && index <= 255) {
+        *target = (*palette)[index];
+        return 0;
+    }
+
+    /* Parse X11 value. */
+    if (!guac_terminal_xparsecolor(value_start, target))
+        return 0;
+
+    guac_client_log(client, GUAC_LOG_WARNING,
+                    "Invalid color value: \"%.*s\".",
+                    value_end - value_start, value_start);
+    return 1;
+}
+
+void guac_terminal_parse_color_scheme(guac_client* client,
+        const char* color_scheme, guac_terminal_color* foreground,
+        guac_terminal_color* background,
+        guac_terminal_color (*palette)[256]) {
+
+    /* Set default gray-black color scheme and initial palette. */
+    *foreground = GUAC_TERMINAL_INITIAL_PALETTE[GUAC_TERMINAL_COLOR_GRAY];
+    *background = GUAC_TERMINAL_INITIAL_PALETTE[GUAC_TERMINAL_COLOR_BLACK];
+    memcpy(palette, GUAC_TERMINAL_INITIAL_PALETTE,
+            sizeof(GUAC_TERMINAL_INITIAL_PALETTE));
+
+    /* Current char being parsed, or NULL if at end of parsing. */
+    const char* cursor = color_scheme;
+
+    while (cursor) {
+        /* Start of the current "name: value" pair. */
+        const char* pair_start = cursor;
+
+        /* End of the current name-value pair. */
+        const char* pair_end = strchr(pair_start, ';');
+        if (pair_end) {
+            cursor = pair_end + 1;
+        }
+        else {
+            pair_end = pair_start + strlen(pair_start);
+            cursor = NULL;
+        }
+
+        guac_terminal_color_scheme_strip_spaces(&pair_start, &pair_end);
+        if (pair_start >= pair_end)
+            /* Allow empty pairs, which happens, e.g., when the configuration
+             * string ends in a semi-colon. */
+            continue;
+
+        /* End of the name part of the pair. */
+        const char* name_end = memchr(pair_start, ':', pair_end - pair_start);
+        if (name_end == NULL) {
+            guac_client_log(client, GUAC_LOG_WARNING,
+                            "Expecting colon: \"%.*s\".",
+                            pair_end - pair_start, pair_start);
+            return;
+        }
+
+        /* The color that the name corresponds to. */
+        guac_terminal_color* color_target = NULL;
+
+        if (guac_terminal_parse_color_scheme_name(
+                client, pair_start, name_end, foreground, background,
+                palette, &color_target))
+            return; /* Parsing failed. */
+
+        if (guac_terminal_parse_color_scheme_value(
+                client, name_end + 1, pair_end,
+                (const guac_terminal_color(*)[256]) palette, color_target))
+            return; /* Parsing failed. */
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/6f9f2189/src/terminal/terminal.c
----------------------------------------------------------------------
diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c
index 95e945d..a99bfb0 100644
--- a/src/terminal/terminal.c
+++ b/src/terminal/terminal.c
@@ -22,6 +22,7 @@
 #include "common/clipboard.h"
 #include "common/cursor.h"
 #include "terminal/buffer.h"
+#include "terminal/color-scheme.h"
 #include "terminal/common.h"
 #include "terminal/display.h"
 #include "terminal/palette.h"
@@ -30,7 +31,6 @@
 #include "terminal/terminal_handlers.h"
 #include "terminal/types.h"
 #include "terminal/typescript.h"
-#include "terminal/xparsecolor.h"
 
 #include <ctype.h>
 #include <errno.h>
@@ -305,247 +305,6 @@ void* guac_terminal_thread(void* data) {
 
 }
 
-/**
- * Compare a non-null-terminated string to a null-terminated literal, in the
- * same manner as strcmp().
- *
- * @param str_start
- *     Start of the non-null-terminated string.
- *
- * @param str_end
- *     End of the non-null-terminated string, after the last character.
- *
- * @param literal
- *     The null-terminated literal to compare against.
- *
- * @return
- *     Zero if the two strings are equal and non-zero otherwise.
- */
-static int guac_terminal_color_scheme_compare_token(const char* str_start,
-        const char* str_end, const char* literal) {
-
-    const int result = strncmp(literal, str_start, str_end - str_start);
-    if (result != 0)
-        return result;
-
-    /* At this point, literal is same length or longer than
-     * | str_end - str_start |, so if the two are equal, literal should
-     * have its null-terminator at | str_end - str_start |. */
-    return (int) (unsigned char) literal[str_end - str_start];
-}
-
-/**
- * Strip the leading and trailing spaces of a bounded string.
- *
- * @param[in,out] str_start
- *     Address of a pointer to the start of the string. On return, the pointer
- *     is advanced to after any leading spaces.
- *
- * @param[in,out] str_end
- *     Address of a pointer to the end of the string, after the last character.
- *     On return, the pointer is moved back to before any trailing spaces.
- */
-static void guac_terminal_color_scheme_strip_spaces(const char** str_start,
-        const char** str_end) {
-
-    /* Strip leading spaces. */
-    while (*str_start < *str_end && isspace(**str_start))
-        (*str_start)++;
-
-    /* Strip trailing spaces. */
-    while (*str_end > *str_start && isspace(*(*str_end - 1)))
-        (*str_end)--;
-}
-
-/**
- * Parse the name part of the name-value pair within the color-scheme
- * configuration.
- *
- * @param client
- *     The client that the terminal is connected to.
- *
- * @param name_start
- *     Start of the name string.
- *
- * @param name_end
- *     End of the name string, after the last character.
- *
- * @param foreground
- *     Pointer to the foreground color.
- *
- * @param background
- *     Pointer to the background color.
- *
- * @param palette
- *     Pointer to the palette array.
- *
- * @param[out] target
- *     On return, pointer to the color struct that corresponds to the name.
- *
- * @return
- *     Zero if successful or non-zero otherwise.
- */
-static int guac_terminal_parse_color_scheme_name(guac_client* client,
-        const char* name_start, const char* name_end,
-        guac_terminal_color* foreground, guac_terminal_color* background,
-        guac_terminal_color (*palette)[256],
-        guac_terminal_color** target) {
-
-    guac_terminal_color_scheme_strip_spaces(&name_start, &name_end);
-
-    if (!guac_terminal_color_scheme_compare_token(
-            name_start, name_end, GUAC_TERMINAL_SCHEME_FOREGROUND)) {
-        *target = foreground;
-        return 0;
-    }
-
-    if (!guac_terminal_color_scheme_compare_token(
-            name_start, name_end, GUAC_TERMINAL_SCHEME_BACKGROUND)) {
-        *target = background;
-        return 0;
-    }
-
-    /* Parse color<n> value. */
-    int index = -1;
-    if (sscanf(name_start, GUAC_TERMINAL_SCHEME_NUMBERED "%d", &index) &&
-            index >= 0 && index <= 255) {
-        *target = &(*palette)[index];
-        return 0;
-    }
-
-    guac_client_log(client, GUAC_LOG_WARNING,
-                    "Unknown color name: \"%.*s\".",
-                    name_end - name_start, name_start);
-    return 1;
-}
-
-/**
- * Parse the value part of the name-value pair within the color-scheme
- * configuration.
- *
- * @param client
- *     The client that the terminal is connected to.
- *
- * @param value_start
- *     Start of the value string.
- *
- * @param value_end
- *     End of the value string, after the last character.
- *
- * @param palette
- *     The current color palette.
- *
- * @param[out] target
- *     On return, the parsed color.
- *
- * @return
- *     Zero if successful or non-zero otherwise.
- */
-static int guac_terminal_parse_color_scheme_value(guac_client* client,
-        const char* value_start, const char* value_end,
-        const guac_terminal_color (*palette)[256],
-        guac_terminal_color* target) {
-
-    guac_terminal_color_scheme_strip_spaces(&value_start, &value_end);
-
-    /* Parse color<n> value. */
-    int index = -1;
-    if (sscanf(value_start, GUAC_TERMINAL_SCHEME_NUMBERED "%d", &index) &&
-            index >= 0 && index <= 255) {
-        *target = (*palette)[index];
-        return 0;
-    }
-
-    /* Parse X11 value. */
-    if (!guac_terminal_xparsecolor(value_start, target))
-        return 0;
-
-    guac_client_log(client, GUAC_LOG_WARNING,
-                    "Invalid color value: \"%.*s\".",
-                    value_end - value_start, value_start);
-    return 1;
-}
-
-/**
- * Parse a color-scheme configuration string, and return specified
- * foreground/background colors and color palette.
- *
- * @param client
- *     The client that the terminal is connected to.
- *
- * @param color_scheme
- *     A semicolon-separated list of name-value pairs, i.e.
- *     "<name>: <value> [; <name>: <value> [; ...]]".
- *     For example, "color2: rgb:cc/33/22; background: color5".
- *
- * @param[out] foreground
- *     Parsed foreground color.
- *
- * @param[out] background
- *     Parsed background color.
- *
- * @param[in,out] palette
- *     Parsed color palette. The caller is responsible for allocating a mutable
- *     array on entry. On return, the array contains the parsed palette.
- */
-static void guac_terminal_parse_color_scheme(guac_client* client,
-        const char* color_scheme, guac_terminal_color* foreground,
-        guac_terminal_color* background,
-        guac_terminal_color (*palette)[256]) {
-
-    /* Set default gray-black color scheme and initial palette. */
-    *foreground = GUAC_TERMINAL_INITIAL_PALETTE[GUAC_TERMINAL_COLOR_GRAY];
-    *background = GUAC_TERMINAL_INITIAL_PALETTE[GUAC_TERMINAL_COLOR_BLACK];
-    memcpy(palette, GUAC_TERMINAL_INITIAL_PALETTE,
-            sizeof(GUAC_TERMINAL_INITIAL_PALETTE));
-
-    /* Current char being parsed, or NULL if at end of parsing. */
-    const char* cursor = color_scheme;
-
-    while (cursor) {
-        /* Start of the current "name: value" pair. */
-        const char* pair_start = cursor;
-
-        /* End of the current name-value pair. */
-        const char* pair_end = strchr(pair_start, ';');
-        if (pair_end) {
-            cursor = pair_end + 1;
-        }
-        else {
-            pair_end = pair_start + strlen(pair_start);
-            cursor = NULL;
-        }
-
-        guac_terminal_color_scheme_strip_spaces(&pair_start, &pair_end);
-        if (pair_start >= pair_end)
-            /* Allow empty pairs, which happens, e.g., when the configuration
-             * string ends in a semi-colon. */
-            continue;
-
-        /* End of the name part of the pair. */
-        const char* name_end = memchr(pair_start, ':', pair_end - pair_start);
-        if (name_end == NULL) {
-            guac_client_log(client, GUAC_LOG_WARNING,
-                            "Expecting colon: \"%.*s\".",
-                            pair_end - pair_start, pair_start);
-            return;
-        }
-
-        /* The color that the name corresponds to. */
-        guac_terminal_color* color_target = NULL;
-
-        if (guac_terminal_parse_color_scheme_name(
-                client, pair_start, name_end, foreground, background,
-                palette, &color_target))
-            return; /* Parsing failed. */
-
-        if (guac_terminal_parse_color_scheme_value(
-                client, name_end + 1, pair_end,
-                (const guac_terminal_color(*)[256]) palette, color_target))
-            return; /* Parsing failed. */
-    }
-}
-
 guac_terminal* guac_terminal_create(guac_client* client,
         guac_common_clipboard* clipboard, int max_scrollback,
         const char* font_name, int font_size, int dpi,

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/6f9f2189/src/terminal/terminal/color-scheme.h
----------------------------------------------------------------------
diff --git a/src/terminal/terminal/color-scheme.h b/src/terminal/terminal/color-scheme.h
new file mode 100644
index 0000000..962d820
--- /dev/null
+++ b/src/terminal/terminal/color-scheme.h
@@ -0,0 +1,95 @@
+/*
+ * 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 GUAC_TERMINAL_COLOR_SCHEME_H
+#define GUAC_TERMINAL_COLOR_SCHEME_H
+
+#include "config.h"
+
+#include "terminal/palette.h"
+
+#include <guacamole/client.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+/**
+ * The name of the color scheme having black foreground and white background.
+ */
+#define GUAC_TERMINAL_SCHEME_BLACK_WHITE "black-white"
+
+/**
+ * The name of the color scheme having gray foreground and black background.
+ */
+#define GUAC_TERMINAL_SCHEME_GRAY_BLACK "gray-black"
+
+/**
+ * The name of the color scheme having green foreground and black background.
+ */
+#define GUAC_TERMINAL_SCHEME_GREEN_BLACK "green-black"
+
+/**
+ * The name of the color scheme having white foreground and black background.
+ */
+#define GUAC_TERMINAL_SCHEME_WHITE_BLACK "white-black"
+
+/**
+ * Color name representing the foreground color.
+ */
+#define GUAC_TERMINAL_SCHEME_FOREGROUND "foreground"
+
+/**
+ * Color name representing the background color.
+ */
+#define GUAC_TERMINAL_SCHEME_BACKGROUND "background"
+
+/**
+ * Color name representing a numbered color.
+ */
+#define GUAC_TERMINAL_SCHEME_NUMBERED "color"
+
+/**
+ * Parse a color-scheme configuration string, and return specified
+ * foreground/background colors and color palette.
+ *
+ * @param client
+ *     The client that the terminal is connected to.
+ *
+ * @param color_scheme
+ *     A semicolon-separated list of name-value pairs, i.e.
+ *     "<name>: <value> [; <name>: <value> [; ...]]".
+ *     For example, "color2: rgb:cc/33/22; background: color5".
+ *
+ * @param[out] foreground
+ *     Parsed foreground color.
+ *
+ * @param[out] background
+ *     Parsed background color.
+ *
+ * @param[in,out] palette
+ *     Parsed color palette. The caller is responsible for allocating a mutable
+ *     array on entry. On return, the array contains the parsed palette.
+ */
+void guac_terminal_parse_color_scheme(guac_client* client,
+        const char* color_scheme, guac_terminal_color* foreground,
+        guac_terminal_color* background,
+        guac_terminal_color (*palette)[256]);
+
+#endif
+

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/6f9f2189/src/terminal/terminal/terminal.h
----------------------------------------------------------------------
diff --git a/src/terminal/terminal/terminal.h b/src/terminal/terminal/terminal.h
index 08094ba..aee7742 100644
--- a/src/terminal/terminal/terminal.h
+++ b/src/terminal/terminal/terminal.h
@@ -70,41 +70,6 @@
 #define GUAC_TERMINAL_WHEEL_SCROLL_AMOUNT 3
 
 /**
- * The name of the color scheme having black foreground and white background.
- */
-#define GUAC_TERMINAL_SCHEME_BLACK_WHITE "black-white"
-
-/**
- * The name of the color scheme having gray foreground and black background.
- */
-#define GUAC_TERMINAL_SCHEME_GRAY_BLACK "gray-black"
-
-/**
- * The name of the color scheme having green foreground and black background.
- */
-#define GUAC_TERMINAL_SCHEME_GREEN_BLACK "green-black"
-
-/**
- * The name of the color scheme having white foreground and black background.
- */
-#define GUAC_TERMINAL_SCHEME_WHITE_BLACK "white-black"
-
-/**
- * Color name representing the foreground color.
- */
-#define GUAC_TERMINAL_SCHEME_FOREGROUND "foreground"
-
-/**
- * Color name representing the background color.
- */
-#define GUAC_TERMINAL_SCHEME_BACKGROUND "background"
-
-/**
- * Color name representing a numbered color.
- */
-#define GUAC_TERMINAL_SCHEME_NUMBERED "color"
-
-/**
  * Flag which specifies that terminal output should be sent to both the current
  * pipe stream and the user's display. By default, terminal output will be sent
  * only to the open pipe.