GUAC-298: Clarify function documentation and naming. Do not simply silently default to ISO8859-1 if encoding is invalid.

This commit is contained in:
Michael Jumper 2015-07-27 18:19:50 -07:00
parent 7bfd7ce0ca
commit 5e4c7de5c7

View File

@ -222,42 +222,62 @@ static rfbClient* __guac_vnc_get_client(guac_client* client) {
}
/**
* Configure the VNC clipboard reader/writer based on configured encoding.
* Defaults to standard ISO8859-1 encoding if an invalid format is encountered.
* Sets the encoding of clipboard data exchanged with the VNC server to the
* encoding having the given name. If the name is left blank, or is invalid,
* the standard ISO8859-1 encoding will be used.
*
* @param guac_client_data
* Structure containing VNC client configuration.
* @param client
* The client to set the clipboard encoding of.
*
* @param name
* Encoding name.
* The name of the encoding to use for all clipboard data. Valid values
* are: "ISO8859-1", "UTF-8", "UTF-16", "CP1252", or "".
*
* @return
* Returns 0 if standard ISO8859-1 encoding is used, 1 otherwise.
* Zero if the chosen encoding is standard for VNC, or non-zero if the VNC
* standard is being violated.
*/
int __guac_client_configure_clipboard_encoding(vnc_guac_client_data* guac_client_data, const char* name) {
static int guac_vnc_set_clipboard_encoding(guac_client* client,
const char* name) {
/* Configure clipboard reader/writer based on encoding name */
vnc_guac_client_data* guac_client_data =
(vnc_guac_client_data*) client->data;
/* Use ISO8859-1 if explicitly selected or blank */
if (name[0] == '\0' || strcmp(name, "ISO8859-1") == 0) {
guac_client_data->clipboard_reader = GUAC_READ_ISO8859_1;
guac_client_data->clipboard_writer = GUAC_WRITE_ISO8859_1;
return 0;
}
/* UTF-8 */
if (strcmp(name, "UTF-8") == 0) {
guac_client_data->clipboard_reader = GUAC_READ_UTF8;
guac_client_data->clipboard_writer = GUAC_WRITE_UTF8;
return 1;
}
else if (strcmp(name, "UTF-16") == 0) {
/* UTF-16 */
if (strcmp(name, "UTF-16") == 0) {
guac_client_data->clipboard_reader = GUAC_READ_UTF16;
guac_client_data->clipboard_writer = GUAC_WRITE_UTF16;
return 1;
}
else if (strcmp(name, "CP-1252") == 0) {
/* CP1252 */
if (strcmp(name, "CP1252") == 0) {
guac_client_data->clipboard_reader = GUAC_READ_CP1252;
guac_client_data->clipboard_writer = GUAC_WRITE_CP1252;
return 1;
}
else {
/* Default to ISO8859-1 */
/* If encoding unrecognized, warn and default to ISO8859-1 */
guac_client_log(client, GUAC_LOG_WARNING,
"Encoding '%s' is invalid. Defaulting to ISO8859-1.", name);
guac_client_data->clipboard_reader = GUAC_READ_ISO8859_1;
guac_client_data->clipboard_writer = GUAC_WRITE_ISO8859_1;
return 0;
}
}
@ -336,11 +356,10 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
guac_client_data->clipboard = guac_common_clipboard_alloc(GUAC_VNC_CLIPBOARD_MAX_LENGTH);
/* Configure clipboard encoding */
if (__guac_client_configure_clipboard_encoding(
guac_client_data, argv[IDX_CLIPBOARD_ENCODING])) {
if (guac_vnc_set_clipboard_encoding(client, argv[IDX_CLIPBOARD_ENCODING]))
guac_client_log(client, GUAC_LOG_INFO,
"Using non-standard VNC clipboard encoding: '%s'.", argv[IDX_CLIPBOARD_ENCODING]);
}
"Using non-standard VNC clipboard encoding: '%s'.",
argv[IDX_CLIPBOARD_ENCODING]);
/* Ensure connection is kept alive during lengthy connects */
guac_socket_require_keep_alive(client->socket);