diff --git a/src/libguac/client.c b/src/libguac/client.c index 64404534..6f1c595b 100644 --- a/src/libguac/client.c +++ b/src/libguac/client.c @@ -478,6 +478,25 @@ int guac_client_load_plugin(guac_client* client, const char* protocol) { } +int guac_client_owner_send_required(guac_client* client, const char** required) { + + int retval; + + pthread_rwlock_rdlock(&(client->__users_lock)); + + /* Invoke callback with current owner */ + retval = guac_protocol_send_required(client->__owner->socket, required); + + /* Flush the socket */ + guac_socket_flush(client->__owner->socket); + + pthread_rwlock_unlock(&(client->__users_lock)); + + /* Return value from sending required */ + return retval; + +} + /** * Updates the provided approximate processing lag, taking into account the * processing lag of the given user. diff --git a/src/libguac/guacamole/client.h b/src/libguac/guacamole/client.h index 71d48f22..578fc593 100644 --- a/src/libguac/guacamole/client.h +++ b/src/libguac/guacamole/client.h @@ -549,6 +549,22 @@ int guac_client_load_plugin(guac_client* client, const char* protocol); */ int guac_client_get_processing_lag(guac_client* client); +/** + * Sends a request to the owner of the given guac_client for parameters required + * to continue the connection started by the client. The function returns zero + * on success or non-zero on failure. + * + * @param client + * The client where additional connection parameters are required. + * + * @param required + * The NULL-terminated array of required parameters. + * + * @return + * Zero on success, non-zero on failure. + */ +int guac_client_owner_send_required(guac_client* client, const char** required); + /** * Streams the given connection parameter value over an argument value stream * ("argv" instruction), exposing the current value of the named connection diff --git a/src/protocols/rdp/rdp.c b/src/protocols/rdp/rdp.c index 07e670e4..9c064c70 100644 --- a/src/protocols/rdp/rdp.c +++ b/src/protocols/rdp/rdp.c @@ -258,9 +258,8 @@ static BOOL rdp_freerdp_authenticate(freerdp* instance, char** username, pthread_mutex_lock(&(rdp_client->rdp_credential_lock)); /* Send require params and flush socket. */ - guac_socket_require_keep_alive(client->__owner->socket); - guac_protocol_send_required(client->__owner->socket, (const char**) params); - guac_socket_flush(client->__owner->socket); + guac_socket_require_keep_alive(client->socket); + guac_client_owner_send_required(client, (const char**) params); /* Wait for condition. */ pthread_cond_wait(&(rdp_client->rdp_credential_cond), &(rdp_client->rdp_credential_lock)); diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index 6179694e..23fbee0d 100644 --- a/src/protocols/ssh/ssh.c +++ b/src/protocols/ssh/ssh.c @@ -78,9 +78,8 @@ static void guac_ssh_get_credential(guac_client *client, char* cred_name) { pthread_mutex_lock(&(ssh_client->term_channel_lock)); /* Let the owner know what we require and flush the socket. */ - guac_socket_require_keep_alive(client->__owner->socket); - guac_protocol_send_required(client->__owner->socket, (const char* []) {cred_name, NULL}); - guac_socket_flush(client->__owner->socket); + guac_socket_require_keep_alive(client->socket); + guac_client_owner_send_required(client, (const char* []) {cred_name, NULL}); /* Wait for the response, and then unlock the thread. */ pthread_cond_wait(&(ssh_client->ssh_credential_cond), &(ssh_client->term_channel_lock)); diff --git a/src/protocols/vnc/auth.c b/src/protocols/vnc/auth.c index b5f93221..434e1c0a 100644 --- a/src/protocols/vnc/auth.c +++ b/src/protocols/vnc/auth.c @@ -42,10 +42,9 @@ char* guac_vnc_get_password(rfbClient* client) { pthread_mutex_lock(&(vnc_client->vnc_credential_lock)); /* Send the request for password and flush the socket. */ - guac_socket_require_keep_alive(gc->__owner->socket); - guac_protocol_send_required(gc->__owner->socket, + guac_socket_require_keep_alive(gc->socket); + guac_client_owner_send_required(gc, (const char* []) {GUAC_VNC_PARAMETER_NAME_PASSWORD, NULL}); - guac_socket_flush(gc->__owner->socket); /* Set the conditional flag. */ vnc_client->vnc_credential_flags |= GUAC_VNC_COND_FLAG_PASSWORD; @@ -93,8 +92,8 @@ rfbCredential* guac_vnc_get_credentials(rfbClient* client, int credentialType) { pthread_mutex_lock(&(vnc_client->vnc_credential_lock)); /* Send required parameters to client and flush the socket. */ - guac_protocol_send_required(gc->socket, (const char**) params); - guac_socket_flush(gc->socket); + guac_socket_require_keep_alive(gc->socket); + guac_client_owner_send_required(gc, (const char**) params); /* Wait for the parameters to be returned. */ pthread_cond_wait(&(vnc_client->vnc_credential_cond),