mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
Initial connect message implementation
This commit is contained in:
@@ -58,7 +58,19 @@ typedef struct guac_instruction {
|
||||
|
||||
|
||||
/**
|
||||
* Frees all memory allocated to the given instruction.
|
||||
* Frees all memory allocated to the given instruction opcode
|
||||
* and arguments. The instruction structure itself will not
|
||||
* be freed.
|
||||
*
|
||||
* @param instruction The instruction to free.
|
||||
*/
|
||||
void guac_free_instruction_data(guac_instruction* instruction);
|
||||
|
||||
|
||||
/**
|
||||
* Frees all memory allocated to the given instruction. This
|
||||
* includes freeing memory allocated for the structure
|
||||
* itself.
|
||||
*
|
||||
* @param instruction The instruction to free.
|
||||
*/
|
||||
|
@@ -76,7 +76,6 @@ guac_client* guac_get_client(int client_fd) {
|
||||
GUACIO* io = guac_open(client_fd);
|
||||
|
||||
/* Pluggable client */
|
||||
char* protocol;
|
||||
char protocol_lib[256] = "libguac_client_";
|
||||
|
||||
union {
|
||||
@@ -86,9 +85,34 @@ guac_client* guac_get_client(int client_fd) {
|
||||
|
||||
char* error;
|
||||
|
||||
/* Client arguments */
|
||||
int argc;
|
||||
char** argv;
|
||||
|
||||
/* Connect instruction */
|
||||
guac_instruction instruction;
|
||||
|
||||
/* Wait for connect instruction */
|
||||
for (;;) {
|
||||
|
||||
int result = guac_read_instruction(io, &instruction);
|
||||
if (result < 0) {
|
||||
syslog(LOG_ERR, "Error reading instruction while waiting for connect");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Connect instruction read */
|
||||
if (result > 0 && strcmp(instruction.opcode, "connect") == 0) {
|
||||
|
||||
/* Get protocol from message */
|
||||
char* protocol = instruction.argv[0];
|
||||
|
||||
strcat(protocol_lib, protocol);
|
||||
strcat(protocol_lib, ".so");
|
||||
|
||||
/* Create new client */
|
||||
client = __guac_alloc_client(io);
|
||||
|
||||
/* Load client plugin */
|
||||
client->client_plugin_handle = dlopen(protocol_lib, RTLD_LAZY);
|
||||
if (!(client->client_plugin_handle)) {
|
||||
@@ -106,13 +130,20 @@ guac_client* guac_get_client(int client_fd) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Initialize client arguments */
|
||||
argc = instruction.argc;
|
||||
argv = instruction.argv;
|
||||
|
||||
/* Create new client */
|
||||
client = __guac_alloc_client(io);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (alias.client_init(client, argc, argv) != 0)
|
||||
return NULL;
|
||||
|
||||
guac_free_instruction_data(&instruction);
|
||||
|
||||
return client;
|
||||
|
||||
}
|
||||
@@ -179,6 +210,7 @@ void guac_start_client(guac_client* client) {
|
||||
) {
|
||||
|
||||
syslog(LOG_ERR, "Error handling mouse instruction");
|
||||
guac_free_instruction_data(&instruction);
|
||||
return;
|
||||
|
||||
}
|
||||
@@ -195,6 +227,7 @@ void guac_start_client(guac_client* client) {
|
||||
) {
|
||||
|
||||
syslog(LOG_ERR, "Error handling key instruction");
|
||||
guac_free_instruction_data(&instruction);
|
||||
return;
|
||||
|
||||
}
|
||||
@@ -210,6 +243,7 @@ void guac_start_client(guac_client* client) {
|
||||
) {
|
||||
|
||||
syslog(LOG_ERR, "Error handling clipboard instruction");
|
||||
guac_free_instruction_data(&instruction);
|
||||
return;
|
||||
|
||||
}
|
||||
@@ -217,9 +251,12 @@ void guac_start_client(guac_client* client) {
|
||||
|
||||
else if (strcmp(instruction.opcode, "disconnect") == 0) {
|
||||
syslog(LOG_INFO, "Client requested disconnect");
|
||||
guac_free_instruction_data(&instruction);
|
||||
return;
|
||||
}
|
||||
|
||||
guac_free_instruction_data(&instruction);
|
||||
|
||||
} while ((retval = guac_read_instruction(io, &instruction)) > 0);
|
||||
|
||||
if (retval < 0) {
|
||||
|
@@ -441,12 +441,15 @@ int guac_read_instruction(GUACIO* io, guac_instruction* parsed_instruction) {
|
||||
|
||||
}
|
||||
|
||||
void guac_free_instruction(guac_instruction* instruction) {
|
||||
void guac_free_instruction_data(guac_instruction* instruction) {
|
||||
free(instruction->opcode);
|
||||
|
||||
if (instruction->argv)
|
||||
free(instruction->argv);
|
||||
}
|
||||
|
||||
void guac_free_instruction(guac_instruction* instruction) {
|
||||
guac_free_instruction_data(instruction);
|
||||
free(instruction);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user