From f8f2c7f7472b87ac95814ae53649e3ee3413ba08 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 1 Jul 2020 18:09:13 -0700 Subject: [PATCH] GUACAMOLE-221: Allow callers to request that argument values be automatically echoed to all connected users. --- src/libguac/argv.c | 14 ++++++++++++-- src/libguac/guacamole/argv-constants.h | 7 +++++++ src/libguac/guacamole/argv-fntypes.h | 6 +++++- src/libguac/guacamole/argv.h | 3 ++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/libguac/argv.c b/src/libguac/argv.c index 893ffffe..a4462c4c 100644 --- a/src/libguac/argv.c +++ b/src/libguac/argv.c @@ -20,6 +20,7 @@ #include "config.h" #include "guacamole/argv.h" +#include "guacamole/client.h" #include "guacamole/protocol.h" #include "guacamole/socket.h" #include "guacamole/stream.h" @@ -51,7 +52,7 @@ typedef struct guac_argv_state { /** * Bitwise OR of all option flags that should affect processing of this - * argument. The only current flag is GUAC_ARGV_OPTION_ONCE. + * argument. */ int options; @@ -243,6 +244,8 @@ static int guac_argv_blob_handler(guac_user* user, guac_stream* stream, */ static int guac_argv_end_handler(guac_user* user, guac_stream* stream) { + int result = 0; + /* Append null terminator to value */ guac_argv* argv = (guac_argv*) stream->data; argv->buffer[argv->length] = '\0'; @@ -254,7 +257,14 @@ static int guac_argv_end_handler(guac_user* user, guac_stream* stream) { guac_argv_state* state = argv->state; if (!(state->options & GUAC_ARGV_OPTION_ONCE) || !state->received) { if (state->callback != NULL) - state->callback(user, argv->mimetype, state->name, argv->buffer, state->data); + result = state->callback(user, argv->mimetype, state->name, argv->buffer, state->data); + } + + /* Alert connected clients regarding newly-accepted values if echo is + * enabled */ + if (!result && (state->options & GUAC_ARGV_OPTION_ECHO)) { + guac_client* client = user->client; + guac_client_stream_argv(client, client->socket, argv->mimetype, state->name, argv->buffer); } /* Notify that argument has been received */ diff --git a/src/libguac/guacamole/argv-constants.h b/src/libguac/guacamole/argv-constants.h index 88402299..a244a156 100644 --- a/src/libguac/guacamole/argv-constants.h +++ b/src/libguac/guacamole/argv-constants.h @@ -34,6 +34,13 @@ */ #define GUAC_ARGV_OPTION_ONCE 1 +/** + * Option flag which declares to guac_argv_register() that the values received + * and accepted for the associated argument should be echoed to all connected + * users via outbound "argv" streams. + */ +#define GUAC_ARGV_OPTION_ECHO 2 + /** * The maximum number of bytes to allow for any argument value received via an * argv stream and processed using guac_argv_received(), including null diff --git a/src/libguac/guacamole/argv-fntypes.h b/src/libguac/guacamole/argv-fntypes.h index d8c49e60..bf4ff374 100644 --- a/src/libguac/guacamole/argv-fntypes.h +++ b/src/libguac/guacamole/argv-fntypes.h @@ -50,8 +50,12 @@ * @param data * Any arbitrary data that was provided when the received argument was * registered with guac_argv_register(). + * + * @return + * Zero if the received argument value has been accepted and has either + * taken effect or is being intentionally ignored, non-zero otherwise. */ -typedef void guac_argv_callback(guac_user* user, const char* mimetype, +typedef int guac_argv_callback(guac_user* user, const char* mimetype, const char* name, const char* value, void* data); #endif diff --git a/src/libguac/guacamole/argv.h b/src/libguac/guacamole/argv.h index e2d60921..3cc4806e 100644 --- a/src/libguac/guacamole/argv.h +++ b/src/libguac/guacamole/argv.h @@ -43,6 +43,7 @@ * @see GUAC_ARGV_MAX_REGISTERED * * @see GUAC_ARGV_OPTION_ONCE + * @see GUAC_ARGV_OPTION_ECHO * * @param name * The name of the argument that should be handled by the given callback. @@ -57,7 +58,7 @@ * * @param options * Bitwise OR of all option flags that should affect processing of this - * argument. The only current flag is GUAC_ARGV_OPTION_ONCE. + * argument. * * @return * Zero if the callback was successfully registered, non-zero if the