diff options
author | Pierre Ossman <ossman@cendio.se> | 2016-01-22 16:40:59 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2019-07-01 10:49:15 +0200 |
commit | 56fa7821560a60db39195e8c81d16b46e8f972c2 (patch) | |
tree | cc2013baaa127f3e6db22de64155b0fd0c85c4a9 /unix | |
parent | 66f1db543b425f6fe64d437477e6f78924ec57be (diff) | |
download | tigervnc-56fa7821560a60db39195e8c81d16b46e8f972c2.tar.gz tigervnc-56fa7821560a60db39195e8c81d16b46e8f972c2.zip |
Add UTF-8 to/from ISO 8859-1 conversion routines
We convert between UTF-8 and ISO 8859-1 (latin 1) in several places
so create some common routines for this.
Diffstat (limited to 'unix')
-rw-r--r-- | unix/xserver/hw/vnc/RFBGlue.cc | 18 | ||||
-rw-r--r-- | unix/xserver/hw/vnc/RFBGlue.h | 4 | ||||
-rw-r--r-- | unix/xserver/hw/vnc/vncSelection.c | 73 |
3 files changed, 30 insertions, 65 deletions
diff --git a/unix/xserver/hw/vnc/RFBGlue.cc b/unix/xserver/hw/vnc/RFBGlue.cc index d9c456e8..f108fae4 100644 --- a/unix/xserver/hw/vnc/RFBGlue.cc +++ b/unix/xserver/hw/vnc/RFBGlue.cc @@ -220,6 +220,24 @@ char* vncConvertLF(const char* src, size_t bytes) } } +char* vncLatin1ToUTF8(const char* src, size_t bytes) +{ + try { + return latin1ToUTF8(src, bytes); + } catch (...) { + return NULL; + } +} + +char* vncUTF8ToLatin1(const char* src, size_t bytes) +{ + try { + return utf8ToLatin1(src, bytes); + } catch (...) { + return NULL; + } +} + void vncStrFree(char* str) { strFree(str); diff --git a/unix/xserver/hw/vnc/RFBGlue.h b/unix/xserver/hw/vnc/RFBGlue.h index 8e70c680..112405b8 100644 --- a/unix/xserver/hw/vnc/RFBGlue.h +++ b/unix/xserver/hw/vnc/RFBGlue.h @@ -50,6 +50,10 @@ int vncGetSocketPort(int fd); int vncIsTCPPortUsed(int port); char* vncConvertLF(const char* src, size_t bytes); + +char* vncLatin1ToUTF8(const char* src, size_t bytes); +char* vncUTF8ToLatin1(const char* src, size_t bytes); + void vncStrFree(char* str); #ifdef __cplusplus diff --git a/unix/xserver/hw/vnc/vncSelection.c b/unix/xserver/hw/vnc/vncSelection.c index 8f4146d9..3438ac86 100644 --- a/unix/xserver/hw/vnc/vncSelection.c +++ b/unix/xserver/hw/vnc/vncSelection.c @@ -247,36 +247,16 @@ static int vncConvertSelection(ClientPtr client, Atom selection, if (rc != Success) return rc; } else if (target == xaUTF8_STRING) { - unsigned char* buffer; - unsigned char* out; - size_t len; + char* buffer; - const unsigned char* in; - size_t in_len; - - buffer = malloc(strlen(clientCutText)*2); + buffer = vncLatin1ToUTF8(clientCutText, (size_t)-1); if (buffer == NULL) return BadAlloc; - out = buffer; - len = 0; - in = clientCutText; - while (*in != '\0') { - if (*in & 0x80) { - *out++ = 0xc0 | (*in >> 6); - *out++ = 0x80 | (*in & 0x3f); - len += 2; - in++; - } else { - *out++ = *in++; - len++; - } - } - rc = dixChangeWindowProperty(serverClient, pWin, realProperty, xaUTF8_STRING, 8, PropModeReplace, - len, buffer, TRUE); - free(buffer); + strlen(buffer), buffer, TRUE); + vncStrFree(buffer); if (rc != Success) return rc; } else { @@ -424,56 +404,19 @@ static void vncHandleSelection(Atom selection, Atom target, vncStrFree(filtered); } else if (target == xaUTF8_STRING) { char *filtered; - unsigned char* buffer; - unsigned char* out; - size_t len; - - const unsigned char* in; - size_t in_len; + char* buffer; if (prop->format != 8) return; if (prop->type != xaUTF8_STRING) return; - buffer = malloc(prop->size); + buffer = vncUTF8ToLatin1(prop->data, prop->size); if (buffer == NULL) return; - out = buffer; - len = 0; - in = prop->data; - in_len = prop->size; - while (in_len > 0) { - if ((*in & 0x80) == 0x00) { - *out++ = *in++; - len++; - in_len--; - } else if ((*in & 0xe0) == 0xc0) { - unsigned ucs; - ucs = (*in++ & 0x1f) << 6; - in_len--; - if (in_len > 0) { - ucs |= (*in++ & 0x3f); - in_len--; - } - if (ucs <= 0xff) - *out++ = ucs; - else - *out++ = '?'; - len++; - } else { - *out++ = '?'; - len++; - do { - in++; - in_len--; - } while ((in_len > 0) && ((*in & 0xc0) == 0x80)); - } - } - - filtered = vncConvertLF(buffer, len); - free(buffer); + filtered = vncConvertLF(buffer, (size_t)-1); + vncStrFree(buffer); if (filtered == NULL) return; |