Skip to contentSkip to conversation

Add tight support to VNC

PATCH In review Alexander Graf 3 participants 19 messages Jan 29, 2009 Kbuild

lore
Share & tools
lore
#1 lore raw

PATCH 1/7 Split VNC defines to vnc.h

In reply to Alexander Graf

The VNC protocol contains quite some constants, some of which are currently hardcoded in the vnc.c code. This is not exactly pretty.

Let's move all those constants out to vnc.h, so they are clearly separated. While at it, I also included other defines that will be used later in this patch series.

---
 vnc.c |   36 +-----------------
 vnc.h |  130 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 131 insertions(+), 35 deletions(-)
 create mode 100644 vnc.h
vnc.c +1 -35
index 2b3a6eb..e88f38f 100644
@@ -32,6 +32,7 @@
 
 #define VNC_REFRESH_INTERVAL (1000 / 30)
 
+#include "vnc.h"
 #include "vnc_keysym.h"
 #include "keymaps.c"
 #include "d3des.h"
@@ -88,41 +89,6 @@ typedef void VncSendHextileTile(VncState *vs,
 
 #define VNC_AUTH_CHALLENGE_SIZE 16
 
-enum {
-    VNC_AUTH_INVALID = 0,
-    VNC_AUTH_NONE = 1,
-    VNC_AUTH_VNC = 2,
-    VNC_AUTH_RA2 = 5,
-    VNC_AUTH_RA2NE = 6,
-    VNC_AUTH_TIGHT = 16,
-    VNC_AUTH_ULTRA = 17,
-    VNC_AUTH_TLS = 18,
-    VNC_AUTH_VENCRYPT = 19
-};
-
-#ifdef CONFIG_VNC_TLS
-enum {
-    VNC_WIREMODE_CLEAR,
-    VNC_WIREMODE_TLS,
-};
-
-enum {
-    VNC_AUTH_VENCRYPT_PLAIN = 256,
-    VNC_AUTH_VENCRYPT_TLSNONE = 257,
-    VNC_AUTH_VENCRYPT_TLSVNC = 258,
-    VNC_AUTH_VENCRYPT_TLSPLAIN = 259,
-    VNC_AUTH_VENCRYPT_X509NONE = 260,
-    VNC_AUTH_VENCRYPT_X509VNC = 261,
-    VNC_AUTH_VENCRYPT_X509PLAIN = 262,
-};
-
-#define X509_CA_CERT_FILE "ca-cert.pem"
-#define X509_CA_CRL_FILE "ca-crl.pem"
-#define X509_SERVER_KEY_FILE "server-key.pem"
-#define X509_SERVER_CERT_FILE "server-cert.pem"
-
-#endif /* CONFIG_VNC_TLS */
-
 struct VncState
 {
     QEMUTimer *timer;
vnc.h new file +130 -0

130 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#6 lore raw

PATCH 6/7 Add tight protocol awareness to vnc.c

In reply to Alexander Graf

This patch enables the vnc server to understand the tight protocol.

Basically, negotiation if tight is existing happens through the authentication code. If a special authentication called VNC_AUTH_TIGHT is used, the real authentication is stacked afterwards and tight extensions exist.

In order to make it easier to add different encodings later, this patch also adds "preferred encoding" awareness, only saves the last preferred encoding though.

This way the client can choose which protocol it wants to use the most.

---
 vnc.c |  122 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 115 insertions(+), 7 deletions(-)
vnc.c +115 -7
index b4b0843..86e2a1b 100644
@@ -103,6 +103,10 @@ struct VncState
     int last_x;
     int last_y;
 
+    int vnc_encoding;
+    unsigned int tight_quality;
+    unsigned int tight_compression;
+
     int major;
     int minor;
 
@@ -451,10 +455,14 @@ static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, i
 
 static void send_framebuffer_update(VncState *vs, int x, int y, int w, int h)
 {
-	if (vnc_has_feature(vs, VNC_FEATURE_HEXTILE))
+    switch(vs->vnc_encoding) {
+	case VNC_ENCODING_HEXTILE:
 	    send_framebuffer_update_hextile(vs, x, y, w, h);
-	else
+	    break;
+	default:
 	    send_framebuffer_update_raw(vs, x, y, w, h);
+	    break;
+    }    
 }
 
 static void vnc_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int dst_y, int w, int h)
@@ -1165,19 +1173,38 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
     unsigned int enc = 0;
 
     vs->features = 0;
+    vs->vnc_encoding = 0;
+    vs->tight_compression=0;
+    vs->tight_quality=9;
     vs->absolute = -1;
     dcl->dpy_copy = NULL;
 
     for (i = n_encodings - 1; i >= 0; i--) {
         enc = encodings[i];
         switch (enc) {
+        case VNC_ENCODING_RRE:
+        case VNC_ENCODING_CORRE:
+        case VNC_ENCODING_ZLIB:
+        case VNC_ENCODING_ZLIBHEX:
+        case VNC_ENCODING_ZRLE:
+        case VNC_ENCODING_LASTRECT:
+        case VNC_ENCODING_POINTER_POS:
+        case VNC_ENCODING_RICH_CURSOR:
+        case VNC_ENCODING_XCURSOR:
+            /* Ingore - at least for now... */
+            break;
         case VNC_ENCODING_RAW:
+            vs->vnc_encoding = enc;
             break;
         case VNC_ENCODING_COPYRECT:
             dcl->dpy_copy = vnc_copy;
             break;
         case VNC_ENCODING_HEXTILE:
             vs->features |= VNC_FEATURE_HEXTILE_MASK;
+            vs->vnc_encoding = enc;
+            break;
+        case VNC_ENCODING_TIGHT:
+            vs->features |= VNC_FEATURE_TIGHT_MASK;
             break;
         case VNC_ENCODING_DESKTOPRESIZE:
             vs->features |= VNC_FEATURE_RESIZE_MASK;
@@ -1194,6 +1221,12 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
         case VNC_ENCODING_WMVi:
             vs->features |= VNC_FEATURE_WMVI_MASK;
             break;
+        case VNC_ENCODING_COMPRESSLEVEL0 ... VNC_ENCODING_COMPRESSLEVEL0 + 9:
+            vs->tight_compression = (enc & 0x0F);
+            break;
+        case VNC_ENCODING_QUALITYLEVEL0 ... VNC_ENCODING_QUALITYLEVEL0 + 9:
+            vs->tight_quality = (enc & 0x0F);
+            break;
         default:
              printf("Unknown encoding: %d (0x%.8x): %d\n", i, enc, enc);
             break;
@@ -1461,6 +1494,36 @@ static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len)
     return 0;
 }
 
+static void write_tight_capability(VncState *vs, int encoding,
+                                   const char *signature, const char *vendor)
+{
+	vnc_write_u32(vs, encoding);
+	vnc_write(vs, vendor, 4);
+	vnc_write(vs, signature, 8);
+}
+
+static void write_tight_interaction_capabilities(VncState *vs)
+{
+    VNC_DEBUG("Sending Tight capabilities...\n");
+    vnc_write_u16(vs, 0); /* nServerMessageTypes  */
+    vnc_write_u16(vs, 0); /* nClientMessageTypes  */ 
+    vnc_write_u16(vs, 5); /* nEncodingTypes */
+    vnc_write_u16(vs, 0); /* pad */
+    write_tight_capability(vs, VNC_ENCODING_TIGHT, VNC_ENCODING_TIGHT_SIG,
+                           VNC_VENDOR_TIGHT);
+    write_tight_capability(vs, VNC_ENCODING_RAW, VNC_ENCODING_RAW_SIG,
+                           VNC_VENDOR_STANDARD);
+    write_tight_capability(vs, VNC_ENCODING_HEXTILE, VNC_ENCODING_HEXTILE_SIG,
+                           VNC_VENDOR_STANDARD);
+    write_tight_capability(vs, VNC_ENCODING_COMPRESSLEVEL0,
+                           VNC_ENCODING_COMPRESSLEVEL0_SIG, VNC_VENDOR_TIGHT);
+    write_tight_capability(vs, VNC_ENCODING_QUALITYLEVEL0,
+                           VNC_ENCODING_QUALITYLEVEL0_SIG, VNC_VENDOR_TIGHT);
+
+    vnc_flush(vs);
+}
+
+
 static int protocol_client_init(VncState *vs, uint8_t *data, size_t len)
 {
     char buf[1024];
@@ -1480,6 +1543,9 @@ static int protocol_client_init(VncState *vs, uint8_t *data, size_t len)
     vnc_write(vs, buf, size);
     vnc_flush(vs);
 
+    if(vnc_has_feature(vs, VNC_FEATURE_TIGHT_PROTOCOL))
+        write_tight_interaction_capabilities(vs);
+    
     vnc_read_when(vs, protocol_client_msg, 1);
 
     return 0;
@@ -1556,6 +1622,32 @@ static int start_auth_vnc(VncState *vs)
     return 0;
 }
 
+static int start_auth_tight(VncState *vs)
+{
+    vnc_write_u32(vs, 0); /* no tunnel types */
+    vnc_write_u32(vs, 1); /* num auth types */
+        
+    switch(vs->auth) {
+        case VNC_AUTH_NONE:
+            write_tight_capability(vs, VNC_AUTH_NONE, VNC_AUTH_NONE_SIG,
+                                   VNC_VENDOR_STANDARD);
+            break;
+        case VNC_AUTH_VNC:
+            write_tight_capability(vs, VNC_AUTH_VNC, VNC_AUTH_VNC_SIG,
+                                   VNC_VENDOR_STANDARD);
+            break;
+        default:
+            VNC_DEBUG("Unknown subset of tight auth: %d", vs->auth);
+            vnc_write_u32(vs, -1);
+            vnc_write(vs, "BAD_", 4);
+            vnc_write(vs, "UNKNOWN_", 8);
+    }
+    
+    vnc_flush(vs);
+    vnc_read_when(vs, protocol_client_auth, 4);
+    return 0;
+}
+
 static int vnc_start_auth(VncState *vs, int auth)
 {
     switch (auth) {
@@ -1570,12 +1662,22 @@ static int vnc_start_auth(VncState *vs, int auth)
     case VNC_AUTH_VNC:
         VNC_DEBUG("Start VNC auth\n");
         return start_auth_vnc(vs);
+    case VNC_AUTH_TIGHT:
+        /* If we know we're on tight here, we ran into recursion */
+        if (vnc_has_feature(vs, VNC_FEATURE_TIGHT_PROTOCOL)) {
+            VNC_DEBUG("Danger! Server sent us tight auth request twice!\n");
+            goto tight_recursion;
+        }
+        vs->features |= VNC_FEATURE_TIGHT_PROTOCOL_MASK;
+        VNC_DEBUG("Start VNC tight auth\n");
+        return start_auth_tight(vs);
 #ifdef CONFIG_VNC_TLS
     case VNC_AUTH_VENCRYPT:
         VNC_DEBUG("Accept VeNCrypt auth\n");;
         return start_auth_vencrypt(vs);
 #endif /* CONFIG_VNC_TLS */
     default: /* Should not be possible, but just in case */
+    tight_recursion:
         VNC_DEBUG("Reject auth %d unknown\n", auth);
         vnc_write_u8(vs, 1);
         if (vs->minor >= 8) {
@@ -2001,10 +2103,15 @@ static int start_auth_vencrypt(VncState *vs)
 
 static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len)
 {
+    int auth = data[0];
+
+    if (len == 4)
+        auth = read_s32(data, 0);
     /* We only advertise 1 auth scheme at a time, so client
      * must pick the one we sent. Verify this */
-    if (data[0] != vs->auth) { /* Reject auth */
-       VNC_DEBUG("Reject auth %d\n", (int)data[0]);
+    if ((auth != vs->auth) &&
+        (auth != VNC_AUTH_TIGHT)) { /* Reject auth */
+       VNC_DEBUG("Reject auth %d != %d\n", auth, vs->auth);
        vnc_write_u32(vs, 1);
        if (vs->minor >= 8) {
            static const char err[] = "Authentication failed";
@@ -2014,7 +2121,7 @@ static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len)
        vnc_client_error(vs);
     } else { /* Accept requested auth */
        VNC_DEBUG("Client requested auth %d\n", auth);
-       return vnc_start_auth(vs, data[0]);
+       return vnc_start_auth(vs, auth);
     }
     return 0;
 }
@@ -2068,9 +2175,10 @@ static int protocol_version(VncState *vs, uint8_t *version, size_t len)
             vnc_client_error(vs);
        }
     } else {
-	VNC_DEBUG("Telling client we support auth %d\n", vs->auth);
-	vnc_write_u8(vs, 1); /* num auth */
+	VNC_DEBUG("Telling client we support auth %d and tight\n", vs->auth);
+	vnc_write_u8(vs, 2); /* num auth */
 	vnc_write_u8(vs, vs->auth);
+	vnc_write_u8(vs, VNC_AUTH_TIGHT);
 	vnc_read_when(vs, protocol_client_auth, 1);
 	vnc_flush(vs);
     }
Signature · 1 line
1.6.0.2
#7 lore raw

PATCH 7/7 Add tight encoding (jpeg) to vnc.c

Because we can now speak the tight protocol, let's use it to transmit jpeg data to the client!

This patch adds a really easy implementation of the jpeg tight encoding. Tight in general can do a lot more, but let's take small steps here and see how things perform.

---
 Makefile.target |    4 +
 configure       |   25 ++++++++
 vnc.c           |  178 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 207 insertions(+), 0 deletions(-)
Makefile.target +4 -0
index a091ce9..7b54748 100644
@@ -554,6 +554,10 @@ CPPFLAGS += $(CONFIG_VNC_TLS_CFLAGS)
 LIBS += $(CONFIG_VNC_TLS_LIBS)
 endif
 
+ifdef CONFIG_VNC_JPEG
+LIBS += $(CONFIG_VNC_JPEG_LIBS)
+endif
+
 ifdef CONFIG_BLUEZ
 LIBS += $(CONFIG_BLUEZ_LIBS)
 endif
configure +25 -0
index c3fbbbe..44e2e0b 100755
@@ -164,6 +164,7 @@ fmod_lib=""
 fmod_inc=""
 oss_lib=""
 vnc_tls="yes"
+vnc_jpeg="yes"
 bsd="no"
 linux="no"
 solaris="no"
@@ -387,6 +388,8 @@ for opt do
   ;;
   --disable-vnc-tls) vnc_tls="no"
   ;;
+  --disable-jpeg) vnc_jpeg="no"
+  ;;
   --disable-slirp) slirp="no"
   ;;
   --disable-vde) vde="no"
