SOURCES: directvnc-3.3.7-tight.patch (NEW) - handling of the 3.3.7...

witekfl witekfl at pld-linux.org
Mon Jan 15 22:20:42 CET 2007


Author: witekfl                      Date: Mon Jan 15 21:20:42 2007 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- handling of the 3.3.7 protocol with the tight extension
  without the tunneling code
- 16bpp only
- it wasn't heavilly tested

---- Files affected:
SOURCES:
   directvnc-3.3.7-tight.patch (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/directvnc-3.3.7-tight.patch
diff -u /dev/null SOURCES/directvnc-3.3.7-tight.patch:1.1
--- /dev/null	Mon Jan 15 22:20:42 2007
+++ SOURCES/directvnc-3.3.7-tight.patch	Mon Jan 15 22:20:37 2007
@@ -0,0 +1,1691 @@
+diff -Nru directvnc-0.7.5/src/caps.c directvnc-0.7.5.new/src/caps.c
+--- directvnc-0.7.5/src/caps.c	1970-01-01 01:00:00.000000000 +0100
++++ directvnc-0.7.5.new/src/caps.c	2007-01-15 14:48:51.000000000 +0100
+@@ -0,0 +1,246 @@
++/*
++ *  Copyright (C) 2003 Constantin Kaplinsky.  All Rights Reserved.
++ *
++ *  This is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This software is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this software; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
++ *  USA.
++ */
++
++/*
++ * caps.c
++ */
++
++#include "caps.h"
++#include "rfbproto.h"
++
++static int CapsIndex(CapsContainer *pcaps, CARD32 code);
++
++/*
++ * The constructor.
++ */
++
++CapsContainer *
++CapsNewContainer(void)
++{
++  CapsContainer *pcaps;
++
++  pcaps = malloc(sizeof(CapsContainer));
++  if (pcaps != NULL) {
++    pcaps->known_count = 0;
++    pcaps->enabled_count = 0;
++  }
++
++  return pcaps;
++}
++
++/*
++ * The destructor.
++ */
++
++void
++CapsDeleteContainer(CapsContainer *pcaps)
++{
++  int i;
++
++  for (i = 0; i < pcaps->known_count; i++) {
++    if (pcaps->descriptions[i] != NULL)
++      free(pcaps->descriptions[i]);
++  }
++
++  free(pcaps);
++}
++
++/*
++ * Add information about a particular capability into the object. There are
++ * two functions to perform this task. These functions overwrite capability
++ * records with the same code.
++ */
++
++void
++CapsAdd(CapsContainer *pcaps,
++        CARD32 code, char *vendor, char *name, char *desc)
++{
++  /* Fill in an rfbCapabilityInfo structure and pass it to CapsAddInfo(). */
++  rfbCapabilityInfo capinfo;
++  capinfo.code = code;
++  memcpy(capinfo.vendorSignature, vendor, sz_rfbCapabilityInfoVendor);
++  memcpy(capinfo.nameSignature, name, sz_rfbCapabilityInfoName);
++  CapsAddInfo(pcaps, &capinfo, desc);
++}
++
++void
++CapsAddInfo(CapsContainer *pcaps,
++            rfbCapabilityInfo *capinfo, char *desc)
++{
++  int i;
++  char *desc_copy;
++
++  i = CapsIndex(pcaps, capinfo->code);
++  if (i == -1) {
++    if (pcaps->known_count >= TIGHTVNC_MAX_CAPS) {
++      return;                   /* container full */
++    }
++    i = pcaps->known_count++;
++    pcaps->known_list[i] = capinfo->code;
++    pcaps->descriptions[i] = NULL;
++  }
++
++  pcaps->known_info[i] = *capinfo;
++  pcaps->enable_flags[i] = (char)0;
++  if (pcaps->descriptions[i] != NULL) {
++    free(pcaps->descriptions[i]);
++  }
++
++  desc_copy = NULL;
++  if (desc != NULL) {
++    desc_copy = strdup(desc);
++  }
++  pcaps->descriptions[i] = desc_copy;
++}
++
++/*
++ * Check if a capability with the specified code was added earlier.
++ */
++
++static int
++CapsIndex(CapsContainer *pcaps, CARD32 code)
++{
++  int i;
++
++  for (i = 0; i < pcaps->known_count; i++) {
++    if (pcaps->known_list[i] == code)
++      return i;
++  }
++
++  return -1;
++}
++
++int
++CapsIsKnown(CapsContainer *pcaps, CARD32 code)
++{
++  return (CapsIndex(pcaps, code) != -1);
++}
++
++/*
++ * Fill in a rfbCapabilityInfo structure with contents corresponding to the
++ * specified code. Returns True on success, False if the specified code is
++ * not known.
++ */
++
++int
++CapsGetInfo(CapsContainer *pcaps, CARD32 code, rfbCapabilityInfo *capinfo)
++{
++  int i;
++
++  i = CapsIndex(pcaps, code);
++  if (i != -1) {
++    *capinfo = pcaps->known_info[i];
++    return 1;
++  }
++
++  return 0;
++}
++
++/*
++ * Get a description string for the specified capability code. Returns NULL
++ * either if the code is not known, or if there is no description for this
++ * capability.
++ */
++
++char *
++CapsGetDescription(CapsContainer *pcaps, CARD32 code)
++{
++  int i;
++
++  i = CapsIndex(pcaps, code);
++  if (i != -1) {
++    return pcaps->descriptions[i];
++  }
++
++  return NULL;
++}
++
++/*
++ * Mark the specified capability as "enabled". This function checks "vendor"
++ * and "name" signatures in the existing record and in the argument structure
++ * and enables the capability only if both records are the same.
++ */
++
++int
++CapsEnable(CapsContainer *pcaps, rfbCapabilityInfo *capinfo)
++{
++  int i;
++  rfbCapabilityInfo *known;
++
++  i = CapsIndex(pcaps, capinfo->code);
++  if (i == -1)
++    return 0;
++
++  known = &pcaps->known_info[i];
++  if ( memcmp(known->vendorSignature, capinfo->vendorSignature,
++              sz_rfbCapabilityInfoVendor) != 0 ||
++       memcmp(known->nameSignature, capinfo->nameSignature,
++              sz_rfbCapabilityInfoName) != 0 ) {
++    pcaps->enable_flags[i] = (char)0;
++    return 0;
++  }
++
++  /* Cannot happen, but just in case. */
++  if (pcaps->enabled_count >= TIGHTVNC_MAX_CAPS) {
++    pcaps->enable_flags[i] = (char)0;
++    return 0;
++  }
++
++  pcaps->enable_flags[i] = (char)1;
++  pcaps->enabled_list[pcaps->enabled_count++] = capinfo->code;
++  return 1;
++}
++
++/*
++ * Check if the specified capability is known and enabled.
++ */
++
++int
++CapsIsEnabled(CapsContainer *pcaps, CARD32 code)
++{
++  int i;
++
++  i = CapsIndex(pcaps, code);
++  if (i != -1) {
++    return (pcaps->enable_flags[i] != (char)0);
++  }
++
++  return 0;
++}
++
++/*
++ * Return the number of enabled capabilities.
++ */
++
++int CapsNumEnabled(CapsContainer *pcaps)
++{
++  return pcaps->enabled_count;
++}
++
++/*
++ * Return the capability code at the specified index.
++ * If the index is not valid, return 0.
++ */
++
++CARD32
++CapsGetByOrder(CapsContainer *pcaps, int idx)
++{
++  return (idx < pcaps->enabled_count) ? pcaps->enabled_list[idx] : 0;
++}
++
+diff -Nru directvnc-0.7.5/src/caps.h directvnc-0.7.5.new/src/caps.h
+--- directvnc-0.7.5/src/caps.h	1970-01-01 01:00:00.000000000 +0100
++++ directvnc-0.7.5.new/src/caps.h	2007-01-15 14:46:50.000000000 +0100
+@@ -0,0 +1,64 @@
++/*
++ *  Copyright (C) 2003 Constantin Kaplinsky.  All Rights Reserved.
++ *
++ *  This is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This software is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this software; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
++ *  USA.
++ */
++
++/*
++ * caps.h
++ */
++
++#ifndef _VNC_CAPSCONTAINER
++#define _VNC_CAPSCONTAINER
++
++#include "directvnc.h"
++/* FIXME: Don't limit the number of capabilities. */
++#define TIGHTVNC_MAX_CAPS  64
++
++typedef struct _CapsContainer
++{
++  int known_count;
++  CARD32 known_list[TIGHTVNC_MAX_CAPS];
++  rfbCapabilityInfo known_info[TIGHTVNC_MAX_CAPS];
++  char *descriptions[TIGHTVNC_MAX_CAPS];
++  char enable_flags[TIGHTVNC_MAX_CAPS];
++
++  /* These are redundant, but improve the performance. */
++  int enabled_count;
++  CARD32 enabled_list[TIGHTVNC_MAX_CAPS];
++
++} CapsContainer;
++
++CapsContainer *CapsNewContainer(void);
++void CapsDeleteContainer(CapsContainer *pcaps);
++
++void CapsAdd(CapsContainer *pcaps,
++             CARD32 code, char *vendor, char *name, char *desc);
++void CapsAddInfo(CapsContainer *pcaps,
++                 rfbCapabilityInfo *capinfo, char *desc);
++
++int CapsIsKnown(CapsContainer *pcaps, CARD32 code);
++int CapsGetInfo(CapsContainer *pcaps, CARD32 code,
++                 rfbCapabilityInfo *capinfo);
++char *CapsGetDescription(CapsContainer *pcaps, CARD32 code);
++
++int CapsEnable(CapsContainer *pcaps, rfbCapabilityInfo *capinfo);
++int CapsIsEnabled(CapsContainer *pcaps, CARD32 code);
++int CapsNumEnabled(CapsContainer *pcaps);
++CARD32 CapsGetByOrder(CapsContainer *pcaps, int idx);
++
++#endif /* _VNC_CAPSCONTAINER */
++
+diff -Nru directvnc-0.7.5/src/cursor.c directvnc-0.7.5.new/src/cursor.c
+--- directvnc-0.7.5/src/cursor.c	2003-01-26 19:47:54.000000000 +0100
++++ directvnc-0.7.5.new/src/cursor.c	2007-01-15 19:59:32.000000000 +0100
+@@ -31,6 +31,15 @@
+ #define True 1
+ #define False 0
+ 
++#define RGB24_TO_PIXEL(bpp,r,g,b)                                       \
++   ((((CARD##bpp)(r) & 0xFF) * opt.client.redmax + 127) / 255             \
++    << opt.client.redshift |                                              \
++    (((CARD##bpp)(g) & 0xFF) * opt.client.greenmax + 127) / 255           \
++    << opt.client.greenshift |                                            \
++    (((CARD##bpp)(b) & 0xFF) * opt.client.bluemax + 127) / 255            \
++    << opt.client.blueshift)
++
++
+ 
+ /* Data kept for RichCursor encoding support. */
+ static Bool prevRichCursorSet = False;
+@@ -46,7 +55,6 @@
+ static void SoftCursorDraw(void);
+ static void FreeCursors(Bool setDotCursor);
+ 
+-
+ /*********************************************************************
+  * HandleRichCursor(). RichCursor shape updates support. This
+  * variation of cursor shape updates cannot be supported directly via
+@@ -54,13 +62,17 @@
+  * buffer (that is why we call it "software cursor").
+  ********************************************************************/
+ 
+-Bool HandleRichCursor(int xhot, int yhot, int width, int height)
++Bool HandleCursorShape(int xhot, int yhot, int width, int height, CARD32 enc)
+ {
++  int bytesPerPixel;
+   size_t bytesPerRow, bytesMaskData;
++  rfbXCursorColors rgb;
++  CARD32 colors[2];
+   char *buf;
+   CARD8 *ptr;
+   int x, y, b;
+ 
++  bytesPerPixel = opt.server.bpp / 8;
+   bytesPerRow = (width + 7) / 8;
+   bytesMaskData = bytesPerRow * height;
+ 
+@@ -75,11 +87,6 @@
+   if (rcSource == NULL)
+     return False;
+ 
+-  if (!read_from_rfb_server(sock, (char *)rcSource,
+-			 width * height * (opt.client.bpp / 8))) {
+-    free(rcSource);
+-    return False;
+-  }
+ 
+   /* Read and decode mask data. */
+ 
+@@ -89,6 +96,64 @@
+     return False;
+   }
+ 
++  /* Read and decode cursor pixel data, depending on the encoding type. */
++
++  if (enc == rfbEncodingXCursor) {
++
++    /* Read and convert background and foreground colors. */
++    if (!read_from_rfb_server(sock, (char *)&rgb, sz_rfbXCursorColors)) {
++      free(rcSource);
++      free(buf);
++      return False;
++    }
++    colors[0] = RGB24_TO_PIXEL(32, rgb.backRed, rgb.backGreen, rgb.backBlue);
++    colors[1] = RGB24_TO_PIXEL(32, rgb.foreRed, rgb.foreGreen, rgb.foreBlue);
++
++    /* Read 1bpp pixel data into a temporary buffer. */
++    if (!read_from_rfb_server(sock, buf, bytesMaskData)) {
++      free(rcSource);
++      free(buf);
++      return False;
++    }
++
++    /* Convert 1bpp data to byte-wide color indices. */
++    ptr = rcSource;
++    for (y = 0; y < height; y++) {
++      for (x = 0; x < width / 8; x++) {
++	for (b = 7; b >= 0; b--) {
++	  *ptr = buf[y * bytesPerRow + x] >> b & 1;
++	  ptr += bytesPerPixel;
++	}
++      }
++      for (b = 7; b > 7 - width % 8; b--) {
++	*ptr = buf[y * bytesPerRow + x] >> b & 1;
++	ptr += bytesPerPixel;
++      }
++    }
++
++    /* Convert indices into the actual pixel values. */
++    switch (bytesPerPixel) {
++    case 1:
++      for (x = 0; x < width * height; x++)
++	rcSource[x] = (CARD8)colors[rcSource[x]];
++      break;
++    case 2:
++      for (x = 0; x < width * height; x++)
++	((CARD16 *)rcSource)[x] = (CARD16)colors[rcSource[x * 2]];
++      break;
++    case 4:
++      for (x = 0; x < width * height; x++)
++	((CARD32 *)rcSource)[x] = colors[rcSource[x * 4]];
++      break;
++    }
++  } else { /* rfbEncodingRichCursor */
++    if (!read_from_rfb_server(sock, (char *)rcSource,
++		  	 width * height * (opt.client.bpp / 8))) {
++      free(rcSource);
++      return False;
++    }
++  }
++
+   if (!read_from_rfb_server(sock, buf, bytesMaskData)) {
+     free(rcSource);
+     free(buf);
+@@ -201,7 +266,8 @@
+  * SoftCursorUnlock() functions is called.
+  ********************************************************************/
+ 
+-void SoftCursorMove(int x, int y)
++void
++SoftCursorMove(int x, int y)
+ {
+   if (prevRichCursorSet && !rcCursorHidden) {
+     SoftCursorCopyArea(OPER_RESTORE);
+@@ -303,3 +369,20 @@
+   }
+ }
+ 
++/*********************************************************************
++ * HandleCursorPos(). Support for the PointerPos pseudo-encoding used
++ * to transmit changes in pointer position from server to clients.
++ * PointerPos encoding is used together with cursor shape updates.
++ ********************************************************************/
++
++int
++HandleCursorPos(int x, int y)
++{
++  if (x >= opt.server.width)
++    x = opt.server.width - 1;
++  if (y >= opt.server.height)
++    y = opt.server.height - 1;
++
++  SoftCursorMove(x, y);
++  return 1;
++}
+diff -Nru directvnc-0.7.5/src/directvnc.h directvnc-0.7.5.new/src/directvnc.h
+--- directvnc-0.7.5/src/directvnc.h	2007-01-15 22:06:18.000000000 +0100
++++ directvnc-0.7.5.new/src/directvnc.h	2007-01-15 20:02:12.000000000 +0100
+@@ -117,6 +117,7 @@
+ {
+    char *servername;
+    int port;
++   char *user;
+    char *password;
+    char *encodings;
+    struct serversettings server;
+@@ -142,6 +143,7 @@
+ int read_from_rfb_server(int sock, char *out, unsigned int n);
+ int write_exact(int sock, char *buf, unsigned int n);
+ int set_non_blocking(int sock);
++int SameMachine(int sock);
+ 
+ /* dfb.c */
+ void dfb_init(int argc, char *argv[]);
+@@ -157,12 +159,11 @@
+ void dfb_restore_cursor_rect( IDirectFBSurface *surf, int x, int y, int width, int heigth);
+ 
+ /* cursor.c */
+-int HandleRichCursor(int x, int y, int w, int h);
++int HandleCursorShape(int x, int y, int w, int h, CARD32 enc);
+ void SoftCursorLockArea(int x, int y, int w, int h);
+ void SoftCursorUnlockScreen(void);
+ void SoftCursorMove(int x, int y);
+ 
+-
+ /* macro for a safe call to DirectFB functions */
+ #define DFBCHECK(x...)                                                    \
+      {                                                                    \
+@@ -174,5 +175,3 @@
+      }
+ 
+ #endif
+-
+-
+diff -Nru directvnc-0.7.5/src/Makefile.am directvnc-0.7.5.new/src/Makefile.am
+--- directvnc-0.7.5/src/Makefile.am	2003-01-31 10:20:35.000000000 +0100
++++ directvnc-0.7.5.new/src/Makefile.am	2007-01-15 14:07:50.000000000 +0100
+@@ -9,7 +9,7 @@
+ LIBOBJS = @LIBOBJS@
+ 
+ bin_PROGRAMS      = directvnc
+-directvnc_SOURCES       = main.c debug.h dfb.c directvnc.h sockets.c args.c\
++directvnc_SOURCES       = caps.c caps.h main.c debug.h dfb.c directvnc.h sockets.c args.c\
+ 		       rfb.c getopt.c getopt1.c getopt.h\
+ 		       d3des.c d3des.h vncauth.c vncauth.h jpeg.c jpeg.h\
+ 		       tight.c tight.h rfbproto.h keysym.h keysymdef.h \
+diff -Nru directvnc-0.7.5/src/rfb.c directvnc-0.7.5.new/src/rfb.c
+--- directvnc-0.7.5/src/rfb.c	2003-01-31 09:41:03.000000000 +0100
++++ directvnc-0.7.5.new/src/rfb.c	2007-01-15 21:49:58.000000000 +0100
+@@ -17,7 +17,8 @@
+  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+  */
+ 
+-
++#include <pwd.h>
++#include <sys/types.h>
+ #include <unistd.h>
+ #include <sys/socket.h>
+ #include <errno.h>
+@@ -28,15 +29,25 @@
+ #include <math.h>
+ #include <zlib.h>
+ 
++#include "caps.h"
+ #include "directvnc.h"
+ #include "tight.h"
+ 
++static void InitCapabilities(void);
++static int SetupTunneling(void);
++static int ReadSecurityType(void);
++static int SelectSecurityType(void);
++static int PerformAuthenticationTight(void);
++static int AuthenticateVNC(void);
++static int AuthenticateUnixLogin(void);
++static int ReadInteractionCaps(void);
++static int ReadCapabilityList(CapsContainer *caps, int count);
++
+ int _rfb_negotiate_protocol ();
+ int _rfb_authenticate ();
+ int _rfb_initialise_client ();
+ int _rfb_initialise_server ();
+ 
+-
+ static int _handle_raw_encoded_message(rfbFramebufferUpdateRectHeader rectheader);
+ static int _handle_copyrect_encoded_message(rfbFramebufferUpdateRectHeader rectheader);
+ static int _handle_rre_encoded_message(rfbFramebufferUpdateRectHeader rectheader);
+@@ -44,6 +55,63 @@
+ static int _handle_hextile_encoded_message(rfbFramebufferUpdateRectHeader rectheader);
+ static int _handle_richcursor_message(rfbFramebufferUpdateRectHeader rectheader);
+ 
++static int tightVncProtocol = 0;
++static CapsContainer *tunnelCaps;    /* known tunneling/encryption methods */
++static CapsContainer *authCaps;	     /* known authentication schemes       */
++static CapsContainer *serverMsgCaps; /* known non-standard server messages */
++static CapsContainer *clientMsgCaps; /* known non-standard client messages */
++static CapsContainer *encodingCaps;  /* known encodings besides Raw        */
++static int tunnelSpecified = 0;
++
++/*
++ * InitCapabilities.
++ */
++
++static void
++InitCapabilities(void)
++{
++  tunnelCaps    = CapsNewContainer();
++  authCaps      = CapsNewContainer();
++  serverMsgCaps = CapsNewContainer();
++  clientMsgCaps = CapsNewContainer();
++  encodingCaps  = CapsNewContainer();
++
++  /* Supported authentication methods */
++  CapsAdd(authCaps, rfbAuthVNC, rfbStandardVendor, sig_rfbAuthVNC,
++	  "Standard VNC password authentication");
<<Diff was trimmed, longer than 597 lines>>


More information about the pld-cvs-commit mailing list