GUACAMOLE-445: Pass printer name from settings to RDP session.

This commit is contained in:
Nick Couchman 2018-02-23 05:34:44 -05:00
parent b21f00c29d
commit e68fe81938
6 changed files with 17 additions and 14 deletions

View File

@ -273,4 +273,3 @@ void guac_rdpdr_process_prn_cache_data(guac_rdpdrPlugin* rdpdr, wStream* input_s
void guac_rdpdr_process_prn_using_xps(guac_rdpdrPlugin* rdpdr, wStream* input_stream) { void guac_rdpdr_process_prn_using_xps(guac_rdpdrPlugin* rdpdr, wStream* input_stream) {
guac_client_log(rdpdr->client, GUAC_LOG_INFO, "Printer unexpectedly switched to XPS mode"); guac_client_log(rdpdr->client, GUAC_LOG_INFO, "Printer unexpectedly switched to XPS mode");
} }

View File

@ -76,12 +76,6 @@
#define GUAC_PRINTER_DRIVER "M\0S\0 \0P\0u\0b\0l\0i\0s\0h\0e\0r\0 \0I\0m\0a\0g\0e\0s\0e\0t\0t\0e\0r\0\0\0" #define GUAC_PRINTER_DRIVER "M\0S\0 \0P\0u\0b\0l\0i\0s\0h\0e\0r\0 \0I\0m\0a\0g\0e\0s\0e\0t\0t\0e\0r\0\0\0"
#define GUAC_PRINTER_DRIVER_LENGTH 50 #define GUAC_PRINTER_DRIVER_LENGTH 50
/**
* Name of the printer itself.
*/
#define GUAC_PRINTER_NAME "G\0u\0a\0c\0a\0m\0o\0l\0e\0\0\0"
#define GUAC_PRINTER_NAME_LENGTH 20
/** /**
* Name of the filesystem. * Name of the filesystem.
*/ */

View File

@ -25,12 +25,14 @@
#include "rdp.h" #include "rdp.h"
#include "rdp_print_job.h" #include "rdp_print_job.h"
#include "rdp_status.h" #include "rdp_status.h"
#include "unicode.h"
#include <freerdp/utils/svc_plugin.h> #include <freerdp/utils/svc_plugin.h>
#include <guacamole/client.h> #include <guacamole/client.h>
#include <guacamole/protocol.h> #include <guacamole/protocol.h>
#include <guacamole/socket.h> #include <guacamole/socket.h>
#include <guacamole/stream.h> #include <guacamole/stream.h>
#include <guacamole/unicode.h>
#include <guacamole/user.h> #include <guacamole/user.h>
#ifdef ENABLE_WINPR #ifdef ENABLE_WINPR
@ -141,18 +143,25 @@ static void guac_rdpdr_device_printer_announce_handler(guac_rdpdr_device* device
Stream_Write(output_stream, "PRN1\0\0\0\0", 8); /* DOS name */ Stream_Write(output_stream, "PRN1\0\0\0\0", 8); /* DOS name */
/* Printer data */ /* Printer data */
Stream_Write_UINT32(output_stream, 24 + GUAC_PRINTER_DRIVER_LENGTH + GUAC_PRINTER_NAME_LENGTH); int settings_length = guac_utf8_strlen(device->device_name);
int printer_name_length = (settings_length + 1) * 2;
char printer_name[printer_name_length];
guac_rdp_utf8_to_utf16((const unsigned char*)device->device_name,
settings_length, printer_name, printer_name_length);
printer_name[printer_name_length - 2] = '\0';
printer_name[printer_name_length - 1] = '\0';
Stream_Write_UINT32(output_stream, 24 + GUAC_PRINTER_DRIVER_LENGTH + printer_name_length);
Stream_Write_UINT32(output_stream, Stream_Write_UINT32(output_stream,
RDPDR_PRINTER_ANNOUNCE_FLAG_DEFAULTPRINTER RDPDR_PRINTER_ANNOUNCE_FLAG_DEFAULTPRINTER
| RDPDR_PRINTER_ANNOUNCE_FLAG_NETWORKPRINTER); | RDPDR_PRINTER_ANNOUNCE_FLAG_NETWORKPRINTER);
Stream_Write_UINT32(output_stream, 0); /* reserved - must be 0 */ Stream_Write_UINT32(output_stream, 0); /* reserved - must be 0 */
Stream_Write_UINT32(output_stream, 0); /* PnPName length (PnPName is ultimately ignored) */ Stream_Write_UINT32(output_stream, 0); /* PnPName length (PnPName is ultimately ignored) */
Stream_Write_UINT32(output_stream, GUAC_PRINTER_DRIVER_LENGTH); /* DriverName length */ Stream_Write_UINT32(output_stream, GUAC_PRINTER_DRIVER_LENGTH); /* DriverName length */
Stream_Write_UINT32(output_stream, GUAC_PRINTER_NAME_LENGTH); /* PrinterName length */ Stream_Write_UINT32(output_stream, printer_name_length); /* PrinterName length */
Stream_Write_UINT32(output_stream, 0); /* CachedFields length */ Stream_Write_UINT32(output_stream, 0); /* CachedFields length */
Stream_Write(output_stream, GUAC_PRINTER_DRIVER, GUAC_PRINTER_DRIVER_LENGTH); Stream_Write(output_stream, GUAC_PRINTER_DRIVER, GUAC_PRINTER_DRIVER_LENGTH);
Stream_Write(output_stream, GUAC_PRINTER_NAME, GUAC_PRINTER_NAME_LENGTH); Stream_Write(output_stream, printer_name, printer_name_length);
} }
@ -190,7 +199,7 @@ static void guac_rdpdr_device_printer_free_handler(guac_rdpdr_device* device) {
/* Do nothing */ /* Do nothing */
} }
void guac_rdpdr_register_printer(guac_rdpdrPlugin* rdpdr) { void guac_rdpdr_register_printer(guac_rdpdrPlugin* rdpdr, char* printer_name) {
int id = rdpdr->devices_registered++; int id = rdpdr->devices_registered++;
@ -200,7 +209,7 @@ void guac_rdpdr_register_printer(guac_rdpdrPlugin* rdpdr) {
/* Init device */ /* Init device */
device->rdpdr = rdpdr; device->rdpdr = rdpdr;
device->device_id = id; device->device_id = id;
device->device_name = "Guacamole Printer"; device->device_name = printer_name;
/* Set handlers */ /* Set handlers */
device->announce_handler = guac_rdpdr_device_printer_announce_handler; device->announce_handler = guac_rdpdr_device_printer_announce_handler;

View File

@ -35,7 +35,7 @@
* Registers a new printer device within the RDPDR plugin. This must be done * Registers a new printer device within the RDPDR plugin. This must be done
* before RDPDR connection finishes. * before RDPDR connection finishes.
*/ */
void guac_rdpdr_register_printer(guac_rdpdrPlugin* rdpdr); void guac_rdpdr_register_printer(guac_rdpdrPlugin* rdpdr, char* printer_name);
#endif #endif

View File

@ -96,7 +96,7 @@ void guac_rdpdr_process_connect(rdpSvcPlugin* plugin) {
/* Register printer if enabled */ /* Register printer if enabled */
if (rdp_client->settings->printing_enabled) if (rdp_client->settings->printing_enabled)
guac_rdpdr_register_printer(rdpdr); guac_rdpdr_register_printer(rdpdr, rdp_client->settings->printer_name);
/* Register drive if enabled */ /* Register drive if enabled */
if (rdp_client->settings->drive_enabled) if (rdp_client->settings->drive_enabled)

View File

@ -990,6 +990,7 @@ void guac_rdp_settings_free(guac_rdp_settings* settings) {
free(settings->remote_app_args); free(settings->remote_app_args);
free(settings->remote_app_dir); free(settings->remote_app_dir);
free(settings->username); free(settings->username);
free(settings->printer_name);
/* Free channel name array */ /* Free channel name array */
if (settings->svc_names != NULL) { if (settings->svc_names != NULL) {