Send error responses via abort.

This commit is contained in:
Michael Jumper 2013-09-27 19:48:11 -07:00
parent cec58edef3
commit 6ce71aa160

View File

@ -131,15 +131,18 @@ int __guac_handle_size(guac_client* client, guac_instruction* instruction) {
int __guac_handle_file(guac_client* client, guac_instruction* instruction) { int __guac_handle_file(guac_client* client, guac_instruction* instruction) {
if (client->file_handler) {
/* Pull corresponding stream */ /* Pull corresponding stream */
int stream_index = atoi(instruction->argv[0]); int stream_index = atoi(instruction->argv[0]);
guac_stream* stream; guac_stream* stream;
/* Validate stream index */ /* Validate stream index */
if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) { if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) {
/* TODO: Return failing ack */
guac_stream dummy_stream;
dummy_stream.index = stream_index;
guac_protocol_send_abort(client->socket, &dummy_stream,
"Invalid stream index", GUAC_PROTOCOL_STATUS_INVALID_PARAMETER);
return 0; return 0;
} }
@ -147,31 +150,39 @@ int __guac_handle_file(guac_client* client, guac_instruction* instruction) {
stream = &(client->__streams[stream_index]); stream = &(client->__streams[stream_index]);
stream->index = stream_index; stream->index = stream_index;
/* If supported, call handler */
if (client->file_handler)
return client->file_handler( return client->file_handler(
client, client,
stream, stream,
instruction->argv[1], /* mimetype */ instruction->argv[1], /* mimetype */
instruction->argv[2] /* filename */ instruction->argv[2] /* filename */
); );
}
/* TODO: Return failing ack */ /* Otherwise, abort */
guac_protocol_send_abort(client->socket, stream,
"File transfer unsupported", GUAC_PROTOCOL_STATUS_UNSUPPORTED);
return 0; return 0;
} }
int __guac_handle_blob(guac_client* client, guac_instruction* instruction) { int __guac_handle_blob(guac_client* client, guac_instruction* instruction) {
if (client->blob_handler) {
int length;
/* Validate stream index */ /* Validate stream index */
int stream_index = atoi(instruction->argv[0]); int stream_index = atoi(instruction->argv[0]);
if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) { if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) {
/* TODO: Return failing ack */
guac_stream dummy_stream;
dummy_stream.index = stream_index;
guac_protocol_send_abort(client->socket, &dummy_stream,
"Invalid stream index", GUAC_PROTOCOL_STATUS_INVALID_PARAMETER);
return 0; return 0;
} }
if (client->blob_handler) {
int length;
/* Decode base64 */ /* Decode base64 */
length = guac_protocol_decode_base64(instruction->argv[1]); length = guac_protocol_decode_base64(instruction->argv[1]);
@ -184,28 +195,34 @@ int __guac_handle_blob(guac_client* client, guac_instruction* instruction) {
} }
/* TODO: Return failing ack */ guac_protocol_send_abort(client->socket, &(client->__streams[stream_index]),
"File transfer unsupported", GUAC_PROTOCOL_STATUS_UNSUPPORTED);
return 0; return 0;
} }
int __guac_handle_end(guac_client* client, guac_instruction* instruction) { int __guac_handle_end(guac_client* client, guac_instruction* instruction) {
if (client->end_handler) {
/* Pull corresponding stream */ /* Pull corresponding stream */
int stream_index = atoi(instruction->argv[0]); int stream_index = atoi(instruction->argv[0]);
/* Validate stream index */ /* Validate stream index */
if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) {
return 0;
guac_stream dummy_stream;
dummy_stream.index = stream_index;
guac_protocol_send_abort(client->socket, &dummy_stream,
"Invalid stream index",
GUAC_PROTOCOL_STATUS_INVALID_PARAMETER);
return 0;
}
if (client->end_handler)
return client->end_handler( return client->end_handler(
client, client,
&(client->__streams[stream_index]) &(client->__streams[stream_index])
); );
}
return 0; return 0;
} }