mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Moved client registry into own separate UUID-tree datatype, added client registry struct, migrated dependencies
This commit is contained in:
@@ -26,122 +26,6 @@
|
||||
#include "protocol.h"
|
||||
#include "client.h"
|
||||
|
||||
/* TODO: Make registry thread-safe */
|
||||
|
||||
guac_client_registry_node* guac_create_client_registry() {
|
||||
|
||||
guac_client_registry_node* registry = malloc(sizeof(guac_client_registry_node));
|
||||
|
||||
registry->used = 0;
|
||||
memset(registry->next, 0, sizeof(registry->next));
|
||||
|
||||
return registry;
|
||||
|
||||
}
|
||||
|
||||
void guac_register_client(guac_client_registry_node* registry, guac_client* client) {
|
||||
|
||||
guac_client_registry_node* current = registry;
|
||||
int i;
|
||||
unsigned char index;
|
||||
|
||||
for (i=0; i<sizeof(uuid_t)-1; i++) {
|
||||
|
||||
guac_client_registry_node* next;
|
||||
|
||||
/* Get next registry node */
|
||||
index = ((unsigned char*) client->uuid)[i];
|
||||
next = ((guac_client_registry_node**) current->next)[index];
|
||||
|
||||
/* If no node, allocate one */
|
||||
if (next == NULL) {
|
||||
current->used++;
|
||||
next = guac_create_client_registry();
|
||||
((guac_client_registry_node**) current->next)[index] = next;
|
||||
}
|
||||
|
||||
current = next;
|
||||
}
|
||||
|
||||
/* Register client */
|
||||
index = ((unsigned char*) client->uuid)[i];
|
||||
((guac_client**) current->next)[index] = client;
|
||||
|
||||
}
|
||||
|
||||
guac_client* guac_find_client(guac_client_registry_node* registry, uuid_t uuid) {
|
||||
|
||||
guac_client_registry_node* current = registry;
|
||||
int i;
|
||||
unsigned char index;
|
||||
|
||||
for (i=0; i<sizeof(uuid_t)-1; i++) {
|
||||
|
||||
/* Get next registry node */
|
||||
index = ((unsigned char*) uuid)[i];
|
||||
current = ((guac_client_registry_node**) current->next)[index];
|
||||
|
||||
/* If no node, client not registered */
|
||||
if (current == NULL)
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
/* Return client found (if any) */
|
||||
index = ((unsigned char*) uuid)[i];
|
||||
return ((guac_client**) current->next)[index];
|
||||
|
||||
}
|
||||
|
||||
void guac_remove_client(guac_client_registry_node* registry, guac_client* client) {
|
||||
|
||||
guac_client_registry_node* current = registry;
|
||||
int i;
|
||||
unsigned char index;
|
||||
|
||||
for (i=0; i<sizeof(uuid_t)-1; i++) {
|
||||
|
||||
/* Get next registry node */
|
||||
index = ((unsigned char*) client->uuid)[i];
|
||||
current = ((guac_client_registry_node**) current->next)[index];
|
||||
|
||||
/* If no node, client not registered */
|
||||
if (current == NULL)
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/* Remove client, if registered */
|
||||
if (((guac_client**) current->next)[index]) {
|
||||
((guac_client**) current->next)[index] = NULL;
|
||||
current->used--;
|
||||
|
||||
/* FIXME: If no more clients at this node, clean up */
|
||||
if (current->used == 0) {
|
||||
/* STUB */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void guac_cleanup_client_registry(guac_client_registry_node* registry) {
|
||||
|
||||
int i;
|
||||
for (i=0; i<sizeof(registry->next); i++) {
|
||||
|
||||
if (registry->next[i] != NULL) {
|
||||
guac_cleanup_client_registry(registry->next[i]);
|
||||
registry->next[i] = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
free(registry);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
png_byte** guac_alloc_png_buffer(int w, int h, int bpp) {
|
||||
|
||||
@@ -183,7 +67,7 @@ guac_client* __guac_alloc_client(GUACIO* io) {
|
||||
}
|
||||
|
||||
|
||||
guac_client* guac_get_client(int client_fd, guac_client_registry_node* registry, guac_client_init_handler* client_init, int argc, char** argv) {
|
||||
guac_client* guac_get_client(int client_fd, guac_client_registry* registry, guac_client_init_handler* client_init, int argc, char** argv) {
|
||||
|
||||
guac_client* client;
|
||||
GUACIO* io = guac_open(client_fd);
|
||||
@@ -247,14 +131,14 @@ guac_client* guac_get_client(int client_fd, guac_client_registry_node* registry,
|
||||
}
|
||||
|
||||
|
||||
void guac_free_client(guac_client* client, guac_client_registry_node* registry) {
|
||||
void guac_free_client(guac_client* client, guac_client_registry* registry) {
|
||||
|
||||
if (client->free_handler)
|
||||
client->free_handler(client);
|
||||
|
||||
guac_close(client->io);
|
||||
|
||||
guac_remove_client(registry, client);
|
||||
guac_remove_client(registry, client->uuid);
|
||||
|
||||
free(client);
|
||||
}
|
||||
|
Reference in New Issue
Block a user