Add log instruction, for inserting debug information into the protocol stream.

This commit is contained in:
Michael Jumper 2014-01-19 16:59:52 -08:00
parent a83cd54cf1
commit 8bf6f47b7e
2 changed files with 66 additions and 0 deletions

View File

@ -37,6 +37,8 @@
#include "stream.h"
#include "timestamp.h"
#include <stdarg.h>
#include <cairo/cairo.h>
/**
@ -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.
*

View File

@ -31,6 +31,7 @@
#include <errno.h>
#include <inttypes.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@ -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) {