UTF8 capable Clipboard Functions - #176
Conversation
any1
left a comment
There was a problem hiding this comment.
I think that we can just convert everything to utf-8 with the old cuttext api.
The thing is that wayvnc expects utf-8 anyway.
This is all broken as is, and converting like you're doing fixes it.
7c0c5fb to
32d3ab3
Compare
| return lf_buf; | ||
| } | ||
|
|
||
| static void notify_cut_text(struct nvnc_client* client, const char* text, |
There was a problem hiding this comment.
boolean arguments like this are bit of an anti-pattern imo.
I recommend splitting this into two functions instead, named: notify_cut_text_utf8 and notify_cut_text_latin1.
This makes the control flow evident without having to look into this function to see what the bool does.
| /* Broadcast clipboard text. Extended clients are sent utf8_text and legacy | ||
| * clients latin1_text; the two may point at the same buffer when no conversion | ||
| * is needed. */ | ||
| static void send_cut_text(struct nvnc* server, const char* utf8_text, |
There was a problem hiding this comment.
This function split obfuscates things a bit. The fact that you or or LLM decided that it need an explanation is a bit of a tell.
| void nvnc_send_cut_text(struct nvnc* server, const char* text, uint32_t len) | ||
| { | ||
| /* text is UTF-8. Legacy clients need Latin-1, so convert only when one | ||
| * is actually connected. */ |
There was a problem hiding this comment.
/* comments should be
* written like this
*/
/* they should not be written
* like this */
| * is actually connected. */ | ||
| struct nvnc_client* client; | ||
|
|
||
| bool legacy_in_use = false; |
| } | ||
|
|
||
| /* Reject overlong encodings, UTF-16 surrogates and code points | ||
| * beyond the Unicode range. */ |
| static void test_single_utf8_to_latin1(const char* input, const char* expected) | ||
| { | ||
| size_t outlen; | ||
| const char * got = utf8_to_latin1(input, strlen(input), &outlen); |
| static void test_latin_to_utf8_and_back(const char* input, const char* expected) | ||
| { | ||
| size_t outlen; | ||
| const char * got = latin1_to_utf8(input, strlen(input), &outlen); |
| #include <stdint.h> | ||
| #include <stdlib.h> | ||
|
|
||
| char* latin1_to_utf8(const char* src, size_t len, size_t* out_len) |
There was a problem hiding this comment.
In this project, the destination buffer is on the left and the source buffer on the right, just like in assignment
dst = src;
|
Hi @any1, thanks for the review. It will take a couple of days, as we are on holiday right now. |
Plain cut text is Latin-1 while the extended clipboard is UTF-8. Always deliver received text to the handler as UTF-8, and accept UTF-8 in nvnc_send_cut_text, converting to Latin-1 for clients without the extended clipboard.
|
@any1 Hi, I updated the PR and tried to address all issues. Now rebased, testetd with RealVnc (legacy) and NoVNC(extended). Feel free to edit cosmetic things directly. |
|
Looks correct, both in form and function. I do wonder though if doing the conversion before iterating over clients is worth it, given that the number of clients is usually 1. With multiple clients video encoding cost dominates. Text encoding conversion is unlikely to ever be more expensive than that. |
|
Feel free to change, I am happy that it's tested right now and still readable. |
Fix for #174
I started with
nvnc_set_cut_text_with_encoding_fnandnvnc_send_cut_text_with_encoding, however there was a problem. If I send with utf8 enabled and the client is only latin1-capable, there needs to be a way to convert from utf8 to latin1. Same problem happens other way around: If the client uses cut text extensions, we need to convert from latin1 to utf8. Given that the server now has utf8 conversions methods, it can also directly expose utf8-cut-text versions. So we are now withnvnc_set_cut_text_utf8_fnandnvnc_send_cut_text_utf8.When converting utf8 to latin1, unknown characters are replaced by
?.The conversion routines are AI written.
I tested with an old Real VNC Viewer (no cut text extension) and NoVnc (has cut text extension).
I have read and understood CONTRIBUTING.md.