@@ -544,6 +547,7 @@ echo "                           Available cards: $audio_possible_cards"
 echo "  --enable-mixemu          enable mixer emulation"
 echo "  --disable-brlapi         disable BrlAPI"
 echo "  --disable-vnc-tls        disable TLS encryption for VNC server"
+echo "  --disable-jpeg           disable JPEG compression for VNC server"
 echo "  --disable-curses         disable curses output"
 echo "  --disable-bluez          disable bluez stack connectivity"
 echo "  --disable-kvm            disable KVM acceleration support"
@@ -823,6 +827,21 @@ EOF
 fi
 
 ##########################################
+# VNC JPEG detection
+if test "$vnc_jpeg" = "yes" ; then
+cat > $TMPC <<EOF
+#include <jpeglib.h>
+int main(void) { jpeg_compress_struct s; jpeg_create_compress(&s); return 0; }
+EOF
+    vnc_jpeg_libs="-ljpeg"
+    if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} $TMPC $vnc_jpeg_libs > /dev/null 2> /dev/null ; then
+	:
+    else
+	vnc_tls="no"
+    fi
+fi
+
+##########################################
 # vde libraries probe
 if test "$vde" = "yes" ; then
   cat > $TMPC << EOF
@@ -1130,6 +1149,7 @@ if test "$vnc_tls" = "yes" ; then
     echo "    TLS CFLAGS    $vnc_tls_cflags"
     echo "    TLS LIBS      $vnc_tls_libs"
 fi
+echo "VNC JPEG support  $vnc_jpeg"
 if test -n "$sparc_cpu"; then
     echo "Target Sparc Arch $sparc_cpu"
 fi
@@ -1371,6 +1391,11 @@ if test "$vnc_tls" = "yes" ; then
   echo "CONFIG_VNC_TLS_LIBS=$vnc_tls_libs" >> $config_mak
   echo "#define CONFIG_VNC_TLS 1" >> $config_h
 fi
+if test "$vnc_jpeg" = "yes" ; then
+  echo "CONFIG_VNC_JPEG=yes" >> $config_mak
+  echo "CONFIG_VNC_JPEG_LIBS=$vnc_jpeg_libs" >> $config_mak
+  echo "#define CONFIG_VNC_JPEG 1" >> $config_h
+fi
 qemu_version=`head $source_path/VERSION`
 echo "VERSION=$qemu_version" >>$config_mak
 echo "#define QEMU_VERSION \"$qemu_version\"" >> $config_h
vnc.c +178 -0

212 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#3 lore raw

PATCH 3/7 Fix invalid #if in vnc.c when debugging is enabled

In reply to Alexander Graf

While running with debugging enabled, I found an #if testing for an undefined value, not defined(value). This patch fixes that.

---
 vnc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
vnc.c +1 -1
index 6b885d3..4b17f85 100644
@@ -47,7 +47,7 @@
 #ifdef _VNC_DEBUG
 #define VNC_DEBUG(fmt, ...) do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
 
-#if CONFIG_VNC_TLS && _VNC_DEBUG >= 2
+#if defined(CONFIG_VNC_TLS) && _VNC_DEBUG >= 2
 /* Very verbose, so only enabled for _VNC_DEBUG >= 2 */
 static void vnc_debug_gnutls_log(int level, const char* str) {
     VNC_DEBUG("%d %s", level, str);
Signature · 1 line
1.6.0.2
#0 lore raw

cover Add tight support to VNC

The current tight implementation only supports raw and hextile encodings. While this is perfectly fine for local networks, it would be good to support tight encodings for remote access as well.

This patchset implements fundamental tight protocol and tight encoding support, implementing jpeg compression.

Using this set as a basis, other tight encodings can be easily added as well, like ZRLE or ZLIBHEX. I will work on that, but this is intrusive enough for one set already ;-).

Alexander Graf (7):
Split VNC defines to vnc.h
Use VNC protocol defines
Fix invalid #if in vnc.c when debugging is enabled Make vnc buffer big-chunk aware
Split vnc authentication code
Add tight protocol awareness to vnc.c
Add tight encoding (jpeg) to vnc.c

 Makefile.target |    4 +
 configure       |   25 +++
 vnc.c           |  500 ++++++++++++++++++++++++++++++++++++++++++-------------
 vnc.h           |  130 ++++++++++++++
 4 files changed, 539 insertions(+), 120 deletions(-)
 create mode 100644 vnc.h
#4 lore raw

PATCH 4/7 Make vnc buffer big-chunk aware

In reply to Alexander Graf

Currently writing to buffers is protected by buffer_reserve. Unfortunately, is reserves at most 1024 bytes more than we currently have, so if we want to write a 2048 bytes chunk, we overwrite random memory.

This patch addresses this in a pretty dumb but easy way.

---
 vnc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
vnc.c +1 -1
index 4b17f85..d0d9580 100644
@@ -592,7 +592,7 @@ static int vnc_listen_poll(void *opaque)
 
 static void buffer_reserve(Buffer *buffer, size_t len)
 {
-    if ((buffer->capacity - buffer->offset) < len) {
+    while ((buffer->capacity - buffer->offset) < len) {
 	buffer->capacity += (len + 1024);
 	buffer->buffer = qemu_realloc(buffer->buffer, buffer->capacity);
 	if (buffer->buffer == NULL) {
Signature · 1 line
1.6.0.2
#5 lore raw

PATCH 5/7 Split vnc authentication code

This patch splits the authentication code, mostly for readability reasons.

---
 vnc.c |   67 ++++++++++++++++++++++++++++++++++------------------------------
 1 files changed, 36 insertions(+), 31 deletions(-)
vnc.c +36 -31
index d0d9580..b4b0843 100644
@@ -180,6 +180,7 @@ static void vnc_write_u8(VncState *vs, uint8_t value);
 static void vnc_flush(VncState *vs);
 static void vnc_update_client(void *opaque);
 static void vnc_client_read(void *opaque);
+static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len);
 
 static void vnc_colordepth(DisplayState *ds);
 
@@ -1555,6 +1556,39 @@ static int start_auth_vnc(VncState *vs)
     return 0;
 }
 
+static int vnc_start_auth(VncState *vs, int auth)
+{
+    switch (auth) {
+    case VNC_AUTH_NONE:
+        VNC_DEBUG("Accept auth none\n");
+        if (vs->minor >= 8) {
+            vnc_write_u32(vs, 0); /* Accept auth completion */
+            vnc_flush(vs);
+        }
+        vnc_read_when(vs, protocol_client_init, 1);
+        break;
+    case VNC_AUTH_VNC:
+        VNC_DEBUG("Start VNC auth\n");
+        return start_auth_vnc(vs);
+#ifdef CONFIG_VNC_TLS
+    case VNC_AUTH_VENCRYPT:
+        VNC_DEBUG("Accept VeNCrypt auth\n");;
+        return start_auth_vencrypt(vs);
+#endif /* CONFIG_VNC_TLS */
+    default: /* Should not be possible, but just in case */
+        VNC_DEBUG("Reject auth %d unknown\n", auth);
+        vnc_write_u8(vs, 1);
+        if (vs->minor >= 8) {
+            static const char err[] = "Authentication failed";
+            vnc_write_u32(vs, sizeof(err));
+            vnc_write(vs, err, sizeof(err));
+        }
+        vnc_client_error(vs);
+    }
+
+    return 0;
+}
+
 
 #ifdef CONFIG_VNC_TLS
 #define DH_BITS 1024
@@ -1979,37 +2013,8 @@ static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len)
        }
        vnc_client_error(vs);
     } else { /* Accept requested auth */
-       VNC_DEBUG("Client requested auth %d\n", (int)data[0]);
-       switch (vs->auth) {
-       case VNC_AUTH_NONE:
-           VNC_DEBUG("Accept auth none\n");
-           if (vs->minor >= 8) {
-               vnc_write_u32(vs, 0); /* Accept auth completion */
-               vnc_flush(vs);
-           }
-           vnc_read_when(vs, protocol_client_init, 1);
-           break;
-
-       case VNC_AUTH_VNC:
-           VNC_DEBUG("Start VNC auth\n");
-           return start_auth_vnc(vs);
-
-#ifdef CONFIG_VNC_TLS
-       case VNC_AUTH_VENCRYPT:
-           VNC_DEBUG("Accept VeNCrypt auth\n");;
-           return start_auth_vencrypt(vs);
-#endif /* CONFIG_VNC_TLS */
-
-       default: /* Should not be possible, but just in case */
-           VNC_DEBUG("Reject auth %d\n", vs->auth);
-           vnc_write_u8(vs, 1);
-           if (vs->minor >= 8) {
-               static const char err[] = "Authentication failed";
-               vnc_write_u32(vs, sizeof(err));
-               vnc_write(vs, err, sizeof(err));
-           }
-           vnc_client_error(vs);
-       }
+       VNC_DEBUG("Client requested auth %d\n", auth);
+       return vnc_start_auth(vs, data[0]);
     }
     return 0;
 }
Signature · 1 line
1.6.0.2
#2 lore raw

PATCH 2/7 Use VNC protocol defines

In reply to Alexander Graf

Now that we have nice defines for all sorts of constants, let's use them!

This patch also takes the "feature variables", currently called has_* into a single feature int. This way adding new features is a lot easier and doesn't clutter the VncState struct.

---
 vnc.c |   97 +++++++++++++++++++++++++++++++++-------------------------------
 1 files changed, 50 insertions(+), 47 deletions(-)
vnc.c +50 -47
index e88f38f..6b885d3 100644
@@ -98,10 +98,7 @@ struct VncState
     int need_update;
     uint32_t dirty_row[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS];
     char *old_data;
-    int has_resize;
-    int has_hextile;
-    int has_pointer_type_change;
-    int has_WMVi;
+    uint32_t features;
     int absolute;
     int last_x;
     int last_y;
@@ -164,6 +161,10 @@ void do_info_vnc(void)
     }
 }
 
+static inline uint32_t vnc_has_feature(VncState *vs, int feature) {
+    return (vs->features & (1 << feature));
+}
+
 /* TODO
    1) Get the queue working for IO.
    2) there is some weirdness when using the -S option (the screen is grey
@@ -277,11 +278,12 @@ static void vnc_dpy_resize(DisplayState *ds)
                    ds_get_height(ds) != vs->serverds.height;
     vs->serverds = *(ds->surface);
     if (size_changed) {
-        if (vs->csock != -1 && vs->has_resize) {
+        if (vs->csock != -1 && vnc_has_feature(vs, VNC_FEATURE_RESIZE)) {
             vnc_write_u8(vs, 0);  /* msg id */
             vnc_write_u8(vs, 0);
             vnc_write_u16(vs, 1); /* number of rects */
-            vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds), -223);
+            vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds),
+                                   VNC_ENCODING_DESKTOPRESIZE);
             vnc_flush(vs);
         }
     }
@@ -378,7 +380,7 @@ static void send_framebuffer_update_raw(VncState *vs, int x, int y, int w, int h
     int i;
     uint8_t *row;
 
-    vnc_framebuffer_update(vs, x, y, w, h, 0);
+    vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_RAW);
 
     row = ds_get_data(vs->ds) + y * ds_get_linesize(vs->ds) + x * ds_get_bytes_per_pixel(vs->ds);
     for (i = 0; i < h; i++) {
@@ -429,7 +431,7 @@ static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, i
     int has_fg, has_bg;
     uint8_t *last_fg, *last_bg;
 
-    vnc_framebuffer_update(vs, x, y, w, h, 5);
+    vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_HEXTILE);
 
     last_fg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel);
     last_bg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel);
@@ -448,7 +450,7 @@ static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, i
 
 static void send_framebuffer_update(VncState *vs, int x, int y, int w, int h)
 {
-	if (vs->has_hextile)
+	if (vnc_has_feature(vs, VNC_FEATURE_HEXTILE))
 	    send_framebuffer_update_hextile(vs, x, y, w, h);
 	else
 	    send_framebuffer_update_raw(vs, x, y, w, h);
@@ -463,7 +465,7 @@ static void vnc_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int dst_
     vnc_write_u8(vs, 0);  /* msg id */
     vnc_write_u8(vs, 0);
     vnc_write_u16(vs, 1); /* number of rects */
-    vnc_framebuffer_update(vs, dst_x, dst_y, w, h, 1);
+    vnc_framebuffer_update(vs, dst_x, dst_y, w, h, VNC_ENCODING_COPYRECT);
     vnc_write_u16(vs, src_x);
     vnc_write_u16(vs, src_y);
     vnc_flush(vs);
@@ -919,12 +921,13 @@ static void client_cut_text(VncState *vs, size_t len, uint8_t *text)
 
 static void check_pointer_type_change(VncState *vs, int absolute)
 {
-    if (vs->has_pointer_type_change && vs->absolute != absolute) {
+    if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE) && vs->absolute != absolute) {
 	vnc_write_u8(vs, 0);
 	vnc_write_u8(vs, 0);
 	vnc_write_u16(vs, 1);
 	vnc_framebuffer_update(vs, absolute, 0,
-			       ds_get_width(vs->ds), ds_get_height(vs->ds), -257);
+			       ds_get_width(vs->ds), ds_get_height(vs->ds),
+                               VNC_ENCODING_POINTER_TYPE_CHANGE);
 	vnc_flush(vs);
     }
     vs->absolute = absolute;
@@ -950,7 +953,7 @@ static void pointer_event(VncState *vs, int button_mask, int x, int y)
 	kbd_mouse_event(x * 0x7FFF / (ds_get_width(vs->ds) - 1),
 			y * 0x7FFF / (ds_get_height(vs->ds) - 1),
 			dz, buttons);
-    } else if (vs->has_pointer_type_change) {
+    } else if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE)) {
 	x -= 0x7FFF;
 	y -= 0x7FFF;
 
@@ -1140,7 +1143,8 @@ static void send_ext_key_event_ack(VncState *vs)
     vnc_write_u8(vs, 0);
     vnc_write_u8(vs, 0);
     vnc_write_u16(vs, 1);
-    vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds), -258);
+    vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds),
+                           VNC_ENCODING_EXT_KEY_EVENT);
     vnc_flush(vs);
 }
 
@@ -1149,50 +1153,50 @@ static void send_ext_audio_ack(VncState *vs)
     vnc_write_u8(vs, 0);
     vnc_write_u8(vs, 0);
     vnc_write_u16(vs, 1);
