GUACAMOLE-1293: Move to status code plus arguments for msg instruction.
This commit is contained in:
parent
6d7156bc70
commit
26eadc37a3
@ -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;
|
const guac_user* joiner = (const guac_user *) data;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
char* owner = "owner";
|
char* owner = strdup("owner");
|
||||||
if (user->info.username != NULL)
|
if (user->info.username != NULL) {
|
||||||
|
free(owner);
|
||||||
owner = strdup(user->info.username);
|
owner = strdup(user->info.username);
|
||||||
|
}
|
||||||
|
|
||||||
char* joinName = "anonymous";
|
char* joinName = strdup("anonymous");
|
||||||
if (joiner->info.username != NULL)
|
if (joiner->info.username != NULL) {
|
||||||
|
free(joinName);
|
||||||
joinName = strdup(joiner->info.username);
|
joinName = strdup(joiner->info.username);
|
||||||
|
}
|
||||||
|
|
||||||
guac_user_log(user, GUAC_LOG_DEBUG, "Notifying %s of %s joining.", owner, joinName);
|
guac_user_log(user, GUAC_LOG_DEBUG, "Notifying owner %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);
|
|
||||||
|
|
||||||
/* Send required parameters to owner. */
|
/* Send required parameters to owner. */
|
||||||
if (user != NULL)
|
if (user != NULL) {
|
||||||
retval = guac_protocol_send_msg(user->socket, msg);
|
const char* args[] = { (const char*)joinName, NULL };
|
||||||
|
retval = guac_protocol_send_msg(user->socket, GUAC_MSG_CLIENT_JOINED, args);
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
retval = -1;
|
retval = -1;
|
||||||
|
|
||||||
free(owner);
|
free(owner);
|
||||||
free(joinName);
|
free(joinName);
|
||||||
free(msg);
|
|
||||||
|
|
||||||
return (void*) ((intptr_t) retval);
|
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))
|
if (!guac_client_owner_supports_msg(client))
|
||||||
return -1;
|
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));
|
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;
|
const guac_user* quitter = (const guac_user *) data;
|
||||||
|
|
||||||
char* owner = "owner";
|
char* ownerName = strdup("owner");
|
||||||
if (user->info.username != NULL)
|
if (user->info.username != NULL) {
|
||||||
owner = strdup(user->info.username);
|
free(ownerName);
|
||||||
|
ownerName = strdup(user->info.username);
|
||||||
|
}
|
||||||
|
|
||||||
char* quitterName = "anonymous";
|
char* quitterName = strdup("anonymous");
|
||||||
if (quitter->info.username != NULL)
|
if (quitter->info.username != NULL) {
|
||||||
|
free(quitterName);
|
||||||
quitterName = strdup(quitter->info.username);
|
quitterName = strdup(quitter->info.username);
|
||||||
|
}
|
||||||
|
|
||||||
guac_user_log(user, GUAC_LOG_DEBUG, "Notifying %s of %s leaving.", owner, quitterName);
|
guac_user_log(user, GUAC_LOG_DEBUG, "Notifying owner %s of %s leaving.", ownerName, 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);
|
|
||||||
|
|
||||||
/* Send required parameters to owner. */
|
/* Send required parameters to owner. */
|
||||||
if (user != NULL)
|
if (user != NULL) {
|
||||||
return (void*) ((intptr_t) guac_protocol_send_msg(user->socket, msg));
|
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);
|
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))
|
if (!guac_client_owner_supports_msg(client))
|
||||||
return -1;
|
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));
|
return (int) ((intptr_t) guac_client_for_owner(client, guac_client_owner_notify_leave_callback, quitter));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -310,12 +310,36 @@ typedef enum guac_protocol_version {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Protocol version 1.5.0, which supports the "msg" instruction, allowing
|
* 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.
|
* handshake instruction.
|
||||||
*/
|
*/
|
||||||
GUAC_PROTOCOL_VERSION_1_5_0 = 0x010500
|
GUAC_PROTOCOL_VERSION_1_5_0 = 0x010500
|
||||||
|
|
||||||
} guac_protocol_version;
|
} 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
|
#endif
|
||||||
|
|
||||||
|
@ -178,13 +178,19 @@ int vguac_protocol_send_log(guac_socket* socket, const char* format,
|
|||||||
* @param socket
|
* @param socket
|
||||||
* The guac_socket connection to send the message to.
|
* The guac_socket connection to send the message to.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param msg
|
||||||
* The message to send to the client.
|
* 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
|
* @return
|
||||||
* Zero if the message is sent successfully; otherwise non-zero.
|
* 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.
|
* Sends a mouse instruction over the given guac_socket connection.
|
||||||
|
@ -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;
|
int ret_val;
|
||||||
|
|
||||||
guac_socket_instruction_begin(socket);
|
guac_socket_instruction_begin(socket);
|
||||||
ret_val =
|
ret_val =
|
||||||
guac_socket_write_string(socket, "3.msg,")
|
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_write_string(socket, ";");
|
||||||
|
|
||||||
guac_socket_instruction_end(socket);
|
guac_socket_instruction_end(socket);
|
||||||
|
Loading…
Reference in New Issue
Block a user