diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c b/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c index e669f781..488dbf69 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c @@ -2,14 +2,24 @@ #include #include +#include + #include "rdpdr_messages.h" +#include "rdpdr_printer.h" #include "rdpdr_service.h" +#include "client.h" void guac_rdpdr_process_print_job_create(guac_rdpdrPlugin* rdpdr, STREAM* input_stream, int completion_id) { + rdp_guac_client_data* client_data = (rdp_guac_client_data*) rdpdr->client->data; STREAM* output_stream = stream_new(24); + /* Open file */ guac_client_log_info(rdpdr->client, "Print job created"); + pthread_mutex_lock(&(client_data->update_lock)); + guac_protocol_send_file(rdpdr->client->socket, + GUAC_RDPDR_PRINTER_BLOB, "print.ps", "application/postscript"); + pthread_mutex_unlock(&(client_data->update_lock)); /* Write header */ stream_write_uint16(output_stream, RDPDR_CTYP_CORE); @@ -28,15 +38,21 @@ void guac_rdpdr_process_print_job_create(guac_rdpdrPlugin* rdpdr, STREAM* input_ void guac_rdpdr_process_print_job_write(guac_rdpdrPlugin* rdpdr, STREAM* input_stream, int completion_id) { int length; + unsigned char* buffer; + rdp_guac_client_data* client_data = (rdp_guac_client_data*) rdpdr->client->data; STREAM* output_stream = stream_new(24); stream_read_uint32(input_stream, length); stream_seek(input_stream, 8); /* Offset */ stream_seek(input_stream, 20); /* Padding */ + buffer = stream_get_tail(input_stream); - /* TODO: Here, read data */ - guac_client_log_info(rdpdr->client, "Data received: %i bytes", length); + /* Send data */ + pthread_mutex_lock(&(client_data->update_lock)); + guac_protocol_send_blob(rdpdr->client->socket, + GUAC_RDPDR_PRINTER_BLOB, buffer, length); + pthread_mutex_unlock(&(client_data->update_lock)); /* Write header */ stream_write_uint16(output_stream, RDPDR_CTYP_CORE); @@ -55,9 +71,14 @@ void guac_rdpdr_process_print_job_write(guac_rdpdrPlugin* rdpdr, STREAM* input_s void guac_rdpdr_process_print_job_close(guac_rdpdrPlugin* rdpdr, STREAM* input_stream, int completion_id) { + rdp_guac_client_data* client_data = (rdp_guac_client_data*) rdpdr->client->data; STREAM* output_stream = stream_new(24); + /* Close file */ guac_client_log_info(rdpdr->client, "Print job closed"); + pthread_mutex_lock(&(client_data->update_lock)); + guac_protocol_send_end(rdpdr->client->socket, GUAC_RDPDR_PRINTER_BLOB); + pthread_mutex_unlock(&(client_data->update_lock)); /* Write header */ stream_write_uint16(output_stream, RDPDR_CTYP_CORE); diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_printer.h b/src/protocols/rdp/guac_rdpdr/rdpdr_printer.h index 01689d90..c834d8a4 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_printer.h +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_printer.h @@ -41,6 +41,11 @@ #include #include +/** + * The index of the blob to use when sending printed files. + */ +#define GUAC_RDPDR_PRINTER_BLOB 0 + /* * Message handlers. */