GUACAMOLE-1538: Only the core functionality of the terminal lib should be public.

This commit is contained in:
James Muehlner 2022-02-26 02:13:22 +00:00
parent ad0155b5f5
commit 46e813343e
35 changed files with 298 additions and 325 deletions

View File

@ -51,8 +51,7 @@ SHOW_INCLUDE_FILES = NO
CASE_SENSE_NAMES = YES
FILE_PATTERNS = *.h
STRIP_FROM_PATH = ../../src/terminal
INPUT = ../../src/terminal/terminal/
EXCLUDE = ../../src/terminal/terminal/terminal_priv.h
INPUT = ../../src/terminal/terminal/terminal.h
JAVADOC_AUTOBRIEF = YES
TAB_SIZE = 4
TYPEDEF_HIDES_STRUCT = YES

View File

@ -27,6 +27,7 @@
#include <guacamole/user.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -36,6 +36,8 @@
#include <libssh2.h>
#include <libssh2_sftp.h>
#include <guacamole/client.h>
#include <guacamole/socket.h>
#include <guacamole/timestamp.h>
#include <guacamole/wol.h>
#include <openssl/err.h>
#include <openssl/ssl.h>

View File

@ -26,6 +26,7 @@
#include <guacamole/socket.h>
#include <guacamole/user.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -30,6 +30,7 @@
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <guacamole/argv.h>
#include <guacamole/client.h>

View File

@ -26,6 +26,7 @@
#include <guacamole/client.h>
#include <guacamole/protocol.h>
#include <guacamole/timestamp.h>
#include <guacamole/wol.h>
#include <libtelnet.h>

View File

@ -30,10 +30,7 @@ lib_LTLIBRARIES = libguac-terminal.la
libguac_terminalincdir = $(includedir)/guacamole/terminal
noinst_HEADERS = \
terminal/terminal-priv.h
libguac_terminalinc_HEADERS = \
noinst_HEADERS = \
terminal/buffer.h \
terminal/char-mappings.h \
terminal/common.h \
@ -43,12 +40,15 @@ libguac_terminalinc_HEADERS = \
terminal/palette.h \
terminal/scrollbar.h \
terminal/select.h \
terminal/terminal.h \
terminal/terminal-priv.h \
terminal/terminal-handlers.h \
terminal/types.h \
terminal/typescript.h \
terminal/xparsecolor.h
libguac_terminalinc_HEADERS = \
terminal/terminal.h
libguac_terminal_la_SOURCES = \
buffer.c \
char-mappings.c \

View File

@ -17,7 +17,6 @@
* under the License.
*/
#include "config.h"
#include "terminal/buffer.h"
#include "terminal/common.h"

View File