-    vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds), -259);
+    vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds),
+                           VNC_ENCODING_AUDIO);
     vnc_flush(vs);
 }
 
 static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
 {
     int i;
+    unsigned int enc = 0;
 
-    vs->has_hextile = 0;
-    vs->has_resize = 0;
-    vs->has_pointer_type_change = 0;
-    vs->has_WMVi = 0;
+    vs->features = 0;
     vs->absolute = -1;
     dcl->dpy_copy = NULL;
 
     for (i = n_encodings - 1; i >= 0; i--) {
-	switch (encodings[i]) {
-	case 0: /* Raw */
-	    vs->has_hextile = 0;
-	    break;
-	case 1: /* CopyRect */
-	    dcl->dpy_copy = vnc_copy;
-	    break;
-	case 5: /* Hextile */
-	    vs->has_hextile = 1;
-	    break;
-	case -223: /* DesktopResize */
-	    vs->has_resize = 1;
-	    break;
-	case -257:
-	    vs->has_pointer_type_change = 1;
-	    break;
-        case -258:
+        enc = encodings[i];
+        switch (enc) {
+        case VNC_ENCODING_RAW:
+            break;
+        case VNC_ENCODING_COPYRECT:
+            dcl->dpy_copy = vnc_copy;
+            break;
+        case VNC_ENCODING_HEXTILE:
+            vs->features |= VNC_FEATURE_HEXTILE_MASK;
+            break;
+        case VNC_ENCODING_DESKTOPRESIZE:
+            vs->features |= VNC_FEATURE_RESIZE_MASK;
+            break;
+        case VNC_ENCODING_POINTER_TYPE_CHANGE:
+            vs->features |= VNC_FEATURE_POINTER_TYPE_CHANGE_MASK;
+            break;
+        case VNC_ENCODING_EXT_KEY_EVENT:
             send_ext_key_event_ack(vs);
             break;
-        case -259:
+        case VNC_ENCODING_AUDIO:
             send_ext_audio_ack(vs);
             break;
-        case 0x574D5669:
-            vs->has_WMVi = 1;
+        case VNC_ENCODING_WMVi:
+            vs->features |= VNC_FEATURE_WMVI_MASK;
             break;
-	default:
-	    break;
-	}
+        default:
+             printf("Unknown encoding: %d (0x%.8x): %d\n", i, enc, enc);
+            break;
+        }
     }
 
     check_pointer_type_change(vs, kbd_mouse_is_absolute());
@@ -1306,12 +1310,13 @@ static void vnc_colordepth(DisplayState *ds)
 {
     struct VncState *vs = ds->opaque;
 
-    if (vs->csock != -1 && vs->has_WMVi) {
+    if (vs->csock != -1 && vnc_has_feature(vs, VNC_FEATURE_WMVI)) {
         /* Sending a WMVi message to notify the client*/
         vnc_write_u8(vs, 0);  /* msg id */
         vnc_write_u8(vs, 0);
         vnc_write_u16(vs, 1); /* number of rects */
-        vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds), 0x574D5669);
+        vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds),
+                               VNC_ENCODING_WMVi);
         pixel_format_message(vs);
         vnc_flush(vs);
     } else {
@@ -2079,9 +2084,7 @@ static void vnc_connect(VncState *vs)
     vnc_read_when(vs, protocol_version, 12);
     memset(vs->old_data, 0, ds_get_linesize(vs->ds) * ds_get_height(vs->ds));
     memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row));
-    vs->has_resize = 0;
-    vs->has_hextile = 0;
-    vs->has_WMVi = 0;
+    vs->features = 0;
     dcl->dpy_copy = NULL;
     vnc_update_client(vs);
     reset_keys(vs);
Signature · 1 line
1.6.0.2
#14 lore raw

[Qemu-devel] Re: [PATCH 4/7] Make vnc buffer big-chunk aware

In reply to Alexander Graf
Quoted 5 lines · Alexander Graf

Currently writing to buffers is protected by buffer_reserve. Unfortunately, is reserves at most 1024 bytes more than we currently have, so if we want to write a 2048 bytes chunk, we overwrite random memory.

Yikes!

Quoted 12 lines

This patch addresses this in a pretty dumb but easy way.

---
 vnc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
vnc.c +0 -0
index 4b17f85..d0d9580 100644

vnc.c static int vnc_listen_poll(void *opaque) · line 597

