diff options
author | Brian Hinz <bphinz@users.sourceforge.net> | 2011-05-17 03:06:24 +0000 |
---|---|---|
committer | Brian Hinz <bphinz@users.sourceforge.net> | 2011-05-17 03:06:24 +0000 |
commit | 17fca55bc93139554e9259e78e9bad39d846141d (patch) | |
tree | 10b1b43913c7ee9efaf4ae1e0b151a10a370a3ec | |
parent | 61fd486451639c282f47d8ff58d22c7a8344703b (diff) | |
download | tigervnc-17fca55bc93139554e9259e78e9bad39d846141d.tar.gz tigervnc-17fca55bc93139554e9259e78e9bad39d846141d.zip |
changed string reads/writes to use utf-8. Also fixed location of icon resource.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4420 3789f03b-4d11-0410-bbf8-ca57d06f2519
-rw-r--r-- | java/src/com/tigervnc/rdr/InStream.java | 18 | ||||
-rw-r--r-- | java/src/com/tigervnc/rdr/OutStream.java | 10 | ||||
-rw-r--r-- | java/src/com/tigervnc/rfb/CMsgReader.java | 8 | ||||
-rw-r--r-- | java/src/com/tigervnc/rfb/CMsgWriter.java | 7 | ||||
-rw-r--r-- | java/src/com/tigervnc/rfb/CSecurityManaged.java | 7 | ||||
-rw-r--r-- | java/src/com/tigervnc/rfb/CSecurityPlain.java | 11 | ||||
-rw-r--r-- | java/src/com/tigervnc/rfb/CSecurityVncAuth.java | 8 | ||||
-rw-r--r-- | java/src/com/tigervnc/vncviewer/CConn.java | 2 | ||||
-rw-r--r-- | java/src/com/tigervnc/vncviewer/ClipboardDialog.java | 12 | ||||
-rw-r--r-- | java/src/com/tigervnc/vncviewer/DesktopWindow.java | 9 |
10 files changed, 58 insertions, 34 deletions
diff --git a/java/src/com/tigervnc/rdr/InStream.java b/java/src/com/tigervnc/rdr/InStream.java index ec2d6d7c..9b299302 100644 --- a/java/src/com/tigervnc/rdr/InStream.java +++ b/java/src/com/tigervnc/rdr/InStream.java @@ -73,16 +73,16 @@ abstract public class InStream { if (len > maxStringLength) throw new Exception("InStream max string length exceeded"); - char[] str = new char[len]; - int i = 0; - while (i < len) { - int j = i + check(1, len - i); - while (i < j) { - str[i++] = (char)b[ptr++]; - } + byte[] str = new byte[len+1]; + readBytes(str, 0, len); + str[len] = 0; + String utf8string = new String(); + try { + utf8string = new String(str,"UTF8"); + } catch(java.io.UnsupportedEncodingException e) { + e.printStackTrace(); } - - return new String(str); + return utf8string; } // maxStringLength protects against allocating a huge buffer. Set it diff --git a/java/src/com/tigervnc/rdr/OutStream.java b/java/src/com/tigervnc/rdr/OutStream.java index 7b4869e0..06f832d9 100644 --- a/java/src/com/tigervnc/rdr/OutStream.java +++ b/java/src/com/tigervnc/rdr/OutStream.java @@ -63,11 +63,11 @@ abstract public class OutStream { public final void writeString(String str) { int len = str.length(); writeU32(len); - for (int i = 0; i < len;) { - int j = i + check(1, len - i); - while (i < j) { - b[ptr++] = (byte)str.charAt(i++); - } + try { + byte[] utf8str = str.getBytes("UTF8"); + writeBytes(utf8str, 0, len); + } catch(java.io.UnsupportedEncodingException e) { + e.printStackTrace(); } } diff --git a/java/src/com/tigervnc/rfb/CMsgReader.java b/java/src/com/tigervnc/rfb/CMsgReader.java index 66b9d174..41230560 100644 --- a/java/src/com/tigervnc/rfb/CMsgReader.java +++ b/java/src/com/tigervnc/rfb/CMsgReader.java @@ -64,7 +64,13 @@ abstract public class CMsgReader { } byte[] buf = new byte[len]; is.readBytes(buf, 0, len); - handler.serverCutText(new String(buf), len); + String str = new String(); + try { + str = new String(buf,"UTF8"); + } catch(java.io.UnsupportedEncodingException e) { + e.printStackTrace(); + } + handler.serverCutText(str, len); } protected void readFramebufferUpdateStart() diff --git a/java/src/com/tigervnc/rfb/CMsgWriter.java b/java/src/com/tigervnc/rfb/CMsgWriter.java index 79f5ee99..7abbc09c 100644 --- a/java/src/com/tigervnc/rfb/CMsgWriter.java +++ b/java/src/com/tigervnc/rfb/CMsgWriter.java @@ -144,7 +144,12 @@ abstract public class CMsgWriter { startMsg(MsgTypes.msgTypeClientCutText); os.pad(3); os.writeU32(len); - os.writeBytes(str.getBytes(), 0, len); + try { + byte[] utf8str = str.getBytes("UTF8"); + os.writeBytes(utf8str, 0, len); + } catch(java.io.UnsupportedEncodingException e) { + e.printStackTrace(); + } endMsg(); } diff --git a/java/src/com/tigervnc/rfb/CSecurityManaged.java b/java/src/com/tigervnc/rfb/CSecurityManaged.java index 3502289f..2461682d 100644 --- a/java/src/com/tigervnc/rfb/CSecurityManaged.java +++ b/java/src/com/tigervnc/rfb/CSecurityManaged.java @@ -37,7 +37,12 @@ public class CSecurityManaged extends CSecurity { // Return the response to the server os.writeU8(username.length()); - os.writeBytes(username.toString().getBytes(), 0, username.length()); + try { + byte[] utf8str = username.toString().getBytes("UTF8"); + os.writeBytes(utf8str, 0, username.length()); + } catch(java.io.UnsupportedEncodingException e) { + e.printStackTrace(); + } os.flush(); int serverPort = is.readU16(); //if (serverPort==0) { return true; }; diff --git a/java/src/com/tigervnc/rfb/CSecurityPlain.java b/java/src/com/tigervnc/rfb/CSecurityPlain.java index c790852b..707915cc 100644 --- a/java/src/com/tigervnc/rfb/CSecurityPlain.java +++ b/java/src/com/tigervnc/rfb/CSecurityPlain.java @@ -37,8 +37,15 @@ public class CSecurityPlain extends CSecurity { // Return the response to the server os.writeU32(username.length()); os.writeU32(password.length()); - os.writeBytes(username.toString().getBytes(), 0, username.length()); - os.writeBytes(password.toString().getBytes(), 0, password.length()); + byte[] utf8str; + try { + utf8str = username.toString().getBytes("UTF8"); + os.writeBytes(utf8str, 0, username.length()); + utf8str = password.toString().getBytes("UTF8"); + os.writeBytes(utf8str, 0, password.length()); + } catch(java.io.UnsupportedEncodingException e) { + e.printStackTrace(); + } os.flush(); return true; } diff --git a/java/src/com/tigervnc/rfb/CSecurityVncAuth.java b/java/src/com/tigervnc/rfb/CSecurityVncAuth.java index f047f530..75673d51 100644 --- a/java/src/com/tigervnc/rfb/CSecurityVncAuth.java +++ b/java/src/com/tigervnc/rfb/CSecurityVncAuth.java @@ -41,8 +41,14 @@ public class CSecurityVncAuth extends CSecurity { // Calculate the correct response
byte[] key = new byte[8];
int pwdLen = passwd.length();
+ byte[] utf8str = new byte[pwdLen]; + try { + utf8str = passwd.toString().getBytes("UTF8"); + } catch(java.io.UnsupportedEncodingException e) { + e.printStackTrace(); + } for (int i=0; i<8; i++)
- key[i] = i<pwdLen ? (byte)passwd.charAt(i) : 0;
+ key[i] = i<pwdLen ? utf8str[i] : 0;
DesCipher des = new DesCipher(key);
for (int j = 0; j < vncAuthChallengeSize; j += 8)
des.encrypt(challenge,j,challenge,j);
diff --git a/java/src/com/tigervnc/vncviewer/CConn.java b/java/src/com/tigervnc/vncviewer/CConn.java index bda9cffc..26dd2a53 100644 --- a/java/src/com/tigervnc/vncviewer/CConn.java +++ b/java/src/com/tigervnc/vncviewer/CConn.java @@ -416,7 +416,7 @@ public class CConn extends CConnection viewport = new ViewportFrame(cp.name(), this);
viewport.setUndecorated(fullScreen);
ClassLoader loader = this.getClass().getClassLoader();
- URL url = loader.getResource("tigervnc.ico");
+ URL url = loader.getResource("com/tigervnc/vncviewer/tigervnc.ico");
ImageIcon icon = null;
if (url != null) {
icon = new ImageIcon(url);
diff --git a/java/src/com/tigervnc/vncviewer/ClipboardDialog.java b/java/src/com/tigervnc/vncviewer/ClipboardDialog.java index 9753b152..eeeeb256 100644 --- a/java/src/com/tigervnc/vncviewer/ClipboardDialog.java +++ b/java/src/com/tigervnc/vncviewer/ClipboardDialog.java @@ -49,13 +49,6 @@ class ClipboardDialog extends Dialog implements ActionListener { pack();
}
- static Clipboard systemClipboard;
- static {
- try {
- systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
- } catch (Exception e) { }
- }
-
public void initDialog() {
textArea.setText(current);
textArea.selectAll();
@@ -69,10 +62,11 @@ class ClipboardDialog extends Dialog implements ActionListener { public void serverCutText(String str, int len) {
setContents(str);
- if (systemClipboard != null) {
+ Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
+ if (cb != null) {
StringSelection ss = new StringSelection(str);
try {
- systemClipboard.setContents(ss, ss);
+ cb.setContents(ss, ss);
} catch(Exception e) {
vlog.debug(e.toString());
}
diff --git a/java/src/com/tigervnc/vncviewer/DesktopWindow.java b/java/src/com/tigervnc/vncviewer/DesktopWindow.java index 4fd80d31..d008b41c 100644 --- a/java/src/com/tigervnc/vncviewer/DesktopWindow.java +++ b/java/src/com/tigervnc/vncviewer/DesktopWindow.java @@ -30,6 +30,7 @@ import java.awt.event.*; import java.awt.image.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.Clipboard; import javax.swing.*; import com.tigervnc.rfb.*; @@ -305,12 +306,12 @@ class DesktopWindow extends JPanel implements String oldContents = "";
synchronized public void checkClipboard() {
- if (ClipboardDialog.systemClipboard != null &&
- cc.viewer.sendClipboard.getValue()) {
- Transferable t = ClipboardDialog.systemClipboard.getContents(this);
+ Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); + if (cb != null && cc.viewer.sendClipboard.getValue()) {
+ Transferable t = cb.getContents(null);
if ((t != null) && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
- String newContents = (String) t.getTransferData(DataFlavor.stringFlavor);
+ String newContents = (String)t.getTransferData(DataFlavor.stringFlavor);
if (newContents != null && !newContents.equals(oldContents)) {
cc.writeClientCutText(newContents, newContents.length());
oldContents = newContents;
|