Github user necouchman commented on a diff in the pull request: https://github.com/apache/guacamole-server/pull/154#discussion_r178643311 --- Diff: src/protocols/rdp/guac_rdpdr/rdpdr_printer.c --- @@ -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 */ /* 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 = malloc(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, RDPDR_PRINTER_ANNOUNCE_FLAG_DEFAULTPRINTER | RDPDR_PRINTER_ANNOUNCE_FLAG_NETWORKPRINTER); 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, 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(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); --- End diff -- Okay, a couple of clarification questions/concerns, here: - For tracking the size of arbitrary data within the `guac_rdpdr_device`, are you thinking all of the data - name, type, and then anything in the `data` field? Or just the size of the `data` field? - The only potential issue with getting rid of `announce_handler`s entirely is that the complexity of the printer one is significantly larger than that of the filesystem one. I can still do this, it just means that `guac_rdpdr_send_client_device_list_announce_request()` will end up with either some `if...else if` statements or a `switch` statement to handle initialization that goes with each of the devices. Or did you envision keeping the `announce_handler`s in some form, just moving a bunch of the code over to the `guac_rdpdr_send_client_device_list_announce_request()` function?
---