Store data alongside streams. Validate stream indices and close state.
This commit is contained in:
parent
6ce71aa160
commit
b88749aedd
@ -149,6 +149,7 @@ int __guac_handle_file(guac_client* client, guac_instruction* instruction) {
|
|||||||
/* Initialize stream */
|
/* Initialize stream */
|
||||||
stream = &(client->__streams[stream_index]);
|
stream = &(client->__streams[stream_index]);
|
||||||
stream->index = stream_index;
|
stream->index = stream_index;
|
||||||
|
stream->data = NULL;
|
||||||
|
|
||||||
/* If supported, call handler */
|
/* If supported, call handler */
|
||||||
if (client->file_handler)
|
if (client->file_handler)
|
||||||
@ -167,6 +168,8 @@ int __guac_handle_file(guac_client* client, guac_instruction* instruction) {
|
|||||||
|
|
||||||
int __guac_handle_blob(guac_client* client, guac_instruction* instruction) {
|
int __guac_handle_blob(guac_client* client, guac_instruction* instruction) {
|
||||||
|
|
||||||
|
guac_stream* stream;
|
||||||
|
|
||||||
/* 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) {
|
||||||
@ -179,29 +182,38 @@ int __guac_handle_blob(guac_client* client, guac_instruction* instruction) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stream = &(client->__streams[stream_index]);
|
||||||
|
|
||||||
|
/* Validate initialization of stream */
|
||||||
|
if (stream->index == GUAC_CLIENT_CLOSED_STREAM_INDEX) {
|
||||||
|
|
||||||
|
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;
|
|
||||||
|
|
||||||
/* Decode base64 */
|
/* Decode base64 */
|
||||||
length = guac_protocol_decode_base64(instruction->argv[1]);
|
int length = guac_protocol_decode_base64(instruction->argv[1]);
|
||||||
|
return client->blob_handler(client, stream, instruction->argv[1],
|
||||||
return client->blob_handler(
|
length);
|
||||||
client,
|
|
||||||
&(client->__streams[stream_index]),
|
|
||||||
instruction->argv[1],
|
|
||||||
length
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
guac_protocol_send_abort(client->socket, &(client->__streams[stream_index]),
|
guac_protocol_send_abort(client->socket, stream,
|
||||||
"File transfer unsupported", GUAC_PROTOCOL_STATUS_UNSUPPORTED);
|
"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) {
|
||||||
|
|
||||||
|
guac_stream* stream;
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
/* Pull corresponding stream */
|
/* Pull corresponding stream */
|
||||||
int stream_index = atoi(instruction->argv[0]);
|
int stream_index = atoi(instruction->argv[0]);
|
||||||
|
|
||||||
@ -217,13 +229,14 @@ int __guac_handle_end(guac_client* client, guac_instruction* instruction) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client->end_handler)
|
stream = &(client->__streams[stream_index]);
|
||||||
return client->end_handler(
|
|
||||||
client,
|
|
||||||
&(client->__streams[stream_index])
|
|
||||||
);
|
|
||||||
|
|
||||||
return 0;
|
if (client->end_handler)
|
||||||
|
result = client->end_handler(client, stream);
|
||||||
|
|
||||||
|
/* Mark stream as closed */
|
||||||
|
stream->index = GUAC_CLIENT_CLOSED_STREAM_INDEX;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int __guac_handle_disconnect(guac_client* client, guac_instruction* instruction) {
|
int __guac_handle_disconnect(guac_client* client, guac_instruction* instruction) {
|
||||||
|
@ -117,6 +117,8 @@ void guac_client_free_stream(guac_client* client, guac_stream* stream) {
|
|||||||
|
|
||||||
guac_client* guac_client_alloc() {
|
guac_client* guac_client_alloc() {
|
||||||
|
|
||||||
|
int i;
|
||||||
|
|
||||||
/* Allocate new client */
|
/* Allocate new client */
|
||||||
guac_client* client = malloc(sizeof(guac_client));
|
guac_client* client = malloc(sizeof(guac_client));
|
||||||
if (client == NULL) {
|
if (client == NULL) {
|
||||||
@ -140,6 +142,10 @@ guac_client* guac_client_alloc() {
|
|||||||
/* Allocate stream pool */
|
/* Allocate stream pool */
|
||||||
client->__stream_pool = guac_pool_alloc(0);
|
client->__stream_pool = guac_pool_alloc(0);
|
||||||
|
|
||||||
|
/* Initialze streams */
|
||||||
|
for (i=0; i<GUAC_CLIENT_MAX_STREAMS; i++)
|
||||||
|
client->__streams[i].index = GUAC_CLIENT_CLOSED_STREAM_INDEX;
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,11 @@
|
|||||||
*/
|
*/
|
||||||
#define GUAC_CLIENT_MAX_STREAMS 64
|
#define GUAC_CLIENT_MAX_STREAMS 64
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The index of a closed stream.
|
||||||
|
*/
|
||||||
|
#define GUAC_CLIENT_CLOSED_STREAM_INDEX -1
|
||||||
|
|
||||||
typedef struct guac_client guac_client;
|
typedef struct guac_client guac_client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,6 +56,11 @@ struct guac_stream {
|
|||||||
*/
|
*/
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arbitrary data associated with this stream.
|
||||||
|
*/
|
||||||
|
void* data;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user