GUAC-743: Store and maintain connections within the client map structure.

This commit is contained in:
Michael Jumper 2014-07-05 13:26:27 -07:00
parent 02d493c9e5
commit d9e7ebde2f

View File

@ -23,6 +23,7 @@
#include "config.h" #include "config.h"
#include "client.h" #include "client.h"
#include "client-map.h"
#include "log.h" #include "log.h"
#include <guacamole/client.h> #include <guacamole/client.h>
@ -56,7 +57,11 @@
#define GUACD_DEV_NULL "/dev/null" #define GUACD_DEV_NULL "/dev/null"
#define GUACD_ROOT "/" #define GUACD_ROOT "/"
void guacd_handle_connection(guac_socket* socket) { /**
* Creates a new guac_client for the connection on the given socket, adding
* it to the client map based on its ID.
*/
static void guacd_handle_connection(guacd_client_map* map, guac_socket* socket) {
guac_client* client; guac_client* client;
guac_client_plugin* plugin; guac_client_plugin* plugin;
@ -216,6 +221,10 @@ void guacd_handle_connection(guac_socket* socket) {
sizeof(char*) * video->argc); sizeof(char*) * video->argc);
client->info.video_mimetypes[video->argc] = NULL; client->info.video_mimetypes[video->argc] = NULL;
/* Store client */
if (guacd_client_map_add(map, client))
guacd_log_error("Unable to add client. Internal client storage has failed");
/* Send connection ID */ /* Send connection ID */
guacd_log_info("Connection ID is \"%s\"", client->connection_id); guacd_log_info("Connection ID is \"%s\"", client->connection_id);
guac_protocol_send_ready(socket, client->connection_id); guac_protocol_send_ready(socket, client->connection_id);
@ -247,6 +256,10 @@ void guacd_handle_connection(guac_socket* socket) {
else else
guacd_log_info("Client finished normally"); guacd_log_info("Client finished normally");
/* Remove client */
if (guacd_client_map_remove(map, client->connection_id) == NULL)
guacd_log_error("Unable to remove client. Internal client storage has failed");
/* Free mimetype lists */ /* Free mimetype lists */
free(client->info.audio_mimetypes); free(client->info.audio_mimetypes);
free(client->info.video_mimetypes); free(client->info.video_mimetypes);
@ -376,6 +389,8 @@ int main(int argc, char* argv[]) {
SSL_CTX* ssl_context = NULL; SSL_CTX* ssl_context = NULL;
#endif #endif
guacd_client_map* map = guacd_client_map_alloc();
/* General */ /* General */
int retval; int retval;
@ -645,7 +660,7 @@ int main(int argc, char* argv[]) {
socket = guac_socket_open(connected_socket_fd); socket = guac_socket_open(connected_socket_fd);
#endif #endif
guacd_handle_connection(socket); guacd_handle_connection(map, socket);
close(connected_socket_fd); close(connected_socket_fd);
return 0; return 0;
} }