├── LibVNCServer-0.9.7 ├── examples │ ├── blooptest.c │ ├── regiontest.c │ ├── simple.c │ ├── filetransfer.c │ ├── Makefile.am │ ├── simple15.c │ ├── colourmaptest.c │ ├── rotatetemplate.c │ ├── storepasswd.c │ ├── fontsel.c │ ├── rotate.c │ ├── pnmshow24.c │ ├── backchannel.c │ ├── pnmshow.c │ ├── vncev.c │ └── camera.c ├── test │ ├── blooptest.c │ ├── Makefile.am │ ├── cargstest.c │ └── copyrecttest.c ├── AUTHORS ├── classes │ ├── VncViewer.jar │ ├── ssl │ │ ├── VncViewer.jar │ │ ├── SignedVncViewer.jar │ │ ├── UltraViewerSSL.jar │ │ ├── SignedUltraViewerSSL.jar │ │ ├── Makefile.am │ │ ├── index.vnc │ │ ├── ultra.vnc │ │ ├── ultrasigned.vnc │ │ ├── ultraproxy.vnc │ │ ├── onetimekey │ │ └── proxy.vnc │ ├── Makefile.am │ ├── index.vnc │ └── javaviewer.pseudo_proxy.patch ├── contrib │ ├── Makefile.am │ └── zippy.c ├── libvncclient │ ├── Makefile.am │ ├── corre.c │ ├── rre.c │ ├── listen.c │ ├── minilzo.h │ ├── hextile.c │ ├── zlib.c │ ├── cursor.c │ └── ultra.c ├── vncterm │ ├── Makefile.am │ ├── ChangeLog │ ├── TODO │ ├── example.c │ ├── README │ ├── VNConsole.h │ ├── VNCommand.c │ └── LinuxVNC.c ├── rfb │ ├── rfbint.h │ └── rfbregion.h ├── libvncserver │ ├── scale.h │ ├── private.h │ ├── zrletypes.h │ ├── cutpaste.c │ ├── zrlepalettehelper.h │ ├── draw.c │ ├── tightvnc-filetransfer │ │ ├── handlefiletransferrequest.h │ │ ├── filetransfermsg.h │ │ ├── filelistinfo.h │ │ └── filelistinfo.c │ ├── d3des.h │ ├── Makefile.am │ ├── zrlepalettehelper.c │ ├── zrleoutstream.h │ ├── tableinitcmtemplate.c │ ├── minilzo.h │ ├── tabletranstemplate.c │ ├── vncauth.c │ ├── tableinittctemplate.c │ ├── font.c │ ├── tableinit24.c │ ├── zrleoutstream.c │ ├── zrle.c │ └── ultra.c ├── client_examples │ ├── Makefile.am │ ├── backchannel.c │ └── ppmtest.c ├── Makefile.am ├── TODO ├── libvncserver-config.in ├── LibVNCServer.spec.in ├── compile └── NEWS └── Android.mk /LibVNCServer-0.9.7/examples/blooptest.c: -------------------------------------------------------------------------------- 1 | #define BACKGROUND_LOOP_TEST 2 | #include "example.c" 3 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/test/blooptest.c: -------------------------------------------------------------------------------- 1 | #define BACKGROUND_LOOP_TEST 2 | #include "../examples/example.c" 3 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/examples/regiontest.c: -------------------------------------------------------------------------------- 1 | #define SRA_TEST 2 | #include "../libvncserver/rfbregion.c" 3 | 4 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/AUTHORS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/android-vnc-server/master/LibVNCServer-0.9.7/AUTHORS -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/classes/VncViewer.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/android-vnc-server/master/LibVNCServer-0.9.7/classes/VncViewer.jar -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/classes/ssl/VncViewer.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/android-vnc-server/master/LibVNCServer-0.9.7/classes/ssl/VncViewer.jar -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/classes/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST=VncViewer.jar index.vnc javaviewer.pseudo_proxy.patch 2 | 3 | SUBDIRS = ssl 4 | DIST_SUBDIRS = ssl 5 | 6 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/classes/ssl/SignedVncViewer.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/android-vnc-server/master/LibVNCServer-0.9.7/classes/ssl/SignedVncViewer.jar -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/classes/ssl/UltraViewerSSL.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/android-vnc-server/master/LibVNCServer-0.9.7/classes/ssl/UltraViewerSSL.jar -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/classes/ssl/SignedUltraViewerSSL.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/android-vnc-server/master/LibVNCServer-0.9.7/classes/ssl/SignedUltraViewerSSL.jar -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/contrib/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS = -I $(top_srcdir) 2 | LDADD = ../libvncserver/libvncserver.la @WSOCKLIB@ 3 | 4 | noinst_PROGRAMS=zippy 5 | 6 | zippy_SOURCES=zippy.c 7 | 8 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/classes/ssl/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST=VncViewer.jar index.vnc SignedVncViewer.jar proxy.vnc README ss_vncviewer onetimekey UltraViewerSSL.jar SignedUltraViewerSSL.jar ultra.vnc ultrasigned.vnc ultraproxy.vnc 2 | 3 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/examples/simple.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc,char** argv) 4 | { 5 | rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,8,3,4); 6 | server->frameBuffer=(char*)malloc(400*300*4); 7 | rfbInitServer(server); 8 | rfbRunEventLoop(server,-1,FALSE); 9 | return(0); 10 | } 11 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/examples/filetransfer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc,char** argv) 4 | { 5 | rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,8,3,4); 6 | server->frameBuffer=(char*)malloc(400*300*4); 7 | rfbRegisterTightVNCFileTransferExtension(); 8 | rfbInitServer(server); 9 | rfbRunEventLoop(server,-1,FALSE); 10 | return(0); 11 | } 12 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncclient/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS=-g -I $(top_srcdir) -I. -Wall 2 | 3 | libvncclient_la_SOURCES=cursor.c listen.c rfbproto.c sockets.c vncviewer.c minilzo.c 4 | 5 | noinst_HEADERS=lzoconf.h minilzo.h 6 | 7 | rfbproto.o: rfbproto.c corre.c hextile.c rre.c tight.c zlib.c zrle.c ultra.c 8 | 9 | EXTRA_DIST=corre.c hextile.c rre.c tight.c zlib.c zrle.c ultra.c 10 | 11 | $(libvncclient_la_OBJECTS): ../rfb/rfbclient.h 12 | 13 | lib_LTLIBRARIES=libvncclient.la 14 | 15 | 16 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/test/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS=-I $(top_srcdir) -g -Wall 2 | LDADD = ../libvncserver/libvncserver.la ../libvncclient/libvncclient.la @WSOCKLIB@ 3 | 4 | if HAVE_LIBPTHREAD 5 | BACKGROUND_TEST=blooptest 6 | ENCODINGS_TEST=encodingstest 7 | endif 8 | 9 | copyrecttest_LDADD=$(LDADD) -lm 10 | 11 | noinst_PROGRAMS=$(ENCODINGS_TEST) cargstest copyrecttest $(BACKGROUND_TEST) \ 12 | cursortest 13 | 14 | test: encodingstest$(EXEEXT) cargstest$(EXEEXT) copyrecttest$(EXEEXT) 15 | ./encodingstest && ./cargstest 16 | 17 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/vncterm/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS=-I $(top_srcdir) 2 | 3 | CONSOLE_SRCS=VNConsole.c 4 | 5 | noinst_HEADERS=VNConsole.h vga.h 6 | 7 | LDADD=../libvncserver/libvncserver.la @WSOCKLIB@ 8 | INCLUDES=-I. 9 | 10 | if LINUX 11 | bin_PROGRAMS=LinuxVNC 12 | LinuxVNC_SOURCES=LinuxVNC.c $(CONSOLE_SRCS) 13 | endif 14 | 15 | if ! MINGW 16 | VNCOMMAND=VNCommand 17 | endif 18 | 19 | noinst_PROGRAMS=example $(VNCOMMAND) 20 | example_SOURCES=example.c $(CONSOLE_SRCS) 21 | VNCommand_SOURCES=VNCommand.c $(CONSOLE_SRCS) 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/examples/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS=-I $(top_srcdir) -g -Wall 2 | LDADD = ../libvncserver/libvncserver.la @WSOCKLIB@ 3 | 4 | if OSX 5 | MAC=mac 6 | mac_LDFLAGS=-framework ApplicationServices -framework Carbon -framework IOKit 7 | endif 8 | 9 | if WITH_TIGHTVNC_FILETRANSFER 10 | FILETRANSFER=filetransfer 11 | endif 12 | 13 | if HAVE_LIBPTHREAD 14 | BLOOPTEST=blooptest 15 | endif 16 | 17 | noinst_HEADERS=radon.h rotatetemplate.c 18 | 19 | noinst_PROGRAMS=example pnmshow regiontest pnmshow24 fontsel \ 20 | vncev storepasswd colourmaptest simple simple15 $(MAC) \ 21 | $(FILETRANSFER) backchannel $(BLOOPTEST) camera rotate 22 | 23 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/rfb/rfbint.h: -------------------------------------------------------------------------------- 1 | #ifndef _RFB_RFBINT_H 2 | #define _RFB_RFBINT_H 1 3 | #ifndef _GENERATED_STDINT_H 4 | #define _GENERATED_STDINT_H "LibVNCServer 0.9.7" 5 | /* generated using a gnu compiler version gcc (GCC) 3.3.5 (Debian 1:3.3.5-8) Copyright (C) 2003 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ 6 | 7 | #include 8 | 9 | 10 | /* system headers have good uint64_t */ 11 | #ifndef _HAVE_UINT64_T 12 | #define _HAVE_UINT64_T 13 | #endif 14 | 15 | /* once */ 16 | #endif 17 | #endif 18 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/vncterm/ChangeLog: -------------------------------------------------------------------------------- 1 | included in LibVNCServer package, autoconf'ed it 2 | SetXCutText implemented 3 | fix for cargs 4 | attributes work. 5 | cursor in LinuxVNC is shown. 6 | paste works 7 | selection works (no cursor trails) 8 | LinuxVNC gets it's dimensions via ioctl TIOCGWINSZ 9 | First working key injection in LinuxVNC! 10 | Added Mouse marking 11 | added screenBuffer (so you have ASCII screen also) 12 | fixed CopyRect for scrolling (need to propagate to libvncserver) 13 | made VNCommand work (no prompt for bash, but else seems ok) 14 | added flag for VNCommand to send input only after a newline 15 | (good for interactive bash) 16 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/scale.h: -------------------------------------------------------------------------------- 1 | 2 | int ScaleX(rfbScreenInfoPtr from, rfbScreenInfoPtr to, int x); 3 | int ScaleY(rfbScreenInfoPtr from, rfbScreenInfoPtr to, int y); 4 | void rfbScaledCorrection(rfbScreenInfoPtr from, rfbScreenInfoPtr to, int *x, int *y, int *w, int *h, char *function); 5 | void rfbScaledScreenUpdateRect(rfbScreenInfoPtr screen, rfbScreenInfoPtr ptr, int x0, int y0, int w0, int h0); 6 | void rfbScaledScreenUpdate(rfbScreenInfoPtr screen, int x1, int y1, int x2, int y2); 7 | rfbScreenInfoPtr rfbScaledScreenAllocate(rfbClientPtr cl, int width, int height); 8 | rfbScreenInfoPtr rfbScalingFind(rfbClientPtr cl, int width, int height); 9 | void rfbScalingSetup(rfbClientPtr cl, int width, int height); 10 | int rfbSendNewScaleSize(rfbClientPtr cl); 11 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/vncterm/TODO: -------------------------------------------------------------------------------- 1 | VNConsole: 2 | LinuxVNC: 3 | VNCommand: 4 | make Control or Alt sequences work. 5 | Find out how to satisfy isatty(). => /dev/ptyN 6 | Fix check if child is alive. 7 | Add command line option for real interactive mode. 8 | 9 | done: 10 | 11 | .treat colours correctly (use /dev/vcsaN's attributes). 12 | .introduce per cell colours (for attributes) 13 | .fix cursor fuckup when selecting. 14 | .default to paste for right mouse button. 15 | .have an idea how to insert keys 16 | .convert VNCommand to an interactive shell (vncTerm) 17 | .bidirectional pipes (spawn a shell ...) 18 | .mark with mouse (copy text) 19 | .when scrolling, cursor must be hidden! 20 | 21 | modifiedRegion which are copied with CopyRect have to be modified also. 22 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/examples/simple15.c: -------------------------------------------------------------------------------- 1 | /* This example shows how to use 15-bit (which is handled as 16-bit 2 | internally). */ 3 | 4 | #include 5 | 6 | int main(int argc,char** argv) 7 | { 8 | int i,j; 9 | uint16_t* f; 10 | 11 | rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,5,3,2); 12 | 13 | server->frameBuffer=(char*)malloc(400*300*2); 14 | f=(uint16_t*)server->frameBuffer; 15 | for(j=0;j<300;j++) 16 | for(i=0;i<400;i++) 17 | f[j*400+i]=/* red */ ((j*32/300) << 10) | 18 | /* green */ (((j+400-i)*32/700) << 5) | 19 | /* blue */ ((i*32/400)); 20 | 21 | rfbInitServer(server); 22 | rfbRunEventLoop(server,-1,FALSE); 23 | return(0); 24 | } 25 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/classes/index.vnc: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | $USER's $DESKTOP desktop ($DISPLAY) 10 | 11 | 13 | 14 | 15 | 16 |
17 | www.TightVNC.com 18 | 19 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/vncterm/example.c: -------------------------------------------------------------------------------- 1 | #include "VNConsole.h" 2 | #include "vga.h" 3 | 4 | int main(int argc,char **argv) 5 | { 6 | vncConsolePtr c=vcGetConsole(&argc,argv,80,25,&vgaFont,FALSE); 7 | char buffer[1024]; 8 | int i,j,l; 9 | for(j=32;j<256;j+=16) { 10 | vcPrintF(c,"%02x: ",j); 11 | for(i=j;i ",i); 18 | vcGetString(c,buffer,1024); 19 | l=strlen(buffer)-1; 20 | while(l>=0 && buffer[l]=='\n') 21 | buffer[l]=0; 22 | if(!strcmp(buffer,"quit")) 23 | return(0); 24 | if(!strcmp(buffer,"s")) 25 | vcScroll(c,2); 26 | if(!strcmp(buffer,"S")) 27 | vcScroll(c,-2); 28 | i++; 29 | } 30 | return(0); 31 | } 32 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/client_examples/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS=-I $(top_srcdir) -g -Wall 2 | LDADD = ../libvncclient/libvncclient.la @WSOCKLIB@ 3 | 4 | if WITH_FFMPEG 5 | FFMPEG_HOME=@with_ffmpeg@ 6 | 7 | if HAVE_MP3LAME 8 | MP3LAME_LIB=-lmp3lame 9 | endif 10 | 11 | vnc2mpg_CFLAGS=-I$(FFMPEG_HOME)/libavformat -I$(FFMPEG_HOME)/libavcodec -I$(FFMPEG_HOME)/libavutil 12 | vnc2mpg_LDADD=$(LDADD) $(FFMPEG_HOME)/libavformat/libavformat.a $(FFMPEG_HOME)/libavcodec/libavcodec.a $(MP3LAME_LIB) -lm 13 | 14 | FFMPEG_CLIENT=vnc2mpg 15 | endif 16 | 17 | if HAVE_LIBSDL 18 | SDLVIEWER=SDLvncviewer 19 | 20 | SDLvncviewer_CFLAGS=$(SDL_CFLAGS) 21 | 22 | # thanks to autoconf, this looks ugly 23 | SDLvncviewer_LDADD=$(LDADD) $(SDL_LIBS) 24 | endif 25 | 26 | noinst_PROGRAMS=ppmtest $(SDLVIEWER) $(FFMPEG_CLIENT) backchannel 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/examples/colourmaptest.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main(int argc,char** argv) 5 | { 6 | int i; 7 | uint8_t bytes[256*3]; 8 | 9 | rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,256,256,8,1,1); 10 | 11 | server->serverFormat.trueColour=FALSE; 12 | server->colourMap.count=256; 13 | server->colourMap.is16=FALSE; 14 | for(i=0;i<256;i++) { 15 | bytes[i*3+0]=255-i; /* red */ 16 | bytes[i*3+1]=0; /* green */ 17 | bytes[i*3+2]=i; /* blue */ 18 | } 19 | bytes[128*3+0]=0xff; 20 | bytes[128*3+1]=0; 21 | bytes[128*3+2]=0; 22 | server->colourMap.data.bytes=bytes; 23 | 24 | server->frameBuffer=(char*)malloc(256*256); 25 | for(i=0;i<256*256;i++) 26 | server->frameBuffer[i]=(i/256); 27 | 28 | rfbInitServer(server); 29 | rfbRunEventLoop(server,-1,FALSE); 30 | 31 | return(0); 32 | } 33 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/test/cargstest.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc,char** argv) 4 | { 5 | int fake_argc=6; 6 | char* fake_argv[6]={ 7 | "dummy_program","-alwaysshared","-httpport","3002","-nothing","-dontdisconnect" 8 | }; 9 | rfbScreenInfoPtr screen; 10 | rfbBool ret=0; 11 | 12 | screen = rfbGetScreen(&fake_argc,fake_argv,1024,768,8,3,1); 13 | #define CHECK(a,b) if(screen->a!=b) { fprintf(stderr,#a " is %d (should be " #b ")\n",screen->a); ret=1; } 14 | CHECK(width,1024); 15 | CHECK(height,768); 16 | CHECK(alwaysShared,TRUE); 17 | CHECK(httpPort,3002); 18 | CHECK(dontDisconnect,TRUE); 19 | if(fake_argc!=2) { 20 | fprintf(stderr,"fake_argc is %d (should be 2)\n",fake_argc); 21 | ret=1; 22 | } 23 | if(strcmp(fake_argv[1],"-nothing")) { 24 | fprintf(stderr,"fake_argv[1] is %s (should be -nothing)\n",fake_argv[1]); 25 | ret=1; 26 | } 27 | return ret; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/Makefile.am: -------------------------------------------------------------------------------- 1 | CFLAGS=-g -Wall 2 | 3 | if WITH_X11VNC 4 | X11VNC=x11vnc 5 | endif 6 | 7 | SUBDIRS=libvncserver examples contrib libvncclient vncterm classes client_examples test $(X11VNC) 8 | DIST_SUBDIRS=libvncserver examples contrib libvncclient vncterm classes client_examples test 9 | 10 | bin_SCRIPTS = libvncserver-config 11 | 12 | includedir=$(prefix)/include/rfb 13 | #include_HEADERS=rfb.h rfbconfig.h rfbint.h rfbproto.h keysym.h rfbregion.h 14 | 15 | include_HEADERS=rfb/rfb.h rfb/rfbconfig.h rfb/rfbint.h rfb/rfbproto.h \ 16 | rfb/keysym.h rfb/rfbregion.h rfb/rfbclient.h 17 | 18 | $(PACKAGE)-$(VERSION).tar.gz: dist 19 | 20 | if HAVE_RPM 21 | # Rule to build RPM distribution package 22 | rpm: $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE).spec 23 | cp $(PACKAGE)-$(VERSION).tar.gz @RPMSOURCEDIR@ 24 | rpmbuild -ba $(PACKAGE).spec 25 | endif 26 | 27 | t: 28 | $(MAKE) -C test test 29 | 30 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/classes/ssl/index.vnc: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | $USER's $DESKTOP desktop ($DISPLAY) 17 | 18 | 20 | 21 | 22 | $PARAMS 23 | 24 |
25 | TightVNC site 26 | 27 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/private.h: -------------------------------------------------------------------------------- 1 | #ifndef RFB_PRIVATE_H 2 | #define RFB_PRIVATE_H 3 | 4 | /* from cursor.c */ 5 | 6 | void rfbShowCursor(rfbClientPtr cl); 7 | void rfbHideCursor(rfbClientPtr cl); 8 | void rfbRedrawAfterHideCursor(rfbClientPtr cl,sraRegionPtr updateRegion); 9 | 10 | /* from main.c */ 11 | 12 | rfbClientPtr rfbClientIteratorHead(rfbClientIteratorPtr i); 13 | 14 | /* from tight.c */ 15 | 16 | #ifdef LIBVNCSERVER_HAVE_LIBZ 17 | #ifdef LIBVNCSERVER_HAVE_LIBJPEG 18 | extern void rfbTightCleanup(rfbScreenInfoPtr screen); 19 | #endif 20 | 21 | /* from zlib.c */ 22 | extern void rfbZlibCleanup(rfbScreenInfoPtr screen); 23 | 24 | /* from zrle.c */ 25 | void rfbFreeZrleData(rfbClientPtr cl); 26 | 27 | #endif 28 | 29 | 30 | /* from ultra.c */ 31 | 32 | extern void rfbUltraCleanup(rfbScreenInfoPtr screen); 33 | extern void rfbFreeUltraData(rfbClientPtr cl); 34 | 35 | /* from rre.c */ 36 | 37 | extern void rfbRRECleanup(rfbScreenInfoPtr screen); 38 | 39 | /* from corre.c */ 40 | 41 | extern void rfbCoRRECleanup(rfbScreenInfoPtr screen); 42 | 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/TODO: -------------------------------------------------------------------------------- 1 | immediate: 2 | ---------- 3 | 4 | make SDLvncviewer more versatile 5 | - Send modifiers key-up on leave focus, 6 | - test for missing keys (especially "[]{}" with ./examples/mac), 7 | - map Apple/Linux/Windows keys onto each other, 8 | - keyboard repeat, 9 | - introduce scrollbars, 10 | - handle selection 11 | style fixes: use Linux' coding guidelines & ANSIfy tightvnc-filetransfer: 12 | discuss on list 13 | LibVNCClient cleanup: prefix with "rfbClient", and make sure it does 14 | not deliberately die() or exit() anywhere! 15 | java vncviewer doesn't do colour cursors? 16 | MinGW32 doesn't do fcntl on sockets; use setsockopt instead... 17 | make corre work again (libvncclient or libvncserver?) 18 | teach SDLvncviewer about CopyRect... 19 | implement "-record" in libvncclient 20 | 21 | later: 22 | ------ 23 | 24 | selectbox: scroll bars 25 | authentification schemes (secure vnc) 26 | IO function ptr exists; now explain how to tunnel and implement a 27 | client address restriction scheme. 28 | using Hermes library for fast colour translations. 29 | VisualNaCro testing 30 | 31 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/classes/ssl/ultra.vnc: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | $USER's $DESKTOP desktop ($DISPLAY) 17 | 18 | 20 | 21 | 22 | 23 | 24 | $PARAMS 25 | 26 |
27 | UltraVNC site 28 | 29 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/classes/ssl/ultrasigned.vnc: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | $USER's $DESKTOP desktop ($DISPLAY) 17 | 18 | 20 | 21 | 22 | 23 | 24 | $PARAMS 25 | 26 |
27 | UltraVNC site 28 | 29 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/classes/ssl/ultraproxy.vnc: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | $USER's $DESKTOP desktop ($DISPLAY) 17 | 18 | 20 | 21 | 22 | 23 | 24 | $PARAMS 25 | 26 |
27 | UltraVNC site 28 | 29 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/zrletypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002 RealVNC Ltd. All Rights Reserved. 3 | * 4 | * This is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This software is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this software; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 17 | * USA. 18 | */ 19 | 20 | #ifndef __ZRLE_TYPES_H__ 21 | #define __ZRLE_TYPES_H__ 22 | 23 | typedef unsigned char zrle_U8; 24 | typedef unsigned short zrle_U16; 25 | typedef unsigned int zrle_U32; 26 | typedef signed char zrle_S8; 27 | typedef signed short zrle_S16; 28 | typedef signed int zrle_S32; 29 | 30 | #endif /* __ZRLE_TYPES_H__ */ 31 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/vncterm/README: -------------------------------------------------------------------------------- 1 | 2 | In this stage (beta), there are two programs functional: 3 | 4 | LinuxVNC 5 | monitor a virtual console (text mode) of Linux. You need 6 | root privileges, or at least be in the "tty" group, because 7 | it reads /dev/vcsN and writes /dev/ttyN. 8 | It follows the same idea as WinVNC, x11vnc or OSXvnc, i.e. it 9 | takes an existing desktop and exports it via RFB (VNC), just that 10 | LinuxVNC exports text. 11 | 12 | VNCommand 13 | executes redirecting stdin from a vncviewer and stdout & 14 | stderr to the vnc clients. This might be renamed to vncTerm if 15 | there are some term capabilities added (up to now, bash doesn't look 16 | nice). Colours and other ANSI sequences need to be added. 17 | 18 | My original plan was to create a program named vncTerm. It was meant to 19 | overcome incompatibilities between different TERMs, but I found "screen" to 20 | be just such a program. Maybe once some time in the future I'll make a 21 | patch for screen to use VNConsole to export it's contents via RFB... 22 | 23 | These two programs are a simple application of LibVNCServer with a small 24 | console layer in between (VNConsole). You can use them under the terms 25 | (not vncTerms ;-) of the GPL. They where written by Johannes E. Schindelin. 26 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/classes/ssl/onetimekey: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # usage: onetimekey path/to/mycert.pem 4 | # 5 | # Takes an openssl cert+key pem file and turns into a long string 6 | # for the x11vnc SSL VNC Java Viewer. 7 | # 8 | # The Java applet URL parameter can be oneTimeKey= where str is 9 | # the output of this program, or can be oneTimeKey=PROMPT in which 10 | # case the applet will ask you to paste in the string. 11 | # 12 | # The problem trying to be solved here is it is difficult to get 13 | # the Java applet to have or use a keystore with the key saved 14 | # in it. Also, as the name implies, an HTTPS server can create 15 | # a one time key to send to the applet (the user has already 16 | # logged in via password to the HTTPS server). 17 | 18 | in=$1 19 | der=/tmp/1time$$.der 20 | touch $der 21 | chmod 600 $der 22 | 23 | openssl pkcs8 -topk8 -nocrypt -in "$in" -out "$der" -outform der 24 | 25 | pbinhex=/tmp/pbinhex.$$ 26 | cat > $pbinhex <frameBuffer; 7 | int i, j, w = screen->width, h = screen->height; 8 | OUT_T* newBuffer = (OUT_T*)malloc(w * h * sizeof(OUT_T)); 9 | 10 | for (j = 0; j < h; j++) 11 | for (i = 0; i < w; i++) 12 | newBuffer[FUNC(i, j)] = buffer[i + j * w]; 13 | 14 | memcpy(buffer, newBuffer, w * h * sizeof(OUT_T)); 15 | free(newBuffer); 16 | 17 | #ifdef SWAPDIMENSIONS 18 | screen->width = h; 19 | screen->paddedWidthInBytes = h * OUT / 8; 20 | screen->height = w; 21 | 22 | { 23 | rfbClientIteratorPtr iterator; 24 | rfbClientPtr cl; 25 | iterator = rfbGetClientIterator(screen); 26 | while ((cl = rfbClientIteratorNext(iterator)) != NULL) 27 | cl->newFBSizePending = 1; 28 | } 29 | #endif 30 | 31 | rfbMarkRectAsModified(screen, 0, 0, screen->width, screen->height); 32 | } 33 | 34 | #if OUT == 32 35 | void FUNCNAME(rfbScreenInfoPtr screen) { 36 | if (screen->serverFormat.bitsPerPixel == 32) 37 | CONCAT2E(FUNCNAME,32)(screen); 38 | else if (screen->serverFormat.bitsPerPixel == 16) 39 | CONCAT2E(FUNCNAME,16)(screen); 40 | else if (screen->serverFormat.bitsPerPixel == 8) 41 | CONCAT2E(FUNCNAME,8)(screen); 42 | else { 43 | rfbErr("Unsupported pixel depth: %d\n", 44 | screen->serverFormat.bitsPerPixel); 45 | return; 46 | } 47 | } 48 | #endif 49 | 50 | #undef FUNCTION 51 | #undef OUT 52 | 53 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/test/copyrecttest.c: -------------------------------------------------------------------------------- 1 | #ifdef __STRICT_ANSI__ 2 | #define _BSD_SOURCE 3 | #endif 4 | #include 5 | #include 6 | 7 | static void initBackground(rfbScreenInfoPtr server) 8 | { 9 | unsigned int i,j; 10 | 11 | for(i=0;iwidth;i++) 12 | for(j=0;jheight;j++) { 13 | server->frameBuffer[(j*server->width+i)*4+0]=i&0xff; 14 | server->frameBuffer[(j*server->width+i)*4+1]=j&0xff; 15 | server->frameBuffer[(j*server->width+i)*4+2]=(i*j)&0xff; 16 | } 17 | } 18 | 19 | int main(int argc,char** argv) 20 | { 21 | int width=400,height=300,w=20,x,y; 22 | double r,phi=0; 23 | 24 | rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,width,height,8,3,4); 25 | server->frameBuffer=(char*)malloc(width*height*4); 26 | initBackground(server); 27 | server->deferUpdateTime=0; 28 | rfbInitServer(server); 29 | 30 | r=0; 31 | while(1) { 32 | if(r<=0) { 33 | initBackground(server); 34 | rfbMarkRectAsModified(server,0,0,width,height); 35 | r=0.43; 36 | phi=0; 37 | } else { 38 | r-=0.0001; 39 | phi+=0.02; 40 | if(phi>2*M_PI) 41 | phi-=2*M_PI; 42 | } 43 | x=width*(0.5+cos(phi)*r); 44 | y=height*(0.5+sin(phi)*r); 45 | if(x>=0 && y>=0 && x+w<=width && y+w<=height) { 46 | unsigned int dx=width*0.5*(1-cos(phi)*r)-x, 47 | dy=height*0.5*(1-sin(phi)*r)-y; 48 | rfbDoCopyRect(server,x,y,x+w,y+w,-dx,-dy); 49 | } 50 | rfbProcessEvents(server,50000); 51 | } 52 | return(0); 53 | } 54 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/cutpaste.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cutpaste.c - routines to deal with cut & paste buffers / selection. 3 | */ 4 | 5 | /* 6 | * OSXvnc Copyright (C) 2001 Dan McGuirk . 7 | * Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge. 8 | * All Rights Reserved. 9 | * 10 | * This is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This software is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this software; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 23 | * USA. 24 | */ 25 | 26 | #include 27 | 28 | 29 | /* 30 | * rfbSetXCutText sets the cut buffer to be the given string. We also clear 31 | * the primary selection. Ideally we'd like to set it to the same thing, but I 32 | * can't work out how to do that without some kind of helper X client. 33 | */ 34 | 35 | void rfbGotXCutText(rfbScreenInfoPtr rfbScreen, char *str, int len) 36 | { 37 | rfbSendServerCutText(rfbScreen, str, len); 38 | } 39 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/examples/storepasswd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * OSXvnc Copyright (C) 2001 Dan McGuirk . 3 | * Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge. 4 | * All Rights Reserved. 5 | * 6 | * This is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This software is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this software; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 19 | * USA. 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | static void usage(void) 26 | { 27 | printf("\nusage: storepasswd \n\n"); 28 | 29 | printf("Stores a password in encrypted format.\n"); 30 | printf("The resulting file can be used with the -rfbauth argument to OSXvnc.\n\n"); 31 | exit(1); 32 | } 33 | 34 | int main(int argc, char *argv[]) 35 | { 36 | if (argc != 3) 37 | usage(); 38 | 39 | if (rfbEncryptAndStorePasswd(argv[1], argv[2]) != 0) { 40 | printf("storing password failed.\n"); 41 | return 1; 42 | } else { 43 | printf("storing password succeeded.\n"); 44 | return 0; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/zrlepalettehelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002 RealVNC Ltd. All Rights Reserved. 3 | * Copyright (C) 2003 Sun Microsystems, Inc. 4 | * 5 | * This is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This software is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this software; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 18 | * USA. 19 | */ 20 | 21 | /* 22 | * The PaletteHelper class helps us build up the palette from pixel data by 23 | * storing a reverse index using a simple hash-table 24 | */ 25 | 26 | #ifndef __ZRLE_PALETTE_HELPER_H__ 27 | #define __ZRLE_PALETTE_HELPER_H__ 28 | 29 | #include "zrletypes.h" 30 | 31 | #define ZRLE_PALETTE_MAX_SIZE 127 32 | 33 | typedef struct { 34 | zrle_U32 palette[ZRLE_PALETTE_MAX_SIZE]; 35 | zrle_U8 index[ZRLE_PALETTE_MAX_SIZE + 4096]; 36 | zrle_U32 key[ZRLE_PALETTE_MAX_SIZE + 4096]; 37 | int size; 38 | } zrlePaletteHelper; 39 | 40 | void zrlePaletteHelperInit (zrlePaletteHelper *helper); 41 | void zrlePaletteHelperInsert(zrlePaletteHelper *helper, 42 | zrle_U32 pix); 43 | int zrlePaletteHelperLookup(zrlePaletteHelper *helper, 44 | zrle_U32 pix); 45 | 46 | #endif /* __ZRLE_PALETTE_HELPER_H__ */ 47 | -------------------------------------------------------------------------------- /Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_SRC_FILES:= \ 5 | fbvncserver.c \ 6 | LibVNCServer-0.9.7/libvncserver/main.c \ 7 | LibVNCServer-0.9.7/libvncserver/rfbserver.c \ 8 | LibVNCServer-0.9.7/libvncserver/rfbregion.c \ 9 | LibVNCServer-0.9.7/libvncserver/auth.c \ 10 | LibVNCServer-0.9.7/libvncserver/sockets.c \ 11 | LibVNCServer-0.9.7/libvncserver/stats.c \ 12 | LibVNCServer-0.9.7/libvncserver/corre.c \ 13 | LibVNCServer-0.9.7/libvncserver/hextile.c \ 14 | LibVNCServer-0.9.7/libvncserver/rre.c \ 15 | LibVNCServer-0.9.7/libvncserver/translate.c \ 16 | LibVNCServer-0.9.7/libvncserver/cutpaste.c \ 17 | LibVNCServer-0.9.7/libvncserver/httpd.c \ 18 | LibVNCServer-0.9.7/libvncserver/cursor.c \ 19 | LibVNCServer-0.9.7/libvncserver/font.c \ 20 | LibVNCServer-0.9.7/libvncserver/draw.c \ 21 | LibVNCServer-0.9.7/libvncserver/selbox.c \ 22 | LibVNCServer-0.9.7/libvncserver/d3des.c \ 23 | LibVNCServer-0.9.7/libvncserver/vncauth.c \ 24 | LibVNCServer-0.9.7/libvncserver/cargs.c \ 25 | LibVNCServer-0.9.7/libvncserver/minilzo.c \ 26 | LibVNCServer-0.9.7/libvncserver/ultra.c \ 27 | LibVNCServer-0.9.7/libvncserver/scale.c \ 28 | LibVNCServer-0.9.7/libvncserver/zlib.c \ 29 | LibVNCServer-0.9.7/libvncserver/zrle.c \ 30 | LibVNCServer-0.9.7/libvncserver/zrleoutstream.c \ 31 | LibVNCServer-0.9.7/libvncserver/zrlepalettehelper.c \ 32 | LibVNCServer-0.9.7/libvncserver/zywrletemplate.c \ 33 | LibVNCServer-0.9.7/libvncserver/tight.c 34 | 35 | LOCAL_C_INCLUDES := \ 36 | $(LOCAL_PATH) \ 37 | $(LOCAL_PATH)/LibVNCServer-0.9.7/libvncserver \ 38 | $(LOCAL_PATH)/LibVNCServer-0.9.7 \ 39 | external/zlib \ 40 | external/jpeg 41 | 42 | LOCAL_SHARED_LIBRARIES := libz 43 | LOCAL_STATIC_LIBRARIES := libjpeg 44 | 45 | LOCAL_MODULE:= androidvncserver 46 | 47 | include $(BUILD_EXECUTABLE) 48 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/draw.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void rfbFillRect(rfbScreenInfoPtr s,int x1,int y1,int x2,int y2,rfbPixel col) 4 | { 5 | int rowstride = s->paddedWidthInBytes, bpp = s->bitsPerPixel>>3; 6 | int i,j; 7 | char* colour=(char*)&col; 8 | 9 | if(!rfbEndianTest) 10 | colour += 4-bpp; 11 | for(j=y1;jframeBuffer+j*rowstride+i*bpp,colour,bpp); 14 | rfbMarkRectAsModified(s,x1,y1,x2,y2); 15 | } 16 | 17 | #define SETPIXEL(x,y) \ 18 | memcpy(s->frameBuffer+(y)*rowstride+(x)*bpp,colour,bpp) 19 | 20 | void rfbDrawPixel(rfbScreenInfoPtr s,int x,int y,rfbPixel col) 21 | { 22 | int rowstride = s->paddedWidthInBytes, bpp = s->bitsPerPixel>>3; 23 | char* colour=(char*)&col; 24 | 25 | if(!rfbEndianTest) 26 | colour += 4-bpp; 27 | SETPIXEL(x,y); 28 | rfbMarkRectAsModified(s,x,y,x+1,y+1); 29 | } 30 | 31 | void rfbDrawLine(rfbScreenInfoPtr s,int x1,int y1,int x2,int y2,rfbPixel col) 32 | { 33 | int rowstride = s->paddedWidthInBytes, bpp = s->bitsPerPixel>>3; 34 | int i; 35 | char* colour=(char*)&col; 36 | 37 | if(!rfbEndianTest) 38 | colour += 4-bpp; 39 | 40 | #define SWAPPOINTS { i=x1; x1=x2; x2=i; i=y1; y1=y2; y2=i; } 41 | if(abs(x1-x2)y2) 43 | SWAPPOINTS 44 | for(i=y1;i<=y2;i++) 45 | SETPIXEL(x1+(i-y1)*(x2-x1)/(y2-y1),i); 46 | /* TODO: Maybe make this more intelligently? */ 47 | if(x2x2) 51 | SWAPPOINTS 52 | else if(x1==x2) { 53 | rfbDrawPixel(s,x1,y1,col); 54 | return; 55 | } 56 | for(i=x1;i<=x2;i++) 57 | SETPIXEL(i,y1+(i-x1)*(y2-y1)/(x2-x1)); 58 | if(y2 30 | 31 | 32 | void InitFileTransfer(); 33 | int SetFtpRoot(char* path); 34 | void EnableFileTransfer(rfbBool enable); 35 | rfbBool IsFileTransferEnabled(); 36 | char* GetFtpRoot(); 37 | 38 | void HandleFileListRequest(rfbClientPtr cl, rfbTightClientRec* data); 39 | void HandleFileDownloadRequest(rfbClientPtr cl, rfbTightClientRec* data); 40 | void HandleFileDownloadCancelRequest(rfbClientPtr cl, rfbTightClientRec* data); 41 | void HandleFileUploadRequest(rfbClientPtr cl, rfbTightClientRec* data); 42 | void HandleFileUploadDataRequest(rfbClientPtr cl, rfbTightClientRec* data); 43 | void HandleFileUploadFailedRequest(rfbClientPtr cl, rfbTightClientRec* data); 44 | void HandleFileCreateDirRequest(rfbClientPtr cl, rfbTightClientRec* data); 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/d3des.h: -------------------------------------------------------------------------------- 1 | #ifndef D3DES_H 2 | #define D3DES_H 3 | 4 | /* 5 | * This is D3DES (V5.09) by Richard Outerbridge with the double and 6 | * triple-length support removed for use in VNC. 7 | * 8 | * These changes are: 9 | * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. 10 | * 11 | * This software is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 | */ 15 | 16 | /* d3des.h - 17 | * 18 | * Headers and defines for d3des.c 19 | * Graven Imagery, 1992. 20 | * 21 | * Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge 22 | * (GEnie : OUTER; CIS : [71755,204]) 23 | */ 24 | 25 | #define EN0 0 /* MODE == encrypt */ 26 | #define DE1 1 /* MODE == decrypt */ 27 | 28 | extern void rfbDesKey(unsigned char *, int); 29 | /* hexkey[8] MODE 30 | * Sets the internal key register according to the hexadecimal 31 | * key contained in the 8 bytes of hexkey, according to the DES, 32 | * for encryption or decryption according to MODE. 33 | */ 34 | 35 | extern void rfbUseKey(unsigned long *); 36 | /* cookedkey[32] 37 | * Loads the internal key register with the data in cookedkey. 38 | */ 39 | 40 | extern void rfbCPKey(unsigned long *); 41 | /* cookedkey[32] 42 | * Copies the contents of the internal key register into the storage 43 | * located at &cookedkey[0]. 44 | */ 45 | 46 | extern void rfbDes(unsigned char *, unsigned char *); 47 | /* from[8] to[8] 48 | * Encrypts/Decrypts (according to the key currently loaded in the 49 | * internal key register) one block of eight bytes at address 'from' 50 | * into the block at address 'to'. They can be the same. 51 | */ 52 | 53 | /* d3des.h V5.09 rwo 9208.04 15:06 Graven Imagery 54 | ********************************************************************/ 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver-config.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | exec_prefix_set=no 6 | includedir=@includedir@ 7 | libdir=@libdir@ 8 | 9 | # if this script is in the same directory as libvncserver-config.in, assume not installed 10 | if [ -f "`dirname "$0"`/libvncserver-config.in" ]; then 11 | dir="`dirname "$0"`" 12 | prefix="`cd "$dir"; pwd`" 13 | includedir="$prefix" 14 | libdir="$prefix/libvncserver/.libs $prefix/libvncclient/.libs" 15 | fi 16 | 17 | usage="\ 18 | Usage: @PACKAGE@-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--link] [--libs] [--cflags]" 19 | 20 | if test $# -eq 0; then 21 | echo "${usage}" 1>&2 22 | exit 1 23 | fi 24 | 25 | while test $# -gt 0; do 26 | case "$1" in 27 | -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; 28 | *) optarg= ;; 29 | esac 30 | 31 | case $1 in 32 | --prefix=*) 33 | prefix=$optarg 34 | if test $exec_prefix_set = no ; then 35 | exec_prefix=$optarg 36 | fi 37 | ;; 38 | --prefix) 39 | echo $prefix 40 | ;; 41 | --exec-prefix=*) 42 | exec_prefix=$optarg 43 | exec_prefix_set=yes 44 | ;; 45 | --exec-prefix) 46 | echo $exec_prefix 47 | ;; 48 | --version) 49 | echo @VERSION@ 50 | ;; 51 | --cflags) 52 | if [ "$includedir" != /usr/include ]; then 53 | includes=-I"$includedir" 54 | fi 55 | echo "$includes" 56 | ;; 57 | --libs) 58 | libs="" 59 | for dir in $libdir; do 60 | libs="$libs -L$dir" 61 | if [ "`uname`" = "SunOS" ]; then 62 | # why only Solaris?? 63 | libs="$libs -R$dir" 64 | fi 65 | done 66 | echo "$libs" -lvncserver -lvncclient @LIBS@ @WSOCKLIB@ 67 | ;; 68 | --link) 69 | echo @CC@ 70 | ;; 71 | *) 72 | echo "${usage}" 1>&2 73 | exit 1 74 | ;; 75 | esac 76 | shift 77 | done 78 | 79 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS=-g -Wall -I $(top_srcdir) 2 | 3 | if WITH_TIGHTVNC_FILETRANSFER 4 | TIGHTVNCFILETRANSFERHDRS=tightvnc-filetransfer/filelistinfo.h \ 5 | tightvnc-filetransfer/filetransfermsg.h \ 6 | tightvnc-filetransfer/handlefiletransferrequest.h \ 7 | tightvnc-filetransfer/rfbtightproto.h 8 | 9 | TIGHTVNCFILETRANSFERSRCS = tightvnc-filetransfer/rfbtightserver.c \ 10 | tightvnc-filetransfer/handlefiletransferrequest.c \ 11 | tightvnc-filetransfer/filetransfermsg.c \ 12 | tightvnc-filetransfer/filelistinfo.c 13 | endif 14 | 15 | includedir=$(prefix)/include/rfb 16 | #include_HEADERS=rfb.h rfbconfig.h rfbint.h rfbproto.h keysym.h rfbregion.h 17 | 18 | include_HEADERS=../rfb/rfb.h ../rfb/rfbconfig.h ../rfb/rfbint.h \ 19 | ../rfb/rfbproto.h ../rfb/keysym.h ../rfb/rfbregion.h ../rfb/rfbclient.h 20 | 21 | noinst_HEADERS=d3des.h ../rfb/default8x16.h zrleoutstream.h \ 22 | zrlepalettehelper.h zrletypes.h private.h minilzo.h lzoconf.h scale.h \ 23 | $(TIGHTVNCFILETRANSFERHDRS) 24 | 25 | EXTRA_DIST=tableinit24.c tableinittctemplate.c tabletranstemplate.c \ 26 | tableinitcmtemplate.c tabletrans24template.c \ 27 | zrleencodetemplate.c 28 | 29 | if HAVE_LIBZ 30 | ZLIBSRCS = zlib.c zrle.c zrleoutstream.c zrlepalettehelper.c zywrletemplate.c 31 | if HAVE_LIBJPEG 32 | JPEGSRCS = tight.c 33 | endif 34 | endif 35 | 36 | LIB_SRCS = main.c rfbserver.c rfbregion.c auth.c sockets.c \ 37 | stats.c corre.c hextile.c rre.c translate.c cutpaste.c \ 38 | httpd.c cursor.c font.c \ 39 | draw.c selbox.c d3des.c vncauth.c cargs.c minilzo.c ultra.c scale.c \ 40 | $(ZLIBSRCS) $(JPEGSRCS) $(TIGHTVNCFILETRANSFERSRCS) 41 | 42 | libvncserver_la_SOURCES=$(LIB_SRCS) 43 | 44 | lib_LTLIBRARIES=libvncserver.la 45 | 46 | if HAVE_RPM 47 | $(PACKAGE)-$(VERSION).tar.gz: dist 48 | 49 | # Rule to build RPM distribution package 50 | rpm: $(PACKAGE)-$(VERSION).tar.gz libvncserver.spec 51 | cp $(PACKAGE)-$(VERSION).tar.gz @RPMSOURCEDIR@ 52 | rpmbuild -ba libvncserver.spec 53 | endif 54 | 55 | 56 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/examples/fontsel.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define FONTDIR "/usr/lib/kbd/consolefonts/" 4 | #define DEFAULTFONT FONTDIR "default8x16" 5 | 6 | static char *fontlist[50]={ 7 | "8x16alt", "b.fnt", "c.fnt", "default8x16", "m.fnt", "ml.fnt", "mod_d.fnt", 8 | "mod_s.fnt", "mr.fnt", "mu.fnt", "r.fnt", "rl.fnt", "ro.fnt", "s.fnt", 9 | "sc.fnt", "scrawl_s.fnt", "scrawl_w.fnt", "sd.fnt", "t.fnt", 10 | NULL 11 | }; 12 | 13 | static rfbScreenInfoPtr rfbScreen = NULL; 14 | static rfbFontDataPtr curFont = NULL; 15 | static void showFont(int index) 16 | { 17 | char buffer[1024]; 18 | 19 | if(!rfbScreen) return; 20 | 21 | if(curFont) 22 | rfbFreeFont(curFont); 23 | 24 | strcpy(buffer,FONTDIR); 25 | strcat(buffer,fontlist[index]); 26 | curFont = rfbLoadConsoleFont(buffer); 27 | 28 | rfbFillRect(rfbScreen,210,30-20,210+10*16,30-20+256*20/16,0xb77797); 29 | if(curFont) { 30 | int i,j; 31 | for(j=0;j<256;j+=16) 32 | for(i=0;i<16;i++) 33 | rfbDrawCharWithClip(rfbScreen,curFont,210+10*i,30+j*20/16,j+i, 34 | 0,0,640,480,0xffffff,0x000000); 35 | } 36 | } 37 | 38 | int main(int argc,char** argv) 39 | { 40 | rfbFontDataPtr font; 41 | rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,640,480,8,3,3); 42 | int i,j; 43 | 44 | s->frameBuffer=(char*)malloc(640*480*3); 45 | rfbInitServer(s); 46 | 47 | for(j=0;j<480;j++) 48 | for(i=0;i<640;i++) { 49 | s->frameBuffer[(j*640+i)*3+0]=j*256/480; 50 | s->frameBuffer[(j*640+i)*3+1]=i*256/640; 51 | s->frameBuffer[(j*640+i)*3+2]=(i+j)*256/(480+640); 52 | } 53 | 54 | rfbScreen = s; 55 | font=rfbLoadConsoleFont(DEFAULTFONT); 56 | if(!font) { 57 | rfbErr("Couldn't find %s\n",DEFAULTFONT); 58 | exit(1); 59 | } 60 | 61 | for(j=0;j<0 && rfbIsActive(s);j++) 62 | rfbProcessEvents(s,900000); 63 | 64 | i = rfbSelectBox(s,font,fontlist,10,20,200,300,0xffdfdf,0x602040,2,showFont); 65 | rfbLog("Selection: %d: %s\n",i,(i>=0)?fontlist[i]:"cancelled"); 66 | 67 | rfbFreeFont(font); 68 | free(s->frameBuffer); 69 | rfbScreenCleanup(s); 70 | 71 | return(0); 72 | } 73 | 74 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/zrlepalettehelper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002 RealVNC Ltd. All Rights Reserved. 3 | * Copyright (C) 2003 Sun Microsystems, Inc. 4 | * 5 | * This is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This software is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this software; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 18 | * USA. 19 | */ 20 | 21 | #include "zrlepalettehelper.h" 22 | #include 23 | #include 24 | 25 | #define ZRLE_HASH(pix) (((pix) ^ ((pix) >> 17)) & 4095) 26 | 27 | void zrlePaletteHelperInit(zrlePaletteHelper *helper) 28 | { 29 | memset(helper->palette, 0, sizeof(helper->palette)); 30 | memset(helper->index, 255, sizeof(helper->index)); 31 | memset(helper->key, 0, sizeof(helper->key)); 32 | helper->size = 0; 33 | } 34 | 35 | void zrlePaletteHelperInsert(zrlePaletteHelper *helper, zrle_U32 pix) 36 | { 37 | if (helper->size < ZRLE_PALETTE_MAX_SIZE) { 38 | int i = ZRLE_HASH(pix); 39 | 40 | while (helper->index[i] != 255 && helper->key[i] != pix) 41 | i++; 42 | if (helper->index[i] != 255) return; 43 | 44 | helper->index[i] = helper->size; 45 | helper->key[i] = pix; 46 | helper->palette[helper->size] = pix; 47 | } 48 | helper->size++; 49 | } 50 | 51 | int zrlePaletteHelperLookup(zrlePaletteHelper *helper, zrle_U32 pix) 52 | { 53 | int i = ZRLE_HASH(pix); 54 | 55 | assert(helper->size <= ZRLE_PALETTE_MAX_SIZE); 56 | 57 | while (helper->index[i] != 255 && helper->key[i] != pix) 58 | i++; 59 | if (helper->index[i] != 255) return helper->index[i]; 60 | 61 | return -1; 62 | } 63 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/rfb/rfbregion.h: -------------------------------------------------------------------------------- 1 | #ifndef SRAREGION_H 2 | #define SRAREGION_H 3 | 4 | /* -=- SRA - Simple Region Algorithm 5 | * A simple rectangular region implementation. 6 | * Copyright (c) 2001 James "Wez" Weatherall, Johannes E. Schindelin 7 | */ 8 | 9 | /* -=- sraRect */ 10 | 11 | typedef struct _rect { 12 | int x1; 13 | int y1; 14 | int x2; 15 | int y2; 16 | } sraRect; 17 | 18 | typedef struct sraRegion sraRegion; 19 | 20 | /* -=- Region manipulation functions */ 21 | 22 | extern sraRegion *sraRgnCreate(); 23 | extern sraRegion *sraRgnCreateRect(int x1, int y1, int x2, int y2); 24 | extern sraRegion *sraRgnCreateRgn(const sraRegion *src); 25 | 26 | extern void sraRgnDestroy(sraRegion *rgn); 27 | extern void sraRgnMakeEmpty(sraRegion *rgn); 28 | extern rfbBool sraRgnAnd(sraRegion *dst, const sraRegion *src); 29 | extern void sraRgnOr(sraRegion *dst, const sraRegion *src); 30 | extern rfbBool sraRgnSubtract(sraRegion *dst, const sraRegion *src); 31 | 32 | extern void sraRgnOffset(sraRegion *dst, int dx, int dy); 33 | 34 | extern rfbBool sraRgnPopRect(sraRegion *region, sraRect *rect, 35 | unsigned long flags); 36 | 37 | extern unsigned long sraRgnCountRects(const sraRegion *rgn); 38 | extern rfbBool sraRgnEmpty(const sraRegion *rgn); 39 | 40 | extern sraRegion *sraRgnBBox(const sraRegion *src); 41 | 42 | /* -=- rectangle iterator */ 43 | 44 | typedef struct sraRectangleIterator { 45 | rfbBool reverseX,reverseY; 46 | int ptrSize,ptrPos; 47 | struct sraSpan** sPtrs; 48 | } sraRectangleIterator; 49 | 50 | extern sraRectangleIterator *sraRgnGetIterator(sraRegion *s); 51 | extern sraRectangleIterator *sraRgnGetReverseIterator(sraRegion *s,rfbBool reverseX,rfbBool reverseY); 52 | extern rfbBool sraRgnIteratorNext(sraRectangleIterator *i,sraRect *r); 53 | extern void sraRgnReleaseIterator(sraRectangleIterator *i); 54 | 55 | void sraRgnPrint(const sraRegion *s); 56 | 57 | /* -=- Rectangle clipper (for speed) */ 58 | 59 | extern rfbBool sraClipRect(int *x, int *y, int *w, int *h, 60 | int cx, int cy, int cw, int ch); 61 | 62 | extern rfbBool sraClipRect2(int *x, int *y, int *x2, int *y2, 63 | int cx, int cy, int cx2, int cy2); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/tightvnc-filetransfer/filetransfermsg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Novell, Inc. 3 | * All Rights Reserved. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of version 2 of the GNU General Public License as 7 | * published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, contact Novell, Inc. 16 | * 17 | * To contact Novell about this file by physical or electronic mail, 18 | * you may find current contact information at www.novell.com 19 | * 20 | * Author : Rohit Kumar 21 | * Email ID : rokumar@novell.com 22 | * Date : 14th July 2005 23 | */ 24 | 25 | 26 | #ifndef FILE_TRANSFER_MSG_H 27 | #define FILE_TRANSFER_MSG_H 28 | 29 | typedef struct _FileTransferMsg { 30 | char* data; 31 | unsigned int length; 32 | } FileTransferMsg; 33 | 34 | FileTransferMsg GetFileListResponseMsg(char* path, char flag); 35 | 36 | FileTransferMsg GetFileDownloadResponseMsg(char* path); 37 | FileTransferMsg GetFileDownloadLengthErrResponseMsg(); 38 | FileTransferMsg GetFileDownLoadErrMsg(); 39 | FileTransferMsg GetFileDownloadResponseMsgInBlocks(rfbClientPtr cl, rfbTightClientPtr data); 40 | FileTransferMsg ChkFileDownloadErr(rfbClientPtr cl, rfbTightClientPtr data); 41 | 42 | FileTransferMsg GetFileUploadLengthErrResponseMsg(); 43 | FileTransferMsg GetFileUploadCompressedLevelErrMsg(); 44 | FileTransferMsg ChkFileUploadErr(rfbClientPtr cl, rfbTightClientPtr data); 45 | FileTransferMsg ChkFileUploadWriteErr(rfbClientPtr cl, rfbTightClientPtr data, char* pBuf); 46 | 47 | void CreateDirectory(char* dirName); 48 | void FileUpdateComplete(rfbClientPtr cl, rfbTightClientPtr data); 49 | void CloseUndoneFileTransfer(rfbClientPtr cl, rfbTightClientPtr data); 50 | 51 | void FreeFileTransferMsg(FileTransferMsg ftm); 52 | 53 | #endif 54 | 55 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/tightvnc-filetransfer/filelistinfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Novell, Inc. 3 | * All Rights Reserved. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of version 2 of the GNU General Public License as 7 | * published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, contact Novell, Inc. 16 | * 17 | * To contact Novell about this file by physical or electronic mail, 18 | * you may find current contact information at www.novell.com 19 | * 20 | * Author : Rohit Kumar 21 | * Email ID : rokumar@novell.com 22 | * Date : 14th July 2005 23 | */ 24 | 25 | 26 | #ifndef FILE_LIST_INFO_H 27 | #define FILE_LIST_INFO_H 28 | 29 | #include 30 | 31 | #if !defined(NAME_MAX) 32 | #define NAME_MAX 255 33 | #endif 34 | 35 | 36 | #define SUCCESS 1 37 | #define FAILURE 0 38 | 39 | typedef struct _FileListItemInfo { 40 | char name[NAME_MAX]; 41 | unsigned int size; 42 | unsigned int data; 43 | } FileListItemInfo, *FileListItemInfoPtr; 44 | 45 | typedef struct _FileListItemSize { 46 | unsigned int size; 47 | unsigned int data; 48 | } FileListItemSize, *FileListItemSizePtr; 49 | 50 | typedef struct _FileListInfo { 51 | FileListItemInfoPtr pEntries; 52 | int numEntries; 53 | } FileListInfo, *FileListInfoPtr; 54 | 55 | int AddFileListItemInfo(FileListInfoPtr fileListInfoPtr, char* name, unsigned int size, unsigned int data); 56 | char* GetFileNameAt(FileListInfo fileListInfo, int number); 57 | unsigned int GetFileSizeAt(FileListInfo fileListInfo, int number); 58 | unsigned int GetFileDataAt(FileListInfo fileListInfo, int number); 59 | unsigned int GetSumOfFileNamesLength(FileListInfo fileListInfo); 60 | void FreeFileListInfo(FileListInfo fileListInfo); 61 | 62 | void DisplayFileList(FileListInfo fli); 63 | 64 | #endif 65 | 66 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/zrleoutstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002 RealVNC Ltd. All Rights Reserved. 3 | * Copyright (C) 2003 Sun Microsystems, Inc. 4 | * 5 | * This is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This software is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this software; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 18 | * USA. 19 | */ 20 | 21 | #ifndef __ZRLE_OUT_STREAM_H__ 22 | #define __ZRLE_OUT_STREAM_H__ 23 | 24 | #include 25 | #include "zrletypes.h" 26 | #include "rfb/rfb.h" 27 | 28 | typedef struct { 29 | zrle_U8 *start; 30 | zrle_U8 *ptr; 31 | zrle_U8 *end; 32 | } zrleBuffer; 33 | 34 | typedef struct { 35 | zrleBuffer in; 36 | zrleBuffer out; 37 | 38 | z_stream zs; 39 | } zrleOutStream; 40 | 41 | #define ZRLE_BUFFER_LENGTH(b) ((b)->ptr - (b)->start) 42 | 43 | zrleOutStream *zrleOutStreamNew (void); 44 | void zrleOutStreamFree (zrleOutStream *os); 45 | rfbBool zrleOutStreamFlush (zrleOutStream *os); 46 | void zrleOutStreamWriteBytes (zrleOutStream *os, 47 | const zrle_U8 *data, 48 | int length); 49 | void zrleOutStreamWriteU8 (zrleOutStream *os, 50 | zrle_U8 u); 51 | void zrleOutStreamWriteOpaque8 (zrleOutStream *os, 52 | zrle_U8 u); 53 | void zrleOutStreamWriteOpaque16 (zrleOutStream *os, 54 | zrle_U16 u); 55 | void zrleOutStreamWriteOpaque32 (zrleOutStream *os, 56 | zrle_U32 u); 57 | void zrleOutStreamWriteOpaque24A(zrleOutStream *os, 58 | zrle_U32 u); 59 | void zrleOutStreamWriteOpaque24B(zrleOutStream *os, 60 | zrle_U32 u); 61 | 62 | #endif /* __ZRLE_OUT_STREAM_H__ */ 63 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncclient/corre.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. 3 | * 4 | * This is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This software is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this software; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 17 | * USA. 18 | */ 19 | 20 | /* 21 | * corre.c - handle CoRRE encoding. 22 | * 23 | * This file shouldn't be compiled directly. It is included multiple times by 24 | * rfbproto.c, each time with a different definition of the macro BPP. For 25 | * each value of BPP, this file defines a function which handles a CoRRE 26 | * encoded rectangle with BPP bits per pixel. 27 | */ 28 | 29 | #define HandleCoRREBPP CONCAT2E(HandleCoRRE,BPP) 30 | #define CARDBPP CONCAT3E(uint,BPP,_t) 31 | 32 | static rfbBool 33 | HandleCoRREBPP (rfbClient* client, int rx, int ry, int rw, int rh) 34 | { 35 | rfbRREHeader hdr; 36 | int i; 37 | CARDBPP pix; 38 | uint8_t *ptr; 39 | int x, y, w, h; 40 | 41 | if (!ReadFromRFBServer(client, (char *)&hdr, sz_rfbRREHeader)) 42 | return FALSE; 43 | 44 | hdr.nSubrects = rfbClientSwap32IfLE(hdr.nSubrects); 45 | 46 | if (!ReadFromRFBServer(client, (char *)&pix, sizeof(pix))) 47 | return FALSE; 48 | 49 | FillRectangle(client, rx, ry, rw, rh, pix); 50 | 51 | if (!ReadFromRFBServer(client, client->buffer, hdr.nSubrects * (4 + (BPP / 8)))) 52 | return FALSE; 53 | 54 | ptr = (uint8_t *)client->buffer; 55 | 56 | for (i = 0; i < hdr.nSubrects; i++) { 57 | pix = *(CARDBPP *)ptr; 58 | ptr += BPP/8; 59 | x = *ptr++; 60 | y = *ptr++; 61 | w = *ptr++; 62 | h = *ptr++; 63 | 64 | FillRectangle(client, rx+x, ry+y, w, h, pix); 65 | } 66 | 67 | return TRUE; 68 | } 69 | 70 | #undef CARDBPP 71 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/examples/rotate.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static int gcd(int x, int y) 6 | { 7 | if (x == 0) 8 | return y; 9 | return gcd((y % x), x); 10 | } 11 | 12 | #define CONCAT2(a,b) a##b 13 | #define CONCAT2E(a,b) CONCAT2(a,b) 14 | #define CONCAT3(a,b,c) a##b##c 15 | #define CONCAT3E(a,b,c) CONCAT3(a,b,c) 16 | 17 | #define FUNCNAME rfbRotate 18 | #define FUNC(i, j) (h - 1 - j + i * h) 19 | #define SWAPDIMENSIONS 20 | #define OUT 8 21 | #include "rotatetemplate.c" 22 | #define OUT 16 23 | #include "rotatetemplate.c" 24 | #define OUT 32 25 | #include "rotatetemplate.c" 26 | #undef FUNCNAME 27 | #undef FUNC 28 | 29 | #define FUNCNAME rfbRotateCounterClockwise 30 | #define FUNC(i, j) (j + (w - 1 - i) * h) 31 | #define OUT 8 32 | #include "rotatetemplate.c" 33 | #define OUT 16 34 | #include "rotatetemplate.c" 35 | #define OUT 32 36 | #include "rotatetemplate.c" 37 | #undef FUNCNAME 38 | #undef FUNC 39 | #undef SWAPDIMENSIONS 40 | 41 | #define FUNCNAME rfbFlipHorizontally 42 | #define FUNC(i, j) ((w - 1 - i) + j * w) 43 | #define OUT 8 44 | #include "rotatetemplate.c" 45 | #define OUT 16 46 | #include "rotatetemplate.c" 47 | #define OUT 32 48 | #include "rotatetemplate.c" 49 | #undef FUNCNAME 50 | #undef FUNC 51 | 52 | #define FUNCNAME rfbFlipVertically 53 | #define FUNC(i, j) (i + (h - 1 - j) * w) 54 | #define OUT 8 55 | #include "rotatetemplate.c" 56 | #define OUT 16 57 | #include "rotatetemplate.c" 58 | #define OUT 32 59 | #include "rotatetemplate.c" 60 | #undef FUNCNAME 61 | #undef FUNC 62 | 63 | #define FUNCNAME rfbRotateHundredAndEighty 64 | #define FUNC(i, j) ((w - 1 - i) + (h - 1 - j) * w) 65 | #define OUT 8 66 | #include "rotatetemplate.c" 67 | #define OUT 16 68 | #include "rotatetemplate.c" 69 | #define OUT 32 70 | #include "rotatetemplate.c" 71 | #undef FUNCNAME 72 | #undef FUNC 73 | 74 | static void HandleKey(rfbBool down,rfbKeySym key,rfbClientPtr cl) 75 | { 76 | if(down) { 77 | if (key==XK_Escape || key=='q' || key=='Q') 78 | rfbCloseClient(cl); 79 | else if (key == 'r') 80 | rfbRotate(cl->screen); 81 | else if (key == 'R') 82 | rfbRotateCounterClockwise(cl->screen); 83 | else if (key == 'f') 84 | rfbFlipHorizontally(cl->screen); 85 | else if (key == 'F') 86 | rfbFlipVertically(cl->screen); 87 | } 88 | } 89 | 90 | #define HAVE_HANDLEKEY 91 | #include "pnmshow.c" 92 | 93 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncclient/rre.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. 3 | * 4 | * This is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This software is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this software; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 17 | * USA. 18 | */ 19 | 20 | /* 21 | * rre.c - handle RRE encoding. 22 | * 23 | * This file shouldn't be compiled directly. It is included multiple times by 24 | * rfbproto.c, each time with a different definition of the macro BPP. For 25 | * each value of BPP, this file defines a function which handles an RRE 26 | * encoded rectangle with BPP bits per pixel. 27 | */ 28 | 29 | #define HandleRREBPP CONCAT2E(HandleRRE,BPP) 30 | #define CARDBPP CONCAT3E(uint,BPP,_t) 31 | 32 | static rfbBool 33 | HandleRREBPP (rfbClient* client, int rx, int ry, int rw, int rh) 34 | { 35 | rfbRREHeader hdr; 36 | int i; 37 | CARDBPP pix; 38 | rfbRectangle subrect; 39 | 40 | if (!ReadFromRFBServer(client, (char *)&hdr, sz_rfbRREHeader)) 41 | return FALSE; 42 | 43 | hdr.nSubrects = rfbClientSwap32IfLE(hdr.nSubrects); 44 | 45 | if (!ReadFromRFBServer(client, (char *)&pix, sizeof(pix))) 46 | return FALSE; 47 | 48 | FillRectangle(client, rx, ry, rw, rh, pix); 49 | 50 | for (i = 0; i < hdr.nSubrects; i++) { 51 | if (!ReadFromRFBServer(client, (char *)&pix, sizeof(pix))) 52 | return FALSE; 53 | 54 | if (!ReadFromRFBServer(client, (char *)&subrect, sz_rfbRectangle)) 55 | return FALSE; 56 | 57 | subrect.x = rfbClientSwap16IfLE(subrect.x); 58 | subrect.y = rfbClientSwap16IfLE(subrect.y); 59 | subrect.w = rfbClientSwap16IfLE(subrect.w); 60 | subrect.h = rfbClientSwap16IfLE(subrect.h); 61 | 62 | FillRectangle(client, rx+subrect.x, ry+subrect.y, subrect.w, subrect.h, pix); 63 | } 64 | 65 | return TRUE; 66 | } 67 | 68 | #undef CARDBPP 69 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/examples/pnmshow24.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #ifndef LIBVNCSERVER_ALLOW24BPP 6 | int main() { 7 | printf("I need the ALLOW24BPP LibVNCServer flag to work\n"); 8 | exit(1); 9 | } 10 | #else 11 | 12 | static void HandleKey(rfbBool down,rfbKeySym key,rfbClientPtr cl) 13 | { 14 | if(down && (key==XK_Escape || key=='q' || key=='Q')) 15 | rfbCloseClient(cl); 16 | } 17 | 18 | int main(int argc,char** argv) 19 | { 20 | FILE* in=stdin; 21 | int j,width,height,paddedWidth; 22 | char buffer[1024]; 23 | rfbScreenInfoPtr rfbScreen; 24 | 25 | if(argc>1) { 26 | in=fopen(argv[1],"rb"); 27 | if(!in) { 28 | printf("Couldn't find file %s.\n",argv[1]); 29 | exit(1); 30 | } 31 | } 32 | 33 | fgets(buffer,1024,in); 34 | if(strncmp(buffer,"P6",2)) { 35 | printf("Not a ppm.\n"); 36 | exit(2); 37 | } 38 | 39 | /* skip comments */ 40 | do { 41 | fgets(buffer,1024,in); 42 | } while(buffer[0]=='#'); 43 | 44 | /* get width & height */ 45 | sscanf(buffer,"%d %d",&width,&height); 46 | rfbLog("Got width %d and height %d.\n",width,height); 47 | fgets(buffer,1024,in); 48 | 49 | /* vncviewers have problems with widths which are no multiple of 4. */ 50 | paddedWidth = width; 51 | 52 | /* if your vncviewer doesn't have problems with a width 53 | which is not a multiple of 4, you can comment this. */ 54 | if(width&3) 55 | paddedWidth+=4-(width&3); 56 | 57 | /* initialize data for vnc server */ 58 | rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,3); 59 | if(argc>1) 60 | rfbScreen->desktopName = argv[1]; 61 | else 62 | rfbScreen->desktopName = "Picture"; 63 | rfbScreen->alwaysShared = TRUE; 64 | rfbScreen->kbdAddEvent = HandleKey; 65 | 66 | /* enable http */ 67 | rfbScreen->httpDir = "../classes"; 68 | 69 | /* allocate picture and read it */ 70 | rfbScreen->frameBuffer = (char*)malloc(paddedWidth*3*height); 71 | fread(rfbScreen->frameBuffer,width*3,height,in); 72 | fclose(in); 73 | 74 | /* pad to paddedWidth */ 75 | if(width != paddedWidth) { 76 | int padCount = 3*(paddedWidth - width); 77 | for(j=height-1;j>=0;j--) { 78 | memmove(rfbScreen->frameBuffer+3*paddedWidth*j, 79 | rfbScreen->frameBuffer+3*width*j, 80 | 3*width); 81 | memset(rfbScreen->frameBuffer+3*paddedWidth*(j+1)-padCount, 82 | 0,padCount); 83 | } 84 | } 85 | 86 | /* initialize server */ 87 | rfbInitServer(rfbScreen); 88 | 89 | /* run event loop */ 90 | rfbRunEventLoop(rfbScreen,40000,FALSE); 91 | 92 | return(0); 93 | } 94 | #endif 95 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/client_examples/backchannel.c: -------------------------------------------------------------------------------- 1 | /* A simple example of an RFB client */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static void HandleRect(rfbClient* client, int x, int y, int w, int h) { 10 | } 11 | 12 | /* 13 | * The client part of the back channel extension example. 14 | * 15 | */ 16 | 17 | #define rfbBackChannel 155 18 | 19 | typedef struct backChannelMsg { 20 | uint8_t type; 21 | uint8_t pad1; 22 | uint16_t pad2; 23 | uint32_t size; 24 | } backChannelMsg; 25 | 26 | static void sendMessage(rfbClient* client, char* text) 27 | { 28 | backChannelMsg msg; 29 | uint32_t length = strlen(text)+1; 30 | 31 | msg.type = rfbBackChannel; 32 | msg.size = rfbClientSwap32IfLE(length); 33 | if(!WriteToRFBServer(client, (char*)&msg, sizeof(msg)) || 34 | !WriteToRFBServer(client, text, length)) { 35 | rfbClientLog("enableBackChannel: write error (%d: %s)", errno, strerror(errno)); 36 | } 37 | } 38 | 39 | static rfbBool handleBackChannelMessage(rfbClient* client, 40 | rfbServerToClientMsg* message) 41 | { 42 | backChannelMsg msg; 43 | char* text; 44 | 45 | if(message->type != rfbBackChannel) 46 | return FALSE; 47 | 48 | rfbClientSetClientData(client, sendMessage, sendMessage); 49 | 50 | if(!ReadFromRFBServer(client, ((char*)&msg)+1, sizeof(msg)-1)) 51 | return TRUE; 52 | msg.size = rfbClientSwap32IfLE(msg.size); 53 | text = malloc(msg.size); 54 | if(!ReadFromRFBServer(client, text, msg.size)) { 55 | free(text); 56 | return TRUE; 57 | } 58 | 59 | rfbClientLog("got back channel message: %s\n", text); 60 | free(text); 61 | 62 | return TRUE; 63 | } 64 | 65 | static int backChannelEncodings[] = { rfbBackChannel, 0 }; 66 | 67 | static rfbClientProtocolExtension backChannel = { 68 | backChannelEncodings, /* encodings */ 69 | NULL, /* handleEncoding */ 70 | handleBackChannelMessage, /* handleMessage */ 71 | NULL /* next extension */ 72 | }; 73 | 74 | int 75 | main(int argc, char **argv) 76 | { 77 | rfbClient* client = rfbGetClient(8,3,4); 78 | 79 | client->GotFrameBufferUpdate = HandleRect; 80 | rfbClientRegisterExtension(&backChannel); 81 | 82 | if (!rfbInitClient(client,&argc,argv)) 83 | return 1; 84 | 85 | while (1) { 86 | /* After each idle second, send a message */ 87 | if(WaitForMessage(client,1000000)>0) 88 | HandleRFBServerMessage(client); 89 | else if(rfbClientGetClientData(client, sendMessage)) 90 | sendMessage(client, "Dear Server,\n" 91 | "thank you for understanding " 92 | "back channel messages!"); 93 | } 94 | 95 | rfbClientCleanup(client); 96 | 97 | return 0; 98 | } 99 | 100 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/classes/ssl/proxy.vnc: -------------------------------------------------------------------------------- 1 | 13 | 14 | 59 | 60 | 61 | 62 | 63 | $USER's $DESKTOP desktop ($DISPLAY) 64 | 65 | 67 | 68 | 69 | $PARAMS 70 | 71 |
72 | TightVNC site 73 | 74 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/client_examples/ppmtest.c: -------------------------------------------------------------------------------- 1 | /* A simple example of an RFB client */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static void PrintRect(rfbClient* client, int x, int y, int w, int h) { 10 | rfbClientLog("Received an update for %d,%d,%d,%d.\n",x,y,w,h); 11 | } 12 | 13 | static void SaveFramebufferAsPPM(rfbClient* client, int x, int y, int w, int h) { 14 | static time_t t=0,t1; 15 | FILE* f; 16 | int i,j; 17 | rfbPixelFormat* pf=&client->format; 18 | int bpp=pf->bitsPerPixel/8; 19 | int row_stride=client->width*bpp; 20 | 21 | /* save one picture only if the last is older than 2 seconds */ 22 | t1=time(NULL); 23 | if(t1-t>2) 24 | t=t1; 25 | else 26 | return; 27 | 28 | /* assert bpp=4 */ 29 | if(bpp!=4 && bpp!=2) { 30 | rfbClientLog("bpp = %d (!=4)\n",bpp); 31 | return; 32 | } 33 | 34 | f=fopen("framebuffer.ppm","wb"); 35 | if(!f) { 36 | rfbClientErr("Could not open framebuffer.ppm\n"); 37 | return; 38 | } 39 | 40 | fprintf(f,"P6\n# %s\n%d %d\n255\n",client->desktopName,client->width,client->height); 41 | for(j=0;jheight*row_stride;j+=row_stride) 42 | for(i=0;iwidth*bpp;i+=bpp) { 43 | const char* p=client->frameBuffer+j+i; 44 | unsigned int v; 45 | if(bpp==4) 46 | v=*(unsigned int*)p; 47 | else if(bpp==2) 48 | v=*(unsigned short*)p; 49 | else 50 | v=*(unsigned char*)p; 51 | fputc((v>>pf->redShift)*256/(pf->redMax+1),f); 52 | fputc((v>>pf->greenShift)*256/(pf->greenMax+1),f); 53 | fputc((v>>pf->blueShift)*256/(pf->blueMax+1),f); 54 | } 55 | fclose(f); 56 | } 57 | 58 | int 59 | main(int argc, char **argv) 60 | { 61 | rfbClient* client = rfbGetClient(8,3,4); 62 | time_t t=time(NULL); 63 | 64 | if(argc>1 && !strcmp("-print",argv[1])) { 65 | client->GotFrameBufferUpdate = PrintRect; 66 | argv[1]=argv[0]; argv++; argc--; 67 | } else 68 | client->GotFrameBufferUpdate = SaveFramebufferAsPPM; 69 | 70 | /* The -listen option is used to make us a daemon process which listens for 71 | incoming connections from servers, rather than actively connecting to a 72 | given server. The -tunnel and -via options are useful to create 73 | connections tunneled via SSH port forwarding. We must test for the 74 | -listen option before invoking any Xt functions - this is because we use 75 | forking, and Xt doesn't seem to cope with forking very well. For -listen 76 | option, when a successful incoming connection has been accepted, 77 | listenForIncomingConnections() returns, setting the listenSpecified 78 | flag. */ 79 | 80 | if (!rfbInitClient(client,&argc,argv)) 81 | return 1; 82 | 83 | /* TODO: better wait for update completion */ 84 | while (time(NULL)-t<5) { 85 | static int i=0; 86 | fprintf(stderr,"\r%d",i++); 87 | if(WaitForMessage(client,50)<0) 88 | break; 89 | if(!HandleRFBServerMessage(client)) 90 | break; 91 | } 92 | 93 | rfbClientCleanup(client); 94 | 95 | return 0; 96 | } 97 | 98 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/vncterm/VNConsole.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* this is now the default */ 4 | #define USE_ATTRIBUTE_BUFFER 5 | 6 | typedef struct vncConsole { 7 | /* width and height in cells (=characters) */ 8 | int width, height; 9 | 10 | /* current position */ 11 | int x,y; 12 | 13 | /* characters */ 14 | char *screenBuffer; 15 | 16 | #ifdef USE_ATTRIBUTE_BUFFER 17 | /* attributes: colours. If NULL, default to gray on black, else 18 | for each cell an unsigned char holds foreColour|(backColour<<4) */ 19 | char *attributeBuffer; 20 | #endif 21 | 22 | /* if this is set, the screen doesn't scroll. */ 23 | rfbBool wrapBottomToTop; 24 | 25 | /* height and width of one character */ 26 | int cWidth, cHeight; 27 | /* offset of characters */ 28 | int xhot,yhot; 29 | 30 | /* colour */ 31 | unsigned char foreColour,backColour; 32 | int8_t cx1,cy1,cx2,cy2; 33 | 34 | /* input buffer */ 35 | char *inputBuffer; 36 | int inputCount; 37 | int inputSize; 38 | long selectTimeOut; 39 | rfbBool doEcho; /* if reading input, do output directly? */ 40 | 41 | /* selection */ 42 | char *selection; 43 | 44 | /* mouse */ 45 | rfbBool wasRightButtonDown; 46 | rfbBool currentlyMarking; 47 | int markStart,markEnd; 48 | 49 | /* should text cursor be drawn? (an underscore at current position) */ 50 | rfbBool cursorActive; 51 | rfbBool cursorIsDrawn; 52 | rfbBool dontDrawCursor; /* for example, while scrolling */ 53 | 54 | rfbFontDataPtr font; 55 | rfbScreenInfoPtr screen; 56 | } vncConsole, *vncConsolePtr; 57 | 58 | #ifdef USE_ATTRIBUTE_BUFFER 59 | vncConsolePtr vcGetConsole(int *argc,char **argv, 60 | int width,int height,rfbFontDataPtr font, 61 | rfbBool withAttributes); 62 | #else 63 | vncConsolePtr vcGetConsole(int argc,char **argv, 64 | int width,int height,rfbFontDataPtr font); 65 | #endif 66 | void vcDrawCursor(vncConsolePtr c); 67 | void vcHideCursor(vncConsolePtr c); 68 | void vcCheckCoordinates(vncConsolePtr c); 69 | 70 | void vcPutChar(vncConsolePtr c,unsigned char ch); 71 | void vcPrint(vncConsolePtr c,unsigned char* str); 72 | void vcPrintF(vncConsolePtr c,char* format,...); 73 | 74 | void vcPutCharColour(vncConsolePtr c,unsigned char ch, 75 | unsigned char foreColour,unsigned char backColour); 76 | void vcPrintColour(vncConsolePtr c,unsigned char* str, 77 | unsigned char foreColour,unsigned char backColour); 78 | void vcPrintFColour(vncConsolePtr c,unsigned char foreColour, 79 | unsigned char backColour,char* format,...); 80 | 81 | char vcGetCh(vncConsolePtr c); 82 | char vcGetChar(vncConsolePtr c); /* blocking */ 83 | char *vcGetString(vncConsolePtr c,char *buffer,int maxLen); 84 | 85 | void vcKbdAddEventProc(rfbBool down,rfbKeySym keySym,rfbClientPtr cl); 86 | void vcPtrAddEventProc(int buttonMask,int x,int y,rfbClientPtr cl); 87 | void vcSetXCutTextProc(char* str,int len, struct _rfbClientRec* cl); 88 | 89 | void vcToggleMarkCell(vncConsolePtr c,int pos); 90 | void vcUnmark(vncConsolePtr c); 91 | 92 | void vcProcessEvents(vncConsolePtr c); 93 | 94 | /* before using this function, hide the cursor */ 95 | void vcScroll(vncConsolePtr c,int lineCount); 96 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/LibVNCServer.spec.in: -------------------------------------------------------------------------------- 1 | # Note that this is NOT a relocatable package 2 | Name: @PACKAGE@ 3 | Version: @VERSION@ 4 | Release: 2 5 | Summary: a library to make writing a vnc server easy 6 | Copyright: GPL 7 | Group: Libraries/Network 8 | Packager: Johannes.Schindelin 9 | Source: %{name}-%{version}.tar.gz 10 | BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot 11 | 12 | %description 13 | LibVNCServer makes writing a VNC server (or more correctly, a program 14 | exporting a framebuffer via the Remote Frame Buffer protocol) easy. 15 | 16 | It is based on OSXvnc, which in turn is based on the original Xvnc by 17 | ORL, later AT&T research labs in UK. 18 | 19 | It hides the programmer from the tedious task of managing clients and 20 | compression schemata. 21 | 22 | LibVNCServer was put together and is (actively ;-) maintained by 23 | Johannes Schindelin 24 | 25 | %package devel 26 | Requires: %{name} = %{version} 27 | Summary: Static Libraries and Header Files for LibVNCServer 28 | Group: Libraries/Network 29 | Requires: %{name} = %{version} 30 | 31 | %description devel 32 | Static Libraries and Header Files for LibVNCServer. 33 | 34 | %package x11vnc 35 | Requires: %{name} = %{version} 36 | Summary: VNC server for the current X11 session 37 | Group: User Interface/X 38 | Requires: %{name} = %{version} 39 | 40 | %description x11vnc 41 | x11vnc is to X Window System what WinVNC is to Windows, i.e. a server 42 | which serves the current X Window System desktop via RFB (VNC) 43 | protocol to the user. 44 | 45 | Based on the ideas of x0rfbserver and on LibVNCServer, it has evolved 46 | into a versatile and performant while still easy to use program. 47 | 48 | %prep 49 | %setup -n %{name}-%{version} 50 | 51 | %build 52 | # CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%{_prefix} 53 | %configure 54 | make 55 | 56 | %install 57 | [ -n "%{buildroot}" -a "%{buildroot}" != / ] && rm -rf %{buildroot} 58 | # make install prefix=%{buildroot}%{_prefix} 59 | %makeinstall includedir="%{buildroot}%{_includedir}/rfb" 60 | 61 | %{__install} -d -m0755 %{buildroot}%{_datadir}/x11vnc/classes 62 | %{__install} classes/VncViewer.jar classes/index.vnc \ 63 | %{buildroot}%{_datadir}/x11vnc/classes 64 | 65 | %clean 66 | [ -n "%{buildroot}" -a "%{buildroot}" != / ] && rm -rf %{buildroot} 67 | 68 | %pre 69 | %post 70 | %preun 71 | %postun 72 | 73 | %files 74 | %defattr(-,root,root) 75 | %doc README INSTALL AUTHORS ChangeLog NEWS TODO 76 | %{_bindir}/LinuxVNC 77 | %{_bindir}/libvncserver-config 78 | %{_libdir}/libvncclient.* 79 | %{_libdir}/libvncserver.* 80 | 81 | %files devel 82 | %defattr(-,root,root) 83 | %{_includedir}/rfb/* 84 | 85 | %files x11vnc 86 | %defattr(-,root,root) 87 | %{_bindir}/x11vnc 88 | %{_mandir}/man1/x11vnc.1* 89 | %{_datadir}/x11vnc/classes 90 | 91 | %changelog 92 | * Fri Aug 19 2005 Alberto Lusiani release 2 93 | - create separate package for x11vnc to prevent conflicts with x11vnc rpm 94 | - create devel package, needed to compile but not needed for running 95 | * Sun Feb 9 2003 Johannes Schindelin 96 | - created libvncserver.spec.in 97 | 98 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncclient/listen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. 3 | * 4 | * This is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This software is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this software; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 17 | * USA. 18 | */ 19 | 20 | /* 21 | * listen.c - listen for incoming connections 22 | */ 23 | 24 | #ifdef __STRICT_ANSI__ 25 | #define _BSD_SOURCE 26 | #endif 27 | #include 28 | #include 29 | #ifdef __MINGW32__ 30 | #include 31 | #else 32 | #include 33 | #include 34 | #endif 35 | #include 36 | #include 37 | 38 | /* 39 | * listenForIncomingConnections() - listen for incoming connections from 40 | * servers, and fork a new process to deal with each connection. 41 | */ 42 | 43 | void 44 | listenForIncomingConnections(rfbClient* client) 45 | { 46 | #ifdef __MINGW32__ 47 | /* FIXME */ 48 | rfbClientErr("listenForIncomingConnections on MinGW32 NOT IMPLEMENTED\n"); 49 | return; 50 | #else 51 | int listenSocket; 52 | fd_set fds; 53 | 54 | client->listenSpecified = TRUE; 55 | 56 | listenSocket = ListenAtTcpPort(client->listenPort); 57 | 58 | if ((listenSocket < 0)) 59 | return; 60 | 61 | rfbClientLog("%s -listen: Listening on port %d\n", 62 | client->programName,client->listenPort); 63 | rfbClientLog("%s -listen: Command line errors are not reported until " 64 | "a connection comes in.\n", client->programName); 65 | 66 | while (TRUE) { 67 | 68 | /* reap any zombies */ 69 | int status, pid; 70 | while ((pid= wait3(&status, WNOHANG, (struct rusage *)0))>0); 71 | 72 | /* TODO: callback for discard any events (like X11 events) */ 73 | 74 | FD_ZERO(&fds); 75 | 76 | FD_SET(listenSocket, &fds); 77 | 78 | select(FD_SETSIZE, &fds, NULL, NULL, NULL); 79 | 80 | if (FD_ISSET(listenSocket, &fds)) { 81 | client->sock = AcceptTcpConnection(listenSocket); 82 | if (client->sock < 0) 83 | return; 84 | if (!SetNonBlocking(client->sock)) 85 | return; 86 | 87 | /* Now fork off a new process to deal with it... */ 88 | 89 | switch (fork()) { 90 | 91 | case -1: 92 | rfbClientErr("fork\n"); 93 | return; 94 | 95 | case 0: 96 | /* child - return to caller */ 97 | close(listenSocket); 98 | return; 99 | 100 | default: 101 | /* parent - go round and listen again */ 102 | close(client->sock); 103 | break; 104 | } 105 | } 106 | } 107 | #endif 108 | } 109 | 110 | 111 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/tableinitcmtemplate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * tableinitcmtemplate.c - template for initialising lookup tables for 3 | * translation from a colour map to true colour. 4 | * 5 | * This file shouldn't be compiled. It is included multiple times by 6 | * translate.c, each time with a different definition of the macro OUT. 7 | * For each value of OUT, this file defines a function which allocates an 8 | * appropriately sized lookup table and initialises it. 9 | * 10 | * I know this code isn't nice to read because of all the macros, but 11 | * efficiency is important here. 12 | */ 13 | 14 | /* 15 | * OSXvnc Copyright (C) 2001 Dan McGuirk . 16 | * Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge. 17 | * All Rights Reserved. 18 | * 19 | * This is free software; you can redistribute it and/or modify 20 | * it under the terms of the GNU General Public License as published by 21 | * the Free Software Foundation; either version 2 of the License, or 22 | * (at your option) any later version. 23 | * 24 | * This software is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | * GNU General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU General Public License 30 | * along with this software; if not, write to the Free Software 31 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 32 | * USA. 33 | */ 34 | 35 | #if !defined(OUT) 36 | #error "This file shouldn't be compiled." 37 | #error "It is included as part of translate.c" 38 | #endif 39 | 40 | #define OUT_T CONCAT3E(uint,OUT,_t) 41 | #define SwapOUT(x) CONCAT2E(Swap,OUT(x)) 42 | #define rfbInitColourMapSingleTableOUT \ 43 | CONCAT2E(rfbInitColourMapSingleTable,OUT) 44 | 45 | static void 46 | rfbInitColourMapSingleTableOUT(char **table, rfbPixelFormat *in, 47 | rfbPixelFormat *out,rfbColourMap* colourMap) 48 | { 49 | uint32_t i, r, g, b; 50 | OUT_T *t; 51 | uint32_t nEntries = 1 << in->bitsPerPixel; 52 | int shift = colourMap->is16?16:8; 53 | 54 | if (*table) free(*table); 55 | *table = (char *)malloc(nEntries * sizeof(OUT_T)); 56 | t = (OUT_T *)*table; 57 | 58 | for (i = 0; i < nEntries; i++) { 59 | r = g = b = 0; 60 | if(i < colourMap->count) { 61 | if(colourMap->is16) { 62 | r = colourMap->data.shorts[3*i+0]; 63 | g = colourMap->data.shorts[3*i+1]; 64 | b = colourMap->data.shorts[3*i+2]; 65 | } else { 66 | r = colourMap->data.bytes[3*i+0]; 67 | g = colourMap->data.bytes[3*i+1]; 68 | b = colourMap->data.bytes[3*i+2]; 69 | } 70 | } 71 | t[i] = ((((r * (1 + out->redMax)) >> shift) << out->redShift) | 72 | (((g * (1 + out->greenMax)) >> shift) << out->greenShift) | 73 | (((b * (1 + out->blueMax)) >> shift) << out->blueShift)); 74 | #if (OUT != 8) 75 | if (out->bigEndian != in->bigEndian) { 76 | t[i] = SwapOUT(t[i]); 77 | } 78 | #endif 79 | } 80 | } 81 | 82 | #undef OUT_T 83 | #undef SwapOUT 84 | #undef rfbInitColourMapSingleTableOUT 85 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncclient/minilzo.h: -------------------------------------------------------------------------------- 1 | /* minilzo.h -- mini subset of the LZO real-time data compression library 2 | 3 | This file is part of the LZO real-time data compression library. 4 | 5 | Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer 6 | Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer 7 | Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer 8 | Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer 9 | Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer 10 | Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer 11 | Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer 12 | All Rights Reserved. 13 | 14 | The LZO library is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License as 16 | published by the Free Software Foundation; either version 2 of 17 | the License, or (at your option) any later version. 18 | 19 | The LZO library is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with the LZO library; see the file COPYING. 26 | If not, write to the Free Software Foundation, Inc., 27 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 | 29 | Markus F.X.J. Oberhumer 30 | 31 | http://www.oberhumer.com/opensource/lzo/ 32 | */ 33 | 34 | /* 35 | * NOTE: 36 | * the full LZO package can be found at 37 | * http://www.oberhumer.com/opensource/lzo/ 38 | */ 39 | 40 | 41 | #ifndef __MINILZO_H 42 | #define __MINILZO_H 43 | 44 | #define MINILZO_VERSION 0x1080 45 | 46 | #ifdef __LZOCONF_H 47 | # error "you cannot use both LZO and miniLZO" 48 | #endif 49 | 50 | #undef LZO_HAVE_CONFIG_H 51 | #include "lzoconf.h" 52 | 53 | #if !defined(LZO_VERSION) || (LZO_VERSION != MINILZO_VERSION) 54 | # error "version mismatch in header files" 55 | #endif 56 | 57 | 58 | #ifdef __cplusplus 59 | extern "C" { 60 | #endif 61 | 62 | 63 | /*********************************************************************** 64 | // 65 | ************************************************************************/ 66 | 67 | /* Memory required for the wrkmem parameter. 68 | * When the required size is 0, you can also pass a NULL pointer. 69 | */ 70 | 71 | #define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS 72 | #define LZO1X_1_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t)) 73 | #define LZO1X_MEM_DECOMPRESS (0) 74 | 75 | 76 | /* compression */ 77 | LZO_EXTERN(int) 78 | lzo1x_1_compress ( const lzo_byte *src, lzo_uint src_len, 79 | lzo_byte *dst, lzo_uintp dst_len, 80 | lzo_voidp wrkmem ); 81 | 82 | /* decompression */ 83 | LZO_EXTERN(int) 84 | lzo1x_decompress ( const lzo_byte *src, lzo_uint src_len, 85 | lzo_byte *dst, lzo_uintp dst_len, 86 | lzo_voidp wrkmem /* NOT USED */ ); 87 | 88 | /* safe decompression with overrun testing */ 89 | LZO_EXTERN(int) 90 | lzo1x_decompress_safe ( const lzo_byte *src, lzo_uint src_len, 91 | lzo_byte *dst, lzo_uintp dst_len, 92 | lzo_voidp wrkmem /* NOT USED */ ); 93 | 94 | 95 | #ifdef __cplusplus 96 | } /* extern "C" */ 97 | #endif 98 | 99 | #endif /* already included */ 100 | 101 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/minilzo.h: -------------------------------------------------------------------------------- 1 | /* minilzo.h -- mini subset of the LZO real-time data compression library 2 | 3 | This file is part of the LZO real-time data compression library. 4 | 5 | Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer 6 | Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer 7 | Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer 8 | Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer 9 | Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer 10 | Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer 11 | Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer 12 | All Rights Reserved. 13 | 14 | The LZO library is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License as 16 | published by the Free Software Foundation; either version 2 of 17 | the License, or (at your option) any later version. 18 | 19 | The LZO library is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with the LZO library; see the file COPYING. 26 | If not, write to the Free Software Foundation, Inc., 27 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 | 29 | Markus F.X.J. Oberhumer 30 | 31 | http://www.oberhumer.com/opensource/lzo/ 32 | */ 33 | 34 | /* 35 | * NOTE: 36 | * the full LZO package can be found at 37 | * http://www.oberhumer.com/opensource/lzo/ 38 | */ 39 | 40 | 41 | #ifndef __MINILZO_H 42 | #define __MINILZO_H 43 | 44 | #define MINILZO_VERSION 0x1080 45 | 46 | #ifdef __LZOCONF_H 47 | # error "you cannot use both LZO and miniLZO" 48 | #endif 49 | 50 | #undef LZO_HAVE_CONFIG_H 51 | #include "lzoconf.h" 52 | 53 | #if !defined(LZO_VERSION) || (LZO_VERSION != MINILZO_VERSION) 54 | # error "version mismatch in header files" 55 | #endif 56 | 57 | 58 | #ifdef __cplusplus 59 | extern "C" { 60 | #endif 61 | 62 | 63 | /*********************************************************************** 64 | // 65 | ************************************************************************/ 66 | 67 | /* Memory required for the wrkmem parameter. 68 | * When the required size is 0, you can also pass a NULL pointer. 69 | */ 70 | 71 | #define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS 72 | #define LZO1X_1_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t)) 73 | #define LZO1X_MEM_DECOMPRESS (0) 74 | 75 | 76 | /* compression */ 77 | LZO_EXTERN(int) 78 | lzo1x_1_compress ( const lzo_byte *src, lzo_uint src_len, 79 | lzo_byte *dst, lzo_uintp dst_len, 80 | lzo_voidp wrkmem ); 81 | 82 | /* decompression */ 83 | LZO_EXTERN(int) 84 | lzo1x_decompress ( const lzo_byte *src, lzo_uint src_len, 85 | lzo_byte *dst, lzo_uintp dst_len, 86 | lzo_voidp wrkmem /* NOT USED */ ); 87 | 88 | /* safe decompression with overrun testing */ 89 | LZO_EXTERN(int) 90 | lzo1x_decompress_safe ( const lzo_byte *src, lzo_uint src_len, 91 | lzo_byte *dst, lzo_uintp dst_len, 92 | lzo_voidp wrkmem /* NOT USED */ ); 93 | 94 | 95 | #ifdef __cplusplus 96 | } /* extern "C" */ 97 | #endif 98 | 99 | #endif /* already included */ 100 | 101 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/vncterm/VNCommand.c: -------------------------------------------------------------------------------- 1 | #ifdef __STRICT_ANSI__ 2 | #define _BSD_SOURCE 3 | #define _POSIX_SOURCE 4 | #endif 5 | #include "VNConsole.h" 6 | #include "vga.h" 7 | #ifdef LIBVNCSERVER_HAVE_FCNTL_H 8 | #include 9 | #endif 10 | #ifdef LIBVNCSERVER_HAVE_SYS_TIME_H 11 | #include 12 | #endif 13 | #ifdef LIBVNCSERVER_HAVE_UNISTD_H 14 | #include 15 | #endif 16 | #ifdef LIBVNCSERVER_HAVE_SYS_WAIT_H 17 | #include 18 | #endif 19 | #include 20 | 21 | 22 | int main(int argc, char **argv) 23 | { 24 | rfbBool interactive=FALSE,sendOnlyWholeLines=TRUE; 25 | int serverArgc,programArg0; 26 | for(serverArgc=1;serverArgcdoEcho = FALSE; 64 | 65 | if(max_fdinputCount) { 81 | if(sendOnlyWholeLines) { 82 | for(i=0;iinputCount;i++) 83 | if(console->inputBuffer[i]=='\n') { 84 | i++; 85 | fwrite(console->inputBuffer,i,1,input_pipe); 86 | fflush(input_pipe); 87 | /* fwrite(console->inputBuffer,i,1,stderr); */ 88 | if(console->inputCount>i) 89 | memmove(console->inputBuffer,console->inputBuffer+i,console->inputCount-i); 90 | console->inputCount-=i; 91 | i=0; 92 | } 93 | } else { 94 | fwrite(console->inputBuffer,console->inputCount,1,input_pipe); 95 | fflush(input_pipe); 96 | /* fwrite(console->inputBuffer,console->inputCount,1,stderr); */ 97 | console->inputCount=0; 98 | } 99 | } 100 | /* process output */ 101 | fs1=fs; tv1=tv; 102 | num_fds=select(max_fd+1,&fs1,NULL,NULL,&tv1); 103 | if(num_fds>0) { 104 | /* 105 | if(FD_ISSET(0,&fs1)) { 106 | ch=getchar(); 107 | fputc(ch,f); 108 | } 109 | */ 110 | if(FD_ISSET(out[0],&fs1)) { 111 | c=read(out[0],buffer,1024); 112 | for(i=0;i 2 | 3 | /* 4 | * This is a simple example demonstrating a protocol extension. 5 | * 6 | * The "back channel" permits sending commands between client and server. 7 | * It works by sending plain text messages. 8 | * 9 | * As suggested in the RFB protocol, the back channel is enabled by asking 10 | * for a "pseudo encoding", and enabling the back channel on the client side 11 | * as soon as it gets a back channel message from the server. 12 | * 13 | * This implements the server part. 14 | * 15 | * Note: If you design your own extension and want it to be useful for others, 16 | * too, you should make sure that 17 | * 18 | * - your server as well as your client can speak to other clients and 19 | * servers respectively (i.e. they are nice if they are talking to a 20 | * program which does not know about your extension). 21 | * 22 | * - if the machine is little endian, all 16-bit and 32-bit integers are 23 | * swapped before they are sent and after they are received. 24 | * 25 | */ 26 | 27 | #define rfbBackChannel 155 28 | 29 | typedef struct backChannelMsg { 30 | uint8_t type; 31 | uint8_t pad1; 32 | uint16_t pad2; 33 | uint32_t size; 34 | } backChannelMsg; 35 | 36 | rfbBool enableBackChannel(rfbClientPtr cl, void** data, int encoding) 37 | { 38 | if(encoding == rfbBackChannel) { 39 | backChannelMsg msg; 40 | const char* text="Server acknowledges back channel encoding\n"; 41 | uint32_t length = strlen(text)+1; 42 | int n; 43 | 44 | rfbLog("Enabling the back channel\n"); 45 | 46 | msg.type = rfbBackChannel; 47 | msg.size = Swap32IfLE(length); 48 | if((n = rfbWriteExact(cl, (char*)&msg, sizeof(msg))) <= 0 || 49 | (n = rfbWriteExact(cl, text, length)) <= 0) { 50 | rfbLogPerror("enableBackChannel: write"); 51 | } 52 | return TRUE; 53 | } 54 | return FALSE; 55 | } 56 | 57 | static rfbBool handleBackChannelMessage(rfbClientPtr cl, void* data, 58 | const rfbClientToServerMsg* message) 59 | { 60 | if(message->type == rfbBackChannel) { 61 | backChannelMsg msg; 62 | char* text; 63 | int n; 64 | if((n = rfbReadExact(cl, ((char*)&msg)+1, sizeof(backChannelMsg)-1)) <= 0) { 65 | if(n != 0) 66 | rfbLogPerror("handleBackChannelMessage: read"); 67 | rfbCloseClient(cl); 68 | return TRUE; 69 | } 70 | msg.size = Swap32IfLE(msg.size); 71 | if((text = malloc(msg.size)) == NULL) { 72 | rfbErr("Could not allocate %d bytes\n", msg.size); 73 | return TRUE; 74 | } 75 | if((n = rfbReadExact(cl, text, msg.size)) <= 0) { 76 | if(n != 0) 77 | rfbLogPerror("handleBackChannelMessage: read"); 78 | rfbCloseClient(cl); 79 | return TRUE; 80 | } 81 | rfbLog("got message:\n%s\n", text); 82 | free(text); 83 | return TRUE; 84 | } 85 | return FALSE; 86 | } 87 | 88 | static int backChannelEncodings[] = {rfbBackChannel, 0}; 89 | 90 | static rfbProtocolExtension backChannelExtension = { 91 | NULL, /* newClient */ 92 | NULL, /* init */ 93 | backChannelEncodings, /* pseudoEncodings */ 94 | enableBackChannel, /* enablePseudoEncoding */ 95 | handleBackChannelMessage, /* handleMessage */ 96 | NULL, /* close */ 97 | NULL, /* usage */ 98 | NULL, /* processArgument */ 99 | NULL /* next extension */ 100 | }; 101 | 102 | int main(int argc,char** argv) 103 | { 104 | rfbScreenInfoPtr server; 105 | 106 | rfbRegisterProtocolExtension(&backChannelExtension); 107 | 108 | server=rfbGetScreen(&argc,argv,400,300,8,3,4); 109 | server->frameBuffer=(char*)malloc(400*300*4); 110 | rfbInitServer(server); 111 | rfbRunEventLoop(server,-1,FALSE); 112 | return(0); 113 | } 114 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/examples/pnmshow.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #ifndef HAVE_HANDLEKEY 6 | static void HandleKey(rfbBool down,rfbKeySym key,rfbClientPtr cl) 7 | { 8 | if(down && (key==XK_Escape || key=='q' || key=='Q')) 9 | rfbCloseClient(cl); 10 | } 11 | #endif 12 | 13 | int main(int argc,char** argv) 14 | { 15 | FILE* in=stdin; 16 | int i,j,k,l,width,height,paddedWidth; 17 | char buffer[1024]; 18 | rfbScreenInfoPtr rfbScreen; 19 | enum { BW, GRAY, TRUECOLOUR } picType=TRUECOLOUR; 20 | int bytesPerPixel,bitsPerPixelInFile; 21 | 22 | if(argc>1) { 23 | in=fopen(argv[1],"rb"); 24 | if(!in) { 25 | printf("Couldn't find file %s.\n",argv[1]); 26 | exit(1); 27 | } 28 | } 29 | 30 | fgets(buffer,1024,in); 31 | if(!strncmp(buffer,"P6",2)) { 32 | picType=TRUECOLOUR; 33 | bytesPerPixel=4; bitsPerPixelInFile=3*8; 34 | } else if(!strncmp(buffer,"P5",2)) { 35 | picType=GRAY; 36 | bytesPerPixel=1; bitsPerPixelInFile=1*8; 37 | } else if(!strncmp(buffer,"P4",2)) { 38 | picType=BW; 39 | bytesPerPixel=1; bitsPerPixelInFile=1; 40 | } else { 41 | printf("Not a ppm.\n"); 42 | exit(2); 43 | } 44 | 45 | /* skip comments */ 46 | do { 47 | fgets(buffer,1024,in); 48 | } while(buffer[0]=='#'); 49 | 50 | /* get width & height */ 51 | sscanf(buffer,"%d %d",&width,&height); 52 | rfbLog("Got width %d and height %d.\n",width,height); 53 | if(picType!=BW) 54 | fgets(buffer,1024,in); 55 | else 56 | width=1+((width-1)|7); 57 | 58 | /* vncviewers have problems with widths which are no multiple of 4. */ 59 | paddedWidth = width; 60 | if(width&3) 61 | paddedWidth+=4-(width&3); 62 | 63 | /* initialize data for vnc server */ 64 | rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,(bitsPerPixelInFile+7)/8,bytesPerPixel); 65 | if(argc>1) 66 | rfbScreen->desktopName = argv[1]; 67 | else 68 | rfbScreen->desktopName = "Picture"; 69 | rfbScreen->alwaysShared = TRUE; 70 | rfbScreen->kbdAddEvent = HandleKey; 71 | 72 | /* enable http */ 73 | rfbScreen->httpDir = "../classes"; 74 | 75 | /* allocate picture and read it */ 76 | rfbScreen->frameBuffer = (char*)malloc(paddedWidth*bytesPerPixel*height); 77 | fread(rfbScreen->frameBuffer,width*bitsPerPixelInFile/8,height,in); 78 | fclose(in); 79 | 80 | if(picType!=TRUECOLOUR) { 81 | rfbScreen->serverFormat.trueColour=FALSE; 82 | rfbScreen->colourMap.count=256; 83 | rfbScreen->colourMap.is16=FALSE; 84 | rfbScreen->colourMap.data.bytes=malloc(256*3); 85 | for(i=0;i<256;i++) 86 | memset(rfbScreen->colourMap.data.bytes+3*i,i,3); 87 | } 88 | 89 | switch(picType) { 90 | case TRUECOLOUR: 91 | /* correct the format to 4 bytes instead of 3 (and pad to paddedWidth) */ 92 | for(j=height-1;j>=0;j--) { 93 | for(i=width-1;i>=0;i--) 94 | for(k=2;k>=0;k--) 95 | rfbScreen->frameBuffer[(j*paddedWidth+i)*4+k]= 96 | rfbScreen->frameBuffer[(j*width+i)*3+k]; 97 | for(i=width*4;iframeBuffer[j*paddedWidth*4+i]=0; 99 | } 100 | break; 101 | case GRAY: 102 | break; 103 | case BW: 104 | /* correct the format from 1 bit to 8 bits */ 105 | for(j=height-1;j>=0;j--) 106 | for(i=width-1;i>=0;i-=8) { 107 | l=(unsigned char)rfbScreen->frameBuffer[(j*width+i)/8]; 108 | for(k=7;k>=0;k--) 109 | rfbScreen->frameBuffer[j*paddedWidth+i+7-k]=(l&(1< 6 | #include 7 | #include 8 | #ifndef __MINGW32__ 9 | #include 10 | #endif 11 | #include 12 | #include 13 | 14 | #define width 100 15 | #define height 100 16 | static char f[width*height]; 17 | static char* keys[0x400]; 18 | 19 | static int hex2number(unsigned char c) 20 | { 21 | if(c>'f') return(-1); 22 | else if(c>'F') 23 | return(10+c-'a'); 24 | else if(c>'9') 25 | return(10+c-'A'); 26 | else 27 | return(c-'0'); 28 | } 29 | 30 | static void read_keys(void) 31 | { 32 | int i,j,k; 33 | char buffer[1024]; 34 | FILE* keysyms=fopen("keysym.h","r"); 35 | 36 | memset(keys,0,0x400*sizeof(char*)); 37 | 38 | if(!keysyms) 39 | return; 40 | 41 | while(!feof(keysyms)) { 42 | fgets(buffer,1024,keysyms); 43 | if(!strncmp(buffer,"#define XK_",strlen("#define XK_"))) { 44 | for(i=strlen("#define XK_");buffer[i] && buffer[i]!=' ' 45 | && buffer[i]!='\t';i++); 46 | if(buffer[i]==0) /* don't support wrapped lines */ 47 | continue; 48 | buffer[i]=0; 49 | for(i++;buffer[i] && buffer[i]!='0';i++); 50 | if(buffer[i]==0 || buffer[i+1]!='x') continue; 51 | for(j=0,i+=2;(k=hex2number(buffer[i]))>=0;i++) 52 | j=j*16+k; 53 | if(keys[j&0x3ff]) { 54 | char* x=(char*)malloc(1+strlen(keys[j&0x3ff])+1+strlen(buffer+strlen("#define "))); 55 | strcpy(x,keys[j&0x3ff]); 56 | strcat(x,","); 57 | strcat(x,buffer+strlen("#define ")); 58 | free(keys[j&0x3ff]); 59 | keys[j&0x3ff]=x; 60 | } else 61 | keys[j&0x3ff] = strdup(buffer+strlen("#define ")); 62 | } 63 | 64 | } 65 | fclose(keysyms); 66 | } 67 | 68 | static int lineHeight=16,lineY=height-16; 69 | static void output(rfbScreenInfoPtr s,char* line) 70 | { 71 | rfbDoCopyRect(s,0,0,width,height-lineHeight,0,-lineHeight); 72 | rfbDrawString(s,&default8x16Font,10,lineY,line,0x01); 73 | rfbLog("%s\n",line); 74 | } 75 | 76 | static void dokey(rfbBool down,rfbKeySym k,rfbClientPtr cl) 77 | { 78 | char buffer[1024+32]; 79 | 80 | sprintf(buffer,"%s: %s (0x%x)", 81 | down?"down":"up",keys[k&0x3ff]?keys[k&0x3ff]:"",(unsigned int)k); 82 | output(cl->screen,buffer); 83 | } 84 | 85 | static void doptr(int buttonMask,int x,int y,rfbClientPtr cl) 86 | { 87 | char buffer[1024]; 88 | if(buttonMask) { 89 | sprintf(buffer,"Ptr: mouse button mask 0x%x at %d,%d",buttonMask,x,y); 90 | output(cl->screen,buffer); 91 | } 92 | 93 | } 94 | 95 | static enum rfbNewClientAction newclient(rfbClientPtr cl) 96 | { 97 | char buffer[1024]; 98 | struct sockaddr_in addr; 99 | unsigned int len=sizeof(addr),ip; 100 | 101 | getpeername(cl->sock,(struct sockaddr*)&addr,&len); 102 | ip=ntohl(addr.sin_addr.s_addr); 103 | sprintf(buffer,"Client connected from ip %d.%d.%d.%d", 104 | (ip>>24)&0xff,(ip>>16)&0xff,(ip>>8)&0xff,ip&0xff); 105 | output(cl->screen,buffer); 106 | return RFB_CLIENT_ACCEPT; 107 | } 108 | 109 | int main(int argc,char** argv) 110 | { 111 | rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,width,height,8,1,1); 112 | s->colourMap.is16=FALSE; 113 | s->colourMap.count=2; 114 | s->colourMap.data.bytes=(unsigned char*)"\xd0\xd0\xd0\x30\x01\xe0"; 115 | s->serverFormat.trueColour=FALSE; 116 | s->frameBuffer=f; 117 | s->kbdAddEvent=dokey; 118 | s->ptrAddEvent=doptr; 119 | s->newClientHook=newclient; 120 | 121 | memset(f,0,width*height); 122 | read_keys(); 123 | rfbInitServer(s); 124 | 125 | while(1) { 126 | rfbProcessEvents(s,999999); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncclient/hextile.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. 3 | * 4 | * This is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This software is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this software; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 17 | * USA. 18 | */ 19 | 20 | /* 21 | * hextile.c - handle hextile encoding. 22 | * 23 | * This file shouldn't be compiled directly. It is included multiple times by 24 | * rfbproto.c, each time with a different definition of the macro BPP. For 25 | * each value of BPP, this file defines a function which handles a hextile 26 | * encoded rectangle with BPP bits per pixel. 27 | */ 28 | 29 | #define HandleHextileBPP CONCAT2E(HandleHextile,BPP) 30 | #define CARDBPP CONCAT3E(uint,BPP,_t) 31 | 32 | static rfbBool 33 | HandleHextileBPP (rfbClient* client, int rx, int ry, int rw, int rh) 34 | { 35 | CARDBPP bg, fg; 36 | int i; 37 | uint8_t *ptr; 38 | int x, y, w, h; 39 | int sx, sy, sw, sh; 40 | uint8_t subencoding; 41 | uint8_t nSubrects; 42 | 43 | for (y = ry; y < ry+rh; y += 16) { 44 | for (x = rx; x < rx+rw; x += 16) { 45 | w = h = 16; 46 | if (rx+rw - x < 16) 47 | w = rx+rw - x; 48 | if (ry+rh - y < 16) 49 | h = ry+rh - y; 50 | 51 | if (!ReadFromRFBServer(client, (char *)&subencoding, 1)) 52 | return FALSE; 53 | 54 | if (subencoding & rfbHextileRaw) { 55 | if (!ReadFromRFBServer(client, client->buffer, w * h * (BPP / 8))) 56 | return FALSE; 57 | 58 | CopyRectangle(client, (uint8_t *)client->buffer, x, y, w, h); 59 | 60 | continue; 61 | } 62 | 63 | if (subencoding & rfbHextileBackgroundSpecified) 64 | if (!ReadFromRFBServer(client, (char *)&bg, sizeof(bg))) 65 | return FALSE; 66 | 67 | FillRectangle(client, x, y, w, h, bg); 68 | 69 | if (subencoding & rfbHextileForegroundSpecified) 70 | if (!ReadFromRFBServer(client, (char *)&fg, sizeof(fg))) 71 | return FALSE; 72 | 73 | if (!(subencoding & rfbHextileAnySubrects)) { 74 | continue; 75 | } 76 | 77 | if (!ReadFromRFBServer(client, (char *)&nSubrects, 1)) 78 | return FALSE; 79 | 80 | ptr = (uint8_t*)client->buffer; 81 | 82 | if (subencoding & rfbHextileSubrectsColoured) { 83 | if (!ReadFromRFBServer(client, client->buffer, nSubrects * (2 + (BPP / 8)))) 84 | return FALSE; 85 | 86 | for (i = 0; i < nSubrects; i++) { 87 | #if BPP==8 88 | GET_PIXEL8(fg, ptr); 89 | #elif BPP==16 90 | GET_PIXEL16(fg, ptr); 91 | #elif BPP==32 92 | GET_PIXEL32(fg, ptr); 93 | #else 94 | #error "Invalid BPP" 95 | #endif 96 | sx = rfbHextileExtractX(*ptr); 97 | sy = rfbHextileExtractY(*ptr); 98 | ptr++; 99 | sw = rfbHextileExtractW(*ptr); 100 | sh = rfbHextileExtractH(*ptr); 101 | ptr++; 102 | 103 | FillRectangle(client, x+sx, y+sy, sw, sh, fg); 104 | } 105 | 106 | } else { 107 | if (!ReadFromRFBServer(client, client->buffer, nSubrects * 2)) 108 | return FALSE; 109 | 110 | for (i = 0; i < nSubrects; i++) { 111 | sx = rfbHextileExtractX(*ptr); 112 | sy = rfbHextileExtractY(*ptr); 113 | ptr++; 114 | sw = rfbHextileExtractW(*ptr); 115 | sh = rfbHextileExtractH(*ptr); 116 | ptr++; 117 | 118 | FillRectangle(client, x+sx, y+sy, sw, sh, fg); 119 | } 120 | } 121 | } 122 | } 123 | 124 | return TRUE; 125 | } 126 | 127 | #undef CARDBPP 128 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/tightvnc-filetransfer/filelistinfo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Novell, Inc. 3 | * All Rights Reserved. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of version 2 of the GNU General Public License as 7 | * published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, contact Novell, Inc. 16 | * 17 | * To contact Novell about this file by physical or electronic mail, 18 | * you may find current contact information at www.novell.com 19 | * 20 | * Author : Rohit Kumar 21 | * Email ID : rokumar@novell.com 22 | * Date : 14th July 2005 23 | */ 24 | 25 | 26 | #include 27 | #include "rfb/rfb.h" 28 | #include "filelistinfo.h" 29 | 30 | 31 | /* This method is used for debugging purpose */ 32 | void 33 | DisplayFileList(FileListInfo fli) 34 | { 35 | int i = 0; 36 | if((fli.pEntries == NULL) || (fli.numEntries == 0)) return; 37 | 38 | rfbLog("DISPLAYING FILE NAMES IN THE LIST ...START\n\n"); 39 | rfbLog("Numer of entries:: %d\n", fli.numEntries); 40 | for(i = 0; i < fli.numEntries; i++) 41 | rfbLog("file[%d]\t<%s>\n", i, fli.pEntries[i].name); 42 | rfbLog("DISPLAYING FILE NAMES IN THE LIST ...END\n\n"); 43 | } 44 | 45 | #ifndef __GNUC__ 46 | #define __FUNCTION__ "unknown" 47 | #endif 48 | 49 | int 50 | AddFileListItemInfo(FileListInfoPtr fileListInfoPtr, char* name, 51 | unsigned int size, unsigned int data) 52 | { 53 | FileListItemInfoPtr fileListItemInfoPtr = (FileListItemInfoPtr) 54 | calloc((fileListInfoPtr->numEntries + 1), 55 | sizeof(FileListItemInfo)); 56 | if(fileListItemInfoPtr == NULL) { 57 | rfbLog("File [%s]: Method [%s]: fileListItemInfoPtr is NULL\n", 58 | __FILE__, __FUNCTION__); 59 | return FAILURE; 60 | } 61 | 62 | if(fileListInfoPtr->numEntries != 0) { 63 | memcpy(fileListItemInfoPtr, fileListInfoPtr->pEntries, 64 | fileListInfoPtr->numEntries * sizeof(FileListItemInfo)); 65 | } 66 | 67 | strcpy(fileListItemInfoPtr[fileListInfoPtr->numEntries].name, name); 68 | fileListItemInfoPtr[fileListInfoPtr->numEntries].size = size; 69 | fileListItemInfoPtr[fileListInfoPtr->numEntries].data = data; 70 | 71 | if(fileListInfoPtr->pEntries != NULL) { 72 | free(fileListInfoPtr->pEntries); 73 | fileListInfoPtr->pEntries = NULL; 74 | } 75 | 76 | fileListInfoPtr->pEntries = fileListItemInfoPtr; 77 | fileListItemInfoPtr = NULL; 78 | fileListInfoPtr->numEntries++; 79 | 80 | return SUCCESS; 81 | } 82 | 83 | 84 | char* 85 | GetFileNameAt(FileListInfo fileListInfo, int number) 86 | { 87 | char* name = NULL; 88 | if(number >= 0 && number < fileListInfo.numEntries) 89 | name = fileListInfo.pEntries[number].name; 90 | return name; 91 | } 92 | 93 | 94 | unsigned int 95 | GetFileSizeAt(FileListInfo fileListInfo, int number) 96 | { 97 | unsigned int size = 0; 98 | if(number >= 0 && number < fileListInfo.numEntries) 99 | size = fileListInfo.pEntries[number].size; 100 | return size; 101 | } 102 | 103 | 104 | unsigned int 105 | GetFileDataAt(FileListInfo fileListInfo, int number) 106 | { 107 | unsigned int data = 0; 108 | if(number >= 0 && number < fileListInfo.numEntries) 109 | data = fileListInfo.pEntries[number].data; 110 | return data; 111 | } 112 | 113 | 114 | unsigned int 115 | GetSumOfFileNamesLength(FileListInfo fileListInfo) 116 | { 117 | int i = 0, sumLen = 0; 118 | for(i = 0; i < fileListInfo.numEntries; i++) 119 | sumLen += strlen(fileListInfo.pEntries[i].name); 120 | return sumLen; 121 | } 122 | 123 | 124 | void 125 | FreeFileListInfo(FileListInfo fileListInfo) 126 | { 127 | if(fileListInfo.pEntries != NULL) { 128 | free(fileListInfo.pEntries); 129 | fileListInfo.pEntries = NULL; 130 | } 131 | fileListInfo.numEntries = 0; 132 | } 133 | 134 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/compile: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Wrapper for compilers which do not understand `-c -o'. 3 | 4 | scriptversion=2005-02-03.08 5 | 6 | # Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc. 7 | # Written by Tom Tromey . 8 | # 9 | # This program is free software; you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation; either version 2, or (at your option) 12 | # any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program; if not, write to the Free Software 21 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | 23 | # As a special exception to the GNU General Public License, if you 24 | # distribute this file as part of a program that contains a 25 | # configuration script generated by Autoconf, you may include it under 26 | # the same distribution terms that you use for the rest of that program. 27 | 28 | # This file is maintained in Automake, please report 29 | # bugs to or send patches to 30 | # . 31 | 32 | case $1 in 33 | '') 34 | echo "$0: No command. Try \`$0 --help' for more information." 1>&2 35 | exit 1; 36 | ;; 37 | -h | --h*) 38 | cat <<\EOF 39 | Usage: compile [--help] [--version] PROGRAM [ARGS] 40 | 41 | Wrapper for compilers which do not understand `-c -o'. 42 | Remove `-o dest.o' from ARGS, run PROGRAM with the remaining 43 | arguments, and rename the output as expected. 44 | 45 | If you are trying to build a whole package this is not the 46 | right script to run: please start by reading the file `INSTALL'. 47 | 48 | Report bugs to . 49 | EOF 50 | exit $? 51 | ;; 52 | -v | --v*) 53 | echo "compile $scriptversion" 54 | exit $? 55 | ;; 56 | esac 57 | 58 | ofile= 59 | cfile= 60 | eat= 61 | 62 | for arg 63 | do 64 | if test -n "$eat"; then 65 | eat= 66 | else 67 | case $1 in 68 | -o) 69 | # configure might choose to run compile as `compile cc -o foo foo.c'. 70 | # So we strip `-o arg' only if arg is an object. 71 | eat=1 72 | case $2 in 73 | *.o | *.obj) 74 | ofile=$2 75 | ;; 76 | *) 77 | set x "$@" -o "$2" 78 | shift 79 | ;; 80 | esac 81 | ;; 82 | *.c) 83 | cfile=$1 84 | set x "$@" "$1" 85 | shift 86 | ;; 87 | *) 88 | set x "$@" "$1" 89 | shift 90 | ;; 91 | esac 92 | fi 93 | shift 94 | done 95 | 96 | if test -z "$ofile" || test -z "$cfile"; then 97 | # If no `-o' option was seen then we might have been invoked from a 98 | # pattern rule where we don't need one. That is ok -- this is a 99 | # normal compilation that the losing compiler can handle. If no 100 | # `.c' file was seen then we are probably linking. That is also 101 | # ok. 102 | exec "$@" 103 | fi 104 | 105 | # Name of file we expect compiler to create. 106 | cofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'` 107 | 108 | # Create the lock directory. 109 | # Note: use `[/.-]' here to ensure that we don't use the same name 110 | # that we are using for the .o file. Also, base the name on the expected 111 | # object file name, since that is what matters with a parallel build. 112 | lockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d 113 | while true; do 114 | if mkdir "$lockdir" >/dev/null 2>&1; then 115 | break 116 | fi 117 | sleep 1 118 | done 119 | # FIXME: race condition here if user kills between mkdir and trap. 120 | trap "rmdir '$lockdir'; exit 1" 1 2 15 121 | 122 | # Run the compile. 123 | "$@" 124 | ret=$? 125 | 126 | if test -f "$cofile"; then 127 | mv "$cofile" "$ofile" 128 | elif test -f "${cofile}bj"; then 129 | mv "${cofile}bj" "$ofile" 130 | fi 131 | 132 | rmdir "$lockdir" 133 | exit $ret 134 | 135 | # Local Variables: 136 | # mode: shell-script 137 | # sh-indentation: 2 138 | # eval: (add-hook 'write-file-hooks 'time-stamp) 139 | # time-stamp-start: "scriptversion=" 140 | # time-stamp-format: "%:y-%02m-%02d.%02H" 141 | # time-stamp-end: "$" 142 | # End: 143 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/tabletranstemplate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * tabletranstemplate.c - template for translation using lookup tables. 3 | * 4 | * This file shouldn't be compiled. It is included multiple times by 5 | * translate.c, each time with different definitions of the macros IN and OUT. 6 | * 7 | * For each pair of values IN and OUT, this file defines two functions for 8 | * translating a given rectangle of pixel data. One uses a single lookup 9 | * table, and the other uses three separate lookup tables for the red, green 10 | * and blue values. 11 | * 12 | * I know this code isn't nice to read because of all the macros, but 13 | * efficiency is important here. 14 | */ 15 | 16 | /* 17 | * OSXvnc Copyright (C) 2001 Dan McGuirk . 18 | * Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge. 19 | * All Rights Reserved. 20 | * 21 | * This is free software; you can redistribute it and/or modify 22 | * it under the terms of the GNU General Public License as published by 23 | * the Free Software Foundation; either version 2 of the License, or 24 | * (at your option) any later version. 25 | * 26 | * This software is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | * GNU General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU General Public License 32 | * along with this software; if not, write to the Free Software 33 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 34 | * USA. 35 | */ 36 | 37 | #if !defined(IN) || !defined(OUT) 38 | #error "This file shouldn't be compiled." 39 | #error "It is included as part of translate.c" 40 | #endif 41 | 42 | #define IN_T CONCAT3E(uint,IN,_t) 43 | #define OUT_T CONCAT3E(uint,OUT,_t) 44 | #define rfbTranslateWithSingleTableINtoOUT \ 45 | CONCAT4E(rfbTranslateWithSingleTable,IN,to,OUT) 46 | #define rfbTranslateWithRGBTablesINtoOUT \ 47 | CONCAT4E(rfbTranslateWithRGBTables,IN,to,OUT) 48 | 49 | /* 50 | * rfbTranslateWithSingleTableINtoOUT translates a rectangle of pixel data 51 | * using a single lookup table. 52 | */ 53 | 54 | static void 55 | rfbTranslateWithSingleTableINtoOUT (char *table, rfbPixelFormat *in, 56 | rfbPixelFormat *out, 57 | char *iptr, char *optr, 58 | int bytesBetweenInputLines, 59 | int width, int height) 60 | { 61 | IN_T *ip = (IN_T *)iptr; 62 | OUT_T *op = (OUT_T *)optr; 63 | int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width; 64 | OUT_T *opLineEnd; 65 | OUT_T *t = (OUT_T *)table; 66 | 67 | while (height > 0) { 68 | opLineEnd = op + width; 69 | 70 | while (op < opLineEnd) { 71 | *(op++) = t[*(ip++)]; 72 | } 73 | 74 | ip += ipextra; 75 | height--; 76 | } 77 | } 78 | 79 | 80 | /* 81 | * rfbTranslateWithRGBTablesINtoOUT translates a rectangle of pixel data 82 | * using three separate lookup tables for the red, green and blue values. 83 | */ 84 | 85 | static void 86 | rfbTranslateWithRGBTablesINtoOUT (char *table, rfbPixelFormat *in, 87 | rfbPixelFormat *out, 88 | char *iptr, char *optr, 89 | int bytesBetweenInputLines, 90 | int width, int height) 91 | { 92 | IN_T *ip = (IN_T *)iptr; 93 | OUT_T *op = (OUT_T *)optr; 94 | int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width; 95 | OUT_T *opLineEnd; 96 | OUT_T *redTable = (OUT_T *)table; 97 | OUT_T *greenTable = redTable + in->redMax + 1; 98 | OUT_T *blueTable = greenTable + in->greenMax + 1; 99 | 100 | while (height > 0) { 101 | opLineEnd = &op[width]; 102 | 103 | while (op < opLineEnd) { 104 | *(op++) = (redTable[(*ip >> in->redShift) & in->redMax] | 105 | greenTable[(*ip >> in->greenShift) & in->greenMax] | 106 | blueTable[(*ip >> in->blueShift) & in->blueMax]); 107 | ip++; 108 | } 109 | ip += ipextra; 110 | height--; 111 | } 112 | } 113 | 114 | #undef IN_T 115 | #undef OUT_T 116 | #undef rfbTranslateWithSingleTableINtoOUT 117 | #undef rfbTranslateWithRGBTablesINtoOUT 118 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/classes/javaviewer.pseudo_proxy.patch: -------------------------------------------------------------------------------- 1 | diff -ru vnc_javasrc/OptionsFrame.java proxy_vnc_javasrc/OptionsFrame.java 2 | --- vnc_javasrc/OptionsFrame.java Fri Jul 5 08:17:23 2002 3 | +++ proxy_vnc_javasrc/OptionsFrame.java Thu Aug 22 23:24:44 2002 4 | @@ -70,6 +70,12 @@ 5 | 6 | Label[] labels = new Label[names.length]; 7 | Choice[] choices = new Choice[names.length]; 8 | + 9 | + Label proxyHostLabel; 10 | + TextField proxyHostEdit; 11 | + Label proxyPortLabel; 12 | + TextField proxyPortEdit; 13 | + 14 | Button closeButton; 15 | VncViewer viewer; 16 | 17 | @@ -93,6 +99,9 @@ 18 | boolean shareDesktop; 19 | boolean viewOnly; 20 | 21 | + String proxyHost; 22 | + int proxyPort; 23 | + 24 | // 25 | // Constructor. Set up the labels and choices from the names and values 26 | // arrays. 27 | @@ -126,6 +135,32 @@ 28 | } 29 | } 30 | 31 | + // TODO: find a way to set these to defaults from browser 32 | + proxyPort = viewer.readIntParameter("Use Proxy Port", -1); 33 | + if(proxyPort>-1) { 34 | + proxyHost = viewer.readParameter("Use Proxy Host", false); 35 | + if(proxyHost == null) 36 | + proxyHost = viewer.host; 37 | + 38 | + proxyHostLabel = new Label("Proxy Host"); 39 | + gbc.gridwidth = 1; 40 | + gridbag.setConstraints(proxyHostLabel,gbc); 41 | + add(proxyHostLabel); 42 | + proxyHostEdit = new TextField(); 43 | + gbc.gridwidth = GridBagConstraints.REMAINDER; 44 | + gridbag.setConstraints(proxyHostEdit,gbc); 45 | + add(proxyHostEdit); 46 | + 47 | + proxyPortLabel = new Label("Proxy Port"); 48 | + gbc.gridwidth = 1; 49 | + gridbag.setConstraints(proxyPortLabel,gbc); 50 | + add(proxyPortLabel); 51 | + proxyPortEdit = new TextField(); 52 | + gbc.gridwidth = GridBagConstraints.REMAINDER; 53 | + gridbag.setConstraints(proxyPortEdit,gbc); 54 | + add(proxyPortEdit); 55 | + } 56 | + 57 | closeButton = new Button("Close"); 58 | gbc.gridwidth = GridBagConstraints.REMAINDER; 59 | gridbag.setConstraints(closeButton, gbc); 60 | @@ -161,6 +196,11 @@ 61 | } 62 | } 63 | 64 | + if(proxyPort>-1) { 65 | + proxyPortEdit.setText(Integer.toString(proxyPort)); 66 | + proxyHostEdit.setText(proxyHost); 67 | + } 68 | + 69 | // Make the booleans and encodings array correspond to the state of the GUI 70 | 71 | setEncodings(); 72 | @@ -361,8 +401,12 @@ 73 | // 74 | 75 | public void actionPerformed(ActionEvent evt) { 76 | - if (evt.getSource() == closeButton) 77 | + if (evt.getSource() == closeButton) { 78 | setVisible(false); 79 | + proxyHost = proxyHostEdit.getText(); 80 | + proxyPort = Integer.parseInt(proxyPortEdit.getText()); 81 | + System.err.println("proxy is " + proxyHost + ":" + proxyPort); 82 | + } 83 | } 84 | 85 | // 86 | diff -ru vnc_javasrc/RfbProto.java proxy_vnc_javasrc/RfbProto.java 87 | --- vnc_javasrc/RfbProto.java Sun Aug 4 18:39:35 2002 88 | +++ proxy_vnc_javasrc/RfbProto.java Thu Aug 22 22:53:53 2002 89 | @@ -119,12 +119,51 @@ 90 | viewer = v; 91 | host = h; 92 | port = p; 93 | - sock = new Socket(host, port); 94 | + if(viewer.options.proxyPort>-1) 95 | + sock = new Socket(viewer.options.proxyHost, viewer.options.proxyPort); 96 | + else 97 | + sock = new Socket(host, port); 98 | is = new DataInputStream(new BufferedInputStream(sock.getInputStream(), 99 | 16384)); 100 | os = sock.getOutputStream(); 101 | + if(viewer.options.proxyPort>-1) 102 | + negotiateProxy(host,port); 103 | } 104 | 105 | + // this is inefficient as hell, but only used once per connection 106 | + String readLine() { 107 | + byte[] ba = new byte[1]; 108 | + String s = new String(""); 109 | + 110 | + ba[0]=0; 111 | + try { 112 | + while(ba[0] != 0xa) { 113 | + ba[0] = (byte)is.readUnsignedByte(); 114 | + s += new String(ba); 115 | + } 116 | + } catch(Exception e) { 117 | + e.printStackTrace(); 118 | + } 119 | + return s; 120 | + } 121 | + 122 | + void negotiateProxy(String realHost,int realPort) throws IOException { 123 | + String line; 124 | + 125 | + // this would be the correct way, but we want to trick strict proxies. 126 | + // line = "CONNECT " + realHost + ":" + realPort + " HTTP/1.1\r\nHost: " + realHost + ":" + realPort + "\r\n\r\n"; 127 | + line = "GET " + realHost + ":" + realPort + "/proxied.connection HTTP/1.0\r\nPragma: No-Cache\r\nProxy-Connection: Keep-Alive\r\n\r\n"; 128 | + os.write(line.getBytes()); 129 | + 130 | + line = readLine(); 131 | + System.err.println("Proxy said: " + line); 132 | + if(!(line.substring(0,7)+line.substring(8,12)).equalsIgnoreCase("HTTP/1. 200")) { 133 | + IOException e = new IOException(line); 134 | + throw e; 135 | + } 136 | + while(!line.equals("\r\n") && !line.equals("\n")) 137 | + line = readLine(); 138 | + } 139 | 140 | void close() { 141 | try { 142 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/vncauth.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. 3 | * 4 | * This is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This software is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 17 | * USA. 18 | */ 19 | 20 | /* 21 | * vncauth.c - Functions for VNC password management and authentication. 22 | */ 23 | 24 | #ifdef __STRICT_ANSI__ 25 | #define _BSD_SOURCE 26 | #define _POSIX_SOURCE 27 | #endif 28 | #ifdef LIBVNCSERVER_HAVE_SYS_TYPES_H 29 | #include 30 | #endif 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include "d3des.h" 36 | 37 | #include 38 | #include 39 | 40 | #ifdef LIBVNCSERVER_HAVE_SYS_STAT_H 41 | #include 42 | #endif 43 | 44 | #include 45 | 46 | #ifdef WIN32 47 | #define srandom srand 48 | #define random rand 49 | #else 50 | #include 51 | #endif 52 | 53 | 54 | /* libvncclient does not need this */ 55 | #ifndef rfbEncryptBytes 56 | 57 | /* 58 | * We use a fixed key to store passwords, since we assume that our local 59 | * file system is secure but nonetheless don't want to store passwords 60 | * as plaintext. 61 | */ 62 | 63 | static unsigned char fixedkey[8] = {23,82,107,6,35,78,88,7}; 64 | 65 | 66 | /* 67 | * Encrypt a password and store it in a file. Returns 0 if successful, 68 | * 1 if the file could not be written. 69 | */ 70 | 71 | int 72 | rfbEncryptAndStorePasswd(char *passwd, char *fname) 73 | { 74 | FILE *fp; 75 | unsigned int i; 76 | unsigned char encryptedPasswd[8]; 77 | 78 | if ((fp = fopen(fname,"w")) == NULL) return 1; 79 | 80 | /* windows security sux */ 81 | #ifndef WIN32 82 | fchmod(fileno(fp), S_IRUSR|S_IWUSR); 83 | #endif 84 | 85 | /* pad password with nulls */ 86 | 87 | for (i = 0; i < 8; i++) { 88 | if (i < strlen(passwd)) { 89 | encryptedPasswd[i] = passwd[i]; 90 | } else { 91 | encryptedPasswd[i] = 0; 92 | } 93 | } 94 | 95 | /* Do encryption in-place - this way we overwrite our copy of the plaintext 96 | password */ 97 | 98 | rfbDesKey(fixedkey, EN0); 99 | rfbDes(encryptedPasswd, encryptedPasswd); 100 | 101 | for (i = 0; i < 8; i++) { 102 | putc(encryptedPasswd[i], fp); 103 | } 104 | 105 | fclose(fp); 106 | return 0; 107 | } 108 | 109 | 110 | /* 111 | * Decrypt a password from a file. Returns a pointer to a newly allocated 112 | * string containing the password or a null pointer if the password could 113 | * not be retrieved for some reason. 114 | */ 115 | 116 | char * 117 | rfbDecryptPasswdFromFile(char *fname) 118 | { 119 | FILE *fp; 120 | int i, ch; 121 | unsigned char *passwd = (unsigned char *)malloc(9); 122 | 123 | if ((fp = fopen(fname,"r")) == NULL) return NULL; 124 | 125 | for (i = 0; i < 8; i++) { 126 | ch = getc(fp); 127 | if (ch == EOF) { 128 | fclose(fp); 129 | return NULL; 130 | } 131 | passwd[i] = ch; 132 | } 133 | 134 | fclose(fp); 135 | 136 | rfbDesKey(fixedkey, DE1); 137 | rfbDes(passwd, passwd); 138 | 139 | passwd[8] = 0; 140 | 141 | return (char *)passwd; 142 | } 143 | 144 | 145 | /* 146 | * Generate CHALLENGESIZE random bytes for use in challenge-response 147 | * authentication. 148 | */ 149 | 150 | void 151 | rfbRandomBytes(unsigned char *bytes) 152 | { 153 | int i; 154 | static rfbBool s_srandom_called = FALSE; 155 | 156 | if (!s_srandom_called) { 157 | srandom((unsigned int)time(NULL) ^ (unsigned int)getpid()); 158 | s_srandom_called = TRUE; 159 | } 160 | 161 | for (i = 0; i < CHALLENGESIZE; i++) { 162 | bytes[i] = (unsigned char)(random() & 255); 163 | } 164 | } 165 | 166 | #endif 167 | 168 | /* 169 | * Encrypt CHALLENGESIZE bytes in memory using a password. 170 | */ 171 | 172 | void 173 | rfbEncryptBytes(unsigned char *bytes, char *passwd) 174 | { 175 | unsigned char key[8]; 176 | unsigned int i; 177 | 178 | /* key is simply password padded with nulls */ 179 | 180 | for (i = 0; i < 8; i++) { 181 | if (i < strlen(passwd)) { 182 | key[i] = passwd[i]; 183 | } else { 184 | key[i] = 0; 185 | } 186 | } 187 | 188 | rfbDesKey(key, EN0); 189 | 190 | for (i = 0; i < CHALLENGESIZE; i += 8) { 191 | rfbDes(bytes+i, bytes+i); 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/examples/camera.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Question: I need to display a live camera image via VNC. Until now I just 4 | * grab an image, set the rect to modified and do a 0.1 s sleep to give the 5 | * system time to transfer the data. 6 | * This is obviously a solution which doesn't scale very well to different 7 | * connection speeds/cpu horsepowers, so I wonder if there is a way for the 8 | * server application to determine if the updates have been sent. This would 9 | * cause the live image update rate to always be the maximum the connection 10 | * supports while avoiding excessive loads. 11 | * 12 | * Thanks in advance, 13 | * 14 | * 15 | * Christian Daschill 16 | * 17 | * 18 | * Answer: Originally, I thought about using seperate threads and using a 19 | * mutex to determine when the frame buffer was being accessed by any client 20 | * so we could determine a safe time to take a picture. The probem is, we 21 | * are lock-stepping everything with framebuffer access. Why not be a 22 | * single-thread application and in-between rfbProcessEvents perform a 23 | * camera snapshot. And this is what I do here. It guarantees that the 24 | * clients have been serviced before taking another picture. 25 | * 26 | * The downside to this approach is that the more clients you have, there is 27 | * less time available for you to service the camera equating to reduced 28 | * frame rate. (or, your clients are on really slow links). Increasing your 29 | * systems ethernet transmit queues may help improve the overall performance 30 | * as the libvncserver should not stall on transmitting to any single 31 | * client. 32 | * 33 | * Another solution would be to provide a seperate framebuffer for each 34 | * client and use mutexes to determine if any particular client is ready for 35 | * a snapshot. This way, your not updating a framebuffer for a slow client 36 | * while it is being transferred. 37 | */ 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | 45 | #define WIDTH 640 46 | #define HEIGHT 480 47 | #define BPP 4 48 | 49 | /* 15 frames per second (if we can) */ 50 | #define PICTURE_TIMEOUT (1.0/15.0) 51 | 52 | 53 | /* 54 | * throttle camera updates 55 | */ 56 | int TimeToTakePicture() { 57 | static struct timeval now={0,0}, then={0,0}; 58 | double elapsed, dnow, dthen; 59 | 60 | gettimeofday(&now,NULL); 61 | 62 | dnow = now.tv_sec + (now.tv_usec /1000000.0); 63 | dthen = then.tv_sec + (then.tv_usec/1000000.0); 64 | elapsed = dnow - dthen; 65 | 66 | if (elapsed > PICTURE_TIMEOUT) 67 | memcpy((char *)&then, (char *)&now, sizeof(struct timeval)); 68 | return elapsed > PICTURE_TIMEOUT; 69 | } 70 | 71 | 72 | 73 | /* 74 | * simulate grabbing a picture from some device 75 | */ 76 | int TakePicture(unsigned char *buffer) 77 | { 78 | static int last_line=0, fps=0, fcount=0; 79 | int line=0; 80 | int i,j; 81 | struct timeval now; 82 | 83 | /* 84 | * simulate grabbing data from a device by updating the entire framebuffer 85 | */ 86 | 87 | for(j=0;jHEIGHT) line=HEIGHT-1; 107 | memset(&buffer[(WIDTH * BPP) * line], 0, (WIDTH * BPP)); 108 | 109 | /* frames per second (informational only) */ 110 | fcount++; 111 | if (last_line > line) { 112 | fps = fcount; 113 | fcount = 0; 114 | } 115 | last_line = line; 116 | fprintf(stderr,"%03d/%03d Picture (%03d fps)\r", line, HEIGHT, fps); 117 | 118 | /* success! We have a new picture! */ 119 | return (1==1); 120 | } 121 | 122 | 123 | 124 | 125 | /* 126 | * Single-threaded application that interleaves client servicing with taking 127 | * pictures from the camera. This way, we do not update the framebuffer 128 | * while an encoding is working on it too (banding, and image artifacts). 129 | */ 130 | int main(int argc,char** argv) 131 | { 132 | long usec; 133 | 134 | rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,WIDTH,HEIGHT,8,3,BPP); 135 | server->desktopName = "Live Video Feed Example"; 136 | server->frameBuffer=(char*)malloc(WIDTH*HEIGHT*BPP); 137 | server->alwaysShared=(1==1); 138 | 139 | /* Initialize the server */ 140 | rfbInitServer(server); 141 | 142 | /* Loop, processing clients and taking pictures */ 143 | while (rfbIsActive(server)) { 144 | if (TimeToTakePicture()) 145 | if (TakePicture((unsigned char *)server->frameBuffer)) 146 | rfbMarkRectAsModified(server,0,0,WIDTH,HEIGHT); 147 | 148 | usec = server->deferUpdateTime*1000; 149 | rfbProcessEvents(server,usec); 150 | } 151 | return(0); 152 | } 153 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/tableinittctemplate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * tableinittctemplate.c - template for initialising lookup tables for 3 | * truecolour to truecolour translation. 4 | * 5 | * This file shouldn't be compiled. It is included multiple times by 6 | * translate.c, each time with a different definition of the macro OUT. 7 | * For each value of OUT, this file defines two functions for initialising 8 | * lookup tables. One is for truecolour translation using a single lookup 9 | * table, the other is for truecolour translation using three separate 10 | * lookup tables for the red, green and blue values. 11 | * 12 | * I know this code isn't nice to read because of all the macros, but 13 | * efficiency is important here. 14 | */ 15 | 16 | /* 17 | * OSXvnc Copyright (C) 2001 Dan McGuirk . 18 | * Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge. 19 | * All Rights Reserved. 20 | * 21 | * This is free software; you can redistribute it and/or modify 22 | * it under the terms of the GNU General Public License as published by 23 | * the Free Software Foundation; either version 2 of the License, or 24 | * (at your option) any later version. 25 | * 26 | * This software is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | * GNU General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU General Public License 32 | * along with this software; if not, write to the Free Software 33 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 34 | * USA. 35 | */ 36 | 37 | #if !defined(OUT) 38 | #error "This file shouldn't be compiled." 39 | #error "It is included as part of translate.c" 40 | #endif 41 | 42 | #define OUT_T CONCAT3E(uint,OUT,_t) 43 | #define SwapOUT(x) CONCAT2E(Swap,OUT(x)) 44 | #define rfbInitTrueColourSingleTableOUT \ 45 | CONCAT2E(rfbInitTrueColourSingleTable,OUT) 46 | #define rfbInitTrueColourRGBTablesOUT CONCAT2E(rfbInitTrueColourRGBTables,OUT) 47 | #define rfbInitOneRGBTableOUT CONCAT2E(rfbInitOneRGBTable,OUT) 48 | 49 | static void 50 | rfbInitOneRGBTableOUT (OUT_T *table, int inMax, int outMax, int outShift, 51 | int swap); 52 | 53 | 54 | /* 55 | * rfbInitTrueColourSingleTable sets up a single lookup table for truecolour 56 | * translation. 57 | */ 58 | 59 | static void 60 | rfbInitTrueColourSingleTableOUT (char **table, rfbPixelFormat *in, 61 | rfbPixelFormat *out) 62 | { 63 | int i; 64 | int inRed, inGreen, inBlue, outRed, outGreen, outBlue; 65 | OUT_T *t; 66 | int nEntries = 1 << in->bitsPerPixel; 67 | 68 | if (*table) free(*table); 69 | *table = (char *)malloc(nEntries * sizeof(OUT_T)); 70 | t = (OUT_T *)*table; 71 | 72 | for (i = 0; i < nEntries; i++) { 73 | inRed = (i >> in->redShift) & in->redMax; 74 | inGreen = (i >> in->greenShift) & in->greenMax; 75 | inBlue = (i >> in->blueShift) & in->blueMax; 76 | 77 | outRed = (inRed * out->redMax + in->redMax / 2) / in->redMax; 78 | outGreen = (inGreen * out->greenMax + in->greenMax / 2) / in->greenMax; 79 | outBlue = (inBlue * out->blueMax + in->blueMax / 2) / in->blueMax; 80 | 81 | t[i] = ((outRed << out->redShift) | 82 | (outGreen << out->greenShift) | 83 | (outBlue << out->blueShift)); 84 | #if (OUT != 8) 85 | if (out->bigEndian != in->bigEndian) { 86 | t[i] = SwapOUT(t[i]); 87 | } 88 | #endif 89 | } 90 | } 91 | 92 | 93 | /* 94 | * rfbInitTrueColourRGBTables sets up three separate lookup tables for the 95 | * red, green and blue values. 96 | */ 97 | 98 | static void 99 | rfbInitTrueColourRGBTablesOUT (char **table, rfbPixelFormat *in, 100 | rfbPixelFormat *out) 101 | { 102 | OUT_T *redTable; 103 | OUT_T *greenTable; 104 | OUT_T *blueTable; 105 | 106 | if (*table) free(*table); 107 | *table = (char *)malloc((in->redMax + in->greenMax + in->blueMax + 3) 108 | * sizeof(OUT_T)); 109 | redTable = (OUT_T *)*table; 110 | greenTable = redTable + in->redMax + 1; 111 | blueTable = greenTable + in->greenMax + 1; 112 | 113 | rfbInitOneRGBTableOUT (redTable, in->redMax, out->redMax, 114 | out->redShift, (out->bigEndian != in->bigEndian)); 115 | rfbInitOneRGBTableOUT (greenTable, in->greenMax, out->greenMax, 116 | out->greenShift, (out->bigEndian != in->bigEndian)); 117 | rfbInitOneRGBTableOUT (blueTable, in->blueMax, out->blueMax, 118 | out->blueShift, (out->bigEndian != in->bigEndian)); 119 | } 120 | 121 | static void 122 | rfbInitOneRGBTableOUT (OUT_T *table, int inMax, int outMax, int outShift, 123 | int swap) 124 | { 125 | int i; 126 | int nEntries = inMax + 1; 127 | 128 | for (i = 0; i < nEntries; i++) { 129 | table[i] = ((i * outMax + inMax / 2) / inMax) << outShift; 130 | #if (OUT != 8) 131 | if (swap) { 132 | table[i] = SwapOUT(table[i]); 133 | } 134 | #endif 135 | } 136 | } 137 | 138 | #undef OUT_T 139 | #undef SwapOUT 140 | #undef rfbInitTrueColourSingleTableOUT 141 | #undef rfbInitTrueColourRGBTablesOUT 142 | #undef rfbInitOneRGBTableOUT 143 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncclient/zlib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2000 Tridia Corporation. All Rights Reserved. 3 | * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. 4 | * 5 | * This is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This software is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this software; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 18 | * USA. 19 | */ 20 | 21 | #ifdef LIBVNCSERVER_HAVE_LIBZ 22 | 23 | /* 24 | * zlib.c - handle zlib encoding. 25 | * 26 | * This file shouldn't be compiled directly. It is included multiple times by 27 | * rfbproto.c, each time with a different definition of the macro BPP. For 28 | * each value of BPP, this file defines a function which handles an zlib 29 | * encoded rectangle with BPP bits per pixel. 30 | */ 31 | 32 | #define HandleZlibBPP CONCAT2E(HandleZlib,BPP) 33 | #define CARDBPP CONCAT3E(uint,BPP,_t) 34 | 35 | static rfbBool 36 | HandleZlibBPP (rfbClient* client, int rx, int ry, int rw, int rh) 37 | { 38 | rfbZlibHeader hdr; 39 | int remaining; 40 | int inflateResult; 41 | int toRead; 42 | 43 | /* First make sure we have a large enough raw buffer to hold the 44 | * decompressed data. In practice, with a fixed BPP, fixed frame 45 | * buffer size and the first update containing the entire frame 46 | * buffer, this buffer allocation should only happen once, on the 47 | * first update. 48 | */ 49 | if ( client->raw_buffer_size < (( rw * rh ) * ( BPP / 8 ))) { 50 | 51 | if ( client->raw_buffer != NULL ) { 52 | 53 | free( client->raw_buffer ); 54 | 55 | } 56 | 57 | client->raw_buffer_size = (( rw * rh ) * ( BPP / 8 )); 58 | client->raw_buffer = (char*) malloc( client->raw_buffer_size ); 59 | 60 | } 61 | 62 | if (!ReadFromRFBServer(client, (char *)&hdr, sz_rfbZlibHeader)) 63 | return FALSE; 64 | 65 | remaining = rfbClientSwap32IfLE(hdr.nBytes); 66 | 67 | /* Need to initialize the decompressor state. */ 68 | client->decompStream.next_in = ( Bytef * )client->buffer; 69 | client->decompStream.avail_in = 0; 70 | client->decompStream.next_out = ( Bytef * )client->raw_buffer; 71 | client->decompStream.avail_out = client->raw_buffer_size; 72 | client->decompStream.data_type = Z_BINARY; 73 | 74 | /* Initialize the decompression stream structures on the first invocation. */ 75 | if ( client->decompStreamInited == FALSE ) { 76 | 77 | inflateResult = inflateInit( &client->decompStream ); 78 | 79 | if ( inflateResult != Z_OK ) { 80 | rfbClientLog( 81 | "inflateInit returned error: %d, msg: %s\n", 82 | inflateResult, 83 | client->decompStream.msg); 84 | return FALSE; 85 | } 86 | 87 | client->decompStreamInited = TRUE; 88 | 89 | } 90 | 91 | inflateResult = Z_OK; 92 | 93 | /* Process buffer full of data until no more to process, or 94 | * some type of inflater error, or Z_STREAM_END. 95 | */ 96 | while (( remaining > 0 ) && 97 | ( inflateResult == Z_OK )) { 98 | 99 | if ( remaining > RFB_BUFFER_SIZE ) { 100 | toRead = RFB_BUFFER_SIZE; 101 | } 102 | else { 103 | toRead = remaining; 104 | } 105 | 106 | /* Fill the buffer, obtaining data from the server. */ 107 | if (!ReadFromRFBServer(client, client->buffer,toRead)) 108 | return FALSE; 109 | 110 | client->decompStream.next_in = ( Bytef * )client->buffer; 111 | client->decompStream.avail_in = toRead; 112 | 113 | /* Need to uncompress buffer full. */ 114 | inflateResult = inflate( &client->decompStream, Z_SYNC_FLUSH ); 115 | 116 | /* We never supply a dictionary for compression. */ 117 | if ( inflateResult == Z_NEED_DICT ) { 118 | rfbClientLog("zlib inflate needs a dictionary!\n"); 119 | return FALSE; 120 | } 121 | if ( inflateResult < 0 ) { 122 | rfbClientLog( 123 | "zlib inflate returned error: %d, msg: %s\n", 124 | inflateResult, 125 | client->decompStream.msg); 126 | return FALSE; 127 | } 128 | 129 | /* Result buffer allocated to be at least large enough. We should 130 | * never run out of space! 131 | */ 132 | if (( client->decompStream.avail_in > 0 ) && 133 | ( client->decompStream.avail_out <= 0 )) { 134 | rfbClientLog("zlib inflate ran out of space!\n"); 135 | return FALSE; 136 | } 137 | 138 | remaining -= toRead; 139 | 140 | } /* while ( remaining > 0 ) */ 141 | 142 | if ( inflateResult == Z_OK ) { 143 | 144 | /* Put the uncompressed contents of the update on the screen. */ 145 | CopyRectangle(client, (uint8_t *)client->raw_buffer, rx, ry, rw, rh); 146 | } 147 | else { 148 | 149 | rfbClientLog( 150 | "zlib inflate returned error: %d, msg: %s\n", 151 | inflateResult, 152 | client->decompStream.msg); 153 | return FALSE; 154 | 155 | } 156 | 157 | return TRUE; 158 | } 159 | 160 | #undef CARDBPP 161 | 162 | #endif 163 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/font.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int rfbDrawChar(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font, 4 | int x,int y,unsigned char c,rfbPixel col) 5 | { 6 | int i,j,width,height; 7 | unsigned char* data=font->data+font->metaData[c*5]; 8 | unsigned char d=*data; 9 | int rowstride=rfbScreen->paddedWidthInBytes; 10 | int bpp=rfbScreen->serverFormat.bitsPerPixel/8; 11 | char *colour=(char*)&col; 12 | 13 | if(!rfbEndianTest) 14 | colour += 4-bpp; 15 | 16 | width=font->metaData[c*5+1]; 17 | height=font->metaData[c*5+2]; 18 | x+=font->metaData[c*5+3]; 19 | y+=-font->metaData[c*5+4]-height+1; 20 | 21 | for(j=0;jframeBuffer+(y+j)*rowstride+(x+i)*bpp,colour,bpp); 29 | d<<=1; 30 | } 31 | /* if((i&7)!=0) data++; */ 32 | } 33 | return(width); 34 | } 35 | 36 | void rfbDrawString(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font, 37 | int x,int y,const char* string,rfbPixel colour) 38 | { 39 | while(*string) { 40 | x+=rfbDrawChar(rfbScreen,font,x,y,*string,colour); 41 | string++; 42 | } 43 | } 44 | 45 | /* TODO: these two functions need to be more efficient */ 46 | /* if col==bcol, assume transparent background */ 47 | int rfbDrawCharWithClip(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font, 48 | int x,int y,unsigned char c, 49 | int x1,int y1,int x2,int y2, 50 | rfbPixel col,rfbPixel bcol) 51 | { 52 | int i,j,width,height; 53 | unsigned char* data=font->data+font->metaData[c*5]; 54 | unsigned char d; 55 | int rowstride=rfbScreen->paddedWidthInBytes; 56 | int bpp=rfbScreen->serverFormat.bitsPerPixel/8,extra_bytes=0; 57 | char* colour=(char*)&col; 58 | char* bcolour=(char*)&bcol; 59 | 60 | if(!rfbEndianTest) { 61 | colour+=4-bpp; 62 | bcolour+=4-bpp; 63 | } 64 | 65 | width=font->metaData[c*5+1]; 66 | height=font->metaData[c*5+2]; 67 | x+=font->metaData[c*5+3]; 68 | y+=-font->metaData[c*5+4]-height+1; 69 | 70 | /* after clipping, x2 will be count of bytes between rows, 71 | * x1 start of i, y1 start of j, width and height will be adjusted. */ 72 | if(y1>y) { y1-=y; data+=(width+7)/8; height-=y1; y+=y1; } else y1=0; 73 | if(x1>x) { x1-=x; data+=x1; width-=x1; x+=x1; extra_bytes+=x1/8; } else x1=0; 74 | if(y2=x1 && x+i=y1 && y+jframeBuffer+(y+j)*rowstride+(x+i)*bpp, 89 | colour,bpp); 90 | } else if(bcol!=col) { 91 | memcpy(rfbScreen->frameBuffer+(y+j)*rowstride+(x+i)*bpp, 92 | bcolour,bpp); 93 | } 94 | } 95 | d<<=1; 96 | } 97 | /* if((i&7)==0) data++; */ 98 | data += extra_bytes; 99 | } 100 | return(width); 101 | } 102 | 103 | void rfbDrawStringWithClip(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font, 104 | int x,int y,const char* string, 105 | int x1,int y1,int x2,int y2, 106 | rfbPixel colour,rfbPixel backColour) 107 | { 108 | while(*string) { 109 | x+=rfbDrawCharWithClip(rfbScreen,font,x,y,*string,x1,y1,x2,y2, 110 | colour,backColour); 111 | string++; 112 | } 113 | } 114 | 115 | int rfbWidthOfString(rfbFontDataPtr font,const char* string) 116 | { 117 | int i=0; 118 | while(*string) { 119 | i+=font->metaData[*string*5+1]; 120 | string++; 121 | } 122 | return(i); 123 | } 124 | 125 | int rfbWidthOfChar(rfbFontDataPtr font,unsigned char c) 126 | { 127 | return(font->metaData[c*5+1]+font->metaData[c*5+3]); 128 | } 129 | 130 | void rfbFontBBox(rfbFontDataPtr font,unsigned char c,int* x1,int* y1,int* x2,int* y2) 131 | { 132 | *x1+=font->metaData[c*5+3]; 133 | *y1+=-font->metaData[c*5+4]-font->metaData[c*5+2]+1; 134 | *x2=*x1+font->metaData[c*5+1]+1; 135 | *y2=*y1+font->metaData[c*5+2]+1; 136 | } 137 | 138 | #ifndef INT_MAX 139 | #define INT_MAX 0x7fffffff 140 | #endif 141 | 142 | void rfbWholeFontBBox(rfbFontDataPtr font, 143 | int *x1, int *y1, int *x2, int *y2) 144 | { 145 | int i; 146 | int* m=font->metaData; 147 | 148 | (*x1)=(*y1)=INT_MAX; (*x2)=(*y2)=1-(INT_MAX); 149 | for(i=0;i<256;i++) { 150 | if(m[i*5+1]-m[i*5+3]>(*x2)) 151 | (*x2)=m[i*5+1]-m[i*5+3]; 152 | if(-m[i*5+2]+m[i*5+4]<(*y1)) 153 | (*y1)=-m[i*5+2]+m[i*5+4]; 154 | if(m[i*5+3]<(*x1)) 155 | (*x1)=m[i*5+3]; 156 | if(-m[i*5+4]>(*y2)) 157 | (*y2)=-m[i*5+4]; 158 | } 159 | (*x2)++; 160 | (*y2)++; 161 | } 162 | 163 | rfbFontDataPtr rfbLoadConsoleFont(char *filename) 164 | { 165 | FILE *f=fopen(filename,"rb"); 166 | rfbFontDataPtr p; 167 | int i; 168 | 169 | if(!f) return NULL; 170 | 171 | p=(rfbFontDataPtr)malloc(sizeof(rfbFontData)); 172 | p->data=(unsigned char*)malloc(4096); 173 | if(1!=fread(p->data,4096,1,f)) { 174 | free(p->data); 175 | free(p); 176 | return NULL; 177 | } 178 | fclose(f); 179 | p->metaData=(int*)malloc(256*5*sizeof(int)); 180 | for(i=0;i<256;i++) { 181 | p->metaData[i*5+0]=i*16; /* offset */ 182 | p->metaData[i*5+1]=8; /* width */ 183 | p->metaData[i*5+2]=16; /* height */ 184 | p->metaData[i*5+3]=0; /* xhot */ 185 | p->metaData[i*5+4]=0; /* yhot */ 186 | } 187 | return(p); 188 | } 189 | 190 | void rfbFreeFont(rfbFontDataPtr f) 191 | { 192 | free(f->data); 193 | free(f->metaData); 194 | free(f); 195 | } 196 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/tableinit24.c: -------------------------------------------------------------------------------- 1 | /* 2 | 24 bit 3 | */ 4 | 5 | /* 6 | * OSXvnc Copyright (C) 2001 Dan McGuirk . 7 | * Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge. 8 | * All Rights Reserved. 9 | * 10 | * This is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This software is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this software; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 23 | * USA. 24 | */ 25 | 26 | static void 27 | rfbInitOneRGBTable24 (uint8_t *table, int inMax, int outMax, int outShift,int swap); 28 | 29 | 30 | static void 31 | rfbInitColourMapSingleTable24(char **table, rfbPixelFormat *in, 32 | rfbPixelFormat *out,rfbColourMap* colourMap) 33 | { 34 | uint32_t i, r, g, b, outValue; 35 | uint8_t *t; 36 | uint8_t c; 37 | unsigned int nEntries = 1 << in->bitsPerPixel; 38 | int shift = colourMap->is16?16:8; 39 | 40 | if (*table) free(*table); 41 | *table = (char *)malloc(nEntries * 3 + 1); 42 | t = (uint8_t *)*table; 43 | 44 | for (i = 0; i < nEntries; i++) { 45 | r = g = b = 0; 46 | if(i < colourMap->count) { 47 | if(colourMap->is16) { 48 | r = colourMap->data.shorts[3*i+0]; 49 | g = colourMap->data.shorts[3*i+1]; 50 | b = colourMap->data.shorts[3*i+2]; 51 | } else { 52 | r = colourMap->data.bytes[3*i+0]; 53 | g = colourMap->data.bytes[3*i+1]; 54 | b = colourMap->data.bytes[3*i+2]; 55 | } 56 | } 57 | outValue = ((((r * (1 + out->redMax)) >> shift) << out->redShift) | 58 | (((g * (1 + out->greenMax)) >> shift) << out->greenShift) | 59 | (((b * (1 + out->blueMax)) >> shift) << out->blueShift)); 60 | *(uint32_t*)&t[3*i] = outValue; 61 | if(!rfbEndianTest) 62 | memmove(t+3*i,t+3*i+1,3); 63 | if (out->bigEndian != in->bigEndian) { 64 | c = t[3*i]; t[3*i] = t[3*i+2]; t[3*i+2] = c; 65 | } 66 | } 67 | } 68 | 69 | /* 70 | * rfbInitTrueColourSingleTable sets up a single lookup table for truecolour 71 | * translation. 72 | */ 73 | 74 | static void 75 | rfbInitTrueColourSingleTable24 (char **table, rfbPixelFormat *in, 76 | rfbPixelFormat *out) 77 | { 78 | int i,outValue; 79 | int inRed, inGreen, inBlue, outRed, outGreen, outBlue; 80 | uint8_t *t; 81 | uint8_t c; 82 | int nEntries = 1 << in->bitsPerPixel; 83 | 84 | if (*table) free(*table); 85 | *table = (char *)malloc(nEntries * 3 + 1); 86 | t = (uint8_t *)*table; 87 | 88 | for (i = 0; i < nEntries; i++) { 89 | inRed = (i >> in->redShift) & in->redMax; 90 | inGreen = (i >> in->greenShift) & in->greenMax; 91 | inBlue = (i >> in->blueShift) & in->blueMax; 92 | 93 | outRed = (inRed * out->redMax + in->redMax / 2) / in->redMax; 94 | outGreen = (inGreen * out->greenMax + in->greenMax / 2) / in->greenMax; 95 | outBlue = (inBlue * out->blueMax + in->blueMax / 2) / in->blueMax; 96 | 97 | outValue = ((outRed << out->redShift) | 98 | (outGreen << out->greenShift) | 99 | (outBlue << out->blueShift)); 100 | *(uint32_t*)&t[3*i] = outValue; 101 | if(!rfbEndianTest) 102 | memmove(t+3*i,t+3*i+1,3); 103 | if (out->bigEndian != in->bigEndian) { 104 | c = t[3*i]; t[3*i] = t[3*i+2]; t[3*i+2] = c; 105 | } 106 | } 107 | } 108 | 109 | 110 | /* 111 | * rfbInitTrueColourRGBTables sets up three separate lookup tables for the 112 | * red, green and blue values. 113 | */ 114 | 115 | static void 116 | rfbInitTrueColourRGBTables24 (char **table, rfbPixelFormat *in, 117 | rfbPixelFormat *out) 118 | { 119 | uint8_t *redTable; 120 | uint8_t *greenTable; 121 | uint8_t *blueTable; 122 | 123 | if (*table) free(*table); 124 | *table = (char *)malloc((in->redMax + in->greenMax + in->blueMax + 3) 125 | * 3 + 1); 126 | redTable = (uint8_t *)*table; 127 | greenTable = redTable + 3*(in->redMax + 1); 128 | blueTable = greenTable + 3*(in->greenMax + 1); 129 | 130 | rfbInitOneRGBTable24 (redTable, in->redMax, out->redMax, 131 | out->redShift, (out->bigEndian != in->bigEndian)); 132 | rfbInitOneRGBTable24 (greenTable, in->greenMax, out->greenMax, 133 | out->greenShift, (out->bigEndian != in->bigEndian)); 134 | rfbInitOneRGBTable24 (blueTable, in->blueMax, out->blueMax, 135 | out->blueShift, (out->bigEndian != in->bigEndian)); 136 | } 137 | 138 | static void 139 | rfbInitOneRGBTable24 (uint8_t *table, int inMax, int outMax, int outShift, 140 | int swap) 141 | { 142 | int i; 143 | int nEntries = inMax + 1; 144 | uint32_t outValue; 145 | uint8_t c; 146 | 147 | for (i = 0; i < nEntries; i++) { 148 | outValue = ((i * outMax + inMax / 2) / inMax) << outShift; 149 | *(uint32_t *)&table[3*i] = outValue; 150 | if(!rfbEndianTest) 151 | memmove(table+3*i,table+3*i+1,3); 152 | if (swap) { 153 | c = table[3*i]; table[3*i] = table[3*i+2]; 154 | table[3*i+2] = c; 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/vncterm/LinuxVNC.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "VNConsole.h" 3 | #include "vga.h" 4 | #include 5 | #include 6 | 7 | static int tty=2; 8 | static int tty_inject_device; 9 | 10 | void do_key(rfbBool down,rfbKeySym keySym,rfbClientPtr cl) 11 | { 12 | static char isControl=0; 13 | 14 | if(down) { 15 | /* if(keySym==XK_Escape) 16 | rfbCloseClient(cl); 17 | else */ if(keySym==XK_Control_L || keySym==XK_Control_R) 18 | isControl++; 19 | else if(tty_inject_device>=0) { 20 | if(keySym==XK_Escape) 21 | keySym=27; 22 | if(isControl) { 23 | if(keySym>='a' && keySym<='z') 24 | keySym-='a'-1; 25 | else if(keySym>='A' && keySym<='Z') 26 | keySym-='A'-1; 27 | else 28 | keySym=0xffff; 29 | } 30 | 31 | if(keySym==XK_Tab) 32 | keySym='\t'; 33 | else if(keySym==XK_Return) 34 | keySym='\r'; 35 | else if(keySym==XK_BackSpace) 36 | keySym=8; 37 | else if(keySym==XK_Home || keySym==XK_KP_Home) 38 | keySym=1; 39 | else if(keySym==XK_End || keySym==XK_KP_End) 40 | keySym=5; 41 | else if(keySym==XK_Up || keySym==XK_KP_Up) 42 | keySym=16; 43 | else if(keySym==XK_Down || keySym==XK_KP_Down) 44 | keySym=14; 45 | else if(keySym==XK_Right || keySym==XK_KP_Right) 46 | keySym=6; 47 | else if(keySym==XK_Left || keySym==XK_KP_Left) 48 | keySym=2; 49 | 50 | if(keySym<0x100) { 51 | int ret; 52 | ret=ioctl(tty_inject_device,TIOCSTI,&keySym); 53 | if(ret<0) { 54 | static char device[64]; 55 | close(tty_inject_device); 56 | sprintf(device,"/dev/tty%d",tty); 57 | tty_inject_device=open(device,O_WRONLY); 58 | ret=ioctl(tty_inject_device,TIOCSTI,&keySym); 59 | if(ret<0) 60 | rfbErr("Couldn't reopen device %s!\n",device); 61 | } 62 | } 63 | } 64 | } else if(keySym==XK_Control_L || keySym==XK_Control_R) 65 | isControl--; 66 | } 67 | 68 | /* these colours are from linux kernel drivers/char/console.c */ 69 | unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7, 70 | 8,12,10,14, 9,13,11,15 }; 71 | /* the default colour table, for VGA+ colour systems */ 72 | int default_red[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa, 73 | 0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff}; 74 | int default_grn[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa, 75 | 0x55,0x55,0xff,0xff,0x55,0x55,0xff,0xff}; 76 | int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa, 77 | 0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff}; 78 | 79 | int main(int argc,char **argv) 80 | { 81 | int width=80,height=25; 82 | char *buffer; 83 | vncConsolePtr console; 84 | char tty_device[64],title[128]; 85 | int i; 86 | FILE* tty_file; 87 | struct winsize dimensions; 88 | 89 | if(argc>1) { 90 | if((tty=atoi(argv[1]))<1) { 91 | rfbErr("Usage: %s [tty_number [vnc args]]\n",argv[0]); 92 | exit(1); 93 | } else { 94 | argv++; 95 | argc--; 96 | } 97 | } 98 | 99 | /* getopt goes here! */ 100 | 101 | sprintf(tty_device,"/dev/tty%d",tty); 102 | if((tty_inject_device=open(tty_device,O_WRONLY))<0) { 103 | rfbErr("Couldn't open tty device %s!\n",tty_device); 104 | exit(1); 105 | } 106 | rfbLog("Using device %s.\n",tty_device); 107 | 108 | if(ioctl(tty_inject_device,TIOCGWINSZ,&dimensions)>=0) { 109 | width=dimensions.ws_col; 110 | height=dimensions.ws_row; 111 | } 112 | 113 | sprintf(title,"LinuxVNC: /dev/tty%d",tty); 114 | 115 | /* console init */ 116 | console=vcGetConsole(&argc,argv,width,height,&vgaFont,TRUE); 117 | for(i=0;i<16;i++) { 118 | console->screen->colourMap.data.bytes[i*3+0]=default_red[color_table[i]]; 119 | console->screen->colourMap.data.bytes[i*3+1]=default_grn[color_table[i]]; 120 | console->screen->colourMap.data.bytes[i*3+2]=default_blu[color_table[i]]; 121 | } 122 | console->screen->desktopName=title; 123 | console->screen->kbdAddEvent=do_key; 124 | console->selectTimeOut=100000; 125 | console->wrapBottomToTop=TRUE; 126 | #ifdef USE_OLD_VCS 127 | buffer=malloc(width*height); 128 | console->cursorActive=FALSE; 129 | #else 130 | buffer=malloc(width*height*2+4); 131 | console->cursorActive=TRUE; 132 | #endif 133 | /* memcpy(buffer,console->screenBuffer,width*height); */ 134 | 135 | #ifdef USE_OLD_VCS 136 | sprintf(tty_device,"/dev/vcs%d",tty); 137 | #else 138 | sprintf(tty_device,"/dev/vcsa%d",tty); 139 | #endif 140 | 141 | while(rfbIsActive(console->screen)) { 142 | if(!console->currentlyMarking) { 143 | tty_file=fopen(tty_device,"rb"); 144 | if(!tty_file) { 145 | rfbErr("cannot open device \"%s\"\n", 146 | tty_device); 147 | exit(1); 148 | } 149 | #ifdef USE_OLD_VCS 150 | fread(buffer,width,height,tty_file); 151 | #else 152 | fread(buffer,width*height*2+4,1,tty_file); 153 | vcHideCursor(console); 154 | #endif 155 | fclose(tty_file); 156 | 157 | for(i=0;iwidth*console->height;i++) { 158 | if 159 | #ifdef USE_OLD_VCS 160 | (buffer[i]!=console->screenBuffer[i]) 161 | #else 162 | (buffer[4+2*i]!=console->screenBuffer[i] || 163 | buffer[5+2*i]!=console->attributeBuffer[i]) 164 | #endif 165 | { 166 | console->x=(i%console->width); 167 | console->y=(i/console->width); 168 | /* 169 | rfbLog("changes: %d,%d (%d!=%d || %d!=%d)\n", 170 | console->x,console->y, 171 | buffer[4+2*i],console->screenBuffer[i], 172 | buffer[5+2*i],console->attributeBuffer[i]); 173 | */ 174 | 175 | #ifdef USE_OLD_VCS 176 | vcPutChar(console,buffer[i]); 177 | #else 178 | vcPutCharColour(console,buffer[4+i*2],buffer[5+i*2]&0x7,buffer[5+i*2]>>4); 179 | #endif 180 | } 181 | } 182 | console->x=buffer[2]; 183 | console->y=buffer[3]; 184 | } 185 | vcProcessEvents(console); 186 | } 187 | return(0); 188 | } 189 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncclient/cursor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001,2002 Constantin Kaplinsky. All Rights Reserved. 3 | * 4 | * This is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This software is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this software; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 17 | * USA. 18 | */ 19 | 20 | /* 21 | * cursor.c - code to support cursor shape updates (XCursor and 22 | * RichCursor preudo-encodings). 23 | */ 24 | 25 | #include 26 | 27 | 28 | #define OPER_SAVE 0 29 | #define OPER_RESTORE 1 30 | 31 | #define RGB24_TO_PIXEL(bpp,r,g,b) \ 32 | ((((uint##bpp##_t)(r) & 0xFF) * client->format.redMax + 127) / 255 \ 33 | << client->format.redShift | \ 34 | (((uint##bpp##_t)(g) & 0xFF) * client->format.greenMax + 127) / 255 \ 35 | << client->format.greenShift | \ 36 | (((uint##bpp##_t)(b) & 0xFF) * client->format.blueMax + 127) / 255 \ 37 | << client->format.blueShift) 38 | 39 | 40 | /********************************************************************* 41 | * HandleCursorShape(). Support for XCursor and RichCursor shape 42 | * updates. We emulate cursor operating on the frame buffer (that is 43 | * why we call it "software cursor"). 44 | ********************************************************************/ 45 | 46 | rfbBool HandleCursorShape(rfbClient* client,int xhot, int yhot, int width, int height, uint32_t enc) 47 | { 48 | int bytesPerPixel; 49 | size_t bytesPerRow, bytesMaskData; 50 | rfbXCursorColors rgb; 51 | uint32_t colors[2]; 52 | char *buf; 53 | uint8_t *ptr; 54 | int x, y, b; 55 | 56 | bytesPerPixel = client->format.bitsPerPixel / 8; 57 | bytesPerRow = (width + 7) / 8; 58 | bytesMaskData = bytesPerRow * height; 59 | 60 | if (width * height == 0) 61 | return TRUE; 62 | 63 | /* Allocate memory for pixel data and temporary mask data. */ 64 | if(client->rcSource) 65 | free(client->rcSource); 66 | 67 | client->rcSource = malloc(width * height * bytesPerPixel); 68 | if (client->rcSource == NULL) 69 | return FALSE; 70 | 71 | buf = malloc(bytesMaskData); 72 | if (buf == NULL) { 73 | free(client->rcSource); 74 | client->rcSource = NULL; 75 | return FALSE; 76 | } 77 | 78 | /* Read and decode cursor pixel data, depending on the encoding type. */ 79 | 80 | if (enc == rfbEncodingXCursor) { 81 | /* Read and convert background and foreground colors. */ 82 | if (!ReadFromRFBServer(client, (char *)&rgb, sz_rfbXCursorColors)) { 83 | free(client->rcSource); 84 | client->rcSource = NULL; 85 | free(buf); 86 | return FALSE; 87 | } 88 | colors[0] = RGB24_TO_PIXEL(32, rgb.backRed, rgb.backGreen, rgb.backBlue); 89 | colors[1] = RGB24_TO_PIXEL(32, rgb.foreRed, rgb.foreGreen, rgb.foreBlue); 90 | 91 | /* Read 1bpp pixel data into a temporary buffer. */ 92 | if (!ReadFromRFBServer(client, buf, bytesMaskData)) { 93 | free(client->rcSource); 94 | client->rcSource = NULL; 95 | free(buf); 96 | return FALSE; 97 | } 98 | 99 | /* Convert 1bpp data to byte-wide color indices. */ 100 | ptr = client->rcSource; 101 | for (y = 0; y < height; y++) { 102 | for (x = 0; x < width / 8; x++) { 103 | for (b = 7; b >= 0; b--) { 104 | *ptr = buf[y * bytesPerRow + x] >> b & 1; 105 | ptr += bytesPerPixel; 106 | } 107 | } 108 | for (b = 7; b > 7 - width % 8; b--) { 109 | *ptr = buf[y * bytesPerRow + x] >> b & 1; 110 | ptr += bytesPerPixel; 111 | } 112 | } 113 | 114 | /* Convert indices into the actual pixel values. */ 115 | switch (bytesPerPixel) { 116 | case 1: 117 | for (x = 0; x < width * height; x++) 118 | client->rcSource[x] = (uint8_t)colors[client->rcSource[x]]; 119 | break; 120 | case 2: 121 | for (x = 0; x < width * height; x++) 122 | ((uint16_t *)client->rcSource)[x] = (uint16_t)colors[client->rcSource[x * 2]]; 123 | break; 124 | case 4: 125 | for (x = 0; x < width * height; x++) 126 | ((uint32_t *)client->rcSource)[x] = colors[client->rcSource[x * 4]]; 127 | break; 128 | } 129 | 130 | } else { /* enc == rfbEncodingRichCursor */ 131 | 132 | if (!ReadFromRFBServer(client, (char *)client->rcSource, width * height * bytesPerPixel)) { 133 | free(client->rcSource); 134 | client->rcSource = NULL; 135 | free(buf); 136 | return FALSE; 137 | } 138 | 139 | } 140 | 141 | /* Read and decode mask data. */ 142 | 143 | if (!ReadFromRFBServer(client, buf, bytesMaskData)) { 144 | free(client->rcSource); 145 | client->rcSource = NULL; 146 | free(buf); 147 | return FALSE; 148 | } 149 | 150 | client->rcMask = malloc(width * height); 151 | if (client->rcMask == NULL) { 152 | free(client->rcSource); 153 | client->rcSource = NULL; 154 | free(buf); 155 | return FALSE; 156 | } 157 | 158 | ptr = client->rcMask; 159 | for (y = 0; y < height; y++) { 160 | for (x = 0; x < width / 8; x++) { 161 | for (b = 7; b >= 0; b--) { 162 | *ptr++ = buf[y * bytesPerRow + x] >> b & 1; 163 | } 164 | } 165 | for (b = 7; b > 7 - width % 8; b--) { 166 | *ptr++ = buf[y * bytesPerRow + x] >> b & 1; 167 | } 168 | } 169 | 170 | if (client->GotCursorShape != NULL) { 171 | client->GotCursorShape(client, xhot, yhot, width, height, bytesPerPixel); 172 | } 173 | 174 | free(buf); 175 | 176 | return TRUE; 177 | } 178 | 179 | 180 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/contrib/zippy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | static int maxx=400, maxy=400, bpp=4; 8 | /* odd maxx doesn't work (vncviewer bug) */ 9 | 10 | /* Here we create a structure so that every client has it's own pointer */ 11 | 12 | /* turns the framebuffer black */ 13 | void blank_framebuffer(char* frame_buffer, int x1, int y1, int x2, int y2); 14 | /* displays a red bar, a green bar, and a blue bar */ 15 | void draw_primary_colors (char* frame_buffer, int x1, int y1, int x2, int y2); 16 | void linecount (char* frame_buffer); 17 | /* handles mouse events */ 18 | void on_mouse_event (int buttonMask,int x,int y,rfbClientPtr cl); 19 | /* handles keyboard events */ 20 | void on_key_press (rfbBool down,rfbKeySym key,rfbClientPtr cl); 21 | 22 | int main (int argc, char **argv) 23 | { 24 | rfbScreenInfoPtr server; 25 | 26 | if(!rfbProcessSizeArguments(&maxx,&maxy,&bpp,&argc,argv)) 27 | return 1; 28 | 29 | server = rfbGetScreen (&argc, argv, maxx, maxy, 8, 3, bpp); 30 | server->desktopName = "Zippy das wundersquirrel\'s VNC server"; 31 | server->frameBuffer = (char*)malloc(maxx*maxy*bpp); 32 | server->alwaysShared = TRUE; 33 | server->kbdAddEvent = on_key_press; 34 | server->ptrAddEvent = on_mouse_event; 35 | 36 | rfbInitServer (server); 37 | 38 | blank_framebuffer(server->frameBuffer, 0, 0, maxx, maxy); 39 | rfbRunEventLoop (server, -1, FALSE); 40 | free(server->frameBuffer); 41 | rfbScreenCleanup (server); 42 | return 0; 43 | } 44 | 45 | void blank_framebuffer(char* frame_buffer, int x1, int y1, int x2, int y2) 46 | { 47 | int i; 48 | for (i=0; i < maxx * maxy * bpp; i++) frame_buffer[i]=(char) 0; 49 | } 50 | 51 | void draw_primary_colors (char* frame_buffer, int x1, int y1, int x2, int y2) 52 | { 53 | int i, j, current_pixel; 54 | for (i=y1; i < y2; i++){ 55 | for (j=x1; j < x2; j++) { 56 | current_pixel = (i*x2 + j) * bpp; 57 | if (i < y2 ) { 58 | frame_buffer[current_pixel+0] = (char) 128; 59 | frame_buffer[current_pixel+1] = (char) 0; 60 | frame_buffer[current_pixel+2] = (char) 0; 61 | } 62 | if (i < y2/3*2) { 63 | frame_buffer[current_pixel+0] = (char) 0; 64 | frame_buffer[current_pixel+1] = (char) 128; 65 | frame_buffer[current_pixel+2] = (char) 0; 66 | } 67 | if (i < y2/3) { 68 | frame_buffer[current_pixel+0] = (char) 0; 69 | frame_buffer[current_pixel+1] = (char) 0; 70 | frame_buffer[current_pixel+2] = (char) 128; 71 | } 72 | } 73 | } 74 | } 75 | 76 | /* Dscho's versions (slower, but works for bpp != 3 or 4) */ 77 | static void draw_primary_colours_generic(rfbScreenInfoPtr s,int x1,int y1,int x2,int y2) 78 | { 79 | rfbPixelFormat f=s->serverFormat; 80 | int i,j; 81 | for(j=y1;jserverFormat; 94 | int i,j,y3=(y1*2+y2)/3,y4=(y1+y2*2)/3; 95 | /* draw first pixel */ 96 | rfbDrawPixel(s,x1,y1,f.redMax<frameBuffer+(x)*bpp+(y)*s->paddedWidthInBytes 103 | memcpy(ADDR(i,j+y1),ADDR(x1,y1),bpp); 104 | memcpy(ADDR(i,j+y3),ADDR(x1,y3),bpp); 105 | memcpy(ADDR(i,j+y4),ADDR(x1,y4),bpp); 106 | } 107 | } 108 | 109 | static void draw_primary_colours_generic_ultrafast(rfbScreenInfoPtr s,int x1,int y1,int x2,int y2) 110 | { 111 | rfbPixelFormat f=s->serverFormat; 112 | int y3=(y1*2+y2)/3,y4=(y1+y2*2)/3; 113 | /* fill rectangles */ 114 | rfbFillRect(s,x1,y1,x2,y3,f.redMax<maxy-20; i-=4) 123 | for (j=0; j<4; j++) for (k=0; k < maxx; k++) { 124 | current_pixel = (i*j*maxx + k) * bpp; 125 | if (i%2 == 0) { 126 | frame_buffer[current_pixel+0] = (char) 0; 127 | frame_buffer[current_pixel+1] = (char) 0; 128 | frame_buffer[current_pixel+2] = (char) 128; 129 | } 130 | 131 | if (i%2 == 1) { 132 | frame_buffer[current_pixel+0] = (char) 128; 133 | frame_buffer[current_pixel+1] = (char) 0; 134 | frame_buffer[current_pixel+2] = (char) 0; 135 | } 136 | } 137 | 138 | } 139 | 140 | 141 | void on_key_press (rfbBool down,rfbKeySym key,rfbClientPtr cl) 142 | { 143 | if (down) /* or else the action occurs on both the press and depress */ 144 | switch (key) { 145 | 146 | case XK_b: 147 | case XK_B: 148 | blank_framebuffer(cl->screen->frameBuffer, 0, 0, maxx, maxy); 149 | rfbDrawString(cl->screen,&default8x16Font,20,maxy-20,"Hello, World!",0xffffff); 150 | rfbMarkRectAsModified(cl->screen,0, 0,maxx,maxy); 151 | rfbLog("Framebuffer blanked\n"); 152 | break; 153 | case XK_p: 154 | case XK_P: 155 | /* draw_primary_colors (cl->screen->frameBuffer, 0, 0, maxx, maxy); */ 156 | draw_primary_colours_generic_ultrafast (cl->screen, 0, 0, maxx, maxy); 157 | rfbMarkRectAsModified(cl->screen,0, 0,maxx,maxy); 158 | rfbLog("Primary colors displayed\n"); 159 | break; 160 | case XK_Q: 161 | case XK_q: 162 | rfbLog("Exiting now\n"); 163 | exit(0); 164 | case XK_C: 165 | case XK_c: 166 | rfbDrawString(cl->screen,&default8x16Font,20,100,"Hello, World!",0xffffff); 167 | rfbMarkRectAsModified(cl->screen,0, 0,maxx,maxy); 168 | break; 169 | default: 170 | rfbLog("The %c key was pressed\n", (char) key); 171 | } 172 | } 173 | 174 | 175 | void on_mouse_event (int buttonMask,int x,int y,rfbClientPtr cl) 176 | { 177 | printf("buttonMask: %i\n" 178 | "x: %i\n" "y: %i\n", buttonMask, x, y); 179 | } 180 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/NEWS: -------------------------------------------------------------------------------- 1 | Mark sent me patches to no longer need C++ for ZRLE encoding! 2 | added --disable-cxx Option for configure 3 | x11vnc changes from Karl Runge: 4 | - Changed all those whimpy printf(...)'s into manly fprintf(stdxxx,...)'s. 5 | 6 | - Added -q switch (quiet) to suppress printing all the debug-looking output. 7 | 8 | - Added -bg switch to fork into background after everything is set up. 9 | (checks for LIBVNCSERVER_HAVE_FORK and LIBVNCSERVER_HAVE_SETSID) 10 | 11 | - Print this string out to stdout: 'PORT=XXXX' (usually XXXX = 5900). 12 | Combining with -bg, easy to write a ssh/rsh wrapper with something like: 13 | port=`ssh $host "x11vnc -bg .."` then run vncviewer based on $port output. 14 | (tunneling the vnc traffic thru ssh a bit more messy, but doable) 15 | 16 | - Quite a bit of code to be more careful when doing 8bpp indexed color, e.g. 17 | not assuming NCOLORS is 256, handling 8bit TrueColor and Direct Color, etc 18 | (I did all this probably in April, not quite clear in my mind now, but 19 | I did test it out a fair amount on my old Sparcstation 20 wrt a user's 20 | questions). 21 | introduce rfbErr for Errors (Erik) 22 | make rfbLog overridable (suggested by Erik) 23 | don't reutrn on EINTR in WriteExact()/ReadExact() (suggested by Erik) 24 | use AX_PREFIX_CONFIG_H to prefix constants in config.h to avoid 25 | name clashes (also suggested by Erik) 26 | transformed Bool, KeySym, Pixel to rfbBool, rfbKeySym, rfbPixel 27 | (as suggested by Erik) 28 | purged exit() calls (suggested by Erik) 29 | fixed bug with maxRectsPerUpdate and Tight Encoding (these are incompatible) 30 | checked sync with TightVNC 1.2.8: 31 | viewonly/full passwords; if given a list, only the first is a full one 32 | vncRandomBytes is a little more secure now 33 | new weights for tight encoding 34 | checked sync with RealVNC 3.3.7 35 | introduced maxRectsPerUpdate 36 | added first alpha version of LibVNCClient 37 | added simple and simple15 example (really simple examples) 38 | finally got around to fix configure in CVS 39 | long standing http bug (.jar was sent twice) fixed by a friend of Karl named Mike 40 | http options in cargs 41 | when closing a client and no longer listening for new ones, don't crash 42 | fixed a bug with ClientConnectionGone 43 | endianness is checked at configure time 44 | fixed a bug that prevented the first client from being closed 45 | fixed that annoying "libvncserver-config --link" bug 46 | make rfbReverseByte public (for rdp2vnc) 47 | fixed compilation on OS X, IRIX, Solaris 48 | install target for headers is now ${prefix}/include/rfb ("#include ") 49 | renamed "sraRegion.h" to "rfbregion.h" 50 | CARD{8,16,32} are more standard uint{8,16,32}_t now 51 | fixed LinuxVNC colour handling 52 | fixed a bug with pthreads where the connection was not closed 53 | moved vncterm to main package (LinuxVNC included) 54 | portability fixes (IRIX, OSX, Solaris) 55 | more portable way to determine endianness and types of a given size 56 | through autoconf based methods 57 | 0.5 58 | rpm packaging through autoconf 59 | autoconf'ed the whole package (including optional support for zlib, 60 | pthreads and libjpeg as well as zrle/c++) 61 | moved appropriate files to contrib/ and examples/ respectively 62 | fixed long standing cargs bug (Justin "Zippy" Dearing) 63 | Even better x11vnc from Karl J. Runge! (supports different kbd layouts of 64 | client/server) 65 | Better x11vnc from Karl J. Runge! 66 | fixed severe bug (Const Kaplinsky) 67 | got patch from Const Kaplisnky with CursorPosUpdate encoding and some Docs 68 | sync'ed with newest RealVNC (ZRLE encoding) 69 | a HTTP request for tunnelling was added (to fool strict web proxies) 70 | sync'ed with TightVNC 1.2.5 71 | 0.4 72 | support for NewFB from Const Kaplinsky 73 | memory leaks squashed (localtime pseudo leak is still there :-) 74 | small improvements for OSXvnc (still not working correctly) 75 | synced with TightVNC 1.2.3 76 | solaris compile cleanups 77 | many x11vnc improvements 78 | added backchannel, an encoding which needs special clients to pass 79 | arbitrary data to the client 80 | changes from Tim Jansen regarding multi threading and client blocking 81 | as well as C++ compliancy 82 | x11vnc can be controlled by starting again with special options if compiling 83 | with LOCAL_CONTROL defined 84 | 0.3 85 | added x11vnc, a x0rfbserver clone 86 | regard deferUpdateTime in processEvents, if usec<0 87 | initialize deferUpdateTime (memory "leak"!) 88 | changed command line handling (arguments are parsed and then removed) 89 | added very simple example: zippy 90 | added rfbDrawLine, rfbDrawPixel 91 | 0.2 92 | inserted a deferUpdate mechanism (X11 independent). 93 | removed deletion of requestedRegion 94 | added rfbLoadConsoleFont 95 | fixed font colour handling. 96 | added rfbSelectBox 97 | added rfbDrawCharWithClip to allow for clipping and a background colour. 98 | fixed font colours 99 | added rfbFillRect 100 | added IO function to check password. 101 | rfbNewClient now sets the socket in the fd_set (for the select() call) 102 | when compiling the library with HAVE_PTHREADS and an application 103 | which includes "rfb.h" without, the structures got mixed up. 104 | So, the pthreads section is now always at the end, and also 105 | you get a linker error for rfbInitServer when using two different 106 | pthread setups. 107 | fixed two deadlocks: when setting a cursor and when using CopyRect 108 | fixed CopyRect when copying modified regions (they lost the modified 109 | property) 110 | WIN32 target compiles and works for example :-) 111 | fixed CopyRect (was using the wrong order of rectangles...) 112 | should also work with pthreads, because copyrects are 113 | always sent immediately (so that two consecutive copy rects 114 | cannot conflict). 115 | changed rfbUndrawCursor(rfbClientPtr) to (rfbScreenInfoPtr), because 116 | this makes more sense! 117 | flag backgroundLoop in rfbScreenInfo (if having pthreads) 118 | CopyRect & CopyRegion were implemented. 119 | if you use a rfbDoCopyR* function, it copies the data in the 120 | framebuffer. If you prefer to do that yourself, use rfbScheduleCopyR* 121 | instead; this doesn't modify the frameBuffer. 122 | added flag to optionally not send XCursor updates, but only RichCursor, 123 | or if that is not possible, fall back to server side cursor. 124 | This is useful if your cursor has many nice colours. 125 | fixed java viewer on server side: 126 | SendCursorUpdate would send data even before the client pixel format 127 | was set, but the java applet doesn't like the server's format. 128 | fixed two pthread issues: 129 | rfbSendFramebuffer was sent by a ProcessClientMessage function 130 | (unprotected by updateMutex). 131 | cursor coordinates were set without protection by cursorMutex 132 | source is now equivalent to TridiaVNC 1.2.1 133 | pthreads now work (use iterators!) 134 | cursors are supported (rfbSetCursor automatically undraws cursor) 135 | support for 3 bytes/pixel (slow!) 136 | server side colourmap support 137 | fixed rfbCloseClient not to close the connection (pthreads!) 138 | this is done lazily (and with proper signalling). 139 | cleaned up mac.c (from original OSXvnc); now compiles (untested!) 140 | compiles cleanly on Linux, IRIX, BSD, Apple (Darwin) 141 | fixed prototypes 142 | 0.1 143 | rewrote API to use pseudo-methods instead of required functions. 144 | lots of clean up. 145 | Example can show symbols now. 146 | All encodings 147 | HTTP 148 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncclient/ultra.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2000 Tridia Corporation. All Rights Reserved. 3 | * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. 4 | * 5 | * This is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This software is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this software; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 18 | * USA. 19 | */ 20 | 21 | /* 22 | * ultrazip.c - handle ultrazip encoding. 23 | * 24 | * This file shouldn't be compiled directly. It is included multiple times by 25 | * rfbproto.c, each time with a different definition of the macro BPP. For 26 | * each value of BPP, this file defines a function which handles an zlib 27 | * encoded rectangle with BPP bits per pixel. 28 | */ 29 | 30 | #define HandleUltraZipBPP CONCAT2E(HandleUltraZip,BPP) 31 | #define HandleUltraBPP CONCAT2E(HandleUltra,BPP) 32 | #define CARDBPP CONCAT3E(uint,BPP,_t) 33 | 34 | static rfbBool 35 | HandleUltraBPP (rfbClient* client, int rx, int ry, int rw, int rh) 36 | { 37 | rfbZlibHeader hdr; 38 | int toRead=0; 39 | int inflateResult=0; 40 | int uncompressedBytes = (( rw * rh ) * ( BPP / 8 )); 41 | 42 | if (!ReadFromRFBServer(client, (char *)&hdr, sz_rfbZlibHeader)) 43 | return FALSE; 44 | 45 | toRead = rfbClientSwap32IfLE(hdr.nBytes); 46 | if (toRead==0) return TRUE; 47 | 48 | if (uncompressedBytes==0) 49 | { 50 | rfbClientLog("ultra error: rectangle has 0 uncomressed bytes ((%dw * %dh) * (%d / 8))\n", rw, rh, BPP); 51 | return FALSE; 52 | } 53 | 54 | /* First make sure we have a large enough raw buffer to hold the 55 | * decompressed data. In practice, with a fixed BPP, fixed frame 56 | * buffer size and the first update containing the entire frame 57 | * buffer, this buffer allocation should only happen once, on the 58 | * first update. 59 | */ 60 | if ( client->raw_buffer_size < uncompressedBytes) { 61 | if ( client->raw_buffer != NULL ) { 62 | free( client->raw_buffer ); 63 | } 64 | client->raw_buffer_size = uncompressedBytes; 65 | /* buffer needs to be aligned on 4-byte boundaries */ 66 | if ((client->raw_buffer_size % 4)!=0) 67 | client->raw_buffer_size += (4-(client->raw_buffer_size % 4)); 68 | client->raw_buffer = (char*) malloc( client->raw_buffer_size ); 69 | } 70 | 71 | /* allocate enough space to store the incoming compressed packet */ 72 | if ( client->ultra_buffer_size < toRead ) { 73 | if ( client->ultra_buffer != NULL ) { 74 | free( client->ultra_buffer ); 75 | } 76 | client->ultra_buffer_size = toRead; 77 | /* buffer needs to be aligned on 4-byte boundaries */ 78 | if ((client->ultra_buffer_size % 4)!=0) 79 | client->ultra_buffer_size += (4-(client->ultra_buffer_size % 4)); 80 | client->ultra_buffer = (char*) malloc( client->ultra_buffer_size ); 81 | } 82 | 83 | /* Fill the buffer, obtaining data from the server. */ 84 | if (!ReadFromRFBServer(client, client->ultra_buffer, toRead)) 85 | return FALSE; 86 | 87 | /* uncompress the data */ 88 | uncompressedBytes = client->raw_buffer_size; 89 | inflateResult = lzo1x_decompress( 90 | (lzo_byte *)client->ultra_buffer, toRead, 91 | (lzo_byte *)client->raw_buffer, (lzo_uintp) &uncompressedBytes, 92 | NULL); 93 | 94 | 95 | if ((rw * rh * (BPP / 8)) != uncompressedBytes) 96 | rfbClientLog("Ultra decompressed too little (%d < %d)", (rw * rh * (BPP / 8)), uncompressedBytes); 97 | 98 | /* Put the uncompressed contents of the update on the screen. */ 99 | if ( inflateResult == LZO_E_OK ) 100 | { 101 | CopyRectangle(client, (unsigned char *)client->raw_buffer, rx, ry, rw, rh); 102 | } 103 | else 104 | { 105 | rfbClientLog("ultra decompress returned error: %d\n", 106 | inflateResult); 107 | return FALSE; 108 | } 109 | return TRUE; 110 | } 111 | 112 | 113 | /* UltraZip is like rre in that it is composed of subrects */ 114 | static rfbBool 115 | HandleUltraZipBPP (rfbClient* client, int rx, int ry, int rw, int rh) 116 | { 117 | rfbZlibHeader hdr; 118 | int i=0; 119 | int toRead=0; 120 | int inflateResult=0; 121 | unsigned char *ptr=NULL; 122 | int uncompressedBytes = ry + (rw * 65535); 123 | unsigned int numCacheRects = rx; 124 | 125 | if (!ReadFromRFBServer(client, (char *)&hdr, sz_rfbZlibHeader)) 126 | return FALSE; 127 | 128 | toRead = rfbClientSwap32IfLE(hdr.nBytes); 129 | 130 | if (toRead==0) return TRUE; 131 | 132 | if (uncompressedBytes==0) 133 | { 134 | rfbClientLog("ultrazip error: rectangle has 0 uncomressed bytes (%dy + (%dw * 65535)) (%d rectangles)\n", ry, rw, rx); 135 | return FALSE; 136 | } 137 | 138 | /* First make sure we have a large enough raw buffer to hold the 139 | * decompressed data. In practice, with a fixed BPP, fixed frame 140 | * buffer size and the first update containing the entire frame 141 | * buffer, this buffer allocation should only happen once, on the 142 | * first update. 143 | */ 144 | if ( client->raw_buffer_size < (uncompressedBytes + 500)) { 145 | if ( client->raw_buffer != NULL ) { 146 | free( client->raw_buffer ); 147 | } 148 | client->raw_buffer_size = uncompressedBytes + 500; 149 | /* buffer needs to be aligned on 4-byte boundaries */ 150 | if ((client->raw_buffer_size % 4)!=0) 151 | client->raw_buffer_size += (4-(client->raw_buffer_size % 4)); 152 | client->raw_buffer = (char*) malloc( client->raw_buffer_size ); 153 | } 154 | 155 | 156 | /* allocate enough space to store the incoming compressed packet */ 157 | if ( client->ultra_buffer_size < toRead ) { 158 | if ( client->ultra_buffer != NULL ) { 159 | free( client->ultra_buffer ); 160 | } 161 | client->ultra_buffer_size = toRead; 162 | client->ultra_buffer = (char*) malloc( client->ultra_buffer_size ); 163 | } 164 | 165 | /* Fill the buffer, obtaining data from the server. */ 166 | if (!ReadFromRFBServer(client, client->ultra_buffer, toRead)) 167 | return FALSE; 168 | 169 | /* uncompress the data */ 170 | uncompressedBytes = client->raw_buffer_size; 171 | inflateResult = lzo1x_decompress( 172 | (lzo_byte *)client->ultra_buffer, toRead, 173 | (lzo_byte *)client->raw_buffer, (lzo_uintp) &uncompressedBytes, NULL); 174 | if ( inflateResult != LZO_E_OK ) 175 | { 176 | rfbClientLog("ultra decompress returned error: %d\n", 177 | inflateResult); 178 | return FALSE; 179 | } 180 | 181 | /* Put the uncompressed contents of the update on the screen. */ 182 | ptr = (unsigned char *)client->raw_buffer; 183 | for (i=0; i 23 | 24 | #define ZRLE_IN_BUFFER_SIZE 16384 25 | #define ZRLE_OUT_BUFFER_SIZE 1024 26 | #undef ZRLE_DEBUG 27 | 28 | static rfbBool zrleBufferAlloc(zrleBuffer *buffer, int size) 29 | { 30 | buffer->ptr = buffer->start = malloc(size); 31 | if (buffer->start == NULL) { 32 | buffer->end = NULL; 33 | return FALSE; 34 | } 35 | 36 | buffer->end = buffer->start + size; 37 | 38 | return TRUE; 39 | } 40 | 41 | static void zrleBufferFree(zrleBuffer *buffer) 42 | { 43 | if (buffer->start) 44 | free(buffer->start); 45 | buffer->start = buffer->ptr = buffer->end = NULL; 46 | } 47 | 48 | static rfbBool zrleBufferGrow(zrleBuffer *buffer, int size) 49 | { 50 | int offset; 51 | 52 | size += buffer->end - buffer->start; 53 | offset = ZRLE_BUFFER_LENGTH (buffer); 54 | 55 | buffer->start = realloc(buffer->start, size); 56 | if (!buffer->start) { 57 | return FALSE; 58 | } 59 | 60 | buffer->end = buffer->start + size; 61 | buffer->ptr = buffer->start + offset; 62 | 63 | return TRUE; 64 | } 65 | 66 | zrleOutStream *zrleOutStreamNew(void) 67 | { 68 | zrleOutStream *os; 69 | 70 | os = malloc(sizeof(zrleOutStream)); 71 | if (os == NULL) 72 | return NULL; 73 | 74 | if (!zrleBufferAlloc(&os->in, ZRLE_IN_BUFFER_SIZE)) { 75 | free(os); 76 | return NULL; 77 | } 78 | 79 | if (!zrleBufferAlloc(&os->out, ZRLE_OUT_BUFFER_SIZE)) { 80 | zrleBufferFree(&os->in); 81 | free(os); 82 | return NULL; 83 | } 84 | 85 | os->zs.zalloc = Z_NULL; 86 | os->zs.zfree = Z_NULL; 87 | os->zs.opaque = Z_NULL; 88 | if (deflateInit(&os->zs, Z_DEFAULT_COMPRESSION) != Z_OK) { 89 | zrleBufferFree(&os->in); 90 | free(os); 91 | return NULL; 92 | } 93 | 94 | return os; 95 | } 96 | 97 | void zrleOutStreamFree (zrleOutStream *os) 98 | { 99 | deflateEnd(&os->zs); 100 | zrleBufferFree(&os->in); 101 | zrleBufferFree(&os->out); 102 | free(os); 103 | } 104 | 105 | rfbBool zrleOutStreamFlush(zrleOutStream *os) 106 | { 107 | os->zs.next_in = os->in.start; 108 | os->zs.avail_in = ZRLE_BUFFER_LENGTH (&os->in); 109 | 110 | #ifdef ZRLE_DEBUG 111 | rfbLog("zrleOutStreamFlush: avail_in %d\n", os->zs.avail_in); 112 | #endif 113 | 114 | while (os->zs.avail_in != 0) { 115 | do { 116 | int ret; 117 | 118 | if (os->out.ptr >= os->out.end && 119 | !zrleBufferGrow(&os->out, os->out.end - os->out.start)) { 120 | rfbLog("zrleOutStreamFlush: failed to grow output buffer\n"); 121 | return FALSE; 122 | } 123 | 124 | os->zs.next_out = os->out.ptr; 125 | os->zs.avail_out = os->out.end - os->out.ptr; 126 | 127 | #ifdef ZRLE_DEBUG 128 | rfbLog("zrleOutStreamFlush: calling deflate, avail_in %d, avail_out %d\n", 129 | os->zs.avail_in, os->zs.avail_out); 130 | #endif 131 | 132 | if ((ret = deflate(&os->zs, Z_SYNC_FLUSH)) != Z_OK) { 133 | rfbLog("zrleOutStreamFlush: deflate failed with error code %d\n", ret); 134 | return FALSE; 135 | } 136 | 137 | #ifdef ZRLE_DEBUG 138 | rfbLog("zrleOutStreamFlush: after deflate: %d bytes\n", 139 | os->zs.next_out - os->out.ptr); 140 | #endif 141 | 142 | os->out.ptr = os->zs.next_out; 143 | } while (os->zs.avail_out == 0); 144 | } 145 | 146 | os->in.ptr = os->in.start; 147 | 148 | return TRUE; 149 | } 150 | 151 | static int zrleOutStreamOverrun(zrleOutStream *os, 152 | int size) 153 | { 154 | #ifdef ZRLE_DEBUG 155 | rfbLog("zrleOutStreamOverrun\n"); 156 | #endif 157 | 158 | while (os->in.end - os->in.ptr < size && os->in.ptr > os->in.start) { 159 | os->zs.next_in = os->in.start; 160 | os->zs.avail_in = ZRLE_BUFFER_LENGTH (&os->in); 161 | 162 | do { 163 | int ret; 164 | 165 | if (os->out.ptr >= os->out.end && 166 | !zrleBufferGrow(&os->out, os->out.end - os->out.start)) { 167 | rfbLog("zrleOutStreamOverrun: failed to grow output buffer\n"); 168 | return FALSE; 169 | } 170 | 171 | os->zs.next_out = os->out.ptr; 172 | os->zs.avail_out = os->out.end - os->out.ptr; 173 | 174 | #ifdef ZRLE_DEBUG 175 | rfbLog("zrleOutStreamOverrun: calling deflate, avail_in %d, avail_out %d\n", 176 | os->zs.avail_in, os->zs.avail_out); 177 | #endif 178 | 179 | if ((ret = deflate(&os->zs, 0)) != Z_OK) { 180 | rfbLog("zrleOutStreamOverrun: deflate failed with error code %d\n", ret); 181 | return 0; 182 | } 183 | 184 | #ifdef ZRLE_DEBUG 185 | rfbLog("zrleOutStreamOverrun: after deflate: %d bytes\n", 186 | os->zs.next_out - os->out.ptr); 187 | #endif 188 | 189 | os->out.ptr = os->zs.next_out; 190 | } while (os->zs.avail_out == 0); 191 | 192 | /* output buffer not full */ 193 | 194 | if (os->zs.avail_in == 0) { 195 | os->in.ptr = os->in.start; 196 | } else { 197 | /* but didn't consume all the data? try shifting what's left to the 198 | * start of the buffer. 199 | */ 200 | rfbLog("zrleOutStreamOverrun: out buf not full, but in data not consumed\n"); 201 | memmove(os->in.start, os->zs.next_in, os->in.ptr - os->zs.next_in); 202 | os->in.ptr -= os->zs.next_in - os->in.start; 203 | } 204 | } 205 | 206 | if (size > os->in.end - os->in.ptr) 207 | size = os->in.end - os->in.ptr; 208 | 209 | return size; 210 | } 211 | 212 | static int zrleOutStreamCheck(zrleOutStream *os, int size) 213 | { 214 | if (os->in.ptr + size > os->in.end) { 215 | return zrleOutStreamOverrun(os, size); 216 | } 217 | return size; 218 | } 219 | 220 | void zrleOutStreamWriteBytes(zrleOutStream *os, 221 | const zrle_U8 *data, 222 | int length) 223 | { 224 | const zrle_U8* dataEnd = data + length; 225 | while (data < dataEnd) { 226 | int n = zrleOutStreamCheck(os, dataEnd - data); 227 | memcpy(os->in.ptr, data, n); 228 | os->in.ptr += n; 229 | data += n; 230 | } 231 | } 232 | 233 | void zrleOutStreamWriteU8(zrleOutStream *os, zrle_U8 u) 234 | { 235 | zrleOutStreamCheck(os, 1); 236 | *os->in.ptr++ = u; 237 | } 238 | 239 | void zrleOutStreamWriteOpaque8(zrleOutStream *os, zrle_U8 u) 240 | { 241 | zrleOutStreamCheck(os, 1); 242 | *os->in.ptr++ = u; 243 | } 244 | 245 | void zrleOutStreamWriteOpaque16 (zrleOutStream *os, zrle_U16 u) 246 | { 247 | zrleOutStreamCheck(os, 2); 248 | *os->in.ptr++ = ((zrle_U8*)&u)[0]; 249 | *os->in.ptr++ = ((zrle_U8*)&u)[1]; 250 | } 251 | 252 | void zrleOutStreamWriteOpaque32 (zrleOutStream *os, zrle_U32 u) 253 | { 254 | zrleOutStreamCheck(os, 4); 255 | *os->in.ptr++ = ((zrle_U8*)&u)[0]; 256 | *os->in.ptr++ = ((zrle_U8*)&u)[1]; 257 | *os->in.ptr++ = ((zrle_U8*)&u)[2]; 258 | *os->in.ptr++ = ((zrle_U8*)&u)[3]; 259 | } 260 | 261 | void zrleOutStreamWriteOpaque24A(zrleOutStream *os, zrle_U32 u) 262 | { 263 | zrleOutStreamCheck(os, 3); 264 | *os->in.ptr++ = ((zrle_U8*)&u)[0]; 265 | *os->in.ptr++ = ((zrle_U8*)&u)[1]; 266 | *os->in.ptr++ = ((zrle_U8*)&u)[2]; 267 | } 268 | 269 | void zrleOutStreamWriteOpaque24B(zrleOutStream *os, zrle_U32 u) 270 | { 271 | zrleOutStreamCheck(os, 3); 272 | *os->in.ptr++ = ((zrle_U8*)&u)[1]; 273 | *os->in.ptr++ = ((zrle_U8*)&u)[2]; 274 | *os->in.ptr++ = ((zrle_U8*)&u)[3]; 275 | } 276 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/zrle.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002 RealVNC Ltd. All Rights Reserved. 3 | * Copyright (C) 2003 Sun Microsystems, Inc. 4 | * 5 | * This is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This software is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this software; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 18 | * USA. 19 | */ 20 | 21 | /* 22 | * zrle.c 23 | * 24 | * Routines to implement Zlib Run-length Encoding (ZRLE). 25 | */ 26 | 27 | #include "rfb/rfb.h" 28 | #include "private.h" 29 | #include "zrleoutstream.h" 30 | 31 | 32 | #define GET_IMAGE_INTO_BUF(tx,ty,tw,th,buf) \ 33 | { char *fbptr = (cl->scaledScreen->frameBuffer \ 34 | + (cl->scaledScreen->paddedWidthInBytes * ty) \ 35 | + (tx * (cl->scaledScreen->bitsPerPixel / 8))); \ 36 | \ 37 | (*cl->translateFn)(cl->translateLookupTable, &cl->screen->serverFormat,\ 38 | &cl->format, fbptr, (char*)buf, \ 39 | cl->scaledScreen->paddedWidthInBytes, tw, th); } 40 | 41 | #define EXTRA_ARGS , rfbClientPtr cl 42 | 43 | #define ENDIAN_LITTLE 0 44 | #define ENDIAN_BIG 1 45 | #define ENDIAN_NO 2 46 | #define BPP 8 47 | #define ZYWRLE_ENDIAN ENDIAN_NO 48 | #include 49 | #undef BPP 50 | #define BPP 15 51 | #undef ZYWRLE_ENDIAN 52 | #define ZYWRLE_ENDIAN ENDIAN_LITTLE 53 | #include 54 | #undef ZYWRLE_ENDIAN 55 | #define ZYWRLE_ENDIAN ENDIAN_BIG 56 | #include 57 | #undef BPP 58 | #define BPP 16 59 | #undef ZYWRLE_ENDIAN 60 | #define ZYWRLE_ENDIAN ENDIAN_LITTLE 61 | #include 62 | #undef ZYWRLE_ENDIAN 63 | #define ZYWRLE_ENDIAN ENDIAN_BIG 64 | #include 65 | #undef BPP 66 | #define BPP 32 67 | #undef ZYWRLE_ENDIAN 68 | #define ZYWRLE_ENDIAN ENDIAN_LITTLE 69 | #include 70 | #undef ZYWRLE_ENDIAN 71 | #define ZYWRLE_ENDIAN ENDIAN_BIG 72 | #include 73 | #define CPIXEL 24A 74 | #undef ZYWRLE_ENDIAN 75 | #define ZYWRLE_ENDIAN ENDIAN_LITTLE 76 | #include 77 | #undef ZYWRLE_ENDIAN 78 | #define ZYWRLE_ENDIAN ENDIAN_BIG 79 | #include 80 | #undef CPIXEL 81 | #define CPIXEL 24B 82 | #undef ZYWRLE_ENDIAN 83 | #define ZYWRLE_ENDIAN ENDIAN_LITTLE 84 | #include 85 | #undef ZYWRLE_ENDIAN 86 | #define ZYWRLE_ENDIAN ENDIAN_BIG 87 | #include 88 | #undef CPIXEL 89 | #undef BPP 90 | 91 | 92 | /* 93 | * zrleBeforeBuf contains pixel data in the client's format. It must be at 94 | * least one pixel bigger than the largest tile of pixel data, since the 95 | * ZRLE encoding algorithm writes to the position one past the end of the pixel 96 | * data. 97 | */ 98 | 99 | /* TODO: put into rfbClient struct */ 100 | static char zrleBeforeBuf[rfbZRLETileWidth * rfbZRLETileHeight * 4 + 4]; 101 | 102 | 103 | 104 | /* 105 | * rfbSendRectEncodingZRLE - send a given rectangle using ZRLE encoding. 106 | */ 107 | 108 | 109 | rfbBool rfbSendRectEncodingZRLE(rfbClientPtr cl, int x, int y, int w, int h) 110 | { 111 | zrleOutStream* zos; 112 | rfbFramebufferUpdateRectHeader rect; 113 | rfbZRLEHeader hdr; 114 | int i; 115 | 116 | if (cl->preferredEncoding == rfbEncodingZYWRLE) { 117 | if (cl->tightQualityLevel < 0) { 118 | cl->zywrleLevel = 1; 119 | } else if (cl->tightQualityLevel < 3) { 120 | cl->zywrleLevel = 3; 121 | } else if (cl->tightQualityLevel < 6) { 122 | cl->zywrleLevel = 2; 123 | } else { 124 | cl->zywrleLevel = 1; 125 | } 126 | } else 127 | cl->zywrleLevel = 0; 128 | 129 | if (!cl->zrleData) 130 | cl->zrleData = zrleOutStreamNew(); 131 | zos = cl->zrleData; 132 | zos->in.ptr = zos->in.start; 133 | zos->out.ptr = zos->out.start; 134 | 135 | switch (cl->format.bitsPerPixel) { 136 | 137 | case 8: 138 | zrleEncode8NE(x, y, w, h, zos, zrleBeforeBuf, cl); 139 | break; 140 | 141 | case 16: 142 | if (cl->format.greenMax > 0x1F) { 143 | if (cl->format.bigEndian) 144 | zrleEncode16BE(x, y, w, h, zos, zrleBeforeBuf, cl); 145 | else 146 | zrleEncode16LE(x, y, w, h, zos, zrleBeforeBuf, cl); 147 | } else { 148 | if (cl->format.bigEndian) 149 | zrleEncode15BE(x, y, w, h, zos, zrleBeforeBuf, cl); 150 | else 151 | zrleEncode15LE(x, y, w, h, zos, zrleBeforeBuf, cl); 152 | } 153 | break; 154 | 155 | case 32: { 156 | rfbBool fitsInLS3Bytes 157 | = ((cl->format.redMax << cl->format.redShift) < (1<<24) && 158 | (cl->format.greenMax << cl->format.greenShift) < (1<<24) && 159 | (cl->format.blueMax << cl->format.blueShift) < (1<<24)); 160 | 161 | rfbBool fitsInMS3Bytes = (cl->format.redShift > 7 && 162 | cl->format.greenShift > 7 && 163 | cl->format.blueShift > 7); 164 | 165 | if ((fitsInLS3Bytes && !cl->format.bigEndian) || 166 | (fitsInMS3Bytes && cl->format.bigEndian)) { 167 | if (cl->format.bigEndian) 168 | zrleEncode24ABE(x, y, w, h, zos, zrleBeforeBuf, cl); 169 | else 170 | zrleEncode24ALE(x, y, w, h, zos, zrleBeforeBuf, cl); 171 | } 172 | else if ((fitsInLS3Bytes && cl->format.bigEndian) || 173 | (fitsInMS3Bytes && !cl->format.bigEndian)) { 174 | if (cl->format.bigEndian) 175 | zrleEncode24BBE(x, y, w, h, zos, zrleBeforeBuf, cl); 176 | else 177 | zrleEncode24BLE(x, y, w, h, zos, zrleBeforeBuf, cl); 178 | } 179 | else { 180 | if (cl->format.bigEndian) 181 | zrleEncode32BE(x, y, w, h, zos, zrleBeforeBuf, cl); 182 | else 183 | zrleEncode32LE(x, y, w, h, zos, zrleBeforeBuf, cl); 184 | } 185 | } 186 | break; 187 | } 188 | 189 | rfbStatRecordEncodingSent(cl, rfbEncodingZRLE, sz_rfbFramebufferUpdateRectHeader + sz_rfbZRLEHeader + ZRLE_BUFFER_LENGTH(&zos->out), 190 | + w * (cl->format.bitsPerPixel / 8) * h); 191 | 192 | if (cl->ublen + sz_rfbFramebufferUpdateRectHeader + sz_rfbZRLEHeader 193 | > UPDATE_BUF_SIZE) 194 | { 195 | if (!rfbSendUpdateBuf(cl)) 196 | return FALSE; 197 | } 198 | 199 | rect.r.x = Swap16IfLE(x); 200 | rect.r.y = Swap16IfLE(y); 201 | rect.r.w = Swap16IfLE(w); 202 | rect.r.h = Swap16IfLE(h); 203 | rect.encoding = Swap32IfLE(cl->preferredEncoding); 204 | 205 | memcpy(cl->updateBuf+cl->ublen, (char *)&rect, 206 | sz_rfbFramebufferUpdateRectHeader); 207 | cl->ublen += sz_rfbFramebufferUpdateRectHeader; 208 | 209 | hdr.length = Swap32IfLE(ZRLE_BUFFER_LENGTH(&zos->out)); 210 | 211 | memcpy(cl->updateBuf+cl->ublen, (char *)&hdr, sz_rfbZRLEHeader); 212 | cl->ublen += sz_rfbZRLEHeader; 213 | 214 | /* copy into updateBuf and send from there. Maybe should send directly? */ 215 | 216 | for (i = 0; i < ZRLE_BUFFER_LENGTH(&zos->out);) { 217 | 218 | int bytesToCopy = UPDATE_BUF_SIZE - cl->ublen; 219 | 220 | if (i + bytesToCopy > ZRLE_BUFFER_LENGTH(&zos->out)) { 221 | bytesToCopy = ZRLE_BUFFER_LENGTH(&zos->out) - i; 222 | } 223 | 224 | memcpy(cl->updateBuf+cl->ublen, (uint8_t*)zos->out.start + i, bytesToCopy); 225 | 226 | cl->ublen += bytesToCopy; 227 | i += bytesToCopy; 228 | 229 | if (cl->ublen == UPDATE_BUF_SIZE) { 230 | if (!rfbSendUpdateBuf(cl)) 231 | return FALSE; 232 | } 233 | } 234 | 235 | return TRUE; 236 | } 237 | 238 | 239 | void rfbFreeZrleData(rfbClientPtr cl) 240 | { 241 | if (cl->zrleData) 242 | zrleOutStreamFree(cl->zrleData); 243 | cl->zrleData = NULL; 244 | } 245 | 246 | -------------------------------------------------------------------------------- /LibVNCServer-0.9.7/libvncserver/ultra.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ultra.c 3 | * 4 | * Routines to implement ultra based encoding (minilzo). 5 | * ultrazip supports packed rectangles if the rects are tiny... 6 | * This improves performance as lzo has more data to work with at once 7 | * This is 'UltraZip' and is currently not implemented. 8 | */ 9 | 10 | #include 11 | #include "minilzo.h" 12 | 13 | /* 14 | * lzoBeforeBuf contains pixel data in the client's format. 15 | * lzoAfterBuf contains the lzo (deflated) encoding version. 16 | * If the lzo compressed/encoded version is 17 | * larger than the raw data or if it exceeds lzoAfterBufSize then 18 | * raw encoding is used instead. 19 | */ 20 | 21 | static int lzoBeforeBufSize = 0; 22 | static char *lzoBeforeBuf = NULL; 23 | 24 | static int lzoAfterBufSize = 0; 25 | static char *lzoAfterBuf = NULL; 26 | static int lzoAfterBufLen = 0; 27 | 28 | /* 29 | * rfbSendOneRectEncodingZlib - send a given rectangle using one Zlib 30 | * rectangle encoding. 31 | */ 32 | 33 | #define MAX_WRKMEM ((LZO1X_1_MEM_COMPRESS) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) 34 | 35 | void rfbUltraCleanup(rfbScreenInfoPtr screen) 36 | { 37 | if (lzoBeforeBufSize) { 38 | free(lzoBeforeBuf); 39 | lzoBeforeBufSize=0; 40 | } 41 | if (lzoAfterBufSize) { 42 | free(lzoAfterBuf); 43 | lzoAfterBufSize=0; 44 | } 45 | } 46 | 47 | void rfbFreeUltraData(rfbClientPtr cl) { 48 | if (cl->compStreamInitedLZO) { 49 | free(cl->lzoWrkMem); 50 | cl->compStreamInitedLZO=FALSE; 51 | } 52 | } 53 | 54 | 55 | static rfbBool 56 | rfbSendOneRectEncodingUltra(rfbClientPtr cl, 57 | int x, 58 | int y, 59 | int w, 60 | int h) 61 | { 62 | rfbFramebufferUpdateRectHeader rect; 63 | rfbZlibHeader hdr; 64 | int deflateResult; 65 | int i; 66 | char *fbptr = (cl->scaledScreen->frameBuffer + (cl->scaledScreen->paddedWidthInBytes * y) 67 | + (x * (cl->scaledScreen->bitsPerPixel / 8))); 68 | 69 | int maxRawSize; 70 | int maxCompSize; 71 | 72 | maxRawSize = (w * h * (cl->format.bitsPerPixel / 8)); 73 | 74 | if (lzoBeforeBufSize < maxRawSize) { 75 | lzoBeforeBufSize = maxRawSize; 76 | if (lzoBeforeBuf == NULL) 77 | lzoBeforeBuf = (char *)malloc(lzoBeforeBufSize); 78 | else 79 | lzoBeforeBuf = (char *)realloc(lzoBeforeBuf, lzoBeforeBufSize); 80 | } 81 | 82 | /* 83 | * lzo requires output buffer to be slightly larger than the input 84 | * buffer, in the worst case. 85 | */ 86 | maxCompSize = (maxRawSize + maxRawSize / 16 + 64 + 3); 87 | 88 | if (lzoAfterBufSize < maxCompSize) { 89 | lzoAfterBufSize = maxCompSize; 90 | if (lzoAfterBuf == NULL) 91 | lzoAfterBuf = (char *)malloc(lzoAfterBufSize); 92 | else 93 | lzoAfterBuf = (char *)realloc(lzoAfterBuf, lzoAfterBufSize); 94 | } 95 | 96 | /* 97 | * Convert pixel data to client format. 98 | */ 99 | (*cl->translateFn)(cl->translateLookupTable, &cl->screen->serverFormat, 100 | &cl->format, fbptr, lzoBeforeBuf, 101 | cl->scaledScreen->paddedWidthInBytes, w, h); 102 | 103 | if ( cl->compStreamInitedLZO == FALSE ) { 104 | cl->compStreamInitedLZO = TRUE; 105 | /* Work-memory needed for compression. Allocate memory in units 106 | * of `lzo_align_t' (instead of `char') to make sure it is properly aligned. 107 | */ 108 | cl->lzoWrkMem = malloc(sizeof(lzo_align_t) * (((LZO1X_1_MEM_COMPRESS) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t))); 109 | } 110 | 111 | /* Perform the compression here. */ 112 | deflateResult = lzo1x_1_compress((unsigned char *)lzoBeforeBuf, (lzo_uint)(w * h * (cl->format.bitsPerPixel / 8)), (unsigned char *)lzoAfterBuf, (lzo_uint *)&maxCompSize, cl->lzoWrkMem); 113 | /* maxCompSize now contains the compressed size */ 114 | 115 | /* Find the total size of the resulting compressed data. */ 116 | lzoAfterBufLen = maxCompSize; 117 | 118 | if ( deflateResult != LZO_E_OK ) { 119 | rfbErr("lzo deflation error: %d\n", deflateResult); 120 | return FALSE; 121 | } 122 | 123 | /* Update statics */ 124 | rfbStatRecordEncodingSent(cl, rfbEncodingUltra, sz_rfbFramebufferUpdateRectHeader + sz_rfbZlibHeader + lzoAfterBufLen, maxRawSize); 125 | 126 | if (cl->ublen + sz_rfbFramebufferUpdateRectHeader + sz_rfbZlibHeader 127 | > UPDATE_BUF_SIZE) 128 | { 129 | if (!rfbSendUpdateBuf(cl)) 130 | return FALSE; 131 | } 132 | 133 | rect.r.x = Swap16IfLE(x); 134 | rect.r.y = Swap16IfLE(y); 135 | rect.r.w = Swap16IfLE(w); 136 | rect.r.h = Swap16IfLE(h); 137 | rect.encoding = Swap32IfLE(rfbEncodingUltra); 138 | 139 | memcpy(&cl->updateBuf[cl->ublen], (char *)&rect, 140 | sz_rfbFramebufferUpdateRectHeader); 141 | cl->ublen += sz_rfbFramebufferUpdateRectHeader; 142 | 143 | hdr.nBytes = Swap32IfLE(lzoAfterBufLen); 144 | 145 | memcpy(&cl->updateBuf[cl->ublen], (char *)&hdr, sz_rfbZlibHeader); 146 | cl->ublen += sz_rfbZlibHeader; 147 | 148 | /* We might want to try sending the data directly... */ 149 | for (i = 0; i < lzoAfterBufLen;) { 150 | 151 | int bytesToCopy = UPDATE_BUF_SIZE - cl->ublen; 152 | 153 | if (i + bytesToCopy > lzoAfterBufLen) { 154 | bytesToCopy = lzoAfterBufLen - i; 155 | } 156 | 157 | memcpy(&cl->updateBuf[cl->ublen], &lzoAfterBuf[i], bytesToCopy); 158 | 159 | cl->ublen += bytesToCopy; 160 | i += bytesToCopy; 161 | 162 | if (cl->ublen == UPDATE_BUF_SIZE) { 163 | if (!rfbSendUpdateBuf(cl)) 164 | return FALSE; 165 | } 166 | } 167 | 168 | return TRUE; 169 | 170 | } 171 | 172 | /* 173 | * rfbSendRectEncodingUltra - send a given rectangle using one or more 174 | * LZO encoding rectangles. 175 | */ 176 | 177 | rfbBool 178 | rfbSendRectEncodingUltra(rfbClientPtr cl, 179 | int x, 180 | int y, 181 | int w, 182 | int h) 183 | { 184 | int maxLines; 185 | int linesRemaining; 186 | rfbRectangle partialRect; 187 | 188 | partialRect.x = x; 189 | partialRect.y = y; 190 | partialRect.w = w; 191 | partialRect.h = h; 192 | 193 | /* Determine maximum pixel/scan lines allowed per rectangle. */ 194 | maxLines = ( ULTRA_MAX_SIZE(w) / w ); 195 | 196 | /* Initialize number of scan lines left to do. */ 197 | linesRemaining = h; 198 | 199 | /* Loop until all work is done. */ 200 | while ( linesRemaining > 0 ) { 201 | 202 | int linesToComp; 203 | 204 | if ( maxLines < linesRemaining ) 205 | linesToComp = maxLines; 206 | else 207 | linesToComp = linesRemaining; 208 | 209 | partialRect.h = linesToComp; 210 | 211 | /* Encode (compress) and send the next rectangle. */ 212 | if ( ! rfbSendOneRectEncodingUltra( cl, 213 | partialRect.x, 214 | partialRect.y, 215 | partialRect.w, 216 | partialRect.h )) { 217 | 218 | return FALSE; 219 | } 220 | 221 | /* Technically, flushing the buffer here is not extrememly 222 | * efficient. However, this improves the overall throughput 223 | * of the system over very slow networks. By flushing 224 | * the buffer with every maximum size lzo rectangle, we 225 | * improve the pipelining usage of the server CPU, network, 226 | * and viewer CPU components. Insuring that these components 227 | * are working in parallel actually improves the performance 228 | * seen by the user. 229 | * Since, lzo is most useful for slow networks, this flush 230 | * is appropriate for the desired behavior of the lzo encoding. 231 | */ 232 | if (( cl->ublen > 0 ) && 233 | ( linesToComp == maxLines )) { 234 | if (!rfbSendUpdateBuf(cl)) { 235 | 236 | return FALSE; 237 | } 238 | } 239 | 240 | /* Update remaining and incremental rectangle location. */ 241 | linesRemaining -= linesToComp; 242 | partialRect.y += linesToComp; 243 | 244 | } 245 | 246 | return TRUE; 247 | 248 | } 249 | --------------------------------------------------------------------------------