GUACAMOLE-221: Allow callers to request that argument values be automatically echoed to all connected users.

This commit is contained in:
Michael Jumper 2020-07-01 18:09:13 -07:00
parent a8151c40c4
commit f8f2c7f747
4 changed files with 26 additions and 4 deletions

View File

@ -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 */

View File

@ -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

View File

@ -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

View File

@ -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