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,47 +131,58 @@ 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 */
int stream_index = atoi(instruction->argv[0]);
guac_stream* stream;
/* Pull corresponding stream */ /* Validate stream index */
int stream_index = atoi(instruction->argv[0]); if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) {
guac_stream* stream;
/* Validate stream index */ guac_stream dummy_stream;
if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) { dummy_stream.index = stream_index;
/* TODO: Return failing ack */
return 0;
}
/* Initialize stream */ guac_protocol_send_abort(client->socket, &dummy_stream,
stream = &(client->__streams[stream_index]); "Invalid stream index", GUAC_PROTOCOL_STATUS_INVALID_PARAMETER);
stream->index = stream_index; return 0;
}
/* Initialize stream */
stream = &(client->__streams[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) {
/* Validate stream index */
int stream_index = atoi(instruction->argv[0]);
if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) {
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->blob_handler) { if (client->blob_handler) {
int length; int length;
/* Validate stream index */
int stream_index = atoi(instruction->argv[0]);
if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) {
/* TODO: Return failing ack */
return 0;
}
/* 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 */
int stream_index = atoi(instruction->argv[0]);
/* Pull corresponding stream */ /* Validate stream index */
int stream_index = atoi(instruction->argv[0]); if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) {
/* Validate stream index */ guac_stream dummy_stream;
if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) dummy_stream.index = stream_index;
return 0;
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;
} }