diff --git a/src/common/guac_cursor.c b/src/common/guac_cursor.c index e376ab03..4ed66b1d 100644 --- a/src/common/guac_cursor.c +++ b/src/common/guac_cursor.c @@ -367,3 +367,12 @@ void guac_common_cursor_set_blank(guac_common_cursor* cursor) { } +void guac_common_cursor_remove_user(guac_common_cursor* cursor, + guac_user* user) { + + /* Disassociate from given user */ + if (cursor->user == user) + cursor->user = NULL; + +} + diff --git a/src/common/guac_cursor.h b/src/common/guac_cursor.h index ae359b7f..9db7067d 100644 --- a/src/common/guac_cursor.h +++ b/src/common/guac_cursor.h @@ -249,4 +249,19 @@ void guac_common_cursor_set_ibar(guac_common_cursor* cursor); */ void guac_common_cursor_set_blank(guac_common_cursor* cursor); +/** + * Removes the given user, such that future synchronization will not occur. + * This is necessary when a user leaves the connection. If a user leaves the + * connection and this is not called, the corresponding guac_user and socket + * may cease to be valid, and future synchronization attempts will segfault. + * + * @param cursor + * The cursor to remove the user from. + * + * @param user + * The user to remove. + */ +void guac_common_cursor_remove_user(guac_common_cursor* cursor, + guac_user* user); + #endif diff --git a/src/protocols/vnc/user.c b/src/protocols/vnc/user.c index 0b89d7c9..53423a11 100644 --- a/src/protocols/vnc/user.c +++ b/src/protocols/vnc/user.c @@ -97,3 +97,12 @@ int guac_vnc_user_join_handler(guac_user* user, int argc, char** argv) { } +int guac_vnc_user_leave_handler(guac_user* user) { + + guac_vnc_client* vnc_client = (guac_vnc_client*) user->client->data; + + guac_common_cursor_remove_user(vnc_client->display->cursor, user); + + return 0; +} + diff --git a/src/protocols/vnc/user.h b/src/protocols/vnc/user.h index 125e4965..e74b2a05 100644 --- a/src/protocols/vnc/user.h +++ b/src/protocols/vnc/user.h @@ -29,5 +29,10 @@ */ guac_user_join_handler guac_vnc_user_join_handler; +/** + * Handler for leaving users. + */ +guac_user_leave_handler guac_vnc_user_leave_handler; + #endif