GUACAMOLE-1293: Move to status code plus arguments for msg instruction.

This commit is contained in:
Virtually Nick 2022-04-09 16:47:15 -04:00
parent 6d7156bc70
commit 26eadc37a3
4 changed files with 68 additions and 34 deletions

View File

@ -762,30 +762,31 @@ static void* guac_client_owner_notify_join_callback(guac_user* user, void* data)
const guac_user* joiner = (const guac_user *) data;
int retval = 0;
char* owner = "owner";
if (user->info.username != NULL)
char* owner = strdup("owner");
if (user->info.username != NULL) {
free(owner);
owner = strdup(user->info.username);
}
char* joinName = "anonymous";
if (joiner->info.username != NULL)
char* joinName = strdup("anonymous");
if (joiner->info.username != NULL) {
free(joinName);
joinName = strdup(joiner->info.username);
}
guac_user_log(user, GUAC_LOG_DEBUG, "Notifying %s of %s joining.", owner, joinName);
size_t msg_size = snprintf(NULL, 0, "User %s has joined the connection.", joinName);
char* msg = malloc(msg_size + 1);
sprintf(msg, "User %s has joined the connection.", joinName);
guac_user_log(user, GUAC_LOG_DEBUG, "Notifying owner %s of %s joining.", owner, joinName);
/* Send required parameters to owner. */
if (user != NULL)
retval = guac_protocol_send_msg(user->socket, msg);
if (user != NULL) {
const char* args[] = { (const char*)joinName, NULL };
retval = guac_protocol_send_msg(user->socket, GUAC_MSG_CLIENT_JOINED, args);
}
else
retval = -1;
free(owner);
free(joinName);
free(msg);
return (void*) ((intptr_t) retval);
@ -797,8 +798,6 @@ int guac_client_owner_notify_join(guac_client* client, guac_user* joiner) {
if (!guac_client_owner_supports_msg(client))
return -1;
guac_client_log(client, GUAC_LOG_DEBUG, "Notifying owner of %s joining.", joiner->user_id);
return (int) ((intptr_t) guac_client_for_owner(client, guac_client_owner_notify_join_callback, joiner));
}
@ -825,23 +824,28 @@ static void* guac_client_owner_notify_leave_callback(guac_user* user, void* data
const guac_user* quitter = (const guac_user *) data;
char* owner = "owner";
if (user->info.username != NULL)
owner = strdup(user->info.username);
char* ownerName = strdup("owner");
if (user->info.username != NULL) {
free(ownerName);
ownerName = strdup(user->info.username);
}
char* quitterName = "anonymous";
if (quitter->info.username != NULL)
char* quitterName = strdup("anonymous");
if (quitter->info.username != NULL) {
free(quitterName);
quitterName = strdup(quitter->info.username);
}
guac_user_log(user, GUAC_LOG_DEBUG, "Notifying %s of %s leaving.", owner, quitterName);
size_t msg_size = snprintf(NULL, 0, "User %s has left the connection.", quitterName);
char* msg = malloc(msg_size + 1);
sprintf(msg, "User %s has left the connection.", quitterName);
guac_user_log(user, GUAC_LOG_DEBUG, "Notifying owner %s of %s leaving.", ownerName, quitterName);
/* Send required parameters to owner. */
if (user != NULL)
return (void*) ((intptr_t) guac_protocol_send_msg(user->socket, msg));
if (user != NULL) {
const char* args[] = { (const char*)quitterName, NULL };
return (void*) ((intptr_t) guac_protocol_send_msg(user->socket, GUAC_MSG_CLIENT_LEFT, args));
}
free(ownerName);
free(quitterName);
return (void*) ((intptr_t) -1);
@ -853,8 +857,6 @@ int guac_client_owner_notify_leave(guac_client* client, guac_user* quitter) {
if (!guac_client_owner_supports_msg(client))
return -1;
guac_client_log(client, GUAC_LOG_DEBUG, "Notifying owner of %s leaving.", quitter->user_id);
return (int) ((intptr_t) guac_client_for_owner(client, guac_client_owner_notify_leave_callback, quitter));
}

View File

@ -310,12 +310,36 @@ typedef enum guac_protocol_version {
/**
* Protocol version 1.5.0, which supports the "msg" instruction, allowing
* messages to be sent to the client, and adds support for the "name"
* messages to be sent to the client, and adds support for the "username"
* handshake instruction.
*/
GUAC_PROTOCOL_VERSION_1_5_0 = 0x010500
} guac_protocol_version;
/**
* A type that represents codes for human-readable messages sent by the "msg"
* instruction to the Client, that will be displayed in the client's browser.
* The codes will be interpreted by the client into translatable messages, and
* make take arguments, as noted below.
*/
typedef enum guac_msg_client {
/**
* A message that notifies the owner of a connection that another user has
* joined their connection. There should be a single argument, the username
* of the user who has joined.
*/
GUAC_MSG_CLIENT_JOINED = 0x0001,
/**
* A message that notifies the owner of a connection that another user has
* left their connection. There should be a single argument provided, the
* username of the user who has left.
*/
GUAC_MSG_CLIENT_LEFT = 0x0002
} guac_msg_client;
#endif

View File

@ -178,13 +178,19 @@ int vguac_protocol_send_log(guac_socket* socket, const char* format,
* @param socket
* The guac_socket connection to send the message to.
*
* @param message
* The message to send to the client.
* @param msg
* The message code to send to the client.
*
* @param args
* A null-terminated array of strings that will be provided to the client
* as part of the message, that the client may then place in the message,
* or null if the message requires no arguments.
*
* @return
* Zero if the message is sent successfully; otherwise non-zero.
*/
int guac_protocol_send_msg(guac_socket* socket, const char* message);
int guac_protocol_send_msg(guac_socket* socket, guac_msg_client msg,
const char** args);
/**
* Sends a mouse instruction over the given guac_socket connection.

View File

@ -659,14 +659,16 @@ int guac_protocol_send_log(guac_socket* socket, const char* format, ...) {
}
int guac_protocol_send_msg(guac_socket* socket, const char* message) {
int guac_protocol_send_msg(guac_socket* socket, guac_msg_client msg,
const char** args) {
int ret_val;
guac_socket_instruction_begin(socket);
ret_val =
guac_socket_write_string(socket, "3.msg,")
|| __guac_socket_write_length_string(socket, message)
|| __guac_socket_write_length_int(socket, msg)
|| guac_socket_write_array(socket, args)
|| guac_socket_write_string(socket, ";");
guac_socket_instruction_end(socket);