From 98740883fc55e36edaf18cac1231a9e7facfc687 Mon Sep 17 00:00:00 2001 From: Marcio T Date: Thu, 10 Mar 2022 09:35:16 -0700 Subject: [PATCH] Major improvements; bug fixes - Fixes to monochrome TRLE encoder - Color builds now run on B&W Macs - Added keyboard support - Added headless mode - Added menu bar - Added about dialog box --- mac-cpp-source/ChainedTCPHelper.cpp | 1 - "mac-cpp-source/MiniVNC.\302\265.bin" | Bin 15872 -> 16768 bytes "mac-cpp-source/MiniVNC.\302\265.rsrc.bin" | Bin 4480 -> 5248 bytes mac-cpp-source/VNCConfig.h | 54 +- mac-cpp-source/VNCEncodeTRLE.cpp | 18 +- mac-cpp-source/VNCEncodeTRLEMono.cpp | 94 +- mac-cpp-source/VNCFrameBuffer.cpp | 81 +- mac-cpp-source/VNCScreenHash.cpp | 1 + mac-cpp-source/VNCServer.cpp | 21 +- mac-cpp-source/VNCServer.h | 47 +- mac-cpp-source/libs/.finf/MacTCP.h | Bin 32 -> 0 bytes mac-cpp-source/libs/.finf/OSUtilities.cpp | Bin 32 -> 0 bytes mac-cpp-source/libs/.finf/OSUtilities.h | Bin 32 -> 0 bytes mac-cpp-source/libs/.finf/compat.h | Bin 32 -> 0 bytes mac-cpp-source/libs/.rsrc/MacTCP.h | Bin 410 -> 0 bytes mac-cpp-source/libs/.rsrc/OSUtilities.cpp | Bin 410 -> 0 bytes mac-cpp-source/libs/.rsrc/OSUtilities.h | Bin 382 -> 0 bytes mac-cpp-source/libs/.rsrc/compat.h | Bin 410 -> 0 bytes .../{ => Ari Halberstadt}/OSUtilities.cpp | 0 .../libs/{ => Ari Halberstadt}/OSUtilities.h | 0 mac-cpp-source/libs/ChromiVNC/LICENSE.H | 164 ++++ mac-cpp-source/libs/ChromiVNC/VNCKeyboard.cpp | 352 ++++++++ mac-cpp-source/libs/ChromiVNC/VNCKeyboard.h | 22 + mac-cpp-source/libs/ChromiVNC/keysymdef.h | 131 +++ .../libs/Common Libs/GestaltUtils.cpp | 77 ++ .../libs/Common Libs/GestaltUtils.h | 25 + mac-cpp-source/libs/MacTCP.h | 854 +----------------- mac-cpp-source/libs/compat.h | 55 +- mac-cpp-source/main.cpp | 158 +++- 29 files changed, 1118 insertions(+), 1037 deletions(-) delete mode 100644 mac-cpp-source/libs/.finf/MacTCP.h delete mode 100644 mac-cpp-source/libs/.finf/OSUtilities.cpp delete mode 100644 mac-cpp-source/libs/.finf/OSUtilities.h delete mode 100644 mac-cpp-source/libs/.finf/compat.h delete mode 100644 mac-cpp-source/libs/.rsrc/MacTCP.h delete mode 100644 mac-cpp-source/libs/.rsrc/OSUtilities.cpp delete mode 100644 mac-cpp-source/libs/.rsrc/OSUtilities.h delete mode 100644 mac-cpp-source/libs/.rsrc/compat.h rename mac-cpp-source/libs/{ => Ari Halberstadt}/OSUtilities.cpp (100%) rename mac-cpp-source/libs/{ => Ari Halberstadt}/OSUtilities.h (100%) create mode 100644 mac-cpp-source/libs/ChromiVNC/LICENSE.H create mode 100644 mac-cpp-source/libs/ChromiVNC/VNCKeyboard.cpp create mode 100644 mac-cpp-source/libs/ChromiVNC/VNCKeyboard.h create mode 100644 mac-cpp-source/libs/ChromiVNC/keysymdef.h create mode 100644 mac-cpp-source/libs/Common Libs/GestaltUtils.cpp create mode 100644 mac-cpp-source/libs/Common Libs/GestaltUtils.h diff --git a/mac-cpp-source/ChainedTCPHelper.cpp b/mac-cpp-source/ChainedTCPHelper.cpp index 6b88477..4e4a20a 100644 --- a/mac-cpp-source/ChainedTCPHelper.cpp +++ b/mac-cpp-source/ChainedTCPHelper.cpp @@ -17,7 +17,6 @@ #include "ChainedTCPHelper.h" - /* Opens the TCP driver and allocates a parameter block for * subsequent calls. */ diff --git "a/mac-cpp-source/MiniVNC.\302\265.bin" "b/mac-cpp-source/MiniVNC.\302\265.bin" index 3cd18a268e2aef2d82414748944bad546e22b3f2..86db234acf23c1d23c0be4e9e584348826223c19 100644 GIT binary patch delta 2412 zcmb6bZA?>F^t?wY{owT#+EPB+(gM;Cv4RUCC=*1S%+fUiX48a#zyeJtT`5M5(QZo? zf4C30jN!JZOZ1PEWR4|UrZKWGMnmbK83v?KIi$&C5CW zoO93jz4yhA#$FO$@7QXd1#q3Y*tz#W-2e7406e#?#g8Cmy!e9lJ%FCU!4Q%K{44#zj|@&@dxlTWB_D~ zV1=KMVIsH1XVgU(9kFRtZXv#mnx~xcRzowc)RV&bGYGYD-*6CNe%yC&J3?#R|K|4y z9dTdBNra^g7Q}t?*KuuT>v5Ps3tI9;M(w^5>IDwXq_*HD%5aOiNsXZk*Al{RgxuzT zwXqx8$+ava2`b#?(xeI40XyMI@PQu!!1*65+(lN#pM~UH06LeDY9MzNjX8ywg-_9k z6(7mYOhj%Oj=sbtjkW(U*uu!@za+-4i&cfo$>g=e83f)IiOiHe6+ZO)g0&J!r5#vJpJ zz~nvtrd@r9_YZbQdWk;My35Vj6|C3u(yG0VtzE2Q>6PY{#LlAjv!&GrzVldR4>Q1m zNjUk5P(vg!;7DyE-sHS_m`V~*yJgoyw2X>Xu1=t{3%QE)Q1wsr4Mn>{(T?aqXb5Aq zlzN#GUZwQnU?fSRkBP~G04N=_X7{-nBG2OSIhZK zO(z`0d5D}-*VmLY8s;j7t%a*f$P{M~(&7p92qRsCcs|lq0CC@B1O!s4$^Ss3%Fxl% zD8$;EpKhlZ$&=htt1-kVh!LMOhC;(ZE;Jk@%hJ5$yAj}&8v!z_b4yqmPU$#F{zQs@ z#LXy(O>K~C1XGF-x+LPYHcv1cp(;&D>>D2Q3Gzus8R3k zi$=P8`beXkPrj8D#FDEOEX0*tEm%osu2aUVm0QP4)<(v1ooVKasd?pQVo{=b|EQUZ zpAx}7YCsKjn>eX%6FA65q@@N>LP7?o$scOva-mizWm6uIIEmIzSRM=MfytoqfUcsKXm(UZp!de7( zl9hIXja2ONir8iFB*jwBVWVucrD%{1|)C^EC6X$C49619<=h9g6R zk?nm42e3d@Is-3|Ze3D9)z%Xk2uI0pdRM)ds@2Y=oIP((IE*d3dZ4A=6-&LaKCx?_ zEUEt0I+f&>zFMdvg*nyau+ddKaSD%xfHz>a81M~6sZx33lpa8`=~_{o$||zc4z`;~g4^di$S0)ItI#muQ}yI$|0S)pvwH#H$&HK{54Z2d6`V%=cZwg2!Fd!-9N^41-~!?a-%PjR z68=tnNM(u%Tm>kiFDo253!ed4f26n~4qqYu7sYKS0Cn3i9@PI4{THz%6hB|z&)t^xu3gvlwMW|pCt~Itv)kO_R>%UxZ4m?)alSu`2j;(%y(LnI*@68y(Z@Q>m7ZttBsoqE6Ap5Hy^ zeCO43&d8f=WcWyTlRF6zJ8`z>#l2E8-v$7CTGnqQ@|Wk(8>cD&dQ+(ZVl#UE0Ioc} z4~|aEB_==EE=;zabilh7VAaFIdzRg#a+|9P*>7S*3r`n-CZTCM_z3QS7Qnm+Uf6|c zvl}N(b>d$5hl3AHFNBk`5prsrzvT}SHJ@YI6GW|N!z0&-zN*-mHa`*l5LP-86wYl5 z#f_)gR&!9fA3~d^u6?;x@BE#GAIN%GYQ5Azv{FjW%n^-BP1n1K`lV*uFj0^6*ws&n zj=>SKY{79&y|b#2E?CZ4OZc52<~70cl`N?iI$)z*i*?$#Gpbl&4@A`@iy3WBF7U6R8R0XNTCkPc95~z$Py6XCA87XC6Wnr-(;eL*eoL z5ks9=%i_3BB<(9xs`iyBsK&Hdbu^^2u#tU(`+9kQ;esa~%x1ozbsFGXb92Yw5a$co z%rt&*FH>PnXbH91}HRj9gd(G?G zZSW{JPKqak{3VJm+h3xQX=sfl`9y{3bBpfE+wC(}y88}Y(7mj;kkR?@l z+u6q9G+{Ze_5@r25HE5acM2{8l-}ZacL#h4PU|Ujc%xMO^Usw~YEaC`X&>Vs?Pg0_X4eh|v&+Wu2|vj8;MT2Iud;!&U=C?sL5M Kv)so`lk9igyybNO diff --git "a/mac-cpp-source/MiniVNC.\302\265.rsrc.bin" "b/mac-cpp-source/MiniVNC.\302\265.rsrc.bin" index 94c5bc7c0945bea35709672faa8b329280d3f815..f9478d2d706817e5fcd31e819f417a89513640ec 100644 GIT binary patch delta 1310 zcmZ`&U1%It6h3!$(zHuXr$TQq)Kh5N_I9|Q+78$O=B%on4KN7*Urvt zXYQ^Wtn6mphkXb%aYRIG$%BQq^dV9NANn9gqz}cuR1p86;**G#rr=-WnV(vHaA4+q z=bUf8bMHC#HV2x6%P;KRdg_~-OZ&ggg?|Qsa%v)v=08ts@r$S20KvC+4IqXu`EF%7 z5wmPdwJj??mCo>Z=|p|y`jD{o)CYIZ3Iben&W83RTCg21kZ8vj%%FD!-s*}T;+CeA zX`0y;U0LvwM=_^6-Qu>VGq4IrNVF?5rt9V_R5lH6nL71YeXt)Aq^I*xju~t&FVmMy zi_S5FEAtx7DXM+xUGYx0vn0H}Lbo`5p=pN+k6(H_a)yvkoxRddvg#a@T8(+eOVvVL zHOq;zVyVpJXw{)Iiq;GjD{TY8tB0Qre8ddXHF3JiI86KT=OFYi!tdgEk#X^`Q8eKw zc4x@Vh2$#7?Sd$ql?9Lix~3GHYcK~5=#q6!vF<5sMlpgFUCG^EpS=tg{)0Ra8!MPq zPJ<1{<8e3VS8!1e?1EinCpiJFbQ=An8^lNSSH7|FkKVlTK|=xZq2_7h|Y6DQq50749L$BzrQr1s}O_;}Mg#shx$Z}@K@ zy5%p#0YAKmoEvxyr5N;VApR&=97BB7Uv%^*>Dl)BMPD?!hKY}XxC@G2MqCHM!!qJe YAmrg9;%mXrewIa|SW;(1*rfiD~XEoEY2WShK{*;s!XgB-&?M!pV+fhj;<8N)PI zzTlFg)Wlo`m(1dVoWx47WCc*JYce~FtX&Gj0){e1K2~1GoSgh}1?T*{lA`<^1+Xd+ z1{;QOpm~A5nR%IEe$EPM`9%t0nRz9N>8T37iOI#hlm7`wPIeWPXJpu%$nuT7{{O%N z#{ZK)vbSxH<(<#Scxv)rK2^pgla=|KSjx-G^(HUnSExq~RsLSX10s`vUX@`CW8ib~ z@dt%`m5XPH4>0)KJe~cNf&6)y$;BXgm6M-~50KvG7Ub#%qz`#I`-5Wd+*V-70O?zq z$vGB4`Wa9?i2elRn*iy5Kt7OWkk(^p`2QcMkb%F~ zU=D=MqzGhBVQ2)2^KJ&Rd!T9{Q43Ko3DN@. * ****************************************************************************/ +#pragma once + /** * Specify a compression level for the color TTRL encoder, * from 0 to 4 */ -#define COMPRESSION_LEVEL 4 +#define VNC_COMPRESSION_LEVEL 2 + +/** + * If the following is defined, MiniVNC will automatically + * start the server if it finds the application is in the + * "Startup Items" folder. It also will return to listening + * for connections after a client disconnects, allowing + * MiniVNC to be used in headless server mode. + */ +//#define VNC_HEADLESS_MODE /** * To build for a specific resolution, uncomment one of @@ -42,45 +53,4 @@ //#define VNC_FB_16_COLORS //#define VNC_FB_256_COLORS -// Derived values, don't change anything below this line - -#if defined(VNC_FB_RES_512_342) - // Plus, SE, Classic, SE/30 - #define VNC_FB_WIDTH 512 - #define VNC_FB_HEIGHT 342 - #define VNC_FB_MONOCHROME -#elif defined(VNC_FB_RES_512_384) - // Classic II, all others - #define VNC_FB_WIDTH 512 - #define VNC_FB_HEIGHT 384 - -#elif defined(VNC_FB_RES_640_480) - // Mac II, LC, etc - #define VNC_FB_WIDTH 640 - #define VNC_FB_HEIGHT 480 - -#elif defined(VNC_FB_RES_1024_768) - #define VNC_FB_WIDTH 1024 - #define VNC_FB_HEIGHT 768 -#endif - -#if defined(VNC_FB_MONOCHROME) - #define VNC_FB_BITS_PER_PIX 1 - -#elif defined(VNC_FB_4_COLORS) - #define VNC_FB_BITS_PER_PIX 2 - -#elif defined(VNC_FB_16_COLORS) - #define VNC_FB_BITS_PER_PIX 4 - -#elif defined(VNC_FB_256_COLORS) - #define VNC_FB_BITS_PER_PIX 8 -#endif - -#define VNC_FB_PIX_PER_BYTE (8 / VNC_FB_BITS_PER_PIX) -#define VNC_FB_PALETTE_SIZE (1 << VNC_FB_BITS_PER_PIX) -#define BYTES_PER_TILE_ROW (2 * VNC_FB_BITS_PER_PIX) -#ifdef VNC_FB_WIDTH - #define VNC_BYTES_PER_LINE (VNC_FB_WIDTH / VNC_FB_PIX_PER_BYTE) -#endif diff --git a/mac-cpp-source/VNCEncodeTRLE.cpp b/mac-cpp-source/VNCEncodeTRLE.cpp index 61adc03..e5dd37c 100644 --- a/mac-cpp-source/VNCEncodeTRLE.cpp +++ b/mac-cpp-source/VNCEncodeTRLE.cpp @@ -16,7 +16,7 @@ ****************************************************************************/ #include -#include "VNCConfig.h" +#include "VNCServer.h" #include "VNCFrameBuffer.h" #include "VNCEncodeTRLE.h" @@ -28,20 +28,22 @@ //#define USE_NATIVE_COLOR_TILES //#define DEBUG_TILE_TYPES -#ifdef COMPRESSION_LEVEL - #if COMPRESSION_LEVEL == 0 +#ifdef VNC_COMPRESSION_LEVEL + #if VNC_COMPRESSION_LEVEL == 0 #define USE_FAST_MONO_ENCODER #define USE_NATIVE_COLOR_TILES - #elif COMPRESSION_LEVEL == 1 + #elif VNC_COMPRESSION_LEVEL == 1 + #define USE_FAST_MONO_ENCODER #define USE_RLE_COLOR_TILES - #elif COMPRESSION_LEVEL == 2 + #elif VNC_COMPRESSION_LEVEL == 2 + #define USE_FAST_MONO_ENCODER #define USE_RLE_COLOR_TILES #define USE_NATIVE_COLOR_TILES - #elif COMPRESSION_LEVEL == 3 + #elif VNC_COMPRESSION_LEVEL == 3 #define USE_RLE_COLOR_TILES #define USE_NATIVE_COLOR_TILES #define USE_2_COLOR_TILES - #elif COMPRESSION_LEVEL == 4 + #elif VNC_COMPRESSION_LEVEL == 4 #define USE_RLE_COLOR_TILES #define USE_NATIVE_COLOR_TILES #define USE_2_COLOR_TILES @@ -94,7 +96,7 @@ OSErr VNCEncoder::setup() { #else const unsigned long tilesPerRow = fbWidth / 16; #endif - #ifdef USE_FAST_MONO_ENCODER + #if defined(VNC_FB_MONOCHROME) || defined(USE_FAST_MONO_ENCODER) fbUpdateBuffer = (unsigned char*) NewPtr(tilesPerRow * PLAIN_PACKED_TILE_SIZE(1)); #else fbUpdateBuffer = (unsigned char*) NewPtr(UPDATE_BUFFER_SIZE); diff --git a/mac-cpp-source/VNCEncodeTRLEMono.cpp b/mac-cpp-source/VNCEncodeTRLEMono.cpp index 15f1d35..f688f87 100644 --- a/mac-cpp-source/VNCEncodeTRLEMono.cpp +++ b/mac-cpp-source/VNCEncodeTRLEMono.cpp @@ -16,11 +16,14 @@ ****************************************************************************/ #include -#include "VNCConfig.h" +#include "VNCServer.h" #include "VNCFrameBuffer.h" #include "VNCEncodeTRLE.h" #define DEBUG_SOLID_TILE 0 // Set to one to show solid tiles +#define USE_ENCODER 0 // 0: Assembly; 1: Hybrid; 2: C++ + +#define min(A,B) ((A) < (B) ? (A) : (B)) extern int tile_y; extern unsigned char lastPaletteSize; @@ -161,11 +164,11 @@ static asm unsigned short _encodeTile(const unsigned char *src:__A0, unsigned ch #define GET_CHUNK VNCEncoder::getChunk #else #define GET_CHUNK getChunkMonochrome +#endif +#if USE_ENCODER == 0 asm Boolean getChunkMonochrome(int x, int y, int w, int h, wdsEntry *wdsPtr); -#endif -#if 1 asm Boolean GET_CHUNK(int x, int y, int w, int h, wdsEntry *wdsPtr) { #define xArg 8(a6) #define yArg 10(a6) @@ -173,6 +176,7 @@ static asm unsigned short _encodeTile(const unsigned char *src:__A0, unsigned ch #define hArg 14(a6) #define wdsArg 16(a6) + #define tmp d1 #define tiles d3 #define rows d4 @@ -194,6 +198,7 @@ static asm unsigned short _encodeTile(const unsigned char *src:__A0, unsigned ch add.w tile_y,tmp #if VNC_FB_WIDTH == 512 lsl.w #6,tmp + ext.l tmp #else #if !defined(VNC_FB_BITS_PER_PIX) mulu fbStride,tmp @@ -205,7 +210,8 @@ static asm unsigned short _encodeTile(const unsigned char *src:__A0, unsigned ch // Add x/8 move.w xArg,tmp lsr.w #3,tmp - adda.w tmp,src + ext.l tmp + adda.l tmp,src // Compute tiles: // tiles = w/16 @@ -248,8 +254,22 @@ static asm unsigned short _encodeTile(const unsigned char *src:__A0, unsigned ch movem.l (a7)+,d3-d4/a2-a4 // Save registers unlk a6 rts + + #undef xArg + #undef yArg + #undef wArg + #undef hArg + #undef wdsArg + + #undef tmp + #undef tiles + #undef rows + + #undef src + #undef dst + #undef wds } -#else +#elif USE_ENCODER == 1 /** * With "src" pointing to the first byte of a 16x16 tile on the screen, this function will write * "rows" as a two-color or solid tile and return the number of bytes written. @@ -263,6 +283,8 @@ static asm unsigned short _encodeTile(const unsigned char *src:__A0, unsigned ch rts } + Boolean GET_CHUNK(int x, int y, int w, int h, wdsEntry *wds); + Boolean GET_CHUNK(int x, int y, int w, int h, wdsEntry *wds) { const char rows = min(16, h - tile_y); unsigned char *dst = fbUpdateBuffer; @@ -279,6 +301,68 @@ static asm unsigned short _encodeTile(const unsigned char *src:__A0, unsigned ch // Prepare for the next row tile_y += 16; + return tile_y < h; + } +#else + // C++ Reference Encoder + + #define TILE_LINE(ROW) if(rows == ROW) goto done; \ + *dst++ = src[0 + ROW * VNC_BYTES_PER_LINE]; \ + *dst++ = src[1 + ROW * VNC_BYTES_PER_LINE]; + + unsigned short encodeTile(const unsigned char *src, unsigned char *dst, unsigned short rows); + + unsigned short encodeTile(const unsigned char *src, unsigned char *dst, unsigned short rows) { + unsigned char *start = dst; + + if(tile_y && dst != fbUpdateBuffer) { + // Packed pallete type with pallete reused from previous tile + *dst++ = 127; + } else { + // Packed pallete type with palleteSize = 2 + *dst++ = 2; // Packed pallete type + *dst++ = 0; // Black CPIXEL + *dst++ = 1; // White CPIXEL + } + + // Encode the packed data for a 16x16 tile + TILE_LINE(0); + TILE_LINE(1); + TILE_LINE(2); + TILE_LINE(3); + TILE_LINE(4); + TILE_LINE(5); + TILE_LINE(6); + TILE_LINE(7); + TILE_LINE(8); + TILE_LINE(9); + TILE_LINE(10); + TILE_LINE(11); + TILE_LINE(12); + TILE_LINE(13); + TILE_LINE(14); + TILE_LINE(15); + done: + + return dst - start; + } + + Boolean VNCEncoder::getChunk(int x, int y, int w, int h, wdsEntry *wds) { + const char rows = min(16, h - tile_y); + unsigned char *dst = fbUpdateBuffer; + unsigned char *src = VNCFrameBuffer::getPixelAddr(x, y + tile_y); + unsigned char tiles = w/16; + while(tiles--) { + dst += encodeTile(src, dst, rows); + src += 2; + } + + wds->length = dst - fbUpdateBuffer; + wds->ptr = (Ptr) fbUpdateBuffer; + + // Prepare for the next row + tile_y += 16; + return tile_y < h; } #endif \ No newline at end of file diff --git a/mac-cpp-source/VNCFrameBuffer.cpp b/mac-cpp-source/VNCFrameBuffer.cpp index e615214..64e8d92 100644 --- a/mac-cpp-source/VNCFrameBuffer.cpp +++ b/mac-cpp-source/VNCFrameBuffer.cpp @@ -19,9 +19,10 @@ #include #include +#include "GestaltUtils.h" +#include "VNCServer.h" #include "VNCTypes.h" #include "VNCFrameBuffer.h" -#include "VNCServer.h" #ifndef USE_STDOUT #define printf ShowStatus @@ -50,40 +51,42 @@ unsigned long ctSeed = 10; //unsigned long LMGetDeskHook() {return * (unsigned long*) 0xA6C;} OSErr VNCFrameBuffer::setup() { + if(checkScreenResolution()) { + vncBits.baseAddr = (Ptr) ScrnBase; + } + #if defined(VNC_FB_MONOCHROME) + else { + // We are on a color Mac, create a virtual B&W map + vncBits.rowBytes = VNC_FB_WIDTH/8; + vncBits.baseAddr = NewPtr((unsigned long)VNC_FB_WIDTH/8 * VNC_FB_HEIGHT); + SetRect(&vncBits.bounds, 0, 0, VNC_FB_WIDTH, VNC_FB_HEIGHT); + OSErr err = MemError(); + if (err != noErr) + return err; + } + #endif + // Create the color palette #ifdef VNC_FB_BITS_PER_PIX const unsigned char fbDepth = VNC_FB_BITS_PER_PIX; #endif + const unsigned int paletteSize = 1 << fbDepth; ctColors = (VNCColor*) NewPtr(sizeof(VNCColor) * paletteSize); if (MemError() != noErr) return MemError(); - #if defined(VNC_FB_MONOCHROME) + if(fbDepth == 1) { + // Set up the monochrome palette ctColors[0].red = -1; ctColors[0].green = -1; ctColors[0].blue = -1; ctColors[1].red = 0; ctColors[1].green = 0; ctColors[1].blue = 0; - #endif - - if(checkScreenResolution()) { - vncBits.baseAddr = (Ptr) ScrnBase; } - #if defined(VNC_FB_MONOCHROME) - else { - // We are on a color Mac, create a virtual B&W map - vncBits.rowBytes = VNC_FB_WIDTH/8; - vncBits.baseAddr = NewPtr((unsigned long)VNC_FB_WIDTH/8 * VNC_FB_HEIGHT); - SetRect(&vncBits.bounds, 0, 0, VNC_FB_WIDTH, VNC_FB_HEIGHT); - OSErr err = MemError(); - if (err != noErr) - return err; - } - #endif - if(hasColorQuickdraw()) { + if(HasColorQD()) { //LMSetDeskHook(NULL); // Set a solid background //deskPat = GetPixPat(128); @@ -105,19 +108,13 @@ OSErr VNCFrameBuffer::destroy() { if(ctColors) { DisposePtr((Ptr)ctColors); } - if(hasColorQuickdraw()) { + if(hasColorQD) { //SetDeskCPat(NULL); //DisposePixPat(deskPat); } return noErr; } -Boolean VNCFrameBuffer::hasColorQuickdraw() { - long attr; - OSErr err = Gestalt(gestaltQuickdrawVersion, &attr); - return attr >= gestalt8BitQD; -} - Boolean VNCFrameBuffer::checkScreenResolution() { // Assume a monochrome screen @@ -128,7 +125,7 @@ Boolean VNCFrameBuffer::checkScreenResolution() { // Update values if this machine has Color QuickDraw - if(hasColorQuickdraw()) { + if(HasColorQD()) { GDPtr gdp = *GetMainDevice(); PixMapPtr gpx = *(gdp->gdPMap); @@ -177,22 +174,24 @@ void VNCFrameBuffer::copy() { CopyBits(&qd.screenBits, &vncBits, &vncBits.bounds, &vncBits.bounds, srcCopy, NULL); } #else - #ifdef VNC_FB_BITS_PER_PIX - const unsigned char fbDepth = VNC_FB_BITS_PER_PIX; - #endif - const unsigned int paletteSize = 1 << fbDepth; - // Update the color table if needed - GDHandle gdh = GetMainDevice(); - PixMapHandle gpx = (*gdh)->gdPMap; - CTabHandle gct = (*gpx)->pmTable; - if(gct && ((*gct)->ctSeed != ctSeed) && (paletteSize == (*gct)->ctSize + 1)) { - for(int i = 0; i < paletteSize; i++) { - ctColors[i].red = (*gct)->ctTable[i].rgb.red; - ctColors[i].green = (*gct)->ctTable[i].rgb.green; - ctColors[i].blue = (*gct)->ctTable[i].rgb.blue; + if(hasColorQD) { + #ifdef VNC_FB_BITS_PER_PIX + const unsigned char fbDepth = VNC_FB_BITS_PER_PIX; + #endif + const unsigned int paletteSize = 1 << fbDepth; + // Update the color table if needed + GDHandle gdh = GetMainDevice(); + PixMapHandle gpx = (*gdh)->gdPMap; + CTabHandle gct = (*gpx)->pmTable; + if(gct && ((*gct)->ctSeed != ctSeed) && (paletteSize == (*gct)->ctSize + 1)) { + for(int i = 0; i < paletteSize; i++) { + ctColors[i].red = (*gct)->ctTable[i].rgb.red; + ctColors[i].green = (*gct)->ctTable[i].rgb.green; + ctColors[i].blue = (*gct)->ctTable[i].rgb.blue; + } + ctSeed = (*gct)->ctSeed; + fbColorMapNeedsUpdate = true; } - ctSeed = (*gct)->ctSeed; - fbColorMapNeedsUpdate = true; } #endif } diff --git a/mac-cpp-source/VNCScreenHash.cpp b/mac-cpp-source/VNCScreenHash.cpp index 91fac18..fcd27c5 100644 --- a/mac-cpp-source/VNCScreenHash.cpp +++ b/mac-cpp-source/VNCScreenHash.cpp @@ -17,6 +17,7 @@ #include +#include "VNCServer.h" #include "VNCFrameBuffer.h" #include "VNCScreenHash.h" diff --git a/mac-cpp-source/VNCServer.cpp b/mac-cpp-source/VNCServer.cpp index 6e23563..315e7a4 100644 --- a/mac-cpp-source/VNCServer.cpp +++ b/mac-cpp-source/VNCServer.cpp @@ -21,6 +21,7 @@ #include #include "VNCServer.h" +#include "VNCKeyboard.h" #include "VNCTypes.h" #include "VNCFrameBuffer.h" #include "VNCScreenHash.h" @@ -132,6 +133,8 @@ VNCRect fbUpdateRect; Boolean fbUpdateInProgress, fbUpdatePending; OSErr vncServerStart() { + VNCKeyboard::Setup(); + vncError = VNCFrameBuffer::setup(); if (vncError != noErr) return vncError; @@ -474,27 +477,11 @@ void vncSetPixelFormat(const VNCSetPixFormat &pixFormat) { printf("Invalid pixel format requested\n"); vncState = VNC_ERROR; } - /*#define VNC_CPIXEL(R,G,B) ((format.redMax * R / 255) << format.redShift) | \ - ((format.greenMax * G / 255) << format.greenShift) | \ - ((format.blueMax * B / 255) << format.blueShift) - unsigned char *c = VNCEncoder::getPalette(); - #if defined(VNC_FB_MONOCHROME) - // Packed pallete type with palleteSize = 2 - c[0] = VNC_CPIXEL(255, 255, 255); // White - c[1] = VNC_CPIXEL( 0, 0, 0); // Black - #else - for(char i = 0; i < VNC_FB_PALETTE_SIZE; i++) { - unsigned short r, g, b; - VNCFrameBuffer::getColor(i, &r, &g, &b); - c[i] = VNC_CPIXEL(r >> 8,g >> 8,b >> 8); - } - #endif - #undef VNC_CPIXEL*/ } void vncKeyEvent(const VNCKeyEvent &keyEvent) { if (allowControl) { - //printf("Got keyEvent %ld,%s\n", msg.key, msg.down ? "down" : "up"); + VNCKeyboard::PressKey(keyEvent.key, keyEvent.down); } } diff --git a/mac-cpp-source/VNCServer.h b/mac-cpp-source/VNCServer.h index 49c70b5..33f655f 100644 --- a/mac-cpp-source/VNCServer.h +++ b/mac-cpp-source/VNCServer.h @@ -15,11 +15,54 @@ * location: . * ****************************************************************************/ -//#define USE_STDOUT +#include "VNCConfig.h" extern Boolean allowControl, sendGraphics, allowIncremental, fbColorMapNeedsUpdate; OSErr vncServerStart(); OSErr vncServerStop(); OSErr vncServerError(); -Boolean vncServerStopped(); \ No newline at end of file +Boolean vncServerStopped(); + +// Constants for specialized builds + +#if defined(VNC_FB_RES_512_342) + // Plus, SE, Classic, SE/30 + #define VNC_FB_WIDTH 512 + #define VNC_FB_HEIGHT 342 + #define VNC_FB_MONOCHROME +#elif defined(VNC_FB_RES_512_384) + // Classic II, all others + #define VNC_FB_WIDTH 512 + #define VNC_FB_HEIGHT 384 + +#elif defined(VNC_FB_RES_640_480) + // Mac II, LC, etc + #define VNC_FB_WIDTH 640 + #define VNC_FB_HEIGHT 480 + +#elif defined(VNC_FB_RES_1024_768) + #define VNC_FB_WIDTH 1024 + #define VNC_FB_HEIGHT 768 +#endif + +#if defined(VNC_FB_MONOCHROME) + #define VNC_FB_BITS_PER_PIX 1 + +#elif defined(VNC_FB_4_COLORS) + #define VNC_FB_BITS_PER_PIX 2 + +#elif defined(VNC_FB_16_COLORS) + #define VNC_FB_BITS_PER_PIX 4 + +#elif defined(VNC_FB_256_COLORS) + #define VNC_FB_BITS_PER_PIX 8 +#endif + +#define VNC_FB_PIX_PER_BYTE (8 / VNC_FB_BITS_PER_PIX) +#define VNC_FB_PALETTE_SIZE (1 << VNC_FB_BITS_PER_PIX) +#define BYTES_PER_TILE_ROW (2 * VNC_FB_BITS_PER_PIX) + +#ifdef VNC_FB_WIDTH + #define VNC_BYTES_PER_LINE (VNC_FB_WIDTH / VNC_FB_PIX_PER_BYTE) +#endif \ No newline at end of file diff --git a/mac-cpp-source/libs/.finf/MacTCP.h b/mac-cpp-source/libs/.finf/MacTCP.h deleted file mode 100644 index c6d6c6f7a19a269842c1da911145c57f33d24da5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32 XcmWG>jR^5}^zdP1U?^kEVZZjR^5}^zdP1VA#fx!+-$*TciVt diff --git a/mac-cpp-source/libs/.finf/OSUtilities.h b/mac-cpp-source/libs/.finf/OSUtilities.h deleted file mode 100644 index 6a78fa88eb233c7ac68f78922952b44a5f30b267..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32 YcmWG>jR^5}^zdP1VA#g+h5-Wr0A(Zu2><{9 diff --git a/mac-cpp-source/libs/.finf/compat.h b/mac-cpp-source/libs/.finf/compat.h deleted file mode 100644 index 1ce7260b4380cb161afe334a03f47f151bf81b4d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32 XcmWG>jR^5}^zdP1U?^jF!+-$*U*rSH diff --git a/mac-cpp-source/libs/.rsrc/MacTCP.h b/mac-cpp-source/libs/.rsrc/MacTCP.h deleted file mode 100644 index adfbce60b96e0b648841eeb92289d3940a2c379a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 410 zcmZQzU}RumUa5#rsD7fe6qyRbSfWtR2Im9_YFC#T1$j8+;KQCV|xuBq^ zsJN)OEH$N~l8GV2H6p~@(ZdI9E{H$@Y}R*g@E&7eNSFn*2#Aq@v?_=bB%%>el%JKF zT%r(Ml30?NpO;!xsfnZv$TS733=svoMZrHIV(TW>3hQgyJ(ED@Wc z)PkJET~7&w9cNKDR$31Fd_7+4r;82FezGv&hQdk!CU85o3( zf!LaXK~Nv8iv<{*KtH2~DgV;49>pA>ybLgW8GQqSgMe%y-*6`a+aGOhtN>ddw(-cZFQWZ)- zDl&@|63Y@Za}twsQWX@m^m(0tdQ%hg6hPV>VKN%U8TmyeU>%yg)x4Y_$&ktdpcz2I zniuFY4+c)({Jg~Ed}LRmv6&cH7_t~RnLaRO!03DIJ*_}LECu5IaMdh89|Jv(8m9b9 q%N?X&0oBMbxG^yL1_TEI*+RbIPEJ5tj`{8X|1kZ`AHZxM5FY^Qsam=K diff --git a/mac-cpp-source/libs/.rsrc/OSUtilities.h b/mac-cpp-source/libs/.rsrc/OSUtilities.h deleted file mode 100644 index 37de07d7995cab2a7cea003f1fdf69cc203807c4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 382 zcmZQzU}RumVDteJAZ*0&LF@nj1eR}gKn}wP?f?H7SiUoX**YNc@4WuOp(U9)nI)O2 z#d;YanGn~A5N}5hA4Z1%K!C{yX+{QjA8$?q^1lLYt+V<6UxE3|J&^PVO_2FNr-9jE zH~g9fW`o`Edmfk#cEg`VV74wu{oiF^wjRix|5kz7`XKTD>%eStpg8l{M_{%Bh<))H zm~Fv0m4W%{D-fH3!GnR*H$N{iIUmBsO0qGqFc>p%GJR+M&S1_U!t|A?=I-NfAAxFt p{s3dJHq@}>uPF48+y<180fsAsZ$NMmkj=&X78FVh4Ez=OEC6m`Z5IFl diff --git a/mac-cpp-source/libs/.rsrc/compat.h b/mac-cpp-source/libs/.rsrc/compat.h deleted file mode 100644 index 0f81b9894efde9a90b130f920093bfd394ace41a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 410 zcmZQzU}RumU#x0VkVa8 zWn|{12j!QR0F@T&B^MN=<|U^Vrxv>ajd6_#@pkm^0h!Ct2qKUHoAuor{F@jUn6CkC zou%L$#0diGF-7Wdn|<7%VtH^ePUoQD5U^6Em?9;ZN=_d)xM&_+6lf;I1fbFwB;i08 z$DknpaFE%FMMe4L5L19|^I+ig&Cg3r&PR498k>oMg&~}Qlj#rhcNl%oa@91TAD%%l zR6PqYIDsBV4O9N5r7}uwKov3!ZVZgR0l`5)wvcbQlM|4ZV}ASpKU6mZ^9L~72gC;e DL?2bm diff --git a/mac-cpp-source/libs/OSUtilities.cpp b/mac-cpp-source/libs/Ari Halberstadt/OSUtilities.cpp similarity index 100% rename from mac-cpp-source/libs/OSUtilities.cpp rename to mac-cpp-source/libs/Ari Halberstadt/OSUtilities.cpp diff --git a/mac-cpp-source/libs/OSUtilities.h b/mac-cpp-source/libs/Ari Halberstadt/OSUtilities.h similarity index 100% rename from mac-cpp-source/libs/OSUtilities.h rename to mac-cpp-source/libs/Ari Halberstadt/OSUtilities.h diff --git a/mac-cpp-source/libs/ChromiVNC/LICENSE.H b/mac-cpp-source/libs/ChromiVNC/LICENSE.H new file mode 100644 index 0000000..30c264b --- /dev/null +++ b/mac-cpp-source/libs/ChromiVNC/LICENSE.H @@ -0,0 +1,164 @@ +// ================================================ +// LICENSE.H +// - The actual licence text. Read carefully, and distribute always. +// ================================================ +// This source file is part of the TridiaVNC package, as originally developed by Jonathan "Chromatix" Morton for Tridia Corporation. + +// TridiaVNC is distributed under the GNU General Public Licence (GPL). You may modify, copy, and/or distribute this program as much +// as you please, provided you remain within the terms of the GPL. You may use Version 2 of the GPL, or, at your option, any later +// version. The current version as of 9th October 2000 is reproduced below for your convenience; the most up-to-date version can +// be found on http://www.fsf.org/. TridiaVNC is Free Software; it has no warranty, not even the normally implied warranties such +// as "fitness for purpose" and so on. Please read the GPL, below, for full details. + +#pragma once + +/* GNU GENERAL PUBLIC LICENSE + +Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. +59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +Preamble + +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using +it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source +code. And you must show them these terms so they know their rights. + +We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. + +Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program +proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and modification follow. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", +below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a +portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as +"you". + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is +covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along +with the Program. + +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these + conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program + is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on +the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works +based on the Program. + +In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other +work under the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the +following: + + a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software + interchange; or, + + b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received + the program in object code or executable form with such an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is +normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies +the executable. + +If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of +the source code, even though third parties are not compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and +will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties +remain in full compliance. + +5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its +terms and conditions for copying, distributing or modifying the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this +License. + +7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all +those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of +the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in +reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may +add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the +limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in +detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and +conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever +published by the Free Software Foundation. + +10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the +Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our +free software and of promoting the sharing and reuse of software generally. + +NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT +WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, +EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE +ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL +NECESSARY SERVICING, REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL +DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE +OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER +PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +END OF TERMS AND CONDITIONS */ diff --git a/mac-cpp-source/libs/ChromiVNC/VNCKeyboard.cpp b/mac-cpp-source/libs/ChromiVNC/VNCKeyboard.cpp new file mode 100644 index 0000000..90c8186 --- /dev/null +++ b/mac-cpp-source/libs/ChromiVNC/VNCKeyboard.cpp @@ -0,0 +1,352 @@ +// The routines in this file taken more or less unchanged from ChromiVNC Server v3.40 alpha5 +// (c) 2005-2005 Jonathan "Chromatix" Morton + +// This source file is part of the TridiaVNC package, as originally developed by Jonathan "Chromatix" Morton for Tridia Corporation. + +// TridiaVNC is distributed under the GNU General Public Licence (GPL). You may modify, copy, and/or distribute this program as much +// as you please, provided you remain within the terms of the GPL. You may use Version 2 of the GPL, or, at your option, any later +// version. The current version as of 9th October 2000 is reproduced below for your convenience; the most up-to-date version can +// be found on http://www.fsf.org/. TridiaVNC is Free Software; it has no warranty, not even the normally implied warranties such +// as "fitness for purpose" and so on. + +#include "LICENSE.h" + +#include +#include +#include + +#include "VNCKeyboard.h" +#include "keysymdef.h" + +// From https://opensource.apple.com/source/python/python-3/python/Mac/Lib/Carbon/Events.py.auto.html + +#define kNullCharCode 0 +#define kHomeCharCode 1 +#define kEnterCharCode 3 +#define kEndCharCode 4 +#define kHelpCharCode 5 +#define kBellCharCode 7 +#define kBackspaceCharCode 8 +#define kTabCharCode 9 +#define kLineFeedCharCode 10 +#define kVerticalTabCharCode 11 +#define kPageUpCharCode 11 +#define kFormFeedCharCode 12 +#define kPageDownCharCode 12 +#define kReturnCharCode 13 +#define kFunctionKeyCharCode 16 +#define kEscapeCharCode 27 +#define kClearCharCode 27 +#define kLeftArrowCharCode 28 +#define kRightArrowCharCode 29 +#define kUpArrowCharCode 30 +#define kDownArrowCharCode 31 +#define kDeleteCharCode 127 +#define kNonBreakingSpaceCharCode 202 + +enum { + shiftKeyCode = 0x38, + controlKeyCode = 0x3B, + optionKeyCode = 0x3A, + cmdKeyCode = 0x37 +}; + +// The following macros modify a LowMem global as well as our internal idea of the keyboard. +#define PRESSKEY(_code) { getKeyBuffer[_code / 8] |= (1 << (_code % 8)); ((unsigned char *) 0x174)[_code / 8] |= (1 << (_code % 8)); } +#define RELEASEKEY(_code) { getKeyBuffer[_code / 8] &= ~(1 << (_code % 8)); ((unsigned char *) 0x174)[_code / 8] &= ~(1 << (_code % 8)); } +#define BITKEY(_code) (getKeyBuffer[_code / 8] & (1 << (_code % 8))) + +EventModifiers modifiedKeys; +unsigned char getKeyBuffer[16], transMap[256][4]; + +void VNCKeyboard::Setup() { + // for the GetKeys patch + for(int c=0; c < 16; c++) + getKeyBuffer[c] = 0; + // for translating keysyms to keycodes + Ptr theKCHR = (char *) ::GetScriptManagerVariable(smKCHRCache); + unsigned long state, theChar; + for(int c=3; c >= 0; c--) { + for(int d=0; d < 256; d++) + transMap[d][c] = 0xFF; + modifiedKeys = ((c & 2) ? optionKey : 0) | ((c & 1) ? shiftKey : 0); + for(int d=0; d < 127; d++) { + state = 0; + theChar = ::KeyTranslate(theKCHR, (d | modifiedKeys), &state) & 0xFF; + if(theChar != 0 && transMap[theChar][c] == 0xFF) + transMap[theChar][c] = d; + } + } +} + +// Simulates pressing or releasing the key represented by keysym, values for which are defined by the X protocol. + +void VNCKeyboard::PressKey(unsigned long keysym, Boolean down) { + EvQElPtr queueEntry = nil; + EventRecord ev; + Boolean modifier = false, onKeyPad = false; + int modifierMask = 0; + int theChar = 0, theKeyCode = 0; + + // Prepare the event record + ev.what = down ? keyDown : keyUp; + ev.modifiers = modifiedKeys; + + // Translate the X11 keysym into MacRoman encoding + // Pay particular attention to modifier keys... + switch(keysym) { + case XK_Shift_L: + case XK_Shift_R: + modifier = true; + modifierMask = shiftKey; + theKeyCode = shiftKeyCode; + break; + + case XK_Control_L: + case XK_Control_R: + modifier = true; + modifierMask = controlKey; + theKeyCode = controlKeyCode; + break; + + case XK_Caps_Lock: + modifier = true; + modifierMask = alphaLock; + theKeyCode = 0x39; + break; + + // The Emacs META key, or the "space cadet" SUPER/HYPER keys, analogous to the Command key + case XK_Meta_L: + case XK_Meta_R: + case XK_Super_L: + case XK_Super_R: + case XK_Hyper_L: + case XK_Hyper_R: + modifier = true; + modifierMask = cmdKey; + theKeyCode = cmdKeyCode; + break; + + case XK_Alt_L: + case XK_Alt_R: + modifier = true; + modifierMask = optionKey; + theKeyCode = optionKeyCode; + break; + + // That's all the modifiers - now test for 'special' keys + case XK_BackSpace: + theChar = kBackspaceCharCode; + break; + + case XK_Tab: + theChar = kTabCharCode; + break; + + case XK_Return: + theChar = kReturnCharCode; + break; + + case XK_Escape: + theChar = kEscapeCharCode; + break; + + case XK_KP_Delete: + onKeyPad = true; + case XK_Delete: + theChar = kDeleteCharCode; + break; + + case XK_KP_Home: + onKeyPad = true; + case XK_Home: + theChar = kHomeCharCode; + break; + + case XK_KP_End: + onKeyPad = true; + case XK_End: + theChar = kEndCharCode; + break; + + case XK_KP_Page_Up: + onKeyPad = true; + case XK_Page_Up: + theChar = kPageUpCharCode; + break; + + case XK_KP_Page_Down: + onKeyPad = true; + case XK_Page_Down: + theChar = kPageDownCharCode; + break; + + case XK_KP_Left: + onKeyPad = true; + case XK_Left: + theChar = kLeftArrowCharCode; + break; + + case XK_KP_Right: + onKeyPad = true; + case XK_Right: + theChar = kRightArrowCharCode; + break; + + case XK_KP_Up: + onKeyPad = true; + case XK_Up: + theChar = kUpArrowCharCode; + break; + + case XK_KP_Down: + onKeyPad = true; + case XK_Down: + theChar = kDownArrowCharCode; + break; + + // The keypad is a strange beast. It generates a separate set of X11 keysyms and can be interpreted differently by Mac apps. + case XK_KP_Multiply: + theChar = '*'; + onKeyPad = true; + break; + + case XK_KP_Add: + theChar = '+'; + onKeyPad = true; + break; + + case XK_KP_Subtract: + theChar = '-'; + onKeyPad = true; + break; + + case XK_KP_Decimal: + theChar = '.'; + onKeyPad = true; + break; + + case XK_KP_Divide: + theChar = '/'; + onKeyPad = true; + break; + + case XK_KP_0: + case XK_KP_1: + case XK_KP_2: + case XK_KP_3: + case XK_KP_4: + case XK_KP_5: + case XK_KP_6: + case XK_KP_7: + case XK_KP_8: + case XK_KP_9: + theChar = (keysym - XK_KP_0) + '0'; + onKeyPad = true; + break; + + // Hmmm... it's not a modifier, and it's not special. Wonder if it's plain ASCII? + default: + if(keysym < 0x20 || keysym > 0x7E) { + // Nope! Ignore it, it might do something *very* strange. + //#warning FIXME! Implement high-order ASCII translation from Latin-1 to MacRoman + return; + } + // US-ASCII can go in without modification. + theChar = keysym & 0x7F; + break; + } + + if(modifier) { + if(down) { + PRESSKEY(theKeyCode); + modifiedKeys |= modifierMask; + } else { + RELEASEKEY(theKeyCode); + modifiedKeys &= ~modifierMask; + } + } + + ev.modifiers = modifiedKeys; + + // If Ctrl+Alt are held down, treat it as a Command key hold. This works around keyboards + // which don't have any kind of META key, and brain-dead VNC clients which don't send it even if present. + if((ev.modifiers & (optionKey | controlKey | cmdKey)) == (optionKey | controlKey)) { + ev.modifiers &= ~(optionKey | controlKey); + ev.modifiers |= cmdKey; + } + + if(modifier) { + if (ev.modifiers & optionKey) + PRESSKEY(optionKeyCode) + else + RELEASEKEY(optionKeyCode) + + if (ev.modifiers & controlKey) + PRESSKEY(controlKeyCode) + else + RELEASEKEY(controlKeyCode) + + if (ev.modifiers & cmdKey) + PRESSKEY(cmdKeyCode) + else + RELEASEKEY(cmdKeyCode) + + return; + } + + // Search for the correct KeyCode (plus any additional modifiers) to match the character... + theKeyCode = 0xFF; + for(int d=0; d < 3; d++) { + if(transMap[theChar][d] != 0xFF) { + theKeyCode = transMap[theChar][d]; + ev.modifiers |= ((d & 2) ? optionKey : 0) | ((d & 1) ? shiftKey : 0); + break; + } + } + + // Didn't find a key to match? Oops. Bye! + if(theKeyCode > 0x7F) + return; + + // Update the GetKeys map + if(down) + getKeyBuffer[theKeyCode / 8] |= (1 << (theKeyCode % 8)); + else + getKeyBuffer[theKeyCode / 8] &= ~(1 << (theKeyCode % 8)); + + // Retranslate the keycode using *all* the modifiers. This may result in zero, one or two characters... + Ptr theKCHR = (char *) ::GetScriptManagerVariable(smKCHRCache); + static unsigned long state = 0; + short mods = ev.modifiers; + long result = ::KeyTranslate(theKCHR, theKeyCode | mods, &state); + + // Extract Character #1 + if(result & 0xFF0000) { + ev.message = ((result >> 16) & 0xFF) | ((int) theKeyCode << 8); + ::PPostEvent(ev.what, ev.message, &queueEntry); + if(queueEntry) + queueEntry->evtQModifiers = mods; + } + + // Extract Character #2 + if(result & 0xFF) { + ev.message = (result & 0xFF) | ((int) theKeyCode << 8); + ::PPostEvent(ev.what, ev.message, &queueEntry); + if(queueEntry) + queueEntry->evtQModifiers = mods; + } + +// The following was producing quite an appreciable slowdown... we might lose keypresses, however. +// LThread::Yield(); +} + +// Overlay the remotely-pressed keys with those already pressed. + +void VNCKeyboard::GetKeys(UInt32 *theKeys) +{ + char *outKeys = (char *) theKeys; + + for(int c=0; c < 16; c++) + outKeys[c] |= getKeyBuffer[c]; +} \ No newline at end of file diff --git a/mac-cpp-source/libs/ChromiVNC/VNCKeyboard.h b/mac-cpp-source/libs/ChromiVNC/VNCKeyboard.h new file mode 100644 index 0000000..32171c6 --- /dev/null +++ b/mac-cpp-source/libs/ChromiVNC/VNCKeyboard.h @@ -0,0 +1,22 @@ +// The routines in this file taken more or less unchanged from ChromiVNC Server v3.40 alpha5 +// (c) 2005-2005 Jonathan "Chromatix" Morton + +// This source file is part of the TridiaVNC package, as originally developed by Jonathan "Chromatix" Morton for Tridia Corporation. + +// TridiaVNC is distributed under the GNU General Public Licence (GPL). You may modify, copy, and/or distribute this program as much +// as you please, provided you remain within the terms of the GPL. You may use Version 2 of the GPL, or, at your option, any later +// version. The current version as of 9th October 2000 is reproduced below for your convenience; the most up-to-date version can +// be found on http://www.fsf.org/. TridiaVNC is Free Software; it has no warranty, not even the normally implied warranties such +// as "fitness for purpose" and so on. + +#include "LICENSE.h" + + +#include "LICENSE.h" + +class VNCKeyboard { + public: + static void Setup(); + static void PressKey(unsigned long keysym, Boolean down); + static void GetKeys(UInt32 *theKeys); +}; \ No newline at end of file diff --git a/mac-cpp-source/libs/ChromiVNC/keysymdef.h b/mac-cpp-source/libs/ChromiVNC/keysymdef.h new file mode 100644 index 0000000..1484ec2 --- /dev/null +++ b/mac-cpp-source/libs/ChromiVNC/keysymdef.h @@ -0,0 +1,131 @@ +// ================================================ +// keysymdef.h +// - Defines enough of the X11 keysyms for our purposes. Compiled from XFree86 3.3.2. +// ================================================ +// This source file is part of the TridiaVNC package, as originally developed by Jonathan "Chromatix" Morton for Tridia Corporation. +// TridiaVNC is released under the GNU General Public Licence (GPL). Please read the file "LICENSE.H" for more information. +// If this file is not present, please contact Jonathan at or write to the Free Software Foundation, +// whose contact details can be found on http://www.fsf.org/. + +#include "LICENSE.H" + +#define XK_VoidSymbol 0xFFFFFF + +#define XK_space 0x0020 + +#define XK_BackSpace 0xFF08 +#define XK_Tab 0xFF09 +#define XK_Linefeed 0xFF0A +#define XK_Clear 0xFF0B +#define XK_Return 0xFF0D +#define XK_Pause 0xFF13 +#define XK_Scroll_Lock 0xFF14 +#define XK_Sys_Req 0xFF15 +#define XK_Escape 0xFF1B + +#define XK_Delete 0xFFFF + +#define XK_Print 0xFF61 +#define XK_dead_grave 0xFE50 +#define XK_dead_acute 0xFE51 +#define XK_dead_circumflex 0xFE52 +#define XK_dead_tilde 0xFE53 + +#define XK_Home 0xFF50 +#define XK_Left 0xFF51 +#define XK_Up 0xFF52 +#define XK_Right 0xFF53 +#define XK_Down 0xFF54 +#define XK_Page_Up 0xFF55 +#define XK_Page_Down 0xFF56 +#define XK_End 0xFF57 +#define XK_Begin 0xFF58 + +#define XK_Select 0xFF60 +#define XK_Print 0xFF61 +#define XK_Execute 0xFF62 +#define XK_Insert 0xFF63 + +#define XK_Cancel 0xFF69 +#define XK_Help 0xFF6A +#define XK_Break 0xFF6B +#define XK_Num_Lock 0xFF7F + +#define XK_KP_Space 0xFF80 +#define XK_KP_Tab 0xFF89 +#define XK_KP_Enter 0xFF8D + +#define XK_KP_Home 0xFF95 +#define XK_KP_Left 0xFF96 +#define XK_KP_Up 0xFF97 +#define XK_KP_Right 0xFF98 +#define XK_KP_Down 0xFF99 +#define XK_KP_Prior 0xFF9A +#define XK_KP_Page_Up 0xFF9A +#define XK_KP_Next 0xFF9B +#define XK_KP_Page_Down 0xFF9B +#define XK_KP_End 0xFF9C +#define XK_KP_Begin 0xFF9D +#define XK_KP_Insert 0xFF9E +#define XK_KP_Delete 0xFF9F +#define XK_KP_Equal 0xFFBD +#define XK_KP_Multiply 0xFFAA +#define XK_KP_Add 0xFFAB +#define XK_KP_Separator 0xFFAC +#define XK_KP_Subtract 0xFFAD +#define XK_KP_Decimal 0xFFAE +#define XK_KP_Divide 0xFFAF + +#define XK_KP_0 0xFFB0 +#define XK_KP_1 0xFFB1 +#define XK_KP_2 0xFFB2 +#define XK_KP_3 0xFFB3 +#define XK_KP_4 0xFFB4 +#define XK_KP_5 0xFFB5 +#define XK_KP_6 0xFFB6 +#define XK_KP_7 0xFFB7 +#define XK_KP_8 0xFFB8 +#define XK_KP_9 0xFFB9 + +#define XK_F1 0xFFBE +#define XK_F2 0xFFBF +#define XK_F3 0xFFC0 +#define XK_F4 0xFFC1 +#define XK_F5 0xFFC2 +#define XK_F6 0xFFC3 +#define XK_F7 0xFFC4 +#define XK_F8 0xFFC5 +#define XK_F9 0xFFC6 +#define XK_F10 0xFFC7 +#define XK_F11 0xFFC8 +#define XK_F12 0xFFC9 +#define XK_F13 0xFFCA +#define XK_F14 0xFFCB +#define XK_F15 0xFFCC +#define XK_F16 0xFFCD +#define XK_F17 0xFFCE +#define XK_F18 0xFFCF +#define XK_F19 0xFFD0 +#define XK_F20 0xFFD1 +#define XK_F21 0xFFD2 +#define XK_F22 0xFFD3 +#define XK_F23 0xFFD4 +#define XK_F24 0xFFD5 + + +#define XK_Shift_L 0xFFE1 +#define XK_Shift_R 0xFFE2 +#define XK_Control_L 0xFFE3 +#define XK_Control_R 0xFFE4 +#define XK_Caps_Lock 0xFFE5 +#define XK_Shift_Lock 0xFFE6 +#define XK_Meta_L 0xFFE7 +#define XK_Meta_R 0xFFE8 +#define XK_Super_L 0xFFEB /* Left super */ +#define XK_Super_R 0xFFEC /* Right super */ +#define XK_Hyper_L 0xFFED /* Left hyper */ +#define XK_Hyper_R 0xFFEE /* Right hyper */ +#define XK_Alt_L 0xFFE9 +#define XK_Alt_R 0xFFEA + + diff --git a/mac-cpp-source/libs/Common Libs/GestaltUtils.cpp b/mac-cpp-source/libs/Common Libs/GestaltUtils.cpp new file mode 100644 index 0000000..83da7c1 --- /dev/null +++ b/mac-cpp-source/libs/Common Libs/GestaltUtils.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** + * Common Libraries (c) 1994 Marcio Teixeira * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * To view a copy of the GNU General Public License, go to the following * + * location: . * + ****************************************************************************/ + +#include "GestaltUtils.h" + +short hasColorQD = 0; +long gSysVers = 0; + +short HasColorQD() { + OSErr err; + long tmpLong; + + hasColorQD = 0; + + if (!TrapAvailable(_Gestalt)) { + SysEnvRec mySys; + err = SysEnvirons( curSysEnvVers, &mySys ); + if( err != envNotPresent ) + hasColorQD = (mySys.hasColorQD) ? 1 : 0; + } else { + err = Gestalt(gestaltQuickdrawVersion, &tmpLong); + if( tmpLong >= gestalt8BitQD ) + hasColorQD = 1; + if( tmpLong >= gestalt32BitQD ) + hasColorQD = 2; + } + + return hasColorQD; +} + +long GetSysVersion() { + OSErr err = Gestalt(gestaltSystemVersion, &gSysVers); + return gSysVers; +} + +short GestaltTestAttr( OSType selector, long responseBit ) { + if (TrapAvailable(_Gestalt)) { + long tmpLong; + OSErr err = Gestalt( selector, &tmpLong ); + return err == noErr && BitTst(&tmpLong, 31 - responseBit); + } + return false; +} + +short GestaltTestMin( OSType selector, long minMask ) { + if (TrapAvailable(_Gestalt)) { + long tmpLong; + OSErr err = Gestalt( selector, &tmpLong ); + if( err != noErr ) + return( FALSE ); + return( tmpLong >= minMask ); + } + return false; +} + +/*Boolean TrapAvailable(short trapWord) { + TrapType trapType = (trapWord & 0x0800) ? ToolTrap : OSTrap; + return ((trapType == ToolTrap) && + ((trapWord & 0x03FF) >= 0x0200) && + (GetToolboxTrapAddress(0xA86E) == GetToolboxTrapAddress(0xAA6E))) + ? false + : NGetTrapAddress(trapWord, trapType) != GetToolboxTrapAddress(_Unimplemented); +}*/ \ No newline at end of file diff --git a/mac-cpp-source/libs/Common Libs/GestaltUtils.h b/mac-cpp-source/libs/Common Libs/GestaltUtils.h new file mode 100644 index 0000000..2270ddc --- /dev/null +++ b/mac-cpp-source/libs/Common Libs/GestaltUtils.h @@ -0,0 +1,25 @@ +/**************************************************************************** + * Common Libraries (c) 1994 Marcio Teixeira * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * To view a copy of the GNU General Public License, go to the following * + * location: . * + ****************************************************************************/ + +extern short hasColorQD; +extern long gSysVers; + +short HasColorQD( void ); +long GetSysVersion( void ); +short GestaltTestAttr( OSType selector, long responseBit ); +short GestaltTestMin( OSType selector, long minMask ); +Boolean TrapAvailable( short trapWord ); \ No newline at end of file diff --git a/mac-cpp-source/libs/MacTCP.h b/mac-cpp-source/libs/MacTCP.h index 5dca7af..ac86191 100644 --- a/mac-cpp-source/libs/MacTCP.h +++ b/mac-cpp-source/libs/MacTCP.h @@ -1,853 +1 @@ -/* - File: MacTCP.h - - Contains: TCP Manager Interfaces. - - Version: Technology: MacTCP 2.0.6 - Package: Universal Interfaces 2.1 in ÒMPW LatestÓ on ETO #18 - - Copyright: © 1984-1995 by Apple Computer, Inc. - All rights reserved. - - Bugs?: If you find a problem with this file, use the Apple Bug Reporter - stack. Include the file and version information (from above) - in the problem description and send to: - Internet: apple.bugs@applelink.apple.com - AppleLink: APPLE.BUGS - -*/ - -#ifndef __MACTCP__ -#define __MACTCP__ - - -#ifndef __TYPES__ -#include -#endif -/* #include */ - -#ifndef __APPLETALK__ -#include -#endif -/* #include */ -/* #include */ -/* #include */ - -#ifdef __cplusplus -extern "C" { -#endif - -#if PRAGMA_ALIGN_SUPPORTED -#pragma options align=mac68k -#endif - -#if PRAGMA_IMPORT_SUPPORTED -#pragma import on -#endif - -/* -Developer Notes: - 0. This MacTCP header replaces what used to be defined in the following header files - MacTCPCommonTypes.h - GetMyIPAddr.h - MiscIPPB.h - TCPPB.h - UDPPB.h - - When the various control calls are made to the ip driver, you must set up a - NewRoutineDescriptor for every non-nil completion routine and/or notifyProc parameter. - Otherwise, the 68K driver code, will not correctly call your routine. - 1. For ipctlGetAddr Control calls, use NewGetIPIOCompletionProc - to set up a GetIPIOCompletionUPP universal procptr to pass as - the ioCompletion parameter. - 2. For the ipctlEchoICMP and ipctlLAPStats Control calls, use - NewIPIOCompletion to set up a IPIOCompletionUPP universal procptr - to pass in the ioCompletion field of the parameter block. - 3. For TCPCreatePB Control calls, use NewTCPNotifyProc to set up a - TCPNotifyUPP universal procptr to pass in the notifyProc field - of the parameter block - 4. For all of the TCP Control calls using the TCPiopb parameter block, - use NewTCPIOCompletionProc to set up a TCPIOCompletionUPP - universal procptr to pass in the ioCompletion field of the paramter - block. - 5. For UDBCreatePB Control calls, use NewUDPNotifyProc to set up a - UDPNotifyUPP universal procptr to pass in the notifyProc field - of the parameter block - 6. For all of the UDP Control calls using the UDPiopb parameter block, - use NewUDPIOCompletionProc to set up a UDPIOCompletionUPP - universal procptr to pass in the ioCompletion field of the paramter - block. - 7. For all calls implementing a notifyProc or ioCompletion routine - which was set up using a NewTCPRoutineProc call, do not call - DisposeRoutineSDescriptor on the universal procptr until - after the completion or notify proc has completed. -*/ -/* MacTCP return Codes in the range -23000 through -23049 */ - -enum { - inProgress = 1, /* I/O in progress */ - ipBadLapErr = -23000, /* bad network configuration */ - ipBadCnfgErr = -23001, /* bad IP configuration error */ - ipNoCnfgErr = -23002, /* missing IP or LAP configuration error */ - ipLoadErr = -23003, /* error in MacTCP load */ - ipBadAddr = -23004, /* error in getting address */ - connectionClosing = -23005, /* connection is closing */ - invalidLength = -23006, - connectionExists = -23007, /* request conflicts with existing connection */ - connectionDoesntExist = -23008, /* connection does not exist */ - insufficientResources = -23009, /* insufficient resources to perform request */ - invalidStreamPtr = -23010, - streamAlreadyOpen = -23011, - connectionTerminated = -23012, - invalidBufPtr = -23013, - invalidRDS = -23014, - invalidWDS = -23014, - openFailed = -23015, - commandTimeout = -23016, - duplicateSocket = -23017 -}; - -/* Error codes from internal IP functions */ -enum { - ipDontFragErr = -23032, /* Packet too large to send w/o fragmenting */ - ipDestDeadErr = -23033, /* destination not responding */ - icmpEchoTimeoutErr = -23035, /* ICMP echo timed-out */ - ipNoFragMemErr = -23036, /* no memory to send fragmented pkt */ - ipRouteErr = -23037, /* can't route packet off-net */ - nameSyntaxErr = -23041, - cacheFault = -23042, - noResultProc = -23043, - noNameServer = -23044, - authNameErr = -23045, - noAnsErr = -23046, - dnrErr = -23047, - outOfMemory = -23048 -}; - -enum { - BYTES_16WORD = 2, /* bytes per = 16, bit ip word */ - BYTES_32WORD = 4, /* bytes per = 32, bit ip word */ - BYTES_64WORD = 8 /* bytes per = 64, bit ip word */ -}; - -/* 8-bit quantity */ -typedef UInt8 b_8; - -/* 16-bit quantity */ -typedef UInt16 b_16; - -/* 32-bit quantity */ -typedef UInt32 b_32; - -/* IP address is 32-bits */ -typedef b_32 ip_addr; - -struct ip_addrbytes { - union { - b_32 addr; - UInt8 byte[4]; - } a; -}; -typedef struct ip_addrbytes ip_addrbytes; - -struct wdsEntry { - unsigned short length; /* length of buffer */ - Ptr ptr; /* pointer to buffer */ -}; -typedef struct wdsEntry wdsEntry; - -struct rdsEntry { - unsigned short length; /* length of buffer */ - Ptr ptr; /* pointer to buffer */ -}; -typedef struct rdsEntry rdsEntry; - -typedef unsigned long BufferPtr; - -typedef unsigned long StreamPtr; - - -enum { - netUnreach = 0, - hostUnreach = 1, - protocolUnreach = 2, - portUnreach = 3, - fragReqd = 4, - sourceRouteFailed = 5, - timeExceeded = 6, - parmProblem = 7, - missingOption = 8, - lastICMPMsgType = 32767 -}; - -typedef unsigned short ICMPMsgType; - -typedef b_16 ip_port; - -struct ICMPReport { - StreamPtr streamPtr; - ip_addr localHost; - ip_port localPort; - ip_addr remoteHost; - ip_port remotePort; - short reportType; - unsigned short optionalAddlInfo; - unsigned long optionalAddlInfoPtr; -}; -typedef struct ICMPReport ICMPReport; - -/* csCode to get our IP address */ - -enum { - ipctlGetAddr = 15 -}; - -typedef void (*GetIPIOCompletionProcPtr)(struct GetAddrParamBlock *iopb); - -#if GENERATINGCFM -typedef UniversalProcPtr GetIPIOCompletionUPP; -#else -typedef GetIPIOCompletionProcPtr GetIPIOCompletionUPP; -#endif - -#define GetIPParamBlockHeader \ - struct QElem* qLink; \ - short qType; \ - short ioTrap; \ - Ptr ioCmdAddr; \ - GetIPIOCompletionUPP ioCompletion; \ - OSErr ioResult; \ - StringPtr ioNamePtr; \ - short ioVRefNum; \ - short ioCRefNum; \ - short csCode -struct GetAddrParamBlock { - struct QElem *qLink; - short qType; - short ioTrap; - Ptr ioCmdAddr; - GetIPIOCompletionUPP ioCompletion; - OSErr ioResult; - StringPtr ioNamePtr; - short ioVRefNum; - short ioCRefNum; - short csCode; /* standard I/O header */ - ip_addr ourAddress; /* our IP address */ - long ourNetMask; /* our IP net mask */ -}; -typedef struct GetAddrParamBlock GetAddrParamBlock; - -/* control codes */ - -enum { - ipctlEchoICMP = 17, /* send icmp echo */ - ipctlLAPStats = 19 /* get lap stats */ -}; - -typedef void (*IPIOCompletionProcPtr)(struct ICMPParamBlock *iopb); - -#if GENERATINGCFM -typedef UniversalProcPtr IPIOCompletionUPP; -#else -typedef IPIOCompletionProcPtr IPIOCompletionUPP; -#endif - -#define IPParamBlockHeader \ - struct QElem* qLink; \ - short qType; \ - short ioTrap; \ - Ptr ioCmdAddr; \ - IPIOCompletionUPP ioCompletion; \ - OSErr ioResult; \ - StringPtr ioNamePtr; \ - short ioVRefNum; \ - short ioCRefNum; \ - short csCode -struct ICMPParamBlock { - struct QElem *qLink; - short qType; - short ioTrap; - Ptr ioCmdAddr; - IPIOCompletionUPP ioCompletion; - OSErr ioResult; - StringPtr ioNamePtr; - short ioVRefNum; - short ioCRefNum; - short csCode; /* standard I/O header */ - short params[11]; - struct { - unsigned long echoRequestOut; /* time in ticks of when the echo request went out */ - unsigned long echoReplyIn; /* time in ticks of when the reply was received */ - struct rdsEntry echoedData; /* data received in responce */ - Ptr options; - unsigned long userDataPtr; - } icmpEchoInfo; -}; -typedef pascal void (*ICMPEchoNotifyProcPtr)(struct ICMPParamBlock *iopb); - -#if GENERATINGCFM -typedef UniversalProcPtr ICMPEchoNotifyUPP; -#else -typedef ICMPEchoNotifyProcPtr ICMPEchoNotifyUPP; -#endif - -struct IPParamBlock { - struct QElem *qLink; - short qType; - short ioTrap; - Ptr ioCmdAddr; - IPIOCompletionUPP ioCompletion; - OSErr ioResult; - StringPtr ioNamePtr; - short ioVRefNum; - short ioCRefNum; - short csCode; /* standard I/O header */ - union { - struct { - ip_addr dest; /* echo to IP address */ - wdsEntry data; - short timeout; - Ptr options; - unsigned short optLength; - ICMPEchoNotifyUPP icmpCompletion; - unsigned long userDataPtr; - } IPEchoPB; - struct { - struct LAPStats *lapStatsPtr; - } LAPStatsPB; - } csParam; -}; -union LAPStatsAddrXlation { - struct arp_entry *arp_table; - struct nbp_entry *nbp_table; -}; -struct LAPStats { - short ifType; - char *ifString; - short ifMaxMTU; - long ifSpeed; - short ifPhyAddrLength; - char *ifPhysicalAddress; - union LAPStatsAddrXlation AddrXlation; - short slotNumber; -}; -typedef struct LAPStats LAPStats; - -struct nbp_entry { - ip_addr ip_address; /* IP address */ - AddrBlock at_address; /* matching AppleTalk address */ - Boolean gateway; /* TRUE if entry for a gateway */ - Boolean valid; /* TRUE if LAP address is valid */ - Boolean probing; /* TRUE if NBP lookup pending */ - SInt8 afiller; /* Filler for proper byte alignment */ - long age; /* ticks since cache entry verified */ - long access; /* ticks since last access */ - SInt8 filler[116]; /* for internal use only !!! */ -}; -struct Enet_addr { - b_16 en_hi; - b_32 en_lo; -}; -typedef struct Enet_addr Enet_addr; - -struct arp_entry { - short age; /* cache aging field */ - b_16 protocol; /* Protocol type */ - ip_addr ip_address; /* IP address */ - Enet_addr en_address; /* matching Ethernet address */ -}; -typedef struct arp_entry arp_entry; - -/* number of ARP table entries */ - -enum { - ARP_TABLE_SIZE = 20 -}; - -enum { - NBP_TABLE_SIZE = 20, /* number of NBP table entries */ - NBP_MAX_NAME_SIZE = 16 + 10 + 2 -}; - -/* Command codes */ -enum { - TCPCreate = 30, - TCPPassiveOpen = 31, - TCPActiveOpen = 32, - TCPSend = 34, - TCPNoCopyRcv = 35, - TCPRcvBfrReturn = 36, - TCPRcv = 37, - TCPClose = 38, - TCPAbort = 39, - TCPStatus = 40, - TCPExtendedStat = 41, - TCPRelease = 42, - TCPGlobalInfo = 43, - TCPCtlMax = 49 -}; - -enum { - TCPClosing = 1, - TCPULPTimeout = 2, - TCPTerminate = 3, - TCPDataArrival = 4, - TCPUrgent = 5, - TCPICMPReceived = 6, - lastEvent = 32767 -}; - -typedef unsigned short TCPEventCode; - - -enum { - TCPRemoteAbort = 2, - TCPNetworkFailure = 3, - TCPSecPrecMismatch = 4, - TCPULPTimeoutTerminate = 5, - TCPULPAbort = 6, - TCPULPClose = 7, - TCPServiceError = 8, - lastReason = 32767 -}; - -typedef unsigned short TCPTerminationReason; - -typedef pascal void (*TCPNotifyProcPtr)(StreamPtr tcpStream, unsigned short eventCode, Ptr userDataPtr, unsigned short terminReason, struct ICMPReport *icmpMsg); - -#if GENERATINGCFM -typedef UniversalProcPtr TCPNotifyUPP; -#else -typedef TCPNotifyProcPtr TCPNotifyUPP; -#endif - -typedef unsigned short tcp_port; - -/* ValidityFlags */ - -enum { - timeoutValue = 0x80, - timeoutAction = 0x40, - typeOfService = 0x20, - precedence = 0x10 -}; - -/* TOSFlags */ -enum { - lowDelay = 0x01, - throughPut = 0x02, - reliability = 0x04 -}; - -struct TCPCreatePB { - Ptr rcvBuff; - unsigned long rcvBuffLen; - TCPNotifyUPP notifyProc; - Ptr userDataPtr; -}; -typedef struct TCPCreatePB TCPCreatePB; - -struct TCPOpenPB { - SInt8 ulpTimeoutValue; - SInt8 ulpTimeoutAction; - SInt8 validityFlags; - SInt8 commandTimeoutValue; - ip_addr remoteHost; - tcp_port remotePort; - ip_addr localHost; - tcp_port localPort; - SInt8 tosFlags; - SInt8 precedence; - Boolean dontFrag; - SInt8 timeToLive; - SInt8 security; - SInt8 optionCnt; - SInt8 options[40]; - Ptr userDataPtr; -}; -typedef struct TCPOpenPB TCPOpenPB; - -struct TCPSendPB { - SInt8 ulpTimeoutValue; - SInt8 ulpTimeoutAction; - SInt8 validityFlags; - Boolean pushFlag; - Boolean urgentFlag; - SInt8 filler; /* Filler for proper byte alignment */ - Ptr wdsPtr; - unsigned long sendFree; - unsigned short sendLength; - Ptr userDataPtr; -}; -typedef struct TCPSendPB TCPSendPB; - -/* for receive and return rcv buff calls */ -/* Note: the filler in the following structure is in a different location than */ -/* that specified in the Programmer's Guide. */ -struct TCPReceivePB { - SInt8 commandTimeoutValue; - Boolean markFlag; - Boolean urgentFlag; - SInt8 filler; /* Filler for proper byte alignment */ - Ptr rcvBuff; - unsigned short rcvBuffLen; - Ptr rdsPtr; - unsigned short rdsLength; - unsigned short secondTimeStamp; - Ptr userDataPtr; -}; -typedef struct TCPReceivePB TCPReceivePB; - -struct TCPClosePB { - SInt8 ulpTimeoutValue; - SInt8 ulpTimeoutAction; - SInt8 validityFlags; - SInt8 filler; /* Filler for proper byte alignment */ - Ptr userDataPtr; -}; -typedef struct TCPClosePB TCPClosePB; - -struct HistoBucket { - unsigned short value; - unsigned long counter; -}; -typedef struct HistoBucket HistoBucket; - - -enum { - NumOfHistoBuckets = 7 -}; - -struct TCPConnectionStats { - unsigned long dataPktsRcvd; - unsigned long dataPktsSent; - unsigned long dataPktsResent; - unsigned long bytesRcvd; - unsigned long bytesRcvdDup; - unsigned long bytesRcvdPastWindow; - unsigned long bytesSent; - unsigned long bytesResent; - unsigned short numHistoBuckets; - struct HistoBucket sentSizeHisto[NumOfHistoBuckets]; - unsigned short lastRTT; - unsigned short tmrSRTT; - unsigned short rttVariance; - unsigned short tmrRTO; - SInt8 sendTries; - SInt8 sourchQuenchRcvd; -}; -typedef struct TCPConnectionStats TCPConnectionStats; - -struct TCPStatusPB { - SInt8 ulpTimeoutValue; - SInt8 ulpTimeoutAction; - long unused; - ip_addr remoteHost; - tcp_port remotePort; - ip_addr localHost; - tcp_port localPort; - SInt8 tosFlags; - SInt8 precedence; - SInt8 connectionState; - SInt8 filler; /* Filler for proper byte alignment */ - unsigned short sendWindow; - unsigned short rcvWindow; - unsigned short amtUnackedData; - unsigned short amtUnreadData; - Ptr securityLevelPtr; - unsigned long sendUnacked; - unsigned long sendNext; - unsigned long congestionWindow; - unsigned long rcvNext; - unsigned long srtt; - unsigned long lastRTT; - unsigned long sendMaxSegSize; - struct TCPConnectionStats *connStatPtr; - Ptr userDataPtr; -}; -typedef struct TCPStatusPB TCPStatusPB; - -struct TCPAbortPB { - Ptr userDataPtr; -}; -typedef struct TCPAbortPB TCPAbortPB; - -struct TCPParam { - unsigned long tcpRtoA; - unsigned long tcpRtoMin; - unsigned long tcpRtoMax; - unsigned long tcpMaxSegSize; - unsigned long tcpMaxConn; - unsigned long tcpMaxWindow; -}; -typedef struct TCPParam TCPParam; - -struct TCPStats { - unsigned long tcpConnAttempts; - unsigned long tcpConnOpened; - unsigned long tcpConnAccepted; - unsigned long tcpConnClosed; - unsigned long tcpConnAborted; - unsigned long tcpOctetsIn; - unsigned long tcpOctetsOut; - unsigned long tcpOctetsInDup; - unsigned long tcpOctetsRetrans; - unsigned long tcpInputPkts; - unsigned long tcpOutputPkts; - unsigned long tcpDupPkts; - unsigned long tcpRetransPkts; -}; -typedef struct TCPStats TCPStats; - -typedef StreamPtr *StreamPPtr; - -struct TCPGlobalInfoPB { - struct TCPParam *tcpParamPtr; - struct TCPStats *tcpStatsPtr; - StreamPPtr tcpCDBTable[1]; - Ptr userDataPtr; - unsigned short maxTCPConnections; -}; -typedef struct TCPGlobalInfoPB TCPGlobalInfoPB; - -typedef void (*TCPIOCompletionProcPtr)(struct TCPiopb *iopb); - -#if GENERATINGCFM -typedef UniversalProcPtr TCPIOCompletionUPP; -#else -typedef TCPIOCompletionProcPtr TCPIOCompletionUPP; -#endif - -struct TCPiopb { - SInt8 fill12[12]; - TCPIOCompletionUPP ioCompletion; - short ioResult; - Ptr ioNamePtr; - short ioVRefNum; - short ioCRefNum; - short csCode; - StreamPtr tcpStream; - union { - struct TCPCreatePB create; - struct TCPOpenPB open; - struct TCPSendPB send; - struct TCPReceivePB receive; - struct TCPClosePB close; - struct TCPAbortPB abort; - struct TCPStatusPB status; - struct TCPGlobalInfoPB globalInfo; - } csParam; -}; -typedef struct TCPiopb TCPiopb; - - -enum { - UDPCreate = 20, - UDPRead = 21, - UDPBfrReturn = 22, - UDPWrite = 23, - UDPRelease = 24, - UDPMaxMTUSize = 25, - UDPStatus = 26, - UDPMultiCreate = 27, - UDPMultiSend = 28, - UDPMultiRead = 29, - UDPCtlMax = 29 -}; - -enum { - UDPDataArrival = 1, - UDPICMPReceived = 2, - lastUDPEvent = 32767 -}; - -typedef unsigned short UDPEventCode; - -typedef pascal void (*UDPNotifyProcPtr)(StreamPtr udpStream, unsigned short eventCode, Ptr userDataPtr, struct ICMPReport *icmpMsg); - -#if GENERATINGCFM -typedef UniversalProcPtr UDPNotifyUPP; -#else -typedef UDPNotifyProcPtr UDPNotifyUPP; -#endif - -typedef unsigned short udp_port; - -/* for create and release calls */ -struct UDPCreatePB { - Ptr rcvBuff; - unsigned long rcvBuffLen; - UDPNotifyUPP notifyProc; - unsigned short localPort; - Ptr userDataPtr; - udp_port endingPort; -}; -typedef struct UDPCreatePB UDPCreatePB; - -struct UDPSendPB { - unsigned short reserved; - ip_addr remoteHost; - udp_port remotePort; - Ptr wdsPtr; - Boolean checkSum; - SInt8 filler; /* Filler for proper byte alignment */ - unsigned short sendLength; - Ptr userDataPtr; - udp_port localPort; -}; -typedef struct UDPSendPB UDPSendPB; - -/* for receive and buffer return calls */ -struct UDPReceivePB { - unsigned short timeOut; - ip_addr remoteHost; - udp_port remotePort; - Ptr rcvBuff; - unsigned short rcvBuffLen; - unsigned short secondTimeStamp; - Ptr userDataPtr; - ip_addr destHost; /* only for use with multi rcv */ - udp_port destPort; /* only for use with multi rcv */ -}; -typedef struct UDPReceivePB UDPReceivePB; - -struct UDPMTUPB { - unsigned short mtuSize; - ip_addr remoteHost; - Ptr userDataPtr; -}; -typedef struct UDPMTUPB UDPMTUPB; - -typedef void (*UDPIOCompletionProcPtr)(struct UDPiopb *iopb); - -#if GENERATINGCFM -typedef UniversalProcPtr UDPIOCompletionUPP; -#else -typedef UDPIOCompletionProcPtr UDPIOCompletionUPP; -#endif - -struct UDPiopb { - SInt8 fill12[12]; - UDPIOCompletionUPP ioCompletion; - short ioResult; - Ptr ioNamePtr; - short ioVRefNum; - short ioCRefNum; - short csCode; - StreamPtr udpStream; - union { - struct UDPCreatePB create; - struct UDPSendPB send; - struct UDPReceivePB receive; - struct UDPMTUPB mtu; - } csParam; -}; -typedef struct UDPiopb UDPiopb; - - -#if GENERATINGCFM -#else -#endif - -enum { - uppGetIPIOCompletionProcInfo = kCStackBased - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct GetAddrParamBlock*))), - uppIPIOCompletionProcInfo = kCStackBased - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct ICMPParamBlock*))), - uppICMPEchoNotifyProcInfo = kPascalStackBased - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct ICMPParamBlock*))), - uppTCPNotifyProcInfo = kPascalStackBased - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(StreamPtr))) - | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(unsigned short))) - | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Ptr))) - | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(unsigned short))) - | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(struct ICMPReport*))), - uppTCPIOCompletionProcInfo = kCStackBased - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct TCPiopb*))), - uppUDPNotifyProcInfo = kPascalStackBased - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(StreamPtr))) - | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(unsigned short))) - | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Ptr))) - | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(struct ICMPReport*))), - uppUDPIOCompletionProcInfo = kCStackBased - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct UDPiopb*))) -}; - -#if GENERATINGCFM -#define NewGetIPIOCompletionProc(userRoutine) \ - (GetIPIOCompletionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppGetIPIOCompletionProcInfo, GetCurrentArchitecture()) -#define NewIPIOCompletionProc(userRoutine) \ - (IPIOCompletionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppIPIOCompletionProcInfo, GetCurrentArchitecture()) -#define NewICMPEchoNotifyProc(userRoutine) \ - (ICMPEchoNotifyUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppICMPEchoNotifyProcInfo, GetCurrentArchitecture()) -#define NewTCPNotifyProc(userRoutine) \ - (TCPNotifyUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppTCPNotifyProcInfo, GetCurrentArchitecture()) -#define NewTCPIOCompletionProc(userRoutine) \ - (TCPIOCompletionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppTCPIOCompletionProcInfo, GetCurrentArchitecture()) -#define NewUDPNotifyProc(userRoutine) \ - (UDPNotifyUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppUDPNotifyProcInfo, GetCurrentArchitecture()) -#define NewUDPIOCompletionProc(userRoutine) \ - (UDPIOCompletionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppUDPIOCompletionProcInfo, GetCurrentArchitecture()) -#else -#define NewGetIPIOCompletionProc(userRoutine) \ - ((GetIPIOCompletionUPP) (userRoutine)) -#define NewIPIOCompletionProc(userRoutine) \ - ((IPIOCompletionUPP) (userRoutine)) -#define NewICMPEchoNotifyProc(userRoutine) \ - ((ICMPEchoNotifyUPP) (userRoutine)) -#define NewTCPNotifyProc(userRoutine) \ - ((TCPNotifyUPP) (userRoutine)) -#define NewTCPIOCompletionProc(userRoutine) \ - ((TCPIOCompletionUPP) (userRoutine)) -#define NewUDPNotifyProc(userRoutine) \ - ((UDPNotifyUPP) (userRoutine)) -#define NewUDPIOCompletionProc(userRoutine) \ - ((UDPIOCompletionUPP) (userRoutine)) -#endif - -#if GENERATINGCFM -#define CallGetIPIOCompletionProc(userRoutine, iopb) \ - CallUniversalProc((UniversalProcPtr)(userRoutine), uppGetIPIOCompletionProcInfo, (iopb)) -#define CallIPIOCompletionProc(userRoutine, iopb) \ - CallUniversalProc((UniversalProcPtr)(userRoutine), uppIPIOCompletionProcInfo, (iopb)) -#define CallICMPEchoNotifyProc(userRoutine, iopb) \ - CallUniversalProc((UniversalProcPtr)(userRoutine), uppICMPEchoNotifyProcInfo, (iopb)) -#define CallTCPNotifyProc(userRoutine, tcpStream, eventCode, userDataPtr, terminReason, icmpMsg) \ - CallUniversalProc((UniversalProcPtr)(userRoutine), uppTCPNotifyProcInfo, (tcpStream), (eventCode), (userDataPtr), (terminReason), (icmpMsg)) -#define CallTCPIOCompletionProc(userRoutine, iopb) \ - CallUniversalProc((UniversalProcPtr)(userRoutine), uppTCPIOCompletionProcInfo, (iopb)) -#define CallUDPNotifyProc(userRoutine, udpStream, eventCode, userDataPtr, icmpMsg) \ - CallUniversalProc((UniversalProcPtr)(userRoutine), uppUDPNotifyProcInfo, (udpStream), (eventCode), (userDataPtr), (icmpMsg)) -#define CallUDPIOCompletionProc(userRoutine, iopb) \ - CallUniversalProc((UniversalProcPtr)(userRoutine), uppUDPIOCompletionProcInfo, (iopb)) -#else -#define CallGetIPIOCompletionProc(userRoutine, iopb) \ - (*(userRoutine))((iopb)) -#define CallIPIOCompletionProc(userRoutine, iopb) \ - (*(userRoutine))((iopb)) -#define CallICMPEchoNotifyProc(userRoutine, iopb) \ - (*(userRoutine))((iopb)) -#define CallTCPNotifyProc(userRoutine, tcpStream, eventCode, userDataPtr, terminReason, icmpMsg) \ - (*(userRoutine))((tcpStream), (eventCode), (userDataPtr), (terminReason), (icmpMsg)) -#define CallTCPIOCompletionProc(userRoutine, iopb) \ - (*(userRoutine))((iopb)) -#define CallUDPNotifyProc(userRoutine, udpStream, eventCode, userDataPtr, icmpMsg) \ - (*(userRoutine))((udpStream), (eventCode), (userDataPtr), (icmpMsg)) -#define CallUDPIOCompletionProc(userRoutine, iopb) \ - (*(userRoutine))((iopb)) -#endif - - -#if PRAGMA_IMPORT_SUPPORTED -#pragma import off -#endif - -#if PRAGMA_ALIGN_SUPPORTED -#pragma options align=reset -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* __MACTCP__ */ +/* File: MacTCP.h Contains: TCP Manager Interfaces. Version: Technology: MacTCP 2.0.6 Package: Universal Interfaces 2.1 in "MPW Latest" on ETO #18 Copyright: © 1984-1995 by Apple Computer, Inc. All rights reserved. Bugs?: If you find a problem with this file, use the Apple Bug Reporter stack. Include the file and version information (from above) in the problem description and send to: Internet: apple.bugs@applelink.apple.com AppleLink: APPLE.BUGS */ #ifndef __MACTCP__ #define __MACTCP__ #ifndef __TYPES__ #include #endif /* #include */ #ifndef __APPLETALK__ #include #endif /* #include */ /* #include */ /* #include */ #ifdef __cplusplus extern "C" { #endif #if PRAGMA_ALIGN_SUPPORTED #pragma options align=mac68k #endif #if PRAGMA_IMPORT_SUPPORTED #pragma import on #endif /* Developer Notes: 0. This MacTCP header replaces what used to be defined in the following header files MacTCPCommonTypes.h GetMyIPAddr.h MiscIPPB.h TCPPB.h UDPPB.h When the various control calls are made to the ip driver, you must set up a NewRoutineDescriptor for every non-nil completion routine and/or notifyProc parameter. Otherwise, the 68K driver code, will not correctly call your routine. 1. For ipctlGetAddr Control calls, use NewGetIPIOCompletionProc to set up a GetIPIOCompletionUPP universal procptr to pass as the ioCompletion parameter. 2. For the ipctlEchoICMP and ipctlLAPStats Control calls, use NewIPIOCompletion to set up a IPIOCompletionUPP universal procptr to pass in the ioCompletion field of the parameter block. 3. For TCPCreatePB Control calls, use NewTCPNotifyProc to set up a TCPNotifyUPP universal procptr to pass in the notifyProc field of the parameter block 4. For all of the TCP Control calls using the TCPiopb parameter block, use NewTCPIOCompletionProc to set up a TCPIOCompletionUPP universal procptr to pass in the ioCompletion field of the paramter block. 5. For UDBCreatePB Control calls, use NewUDPNotifyProc to set up a UDPNotifyUPP universal procptr to pass in the notifyProc field of the parameter block 6. For all of the UDP Control calls using the UDPiopb parameter block, use NewUDPIOCompletionProc to set up a UDPIOCompletionUPP universal procptr to pass in the ioCompletion field of the paramter block. 7. For all calls implementing a notifyProc or ioCompletion routine which was set up using a NewTCPRoutineProc call, do not call DisposeRoutineSDescriptor on the universal procptr until after the completion or notify proc has completed. */ /* MacTCP return Codes in the range -23000 through -23049 */ enum { inProgress = 1, /* I/O in progress */ ipBadLapErr = -23000, /* bad network configuration */ ipBadCnfgErr = -23001, /* bad IP configuration error */ ipNoCnfgErr = -23002, /* missing IP or LAP configuration error */ ipLoadErr = -23003, /* error in MacTCP load */ ipBadAddr = -23004, /* error in getting address */ connectionClosing = -23005, /* connection is closing */ invalidLength = -23006, connectionExists = -23007, /* request conflicts with existing connection */ connectionDoesntExist = -23008, /* connection does not exist */ insufficientResources = -23009, /* insufficient resources to perform request */ invalidStreamPtr = -23010, streamAlreadyOpen = -23011, connectionTerminated = -23012, invalidBufPtr = -23013, invalidRDS = -23014, invalidWDS = -23014, openFailed = -23015, commandTimeout = -23016, duplicateSocket = -23017 }; /* Error codes from internal IP functions */ enum { ipDontFragErr = -23032, /* Packet too large to send w/o fragmenting */ ipDestDeadErr = -23033, /* destination not responding */ icmpEchoTimeoutErr = -23035, /* ICMP echo timed-out */ ipNoFragMemErr = -23036, /* no memory to send fragmented pkt */ ipRouteErr = -23037, /* can't route packet off-net */ nameSyntaxErr = -23041, cacheFault = -23042, noResultProc = -23043, noNameServer = -23044, authNameErr = -23045, noAnsErr = -23046, dnrErr = -23047, outOfMemory = -23048 }; enum { BYTES_16WORD = 2, /* bytes per = 16, bit ip word */ BYTES_32WORD = 4, /* bytes per = 32, bit ip word */ BYTES_64WORD = 8 /* bytes per = 64, bit ip word */ }; /* 8-bit quantity */ typedef UInt8 b_8; /* 16-bit quantity */ typedef UInt16 b_16; /* 32-bit quantity */ typedef UInt32 b_32; /* IP address is 32-bits */ typedef b_32 ip_addr; struct ip_addrbytes { union { b_32 addr; UInt8 byte[4]; } a; }; typedef struct ip_addrbytes ip_addrbytes; struct wdsEntry { unsigned short length; /* length of buffer */ Ptr ptr; /* pointer to buffer */ }; typedef struct wdsEntry wdsEntry; struct rdsEntry { unsigned short length; /* length of buffer */ Ptr ptr; /* pointer to buffer */ }; typedef struct rdsEntry rdsEntry; typedef unsigned long BufferPtr; typedef unsigned long StreamPtr; enum { netUnreach = 0, hostUnreach = 1, protocolUnreach = 2, portUnreach = 3, fragReqd = 4, sourceRouteFailed = 5, timeExceeded = 6, parmProblem = 7, missingOption = 8, lastICMPMsgType = 32767 }; typedef unsigned short ICMPMsgType; typedef b_16 ip_port; struct ICMPReport { StreamPtr streamPtr; ip_addr localHost; ip_port localPort; ip_addr remoteHost; ip_port remotePort; short reportType; unsigned short optionalAddlInfo; unsigned long optionalAddlInfoPtr; }; typedef struct ICMPReport ICMPReport; /* csCode to get our IP address */ enum { ipctlGetAddr = 15 }; typedef void (*GetIPIOCompletionProcPtr)(struct GetAddrParamBlock *iopb); #if GENERATINGCFM typedef UniversalProcPtr GetIPIOCompletionUPP; #else typedef GetIPIOCompletionProcPtr GetIPIOCompletionUPP; #endif #define GetIPParamBlockHeader \ struct QElem* qLink; \ short qType; \ short ioTrap; \ Ptr ioCmdAddr; \ GetIPIOCompletionUPP ioCompletion; \ OSErr ioResult; \ StringPtr ioNamePtr; \ short ioVRefNum; \ short ioCRefNum; \ short csCode struct GetAddrParamBlock { struct QElem *qLink; short qType; short ioTrap; Ptr ioCmdAddr; GetIPIOCompletionUPP ioCompletion; OSErr ioResult; StringPtr ioNamePtr; short ioVRefNum; short ioCRefNum; short csCode; /* standard I/O header */ ip_addr ourAddress; /* our IP address */ long ourNetMask; /* our IP net mask */ }; typedef struct GetAddrParamBlock GetAddrParamBlock; /* control codes */ enum { ipctlEchoICMP = 17, /* send icmp echo */ ipctlLAPStats = 19 /* get lap stats */ }; typedef void (*IPIOCompletionProcPtr)(struct ICMPParamBlock *iopb); #if GENERATINGCFM typedef UniversalProcPtr IPIOCompletionUPP; #else typedef IPIOCompletionProcPtr IPIOCompletionUPP; #endif #define IPParamBlockHeader \ struct QElem* qLink; \ short qType; \ short ioTrap; \ Ptr ioCmdAddr; \ IPIOCompletionUPP ioCompletion; \ OSErr ioResult; \ StringPtr ioNamePtr; \ short ioVRefNum; \ short ioCRefNum; \ short csCode struct ICMPParamBlock { struct QElem *qLink; short qType; short ioTrap; Ptr ioCmdAddr; IPIOCompletionUPP ioCompletion; OSErr ioResult; StringPtr ioNamePtr; short ioVRefNum; short ioCRefNum; short csCode; /* standard I/O header */ short params[11]; struct { unsigned long echoRequestOut; /* time in ticks of when the echo request went out */ unsigned long echoReplyIn; /* time in ticks of when the reply was received */ struct rdsEntry echoedData; /* data received in responce */ Ptr options; unsigned long userDataPtr; } icmpEchoInfo; }; typedef pascal void (*ICMPEchoNotifyProcPtr)(struct ICMPParamBlock *iopb); #if GENERATINGCFM typedef UniversalProcPtr ICMPEchoNotifyUPP; #else typedef ICMPEchoNotifyProcPtr ICMPEchoNotifyUPP; #endif struct IPParamBlock { struct QElem *qLink; short qType; short ioTrap; Ptr ioCmdAddr; IPIOCompletionUPP ioCompletion; OSErr ioResult; StringPtr ioNamePtr; short ioVRefNum; short ioCRefNum; short csCode; /* standard I/O header */ union { struct { ip_addr dest; /* echo to IP address */ wdsEntry data; short timeout; Ptr options; unsigned short optLength; ICMPEchoNotifyUPP icmpCompletion; unsigned long userDataPtr; } IPEchoPB; struct { struct LAPStats *lapStatsPtr; } LAPStatsPB; } csParam; }; union LAPStatsAddrXlation { struct arp_entry *arp_table; struct nbp_entry *nbp_table; }; struct LAPStats { short ifType; char *ifString; short ifMaxMTU; long ifSpeed; short ifPhyAddrLength; char *ifPhysicalAddress; union LAPStatsAddrXlation AddrXlation; short slotNumber; }; typedef struct LAPStats LAPStats; struct nbp_entry { ip_addr ip_address; /* IP address */ AddrBlock at_address; /* matching AppleTalk address */ Boolean gateway; /* TRUE if entry for a gateway */ Boolean valid; /* TRUE if LAP address is valid */ Boolean probing; /* TRUE if NBP lookup pending */ SInt8 afiller; /* Filler for proper byte alignment */ long age; /* ticks since cache entry verified */ long access; /* ticks since last access */ SInt8 filler[116]; /* for internal use only !!! */ }; struct Enet_addr { b_16 en_hi; b_32 en_lo; }; typedef struct Enet_addr Enet_addr; struct arp_entry { short age; /* cache aging field */ b_16 protocol; /* Protocol type */ ip_addr ip_address; /* IP address */ Enet_addr en_address; /* matching Ethernet address */ }; typedef struct arp_entry arp_entry; /* number of ARP table entries */ enum { ARP_TABLE_SIZE = 20 }; enum { NBP_TABLE_SIZE = 20, /* number of NBP table entries */ NBP_MAX_NAME_SIZE = 16 + 10 + 2 }; /* Command codes */ enum { TCPCreate = 30, TCPPassiveOpen = 31, TCPActiveOpen = 32, TCPSend = 34, TCPNoCopyRcv = 35, TCPRcvBfrReturn = 36, TCPRcv = 37, TCPClose = 38, TCPAbort = 39, TCPStatus = 40, TCPExtendedStat = 41, TCPRelease = 42, TCPGlobalInfo = 43, TCPCtlMax = 49 }; enum { TCPClosing = 1, TCPULPTimeout = 2, TCPTerminate = 3, TCPDataArrival = 4, TCPUrgent = 5, TCPICMPReceived = 6, lastEvent = 32767 }; typedef unsigned short TCPEventCode; enum { TCPRemoteAbort = 2, TCPNetworkFailure = 3, TCPSecPrecMismatch = 4, TCPULPTimeoutTerminate = 5, TCPULPAbort = 6, TCPULPClose = 7, TCPServiceError = 8, lastReason = 32767 }; typedef unsigned short TCPTerminationReason; typedef pascal void (*TCPNotifyProcPtr)(StreamPtr tcpStream, unsigned short eventCode, Ptr userDataPtr, unsigned short terminReason, struct ICMPReport *icmpMsg); #if GENERATINGCFM typedef UniversalProcPtr TCPNotifyUPP; #else typedef TCPNotifyProcPtr TCPNotifyUPP; #endif typedef unsigned short tcp_port; /* ValidityFlags */ enum { timeoutValue = 0x80, timeoutAction = 0x40, typeOfService = 0x20, precedence = 0x10 }; /* TOSFlags */ enum { lowDelay = 0x01, throughPut = 0x02, reliability = 0x04 }; struct TCPCreatePB { Ptr rcvBuff; unsigned long rcvBuffLen; TCPNotifyUPP notifyProc; Ptr userDataPtr; }; typedef struct TCPCreatePB TCPCreatePB; struct TCPOpenPB { SInt8 ulpTimeoutValue; SInt8 ulpTimeoutAction; SInt8 validityFlags; SInt8 commandTimeoutValue; ip_addr remoteHost; tcp_port remotePort; ip_addr localHost; tcp_port localPort; SInt8 tosFlags; SInt8 precedence; Boolean dontFrag; SInt8 timeToLive; SInt8 security; SInt8 optionCnt; SInt8 options[40]; Ptr userDataPtr; }; typedef struct TCPOpenPB TCPOpenPB; struct TCPSendPB { SInt8 ulpTimeoutValue; SInt8 ulpTimeoutAction; SInt8 validityFlags; Boolean pushFlag; Boolean urgentFlag; SInt8 filler; /* Filler for proper byte alignment */ Ptr wdsPtr; unsigned long sendFree; unsigned short sendLength; Ptr userDataPtr; }; typedef struct TCPSendPB TCPSendPB; /* for receive and return rcv buff calls */ /* Note: the filler in the following structure is in a different location than */ /* that specified in the Programmer's Guide. */ struct TCPReceivePB { SInt8 commandTimeoutValue; Boolean markFlag; Boolean urgentFlag; SInt8 filler; /* Filler for proper byte alignment */ Ptr rcvBuff; unsigned short rcvBuffLen; Ptr rdsPtr; unsigned short rdsLength; unsigned short secondTimeStamp; Ptr userDataPtr; }; typedef struct TCPReceivePB TCPReceivePB; struct TCPClosePB { SInt8 ulpTimeoutValue; SInt8 ulpTimeoutAction; SInt8 validityFlags; SInt8 filler; /* Filler for proper byte alignment */ Ptr userDataPtr; }; typedef struct TCPClosePB TCPClosePB; struct HistoBucket { unsigned short value; unsigned long counter; }; typedef struct HistoBucket HistoBucket; enum { NumOfHistoBuckets = 7 }; struct TCPConnectionStats { unsigned long dataPktsRcvd; unsigned long dataPktsSent; unsigned long dataPktsResent; unsigned long bytesRcvd; unsigned long bytesRcvdDup; unsigned long bytesRcvdPastWindow; unsigned long bytesSent; unsigned long bytesResent; unsigned short numHistoBuckets; struct HistoBucket sentSizeHisto[NumOfHistoBuckets]; unsigned short lastRTT; unsigned short tmrSRTT; unsigned short rttVariance; unsigned short tmrRTO; SInt8 sendTries; SInt8 sourchQuenchRcvd; }; typedef struct TCPConnectionStats TCPConnectionStats; struct TCPStatusPB { SInt8 ulpTimeoutValue; SInt8 ulpTimeoutAction; long unused; ip_addr remoteHost; tcp_port remotePort; ip_addr localHost; tcp_port localPort; SInt8 tosFlags; SInt8 precedence; SInt8 connectionState; SInt8 filler; /* Filler for proper byte alignment */ unsigned short sendWindow; unsigned short rcvWindow; unsigned short amtUnackedData; unsigned short amtUnreadData; Ptr securityLevelPtr; unsigned long sendUnacked; unsigned long sendNext; unsigned long congestionWindow; unsigned long rcvNext; unsigned long srtt; unsigned long lastRTT; unsigned long sendMaxSegSize; struct TCPConnectionStats *connStatPtr; Ptr userDataPtr; }; typedef struct TCPStatusPB TCPStatusPB; struct TCPAbortPB { Ptr userDataPtr; }; typedef struct TCPAbortPB TCPAbortPB; struct TCPParam { unsigned long tcpRtoA; unsigned long tcpRtoMin; unsigned long tcpRtoMax; unsigned long tcpMaxSegSize; unsigned long tcpMaxConn; unsigned long tcpMaxWindow; }; typedef struct TCPParam TCPParam; struct TCPStats { unsigned long tcpConnAttempts; unsigned long tcpConnOpened; unsigned long tcpConnAccepted; unsigned long tcpConnClosed; unsigned long tcpConnAborted; unsigned long tcpOctetsIn; unsigned long tcpOctetsOut; unsigned long tcpOctetsInDup; unsigned long tcpOctetsRetrans; unsigned long tcpInputPkts; unsigned long tcpOutputPkts; unsigned long tcpDupPkts; unsigned long tcpRetransPkts; }; typedef struct TCPStats TCPStats; typedef StreamPtr *StreamPPtr; struct TCPGlobalInfoPB { struct TCPParam *tcpParamPtr; struct TCPStats *tcpStatsPtr; StreamPPtr tcpCDBTable[1]; Ptr userDataPtr; unsigned short maxTCPConnections; }; typedef struct TCPGlobalInfoPB TCPGlobalInfoPB; typedef void (*TCPIOCompletionProcPtr)(struct TCPiopb *iopb); #if GENERATINGCFM typedef UniversalProcPtr TCPIOCompletionUPP; #else typedef TCPIOCompletionProcPtr TCPIOCompletionUPP; #endif struct TCPiopb { SInt8 fill12[12]; TCPIOCompletionUPP ioCompletion; short ioResult; Ptr ioNamePtr; short ioVRefNum; short ioCRefNum; short csCode; StreamPtr tcpStream; union { struct TCPCreatePB create; struct TCPOpenPB open; struct TCPSendPB send; struct TCPReceivePB receive; struct TCPClosePB close; struct TCPAbortPB abort; struct TCPStatusPB status; struct TCPGlobalInfoPB globalInfo; } csParam; }; typedef struct TCPiopb TCPiopb; enum { UDPCreate = 20, UDPRead = 21, UDPBfrReturn = 22, UDPWrite = 23, UDPRelease = 24, UDPMaxMTUSize = 25, UDPStatus = 26, UDPMultiCreate = 27, UDPMultiSend = 28, UDPMultiRead = 29, UDPCtlMax = 29 }; enum { UDPDataArrival = 1, UDPICMPReceived = 2, lastUDPEvent = 32767 }; typedef unsigned short UDPEventCode; typedef pascal void (*UDPNotifyProcPtr)(StreamPtr udpStream, unsigned short eventCode, Ptr userDataPtr, struct ICMPReport *icmpMsg); #if GENERATINGCFM typedef UniversalProcPtr UDPNotifyUPP; #else typedef UDPNotifyProcPtr UDPNotifyUPP; #endif typedef unsigned short udp_port; /* for create and release calls */ struct UDPCreatePB { Ptr rcvBuff; unsigned long rcvBuffLen; UDPNotifyUPP notifyProc; unsigned short localPort; Ptr userDataPtr; udp_port endingPort; }; typedef struct UDPCreatePB UDPCreatePB; struct UDPSendPB { unsigned short reserved; ip_addr remoteHost; udp_port remotePort; Ptr wdsPtr; Boolean checkSum; SInt8 filler; /* Filler for proper byte alignment */ unsigned short sendLength; Ptr userDataPtr; udp_port localPort; }; typedef struct UDPSendPB UDPSendPB; /* for receive and buffer return calls */ struct UDPReceivePB { unsigned short timeOut; ip_addr remoteHost; udp_port remotePort; Ptr rcvBuff; unsigned short rcvBuffLen; unsigned short secondTimeStamp; Ptr userDataPtr; ip_addr destHost; /* only for use with multi rcv */ udp_port destPort; /* only for use with multi rcv */ }; typedef struct UDPReceivePB UDPReceivePB; struct UDPMTUPB { unsigned short mtuSize; ip_addr remoteHost; Ptr userDataPtr; }; typedef struct UDPMTUPB UDPMTUPB; typedef void (*UDPIOCompletionProcPtr)(struct UDPiopb *iopb); #if GENERATINGCFM typedef UniversalProcPtr UDPIOCompletionUPP; #else typedef UDPIOCompletionProcPtr UDPIOCompletionUPP; #endif struct UDPiopb { SInt8 fill12[12]; UDPIOCompletionUPP ioCompletion; short ioResult; Ptr ioNamePtr; short ioVRefNum; short ioCRefNum; short csCode; StreamPtr udpStream; union { struct UDPCreatePB create; struct UDPSendPB send; struct UDPReceivePB receive; struct UDPMTUPB mtu; } csParam; }; typedef struct UDPiopb UDPiopb; #if GENERATINGCFM #else #endif enum { uppGetIPIOCompletionProcInfo = kCStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct GetAddrParamBlock*))), uppIPIOCompletionProcInfo = kCStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct ICMPParamBlock*))), uppICMPEchoNotifyProcInfo = kPascalStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct ICMPParamBlock*))), uppTCPNotifyProcInfo = kPascalStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(StreamPtr))) | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(unsigned short))) | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Ptr))) | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(unsigned short))) | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(struct ICMPReport*))), uppTCPIOCompletionProcInfo = kCStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct TCPiopb*))), uppUDPNotifyProcInfo = kPascalStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(StreamPtr))) | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(unsigned short))) | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Ptr))) | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(struct ICMPReport*))), uppUDPIOCompletionProcInfo = kCStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct UDPiopb*))) }; #if GENERATINGCFM #define NewGetIPIOCompletionProc(userRoutine) \ (GetIPIOCompletionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppGetIPIOCompletionProcInfo, GetCurrentArchitecture()) #define NewIPIOCompletionProc(userRoutine) \ (IPIOCompletionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppIPIOCompletionProcInfo, GetCurrentArchitecture()) #define NewICMPEchoNotifyProc(userRoutine) \ (ICMPEchoNotifyUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppICMPEchoNotifyProcInfo, GetCurrentArchitecture()) #define NewTCPNotifyProc(userRoutine) \ (TCPNotifyUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppTCPNotifyProcInfo, GetCurrentArchitecture()) #define NewTCPIOCompletionProc(userRoutine) \ (TCPIOCompletionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppTCPIOCompletionProcInfo, GetCurrentArchitecture()) #define NewUDPNotifyProc(userRoutine) \ (UDPNotifyUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppUDPNotifyProcInfo, GetCurrentArchitecture()) #define NewUDPIOCompletionProc(userRoutine) \ (UDPIOCompletionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppUDPIOCompletionProcInfo, GetCurrentArchitecture()) #else #define NewGetIPIOCompletionProc(userRoutine) \ ((GetIPIOCompletionUPP) (userRoutine)) #define NewIPIOCompletionProc(userRoutine) \ ((IPIOCompletionUPP) (userRoutine)) #define NewICMPEchoNotifyProc(userRoutine) \ ((ICMPEchoNotifyUPP) (userRoutine)) #define NewTCPNotifyProc(userRoutine) \ ((TCPNotifyUPP) (userRoutine)) #define NewTCPIOCompletionProc(userRoutine) \ ((TCPIOCompletionUPP) (userRoutine)) #define NewUDPNotifyProc(userRoutine) \ ((UDPNotifyUPP) (userRoutine)) #define NewUDPIOCompletionProc(userRoutine) \ ((UDPIOCompletionUPP) (userRoutine)) #endif #if GENERATINGCFM #define CallGetIPIOCompletionProc(userRoutine, iopb) \ CallUniversalProc((UniversalProcPtr)(userRoutine), uppGetIPIOCompletionProcInfo, (iopb)) #define CallIPIOCompletionProc(userRoutine, iopb) \ CallUniversalProc((UniversalProcPtr)(userRoutine), uppIPIOCompletionProcInfo, (iopb)) #define CallICMPEchoNotifyProc(userRoutine, iopb) \ CallUniversalProc((UniversalProcPtr)(userRoutine), uppICMPEchoNotifyProcInfo, (iopb)) #define CallTCPNotifyProc(userRoutine, tcpStream, eventCode, userDataPtr, terminReason, icmpMsg) \ CallUniversalProc((UniversalProcPtr)(userRoutine), uppTCPNotifyProcInfo, (tcpStream), (eventCode), (userDataPtr), (terminReason), (icmpMsg)) #define CallTCPIOCompletionProc(userRoutine, iopb) \ CallUniversalProc((UniversalProcPtr)(userRoutine), uppTCPIOCompletionProcInfo, (iopb)) #define CallUDPNotifyProc(userRoutine, udpStream, eventCode, userDataPtr, icmpMsg) \ CallUniversalProc((UniversalProcPtr)(userRoutine), uppUDPNotifyProcInfo, (udpStream), (eventCode), (userDataPtr), (icmpMsg)) #define CallUDPIOCompletionProc(userRoutine, iopb) \ CallUniversalProc((UniversalProcPtr)(userRoutine), uppUDPIOCompletionProcInfo, (iopb)) #else #define CallGetIPIOCompletionProc(userRoutine, iopb) \ (*(userRoutine))((iopb)) #define CallIPIOCompletionProc(userRoutine, iopb) \ (*(userRoutine))((iopb)) #define CallICMPEchoNotifyProc(userRoutine, iopb) \ (*(userRoutine))((iopb)) #define CallTCPNotifyProc(userRoutine, tcpStream, eventCode, userDataPtr, terminReason, icmpMsg) \ (*(userRoutine))((tcpStream), (eventCode), (userDataPtr), (terminReason), (icmpMsg)) #define CallTCPIOCompletionProc(userRoutine, iopb) \ (*(userRoutine))((iopb)) #define CallUDPNotifyProc(userRoutine, udpStream, eventCode, userDataPtr, icmpMsg) \ (*(userRoutine))((udpStream), (eventCode), (userDataPtr), (icmpMsg)) #define CallUDPIOCompletionProc(userRoutine, iopb) \ (*(userRoutine))((iopb)) #endif #if PRAGMA_IMPORT_SUPPORTED #pragma import off #endif #if PRAGMA_ALIGN_SUPPORTED #pragma options align=reset #endif #ifdef __cplusplus } #endif #endif /* __MACTCP__ */ \ No newline at end of file diff --git a/mac-cpp-source/libs/compat.h b/mac-cpp-source/libs/compat.h index bfd04b0..0774725 100644 --- a/mac-cpp-source/libs/compat.h +++ b/mac-cpp-source/libs/compat.h @@ -1,54 +1 @@ -#ifndef _COMPAT_ -#define _COMPAT_ - -/* compiler ifdef things */ - -#ifdef THINK_C - -#ifndef nil -#define nil 0L -#endif - -#define CR '\r' -#define LF '\n' -#define CRSTR "\r" -#define LFSTR "\n" -#define CRLF "\r\n" -#define QDARROW arrow -#define QDTHEPORT thePort -#define QDSCREENBITS screenBits -#define QDBLACK black -#define QDDKGRAY dkGray -#define okButton OK -#define cancelButton Cancel -/*#define c2pstr CtoPstr -#define p2cstr PtoCstr*/ - -#define PROTOS - -#else - -#define PROTOS - -#define CR '\n' -#define LF '\r' -#define CRSTR "\n" -#define LFSTR "\r" -#define CRLF "\n\r" -#define QDARROW qd.arrow -#define QDTHEPORT qd.thePort -#define QDSCREENBITS qd.screenBits -#define QDBLACK qd.black -#define QDDKGRAY qd.dkGray -#define okButton ok -#define cancelButton cancel - -#endif - -typedef unsigned char UInt8; -typedef unsigned short UInt16; -typedef unsigned long UInt32; -typedef signed char SInt8; -typedef unsigned char byte; - -#endif +#ifndef _COMPAT_ #define _COMPAT_ /* compiler ifdef things */ #ifdef THINK_C #ifndef nil #define nil 0L #endif #define CR '\r' #define LF '\n' #define CRSTR "\r" #define LFSTR "\n" #define CRLF "\r\n" #define QDARROW arrow #define QDTHEPORT thePort #define QDSCREENBITS screenBits #define QDBLACK black #define QDDKGRAY dkGray #define okButton OK #define cancelButton Cancel /*#define c2pstr CtoPstr #define p2cstr PtoCstr*/ #define PROTOS #else #define PROTOS #define CR '\n' #define LF '\r' #define CRSTR "\n" #define LFSTR "\r" #define CRLF "\n\r" #define QDARROW qd.arrow #define QDTHEPORT qd.thePort #define QDSCREENBITS qd.screenBits #define QDBLACK qd.black #define QDDKGRAY qd.dkGray #define okButton ok #define cancelButton cancel #endif typedef unsigned char UInt8; typedef unsigned short UInt16; typedef unsigned long UInt32; typedef signed char SInt8; typedef unsigned char byte; #endif \ No newline at end of file diff --git a/mac-cpp-source/main.cpp b/mac-cpp-source/main.cpp index f1238c3..cc4755e 100644 --- a/mac-cpp-source/main.cpp +++ b/mac-cpp-source/main.cpp @@ -29,9 +29,16 @@ #include "VNCScreenHash.h" #include "VNCFrameBuffer.h" #include "OSUtilities.h" +#include "GestaltUtils.h" #include +enum { + mApple = 1, + mFile = 2, + mEdit = 3 +}; + enum { iQuit = 1, iStart = 2, @@ -47,7 +54,12 @@ DialogPtr gDialog; void ShowStatus(const char* format, ...); void SetDialogTitle(const char* format, ...); Boolean DoEvent(EventRecord *event); +Boolean DoMenuSelection(long choice); ControlHandle FindCHndl(int item, short *type = NULL); +OSErr StartServer(); +Boolean RunningAtStartup(); +void SetUpMenus(); +int ShowAlert(unsigned long type, short id, const char* format, ...); main() { #ifndef USE_STDOUT @@ -61,13 +73,10 @@ main() { InitCursor(); #endif + SetUpMenus(); + /* Create the new dialog */ gDialog = GetNewDialog(128, NULL, (WindowPtr) -1); - #if defined(VNC_FB_MONOCHROME) - SetDialogTitle("%s (B&W)", __DATE__); - #else - SetDialogTitle("%s (Pack %d)", __DATE__, COMPRESSION_LEVEL); - #endif if(VNCFrameBuffer::checkScreenResolution()) ShowStatus("Click \"Start Server\" to begin."); @@ -76,6 +85,13 @@ main() { SetControlValue(FindCHndl(iIncremental), allowIncremental); SetControlValue(FindCHndl(iControl), allowControl); + #ifdef VNC_HEADLESS_MODE + SetDialogTitle("GitHub Sponsor Edition"); + if(RunningAtStartup()) { + StartServer(); + } + #endif + /* Run the event loop */ while (!gCancel || !vncServerStopped()) { EventRecord event; @@ -87,8 +103,14 @@ main() { switch(vncServerError()) { case connectionClosing: case connectionTerminated: - vncServerStop(); - vncServerStart(); + #ifdef VNC_HEADLESS_MODE + vncServerStop(); + vncServerStart(); + #else + vncServerStop(); + HiliteControl(FindCHndl(iStart), 0); + ShowStatus("Connection closed"); + #endif break; case noErr: VNCFrameBuffer::copy(); @@ -103,7 +125,9 @@ main() { DisposeDialog(gDialog); gDialog = NULL; - Alert(129, NULL); // Sponsorship dialog box + #ifndef VNC_HEADLESS_MODE + Alert(129, NULL); // Sponsorship dialog box + #endif return 0; } @@ -140,6 +164,9 @@ Boolean DoEvent(EventRecord *event) { vncServerStop(); gCancel = true; break; + case inMenuBar: + DoMenuSelection(MenuSelect(event->where)); + break; case inContent: if (window != FrontWindow()) { SelectWindow(window); @@ -164,12 +191,7 @@ Boolean DoEvent(EventRecord *event) { } switch (itemHit) { case iStart: - err = vncServerStart(); - if(err == noErr) { - HiliteControl(FindCHndl(itemHit), 255); - } else { - ShowStatus("Error starting server %d.", err); - } + StartServer(); break; case iGraphics: sendGraphics = value; @@ -190,6 +212,60 @@ Boolean DoEvent(EventRecord *event) { return(gCancel || stop); } +void SetUpMenus() { + Handle ourMenu = GetNewMBar(128); + SetMenuBar( ourMenu ); + DrawMenuBar(); + AppendResMenu( GetMenuHandle( mApple ), 'DRVR' ); +} + +Boolean DoMenuSelection(long choice) { + Str255 daName; + Boolean handled = false; + const int menuId = HiWord(choice); + const int itemNum = LoWord(choice); + switch(menuId) { + case mApple: + switch( itemNum ) { + case 1: + ShowAlert(0, 130, + #if defined(VNC_FB_MONOCHROME) + "B&W for Compact Macs (%s)", __DATE__ + #else + "Color Packing %d (%s)", VNC_COMPRESSION_LEVEL, __DATE__ + #endif + + ); + break; + default: + GetMenuItemText( GetMenuHandle( mApple ), itemNum, daName ); + OpenDeskAcc( daName ); + break; + } + break; + case mFile: // File menu + if (itemNum == 1) { // Quit + vncServerStop(); + gCancel = true; + } + break; + case mEdit: // Edit menu + break; + } + HiliteMenu(0); + return handled; +} + +OSErr StartServer() { + OSErr err = vncServerStart(); + if(err == noErr) { + HiliteControl(FindCHndl(iStart), 255); + } else { + ShowStatus("Error starting server %d.", err); + } + return err; +} + ControlHandle FindCHndl(int item, short *type) { short tmp, value; Rect rect; @@ -219,3 +295,57 @@ void SetDialogTitle(const char* format, ...) { pStr[0] = pStr[len] == '\n' ? len - 1 : len; SetWTitle(gDialog, pStr); } + +int ShowAlert(unsigned long type, short id, const char* format, ...) { + Str255 pStr; + va_list argptr; + va_start(argptr, format); + vsprintf((char*)pStr + 1, format, argptr); + va_end(argptr); + pStr[0] = strlen((char*)pStr + 1); + ParamText(pStr, "\p", "\p", "\p"); + switch(type) { + case 'ERR': return StopAlert(id, NULL); + case 'YN': return NoteAlert(id, NULL); + default: return Alert(id, NULL); + } + return 0; +} + +#ifdef VNC_HEADLESS_MODE + /** + * Determines whether we are in the "Startup Items" folder. + */ + Boolean RunningAtStartup() { + OSErr err; + short parentVRefNum, startupVRefNum; + long parentDirID, startupDirID; + + if (GestaltTestAttr( gestaltFindFolderAttr, gestaltFindFolderPresent)) { + /* Obtain file handle to my application's resource file */ + const short myRes = CurResFile(); + + /* Find my parent directory */ + FCBPBRec param; + param.ioCompletion = NULL; + param.ioNamePtr = NULL; + param.ioVRefNum = 0; + param.ioRefNum = myRes; + param.ioFCBIndx = 0; + + OSErr err = PBGetFCBInfo( ¶m, FALSE ); + const short parentVRefNum = param.ioFCBVRefNum; + const long parentDirID = param.ioFCBParID; + + /* Determine whether we are in the "Startup Items" folder */ + err = FindFolder( kOnSystemDisk, kStartupFolderType, kDontCreateFolder, + &startupVRefNum, &startupDirID ); + + if (err != noErr) return false; + + return startupVRefNum == parentVRefNum && + startupDirID == startupDirID; + } + return false; + } +#endif \ No newline at end of file