Add the modified VNC DLL from Stephen Fewer
git-svn-id: file:///home/svn/framework3/trunk@5807 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
56a413d803
commit
835ce24792
|
@ -0,0 +1,2 @@
|
||||||
|
Use the solutions file 'winvnc\VNC DLL Injection.sln' to build vncdll.dll
|
||||||
|
This build has only been tested with Visual Studio 2003.
|
|
@ -0,0 +1,27 @@
|
||||||
|
Copyright (c) 2008, Harmony Security
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of Harmony Security nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this software
|
||||||
|
without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1,10 @@
|
||||||
|
This project is a mangled version of RealVNC v3.3.7, it has been modified to work
|
||||||
|
as a payload with the DLL injection system developed by Jarkko Turkulainen and
|
||||||
|
Matt Miller. The majority of the changes were made by Matt Miller, with minor
|
||||||
|
tweaks and packaging by H D Moore. If you have questions about this source code
|
||||||
|
or would like to extend it, you should contact:
|
||||||
|
|
||||||
|
Matt Miller <mmiller[at]hick.org>
|
||||||
|
H D Moore <hdm[at]metasploit.com>
|
||||||
|
|
||||||
|
Updates to this project will be made available at metasploit.com
|
|
@ -0,0 +1,115 @@
|
||||||
|
|
||||||
|
VNC Source Distribution for Windows platforms
|
||||||
|
=============================================
|
||||||
|
|
||||||
|
VNC is Copyright RealVNC Ltd. 2002 and Copyright AT&T Laboratories Cambridge
|
||||||
|
1996-2001. This software is distributed under the GNU General Public Licence
|
||||||
|
as published by the Free Software Foundation. See the accompanying licence.txt
|
||||||
|
file for the conditions under which the software is made available.
|
||||||
|
|
||||||
|
VNC also contains code from other sources. See the Acknowledgements section
|
||||||
|
below, and the individual files for details of the conditions under which
|
||||||
|
they are made available.
|
||||||
|
|
||||||
|
There are two programs here in the two subdirectories:
|
||||||
|
|
||||||
|
vncviewer - this is the VNC viewer, or client, program for Win32.
|
||||||
|
|
||||||
|
winvnc - this is the VNC server for Win32. It allows a Windows desktop
|
||||||
|
to be accessed remotely using a VNC viewer.
|
||||||
|
|
||||||
|
Both programs have been built using Microsoft Visual C++ 6.0, and appropriate
|
||||||
|
build settings are provided in this source distribution.
|
||||||
|
|
||||||
|
|
||||||
|
ACKNOWLEDGEMENTS
|
||||||
|
================
|
||||||
|
|
||||||
|
This distribution contains public domain zlib software by Jean-loup Gailly and Mark Adler.
|
||||||
|
This is:
|
||||||
|
|
||||||
|
Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler.
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
Jean-loup Gailly Mark Adler
|
||||||
|
jloup@gzip.org madler@alumni.caltech.edu
|
||||||
|
|
||||||
|
|
||||||
|
The data format used by the zlib library is described by RFCs (Request for
|
||||||
|
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
|
||||||
|
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
|
||||||
|
|
||||||
|
This distribution contains public domain DES software by Richard Outerbridge.
|
||||||
|
This is:
|
||||||
|
|
||||||
|
Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge.
|
||||||
|
(GEnie : OUTER; CIS : [71755,204]) Graven Imagery, 1992.
|
||||||
|
|
||||||
|
|
||||||
|
This distribution contains Java DES software by Dave Zimmerman
|
||||||
|
<dzimm@widget.com> and Jef Poskanzer <jef@acme.com>. This is:
|
||||||
|
|
||||||
|
Copyright (c) 1996 Widget Workshop, Inc. All Rights Reserved.
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software and its
|
||||||
|
documentation for NON-COMMERCIAL or COMMERCIAL purposes and without fee
|
||||||
|
is hereby granted, provided that this copyright notice is kept intact.
|
||||||
|
|
||||||
|
WIDGET WORKSHOP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
|
||||||
|
SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
|
||||||
|
NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WIDGET WORKSHOP SHALL NOT BE
|
||||||
|
LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
|
||||||
|
MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
|
||||||
|
CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
|
||||||
|
PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
|
||||||
|
NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
|
||||||
|
SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
|
||||||
|
SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
|
||||||
|
PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). WIDGET
|
||||||
|
WORKSHOP SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF
|
||||||
|
FITNESS FOR HIGH RISK ACTIVITIES.
|
||||||
|
|
||||||
|
Copyright (C) 1996 by Jef Poskanzer <jef@acme.com>. All rights
|
||||||
|
reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
|
||||||
|
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||||
|
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
Visit the ACME Labs Java page for up-to-date versions of this and other
|
||||||
|
fine Java utilities: http://www.acme.com/java/
|
|
@ -0,0 +1,115 @@
|
||||||
|
|
||||||
|
VNC Binary Distribution for Windows platforms
|
||||||
|
=============================================
|
||||||
|
|
||||||
|
VNC is Copyright RealVNC Ltd. 2002 and Copyright AT&T Laboratories Cambridge
|
||||||
|
1996-2001. This software is distributed under the GNU General Public Licence
|
||||||
|
as published by the Free Software Foundation. VNC also contains code from
|
||||||
|
other sources, as outlined in the Acknowledgements section below.
|
||||||
|
|
||||||
|
The installer package contains two VNC components:
|
||||||
|
|
||||||
|
VNCViewer - this is the VNC viewer, or client, program for Win32.
|
||||||
|
[Win9x, WinME, NT4, Win2000, WinXP]
|
||||||
|
|
||||||
|
WinVNC - this is the VNC server for Win32. It allows a Windows desktop
|
||||||
|
to be accessed remotely using a VNC viewer.
|
||||||
|
[Win9x, WinME, NT4, Win2000, WinXP(*)]
|
||||||
|
|
||||||
|
(*) Unless the in-built Fast User Switching or Remote Administration
|
||||||
|
features are used.
|
||||||
|
|
||||||
|
Both components were built using Microsoft Visual C++ 6.0, and are designed
|
||||||
|
to operate upon the Win32 platforms listed above.
|
||||||
|
|
||||||
|
ACKNOWLEDGEMENTS
|
||||||
|
================
|
||||||
|
|
||||||
|
This distribution contains public domain zlib software by Jean-loup Gailly and Mark Adler.
|
||||||
|
This is:
|
||||||
|
|
||||||
|
Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler.
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
Jean-loup Gailly Mark Adler
|
||||||
|
jloup@gzip.org madler@alumni.caltech.edu
|
||||||
|
|
||||||
|
|
||||||
|
The data format used by the zlib library is described by RFCs (Request for
|
||||||
|
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
|
||||||
|
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
|
||||||
|
|
||||||
|
This distribution contains public domain DES software by Richard Outerbridge.
|
||||||
|
This is:
|
||||||
|
|
||||||
|
Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge.
|
||||||
|
(GEnie : OUTER; CIS : [71755,204]) Graven Imagery, 1992.
|
||||||
|
|
||||||
|
|
||||||
|
This distribution contains Java DES software by Dave Zimmerman
|
||||||
|
<dzimm@widget.com> and Jef Poskanzer <jef@acme.com>. This is:
|
||||||
|
|
||||||
|
Copyright (c) 1996 Widget Workshop, Inc. All Rights Reserved.
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software and its
|
||||||
|
documentation for NON-COMMERCIAL or COMMERCIAL purposes and without fee
|
||||||
|
is hereby granted, provided that this copyright notice is kept intact.
|
||||||
|
|
||||||
|
WIDGET WORKSHOP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
|
||||||
|
SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
|
||||||
|
NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WIDGET WORKSHOP SHALL NOT BE
|
||||||
|
LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
|
||||||
|
MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
|
||||||
|
CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
|
||||||
|
PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
|
||||||
|
NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
|
||||||
|
SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
|
||||||
|
SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
|
||||||
|
PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). WIDGET
|
||||||
|
WORKSHOP SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF
|
||||||
|
FITNESS FOR HIGH RISK ACTIVITIES.
|
||||||
|
|
||||||
|
Copyright (C) 1996 by Jef Poskanzer <jef@acme.com>. All rights
|
||||||
|
reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
|
||||||
|
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||||
|
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
Visit the ACME Labs Java page for up-to-date versions of this and other
|
||||||
|
fine Java utilities: http://www.acme.com/java/
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,104 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="Xregion" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||||
|
|
||||||
|
CFG=Xregion - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "Xregion.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "Xregion.mak" CFG="Xregion - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "Xregion - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||||
|
!MESSAGE "Xregion - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "Xregion - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LIB32=link.exe -lib
|
||||||
|
# ADD BASE LIB32 /nologo
|
||||||
|
# ADD LIB32 /nologo
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "Xregion - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LIB32=link.exe -lib
|
||||||
|
# ADD BASE LIB32 /nologo
|
||||||
|
# ADD LIB32 /nologo
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "Xregion - Win32 Release"
|
||||||
|
# Name "Xregion - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\Region.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\region.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\Xregion.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,214 @@
|
||||||
|
/* $Xorg: Xutil.h,v 1.8 2001/02/09 02:03:39 xorgcvs Exp $ */
|
||||||
|
|
||||||
|
/***********************************************************
|
||||||
|
|
||||||
|
Copyright 1987, 1998 The Open Group
|
||||||
|
|
||||||
|
Permission to use, copy, modify, distribute, and sell this software and its
|
||||||
|
documentation for any purpose is hereby granted without fee, provided that
|
||||||
|
the above copyright notice appear in all copies and that both that
|
||||||
|
copyright notice and this permission notice appear in supporting
|
||||||
|
documentation.
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
Except as contained in this notice, the name of The Open Group shall not be
|
||||||
|
used in advertising or otherwise to promote the sale, use or other dealings
|
||||||
|
in this Software without prior written authorization from The Open Group.
|
||||||
|
|
||||||
|
|
||||||
|
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
|
||||||
|
|
||||||
|
All Rights Reserved
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software and its
|
||||||
|
documentation for any purpose and without fee is hereby granted,
|
||||||
|
provided that the above copyright notice appear in all copies and that
|
||||||
|
both that copyright notice and this permission notice appear in
|
||||||
|
supporting documentation, and that the name of Digital not be
|
||||||
|
used in advertising or publicity pertaining to distribution of the
|
||||||
|
software without specific, written prior permission.
|
||||||
|
|
||||||
|
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||||
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||||
|
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||||
|
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||||
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
******************************************************************/
|
||||||
|
/* $XFree86: xc/lib/X11/Xutil.h,v 3.4 2001/12/14 19:54:10 dawes Exp $ */
|
||||||
|
|
||||||
|
#ifndef _XREGION_H_
|
||||||
|
#define _XREGION_H_
|
||||||
|
|
||||||
|
// - Faked defines to fool the X11 region code
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define Bool int
|
||||||
|
#define Xmalloc malloc
|
||||||
|
#define Xfree free
|
||||||
|
#define Xrealloc realloc
|
||||||
|
|
||||||
|
#define NeedFunctionPrototypes 1
|
||||||
|
|
||||||
|
// - Cribbed from Xlib.h
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
short x, y;
|
||||||
|
} XPoint;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
short x, y;
|
||||||
|
unsigned short width, height;
|
||||||
|
} XRectangle;
|
||||||
|
|
||||||
|
//#include <Xregion/region.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* opaque reference to Region data type
|
||||||
|
*/
|
||||||
|
typedef struct _XRegion *XRegion;
|
||||||
|
|
||||||
|
/* Return values from XRectInRegion() */
|
||||||
|
|
||||||
|
#define RectangleOut 0
|
||||||
|
#define RectangleIn 1
|
||||||
|
#define RectanglePart 2
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern int XClipBox(
|
||||||
|
#if NeedFunctionPrototypes
|
||||||
|
XRegion /* r */,
|
||||||
|
XRectangle* /* rect_return */
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
extern XRegion XCreateRegion(
|
||||||
|
#if NeedFunctionPrototypes
|
||||||
|
void
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
extern const char *XDefaultString (void);
|
||||||
|
|
||||||
|
extern int XDestroyRegion(
|
||||||
|
#if NeedFunctionPrototypes
|
||||||
|
XRegion /* r */
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
extern int XEmptyRegion(
|
||||||
|
#if NeedFunctionPrototypes
|
||||||
|
XRegion /* r */
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
extern int XEqualRegion(
|
||||||
|
#if NeedFunctionPrototypes
|
||||||
|
XRegion /* r1 */,
|
||||||
|
XRegion /* r2 */
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
extern int XIntersectRegion(
|
||||||
|
#if NeedFunctionPrototypes
|
||||||
|
XRegion /* sra */,
|
||||||
|
XRegion /* srb */,
|
||||||
|
XRegion /* dr_return */
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
extern int XOffsetRegion(
|
||||||
|
#if NeedFunctionPrototypes
|
||||||
|
XRegion /* r */,
|
||||||
|
int /* dx */,
|
||||||
|
int /* dy */
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
extern Bool XPointInRegion(
|
||||||
|
#if NeedFunctionPrototypes
|
||||||
|
XRegion /* r */,
|
||||||
|
int /* x */,
|
||||||
|
int /* y */
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
extern XRegion XPolygonRegion(
|
||||||
|
#if NeedFunctionPrototypes
|
||||||
|
XPoint* /* points */,
|
||||||
|
int /* n */,
|
||||||
|
int /* fill_rule */
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
extern int XRectInRegion(
|
||||||
|
#if NeedFunctionPrototypes
|
||||||
|
XRegion /* r */,
|
||||||
|
int /* x */,
|
||||||
|
int /* y */,
|
||||||
|
unsigned int /* width */,
|
||||||
|
unsigned int /* height */
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
extern int XShrinkRegion(
|
||||||
|
#if NeedFunctionPrototypes
|
||||||
|
XRegion /* r */,
|
||||||
|
int /* dx */,
|
||||||
|
int /* dy */
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
extern int XSubtractRegion(
|
||||||
|
#if NeedFunctionPrototypes
|
||||||
|
XRegion /* sra */,
|
||||||
|
XRegion /* srb */,
|
||||||
|
XRegion /* dr_return */
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
extern int XUnionRectWithRegion(
|
||||||
|
#if NeedFunctionPrototypes
|
||||||
|
XRectangle* /* rectangle */,
|
||||||
|
XRegion /* src_region */,
|
||||||
|
XRegion /* dest_region_return */
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
extern int XUnionRegion(
|
||||||
|
#if NeedFunctionPrototypes
|
||||||
|
XRegion /* sra */,
|
||||||
|
XRegion /* srb */,
|
||||||
|
XRegion /* dr_return */
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
extern int XXorRegion(
|
||||||
|
#if NeedFunctionPrototypes
|
||||||
|
XRegion /* sra */,
|
||||||
|
XRegion /* srb */,
|
||||||
|
XRegion /* dr_return */
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _XUTIL_H_ */
|
|
@ -0,0 +1,128 @@
|
||||||
|
<?xml version="1.0" encoding="Windows-1252"?>
|
||||||
|
<VisualStudioProject
|
||||||
|
ProjectType="Visual C++"
|
||||||
|
Version="9.00"
|
||||||
|
Name="Xregion"
|
||||||
|
ProjectGUID="{2B336221-F3CC-4100-AFC6-FE6F7D1348A3}"
|
||||||
|
TargetFrameworkVersion="131072"
|
||||||
|
>
|
||||||
|
<Platforms>
|
||||||
|
<Platform
|
||||||
|
Name="Win32"
|
||||||
|
/>
|
||||||
|
</Platforms>
|
||||||
|
<ToolFiles>
|
||||||
|
</ToolFiles>
|
||||||
|
<Configurations>
|
||||||
|
<Configuration
|
||||||
|
Name="Release|Win32"
|
||||||
|
OutputDirectory=".\Release"
|
||||||
|
IntermediateDirectory=".\Release"
|
||||||
|
ConfigurationType="4"
|
||||||
|
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||||
|
UseOfMFC="0"
|
||||||
|
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||||
|
CharacterSet="2"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
InlineFunctionExpansion="1"
|
||||||
|
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
||||||
|
StringPooling="true"
|
||||||
|
RuntimeLibrary="0"
|
||||||
|
EnableFunctionLevelLinking="true"
|
||||||
|
UsePrecompiledHeader="0"
|
||||||
|
PrecompiledHeaderFile=".\Release/Xregion.pch"
|
||||||
|
AssemblerListingLocation=".\Release/"
|
||||||
|
ObjectFile=".\Release/"
|
||||||
|
ProgramDataBaseFileName=".\Release/"
|
||||||
|
WarningLevel="3"
|
||||||
|
SuppressStartupBanner="true"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedResourceCompilerTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
PreprocessorDefinitions="NDEBUG"
|
||||||
|
Culture="2057"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLibrarianTool"
|
||||||
|
OutputFile=".\Release\Xregion.lib"
|
||||||
|
SuppressStartupBanner="true"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCALinkTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXDCMakeTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCBscMakeTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCFxCopTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"
|
||||||
|
/>
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
<References>
|
||||||
|
</References>
|
||||||
|
<Files>
|
||||||
|
<Filter
|
||||||
|
Name="Source Files"
|
||||||
|
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="Region.c"
|
||||||
|
>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Header Files"
|
||||||
|
Filter="h;hpp;hxx;hm;inl"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="region.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="Xregion.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
</Files>
|
||||||
|
<Globals>
|
||||||
|
</Globals>
|
||||||
|
</VisualStudioProject>
|
|
@ -0,0 +1,94 @@
|
||||||
|
<?xml version="1.0" encoding="Windows-1252"?>
|
||||||
|
<VisualStudioProject
|
||||||
|
ProjectType="Visual C++"
|
||||||
|
Version="7.10"
|
||||||
|
Name="Xregion"
|
||||||
|
SccProjectName=""
|
||||||
|
SccLocalPath="">
|
||||||
|
<Platforms>
|
||||||
|
<Platform
|
||||||
|
Name="Win32"/>
|
||||||
|
</Platforms>
|
||||||
|
<Configurations>
|
||||||
|
<Configuration
|
||||||
|
Name="Release|Win32"
|
||||||
|
OutputDirectory=".\Release"
|
||||||
|
IntermediateDirectory=".\Release"
|
||||||
|
ConfigurationType="4"
|
||||||
|
UseOfMFC="0"
|
||||||
|
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||||
|
CharacterSet="2">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
InlineFunctionExpansion="1"
|
||||||
|
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
||||||
|
StringPooling="TRUE"
|
||||||
|
RuntimeLibrary="0"
|
||||||
|
EnableFunctionLevelLinking="TRUE"
|
||||||
|
UsePrecompiledHeader="2"
|
||||||
|
PrecompiledHeaderFile=".\Release/Xregion.pch"
|
||||||
|
AssemblerListingLocation=".\Release/"
|
||||||
|
ObjectFile=".\Release/"
|
||||||
|
ProgramDataBaseFileName=".\Release/"
|
||||||
|
WarningLevel="3"
|
||||||
|
SuppressStartupBanner="TRUE"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLibrarianTool"
|
||||||
|
OutputFile=".\Release\Xregion.lib"
|
||||||
|
SuppressStartupBanner="TRUE"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
PreprocessorDefinitions="NDEBUG"
|
||||||
|
Culture="2057"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedWrapperGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
<References>
|
||||||
|
</References>
|
||||||
|
<Files>
|
||||||
|
<Filter
|
||||||
|
Name="Source Files"
|
||||||
|
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||||
|
<File
|
||||||
|
RelativePath="Region.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Header Files"
|
||||||
|
Filter="h;hpp;hxx;hm;inl">
|
||||||
|
<File
|
||||||
|
RelativePath="region.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="Xregion.h">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
</Files>
|
||||||
|
<Globals>
|
||||||
|
</Globals>
|
||||||
|
</VisualStudioProject>
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?xml version="1.0" encoding="Windows-1252"?>
|
||||||
|
<VisualStudioUserFile
|
||||||
|
ProjectType="Visual C++"
|
||||||
|
Version="9.00"
|
||||||
|
ShowAllFiles="false"
|
||||||
|
>
|
||||||
|
<Configurations>
|
||||||
|
<Configuration
|
||||||
|
Name="Release|Win32"
|
||||||
|
>
|
||||||
|
<DebugSettings
|
||||||
|
Command=""
|
||||||
|
WorkingDirectory=""
|
||||||
|
CommandArguments=""
|
||||||
|
Attach="false"
|
||||||
|
DebuggerType="3"
|
||||||
|
Remote="1"
|
||||||
|
RemoteMachine="UNKNOWN"
|
||||||
|
RemoteCommand=""
|
||||||
|
HttpUrl=""
|
||||||
|
PDBPath=""
|
||||||
|
SQLDebugging=""
|
||||||
|
Environment=""
|
||||||
|
EnvironmentMerge="true"
|
||||||
|
DebuggerFlavor=""
|
||||||
|
MPIRunCommand=""
|
||||||
|
MPIRunArguments=""
|
||||||
|
MPIRunWorkingDirectory=""
|
||||||
|
ApplicationCommand=""
|
||||||
|
ApplicationArguments=""
|
||||||
|
ShimCommand=""
|
||||||
|
MPIAcceptMode=""
|
||||||
|
MPIAcceptFilter=""
|
||||||
|
/>
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
</VisualStudioUserFile>
|
|
@ -0,0 +1,188 @@
|
||||||
|
/* $Xorg: region.h,v 1.4 2001/02/09 02:03:40 xorgcvs Exp $ */
|
||||||
|
/************************************************************************
|
||||||
|
|
||||||
|
Copyright 1987, 1998 The Open Group
|
||||||
|
|
||||||
|
Permission to use, copy, modify, distribute, and sell this software and its
|
||||||
|
documentation for any purpose is hereby granted without fee, provided that
|
||||||
|
the above copyright notice appear in all copies and that both that
|
||||||
|
copyright notice and this permission notice appear in supporting
|
||||||
|
documentation.
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
Except as contained in this notice, the name of The Open Group shall not be
|
||||||
|
used in advertising or otherwise to promote the sale, use or other dealings
|
||||||
|
in this Software without prior written authorization from The Open Group.
|
||||||
|
|
||||||
|
|
||||||
|
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
|
||||||
|
|
||||||
|
All Rights Reserved
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software and its
|
||||||
|
documentation for any purpose and without fee is hereby granted,
|
||||||
|
provided that the above copyright notice appear in all copies and that
|
||||||
|
both that copyright notice and this permission notice appear in
|
||||||
|
supporting documentation, and that the name of Digital not be
|
||||||
|
used in advertising or publicity pertaining to distribution of the
|
||||||
|
software without specific, written prior permission.
|
||||||
|
|
||||||
|
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||||
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||||
|
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||||
|
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||||
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#ifndef _XREGION_H
|
||||||
|
#define _XREGION_H
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
short x1, x2, y1, y2;
|
||||||
|
} Box, BOX, BoxRec, *BoxPtr;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
short x, y, width, height;
|
||||||
|
}RECTANGLE, RectangleRec, *RectanglePtr;
|
||||||
|
|
||||||
|
#define TRUE 1
|
||||||
|
#define FALSE 0
|
||||||
|
#ifndef MAX
|
||||||
|
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
#ifndef MIN
|
||||||
|
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* clip region
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct _XRegion {
|
||||||
|
long size;
|
||||||
|
long numRects;
|
||||||
|
BOX *rects;
|
||||||
|
BOX extents;
|
||||||
|
} REGION;
|
||||||
|
|
||||||
|
/* Xutil.h contains the declaration:
|
||||||
|
* typedef struct _XRegion *Region;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* 1 if two BOXs overlap.
|
||||||
|
* 0 if two BOXs do not overlap.
|
||||||
|
* Remember, x2 and y2 are not in the region
|
||||||
|
*/
|
||||||
|
#define EXTENTCHECK(r1, r2) \
|
||||||
|
((r1)->x2 > (r2)->x1 && \
|
||||||
|
(r1)->x1 < (r2)->x2 && \
|
||||||
|
(r1)->y2 > (r2)->y1 && \
|
||||||
|
(r1)->y1 < (r2)->y2)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* update region extents
|
||||||
|
*/
|
||||||
|
#define EXTENTS(r,idRect){\
|
||||||
|
if((r)->x1 < (idRect)->extents.x1)\
|
||||||
|
(idRect)->extents.x1 = (r)->x1;\
|
||||||
|
if((r)->y1 < (idRect)->extents.y1)\
|
||||||
|
(idRect)->extents.y1 = (r)->y1;\
|
||||||
|
if((r)->x2 > (idRect)->extents.x2)\
|
||||||
|
(idRect)->extents.x2 = (r)->x2;\
|
||||||
|
if((r)->y2 > (idRect)->extents.y2)\
|
||||||
|
(idRect)->extents.y2 = (r)->y2;\
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check to see if there is enough memory in the present region.
|
||||||
|
*/
|
||||||
|
#define MEMCHECK(reg, rect, firstrect){\
|
||||||
|
if ((reg)->numRects >= ((reg)->size - 1)){\
|
||||||
|
(firstrect) = (BOX *) Xrealloc \
|
||||||
|
((char *)(firstrect), (unsigned) (2 * (sizeof(BOX)) * ((reg)->size)));\
|
||||||
|
if ((firstrect) == 0)\
|
||||||
|
return(0);\
|
||||||
|
(reg)->size *= 2;\
|
||||||
|
(rect) = &(firstrect)[(reg)->numRects];\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
|
/* this routine checks to see if the previous rectangle is the same
|
||||||
|
* or subsumes the new rectangle to add.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\
|
||||||
|
(!(((Reg)->numRects > 0)&&\
|
||||||
|
((R-1)->y1 == (Ry1)) &&\
|
||||||
|
((R-1)->y2 == (Ry2)) &&\
|
||||||
|
((R-1)->x1 <= (Rx1)) &&\
|
||||||
|
((R-1)->x2 >= (Rx2))))
|
||||||
|
|
||||||
|
/* add a rectangle to the given Region */
|
||||||
|
#define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\
|
||||||
|
if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\
|
||||||
|
CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
|
||||||
|
(r)->x1 = (rx1);\
|
||||||
|
(r)->y1 = (ry1);\
|
||||||
|
(r)->x2 = (rx2);\
|
||||||
|
(r)->y2 = (ry2);\
|
||||||
|
EXTENTS((r), (reg));\
|
||||||
|
(reg)->numRects++;\
|
||||||
|
(r)++;\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* add a rectangle to the given Region */
|
||||||
|
#define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\
|
||||||
|
if ((rx1 < rx2) && (ry1 < ry2) &&\
|
||||||
|
CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
|
||||||
|
(r)->x1 = (rx1);\
|
||||||
|
(r)->y1 = (ry1);\
|
||||||
|
(r)->x2 = (rx2);\
|
||||||
|
(r)->y2 = (ry2);\
|
||||||
|
(reg)->numRects++;\
|
||||||
|
(r)++;\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
|
#define EMPTY_REGION(pReg) pReg->numRects = 0
|
||||||
|
|
||||||
|
#define REGION_NOT_EMPTY(pReg) pReg->numRects
|
||||||
|
|
||||||
|
#define INBOX(r, x, y) \
|
||||||
|
( ( ((r).x2 > x)) && \
|
||||||
|
( ((r).x1 <= x)) && \
|
||||||
|
( ((r).y2 > y)) && \
|
||||||
|
( ((r).y1 <= y)) )
|
||||||
|
|
||||||
|
/*
|
||||||
|
* number of points to buffer before sending them off
|
||||||
|
* to scanlines() : Must be an even number
|
||||||
|
*/
|
||||||
|
#define NUMPTSTOBUFFER 200
|
||||||
|
|
||||||
|
/*
|
||||||
|
* used to allocate buffers for points and link
|
||||||
|
* the buffers together
|
||||||
|
*/
|
||||||
|
typedef struct _POINTBLOCK {
|
||||||
|
XPoint pts[NUMPTSTOBUFFER];
|
||||||
|
struct _POINTBLOCK *next;
|
||||||
|
} POINTBLOCK;
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,71 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
#ifndef __RDR_EXCEPTION_H__
|
||||||
|
#define __RDR_EXCEPTION_H__
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
namespace rdr {
|
||||||
|
|
||||||
|
struct Exception {
|
||||||
|
enum { len = 256 };
|
||||||
|
char str_[len];
|
||||||
|
Exception(const char* s=0, const char* e="rdr::Exception") {
|
||||||
|
str_[0] = 0;
|
||||||
|
strncat(str_, e, len-1);
|
||||||
|
if (s) {
|
||||||
|
strncat(str_, ": ", len-1-strlen(str_));
|
||||||
|
strncat(str_, s, len-1-strlen(str_));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
virtual const char* str() const { return str_; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SystemException : public Exception {
|
||||||
|
int err;
|
||||||
|
SystemException(const char* s, int err_) : err(err_) {
|
||||||
|
str_[0] = 0;
|
||||||
|
strncat(str_, "rdr::SystemException: ", len-1);
|
||||||
|
strncat(str_, s, len-1-strlen(str_));
|
||||||
|
strncat(str_, ": ", len-1-strlen(str_));
|
||||||
|
strncat(str_, strerror(err), len-1-strlen(str_));
|
||||||
|
strncat(str_, " (", len-1-strlen(str_));
|
||||||
|
char buf[20];
|
||||||
|
sprintf(buf,"%d",err);
|
||||||
|
strncat(str_, buf, len-1-strlen(str_));
|
||||||
|
strncat(str_, ")", len-1-strlen(str_));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TimedOut : public Exception {
|
||||||
|
TimedOut(const char* s=0) : Exception(s,"rdr::TimedOut") {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EndOfStream : public Exception {
|
||||||
|
EndOfStream(const char* s=0) : Exception(s,"rdr::EndOfStream") {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FrameException : public Exception {
|
||||||
|
FrameException(const char* s=0) : Exception(s,"rdr::FrameException") {}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,247 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <winsock.h>
|
||||||
|
#include <sys/timeb.h>
|
||||||
|
#define read(s,b,l) recv(s,(char*)b,l,0)
|
||||||
|
#undef errno
|
||||||
|
#define errno WSAGetLastError()
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// XXX should use autoconf HAVE_SYS_SELECT_H
|
||||||
|
#ifdef _AIX
|
||||||
|
#include <sys/select.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <rdr/FdInStream.h>
|
||||||
|
#include <rdr/Exception.h>
|
||||||
|
|
||||||
|
using namespace rdr;
|
||||||
|
|
||||||
|
enum { DEFAULT_BUF_SIZE = 8192,
|
||||||
|
MIN_BULK_SIZE = 1024 };
|
||||||
|
|
||||||
|
FdInStream::FdInStream(int fd_, int timeout_, int bufSize_)
|
||||||
|
: fd(fd_), timeout(timeout_), blockCallback(0), blockCallbackArg(0),
|
||||||
|
timing(false), timeWaitedIn100us(5), timedKbits(0),
|
||||||
|
bufSize(bufSize_ ? bufSize_ : DEFAULT_BUF_SIZE), offset(0)
|
||||||
|
{
|
||||||
|
ptr = end = start = new U8[bufSize];
|
||||||
|
}
|
||||||
|
|
||||||
|
FdInStream::FdInStream(int fd_, void (*blockCallback_)(void*),
|
||||||
|
void* blockCallbackArg_, int bufSize_)
|
||||||
|
: fd(fd_), timeout(0), blockCallback(blockCallback_),
|
||||||
|
blockCallbackArg(blockCallbackArg_),
|
||||||
|
timing(false), timeWaitedIn100us(5), timedKbits(0),
|
||||||
|
bufSize(bufSize_ ? bufSize_ : DEFAULT_BUF_SIZE), offset(0)
|
||||||
|
{
|
||||||
|
ptr = end = start = new U8[bufSize];
|
||||||
|
}
|
||||||
|
|
||||||
|
FdInStream::~FdInStream()
|
||||||
|
{
|
||||||
|
delete [] start;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int FdInStream::pos()
|
||||||
|
{
|
||||||
|
return offset + ptr - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FdInStream::readBytes(void* data, int length)
|
||||||
|
{
|
||||||
|
if (length < MIN_BULK_SIZE) {
|
||||||
|
InStream::readBytes(data, length);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
U8* dataPtr = (U8*)data;
|
||||||
|
|
||||||
|
int n = end - ptr;
|
||||||
|
if (n > length) n = length;
|
||||||
|
|
||||||
|
memcpy(dataPtr, ptr, n);
|
||||||
|
dataPtr += n;
|
||||||
|
length -= n;
|
||||||
|
ptr += n;
|
||||||
|
|
||||||
|
while (length > 0) {
|
||||||
|
n = readWithTimeoutOrCallback(dataPtr, length);
|
||||||
|
dataPtr += n;
|
||||||
|
length -= n;
|
||||||
|
offset += n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int FdInStream::overrun(int itemSize, int nItems)
|
||||||
|
{
|
||||||
|
if (itemSize > bufSize)
|
||||||
|
throw Exception("FdInStream overrun: max itemSize exceeded");
|
||||||
|
|
||||||
|
if (end - ptr != 0)
|
||||||
|
memmove(start, ptr, end - ptr);
|
||||||
|
|
||||||
|
offset += ptr - start;
|
||||||
|
end -= ptr - start;
|
||||||
|
ptr = start;
|
||||||
|
|
||||||
|
while (end < start + itemSize) {
|
||||||
|
int n = readWithTimeoutOrCallback((U8*)end, start + bufSize - end);
|
||||||
|
end += n;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemSize * nItems > end - ptr)
|
||||||
|
nItems = (end - ptr) / itemSize;
|
||||||
|
|
||||||
|
return nItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FdInStream::checkReadable(int fd, int timeout)
|
||||||
|
{
|
||||||
|
while (true) {
|
||||||
|
fd_set rfds;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
tv.tv_sec = timeout / 1000;
|
||||||
|
tv.tv_usec = (timeout % 1000) * 1000;
|
||||||
|
|
||||||
|
FD_ZERO(&rfds);
|
||||||
|
FD_SET(fd, &rfds);
|
||||||
|
int n = select(fd+1, &rfds, 0, 0, &tv);
|
||||||
|
if (n != -1 || errno != EINTR)
|
||||||
|
return n;
|
||||||
|
fprintf(stderr,"select returned EINTR\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
static void gettimeofday(struct timeval* tv, void*)
|
||||||
|
{
|
||||||
|
LARGE_INTEGER counts, countsPerSec;
|
||||||
|
static double usecPerCount = 0.0;
|
||||||
|
|
||||||
|
if (QueryPerformanceCounter(&counts)) {
|
||||||
|
if (usecPerCount == 0.0) {
|
||||||
|
QueryPerformanceFrequency(&countsPerSec);
|
||||||
|
usecPerCount = 1000000.0 / countsPerSec.QuadPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
LONGLONG usecs = (LONGLONG)(counts.QuadPart * usecPerCount);
|
||||||
|
tv->tv_usec = (long)(usecs % 1000000);
|
||||||
|
tv->tv_sec = (long)(usecs / 1000000);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
struct timeb tb;
|
||||||
|
ftime(&tb);
|
||||||
|
tv->tv_sec = tb.time;
|
||||||
|
tv->tv_usec = tb.millitm * 1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int FdInStream::readWithTimeoutOrCallback(void* buf, int len)
|
||||||
|
{
|
||||||
|
struct timeval before, after;
|
||||||
|
if (timing)
|
||||||
|
gettimeofday(&before, 0);
|
||||||
|
|
||||||
|
int n = checkReadable(fd, timeout);
|
||||||
|
|
||||||
|
if (n < 0) throw SystemException("select",errno);
|
||||||
|
|
||||||
|
if (n == 0) {
|
||||||
|
if (timeout) throw TimedOut();
|
||||||
|
if (blockCallback) (*blockCallback)(blockCallbackArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
n = ::read(fd, buf, len);
|
||||||
|
if (n != -1 || errno != EINTR)
|
||||||
|
break;
|
||||||
|
fprintf(stderr,"read returned EINTR\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n < 0) throw SystemException("read",errno);
|
||||||
|
if (n == 0) throw EndOfStream();
|
||||||
|
|
||||||
|
if (timing) {
|
||||||
|
gettimeofday(&after, 0);
|
||||||
|
// fprintf(stderr,"%d.%06d\n",(after.tv_sec - before.tv_sec),
|
||||||
|
// (after.tv_usec - before.tv_usec));
|
||||||
|
int newTimeWaited = ((after.tv_sec - before.tv_sec) * 10000 +
|
||||||
|
(after.tv_usec - before.tv_usec) / 100);
|
||||||
|
int newKbits = n * 8 / 1000;
|
||||||
|
|
||||||
|
// if (newTimeWaited == 0) {
|
||||||
|
// fprintf(stderr,"new kbps infinite t %d k %d\n",
|
||||||
|
// newTimeWaited, newKbits);
|
||||||
|
// } else {
|
||||||
|
// fprintf(stderr,"new kbps %d t %d k %d\n",
|
||||||
|
// newKbits * 10000 / newTimeWaited, newTimeWaited, newKbits);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// limit rate to between 10kbit/s and 40Mbit/s
|
||||||
|
|
||||||
|
if (newTimeWaited > newKbits*1000) newTimeWaited = newKbits*1000;
|
||||||
|
if (newTimeWaited < newKbits/4) newTimeWaited = newKbits/4;
|
||||||
|
|
||||||
|
timeWaitedIn100us += newTimeWaited;
|
||||||
|
timedKbits += newKbits;
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FdInStream::startTiming()
|
||||||
|
{
|
||||||
|
timing = true;
|
||||||
|
|
||||||
|
// Carry over up to 1s worth of previous rate for smoothing.
|
||||||
|
|
||||||
|
if (timeWaitedIn100us > 10000) {
|
||||||
|
timedKbits = timedKbits * 10000 / timeWaitedIn100us;
|
||||||
|
timeWaitedIn100us = 10000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FdInStream::stopTiming()
|
||||||
|
{
|
||||||
|
timing = false;
|
||||||
|
if (timeWaitedIn100us < timedKbits/2)
|
||||||
|
timeWaitedIn100us = timedKbits/2; // upper limit 20Mbit/s
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int FdInStream::kbitsPerSecond()
|
||||||
|
{
|
||||||
|
// The following calculation will overflow 32-bit arithmetic if we have
|
||||||
|
// received more than about 50Mbytes (400Mbits) since we started timing, so
|
||||||
|
// it should be OK for a single RFB update.
|
||||||
|
|
||||||
|
return timedKbits * 10000 / timeWaitedIn100us;
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
//
|
||||||
|
// FdInStream streams from a file descriptor.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __RDR_FDINSTREAM_H__
|
||||||
|
#define __RDR_FDINSTREAM_H__
|
||||||
|
|
||||||
|
#include <rdr/InStream.h>
|
||||||
|
|
||||||
|
namespace rdr {
|
||||||
|
|
||||||
|
class FdInStream : public InStream {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
FdInStream(int fd, int timeout=0, int bufSize=0);
|
||||||
|
FdInStream(int fd, void (*blockCallback)(void*), void* blockCallbackArg=0,
|
||||||
|
int bufSize=0);
|
||||||
|
virtual ~FdInStream();
|
||||||
|
|
||||||
|
int getFd() { return fd; }
|
||||||
|
int pos();
|
||||||
|
void readBytes(void* data, int length);
|
||||||
|
int bytesInBuf() { return end - ptr; }
|
||||||
|
|
||||||
|
void startTiming();
|
||||||
|
void stopTiming();
|
||||||
|
unsigned int kbitsPerSecond();
|
||||||
|
unsigned int timeWaited() { return timeWaitedIn100us; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int overrun(int itemSize, int nItems);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int checkReadable(int fd, int timeout);
|
||||||
|
int readWithTimeoutOrCallback(void* buf, int len);
|
||||||
|
|
||||||
|
int fd;
|
||||||
|
int timeout;
|
||||||
|
void (*blockCallback)(void*);
|
||||||
|
void* blockCallbackArg;
|
||||||
|
|
||||||
|
bool timing;
|
||||||
|
unsigned int timeWaitedIn100us;
|
||||||
|
unsigned int timedKbits;
|
||||||
|
|
||||||
|
int bufSize;
|
||||||
|
int offset;
|
||||||
|
U8* start;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end of namespace rdr
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,113 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <winsock.h>
|
||||||
|
#define write(s,b,l) send(s,(const char*)b,l,0)
|
||||||
|
#undef errno
|
||||||
|
#define errno WSAGetLastError()
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <rdr/FdOutStream.h>
|
||||||
|
#include <rdr/Exception.h>
|
||||||
|
|
||||||
|
|
||||||
|
using namespace rdr;
|
||||||
|
|
||||||
|
enum { DEFAULT_BUF_SIZE = 16384,
|
||||||
|
MIN_BULK_SIZE = 1024 };
|
||||||
|
|
||||||
|
FdOutStream::FdOutStream(int fd_, int bufSize_)
|
||||||
|
: fd(fd_), bufSize(bufSize_ ? bufSize_ : DEFAULT_BUF_SIZE), offset(0)
|
||||||
|
{
|
||||||
|
ptr = start = new U8[bufSize];
|
||||||
|
end = start + bufSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
FdOutStream::~FdOutStream()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
flush();
|
||||||
|
} catch (Exception&) {
|
||||||
|
}
|
||||||
|
delete [] start;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FdOutStream::writeBytes(const void* data, int length)
|
||||||
|
{
|
||||||
|
if (length < MIN_BULK_SIZE) {
|
||||||
|
OutStream::writeBytes(data, length);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const U8* dataPtr = (const U8*)data;
|
||||||
|
|
||||||
|
flush();
|
||||||
|
|
||||||
|
while (length > 0) {
|
||||||
|
int n = write(fd, dataPtr, length);
|
||||||
|
|
||||||
|
if (n < 0) throw SystemException("write",errno);
|
||||||
|
|
||||||
|
length -= n;
|
||||||
|
dataPtr += n;
|
||||||
|
offset += n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int FdOutStream::length()
|
||||||
|
{
|
||||||
|
return offset + ptr - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FdOutStream::flush()
|
||||||
|
{
|
||||||
|
U8* sentUpTo = start;
|
||||||
|
while (sentUpTo < ptr) {
|
||||||
|
int n = write(fd, (const void*) sentUpTo, ptr - sentUpTo);
|
||||||
|
|
||||||
|
if (n < 0) throw SystemException("write",errno);
|
||||||
|
|
||||||
|
sentUpTo += n;
|
||||||
|
offset += n;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr = start;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int FdOutStream::overrun(int itemSize, int nItems)
|
||||||
|
{
|
||||||
|
if (itemSize > bufSize)
|
||||||
|
throw Exception("FdOutStream overrun: max itemSize exceeded");
|
||||||
|
|
||||||
|
flush();
|
||||||
|
|
||||||
|
if (itemSize * nItems > end - ptr)
|
||||||
|
nItems = (end - ptr) / itemSize;
|
||||||
|
|
||||||
|
return nItems;
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
//
|
||||||
|
// FdOutStream streams to a file descriptor.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __RDR_FDOUTSTREAM_H__
|
||||||
|
#define __RDR_FDOUTSTREAM_H__
|
||||||
|
|
||||||
|
#include <rdr/OutStream.h>
|
||||||
|
|
||||||
|
namespace rdr {
|
||||||
|
|
||||||
|
class FdOutStream : public OutStream {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
FdOutStream(int fd, int bufSize=0);
|
||||||
|
virtual ~FdOutStream();
|
||||||
|
|
||||||
|
int getFd() { return fd; }
|
||||||
|
|
||||||
|
void flush();
|
||||||
|
int length();
|
||||||
|
void writeBytes(const void* data, int length);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int overrun(int itemSize, int nItems);
|
||||||
|
int fd;
|
||||||
|
int bufSize;
|
||||||
|
int offset;
|
||||||
|
U8* start;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,52 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
//
|
||||||
|
// A FixedMemOutStream writes to a buffer of a fixed length.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __RDR_FIXEDMEMOUTSTREAM_H__
|
||||||
|
#define __RDR_FIXEDMEMOUTSTREAM_H__
|
||||||
|
|
||||||
|
#include <rdr/OutStream.h>
|
||||||
|
#include <rdr/Exception.h>
|
||||||
|
|
||||||
|
namespace rdr {
|
||||||
|
|
||||||
|
class FixedMemOutStream : public OutStream {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
FixedMemOutStream(void* buf, int len) {
|
||||||
|
ptr = start = (U8*)buf;
|
||||||
|
end = start + len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int length() { return ptr - start; }
|
||||||
|
void reposition(int pos) { ptr = start + pos; }
|
||||||
|
const void* data() { return (const void*)start; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int overrun(int itemSize, int nItems) { throw EndOfStream(); }
|
||||||
|
U8* start;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,35 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
#include <rdr/InStream.h>
|
||||||
|
#include <rdr/Exception.h>
|
||||||
|
|
||||||
|
using namespace rdr;
|
||||||
|
|
||||||
|
U32 InStream::maxStringLength = 65535;
|
||||||
|
|
||||||
|
char* InStream::readString()
|
||||||
|
{
|
||||||
|
U32 len = readU32();
|
||||||
|
if (len > maxStringLength)
|
||||||
|
throw Exception("InStream max string length exceeded");
|
||||||
|
char* str = new char[len+1];
|
||||||
|
readBytes(str, len);
|
||||||
|
str[len] = 0;
|
||||||
|
return str;
|
||||||
|
}
|
|
@ -0,0 +1,143 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
//
|
||||||
|
// rdr::InStream marshalls data from a buffer stored in RDR (RFB Data
|
||||||
|
// Representation).
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __RDR_INSTREAM_H__
|
||||||
|
#define __RDR_INSTREAM_H__
|
||||||
|
|
||||||
|
#include <rdr/types.h>
|
||||||
|
#include <string.h> // for memcpy
|
||||||
|
|
||||||
|
namespace rdr {
|
||||||
|
|
||||||
|
class InStream {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual ~InStream() {}
|
||||||
|
|
||||||
|
// check() ensures there is buffer data for at least one item of size
|
||||||
|
// itemSize bytes. Returns the number of items in the buffer (up to a
|
||||||
|
// maximum of nItems).
|
||||||
|
|
||||||
|
inline int check(int itemSize, int nItems=1)
|
||||||
|
{
|
||||||
|
if (ptr + itemSize * nItems > end) {
|
||||||
|
if (ptr + itemSize > end)
|
||||||
|
return overrun(itemSize, nItems);
|
||||||
|
|
||||||
|
nItems = (end - ptr) / itemSize;
|
||||||
|
}
|
||||||
|
return nItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
// readU/SN() methods read unsigned and signed N-bit integers.
|
||||||
|
|
||||||
|
inline U8 readU8() { check(1); return *ptr++; }
|
||||||
|
inline U16 readU16() { check(2); int b0 = *ptr++; int b1 = *ptr++;
|
||||||
|
return b0 << 8 | b1; }
|
||||||
|
inline U32 readU32() { check(4); int b0 = *ptr++; int b1 = *ptr++;
|
||||||
|
int b2 = *ptr++; int b3 = *ptr++;
|
||||||
|
return b0 << 24 | b1 << 16 | b2 << 8 | b3; }
|
||||||
|
|
||||||
|
inline S8 readS8() { return (S8) readU8(); }
|
||||||
|
inline S16 readS16() { return (S16)readU16(); }
|
||||||
|
inline S32 readS32() { return (S32)readU32(); }
|
||||||
|
|
||||||
|
// readString() reads a string - a U32 length followed by the data.
|
||||||
|
// Returns a null-terminated string - the caller should delete[] it
|
||||||
|
// afterwards.
|
||||||
|
|
||||||
|
char* readString();
|
||||||
|
|
||||||
|
// maxStringLength protects against allocating a huge buffer. Set it
|
||||||
|
// higher if you need longer strings.
|
||||||
|
|
||||||
|
static U32 maxStringLength;
|
||||||
|
|
||||||
|
inline void skip(int bytes) {
|
||||||
|
while (bytes > 0) {
|
||||||
|
int n = check(1, bytes);
|
||||||
|
ptr += n;
|
||||||
|
bytes -= n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// readBytes() reads an exact number of bytes.
|
||||||
|
|
||||||
|
virtual void readBytes(void* data, int length) {
|
||||||
|
U8* dataPtr = (U8*)data;
|
||||||
|
U8* dataEnd = dataPtr + length;
|
||||||
|
while (dataPtr < dataEnd) {
|
||||||
|
int n = check(1, dataEnd - dataPtr);
|
||||||
|
memcpy(dataPtr, ptr, n);
|
||||||
|
ptr += n;
|
||||||
|
dataPtr += n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// readOpaqueN() reads a quantity without byte-swapping.
|
||||||
|
|
||||||
|
inline U8 readOpaque8() { return readU8(); }
|
||||||
|
inline U16 readOpaque16() { check(2); U16 r; ((U8*)&r)[0] = *ptr++;
|
||||||
|
((U8*)&r)[1] = *ptr++; return r; }
|
||||||
|
inline U32 readOpaque32() { check(4); U32 r; ((U8*)&r)[0] = *ptr++;
|
||||||
|
((U8*)&r)[1] = *ptr++; ((U8*)&r)[2] = *ptr++;
|
||||||
|
((U8*)&r)[3] = *ptr++; return r; }
|
||||||
|
inline U32 readOpaque24A() { check(3); U32 r=0; ((U8*)&r)[0] = *ptr++;
|
||||||
|
((U8*)&r)[1] = *ptr++; ((U8*)&r)[2] = *ptr++;
|
||||||
|
return r; }
|
||||||
|
inline U32 readOpaque24B() { check(3); U32 r=0; ((U8*)&r)[1] = *ptr++;
|
||||||
|
((U8*)&r)[2] = *ptr++; ((U8*)&r)[3] = *ptr++;
|
||||||
|
return r; }
|
||||||
|
|
||||||
|
// pos() returns the position in the stream.
|
||||||
|
|
||||||
|
virtual int pos() = 0;
|
||||||
|
|
||||||
|
// getptr(), getend() and setptr() are "dirty" methods which allow you to
|
||||||
|
// manipulate the buffer directly. This is useful for a stream which is a
|
||||||
|
// wrapper around an underlying stream.
|
||||||
|
|
||||||
|
inline const U8* getptr() const { return ptr; }
|
||||||
|
inline const U8* getend() const { return end; }
|
||||||
|
inline void setptr(const U8* p) { ptr = p; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// overrun() is implemented by a derived class to cope with buffer overrun.
|
||||||
|
// It ensures there are at least itemSize bytes of buffer data. Returns
|
||||||
|
// the number of items in the buffer (up to a maximum of nItems). itemSize
|
||||||
|
// is supposed to be "small" (a few bytes).
|
||||||
|
|
||||||
|
virtual int overrun(int itemSize, int nItems) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
InStream() {}
|
||||||
|
const U8* ptr;
|
||||||
|
const U8* end;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,18 @@
|
||||||
|
|
||||||
|
SRCS = FdInStream.cxx FdOutStream.cxx InStream.cxx NullOutStream.cxx \
|
||||||
|
ZlibInStream.cxx ZlibOutStream.cxx
|
||||||
|
|
||||||
|
OBJS = $(SRCS:.cxx=.o)
|
||||||
|
|
||||||
|
DIR_CPPFLAGS = -I$(top_srcdir) @ZLIB_INCLUDE@
|
||||||
|
|
||||||
|
library = librdr.a
|
||||||
|
|
||||||
|
all:: $(library)
|
||||||
|
|
||||||
|
$(library): $(OBJS)
|
||||||
|
rm -f $(library)
|
||||||
|
$(AR) $(library) $(OBJS)
|
||||||
|
$(RANLIB) $(library)
|
||||||
|
|
||||||
|
# followed by boilerplate.mk
|
|
@ -0,0 +1,47 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
#ifndef __RDR_MEMINSTREAM_H__
|
||||||
|
#define __RDR_MEMINSTREAM_H__
|
||||||
|
|
||||||
|
#include <rdr/InStream.h>
|
||||||
|
#include <rdr/Exception.h>
|
||||||
|
|
||||||
|
namespace rdr {
|
||||||
|
|
||||||
|
class MemInStream : public InStream {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
MemInStream(const void* data, int len) {
|
||||||
|
ptr = start = (const U8*)data;
|
||||||
|
end = start + len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos() { return ptr - start; }
|
||||||
|
void reposition(int pos) { ptr = start + pos; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int overrun(int itemSize, int nItems) { throw EndOfStream(); }
|
||||||
|
const U8* start;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,82 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
//
|
||||||
|
// A MemOutStream grows as needed when data is written to it.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __RDR_MEMOUTSTREAM_H__
|
||||||
|
#define __RDR_MEMOUTSTREAM_H__
|
||||||
|
|
||||||
|
#include <rdr/OutStream.h>
|
||||||
|
|
||||||
|
namespace rdr {
|
||||||
|
|
||||||
|
class MemOutStream : public OutStream {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
MemOutStream(int len=1024) {
|
||||||
|
start = ptr = new U8[len];
|
||||||
|
end = start + len;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~MemOutStream() {
|
||||||
|
delete [] start;
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeBytes(const void* data, int length) {
|
||||||
|
check(length);
|
||||||
|
memcpy(ptr, data, length);
|
||||||
|
ptr += length;
|
||||||
|
}
|
||||||
|
|
||||||
|
int length() { return ptr - start; }
|
||||||
|
void clear() { ptr = start; };
|
||||||
|
void reposition(int pos) { ptr = start + pos; }
|
||||||
|
|
||||||
|
// data() returns a pointer to the buffer.
|
||||||
|
|
||||||
|
const void* data() { return (const void*)start; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// overrun() either doubles the buffer or adds enough space for nItems of
|
||||||
|
// size itemSize bytes.
|
||||||
|
|
||||||
|
int overrun(int itemSize, int nItems) {
|
||||||
|
int len = ptr - start + itemSize * nItems;
|
||||||
|
if (len < (end - start) * 2)
|
||||||
|
len = (end - start) * 2;
|
||||||
|
|
||||||
|
U8* newStart = new U8[len];
|
||||||
|
memcpy(newStart, start, ptr - start);
|
||||||
|
ptr = newStart + (ptr - start);
|
||||||
|
delete [] start;
|
||||||
|
start = newStart;
|
||||||
|
end = newStart + len;
|
||||||
|
|
||||||
|
return nItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
U8* start;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,60 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
#include <rdr/NullOutStream.h>
|
||||||
|
#include <rdr/Exception.h>
|
||||||
|
|
||||||
|
using namespace rdr;
|
||||||
|
|
||||||
|
static const int bufferSize = 1024;
|
||||||
|
|
||||||
|
NullOutStream::NullOutStream()
|
||||||
|
: offset(0)
|
||||||
|
{
|
||||||
|
start = ptr = new U8[bufferSize];
|
||||||
|
end = start + bufferSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
NullOutStream::~NullOutStream()
|
||||||
|
{
|
||||||
|
delete [] start;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NullOutStream::length()
|
||||||
|
{
|
||||||
|
return offset + ptr - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NullOutStream::writeBytes(const void* data, int length)
|
||||||
|
{
|
||||||
|
offset += length;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NullOutStream::overrun(int itemSize, int nItems)
|
||||||
|
{
|
||||||
|
if (itemSize > bufferSize)
|
||||||
|
throw Exception("NullOutStream overrun: max itemSize exceeded");
|
||||||
|
|
||||||
|
offset += ptr - start;
|
||||||
|
ptr = start;
|
||||||
|
|
||||||
|
if (itemSize * nItems > end - ptr)
|
||||||
|
nItems = (end - ptr) / itemSize;
|
||||||
|
|
||||||
|
return nItems;
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
#ifndef __RDR_NULLOUTSTREAM_H__
|
||||||
|
#define __RDR_NULLOUTSTREAM_H__
|
||||||
|
|
||||||
|
#include <rdr/OutStream.h>
|
||||||
|
|
||||||
|
namespace rdr {
|
||||||
|
|
||||||
|
class NullOutStream : public OutStream {
|
||||||
|
|
||||||
|
public:
|
||||||
|
NullOutStream();
|
||||||
|
virtual ~NullOutStream();
|
||||||
|
int length();
|
||||||
|
void writeBytes(const void* data, int length);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int overrun(int itemSize, int nItems);
|
||||||
|
int offset;
|
||||||
|
U8* start;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,152 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
//
|
||||||
|
// rdr::OutStream marshalls data into a buffer stored in RDR (RFB Data
|
||||||
|
// Representation).
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __RDR_OUTSTREAM_H__
|
||||||
|
#define __RDR_OUTSTREAM_H__
|
||||||
|
|
||||||
|
#include <rdr/types.h>
|
||||||
|
#include <string.h> // for memcpy
|
||||||
|
|
||||||
|
namespace rdr {
|
||||||
|
|
||||||
|
class OutStream {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
OutStream() {}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual ~OutStream() {}
|
||||||
|
|
||||||
|
// check() ensures there is buffer space for at least one item of size
|
||||||
|
// itemSize bytes. Returns the number of items which fit (up to a maximum
|
||||||
|
// of nItems).
|
||||||
|
|
||||||
|
inline int check(int itemSize, int nItems=1)
|
||||||
|
{
|
||||||
|
if (ptr + itemSize * nItems > end) {
|
||||||
|
if (ptr + itemSize > end)
|
||||||
|
return overrun(itemSize, nItems);
|
||||||
|
|
||||||
|
nItems = (end - ptr) / itemSize;
|
||||||
|
}
|
||||||
|
return nItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
// writeU/SN() methods write unsigned and signed N-bit integers.
|
||||||
|
|
||||||
|
inline void writeU8( U8 u) { check(1); *ptr++ = u; }
|
||||||
|
inline void writeU16(U16 u) { check(2); *ptr++ = u >> 8; *ptr++ = (U8)u; }
|
||||||
|
inline void writeU32(U32 u) { check(4); *ptr++ = u >> 24; *ptr++ = u >> 16;
|
||||||
|
*ptr++ = u >> 8; *ptr++ = u; }
|
||||||
|
|
||||||
|
inline void writeS8( S8 s) { writeU8((U8)s); }
|
||||||
|
inline void writeS16(S16 s) { writeU16((U16)s); }
|
||||||
|
inline void writeS32(S32 s) { writeU32((U32)s); }
|
||||||
|
|
||||||
|
// writeString() writes a string - a U32 length followed by the data. The
|
||||||
|
// given string should be null-terminated (but the terminating null is not
|
||||||
|
// written to the stream).
|
||||||
|
|
||||||
|
inline void writeString(const char* str) {
|
||||||
|
U32 len = strlen(str);
|
||||||
|
writeU32(len);
|
||||||
|
writeBytes(str, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void pad(int bytes) {
|
||||||
|
while (bytes-- > 0) writeU8(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void skip(int bytes) {
|
||||||
|
while (bytes > 0) {
|
||||||
|
int n = check(1, bytes);
|
||||||
|
ptr += n;
|
||||||
|
bytes -= n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// writeBytes() writes an exact number of bytes.
|
||||||
|
|
||||||
|
virtual void writeBytes(const void* data, int length) {
|
||||||
|
const U8* dataPtr = (const U8*)data;
|
||||||
|
const U8* dataEnd = dataPtr + length;
|
||||||
|
while (dataPtr < dataEnd) {
|
||||||
|
int n = check(1, dataEnd - dataPtr);
|
||||||
|
memcpy(ptr, dataPtr, n);
|
||||||
|
ptr += n;
|
||||||
|
dataPtr += n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// writeOpaqueN() writes a quantity without byte-swapping.
|
||||||
|
|
||||||
|
inline void writeOpaque8( U8 u) { writeU8(u); }
|
||||||
|
inline void writeOpaque16(U16 u) { check(2); *ptr++ = ((U8*)&u)[0];
|
||||||
|
*ptr++ = ((U8*)&u)[1]; }
|
||||||
|
inline void writeOpaque32(U32 u) { check(4); *ptr++ = ((U8*)&u)[0];
|
||||||
|
*ptr++ = ((U8*)&u)[1];
|
||||||
|
*ptr++ = ((U8*)&u)[2];
|
||||||
|
*ptr++ = ((U8*)&u)[3]; }
|
||||||
|
inline void writeOpaque24A(U32 u) { check(3); *ptr++ = ((U8*)&u)[0];
|
||||||
|
*ptr++ = ((U8*)&u)[1];
|
||||||
|
*ptr++ = ((U8*)&u)[2]; }
|
||||||
|
inline void writeOpaque24B(U32 u) { check(3); *ptr++ = ((U8*)&u)[1];
|
||||||
|
*ptr++ = ((U8*)&u)[2];
|
||||||
|
*ptr++ = ((U8*)&u)[3]; }
|
||||||
|
|
||||||
|
// length() returns the length of the stream.
|
||||||
|
|
||||||
|
virtual int length() = 0;
|
||||||
|
|
||||||
|
// flush() requests that the stream be flushed.
|
||||||
|
|
||||||
|
virtual void flush() {}
|
||||||
|
|
||||||
|
// getptr(), getend() and setptr() are "dirty" methods which allow you to
|
||||||
|
// manipulate the buffer directly. This is useful for a stream which is a
|
||||||
|
// wrapper around an underlying stream.
|
||||||
|
|
||||||
|
inline U8* getptr() { return ptr; }
|
||||||
|
inline U8* getend() { return end; }
|
||||||
|
inline void setptr(U8* p) { ptr = p; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// overrun() is implemented by a derived class to cope with buffer overrun.
|
||||||
|
// It ensures there are at least itemSize bytes of buffer space. Returns
|
||||||
|
// the number of items which fit (up to a maximum of nItems). itemSize is
|
||||||
|
// supposed to be "small" (a few bytes).
|
||||||
|
|
||||||
|
virtual int overrun(int itemSize, int nItems) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
U8* ptr;
|
||||||
|
U8* end;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,121 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
#include <rdr/ZlibInStream.h>
|
||||||
|
#include <rdr/Exception.h>
|
||||||
|
#include <zlib.h>
|
||||||
|
|
||||||
|
using namespace rdr;
|
||||||
|
|
||||||
|
enum { DEFAULT_BUF_SIZE = 16384 };
|
||||||
|
|
||||||
|
ZlibInStream::ZlibInStream(int bufSize_)
|
||||||
|
: underlying(0), bufSize(bufSize_ ? bufSize_ : DEFAULT_BUF_SIZE), offset(0),
|
||||||
|
bytesIn(0)
|
||||||
|
{
|
||||||
|
zs = new z_stream;
|
||||||
|
zs->zalloc = Z_NULL;
|
||||||
|
zs->zfree = Z_NULL;
|
||||||
|
zs->opaque = Z_NULL;
|
||||||
|
zs->next_in = Z_NULL;
|
||||||
|
zs->avail_in = 0;
|
||||||
|
if (inflateInit(zs) != Z_OK) {
|
||||||
|
delete zs;
|
||||||
|
throw Exception("ZlibInStream: inflateInit failed");
|
||||||
|
}
|
||||||
|
ptr = end = start = new U8[bufSize];
|
||||||
|
}
|
||||||
|
|
||||||
|
ZlibInStream::~ZlibInStream()
|
||||||
|
{
|
||||||
|
delete [] start;
|
||||||
|
inflateEnd(zs);
|
||||||
|
delete zs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZlibInStream::setUnderlying(InStream* is, int bytesIn_)
|
||||||
|
{
|
||||||
|
underlying = is;
|
||||||
|
bytesIn = bytesIn_;
|
||||||
|
ptr = end = start;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ZlibInStream::pos()
|
||||||
|
{
|
||||||
|
return offset + ptr - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZlibInStream::reset()
|
||||||
|
{
|
||||||
|
ptr = end = start;
|
||||||
|
if (!underlying) return;
|
||||||
|
|
||||||
|
while (bytesIn > 0) {
|
||||||
|
decompress();
|
||||||
|
end = start; // throw away any data
|
||||||
|
}
|
||||||
|
underlying = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ZlibInStream::overrun(int itemSize, int nItems)
|
||||||
|
{
|
||||||
|
if (itemSize > bufSize)
|
||||||
|
throw Exception("ZlibInStream overrun: max itemSize exceeded");
|
||||||
|
if (!underlying)
|
||||||
|
throw Exception("ZlibInStream overrun: no underlying stream");
|
||||||
|
|
||||||
|
if (end - ptr != 0)
|
||||||
|
memmove(start, ptr, end - ptr);
|
||||||
|
|
||||||
|
offset += ptr - start;
|
||||||
|
end -= ptr - start;
|
||||||
|
ptr = start;
|
||||||
|
|
||||||
|
while (end - ptr < itemSize) {
|
||||||
|
decompress();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemSize * nItems > end - ptr)
|
||||||
|
nItems = (end - ptr) / itemSize;
|
||||||
|
|
||||||
|
return nItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
// decompress() calls the decompressor once. Note that this won't necessarily
|
||||||
|
// generate any output data - it may just consume some input data.
|
||||||
|
|
||||||
|
void ZlibInStream::decompress()
|
||||||
|
{
|
||||||
|
zs->next_out = (U8*)end;
|
||||||
|
zs->avail_out = start + bufSize - end;
|
||||||
|
|
||||||
|
underlying->check(1);
|
||||||
|
zs->next_in = (U8*)underlying->getptr();
|
||||||
|
zs->avail_in = underlying->getend() - underlying->getptr();
|
||||||
|
if ((int)zs->avail_in > bytesIn)
|
||||||
|
zs->avail_in = bytesIn;
|
||||||
|
|
||||||
|
int rc = inflate(zs, Z_SYNC_FLUSH);
|
||||||
|
if (rc != Z_OK) {
|
||||||
|
throw Exception("ZlibInStream: inflate failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
bytesIn -= zs->next_in - underlying->getptr();
|
||||||
|
end = zs->next_out;
|
||||||
|
underlying->setptr(zs->next_in);
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
//
|
||||||
|
// ZlibInStream streams from a compressed data stream ("underlying"),
|
||||||
|
// decompressing with zlib on the fly.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __RDR_ZLIBINSTREAM_H__
|
||||||
|
#define __RDR_ZLIBINSTREAM_H__
|
||||||
|
|
||||||
|
#include <rdr/InStream.h>
|
||||||
|
|
||||||
|
struct z_stream_s;
|
||||||
|
|
||||||
|
namespace rdr {
|
||||||
|
|
||||||
|
class ZlibInStream : public InStream {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ZlibInStream(int bufSize=0);
|
||||||
|
virtual ~ZlibInStream();
|
||||||
|
|
||||||
|
void setUnderlying(InStream* is, int bytesIn);
|
||||||
|
void reset();
|
||||||
|
int pos();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int overrun(int itemSize, int nItems);
|
||||||
|
void decompress();
|
||||||
|
|
||||||
|
InStream* underlying;
|
||||||
|
int bufSize;
|
||||||
|
int offset;
|
||||||
|
z_stream_s* zs;
|
||||||
|
int bytesIn;
|
||||||
|
U8* start;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end of namespace rdr
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,140 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
#include <rdr/ZlibOutStream.h>
|
||||||
|
#include <rdr/Exception.h>
|
||||||
|
#include <zlib.h>
|
||||||
|
|
||||||
|
using namespace rdr;
|
||||||
|
|
||||||
|
enum { DEFAULT_BUF_SIZE = 16384 };
|
||||||
|
|
||||||
|
ZlibOutStream::ZlibOutStream(OutStream* os, int bufSize_)
|
||||||
|
: underlying(os), bufSize(bufSize_ ? bufSize_ : DEFAULT_BUF_SIZE), offset(0)
|
||||||
|
{
|
||||||
|
zs = new z_stream;
|
||||||
|
zs->zalloc = Z_NULL;
|
||||||
|
zs->zfree = Z_NULL;
|
||||||
|
zs->opaque = Z_NULL;
|
||||||
|
if (deflateInit(zs, Z_DEFAULT_COMPRESSION) != Z_OK) {
|
||||||
|
delete zs;
|
||||||
|
throw Exception("ZlibOutStream: deflateInit failed");
|
||||||
|
}
|
||||||
|
ptr = start = new U8[bufSize];
|
||||||
|
end = start + bufSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZlibOutStream::~ZlibOutStream()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
flush();
|
||||||
|
} catch (Exception&) {
|
||||||
|
}
|
||||||
|
delete [] start;
|
||||||
|
deflateEnd(zs);
|
||||||
|
delete zs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZlibOutStream::setUnderlying(OutStream* os)
|
||||||
|
{
|
||||||
|
underlying = os;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ZlibOutStream::length()
|
||||||
|
{
|
||||||
|
return offset + ptr - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZlibOutStream::flush()
|
||||||
|
{
|
||||||
|
zs->next_in = start;
|
||||||
|
zs->avail_in = ptr - start;
|
||||||
|
|
||||||
|
// fprintf(stderr,"zos flush: avail_in %d\n",zs->avail_in);
|
||||||
|
|
||||||
|
while (zs->avail_in != 0) {
|
||||||
|
|
||||||
|
do {
|
||||||
|
underlying->check(1);
|
||||||
|
zs->next_out = underlying->getptr();
|
||||||
|
zs->avail_out = underlying->getend() - underlying->getptr();
|
||||||
|
|
||||||
|
// fprintf(stderr,"zos flush: calling deflate, avail_in %d, avail_out %d\n",
|
||||||
|
// zs->avail_in,zs->avail_out);
|
||||||
|
int rc = deflate(zs, Z_SYNC_FLUSH);
|
||||||
|
if (rc != Z_OK) throw Exception("ZlibOutStream: deflate failed");
|
||||||
|
|
||||||
|
// fprintf(stderr,"zos flush: after deflate: %d bytes\n",
|
||||||
|
// zs->next_out-underlying->getptr());
|
||||||
|
|
||||||
|
underlying->setptr(zs->next_out);
|
||||||
|
} while (zs->avail_out == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
offset += ptr - start;
|
||||||
|
ptr = start;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ZlibOutStream::overrun(int itemSize, int nItems)
|
||||||
|
{
|
||||||
|
// fprintf(stderr,"ZlibOutStream overrun\n");
|
||||||
|
|
||||||
|
if (itemSize > bufSize)
|
||||||
|
throw Exception("ZlibOutStream overrun: max itemSize exceeded");
|
||||||
|
|
||||||
|
while (end - ptr < itemSize) {
|
||||||
|
zs->next_in = start;
|
||||||
|
zs->avail_in = ptr - start;
|
||||||
|
|
||||||
|
do {
|
||||||
|
underlying->check(1);
|
||||||
|
zs->next_out = underlying->getptr();
|
||||||
|
zs->avail_out = underlying->getend() - underlying->getptr();
|
||||||
|
|
||||||
|
// fprintf(stderr,"zos overrun: calling deflate, avail_in %d, avail_out %d\n",
|
||||||
|
// zs->avail_in,zs->avail_out);
|
||||||
|
|
||||||
|
int rc = deflate(zs, 0);
|
||||||
|
if (rc != Z_OK) throw Exception("ZlibOutStream: deflate failed");
|
||||||
|
|
||||||
|
// fprintf(stderr,"zos overrun: after deflate: %d bytes\n",
|
||||||
|
// zs->next_out-underlying->getptr());
|
||||||
|
|
||||||
|
underlying->setptr(zs->next_out);
|
||||||
|
} while (zs->avail_out == 0);
|
||||||
|
|
||||||
|
// output buffer not full
|
||||||
|
|
||||||
|
if (zs->avail_in == 0) {
|
||||||
|
offset += ptr - start;
|
||||||
|
ptr = start;
|
||||||
|
} else {
|
||||||
|
// but didn't consume all the data? try shifting what's left to the
|
||||||
|
// start of the buffer.
|
||||||
|
fprintf(stderr,"z out buf not full, but in data not consumed\n");
|
||||||
|
memmove(start, zs->next_in, ptr - zs->next_in);
|
||||||
|
offset += zs->next_in - start;
|
||||||
|
ptr -= zs->next_in - start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemSize * nItems > end - ptr)
|
||||||
|
nItems = (end - ptr) / itemSize;
|
||||||
|
|
||||||
|
return nItems;
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
//
|
||||||
|
// ZlibOutStream streams to a compressed data stream (underlying), compressing
|
||||||
|
// with zlib on the fly.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __RDR_ZLIBOUTSTREAM_H__
|
||||||
|
#define __RDR_ZLIBOUTSTREAM_H__
|
||||||
|
|
||||||
|
#include <rdr/OutStream.h>
|
||||||
|
|
||||||
|
struct z_stream_s;
|
||||||
|
|
||||||
|
namespace rdr {
|
||||||
|
|
||||||
|
class ZlibOutStream : public OutStream {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ZlibOutStream(OutStream* os=0, int bufSize=0);
|
||||||
|
virtual ~ZlibOutStream();
|
||||||
|
|
||||||
|
void setUnderlying(OutStream* os);
|
||||||
|
void flush();
|
||||||
|
int length();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int overrun(int itemSize, int nItems);
|
||||||
|
|
||||||
|
OutStream* underlying;
|
||||||
|
int bufSize;
|
||||||
|
int offset;
|
||||||
|
z_stream_s* zs;
|
||||||
|
U8* start;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end of namespace rdr
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,245 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="rdr" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||||
|
|
||||||
|
CFG=rdr - Win32 Release CORBA DEBUG
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "rdr.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "rdr.mak" CFG="rdr - Win32 Release CORBA DEBUG"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "rdr - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||||
|
!MESSAGE "rdr - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||||
|
!MESSAGE "rdr - Win32 Release CORBA DEBUG" (based on "Win32 (x86) Static Library")
|
||||||
|
!MESSAGE "rdr - Win32 Release CORBA" (based on "Win32 (x86) Static Library")
|
||||||
|
!MESSAGE "rdr - Win32 Profile" (based on "Win32 (x86) Static Library")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "rdr - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LIB32=link.exe -lib
|
||||||
|
# ADD BASE LIB32 /nologo
|
||||||
|
# ADD LIB32 /nologo
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "rdr - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LIB32=link.exe -lib
|
||||||
|
# ADD BASE LIB32 /nologo
|
||||||
|
# ADD LIB32 /nologo
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "rdr - Win32 Release CORBA DEBUG"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "rdr___Win32_Release_CORBA_DEBUG"
|
||||||
|
# PROP BASE Intermediate_Dir "rdr___Win32_Release_CORBA_DEBUG"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "..\Release_CORBA_DEBUG"
|
||||||
|
# PROP Intermediate_Dir "..\Release_CORBA_DEBUG"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LIB32=link.exe -lib
|
||||||
|
# ADD BASE LIB32 /nologo
|
||||||
|
# ADD LIB32 /nologo
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "rdr - Win32 Release CORBA"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "rdr___Win32_Release_CORBA"
|
||||||
|
# PROP BASE Intermediate_Dir "rdr___Win32_Release_CORBA"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "..\Release_CORBA"
|
||||||
|
# PROP Intermediate_Dir "..\Release_CORBA"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LIB32=link.exe -lib
|
||||||
|
# ADD BASE LIB32 /nologo
|
||||||
|
# ADD LIB32 /nologo
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "rdr - Win32 Profile"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "rdr___Win32_Profile"
|
||||||
|
# PROP BASE Intermediate_Dir "rdr___Win32_Profile"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "..\Profile"
|
||||||
|
# PROP Intermediate_Dir "..\Profile"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /MTd /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LIB32=link.exe -lib
|
||||||
|
# ADD BASE LIB32 /nologo
|
||||||
|
# ADD LIB32 /nologo
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "rdr - Win32 Release"
|
||||||
|
# Name "rdr - Win32 Debug"
|
||||||
|
# Name "rdr - Win32 Release CORBA DEBUG"
|
||||||
|
# Name "rdr - Win32 Release CORBA"
|
||||||
|
# Name "rdr - Win32 Profile"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\FdInStream.cxx
|
||||||
|
# ADD CPP /I ".." /I "../zlib"
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\FdOutStream.cxx
|
||||||
|
# ADD CPP /I ".." /I "../zlib"
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\InStream.cxx
|
||||||
|
# ADD CPP /I ".." /I "../zlib"
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\NullOutStream.cxx
|
||||||
|
# ADD CPP /I ".." /I "../zlib"
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\ZlibInStream.cxx
|
||||||
|
# ADD CPP /I ".." /I "../zlib"
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\ZlibOutStream.cxx
|
||||||
|
# ADD CPP /I ".." /I "../zlib"
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\Exception.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\FdInStream.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\FdOutStream.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\FixedMemOutStream.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\InStream.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\MemInStream.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\MemOutStream.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\NullOutStream.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\OutStream.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\types.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\ZlibInStream.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\ZlibOutStream.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,245 @@
|
||||||
|
<?xml version="1.0" encoding="Windows-1252"?>
|
||||||
|
<VisualStudioProject
|
||||||
|
ProjectType="Visual C++"
|
||||||
|
Version="9.00"
|
||||||
|
Name="rdr"
|
||||||
|
ProjectGUID="{F2473D0A-3E49-4127-9FF6-51D53C45590A}"
|
||||||
|
TargetFrameworkVersion="131072"
|
||||||
|
>
|
||||||
|
<Platforms>
|
||||||
|
<Platform
|
||||||
|
Name="Win32"
|
||||||
|
/>
|
||||||
|
</Platforms>
|
||||||
|
<ToolFiles>
|
||||||
|
</ToolFiles>
|
||||||
|
<Configurations>
|
||||||
|
<Configuration
|
||||||
|
Name="Release|Win32"
|
||||||
|
OutputDirectory=".\Release"
|
||||||
|
IntermediateDirectory=".\Release"
|
||||||
|
ConfigurationType="4"
|
||||||
|
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||||
|
UseOfMFC="0"
|
||||||
|
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||||
|
CharacterSet="2"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
InlineFunctionExpansion="1"
|
||||||
|
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
||||||
|
StringPooling="true"
|
||||||
|
RuntimeLibrary="0"
|
||||||
|
EnableFunctionLevelLinking="true"
|
||||||
|
UsePrecompiledHeader="0"
|
||||||
|
PrecompiledHeaderFile=".\Release/rdr.pch"
|
||||||
|
AssemblerListingLocation=".\Release/"
|
||||||
|
ObjectFile=".\Release/"
|
||||||
|
ProgramDataBaseFileName=".\Release/"
|
||||||
|
WarningLevel="3"
|
||||||
|
SuppressStartupBanner="true"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedResourceCompilerTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
PreprocessorDefinitions="NDEBUG"
|
||||||
|
Culture="2057"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLibrarianTool"
|
||||||
|
OutputFile=".\Release\rdr.lib"
|
||||||
|
SuppressStartupBanner="true"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCALinkTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXDCMakeTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCBscMakeTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCFxCopTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"
|
||||||
|
/>
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
<References>
|
||||||
|
</References>
|
||||||
|
<Files>
|
||||||
|
<Filter
|
||||||
|
Name="Source Files"
|
||||||
|
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="FdInStream.cxx"
|
||||||
|
>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
AdditionalIncludeDirectories="..,../zlib"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
CompileAs="0"
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="FdOutStream.cxx"
|
||||||
|
>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
AdditionalIncludeDirectories="..,../zlib"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
CompileAs="0"
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="InStream.cxx"
|
||||||
|
>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
AdditionalIncludeDirectories="..,../zlib"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
CompileAs="0"
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="NullOutStream.cxx"
|
||||||
|
>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
AdditionalIncludeDirectories="..,../zlib"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
CompileAs="0"
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="ZlibInStream.cxx"
|
||||||
|
>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
AdditionalIncludeDirectories="..,../zlib"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
CompileAs="0"
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="ZlibOutStream.cxx"
|
||||||
|
>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
AdditionalIncludeDirectories="..,../zlib"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
CompileAs="0"
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Header Files"
|
||||||
|
Filter="h;hpp;hxx;hm;inl"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="Exception.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="FdInStream.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="FdOutStream.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="FixedMemOutStream.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="InStream.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="MemInStream.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="MemOutStream.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="NullOutStream.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="OutStream.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="types.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="ZlibInStream.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="ZlibOutStream.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
</Files>
|
||||||
|
<Globals>
|
||||||
|
</Globals>
|
||||||
|
</VisualStudioProject>
|
|
@ -0,0 +1,186 @@
|
||||||
|
<?xml version="1.0" encoding="Windows-1252"?>
|
||||||
|
<VisualStudioProject
|
||||||
|
ProjectType="Visual C++"
|
||||||
|
Version="7.10"
|
||||||
|
Name="rdr"
|
||||||
|
SccProjectName=""
|
||||||
|
SccLocalPath="">
|
||||||
|
<Platforms>
|
||||||
|
<Platform
|
||||||
|
Name="Win32"/>
|
||||||
|
</Platforms>
|
||||||
|
<Configurations>
|
||||||
|
<Configuration
|
||||||
|
Name="Release|Win32"
|
||||||
|
OutputDirectory=".\Release"
|
||||||
|
IntermediateDirectory=".\Release"
|
||||||
|
ConfigurationType="4"
|
||||||
|
UseOfMFC="0"
|
||||||
|
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||||
|
CharacterSet="2">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
InlineFunctionExpansion="1"
|
||||||
|
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
||||||
|
StringPooling="TRUE"
|
||||||
|
RuntimeLibrary="0"
|
||||||
|
EnableFunctionLevelLinking="TRUE"
|
||||||
|
UsePrecompiledHeader="2"
|
||||||
|
PrecompiledHeaderFile=".\Release/rdr.pch"
|
||||||
|
AssemblerListingLocation=".\Release/"
|
||||||
|
ObjectFile=".\Release/"
|
||||||
|
ProgramDataBaseFileName=".\Release/"
|
||||||
|
WarningLevel="3"
|
||||||
|
SuppressStartupBanner="TRUE"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLibrarianTool"
|
||||||
|
OutputFile=".\Release\rdr.lib"
|
||||||
|
SuppressStartupBanner="TRUE"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
PreprocessorDefinitions="NDEBUG"
|
||||||
|
Culture="2057"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedWrapperGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
<References>
|
||||||
|
</References>
|
||||||
|
<Files>
|
||||||
|
<Filter
|
||||||
|
Name="Source Files"
|
||||||
|
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||||
|
<File
|
||||||
|
RelativePath="FdInStream.cxx">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
AdditionalIncludeDirectories="..,../zlib"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
CompileAs="0"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="FdOutStream.cxx">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
AdditionalIncludeDirectories="..,../zlib"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
CompileAs="0"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="InStream.cxx">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
AdditionalIncludeDirectories="..,../zlib"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
CompileAs="0"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="NullOutStream.cxx">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
AdditionalIncludeDirectories="..,../zlib"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
CompileAs="0"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="ZlibInStream.cxx">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
AdditionalIncludeDirectories="..,../zlib"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
CompileAs="0"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="ZlibOutStream.cxx">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
AdditionalIncludeDirectories="..,../zlib"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
CompileAs="0"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Header Files"
|
||||||
|
Filter="h;hpp;hxx;hm;inl">
|
||||||
|
<File
|
||||||
|
RelativePath="Exception.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="FdInStream.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="FdOutStream.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="FixedMemOutStream.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="InStream.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="MemInStream.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="MemOutStream.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="NullOutStream.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="OutStream.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="types.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="ZlibInStream.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="ZlibOutStream.h">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
</Files>
|
||||||
|
<Globals>
|
||||||
|
</Globals>
|
||||||
|
</VisualStudioProject>
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?xml version="1.0" encoding="Windows-1252"?>
|
||||||
|
<VisualStudioUserFile
|
||||||
|
ProjectType="Visual C++"
|
||||||
|
Version="9.00"
|
||||||
|
ShowAllFiles="false"
|
||||||
|
>
|
||||||
|
<Configurations>
|
||||||
|
<Configuration
|
||||||
|
Name="Release|Win32"
|
||||||
|
>
|
||||||
|
<DebugSettings
|
||||||
|
Command=""
|
||||||
|
WorkingDirectory=""
|
||||||
|
CommandArguments=""
|
||||||
|
Attach="false"
|
||||||
|
DebuggerType="3"
|
||||||
|
Remote="1"
|
||||||
|
RemoteMachine="UNKNOWN"
|
||||||
|
RemoteCommand=""
|
||||||
|
HttpUrl=""
|
||||||
|
PDBPath=""
|
||||||
|
SQLDebugging=""
|
||||||
|
Environment=""
|
||||||
|
EnvironmentMerge="true"
|
||||||
|
DebuggerFlavor=""
|
||||||
|
MPIRunCommand=""
|
||||||
|
MPIRunArguments=""
|
||||||
|
MPIRunWorkingDirectory=""
|
||||||
|
ApplicationCommand=""
|
||||||
|
ApplicationArguments=""
|
||||||
|
ShimCommand=""
|
||||||
|
MPIAcceptMode=""
|
||||||
|
MPIAcceptFilter=""
|
||||||
|
/>
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
</VisualStudioUserFile>
|
|
@ -0,0 +1,33 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
#ifndef __RDR_TYPES_H__
|
||||||
|
#define __RDR_TYPES_H__
|
||||||
|
|
||||||
|
namespace rdr {
|
||||||
|
|
||||||
|
typedef unsigned char U8;
|
||||||
|
typedef unsigned short U16;
|
||||||
|
typedef unsigned int U32;
|
||||||
|
typedef signed char S8;
|
||||||
|
typedef signed short S16;
|
||||||
|
typedef signed int S32;
|
||||||
|
|
||||||
|
} // end of namespace rdr
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
SRCS = d3des.c vncauth.c
|
||||||
|
|
||||||
|
OBJS = d3des.o vncauth.o
|
||||||
|
|
||||||
|
DIR_CPPFLAGS = -I$(top_srcdir)
|
||||||
|
|
||||||
|
library = librfb.a
|
||||||
|
|
||||||
|
all:: $(library)
|
||||||
|
|
||||||
|
$(library): $(OBJS)
|
||||||
|
rm -f $(library)
|
||||||
|
$(AR) $(library) $(OBJS)
|
||||||
|
$(RANLIB) $(library)
|
||||||
|
|
||||||
|
# followed by boilerplate.mk
|
|
@ -0,0 +1,434 @@
|
||||||
|
/*
|
||||||
|
* This is D3DES (V5.09) by Richard Outerbridge with the double and
|
||||||
|
* triple-length support removed for use in VNC. Also the bytebit[] array
|
||||||
|
* has been reversed so that the most significant bit in each byte of the
|
||||||
|
* key is ignored, not the least significant.
|
||||||
|
*
|
||||||
|
* These changes are:
|
||||||
|
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* D3DES (V5.09) -
|
||||||
|
*
|
||||||
|
* A portable, public domain, version of the Data Encryption Standard.
|
||||||
|
*
|
||||||
|
* Written with Symantec's THINK (Lightspeed) C by Richard Outerbridge.
|
||||||
|
* Thanks to: Dan Hoey for his excellent Initial and Inverse permutation
|
||||||
|
* code; Jim Gillogly & Phil Karn for the DES key schedule code; Dennis
|
||||||
|
* Ferguson, Eric Young and Dana How for comparing notes; and Ray Lau,
|
||||||
|
* for humouring me on.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge.
|
||||||
|
* (GEnie : OUTER; CIS : [71755,204]) Graven Imagery, 1992.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "d3des.h"
|
||||||
|
|
||||||
|
static void scrunch(unsigned char *, unsigned long *);
|
||||||
|
static void unscrun(unsigned long *, unsigned char *);
|
||||||
|
static void desfunc(unsigned long *, unsigned long *);
|
||||||
|
static void cookey(unsigned long *);
|
||||||
|
|
||||||
|
static unsigned long KnL[32] = { 0L };
|
||||||
|
|
||||||
|
static unsigned short bytebit[8] = {
|
||||||
|
01, 02, 04, 010, 020, 040, 0100, 0200 };
|
||||||
|
|
||||||
|
static unsigned long bigbyte[24] = {
|
||||||
|
0x800000L, 0x400000L, 0x200000L, 0x100000L,
|
||||||
|
0x80000L, 0x40000L, 0x20000L, 0x10000L,
|
||||||
|
0x8000L, 0x4000L, 0x2000L, 0x1000L,
|
||||||
|
0x800L, 0x400L, 0x200L, 0x100L,
|
||||||
|
0x80L, 0x40L, 0x20L, 0x10L,
|
||||||
|
0x8L, 0x4L, 0x2L, 0x1L };
|
||||||
|
|
||||||
|
/* Use the key schedule specified in the Standard (ANSI X3.92-1981). */
|
||||||
|
|
||||||
|
static unsigned char pc1[56] = {
|
||||||
|
56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17,
|
||||||
|
9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35,
|
||||||
|
62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21,
|
||||||
|
13, 5, 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3 };
|
||||||
|
|
||||||
|
static unsigned char totrot[16] = {
|
||||||
|
1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28 };
|
||||||
|
|
||||||
|
static unsigned char pc2[48] = {
|
||||||
|
13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9,
|
||||||
|
22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1,
|
||||||
|
40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47,
|
||||||
|
43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31 };
|
||||||
|
|
||||||
|
void deskey(key, edf) /* Thanks to James Gillogly & Phil Karn! */
|
||||||
|
unsigned char *key;
|
||||||
|
int edf;
|
||||||
|
{
|
||||||
|
register int i, j, l, m, n;
|
||||||
|
unsigned char pc1m[56], pcr[56];
|
||||||
|
unsigned long kn[32];
|
||||||
|
|
||||||
|
for ( j = 0; j < 56; j++ ) {
|
||||||
|
l = pc1[j];
|
||||||
|
m = l & 07;
|
||||||
|
pc1m[j] = (key[l >> 3] & bytebit[m]) ? 1 : 0;
|
||||||
|
}
|
||||||
|
for( i = 0; i < 16; i++ ) {
|
||||||
|
if( edf == DE1 ) m = (15 - i) << 1;
|
||||||
|
else m = i << 1;
|
||||||
|
n = m + 1;
|
||||||
|
kn[m] = kn[n] = 0L;
|
||||||
|
for( j = 0; j < 28; j++ ) {
|
||||||
|
l = j + totrot[i];
|
||||||
|
if( l < 28 ) pcr[j] = pc1m[l];
|
||||||
|
else pcr[j] = pc1m[l - 28];
|
||||||
|
}
|
||||||
|
for( j = 28; j < 56; j++ ) {
|
||||||
|
l = j + totrot[i];
|
||||||
|
if( l < 56 ) pcr[j] = pc1m[l];
|
||||||
|
else pcr[j] = pc1m[l - 28];
|
||||||
|
}
|
||||||
|
for( j = 0; j < 24; j++ ) {
|
||||||
|
if( pcr[pc2[j]] ) kn[m] |= bigbyte[j];
|
||||||
|
if( pcr[pc2[j+24]] ) kn[n] |= bigbyte[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cookey(kn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cookey(raw1)
|
||||||
|
register unsigned long *raw1;
|
||||||
|
{
|
||||||
|
register unsigned long *cook, *raw0;
|
||||||
|
unsigned long dough[32];
|
||||||
|
register int i;
|
||||||
|
|
||||||
|
cook = dough;
|
||||||
|
for( i = 0; i < 16; i++, raw1++ ) {
|
||||||
|
raw0 = raw1++;
|
||||||
|
*cook = (*raw0 & 0x00fc0000L) << 6;
|
||||||
|
*cook |= (*raw0 & 0x00000fc0L) << 10;
|
||||||
|
*cook |= (*raw1 & 0x00fc0000L) >> 10;
|
||||||
|
*cook++ |= (*raw1 & 0x00000fc0L) >> 6;
|
||||||
|
*cook = (*raw0 & 0x0003f000L) << 12;
|
||||||
|
*cook |= (*raw0 & 0x0000003fL) << 16;
|
||||||
|
*cook |= (*raw1 & 0x0003f000L) >> 4;
|
||||||
|
*cook++ |= (*raw1 & 0x0000003fL);
|
||||||
|
}
|
||||||
|
usekey(dough);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cpkey(into)
|
||||||
|
register unsigned long *into;
|
||||||
|
{
|
||||||
|
register unsigned long *from, *endp;
|
||||||
|
|
||||||
|
from = KnL, endp = &KnL[32];
|
||||||
|
while( from < endp ) *into++ = *from++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void usekey(from)
|
||||||
|
register unsigned long *from;
|
||||||
|
{
|
||||||
|
register unsigned long *to, *endp;
|
||||||
|
|
||||||
|
to = KnL, endp = &KnL[32];
|
||||||
|
while( to < endp ) *to++ = *from++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void des(inblock, outblock)
|
||||||
|
unsigned char *inblock, *outblock;
|
||||||
|
{
|
||||||
|
unsigned long work[2];
|
||||||
|
|
||||||
|
scrunch(inblock, work);
|
||||||
|
desfunc(work, KnL);
|
||||||
|
unscrun(work, outblock);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void scrunch(outof, into)
|
||||||
|
register unsigned char *outof;
|
||||||
|
register unsigned long *into;
|
||||||
|
{
|
||||||
|
*into = (*outof++ & 0xffL) << 24;
|
||||||
|
*into |= (*outof++ & 0xffL) << 16;
|
||||||
|
*into |= (*outof++ & 0xffL) << 8;
|
||||||
|
*into++ |= (*outof++ & 0xffL);
|
||||||
|
*into = (*outof++ & 0xffL) << 24;
|
||||||
|
*into |= (*outof++ & 0xffL) << 16;
|
||||||
|
*into |= (*outof++ & 0xffL) << 8;
|
||||||
|
*into |= (*outof & 0xffL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unscrun(outof, into)
|
||||||
|
register unsigned long *outof;
|
||||||
|
register unsigned char *into;
|
||||||
|
{
|
||||||
|
*into++ = (*outof >> 24) & 0xffL;
|
||||||
|
*into++ = (*outof >> 16) & 0xffL;
|
||||||
|
*into++ = (*outof >> 8) & 0xffL;
|
||||||
|
*into++ = *outof++ & 0xffL;
|
||||||
|
*into++ = (*outof >> 24) & 0xffL;
|
||||||
|
*into++ = (*outof >> 16) & 0xffL;
|
||||||
|
*into++ = (*outof >> 8) & 0xffL;
|
||||||
|
*into = *outof & 0xffL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned long SP1[64] = {
|
||||||
|
0x01010400L, 0x00000000L, 0x00010000L, 0x01010404L,
|
||||||
|
0x01010004L, 0x00010404L, 0x00000004L, 0x00010000L,
|
||||||
|
0x00000400L, 0x01010400L, 0x01010404L, 0x00000400L,
|
||||||
|
0x01000404L, 0x01010004L, 0x01000000L, 0x00000004L,
|
||||||
|
0x00000404L, 0x01000400L, 0x01000400L, 0x00010400L,
|
||||||
|
0x00010400L, 0x01010000L, 0x01010000L, 0x01000404L,
|
||||||
|
0x00010004L, 0x01000004L, 0x01000004L, 0x00010004L,
|
||||||
|
0x00000000L, 0x00000404L, 0x00010404L, 0x01000000L,
|
||||||
|
0x00010000L, 0x01010404L, 0x00000004L, 0x01010000L,
|
||||||
|
0x01010400L, 0x01000000L, 0x01000000L, 0x00000400L,
|
||||||
|
0x01010004L, 0x00010000L, 0x00010400L, 0x01000004L,
|
||||||
|
0x00000400L, 0x00000004L, 0x01000404L, 0x00010404L,
|
||||||
|
0x01010404L, 0x00010004L, 0x01010000L, 0x01000404L,
|
||||||
|
0x01000004L, 0x00000404L, 0x00010404L, 0x01010400L,
|
||||||
|
0x00000404L, 0x01000400L, 0x01000400L, 0x00000000L,
|
||||||
|
0x00010004L, 0x00010400L, 0x00000000L, 0x01010004L };
|
||||||
|
|
||||||
|
static unsigned long SP2[64] = {
|
||||||
|
0x80108020L, 0x80008000L, 0x00008000L, 0x00108020L,
|
||||||
|
0x00100000L, 0x00000020L, 0x80100020L, 0x80008020L,
|
||||||
|
0x80000020L, 0x80108020L, 0x80108000L, 0x80000000L,
|
||||||
|
0x80008000L, 0x00100000L, 0x00000020L, 0x80100020L,
|
||||||
|
0x00108000L, 0x00100020L, 0x80008020L, 0x00000000L,
|
||||||
|
0x80000000L, 0x00008000L, 0x00108020L, 0x80100000L,
|
||||||
|
0x00100020L, 0x80000020L, 0x00000000L, 0x00108000L,
|
||||||
|
0x00008020L, 0x80108000L, 0x80100000L, 0x00008020L,
|
||||||
|
0x00000000L, 0x00108020L, 0x80100020L, 0x00100000L,
|
||||||
|
0x80008020L, 0x80100000L, 0x80108000L, 0x00008000L,
|
||||||
|
0x80100000L, 0x80008000L, 0x00000020L, 0x80108020L,
|
||||||
|
0x00108020L, 0x00000020L, 0x00008000L, 0x80000000L,
|
||||||
|
0x00008020L, 0x80108000L, 0x00100000L, 0x80000020L,
|
||||||
|
0x00100020L, 0x80008020L, 0x80000020L, 0x00100020L,
|
||||||
|
0x00108000L, 0x00000000L, 0x80008000L, 0x00008020L,
|
||||||
|
0x80000000L, 0x80100020L, 0x80108020L, 0x00108000L };
|
||||||
|
|
||||||
|
static unsigned long SP3[64] = {
|
||||||
|
0x00000208L, 0x08020200L, 0x00000000L, 0x08020008L,
|
||||||
|
0x08000200L, 0x00000000L, 0x00020208L, 0x08000200L,
|
||||||
|
0x00020008L, 0x08000008L, 0x08000008L, 0x00020000L,
|
||||||
|
0x08020208L, 0x00020008L, 0x08020000L, 0x00000208L,
|
||||||
|
0x08000000L, 0x00000008L, 0x08020200L, 0x00000200L,
|
||||||
|
0x00020200L, 0x08020000L, 0x08020008L, 0x00020208L,
|
||||||
|
0x08000208L, 0x00020200L, 0x00020000L, 0x08000208L,
|
||||||
|
0x00000008L, 0x08020208L, 0x00000200L, 0x08000000L,
|
||||||
|
0x08020200L, 0x08000000L, 0x00020008L, 0x00000208L,
|
||||||
|
0x00020000L, 0x08020200L, 0x08000200L, 0x00000000L,
|
||||||
|
0x00000200L, 0x00020008L, 0x08020208L, 0x08000200L,
|
||||||
|
0x08000008L, 0x00000200L, 0x00000000L, 0x08020008L,
|
||||||
|
0x08000208L, 0x00020000L, 0x08000000L, 0x08020208L,
|
||||||
|
0x00000008L, 0x00020208L, 0x00020200L, 0x08000008L,
|
||||||
|
0x08020000L, 0x08000208L, 0x00000208L, 0x08020000L,
|
||||||
|
0x00020208L, 0x00000008L, 0x08020008L, 0x00020200L };
|
||||||
|
|
||||||
|
static unsigned long SP4[64] = {
|
||||||
|
0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,
|
||||||
|
0x00802080L, 0x00800081L, 0x00800001L, 0x00002001L,
|
||||||
|
0x00000000L, 0x00802000L, 0x00802000L, 0x00802081L,
|
||||||
|
0x00000081L, 0x00000000L, 0x00800080L, 0x00800001L,
|
||||||
|
0x00000001L, 0x00002000L, 0x00800000L, 0x00802001L,
|
||||||
|
0x00000080L, 0x00800000L, 0x00002001L, 0x00002080L,
|
||||||
|
0x00800081L, 0x00000001L, 0x00002080L, 0x00800080L,
|
||||||
|
0x00002000L, 0x00802080L, 0x00802081L, 0x00000081L,
|
||||||
|
0x00800080L, 0x00800001L, 0x00802000L, 0x00802081L,
|
||||||
|
0x00000081L, 0x00000000L, 0x00000000L, 0x00802000L,
|
||||||
|
0x00002080L, 0x00800080L, 0x00800081L, 0x00000001L,
|
||||||
|
0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,
|
||||||
|
0x00802081L, 0x00000081L, 0x00000001L, 0x00002000L,
|
||||||
|
0x00800001L, 0x00002001L, 0x00802080L, 0x00800081L,
|
||||||
|
0x00002001L, 0x00002080L, 0x00800000L, 0x00802001L,
|
||||||
|
0x00000080L, 0x00800000L, 0x00002000L, 0x00802080L };
|
||||||
|
|
||||||
|
static unsigned long SP5[64] = {
|
||||||
|
0x00000100L, 0x02080100L, 0x02080000L, 0x42000100L,
|
||||||
|
0x00080000L, 0x00000100L, 0x40000000L, 0x02080000L,
|
||||||
|
0x40080100L, 0x00080000L, 0x02000100L, 0x40080100L,
|
||||||
|
0x42000100L, 0x42080000L, 0x00080100L, 0x40000000L,
|
||||||
|
0x02000000L, 0x40080000L, 0x40080000L, 0x00000000L,
|
||||||
|
0x40000100L, 0x42080100L, 0x42080100L, 0x02000100L,
|
||||||
|
0x42080000L, 0x40000100L, 0x00000000L, 0x42000000L,
|
||||||
|
0x02080100L, 0x02000000L, 0x42000000L, 0x00080100L,
|
||||||
|
0x00080000L, 0x42000100L, 0x00000100L, 0x02000000L,
|
||||||
|
0x40000000L, 0x02080000L, 0x42000100L, 0x40080100L,
|
||||||
|
0x02000100L, 0x40000000L, 0x42080000L, 0x02080100L,
|
||||||
|
0x40080100L, 0x00000100L, 0x02000000L, 0x42080000L,
|
||||||
|
0x42080100L, 0x00080100L, 0x42000000L, 0x42080100L,
|
||||||
|
0x02080000L, 0x00000000L, 0x40080000L, 0x42000000L,
|
||||||
|
0x00080100L, 0x02000100L, 0x40000100L, 0x00080000L,
|
||||||
|
0x00000000L, 0x40080000L, 0x02080100L, 0x40000100L };
|
||||||
|
|
||||||
|
static unsigned long SP6[64] = {
|
||||||
|
0x20000010L, 0x20400000L, 0x00004000L, 0x20404010L,
|
||||||
|
0x20400000L, 0x00000010L, 0x20404010L, 0x00400000L,
|
||||||
|
0x20004000L, 0x00404010L, 0x00400000L, 0x20000010L,
|
||||||
|
0x00400010L, 0x20004000L, 0x20000000L, 0x00004010L,
|
||||||
|
0x00000000L, 0x00400010L, 0x20004010L, 0x00004000L,
|
||||||
|
0x00404000L, 0x20004010L, 0x00000010L, 0x20400010L,
|
||||||
|
0x20400010L, 0x00000000L, 0x00404010L, 0x20404000L,
|
||||||
|
0x00004010L, 0x00404000L, 0x20404000L, 0x20000000L,
|
||||||
|
0x20004000L, 0x00000010L, 0x20400010L, 0x00404000L,
|
||||||
|
0x20404010L, 0x00400000L, 0x00004010L, 0x20000010L,
|
||||||
|
0x00400000L, 0x20004000L, 0x20000000L, 0x00004010L,
|
||||||
|
0x20000010L, 0x20404010L, 0x00404000L, 0x20400000L,
|
||||||
|
0x00404010L, 0x20404000L, 0x00000000L, 0x20400010L,
|
||||||
|
0x00000010L, 0x00004000L, 0x20400000L, 0x00404010L,
|
||||||
|
0x00004000L, 0x00400010L, 0x20004010L, 0x00000000L,
|
||||||
|
0x20404000L, 0x20000000L, 0x00400010L, 0x20004010L };
|
||||||
|
|
||||||
|
static unsigned long SP7[64] = {
|
||||||
|
0x00200000L, 0x04200002L, 0x04000802L, 0x00000000L,
|
||||||
|
0x00000800L, 0x04000802L, 0x00200802L, 0x04200800L,
|
||||||
|
0x04200802L, 0x00200000L, 0x00000000L, 0x04000002L,
|
||||||
|
0x00000002L, 0x04000000L, 0x04200002L, 0x00000802L,
|
||||||
|
0x04000800L, 0x00200802L, 0x00200002L, 0x04000800L,
|
||||||
|
0x04000002L, 0x04200000L, 0x04200800L, 0x00200002L,
|
||||||
|
0x04200000L, 0x00000800L, 0x00000802L, 0x04200802L,
|
||||||
|
0x00200800L, 0x00000002L, 0x04000000L, 0x00200800L,
|
||||||
|
0x04000000L, 0x00200800L, 0x00200000L, 0x04000802L,
|
||||||
|
0x04000802L, 0x04200002L, 0x04200002L, 0x00000002L,
|
||||||
|
0x00200002L, 0x04000000L, 0x04000800L, 0x00200000L,
|
||||||
|
0x04200800L, 0x00000802L, 0x00200802L, 0x04200800L,
|
||||||
|
0x00000802L, 0x04000002L, 0x04200802L, 0x04200000L,
|
||||||
|
0x00200800L, 0x00000000L, 0x00000002L, 0x04200802L,
|
||||||
|
0x00000000L, 0x00200802L, 0x04200000L, 0x00000800L,
|
||||||
|
0x04000002L, 0x04000800L, 0x00000800L, 0x00200002L };
|
||||||
|
|
||||||
|
static unsigned long SP8[64] = {
|
||||||
|
0x10001040L, 0x00001000L, 0x00040000L, 0x10041040L,
|
||||||
|
0x10000000L, 0x10001040L, 0x00000040L, 0x10000000L,
|
||||||
|
0x00040040L, 0x10040000L, 0x10041040L, 0x00041000L,
|
||||||
|
0x10041000L, 0x00041040L, 0x00001000L, 0x00000040L,
|
||||||
|
0x10040000L, 0x10000040L, 0x10001000L, 0x00001040L,
|
||||||
|
0x00041000L, 0x00040040L, 0x10040040L, 0x10041000L,
|
||||||
|
0x00001040L, 0x00000000L, 0x00000000L, 0x10040040L,
|
||||||
|
0x10000040L, 0x10001000L, 0x00041040L, 0x00040000L,
|
||||||
|
0x00041040L, 0x00040000L, 0x10041000L, 0x00001000L,
|
||||||
|
0x00000040L, 0x10040040L, 0x00001000L, 0x00041040L,
|
||||||
|
0x10001000L, 0x00000040L, 0x10000040L, 0x10040000L,
|
||||||
|
0x10040040L, 0x10000000L, 0x00040000L, 0x10001040L,
|
||||||
|
0x00000000L, 0x10041040L, 0x00040040L, 0x10000040L,
|
||||||
|
0x10040000L, 0x10001000L, 0x10001040L, 0x00000000L,
|
||||||
|
0x10041040L, 0x00041000L, 0x00041000L, 0x00001040L,
|
||||||
|
0x00001040L, 0x00040040L, 0x10000000L, 0x10041000L };
|
||||||
|
|
||||||
|
static void desfunc(block, keys)
|
||||||
|
register unsigned long *block, *keys;
|
||||||
|
{
|
||||||
|
register unsigned long fval, work, right, leftt;
|
||||||
|
register int round;
|
||||||
|
|
||||||
|
leftt = block[0];
|
||||||
|
right = block[1];
|
||||||
|
work = ((leftt >> 4) ^ right) & 0x0f0f0f0fL;
|
||||||
|
right ^= work;
|
||||||
|
leftt ^= (work << 4);
|
||||||
|
work = ((leftt >> 16) ^ right) & 0x0000ffffL;
|
||||||
|
right ^= work;
|
||||||
|
leftt ^= (work << 16);
|
||||||
|
work = ((right >> 2) ^ leftt) & 0x33333333L;
|
||||||
|
leftt ^= work;
|
||||||
|
right ^= (work << 2);
|
||||||
|
work = ((right >> 8) ^ leftt) & 0x00ff00ffL;
|
||||||
|
leftt ^= work;
|
||||||
|
right ^= (work << 8);
|
||||||
|
right = ((right << 1) | ((right >> 31) & 1L)) & 0xffffffffL;
|
||||||
|
work = (leftt ^ right) & 0xaaaaaaaaL;
|
||||||
|
leftt ^= work;
|
||||||
|
right ^= work;
|
||||||
|
leftt = ((leftt << 1) | ((leftt >> 31) & 1L)) & 0xffffffffL;
|
||||||
|
|
||||||
|
for( round = 0; round < 8; round++ ) {
|
||||||
|
work = (right << 28) | (right >> 4);
|
||||||
|
work ^= *keys++;
|
||||||
|
fval = SP7[ work & 0x3fL];
|
||||||
|
fval |= SP5[(work >> 8) & 0x3fL];
|
||||||
|
fval |= SP3[(work >> 16) & 0x3fL];
|
||||||
|
fval |= SP1[(work >> 24) & 0x3fL];
|
||||||
|
work = right ^ *keys++;
|
||||||
|
fval |= SP8[ work & 0x3fL];
|
||||||
|
fval |= SP6[(work >> 8) & 0x3fL];
|
||||||
|
fval |= SP4[(work >> 16) & 0x3fL];
|
||||||
|
fval |= SP2[(work >> 24) & 0x3fL];
|
||||||
|
leftt ^= fval;
|
||||||
|
work = (leftt << 28) | (leftt >> 4);
|
||||||
|
work ^= *keys++;
|
||||||
|
fval = SP7[ work & 0x3fL];
|
||||||
|
fval |= SP5[(work >> 8) & 0x3fL];
|
||||||
|
fval |= SP3[(work >> 16) & 0x3fL];
|
||||||
|
fval |= SP1[(work >> 24) & 0x3fL];
|
||||||
|
work = leftt ^ *keys++;
|
||||||
|
fval |= SP8[ work & 0x3fL];
|
||||||
|
fval |= SP6[(work >> 8) & 0x3fL];
|
||||||
|
fval |= SP4[(work >> 16) & 0x3fL];
|
||||||
|
fval |= SP2[(work >> 24) & 0x3fL];
|
||||||
|
right ^= fval;
|
||||||
|
}
|
||||||
|
|
||||||
|
right = (right << 31) | (right >> 1);
|
||||||
|
work = (leftt ^ right) & 0xaaaaaaaaL;
|
||||||
|
leftt ^= work;
|
||||||
|
right ^= work;
|
||||||
|
leftt = (leftt << 31) | (leftt >> 1);
|
||||||
|
work = ((leftt >> 8) ^ right) & 0x00ff00ffL;
|
||||||
|
right ^= work;
|
||||||
|
leftt ^= (work << 8);
|
||||||
|
work = ((leftt >> 2) ^ right) & 0x33333333L;
|
||||||
|
right ^= work;
|
||||||
|
leftt ^= (work << 2);
|
||||||
|
work = ((right >> 16) ^ leftt) & 0x0000ffffL;
|
||||||
|
leftt ^= work;
|
||||||
|
right ^= (work << 16);
|
||||||
|
work = ((right >> 4) ^ leftt) & 0x0f0f0f0fL;
|
||||||
|
leftt ^= work;
|
||||||
|
right ^= (work << 4);
|
||||||
|
*block++ = right;
|
||||||
|
*block = leftt;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Validation sets:
|
||||||
|
*
|
||||||
|
* Single-length key, single-length plaintext -
|
||||||
|
* Key : 0123 4567 89ab cdef
|
||||||
|
* Plain : 0123 4567 89ab cde7
|
||||||
|
* Cipher : c957 4425 6a5e d31d
|
||||||
|
*
|
||||||
|
* Double-length key, single-length plaintext -
|
||||||
|
* Key : 0123 4567 89ab cdef fedc ba98 7654 3210
|
||||||
|
* Plain : 0123 4567 89ab cde7
|
||||||
|
* Cipher : 7f1d 0a77 826b 8aff
|
||||||
|
*
|
||||||
|
* Double-length key, double-length plaintext -
|
||||||
|
* Key : 0123 4567 89ab cdef fedc ba98 7654 3210
|
||||||
|
* Plain : 0123 4567 89ab cdef 0123 4567 89ab cdff
|
||||||
|
* Cipher : 27a0 8440 406a df60 278f 47cf 42d6 15d7
|
||||||
|
*
|
||||||
|
* Triple-length key, single-length plaintext -
|
||||||
|
* Key : 0123 4567 89ab cdef fedc ba98 7654 3210 89ab cdef 0123 4567
|
||||||
|
* Plain : 0123 4567 89ab cde7
|
||||||
|
* Cipher : de0b 7c06 ae5e 0ed5
|
||||||
|
*
|
||||||
|
* Triple-length key, double-length plaintext -
|
||||||
|
* Key : 0123 4567 89ab cdef fedc ba98 7654 3210 89ab cdef 0123 4567
|
||||||
|
* Plain : 0123 4567 89ab cdef 0123 4567 89ab cdff
|
||||||
|
* Cipher : ad0d 1b30 ac17 cf07 0ed1 1c63 81e4 4de5
|
||||||
|
*
|
||||||
|
* d3des V5.0a rwo 9208.07 18:44 Graven Imagery
|
||||||
|
**********************************************************************/
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* This is D3DES (V5.09) by Richard Outerbridge with the double and
|
||||||
|
* triple-length support removed for use in VNC.
|
||||||
|
*
|
||||||
|
* These changes are:
|
||||||
|
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* d3des.h -
|
||||||
|
*
|
||||||
|
* Headers and defines for d3des.c
|
||||||
|
* Graven Imagery, 1992.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge
|
||||||
|
* (GEnie : OUTER; CIS : [71755,204])
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define EN0 0 /* MODE == encrypt */
|
||||||
|
#define DE1 1 /* MODE == decrypt */
|
||||||
|
|
||||||
|
extern void deskey(unsigned char *, int);
|
||||||
|
/* hexkey[8] MODE
|
||||||
|
* Sets the internal key register according to the hexadecimal
|
||||||
|
* key contained in the 8 bytes of hexkey, according to the DES,
|
||||||
|
* for encryption or decryption according to MODE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern void usekey(unsigned long *);
|
||||||
|
/* cookedkey[32]
|
||||||
|
* Loads the internal key register with the data in cookedkey.
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern void cpkey(unsigned long *);
|
||||||
|
/* cookedkey[32]
|
||||||
|
* Copies the contents of the internal key register into the storage
|
||||||
|
* located at &cookedkey[0].
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern void des(unsigned char *, unsigned char *);
|
||||||
|
/* from[8] to[8]
|
||||||
|
* Encrypts/Decrypts (according to the key currently loaded in the
|
||||||
|
* internal key register) one block of eight bytes at address 'from'
|
||||||
|
* into the block at address 'to'. They can be the same.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* d3des.h V5.09 rwo 9208.04 15:06 Graven Imagery
|
||||||
|
********************************************************************/
|
|
@ -0,0 +1,692 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2002 RealVNC Ltd. All Rights Reserved.
|
||||||
|
* Copyright (C) 1999 AT&T Laboratories Cambridge. 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* rfbproto.h - header file for the RFB protocol version 3.3
|
||||||
|
*
|
||||||
|
* Uses types CARD<n> for an n-bit unsigned integer, INT<n> for an n-bit signed
|
||||||
|
* integer (for n = 8, 16 and 32).
|
||||||
|
*
|
||||||
|
* All multiple byte integers are in big endian (network) order (most
|
||||||
|
* significant byte first). Unless noted otherwise there is no special
|
||||||
|
* alignment of protocol structures.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Once the initial handshaking is done, all messages start with a type byte,
|
||||||
|
* (usually) followed by message-specific data. The order of definitions in
|
||||||
|
* this file is as follows:
|
||||||
|
*
|
||||||
|
* (1) Structures used in several types of message.
|
||||||
|
* (2) Structures used in the initial handshaking.
|
||||||
|
* (3) Message types.
|
||||||
|
* (4) Encoding types.
|
||||||
|
* (5) For each message type, the form of the data following the type byte.
|
||||||
|
* Sometimes this is defined by a single structure but the more complex
|
||||||
|
* messages have to be explained by comments.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* Structures used in several messages
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* Structure used to specify a rectangle. This structure is a multiple of 4
|
||||||
|
* bytes so that it can be interspersed with 32-bit pixel data without
|
||||||
|
* affecting alignment.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD16 x;
|
||||||
|
CARD16 y;
|
||||||
|
CARD16 w;
|
||||||
|
CARD16 h;
|
||||||
|
} rfbRectangle;
|
||||||
|
|
||||||
|
#define sz_rfbRectangle 8
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* Structure used to specify pixel format.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
|
||||||
|
CARD8 bitsPerPixel; /* 8,16,32 only */
|
||||||
|
|
||||||
|
CARD8 depth; /* 8 to 32 */
|
||||||
|
|
||||||
|
CARD8 bigEndian; /* True if multi-byte pixels are interpreted
|
||||||
|
as big endian, or if single-bit-per-pixel
|
||||||
|
has most significant bit of the byte
|
||||||
|
corresponding to first (leftmost) pixel. Of
|
||||||
|
course this is meaningless for 8 bits/pix */
|
||||||
|
|
||||||
|
CARD8 trueColour; /* If false then we need a "colour map" to
|
||||||
|
convert pixels to RGB. If true, xxxMax and
|
||||||
|
xxxShift specify bits used for red, green
|
||||||
|
and blue */
|
||||||
|
|
||||||
|
/* the following fields are only meaningful if trueColour is true */
|
||||||
|
|
||||||
|
CARD16 redMax; /* maximum red value (= 2^n - 1 where n is the
|
||||||
|
number of bits used for red). Note this
|
||||||
|
value is always in big endian order. */
|
||||||
|
|
||||||
|
CARD16 greenMax; /* similar for green */
|
||||||
|
|
||||||
|
CARD16 blueMax; /* and blue */
|
||||||
|
|
||||||
|
CARD8 redShift; /* number of shifts needed to get the red
|
||||||
|
value in a pixel to the least significant
|
||||||
|
bit. To find the red value from a given
|
||||||
|
pixel, do the following:
|
||||||
|
1) Swap pixel value according to bigEndian
|
||||||
|
(e.g. if bigEndian is false and host byte
|
||||||
|
order is big endian, then swap).
|
||||||
|
2) Shift right by redShift.
|
||||||
|
3) AND with redMax (in host byte order).
|
||||||
|
4) You now have the red value between 0 and
|
||||||
|
redMax. */
|
||||||
|
|
||||||
|
CARD8 greenShift; /* similar for green */
|
||||||
|
|
||||||
|
CARD8 blueShift; /* and blue */
|
||||||
|
|
||||||
|
CARD8 pad1;
|
||||||
|
CARD16 pad2;
|
||||||
|
|
||||||
|
} rfbPixelFormat;
|
||||||
|
|
||||||
|
#define sz_rfbPixelFormat 16
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* Initial handshaking messages
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* Protocol Version
|
||||||
|
*
|
||||||
|
* The server always sends 12 bytes to start which identifies the latest RFB
|
||||||
|
* protocol version number which it supports. These bytes are interpreted
|
||||||
|
* as a string of 12 ASCII characters in the format "RFB xxx.yyy\n" where
|
||||||
|
* xxx and yyy are the major and minor version numbers (for version 3.3
|
||||||
|
* this is "RFB 003.003\n").
|
||||||
|
*
|
||||||
|
* The client then replies with a similar 12-byte message giving the version
|
||||||
|
* number of the protocol which should actually be used (which may be different
|
||||||
|
* to that quoted by the server).
|
||||||
|
*
|
||||||
|
* It is intended that both clients and servers may provide some level of
|
||||||
|
* backwards compatibility by this mechanism. Servers in particular should
|
||||||
|
* attempt to provide backwards compatibility, and even forwards compatibility
|
||||||
|
* to some extent. For example if a client demands version 3.1 of the
|
||||||
|
* protocol, a 3.0 server can probably assume that by ignoring requests for
|
||||||
|
* encoding types it doesn't understand, everything will still work OK. This
|
||||||
|
* will probably not be the case for changes in the major version number.
|
||||||
|
*
|
||||||
|
* The format string below can be used in sprintf or sscanf to generate or
|
||||||
|
* decode the version string respectively.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define rfbProtocolVersionFormat "RFB %03d.%03d\n"
|
||||||
|
#define rfbProtocolMajorVersion 3
|
||||||
|
#define rfbProtocolMinorVersion 3
|
||||||
|
|
||||||
|
typedef char rfbProtocolVersionMsg[13]; /* allow extra byte for null */
|
||||||
|
|
||||||
|
#define sz_rfbProtocolVersionMsg 12
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* Authentication
|
||||||
|
*
|
||||||
|
* Once the protocol version has been decided, the server then sends a 32-bit
|
||||||
|
* word indicating whether any authentication is needed on the connection.
|
||||||
|
* The value of this word determines the authentication scheme in use. For
|
||||||
|
* version 3.0 of the protocol this may have one of the following values:
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define rfbConnFailed 0
|
||||||
|
#define rfbNoAuth 1
|
||||||
|
#define rfbVncAuth 2
|
||||||
|
|
||||||
|
/*
|
||||||
|
* rfbConnFailed: For some reason the connection failed (e.g. the server
|
||||||
|
* cannot support the desired protocol version). This is
|
||||||
|
* followed by a string describing the reason (where a
|
||||||
|
* string is specified as a 32-bit length followed by that
|
||||||
|
* many ASCII characters).
|
||||||
|
*
|
||||||
|
* rfbNoAuth: No authentication is needed.
|
||||||
|
*
|
||||||
|
* rfbVncAuth: The VNC authentication scheme is to be used. A 16-byte
|
||||||
|
* challenge follows, which the client encrypts as
|
||||||
|
* appropriate using the password and sends the resulting
|
||||||
|
* 16-byte response. If the response is correct, the
|
||||||
|
* server sends the 32-bit word rfbVncAuthOK. If a simple
|
||||||
|
* failure happens, the server sends rfbVncAuthFailed and
|
||||||
|
* closes the connection. If the server decides that too
|
||||||
|
* many failures have occurred, it sends rfbVncAuthTooMany
|
||||||
|
* and closes the connection. In the latter case, the
|
||||||
|
* server should not allow an immediate reconnection by
|
||||||
|
* the client.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define rfbVncAuthOK 0
|
||||||
|
#define rfbVncAuthFailed 1
|
||||||
|
#define rfbVncAuthTooMany 2
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* Client Initialisation Message
|
||||||
|
*
|
||||||
|
* Once the client and server are sure that they're happy to talk to one
|
||||||
|
* another, the client sends an initialisation message. At present this
|
||||||
|
* message only consists of a boolean indicating whether the server should try
|
||||||
|
* to share the desktop by leaving other clients connected, or give exclusive
|
||||||
|
* access to this client by disconnecting all other clients.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD8 shared;
|
||||||
|
} rfbClientInitMsg;
|
||||||
|
|
||||||
|
#define sz_rfbClientInitMsg 1
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* Server Initialisation Message
|
||||||
|
*
|
||||||
|
* After the client initialisation message, the server sends one of its own.
|
||||||
|
* This tells the client the width and height of the server's framebuffer,
|
||||||
|
* its pixel format and the name associated with the desktop.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD16 framebufferWidth;
|
||||||
|
CARD16 framebufferHeight;
|
||||||
|
rfbPixelFormat format; /* the server's preferred pixel format */
|
||||||
|
CARD32 nameLength;
|
||||||
|
/* followed by char name[nameLength] */
|
||||||
|
} rfbServerInitMsg;
|
||||||
|
|
||||||
|
#define sz_rfbServerInitMsg (8 + sz_rfbPixelFormat)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Following the server initialisation message it's up to the client to send
|
||||||
|
* whichever protocol messages it wants. Typically it will send a
|
||||||
|
* SetPixelFormat message and a SetEncodings message, followed by a
|
||||||
|
* FramebufferUpdateRequest. From then on the server will send
|
||||||
|
* FramebufferUpdate messages in response to the client's
|
||||||
|
* FramebufferUpdateRequest messages. The client should send
|
||||||
|
* FramebufferUpdateRequest messages with incremental set to true when it has
|
||||||
|
* finished processing one FramebufferUpdate and is ready to process another.
|
||||||
|
* With a fast client, the rate at which FramebufferUpdateRequests are sent
|
||||||
|
* should be regulated to avoid hogging the network.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* Message types
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/* server -> client */
|
||||||
|
|
||||||
|
#define rfbFramebufferUpdate 0
|
||||||
|
#define rfbSetColourMapEntries 1
|
||||||
|
#define rfbBell 2
|
||||||
|
#define rfbServerCutText 3
|
||||||
|
|
||||||
|
|
||||||
|
/* client -> server */
|
||||||
|
|
||||||
|
#define rfbSetPixelFormat 0
|
||||||
|
#define rfbFixColourMapEntries 1 /* not currently supported */
|
||||||
|
#define rfbSetEncodings 2
|
||||||
|
#define rfbFramebufferUpdateRequest 3
|
||||||
|
#define rfbKeyEvent 4
|
||||||
|
#define rfbPointerEvent 5
|
||||||
|
#define rfbClientCutText 6
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* Encoding types
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#define rfbEncodingRaw 0
|
||||||
|
#define rfbEncodingCopyRect 1
|
||||||
|
#define rfbEncodingRRE 2
|
||||||
|
#define rfbEncodingCoRRE 4
|
||||||
|
#define rfbEncodingHextile 5
|
||||||
|
#define rfbEncodingZRLE 16
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* Server -> client message definitions
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* FramebufferUpdate - a block of rectangles to be copied to the framebuffer.
|
||||||
|
*
|
||||||
|
* This message consists of a header giving the number of rectangles of pixel
|
||||||
|
* data followed by the rectangles themselves. The header is padded so that
|
||||||
|
* together with the type byte it is an exact multiple of 4 bytes (to help
|
||||||
|
* with alignment of 32-bit pixels):
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD8 type; /* always rfbFramebufferUpdate */
|
||||||
|
CARD8 pad;
|
||||||
|
CARD16 nRects;
|
||||||
|
/* followed by nRects rectangles */
|
||||||
|
} rfbFramebufferUpdateMsg;
|
||||||
|
|
||||||
|
#define sz_rfbFramebufferUpdateMsg 4
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Each rectangle of pixel data consists of a header describing the position
|
||||||
|
* and size of the rectangle and a type word describing the encoding of the
|
||||||
|
* pixel data, followed finally by the pixel data. Note that if the client has
|
||||||
|
* not sent a SetEncodings message then it will only receive raw pixel data.
|
||||||
|
* Also note again that this structure is a multiple of 4 bytes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
rfbRectangle r;
|
||||||
|
CARD32 encoding; /* one of the encoding types rfbEncoding... */
|
||||||
|
} rfbFramebufferUpdateRectHeader;
|
||||||
|
|
||||||
|
#define sz_rfbFramebufferUpdateRectHeader (sz_rfbRectangle + 4)
|
||||||
|
|
||||||
|
|
||||||
|
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
* Raw Encoding. Pixels are sent in top-to-bottom scanline order,
|
||||||
|
* left-to-right within a scanline with no padding in between.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
* CopyRect Encoding. The pixels are specified simply by the x and y position
|
||||||
|
* of the source rectangle.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD16 srcX;
|
||||||
|
CARD16 srcY;
|
||||||
|
} rfbCopyRect;
|
||||||
|
|
||||||
|
#define sz_rfbCopyRect 4
|
||||||
|
|
||||||
|
|
||||||
|
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
* RRE - Rise-and-Run-length Encoding. We have an rfbRREHeader structure
|
||||||
|
* giving the number of subrectangles following. Finally the data follows in
|
||||||
|
* the form [<bgpixel><subrect><subrect>...] where each <subrect> is
|
||||||
|
* [<pixel><rfbRectangle>].
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD32 nSubrects;
|
||||||
|
} rfbRREHeader;
|
||||||
|
|
||||||
|
#define sz_rfbRREHeader 4
|
||||||
|
|
||||||
|
|
||||||
|
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
* CoRRE - Compact RRE Encoding. We have an rfbRREHeader structure giving
|
||||||
|
* the number of subrectangles following. Finally the data follows in the form
|
||||||
|
* [<bgpixel><subrect><subrect>...] where each <subrect> is
|
||||||
|
* [<pixel><rfbCoRRERectangle>]. This means that
|
||||||
|
* the whole rectangle must be at most 255x255 pixels.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD8 x;
|
||||||
|
CARD8 y;
|
||||||
|
CARD8 w;
|
||||||
|
CARD8 h;
|
||||||
|
} rfbCoRRERectangle;
|
||||||
|
|
||||||
|
#define sz_rfbCoRRERectangle 4
|
||||||
|
|
||||||
|
|
||||||
|
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
* Hextile Encoding. The rectangle is divided up into "tiles" of 16x16 pixels,
|
||||||
|
* starting at the top left going in left-to-right, top-to-bottom order. If
|
||||||
|
* the width of the rectangle is not an exact multiple of 16 then the width of
|
||||||
|
* the last tile in each row will be correspondingly smaller. Similarly if the
|
||||||
|
* height is not an exact multiple of 16 then the height of each tile in the
|
||||||
|
* final row will also be smaller. Each tile begins with a "subencoding" type
|
||||||
|
* byte, which is a mask made up of a number of bits. If the Raw bit is set
|
||||||
|
* then the other bits are irrelevant; w*h pixel values follow (where w and h
|
||||||
|
* are the width and height of the tile). Otherwise the tile is encoded in a
|
||||||
|
* similar way to RRE, except that the position and size of each subrectangle
|
||||||
|
* can be specified in just two bytes. The other bits in the mask are as
|
||||||
|
* follows:
|
||||||
|
*
|
||||||
|
* BackgroundSpecified - if set, a pixel value follows which specifies
|
||||||
|
* the background colour for this tile. The first non-raw tile in a
|
||||||
|
* rectangle must have this bit set. If this bit isn't set then the
|
||||||
|
* background is the same as the last tile.
|
||||||
|
*
|
||||||
|
* ForegroundSpecified - if set, a pixel value follows which specifies
|
||||||
|
* the foreground colour to be used for all subrectangles in this tile.
|
||||||
|
* If this bit is set then the SubrectsColoured bit must be zero.
|
||||||
|
*
|
||||||
|
* AnySubrects - if set, a single byte follows giving the number of
|
||||||
|
* subrectangles following. If not set, there are no subrectangles (i.e.
|
||||||
|
* the whole tile is just solid background colour).
|
||||||
|
*
|
||||||
|
* SubrectsColoured - if set then each subrectangle is preceded by a pixel
|
||||||
|
* value giving the colour of that subrectangle. If not set, all
|
||||||
|
* subrectangles are the same colour, the foreground colour; if the
|
||||||
|
* ForegroundSpecified bit wasn't set then the foreground is the same as
|
||||||
|
* the last tile.
|
||||||
|
*
|
||||||
|
* The position and size of each subrectangle is specified in two bytes. The
|
||||||
|
* Pack macros below can be used to generate the two bytes from x, y, w, h,
|
||||||
|
* and the Extract macros can be used to extract the x, y, w, h values from
|
||||||
|
* the two bytes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define rfbHextileRaw (1 << 0)
|
||||||
|
#define rfbHextileBackgroundSpecified (1 << 1)
|
||||||
|
#define rfbHextileForegroundSpecified (1 << 2)
|
||||||
|
#define rfbHextileAnySubrects (1 << 3)
|
||||||
|
#define rfbHextileSubrectsColoured (1 << 4)
|
||||||
|
|
||||||
|
#define rfbHextilePackXY(x,y) (((x) << 4) | (y))
|
||||||
|
#define rfbHextilePackWH(w,h) ((((w)-1) << 4) | ((h)-1))
|
||||||
|
#define rfbHextileExtractX(byte) ((byte) >> 4)
|
||||||
|
#define rfbHextileExtractY(byte) ((byte) & 0xf)
|
||||||
|
#define rfbHextileExtractW(byte) (((byte) >> 4) + 1)
|
||||||
|
#define rfbHextileExtractH(byte) (((byte) & 0xf) + 1)
|
||||||
|
|
||||||
|
|
||||||
|
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
* ZRLE - encoding combining Zlib compression, tiling, palettisation and
|
||||||
|
* run-length encoding.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD32 length;
|
||||||
|
} rfbZRLEHeader;
|
||||||
|
|
||||||
|
#define sz_rfbZRLEHeader 4
|
||||||
|
|
||||||
|
#define rfbZRLETileWidth 64
|
||||||
|
#define rfbZRLETileHeight 64
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* SetColourMapEntries - these messages are only sent if the pixel
|
||||||
|
* format uses a "colour map" (i.e. trueColour false) and the client has not
|
||||||
|
* fixed the entire colour map using FixColourMapEntries. In addition they
|
||||||
|
* will only start being sent after the client has sent its first
|
||||||
|
* FramebufferUpdateRequest. So if the client always tells the server to use
|
||||||
|
* trueColour then it never needs to process this type of message.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD8 type; /* always rfbSetColourMapEntries */
|
||||||
|
CARD8 pad;
|
||||||
|
CARD16 firstColour;
|
||||||
|
CARD16 nColours;
|
||||||
|
|
||||||
|
/* Followed by nColours * 3 * CARD16
|
||||||
|
r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */
|
||||||
|
|
||||||
|
} rfbSetColourMapEntriesMsg;
|
||||||
|
|
||||||
|
#define sz_rfbSetColourMapEntriesMsg 6
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* Bell - ring a bell on the client if it has one.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD8 type; /* always rfbBell */
|
||||||
|
} rfbBellMsg;
|
||||||
|
|
||||||
|
#define sz_rfbBellMsg 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* ServerCutText - the server has new text in its cut buffer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD8 type; /* always rfbServerCutText */
|
||||||
|
CARD8 pad1;
|
||||||
|
CARD16 pad2;
|
||||||
|
CARD32 length;
|
||||||
|
/* followed by char text[length] */
|
||||||
|
} rfbServerCutTextMsg;
|
||||||
|
|
||||||
|
#define sz_rfbServerCutTextMsg 8
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* Union of all server->client messages.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
CARD8 type;
|
||||||
|
rfbFramebufferUpdateMsg fu;
|
||||||
|
rfbSetColourMapEntriesMsg scme;
|
||||||
|
rfbBellMsg b;
|
||||||
|
rfbServerCutTextMsg sct;
|
||||||
|
} rfbServerToClientMsg;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* Message definitions (client -> server)
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* SetPixelFormat - tell the RFB server the format in which the client wants
|
||||||
|
* pixels sent.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD8 type; /* always rfbSetPixelFormat */
|
||||||
|
CARD8 pad1;
|
||||||
|
CARD16 pad2;
|
||||||
|
rfbPixelFormat format;
|
||||||
|
} rfbSetPixelFormatMsg;
|
||||||
|
|
||||||
|
#define sz_rfbSetPixelFormatMsg (sz_rfbPixelFormat + 4)
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* FixColourMapEntries - when the pixel format uses a "colour map", fix
|
||||||
|
* read-only colour map entries.
|
||||||
|
*
|
||||||
|
* ***************** NOT CURRENTLY SUPPORTED *****************
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD8 type; /* always rfbFixColourMapEntries */
|
||||||
|
CARD8 pad;
|
||||||
|
CARD16 firstColour;
|
||||||
|
CARD16 nColours;
|
||||||
|
|
||||||
|
/* Followed by nColours * 3 * CARD16
|
||||||
|
r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */
|
||||||
|
|
||||||
|
} rfbFixColourMapEntriesMsg;
|
||||||
|
|
||||||
|
#define sz_rfbFixColourMapEntriesMsg 6
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* SetEncodings - tell the RFB server which encoding types we accept. Put them
|
||||||
|
* in order of preference, if we have any. We may always receive raw
|
||||||
|
* encoding, even if we don't specify it here.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD8 type; /* always rfbSetEncodings */
|
||||||
|
CARD8 pad;
|
||||||
|
CARD16 nEncodings;
|
||||||
|
/* followed by nEncodings * CARD32 encoding types */
|
||||||
|
} rfbSetEncodingsMsg;
|
||||||
|
|
||||||
|
#define sz_rfbSetEncodingsMsg 4
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* FramebufferUpdateRequest - request for a framebuffer update. If incremental
|
||||||
|
* is true then the client just wants the changes since the last update. If
|
||||||
|
* false then it wants the whole of the specified rectangle.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD8 type; /* always rfbFramebufferUpdateRequest */
|
||||||
|
CARD8 incremental;
|
||||||
|
CARD16 x;
|
||||||
|
CARD16 y;
|
||||||
|
CARD16 w;
|
||||||
|
CARD16 h;
|
||||||
|
} rfbFramebufferUpdateRequestMsg;
|
||||||
|
|
||||||
|
#define sz_rfbFramebufferUpdateRequestMsg 10
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* KeyEvent - key press or release
|
||||||
|
*
|
||||||
|
* Keys are specified using the "keysym" values defined by the X Window System.
|
||||||
|
* For most ordinary keys, the keysym is the same as the corresponding ASCII
|
||||||
|
* value. Other common keys are:
|
||||||
|
*
|
||||||
|
* BackSpace 0xff08
|
||||||
|
* Tab 0xff09
|
||||||
|
* Return or Enter 0xff0d
|
||||||
|
* Escape 0xff1b
|
||||||
|
* Insert 0xff63
|
||||||
|
* Delete 0xffff
|
||||||
|
* Home 0xff50
|
||||||
|
* End 0xff57
|
||||||
|
* Page Up 0xff55
|
||||||
|
* Page Down 0xff56
|
||||||
|
* Left 0xff51
|
||||||
|
* Up 0xff52
|
||||||
|
* Right 0xff53
|
||||||
|
* Down 0xff54
|
||||||
|
* F1 0xffbe
|
||||||
|
* F2 0xffbf
|
||||||
|
* ... ...
|
||||||
|
* F12 0xffc9
|
||||||
|
* Shift 0xffe1
|
||||||
|
* Control 0xffe3
|
||||||
|
* Meta 0xffe7
|
||||||
|
* Alt 0xffe9
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD8 type; /* always rfbKeyEvent */
|
||||||
|
CARD8 down; /* true if down (press), false if up */
|
||||||
|
CARD16 pad;
|
||||||
|
CARD32 key; /* key is specified as an X keysym */
|
||||||
|
} rfbKeyEventMsg;
|
||||||
|
|
||||||
|
#define sz_rfbKeyEventMsg 8
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* PointerEvent - mouse/pen move and/or button press.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD8 type; /* always rfbPointerEvent */
|
||||||
|
CARD8 buttonMask; /* bits 0-7 are buttons 1-8, 0=up, 1=down */
|
||||||
|
CARD16 x;
|
||||||
|
CARD16 y;
|
||||||
|
} rfbPointerEventMsg;
|
||||||
|
|
||||||
|
#define rfbButton1Mask 1
|
||||||
|
#define rfbButton2Mask 2
|
||||||
|
#define rfbButton3Mask 4
|
||||||
|
#define rfbButton4Mask 8
|
||||||
|
#define rfbButton5Mask 16
|
||||||
|
#define rfbWheelUpMask rfbButton4Mask
|
||||||
|
#define rfbWheelDownMask rfbButton5Mask
|
||||||
|
|
||||||
|
#define sz_rfbPointerEventMsg 6
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* ClientCutText - the client has new text in its cut buffer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CARD8 type; /* always rfbClientCutText */
|
||||||
|
CARD8 pad1;
|
||||||
|
CARD16 pad2;
|
||||||
|
CARD32 length;
|
||||||
|
/* followed by char text[length] */
|
||||||
|
} rfbClientCutTextMsg;
|
||||||
|
|
||||||
|
#define sz_rfbClientCutTextMsg 8
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------
|
||||||
|
* Union of all client->server messages.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
CARD8 type;
|
||||||
|
rfbSetPixelFormatMsg spf;
|
||||||
|
rfbFixColourMapEntriesMsg fcme;
|
||||||
|
rfbSetEncodingsMsg se;
|
||||||
|
rfbFramebufferUpdateRequestMsg fur;
|
||||||
|
rfbKeyEventMsg ke;
|
||||||
|
rfbPointerEventMsg pe;
|
||||||
|
rfbClientCutTextMsg cct;
|
||||||
|
} rfbClientToServerMsg;
|
|
@ -0,0 +1,164 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2002 RealVNC Ltd. All Rights Reserved.
|
||||||
|
* Copyright (C) 1999 AT&T Laboratories Cambridge. 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 program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||||
|
* USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vncauth.c - Functions for VNC password management and authentication.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <rfb/vncauth.h>
|
||||||
|
#include "d3des.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We use a fixed key to store passwords, since we assume that our local
|
||||||
|
* file system is secure but nonetheless don't want to store passwords
|
||||||
|
* as plaintext.
|
||||||
|
*/
|
||||||
|
|
||||||
|
unsigned char fixedkey[8] = {23,82,107,6,35,78,88,7};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Encrypt a password and store it in a file. Returns 0 if successful,
|
||||||
|
* 1 if the file could not be written.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
vncEncryptAndStorePasswd(char *passwd, char *fname)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
int i;
|
||||||
|
unsigned char encryptedPasswd[8];
|
||||||
|
|
||||||
|
if ((fp = fopen(fname,"w")) == NULL) return 1;
|
||||||
|
|
||||||
|
chmod(fname, S_IRUSR|S_IWUSR);
|
||||||
|
|
||||||
|
/* pad password with nulls */
|
||||||
|
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
if (i < strlen(passwd)) {
|
||||||
|
encryptedPasswd[i] = passwd[i];
|
||||||
|
} else {
|
||||||
|
encryptedPasswd[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do encryption in-place - this way we overwrite our copy of the plaintext
|
||||||
|
password */
|
||||||
|
|
||||||
|
deskey(fixedkey, EN0);
|
||||||
|
des(encryptedPasswd, encryptedPasswd);
|
||||||
|
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
putc(encryptedPasswd[i], fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Decrypt a password from a file. Returns a pointer to a newly allocated
|
||||||
|
* string containing the password or a null pointer if the password could
|
||||||
|
* not be retrieved for some reason.
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *
|
||||||
|
vncDecryptPasswdFromFile(char *fname)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
int i, ch;
|
||||||
|
unsigned char *passwd = (unsigned char *)malloc(9);
|
||||||
|
|
||||||
|
if ((fp = fopen(fname,"r")) == NULL) return NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
ch = getc(fp);
|
||||||
|
if (ch == EOF) {
|
||||||
|
fclose(fp);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
passwd[i] = ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
deskey(fixedkey, DE1);
|
||||||
|
des(passwd, passwd);
|
||||||
|
|
||||||
|
passwd[8] = 0;
|
||||||
|
|
||||||
|
return (char *)passwd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generate CHALLENGESIZE random bytes for use in challenge-response
|
||||||
|
* authentication.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
vncRandomBytes(unsigned char *bytes)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
unsigned int seed = (unsigned int) time(0) + getpid() + rand();
|
||||||
|
|
||||||
|
srand(seed);
|
||||||
|
for (i = 0; i < CHALLENGESIZE; i++) {
|
||||||
|
bytes[i] = (unsigned char)(rand() & 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Encrypt CHALLENGESIZE bytes in memory using a password.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
vncEncryptBytes(unsigned char *bytes, char *passwd)
|
||||||
|
{
|
||||||
|
unsigned char key[8];
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
/* key is simply password padded with nulls */
|
||||||
|
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
if (i < strlen(passwd)) {
|
||||||
|
key[i] = passwd[i];
|
||||||
|
} else {
|
||||||
|
key[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deskey(key, EN0);
|
||||||
|
|
||||||
|
for (i = 0; i < CHALLENGESIZE; i += 8) {
|
||||||
|
des(bytes+i, bytes+i);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 1999 AT&T Laboratories Cambridge. 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vncauth.h - describes the functions provided by the vncauth library.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MAXPWLEN 8
|
||||||
|
#define CHALLENGESIZE 16
|
||||||
|
|
||||||
|
extern int vncEncryptAndStorePasswd(char *passwd, char *fname);
|
||||||
|
extern char *vncDecryptPasswdFromFile(char *fname);
|
||||||
|
extern void vncRandomBytes(unsigned char *bytes);
|
||||||
|
extern void vncEncryptBytes(unsigned char *bytes, char *passwd);
|
|
@ -0,0 +1,241 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
//
|
||||||
|
// zrleDecode.h - zrle decoding function.
|
||||||
|
//
|
||||||
|
// Before including this file, you must define a number of CPP macros.
|
||||||
|
//
|
||||||
|
// BPP should be 8, 16 or 32 depending on the bits per pixel.
|
||||||
|
// FILL_RECT
|
||||||
|
// IMAGE_RECT
|
||||||
|
|
||||||
|
#include <rdr/ZlibInStream.h>
|
||||||
|
#include <rdr/InStream.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
using namespace rdr;
|
||||||
|
|
||||||
|
/* __RFB_CONCAT2 concatenates its two arguments. __RFB_CONCAT2E does the same
|
||||||
|
but also expands its arguments if they are macros */
|
||||||
|
|
||||||
|
#ifndef __RFB_CONCAT2E
|
||||||
|
#define __RFB_CONCAT2(a,b) a##b
|
||||||
|
#define __RFB_CONCAT2E(a,b) __RFB_CONCAT2(a,b)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CPIXEL
|
||||||
|
#define PIXEL_T __RFB_CONCAT2E(rdr::U,BPP)
|
||||||
|
#define READ_PIXEL __RFB_CONCAT2E(readOpaque,CPIXEL)
|
||||||
|
#define ZRLE_DECODE_BPP __RFB_CONCAT2E(zrleDecode,CPIXEL)
|
||||||
|
#else
|
||||||
|
#define PIXEL_T __RFB_CONCAT2E(rdr::U,BPP)
|
||||||
|
#define READ_PIXEL __RFB_CONCAT2E(readOpaque,BPP)
|
||||||
|
#define ZRLE_DECODE_BPP __RFB_CONCAT2E(zrleDecode,BPP)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void ZRLE_DECODE_BPP (int x, int y, int w, int h, rdr::InStream* is,
|
||||||
|
rdr::ZlibInStream* zis, PIXEL_T* buf)
|
||||||
|
{
|
||||||
|
int length = is->readU32();
|
||||||
|
zis->setUnderlying(is, length);
|
||||||
|
|
||||||
|
for (int ty = y; ty < y+h; ty += rfbZRLETileHeight) {
|
||||||
|
int th = rfbZRLETileHeight;
|
||||||
|
if (th > y+h-ty) th = y+h-ty;
|
||||||
|
for (int tx = x; tx < x+w; tx += rfbZRLETileWidth) {
|
||||||
|
int tw = rfbZRLETileWidth;
|
||||||
|
if (tw > x+w-tx) tw = x+w-tx;
|
||||||
|
|
||||||
|
int mode = zis->readU8();
|
||||||
|
bool rle = mode & 128;
|
||||||
|
int palSize = mode & 127;
|
||||||
|
PIXEL_T palette[128];
|
||||||
|
|
||||||
|
// fprintf(stderr,"rle %d palSize %d\n",rle,palSize);
|
||||||
|
|
||||||
|
for (int i = 0; i < palSize; i++) {
|
||||||
|
palette[i] = zis->READ_PIXEL();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (palSize == 1) {
|
||||||
|
PIXEL_T pix = palette[0];
|
||||||
|
FILL_RECT(tx,ty,tw,th,pix);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rle) {
|
||||||
|
if (palSize == 0) {
|
||||||
|
|
||||||
|
// raw
|
||||||
|
|
||||||
|
#ifdef CPIXEL
|
||||||
|
for (PIXEL_T* ptr = buf; ptr < buf+tw*th; ptr++) {
|
||||||
|
*ptr = zis->READ_PIXEL();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
zis->readBytes(buf, tw * th * (BPP / 8));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// packed pixels
|
||||||
|
int bppp = ((palSize > 16) ? 8 :
|
||||||
|
((palSize > 4) ? 4 : ((palSize > 2) ? 2 : 1)));
|
||||||
|
|
||||||
|
PIXEL_T* ptr = buf;
|
||||||
|
|
||||||
|
for (int i = 0; i < th; i++) {
|
||||||
|
PIXEL_T* eol = ptr + tw;
|
||||||
|
U8 byte = 0;
|
||||||
|
U8 nbits = 0;
|
||||||
|
|
||||||
|
while (ptr < eol) {
|
||||||
|
if (nbits == 0) {
|
||||||
|
byte = zis->readU8();
|
||||||
|
nbits = 8;
|
||||||
|
}
|
||||||
|
nbits -= bppp;
|
||||||
|
U8 index = (byte >> nbits) & ((1 << bppp) - 1) & 127;
|
||||||
|
*ptr++ = palette[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef FAVOUR_FILL_RECT
|
||||||
|
//fprintf(stderr,"copying data to screen %dx%d at %d,%d\n",tw,th,tx,ty);
|
||||||
|
IMAGE_RECT(tx,ty,tw,th,buf);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (palSize == 0) {
|
||||||
|
|
||||||
|
// plain RLE
|
||||||
|
|
||||||
|
PIXEL_T* ptr = buf;
|
||||||
|
PIXEL_T* end = ptr + th * tw;
|
||||||
|
while (ptr < end) {
|
||||||
|
PIXEL_T pix = zis->READ_PIXEL();
|
||||||
|
int len = 1;
|
||||||
|
int b;
|
||||||
|
do {
|
||||||
|
b = zis->readU8();
|
||||||
|
len += b;
|
||||||
|
} while (b == 255);
|
||||||
|
|
||||||
|
assert(len <= end - ptr);
|
||||||
|
|
||||||
|
#ifdef FAVOUR_FILL_RECT
|
||||||
|
int i = ptr - buf;
|
||||||
|
ptr += len;
|
||||||
|
|
||||||
|
int runX = i % tw;
|
||||||
|
int runY = i / tw;
|
||||||
|
|
||||||
|
if (runX + len > tw) {
|
||||||
|
if (runX != 0) {
|
||||||
|
FILL_RECT(tx+runX, ty+runY, tw-runX, 1, pix);
|
||||||
|
len -= tw-runX;
|
||||||
|
runX = 0;
|
||||||
|
runY++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len > tw) {
|
||||||
|
FILL_RECT(tx, ty+runY, tw, len/tw, pix);
|
||||||
|
runY += len / tw;
|
||||||
|
len = len % tw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len != 0) {
|
||||||
|
FILL_RECT(tx+runX, ty+runY, len, 1, pix);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
while (len-- > 0) *ptr++ = pix;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// palette RLE
|
||||||
|
|
||||||
|
PIXEL_T* ptr = buf;
|
||||||
|
PIXEL_T* end = ptr + th * tw;
|
||||||
|
while (ptr < end) {
|
||||||
|
int index = zis->readU8();
|
||||||
|
int len = 1;
|
||||||
|
if (index & 128) {
|
||||||
|
int b;
|
||||||
|
do {
|
||||||
|
b = zis->readU8();
|
||||||
|
len += b;
|
||||||
|
} while (b == 255);
|
||||||
|
|
||||||
|
assert(len <= end - ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
index &= 127;
|
||||||
|
|
||||||
|
PIXEL_T pix = palette[index];
|
||||||
|
|
||||||
|
#ifdef FAVOUR_FILL_RECT
|
||||||
|
int i = ptr - buf;
|
||||||
|
ptr += len;
|
||||||
|
|
||||||
|
int runX = i % tw;
|
||||||
|
int runY = i / tw;
|
||||||
|
|
||||||
|
if (runX + len > tw) {
|
||||||
|
if (runX != 0) {
|
||||||
|
FILL_RECT(tx+runX, ty+runY, tw-runX, 1, pix);
|
||||||
|
len -= tw-runX;
|
||||||
|
runX = 0;
|
||||||
|
runY++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len > tw) {
|
||||||
|
FILL_RECT(tx, ty+runY, tw, len/tw, pix);
|
||||||
|
runY += len / tw;
|
||||||
|
len = len % tw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len != 0) {
|
||||||
|
FILL_RECT(tx+runX, ty+runY, len, 1, pix);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
while (len-- > 0) *ptr++ = pix;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef FAVOUR_FILL_RECT
|
||||||
|
//fprintf(stderr,"copying data to screen %dx%d at %d,%d\n",tw,th,tx,ty);
|
||||||
|
IMAGE_RECT(tx,ty,tw,th,buf);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
zis->reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef ZRLE_DECODE_BPP
|
||||||
|
#undef READ_PIXEL
|
||||||
|
#undef PIXEL_T
|
|
@ -0,0 +1,310 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002 RealVNC Ltd. 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.
|
||||||
|
|
||||||
|
//
|
||||||
|
// zrleEncode.h - zrle encoding function.
|
||||||
|
//
|
||||||
|
// Before including this file, you must define a number of CPP macros.
|
||||||
|
//
|
||||||
|
// BPP should be 8, 16 or 32 depending on the bits per pixel.
|
||||||
|
// GET_IMAGE_INTO_BUF should be some code which gets a rectangle of pixel data
|
||||||
|
// into the given buffer. EXTRA_ARGS can be defined to pass any other
|
||||||
|
// arguments needed by GET_IMAGE_INTO_BUF.
|
||||||
|
//
|
||||||
|
// Note that the buf argument to ZRLE_ENCODE needs to be at least one pixel
|
||||||
|
// bigger than the largest tile of pixel data, since the ZRLE encoding
|
||||||
|
// algorithm writes to the position one past the end of the pixel data.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <rdr/OutStream.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
using namespace rdr;
|
||||||
|
|
||||||
|
/* __RFB_CONCAT2 concatenates its two arguments. __RFB_CONCAT2E does the same
|
||||||
|
but also expands its arguments if they are macros */
|
||||||
|
|
||||||
|
#ifndef __RFB_CONCAT2E
|
||||||
|
#define __RFB_CONCAT2(a,b) a##b
|
||||||
|
#define __RFB_CONCAT2E(a,b) __RFB_CONCAT2(a,b)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CPIXEL
|
||||||
|
#define PIXEL_T __RFB_CONCAT2E(rdr::U,BPP)
|
||||||
|
#define WRITE_PIXEL __RFB_CONCAT2E(writeOpaque,CPIXEL)
|
||||||
|
#define ZRLE_ENCODE __RFB_CONCAT2E(zrleEncode,CPIXEL)
|
||||||
|
#define ZRLE_ENCODE_TILE __RFB_CONCAT2E(zrleEncodeTile,CPIXEL)
|
||||||
|
#define BPPOUT 24
|
||||||
|
#else
|
||||||
|
#define PIXEL_T __RFB_CONCAT2E(rdr::U,BPP)
|
||||||
|
#define WRITE_PIXEL __RFB_CONCAT2E(writeOpaque,BPP)
|
||||||
|
#define ZRLE_ENCODE __RFB_CONCAT2E(zrleEncode,BPP)
|
||||||
|
#define ZRLE_ENCODE_TILE __RFB_CONCAT2E(zrleEncodeTile,BPP)
|
||||||
|
#define BPPOUT BPP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ZRLE_ONCE
|
||||||
|
#define ZRLE_ONCE
|
||||||
|
static const int bitsPerPackedPixel[] = {
|
||||||
|
0, 1, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
|
||||||
|
};
|
||||||
|
|
||||||
|
// The PaletteHelper class helps us build up the palette from pixel data by
|
||||||
|
// storing a reverse index using a simple hash-table
|
||||||
|
|
||||||
|
class PaletteHelper {
|
||||||
|
public:
|
||||||
|
enum { MAX_SIZE = 127 };
|
||||||
|
|
||||||
|
PaletteHelper()
|
||||||
|
{
|
||||||
|
memset(index, 255, sizeof(index));
|
||||||
|
size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int hash(rdr::U32 pix)
|
||||||
|
{
|
||||||
|
return (pix ^ (pix >> 17)) & 4095;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void insert(rdr::U32 pix)
|
||||||
|
{
|
||||||
|
if (size < MAX_SIZE) {
|
||||||
|
int i = hash(pix);
|
||||||
|
while (index[i] != 255 && key[i] != pix)
|
||||||
|
i++;
|
||||||
|
if (index[i] != 255) return;
|
||||||
|
|
||||||
|
index[i] = size;
|
||||||
|
key[i] = pix;
|
||||||
|
palette[size] = pix;
|
||||||
|
}
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int lookup(rdr::U32 pix)
|
||||||
|
{
|
||||||
|
assert(size <= MAX_SIZE);
|
||||||
|
int i = hash(pix);
|
||||||
|
while (index[i] != 255 && key[i] != pix)
|
||||||
|
i++;
|
||||||
|
if (index[i] != 255) return index[i];
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
rdr::U32 palette[MAX_SIZE];
|
||||||
|
rdr::U8 index[4096+MAX_SIZE];
|
||||||
|
rdr::U32 key[4096+MAX_SIZE];
|
||||||
|
int size;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void ZRLE_ENCODE_TILE (PIXEL_T* data, int w, int h, rdr::OutStream* os);
|
||||||
|
|
||||||
|
void ZRLE_ENCODE (int x, int y, int w, int h, rdr::OutStream* os,
|
||||||
|
rdr::ZlibOutStream* zos, void* buf
|
||||||
|
EXTRA_ARGS
|
||||||
|
)
|
||||||
|
{
|
||||||
|
zos->setUnderlying(os);
|
||||||
|
|
||||||
|
for (int ty = y; ty < y+h; ty += rfbZRLETileHeight) {
|
||||||
|
int th = rfbZRLETileHeight;
|
||||||
|
if (th > y+h-ty) th = y+h-ty;
|
||||||
|
for (int tx = x; tx < x+w; tx += rfbZRLETileWidth) {
|
||||||
|
int tw = rfbZRLETileWidth;
|
||||||
|
if (tw > x+w-tx) tw = x+w-tx;
|
||||||
|
|
||||||
|
GET_IMAGE_INTO_BUF(tx,ty,tw,th,buf);
|
||||||
|
|
||||||
|
ZRLE_ENCODE_TILE((PIXEL_T*)buf, tw, th, zos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zos->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ZRLE_ENCODE_TILE (PIXEL_T* data, int w, int h, rdr::OutStream* os)
|
||||||
|
{
|
||||||
|
// First find the palette and the number of runs
|
||||||
|
|
||||||
|
PaletteHelper ph;
|
||||||
|
|
||||||
|
int runs = 0;
|
||||||
|
int singlePixels = 0;
|
||||||
|
|
||||||
|
PIXEL_T* ptr = data;
|
||||||
|
PIXEL_T* end = ptr + h * w;
|
||||||
|
*end = ~*(end-1); // one past the end is different so the while loop ends
|
||||||
|
|
||||||
|
while (ptr < end) {
|
||||||
|
PIXEL_T pix = *ptr;
|
||||||
|
if (*++ptr != pix) {
|
||||||
|
singlePixels++;
|
||||||
|
} else {
|
||||||
|
while (*++ptr == pix) ;
|
||||||
|
runs++;
|
||||||
|
}
|
||||||
|
ph.insert(pix);
|
||||||
|
}
|
||||||
|
|
||||||
|
//fprintf(stderr,"runs %d, single pixels %d, paletteSize %d\n",
|
||||||
|
// runs, singlePixels, ph.size);
|
||||||
|
|
||||||
|
// Solid tile is a special case
|
||||||
|
|
||||||
|
if (ph.size == 1) {
|
||||||
|
os->writeU8(1);
|
||||||
|
os->WRITE_PIXEL(ph.palette[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to work out whether to use RLE and/or a palette. We do this by
|
||||||
|
// estimating the number of bytes which will be generated and picking the
|
||||||
|
// method which results in the fewest bytes. Of course this may not result
|
||||||
|
// in the fewest bytes after compression...
|
||||||
|
|
||||||
|
bool useRle = false;
|
||||||
|
bool usePalette = false;
|
||||||
|
|
||||||
|
int estimatedBytes = w * h * (BPPOUT/8); // start assuming raw
|
||||||
|
|
||||||
|
int plainRleBytes = ((BPPOUT/8)+1) * (runs + singlePixels);
|
||||||
|
|
||||||
|
if (plainRleBytes < estimatedBytes) {
|
||||||
|
useRle = true;
|
||||||
|
estimatedBytes = plainRleBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ph.size < 128) {
|
||||||
|
int paletteRleBytes = (BPPOUT/8) * ph.size + 2 * runs + singlePixels;
|
||||||
|
|
||||||
|
if (paletteRleBytes < estimatedBytes) {
|
||||||
|
useRle = true;
|
||||||
|
usePalette = true;
|
||||||
|
estimatedBytes = paletteRleBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ph.size < 17) {
|
||||||
|
int packedBytes = ((BPPOUT/8) * ph.size +
|
||||||
|
w * h * bitsPerPackedPixel[ph.size-1] / 8);
|
||||||
|
|
||||||
|
if (packedBytes < estimatedBytes) {
|
||||||
|
useRle = false;
|
||||||
|
usePalette = true;
|
||||||
|
estimatedBytes = packedBytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!usePalette) ph.size = 0;
|
||||||
|
|
||||||
|
os->writeU8((useRle ? 128 : 0) | ph.size);
|
||||||
|
|
||||||
|
for (int i = 0; i < ph.size; i++) {
|
||||||
|
os->WRITE_PIXEL(ph.palette[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (useRle) {
|
||||||
|
|
||||||
|
PIXEL_T* ptr = data;
|
||||||
|
PIXEL_T* end = ptr + w * h;
|
||||||
|
PIXEL_T* runStart;
|
||||||
|
PIXEL_T pix;
|
||||||
|
while (ptr < end) {
|
||||||
|
runStart = ptr;
|
||||||
|
pix = *ptr++;
|
||||||
|
while (*ptr == pix && ptr < end)
|
||||||
|
ptr++;
|
||||||
|
int len = ptr - runStart;
|
||||||
|
if (len <= 2 && usePalette) {
|
||||||
|
int index = ph.lookup(pix);
|
||||||
|
if (len == 2)
|
||||||
|
os->writeU8(index);
|
||||||
|
os->writeU8(index);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (usePalette) {
|
||||||
|
int index = ph.lookup(pix);
|
||||||
|
os->writeU8(index | 128);
|
||||||
|
} else {
|
||||||
|
os->WRITE_PIXEL(pix);
|
||||||
|
}
|
||||||
|
len -= 1;
|
||||||
|
while (len >= 255) {
|
||||||
|
os->writeU8(255);
|
||||||
|
len -= 255;
|
||||||
|
}
|
||||||
|
os->writeU8(len);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// no RLE
|
||||||
|
|
||||||
|
if (usePalette) {
|
||||||
|
|
||||||
|
// packed pixels
|
||||||
|
|
||||||
|
assert (ph.size < 17);
|
||||||
|
|
||||||
|
int bppp = bitsPerPackedPixel[ph.size-1];
|
||||||
|
|
||||||
|
PIXEL_T* ptr = data;
|
||||||
|
|
||||||
|
for (int i = 0; i < h; i++) {
|
||||||
|
U8 nbits = 0;
|
||||||
|
U8 byte = 0;
|
||||||
|
|
||||||
|
PIXEL_T* eol = ptr + w;
|
||||||
|
|
||||||
|
while (ptr < eol) {
|
||||||
|
PIXEL_T pix = *ptr++;
|
||||||
|
U8 index = ph.lookup(pix);
|
||||||
|
byte = (byte << bppp) | index;
|
||||||
|
nbits += bppp;
|
||||||
|
if (nbits >= 8) {
|
||||||
|
os->writeU8(byte);
|
||||||
|
nbits = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nbits > 0) {
|
||||||
|
byte <<= 8 - nbits;
|
||||||
|
os->writeU8(byte);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// raw
|
||||||
|
|
||||||
|
#ifdef CPIXEL
|
||||||
|
for (PIXEL_T* ptr = data; ptr < data+w*h; ptr++) {
|
||||||
|
os->WRITE_PIXEL(*ptr);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
os->writeBytes(data, w*h*(BPP/8));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef PIXEL_T
|
||||||
|
#undef WRITE_PIXEL
|
||||||
|
#undef ZRLE_ENCODE
|
||||||
|
#undef ZRLE_ENCODE_TILE
|
||||||
|
#undef BPPOUT
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1 @@
|
||||||
|
Manifest resource last updated at 16:28:39.34 on 09/09/2008
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10
external/source/reflective_vncdll/winvnc/Release/vncdll.dll.intermediate.manifest
vendored
Normal file
10
external/source/reflective_vncdll/winvnc/Release/vncdll.dll.intermediate.manifest
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
|
||||||
|
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
|
||||||
|
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||||
|
<security>
|
||||||
|
<requestedPrivileges>
|
||||||
|
<requestedExecutionLevel level='asInvoker' uiAccess='false' />
|
||||||
|
</requestedPrivileges>
|
||||||
|
</security>
|
||||||
|
</trustInfo>
|
||||||
|
</assembly>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue