GUACAMOLE-200: Refactor RDPDR print job object to top-level.

This commit is contained in:
Michael Jumper 2017-02-13 23:51:33 -08:00
parent 17093a8149
commit 1537e475af
4 changed files with 100 additions and 99 deletions

View File

@ -41,6 +41,7 @@ libguac_client_rdp_la_SOURCES = \
rdp_gdi.c \ rdp_gdi.c \
rdp_glyph.c \ rdp_glyph.c \
rdp_keymap.c \ rdp_keymap.c \
rdp_print_job.c \
rdp_pointer.c \ rdp_pointer.c \
rdp_rail.c \ rdp_rail.c \
rdp_settings.c \ rdp_settings.c \
@ -72,9 +73,9 @@ guacdr_sources = \
guac_rdpdr/rdpdr_fs_service.c \ guac_rdpdr/rdpdr_fs_service.c \
guac_rdpdr/rdpdr_messages.c \ guac_rdpdr/rdpdr_messages.c \
guac_rdpdr/rdpdr_printer.c \ guac_rdpdr/rdpdr_printer.c \
guac_rdpdr/rdpdr_print_job.c \
guac_rdpdr/rdpdr_service.c \ guac_rdpdr/rdpdr_service.c \
rdp_fs.c \ rdp_fs.c \
rdp_print_job.c \
rdp_stream.c \ rdp_stream.c \
unicode.c unicode.c
@ -90,7 +91,6 @@ noinst_HEADERS = \
guac_rdpdr/rdpdr_fs_service.h \ guac_rdpdr/rdpdr_fs_service.h \
guac_rdpdr/rdpdr_messages.h \ guac_rdpdr/rdpdr_messages.h \
guac_rdpdr/rdpdr_printer.h \ guac_rdpdr/rdpdr_printer.h \
guac_rdpdr/rdpdr_print_job.h \
guac_rdpdr/rdpdr_service.h \ guac_rdpdr/rdpdr_service.h \
guac_rdpsnd/rdpsnd_messages.h \ guac_rdpsnd/rdpsnd_messages.h \
guac_rdpsnd/rdpsnd_service.h \ guac_rdpsnd/rdpsnd_service.h \
@ -111,6 +111,7 @@ noinst_HEADERS = \
rdp_glyph.h \ rdp_glyph.h \
rdp_keymap.h \ rdp_keymap.h \
rdp_pointer.h \ rdp_pointer.h \
rdp_print_job.h \
rdp_rail.h \ rdp_rail.h \
rdp_settings.h \ rdp_settings.h \
rdp_status.h \ rdp_status.h \

View File

@ -21,8 +21,8 @@
#include "rdpdr_messages.h" #include "rdpdr_messages.h"
#include "rdpdr_printer.h" #include "rdpdr_printer.h"
#include "rdpdr_print_job.h"
#include "rdpdr_service.h" #include "rdpdr_service.h"
#include "rdp_print_job.h"
#include "rdp_status.h" #include "rdp_status.h"
#include <freerdp/utils/svc_plugin.h> #include <freerdp/utils/svc_plugin.h>
@ -53,7 +53,7 @@ void guac_rdpdr_process_print_job_create(guac_rdpdr_device* device,
/* Create print job */ /* Create print job */
device->data = guac_client_for_owner(device->rdpdr->client, device->data = guac_client_for_owner(device->rdpdr->client,
guac_rdpdr_print_job_alloc, NULL); guac_rdp_print_job_alloc, NULL);
/* Respond with success */ /* Respond with success */
wStream* output_stream = guac_rdpdr_new_io_completion(device, wStream* output_stream = guac_rdpdr_new_io_completion(device,
@ -67,7 +67,7 @@ void guac_rdpdr_process_print_job_create(guac_rdpdr_device* device,
void guac_rdpdr_process_print_job_write(guac_rdpdr_device* device, void guac_rdpdr_process_print_job_write(guac_rdpdr_device* device,
wStream* input_stream, int completion_id) { wStream* input_stream, int completion_id) {
guac_rdpdr_print_job* job = (guac_rdpdr_print_job*) device->data; guac_rdp_print_job* job = (guac_rdp_print_job*) device->data;
unsigned char* buffer; unsigned char* buffer;
int length; int length;
@ -80,7 +80,7 @@ void guac_rdpdr_process_print_job_write(guac_rdpdr_device* device,
buffer = Stream_Pointer(input_stream); buffer = Stream_Pointer(input_stream);
/* Write data only if job exists, translating status for RDP */ /* Write data only if job exists, translating status for RDP */
if (job != NULL && (length = guac_rdpdr_print_job_write(job, if (job != NULL && (length = guac_rdp_print_job_write(job,
buffer, length)) >= 0) { buffer, length)) >= 0) {
status = STATUS_SUCCESS; status = STATUS_SUCCESS;
} }
@ -105,9 +105,9 @@ void guac_rdpdr_process_print_job_close(guac_rdpdr_device* device,
wStream* input_stream, int completion_id) { wStream* input_stream, int completion_id) {
/* End print job */ /* End print job */
guac_rdpdr_print_job* job = (guac_rdpdr_print_job*) device->data; guac_rdp_print_job* job = (guac_rdp_print_job*) device->data;
if (job != NULL) { if (job != NULL) {
guac_rdpdr_print_job_free(job); guac_rdp_print_job_free(job);
device->data = NULL; device->data = NULL;
} }
@ -180,10 +180,10 @@ static void guac_rdpdr_device_printer_iorequest_handler(guac_rdpdr_device* devic
static void guac_rdpdr_device_printer_free_handler(guac_rdpdr_device* device) { static void guac_rdpdr_device_printer_free_handler(guac_rdpdr_device* device) {
/* Terminate and free print job if open */ /* Terminate and free print job if open */
guac_rdpdr_print_job* job = (guac_rdpdr_print_job*) device->data; guac_rdp_print_job* job = (guac_rdp_print_job*) device->data;
if (job != NULL) { if (job != NULL) {
guac_rdpdr_print_job_kill(job); guac_rdp_print_job_kill(job);
guac_rdpdr_print_job_free(job); guac_rdp_print_job_free(job);
} }
} }

View File

@ -19,7 +19,7 @@
#include "config.h" #include "config.h"
#include "rdpdr_print_job.h" #include "rdp_print_job.h"
#include <guacamole/client.h> #include <guacamole/client.h>
#include <guacamole/protocol.h> #include <guacamole/protocol.h>
@ -38,7 +38,7 @@
* a NULL-terminated array of arguments, where the first argument is the name * a NULL-terminated array of arguments, where the first argument is the name
* of the file to run. * of the file to run.
*/ */
char* const guac_rdpdr_pdf_filter_command[] = { char* const guac_rdp_pdf_filter_command[] = {
"gs", "gs",
"-q", "-q",
"-dNOPAUSE", "-dNOPAUSE",
@ -57,7 +57,7 @@ char* const guac_rdpdr_pdf_filter_command[] = {
/** /**
* Updates the state of the given print job. Any threads currently blocked by a * Updates the state of the given print job. Any threads currently blocked by a
* call to guac_rdpdr_print_job_wait_for_ack() will be unblocked. * call to guac_rdp_print_job_wait_for_ack() will be unblocked.
* *
* @param job * @param job
* The print job whose state should be updated. * The print job whose state should be updated.
@ -65,8 +65,8 @@ char* const guac_rdpdr_pdf_filter_command[] = {
* @param state * @param state
* The new state to assign to the given print job. * The new state to assign to the given print job.
*/ */
static void guac_rdpdr_print_job_set_state(guac_rdpdr_print_job* job, static void guac_rdp_print_job_set_state(guac_rdp_print_job* job,
guac_rdpdr_print_job_state state) { guac_rdp_print_job_state state) {
pthread_mutex_lock(&(job->state_lock)); pthread_mutex_lock(&(job->state_lock));
@ -80,29 +80,29 @@ static void guac_rdpdr_print_job_set_state(guac_rdpdr_print_job* job,
/** /**
* Suspends execution of the current thread until the state of the given print * Suspends execution of the current thread until the state of the given print
* job is not GUAC_RDPDR_PRINT_JOB_WAITING_FOR_ACK. If the state of the print * job is not GUAC_RDP_PRINT_JOB_WAITING_FOR_ACK. If the state of the print
* job is GUAC_RDPDR_PRINT_JOB_ACK_RECEIVED, the state is automatically reset * job is GUAC_RDP_PRINT_JOB_ACK_RECEIVED, the state is automatically reset
* back to GUAC_RDPDR_PRINT_JOB_WAITING_FOR_ACK prior to returning. * back to GUAC_RDP_PRINT_JOB_WAITING_FOR_ACK prior to returning.
* *
* @param job * @param job
* The print job to wait for. * The print job to wait for.
* *
* @return * @return
* Zero if the state of the print job is GUAC_RDPDR_PRINT_JOB_CLOSED, * Zero if the state of the print job is GUAC_RDP_PRINT_JOB_CLOSED,
* non-zero if the state was GUAC_RDPDR_PRINT_JOB_ACK_RECEIVED and has been * non-zero if the state was GUAC_RDP_PRINT_JOB_ACK_RECEIVED and has been
* automatically reset to GUAC_RDPDR_PRINT_JOB_WAITING_FOR_ACK. * automatically reset to GUAC_RDP_PRINT_JOB_WAITING_FOR_ACK.
*/ */
static int guac_rdpdr_print_job_wait_for_ack(guac_rdpdr_print_job* job) { static int guac_rdp_print_job_wait_for_ack(guac_rdp_print_job* job) {
/* Wait for ack if stream open and not yet received */ /* Wait for ack if stream open and not yet received */
pthread_mutex_lock(&(job->state_lock)); pthread_mutex_lock(&(job->state_lock));
if (job->state == GUAC_RDPDR_PRINT_JOB_WAITING_FOR_ACK) if (job->state == GUAC_RDP_PRINT_JOB_WAITING_FOR_ACK)
pthread_cond_wait(&job->state_modified, &job->state_lock); pthread_cond_wait(&job->state_modified, &job->state_lock);
/* Reset state if ack received */ /* Reset state if ack received */
int got_ack = (job->state == GUAC_RDPDR_PRINT_JOB_ACK_RECEIVED); int got_ack = (job->state == GUAC_RDP_PRINT_JOB_ACK_RECEIVED);
if (got_ack) if (got_ack)
job->state = GUAC_RDPDR_PRINT_JOB_WAITING_FOR_ACK; job->state = GUAC_RDP_PRINT_JOB_WAITING_FOR_ACK;
/* Return whether ack was successfully received */ /* Return whether ack was successfully received */
pthread_mutex_unlock(&(job->state_lock)); pthread_mutex_unlock(&(job->state_lock));
@ -119,21 +119,21 @@ static int guac_rdpdr_print_job_wait_for_ack(guac_rdpdr_print_job* job) {
* The user receiving the "file" instruction. * The user receiving the "file" instruction.
* *
* @param data * @param data
* A pointer to the guac_rdpdr_print_job representing the print job being * A pointer to the guac_rdp_print_job representing the print job being
* streamed. * streamed.
* *
* @return * @return
* Always NULL. * Always NULL.
*/ */
static void* guac_rdpdr_print_job_begin_stream(guac_user* user, void* data) { static void* guac_rdp_print_job_begin_stream(guac_user* user, void* data) {
guac_rdpdr_print_job* job = (guac_rdpdr_print_job*) data; guac_rdp_print_job* job = (guac_rdp_print_job*) data;
guac_client_log(job->client, GUAC_LOG_DEBUG, "Beginning print stream: %s", guac_client_log(job->client, GUAC_LOG_DEBUG, "Beginning print stream: %s",
job->filename); job->filename);
/* Kill job and do nothing if user no longer exists */ /* Kill job and do nothing if user no longer exists */
if (user == NULL) { if (user == NULL) {
guac_rdpdr_print_job_kill(job); guac_rdp_print_job_kill(job);
return NULL; return NULL;
} }
@ -155,24 +155,24 @@ static void* guac_rdpdr_print_job_begin_stream(guac_user* user, void* data) {
* The user receiving the "blob" instruction. * The user receiving the "blob" instruction.
* *
* @param data * @param data
* A pointer to an guac_rdpdr_print_blob structure containing the data to * A pointer to an guac_rdp_print_blob structure containing the data to
* be written, the number of bytes being written, and the print job being * be written, the number of bytes being written, and the print job being
* streamed. * streamed.
* *
* @return * @return
* Always NULL. * Always NULL.
*/ */
static void* guac_rdpdr_print_job_send_blob(guac_user* user, void* data) { static void* guac_rdp_print_job_send_blob(guac_user* user, void* data) {
guac_rdpdr_print_blob* blob = (guac_rdpdr_print_blob*) data; guac_rdp_print_blob* blob = (guac_rdp_print_blob*) data;
guac_rdpdr_print_job* job = blob->job; guac_rdp_print_job* job = blob->job;
guac_client_log(job->client, GUAC_LOG_DEBUG, "Sending %i byte(s) " guac_client_log(job->client, GUAC_LOG_DEBUG, "Sending %i byte(s) "
"of filtered output.", blob->length); "of filtered output.", blob->length);
/* Kill job and do nothing if user no longer exists */ /* Kill job and do nothing if user no longer exists */
if (user == NULL) { if (user == NULL) {
guac_rdpdr_print_job_kill(job); guac_rdp_print_job_kill(job);
return NULL; return NULL;
} }
@ -194,20 +194,20 @@ static void* guac_rdpdr_print_job_send_blob(guac_user* user, void* data) {
* The user receiving the "end" instruction. * The user receiving the "end" instruction.
* *
* @param data * @param data
* A pointer to the guac_rdpdr_print_job representing the print job being * A pointer to the guac_rdp_print_job representing the print job being
* streamed. * streamed.
* *
* @return * @return
* Always NULL. * Always NULL.
*/ */
static void* guac_rdpdr_print_job_end_stream(guac_user* user, void* data) { static void* guac_rdp_print_job_end_stream(guac_user* user, void* data) {
guac_rdpdr_print_job* job = (guac_rdpdr_print_job*) data; guac_rdp_print_job* job = (guac_rdp_print_job*) data;
guac_client_log(job->client, GUAC_LOG_DEBUG, "End of print stream."); guac_client_log(job->client, GUAC_LOG_DEBUG, "End of print stream.");
/* Kill job and do nothing if user no longer exists */ /* Kill job and do nothing if user no longer exists */
if (user == NULL) { if (user == NULL) {
guac_rdpdr_print_job_kill(job); guac_rdp_print_job_kill(job);
return NULL; return NULL;
} }
@ -248,14 +248,14 @@ static void* guac_rdpdr_print_job_end_stream(guac_user* user, void* data) {
* @return * @return
* Always zero. * Always zero.
*/ */
static int guac_rdpdr_print_filter_ack_handler(guac_user* user, static int guac_rdp_print_filter_ack_handler(guac_user* user,
guac_stream* stream, char* message, guac_protocol_status status) { guac_stream* stream, char* message, guac_protocol_status status) {
guac_rdpdr_print_job* job = (guac_rdpdr_print_job*) stream->data; guac_rdp_print_job* job = (guac_rdp_print_job*) stream->data;
/* Update state for successful acks */ /* Update state for successful acks */
if (status == GUAC_PROTOCOL_STATUS_SUCCESS) if (status == GUAC_PROTOCOL_STATUS_SUCCESS)
guac_rdpdr_print_job_set_state(job, GUAC_RDPDR_PRINT_JOB_ACK_RECEIVED); guac_rdp_print_job_set_state(job, GUAC_RDP_PRINT_JOB_ACK_RECEIVED);
/* Terminate stream if ack signals an error */ /* Terminate stream if ack signals an error */
else { else {
@ -265,7 +265,7 @@ static int guac_rdpdr_print_filter_ack_handler(guac_user* user,
"print stream."); "print stream.");
/* Kill job (the results will no longer be received) */ /* Kill job (the results will no longer be received) */
guac_rdpdr_print_job_kill(job); guac_rdp_print_job_kill(job);
} }
@ -298,7 +298,7 @@ static int guac_rdpdr_print_filter_ack_handler(guac_user* user,
* created. If the filter process could not be created, the values assigned * created. If the filter process could not be created, the values assigned
* through input_fd and output_fd are undefined. * through input_fd and output_fd are undefined.
*/ */
static pid_t guac_rdpdr_create_filter_process(guac_client* client, static pid_t guac_rdp_create_filter_process(guac_client* client,
int* input_fd, int* output_fd) { int* input_fd, int* output_fd) {
int child_pid; int child_pid;
@ -352,9 +352,9 @@ static pid_t guac_rdpdr_create_filter_process(guac_client* client,
/* Run PDF filter */ /* Run PDF filter */
guac_client_log(client, GUAC_LOG_INFO, "Running %s", guac_client_log(client, GUAC_LOG_INFO, "Running %s",
guac_rdpdr_pdf_filter_command[0]); guac_rdp_pdf_filter_command[0]);
if (execvp(guac_rdpdr_pdf_filter_command[0], if (execvp(guac_rdp_pdf_filter_command[0],
guac_rdpdr_pdf_filter_command) < 0) guac_rdp_pdf_filter_command) < 0)
guac_client_log(client, GUAC_LOG_ERROR, "Unable to execute PDF " guac_client_log(client, GUAC_LOG_ERROR, "Unable to execute PDF "
"filter command: %s", strerror(errno)); "filter command: %s", strerror(errno));
else else
@ -384,18 +384,18 @@ static pid_t guac_rdpdr_create_filter_process(guac_client* client,
* processing or the associated Guacamole stream has closed. * processing or the associated Guacamole stream has closed.
* *
* @param data * @param data
* A pointer to the guac_rdpdr_print_job representing the print job that * A pointer to the guac_rdp_print_job representing the print job that
* should be read. * should be read.
* *
* @return * @return
* Always NULL. * Always NULL.
*/ */
static void* guac_rdpdr_print_job_output_thread(void* data) { static void* guac_rdp_print_job_output_thread(void* data) {
int length; int length;
char buffer[6048]; char buffer[6048];
guac_rdpdr_print_job* job = (guac_rdpdr_print_job*) data; guac_rdp_print_job* job = (guac_rdp_print_job*) data;
guac_client_log(job->client, GUAC_LOG_DEBUG, "Reading output from filter " guac_client_log(job->client, GUAC_LOG_DEBUG, "Reading output from filter "
"process..."); "process...");
@ -403,9 +403,9 @@ static void* guac_rdpdr_print_job_output_thread(void* data) {
while ((length = read(job->output_fd, buffer, sizeof(buffer))) > 0) { while ((length = read(job->output_fd, buffer, sizeof(buffer))) > 0) {
/* Wait for client to be ready for blob */ /* Wait for client to be ready for blob */
if (guac_rdpdr_print_job_wait_for_ack(job)) { if (guac_rdp_print_job_wait_for_ack(job)) {
guac_rdpdr_print_blob blob = { guac_rdp_print_blob blob = {
.job = job, .job = job,
.buffer = buffer, .buffer = buffer,
.length = length .length = length
@ -413,7 +413,7 @@ static void* guac_rdpdr_print_job_output_thread(void* data) {
/* Write a single blob of output */ /* Write a single blob of output */
guac_client_for_user(job->client, job->user, guac_client_for_user(job->client, job->user,
guac_rdpdr_print_job_send_blob, &blob); guac_rdp_print_job_send_blob, &blob);
} }
@ -433,7 +433,7 @@ static void* guac_rdpdr_print_job_output_thread(void* data) {
/* Terminate stream */ /* Terminate stream */
guac_client_for_user(job->client, job->user, guac_client_for_user(job->client, job->user,
guac_rdpdr_print_job_end_stream, job); guac_rdp_print_job_end_stream, job);
/* Ensure all associated file descriptors are closed */ /* Ensure all associated file descriptors are closed */
close(job->input_fd); close(job->input_fd);
@ -444,7 +444,7 @@ static void* guac_rdpdr_print_job_output_thread(void* data) {
} }
void* guac_rdpdr_print_job_alloc(guac_user* user, void* data) { void* guac_rdp_print_job_alloc(guac_user* user, void* data) {
/* Allocate nothing if user does not exist */ /* Allocate nothing if user does not exist */
if (user == NULL) if (user == NULL)
@ -456,7 +456,7 @@ void* guac_rdpdr_print_job_alloc(guac_user* user, void* data) {
return NULL; return NULL;
/* Bail early if allocation fails */ /* Bail early if allocation fails */
guac_rdpdr_print_job* job = malloc(sizeof(guac_rdpdr_print_job)); guac_rdp_print_job* job = malloc(sizeof(guac_rdp_print_job));
if (job == NULL) if (job == NULL)
return NULL; return NULL;
@ -467,14 +467,14 @@ void* guac_rdpdr_print_job_alloc(guac_user* user, void* data) {
job->bytes_received = 0; job->bytes_received = 0;
/* Set default filename for job */ /* Set default filename for job */
strcpy(job->filename, GUAC_RDPDR_PRINT_JOB_DEFAULT_FILENAME); strcpy(job->filename, GUAC_RDP_PRINT_JOB_DEFAULT_FILENAME);
/* Prepare stream for receipt of acks */ /* Prepare stream for receipt of acks */
stream->ack_handler = guac_rdpdr_print_filter_ack_handler; stream->ack_handler = guac_rdp_print_filter_ack_handler;
stream->data = job; stream->data = job;
/* Create print filter process */ /* Create print filter process */
job->filter_pid = guac_rdpdr_create_filter_process(job->client, job->filter_pid = guac_rdp_create_filter_process(job->client,
&job->input_fd, &job->output_fd); &job->input_fd, &job->output_fd);
/* Abort if print filter process cannot be created */ /* Abort if print filter process cannot be created */
@ -485,13 +485,13 @@ void* guac_rdpdr_print_job_alloc(guac_user* user, void* data) {
} }
/* Init stream state signal and lock */ /* Init stream state signal and lock */
job->state = GUAC_RDPDR_PRINT_JOB_WAITING_FOR_ACK; job->state = GUAC_RDP_PRINT_JOB_WAITING_FOR_ACK;
pthread_cond_init(&job->state_modified, NULL); pthread_cond_init(&job->state_modified, NULL);
pthread_mutex_init(&job->state_lock, NULL); pthread_mutex_init(&job->state_lock, NULL);
/* Start output thread */ /* Start output thread */
pthread_create(&job->output_thread, NULL, pthread_create(&job->output_thread, NULL,
guac_rdpdr_print_job_output_thread, job); guac_rdp_print_job_output_thread, job);
/* Print job allocated successfully */ /* Print job allocated successfully */
return job; return job;
@ -518,7 +518,7 @@ void* guac_rdpdr_print_job_alloc(guac_user* user, void* data) {
* Non-zero if the given buffer began with the "%%Title:" header and this * Non-zero if the given buffer began with the "%%Title:" header and this
* header was successfully parsed, zero otherwise. * header was successfully parsed, zero otherwise.
*/ */
static int guac_rdpdr_print_job_parse_title_header(guac_rdpdr_print_job* job, static int guac_rdp_print_job_parse_title_header(guac_rdp_print_job* job,
void* buffer, int length) { void* buffer, int length) {
int i; int i;
@ -565,7 +565,7 @@ static int guac_rdpdr_print_job_parse_title_header(guac_rdpdr_print_job* job,
* Searches through the given buffer for PostScript headers denoting the title * Searches through the given buffer for PostScript headers denoting the title
* of the document, assigning the filename of the given print job using the * of the document, assigning the filename of the given print job using the
* discovered title. If no title can be found within * discovered title. If no title can be found within
* GUAC_RDPDR_PRINT_JOB_TITLE_SEARCH_LENGTH bytes, this function has no effect. * GUAC_RDP_PRINT_JOB_TITLE_SEARCH_LENGTH bytes, this function has no effect.
* *
* @param job * @param job
* The job whose filename should be set if the document title can be found * The job whose filename should be set if the document title can be found
@ -577,21 +577,21 @@ static int guac_rdpdr_print_job_parse_title_header(guac_rdpdr_print_job* job,
* @param length * @param length
* The number of bytes within the buffer. * The number of bytes within the buffer.
*/ */
static void guac_rdpdr_print_job_read_filename(guac_rdpdr_print_job* job, static void guac_rdp_print_job_read_filename(guac_rdp_print_job* job,
void* buffer, int length) { void* buffer, int length) {
char* current = buffer; char* current = buffer;
int i; int i;
/* Restrict search area */ /* Restrict search area */
if (length > GUAC_RDPDR_PRINT_JOB_TITLE_SEARCH_LENGTH) if (length > GUAC_RDP_PRINT_JOB_TITLE_SEARCH_LENGTH)
length = GUAC_RDPDR_PRINT_JOB_TITLE_SEARCH_LENGTH; length = GUAC_RDP_PRINT_JOB_TITLE_SEARCH_LENGTH;
/* Search for document title within buffer */ /* Search for document title within buffer */
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
/* If document title has been found, we're done */ /* If document title has been found, we're done */
if (guac_rdpdr_print_job_parse_title_header(job, current, length)) if (guac_rdp_print_job_parse_title_header(job, current, length))
break; break;
/* Advance to next character */ /* Advance to next character */
@ -602,18 +602,18 @@ static void guac_rdpdr_print_job_read_filename(guac_rdpdr_print_job* job,
} }
int guac_rdpdr_print_job_write(guac_rdpdr_print_job* job, int guac_rdp_print_job_write(guac_rdp_print_job* job,
void* buffer, int length) { void* buffer, int length) {
/* Create print job, if not yet created */ /* Create print job, if not yet created */
if (job->bytes_received == 0) { if (job->bytes_received == 0) {
/* Attempt to read document title from first buffer of data */ /* Attempt to read document title from first buffer of data */
guac_rdpdr_print_job_read_filename(job, buffer, length); guac_rdp_print_job_read_filename(job, buffer, length);
/* Begin print stream */ /* Begin print stream */
guac_client_for_user(job->client, job->user, guac_client_for_user(job->client, job->user,
guac_rdpdr_print_job_begin_stream, job); guac_rdp_print_job_begin_stream, job);
} }
@ -625,7 +625,7 @@ int guac_rdpdr_print_job_write(guac_rdpdr_print_job* job,
} }
void guac_rdpdr_print_job_free(guac_rdpdr_print_job* job) { void guac_rdp_print_job_free(guac_rdp_print_job* job) {
/* No more input will be provided */ /* No more input will be provided */
close(job->input_fd); close(job->input_fd);
@ -638,14 +638,14 @@ void guac_rdpdr_print_job_free(guac_rdpdr_print_job* job) {
} }
void guac_rdpdr_print_job_kill(guac_rdpdr_print_job* job) { void guac_rdp_print_job_kill(guac_rdp_print_job* job) {
/* Stop all handling of I/O */ /* Stop all handling of I/O */
close(job->input_fd); close(job->input_fd);
close(job->output_fd); close(job->output_fd);
/* Mark stream as closed */ /* Mark stream as closed */
guac_rdpdr_print_job_set_state(job, GUAC_RDPDR_PRINT_JOB_CLOSED); guac_rdp_print_job_set_state(job, GUAC_RDP_PRINT_JOB_CLOSED);
} }

View File

@ -17,8 +17,8 @@
* under the License. * under the License.
*/ */
#ifndef GUAC_RDPDR_PRINT_JOB_H #ifndef GUAC_RDP_PRINT_JOB_H
#define GUAC_RDPDR_PRINT_JOB_H #define GUAC_RDP_PRINT_JOB_H
#include "config.h" #include "config.h"
@ -30,33 +30,33 @@
#include <unistd.h> #include <unistd.h>
/** /**
* The maximum number of bytes in the filename of an RDPDR print job sent as a * The maximum number of bytes in the filename of an RDP print job sent as a
* file over the Guacamole protocol, including NULL terminator. * file over the Guacamole protocol, including NULL terminator.
*/ */
#define GUAC_RDPDR_PRINT_JOB_FILENAME_MAX_LENGTH 1024 #define GUAC_RDP_PRINT_JOB_FILENAME_MAX_LENGTH 1024
/** /**
* The default filename to use for the PDF output of an RDPDR print job if no * The default filename to use for the PDF output of an RDP print job if no
* document title can be found within the printed data. * document title can be found within the printed data.
*/ */
#define GUAC_RDPDR_PRINT_JOB_DEFAULT_FILENAME "guacamole-print.pdf" #define GUAC_RDP_PRINT_JOB_DEFAULT_FILENAME "guacamole-print.pdf"
/** /**
* The maximum number of bytes to search through at the beginning of a * The maximum number of bytes to search through at the beginning of a
* PostScript document when locating the document title. * PostScript document when locating the document title.
*/ */
#define GUAC_RDPDR_PRINT_JOB_TITLE_SEARCH_LENGTH 2048 #define GUAC_RDP_PRINT_JOB_TITLE_SEARCH_LENGTH 2048
/** /**
* The current state of an RDPDR print job. * The current state of an RDP print job.
*/ */
typedef enum guac_rdpdr_print_job_state { typedef enum guac_rdp_print_job_state {
/** /**
* The print stream has been opened with the Guacamole client, but the * The print stream has been opened with the Guacamole client, but the
* client has not yet confirmed that it is ready to receive data. * client has not yet confirmed that it is ready to receive data.
*/ */
GUAC_RDPDR_PRINT_JOB_WAITING_FOR_ACK, GUAC_RDP_PRINT_JOB_WAITING_FOR_ACK,
/** /**
* The print stream has been opened with the Guacamole client, and the * The print stream has been opened with the Guacamole client, and the
@ -64,20 +64,20 @@ typedef enum guac_rdpdr_print_job_state {
* receive data (or that data has been received and it is ready to receive * receive data (or that data has been received and it is ready to receive
* more). * more).
*/ */
GUAC_RDPDR_PRINT_JOB_ACK_RECEIVED, GUAC_RDP_PRINT_JOB_ACK_RECEIVED,
/** /**
* The print stream has been closed or the printer is terminating, and no * The print stream has been closed or the printer is terminating, and no
* further data should be sent to the client. * further data should be sent to the client.
*/ */
GUAC_RDPDR_PRINT_JOB_CLOSED GUAC_RDP_PRINT_JOB_CLOSED
} guac_rdpdr_print_job_state; } guac_rdp_print_job_state;
/** /**
* Data specific to an instance of the printer device. * Data specific to an instance of the printer device.
*/ */
typedef struct guac_rdpdr_print_job { typedef struct guac_rdp_print_job {
guac_client* client; guac_client* client;
@ -101,7 +101,7 @@ typedef struct guac_rdpdr_print_job {
* streamed to the Guacamole user. This value will be automatically * streamed to the Guacamole user. This value will be automatically
* determined based on the contents of the printed document. * determined based on the contents of the printed document.
*/ */
char filename[GUAC_RDPDR_PRINT_JOB_FILENAME_MAX_LENGTH]; char filename[GUAC_RDP_PRINT_JOB_FILENAME_MAX_LENGTH];
/** /**
* File descriptor that should be written to when sending documents to the * File descriptor that should be written to when sending documents to the
@ -121,7 +121,7 @@ typedef struct guac_rdpdr_print_job {
* acknowledged receipt of data along the steam, and whether the print * acknowledged receipt of data along the steam, and whether the print
* stream itself has closed. * stream itself has closed.
*/ */
guac_rdpdr_print_job_state state; guac_rdp_print_job_state state;
/** /**
* Lock which is acquired prior to modifying the state property or waiting * Lock which is acquired prior to modifying the state property or waiting
@ -145,17 +145,17 @@ typedef struct guac_rdpdr_print_job {
*/ */
int bytes_received; int bytes_received;
} guac_rdpdr_print_job; } guac_rdp_print_job;
/** /**
* A blob of print data being sent to the Guacamole user. * A blob of print data being sent to the Guacamole user.
*/ */
typedef struct guac_rdpdr_print_blob { typedef struct guac_rdp_print_blob {
/** /**
* The print job which generated the data being sent. * The print job which generated the data being sent.
*/ */
guac_rdpdr_print_job* job; guac_rdp_print_job* job;
/** /**
* The data being sent. * The data being sent.
@ -167,7 +167,7 @@ typedef struct guac_rdpdr_print_blob {
*/ */
int length; int length;
} guac_rdpdr_print_blob; } guac_rdp_print_blob;
/** /**
* Allocates a new print job for the given user. It is expected that this * Allocates a new print job for the given user. It is expected that this
@ -183,10 +183,10 @@ typedef struct guac_rdpdr_print_blob {
* always be NULL. * always be NULL.
* *
* @return * @return
* A pointer to a newly-allocated guac_rdpdr_print_job, or NULL if the * A pointer to a newly-allocated guac_rdp_print_job, or NULL if the
* print job could not be created. * print job could not be created.
*/ */
void* guac_rdpdr_print_job_alloc(guac_user* user, void* data); void* guac_rdp_print_job_alloc(guac_user* user, void* data);
/** /**
* Writes PostScript print data to the given active print job. The print job * Writes PostScript print data to the given active print job. The print job
@ -204,7 +204,7 @@ void* guac_rdpdr_print_job_alloc(guac_user* user, void* data);
* The number of bytes written, or -1 if an error occurs which prevents * The number of bytes written, or -1 if an error occurs which prevents
* further writes. * further writes.
*/ */
int guac_rdpdr_print_job_write(guac_rdpdr_print_job* job, int guac_rdp_print_job_write(guac_rdp_print_job* job,
void* buffer, int length); void* buffer, int length);
/** /**
@ -216,17 +216,17 @@ int guac_rdpdr_print_job_write(guac_rdpdr_print_job* job,
* @param job * @param job
* The print job to free. * The print job to free.
*/ */
void guac_rdpdr_print_job_free(guac_rdpdr_print_job* job); void guac_rdp_print_job_free(guac_rdp_print_job* job);
/** /**
* Forcibly kills the given print job, stopping all associated processing and * Forcibly kills the given print job, stopping all associated processing and
* streaming. The memory associated with the print job will still need to be * streaming. The memory associated with the print job will still need to be
* reclaimed via guac_rdpdr_print_job_free(). * reclaimed via guac_rdp_print_job_free().
* *
* @param job * @param job
* The print job to kill. * The print job to kill.
*/ */
void guac_rdpdr_print_job_kill(guac_rdpdr_print_job* job); void guac_rdp_print_job_kill(guac_rdp_print_job* job);
#endif #endif