GUACAMOLE-559: Guarantee ordered modification to the clipboard. Do not allow modification of clipboard while clipboard contents are being sent.
This commit is contained in:
parent
860a5fca8f
commit
4f25410aa9
@ -24,6 +24,7 @@
|
||||
#include <guacamole/protocol.h>
|
||||
#include <guacamole/stream.h>
|
||||
#include <guacamole/user.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -37,6 +38,8 @@ guac_common_clipboard* guac_common_clipboard_alloc(int size) {
|
||||
clipboard->length = 0;
|
||||
clipboard->available = size;
|
||||
|
||||
pthread_mutex_init(&(clipboard->lock), NULL);
|
||||
|
||||
return clipboard;
|
||||
|
||||
}
|
||||
@ -108,18 +111,37 @@ static void* __send_user_clipboard(guac_user* user, void* data) {
|
||||
}
|
||||
|
||||
void guac_common_clipboard_send(guac_common_clipboard* clipboard, guac_client* client) {
|
||||
|
||||
pthread_mutex_lock(&(clipboard->lock));
|
||||
|
||||
guac_client_log(client, GUAC_LOG_DEBUG, "Broadcasting clipboard to all connected users.");
|
||||
guac_client_foreach_user(client, __send_user_clipboard, clipboard);
|
||||
guac_client_log(client, GUAC_LOG_DEBUG, "Broadcast of clipboard complete.");
|
||||
|
||||
pthread_mutex_unlock(&(clipboard->lock));
|
||||
|
||||
}
|
||||
|
||||
void guac_common_clipboard_reset(guac_common_clipboard* clipboard, const char* mimetype) {
|
||||
void guac_common_clipboard_reset(guac_common_clipboard* clipboard,
|
||||
const char* mimetype) {
|
||||
|
||||
pthread_mutex_lock(&(clipboard->lock));
|
||||
|
||||
/* Clear clipboard contents */
|
||||
clipboard->length = 0;
|
||||
strncpy(clipboard->mimetype, mimetype, sizeof(clipboard->mimetype)-1);
|
||||
|
||||
/* Assign given mimetype */
|
||||
strncpy(clipboard->mimetype, mimetype, sizeof(clipboard->mimetype) - 1);
|
||||
clipboard->mimetype[sizeof(clipboard->mimetype) - 1] = '\0';
|
||||
|
||||
pthread_mutex_unlock(&(clipboard->lock));
|
||||
|
||||
}
|
||||
|
||||
void guac_common_clipboard_append(guac_common_clipboard* clipboard, const char* data, int length) {
|
||||
|
||||
pthread_mutex_lock(&(clipboard->lock));
|
||||
|
||||
/* Truncate data to available length */
|
||||
int remaining = clipboard->available - clipboard->length;
|
||||
if (remaining < length)
|
||||
@ -131,5 +153,7 @@ void guac_common_clipboard_append(guac_common_clipboard* clipboard, const char*
|
||||
/* Update length */
|
||||
clipboard->length += length;
|
||||
|
||||
pthread_mutex_unlock(&(clipboard->lock));
|
||||
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
#include <pthread.h>
|
||||
|
||||
/**
|
||||
* The maximum number of bytes to send in an individual blob when
|
||||
@ -35,6 +36,13 @@
|
||||
*/
|
||||
typedef struct guac_common_clipboard {
|
||||
|
||||
/**
|
||||
* Lock which restricts simultaneous access to the clipboard, guaranteeing
|
||||
* ordered modifications to the clipboard and that changes to the clipboard
|
||||
* are not allowed while the clipboard is being broadcast to all users.
|
||||
*/
|
||||
pthread_mutex_t lock;
|
||||
|
||||
/**
|
||||
* The mimetype of the contained clipboard data.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user