diff --git a/guacamole/proxy/protocol.c b/guacamole/proxy/protocol.c index f390c7fae..76681d9f7 100644 --- a/guacamole/proxy/protocol.c +++ b/guacamole/proxy/protocol.c @@ -207,6 +207,9 @@ guac_instruction* guac_read_instruction(GUACIO* io) { guac_instruction* parsed_instruction; int retval; int i = 0; + int argcount = 0; + int j; + int current_arg = 0; /* Loop until a instruction is read */ for (;;) { @@ -214,7 +217,14 @@ guac_instruction* guac_read_instruction(GUACIO* io) { /* Search for end of instruction */ for (; i < io->instructionbuf_used_length; i++) { - if (io->instructionbuf[i] == ';') { + /* Count arguments as we look for the end */ + if (io->instructionbuf[i] == ',') + argcount++; + else if (io->instructionbuf[i] == ':' && argcount == 0) + argcount++; + + /* End found ... */ + else if (io->instructionbuf[i] == ';') { /* Parse new instruction */ char* instruction = malloc(i+1); @@ -222,9 +232,30 @@ guac_instruction* guac_read_instruction(GUACIO* io) { instruction[i] = '\0'; /* Replace semicolon with null terminator. */ parsed_instruction = malloc(sizeof(guac_instruction)); - parsed_instruction->opcode = instruction; - parsed_instruction->argc = 0; - parsed_instruction->argv = NULL; + parsed_instruction->opcode = NULL; + + parsed_instruction->argc = argcount; + parsed_instruction->argv = malloc(sizeof(char*) * argcount); + + for (j=0; jopcode == NULL) { + instruction[j] = '\0'; + parsed_instruction->argv[current_arg++] = &(instruction[j+1]); + parsed_instruction->opcode = instruction; + } + + /* If encountered a comma, set following argument */ + else if (instruction[j] == ',') { + instruction[j] = '\0'; + parsed_instruction->argv[current_arg++] = &(instruction[j+1]); + } + } + + /* If no arguments, set opcode to entire instruction */ + if (parsed_instruction->opcode == NULL) + parsed_instruction->opcode = instruction; /* Found. Reset buffer */ memmove(io->instructionbuf, io->instructionbuf + i + 1, io->instructionbuf_used_length - i - 1); diff --git a/guacamole/proxy/proxy.c b/guacamole/proxy/proxy.c index af21203aa..f29b31ca9 100644 --- a/guacamole/proxy/proxy.c +++ b/guacamole/proxy/proxy.c @@ -181,9 +181,27 @@ void proxy(int client_fd) { wait_result = guac_instructions_waiting(io); if (wait_result > 0) { - guac_instruction* instruction = guac_read_instruction(io); - if (instruction) { - fprintf(stderr, "NEW READ INSTRUCTION: %s\n", instruction->opcode); + guac_instruction* instruction; + + while ((instruction = guac_read_instruction(io))) { + + if (strcmp(instruction->opcode, "mouse") == 0) { + SendPointerEvent( + rfb_client, + atoi(instruction->argv[0]), /* x */ + atoi(instruction->argv[1]), /* y */ + atoi(instruction->argv[2]) /* mask */ + ); + } + + else if (strcmp(instruction->opcode, "key") == 0) { + SendKeyEvent( + rfb_client, + atoi(instruction->argv[0]), /* keysym */ + atoi(instruction->argv[1]) /* pressed */ + ); + } + guac_free_instruction(instruction); } }