diff --git a/src/libguac/guacamole/user.h b/src/libguac/guacamole/user.h index 67ca7c88..f920c325 100644 --- a/src/libguac/guacamole/user.h +++ b/src/libguac/guacamole/user.h @@ -544,6 +544,32 @@ void guac_user_free(guac_user* user); */ int guac_user_handle_connection(guac_user* user, int usec_timeout); +/** + * Call the appropriate handler defined by the given user for the given + * instruction. A comparison is made between the instruction opcode and the + * initial handler lookup table defined in user-handlers.c. The initial handlers + * will in turn call the user's handler (if defined). + * + * @param user + * The user whose handlers should be called. + * + * @param opcode + * The opcode of the instruction to pass to the user via the appropriate + * handler. + * + * @param argc + * The number of arguments which are part of the instruction. + * + * @param argv + * An array of all arguments which are part of the instruction. + * + * @return + * Non-negative if the instruction was handled successfully, or negative + * if an error occurred. + */ +int guac_user_handle_instruction(guac_user* user, const char* opcode, + int argc, char** argv); + /** * Allocates a new stream. An arbitrary index is automatically assigned * if no previously-allocated stream is available for use. diff --git a/src/libguac/user-handlers.c b/src/libguac/user-handlers.c index 737e6f30..92dc249a 100644 --- a/src/libguac/user-handlers.c +++ b/src/libguac/user-handlers.c @@ -693,7 +693,7 @@ void guac_free_mimetypes(char** mimetypes) { } -int guac_user_handle_instruction(__guac_instruction_handler_mapping* map, +int __guac_user_call_opcode_handler(__guac_instruction_handler_mapping* map, guac_user* user, const char* opcode, int argc, char** argv) { /* For each defined instruction */ diff --git a/src/libguac/user-handlers.h b/src/libguac/user-handlers.h index 1a6477ed..dd9f829b 100644 --- a/src/libguac/user-handlers.h +++ b/src/libguac/user-handlers.h @@ -261,8 +261,10 @@ char** guac_copy_mimetypes(char** mimetypes, int count); /** * Call the appropriate handler defined by the given user for the given * instruction. A comparison is made between the instruction opcode and the - * initial handler lookup table defined in user-handlers.c. The intial handlers - * will in turn call the user's handler (if defined). + * initial handler lookup table defined in the map that is provided to this + * function. If an entry for the instruction is found in the provided map, + * the handler defined in that map will be called and the value returned. If + * no match is found, it is silently ignored. * * @param map * The array that holds the opcode to handler mappings. @@ -284,7 +286,7 @@ char** guac_copy_mimetypes(char** mimetypes, int count); * Non-negative if the instruction was handled successfully, or negative * if an error occurred. */ -int guac_user_handle_instruction(__guac_instruction_handler_mapping* map, +int __guac_user_call_opcode_handler(__guac_instruction_handler_mapping* map, guac_user* user, const char* opcode, int argc, char** argv); #endif diff --git a/src/libguac/user-handshake.c b/src/libguac/user-handshake.c index 9cccec4c..cf96d347 100644 --- a/src/libguac/user-handshake.c +++ b/src/libguac/user-handshake.c @@ -25,6 +25,7 @@ #include "guacamole/protocol.h" #include "guacamole/socket.h" #include "guacamole/user.h" +#include "user-handlers.h" #include #include @@ -161,7 +162,7 @@ static void* guac_user_input_thread(void* data) { guac_error_message = NULL; /* Call handler, stop on error */ - if (guac_user_handle_instruction(__guac_instruction_handler_map, + if (__guac_user_call_opcode_handler(__guac_instruction_handler_map, user, parser->opcode, parser->argc, parser->argv) < 0) { /* Log error */ @@ -266,7 +267,7 @@ int guac_user_handle_connection(guac_user* user, int usec_timeout) { parser->opcode); /* Run instruction handler for opcode with arguments. */ - if (guac_user_handle_instruction(__guac_handshake_handler_map, user, + if (__guac_user_call_opcode_handler(__guac_handshake_handler_map, user, parser->opcode, parser->argc, parser->argv)) { guac_user_log_handshake_failure(user); diff --git a/src/libguac/user.c b/src/libguac/user.c index 64c2a763..9145b275 100644 --- a/src/libguac/user.c +++ b/src/libguac/user.c @@ -167,6 +167,13 @@ void guac_user_free_object(guac_user* user, guac_object* object) { } +int guac_user_handle_instruction(guac_user* user, const char* opcode, int argc, char** argv) { + + return __guac_user_call_opcode_handler(__guac_instruction_handler_map, + user, opcode, argc, argv); + +} + void guac_user_stop(guac_user* user) { user->active = 0; }