diff --git a/src/libguac/guacamole/protocol.h b/src/libguac/guacamole/protocol.h index 7fc871f8..f5d58a4e 100644 --- a/src/libguac/guacamole/protocol.h +++ b/src/libguac/guacamole/protocol.h @@ -37,6 +37,8 @@ #include "stream.h" #include "timestamp.h" +#include + #include /** @@ -280,6 +282,35 @@ int guac_protocol_send_disconnect(guac_socket* socket); int guac_protocol_send_error(guac_socket* socket, const char* error, guac_protocol_status status); +/** + * Sends a log instruction over the given guac_socket connection. This is + * mainly useful in debugging. + * + * If an error occurs sending the instruction, a non-zero value is + * returned, and guac_error is set appropriately. + * + * @param socket The guac_socket connection to use. + * @param format A printf-style format string to log. + * @param ... Arguments to use when filling the format string for printing. + * @return Zero on success, non-zero on error. + */ +int guac_protocol_send_log(guac_socket* socket, const char* format, ...); + +/** + * Sends a log instruction over the given guac_socket connection. This is + * mainly useful in debugging. + * + * If an error occurs sending the instruction, a non-zero value is + * returned, and guac_error is set appropriately. + * + * @param socket The guac_socket connection to use. + * @param format A printf-style format string to log. + * @param ap The va_list containing the arguments to be used when filling the + * format string for printing. + */ +int vguac_protocol_send_log(guac_socket* socket, const char* format, + va_list args); + /** * Sends a nest instruction over the given guac_socket connection. * diff --git a/src/libguac/protocol.c b/src/libguac/protocol.c index 48372e15..1feb0844 100644 --- a/src/libguac/protocol.c +++ b/src/libguac/protocol.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -774,6 +775,40 @@ int guac_protocol_send_error(guac_socket* socket, const char* error, } +int vguac_protocol_send_log(guac_socket* socket, const char* format, + va_list args) { + + int ret_val; + + /* Copy log message into buffer */ + char message[4096]; + vsnprintf(message, sizeof(message), format, args); + + /* Log to instruction */ + guac_socket_instruction_begin(socket); + ret_val = + guac_socket_write_string(socket, "3.log,") + || __guac_socket_write_length_string(socket, message) + || guac_socket_write_string(socket, ";"); + + guac_socket_instruction_end(socket); + return ret_val; + +} + +int guac_protocol_send_log(guac_socket* socket, const char* format, ...) { + + int ret_val; + + va_list args; + va_start(args, format); + ret_val = vguac_protocol_send_log(socket, format, args); + va_end(args); + + return ret_val; + +} + int guac_protocol_send_file(guac_socket* socket, const guac_stream* stream, const char* mimetype, const char* name) {