Skip to content

Commit

Permalink
Merge 1.5.4 changes back to master.
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-jumper committed Aug 29, 2023
2 parents 80598ae + 5e0fb22 commit eae2428
Show file tree
Hide file tree
Showing 46 changed files with 1,652 additions and 211 deletions.
14 changes: 11 additions & 3 deletions src/common/common/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ typedef struct guac_common_cursor {
*/
guac_timestamp timestamp;

/**
* Lock which restricts simultaneous access to the cursor, guaranteeing
* ordered modifications to the cursor and that incompatible operations
* do not occur simultaneously. This lock is for internal use within the
* cursor only.
*/
pthread_mutex_t _lock;

} guac_common_cursor;

/**
Expand Down Expand Up @@ -153,14 +161,14 @@ void guac_common_cursor_free(guac_common_cursor* cursor);
* @param cursor
* The cursor to send.
*
* @param user
* @param client
* The user receiving the updated cursor.
*
* @param socket
* The socket over which the updated cursor should be sent.
*/
void guac_common_cursor_dup(guac_common_cursor* cursor, guac_user* user,
guac_socket* socket);
void guac_common_cursor_dup(
guac_common_cursor* cursor, guac_client* client, guac_socket* socket);

/**
* Updates the current position and button state of the mouse cursor, marking
Expand Down
7 changes: 4 additions & 3 deletions src/common/common/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@ void guac_common_display_free(guac_common_display* display);
* @param display
* The display whose state should be sent along the given socket.
*
* @param user
* The user receiving the display state.
* @param client
* The client associated with the users receiving the display state.
*
* @param socket
* The socket over which the display state should be sent.
*/
void guac_common_display_dup(guac_common_display* display, guac_user* user,
void guac_common_display_dup(
guac_common_display* display, guac_client* client,
guac_socket* socket);

/**
Expand Down
16 changes: 15 additions & 1 deletion src/common/common/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,26 @@ typedef struct guac_common_list {
*/
guac_common_list* guac_common_list_alloc();

/**
* A handler that will be invoked with the data pointer of each element of
* the list when guac_common_list_free() is invoked.
*
* @param data
* The arbitrary data pointed to by the list element.
*/
typedef void guac_common_list_element_free_handler(void* data);

/**
* Frees the given list.
*
* @param list The list to free.
*
* @param free_element_handler
* A handler that will be invoked with each arbitrary data pointer in the
* list, if not NULL.
*/
void guac_common_list_free(guac_common_list* list);
void guac_common_list_free(guac_common_list* list,
guac_common_list_element_free_handler* free_element_handler);

/**
* Adds the given data to the list as a new element, returning the created
Expand Down
8 changes: 4 additions & 4 deletions src/common/common/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,14 +490,14 @@ void guac_common_surface_flush(guac_common_surface* surface);
* @param surface
* The surface to duplicate.
*
* @param user
* The user receiving the surface.
* @param client
* The client whos users are receiving the surface.
*
* @param socket
* The socket over which the surface contents should be sent.
*/
void guac_common_surface_dup(guac_common_surface* surface, guac_user* user,
guac_socket* socket);
void guac_common_surface_dup(guac_common_surface* surface,
guac_client* client, guac_socket* socket);

/**
* Declares that the given surface should receive touch events. By default,
Expand Down
27 changes: 24 additions & 3 deletions src/common/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <guacamole/timestamp.h>
#include <guacamole/user.h>

#include <pthread.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -74,12 +75,16 @@ guac_common_cursor* guac_common_cursor_alloc(guac_client* client) {
cursor->x = 0;
cursor->y = 0;

pthread_mutex_init(&(cursor->_lock), NULL);

return cursor;

}

void guac_common_cursor_free(guac_common_cursor* cursor) {

pthread_mutex_destroy(&(cursor->_lock));

guac_client* client = cursor->client;
guac_layer* buffer = cursor->buffer;
cairo_surface_t* surface = cursor->surface;
Expand All @@ -99,8 +104,10 @@ void guac_common_cursor_free(guac_common_cursor* cursor) {

}

void guac_common_cursor_dup(guac_common_cursor* cursor, guac_user* user,
guac_socket* socket) {
void guac_common_cursor_dup(
guac_common_cursor* cursor, guac_client* client, guac_socket* socket) {

pthread_mutex_lock(&(cursor->_lock));

/* Synchronize location */
guac_protocol_send_mouse(socket, cursor->x, cursor->y, cursor->button_mask,
Expand All @@ -111,14 +118,16 @@ void guac_common_cursor_dup(guac_common_cursor* cursor, guac_user* user,
guac_protocol_send_size(socket, cursor->buffer,
cursor->width, cursor->height);

guac_user_stream_png(user, socket, GUAC_COMP_SRC,
guac_client_stream_png(client, socket, GUAC_COMP_SRC,
cursor->buffer, 0, 0, cursor->surface);

guac_protocol_send_cursor(socket,
cursor->hotspot_x, cursor->hotspot_y,
cursor->buffer, 0, 0, cursor->width, cursor->height);
}

pthread_mutex_unlock(&(cursor->_lock));

guac_socket_flush(socket);

}
Expand Down Expand Up @@ -154,6 +163,8 @@ static void* guac_common_cursor_broadcast_state(guac_user* user,
void guac_common_cursor_update(guac_common_cursor* cursor, guac_user* user,
int x, int y, int button_mask) {

pthread_mutex_lock(&(cursor->_lock));

/* Update current user of cursor */
cursor->user = user;

Expand All @@ -169,6 +180,8 @@ void guac_common_cursor_update(guac_common_cursor* cursor, guac_user* user,
guac_client_foreach_user(cursor->client,
guac_common_cursor_broadcast_state, cursor);

pthread_mutex_unlock(&(cursor->_lock));

}

/**
Expand Down Expand Up @@ -212,6 +225,8 @@ static void guac_common_cursor_resize(guac_common_cursor* cursor,
void guac_common_cursor_set_argb(guac_common_cursor* cursor, int hx, int hy,
unsigned const char* data, int width, int height, int stride) {

pthread_mutex_lock(&(cursor->_lock));

/* Copy image data */
guac_common_cursor_resize(cursor, width, height, stride);
memcpy(cursor->image_buffer, data, height * stride);
Expand Down Expand Up @@ -242,6 +257,8 @@ void guac_common_cursor_set_argb(guac_common_cursor* cursor, int hx, int hy,

guac_socket_flush(cursor->client->socket);

pthread_mutex_unlock(&(cursor->_lock));

}

void guac_common_cursor_set_surface(guac_common_cursor* cursor, int hx, int hy,
Expand Down Expand Up @@ -298,9 +315,13 @@ void guac_common_cursor_set_blank(guac_common_cursor* cursor) {
void guac_common_cursor_remove_user(guac_common_cursor* cursor,
guac_user* user) {

pthread_mutex_lock(&(cursor->_lock));

/* Disassociate from given user */
if (cursor->user == user)
cursor->user = NULL;

pthread_mutex_unlock(&(cursor->_lock));

}

19 changes: 10 additions & 9 deletions src/common/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@
* The head element of the linked list of layers to synchronize, which may
* be NULL if the list is currently empty.
*
* @param user
* The user receiving the layers.
* @param client
* The client associated with the users receiving the layers.
*
* @param socket
* The socket over which each layer should be sent.
*/
static void guac_common_display_dup_layers(guac_common_display_layer* layers,
guac_user* user, guac_socket* socket) {
guac_client* client, guac_socket* socket) {

guac_common_display_layer* current = layers;

/* Synchronize all surfaces in given list */
while (current != NULL) {
guac_common_surface_dup(current->surface, user, socket);
guac_common_surface_dup(current->surface, client, socket);
current = current->next;
}

Expand Down Expand Up @@ -163,22 +163,23 @@ void guac_common_display_free(guac_common_display* display) {

}

void guac_common_display_dup(guac_common_display* display, guac_user* user,
void guac_common_display_dup(
guac_common_display* display, guac_client* client,
guac_socket* socket) {

guac_client* client = user->client;

pthread_mutex_lock(&display->_lock);

/* Sunchronize shared cursor */
guac_common_cursor_dup(display->cursor, user, socket);
guac_common_cursor_dup(display->cursor, client, socket);

/* Synchronize default surface */
guac_common_surface_dup(display->default_surface, user, socket);
guac_common_surface_dup(display->default_surface, client, socket);

/* Synchronize all layers and buffers */
guac_common_display_dup_layers(display->layers, user, socket);
guac_common_display_dup_layers(display->buffers, user, socket);
guac_common_display_dup_layers(display->layers, client, socket);
guac_common_display_dup_layers(display->buffers, client, socket);

/* Sends a sync instruction to mark the boundary of the first frame */
guac_protocol_send_sync(socket, client->last_sent_timestamp, 1);
Expand Down
20 changes: 19 additions & 1 deletion src/common/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,26 @@ guac_common_list* guac_common_list_alloc() {

}

void guac_common_list_free(guac_common_list* list) {
void guac_common_list_free(
guac_common_list* list,
guac_common_list_element_free_handler* free_element_handler) {

/* Free every element of the list */
guac_common_list_element* element = list->head;
while(element != NULL) {

guac_common_list_element* next = element->next;

if (free_element_handler != NULL)
free_element_handler(element->data);

free(element);
element = next;
}

/* Free the list itself */
free(list);

}

guac_common_list_element* guac_common_list_add(guac_common_list* list,
Expand Down
7 changes: 3 additions & 4 deletions src/common/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1989,8 +1989,8 @@ void guac_common_surface_flush(guac_common_surface* surface) {

}

void guac_common_surface_dup(guac_common_surface* surface, guac_user* user,
guac_socket* socket) {
void guac_common_surface_dup(guac_common_surface* surface,
guac_client* client, guac_socket* socket) {

pthread_mutex_lock(&surface->_lock);

Expand Down Expand Up @@ -2028,7 +2028,7 @@ void guac_common_surface_dup(guac_common_surface* surface, guac_user* user,
surface->width, surface->height, surface->stride);

/* Send PNG for rect */
guac_user_stream_png(user, socket, GUAC_COMP_OVER, surface->layer,
guac_client_stream_png(client, socket, GUAC_COMP_OVER, surface->layer,
0, 0, rect);
cairo_surface_destroy(rect);

Expand All @@ -2038,4 +2038,3 @@ void guac_common_surface_dup(guac_common_surface* surface, guac_user* user,
pthread_mutex_unlock(&surface->_lock);

}

7 changes: 4 additions & 3 deletions src/guacd/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@
static int __write_all(int fd, char* buffer, int length) {

/* Repeatedly write() until all data is written */
while (length > 0) {
int remaining_length = length;
while (remaining_length > 0) {

int written = write(fd, buffer, length);
int written = write(fd, buffer, remaining_length);
if (written < 0)
return -1;

length -= written;
remaining_length -= written;
buffer += written;

}
Expand Down
Loading

0 comments on commit eae2428

Please sign in to comment.