@ -17,7 +17,6 @@
* under the License.
*/
#include "config.h"
const int vt100_map[] = {
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',

View File

@ -17,7 +17,6 @@
* under the License.
*/
#include "config.h"
#include "terminal/color-scheme.h"
#include "terminal/palette.h"

View File

@ -17,7 +17,6 @@
* under the License.
*/
#include "config.h"
#include "terminal/types.h"
#include <stdbool.h>

View File

@ -17,12 +17,13 @@
* under the License.
*/
#include "config.h"
#include "common/surface.h"
#include "terminal/common.h"
#include "terminal/display.h"
#include "terminal/palette.h"
#include "terminal/terminal.h"
#include "terminal/terminal-priv.h"
#include "terminal/types.h"
#include <math.h>

View File

@ -17,7 +17,6 @@
* under the License.
*/
#include "config.h"
#include "terminal/palette.h"
#include <ctype.h>

View File

@ -17,7 +17,6 @@
* under the License.
*/
#include "config.h"
#include "terminal/palette.h"
const guac_terminal_color GUAC_TERMINAL_INITIAL_PALETTE[256] = {

View File

@ -17,7 +17,6 @@
* under the License.
*/
#include "config.h"
#include "terminal/scrollbar.h"
#include <guacamole/client.h>

View File

@ -17,7 +17,6 @@
* under the License.
*/
#include "config.h"
#include "common/clipboard.h"
#include "terminal/buffer.h"

View File

@ -17,7 +17,6 @@
* under the License.
*/
#include "config.h"
#include "terminal/common.h"
#include "terminal/terminal.h"
#include "terminal/terminal-priv.h"

View File

@ -17,7 +17,6 @@
* under the License.
*/
#include "config.h"
#include "common/clipboard.h"
#include "common/cursor.h"

View File

@ -28,7 +28,6 @@
*/
#include "config.h"
#include "types.h"

View File

@ -27,7 +27,6 @@
* @file char-mappings.h
*/
#include "config.h"
/**
* VT100 graphics mapping. Each entry is the corresponding Unicode codepoint

View File

@ -17,8 +17,8 @@
* under the License.
*/
#ifndef GUAC_TERMINAL_GET_COLOR_SCHEME_H
#define GUAC_TERMINAL_GET_COLOR_SCHEME_H
#ifndef GUAC_TERMINAL_COLOR_SCHEME_H
#define GUAC_TERMINAL_COLOR_SCHEME_H
/**
* Definitions and functions related to color scheme handling.
@ -26,9 +26,8 @@
* @file color-scheme.h
*/
#include "config.h"
#include "terminal/palette.h"
#include "palette.h"
#include <guacamole/client.h>

View File

@ -27,7 +27,6 @@
* @file common.h
*/
#include "config.h"
#include "types.h"
#include <stdbool.h>

View File

@ -27,7 +27,6 @@
* @file display.h
*/
#include "config.h"
#include "common/surface.h"
#include "palette.h"

View File

@ -26,8 +26,7 @@
* @file named-colors.h
*/
#include "config.h"
#include "terminal/palette.h"
#include "palette.h"
/**
* Searches for the color having the given name, storing that color within the

View File

@ -26,7 +26,6 @@
* @file palette.h
*/
#include "config.h"
#include <stdint.h>

View File

@ -26,7 +26,6 @@
* @file scrollbar.h
*/
#include "config.h"
#include <guacamole/client.h>
#include <guacamole/layer.h>

View File

@ -27,7 +27,6 @@
* @file select.h
*/
#include "config.h"
#include "terminal.h"
#include <stdbool.h>

View File

@ -29,6 +29,7 @@
#include "config.h"
#include "display.h"
#include "terminal.h"
/**

View File

@ -22,7 +22,12 @@
#define GUAC_TERMINAL_PRIV_H
#include "common/clipboard.h"
#include "terminal/terminal.h"
#include "common/cursor.h"
#include "buffer.h"
#include "display.h"
#include "scrollbar.h"
#include "terminal.h"
#include "typescript.h"
struct guac_terminal {
@ -442,5 +447,194 @@ struct guac_terminal {
};
/**
* Handles a scroll event received from the scrollbar associated with a
* terminal.
*
* @param scrollbar
* The scrollbar that has been scrolled.
*
* @param value
* The new value that should be stored within the scrollbar, and
* represented within the terminal display.
*/
void guac_terminal_scroll_handler(guac_terminal_scrollbar* scrollbar, int value);
/**
* Sets the given range of columns within the given row to the given
* character.
*/
void guac_terminal_set_columns(guac_terminal* terminal, int row,
int start_column, int end_column, guac_terminal_char* character);
/**
* Acquires exclusive access to the terminal. Note that enforcing this
* exclusive access requires that ALL users of the terminal call this
* function before making further calls to the terminal.
*/
void guac_terminal_lock(guac_terminal* terminal);
/**
* Releases exclusive access to the terminal.
*/
void guac_terminal_unlock(guac_terminal* terminal);
/**
* Resets the state of the given terminal, as if it were just allocated.
*/
void guac_terminal_reset(guac_terminal* term);
/**
* Sets the character at the given row and column to the specified value.
*/
int guac_terminal_set(guac_terminal* term, int row, int col, int codepoint);
/**
* Clears the given region within a single row.
*/
int guac_terminal_clear_columns(guac_terminal* term,
int row, int start_col, int end_col);
/**
* Clears the given region from right-to-left, top-to-bottom, replacing
* all characters with the current background color and attributes.
*/
int guac_terminal_clear_range(guac_terminal* term,
int start_row, int start_col,
int end_row, int end_col);
/**
* Scrolls the terminal's current scroll region up by one row.
*/
int guac_terminal_scroll_up(guac_terminal* term,
int start_row, int end_row, int amount);
/**
* Scrolls the terminal's current scroll region down by one row.
*/
int guac_terminal_scroll_down(guac_terminal* term,
int start_row, int end_row, int amount);
/**
* Commits the current cursor location, updating the visible cursor
* on the screen.
*/
void guac_terminal_commit_cursor(guac_terminal* term);
/**
* Scroll down the display by the given amount, replacing the new space with
* data from the buffer. If not enough data is available, the maximum
* amount will be scrolled.
*/
void guac_terminal_scroll_display_down(guac_terminal* terminal, int amount);
/**
* Scroll up the display by the given amount, replacing the new space with data
* from either the buffer or the terminal buffer. If not enough data is
* available, the maximum amount will be scrolled.
*/
void guac_terminal_scroll_display_up(guac_terminal* terminal, int amount);
/**
* Opens a new pipe stream, redirecting all output from the given terminal to
* that pipe stream. If a pipe stream is already open, that pipe stream will
* be flushed and closed prior to opening the new pipe stream.
*
* @param term
* The terminal which should redirect output to a new pipe stream having
* the given name.
*
* @param name
* The name of the pipe stream to open.
*
* @param flags
* A bitwise OR of all integer flags which should apply to the new pipe
* stream.
*
* @see GUAC_TERMINAL_PIPE_INTERPRET_OUTPUT
* @see GUAC_TERMINAL_PIPE_AUTOFLUSH
*/
void guac_terminal_pipe_stream_open(guac_terminal* term, const char* name,
int flags);
/**
* Writes a single byte of data to the pipe stream currently open and
* associated with the given terminal. The pipe stream must already have been
* opened via guac_terminal_pipe_stream_open(). If no pipe stream is currently
* open, this function has no effect. Data written through this function may
* be buffered.
*
* @param term
* The terminal whose currently-open pipe stream should be written to.
*
* @param c
* The byte of data to write to the pipe stream.
*/
void guac_terminal_pipe_stream_write(guac_terminal* term, char c);
/**
* Flushes any data currently buffered for the currently-open pipe stream
* associated with the given terminal. The pipe stream must already have been
* opened via guac_terminal_pipe_stream_open(). If no pipe stream is currently
* open or no data is in the buffer, this function has no effect.
*
* @param term
* The terminal whose pipe stream buffer should be flushed.
*/
void guac_terminal_pipe_stream_flush(guac_terminal* term);
/**
* Closes the currently-open pipe stream associated with the given terminal,
* redirecting all output back to the terminal display. Any data currently
* buffered for output to the pipe stream will be flushed prior to closure. The
* pipe stream must already have been opened via
* guac_terminal_pipe_stream_open(). If no pipe stream is currently open, this
* function has no effect.
*
* @param term
* The terminal whose currently-open pipe stream should be closed.
*/
void guac_terminal_pipe_stream_close(guac_terminal* term);
/**
* Sets a tabstop in the given column.
*/
void guac_terminal_set_tab(guac_terminal* term, int column);
/**
* Removes the tabstop at the given column.
*/
void guac_terminal_unset_tab(guac_terminal* term, int column);
/**
* Removes all tabstops.
*/
void guac_terminal_clear_tabs(guac_terminal* term);
/**
* Given a column within the given terminal, returns the location of the
* next tabstop (or the rightmost character, if no more tabstops exist).
*/
int guac_terminal_next_tab(guac_terminal* term, int column);
/**
* Copies the given range of columns to a new location, offset from
* the original by the given number of columns.
*/
void guac_terminal_copy_columns(guac_terminal* terminal, int row,
int start_column, int end_column, int offset);
/**
* Copies the given range of rows to a new location, offset from the
* original by the given number of rows.
*/
void guac_terminal_copy_rows(guac_terminal* terminal,
int start_row, int end_row, int offset);
/**
* Flushes all pending operations within the given guac_terminal.
*/
void guac_terminal_flush(guac_terminal* terminal);
#endif

View File

@ -28,15 +28,6 @@
* @file terminal.h
*/
#include "config.h"
#include "buffer.h"
#include "common/cursor.h"
#include "display.h"
#include "scrollbar.h"
#include "types.h"
#include "typescript.h"
#include <pthread.h>
#include <stdbool.h>
@ -453,6 +444,52 @@ int guac_terminal_send_key(guac_terminal* term, int keysym, int pressed);
int guac_terminal_send_mouse(guac_terminal* term, guac_user* user,
int x, int y, int mask);
/**
* Sends the given string as if typed by the user. If terminal input is
* currently coming from a stream due to a prior call to
* guac_terminal_send_stream(), any input which would normally result from
* invoking this function is dropped.
*
* @param term
* The terminal which should receive the given data on STDIN.
*
* @param data
* The data the terminal should receive on STDIN.
*
* @param length
* The size of the given data, in bytes.
*
* @return
* The number of bytes written to STDIN, or a negative value if an error
* occurs preventing the data from being written. This should always be
* the size of the data given unless data is intentionally dropped.
*/
int guac_terminal_send_data(guac_terminal* term, const char* data, int length);
/**
* Sends the given string as if typed by the user. If terminal input is
* currently coming from a stream due to a prior call to
* guac_terminal_send_stream(), any input which would normally result from
* invoking this function is dropped.
*
* @param term
* The terminal which should receive the given data on STDIN.
*
* @param data
* The data the terminal should receive on STDIN.
*
* @return
* The number of bytes written to STDIN, or a negative value if an error
* occurs preventing the data from being written. This should always be
* the size of the data given unless data is intentionally dropped.
*/
int guac_terminal_send_string(guac_terminal* term, const char* data);
/**
* Writes the given string of characters to the terminal.
*/
int guac_terminal_write(guac_terminal* term, const char* c, int size);
/**
* Initializes the handlers of the given guac_stream such that it serves as the
* source of input to the terminal. Other input sources will be temporarily
@ -482,17 +519,27 @@ int guac_terminal_send_stream(guac_terminal* term, guac_user* user,
guac_stream* stream);
/**
* Handles a scroll event received from the scrollbar associated with a
* terminal.
* Sends data through STDIN as if typed by the user, using the format string
* given and any args (similar to printf). If terminal input is currently
* coming from a stream due to a prior call to guac_terminal_send_stream(), any
* input which would normally result from invoking this function is dropped.
*
* @param scrollbar
* The scrollbar that has been scrolled.
* @param term
* The terminal which should receive the given data on STDIN.
*
* @param value
* The new value that should be stored within the scrollbar, and
* represented within the terminal display.
* @param format
* A printf-style format string describing the data to be received on
* STDIN.
*
* @param ...
* Any srguments to use when filling the format string.
*
* @return
* The number of bytes written to STDIN, or a negative value if an error
* occurs preventing the data from being written. This should always be
* the size of the data given unless data is intentionally dropped.
*/
void guac_terminal_scroll_handler(guac_terminal_scrollbar* scrollbar, int value);
int guac_terminal_sendf(guac_terminal* term, const char* format, ...);
/**
* Replicates the current display state to a user that has just joined the
@ -512,6 +559,11 @@ void guac_terminal_scroll_handler(guac_terminal_scrollbar* scrollbar, int value)
void guac_terminal_dup(guac_terminal* term, guac_user* user,
guac_socket* socket);
/**
* Resize the terminal to the given dimensions.
*/
int guac_terminal_resize(guac_terminal* term, int width, int height);
/**
* Returns the number of rows within the buffer of the given terminal which are
* not currently displayed on screen. Adjustments to the desired scrollback
@ -588,262 +640,6 @@ void guac_terminal_clipboard_append(guac_terminal* terminal,
*/
void guac_terminal_remove_user(guac_terminal* terminal, guac_user* user);
/* INTERNAL FUNCTIONS */
/**
* Acquires exclusive access to the terminal. Note that enforcing this
* exclusive access requires that ALL users of the terminal call this
* function before making further calls to the terminal.
*/
void guac_terminal_lock(guac_terminal* terminal);
/**
* Releases exclusive access to the terminal.
*/
void guac_terminal_unlock(guac_terminal* terminal);
/**
* Resets the state of the given terminal, as if it were just allocated.
*/
void guac_terminal_reset(guac_terminal* term);
/**
* Writes the given string of characters to the terminal.
*/
int guac_terminal_write(guac_terminal* term, const char* c, int size);
/**
* Sets the character at the given row and column to the specified value.
*/
int guac_terminal_set(guac_terminal* term, int row, int col, int codepoint);
/**
* Clears the given region within a single row.
*/
int guac_terminal_clear_columns(guac_terminal* term,
int row, int start_col, int end_col);
/**
* Clears the given region from right-to-left, top-to-bottom, replacing
* all characters with the current background color and attributes.
*/
int guac_terminal_clear_range(guac_terminal* term,
int start_row, int start_col,
int end_row, int end_col);
/**
* Scrolls the terminal's current scroll region up by one row.
*/
int guac_terminal_scroll_up(guac_terminal* term,
int start_row, int end_row, int amount);
/**
* Scrolls the terminal's current scroll region down by one row.
*/
int guac_terminal_scroll_down(guac_terminal* term,
int start_row, int end_row, int amount);
/**
* Commits the current cursor location, updating the visible cursor
* on the screen.
*/
void guac_terminal_commit_cursor(guac_terminal* term);
/**
* Scroll down the display by the given amount, replacing the new space with
* data from the buffer. If not enough data is available, the maximum
* amount will be scrolled.
*/
void guac_terminal_scroll_display_down(guac_terminal* terminal, int amount);
/**
* Scroll up the display by the given amount, replacing the new space with data
* from either the buffer or the terminal buffer. If not enough data is
* available, the maximum amount will be scrolled.
*/
void guac_terminal_scroll_display_up(guac_terminal* terminal, int amount);
/* LOW-LEVEL TERMINAL OPERATIONS */
/**
* Copies the given range of columns to a new location, offset from
* the original by the given number of columns.
*/
void guac_terminal_copy_columns(guac_terminal* terminal, int row,
int start_column, int end_column, int offset);
/**
* Copies the given range of rows to a new location, offset from the
* original by the given number of rows.
*/
void guac_terminal_copy_rows(guac_terminal* terminal,
int start_row, int end_row, int offset);
/**
* Sets the given range of columns within the given row to the given
* character.
*/
void guac_terminal_set_columns(guac_terminal* terminal, int row,
int start_column, int end_column, guac_terminal_char* character);
/**
* Resize the terminal to the given dimensions.
*/
int guac_terminal_resize(guac_terminal* term, int width, int height);
/**
* Flushes all pending operations within the given guac_terminal.
*/
void guac_terminal_flush(guac_terminal* terminal);
/**
* Sends the given string as if typed by the user. If terminal input is
* currently coming from a stream due to a prior call to
* guac_terminal_send_stream(), any input which would normally result from
* invoking this function is dropped.
*
* @param term
* The terminal which should receive the given data on STDIN.
*
* @param data
* The data the terminal should receive on STDIN.
*
* @param length
* The size of the given data, in bytes.
*
* @return
* The number of bytes written to STDIN, or a negative value if an error
* occurs preventing the data from being written. This should always be
* the size of the data given unless data is intentionally dropped.
*/
int guac_terminal_send_data(guac_terminal* term, const char* data, int length);
/**
* Sends the given string as if typed by the user. If terminal input is
* currently coming from a stream due to a prior call to
* guac_terminal_send_stream(), any input which would normally result from
* invoking this function is dropped.
*
* @param term
* The terminal which should receive the given data on STDIN.
*
* @param data
* The data the terminal should receive on STDIN.
*
* @return
* The number of bytes written to STDIN, or a negative value if an error
* occurs preventing the data from being written. This should always be
* the size of the data given unless data is intentionally dropped.
*/
int guac_terminal_send_string(guac_terminal* term, const char* data);
/**
* Sends data through STDIN as if typed by the user, using the format string
* given and any args (similar to printf). If terminal input is currently
* coming from a stream due to a prior call to guac_terminal_send_stream(), any
* input which would normally result from invoking this function is dropped.
*
* @param term
* The terminal which should receive the given data on STDIN.
*
* @param format
* A printf-style format string describing the data to be received on
* STDIN.
*
* @param ...
* Any srguments to use when filling the format string.
*
* @return
* The number of bytes written to STDIN, or a negative value if an error
* occurs preventing the data from being written. This should always be
* the size of the data given unless data is intentionally dropped.
*/
int guac_terminal_sendf(guac_terminal* term, const char* format, ...);
/**
* Sets a tabstop in the given column.
*/
void guac_terminal_set_tab(guac_terminal* term, int column);
/**
* Removes the tabstop at the given column.
*/
void guac_terminal_unset_tab(guac_terminal* term, int column);
/**
* Removes all tabstops.
*/
void guac_terminal_clear_tabs(guac_terminal* term);
/**
* Given a column within the given terminal, returns the location of the
* next tabstop (or the rightmost character, if no more tabstops exist).
*/
int guac_terminal_next_tab(guac_terminal* term, int column);
/**
* Opens a new pipe stream, redirecting all output from the given terminal to
* that pipe stream. If a pipe stream is already open, that pipe stream will
* be flushed and closed prior to opening the new pipe stream.
*
* @param term
* The terminal which should redirect output to a new pipe stream having
* the given name.
*
* @param name
* The name of the pipe stream to open.
*
* @param flags
* A bitwise OR of all integer flags which should apply to the new pipe
* stream.
*
* @see GUAC_TERMINAL_PIPE_INTERPRET_OUTPUT
* @see GUAC_TERMINAL_PIPE_AUTOFLUSH
*/
void guac_terminal_pipe_stream_open(guac_terminal* term, const char* name,
int flags);
/**
* Writes a single byte of data to the pipe stream currently open and
* associated with the given terminal. The pipe stream must already have been
* opened via guac_terminal_pipe_stream_open(). If no pipe stream is currently
* open, this function has no effect. Data written through this function may
* be buffered.
*
* @param term
* The terminal whose currently-open pipe stream should be written to.
*
* @param c
* The byte of data to write to the pipe stream.
*/
void guac_terminal_pipe_stream_write(guac_terminal* term, char c);
/**
* Flushes any data currently buffered for the currently-open pipe stream
* associated with the given terminal. The pipe stream must already have been
* opened via guac_terminal_pipe_stream_open(). If no pipe stream is currently
* open or no data is in the buffer, this function has no effect.
*
* @param term
* The terminal whose pipe stream buffer should be flushed.
*/
void guac_terminal_pipe_stream_flush(guac_terminal* term);
/**
* Closes the currently-open pipe stream associated with the given terminal,
* redirecting all output back to the terminal display. Any data currently
* buffered for output to the pipe stream will be flushed prior to closure. The
* pipe stream must already have been opened via
* guac_terminal_pipe_stream_open(). If no pipe stream is currently open, this
* function has no effect.
*
* @param term
* The terminal whose currently-open pipe stream should be closed.
*/
void guac_terminal_pipe_stream_close(guac_terminal* term);
/**
* Requests that the terminal write all output to a new pair of typescript
* files within the given path and using the given base name. Terminal output

View File

@ -28,7 +28,6 @@
* @file types.h
*/
#include "config.h"
#include "palette.h"
#include <stdbool.h>

View File

@ -28,7 +28,6 @@
* @file typescript.h
*/
#include "config.h"
#include <guacamole/timestamp.h>

View File

@ -26,9 +26,8 @@
* @file xparsecolor.h
*/
#include "config.h"
#include "terminal/palette.h"
#include "palette.h"
/**
* Parses an X11 color spec, as defined by Xlib's XParseColor(), storing the

View File

@ -17,7 +17,6 @@
* under the License.
*/
#include "config.h"
#include "common/io.h"
#include "terminal/typescript.h"

View File

@ -17,7 +17,6 @@
* under the License.
*/
#include "config.h"
#include "terminal/named-colors.h"
#include "terminal/palette.h"