Skip to content

Commit

Permalink
Android: VNCConn: add UTF-8 cuttext sending
Browse files Browse the repository at this point in the history
Closes #252
  • Loading branch information
bk138 committed Jan 26, 2025
1 parent 26004a1 commit adb0f6d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
14 changes: 14 additions & 0 deletions android/app/src/main/cpp/vncconn.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,20 @@ JNIEXPORT jboolean JNICALL Java_com_coboltforge_dontmind_multivnc_VNCConn_rfbSen
return JNI_FALSE;
}

JNIEXPORT jboolean JNICALL Java_com_coboltforge_dontmind_multivnc_VNCConn_rfbSendClientCutTextUTF8(JNIEnv *env, jobject obj, jstring jText) {
rfbClient *cl = getRfbClient(env, obj);
if (cl) {
const char *cText = (*env)->GetStringUTFChars(env, jText, NULL);
if (!cText)
return JNI_FALSE;
jboolean status = SendClientCutTextUTF8(cl, (char *) cText, (int) strlen(cText));
(*env)->ReleaseStringUTFChars(env, jText, cText);
return status;
}
else
return JNI_FALSE;
}

JNIEXPORT jboolean JNICALL Java_com_coboltforge_dontmind_multivnc_VNCConn_rfbIsEncrypted(JNIEnv *env, jobject obj) {
rfbClient *cl = getRfbClient(env, obj);
if (cl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,21 @@ private boolean sendKeyEvent(OutputEvent.KeyboardEvent evt) {


private boolean sendCutText(String text) {
boolean status = false;
if (rfbClient != 0) {
if (Utils.DEBUG()) Log.d(TAG, "sending cuttext " + text);
return rfbSendClientCutText(StandardCharsets.ISO_8859_1.encode(text).array());
// first, try sending UTF-8
if(rfbSendClientCutTextUTF8(text)) {
if (Utils.DEBUG()) Log.d(TAG, "Sent UTF-8 cuttext: '" + text + "' successfully");
status = true;
} else {
// server does not support Extended Clipboard, try Latin-1.
// encode() docs say: "This method always replaces malformed-input and unmappable-character
// sequences with this charset's default replacement string."
status = rfbSendClientCutText(StandardCharsets.ISO_8859_1.encode(text).array());
if (Utils.DEBUG()) Log.d(TAG, "Sent ISO-8859-1 cuttext: '" + text + "'" + (status ? "successfully" : "unsuccessfully"));
}
}
return false;
return status;
}


Expand All @@ -404,6 +414,7 @@ private native boolean rfbInit(String host, int port, int repeaterId, int bytesP
private native boolean rfbSendKeyEvent(long keysym, boolean down);
private native boolean rfbSendPointerEvent(int x, int y, int buttonMask);
private native boolean rfbSendClientCutText(byte[] bytes);
private native boolean rfbSendClientCutTextUTF8(String text);
private native boolean rfbIsEncrypted();


Expand Down

0 comments on commit adb0f6d

Please sign in to comment.