Quoted 7 lines
vnc.c +1 -1
@@ -592,7 +592,7 @@ static int vnc_listen_poll(void *opaque)
 
 static void buffer_reserve(Buffer *buffer, size_t len)
 {
-    if ((buffer->capacity - buffer->offset) < len) {
+    while ((buffer->capacity - buffer->offset) < len) {
 	buffer->capacity += (len + 1024);
 

Okay, I no longer believe you.

If we want to write len bytes, and we increase capacity by (len + 1024) bytes, then we should be fine. The reason it's len + 1024 vs just len is to avoid many qemu_realloc()s on many small reservations (like for adding u32s).

Regards,

Anthony Liguori

Quoted 3 lines
vnc.c +0 -0
 	buffer->buffer = qemu_realloc(buffer->buffer, buffer->capacity);

if (buffer->buffer == NULL) {

#11 lore raw

[Qemu-devel] Re: [PATCH 6/7] Add tight protocol awareness to vnc.c

In reply to Alexander Graf
Quoted 7 lines · Alexander Graf

This patch enables the vnc server to understand the tight protocol.

Basically, negotiation if tight is existing happens through the authentication code. If a special authentication called VNC_AUTH_TIGHT is used, the real authentication is stacked afterwards and tight extensions exist.

This is wrong. The way the standard works is that the client advertises the Tight encoding via SetEncodingTypes. That's all that should be needed. The VNC_AUTH_TIGHT thing is a Tight extension that shouldn't be needed for implementing tight encoding.

Regards,

Anthony Liguori

#15 lore raw

[Qemu-devel] Re: [PATCH 4/7] Make vnc buffer big-chunk aware

In reply to Anthony Liguori
Quoted 30 lines · Anthony Liguori
Quoted 5 lines · Alexander Graf

Currently writing to buffers is protected by buffer_reserve. Unfortunately, is reserves at most 1024 bytes more than we currently have, so if we want to write a 2048 bytes chunk, we overwrite random memory.

Yikes!

Quoted 12 lines

This patch addresses this in a pretty dumb but easy way.

---
vnc.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
vnc.c +0 -0
index 4b17f85..d0d9580 100644

vnc.c static int vnc_listen_poll(void *opaque) · line 596

Quoted 6 lines
vnc.c +1 -1
@@ -592,7 +592,7 @@ static int vnc_listen_poll(void *opaque)
 static void buffer_reserve(Buffer *buffer, size_t len)
 {
-    if ((buffer->capacity - buffer->offset) < len) {
+    while ((buffer->capacity - buffer->offset) < len) {
   buffer->capacity += (len + 1024);
 

Okay, I no longer believe you.

Quoted 1 line

If we want to write len bytes, and we increase capacity by (len + 1024) bytes, then we should be fine. The reason it's len + 1024 vs just len is to avoid many qemu_realloc()s on many small reservations (like for adding u32s).

Ugh. I must've been really tired there :o. You're right, the code does look good.

Alex

Quoted 9 lines

Regards,

Anthony Liguori

Quoted 3 lines
vnc.c +0 -0
   buffer->buffer = qemu_realloc(buffer->buffer, buffer->capacity);
   if (buffer->buffer == NULL) {
#8 lore raw

[Qemu-devel] Re: [PATCH 7/7] Add tight encoding (jpeg) to vnc.c

In reply to Alexander Graf
Quoted 9 lines · Alexander Graf

Because we can now speak the tight protocol, let's use it to transmit jpeg data to the client!

This patch adds a really easy implementation of the jpeg tight encoding. Tight in general can do a lot more, but let's take small steps here and see how things perform.

I don't really like the idea of taking this. Tight is supported by a lot of clients and is usually very high on the preferred list. However, most servers do not enable jpeg compression by default because it's lossy.

If we implement Tight and then use jpeg by default, for most clients, the default is going to be lossy encoding. While lossy isn't so bad for high detailed images (like pictures), it's pretty terrible for simple, high contrast images (like windows in a desktop).

TightVNC has some sophisticated heuristics for determining whether to use jpeg or not (when it's enabled). I think that sort of heuristic is a prerequisite for enabling tight's jpeg support.

FWIW, Tight essentially does hextile encoding but adds zlib compression. That's probably a better place to start as it should outperform hextile while remaining lossless.

Regards,

Anthony Liguori

#16 lore raw

[Qemu-devel] Re: [PATCH 1/7] Split VNC defines to vnc.h

In reply to Alexander Graf
Quoted 7 lines · Alexander Graf

The VNC protocol contains quite some constants, some of which are currently hardcoded in the vnc.c code. This is not exactly pretty.

Let's move all those constants out to vnc.h, so they are clearly separated. While at it, I also included other defines that will be used later in this patch series.

A much needed change.

Quoted 20 lines
vnc.h new file +13 -0
new file mode 100644
index 0000000..ae69bc3
@@ -0,0 +1,130 @@
+#ifndef __VNCTIGHT_H
+#define __VNCTIGHT_H
+
+/*****************************************************************************
+ *
+ * Authentication modes
+ *
+ *****************************************************************************/
+
+enum {
+    VNC_AUTH_INVALID = 0,
+    VNC_AUTH_NONE = 1,
+    VNC_AUTH_VNC = 2,

vnc.h line 23

Quoted 10 lines
vnc.h new file +10 -0
+    VNC_AUTH_RA2 = 5,
+    VNC_AUTH_RA2NE = 6,
+    VNC_AUTH_TIGHT = 16,
+    VNC_AUTH_ULTRA = 17,
+    VNC_AUTH_TLS = 18,
+    VNC_AUTH_VENCRYPT = 19
+};
+
+#define VNC_AUTH_NONE_SIG "NOAUTH__"
+#define VNC_AUTH_VNC_SIG  "VNCAUTH_"

These AUTH sigs are not part of the standard as far as I'm aware of it. This is the VNC_AUTH_TIGHT stuff? I'd rather not do that.

vnc.h line 61

Quoted 10 lines
vnc.h new file +9 -0
+
+#define VNC_ENCODING_RAW                  0x00000000
+#define VNC_ENCODING_COPYRECT             0x00000001
+#define VNC_ENCODING_RRE                  0x00000002
+#define VNC_ENCODING_CORRE                0x00000004
+#define VNC_ENCODING_HEXTILE              0x00000005
+#define VNC_ENCODING_ZLIB                 0x00000006
+#define VNC_ENCODING_TIGHT                0x00000007
+#define VNC_ENCODING_ZLIBHEX              0x00000008

This was never standardized.

vnc.h line 67

Quoted 7 lines
vnc.h new file +6 -0
+#define VNC_ENCODING_ZRLE                 0x00000010
+#define VNC_ENCODING_COMPRESSLEVEL0       0xFFFFFF00
+#define VNC_ENCODING_QUALITYLEVEL0        0xFFFFFFE0
+#define VNC_ENCODING_XCURSOR              0xFFFFFF10
+#define VNC_ENCODING_RICH_CURSOR          0xFFFFFF11
+#define VNC_ENCODING_POINTER_POS          0xFFFFFF18

Nor was this.

vnc.h line 68

Quoted 2 lines
vnc.h new file +1 -0
+#define VNC_ENCODING_LASTRECT             0xFFFFFF20

Nor this.

Quoted 9 lines
vnc.h new file +8 -0
+#define VNC_ENCODING_DESKTOPRESIZE        0xFFFFFF21
+#define VNC_ENCODING_POINTER_TYPE_CHANGE  0XFFFFFEFF
+#define VNC_ENCODING_EXT_KEY_EVENT        0XFFFFFEFE
+#define VNC_ENCODING_AUDIO                0XFFFFFEFD
+#define VNC_ENCODING_WMVi                 0x574D5669
+
+/* signatures for basic encoding types */
+#define VNC_ENCODING_RAW_SIG              "RAW_____"

vnc.h line 86

Quoted 10 lines
vnc.h new file +10 -0
+#define VNC_ENCODING_COPYRECT_SIG         "COPYRECT"
+#define VNC_ENCODING_RRE_SIG              "RRE_____"
+#define VNC_ENCODING_CORRE_SIG            "CORRE___"
+#define VNC_ENCODING_HEXTILE_SIG          "HEXTILE_"
+#define VNC_ENCODING_ZLIB_SIG             "ZLIB____"
+#define VNC_ENCODING_TIGHT_SIG            "TIGHT___"
+#define VNC_ENCODING_ZLIBHEX_SIG          "ZLIBHEX_"
+#define VNC_ENCODING_ZRLE_SIG             "ZRLE____"
+#define VNC_ENCODING_COMPRESSLEVEL0_SIG   "COMPRLVL"
+#define VNC_ENCODING_QUALITYLEVEL0_SIG    "JPEGQLVL"

These are not part of the standard either. I'm not sure what they do.

Quoted 4 lines
vnc.h new file +3 -0
+/*****************************************************************************
+ *
+ * Other tight constants

vnc.h line 100

Quoted 10 lines
vnc.h new file +10 -0
+ *
+ *****************************************************************************/
+
+/*
+ * Vendors known by TightVNC: standard VNC/RealVNC, TridiaVNC, and TightVNC.
+ */
+
+#define VNC_VENDOR_STANDARD        "STDV"
+#define VNC_VENDOR_TRIDIA          "TRDV"
+#define VNC_VENDOR_TIGHT           "TGHT"

This also is not part of the standard.

Regards,

Anthony Liguori

Quoted 30 lines
vnc.h new file +29 -0
+#define VNC_TIGHT_CCB_RESET_MASK   (0x0f)
+#define VNC_TIGHT_CCB_TYPE_MASK    (0x0f << 4)
+#define VNC_TIGHT_CCB_TYPE_FILL    (0x08 << 4)
+#define VNC_TIGHT_CCB_TYPE_JPEG    (0x09 << 4)
+#define VNC_TIGHT_CCB_BASIC_MAX    (0x07 << 4)
+#define VNC_TIGHT_CCB_BASIC_ZLIB   (0x03 << 4)
+#define VNC_TIGHT_CCB_BASIC_FILTER (0x04 << 4)
+
+/*****************************************************************************
+ *
+ * Features
+ *
+ *****************************************************************************/
+
+#define VNC_FEATURE_RESIZE                   0
+#define VNC_FEATURE_HEXTILE                  1
+#define VNC_FEATURE_POINTER_TYPE_CHANGE      2
+#define VNC_FEATURE_WMVI                     3
+#define VNC_FEATURE_TIGHT                    4
+#define VNC_FEATURE_TIGHT_PROTOCOL           5
+
+#define VNC_FEATURE_RESIZE_MASK              (1 << VNC_FEATURE_RESIZE)
+#define VNC_FEATURE_HEXTILE_MASK             (1 << VNC_FEATURE_HEXTILE)
+#define VNC_FEATURE_POINTER_TYPE_CHANGE_MASK (1 << VNC_FEATURE_POINTER_TYPE_CHANGE)
+#define VNC_FEATURE_WMVI_MASK                (1 << VNC_FEATURE_WMVI)
+#define VNC_FEATURE_TIGHT_MASK               (1 << VNC_FEATURE_TIGHT)
+#define VNC_FEATURE_TIGHT_PROTOCOL_MASK      (1 << VNC_FEATURE_TIGHT_PROTOCOL)
+
+#endif /* __VNCTIGHT_H */
#12 lore raw

[Qemu-devel] Re: [PATCH 6/7] Add tight protocol awareness to vnc.c

In reply to Anthony Liguori
Quoted 9 lines · Anthony Liguori
Quoted 7 lines · Alexander Graf

This patch enables the vnc server to understand the tight protocol.

Basically, negotiation if tight is existing happens through the authentication code. If a special authentication called VNC_AUTH_TIGHT is used, the real authentication is stacked afterwards and tight extensions exist.

Quoted 4 lines

This is wrong. The way the standard works is that the client advertises the Tight encoding via SetEncodingTypes. That's all that should be needed. The VNC_AUTH_TIGHT thing is a Tight extension that shouldn't be needed for implementing tight encoding.

So how am I supposed to do the write_tight_interaction_capabilities() thing? I don't see how we advertise to the guest that we do support tight encoding if we can't tell it that we do.

Alex

Quoted 4 lines

Regards,

Anthony Liguori

#17 lore raw

[Qemu-devel] Re: [PATCH 1/7] Split VNC defines to vnc.h

In reply to Anthony Liguori
Quoted 39 lines · Anthony Liguori
Quoted 7 lines · Alexander Graf

The VNC protocol contains quite some constants, some of which are currently hardcoded in the vnc.c code. This is not exactly pretty.

Let's move all those constants out to vnc.h, so they are clearly separated. While at it, I also included other defines that will be used later in this patch series.

A much needed change.

Quoted 28 lines
vnc.h new file +8 -0
new file mode 100644
index 0000000..ae69bc3
@@ -0,0 +1,130 @@
+#ifndef __VNCTIGHT_H
+#define __VNCTIGHT_H
+
+/*****************************************************************************
 
+ *
+ * Authentication modes
+ *
+

*****************************************************************************/

vnc.h new file +11 -0
+
+enum {
+    VNC_AUTH_INVALID = 0,
+    VNC_AUTH_NONE = 1,
+    VNC_AUTH_VNC = 2,
+    VNC_AUTH_RA2 = 5,
+    VNC_AUTH_RA2NE = 6,
+    VNC_AUTH_TIGHT = 16,
+    VNC_AUTH_ULTRA = 17,
+    VNC_AUTH_TLS = 18,
+    VNC_AUTH_VENCRYPT = 19
Quoted 8 lines

vnc.h line 23

Quoted 5 lines
vnc.h new file +4 -0
+};
+
+#define VNC_AUTH_NONE_SIG "NOAUTH__"
+#define VNC_AUTH_VNC_SIG  "VNCAUTH_"

These AUTH sigs are not part of the standard as far as I'm aware of it. This is the VNC_AUTH_TIGHT stuff? I'd rather not do that.

Right. That is the follow-up from AUTH_TIGHT. Tight uses signatures in general as addition to normal codes. The same thing applies to the encoding signatures. These are required for the "Hey client, I know these encodings" packet.

Quoted 14 lines

vnc.h line 61

Quoted 11 lines
vnc.h new file +9 -0
+
+#define VNC_ENCODING_RAW                  0x00000000
+#define VNC_ENCODING_COPYRECT             0x00000001
+#define VNC_ENCODING_RRE                  0x00000002
+#define VNC_ENCODING_CORRE                0x00000004
+#define VNC_ENCODING_HEXTILE              0x00000005
+#define VNC_ENCODING_ZLIB                 0x00000006
+#define VNC_ENCODING_TIGHT                0x00000007
+#define VNC_ENCODING_ZLIBHEX              0x00000008

This was never standardized.

Quoted 1 line

From rfbproto.h of current tightvnc:

#define rfbEncodingRaw       0
#define rfbEncodingCopyRect  1
#define rfbEncodingRRE       2
#define rfbEncodingCoRRE     4
#define rfbEncodingHextile   5
#define rfbEncodingZlib      6
#define rfbEncodingTight     7
#define rfbEncodingZlibHex   8
#define rfbEncodingZRLE     16
[...]
#define rfbEncodingXCursor         0xFFFFFF10
#define rfbEncodingRichCursor      0xFFFFFF11
#define rfbEncodingPointerPos      0xFFFFFF18

#define rfbEncodingLastRect 0xFFFFFF20
#define rfbEncodingNewFBSize 0xFFFFFF21

Where else should I look for defines? I'd rather have them here and if anything collide than not in any header files.

Quoted 95 lines

vnc.h line 67

Quoted 8 lines
vnc.h new file +6 -0
+#define VNC_ENCODING_ZRLE                 0x00000010
+#define VNC_ENCODING_COMPRESSLEVEL0       0xFFFFFF00
+#define VNC_ENCODING_QUALITYLEVEL0        0xFFFFFFE0
+#define VNC_ENCODING_XCURSOR              0xFFFFFF10
+#define VNC_ENCODING_RICH_CURSOR          0xFFFFFF11
+#define VNC_ENCODING_POINTER_POS          0xFFFFFF18

Nor was this.

Quoted 2 lines

+#define VNC_ENCODING_LASTRECT 0xFFFFFF20

Nor this.

Quoted 9 lines
vnc.h new file +8 -0
+#define VNC_ENCODING_DESKTOPRESIZE        0xFFFFFF21
+#define VNC_ENCODING_POINTER_TYPE_CHANGE  0XFFFFFEFF
+#define VNC_ENCODING_EXT_KEY_EVENT        0XFFFFFEFE
+#define VNC_ENCODING_AUDIO                0XFFFFFEFD
+#define VNC_ENCODING_WMVi                 0x574D5669
+
+/* signatures for basic encoding types */
+#define VNC_ENCODING_RAW_SIG              "RAW_____"

vnc.h line 86

Quoted 10 lines
vnc.h new file +10 -0
+#define VNC_ENCODING_COPYRECT_SIG         "COPYRECT"
+#define VNC_ENCODING_RRE_SIG              "RRE_____"
+#define VNC_ENCODING_CORRE_SIG            "CORRE___"
+#define VNC_ENCODING_HEXTILE_SIG          "HEXTILE_"
+#define VNC_ENCODING_ZLIB_SIG             "ZLIB____"
+#define VNC_ENCODING_TIGHT_SIG            "TIGHT___"
+#define VNC_ENCODING_ZLIBHEX_SIG          "ZLIBHEX_"
+#define VNC_ENCODING_ZRLE_SIG             "ZRLE____"
+#define VNC_ENCODING_COMPRESSLEVEL0_SIG   "COMPRLVL"
+#define VNC_ENCODING_QUALITYLEVEL0_SIG    "JPEGQLVL"

These are not part of the standard either. I'm not sure what they do.

Quoted 14 lines
vnc.h new file +5 -0
+/*****************************************************************************
 
+ *
+ * Other tight constants
+ *
+

*****************************************************************************/

vnc.h new file +3 -0
+
+/*
+ * Vendors known by TightVNC: standard VNC/RealVNC, TridiaVNC, and

TightVNC.
+ */

vnc.h line 100

Quoted 4 lines
vnc.h new file +4 -0
+
+#define VNC_VENDOR_STANDARD        "STDV"
+#define VNC_VENDOR_TRIDIA          "TRDV"
+#define VNC_VENDOR_TIGHT           "TGHT"

This also is not part of the standard.

Regards,

Anthony Liguori

Quoted 35 lines
vnc.h new file +13 -0
+#define VNC_TIGHT_CCB_RESET_MASK   (0x0f)
+#define VNC_TIGHT_CCB_TYPE_MASK    (0x0f << 4)
+#define VNC_TIGHT_CCB_TYPE_FILL    (0x08 << 4)
+#define VNC_TIGHT_CCB_TYPE_JPEG    (0x09 << 4)
+#define VNC_TIGHT_CCB_BASIC_MAX    (0x07 << 4)
+#define VNC_TIGHT_CCB_BASIC_ZLIB   (0x03 << 4)
+#define VNC_TIGHT_CCB_BASIC_FILTER (0x04 << 4)
+
+/*****************************************************************************
 
+ *
+ * Features
+ *
+

*****************************************************************************/

vnc.h new file +11 -0
+
+#define VNC_FEATURE_RESIZE                   0
+#define VNC_FEATURE_HEXTILE                  1
+#define VNC_FEATURE_POINTER_TYPE_CHANGE      2
+#define VNC_FEATURE_WMVI                     3
+#define VNC_FEATURE_TIGHT                    4
+#define VNC_FEATURE_TIGHT_PROTOCOL           5
+
+#define VNC_FEATURE_RESIZE_MASK              (1 << VNC_FEATURE_RESIZE)
+#define VNC_FEATURE_HEXTILE_MASK             (1 << VNC_FEATURE_HEXTILE)
+#define VNC_FEATURE_POINTER_TYPE_CHANGE_MASK (1 <<

VNC_FEATURE_POINTER_TYPE_CHANGE)

vnc.h new file +3 -0
+#define VNC_FEATURE_WMVI_MASK                (1 << VNC_FEATURE_WMVI)
+#define VNC_FEATURE_TIGHT_MASK               (1 << VNC_FEATURE_TIGHT)
+#define VNC_FEATURE_TIGHT_PROTOCOL_MASK      (1 <<

VNC_FEATURE_TIGHT_PROTOCOL)

vnc.h new file +2 -0
+
+#endif /* __VNCTIGHT_H */
#9 lore raw

Re: [Qemu-devel] Re: [PATCH 7/7] Add tight encoding (jpeg) to vnc.c

In reply to Anthony Liguori
Quoted 5 lines · Anthony Liguori

If we implement Tight and then use jpeg by default, for most clients, the default is going to be lossy encoding. While lossy isn't so bad for high detailed images (like pictures), it's pretty terrible for simple, high contrast images (like windows in a desktop).

Quoted 8 lines

TightVNC has some sophisticated heuristics for determining whether to use jpeg or not (when it's enabled). I think that sort of heuristic is a prerequisite for enabling tight's jpeg support.

FWIW, Tight essentially does hextile encoding but adds zlib compression. That's probably a better place to start as it should outperform hextile while remaining lossless.

Another thing to consider is that using jpeg compression is going to worsen qemu performances, so I think it should be used only when necessary, e.g. the network connection between client and server is bad.

#13 lore raw

[Qemu-devel] Re: [PATCH 6/7] Add tight protocol awareness to vnc.c

In reply to Alexander Graf
Quoted 18 lines · Alexander Graf
Quoted 10 lines · Anthony Liguori
Quoted 8 lines · Alexander Graf

This patch enables the vnc server to understand the tight protocol.

Basically, negotiation if tight is existing happens through the authentication code. If a special authentication called VNC_AUTH_TIGHT is used, the real authentication is stacked afterwards and tight extensions exist.

Quoted 5 lines

This is wrong. The way the standard works is that the client advertises the Tight encoding via SetEncodingTypes. That's all that should be needed. The VNC_AUTH_TIGHT thing is a Tight extension that shouldn't be needed for implementing tight encoding.

Quoted 4 lines

So how am I supposed to do the write_tight_interaction_capabilities() thing? I don't see how we advertise to the guest that we do support tight encoding if we can't tell it that we do.

The server doesn't advertise encodings to the client. The client advertises supported encodings to the server and the server chooses to use whatever one it would like to (that is supports). A server is supposed to ignore encodings that it doesn't know about.

Regards,

Anthony Liguori

Quoted 8 lines

Alex

Quoted 4 lines

Regards,

Anthony Liguori

#18 lore raw

[Qemu-devel] Re: [PATCH 1/7] Split VNC defines to vnc.h

In reply to Alexander Graf
Quoted 89 lines · Alexander Graf
Quoted 41 lines · Anthony Liguori
Quoted 8 lines · Alexander Graf

The VNC protocol contains quite some constants, some of which are currently hardcoded in the vnc.c code. This is not exactly pretty.

Let's move all those constants out to vnc.h, so they are clearly separated. While at it, I also included other defines that will be used later in this patch series.

A much needed change.

Quoted 28 lines
vnc.h new file +8 -0
new file mode 100644
index 0000000..ae69bc3
@@ -0,0 +1,130 @@
+#ifndef __VNCTIGHT_H
+#define __VNCTIGHT_H
+
+/*****************************************************************************
 
+ *
+ * Authentication modes
+ *
+

*****************************************************************************/

vnc.h new file +11 -0
+
+enum {
+    VNC_AUTH_INVALID = 0,
+    VNC_AUTH_NONE = 1,
+    VNC_AUTH_VNC = 2,
+    VNC_AUTH_RA2 = 5,
+    VNC_AUTH_RA2NE = 6,
+    VNC_AUTH_TIGHT = 16,
+    VNC_AUTH_ULTRA = 17,
+    VNC_AUTH_TLS = 18,
+    VNC_AUTH_VENCRYPT = 19
Quoted 9 lines

vnc.h line 23

Quoted 6 lines
vnc.h new file +4 -0
+};
+
+#define VNC_AUTH_NONE_SIG "NOAUTH__"
+#define VNC_AUTH_VNC_SIG  "VNCAUTH_"

These AUTH sigs are not part of the standard as far as I'm aware of it. This is the VNC_AUTH_TIGHT stuff? I'd rather not do that.

Right. That is the follow-up from AUTH_TIGHT. Tight uses signatures in general as addition to normal codes. The same thing applies to the encoding signatures. These are required for the "Hey client, I know these encodings" packet.

Quoted 4 lines
Quoted 4 lines
vnc.h new file +4 -0
+
+#define VNC_ENCODING_RAW                  0x00000000
+#define VNC_ENCODING_COPYRECT             0x00000001
+#define VNC_ENCODING_RRE                  0x00000002
Quoted 9 lines

vnc.h line 61

Quoted 7 lines
vnc.h new file +5 -0
+#define VNC_ENCODING_CORRE                0x00000004
+#define VNC_ENCODING_HEXTILE              0x00000005
+#define VNC_ENCODING_ZLIB                 0x00000006
+#define VNC_ENCODING_TIGHT                0x00000007
+#define VNC_ENCODING_ZLIBHEX              0x00000008

This was never standardized.

From rfbproto.h of current tightvnc:

#define rfbEncodingRaw       0
#define rfbEncodingCopyRect  1
#define rfbEncodingRRE       2
#define rfbEncodingCoRRE     4
#define rfbEncodingHextile   5
#define rfbEncodingZlib      6
#define rfbEncodingTight     7
#define rfbEncodingZlibHex   8
#define rfbEncodingZRLE     16
[...]
#define rfbEncodingXCursor         0xFFFFFF10
#define rfbEncodingRichCursor      0xFFFFFF11
#define rfbEncodingPointerPos      0xFFFFFF18
Quoted 6 lines

#define rfbEncodingLastRect 0xFFFFFF20
#define rfbEncodingNewFBSize 0xFFFFFF21

Where else should I look for defines? I'd rather have them here and if anything collide than not in any header files.

http://www.realvnc.com/docs/rfbproto.pdf is where the protocol is defined. Early in VNC's life, when TightVNC first fork()'d from RealVNC, there was no formal protocol definition. This led to some incompatible implementations so if you want to maintain compatibility with the largest number of clients, it's best to stick to what's defined by the standard.

Regards,

Anthony Liguori

#10 lore raw

Re: [Qemu-devel] Re: [PATCH 7/7] Add tight encoding (jpeg) to vnc.c

In reply to Stefano Stabellini
Quoted 18 lines · Stefano Stabellini
Quoted 5 lines · Anthony Liguori

If we implement Tight and then use jpeg by default, for most clients, the default is going to be lossy encoding. While lossy isn't so bad for high detailed images (like pictures), it's pretty terrible for simple, high contrast images (like windows in a desktop).

Quoted 9 lines

TightVNC has some sophisticated heuristics for determining whether to use jpeg or not (when it's enabled). I think that sort of heuristic is a prerequisite for enabling tight's jpeg support.

FWIW, Tight essentially does hextile encoding but adds zlib compression. That's probably a better place to start as it should outperform hextile while remaining lossless.

Quoted 4 lines

Another thing to consider is that using jpeg compression is going to worsen qemu performances, so I think it should be used only when necessary, e.g. the network connection between client and server is bad.

Most clients I know do not enable JPEG by default. It requires a user to explicitly do so.

Regards,

Anthony Liguori