Moving the tests.....still more....
authorSteven Edwards <winehacker@gmail.com>
Thu, 21 Oct 2004 04:59:01 +0000 (04:59 +0000)
committerSteven Edwards <winehacker@gmail.com>
Thu, 21 Oct 2004 04:59:01 +0000 (04:59 +0000)
svn path=/trunk/; revision=11362

91 files changed:
rosapps/tests/icontest/.cvsignore [new file with mode: 0644]
rosapps/tests/icontest/icon.ico [new file with mode: 0644]
rosapps/tests/icontest/icontest.c [new file with mode: 0644]
rosapps/tests/icontest/icontest.rc [new file with mode: 0644]
rosapps/tests/icontest/makefile [new file with mode: 0644]
rosapps/tests/icontest/resource.h [new file with mode: 0644]
rosapps/tests/iptest/.cvsignore [new file with mode: 0644]
rosapps/tests/iptest/iptest.cpp [new file with mode: 0644]
rosapps/tests/iptest/makefile [new file with mode: 0644]
rosapps/tests/isotest/.cvsignore [new file with mode: 0644]
rosapps/tests/isotest/isotest.c [new file with mode: 0644]
rosapps/tests/isotest/makefile [new file with mode: 0644]
rosapps/tests/lan/lantest.cpp [new file with mode: 0644]
rosapps/tests/lan/makefile [new file with mode: 0644]
rosapps/tests/lineclip/.cvsignore [new file with mode: 0644]
rosapps/tests/lineclip/lineclip.c [new file with mode: 0644]
rosapps/tests/lineclip/makefile [new file with mode: 0644]
rosapps/tests/linetest/.cvsignore [new file with mode: 0644]
rosapps/tests/linetest/linetest.c [new file with mode: 0644]
rosapps/tests/linetest/makefile [new file with mode: 0644]
rosapps/tests/lpc/.cvsignore [new file with mode: 0644]
rosapps/tests/lpc/conport.c [new file with mode: 0644]
rosapps/tests/lpc/creport.c [new file with mode: 0644]
rosapps/tests/lpc/dumpinfo.c [new file with mode: 0644]
rosapps/tests/lpc/dumpinfo.h [new file with mode: 0644]
rosapps/tests/lpc/lpcclt.c [new file with mode: 0644]
rosapps/tests/lpc/lpcsrv.c [new file with mode: 0644]
rosapps/tests/lpc/lpctest.h [new file with mode: 0644]
rosapps/tests/lpc/makefile [new file with mode: 0644]
rosapps/tests/map_dup_inherit/.cvsignore [new file with mode: 0644]
rosapps/tests/map_dup_inherit/makefile [new file with mode: 0644]
rosapps/tests/map_dup_inherit/map_dup_inherit.c [new file with mode: 0644]
rosapps/tests/mdi/.cvsignore [new file with mode: 0644]
rosapps/tests/mdi/makefile [new file with mode: 0644]
rosapps/tests/mdi/mdi.c [new file with mode: 0644]
rosapps/tests/mdi/mdi.rc [new file with mode: 0644]
rosapps/tests/mdi/resource.h [new file with mode: 0644]
rosapps/tests/miditest/.cvsignore [new file with mode: 0644]
rosapps/tests/miditest/makefile [new file with mode: 0644]
rosapps/tests/miditest/miditest.c [new file with mode: 0644]
rosapps/tests/miditest/miditest.rc [new file with mode: 0644]
rosapps/tests/moztest/.cvsignore [new file with mode: 0644]
rosapps/tests/moztest/makefile [new file with mode: 0644]
rosapps/tests/moztest/moztest.c [new file with mode: 0644]
rosapps/tests/mstest/.cvsignore [new file with mode: 0644]
rosapps/tests/mstest/Makefile [new file with mode: 0644]
rosapps/tests/mstest/msclient.c [new file with mode: 0644]
rosapps/tests/mstest/msserver.c [new file with mode: 0644]
rosapps/tests/multithrdwin/.cvsignore [new file with mode: 0644]
rosapps/tests/multithrdwin/makefile [new file with mode: 0644]
rosapps/tests/multithrdwin/multithrdwin.c [new file with mode: 0644]
rosapps/tests/multiwin/.cvsignore [new file with mode: 0644]
rosapps/tests/multiwin/makefile [new file with mode: 0644]
rosapps/tests/multiwin/multiwin.c [new file with mode: 0644]
rosapps/tests/mutex/.cvsignore [new file with mode: 0644]
rosapps/tests/mutex/makefile [new file with mode: 0644]
rosapps/tests/mutex/mutex.c [new file with mode: 0644]
rosapps/tests/nameserverlist/.cvsignore [new file with mode: 0644]
rosapps/tests/nameserverlist/makefile [new file with mode: 0644]
rosapps/tests/nameserverlist/nameserverlist.c [new file with mode: 0644]
rosapps/tests/noexecute/.cvsignore [new file with mode: 0644]
rosapps/tests/noexecute/makefile [new file with mode: 0644]
rosapps/tests/noexecute/noexecute.c [new file with mode: 0644]
rosapps/tests/nptest/.cvsignore [new file with mode: 0644]
rosapps/tests/nptest/Makefile [new file with mode: 0644]
rosapps/tests/nptest/npclient.c [new file with mode: 0644]
rosapps/tests/nptest/npserver.c [new file with mode: 0644]
rosapps/tests/oskittcp/.cvsignore [new file with mode: 0644]
rosapps/tests/oskittcp/cmd_oskit.py [new file with mode: 0644]
rosapps/tests/oskittcp/makefile [new file with mode: 0644]
rosapps/tests/oskittcp/tcptest.cpp [new file with mode: 0644]
rosapps/tests/oskittcp/tcptest.dsp [new file with mode: 0644]
rosapps/tests/oskittcp/tcptest.dsw [new file with mode: 0644]
rosapps/tests/p_dup_handle/.cvsignore [new file with mode: 0644]
rosapps/tests/p_dup_handle/makefile [new file with mode: 0644]
rosapps/tests/p_dup_handle/p_dup_handle.c [new file with mode: 0644]
rosapps/tests/palbitblt/.cvsignore [new file with mode: 0644]
rosapps/tests/palbitblt/makefile [new file with mode: 0644]
rosapps/tests/palbitblt/pal.c [new file with mode: 0644]
rosapps/tests/regdump/.cvsignore [new file with mode: 0644]
rosapps/tests/regdump/main.c [new file with mode: 0644]
rosapps/tests/regdump/makefile [new file with mode: 0644]
rosapps/tests/regdump/regcmds.c [new file with mode: 0644]
rosapps/tests/regdump/regdump.c [new file with mode: 0644]
rosapps/tests/regdump/regdump.h [new file with mode: 0644]
rosapps/tests/regdump/regproc.c [new file with mode: 0644]
rosapps/tests/regdump/regproc.h [new file with mode: 0644]
rosapps/tests/shm/.cvsignore [new file with mode: 0644]
rosapps/tests/shm/makefile [new file with mode: 0644]
rosapps/tests/shm/shmclt.c [new file with mode: 0644]
rosapps/tests/shm/shmsrv.c [new file with mode: 0644]

diff --git a/rosapps/tests/icontest/.cvsignore b/rosapps/tests/icontest/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/icontest/icon.ico b/rosapps/tests/icontest/icon.ico
new file mode 100644 (file)
index 0000000..746b9be
Binary files /dev/null and b/rosapps/tests/icontest/icon.ico differ
diff --git a/rosapps/tests/icontest/icontest.c b/rosapps/tests/icontest/icontest.c
new file mode 100644 (file)
index 0000000..e93adcf
--- /dev/null
@@ -0,0 +1,216 @@
+#include <windows.h>
+#include "resource.h"
+#include <string.h>
+#include <stdio.h>
+
+#ifndef GetCursorInfo
+  #define _GetCursorInfo
+#endif
+
+const char titleDrwIco[] = "DrawIcon Output";
+const char titleMask[] = "Mask(AND image)";
+const char titleXor[] = "XOR(color image)";
+const char file[] = "Icon from file:";
+const char res[] = "Icon from Resorce:";
+const char cursor[] = "Current Cursor:";
+const char cursormask[] = "Cursor Mask Bitmap";
+const char cursorcolor[] = "Cursor Color Bitmap";
+
+#ifdef _GetCursorInfo
+typedef BOOL (__stdcall *GETCURSORINFO) (CURSORINFO *CursorInfo);
+
+static GETCURSORINFO GetCursorInfo = NULL;
+#endif
+
+HFONT tf;
+HINSTANCE hInst;
+
+LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
+
+int WINAPI 
+WinMain(HINSTANCE hInstance,
+    HINSTANCE hPrevInstance,
+    LPSTR lpszCmdLine,
+    int nCmdShow)
+{
+  WNDCLASS wc;
+  MSG msg;
+  HWND hWnd;
+
+  hInst = hInstance;
+  
+  #ifdef _GetCursorInfo
+  GetCursorInfo = (GETCURSORINFO)GetProcAddress(GetModuleHandleW(L"user32.dll"), "GetCursorInfo");
+  #endif
+
+  wc.lpszClassName = "IconTestClass";
+  wc.lpfnWndProc = MainWndProc;
+  wc.style = CS_VREDRAW | CS_HREDRAW;
+  wc.hInstance = hInstance;
+  wc.hIcon = LoadIcon(NULL, (LPCTSTR)IDI_APPLICATION);
+  wc.hCursor = LoadCursor(NULL, (LPCTSTR)IDC_ARROW);
+  wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
+  wc.lpszMenuName = NULL;
+  wc.cbClsExtra = 0;
+  wc.cbWndExtra = 0;
+  if (RegisterClass(&wc) == 0)
+  {
+    DbgPrint("RegisterClass failed (last error 0x%X)\n", GetLastError());
+    return(1);
+  }
+
+  hWnd = CreateWindow("IconTestClass",
+              "Icon Test",
+              WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
+              CW_USEDEFAULT,
+              CW_USEDEFAULT,
+              480,
+              480,
+              NULL,
+              NULL,
+              hInstance,
+              NULL);
+  if (hWnd == NULL)
+  {
+    DbgPrint("CreateWindow failed (last error 0x%X)\n", GetLastError());
+    return(1);
+  }
+    
+  tf = CreateFontA(14,0, 0, TA_BASELINE, FW_NORMAL, FALSE, FALSE, FALSE,
+                   ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
+                   DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "Timmons");
+
+  ShowWindow(hWnd, nCmdShow);
+  
+  SetTimer(hWnd, 1, 1000, NULL);
+
+  while(GetMessage(&msg, NULL, 0, 0))
+  {
+    TranslateMessage(&msg);
+    DispatchMessage(&msg);
+  }
+
+  return msg.wParam;
+}
+
+LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+    PAINTSTRUCT ps;
+    HDC hDC;
+    HICON hIcon;
+    HGDIOBJ hOld;
+    HDC hMemDC;
+    CURSORINFO cursorinfo;
+    ICONINFO iconinfo;
+    BITMAP bmp;
+    RECT rc;
+    CHAR str[20];
+        
+    switch(msg)
+    {
+    case WM_PAINT:
+      hDC = BeginPaint(hWnd, &ps);
+      SelectObject(hDC, tf);
+      SetBkMode(hDC, TRANSPARENT);
+      
+      TextOut(hDC, 160, 10, file, strlen(file));
+      TextOut(hDC, 15, 85, titleDrwIco, strlen(titleDrwIco));
+      TextOut(hDC, 160, 85, titleMask, strlen(titleMask));
+      TextOut(hDC, 300, 85, titleXor, strlen(titleXor));
+      
+      hIcon = LoadImage(NULL, "icon.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE|LR_LOADFROMFILE);
+      DrawIcon(hDC,50,50,hIcon);
+
+      hMemDC = CreateCompatibleDC(hDC);
+      GetIconInfo(hIcon, &iconinfo);
+      DestroyIcon(hIcon);
+
+      hOld = SelectObject(hMemDC, iconinfo.hbmMask);
+      BitBlt(hDC, 200, 50, 32, 32, hMemDC, 0, 0, SRCCOPY);
+      SelectObject(hMemDC, iconinfo.hbmColor);
+      BitBlt(hDC, 350, 50, 32, 32, hMemDC, 0, 0, SRCCOPY);
+
+      DeleteObject(iconinfo.hbmMask);
+      DeleteObject(iconinfo.hbmColor);
+      
+      TextOut(hDC, 145, 150, res, strlen(res));
+      TextOut(hDC, 15, 225, titleDrwIco, strlen(titleDrwIco));
+      TextOut(hDC, 160, 225, titleMask, strlen(titleMask));
+      TextOut(hDC, 300, 225, titleXor, strlen(titleXor));
+          
+      hIcon = LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);          
+      DrawIcon(hDC,50,190,hIcon);
+          
+      GetIconInfo(hIcon, &iconinfo);
+      DestroyIcon(hIcon);          
+          
+      SelectObject(hMemDC, iconinfo.hbmMask);
+      BitBlt(hDC, 200, 190, 32, 32, hMemDC, 0, 0, SRCCOPY);
+      SelectObject(hMemDC, iconinfo.hbmColor);
+      BitBlt(hDC, 350, 190, 32, 32, hMemDC, 0, 0, SRCCOPY);
+
+      DeleteObject(iconinfo.hbmMask);
+      DeleteObject(iconinfo.hbmColor);
+      
+      cursorinfo.cbSize = sizeof(CURSORINFO);
+      if(GetCursorInfo(&cursorinfo))
+      {
+        if(cursorinfo.hCursor && cursorinfo.flags)
+        {
+          TextOut(hDC, 160, 290, cursor, strlen(cursor));
+          DrawIcon(hDC, 50, 330, cursorinfo.hCursor);
+          GetIconInfo(cursorinfo.hCursor, &iconinfo);
+          TextOut(hDC, 15, 365, titleDrwIco, strlen(titleDrwIco));
+          
+          sprintf(str, "Hotspot: %ld; %ld", iconinfo.xHotspot, iconinfo.yHotspot);
+          TextOut(hDC, 15, 380, str, strlen(str));
+          
+          if(iconinfo.hbmMask)
+          {
+            GetObjectW(iconinfo.hbmMask, sizeof(BITMAP), &bmp);
+            SelectObject(hMemDC, iconinfo.hbmMask);
+            BitBlt(hDC, 200, 330, bmp.bmWidth, bmp.bmHeight, hMemDC, 0, 0, SRCCOPY);
+            DeleteObject(iconinfo.hbmMask);
+            TextOut(hDC, 160, 365 - 32 + bmp.bmHeight, cursormask, strlen(cursormask));
+            
+            sprintf(str, "%dBPP", bmp.bmBitsPixel);
+            TextOut(hDC, 160, 380 - 32 + bmp.bmHeight, str, strlen(str));
+          }
+          
+          if(iconinfo.hbmColor)
+          {
+            GetObjectW(iconinfo.hbmColor, sizeof(BITMAP), &bmp);
+            SelectObject(hMemDC, iconinfo.hbmColor);
+            BitBlt(hDC, 350, 330, bmp.bmWidth, bmp.bmHeight, hMemDC, 0, 0, SRCCOPY);
+            DeleteObject(iconinfo.hbmColor);
+            TextOut(hDC, 300, 365 - 32 + bmp.bmHeight, cursorcolor, strlen(cursorcolor));
+            
+            sprintf(str, "%dBPP", bmp.bmBitsPixel);
+            TextOut(hDC, 300, 380 - 32 + bmp.bmHeight, str, strlen(str));
+          }
+        }
+      }
+      
+      SelectObject(hMemDC, hOld);
+      
+      DeleteObject(hMemDC);          
+      EndPaint(hWnd, &ps);
+    break;
+    
+    case WM_TIMER:
+      rc.left = 0;
+      rc.top = 330;
+      rc.right = 480;
+      rc.bottom = 480;
+      InvalidateRect(hWnd, &rc, TRUE);
+      break;
+
+    case WM_DESTROY:
+      PostQuitMessage(0);
+    break;
+
+    default:
+      return DefWindowProc(hWnd, msg, wParam, lParam);
+    }
+    return 0;
+}
diff --git a/rosapps/tests/icontest/icontest.rc b/rosapps/tests/icontest/icontest.rc
new file mode 100644 (file)
index 0000000..5003913
--- /dev/null
@@ -0,0 +1,5 @@
+#include <defines.h>
+#include <reactos/resource.h>
+#include "resource.h"
+
+IDI_ICON                ICON    DISCARDABLE     "icon.ico"
diff --git a/rosapps/tests/icontest/makefile b/rosapps/tests/icontest/makefile
new file mode 100644 (file)
index 0000000..ec194bc
--- /dev/null
@@ -0,0 +1,21 @@
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = no
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = windows
+
+TARGET_NAME = icontest
+
+TARGET_SDKLIBS = ntdll.a kernel32.a gdi32.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+TARGET_CFLAGS = -Wall -Werror
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/icontest/resource.h b/rosapps/tests/icontest/resource.h
new file mode 100644 (file)
index 0000000..5d9eb75
--- /dev/null
@@ -0,0 +1 @@
+#define IDI_ICON                        101
diff --git a/rosapps/tests/iptest/.cvsignore b/rosapps/tests/iptest/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/iptest/iptest.cpp b/rosapps/tests/iptest/iptest.cpp
new file mode 100644 (file)
index 0000000..e442060
--- /dev/null
@@ -0,0 +1,476 @@
+#include <iostream>
+#include <list>
+#include <string>
+#include <sstream>
+extern "C" {
+    typedef unsigned short u_short;
+#include <stdio.h>
+#include <windows.h>
+#include <winsock2.h>
+#include <ddk/tdi.h>
+#include <ddk/tdikrnl.h>
+#include <ddk/tdiinfo.h>
+#include <ddk/ndis.h>
+#include <titypes.h>
+#include <ip.h>
+#include <tcp.h>
+#include <receive.h>
+#include <lan.h>
+#include <routines.h>
+};
+
+/* Undis */
+extern "C" VOID ExpInitLookasideLists();
+
+std::list<std::string> output_packets;
+DWORD DebugTraceLevel = 0x7fffffff;
+PVOID GlobalBufferPool, GlobalPacketPool;
+
+#define MAX_DG_SIZE 16384
+
+char hwaddr[6] = { 0x08, 0x00, 0x20, 0x0b, 0xb7, 0xbb };
+
+char hdr[14] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x08, 0x00 };
+
+#define STRINGIFY(x) #x
+
+void display_row( char *data, int off, int len ) {
+    int i;
+
+    printf( "%08x:", off );
+    for( i = off; i < len && i < off + 16; i++ ) {
+       printf( " %02x", data[i] & 0xff );
+    }
+
+    printf( " -- " );
+
+    for( i = off; i < len && i < off + 16; i++ ) {
+       printf( "%c", (data[i] >= ' ') ? data[i] : '.' );
+    }
+
+    printf( "\n" );
+}
+
+void connect_complete( void *context, NTSTATUS status, unsigned long count ) {
+    printf( "Connection: status %x\n", status );
+}
+
+void receive_complete( void *context, NTSTATUS status, unsigned long count ) {
+    printf( "Receive: status %s (bytes %d)\n", status, count );
+    if( !status && count ) {
+       for( int off = 0; off < count; off += 16 ) {
+           display_row( (char *)context, off, count );
+       }
+       printf( "\n" );
+    }
+}
+
+class SocketObject {
+public:
+    virtual ~SocketObject() { }
+    virtual int send( char *buf, int len, int *bytes, 
+                     struct sockaddr_in *si ) = 0;
+    virtual int recv( char *buf, int len, int *bytes,
+                     struct sockaddr_in *si ) = 0;
+};
+
+UINT TdiAddressSizeFromType( UINT AddressType ) {
+    switch( AddressType ) {
+    case TDI_ADDRESS_TYPE_IP:
+       return sizeof(TA_IP_ADDRESS);
+    default:
+       KeBugCheck( 0 );
+    }
+    return 0;
+}
+
+NTSTATUS TdiBuildNullConnectionInfoInPlace
+( PTDI_CONNECTION_INFORMATION ConnInfo,
+  ULONG Type ) 
+/*
+ * FUNCTION: Builds a NULL TDI connection information structure
+ * ARGUMENTS:
+ *     ConnectionInfo = Address of buffer to place connection information
+ *     Type           = TDI style address type (TDI_ADDRESS_TYPE_XXX).
+ * RETURNS:
+ *     Status of operation
+ */
+{
+  ULONG TdiAddressSize;
+  
+  TdiAddressSize = TdiAddressSizeFromType(Type);
+
+  RtlZeroMemory(ConnInfo,
+               sizeof(TDI_CONNECTION_INFORMATION) +
+               TdiAddressSize);
+
+  ConnInfo->OptionsLength = sizeof(ULONG);
+  ConnInfo->RemoteAddressLength = 0;
+  ConnInfo->RemoteAddress = NULL;
+
+  return STATUS_SUCCESS;
+}
+
+NTSTATUS TdiBuildNullConnectionInfo
+( PTDI_CONNECTION_INFORMATION *ConnectionInfo,
+  ULONG Type )
+/*
+ * FUNCTION: Builds a NULL TDI connection information structure
+ * ARGUMENTS:
+ *     ConnectionInfo = Address of buffer pointer to allocate connection 
+ *                      information in
+ *     Type           = TDI style address type (TDI_ADDRESS_TYPE_XXX).
+ * RETURNS:
+ *     Status of operation
+ */
+{
+  PTDI_CONNECTION_INFORMATION ConnInfo;
+  ULONG TdiAddressSize;
+  NTSTATUS Status;
+  
+  TdiAddressSize = TdiAddressSizeFromType(Type);
+
+  ConnInfo = (PTDI_CONNECTION_INFORMATION)
+    ExAllocatePool(NonPagedPool,
+                  sizeof(TDI_CONNECTION_INFORMATION) +
+                  TdiAddressSize);
+  if (!ConnInfo)
+    return STATUS_INSUFFICIENT_RESOURCES;
+
+  Status = TdiBuildNullConnectionInfoInPlace( ConnInfo, Type );
+
+  if (!NT_SUCCESS(Status)) 
+      ExFreePool( ConnInfo );
+  else
+      *ConnectionInfo = ConnInfo;
+
+  ConnInfo->RemoteAddress = (PTA_ADDRESS)&ConnInfo[1];
+  ConnInfo->RemoteAddressLength = TdiAddressSize;
+
+  return Status;
+}
+
+
+UINT TaLengthOfTransportAddress( PTRANSPORT_ADDRESS Addr ) {
+    UINT AddrLen = 2 * sizeof( ULONG ) + Addr->Address[0].AddressLength;
+    printf("AddrLen %x\n", AddrLen);
+    return AddrLen;
+}
+
+NTSTATUS
+TdiBuildConnectionInfoInPlace
+( PTDI_CONNECTION_INFORMATION ConnectionInfo,
+  PTA_ADDRESS Address ) {
+    NTSTATUS Status = STATUS_SUCCESS;
+    
+    RtlCopyMemory( ConnectionInfo->RemoteAddress,
+                  Address, 
+                  ConnectionInfo->RemoteAddressLength );
+    
+    return Status;
+}
+
+NTSTATUS
+TdiBuildConnectionInfo
+( PTDI_CONNECTION_INFORMATION *ConnectionInfo,
+  PTA_ADDRESS Address ) {
+  NTSTATUS Status = TdiBuildNullConnectionInfo( ConnectionInfo,
+                                               Address->AddressType );
+  
+  if( NT_SUCCESS(Status) )
+      TdiBuildConnectionInfoInPlace( *ConnectionInfo, Address );
+  
+  return Status;
+}
+
+class TCPSocketObject : public SocketObject {
+public:
+    TCPSocketObject( std::string host, int port, NTSTATUS *status ) {
+       TA_IP_ADDRESS ConnectTo;
+       PTDI_CONNECTION_INFORMATION ConnInfo;
+
+       ConnectTo.TAAddressCount = 1;
+       ConnectTo.Address[0].AddressLength = sizeof(TDI_ADDRESS_IP);
+       ConnectTo.Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
+       ConnectTo.Address[0].Address[0].sin_port = htons(port);
+       ConnectTo.Address[0].Address[0].in_addr = 0x6a020a0a;
+
+       TdiBuildConnectionInfo( &ConnInfo, (PTA_ADDRESS)&ConnectTo );
+
+       Connection = TCPAllocateConnectionEndpoint( NULL );
+       *status = TCPSocket( Connection, 
+                            AF_INET,
+                            SOCK_STREAM, IPPROTO_TCP );
+       if( !*status ) 
+           *status = TCPConnect( Connection,
+                                 ConnInfo,
+                                 NULL,
+                                 connect_complete,
+                                 NULL );
+    }
+
+    ~TCPSocketObject() {
+       TCPClose( Connection );
+       if( Connection ) TCPFreeConnectionEndpoint( Connection );
+    }
+
+    int send( char *buf, int len, int *bytes, struct sockaddr_in *si ) {
+       NTSTATUS Status = STATUS_UNSUCCESSFUL;
+
+       if( Connection )
+           Status = TCPSendData( Connection, 
+                                 buf,
+                                 len,
+                                 (PULONG)bytes,
+                                 0 );
+       return Status;
+    }
+
+    int recv( char *buf, int len, int *bytes, struct sockaddr_in *si ) {
+       NTSTATUS Status = STATUS_UNSUCCESSFUL;
+
+       if( Connection )
+           Status = TCPSendData( Connection, 
+                                 buf,
+                                 len,
+                                 (PULONG)bytes,
+                                 0 );
+       return Status;
+    }
+
+private:
+    PCONNECTION_ENDPOINT Connection;
+};
+
+VOID SendPacket( PVOID Context, 
+                PNDIS_PACKET NdisPacket, 
+                UINT Offset, 
+                PVOID LinkAddress,
+                USHORT Type ) {
+    PCHAR DataOut;
+    PUCHAR Addr = (PUCHAR)LinkAddress;
+    UINT Size;
+    std::string output_packet;
+
+    printf( "Sending packet: %02x:%02x:%02x:%02x:%02x:%02x\n", 
+           Addr[0], Addr[1], Addr[2], Addr[3], Addr[4], Addr[5] );
+    
+    GetDataPtr( NdisPacket, Offset, &DataOut, &Size );
+    for( int off = 0; off < Size; off += 16 ) {
+       display_row( DataOut, off, Size );
+    }
+    printf( "\n" );
+
+    output_packet += std::string( hwaddr, sizeof(hwaddr) );
+    output_packet += std::string( (char *)LinkAddress, sizeof(hwaddr) );
+    output_packet += (char)(Type >> 8);
+    output_packet += (char)Type;
+    output_packet += std::string( DataOut + Offset, Size - Offset );
+
+    output_packets.push_back( output_packet );
+}
+
+#if 0
+UINT CopyBufferToBufferChain
+( PNDIS_BUFFER DstBuffer, UINT DstOffset, PCHAR SrcData, UINT Length ) {
+    assert( 0 );
+}
+#endif
+
+int main( int argc, char **argv ) {
+    int asock = INVALID_SOCKET, selret, dgrecv, fromsize, err, port = 5001;
+    int bytes, adapter_id, mtu, speed;
+    char datagram[MAX_DG_SIZE];
+    struct fd_set readf;
+    struct timeval tv;
+    struct sockaddr_in addr_from = { AF_INET }, addr_to;
+    std::string word, cmdin, host;
+    std::list<std::string>::iterator i;
+    WSADATA wsadata;
+    NTSTATUS Status;
+    UNICODE_STRING RegistryUnicodePath;
+    PCONNECTION_ENDPOINT Connection;
+    PIP_INTERFACE Interface;
+    IP_PACKET IPPacket;
+    LLIP_BIND_INFO BindInfo;
+    SocketObject *S = NULL;
+
+    RtlInitUnicodeString
+       ( &RegistryUnicodePath, 
+         L"\\SYSTEM\\CurrentControlSet\\Services"
+         L"\\Tcpip" );
+
+    ExpInitLookasideLists();
+
+    WSAStartup( 0x101, &wsadata );
+
+    if( argc > 1 ) port = atoi(argv[1]);
+
+    IPStartup( &RegistryUnicodePath );
+
+    BindInfo.Context = NULL;
+    BindInfo.HeaderSize = sizeof(ETH_HEADER);
+    BindInfo.MTU = 1500; /* MTU for ethernet */
+    BindInfo.Address = (PUCHAR)hwaddr;
+    BindInfo.AddressLength = sizeof(hwaddr);
+    BindInfo.Transmit = SendPacket;
+    
+    IPCreateInterface( &BindInfo );
+
+    asock = socket( AF_INET, SOCK_DGRAM, 0 );
+
+    addr_from.sin_port = htons( port );
+
+    if( bind( asock, (struct sockaddr *)&addr_from, sizeof( addr_from ) ) ) {
+       printf( "Bind error\n" );
+       return 0;
+    }
+    
+    while( true ) {
+       FD_ZERO( &readf );
+       FD_SET( asock, &readf );
+       tv.tv_sec = 0; 
+       tv.tv_usec = 10000;
+       selret = select( asock + 1, &readf, NULL, NULL, &tv );
+       
+       if( FD_ISSET( asock, &readf ) ) {
+           fromsize = sizeof( addr_from );
+           dgrecv = recvfrom( asock, datagram, sizeof(datagram), 0,
+                              (struct sockaddr *)&addr_from, &fromsize );
+           
+           if( datagram[0] == 'C' && datagram[1] == 'M' &&
+               datagram[2] == 'D' && datagram[3] == ' ' ) {
+               int theport, bytes, recvret, off, bytin;
+               struct sockaddr_in nam;
+               std::string faddr, word;
+               std::istringstream 
+                   cmdin( std::string( datagram + 4, dgrecv - 4 ) );
+               
+               cmdin >> word;
+               
+/* UDP Section */
+               if( word == "udpsocket" ) {
+/* TCP Section */              
+               } else if( word == "tcpsocket" ) {
+                   cmdin >> host >> port;
+                   S = new TCPSocketObject( host, port, &Status );
+                   fprintf( stderr, "Socket: Result %x\n", Status );
+               } else if( word == "close" ) {
+                   TCPClose( Connection );
+                   TCPFreeConnectionEndpoint( Connection );
+               } else if( word == "type" ) {
+                   std::string therest = &cmdin.str()[word.size()];
+                   char* p = &therest[0];
+                   p += strspn ( p, " \t" );
+                   char* src = p;
+                   char* dst = p;
+                   while ( *src )
+                   {
+                       char c = *src++;
+                       if ( c == '\r' || c == '\n' ) break;
+                       if ( c == '\\' )
+                       {
+                           c = *src++;
+                           switch ( c )
+                           {
+                           case 'b': c = '\b'; break;
+                           case 'n': c = '\n'; break;
+                           case 'r': c = '\r'; break;
+                           case 't': c = '\t'; break;
+                           case 'v': c = '\v'; break;
+                           }
+                       }
+                       *dst++ = c;
+                   }
+                   *dst = '\0';
+                   if( S ) 
+                       err = S->send( p, strlen(p), &bytes, NULL );
+                   if( err > 0 ) { bytin = err; err = 0; }
+                   
+                   if( err ) 
+                       fprintf ( stderr, "OskitTCPConnect: error %d\n", 
+                                 err );
+                   else {
+                       printf ( "wrote %d bytes\n", bytin );
+                   }               
+               } else if( word == "send" ) {
+                   off = 0;
+                   while( cmdin >> word ) {
+                       datagram[off++] = 
+                           atoi( (std::string("0x") + word).c_str() );
+                   }
+                   
+                   if( (err = S->send( datagram, off, &bytin, NULL )) != 0 ) {
+                       fprintf( stderr, "OskitTCPConnect: error %d\n", err );
+                   } else {
+                       printf( "wrote %d bytes\n", bytin );
+                   }
+               } else if( word == "recv" ) {
+                   cmdin >> bytes;
+                   
+                   if( (err = S->recv( datagram, 
+                                       sizeof(datagram),
+                                       &bytes, 
+                                       NULL )) != 0 ) {
+                       fprintf( stderr, "OskitTCPRecv: error %d\n", err );
+                   }
+                   
+/* Misc section */
+               } else if( word == "end" ) {
+                   return 0;
+               }
+           } else if( dgrecv > 14 ) {
+               addr_to = addr_from;
+               
+               if( datagram[12] == 8 && datagram[13] == 6 ) {
+                   /* Answer arp query */
+                   char laddr[4];
+                   /* Mark patch as to the previous sender */
+                   memcpy( datagram + 32, datagram + 6, 6 );
+                   memcpy( datagram, datagram + 6, 6 );
+                   /* Mark packet as from us */
+                   memcpy( datagram + 22, hwaddr, 6 );
+                   memcpy( datagram + 6, hwaddr, 6 );
+                   /* Swap inet addresses */
+                   memcpy( laddr, datagram + 28, 4 );
+                   memcpy( datagram + 28, datagram + 38, 4 );
+                   memcpy( datagram + 38, laddr, 4 );
+                   /* Set reply opcode */
+                   datagram[21] = 2;
+                   
+                   err = sendto( asock, datagram, dgrecv, 0,
+                                 (struct sockaddr *)&addr_to, 
+                                 sizeof(addr_to) );
+                   
+                   if( err != 0 )
+                       printf( "sendto: %d\n", err );
+               } else {
+                   memcpy( hdr, datagram + 6, 6 );
+                   memcpy( hdr + 6, datagram, 6 );
+                   memcpy( hdr + 12, datagram + 12, 2 );
+                   IPPacket.Header = datagram;
+                   IPPacket.Data = datagram + 14;
+                   IPPacket.TotalSize = dgrecv;
+                   IPReceive( Interface, &IPPacket );
+               }
+           }
+       }
+       
+       IPTimeout(NULL, NULL, NULL, NULL);
+       
+       for( i = output_packets.begin(); i != output_packets.end(); i++ ) {
+           err = sendto( asock, i->c_str(), i->size(), 0, 
+                         (struct sockaddr *)&addr_to, sizeof(addr_to) );
+           
+           fprintf( stderr, "** SENDING PACKET %d bytes **\n", i->size() );
+           
+           if( err != 0 )
+               printf( "sendto: %d\n", err );
+       }
+       
+       output_packets.clear();
+    }
+}
+    
diff --git a/rosapps/tests/iptest/makefile b/rosapps/tests/iptest/makefile
new file mode 100644 (file)
index 0000000..e299bdc
--- /dev/null
@@ -0,0 +1,26 @@
+#
+# $Id: makefile,v 1.1 2004/10/21 04:58:58 sedwards Exp $
+
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = iptest
+
+TARGET_SDKLIBS = ws2_32.a ip.a oskittcp.a undis.a ntdll.a 
+
+TARGET_OBJECTS = iptest.o
+
+TARGET_CPPFLAGS =  -I$(PATH_TO_TOP)/drivers/lib/oskittcp/include -I$(PATH_TO_TOP)/w32api/include -I$(PATH_TO_TOP)/include -I$(PATH_TO_TOP)/drivers/net/tcpip/include -g
+
+TARGET_GCCLIBS = stdc++
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/isotest/.cvsignore b/rosapps/tests/isotest/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/isotest/isotest.c b/rosapps/tests/isotest/isotest.c
new file mode 100644 (file)
index 0000000..27f9aef
--- /dev/null
@@ -0,0 +1,231 @@
+/*
+ * isotest - display cdrom information
+ */
+
+#include <windows.h>
+//#include <winioctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <wchar.h>
+
+
+void HexDump(char *buffer, ULONG size)
+{
+  ULONG offset = 0;
+  unsigned char *ptr;
+
+  while (offset < (size & ~15))
+    {
+      ptr = (unsigned char*)((ULONG)buffer + offset);
+      printf("%08lx  %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx-%02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx",
+            offset,
+            ptr[0],
+            ptr[1],
+            ptr[2],
+            ptr[3],
+            ptr[4],
+            ptr[5],
+            ptr[6],
+            ptr[7],
+            ptr[8],
+            ptr[9],
+            ptr[10],
+            ptr[11],
+            ptr[12],
+            ptr[13],
+            ptr[14],
+            ptr[15]);
+
+      printf("  %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
+            isprint(ptr[0])?ptr[0]:'.',
+            isprint(ptr[1])?ptr[1]:'.',
+            isprint(ptr[2])?ptr[2]:'.',
+            isprint(ptr[3])?ptr[3]:'.',
+            isprint(ptr[4])?ptr[4]:'.',
+            isprint(ptr[5])?ptr[5]:'.',
+            isprint(ptr[6])?ptr[6]:'.',
+            isprint(ptr[7])?ptr[7]:'.',
+            isprint(ptr[8])?ptr[8]:'.',
+            isprint(ptr[9])?ptr[9]:'.',
+            isprint(ptr[10])?ptr[10]:'.',
+            isprint(ptr[11])?ptr[11]:'.',
+            isprint(ptr[12])?ptr[12]:'.',
+            isprint(ptr[13])?ptr[13]:'.',
+            isprint(ptr[14])?ptr[14]:'.',
+            isprint(ptr[15])?ptr[15]:'.');
+
+      offset += 16;
+    }
+
+  ptr = (unsigned char*)((ULONG)buffer + offset);
+  if (offset < size)
+    {
+      printf("%08lx ", offset);
+      while (offset < size)
+       {
+         printf(" %02hx", *ptr);
+         offset++;
+         ptr++;
+       }
+    }
+
+  printf("\n\n");
+}
+
+
+#ifndef EVENT_ALL_ACCESS
+#define EVENT_ALL_ACCESS       (0x1f0003L)
+#endif
+
+BOOL
+ReadBlock(HANDLE FileHandle,
+         PVOID Buffer,
+         PLARGE_INTEGER Offset,
+         ULONG Length,
+         PULONG BytesRead)
+{
+  IO_STATUS_BLOCK IoStatusBlock;
+  OBJECT_ATTRIBUTES ObjectAttributes;
+  NTSTATUS Status;
+  HANDLE EventHandle;
+
+  InitializeObjectAttributes(&ObjectAttributes,
+                            NULL, 0, NULL, NULL);
+
+  Status = NtCreateEvent(&EventHandle,
+                        EVENT_ALL_ACCESS,
+                        &ObjectAttributes,
+                        TRUE,
+                        FALSE);
+  if (!NT_SUCCESS(Status))
+    {
+      printf("NtCreateEvent() failed\n");
+      return(FALSE);
+    }
+
+  Status = NtReadFile(FileHandle,
+                     EventHandle,
+                     NULL,
+                     NULL,
+                     &IoStatusBlock,
+                     Buffer,
+                     Length,
+                     Offset,
+                     NULL);
+  if (Status == STATUS_PENDING)
+    {
+      NtWaitForSingleObject(EventHandle, FALSE, NULL);
+      Status = IoStatusBlock.Status;
+    }
+
+  NtClose(EventHandle);
+
+  if (Status != STATUS_PENDING && BytesRead != NULL)
+    {
+      *BytesRead = IoStatusBlock.Information;
+    }
+  if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE)
+    {
+      printf("ReadBlock() failed (Status: %lx)\n", Status);
+      return(FALSE);
+    }
+
+  return(TRUE);
+}
+
+
+
+int main (int argc, char *argv[])
+{
+  HANDLE hDisk;
+  DWORD dwRead;
+  char *Buffer;
+  CHAR Filename[80];
+  LARGE_INTEGER FilePosition;
+
+  if (argc != 2)
+    {
+      printf("Usage: isotest [Drive:]\n");
+      return 0;
+    }
+
+  strcpy(Filename, "\\\\.\\");
+  strcat(Filename, argv[1]);
+
+  hDisk = CreateFile(Filename,
+                    GENERIC_READ,
+                    FILE_SHARE_READ | FILE_SHARE_WRITE,
+                    NULL,
+                    OPEN_EXISTING,
+                    0,
+                    NULL);
+  if (hDisk == INVALID_HANDLE_VALUE)
+    {
+      printf("CreateFile(): Invalid disk handle!\n");
+      return 0;
+    }
+
+  Buffer = (char*)malloc(2048);
+  if (Buffer == NULL)
+    {
+      CloseHandle(hDisk);
+      printf("Out of memory!\n");
+      return 0;
+    }
+  memset(Buffer, 0, 2048);
+
+
+  FilePosition.QuadPart = 16 * 2048;
+#if 0
+  SetLastError(NO_ERROR);
+  SetFilePointer(hDisk,
+                FilePosition.u.LowPart,
+                &FilePosition.u.HighPart,
+                FILE_BEGIN);
+  if (GetLastError() != NO_ERROR)
+    {
+      CloseHandle(hDisk);
+      free(Buffer);
+      printf("SetFilePointer() failed!\n");
+      return 0;
+    }
+
+  if (ReadFile(hDisk,
+              Buffer,
+              2048,
+              &dwRead,
+              NULL) == FALSE)
+    {
+      CloseHandle(hDisk);
+      free(Buffer);
+      printf("ReadFile() failed!\n");
+      return 0;
+    }
+#endif
+
+  if (ReadBlock(hDisk,
+               Buffer,
+               &FilePosition,
+               2048,
+               &dwRead) == FALSE)
+    {
+      CloseHandle(hDisk);
+      free(Buffer);
+#if 0
+      printf("ReadBlock() failed!\n");
+#endif
+      return 0;
+    }
+
+  HexDump(Buffer, 128);
+
+  CloseHandle(hDisk);
+
+  free(Buffer);
+
+  return 0;
+}
+
+/* EOF */
diff --git a/rosapps/tests/isotest/makefile b/rosapps/tests/isotest/makefile
new file mode 100644 (file)
index 0000000..fe137f8
--- /dev/null
@@ -0,0 +1,25 @@
+# $Id: makefile,v 1.1 2004/10/21 04:58:58 sedwards Exp $
+
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = isotest
+
+#TARGET_CFLAGS = -fnative_struct
+
+TARGET_SDKLIBS = ntdll.a kernel32.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+TARGET_CFLAGS = -Wall -Werror
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/lan/lantest.cpp b/rosapps/tests/lan/lantest.cpp
new file mode 100644 (file)
index 0000000..5a02cc3
--- /dev/null
@@ -0,0 +1,218 @@
+#include <windows.h>
+#include <net/lan.h>
+#include <iostream>
+#include <string>
+#include <ddk/ntddk.h>
+#include <rosrtl/string.h>
+
+using std::string;
+using std::cin;
+using std::cout;
+using std::cerr;
+using std::endl;
+
+void display_row( char *data, int off, int len ) {
+    int i;
+
+    printf( "%08x:", off );
+    for( i = off; i < len && i < off + 16; i++ ) {
+       printf( " %02x", data[i] & 0xff );
+    }
+
+    for( ; i < off + 16; i++ )
+       printf("   ");
+
+    printf( " -- " );
+
+    for( i = off; i < len && i < off + 16; i++ ) {
+       printf( "%c", (data[i] >= ' ' && data[i] <= '~') ? data[i] : '.' );
+    }
+
+    printf( "\n" );
+}
+
+void display_buffer( char *Packet, int ReadLen ) {
+    UINT PktLen;
+    for( PktLen = 0; PktLen < ReadLen; PktLen += 16 )
+       display_row( Packet, PktLen, ReadLen );
+}
+
+int byte_till_end( char *Packet, int PktLen ) {
+    int byte;
+    std::string word;
+
+    cin >> word;
+    while( word != "end" ) {
+       byte = strtoul( (string("0x") + word).c_str(), 0, 0 );
+       fprintf( stderr, "Byte[%d]: %x\n", PktLen, byte & 0xff );
+       Packet[PktLen++] = byte;
+       cin >> word;
+    }
+
+    return PktLen;
+}
+
+/* Ethernet types. We swap constants so we can compare values at runtime
+   without swapping them there */
+#define ETYPE_IPv4 WH2N(0x0800)
+#define ETYPE_IPv6 WH2N(0x86DD)
+#define ETYPE_ARP  WH2N(0x0806)
+
+extern "C"
+NTSTATUS STDCALL NtCreateFile(
+    PHANDLE FileHandle,
+    ACCESS_MASK DesiredAccess,
+    POBJECT_ATTRIBUTES ObjectAttributes,
+    PIO_STATUS_BLOCK IoStatusBlock,
+    PLARGE_INTEGER AllocationSize,
+    ULONG FileAttributes,
+    ULONG ShareAccess,
+    ULONG CreateDisposition,
+    ULONG CreateOptions,
+    PVOID EaBuffer,
+    ULONG EaLength);
+
+int main( int argc, char **argv ) {
+    string word;
+    HANDLE LanFile;
+    OBJECT_ATTRIBUTES Attributes;
+    UNICODE_STRING LanDevice;
+    IO_STATUS_BLOCK Iosb;
+    HANDLE Event;
+    PFILE_FULL_EA_INFORMATION EaBuffer;
+    NTSTATUS Status;
+    DWORD On = 1, PktLen;
+    CHAR Packet[1600];
+    PLAN_PACKET_HEADER Hdr = (PLAN_PACKET_HEADER)Packet;
+    PLAN_ADDRESS Addr = (PLAN_ADDRESS)Packet;
+    USHORT TypesToListen[] = { ETYPE_IPv4, ETYPE_IPv6, ETYPE_ARP };
+    UINT EaLength = LAN_EA_INFO_SIZE(sizeof(TypesToListen)/sizeof(USHORT));
+
+    Status = NtCreateEvent(&Event,
+                          EVENT_ALL_ACCESS,
+                          NULL,
+                          0,
+                          0 );
+    
+    RtlInitUnicodeString( &LanDevice, L"\\Device\\Lan" );
+
+    InitializeObjectAttributes( &Attributes, 
+                               &LanDevice,
+                               OBJ_CASE_INSENSITIVE,
+                               NULL,
+                               NULL );
+
+    EaBuffer = (PFILE_FULL_EA_INFORMATION)calloc( EaLength, 1 );
+    LAN_FILL_EA_INFO(EaBuffer,sizeof(TypesToListen)/sizeof(USHORT),
+                    TypesToListen);
+
+    Status = ZwCreateFile( &LanFile, 
+                          SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE | 
+                          GENERIC_EXECUTE, 
+                          &Attributes,
+                          &Iosb,
+                          NULL,
+                          FILE_ATTRIBUTE_NORMAL,
+                          FILE_SHARE_READ | FILE_SHARE_WRITE,
+                          FILE_OPEN_IF,
+                          FILE_SYNCHRONOUS_IO_NONALERT,
+                          EaBuffer,
+                          EaLength );
+
+    if( !NT_SUCCESS(Status) ) {
+       cerr << "Could not open lan device " << Status << "\n";
+       return 1;
+    }
+    
+    Status = DeviceIoControl( LanFile,
+                             IOCTL_IF_BUFFERED_MODE,
+                             &On,
+                             sizeof(On),
+                             0,
+                             0,
+                             &PktLen,
+                             NULL );
+    
+    if( !Status ) {
+       cerr << "Could not turn on buffered mode " << Status << "\n";
+       return 1;
+    }
+
+    while( cin >> word ) {
+       if( word == "end" ) {
+           NtClose( LanFile );
+           return 0;
+       } else if( word == "enum" ) {
+           Status = DeviceIoControl( LanFile,
+                                     IOCTL_IF_ENUM_ADAPTERS,
+                                     NULL,
+                                     0,
+                                     Packet,
+                                     sizeof(Packet),
+                                     &PktLen,
+                                     NULL );
+
+           cout << "EnumAdapters: " << Status << "\n";
+           if( Status ) 
+               display_buffer( Packet, PktLen );
+       } else if( word == "query" ) {
+           cin >> PktLen;
+
+           Status = DeviceIoControl( LanFile,
+                                     IOCTL_IF_ADAPTER_INFO,
+                                     &PktLen,
+                                     sizeof(PktLen),
+                                     Packet,
+                                     sizeof(Packet),
+                                     &PktLen,
+                                     NULL );
+           
+           cout << "QueryAdapterInfo: " << Status << "\n";
+           if( Status )
+               display_buffer( Packet, PktLen );
+       } else if( word == "send" ) {
+           cin >> Hdr->Fixed.Adapter 
+               >> Hdr->Fixed.AddressType 
+               >> Hdr->Fixed.AddressLen 
+               >> Hdr->Fixed.PacketType;
+           Hdr->Fixed.Mdl = NULL;
+           PktLen = byte_till_end( Packet, Hdr->Address - (PCHAR)Hdr );
+           Status = NtWriteFile( LanFile, 
+                                 NULL,
+                                 NULL,
+                                 NULL,
+                                 &Iosb,
+                                 Packet,
+                                 PktLen,
+                                 NULL,
+                                 NULL );
+
+           cout << "NtWriteFile: " << Status << "\n";
+       } else if( word == "recv" ) {
+           ULONG ReadLen;
+           Status = NtReadFile( LanFile,
+                                Event,
+                                NULL,
+                                NULL,
+                                &Iosb,
+                                Packet,
+                                sizeof(Packet),
+                                NULL,
+                                NULL );
+           cout << "NtReadFile: " << Status << "\n";
+           if( Status == STATUS_PENDING ) {
+               LARGE_INTEGER Timeout = { 0 };
+               Status = NtWaitForSingleObject( Event, 1, &Timeout );
+           } 
+
+           ReadLen = Iosb.Information;
+
+           if( Status == STATUS_SUCCESS ) {
+               cout << "Read " << ReadLen << " bytes\n";
+               display_buffer( Packet, ReadLen );
+           }
+       }
+    }
+
+    return 0;
+}
diff --git a/rosapps/tests/lan/makefile b/rosapps/tests/lan/makefile
new file mode 100644 (file)
index 0000000..0d5f915
--- /dev/null
@@ -0,0 +1,24 @@
+#
+# $Id: makefile,v 1.1 2004/10/21 04:58:58 sedwards Exp $
+
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = lantest
+
+TARGET_SDKLIBS = ws2_32.a ntdll.a
+
+TARGET_OBJECTS = lantest.o -lstdc++
+
+TARGET_CPPFLAGS = -I$(PATH_TO_TOP)/include -g
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/lineclip/.cvsignore b/rosapps/tests/lineclip/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/lineclip/lineclip.c b/rosapps/tests/lineclip/lineclip.c
new file mode 100644 (file)
index 0000000..3fba19c
--- /dev/null
@@ -0,0 +1,166 @@
+#include <windows.h>
+#include <stdio.h>
+
+LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
+
+int WINAPI 
+WinMain(HINSTANCE hInstance,
+       HINSTANCE hPrevInstance,
+       LPSTR lpszCmdLine,
+       int nCmdShow)
+{
+  WNDCLASS wc;
+  MSG msg;
+  HWND hWnd;
+
+  wc.lpszClassName = "ClipClass";
+  wc.lpfnWndProc = MainWndProc;
+  wc.style = CS_VREDRAW | CS_HREDRAW;
+  wc.hInstance = hInstance;
+  wc.hIcon = LoadIcon(NULL, (LPCTSTR)IDI_APPLICATION);
+  wc.hCursor = LoadCursor(NULL, (LPCTSTR)IDC_ARROW);
+  wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
+  wc.lpszMenuName = NULL;
+  wc.cbClsExtra = 0;
+  wc.cbWndExtra = 0;
+  if (RegisterClass(&wc) == 0)
+    {
+      fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n",
+             GetLastError());
+      return(1);
+    }
+
+  hWnd = CreateWindow("ClipClass",
+                     "Line clipping test",
+                     WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
+                     0,
+                     0,
+                     CW_USEDEFAULT,
+                     CW_USEDEFAULT,
+                     NULL,
+                     NULL,
+                     hInstance,
+                     NULL);
+  if (hWnd == NULL)
+    {
+      fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n",
+             GetLastError());
+      return(1);
+    }
+
+  ShowWindow(hWnd, nCmdShow);
+
+  while(GetMessage(&msg, NULL, 0, 0))
+  {
+    TranslateMessage(&msg);
+    DispatchMessage(&msg);
+  }
+
+  return msg.wParam;
+}
+
+static void
+DrawLines(HDC hDC)
+{
+  static struct
+    {
+    int fromx;
+    int fromy;
+    int tox;
+    int toy;
+    }
+  points[ ] =
+    {
+      {  50,  99, 125,  99 },
+      { 160,  99, 190,  99 },
+      { 300,  99, 225,  99 },
+      {  50, 100, 125, 100 },
+      { 160, 100, 190, 100 },
+      { 300, 100, 225, 100 },
+      {  50, 125, 300, 125 },
+      {  50, 149, 125, 149 },
+      { 160, 149, 190, 149 },
+      { 300, 149, 225, 149 },
+      {  50, 150, 125, 150 },
+      { 160, 150, 190, 150 },
+      { 300, 150, 225, 150 },
+      { 160, 249, 190, 249 },
+      { 160, 250, 190, 250 },
+      { 149,  50, 149, 125 },
+      { 149, 160, 149, 190 },
+      { 149, 300, 149, 225 },
+      { 150,  50, 150, 125 },
+      { 150, 160, 150, 190 },
+      { 150, 300, 150, 225 },
+      { 199,  50, 199, 125 },
+      { 199, 160, 199, 190 },
+      { 199, 300, 199, 225 },
+      { 200,  50, 200, 125 },
+      { 200, 160, 200, 190 },
+      { 200, 300, 200, 225 },
+      { 175,  50, 175, 300 },
+      {  50,  55, 300, 290 },
+      { 300, 295,  50,  60 },
+      {  50, 290, 300,  55 },
+      { 300,  60,  50, 295 },
+      {  55,  50, 290, 300 },
+      { 295, 300,  60,  50 },
+      {  55, 300, 290,  50 },
+      { 295,  50,  60, 300 }
+    };
+  int i;
+
+  for (i = 0; i < sizeof(points) / sizeof(points[0]); i++)
+    {
+      MoveToEx(hDC, points[i].fromx, points[i].fromy, NULL);
+      LineTo(hDC, points[i].tox, points[i].toy);
+    }
+}
+
+LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+       PAINTSTRUCT ps;
+       HDC hDC;
+       RECT clr;
+       HRGN ClipRgn, ExcludeRgn;
+       RECT Rect;
+
+       switch(msg)
+       {
+       case WM_PAINT:
+         GetClientRect(hWnd, &clr);
+         ClipRgn = CreateRectRgnIndirect(&clr);
+         hDC = BeginPaint(hWnd, &ps);
+         Rect.left = 100;
+         Rect.top = 100;
+         Rect.right = 250;
+         Rect.bottom = 150;
+         FillRect(hDC, &Rect, CreateSolidBrush(RGB(0xFF, 0x00, 0x00)));
+         ExcludeRgn = CreateRectRgnIndirect(&Rect);
+         CombineRgn(ClipRgn, ClipRgn, ExcludeRgn, RGN_DIFF);
+         DeleteObject(ExcludeRgn);
+         Rect.left = 150;
+         Rect.top = 150;
+         Rect.right = 200;
+         Rect.bottom = 250;
+         FillRect(hDC, &Rect, CreateSolidBrush(RGB(0xFF, 0x00, 0x00)));
+         SelectObject(hDC, CreatePen(PS_SOLID, 0, RGB(0xFF, 0xFF, 0x00)));
+         DrawLines(hDC);
+         SelectObject(hDC, CreatePen(PS_SOLID, 0, RGB(0x00, 0x00, 0xFF)));
+         ExcludeRgn = CreateRectRgnIndirect(&Rect);
+         CombineRgn(ClipRgn, ClipRgn, ExcludeRgn, RGN_DIFF);
+         DeleteObject(ExcludeRgn);
+         SelectClipRgn(hDC, ClipRgn);
+         DrawLines(hDC);
+         EndPaint(hWnd, &ps);
+         break;
+
+       case WM_DESTROY:
+         PostQuitMessage(0);
+         break;
+
+       default:
+         return DefWindowProc(hWnd, msg, wParam, lParam);
+       }
+       return 0;
+}
diff --git a/rosapps/tests/lineclip/makefile b/rosapps/tests/lineclip/makefile
new file mode 100644 (file)
index 0000000..030d48b
--- /dev/null
@@ -0,0 +1,23 @@
+# $Id: makefile,v 1.1 2004/10/21 04:58:58 sedwards Exp $
+
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = windows
+
+TARGET_NAME = lineclip
+
+TARGET_SDKLIBS = kernel32.a gdi32.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+TARGET_CFLAGS = -Wall -Werror
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/linetest/.cvsignore b/rosapps/tests/linetest/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/linetest/linetest.c b/rosapps/tests/linetest/linetest.c
new file mode 100644 (file)
index 0000000..f6da86d
--- /dev/null
@@ -0,0 +1,181 @@
+#include <windows.h>
+#include <stdio.h>
+
+LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
+
+const TCHAR* CLASS_NAME = _T("LineTestClass");
+
+int WINAPI 
+WinMain(HINSTANCE hInstance,
+       HINSTANCE hPrevInstance,
+       LPSTR lpszCmdLine,
+       int nCmdShow)
+{
+  WNDCLASS wc;
+  MSG msg;
+  HWND hWnd;
+
+  wc.lpszClassName = CLASS_NAME;
+  wc.lpfnWndProc = MainWndProc;
+  wc.style = CS_VREDRAW | CS_HREDRAW;
+  wc.hInstance = hInstance;
+  wc.hIcon = LoadIcon(NULL, (LPCSTR)IDI_APPLICATION);
+  wc.hCursor = LoadCursor(NULL, (LPCSTR)IDC_ARROW);
+  wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
+  wc.lpszMenuName = NULL;
+  wc.cbClsExtra = 0;
+  wc.cbWndExtra = 0;
+  if (RegisterClass(&wc) == 0)
+    {
+      fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n",
+             GetLastError());
+      return(1);
+    }
+
+  hWnd = CreateWindow(CLASS_NAME,
+                     _T("Line drawing test"),
+                     WS_OVERLAPPEDWINDOW,
+                     0,
+                     0,
+                     CW_USEDEFAULT,
+                     CW_USEDEFAULT,
+                     NULL,
+                     NULL,
+                     hInstance,
+                     NULL);
+  if (hWnd == NULL)
+    {
+      fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n",
+             GetLastError());
+      return(1);
+    }
+
+  ShowWindow(hWnd, nCmdShow);
+
+  while(GetMessage(&msg, NULL, 0, 0))
+  {
+    TranslateMessage(&msg);
+    DispatchMessage(&msg);
+  }
+
+  return msg.wParam;
+}
+
+#define red RGB(255,0,0)
+#define grn RGB(0,255,0)
+#define blu RGB(0,0,255)
+#define blk RGB(0,0,0)
+
+static void
+DrawLines(HDC hDC)
+{
+  static struct
+    {
+    int fromx;
+    int fromy;
+    int tox;
+    int toy;
+    COLORREF clr;
+    }
+  points[ ] =
+    {
+      { 10, 10, 19, 10, red },
+      { 20, 10, 20, 19, grn },
+      { 20, 20, 11, 20, blu },
+      { 10, 20, 10, 11, blk },
+      { 12, 12, 15, 15, red },
+      { 18, 12, 15, 15, grn },
+      { 18, 18, 15, 15, blu },
+      { 12, 18, 15, 15, blk },
+
+      { 35, 10, 39, 14, red },
+      { 40, 15, 36, 19, grn },
+      { 35, 20, 31, 16, blu },
+      { 30, 15, 34, 11, blk },
+
+      { 2, 1, 5, 2, red },
+      { 6, 2, 5, 5, grn },
+      { 5, 6, 2, 5, blu },
+      { 1, 5, 2, 2, blk },
+
+         { 50,  1, 51,  1, red },
+         { 50,  2, 52,  2, grn },
+         { 50,  3, 53,  3, blu },
+         { 50,  4, 54,  4, blk },
+         { 50,  5, 55,  5, red },
+         { 50,  6, 56,  6, grn },
+         { 50,  7, 57,  7, blu },
+         { 50,  8, 58,  8, blk },
+         { 50,  9, 59,  9, red },
+         { 50, 10, 60, 10, grn },
+         { 50, 11, 61, 11, blu },
+         { 50, 12, 62, 12, blk },
+
+         { 50, 14, 62, 14, red },
+         { 51, 15, 62, 15, grn },
+         { 52, 16, 62, 16, blu },
+         { 53, 17, 62, 17, blk },
+         { 54, 18, 62, 18, red },
+         { 55, 19, 62, 19, grn },
+         { 56, 20, 62, 20, blu },
+         { 57, 21, 62, 21, blk },
+         { 58, 22, 62, 22, red },
+         { 59, 23, 62, 23, grn },
+         { 60, 24, 62, 24, blu },
+         { 61, 25, 62, 25, blk },
+       };
+  int i;
+
+  for (i = 0; i < sizeof(points) / sizeof(points[0]); i++)
+    {
+      HPEN hpen, hpenold;
+      hpen = CreatePen ( PS_SOLID, 0, points[i].clr );
+      hpenold = (HPEN)SelectObject ( hDC, hpen );
+      MoveToEx ( hDC, points[i].fromx, points[i].fromy, NULL );
+      LineTo ( hDC, points[i].tox, points[i].toy );
+      SelectObject ( hDC, hpenold );
+      DeleteObject ( hpen );
+    }
+}
+
+LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+  PAINTSTRUCT ps;
+  HDC hDC;
+  RECT clr;
+  HBRUSH hbr;
+  
+  switch(msg)
+  {
+  case WM_PAINT:
+    GetClientRect(hWnd, &clr);
+    //ClipRgn = CreateRectRgnIndirect(&clr);
+    hDC = BeginPaint(hWnd, &ps);
+    //Rect.left = 100;
+    //Rect.top = 100;
+    //Rect.right = 250;
+    //Rect.bottom = 150;
+    //FillRect(hDC, &Rect, CreateSolidBrush(RGB(0xFF, 0x00, 0x00)));
+    //ExcludeRgn = CreateRectRgnIndirect(&Rect);
+    //CombineRgn(ClipRgn, ClipRgn, ExcludeRgn, RGN_DIFF);
+    //DeleteObject(ExcludeRgn);
+    //Rect.left = 150;
+    //Rect.top = 150;
+    //Rect.right = 200;
+    //Rect.bottom = 250;
+    hbr = CreateSolidBrush(RGB(255, 255, 255));
+    FillRect ( hDC, &clr, hbr );
+    DeleteObject ( hbr );
+    DrawLines(hDC);
+    EndPaint(hWnd, &ps);
+    break;
+    
+  case WM_DESTROY:
+    PostQuitMessage(0);
+    break;
+    
+  default:
+    return DefWindowProc(hWnd, msg, wParam, lParam);
+  }
+  return 0;
+}
diff --git a/rosapps/tests/linetest/makefile b/rosapps/tests/linetest/makefile
new file mode 100644 (file)
index 0000000..b3c7f2f
--- /dev/null
@@ -0,0 +1,23 @@
+# $Id: makefile,v 1.1 2004/10/21 04:58:59 sedwards Exp $
+
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = windows
+
+TARGET_NAME = linetest
+
+TARGET_SDKLIBS = kernel32.a gdi32.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+TARGET_CFLAGS = -Wall -Werror
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/lpc/.cvsignore b/rosapps/tests/lpc/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/lpc/conport.c b/rosapps/tests/lpc/conport.c
new file mode 100644 (file)
index 0000000..c22781a
--- /dev/null
@@ -0,0 +1,205 @@
+/* $Id: conport.c,v 1.1 2004/10/21 04:58:59 sedwards Exp $
+ *
+ * reactos/apps/lpc/conport.c
+ *
+ * To be run in a real WNT 4.0 system with
+ * "\SmApiPort" as argument. Do not try to
+ * connect to "\Windows\ApiPort" since that
+ * reboots immeditely.
+ * 
+ * Use Russinovich' HandleEx to verify
+ * conport.exe owns two unnamed LPC ports:
+ * the one created by kernel32.dll connecting
+ * to csrss.exe, and one connected to here.
+ *
+ * 19990627 (Emanuele Aliberti)
+ *     Initial implementation.
+ * 19990704 (EA)
+ *     Dump object's attributes moved in dumpinfo.c.
+ */
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#define PROTO_LPC
+#include <ddk/ntddk.h>
+#include "dumpinfo.h"
+
+#define LPC_CONNECT_FLAG1 0x00000001
+#define LPC_CONNECT_FLAG2 0x00000010
+#define LPC_CONNECT_FLAG3 0x00000100
+#define LPC_CONNECT_FLAG4 0x00001000
+#define LPC_CONNECT_FLAG5 0x00010000
+
+NTSTATUS
+(STDCALL * ConnectPort)(
+       OUT     PHANDLE                 PortHandle,
+       IN      PUNICODE_STRING         PortName,
+       IN      POBJECT_ATTRIBUTES      ObjectAttributes,
+       IN      DWORD   Unknown3,
+       IN      DWORD   Unknown4,
+       IN      DWORD   Unknown5,
+       IN      DWORD   Unknown6,
+       IN      ULONG   Flags
+       );
+
+NTSTATUS
+(STDCALL * QueryObject)(
+       IN      HANDLE  ObjectHandle,
+       IN      CINT    ObjectInformationClass,
+       OUT     PVOID   ObjectInformation,
+       IN      ULONG   Length,
+       OUT     PULONG  ResultLength
+       );
+  
+NTSTATUS
+(STDCALL * YieldExecution)(VOID);
+
+#define BUF_SIZE 1024
+#define MAXARG   1000000
+
+
+VOID
+TryConnectPort(char *port_name)
+{
+       DWORD                   Status = 0;
+       HANDLE                  Port = 0;
+       int                     i;
+       UNICODE_STRING          PortName;
+       OBJECT_ATTRIBUTES       ObjectAttributes;
+       WORD                    Name [BUF_SIZE] = {0};
+       int                     dwx = 0;
+       char                    * port_name_save = port_name;
+
+       /*
+        * Convert the port's name to Unicode.
+        */
+       for (
+               PortName.Length = 0;
+               (       *port_name
+                       && (PortName.Length < BUF_SIZE)
+                       );
+               )
+       {
+               Name[PortName.Length++] = (WORD) *port_name++;
+       }
+       Name[PortName.Length] = 0;
+
+       PortName.Length = PortName.Length * sizeof (WORD);
+       PortName.MaximumLength = PortName.Length + sizeof (WORD);
+       PortName.Buffer = (PWSTR) Name;
+       /*
+        * Prepare the port object attributes.
+        */
+       ObjectAttributes.Length =
+               sizeof (OBJECT_ATTRIBUTES);
+       ObjectAttributes.RootDirectory =
+               NULL;
+       ObjectAttributes.ObjectName =
+               NULL /*& PortName */;
+       ObjectAttributes.Attributes =
+               OBJ_CASE_INSENSITIVE;
+       ObjectAttributes.SecurityDescriptor =
+               NULL;
+       ObjectAttributes.SecurityQualityOfService =
+               NULL;
+       /*
+        * Try to issue a connection request.
+        */
+       Port = 0;
+       Status = ConnectPort(
+                       & Port,                 /* & PortHandle */
+                       & PortName,             /* & PortName */
+                       & ObjectAttributes,     /* & PortAttributes */
+                       NULL,                   /* & SecurityQos */
+                       NULL,                   /* & SectionInfo */
+                       NULL,                   /* & MapInfo */
+                       NULL,                   /* & MaxMessageSize */
+                       LPC_CONNECT_FLAG5       /* & ConnectInfoLength */
+                       );
+       if (Status == STATUS_SUCCESS)
+       {
+               DumpInfo(
+                       Name,
+                       Status,
+                       "connected",
+                       Port
+                       );
+               /* Hot waiting */
+               for (dwx=0; dwx<MAXARG; ++dwx)
+               {
+                       YieldExecution();
+               }
+               if (FALSE == CloseHandle(Port))
+               {
+                       printf(
+                               "Could not close the port handle %08X.\n",
+                               Port
+                               );
+               }
+               return;
+       }
+       printf(
+               "Connection to port \"%s\" failed (Status = %08X).\n",
+               port_name_save,
+               Status
+               );
+}
+
+
+main( int argc, char * argv[] )
+{
+       HINSTANCE ntdll;
+
+       if (argc != 2)
+       {
+               printf("WNT LPC Port Connector\n");
+               printf("Usage: %s [port_name]\n",argv[0]);
+               exit(EXIT_FAILURE);
+       }
+       printf("LoadLibrary(NTDLL)\n");
+       ntdll = LoadLibrary("NTDLL");
+       if (ntdll == NULL)
+       {
+               printf("Could not load NTDLL\n");
+               return EXIT_FAILURE;
+       }
+       printf("GetProcAddress(NTDLL.NtConnectPort)\n");
+       ConnectPort = (VOID*) GetProcAddress(
+                                       ntdll,
+                                       "NtConnectPort"
+                                       );
+       if (ConnectPort == NULL)
+       {
+               FreeLibrary(ntdll);
+               printf("Could not find NTDLL.NtConnectPort\n");
+               return EXIT_FAILURE;
+       }
+       printf("GetProcAddress(NTDLL.NtQueryObject)\n");
+       QueryObject = (VOID*) GetProcAddress(
+                                       ntdll,
+                                       "NtQueryObject"
+                                       );
+       if (QueryObject == NULL)
+       {
+               FreeLibrary(ntdll);
+               printf("Could not find NTDLL.NtQueryObject\n");
+               return EXIT_FAILURE;
+       }
+       printf("GetProcAddress(NTDLL.NtYieldExecution)\n");
+       YieldExecution = (VOID*) GetProcAddress(
+                                       ntdll,
+                                       "NtYieldExecution"
+                                       );
+       if (YieldExecution == NULL)
+       {
+               FreeLibrary(ntdll);
+               printf("Could not find NTDLL.NtYieldExecution\n");
+               return EXIT_FAILURE;
+       }
+       printf("TryConnectPort(%s)\n",argv[1]);
+       TryConnectPort(argv[1]);
+       printf("Done\n");
+       return EXIT_SUCCESS;
+}
+
+/* EOF */
diff --git a/rosapps/tests/lpc/creport.c b/rosapps/tests/lpc/creport.c
new file mode 100644 (file)
index 0000000..b6e30a1
--- /dev/null
@@ -0,0 +1,192 @@
+/* $Id: creport.c,v 1.1 2004/10/21 04:58:59 sedwards Exp $
+ *
+ * reactos/apps/lpc/creport.c
+ *
+ * To be run in a real WNT 4.0 system to
+ * create an LPC named port.
+ * 
+ * Use Russinovich' HandleEx to verify
+ * creport.exe owns the named LPC port
+ * you asked to create.
+ */
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#define PROTO_LPC
+#include <ddk/ntddk.h>
+#include "dumpinfo.h"
+
+#define LPC_CONNECT_FLAG1 0x00000001
+#define LPC_CONNECT_FLAG2 0x00000010
+#define LPC_CONNECT_FLAG3 0x00000100
+#define LPC_CONNECT_FLAG4 0x00001000
+#define LPC_CONNECT_FLAG5 0x00010000
+
+NTSTATUS
+(STDCALL * CreatePort)(
+       /*OUT   PHANDLE                 PortHandle,*/
+       PVOID   Buffer,
+       IN      POBJECT_ATTRIBUTES      PortAttributes  OPTIONAL,  
+       IN      ACCESS_MASK             DesiredAccess,
+       IN      DWORD                   Unknown3,
+       IN      ULONG                   Flags
+       );
+
+NTSTATUS
+(STDCALL * QueryObject)(
+       IN      HANDLE  ObjectHandle,
+       IN      CINT    ObjectInformationClass,
+       OUT     PVOID   ObjectInformation,
+       IN      ULONG   Length,
+       OUT     PULONG  ResultLength
+       );
+  
+NTSTATUS
+(STDCALL * YieldExecution)(VOID);
+
+#define BUF_SIZE 1024
+#define MAXARG   5000000
+
+
+VOID
+TryCreatePort(char *port_name)
+{
+       DWORD                   Status = 0;
+       HANDLE                  Port = 0;
+       int                     i;
+       UNICODE_STRING          PortName;
+       OBJECT_ATTRIBUTES       ObjectAttributes;
+       WORD                    Name [BUF_SIZE] = {0};
+       int                     dwx = 0;
+       char                    * port_name_save = port_name;
+
+       /*
+        * Convert the port's name to Unicode.
+        */
+       for (
+               PortName.Length = 0;
+               (       *port_name
+                       && (PortName.Length < BUF_SIZE)
+                       );
+               )
+       {
+               Name[PortName.Length++] = (WORD) *port_name++;
+       }
+       Name[PortName.Length] = 0;
+
+       PortName.Length = PortName.Length * sizeof (WORD);
+       PortName.MaximumLength = PortName.Length + sizeof (WORD);
+       PortName.Buffer = (PWSTR) Name;
+       /*
+        * Prepare the port object attributes.
+        */
+       ObjectAttributes.Length =
+               sizeof (OBJECT_ATTRIBUTES);
+       ObjectAttributes.RootDirectory =
+               NULL;
+       ObjectAttributes.ObjectName =
+               & PortName;
+       ObjectAttributes.Attributes =
+               0; //OBJ_CASE_INSENSITIVE --> STATUS_INVALID_PARAMETER ==> case sensitive!;
+       ObjectAttributes.SecurityDescriptor =
+               NULL;
+       ObjectAttributes.SecurityQualityOfService =
+               NULL;
+       /*
+        * Try to issue a connection request.
+        */
+       Port = 0;
+       Status = CreatePort(
+                       & Port,
+                       & ObjectAttributes,
+                       0, /* ACCESS_MASK? */
+                       0, /* Unknown3 */
+                       LPC_CONNECT_FLAG5
+                       );
+       if (Status == STATUS_SUCCESS)
+       {
+               DumpInfo(
+                       Name,
+                       Status,
+                       "created",
+                       Port
+                       );
+               /* Hot waiting */
+               for (dwx=0; dwx<MAXARG; ++dwx)
+               {
+                       YieldExecution();
+               }
+               if (FALSE == CloseHandle(Port))
+               {
+                       printf(
+                               "Could not close the port handle %08X.\n",
+                               Port
+                               );
+               }
+               return;
+       }
+       printf(
+               "Creating port \"%s\" failed (Status = %08X).\n",
+               port_name_save,
+               Status
+               );
+}
+
+
+main( int argc, char * argv[] )
+{
+       HINSTANCE ntdll;
+
+       if (argc != 2)
+       {
+               printf("WNT LPC Port Creator\n");
+               printf("Usage: %s [port_name]\n",argv[0]);
+               exit(EXIT_FAILURE);
+       }
+       printf("LoadLibrary(NTDLL)\n");
+       ntdll = LoadLibrary("NTDLL");
+       if (ntdll == NULL)
+       {
+               printf("Could not load NTDLL\n");
+               return EXIT_FAILURE;
+       }
+       printf("GetProcAddress(NTDLL.NtCreatePort)\n");
+       CreatePort = (VOID*) GetProcAddress(
+                                       ntdll,
+                                       "NtCreatePort"
+                                       );
+       if (CreatePort == NULL)
+       {
+               FreeLibrary(ntdll);
+               printf("Could not find NTDLL.NtCreatePort\n");
+               return EXIT_FAILURE;
+       }
+       printf("GetProcAddress(NTDLL.NtQueryObject)\n");
+       QueryObject = (VOID*) GetProcAddress(
+                                       ntdll,
+                                       "NtQueryObject"
+                                       );
+       if (QueryObject == NULL)
+       {
+               FreeLibrary(ntdll);
+               printf("Could not find NTDLL.NtQueryObject\n");
+               return EXIT_FAILURE;
+       }
+       printf("GetProcAddress(NTDLL.NtYieldExecution)\n");
+       YieldExecution = (VOID*) GetProcAddress(
+                                       ntdll,
+                                       "NtYieldExecution"
+                                       );
+       if (YieldExecution == NULL)
+       {
+               FreeLibrary(ntdll);
+               printf("Could not find NTDLL.NtYieldExecution\n");
+               return EXIT_FAILURE;
+       }
+       printf("TryCreatePort(%s)\n",argv[1]);
+       TryCreatePort(argv[1]);
+       printf("Done\n");
+       return EXIT_SUCCESS;
+}
+
+/* EOF */
diff --git a/rosapps/tests/lpc/dumpinfo.c b/rosapps/tests/lpc/dumpinfo.c
new file mode 100644 (file)
index 0000000..b701229
--- /dev/null
@@ -0,0 +1,239 @@
+/* $Id: dumpinfo.c,v 1.1 2004/10/21 04:58:59 sedwards Exp $
+ *
+ * reactos/apps/lpc/dumpinfo.c
+ *
+ * ReactOS Operating System
+ *
+ * Dump a kernel object's attributes by its handle.
+ *
+ * 19990627 (Emanuele Aliberti)
+ *     Initial implementation.
+ * 19990704 (EA)
+ *     Added code to find the basic information buffer size
+ *     for the LPC port object.
+ * 19990710 (EA)
+ * 
+ */
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ddk/ntddk.h>
+
+#define BUF_SIZE               1024
+#define MAX_BASIC_INFO_SIZE    512
+
+
+extern
+NTSTATUS
+(STDCALL * QueryObject)(
+       IN      HANDLE  ObjectHandle,
+       IN      CINT    ObjectInformationClass,
+       OUT     PVOID   ObjectInformation,
+       IN      ULONG   Length,
+       OUT     PULONG  ResultLength
+       );
+
+extern
+NTSTATUS
+(STDCALL * QueryInformationPort)(
+       IN      HANDLE  PortHandle,
+       IN      CINT    PortInformationClass,   /* guess */
+       OUT     PVOID   PortInformation,        /* guess */
+       IN      ULONG   PortInformationLength,  /* guess */
+       OUT     PULONG  ReturnLength            /* guess */
+       );
+
+
+/*
+static
+VOID
+DumpBuffer(
+       char    *Name,
+       BYTE    *buffer,
+       ULONG   size
+       )
+{
+       register ULONG i = 0;
+
+       printf("%s [%d] = ",Name,size);
+       for (   i = 0;
+               i != size;
+               ++i
+               )
+       {
+               printf("%02X",buffer[i]);
+       }
+       printf("\n");
+}
+*/
+
+VOID
+DumpInfo (
+       LPCWSTR         Name,
+       NTSTATUS        Status,
+       LPCWSTR         Comment,
+       HANDLE          Port
+       )
+{
+       BYTE                    ObjectInformation [BUF_SIZE] = {0};
+       ULONG                   ResultLength;
+       
+       wprintf(
+               L"Port \"%s\" %s:\n",
+               Name,
+               Comment
+               );
+
+       printf("\tStatus = %08X\n",Status);
+       printf("\tPort   = %08X\n\n",Port);
+       /*
+        * Query object information.
+        */
+       printf("Basic Information:\n");
+       Status = QueryObject(
+                       Port,
+                       ObjectBasicInformation,
+                       ObjectInformation,
+                       sizeof (LPC_PORT_BASIC_INFORMATION),
+                       & ResultLength
+                       );
+       if (Status == STATUS_SUCCESS)
+       {
+               PLPC_PORT_BASIC_INFORMATION     i;
+
+               i = (PLPC_PORT_BASIC_INFORMATION) ObjectInformation;
+       
+               printf( "\tUnknown01 = 0x%08X\n", i->Unknown0 );
+               printf( "\tUnknown02 = 0x%08X\n", i->Unknown1 );
+               printf( "\tUnknown03 = 0x%08X\n", i->Unknown2 );
+               printf( "\tUnknown04 = 0x%08X\n", i->Unknown3 );
+               printf( "\tUnknown05 = 0x%08X\n", i->Unknown4 );
+               printf( "\tUnknown06 = 0x%08X\n", i->Unknown5 );
+               printf( "\tUnknown07 = 0x%08X\n", i->Unknown6 );
+               printf( "\tUnknown08 = 0x%08X\n", i->Unknown7 );
+               printf( "\tUnknown09 = 0x%08X\n", i->Unknown8 );
+               printf( "\tUnknown10 = 0x%08X\n", i->Unknown9 );
+               printf( "\tUnknown11 = 0x%08X\n", i->Unknown10 );
+               printf( "\tUnknown12 = 0x%08X\n", i->Unknown11 );
+               printf( "\tUnknown13 = 0x%08X\n", i->Unknown12 );
+               printf( "\tUnknown14 = 0x%08X\n", i->Unknown13 );
+       }
+       else
+       {
+               printf("\tStatus = %08X\n",Status);
+       }
+       printf("Type Information:\n");
+       Status = QueryObject(
+                       Port,
+                       ObjectTypeInformation,
+                       ObjectInformation,
+                       sizeof ObjectInformation,
+                       & ResultLength
+                       );
+       if (Status == STATUS_SUCCESS)
+       {
+               OBJECT_TYPE_INFORMATION * i;
+
+               i = (OBJECT_TYPE_INFORMATION *) ObjectInformation;
+               
+               wprintf(
+                       L"\tName: \"%s\"\n",
+                       (i->Name.Length ? i->Name.Buffer : L"")
+                       );
+/*
+FIXME: why this always raise an access violation exception?
+               wprintf(
+                       L"\tType: \"%s\"\n",
+                       (i->Type.Length ? i->Type.Buffer : L"")
+                       );
+/**/
+               printf(
+                       "\tTotal Handles: %d\n",
+                       i->TotalHandles
+                       );
+               printf(
+                       "\tReference Count: %d\n",
+                       i->ReferenceCount
+                       );
+       }
+       else
+       {
+               printf("\tStatus = %08X\n",Status);
+       }
+       printf("Name Information:\n");
+       Status = QueryObject(
+                       Port,
+                       ObjectNameInformation,
+                       ObjectInformation,
+                       sizeof ObjectInformation,
+                       & ResultLength
+                       );
+       if (Status == STATUS_SUCCESS)
+       {
+               OBJECT_NAME_INFORMATION * i;
+
+               i = (OBJECT_NAME_INFORMATION *) ObjectInformation;
+               wprintf(
+                       L"\tName: \"%s\"\n",
+                       (i->Name.Length ? i->Name.Buffer : L"")
+                       );
+       }
+       else
+       {
+               printf("\tStatus = %08X\n",Status);
+       }
+       printf("Data Information:\n");
+       Status = QueryObject(
+                       Port,
+                       ObjectDataInformation,
+                       ObjectInformation,
+                       sizeof ObjectInformation,
+                       & ResultLength
+                       );
+       if (Status == STATUS_SUCCESS)
+       {
+               OBJECT_DATA_INFORMATION * i;
+
+               i = (OBJECT_DATA_INFORMATION *) ObjectInformation;
+               printf(
+                       "\tInherit Handle: %s\n",
+                       (i->bInheritHandle ? "TRUE" : "FALSE")
+                       );
+               printf(
+                       "\tProtect from Close: %s\n",
+                       (i->bProtectFromClose ? "TRUE" : "FALSE")
+                       );
+       }
+       else
+       {
+               printf("\tStatus = %08X\n",Status);
+       }
+//---
+       printf("Port Information:\n");
+/*     Status = QueryInformationPort(
+                       Port,
+                       1, /* info class * /
+                       ObjectInformation,
+                       sizeof ObjectInformation,
+                       & ResultLength
+                       );
+       if (Status == STATUS_SUCCESS)
+       {
+               DWORD * i = ObjectInformation;
+               int j = 0;
+
+               while (j < ResultLength / sizeof (DWORD))
+               {
+                       printf("\t%08X\n",i[j]);
+                       ++j;
+               }
+       }
+       else
+       {
+               printf("\tStatus = %08X\n",Status);
+       }
+*/
+}
+
+
+/* EOF */
diff --git a/rosapps/tests/lpc/dumpinfo.h b/rosapps/tests/lpc/dumpinfo.h
new file mode 100644 (file)
index 0000000..51e7873
--- /dev/null
@@ -0,0 +1,8 @@
+VOID
+DumpInfo (
+       LPCWSTR         Name,
+       NTSTATUS        Status,
+       LPCWSTR         Comment,
+       HANDLE          Port
+       );
+
diff --git a/rosapps/tests/lpc/lpcclt.c b/rosapps/tests/lpc/lpcclt.c
new file mode 100644 (file)
index 0000000..c227eca
--- /dev/null
@@ -0,0 +1,92 @@
+/* $Id: lpcclt.c,v 1.1 2004/10/21 04:58:59 sedwards Exp $
+ *
+ * DESCRIPTION: Simple LPC Client
+ * PROGRAMMER:  David Welch
+ */
+#include <ddk/ntddk.h>
+#include <rosrtl/string.h>
+#include <windows.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "lpctest.h"
+
+const char * MyName = "LPC-CLI";
+HANDLE OutputHandle;
+HANDLE InputHandle;
+
+void debug_printf(char* fmt, ...)
+{
+   va_list args;
+   char buffer[255];
+
+   va_start(args,fmt);
+   vsprintf(buffer,fmt,args);
+   WriteConsoleA(OutputHandle, buffer, strlen(buffer), NULL, NULL);
+   va_end(args);
+}
+
+
+int main(int argc, char* argv[])
+{
+   UNICODE_STRING PortName = ROS_STRING_INITIALIZER(TEST_PORT_NAME_U);
+   NTSTATUS Status;
+   HANDLE PortHandle;
+   LPC_MAX_MESSAGE Request;
+   ULONG ConnectInfo;
+   ULONG ConnectInfoLength = 0;
+   SECURITY_QUALITY_OF_SERVICE Sqos;
+   
+   printf("%s: Lpc test client\n", MyName);
+   
+   printf("%s: Connecting to port \"%s\"...\n", MyName, TEST_PORT_NAME);
+   ConnectInfoLength = 0;
+   ZeroMemory (& Sqos, sizeof Sqos);
+   Status = NtConnectPort(&PortHandle,
+                         &PortName,
+                         & Sqos,
+                         0,
+                         0,
+                         0,
+                         NULL,
+                         &ConnectInfoLength);
+   if (!NT_SUCCESS(Status))
+     {
+       printf("%s: NtConnectPort() failed with status = 0x%08X.\n", MyName, Status);
+       return EXIT_FAILURE;
+     }
+
+   printf("%s: Connected to \"%s\" with anonymous port 0x%x.\n", MyName, TEST_PORT_NAME, PortHandle);
+
+   ZeroMemory(& Request, sizeof Request);
+   strcpy(Request.Data, GetCommandLineA());
+   Request.Header.DataSize = strlen(Request.Data);
+   Request.Header.MessageSize = sizeof(LPC_MESSAGE) + 
+     Request.Header.DataSize;
+   
+   printf("%s: Sending to port 0x%x message \"%s\"...\n", 
+          MyName,
+          PortHandle,
+         (char *) Request.Data);
+   Status = NtRequestPort(PortHandle, 
+                         &Request.Header);
+   if (!NT_SUCCESS(Status))
+     {
+       printf("%s: NtRequestPort(0x%x) failed with status = 0x%8X.\n", 
+               MyName,
+               PortHandle,
+              Status);
+       return EXIT_FAILURE;
+     }
+   
+   printf("%s: Sending datagram to port 0x%x succeeded.\n", MyName, PortHandle);
+
+   Sleep(2000);
+
+   printf("%s: Disconnecting...", MyName);
+   NtClose (PortHandle);
+
+   return EXIT_SUCCESS;
+}
diff --git a/rosapps/tests/lpc/lpcsrv.c b/rosapps/tests/lpc/lpcsrv.c
new file mode 100644 (file)
index 0000000..ee0acee
--- /dev/null
@@ -0,0 +1,139 @@
+/* $Id: lpcsrv.c,v 1.1 2004/10/21 04:58:59 sedwards Exp $
+ *
+ * DESCRIPTION: Simple LPC Server
+ * PROGRAMMER:  David Welch
+ */
+#include <ddk/ntddk.h>
+#include <rosrtl/string.h>
+#include <windows.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "lpctest.h"
+
+static const char * MyName = "LPC-SRV";
+
+HANDLE OutputHandle;
+HANDLE InputHandle;
+
+void debug_printf(char* fmt, ...)
+{
+   va_list args;
+   char buffer[255];
+
+   va_start(args,fmt);
+   vsprintf(buffer,fmt,args);
+   WriteConsoleA(OutputHandle, buffer, strlen(buffer), NULL, NULL);
+   va_end(args);
+}
+
+
+int main(int argc, char* argv[])
+{
+   UNICODE_STRING PortName = ROS_STRING_INITIALIZER(TEST_PORT_NAME_U);
+   OBJECT_ATTRIBUTES ObjectAttributes;
+   NTSTATUS Status;
+   HANDLE NamedPortHandle;
+   HANDLE PortHandle;
+   LPC_MAX_MESSAGE ConnectMsg;
+   
+   printf("%s: Lpc test server\n", MyName);
+
+   InitializeObjectAttributes(&ObjectAttributes,
+                             &PortName,
+                             0,
+                             NULL,
+                             NULL);
+   
+   printf("%s: Creating port \"%s\"...\n", MyName, TEST_PORT_NAME);
+   Status = NtCreatePort(&NamedPortHandle,
+                        &ObjectAttributes,
+                        0,
+                        0,
+                        0);
+   if (!NT_SUCCESS(Status))
+     {
+       printf("%s: NtCreatePort() failed with status = 0x%08lX.\n", MyName, Status);
+       return EXIT_FAILURE;
+     }
+   printf("%s: Port \"%s\" created (0x%x).\n\n", MyName, TEST_PORT_NAME, NamedPortHandle);
+   
+   for (;;)
+   { 
+     printf("%s: Listening for connections requests on port 0x%x...\n", MyName, NamedPortHandle);
+     Status = NtListenPort(NamedPortHandle,
+                        &ConnectMsg.Header);
+     if (!NT_SUCCESS(Status))
+       {
+         printf("%s: NtListenPort() failed with status = 0x%08lX.\n", MyName, Status);
+         return EXIT_FAILURE;
+       }
+
+     printf("%s: Received connection request 0x%08x on port 0x%x.\n", MyName,
+        ConnectMsg.Header.MessageId, NamedPortHandle);
+     printf("%s: Request from: PID=%x, TID=%x.\n", MyName,
+        ConnectMsg.Header.ClientId.UniqueProcess, ConnectMsg.Header.ClientId.UniqueThread);
+   
+     printf("%s: Accepting connection request 0x%08x...\n", MyName, 
+        ConnectMsg.Header.MessageId);
+     Status = NtAcceptConnectPort(&PortHandle,
+                               NamedPortHandle,
+                               & ConnectMsg.Header,
+                               TRUE,
+                               0,
+                               NULL);
+     if (!NT_SUCCESS(Status))
+       {
+         printf("%s: NtAcceptConnectPort() failed with status = 0x%08lX.\n", MyName, Status);
+         return EXIT_FAILURE;
+       }   
+     printf("%s: Connection request 0x%08x accepted as port 0x%x.\n", MyName, 
+        ConnectMsg.Header.MessageId, PortHandle);
+   
+     printf("%s: Completing connection for port 0x%x (0x%08x).\n", MyName, 
+        PortHandle, ConnectMsg.Header.MessageId);
+     Status = NtCompleteConnectPort(PortHandle);
+     if (!NT_SUCCESS(Status))
+       {
+         printf("%s: NtCompleteConnectPort() failed with status = 0x%08lX.\n", MyName, Status);
+         return EXIT_FAILURE;
+       }
+  
+     printf("%s: Entering server loop for port 0x%x...\n", MyName, PortHandle); 
+     for(;;)
+       {
+         LPC_MAX_MESSAGE Request;
+       
+         Status = NtReplyWaitReceivePort(PortHandle,
+                                       0,
+                                       NULL,
+                                       &Request.Header);
+        if (!NT_SUCCESS(Status))
+          {
+            printf("%s: NtReplyWaitReceivePort() failed with status = 0x%08lX.\n", MyName, Status);
+             return EXIT_FAILURE;
+           }
+
+         if (LPC_DATAGRAM == PORT_MESSAGE_TYPE(Request))
+           {
+             printf("%s: Datagram message contents are <%s>.\n",
+               MyName, 
+              Request.Data);
+           }
+         else
+           {
+             printf("%s: Message with type %d received on port 0x%x.\n", MyName,
+               PORT_MESSAGE_TYPE(Request), PortHandle);
+             NtClose(PortHandle);
+             printf("%s: Connected port 0x%x closed.\n\n", MyName, PortHandle);
+             break;
+           }
+       }
+   }
+   return EXIT_SUCCESS;
+}
+
+
+/* EOF */
diff --git a/rosapps/tests/lpc/lpctest.h b/rosapps/tests/lpc/lpctest.h
new file mode 100644 (file)
index 0000000..6e65208
--- /dev/null
@@ -0,0 +1,5 @@
+#ifndef _LPCTEST_H
+#define _LPCTEST_H
+#define TEST_PORT_NAME    "\\TestPort"
+#define TEST_PORT_NAME_U  L"\\TestPort"
+#endif
diff --git a/rosapps/tests/lpc/makefile b/rosapps/tests/lpc/makefile
new file mode 100644 (file)
index 0000000..9085464
--- /dev/null
@@ -0,0 +1,52 @@
+#
+#
+#
+PATH_TO_TOP = ../../../reactos
+
+include $(PATH_TO_TOP)/config
+include $(PATH_TO_TOP)/rules.mak
+
+SRV_OBJECTS= lpcsrv.o
+CLT_OBJECTS= lpcclt.o
+
+PROGS= lpcsrv.exe lpcclt.exe
+
+CFLAGS = $(STD_CFLAGS)
+
+LIBS = $(SDK_PATH_LIB)/kernel32.a \
+  $(SDK_PATH_LIB)/ntdll.a
+
+all: $(PROGS)
+
+.phony: all
+
+implib:
+
+clean:
+       - $(RM) lpcsrv.o lpcsrv.exe lpcsrv.sym lpcclt.o lpcclt.exe lpcclt.sym
+       
+.phony: implib clean
+
+ifneq ($(BOOTCD_INSTALL),)
+
+install: $(PROGS:%=$(INSTALL_DIR)/%)
+
+$(PROGS:%=$(INSTALL_DIR)/%): $(INSTALL_DIR)/%: %
+       $(CP) $* $(INSTALL_DIR)/$*
+       
+else # BOOTCD_INSTALL
+
+install: $(PROGS:%=$(INSTALL_DIR)/bin/%)
+
+$(PROGS:%=$(INSTALL_DIR)/bin/%): $(INSTALL_DIR)/bin/%: %
+       $(CP) $* $(INSTALL_DIR)/bin/$*
+
+endif # BOOTCD_INSTALL
+
+lpcsrv.exe: $(SRV_OBJECTS) $(LIBS)
+       $(CC) $(SRV_OBJECTS) $(LIBS) -o lpcsrv.exe
+       $(NM) --numeric-sort lpcsrv.exe > lpcsrv.sym
+
+lpcclt.exe: $(CLT_OBJECTS) $(LIBS)
+       $(CC) $(CLT_OBJECTS) $(LIBS) -o lpcclt.exe
+       $(NM) --numeric-sort lpcclt.exe > lpcclt.sym
diff --git a/rosapps/tests/map_dup_inherit/.cvsignore b/rosapps/tests/map_dup_inherit/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/map_dup_inherit/makefile b/rosapps/tests/map_dup_inherit/makefile
new file mode 100644 (file)
index 0000000..912e727
--- /dev/null
@@ -0,0 +1,23 @@
+# $Id: makefile,v 1.1 2004/10/21 04:58:59 sedwards Exp $
+
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = map_dup_inherit
+
+TARGET_SDKLIBS = kernel32.a gdi32.a ntdll.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+TARGET_CFLAGS = -Wall -Werror
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/map_dup_inherit/map_dup_inherit.c b/rosapps/tests/map_dup_inherit/map_dup_inherit.c
new file mode 100644 (file)
index 0000000..2abd2ca
--- /dev/null
@@ -0,0 +1,91 @@
+#include <stdio.h>
+#include <windows.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* This tests the ability of the target win32 to create an anonymous file
+ * mapping, create a mapping view with MapViewOfFile, and then realize the
+ * pages with VirtualAlloc.
+ */
+
+int main( int argc, char **argv ) {
+  HANDLE file_view;
+  void *file_map;
+  int *x;
+
+  fprintf( stderr, "%lu: Starting\n", GetCurrentProcessId() );
+
+  if( argc == 2 ) {
+    file_map = (void *)atoi(argv[1]);
+  } else {
+    file_map = CreateFileMapping( INVALID_HANDLE_VALUE, 
+                                 NULL, 
+                                 PAGE_READWRITE | SEC_RESERVE, 
+                                 0, 0x1000, NULL );
+    if( !SetHandleInformation( file_map, 
+                              HANDLE_FLAG_INHERIT, 
+                              HANDLE_FLAG_INHERIT ) ) {
+      fprintf( stderr, "%lu: Could not make handle inheritable.\n",
+              GetCurrentProcessId() );
+      return 100;
+    }
+  }
+   
+  if( !file_map ) {
+    fprintf( stderr, "%lu: Could not create anonymous file map.\n",
+            GetCurrentProcessId() );
+    return 1;
+  }
+  
+  file_view = MapViewOfFile( file_map,
+                            FILE_MAP_WRITE,
+                            0,
+                            0,
+                            0x1000 );
+  
+  if( !file_view ) {
+    fprintf( stderr, "%lu: Could not map view of file.\n",
+            GetCurrentProcessId() );
+    return 2;
+  }
+  
+  if( !VirtualAlloc( file_view, 0x1000, MEM_COMMIT, PAGE_READWRITE ) ) {
+    fprintf( stderr, "%lu: VirtualAlloc failed to realize the page.\n",
+            GetCurrentProcessId() );
+    return 3;
+  }
+  
+  x = (int *)file_view;
+  x[0] = 0x12345678;
+  
+  if( x[0] != 0x12345678 ) {
+    fprintf( stderr, "%lu: Can't write to the memory (%08x != 0x12345678)\n",
+            GetCurrentProcessId(), x[0] );
+    return 4;
+  }
+
+  if( argc == 1 ) {
+    STARTUPINFO si;
+    PROCESS_INFORMATION pi;
+    char cmdline[1000];
+
+    memset( &si, 0, sizeof( si ) );
+    memset( &pi, 0, sizeof( pi ) );
+
+    sprintf(cmdline,"%s %d", argv[0], (int)file_map);
+    if( !CreateProcess(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL,
+                      &si, &pi ) ) {
+      fprintf( stderr, "%lu: Could not create child process.\n",
+              GetCurrentProcessId() );
+      return 5;
+    }
+
+    if( WaitForSingleObject( pi.hThread, INFINITE ) != WAIT_OBJECT_0 ) {
+      fprintf( stderr, "%lu: Failed to wait for child process to terminate.\n",
+              GetCurrentProcessId() );
+      return 6;
+    }
+  }
+
+  return 0;
+}
diff --git a/rosapps/tests/mdi/.cvsignore b/rosapps/tests/mdi/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/mdi/makefile b/rosapps/tests/mdi/makefile
new file mode 100644 (file)
index 0000000..ec38564
--- /dev/null
@@ -0,0 +1,23 @@
+# $Id: makefile,v 1.1 2004/10/21 04:58:59 sedwards Exp $
+
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = no
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = windows
+
+TARGET_NAME = mdi
+
+TARGET_SDKLIBS = kernel32.a gdi32.a ntdll.a comctl32.a comdlg32.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+TARGET_CFLAGS = -D__USE_W32API -Wall -Werror
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/mdi/mdi.c b/rosapps/tests/mdi/mdi.c
new file mode 100644 (file)
index 0000000..ecbbbea
--- /dev/null
@@ -0,0 +1,523 @@
+/*
+  Thanks to theForger from winprog.org
+*/
+#include <windows.h>
+#include <commctrl.h>
+
+#include <string.h>
+#include "resource.h"
+
+const char g_szClassName[] = "myWindowClass";
+const char g_szChildClassName[] = "myMDIChildWindowClass";
+
+#define IDC_MAIN_MDI   101
+#define IDC_MAIN_TOOL  102
+#define IDC_MAIN_STATUS        103
+
+#define IDC_CHILD_EDIT 101
+
+#define ID_MDI_FIRSTCHILD 50000
+
+HWND g_hMDIClient = NULL;
+HWND g_hMainWindow = NULL;
+
+BOOL LoadTextFileToEdit(HWND hEdit, LPCTSTR pszFileName)
+{
+       HANDLE hFile;
+       BOOL bSuccess = FALSE;
+
+       hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
+               OPEN_EXISTING, 0, NULL);
+       if(hFile != INVALID_HANDLE_VALUE)
+       {
+               DWORD dwFileSize;
+
+               dwFileSize = GetFileSize(hFile, NULL);
+               if(dwFileSize != 0xFFFFFFFF)
+               {
+                       LPSTR pszFileText;
+
+                       pszFileText = GlobalAlloc(GPTR, dwFileSize + 1);
+                       if(pszFileText != NULL)
+                       {
+                               DWORD dwRead;
+
+                               if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL))
+                               {
+                                       pszFileText[dwFileSize] = 0; // Add null terminator
+                                       if(SetWindowText(hEdit, pszFileText))
+                                               bSuccess = TRUE; // It worked!
+                               }
+                               GlobalFree(pszFileText);
+                       }
+               }
+               CloseHandle(hFile);
+       }
+       return bSuccess;
+}
+
+BOOL SaveTextFileFromEdit(HWND hEdit, LPCTSTR pszFileName)
+{
+       HANDLE hFile;
+       BOOL bSuccess = FALSE;
+
+       hFile = CreateFile(pszFileName, GENERIC_WRITE, 0, NULL,
+               CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+       if(hFile != INVALID_HANDLE_VALUE)
+       {
+               DWORD dwTextLength;
+
+               dwTextLength = GetWindowTextLength(hEdit);
+               // No need to bother if there's no text.
+               if(dwTextLength > 0)
+               {
+                       LPSTR pszText;
+                       DWORD dwBufferSize = dwTextLength + 1;
+
+                       pszText = GlobalAlloc(GPTR, dwBufferSize);
+                       if(pszText != NULL)
+                       {
+                               if(GetWindowText(hEdit, pszText, dwBufferSize))
+                               {
+                                       DWORD dwWritten;
+
+                                       if(WriteFile(hFile, pszText, dwTextLength, &dwWritten, NULL))
+                                               bSuccess = TRUE;
+                               }
+                               GlobalFree(pszText);
+                       }
+               }
+               CloseHandle(hFile);
+       }
+       return bSuccess;
+}
+
+void DoFileOpen(HWND hwnd)
+{
+       OPENFILENAME ofn;
+       char szFileName[MAX_PATH] = "";
+
+       ZeroMemory(&ofn, sizeof(ofn));
+
+       ofn.lStructSize = sizeof(ofn);
+       ofn.hwndOwner = hwnd;
+       ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
+       ofn.lpstrFile = szFileName;
+       ofn.nMaxFile = MAX_PATH;
+       ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
+       ofn.lpstrDefExt = "txt";
+
+       if(GetOpenFileName(&ofn))
+       {
+               HWND hEdit = GetDlgItem(hwnd, IDC_CHILD_EDIT);
+               if(LoadTextFileToEdit(hEdit, szFileName))
+               {
+                       SendDlgItemMessage(g_hMainWindow, IDC_MAIN_STATUS, SB_SETTEXT, 0, (LPARAM)"Opened...");
+                       SendDlgItemMessage(g_hMainWindow, IDC_MAIN_STATUS, SB_SETTEXT, 1, (LPARAM)szFileName);
+
+                       SetWindowText(hwnd, szFileName);
+               }
+       }
+}
+
+void DoFileSave(HWND hwnd)
+{
+       OPENFILENAME ofn;
+       char szFileName[MAX_PATH] = "";
+
+       ZeroMemory(&ofn, sizeof(ofn));
+
+       ofn.lStructSize = sizeof(ofn);
+       ofn.hwndOwner = hwnd;
+       ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
+       ofn.lpstrFile = szFileName;
+       ofn.nMaxFile = MAX_PATH;
+       ofn.lpstrDefExt = "txt";
+       ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
+
+       if(GetSaveFileName(&ofn))
+       {
+               HWND hEdit = GetDlgItem(hwnd, IDC_CHILD_EDIT);
+               if(SaveTextFileFromEdit(hEdit, szFileName))
+               {
+                       SendDlgItemMessage(g_hMainWindow, IDC_MAIN_STATUS, SB_SETTEXT, 0, (LPARAM)"Saved...");
+                       SendDlgItemMessage(g_hMainWindow, IDC_MAIN_STATUS, SB_SETTEXT, 1, (LPARAM)szFileName);
+
+                       SetWindowText(hwnd, szFileName);
+               }
+       }
+}
+
+HWND CreateNewMDIChild(HWND hMDIClient)
+{
+       MDICREATESTRUCT mcs;
+       HWND hChild;
+
+       mcs.szTitle = "[Untitled]";
+       mcs.szClass = g_szChildClassName;
+       mcs.hOwner  = GetModuleHandle(NULL);
+       mcs.x = mcs.cx = CW_USEDEFAULT;
+       mcs.y = mcs.cy = CW_USEDEFAULT;
+       mcs.style = MDIS_ALLCHILDSTYLES;
+
+       hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LONG)&mcs);
+       if(!hChild)
+       {
+               MessageBox(hMDIClient, "MDI Child creation failed.", "Oh Oh...",
+                       MB_ICONEXCLAMATION | MB_OK);
+       }
+       return hChild;
+}
+
+LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+       switch(msg)
+       {
+               case WM_CREATE:
+               {
+                       HWND hTool;
+                       TBBUTTON tbb[3];
+                       TBADDBITMAP tbab;
+
+                       HWND hStatus;
+                       int statwidths[] = {100, -1};
+
+                       CLIENTCREATESTRUCT ccs;
+
+                       // Create MDI Client
+
+                       // Find window menu where children will be listed
+                       ccs.hWindowMenu  = GetSubMenu(GetMenu(hwnd), 2);
+                       ccs.idFirstChild = ID_MDI_FIRSTCHILD;
+
+                       g_hMDIClient = CreateWindowEx(WS_EX_CLIENTEDGE, "mdiclient", NULL,
+                               WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
+                               CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
+                               hwnd, (HMENU)IDC_MAIN_MDI, GetModuleHandle(NULL), (LPVOID)&ccs);
+
+                       if(g_hMDIClient == NULL)
+                               MessageBox(hwnd, "Could not create MDI client.", "Error", MB_OK | MB_ICONERROR);
+
+                       // Create Toolbar
+
+                       hTool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
+                               hwnd, (HMENU)IDC_MAIN_TOOL, GetModuleHandle(NULL), NULL);
+                       if(hTool == NULL)
+                               MessageBox(hwnd, "Could not create tool bar.", "Error", MB_OK | MB_ICONERROR);
+
+                       // Send the TB_BUTTONSTRUCTSIZE message, which is required for
+                       // backward compatibility.
+                       SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
+                       
+                       tbab.hInst = HINST_COMMCTRL;
+                       tbab.nID = IDB_STD_SMALL_COLOR;
+                       SendMessage(hTool, TB_ADDBITMAP, 0, (LPARAM)&tbab);
+
+                       ZeroMemory(tbb, sizeof(tbb));
+                       tbb[0].iBitmap = STD_FILENEW;
+                       tbb[0].fsState = TBSTATE_ENABLED;
+                       tbb[0].fsStyle = TBSTYLE_BUTTON;
+                       tbb[0].idCommand = ID_FILE_NEW;
+
+                       tbb[1].iBitmap = STD_FILEOPEN;
+                       tbb[1].fsState = TBSTATE_ENABLED;
+                       tbb[1].fsStyle = TBSTYLE_BUTTON;
+                       tbb[1].idCommand = ID_FILE_OPEN;
+
+                       tbb[2].iBitmap = STD_FILESAVE;
+                       tbb[2].fsState = TBSTATE_ENABLED;
+                       tbb[2].fsStyle = TBSTYLE_BUTTON;
+                       tbb[2].idCommand = ID_FILE_SAVEAS;
+
+                       SendMessage(hTool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);
+
+                       // Create Status bar
+
+                       hStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL,
+                               WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0,
+                               hwnd, (HMENU)IDC_MAIN_STATUS, GetModuleHandle(NULL), NULL);
+
+                       SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
+                       SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Hi there :)");
+               }
+               break;
+               case WM_SIZE:
+               {
+                       HWND hTool;
+                       RECT rcTool;
+                       int iToolHeight;
+
+                       HWND hStatus;
+                       RECT rcStatus;
+                       int iStatusHeight;
+
+                       HWND hMDI;
+                       int iMDIHeight;
+                       RECT rcClient;
+
+                       // Size toolbar and get height
+
+                       hTool = GetDlgItem(hwnd, IDC_MAIN_TOOL);
+                       SendMessage(hTool, TB_AUTOSIZE, 0, 0);
+
+                       GetWindowRect(hTool, &rcTool);
+                       iToolHeight = rcTool.bottom - rcTool.top;
+
+                       // Size status bar and get height
+
+                       hStatus = GetDlgItem(hwnd, IDC_MAIN_STATUS);
+                       SendMessage(hStatus, WM_SIZE, 0, 0);
+
+                       GetWindowRect(hStatus, &rcStatus);
+                       iStatusHeight = rcStatus.bottom - rcStatus.top;
+
+                       // Calculate remaining height and size edit
+
+                       GetClientRect(hwnd, &rcClient);
+
+                       iMDIHeight = rcClient.bottom - iToolHeight - iStatusHeight;
+
+                       hMDI = GetDlgItem(hwnd, IDC_MAIN_MDI);
+                       SetWindowPos(hMDI, NULL, 0, iToolHeight, rcClient.right, iMDIHeight, SWP_NOZORDER);
+               }
+               break;
+               case WM_CLOSE:
+                       DestroyWindow(hwnd);
+               break;
+               case WM_DESTROY:
+                       PostQuitMessage(0);
+               break;
+               case WM_COMMAND:
+                       switch(LOWORD(wParam))
+                       {
+                               case ID_FILE_EXIT:
+                                       PostMessage(hwnd, WM_CLOSE, 0, 0);
+                               break;
+                               case ID_FILE_NEW:
+                                       CreateNewMDIChild(g_hMDIClient);
+                               break;
+                               case ID_FILE_OPEN:
+                               {
+                                       HWND hChild = CreateNewMDIChild(g_hMDIClient);
+                                       if(hChild)
+                                       {
+                                               DoFileOpen(hChild);     
+                                       }
+                               }
+                               break;
+                               case ID_FILE_CLOSE:
+                               {
+                                       HWND hChild = (HWND)SendMessage(g_hMDIClient, WM_MDIGETACTIVE,0,0);
+                                       if(hChild)
+                                       {
+                                               SendMessage(hChild, WM_CLOSE, 0, 0);
+                                       }
+                               }
+                               break;
+                               case ID_WINDOW_TILE:
+                                       SendMessage(g_hMDIClient, WM_MDITILE, 0, 0);
+                               break;
+                               case ID_WINDOW_CASCADE:
+                                       SendMessage(g_hMDIClient, WM_MDICASCADE, 0, 0);
+                               break;
+                               default:
+                               {
+                                       if(LOWORD(wParam) >= ID_MDI_FIRSTCHILD)
+                                       {
+                                               DefFrameProc(hwnd, g_hMDIClient, WM_COMMAND, wParam, lParam);
+                                       }
+                                       else 
+                                       {
+                                               HWND hChild = (HWND)SendMessage(g_hMDIClient, WM_MDIGETACTIVE,0,0);
+                                               if(hChild)
+                                               {
+                                                       SendMessage(hChild, WM_COMMAND, wParam, lParam);
+                                               }
+                                       }
+                               }
+                       }
+               break;
+               default:
+                       return DefFrameProc(hwnd, g_hMDIClient, msg, wParam, lParam);
+       }
+       return 0;
+}
+
+LRESULT CALLBACK MDIChildWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+       switch(msg)
+       {
+               case WM_CREATE:
+               {
+                       HFONT hfDefault;
+                       HWND hEdit;
+
+                       // Create Edit Control
+
+                       hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", 
+                               WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 
+                               0, 0, 100, 100, hwnd, (HMENU)IDC_CHILD_EDIT, GetModuleHandle(NULL), NULL);
+                       if(hEdit == NULL)
+                               MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
+
+                       hfDefault = GetStockObject(DEFAULT_GUI_FONT);
+                       SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
+               }
+               break;
+               case WM_MDIACTIVATE:
+               {
+                       HMENU hMenu, hFileMenu;
+                       UINT EnableFlag;
+
+                       hMenu = GetMenu(g_hMainWindow);
+                       if(hwnd == (HWND)lParam)
+                       {          //being activated, enable the menus
+                               EnableFlag = MF_ENABLED;
+                       }
+                       else
+                       {                                                  //being de-activated, gray the menus
+                               EnableFlag = MF_GRAYED;
+                       }
+
+                       EnableMenuItem(hMenu, 1, MF_BYPOSITION | EnableFlag);
+                       EnableMenuItem(hMenu, 2, MF_BYPOSITION | EnableFlag);
+
+                       hFileMenu = GetSubMenu(hMenu, 0);
+                       EnableMenuItem(hFileMenu, ID_FILE_SAVEAS, MF_BYCOMMAND | EnableFlag);
+
+                       EnableMenuItem(hFileMenu, ID_FILE_CLOSE, MF_BYCOMMAND | EnableFlag);
+                       EnableMenuItem(hFileMenu, ID_FILE_CLOSEALL, MF_BYCOMMAND | EnableFlag);
+
+                       DrawMenuBar(g_hMainWindow);
+               }
+               break;
+               case WM_COMMAND:
+                       switch(LOWORD(wParam))
+                       {
+                               case ID_FILE_OPEN:
+                                       DoFileOpen(hwnd);
+                               break;
+                               case ID_FILE_SAVEAS:
+                                       DoFileSave(hwnd);
+                               break;
+                               case ID_EDIT_CUT:
+                                       SendDlgItemMessage(hwnd, IDC_CHILD_EDIT, WM_CUT, 0, 0);
+                               break;
+                               case ID_EDIT_COPY:
+                                       SendDlgItemMessage(hwnd, IDC_CHILD_EDIT, WM_COPY, 0, 0);
+                               break;
+                               case ID_EDIT_PASTE:
+                                       SendDlgItemMessage(hwnd, IDC_CHILD_EDIT, WM_PASTE, 0, 0);
+                               break;
+                       }
+               break;
+               case WM_SIZE:
+               {
+                       HWND hEdit;
+                       RECT rcClient;
+
+                       // Calculate remaining height and size edit
+
+                       GetClientRect(hwnd, &rcClient);
+
+                       hEdit = GetDlgItem(hwnd, IDC_CHILD_EDIT);
+                       SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
+               }
+               return DefMDIChildProc(hwnd, msg, wParam, lParam);
+               default:
+                       return DefMDIChildProc(hwnd, msg, wParam, lParam);
+       
+       }
+       return 0;
+}
+
+BOOL SetUpMDIChildWindowClass(HINSTANCE hInstance)
+{
+       WNDCLASSEX wc;
+
+       wc.cbSize                = sizeof(WNDCLASSEX);
+       wc.style                 = CS_HREDRAW | CS_VREDRAW;
+       wc.lpfnWndProc   = MDIChildWndProc;
+       wc.cbClsExtra    = 0;
+       wc.cbWndExtra    = 0;
+       wc.hInstance     = hInstance;
+       wc.hIcon                 = LoadIcon(NULL, (LPCTSTR)IDI_APPLICATION);
+       wc.hCursor               = LoadCursor(NULL, (LPCTSTR)IDC_ARROW);
+       wc.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
+       wc.lpszMenuName  = NULL;
+       wc.lpszClassName = g_szChildClassName;
+       wc.hIconSm               = LoadIcon(NULL, (LPCTSTR)IDI_APPLICATION);
+
+       if(!RegisterClassEx(&wc))
+       {
+               MessageBox(0, "Could Not Register Child Window", "Oh Oh...",
+                       MB_ICONEXCLAMATION | MB_OK);
+               return FALSE;
+       }
+       else
+               return TRUE;
+}
+
+
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
+       LPSTR lpCmdLine, int nCmdShow)
+{
+       WNDCLASSEX wc;
+       HWND hwnd;
+       MSG Msg;
+
+       InitCommonControls();
+
+       wc.cbSize                = sizeof(WNDCLASSEX);
+       wc.style                 = 0;
+       wc.lpfnWndProc   = WndProc;
+       wc.cbClsExtra    = 0;
+       wc.cbWndExtra    = 0;
+       wc.hInstance     = hInstance;
+       wc.hIcon                 = LoadIcon(NULL, (LPCTSTR)IDI_APPLICATION);
+       wc.hCursor               = LoadCursor(NULL, (LPCTSTR)IDC_ARROW);
+       wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
+       wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MAINMENU);
+       wc.lpszClassName = g_szClassName;
+       wc.hIconSm               = LoadIcon(NULL, (LPCTSTR)IDI_APPLICATION);
+
+       if(!RegisterClassEx(&wc))
+       {
+               MessageBox(NULL, "Window Registration Failed!", "Error!",
+                       MB_ICONEXCLAMATION | MB_OK);
+               return 0;
+       }
+
+       if(!SetUpMDIChildWindowClass(hInstance))
+               return 0;
+
+       hwnd = CreateWindowEx(
+               0,
+               g_szClassName,
+               "MDI Test Application",
+               WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
+               CW_USEDEFAULT, CW_USEDEFAULT, 480, 320,
+               NULL, NULL, hInstance, NULL);
+
+       if(hwnd == NULL)
+       {
+               MessageBox(NULL, "Window Creation Failed!", "Error!",
+                       MB_ICONEXCLAMATION | MB_OK);
+               return 0;
+       }
+
+       g_hMainWindow = hwnd;
+
+       ShowWindow(hwnd, nCmdShow);
+       UpdateWindow(hwnd);
+
+       while(GetMessage(&Msg, NULL, 0, 0) > 0)
+       {
+               if (!TranslateMDISysAccel(g_hMDIClient, &Msg))
+               {
+                       TranslateMessage(&Msg);
+                       DispatchMessage(&Msg);
+               }
+       }
+       return Msg.wParam;
+}
diff --git a/rosapps/tests/mdi/mdi.rc b/rosapps/tests/mdi/mdi.rc
new file mode 100644 (file)
index 0000000..c22ad1f
--- /dev/null
@@ -0,0 +1,30 @@
+#include <defines.h>
+#include <reactos/resource.h>
+#include "resource.h"
+
+IDR_MAINMENU MENU DISCARDABLE 
+BEGIN
+    POPUP "&File"
+    BEGIN
+        MENUITEM "&New",                        ID_FILE_NEW
+        MENUITEM "&Open...",                    ID_FILE_OPEN
+        MENUITEM "Save &As...",                 ID_FILE_SAVEAS, GRAYED
+        MENUITEM SEPARATOR
+        MENUITEM "&Close",                      ID_FILE_CLOSE, GRAYED
+        MENUITEM SEPARATOR
+        MENUITEM "E&xit",                       ID_FILE_EXIT
+    END
+    POPUP "&Edit", GRAYED
+    BEGIN
+        MENUITEM "C&ut",                        ID_EDIT_CUT
+        MENUITEM "&Copy",                       ID_EDIT_COPY
+        MENUITEM "&Paste",                      ID_EDIT_PASTE
+    END
+    POPUP "&Window", GRAYED
+    BEGIN
+        MENUITEM "&Tile",                       ID_WINDOW_TILE
+        MENUITEM "&Cascade",                    ID_WINDOW_CASCADE
+    END
+END
+
+
diff --git a/rosapps/tests/mdi/resource.h b/rosapps/tests/mdi/resource.h
new file mode 100644 (file)
index 0000000..3ea6b7e
--- /dev/null
@@ -0,0 +1,27 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Developer Studio generated include file.
+// Used by app_four.rc
+//
+#define IDR_MAINMENU                    102
+#define ID_FILE_EXIT                    40001
+#define ID_FILE_NEW                     40002
+#define ID_FILE_OPEN                    40003
+#define ID_FILE_SAVEAS                  40005
+#define ID_WINDOW_CASCADE               40008
+#define ID_WINDOW_TILE                  40009
+#define ID_FILE_CLOSE                   40010
+#define ID_FILE_CLOSEALL                40011
+#define ID_EDIT_CUT                     40015
+#define ID_EDIT_COPY                    40016
+#define ID_EDIT_PASTE                   40017
+
+// Next default values for new objects
+// 
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE        101
+#define _APS_NEXT_COMMAND_VALUE         40020
+#define _APS_NEXT_CONTROL_VALUE         1000
+#define _APS_NEXT_SYMED_VALUE           101
+#endif
+#endif
diff --git a/rosapps/tests/miditest/.cvsignore b/rosapps/tests/miditest/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/miditest/makefile b/rosapps/tests/miditest/makefile
new file mode 100644 (file)
index 0000000..924d956
--- /dev/null
@@ -0,0 +1,23 @@
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = miditest
+
+TARGET_SDKLIBS = winmm.a
+
+TARGET_GCCLIBS =
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+TARGET_CFLAGS = -Wall -Werror
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/miditest/miditest.c b/rosapps/tests/miditest/miditest.c
new file mode 100644 (file)
index 0000000..1310be3
--- /dev/null
@@ -0,0 +1,52 @@
+#include <windows.h>
+#include <stdio.h>
+#include <mmsystem.h>
+
+// WINE's mmsystem.h doesn't seem to define these properly:
+
+#define MIDIOUTCAPS MIDIOUTCAPSA
+#define MIDIINCAPS MIDIINCAPSA
+#undef midiOutGetDevCaps
+#define midiOutGetDevCaps midiOutGetDevCapsA
+#undef midiInGetDevCaps
+#define midiInGetDevCaps midiInGetDevCapsA
+
+
+int main()
+{
+    UINT outs = midiOutGetNumDevs();
+//    UINT ins = midiInGetNumDevs();
+
+    MIDIOUTCAPS outcaps;
+//    MIDIINCAPS incaps;
+
+    int c;
+
+    printf("MIDI output devices: %d\n", outs);
+
+    for (c = 0; c < outs; c ++)
+    {
+        if (midiOutGetDevCaps(c, &outcaps, sizeof(MIDIOUTCAPS)) == MMSYSERR_NOERROR)
+            printf("Device #%d: %s\n", c, outcaps.szPname);
+    }
+
+    printf("Opening MIDI output #0\n");
+
+    HMIDIOUT Handle = NULL;
+    UINT Result = midiOutOpen(&Handle, 0, 0, 0, CALLBACK_NULL);
+    printf("Result == %d Handle == %d\n", Result, (int)Handle);
+
+    // play something:
+    midiOutShortMsg(Handle, 0x007f3090);
+
+/*
+    printf("\nMIDI input devices: %d\n", ins);
+
+    for (c = 0; c < ins; c ++)
+    {
+        midiInGetDevCaps(c, &incaps, sizeof(incaps));
+        printf("Device #%d: %s\n", c, incaps.szPname);
+    }
+*/
+    return 0;
+}
diff --git a/rosapps/tests/miditest/miditest.rc b/rosapps/tests/miditest/miditest.rc
new file mode 100644 (file)
index 0000000..c22ad1f
--- /dev/null
@@ -0,0 +1,30 @@
+#include <defines.h>
+#include <reactos/resource.h>
+#include "resource.h"
+
+IDR_MAINMENU MENU DISCARDABLE 
+BEGIN
+    POPUP "&File"
+    BEGIN
+        MENUITEM "&New",                        ID_FILE_NEW
+        MENUITEM "&Open...",                    ID_FILE_OPEN
+        MENUITEM "Save &As...",                 ID_FILE_SAVEAS, GRAYED
+        MENUITEM SEPARATOR
+        MENUITEM "&Close",                      ID_FILE_CLOSE, GRAYED
+        MENUITEM SEPARATOR
+        MENUITEM "E&xit",                       ID_FILE_EXIT
+    END
+    POPUP "&Edit", GRAYED
+    BEGIN
+        MENUITEM "C&ut",                        ID_EDIT_CUT
+        MENUITEM "&Copy",                       ID_EDIT_COPY
+        MENUITEM "&Paste",                      ID_EDIT_PASTE
+    END
+    POPUP "&Window", GRAYED
+    BEGIN
+        MENUITEM "&Tile",                       ID_WINDOW_TILE
+        MENUITEM "&Cascade",                    ID_WINDOW_CASCADE
+    END
+END
+
+
diff --git a/rosapps/tests/moztest/.cvsignore b/rosapps/tests/moztest/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/moztest/makefile b/rosapps/tests/moztest/makefile
new file mode 100644 (file)
index 0000000..4cf8b06
--- /dev/null
@@ -0,0 +1,21 @@
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = moztest
+
+TARGET_SDKLIBS = ntdll.a ws2_32.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+TARGET_CFLAGS = -D__USE_W32API -Wall -Werror
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/moztest/moztest.c b/rosapps/tests/moztest/moztest.c
new file mode 100644 (file)
index 0000000..3c4ef68
--- /dev/null
@@ -0,0 +1,250 @@
+/*
+ * Mozilla Test
+ * Copyright (C) 2004 Filip Navara
+ */
+
+#include <winsock.h>
+#include <stdio.h>
+
+ULONG DbgPrint(PCH Format,...);
+
+#define DBG(x) \
+        printf("%s:%i - %s", __FILE__, __LINE__, x); \
+        DbgPrint("%s:%i - %s", __FILE__, __LINE__, x);
+
+int SocketTest()
+{
+   /*
+    * A socket pair is often used for interprocess communication,
+    * so we need to make sure neither socket is associated with
+    * the I/O completion port; otherwise it can't be used by a
+    * child process.
+    *
+    * The default implementation below cannot be used for NT
+    * because PR_Accept would have associated the I/O completion
+    * port with the listening and accepted sockets.
+    */
+   SOCKET listenSock;
+   SOCKET osfd[2];
+   struct sockaddr_in selfAddr, peerAddr;
+   int addrLen;
+   WORD wVersionRequested;
+   WSADATA wsaData;
+   int err;
+    
+   /*
+    * Initialization.
+    */
+   
+   wVersionRequested = MAKEWORD( 2, 2 );
+    
+   DBG("Calling WSAStartup\n");
+   err = WSAStartup( wVersionRequested, &wsaData );
+   if ( err != 0 ) {
+       /* Tell the user that we could not find a usable */
+       /* WinSock DLL.                                  */
+       DBG("WSAStartup failed\n");
+       return 1;
+   }
+    
+   /* Confirm that the WinSock DLL supports 2.2.*/
+   /* Note that if the DLL supports versions greater    */
+   /* than 2.2 in addition to 2.2, it will still return */
+   /* 2.2 in wVersion since that is the version we      */
+   /* requested.                                        */
+    
+   if ( LOBYTE( wsaData.wVersion ) != 2 ||
+           HIBYTE( wsaData.wVersion ) != 2 ) {
+       /* Tell the user that we could not find a usable */
+       /* WinSock DLL.                                  */
+       DBG("WSAStartup version unacceptable\n");
+       WSACleanup( );
+       return 1; 
+   }
+    
+   /* The WinSock DLL is acceptable. Proceed. */
+
+   DBG("Calling socket\n");
+   osfd[0] = osfd[1] = INVALID_SOCKET;
+   listenSock = socket(AF_INET, SOCK_STREAM, 0);
+   if (listenSock == INVALID_SOCKET) {
+       DBG("socket failed\n");
+       goto failed;
+   }
+   
+   selfAddr.sin_family = AF_INET;
+   selfAddr.sin_port = 0;
+   selfAddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); /* BugZilla: 35408 */
+   addrLen = sizeof(selfAddr);
+   DBG("Calling bind\n");
+   if (bind(listenSock, (struct sockaddr *) &selfAddr,
+           addrLen) == SOCKET_ERROR) {
+       DBG("bind failed\n");
+       goto failed;
+   }
+
+   DBG("Calling getsockname\n");
+   if (getsockname(listenSock, (struct sockaddr *) &selfAddr,
+           &addrLen) == SOCKET_ERROR) {
+       DBG("getsockname failed\n");
+       goto failed;
+   }
+
+   DBG("Calling listen\n");
+   if (listen(listenSock, 5) == SOCKET_ERROR) {
+       DBG("listen failed\n");
+       goto failed;
+   }
+
+   DBG("Calling socket\n");
+   osfd[0] = socket(AF_INET, SOCK_STREAM, 0);
+   if (osfd[0] == INVALID_SOCKET) {
+       DBG("socket failed\n");
+       goto failed;
+   }
+   selfAddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+   /*
+    * Only a thread is used to do the connect and accept.
+    * I am relying on the fact that connect returns
+    * successfully as soon as the connect request is put
+    * into the listen queue (but before accept is called).
+    * This is the behavior of the BSD socket code.  If
+    * connect does not return until accept is called, we
+    * will need to create another thread to call connect.
+    */
+   DBG("Calling connect\n");
+   if (connect(osfd[0], (struct sockaddr *) &selfAddr,
+           addrLen) == SOCKET_ERROR) {
+       DBG("connect failed\n");
+       goto failed;
+   }
+
+   /*
+    * A malicious local process may connect to the listening
+    * socket, so we need to verify that the accepted connection
+    * is made from our own socket osfd[0].
+    */
+   DBG("Calling getsockname\n");
+   if (getsockname(osfd[0], (struct sockaddr *) &selfAddr,
+           &addrLen) == SOCKET_ERROR) {
+       DBG("getsockname failed\n");
+       goto failed;
+   }
+
+   DBG("Calling accept\n");
+   osfd[1] = accept(listenSock, (struct sockaddr *) &peerAddr, &addrLen);
+   if (osfd[1] == INVALID_SOCKET) {
+       DBG("accept failed\n");
+       goto failed;
+   }
+   if (peerAddr.sin_port != selfAddr.sin_port) {
+       /* the connection we accepted is not from osfd[0] */
+       DBG("peerAddr.sin_port != selfAddr.sin_port\n");
+       goto failed;
+   }
+
+   DBG("Hurray!\n");
+
+   closesocket(listenSock);
+
+   closesocket(osfd[0]);
+   closesocket(osfd[1]);
+
+   WSACleanup();
+
+   return 0;
+
+failed:
+   if (listenSock != INVALID_SOCKET) {
+       closesocket(listenSock);
+   }
+   if (osfd[0] != INVALID_SOCKET) {
+       closesocket(osfd[0]);
+   }
+   if (osfd[1] != INVALID_SOCKET) {
+       closesocket(osfd[1]);
+   }
+
+   WSACleanup();
+
+   return 1;
+}
+
+int VirtualTest()
+{
+   DWORD dwErr;
+   SYSTEM_INFO si;
+   HANDLE hMap;
+   PBYTE pBufferStart;
+   PCHAR pszFileName = "test.txt";
+   ULONG dwMaxSize = strlen(pszFileName);
+
+   DBG("Calling CreateFileMappingA\n");
+   hMap = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL,
+      PAGE_READWRITE | SEC_RESERVE, 0, dwMaxSize, pszFileName);
+   if (!hMap)
+   {
+      DBG("CreateFileMappingA failed\n");
+      return 1;
+   }
+
+   dwErr = GetLastError();
+   DBG("Calling MapViewOfFile\n");
+   pBufferStart = (BYTE *)MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
+   if (!pBufferStart)
+   {
+      DBG("MapViewOfFile failed\n");
+      return 1;
+   }
+
+   GetSystemInfo(&si);
+
+   if (dwErr == ERROR_ALREADY_EXISTS)
+   {
+      DBG("MapViewOfFile returned ERROR_ALREADY_EXISTS\n");
+      DBG("This really shouldn't happen, but it's not fatal.\n");
+      UnmapViewOfFile(pBufferStart);
+      CloseHandle(hMap);
+      return 1;
+   }
+   else
+   {
+      DBG("Calling VirtualAlloc\n");
+      if (!VirtualAlloc(pBufferStart, si.dwPageSize, MEM_COMMIT, PAGE_READWRITE))
+      {
+         DBG("VirtualAlloc failed\n");
+         UnmapViewOfFile(pBufferStart);
+         CloseHandle(hMap);
+         return 1;
+      }
+   }
+
+   DBG("Hurray!\n");
+
+   UnmapViewOfFile(pBufferStart);
+   CloseHandle(hMap);
+
+   return 0;
+}
+
+int main(int argc, char **argv)
+{
+   if (argc != 2)
+   {
+      printf("Usage: %s test_name\n\n", argv[0]);
+      printf("Valid test names:\n");
+      printf("\tsocket\n");
+      printf("\tvirtual\n");
+      return 0;
+   }
+
+   if (!stricmp(argv[1], "socket"))
+      return SocketTest();
+   if (!stricmp(argv[1], "virtual"))
+      return VirtualTest();
+
+   printf("Test '%s' doesn't exist\n", argv[1]);
+
+   return 0;
+}
diff --git a/rosapps/tests/mstest/.cvsignore b/rosapps/tests/mstest/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/mstest/Makefile b/rosapps/tests/mstest/Makefile
new file mode 100644 (file)
index 0000000..e60f653
--- /dev/null
@@ -0,0 +1,52 @@
+#
+#
+#
+PATH_TO_TOP = ../../../reactos
+
+include $(PATH_TO_TOP)/config
+include $(PATH_TO_TOP)/rules.mak
+
+SRV_OBJECTS = msserver.o
+CLT_OBJECTS = msclient.o
+
+PROGS = msserver.exe msclient.exe
+
+CFLAGS = $(STD_CFLAGS)
+
+LIBS = $(SDK_PATH_LIB)/kernel32.a \
+  $(SDK_PATH_LIB)/ntdll.a
+
+all: $(PROGS)
+
+.phony: all
+
+implib:
+
+clean:
+       - $(RM) *.o *.exe *.sym
+
+.phony: implib clean
+
+ifneq ($(BOOTCD_INSTALL),)
+
+install: $(PROGS:%=$(INSTALL_DIR)/%)
+
+$(PROGS:%=$(INSTALL_DIR)/%): $(INSTALL_DIR)/%: %
+       $(CP) $* $(INSTALL_DIR)/$*
+
+else # BOOTCD_INSTALL
+
+install: $(PROGS:%=$(INSTALL_DIR)/bin/%)
+
+$(PROGS:%=$(INSTALL_DIR)/bin/%): $(INSTALL_DIR)/bin/%: %
+       $(CP) $* $(INSTALL_DIR)/bin/$*
+
+endif # BOOTCD_INSTALL
+
+msserver.exe: $(SRV_OBJECTS) $(LIBS)
+       $(CC) $(SRV_OBJECTS) $(LIBS) -o msserver.exe
+       $(NM) --numeric-sort msserver.exe > msserver.sym
+
+msclient.exe: $(CLT_OBJECTS) $(LIBS)
+       $(CC) $(CLT_OBJECTS) $(LIBS) -o msclient.exe
+       $(NM) --numeric-sort msclient.exe > msclient.sym
diff --git a/rosapps/tests/mstest/msclient.c b/rosapps/tests/mstest/msclient.c
new file mode 100644 (file)
index 0000000..873148f
--- /dev/null
@@ -0,0 +1,46 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <windows.h>
+#include <tchar.h>
+
+#define BUFSIZE 1024
+#define MAILSLOT_TIMEOUT 1000
+
+
+int main(int argc, char *argv[])
+{
+   HANDLE hMailslot;
+   LPSTR lpszMailslotName = "\\\\.\\MAILSLOT\\mymailslot";
+   LPSTR lpszTestMessage = "Mailslot test message!";
+   DWORD cbLength, cbWritten;
+   
+   hMailslot = CreateFile(lpszMailslotName,
+                         GENERIC_WRITE,
+                         FILE_SHARE_READ,
+                         (LPSECURITY_ATTRIBUTES)NULL,
+                         OPEN_EXISTING,
+                         FILE_ATTRIBUTE_NORMAL,
+                         (HANDLE)NULL);
+   printf("hMailslot %x\n", (DWORD)hMailslot);
+   if (hMailslot == INVALID_HANDLE_VALUE)
+     {
+       printf("CreateFile() failed\n");
+       return 0;
+     }
+   
+   cbLength = (ULONG)strlen(lpszTestMessage)+1;
+   
+   WriteFile(hMailslot,
+            lpszTestMessage,
+            cbLength,
+            &cbWritten,
+            NULL);
+   
+   CloseHandle(hMailslot);
+   
+   return 0;
+}
+
+/* EOF */
+
diff --git a/rosapps/tests/mstest/msserver.c b/rosapps/tests/mstest/msserver.c
new file mode 100644 (file)
index 0000000..939c0aa
--- /dev/null
@@ -0,0 +1,40 @@
+
+
+#include <windows.h>
+
+
+int main(int argc, char *argv[])
+{
+   HANDLE hMailslot;
+   CHAR chBuf[512];
+   BOOL fResult;
+   DWORD cbRead;
+   LPTSTR lpszMailslotName = "\\\\.\\mailslot\\mymailslot";
+
+   hMailslot = CreateMailslot(lpszMailslotName,
+                             512,
+                             MAILSLOT_WAIT_FOREVER,
+                             NULL);
+for (;;)
+{
+   fResult = ReadFile(hMailslot,
+                     chBuf,
+                     512,
+                     &cbRead,
+                     NULL);
+   if (fResult == FALSE)
+     {
+       printf("ReadFile() failed!\n");
+       CloseHandle(hMailslot);
+       return 0;
+     }
+
+   printf("Data read: %s\n", chBuf);
+}
+
+   CloseHandle(hMailslot);
+
+   return 0;
+}
+
+/* EOF */
diff --git a/rosapps/tests/multithrdwin/.cvsignore b/rosapps/tests/multithrdwin/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/multithrdwin/makefile b/rosapps/tests/multithrdwin/makefile
new file mode 100644 (file)
index 0000000..0fcf9ef
--- /dev/null
@@ -0,0 +1,23 @@
+# $Id: makefile,v 1.1 2004/10/21 04:58:59 sedwards Exp $
+
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = windows
+
+TARGET_NAME = multithrdwin
+
+TARGET_SDKLIBS = kernel32.a gdi32.a ntdll.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+TARGET_CFLAGS = -Wall -Werror
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/multithrdwin/multithrdwin.c b/rosapps/tests/multithrdwin/multithrdwin.c
new file mode 100644 (file)
index 0000000..fa7e838
--- /dev/null
@@ -0,0 +1,236 @@
+#include <windows.h>
+#include <stdio.h>
+
+typedef struct _THRDCREATEWIN
+{
+  HANDLE hThread;
+  DWORD ThreadId;
+  LPSTR Caption;
+  HWND *Parent;
+  HWND Window;
+  DWORD Style;
+  POINT Position;
+  SIZE Size;
+} THRDCREATEWIN, *PTHRDCREATEWIN;
+
+static HINSTANCE hAppInstance;
+static HANDLE WinCreatedEvent;
+static THRDCREATEWIN wnds[3];
+
+LRESULT WINAPI MultiWndProc(HWND, UINT, WPARAM, LPARAM);
+
+DWORD WINAPI
+WindowThreadProc(LPVOID lpParameter)
+{
+  MSG msg;
+  char caption[64];
+  PTHRDCREATEWIN cw = (PTHRDCREATEWIN)lpParameter;
+  
+  sprintf(caption, cw->Caption, GetCurrentThreadId());
+  
+  cw->Window = CreateWindow("MultiClass",
+                            caption,
+                            cw->Style | WS_VISIBLE,
+                            cw->Position.x,
+                            cw->Position.y,
+                            cw->Size.cx,
+                            cw->Size.cy,
+                            (cw->Parent ? *(cw->Parent) : 0),
+                            NULL,
+                            hAppInstance,
+                            NULL);
+  
+  SetEvent(WinCreatedEvent);
+  
+  if(!cw->Window)
+  {
+    fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n",
+            GetLastError());
+    return 1;
+  }
+  CreateWindow("BUTTON","Sleep",WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_GROUP|BS_PUSHBUTTON, 10, 10, 70, 23, cw->Window, (PVOID)1, hAppInstance, NULL);
+  CreateWindow("BUTTON","1",WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_GROUP|BS_PUSHBUTTON, 83, 10, 20, 23, cw->Window, (PVOID)2, hAppInstance, NULL);
+  CreateWindow("BUTTON","2",WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_GROUP|BS_PUSHBUTTON, 105, 10, 20, 23, cw->Window, (PVOID)3, hAppInstance, NULL);
+  CreateWindow("BUTTON","3",WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_GROUP|BS_PUSHBUTTON, 127, 10, 20, 23, cw->Window, (PVOID)4, hAppInstance, NULL);
+  while(GetMessage(&msg, NULL, 0, 0))
+  {
+    TranslateMessage(&msg);
+    DispatchMessage(&msg);
+  }
+  
+  return 0;
+}
+
+int WINAPI 
+WinMain(HINSTANCE hInstance,
+       HINSTANCE hPrevInstance,
+       LPSTR lpszCmdLine,
+       int nCmdShow)
+{
+  WNDCLASS wc;
+  int i;
+  HANDLE Threads[3];
+  
+  hAppInstance = hInstance;
+  
+  WinCreatedEvent = CreateEvent(NULL,
+                                FALSE,
+                                FALSE,
+                                NULL);
+  
+  if(!WinCreatedEvent)
+  {
+    fprintf(stderr, "Failed to create event (last error 0x%lX)\n",
+            GetLastError());
+    return 1;
+  }
+
+  wc.lpszClassName = "MultiClass";
+  wc.lpfnWndProc = MultiWndProc;
+  wc.style = CS_VREDRAW | CS_HREDRAW;
+  wc.hInstance = hInstance;
+  wc.hIcon = LoadIcon(NULL, (LPCTSTR) IDI_APPLICATION);
+  wc.hCursor = LoadCursor(NULL, (LPCTSTR) IDC_ARROW);
+  wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
+  wc.lpszMenuName = NULL;
+  wc.cbClsExtra = 0;
+  wc.cbWndExtra = 0;
+  if (RegisterClass(&wc) == 0)
+    {
+      fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n",
+             GetLastError());
+      return(1);
+    }
+
+  wnds[0].Caption = "TopLevel1 (ThreadID: %d)";
+  wnds[0].Parent = NULL;
+  wnds[0].Style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
+  wnds[0].Position.x = wnds[0].Position.y = 0;
+  wnds[0].Size.cx = 320;
+  wnds[0].Size.cy = 240;
+  
+  wnds[1].Caption = "Child1 of TopLevel1 (ThreadID: %d)";
+  wnds[1].Parent = &wnds[0].Window;
+  wnds[1].Style = WS_CHILD | WS_BORDER | WS_CAPTION | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
+  wnds[1].Position.x = 20;
+  wnds[1].Position.y = 120;
+  wnds[1].Size.cx = wnds[1].Size.cy = 240;
+  
+  wnds[2].Caption = "TopLevel2 (ThreadID: %d)";
+  wnds[2].Parent = NULL;
+  wnds[2].Style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
+  wnds[2].Position.x = 400;
+  wnds[2].Position.y = 0;
+  wnds[2].Size.cx = 160;
+  wnds[2].Size.cy = 490;
+  
+  for(i = 0; i < (sizeof(wnds) / sizeof(THRDCREATEWIN)); i++)
+  {
+    wnds[i].hThread = CreateThread(NULL,
+                                   0,
+                                   WindowThreadProc,
+                                   &wnds[i],
+                                   0,
+                                   &wnds[i].ThreadId);
+    Threads[i] = wnds[i].hThread;
+    if(!wnds[i].hThread)
+    {
+      fprintf(stderr, "CreateThread #%i failed (last error 0x%lX)\n",
+              i, GetLastError());
+      return 1;
+    }
+    WaitForSingleObject(WinCreatedEvent, INFINITE);
+  }
+  
+  WaitForMultipleObjects(sizeof(Threads) / sizeof(HANDLE), &Threads[0], TRUE, INFINITE);
+  
+  UnregisterClass("MultiClass", hInstance);
+  
+  return 0;
+}
+
+LRESULT CALLBACK MultiWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+  PAINTSTRUCT ps;
+  HDC hDC;
+  RECT Client;
+  HBRUSH Brush;
+  DWORD Ret;
+  
+  static COLORREF Colors[] =
+    {
+      RGB(0x00, 0x00, 0x00),
+      RGB(0x80, 0x00, 0x00),
+      RGB(0x00, 0x80, 0x00),
+      RGB(0x00, 0x00, 0x80),
+      RGB(0x80, 0x80, 0x00),
+      RGB(0x80, 0x00, 0x80),
+      RGB(0x00, 0x80, 0x80),
+      RGB(0x80, 0x80, 0x80),
+      RGB(0xff, 0x00, 0x00),
+      RGB(0x00, 0xff, 0x00),
+      RGB(0x00, 0x00, 0xff),
+      RGB(0xff, 0xff, 0x00),
+      RGB(0xff, 0x00, 0xff),
+      RGB(0x00, 0xff, 0xff),
+      RGB(0xff, 0xff, 0xff)
+    };
+  static unsigned CurrentColor = 0;
+
+  switch(msg)
+    {
+      case WM_PAINT:
+       hDC = BeginPaint(hWnd, &ps);
+       GetClientRect(hWnd, &Client);
+       Brush = CreateSolidBrush(Colors[CurrentColor]);
+       FillRect(hDC, &Client, Brush);
+       DeleteObject(Brush);
+       CurrentColor++;
+       if (sizeof(Colors) / sizeof(Colors[0]) <= CurrentColor)
+         {
+           CurrentColor = 0;
+         }
+       EndPaint(hWnd, &ps);
+       break;
+      
+      case WM_COMMAND:
+        switch(LOWORD(wParam))
+        {
+          case 1:
+            Sleep(20000);
+            break;
+          case 2:
+          case 3:
+          case 4:
+            if(SendMessageTimeout(wnds[LOWORD(wParam) - 2].Window, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 1000, &Ret))
+            {
+              DbgPrint("SendMessageTimeout() OK");
+              MessageBox(hWnd, "SendMessageTimeout() OK", NULL, 0);
+            }
+            else
+            {
+              if(GetLastError() == ERROR_TIMEOUT)
+              {
+                DbgPrint("SendMessageTimeout() Timeout");
+                MessageBox(hWnd, "SendMessageTimeout() Timeout", NULL, 0);
+              }
+              else
+              {
+                DbgPrint("SendMessageTimeout() Failed");
+                MessageBox(hWnd, "SendMessageTimeout() Failed", NULL, 0);
+              }
+            }
+            break;
+        }
+        break;
+      
+      case WM_DESTROY:
+       PostQuitMessage(0);
+       break;
+
+      default:
+       return DefWindowProc(hWnd, msg, wParam, lParam);
+    }
+
+  return 0;
+}
diff --git a/rosapps/tests/multiwin/.cvsignore b/rosapps/tests/multiwin/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/multiwin/makefile b/rosapps/tests/multiwin/makefile
new file mode 100644 (file)
index 0000000..4b20bd8
--- /dev/null
@@ -0,0 +1,23 @@
+# $Id: makefile,v 1.1 2004/10/21 04:59:00 sedwards Exp $
+
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = windows
+
+TARGET_NAME = multiwin
+
+TARGET_SDKLIBS = kernel32.a gdi32.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+TARGET_CFLAGS = -Wall -Werror
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/multiwin/multiwin.c b/rosapps/tests/multiwin/multiwin.c
new file mode 100644 (file)
index 0000000..12b6b26
--- /dev/null
@@ -0,0 +1,147 @@
+#include <windows.h>
+#include <stdio.h>
+
+static UINT WindowCount;
+LRESULT WINAPI MultiWndProc(HWND, UINT, WPARAM, LPARAM);
+
+int WINAPI 
+WinMain(HINSTANCE hInstance,
+       HINSTANCE hPrevInstance,
+       LPSTR lpszCmdLine,
+       int nCmdShow)
+{
+  WNDCLASS wc;
+  MSG msg;
+  HWND hWnd1;
+  HWND hWnd2;
+  HWND hWndChild;
+
+  wc.lpszClassName = "MultiClass";
+  wc.lpfnWndProc = MultiWndProc;
+  wc.style = CS_VREDRAW | CS_HREDRAW;
+  wc.hInstance = hInstance;
+  wc.hIcon = LoadIcon(NULL, (LPCTSTR) IDI_APPLICATION);
+  wc.hCursor = LoadCursor(NULL, (LPCTSTR) IDC_ARROW);
+  wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
+  wc.lpszMenuName = NULL;
+  wc.cbClsExtra = 0;
+  wc.cbWndExtra = 0;
+  if (RegisterClass(&wc) == 0)
+    {
+      fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n",
+             GetLastError());
+      return(1);
+    }
+
+  hWnd1 = CreateWindow("MultiClass",
+                     "TopLevel1",
+                     WS_OVERLAPPEDWINDOW,
+                     0,
+                     0,
+                     320,
+                     240,
+                     NULL,
+                     NULL,
+                     hInstance,
+                     NULL);
+
+  hWndChild = CreateWindow("MultiClass",
+                     "Child1 of TopLevel1",
+                     WS_CHILD | WS_BORDER | WS_CAPTION | WS_VISIBLE | WS_SYSMENU,
+                     20,
+                     120,
+                     200,
+                     200,
+                     hWnd1,
+                     NULL,
+                     hInstance,
+                     NULL);
+
+  hWnd2 = CreateWindow("MultiClass",
+                     "TopLevel2",
+                     WS_OVERLAPPEDWINDOW,
+                     400,
+                     0,
+                     160,
+                     490,
+                     NULL,
+                     NULL,
+                     hInstance,
+                     NULL);
+
+  if (! hWnd1 || ! hWnd2 || ! hWndChild)
+    {
+      fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n",
+             GetLastError());
+      return(1);
+    }
+  WindowCount = 2;
+
+  ShowWindow(hWnd1, SW_NORMAL);
+  ShowWindow(hWnd2, SW_NORMAL);
+
+  while(GetMessage(&msg, NULL, 0, 0))
+  {
+    TranslateMessage(&msg);
+    DispatchMessage(&msg);
+  }
+  return msg.wParam;
+}
+
+LRESULT CALLBACK MultiWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+  PAINTSTRUCT ps;
+  HDC hDC;
+  LONG Style;
+  RECT Client;
+  HBRUSH Brush;
+  static COLORREF Colors[] =
+    {
+      RGB(0x00, 0x00, 0x00),
+      RGB(0x80, 0x00, 0x00),
+      RGB(0x00, 0x80, 0x00),
+      RGB(0x00, 0x00, 0x80),
+      RGB(0x80, 0x80, 0x00),
+      RGB(0x80, 0x00, 0x80),
+      RGB(0x00, 0x80, 0x80),
+      RGB(0x80, 0x80, 0x80),
+      RGB(0xff, 0x00, 0x00),
+      RGB(0x00, 0xff, 0x00),
+      RGB(0x00, 0x00, 0xff),
+      RGB(0xff, 0xff, 0x00),
+      RGB(0xff, 0x00, 0xff),
+      RGB(0x00, 0xff, 0xff),
+      RGB(0xff, 0xff, 0xff)
+    };
+  static unsigned CurrentColor = 0;
+
+  switch(msg)
+    {
+      case WM_PAINT:
+       hDC = BeginPaint(hWnd, &ps);
+       GetClientRect(hWnd, &Client);
+       Brush = CreateSolidBrush(Colors[CurrentColor]);
+       FillRect(hDC, &Client, Brush);
+       DeleteObject(Brush);
+       CurrentColor++;
+       if (sizeof(Colors) / sizeof(Colors[0]) <= CurrentColor)
+         {
+           CurrentColor = 0;
+         }
+       EndPaint(hWnd, &ps);
+       break;
+
+      case WM_DESTROY:
+       Style = GetWindowLong(hWnd, GWL_STYLE);
+       if (0 == (Style & WS_CHILD) && 0 == --WindowCount)
+         {
+           PostQuitMessage(0);
+         }
+       break;
+
+      default:
+       return DefWindowProc(hWnd, msg, wParam, lParam);
+    }
+
+  return 0;
+}
diff --git a/rosapps/tests/mutex/.cvsignore b/rosapps/tests/mutex/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/mutex/makefile b/rosapps/tests/mutex/makefile
new file mode 100644 (file)
index 0000000..db5b180
--- /dev/null
@@ -0,0 +1,24 @@
+#
+# $Id: makefile,v 1.1 2004/10/21 04:59:00 sedwards Exp $
+
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = mutex
+
+TARGET_SDKLIBS = ntdll.a kernel32.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+TARGET_CFLAGS = -Wall -Werror
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/mutex/mutex.c b/rosapps/tests/mutex/mutex.c
new file mode 100644 (file)
index 0000000..0597d27
--- /dev/null
@@ -0,0 +1,122 @@
+#include <ddk/ntddk.h>
+#include <windows.h>
+#include <string.h>
+#include <stdio.h>
+
+
+HANDLE OutputHandle;
+HANDLE InputHandle;
+
+HANDLE hThread[2];
+DWORD dwCounter = 0;
+HANDLE hMutex;
+
+
+void dprintf(char* fmt, ...)
+{
+   va_list args;
+   char buffer[255];
+
+   va_start(args,fmt);
+   vsprintf(buffer,fmt,args);
+   WriteConsoleA(OutputHandle, buffer, strlen(buffer), NULL, NULL);
+   va_end(args);
+}
+
+
+DWORD WINAPI thread1(LPVOID crap)
+{
+  DWORD dwError = 0;
+  DWORD i;
+
+  dprintf("Thread 1 running!\n");
+
+  for (i = 0; i < 10; i++)
+    {
+      dwError = WaitForSingleObject(hMutex, INFINITE);
+      if (dwError == WAIT_FAILED)
+       {
+         dprintf("Thread2: WaitForSingleObject failed!\n");
+         return 1;
+       }
+      else if (dwError == WAIT_ABANDONED_0)
+       {
+         dprintf("Thread2: WaitForSingleObject returned WAIT_ABANDONED_0\n");
+       }
+
+      dprintf("Thread1: dwCounter : %lu -->", dwCounter);
+      dwCounter++;
+      dprintf(" %lu\n", dwCounter);
+      ReleaseMutex(hMutex);
+    }
+
+  dprintf("Thread 1 done!\n");
+
+  return 1;
+}
+
+DWORD WINAPI thread2(LPVOID crap)
+{
+  DWORD dwError = 0;
+  DWORD i;
+  dprintf("Thread 2 running!\n");
+
+  for (i = 0; i < 10; i++)
+    {
+      dwError = WaitForSingleObject(hMutex, INFINITE);
+      if (dwError == WAIT_FAILED)
+       {
+         dprintf("Thread2: WaitForSingleObject failed!\n");
+         return 1;
+       }
+      else if (dwError == WAIT_ABANDONED_0)
+       {
+         dprintf("Thread2: WaitForSingleObject returned WAIT_ABANDONED_0\n");
+       }
+
+      dprintf("Thread2: dwCounter : %lu -->", dwCounter);
+      dwCounter++;
+      dprintf(" %lu\n", dwCounter);
+      ReleaseMutex(hMutex);
+    }
+
+  dprintf("Thread 2 done!\n");
+
+  return 1;
+}
+
+
+int main(int argc, char* argv[])
+{
+  DWORD dwError;
+  DWORD id1,id2;
+
+  AllocConsole();
+  InputHandle = GetStdHandle(STD_INPUT_HANDLE);
+  OutputHandle =  GetStdHandle(STD_OUTPUT_HANDLE);
+
+  dprintf("Calling CreateMutex()\n");
+  hMutex = CreateMutexW(NULL, FALSE, L"TestMutex");
+  if (hMutex == INVALID_HANDLE_VALUE)
+    {
+      dprintf("CreateMutex() failed! Error: %lu\n", GetLastError());
+      return 0;
+    }
+  dprintf("CreateMutex() succeeded!\n");
+
+  hThread[0] = CreateThread(0, 0, thread1, 0, 0, &id1);
+  hThread[1] = CreateThread(0, 0, thread2, 0, 0, &id2);
+
+  dprintf("Calling WaitForMultipleObject()\n");
+  dwError = WaitForMultipleObjects(2, hThread, TRUE, INFINITE);
+  dprintf("WaitForMultipleObject() Error: %lu\n", dwError);
+
+  CloseHandle(hThread[0]);
+  CloseHandle(hThread[1]);
+
+  CloseHandle(hMutex);
+
+  dprintf("Main thread done!\n");
+
+  return 0;
+}
diff --git a/rosapps/tests/nameserverlist/.cvsignore b/rosapps/tests/nameserverlist/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/nameserverlist/makefile b/rosapps/tests/nameserverlist/makefile
new file mode 100644 (file)
index 0000000..f74ed4e
--- /dev/null
@@ -0,0 +1,22 @@
+
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = nameserverlist
+
+TARGET_SDKLIBS = iphlpapi.a ws2_32.a kernel32.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+TARGET_CFLAGS = -D__USE_W32API -Wall -Werror -g
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/nameserverlist/nameserverlist.c b/rosapps/tests/nameserverlist/nameserverlist.c
new file mode 100644 (file)
index 0000000..9faab02
--- /dev/null
@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <winsock2.h>
+#include <iphlpapi.h>
+
+int main( int argc, char **argv ) {
+  ULONG OutBufLen = 0;
+  PFIXED_INFO pFixedInfo;
+  PIP_ADDR_STRING Addr;
+
+  GetNetworkParams(NULL, &OutBufLen);
+  pFixedInfo = malloc(OutBufLen);
+  if (!pFixedInfo) {
+    printf( "Failed to alloc %d bytes.\n", (int)OutBufLen );
+    return 1;
+  }
+
+  printf( "%d Bytes allocated\n", (int)OutBufLen );
+
+  GetNetworkParams(pFixedInfo,&OutBufLen);
+
+  for( Addr = &pFixedInfo->DnsServerList; 
+       Addr;
+       Addr = Addr->Next ) {
+    printf( "%c%s\n", 
+           Addr == pFixedInfo->CurrentDnsServer ? '*' : ' ',
+           Addr->IpAddress.String );
+  }
+
+  free( pFixedInfo );
+  return 0;
+}
diff --git a/rosapps/tests/noexecute/.cvsignore b/rosapps/tests/noexecute/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/noexecute/makefile b/rosapps/tests/noexecute/makefile
new file mode 100644 (file)
index 0000000..c4191c2
--- /dev/null
@@ -0,0 +1,32 @@
+#
+# $Id: makefile,v 1.1 2004/10/21 04:59:00 sedwards Exp $
+#
+
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = noexecute
+
+TARGET_SDKLIBS = pseh.a
+
+TARGET_PCH = 
+
+TARGET_OBJECTS = \
+       noexecute.o 
+
+TARGET_CFLAGS =   -Wall -Werror -D__USE_W32API
+
+DEP_OBJECTS = $(TARGET_OBJECTS)
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+include $(TOOLS_PATH)/depend.mk
+
+# EOF
diff --git a/rosapps/tests/noexecute/noexecute.c b/rosapps/tests/noexecute/noexecute.c
new file mode 100644 (file)
index 0000000..aca7050
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * $Id: noexecute.c,v 1.1 2004/10/21 04:59:00 sedwards Exp $
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <windows.h>
+
+#include <pseh.h>
+
+int test(int x)
+{
+    return x+1;
+}
+
+void execute(char* message, int(*func)(int))
+{
+   ULONG status = 0;
+   ULONG result;
+
+   printf("%s ... ", message);
+
+   _SEH_TRY
+   {
+      result = func(1);
+   }
+   _SEH_HANDLE
+   {
+      status = _SEH_GetExceptionCode();
+   }
+   _SEH_END;
+   if (status == 0)
+   {
+       printf("OK.\n");
+   }
+   else
+   {
+       printf("Error, status=%lx.\n", status);
+   }
+}
+
+char data[100];
+
+int main(void)
+{
+    unsigned char stack[100];
+    void* heap;
+    ULONG protection;
+
+    printf("NoExecute\n");
+
+    execute("Executing within the code segment", test);
+    memcpy(data, test, 100);
+    execute("Executing within the data segment", (int(*)(int))data);
+    memcpy(stack, test, 100);
+    execute("Executing on stack segment", (int(*)(int))stack);
+    heap = VirtualAlloc(NULL, 100, MEM_COMMIT, PAGE_READWRITE);
+    memcpy(heap, test, 100);
+    execute("Executing on the heap with protection PAGE_READWRITE", (int(*)(int))heap);
+    VirtualProtect(heap, 100, PAGE_EXECUTE, &protection);
+    execute("Executing on the heap with protection PAGE_EXECUTE", (int(*)(int))heap);
+
+    return 0;
+}
diff --git a/rosapps/tests/nptest/.cvsignore b/rosapps/tests/nptest/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/nptest/Makefile b/rosapps/tests/nptest/Makefile
new file mode 100644 (file)
index 0000000..783534c
--- /dev/null
@@ -0,0 +1,51 @@
+#
+#
+#
+PATH_TO_TOP = ../../../reactos
+
+include $(PATH_TO_TOP)/config
+include $(PATH_TO_TOP)/rules.mak
+
+SRV_OBJECTS = npserver.o
+CLT_OBJECTS = npclient.o
+
+PROGS = npserver.exe npclient.exe
+
+CFLAGS = $(STD_CFLAGS)
+
+LIBS = $(SDK_PATH_LIB)/kernel32.a
+
+all: $(PROGS)
+
+.phony: all
+
+implib:
+
+clean:
+       - $(RM) *.o *.exe *.sym
+
+.phony: implib clean
+
+ifneq ($(BOOTCD_INSTALL),)
+
+install: $(PROGS:%=$(INSTALL_DIR)/%)
+
+$(PROGS:%=$(INSTALL_DIR)/%): $(INSTALL_DIR)/%: %
+       $(CP) $* $(INSTALL_DIR)/$*
+
+else # BOOTCD_INSTALL
+
+install: $(PROGS:%=$(INSTALL_DIR)/bin/%)
+
+$(PROGS:%=$(INSTALL_DIR)/bin/%): $(INSTALL_DIR)/bin/%: %
+       $(CP) $* $(INSTALL_DIR)/bin/$*
+
+endif # BOOTCD_INSTALL
+
+npserver.exe: $(SRV_OBJECTS) $(LIBS)
+       $(CC) $(SRV_OBJECTS) $(LIBS) -o npserver.exe
+       $(NM) --numeric-sort npserver.exe > npserver.sym
+
+npclient.exe: $(CLT_OBJECTS) $(LIBS)
+       $(CC) $(CLT_OBJECTS) $(LIBS) -o npclient.exe
+       $(NM) --numeric-sort npclient.exe > npclient.sym
diff --git a/rosapps/tests/nptest/npclient.c b/rosapps/tests/nptest/npclient.c
new file mode 100644 (file)
index 0000000..6d93f3a
--- /dev/null
@@ -0,0 +1,100 @@
+#include <windows.h>
+
+VOID MyErrExit(LPTSTR Message)
+{
+//     MessageBox(NULL, Message, NULL, MB_OK);
+   puts(Message);
+   ExitProcess(0);
+}
+
+int main(int argc, char *argv[])
+{
+   HANDLE hPipe;
+   LPVOID lpvMessage;
+   CHAR chBuf[512];
+   BOOL fSuccess;
+   DWORD cbRead, cbWritten, dwMode;
+   LPTSTR lpszPipename = "\\\\.\\pipe\\mynamedpipe";
+
+// Try to open a named pipe; wait for it, if necessary.
+
+   while (1)
+   {
+      hPipe = CreateFile(
+         lpszPipename,   // pipe name
+         GENERIC_READ |  // read and write access
+         GENERIC_WRITE,
+         0,              // no sharing
+         NULL,           // no security attributes
+         OPEN_EXISTING,  // opens existing pipe
+         0,              // default attributes
+         NULL);          // no template file
+
+   // Break if the pipe handle is valid.
+
+      if (hPipe != INVALID_HANDLE_VALUE)
+         break;
+
+      // Exit if an error other than ERROR_PIPE_BUSY occurs.
+
+      if (GetLastError() != ERROR_PIPE_BUSY)
+         MyErrExit("Could not open pipe");
+
+      // All pipe instances are busy, so wait for 20 seconds.
+
+      if (! WaitNamedPipe(lpszPipename, 20000) )
+         MyErrExit("Could not open pipe");
+   }
+
+// The pipe connected; change to message-read mode.
+
+   dwMode = PIPE_READMODE_MESSAGE;
+   fSuccess = SetNamedPipeHandleState(
+      hPipe,    // pipe handle
+      &dwMode,  // new pipe mode
+      NULL,     // don't set maximum bytes
+      NULL);    // don't set maximum time
+   if (!fSuccess)
+      MyErrExit("SetNamedPipeHandleState");
+
+// Send a message to the pipe server.
+
+   lpvMessage = (argc > 1) ? argv[1] : "default message";
+
+   fSuccess = WriteFile(
+      hPipe,                  // pipe handle
+      lpvMessage,             // message
+      strlen(lpvMessage) + 1, // message length
+      &cbWritten,             // bytes written
+      NULL);                  // not overlapped
+   if (! fSuccess)
+      MyErrExit("WriteFile");
+
+   do
+   {
+   // Read from the pipe.
+
+      fSuccess = ReadFile(
+         hPipe,    // pipe handle
+         chBuf,    // buffer to receive reply
+         512,      // size of buffer
+         &cbRead,  // number of bytes read
+         NULL);    // not overlapped
+
+      if (! fSuccess && GetLastError() != ERROR_MORE_DATA)
+         break;
+
+      // Reply from the pipe is written to STDOUT.
+
+      if (! WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),
+         chBuf, cbRead, &cbWritten, NULL))
+      {
+         break;
+      }
+
+   } while (! fSuccess);  // repeat loop if ERROR_MORE_DATA
+
+   CloseHandle(hPipe);
+
+   return 0;
+}
diff --git a/rosapps/tests/nptest/npserver.c b/rosapps/tests/nptest/npserver.c
new file mode 100644 (file)
index 0000000..0969b42
--- /dev/null
@@ -0,0 +1,120 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <windows.h>
+#include <tchar.h>
+
+#define BUFSIZE 1024
+#define PIPE_TIMEOUT 1000
+
+VOID InstanceThread (LPVOID);
+
+VOID
+GetAnswerToRequest(LPTSTR lpRequest,
+                  LPTSTR lpReply,
+                  LPDWORD lpcbReplyBytes)
+{
+}
+
+VOID MyErrExit(LPTSTR Message)
+{
+//     MessageBox(NULL, Message, NULL, MB_OK);
+   puts(Message);
+   ExitProcess(0);
+}
+
+
+
+
+int xx = 0;
+
+int main(int argc, char *argv[])
+{
+   BOOL fConnected;
+   DWORD dwThreadId;
+   HANDLE hPipe, hThread;
+   LPTSTR lpszPipename = TEXT("\\\\.\\pipe\\mynamedpipe");
+
+//   for (;;)
+//     {
+       hPipe = CreateNamedPipe(lpszPipename,
+                               PIPE_ACCESS_DUPLEX,
+                               PIPE_TYPE_MESSAGE |
+                               PIPE_READMODE_MESSAGE |
+                               PIPE_WAIT,
+                               PIPE_UNLIMITED_INSTANCES,
+                               BUFSIZE,
+                               BUFSIZE,
+                               PIPE_TIMEOUT,
+                               NULL);
+       if (hPipe == INVALID_HANDLE_VALUE)
+         {
+            printf("CreateNamedPipe() failed\n");
+            return 0;
+         }
+
+       fConnected = ConnectNamedPipe(hPipe,
+                                     NULL) ? TRUE : (GetLastError () ==
+                                           ERROR_PIPE_CONNECTED);
+       if (fConnected)
+         {
+            printf("Pipe connected!\n");
+
+            DisconnectNamedPipe(hPipe);
+
+#if 0
+            hThread = CreateThread(NULL,
+                                   0,
+                                   (LPTHREAD_START_ROUTINE) InstanceThread,
+                                   (LPVOID) hPipe,
+                                   0,
+                                   &dwThreadId);
+            if (hThread == NULL)
+              MyErrExit("CreateThread");
+#endif
+         }
+       else
+         {
+//          CloseHandle(hPipe);
+         }
+//     }
+
+   CloseHandle(hPipe);
+
+   return 0;
+}
+
+VOID InstanceThread (LPVOID lpvParam)
+{
+   CHAR chRequest[BUFSIZE];
+   CHAR chReply[BUFSIZE];
+   DWORD cbBytesRead, cbReplyBytes, cbWritten;
+   BOOL fSuccess;
+   HANDLE hPipe;
+   
+   hPipe = (HANDLE)lpvParam;
+   while (1)
+     {
+       fSuccess = ReadFile(hPipe,
+                           chRequest,
+                           BUFSIZE,
+                           &cbBytesRead,
+                           NULL);
+       if (!fSuccess || cbBytesRead == 0)
+         break;
+
+       GetAnswerToRequest(chRequest, chReply, &cbReplyBytes);
+
+       fSuccess = WriteFile(hPipe,
+                            chReply,
+                            cbReplyBytes,
+                            &cbWritten,
+                            NULL);
+       if (!fSuccess || cbReplyBytes != cbWritten)
+         break;
+    }
+
+   FlushFileBuffers(hPipe);
+   DisconnectNamedPipe(hPipe);
+   CloseHandle(hPipe);
+}
diff --git a/rosapps/tests/oskittcp/.cvsignore b/rosapps/tests/oskittcp/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/oskittcp/cmd_oskit.py b/rosapps/tests/oskittcp/cmd_oskit.py
new file mode 100644 (file)
index 0000000..e1fac17
--- /dev/null
@@ -0,0 +1,10 @@
+from socket import *
+import sys
+
+s = socket(AF_INET,SOCK_DGRAM,0)
+s.connect(('localhost',5001))
+
+while 1:
+       sys.stdout.write('>> ')
+       line = sys.stdin.readline()
+       s.send('CMD ' + line)
\ No newline at end of file
diff --git a/rosapps/tests/oskittcp/makefile b/rosapps/tests/oskittcp/makefile
new file mode 100644 (file)
index 0000000..33d004b
--- /dev/null
@@ -0,0 +1,28 @@
+#
+# $Id: makefile,v 1.1 2004/10/21 04:59:00 sedwards Exp $
+
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = oskittcp
+
+TARGET_SDKLIBS = ws2_32.a oskittcp.a ntdll.a 
+
+TARGET_OBJECTS = tcptest.o
+
+TARGET_CPPFLAGS =  -I$(PATH_TO_TOP)/drivers/lib/oskittcp/include -I$(PATH_TO_TOP)/w32api/include -I$(PATH_TO_TOP)/include -g
+
+TARGET_GCCLIBS = stdc++
+
+TARGET_LDFLAGS = -g
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/oskittcp/tcptest.cpp b/rosapps/tests/oskittcp/tcptest.cpp
new file mode 100644 (file)
index 0000000..8760ef9
--- /dev/null
@@ -0,0 +1,380 @@
+#ifdef _MSC_VER
+#pragma warning ( disable : 4786 )
+#endif//_MSC_VER
+
+#include <list>
+#include <string>
+#include <sstream>
+#include <malloc.h>
+extern "C" {
+    typedef unsigned short u_short;
+#include <stdio.h>
+#include <oskittcp.h>
+#include <windows.h>
+#ifndef _MSC_VER
+#include <winsock2.h>
+#endif//_MSC_VER
+};
+
+unsigned char hwaddr[6] = { 0x08, 0x00, 0x20, 0x0b, 0xb7, 0xbb };
+
+#undef malloc
+#undef free
+
+unsigned long TCP_IPIdentification;
+
+#define MAX_DG_SIZE 0x10000
+#define TI_DbgPrint(x,y) printf y
+
+std::list<std::string> output_packets;
+
+typedef struct _CONNECTION_ENDPOINT {
+    OSK_UINT State;
+} CONNECTION_ENDPOINT, *PCONNECTION_ENDPOINT;
+
+extern "C" int is_stack_ptr ( const void* p )
+{
+       MEMORY_BASIC_INFORMATION mbi1, mbi2;
+       VirtualQuery ( p, &mbi1, sizeof(mbi1) );
+       VirtualQuery ( _alloca(1), &mbi2, sizeof(mbi2) );
+       return mbi1.AllocationBase == mbi2.AllocationBase;
+}
+
+int TCPSocketState(void *ClientData,
+                  void *WhichSocket, 
+                  void *WhichConnection,
+                  OSK_UINT NewState ) {
+    PCONNECTION_ENDPOINT Connection = (PCONNECTION_ENDPOINT)WhichConnection;
+    //PLIST_ENTRY Entry;
+
+    TI_DbgPrint(MID_TRACE,("Called: NewState %x\n", NewState));
+
+    if( !Connection ) {
+       TI_DbgPrint(MID_TRACE,("Socket closing.\n"));
+       return 0;
+    }
+
+    if( (NewState & SEL_CONNECT) && 
+       !(Connection->State & SEL_CONNECT) ) {
+    } else if( (NewState & SEL_READ) || (NewState & SEL_FIN) ) {
+    } 
+
+    return 0;
+}
+
+#define STRINGIFY(x) #x
+
+char hdr[14] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x08, 0x00 };
+
+int TCPPacketSend(void *ClientData, OSK_PCHAR data, OSK_UINT len ) {
+    output_packets.push_back( std::string( hdr, 14 ) + 
+                             std::string( (char *)data, (int)len ) );
+    return 0;
+}
+
+struct ifaddr *TCPFindInterface( void *ClientData,
+                                OSK_UINT AddrType,
+                                OSK_UINT FindType,
+                                struct sockaddr *ReqAddr ) {
+    static struct sockaddr_in ifa = { AF_INET }, nm = { AF_INET };
+    static struct ifaddr a = { 
+       (struct sockaddr *)&ifa, 
+       NULL, 
+       (struct sockaddr *)&nm, 
+       0, 
+       0, 
+       1, 
+       1500 
+    };
+    ifa.sin_addr.s_addr = inet_addr( "10.10.2.115" );
+    nm.sin_addr.s_addr  = inet_addr( "255.255.255.0" );
+    return &a;
+}
+
+void *TCPMalloc( void *ClientData,
+                OSK_UINT Bytes, OSK_PCHAR File, OSK_UINT Line ) {
+    void *v = malloc( Bytes );
+    fprintf( stderr, "(%s:%d) malloc( %d ) => %x\n", File, Line, Bytes, v );
+    return v;
+}
+
+void TCPFree( void *ClientData,
+             void *data, OSK_PCHAR File, OSK_UINT Line ) {
+    fprintf( stderr, "(%s:%d) free( %x )\n", File, Line, data );
+    free( data );
+}
+
+int TCPSleep( void *ClientData, void *token, int priority, char *msg,
+             int tmio ) {
+#if 0
+    PSLEEPING_THREAD SleepingThread;
+    
+    TI_DbgPrint(MID_TRACE,
+               ("Called TSLEEP: tok = %x, pri = %d, wmesg = %s, tmio = %x\n",
+                token, priority, msg, tmio));
+
+    SleepingThread = ExAllocatePool( NonPagedPool, sizeof( *SleepingThread ) );
+    if( SleepingThread ) {
+       KeInitializeEvent( &SleepingThread->Event, NotificationEvent, FALSE );
+       SleepingThread->SleepToken = token;
+
+       ExAcquireFastMutex( &SleepingThreadsLock );
+       InsertTailList( &SleepingThreadsList, &SleepingThread->Entry );
+       ExReleaseFastMutex( &SleepingThreadsLock );
+
+       TI_DbgPrint(MID_TRACE,("Waiting on %x\n", token));
+       KeWaitForSingleObject( &SleepingThread->Event,
+                              WrSuspended,
+                              KernelMode,
+                              TRUE,
+                              NULL );
+
+       ExAcquireFastMutex( &SleepingThreadsLock );
+       RemoveEntryList( &SleepingThread->Entry );
+       ExReleaseFastMutex( &SleepingThreadsLock );
+
+       ExFreePool( SleepingThread );
+    }
+    TI_DbgPrint(MID_TRACE,("Waiting finished: %x\n", token));
+#endif
+    return 0;
+}
+
+void TCPWakeup( void *ClientData, void *token ) {
+#if 0
+    PLIST_ENTRY Entry;
+    PSLEEPING_THREAD SleepingThread;
+
+    ExAcquireFastMutex( &SleepingThreadsLock );
+    Entry = SleepingThreadsList.Flink;
+    while( Entry != &SleepingThreadsList ) {
+       SleepingThread = CONTAINING_RECORD(Entry, SLEEPING_THREAD, Entry);
+       TI_DbgPrint(MID_TRACE,("Sleeper @ %x\n", SleepingThread));
+       if( SleepingThread->SleepToken == token ) {
+           TI_DbgPrint(MID_TRACE,("Setting event to wake %x\n", token));
+           KeSetEvent( &SleepingThread->Event, IO_NETWORK_INCREMENT, FALSE );
+       }
+       Entry = Entry->Flink;
+    }
+    ExReleaseFastMutex( &SleepingThreadsLock );
+#endif
+}
+
+OSKITTCP_EVENT_HANDLERS EventHandlers = {
+    NULL,
+    TCPSocketState,
+    TCPPacketSend,
+    TCPFindInterface,
+    TCPMalloc,
+    TCPFree,
+    TCPSleep,
+    TCPWakeup
+};
+
+void display_row( char *data, int off, int len ) {
+    int i;
+
+    printf( "%08x:", off );
+    for( i = off; i < len && i < off + 16; i++ ) {
+       printf( " %02x", data[i] & 0xff );
+    }
+
+    printf( " -- " );
+
+    for( i = off; i < len && i < off + 16; i++ ) {
+       printf( "%c", (data[i] >= ' ') ? data[i] : '.' );
+    }
+
+    printf( "\n" );
+}
+
+int main( int argc, char **argv ) {
+    int asock = INVALID_SOCKET, selret, dgrecv, fromsize, err, port = 5001;
+    char datagram[MAX_DG_SIZE];
+    void *conn = 0;
+    struct fd_set readf;
+    struct timeval tv;
+    struct sockaddr_in addr_from = { AF_INET }, addr_to = { AF_INET };
+    std::list<std::string>::iterator i;
+    WSADATA wsadata;
+
+    WSAStartup( 0x101, &wsadata );
+
+    if( argc > 1 ) port = atoi(argv[1]);
+
+    RegisterOskitTCPEventHandlers( &EventHandlers );
+    InitOskitTCP();
+
+    asock = socket( AF_INET, SOCK_DGRAM, 0 );
+
+    addr_from.sin_port = htons( port );
+
+    if( bind( asock, (struct sockaddr *)&addr_from, sizeof( addr_from ) ) ) {
+       printf( "Bind error\n" );
+       return 0;
+    }
+
+    addr_to.sin_port = htons( port & (~1) );
+    addr_to.sin_addr.s_addr = inet_addr("127.0.0.1");
+
+    while( true ) {
+       FD_ZERO( &readf );
+       FD_SET( asock, &readf );
+       tv.tv_sec = 0; 
+       tv.tv_usec = 10000;
+       selret = select( asock + 1, &readf, NULL, NULL, &tv );
+
+       if( FD_ISSET( asock, &readf ) ) {
+           fromsize = sizeof( addr_from );
+           dgrecv = recvfrom( asock, datagram, sizeof(datagram), 0,
+                              (struct sockaddr *)&addr_from, &fromsize );
+
+           if( datagram[0] == 'C' && datagram[1] == 'M' &&
+               datagram[2] == 'D' && datagram[3] == ' ' ) {
+               int theport, bytes, /*recvret,*/ off, bytin;
+               struct sockaddr_in nam;
+               std::string faddr, word;
+               std::istringstream 
+                   cmdin( std::string( datagram + 4, dgrecv - 4 ) );
+               
+               cmdin >> word;
+               
+               if( word == "socket" ) {
+                   cmdin >> faddr >> theport;
+
+                   nam.sin_family = AF_INET;
+                   nam.sin_addr.s_addr = inet_addr(faddr.c_str());
+                   nam.sin_port = htons(theport);
+
+                   if( (err = OskitTCPSocket( NULL, &conn, AF_INET, 
+                                             SOCK_STREAM, 0 )) != 0 ) {
+                       fprintf( stderr, "OskitTCPSocket: error %d\n", err );
+                   }
+                   
+                   if( (err = OskitTCPConnect( conn, NULL, &nam, 
+                                               sizeof(nam) )) != 0 ) {
+                       fprintf( stderr, "OskitTCPConnect: error %d\n", err );
+                   } else {
+                       printf( "Socket created\n" );
+                   }
+               } 
+
+               /* The rest of the commands apply only to an open socket */
+               if( !conn ) continue;
+
+               if( word == "recv" ) {
+                   cmdin >> bytes;
+
+                   if( (err = OskitTCPRecv( conn, (OSK_PCHAR)datagram, 
+                                            sizeof(datagram),
+                                            (unsigned int *)&bytin, 0 )) != 0 ) {
+                       fprintf( stderr, "OskitTCPRecv: error %d\n", err );
+                   } else {
+                       for( off = 0; off < bytin; off += 16 ) {
+                           display_row( datagram, off, bytin );
+                       }
+                       printf( "\n" );
+                   }
+               } else if ( word == "type" ) {
+                       std::string therest = &cmdin.str()[word.size()];
+                       char* p = &therest[0];
+                       p += strspn ( p, " \t" );
+                       char* src = p;
+                       char* dst = p;
+                       while ( *src )
+                       {
+                               char c = *src++;
+                               if ( c == '\r' || c == '\n' ) break;
+                               if ( c == '\\' )
+                               {
+                                       c = *src++;
+                                       switch ( c )
+                                       {
+                                       case 'b': c = '\b'; break;
+                                       case 'n': c = '\n'; break;
+                                       case 'r': c = '\r'; break;
+                                       case 't': c = '\t'; break;
+                                       case 'v': c = '\v'; break;
+                                       }
+                               }
+                               *dst++ = c;
+                       }
+                       *dst = '\0';
+                       if ( (err = OskitTCPSend ( conn, (OSK_PCHAR)p, strlen(p), (OSK_UINT*)&bytin, 0 ))
+                               != 0 ) {
+                               fprintf ( stderr, "OskitTCPConnect: error %d\n", err );
+                       } else {
+                               printf ( "wrote %d bytes\n", bytin );
+                       }
+               } else if( word == "send" ) {
+                   off = 0;
+                   while( cmdin >> word ) {
+                       datagram[off++] = 
+                           atoi( (std::string("0x") + word).c_str() );
+                   }
+                   
+                   if( (err = OskitTCPSend( conn, (OSK_PCHAR)datagram, 
+                                            off, (OSK_UINT *)&bytin, 0 )) 
+                       != 0 ) {
+                       fprintf( stderr, "OskitTCPConnect: error %d\n", err );
+                   } else {
+                       printf( "wrote %d bytes\n", bytin );
+                   }
+               } else if( word == "close" ) {
+                   OskitTCPClose( conn );
+                   conn = NULL;
+               }
+           } else if( dgrecv > 14 ) {
+               addr_to = addr_from;
+
+               if( datagram[12] == 8 && datagram[13] == 6 ) {
+                   /* Answer arp query */
+                   char laddr[4];
+                   /* Mark patch as to the previous sender */
+                   memcpy( datagram + 32, datagram + 6, 6 );
+                   memcpy( datagram, datagram + 6, 6 );
+                   /* Mark packet as from us */
+                   memcpy( datagram + 22, hwaddr, 6 );
+                   memcpy( datagram + 6, hwaddr, 6 );
+                   /* Swap inet addresses */
+                   memcpy( laddr, datagram + 28, 4 );
+                   memcpy( datagram + 28, datagram + 38, 4 );
+                   memcpy( datagram + 38, laddr, 4 );
+                   /* Set reply opcode */
+                   datagram[21] = 2;
+
+                   err = sendto( asock, datagram, dgrecv, 0,
+                                 (struct sockaddr *)&addr_to, 
+                                 sizeof(addr_to) );
+                   
+                   if( err != 0 )
+                       printf( "sendto: %d\n", err );
+               } else {
+                   memcpy( hdr, datagram + 6, 6 );
+                   memcpy( hdr + 6, datagram, 6 );
+                   memcpy( hdr + 12, datagram + 12, 2 );
+                   OskitTCPReceiveDatagram
+                       ( (unsigned char *)datagram + 14, 
+                         dgrecv - 14, 20 );
+               }
+           }
+       }
+
+       TimerOskitTCP();
+
+       for( i = output_packets.begin(); i != output_packets.end(); i++ ) {
+           err = sendto( asock, i->c_str(), i->size(), 0, 
+                         (struct sockaddr *)&addr_to, sizeof(addr_to) );
+
+           fprintf( stderr, "** SENDING PACKET %d bytes **\n", i->size() );
+
+           if( err != 0 )
+               printf( "sendto: %d\n", err );
+       }
+
+       output_packets.clear();
+    }
+}
+    
diff --git a/rosapps/tests/oskittcp/tcptest.dsp b/rosapps/tests/oskittcp/tcptest.dsp
new file mode 100644 (file)
index 0000000..fd5f903
--- /dev/null
@@ -0,0 +1,434 @@
+# Microsoft Developer Studio Project File - Name="tcptest" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=tcptest - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "tcptest.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "tcptest.mak" CFG="tcptest - Win32 Debug"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "tcptest - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "tcptest - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "tcptest - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF  "$(CFG)" == "tcptest - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../../drivers/lib/oskittcp/include" /I "../../../drivers\lib\oskittcp\include\freebsd\src\sys" /I "../../../drivers\lib\oskittcp\include\freebsd\dev\include" /I "../../../drivers\lib\oskittcp\include\freebsd\net\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "KERNEL" /D __REACTOS__=1 /D "FREEZAP" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF 
+
+# Begin Target
+
+# Name "tcptest - Win32 Release"
+# Name "tcptest - Win32 Debug"
+# Begin Group "tcptest"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\tcptest.cpp
+
+!IF  "$(CFG)" == "tcptest - Win32 Release"
+
+!ELSEIF  "$(CFG)" == "tcptest - Win32 Debug"
+
+# SUBTRACT CPP /D "KERNEL"
+
+!ENDIF 
+
+# End Source File
+# End Group
+# Begin Group "oskittcp"
+
+# PROP Default_Filter ""
+# Begin Group "src"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\defaults.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\in.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\in_cksum.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\in_pcb.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\in_proto.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\in_rmx.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\inet_ntoa.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\interface.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\ip_input.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\ip_output.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\kern_clock.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\kern_subr.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\param.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\radix.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\random.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\raw_cb.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\raw_ip.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\raw_usrreq.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\route.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\rtsock.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\scanc.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\sleep.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\tcp_debug.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\tcp_input.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\tcp_output.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\tcp_subr.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\tcp_timer.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\tcp_usrreq.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\uipc_domain.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\uipc_mbuf.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\uipc_socket.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\oskittcp\uipc_socket2.c
+# End Source File
+# End Group
+# Begin Group "include"
+
+# PROP Default_Filter ""
+# Begin Group "freebsd"
+
+# PROP Default_Filter ""
+# Begin Group "src No. 1"
+
+# PROP Default_Filter ""
+# Begin Group "sys"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\buf.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\callout.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\cdefs.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\domain.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\errno.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\fcntl.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\file.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\filedesc.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\filio.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\ioccom.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\ioctl.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\kernel.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\libkern.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\malloc.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\mbuf.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\param.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\proc.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\protosw.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\queue.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\resource.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\resourcevar.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\rtprio.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\select.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\signal.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\signalvar.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\socket.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\socketvar.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\sockio.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\stat.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\sysctl.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\syslimits.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\syslog.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\systm.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\time.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\ttycom.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\types.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\ucred.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\uio.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\freebsd\src\sys\sys\unistd.h
+# End Source File
+# End Group
+# End Group
+# End Group
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\memtrack.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\oskitdebug.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\oskiterrno.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\oskitfreebsd.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\oskittcp.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\drivers\lib\oskittcp\include\oskittypes.h
+# End Source File
+# End Group
+# End Group
+# End Target
+# End Project
diff --git a/rosapps/tests/oskittcp/tcptest.dsw b/rosapps/tests/oskittcp/tcptest.dsw
new file mode 100644 (file)
index 0000000..a00140e
--- /dev/null
@@ -0,0 +1,29 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "tcptest"=.\tcptest.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/rosapps/tests/p_dup_handle/.cvsignore b/rosapps/tests/p_dup_handle/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/p_dup_handle/makefile b/rosapps/tests/p_dup_handle/makefile
new file mode 100644 (file)
index 0000000..b24ec24
--- /dev/null
@@ -0,0 +1,23 @@
+# $Id: makefile,v 1.1 2004/10/21 04:59:00 sedwards Exp $
+
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = p_dup_handle
+
+TARGET_SDKLIBS = kernel32.a gdi32.a ntdll.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+TARGET_CFLAGS = -Wall -Werror
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/p_dup_handle/p_dup_handle.c b/rosapps/tests/p_dup_handle/p_dup_handle.c
new file mode 100644 (file)
index 0000000..6aa5f7d
--- /dev/null
@@ -0,0 +1,69 @@
+#include <stdio.h>
+#include <windows.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* This tests the ability of the target win32 to duplicate a process handle,
+ * spawn a child, and have the child dup it's own handle back into the parent
+ * using the duplicated handle.
+ */
+
+int main( int argc, char **argv ) {
+  HANDLE h_process;
+  HANDLE h_process_in_parent;
+
+  fprintf( stderr, "%lu: Starting\n", GetCurrentProcessId() );
+
+  if( argc == 2 ) {
+    h_process = (HANDLE)atoi(argv[1]);
+  } else {
+    if( !DuplicateHandle( GetCurrentProcess(),
+                         GetCurrentProcess(),
+                         GetCurrentProcess(),
+                         &h_process,
+                         0,
+                         TRUE,
+                         DUPLICATE_SAME_ACCESS) ) {
+      fprintf( stderr, "%lu: Could not duplicate my own process handle.\n",
+              GetCurrentProcessId() );
+      return 101;
+    }
+  }
+
+  if( argc == 1 ) {
+    STARTUPINFO si;
+    PROCESS_INFORMATION pi;
+    char cmdline[1000];
+
+    memset( &si, 0, sizeof( si ) );
+    memset( &pi, 0, sizeof( pi ) );
+
+    sprintf( cmdline, "%s %lu", argv[0], (DWORD)h_process );
+    if( !CreateProcess(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL,
+                      &si, &pi ) ) {
+      fprintf( stderr, "%lu: Could not create child process.\n",
+              GetCurrentProcessId() );
+      return 5;
+    }
+
+    if( WaitForSingleObject( pi.hThread, INFINITE ) != WAIT_OBJECT_0 ) {
+      fprintf( stderr, "%lu: Failed to wait for child process to terminate.\n",
+              GetCurrentProcessId() );
+      return 6;
+    }
+  } else {
+    if( !DuplicateHandle( GetCurrentProcess(),
+                         GetCurrentProcess(),
+                         h_process,
+                         &h_process_in_parent,
+                         0,
+                         TRUE,
+                         DUPLICATE_SAME_ACCESS) ) {
+      fprintf( stderr, "%lu: Could not duplicate my handle into the parent.\n",
+              GetCurrentProcessId() );
+      return 102;
+    }
+  }
+
+  return 0;
+}
diff --git a/rosapps/tests/palbitblt/.cvsignore b/rosapps/tests/palbitblt/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/palbitblt/makefile b/rosapps/tests/palbitblt/makefile
new file mode 100644 (file)
index 0000000..da502ce
--- /dev/null
@@ -0,0 +1,21 @@
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = windows
+
+TARGET_NAME = palbitblt
+
+TARGET_SDKLIBS = kernel32.a gdi32.a
+
+TARGET_OBJECTS = pal.o
+
+TARGET_CFLAGS = -Wall -Werror
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/palbitblt/pal.c b/rosapps/tests/palbitblt/pal.c
new file mode 100644 (file)
index 0000000..7ffa852
--- /dev/null
@@ -0,0 +1,201 @@
+/* The idea of this test app is inspired from tutorial       *
+ * found at http://www.theparticle.com/pgraph.html           *
+ *                                                           *
+ * Developed by: Aleksey Bragin <aleksey@studiocerebral.com> *
+ * Version: 1.0                                              */
+
+#include <windows.h>
+#include <stdlib.h>
+
+#define W_WIDTH 320
+#define W_HEIGHT 240
+
+// special version of BITMAPINFO and LOGPALETTE for max of 256 palette entries
+typedef struct
+{
+       BITMAPINFOHEADER bmiHeader;
+       RGBQUAD bmiColors[256];
+} BITMAPINFO256;
+
+typedef struct {
+       WORD    palVersion;
+       WORD    palNumEntries;
+       PALETTEENTRY palPalEntry[256];
+} LOGPALETTE256;
+
+// The only global variable --- contents of the DIBitmap
+BYTE* dibits;
+
+void GeneratePalette(RGBQUAD* p)
+{
+       int i;
+       for(i=0;i<256;i++)
+       {
+               p[i].rgbRed = i;
+               p[i].rgbGreen = i;
+               p[i].rgbBlue = i;
+               p[i].rgbReserved = 0;
+       }
+}
+
+void DoBlt(HBITMAP hBM)
+{
+       HDC hDC,Context;
+       HWND ActiveWindow;
+       RECT dest;
+       HBITMAP dflBmp;
+
+       if((ActiveWindow = GetActiveWindow()) == NULL)
+               return;
+
+       hDC = GetDC(ActiveWindow);
+       GetClientRect(ActiveWindow,&dest);
+       
+       Context = CreateCompatibleDC(0);
+       dflBmp = SelectObject(Context, hBM);
+       BitBlt(hDC, 0, 0, dest.right, dest.bottom, Context, 0, 0, SRCCOPY);
+       SelectObject(Context, dflBmp);
+       DeleteDC(Context);
+       DeleteObject(dflBmp);
+       ReleaseDC(ActiveWindow, hDC);
+}
+
+void UpdatePalette(HBITMAP hBM){
+       int i,y;
+       static unsigned int c=0;
+
+       for(i=0;i<W_WIDTH;i++){
+               for(y=0;y<=W_HEIGHT-1;y++)
+                       dibits[y*320+i] = c % 256;
+
+               if (c > 512)
+                       c = 0;
+               else
+                       c++; // It's operation of incrementing of c variable, not reference of a cool OO language :-)
+       }
+       
+       DoBlt(hBM);
+}
+
+void InitBitmap(HANDLE *hBM){
+       HPALETTE PalHan;
+       HWND ActiveWindow;
+       HDC hDC;
+       RGBQUAD palette[256];
+       int i;
+       BITMAPINFO256 bmInf;
+       LOGPALETTE256 palInf;
+
+       ActiveWindow = GetActiveWindow();
+       hDC = GetDC(ActiveWindow);
+
+       bmInf.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+       bmInf.bmiHeader.biWidth = W_WIDTH;
+       bmInf.bmiHeader.biHeight = -abs(W_HEIGHT);
+       bmInf.bmiHeader.biPlanes = 1;
+       bmInf.bmiHeader.biBitCount = 8;
+       bmInf.bmiHeader.biCompression = BI_RGB;
+       bmInf.bmiHeader.biSizeImage = 0;
+       bmInf.bmiHeader.biXPelsPerMeter = 0;
+       bmInf.bmiHeader.biYPelsPerMeter = 0;
+       bmInf.bmiHeader.biClrUsed = 256;
+       bmInf.bmiHeader.biClrImportant = 256;
+
+       GeneratePalette(palette);
+
+       for(i=0;i<256;i++)
+               bmInf.bmiColors[i] = palette[i];
+
+       palInf.palVersion = 0x300;
+       palInf.palNumEntries = 256;
+       for(i=0;i<256;i++){
+               palInf.palPalEntry[i].peRed = palette[i].rgbRed;
+               palInf.palPalEntry[i].peGreen = palette[i].rgbGreen;
+               palInf.palPalEntry[i].peBlue = palette[i].rgbBlue;
+               palInf.palPalEntry[i].peFlags = PC_NOCOLLAPSE;
+       }
+
+       // Create palette
+       PalHan = CreatePalette((LOGPALETTE*)&palInf);
+       
+       // Select it into hDC
+       SelectPalette(hDC,PalHan,FALSE);
+       
+       // Realize palette in hDC
+       RealizePalette(hDC);
+       
+       // Delete handle to palette
+       DeleteObject(PalHan);
+
+       // Create dib section
+       *hBM = CreateDIBSection(hDC,(BITMAPINFO*)&bmInf,
+               DIB_RGB_COLORS,(void**)&dibits,0,0);
+
+       // Release dc
+       ReleaseDC(ActiveWindow,hDC);
+}
+
+LRESULT CALLBACK WndProc(HWND hWnd,UINT msg, WPARAM wParam,LPARAM lParam)
+{
+       switch(msg){
+               case WM_DESTROY:
+                       PostQuitMessage(0);
+                       return 0;
+               default:
+                       return DefWindowProc(hWnd,msg,wParam,lParam);
+       }
+}
+
+
+
+int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpszCmdParam,int nCmdShow)
+{
+       WNDCLASS WndClass;
+       HWND hWnd;
+       MSG msg;
+       char szName[] = "Palette BitBlt test";
+       BOOL exit = FALSE;
+       HBITMAP hBM;
+
+       // Create and register window class (not modified!!!!!!!!!!!1)
+       WndClass.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
+       WndClass.lpfnWndProc = WndProc;
+       WndClass.cbClsExtra = 0;
+       WndClass.cbWndExtra = 0;
+       WndClass.hbrBackground = NULL;//GetStockObject(BLACK_BRUSH);
+       WndClass.hIcon = NULL;//LoadIcon(hInstance,NULL);
+       WndClass.hCursor = NULL;//LoadCursor(NULL,IDC_ARROW);
+       WndClass.hInstance = hInstance;
+       WndClass.lpszClassName = szName;
+       WndClass.lpszMenuName = 0;
+
+       RegisterClass(&WndClass);
+
+       // Create and show window (change styles !!!!!!!!)
+       hWnd = CreateWindow(szName, "ReactOS palette bitblt test",
+               WS_CAPTION|WS_MINIMIZEBOX|WS_SYSMENU,
+               CW_USEDEFAULT,CW_USEDEFAULT,W_WIDTH,W_HEIGHT,
+               0,0,hInstance,0);
+       ShowWindow(hWnd,nCmdShow);
+
+       // Prepare bitmap to be bitblt
+       InitBitmap(&hBM);       
+
+       // Main message loop
+       while (!exit)
+       {
+               UpdatePalette(hBM);
+               Sleep(200);
+               
+               if(PeekMessage(&msg,0,0,0,PM_NOREMOVE) == TRUE)
+               {
+                       if (!GetMessage(&msg,0,0,0))
+                               exit = TRUE;
+
+                       TranslateMessage(&msg);
+                       DispatchMessage(&msg);
+               }
+       }
+
+       return msg.wParam;
+}
diff --git a/rosapps/tests/regdump/.cvsignore b/rosapps/tests/regdump/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/regdump/main.c b/rosapps/tests/regdump/main.c
new file mode 100644 (file)
index 0000000..dd474c3
--- /dev/null
@@ -0,0 +1,45 @@
+// main.c :
+//
+#include <windows.h>
+#include <stdio.h>
+#include "regdump.h"
+
+
+HANDLE OutputHandle;
+HANDLE InputHandle;
+
+
+DWORD GetInput(char* Buffer, int buflen)
+{
+    DWORD Result;
+
+    ReadConsoleA(InputHandle, Buffer, buflen, &Result, NULL);
+    return Result;
+}
+
+int __cdecl main(int argc, char* argv[])
+{
+    //AllocConsole();
+    InputHandle = GetStdHandle(STD_INPUT_HANDLE);
+    OutputHandle =  GetStdHandle(STD_OUTPUT_HANDLE);
+    //return regmain(argc, argv);
+    return regdump(argc, argv);
+}
+
+
+#ifndef __GNUC__
+
+//__declspec(dllimport) int __stdcall DllMain(void* hinstDll, unsigned long dwReason, void* reserved);
+
+char* args[] = { "regdump.exe", "0", "ansi", "verbose"};
+
+int __cdecl mainCRTStartup(void)
+{
+
+    //DllMain(NULL, DLL_PROCESS_ATTACH, NULL);
+
+    main(1, args);
+    return 0;
+}
+
+#endif /*__GNUC__*/
diff --git a/rosapps/tests/regdump/makefile b/rosapps/tests/regdump/makefile
new file mode 100644 (file)
index 0000000..70d6658
--- /dev/null
@@ -0,0 +1,27 @@
+#
+# $Id: makefile,v 1.0
+
+PATH_TO_TOP = ../../../reactos
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = regdump
+
+#TARGET_CFLAGS = -DWIN32_REGDBG -DUNICODE -D_UNICODE
+TARGET_CFLAGS = -DWIN32_REGDBG
+
+TARGET_SDKLIBS = ntdll.a kernel32.a advapi32.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o regcmds.o regproc.o main.o
+
+TARGET_CFLAGS = -Wall -Werror
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/tests/regdump/regcmds.c b/rosapps/tests/regdump/regcmds.c
new file mode 100644 (file)
index 0000000..30e288e
--- /dev/null
@@ -0,0 +1,224 @@
+/* $Id: regcmds.c,v 1.1 2004/10/21 04:59:00 sedwards Exp $
+ *
+ *  ReactOS regedit
+ *
+ *  regcmds.c
+ *
+ *  Copyright (C) 2002  Robert Dickenson <robd@reactos.org>
+ *
+ *  Original Work Copyright 2002 Andriy Palamarchuk
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers
+#include <windows.h>
+#include <tchar.h>
+#include <stdio.h>
+
+#ifdef WIN32_REGDBG
+#else
+#include <ctype.h>
+#endif
+
+#include "regproc.h"
+
+
+////////////////////////////////////////////////////////////////////////////////
+// Global Variables:
+//
+
+static char *usage =
+"Usage:\n"
+"    regedit filename\n"
+"    regedit /E filename [regpath]\n"
+"    regedit /D regpath\n"
+"\n"
+"filename - registry file name\n"
+"regpath - name of the registry key\n"
+"\n"
+"When is called without any switches adds contents of the specified\n"
+"registry file to the registry\n"
+"\n"
+"Switches:\n"
+"    /E - exports contents of the specified registry key to the specified\n"
+"      file. Exports the whole registry if no key is specified.\n"
+"    /D - deletes specified registry key\n"
+"    /S - silent execution, can be used with any other switch.\n"
+"      The only existing mode, exists for compatibility with Windows regedit.\n"
+"    /V - advanced mode, can be used with any other switch.\n"
+"      Ignored, exists for compatibility with Windows regedit.\n"
+"    /L - location of system.dat file. Can be used with any other switch.\n"
+"      Ignored. Exists for compatibility with Windows regedit.\n"
+"    /R - location of user.dat file. Can be used with any other switch.\n"
+"      Ignored. Exists for compatibility with Windows regedit.\n"
+"    /? - print this help. Any other switches are ignored.\n"
+"    /C - create registry from. Not implemented.\n"
+"\n"
+"The switches are case-insensitive, can be prefixed either by '-' or '/'.\n"
+"This program is command-line compatible with Microsoft Windows\n"
+"regedit. The difference with Windows regedit - this application has\n"
+"command-line interface only.\n";
+
+typedef enum {
+    ACTION_UNDEF, ACTION_ADD, ACTION_EXPORT, ACTION_DELETE, ACTION_VIEW
+} REGEDIT_ACTION;
+
+/**
+ * Process unknown switch.
+ *
+ * Params:
+ *   chu - the switch character in upper-case.
+ *   s - the command line string where s points to the switch character.
+ */
+void error_unknown_switch(char chu, char *s)
+{
+    if (isalpha(chu)) {
+        printf("Undefined switch /%c!\n", chu);
+    } else {
+        printf("Alphabetic character is expected after '%c' "
+               "in switch specification\n", *(s - 1));
+    }
+    //exit(1);
+}
+
+BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
+{
+    TCHAR filename[MAX_PATH];
+    TCHAR reg_key_name[KEY_MAX_LEN];
+
+    switch (action) {
+    case ACTION_ADD:
+        get_file_name(&s, filename, MAX_PATH);
+        if (!filename[0]) {
+            printf("No file name is specified\n%s", usage);
+            return FALSE;
+            //exit(1);
+        }
+        while (filename[0]) {
+            if (!import_registry_file(filename)) {
+                perror("");
+                printf("Can't open file \"%s\"\n", filename);
+                return FALSE;
+                //exit(1);
+            }
+            get_file_name(&s, filename, MAX_PATH);
+        }
+        break;
+    case ACTION_DELETE:
+        get_file_name(&s, reg_key_name, KEY_MAX_LEN);
+        if (!reg_key_name[0]) {
+            printf("No registry key is specified for removal\n%s", usage);
+            return FALSE;
+            //exit(1);
+        }
+        delete_registry_key(reg_key_name);
+        break;
+    case ACTION_EXPORT:
+        filename[0] = '\0';
+        get_file_name(&s, filename, MAX_PATH);
+        if (!filename[0]) {
+            printf("No file name is specified\n%s", usage);
+            return FALSE;
+            //exit(1);
+        }
+        if (s[0]) {
+            get_file_name(&s, reg_key_name, KEY_MAX_LEN);
+            export_registry_key(filename, reg_key_name);
+        } else {
+            export_registry_key(filename, NULL);
+        }
+        break;
+    default:
+        printf("Unhandled action!\n");
+        return FALSE;
+    }
+    return TRUE;
+}
+
+BOOL ProcessCmdLine(LPSTR lpCmdLine)
+{
+    REGEDIT_ACTION action = ACTION_UNDEF;
+    LPSTR s = lpCmdLine;        /* command line pointer */
+    CHAR ch = *s;               /* current character */
+
+    while (ch && ((ch == '-') || (ch == '/'))) {
+        char chu;
+        char ch2;
+
+        s++;
+        ch = *s;
+        ch2 = *(s+1);
+        chu = toupper(ch);
+        if (!ch2 || isspace(ch2)) {
+            if (chu == 'S' || chu == 'V') {
+                /* ignore these switches */
+            } else {
+                switch (chu) {
+                case 'D':
+                    action = ACTION_DELETE;
+                    break;
+                case 'E':
+                    action = ACTION_EXPORT;
+                    break;
+                case 'V':
+                    action = ACTION_VIEW;
+                    break;
+                case '?':
+                    printf(usage);
+                    return FALSE;
+                    //exit(0);
+                    break;
+                default:
+                    error_unknown_switch(chu, s);
+                    return FALSE;
+                    break;
+                }
+            }
+            s++;
+        } else {
+            if (ch2 == ':') {
+                switch (chu) {
+                case 'L':
+                    /* fall through */
+                case 'R':
+                    s += 2;
+                    while (*s && !isspace(*s)) {
+                        s++;
+                    }
+                    break;
+                default:
+                    error_unknown_switch(chu, s);
+                    return FALSE;
+                    break;
+                }
+            } else {
+                /* this is a file name, starting from '/' */
+                s--;
+                break;
+            }
+        }
+        /* skip spaces to the next parameter */
+        ch = *s;
+        while (ch && isspace(ch)) {
+            s++;
+            ch = *s;
+        }
+    }
+    if (action == ACTION_UNDEF) {
+        action = ACTION_ADD;
+    }
+    return PerformRegAction(action, s);
+}
diff --git a/rosapps/tests/regdump/regdump.c b/rosapps/tests/regdump/regdump.c
new file mode 100644 (file)
index 0000000..ed8b29b
--- /dev/null
@@ -0,0 +1,167 @@
+/* $Id: regdump.c,v 1.1 2004/10/21 04:59:00 sedwards Exp $
+ *
+ *  ReactOS regedit
+ *
+ *  regdump.c
+ *
+ *  Copyright (C) 2002  Robert Dickenson <robd@reactos.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <windows.h>
+#include <tchar.h>
+#include <stdio.h>
+#include "regdump.h"
+
+
+#ifdef UNICODE
+//#define dprintf _tprintf
+#define dprintf printf
+#else
+#define dprintf printf
+#endif
+
+void RegKeyPrint(int which);
+
+
+
+const char* default_cmd_line1 = "/E HKLM_EXPORT.TXT HKEY_LOCAL_MACHINE";
+const char* default_cmd_line2 = "TEST_IMPORT.TXT";
+const char* default_cmd_line3 = "/P HKEY_LOCAL_MACHINE\\SYSTEM";
+const char* default_cmd_line4 = "/P HKEY_LOCAL_MACHINE\\SOFTWARE";
+const char* default_cmd_line5 = "/P HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes";
+const char* default_cmd_line6 = "/E HKCR_EXPORT.TXT HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes";
+const char* default_cmd_line7 = "/D HKEY_LOCAL_MACHINE\\SYSTEM";
+const char* default_cmd_line8 = "/D HKEY_LOCAL_MACHINE\\SOFTWARE";
+const char* default_cmd_line9 = "/D HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes";
+
+/* Show usage */
+void usage(const char* appName)
+{
+    fprintf(stderr, "%s: Dump registry key to console\n", appName);
+    fprintf(stderr, "%s HKCR | HKCU | HKLM | HKU | HKCC | HKRR\n", appName);
+}
+
+void show_menu(void)
+{
+    _tprintf(_T("\nchoose test :\n"));
+    _tprintf(_T("  0 = Exit\n"));
+         printf("  1 = %s\n", default_cmd_line1);
+         printf("  2 = %s\n", default_cmd_line2);
+         printf("  3 = %s\n", default_cmd_line3);
+         printf("  4 = %s\n", default_cmd_line4);
+         printf("  5 = %s\n", default_cmd_line5);
+         printf("  6 = %s\n", default_cmd_line6);
+         printf("  7 = %s\n", default_cmd_line7);
+         printf("  8 = %s\n", default_cmd_line8);
+         printf("  9 = %s\n", default_cmd_line9);
+/*
+    _tprintf(_T("  1 = %s\n"), default_cmd_line1);
+    _tprintf(_T("  2 = %s\n"), default_cmd_line2);
+    _tprintf(_T("  3 = %s\n"), default_cmd_line3);
+    _tprintf(_T("  4 = %s\n"), default_cmd_line4);
+    _tprintf(_T("  5 = %s\n"), default_cmd_line5);
+    _tprintf(_T("  6 = %s\n"), default_cmd_line6);
+    _tprintf(_T("  7 = %s\n"), default_cmd_line7);
+    _tprintf(_T("  8 = %s\n"), default_cmd_line8);
+    _tprintf(_T("  9 = %s\n"), default_cmd_line9);
+ */
+//        _tprintf(_T("  A = HKEY_CLASSES_ROOT\n"));
+//        _tprintf(_T("  B = HKEY_CURRENT_USER\n"));
+//        _tprintf(_T("  C = HKEY_LOCAL_MACHINE\n"));
+//        _tprintf(_T("  D = HKEY_USERS\n"));
+//        _tprintf(_T("  E = HKEY_CURRENT_CONFIG\n"));
+//        _tprintf(_T("  F = REGISTRY ROOT\n"));
+}
+
+int regdump(int argc, char* argv[])
+{
+    char Buffer[500];
+
+    if (argc > 1) {
+//      if (0 == _tcsstr(argv[1], _T("HKLM"))) {
+        if (strstr(argv[1], "help")) {
+            usage(argv[0]);
+        } else if (strstr(argv[1], "HKCR")) {
+            RegKeyPrint('1');
+        } else if (strstr(argv[1], "HKCU")) {
+            RegKeyPrint('2');
+        } else if (strstr(argv[1], "HKLM")) {
+            RegKeyPrint('3');
+        } else if (strstr(argv[1], "HKU")) {
+            RegKeyPrint('4');
+        } else if (strstr(argv[1], "HKCC")) {
+            RegKeyPrint('5');
+        } else if (strstr(argv[1], "HKRR")) {
+            RegKeyPrint('6');
+        } else {
+            dprintf("started with argc = %d, argv[1] = %s (unknown?)\n", argc, argv[1]);
+        }
+        return 0;
+    }
+    show_menu();
+    while (1) {
+        GetInput(Buffer, sizeof(Buffer));
+        switch (toupper(Buffer[0])) {
+        case '0':
+            return(0);
+        case '1':
+            strcpy(Buffer, default_cmd_line1);
+            goto doit;
+        case '2':
+            strcpy(Buffer, default_cmd_line2);
+            goto doit;
+        case '3':
+            strcpy(Buffer, default_cmd_line3);
+            goto doit;
+        case '4':
+            strcpy(Buffer, default_cmd_line4);
+            goto doit;
+        case '5':
+            strcpy(Buffer, default_cmd_line5);
+            goto doit;
+        case '6':
+            strcpy(Buffer, default_cmd_line6);
+            goto doit;
+        case '7':
+            strcpy(Buffer, default_cmd_line7);
+            goto doit;
+        case '8':
+            strcpy(Buffer, default_cmd_line8);
+            goto doit;
+        case '9':
+            strcpy(Buffer, default_cmd_line9);
+            goto doit;
+        case 'A':
+        case 'B':
+        case 'C':
+        case 'D':
+        case 'E':
+        case 'F':
+            RegKeyPrint(toupper(Buffer[0]) - 'A' + 1);
+            break;
+        default: doit:
+            if (!ProcessCmdLine(Buffer)) {
+                dprintf("invalid input.\n");
+                show_menu();
+            } else {
+                dprintf("done.\n");
+            }
+            break;
+        }
+    }
+    return 0;
+}
diff --git a/rosapps/tests/regdump/regdump.h b/rosapps/tests/regdump/regdump.h
new file mode 100644 (file)
index 0000000..be2c895
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ *  ReactOS
+ *
+ *  regdump.h
+ *
+ *  Copyright (C) 2002  Robert Dickenson <robd@reactos.org>
+ *
+ *  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 2 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.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __REGDUMP_H__
+#define __REGDUMP_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+extern HANDLE OutputHandle;
+extern HANDLE InputHandle;
+
+DWORD GetInput(char* Buffer, int buflen);
+//void dprintf(char* fmt, ...);
+int regdump(int argc, char* argv[]);
+BOOL ProcessCmdLine(LPSTR lpCmdLine);
+
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif // __REGDUMP_H__
diff --git a/rosapps/tests/regdump/regproc.c b/rosapps/tests/regdump/regproc.c
new file mode 100644 (file)
index 0000000..6fb0a2d
--- /dev/null
@@ -0,0 +1,1491 @@
+/*
+ * Registry processing routines. Routines, common for registry
+ * processing frontends.
+ *
+ * Copyright 1999 Sylvain St-Germain
+ * Copyright 2002 Andriy Palamarchuk
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifdef WIN32_REGDBG
+#include <windows.h>
+#include <tchar.h>
+#ifndef __GNUC__
+#include <ntsecapi.h>
+#else
+#include <ctype.h>
+#endif
+#include <limits.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+//#include <winreg.h>
+#include "regdump.h"
+#else
+
+#define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers
+#include <windows.h>
+#include <commctrl.h>
+#include <stdlib.h>
+#include <tchar.h>
+#include <process.h>
+#include <stdio.h>
+#include <wchar.h>
+    
+#include <ctype.h>
+#include <limits.h>
+#include <winnt.h>
+#include <winreg.h>
+#include <assert.h>
+
+#endif
+
+#include "regproc.h"
+
+
+#define REG_VAL_BUF_SIZE        4096
+
+/* Delimiters used to parse the "value" to query queryValue*/
+#define QUERY_VALUE_MAX_ARGS  1
+
+/* maximal number of characters in hexadecimal data line,
+   not including '\' character */
+#define REG_FILE_HEX_LINE_LEN   76
+
+/* Globals used by the api setValue, queryValue */
+static LPTSTR currentKeyName   = NULL;
+static HKEY  currentKeyClass  = 0;
+static HKEY  currentKeyHandle = 0;
+static BOOL  bTheKeyIsOpen    = FALSE;
+
+static TCHAR *reg_class_names[] = {
+    _T("HKEY_LOCAL_MACHINE"),
+    _T("HKEY_USERS"),
+    _T("HKEY_CLASSES_ROOT"),
+    _T("HKEY_CURRENT_CONFIG"),
+    _T("HKEY_CURRENT_USER")
+};
+
+#define REG_CLASS_NUMBER (sizeof(reg_class_names) / sizeof(reg_class_names[0]))
+
+static HKEY reg_class_keys[REG_CLASS_NUMBER] = {
+    HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CLASSES_ROOT,
+    HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER
+};
+
+/* return values */
+#define NOT_ENOUGH_MEMORY     1
+#define IO_ERROR              2
+
+/* processing macros */
+
+/* common check of memory allocation results */
+#ifdef UNICODE
+#define CHECK_ENOUGH_MEMORY(p) \
+    if (!(p)) \
+    { \
+        _tprintf(_T("file %S, line %d: Not enough memory"), __FILE__, __LINE__); \
+        assert(0);\
+        exit(NOT_ENOUGH_MEMORY); \
+    }
+#else
+#define CHECK_ENOUGH_MEMORY(p) \
+    if (!(p)) \
+    { \
+        _tprintf(_T("file %s, line %d: Not enough memory"), __FILE__, __LINE__); \
+        assert(0);\
+        exit(NOT_ENOUGH_MEMORY); \
+    }
+#endif
+
+#ifdef UNICODE
+#define _TEOF WEOF 
+#else
+#define _TEOF EOF 
+#endif
+
+/******************************************************************************
+ * This is a replacement for strsep which is not portable (missing on Solaris).
+ */
+#if 0
+/* DISABLED */
+char* getToken(char** str, const char* delims)
+{
+    char* token;
+
+    if (*str==NULL) {
+        /* No more tokens */
+        return NULL;
+    }
+
+    token=*str;
+    while (**str!='\0') {
+        if (strchr(delims,**str)!=NULL) {
+            **str='\0';
+            (*str)++;
+            return token;
+        }
+        (*str)++;
+    }
+    /* There is no other token */
+    *str=NULL;
+    return token;
+}
+#endif
+
+/******************************************************************************
+ * Copies file name from command line string to the buffer.
+ * Rewinds the command line string pointer to the next non-spece character
+ * after the file name.
+ * Buffer contains an empty string if no filename was found;
+ *
+ * params:
+ * command_line - command line current position pointer
+ *      where *s[0] is the first symbol of the file name.
+ * file_name - buffer to write the file name to.
+ */
+void get_file_nameA(CHAR **command_line, CHAR *file_name, int max_filename)
+{
+    CHAR *s = *command_line;
+    int pos = 0;                /* position of pointer "s" in *command_line */
+    file_name[0] = 0;
+
+    if (!s[0]) {
+        return;
+    }
+    if (s[0] == '"') {
+        s++;
+        (*command_line)++;
+        while (s[0] != '"') {
+            if (!s[0]) {
+                _tprintf(_T("Unexpected end of file name!\n"));
+                assert(0);
+                //exit(1);
+            }
+            s++;
+            pos++;
+        }
+    } else {
+        while (s[0] && !isspace(s[0])) {
+            s++;
+            pos++;
+        }
+    }
+    memcpy(file_name, *command_line, pos * sizeof((*command_line)[0]));
+    /* remove the last backslash */
+    if (file_name[pos - 1] == '\\') {
+        file_name[pos - 1] = '\0';
+    } else {
+        file_name[pos] = '\0';
+    }
+    if (s[0]) {
+        s++;
+        pos++;
+    }
+    while (s[0] && isspace(s[0])) {
+        s++;
+        pos++;
+    }
+    (*command_line) += pos;
+}
+
+void get_file_nameW(CHAR** command_line, WCHAR* filename, int max_filename)
+{
+    CHAR filenameA[_MAX_PATH];
+    int len;
+
+    get_file_nameA(command_line, filenameA, _MAX_PATH);
+    len = strlen(filenameA);
+    OemToCharBuffW(filenameA, filename, max_filename);
+    filename[len] = _T('\0');
+/*
+    UNICODE_STRING UnicodeString;
+    ANSI_STRING AnsiString;
+    CHAR filenameA[_MAX_PATH];
+
+    get_file_nameA(command_line, filenameA, _MAX_PATH);
+
+    //RtlInitAnsiString(&AnsiString, filenameA);
+    UnicodeString.Buffer = filename;
+    UnicodeString.MaximumLength = max_filename;//MAX_PATH;
+    RtlAnsiStringToUnicodeString(&UnicodeString, &AnsiString, FALSE);
+ */
+}
+
+/******************************************************************************
+ * Converts a hex representation of a DWORD into a DWORD.
+ */
+DWORD convertHexToDWord(TCHAR* str, BYTE* buf)
+{
+    DWORD dw;
+    TCHAR xbuf[9];
+
+    memcpy(xbuf, str, 8 * sizeof(TCHAR));
+    xbuf[88 * sizeof(TCHAR)] = '\0';
+    _stscanf(xbuf, _T("%08lx"), &dw);
+    memcpy(buf, &dw, sizeof(DWORD));
+    return sizeof(DWORD);
+}
+
+/******************************************************************************
+ * Converts a hex buffer into a hex comma separated values
+ */
+TCHAR* convertHexToHexCSV(BYTE* buf, ULONG bufLen)
+{
+    TCHAR* str;
+    TCHAR* ptrStr;
+    BYTE* ptrBuf;
+
+    ULONG current = 0;
+    str = HeapAlloc(GetProcessHeap(), 0, (bufLen+1)*2*sizeof(TCHAR));
+    memset(str, 0, (bufLen+1)*2);
+    ptrStr = str;  /* Pointer to result  */
+    ptrBuf = buf;  /* Pointer to current */
+    while (current < bufLen) {
+        BYTE bCur = ptrBuf[current++];
+        TCHAR res[3];
+        _stprintf(res, _T("%02x"), (unsigned int)*&bCur);
+        _tcscat(str, res);
+        _tcscat(str, _T(","));
+    }
+    /* Get rid of the last comma */
+    str[_tcslen(str)-1] = _T('\0');
+    return str;
+}
+
+/******************************************************************************
+ * Converts a hex buffer into a DWORD string
+ */
+TCHAR* convertHexToDWORDStr(BYTE* buf, ULONG bufLen)
+{
+    TCHAR* str;
+    DWORD dw;
+
+    if (bufLen != sizeof(DWORD)) return NULL;
+    str = HeapAlloc(GetProcessHeap(), 0, ((bufLen*2)+1)*sizeof(TCHAR));
+    memcpy(&dw, buf, sizeof(DWORD));
+    _stprintf(str, _T("%08lx"), dw);
+    /* Get rid of the last comma */
+    return str;
+}
+
+/******************************************************************************
+ * Converts a hex comma separated values list into a hex list.
+ * The Hex input string must be in exactly the correct form.
+ */
+DWORD convertHexCSVToHex(TCHAR* str, BYTE* buf, ULONG bufLen)
+{
+    TCHAR* s = str;  /* Pointer to current */
+    CHAR* b = buf;  /* Pointer to result  */
+    ULONG strLen    = _tcslen(str);
+    ULONG strPos    = 0;
+    DWORD byteCount = 0;
+
+    memset(buf, 0, bufLen);
+    /*
+     * warn the user if we are here with a string longer than 2 bytes that does
+     * not contains ",".  It is more likely because the data is invalid.
+     */
+    if ((strLen > 2) && (_tcschr(str, _T(',')) == NULL)) {
+        _tprintf(_T("WARNING converting CSV hex stream with no comma, ") \
+                 _T("input data seems invalid.\n"));
+    }
+    if (strLen > 3*bufLen) {
+        _tprintf(_T("ERROR converting CSV hex stream.  Too long\n"));
+    }
+    while (strPos < strLen) {
+        TCHAR xbuf[3];
+        TCHAR wc;
+        memcpy(xbuf, s, 2);
+        xbuf[3] = _T('\0');
+        _stscanf(xbuf, _T("%02x"), (UINT*)&wc);
+        if (byteCount < bufLen)
+            *b++ = (unsigned char)wc;
+        s += 3;
+        strPos += 3;
+        ++byteCount;
+    }
+    return byteCount;
+}
+
+/******************************************************************************
+ * This function returns the HKEY associated with the data type encoded in the
+ * value.  It modifies the input parameter (key value) in order to skip this
+ * "now useless" data type information.
+ *
+ * Note: Updated based on the algorithm used in 'server/registry.c'
+ */
+DWORD getDataType(LPTSTR* lpValue, DWORD* parse_type)
+{
+    struct data_type { const TCHAR *tag; int len; int type; int parse_type; };
+
+    static const struct data_type data_types[] =
+    {                   /* actual type */  /* type to assume for parsing */
+        { _T("\""),        1,   REG_SZ,              REG_SZ },
+        { _T("str:\""),    5,   REG_SZ,              REG_SZ },
+//        { _T("str(2):\""), 8,   REG_EXPAND_SZ,       REG_SZ },
+        { _T("expand:\""), 8,   REG_EXPAND_SZ,       REG_EXPAND_SZ },
+        { _T("hex:"),      4,   REG_BINARY,          REG_BINARY },
+        { _T("dword:"),    6,   REG_DWORD,           REG_DWORD },
+        { _T("hex("),      4,   -1,                  REG_BINARY },
+        { NULL,            0,    0,                  0 }
+    };
+
+    const struct data_type *ptr;
+    int type;
+
+    for (ptr = data_types; ptr->tag; ptr++) {
+        if (memcmp(ptr->tag, *lpValue, ptr->len))
+            continue;
+
+        /* Found! */
+        *parse_type = ptr->parse_type;
+        type = ptr->type;
+        *lpValue += ptr->len;
+        if (type == -1) {
+            TCHAR* end;
+            /* "hex(xx):" is special */
+            type = (int)_tcstoul(*lpValue , &end, 16);
+            if (**lpValue == _T('\0') || *end != _T(')') || *(end+1) != _T(':')) {
+                type = REG_NONE;
+            } else {
+                *lpValue = end + 2;
+            }
+        }
+        return type;
+    }
+    return (**lpValue == _T('\0') ? REG_SZ : REG_NONE);
+}
+
+/******************************************************************************
+ * Returns an allocated buffer with a cleaned copy (removed the surrounding
+ * dbl quotes) of the passed value.
+ */
+LPTSTR getArg(LPTSTR arg)
+{
+  LPTSTR tmp = NULL;
+  ULONG len;
+
+  if (arg == NULL) return NULL;
+
+  // Get rid of surrounding quotes
+  len = _tcslen(arg);
+  if (arg[len-1] == _T('\"')) arg[len-1] = _T('\0');
+  if (arg[0]     == _T('\"')) arg++;
+  tmp = HeapAlloc(GetProcessHeap(), 0, (_tcslen(arg)+1) * sizeof(TCHAR));
+  _tcscpy(tmp, arg);
+  return tmp;
+}
+
+/******************************************************************************
+ * Replaces escape sequences with the characters.
+ */
+void REGPROC_unescape_string(LPTSTR str)
+{
+    int str_idx = 0;            /* current character under analysis */
+    int val_idx = 0;            /* the last character of the unescaped string */
+    int len = _tcslen(str);
+    for (str_idx = 0; str_idx < len; str_idx++, val_idx++) {
+        if (str[str_idx] == _T('\\')) {
+            str_idx++;
+            switch (str[str_idx]) {
+            case _T('n'):
+                str[val_idx] = _T('\n');
+                break;
+            case _T('\\'):
+            case _T('"'):
+                str[val_idx] = str[str_idx];
+                break;
+            default:
+                _tprintf(_T("Warning! Unrecognized escape sequence: \\%c'\n"), str[str_idx]);
+                str[val_idx] = str[str_idx];
+                break;
+            }
+        } else {
+            str[val_idx] = str[str_idx];
+        }
+    }
+    str[val_idx] = _T('\0');
+}
+
+/******************************************************************************
+ * Sets the value with name val_name to the data in val_data for the currently
+ * opened key.
+ *
+ * Parameters:
+ * val_name - name of the registry value
+ * val_data - registry value data
+ */
+HRESULT setValue(LPTSTR val_name, LPTSTR val_data)
+{
+  HRESULT hRes;
+  DWORD   dwDataType, dwParseType;
+  LPBYTE lpbData;
+  BYTE   convert[KEY_MAX_LEN];
+  BYTE *bBigBuffer = 0;
+  DWORD  dwLen;
+
+  if ((val_name == NULL) || (val_data == NULL))
+    return ERROR_INVALID_PARAMETER;
+
+  /* Get the data type stored into the value field */
+  dwDataType = getDataType(&val_data, &dwParseType);
+
+//  if (dwParseType == REG_EXPAND_SZ) {
+//  }
+//  if (dwParseType == REG_SZ || dwParseType == REG_EXPAND_SZ) { /* no conversion for string */
+
+  if (dwParseType == REG_SZ) {       /* no conversion for string */
+    dwLen = _tcslen(val_data);
+    if (dwLen > 0 && val_data[dwLen-1] == _T('"')) {
+      dwLen--;
+      val_data[dwLen] = _T('\0');
+    }
+    dwLen++;
+    dwLen *= sizeof(TCHAR);
+    REGPROC_unescape_string(val_data);
+    lpbData = val_data;
+  } else if (dwParseType == REG_DWORD) { /* Convert the dword types */
+    dwLen   = convertHexToDWord(val_data, convert);
+    lpbData = convert;
+  } else {                               /* Convert the hexadecimal types */
+    int b_len = _tcslen(val_data)+2/3;
+    if (b_len > KEY_MAX_LEN) {
+      bBigBuffer = HeapAlloc (GetProcessHeap(), 0, b_len * sizeof(TCHAR));
+      if (bBigBuffer == NULL) {
+          return ERROR_REGISTRY_IO_FAILED;
+      }
+      CHECK_ENOUGH_MEMORY(bBigBuffer);
+      dwLen = convertHexCSVToHex(val_data, bBigBuffer, b_len);
+      lpbData = bBigBuffer;
+    } else {
+      dwLen   = convertHexCSVToHex(val_data, convert, KEY_MAX_LEN);
+      lpbData = convert;
+    }
+  }
+  hRes = RegSetValueEx(currentKeyHandle, val_name,
+          0, /* Reserved */dwDataType, lpbData, dwLen);
+
+    _tprintf(_T("  Value: %s, Data: %s\n"), val_name, lpbData);
+
+
+  if (bBigBuffer)
+      HeapFree(GetProcessHeap(), 0, bBigBuffer);
+  return hRes;
+}
+
+
+/******************************************************************************
+ * Open the key
+ */
+HRESULT openKey(LPTSTR stdInput)
+{
+  DWORD   dwDisp;
+  HRESULT hRes;
+
+  /* Sanity checks */
+  if (stdInput == NULL)
+    return ERROR_INVALID_PARAMETER;
+
+  /* Get the registry class */
+  currentKeyClass = getRegClass(stdInput); /* Sets global variable */
+  if (currentKeyClass == (HKEY)ERROR_INVALID_PARAMETER)
+    return (HRESULT)ERROR_INVALID_PARAMETER;
+
+  /* Get the key name */
+  currentKeyName = getRegKeyName(stdInput); /* Sets global variable */
+  if (currentKeyName == NULL)
+    return ERROR_INVALID_PARAMETER;
+
+  hRes = RegCreateKeyEx(
+          currentKeyClass,          /* Class     */
+          currentKeyName,           /* Sub Key   */
+          0,                        /* MUST BE 0 */
+          NULL,                     /* object type */
+          REG_OPTION_NON_VOLATILE,  /* option, REG_OPTION_NON_VOLATILE ... */
+          KEY_ALL_ACCESS,           /* access mask, KEY_ALL_ACCESS */
+          NULL,                     /* security attribute */
+          &currentKeyHandle,        /* result */
+          &dwDisp);                 /* disposition, REG_CREATED_NEW_KEY or
+                                                    REG_OPENED_EXISTING_KEY */
+
+  if (hRes == ERROR_SUCCESS)
+    bTheKeyIsOpen = TRUE;
+
+  return hRes;
+
+}
+
+/******************************************************************************
+ * Extracts from [HKEY\some\key\path] or HKEY\some\key\path types of line
+ * the key name (what starts after the first '\')
+ */
+LPTSTR getRegKeyName(LPTSTR lpLine)
+{
+  LPTSTR keyNameBeg;
+  TCHAR  lpLineCopy[KEY_MAX_LEN];
+
+  if (lpLine == NULL)
+    return NULL;
+
+  _tcscpy(lpLineCopy, lpLine);
+  keyNameBeg = _tcschr(lpLineCopy, _T('\\'));    /* The key name start by '\' */
+  if (keyNameBeg) {
+      LPTSTR keyNameEnd;
+
+      keyNameBeg++;                             /* is not part of the name */
+      keyNameEnd = _tcschr(lpLineCopy, _T(']'));
+      if (keyNameEnd) {
+          *keyNameEnd = _T('\0');               /* remove ']' from the key name */
+      }
+  } else {
+      keyNameBeg = lpLineCopy + _tcslen(lpLineCopy); /* branch - empty string */
+  }
+  currentKeyName = HeapAlloc(GetProcessHeap(), 0, (_tcslen(keyNameBeg)+1)*sizeof(TCHAR));
+  CHECK_ENOUGH_MEMORY(currentKeyName);
+  _tcscpy(currentKeyName, keyNameBeg);
+  return currentKeyName;
+}
+
+/******************************************************************************
+ * Extracts from [HKEY\some\key\path] or HKEY\some\key\path types of line
+ * the key class (what ends before the first '\')
+ */
+HKEY getRegClass(LPTSTR lpClass)
+{
+  LPTSTR classNameEnd;
+  LPTSTR classNameBeg;
+  int i;
+
+  TCHAR lpClassCopy[KEY_MAX_LEN];
+
+  if (lpClass == NULL)
+    return (HKEY)ERROR_INVALID_PARAMETER;
+
+  _tcsncpy(lpClassCopy, lpClass, KEY_MAX_LEN);
+
+  classNameEnd  = _tcschr(lpClassCopy, _T('\\'));    /* The class name ends by '\' */
+  if (!classNameEnd) {                          /* or the whole string */
+      classNameEnd = lpClassCopy + _tcslen(lpClassCopy);
+      if (classNameEnd[-1] == _T(']')) {
+          classNameEnd--;
+      }
+  }
+  *classNameEnd = _T('\0');                       /* Isolate the class name */
+  if (lpClassCopy[0] == _T('[')) {
+      classNameBeg = lpClassCopy + 1;
+  } else {
+      classNameBeg = lpClassCopy;
+  }
+  for (i = 0; i < REG_CLASS_NUMBER; i++) {
+      if (!_tcscmp(classNameBeg, reg_class_names[i])) {
+          return reg_class_keys[i];
+      }
+  }
+  return (HKEY)ERROR_INVALID_PARAMETER;
+}
+
+/******************************************************************************
+ * Close the currently opened key.
+ */
+void closeKey(VOID)
+{
+    RegCloseKey(currentKeyHandle);
+    HeapFree(GetProcessHeap(), 0, currentKeyName); /* Allocated by getKeyName */
+    bTheKeyIsOpen    = FALSE;
+    currentKeyName   = NULL;
+    currentKeyClass  = 0;
+    currentKeyHandle = 0;
+}
+
+/******************************************************************************
+ * This function is the main entry point to the setValue type of action.  It
+ * receives the currently read line and dispatch the work depending on the
+ * context.
+ */
+void doSetValue(LPTSTR stdInput)
+{
+  /*
+   * We encountered the end of the file, make sure we
+   * close the opened key and exit
+   */
+  if (stdInput == NULL) {
+    if (bTheKeyIsOpen != FALSE)
+      closeKey();
+    return;
+  }
+
+  if (stdInput[0] == _T('[')) {     /* We are reading a new key */
+      if (bTheKeyIsOpen != FALSE) {
+          closeKey();                    /* Close the previous key before */
+      }
+      if (openKey(stdInput) != ERROR_SUCCESS) {
+          _tprintf(_T("doSetValue failed to open key %s\n"), stdInput);
+      }
+  } else if ((bTheKeyIsOpen) &&
+            ((stdInput[0] == _T('@')) || /* reading a default @=data pair */
+             (stdInput[0] == _T('\"')))) { /* reading a new value=data pair */
+    processSetValue(stdInput);
+  } else {             /* since we are assuming that the file format is */
+    if (bTheKeyIsOpen) /* valid we must be reading a blank line which  */
+      closeKey();      /* indicate end of this key processing */
+  }
+}
+
+/******************************************************************************
+ * This funtion is the main entry point to the queryValue type of action.  It
+ * receives the currently read line and dispatch the work depending on the
+ * context.
+ */
+void doQueryValue(LPTSTR stdInput) {
+  /*
+   * We encoutered the end of the file, make sure we
+   * close the opened key and exit
+   */
+  if (stdInput == NULL) {
+    if (bTheKeyIsOpen != FALSE)
+      closeKey();
+    return;
+  }
+
+  if (stdInput[0] == _T('[')) {     /* We are reading a new key */
+    if (bTheKeyIsOpen != FALSE)
+      closeKey();                    /* Close the previous key before */
+    if (openKey(stdInput) != ERROR_SUCCESS ) {
+      _tprintf(_T("doQueryValue failed to open key %s\n"), stdInput);
+    }
+  }
+  else if( (bTheKeyIsOpen) &&
+           ((stdInput[0] == _T('@')) || /* reading a default @=data pair */
+           (stdInput[0] == _T('\"')))) { /* reading a new value=data pair */
+    processQueryValue(stdInput);
+  } else {                /* since we are assuming that the file format is */
+    if (bTheKeyIsOpen)    /* valid we must be reading a blank line which  */
+      closeKey();         /* indicate end of this key processing */
+  }
+}
+
+/******************************************************************************
+ * This funtion is the main entry point to the deletetValue type of action.  It
+ * receives the currently read line and dispatch the work depending on the
+ * context.
+ */
+void doDeleteValue(LPTSTR line) {
+  _tprintf(_T("deleteValue not yet implemented\n"));
+}
+
+/******************************************************************************
+ * This funtion is the main entry point to the deleteKey type of action.  It
+ * receives the currently read line and dispatch the work depending on the
+ * context.
+ */
+void doDeleteKey(LPTSTR line)   {
+  _tprintf(_T("deleteKey not yet implemented\n"));
+}
+
+/******************************************************************************
+ * This funtion is the main entry point to the createKey type of action.  It
+ * receives the currently read line and dispatch the work depending on the
+ * context.
+ */
+void doCreateKey(LPTSTR line)   {
+  _tprintf(_T("createKey not yet implemented\n"));
+}
+
+/******************************************************************************
+ * This function is a wrapper for the setValue function.  It prepares the
+ * land and clean the area once completed.
+ * Note: this function modifies the line parameter.
+ *
+ * line - registry file unwrapped line. Should have the registry value name and
+ *      complete registry value data.
+ */
+void processSetValue(LPTSTR line)
+{
+  LPTSTR val_name;                   /* registry value name   */
+  LPTSTR val_data;                   /* registry value data   */
+
+  int line_idx = 0;                 /* current character under analysis */
+  HRESULT hRes = 0;
+
+  /* get value name */
+  if (line[line_idx] == _T('@') && line[line_idx + 1] == _T('=')) {
+      line[line_idx] = _T('\0');
+      val_name = line;
+      line_idx++;
+  } else if (line[line_idx] == _T('\"')) {
+      line_idx++;
+      val_name = line + line_idx;
+      while (TRUE) {
+          if (line[line_idx] == _T('\\')) {  /* skip escaped character */
+              line_idx += 2;
+          } else {
+              if (line[line_idx] == _T('\"')) {
+                  line[line_idx] = _T('\0');
+                  line_idx++;
+                  break;
+              } else {
+                  line_idx++;
+              }
+          }
+      }
+      if (line[line_idx] != _T('=')) {
+          line[line_idx] = _T('\"');
+          _tprintf(_T("Warning! uncrecognized line:\n%s\n"), line);
+          return;
+      }
+  } else {
+      _tprintf(_T("Warning! unrecognized line:\n%s\n"), line);
+      return;
+  }
+  line_idx++;                   /* skip the '=' character */
+  val_data = line + line_idx;
+  REGPROC_unescape_string(val_name);
+
+    _tprintf(_T("Key: %s, Value: %s, Data: %s\n"), currentKeyName, val_name, val_data);
+
+  hRes = setValue(val_name, val_data);
+  if (hRes != ERROR_SUCCESS) {
+    _tprintf(_T("ERROR Key %s not created. Value: %s, Data: %s\n"), currentKeyName, val_name, val_data);
+  }
+}
+
+/******************************************************************************
+ * This function is a wrapper for the queryValue function.  It prepares the
+ * land and clean the area once completed.
+ */
+void processQueryValue(LPTSTR cmdline)
+{
+  _tprintf(_T("ERROR!!! - temporary disabled"));
+  //exit(1);
+  return;
+#if 0
+  LPSTR   argv[QUERY_VALUE_MAX_ARGS];/* args storage    */
+  LPSTR   token      = NULL;         /* current token analized */
+  ULONG   argCounter = 0;            /* counter of args */
+  INT     counter;
+  HRESULT hRes       = 0;
+  LPSTR   keyValue   = NULL;
+  LPSTR   lpsRes     = NULL;
+
+  /*
+   * Init storage and parse the line
+   */
+  for (counter = 0; counter < QUERY_VALUE_MAX_ARGS; counter++)
+    argv[counter] = NULL;
+
+  while ((token = getToken(&cmdline, queryValueDelim[argCounter])) != NULL) {
+    argv[argCounter++] = getArg(token);
+    if (argCounter == QUERY_VALUE_MAX_ARGS)
+      break;  /* Stop processing args no matter what */
+  }
+
+  /* The value we look for is the first token on the line */
+  if (argv[0] == NULL)
+    return; /* SHOULD NOT HAPPEN */
+  else
+    keyValue = argv[0];
+
+  if ((keyValue[0] == '@') && (_tcslen(keyValue) == 1)) {
+    LONG lLen = KEY_MAX_LEN;
+    TCHAR* lpsData = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,KEY_MAX_LEN);
+    /*
+     * We need to query the key default value
+     */
+    hRes = RegQueryValue(currentKeyHandle, currentKeyName, (LPBYTE)lpsData, &lLen);
+    if (hRes == ERROR_MORE_DATA) {
+        lpsData = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lpsData, lLen);
+        hRes = RegQueryValue(currentKeyHandle, currentKeyName, (LPBYTE)lpsData, &lLen);
+    }
+    if (hRes == ERROR_SUCCESS) {
+      lpsRes = HeapAlloc(GetProcessHeap(), 0, lLen);
+      strncpy(lpsRes, lpsData, lLen);
+      lpsRes[lLen-1]='\0';
+    }
+  } else {
+    DWORD dwLen = KEY_MAX_LEN;
+    BYTE* lpbData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, KEY_MAX_LEN);
+    DWORD dwType;
+    /*
+     * We need to query a specific value for the key
+     */
+    hRes = RegQueryValueEx(
+             currentKeyHandle,
+             keyValue,
+             0,
+             &dwType,
+             (LPBYTE)lpbData,
+             &dwLen);
+
+    if (hRes == ERROR_MORE_DATA) {
+        lpbData = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lpbData, dwLen * sizeof(TCHAR));
+        hRes = RegQueryValueEx(currentKeyHandle, keyValue, NULL, &dwType, (LPBYTE)lpbData, &dwLen);
+    }
+
+    if (hRes == ERROR_SUCCESS) {
+      /*
+       * Convert the returned data to a displayable format
+       */
+      switch (dwType) {
+        case REG_SZ:
+        case REG_EXPAND_SZ:
+          lpsRes = HeapAlloc(GetProcessHeap(), 0, dwLen * sizeof(TCHAR));
+          strncpy(lpsRes, lpbData, dwLen);
+          lpsRes[dwLen-1] = '\0';
+          break;
+        case REG_DWORD:
+          lpsRes = convertHexToDWORDStr(lpbData, dwLen);
+          break;
+        default:
+          lpsRes = convertHexToHexCSV(lpbData, dwLen);
+          break;
+      }
+    }
+
+    HeapFree(GetProcessHeap(), 0, lpbData);
+  }
+  if (hRes == ERROR_SUCCESS) {
+    _tprintf(_T("Value \"%s\" = \"%s\" in key [%s]\n"), keyValue, lpsRes, currentKeyName);
+
+  } else {
+    _tprintf(_T("ERROR Value \"%s\" not found. for key \"%s\"\n"), keyValue, currentKeyName);
+  }
+
+  /*
+   * Do some cleanup
+   */
+  for (counter=0; counter<argCounter; counter++)
+    if (argv[counter] != NULL)
+      HeapFree(GetProcessHeap(), 0, argv[counter]);
+
+  if (lpsRes != NULL)
+    HeapFree(GetProcessHeap(), 0, lpsRes);
+#endif
+}
+
+/******************************************************************************
+ * Calls command for each line of a registry file.
+ * Correctly processes comments (in # form), line continuation.
+ *
+ * Parameters:
+ *   in - input stream to read from
+ *   command - command to be called for each line
+ */
+void processRegLines(FILE *in, CommandAPI command)
+{
+    LPTSTR line     = NULL;  /* line read from input stream */
+    ULONG lineSize = REG_VAL_BUF_SIZE;
+
+    line = HeapAlloc(GetProcessHeap(), 0, lineSize * sizeof(TCHAR));
+    CHECK_ENOUGH_MEMORY(line);
+
+    while (!feof(in)) {
+        LPTSTR s; /* The pointer into line for where the current fgets should read */
+        s = line;
+        for (;;) {
+            size_t size_remaining;
+            int size_to_get;
+            TCHAR *s_eol; /* various local uses */
+
+            /* Do we need to expand the buffer ? */
+            assert (s >= line && s <= line + lineSize);
+            size_remaining = lineSize - (s-line);
+            if (size_remaining < 2) { /* room for 1 character and the \0 */
+                TCHAR *new_buffer;
+                size_t new_size = lineSize + REG_VAL_BUF_SIZE;
+                if (new_size > lineSize) /* no arithmetic overflow */
+                    new_buffer = HeapReAlloc (GetProcessHeap(), 0, line, new_size * sizeof(TCHAR));
+                else
+                    new_buffer = NULL;
+                CHECK_ENOUGH_MEMORY(new_buffer);
+                line = new_buffer;
+                s = line + lineSize - size_remaining;
+                lineSize = new_size;
+                size_remaining = lineSize - (s-line);
+            }
+
+            /* Get as much as possible into the buffer, terminated either by
+             * eof, error, eol or getting the maximum amount.  Abort on error.
+             */
+//
+// This line is surely foobar, don't want to read INT_MAX in buffer at s, it's never going to be that big...
+//            size_to_get = (size_remaining > INT_MAX ? INT_MAX : size_remaining);
+//
+// Looks as if 'lineSize' contains the number of characters of buffer size
+//
+            size_to_get = (size_remaining > lineSize ? lineSize : size_remaining);
+
+            if (NULL == _fgetts(s, size_to_get, in)) {
+                if (ferror(in)) {
+                    //_tperror(_T("While reading input"));
+                    perror ("While reading input");
+                    //exit(IO_ERROR);
+                    return;
+                } else {
+                    assert (feof(in));
+                    *s = _T('\0');
+                    /* It is not clear to me from the definition that the
+                     * contents of the buffer are well defined on detecting
+                     * an eof without managing to read anything.
+                     */
+                }
+            }
+
+            /* If we didn't read the eol nor the eof go around for the rest */
+            s_eol = _tcschr (s, _T('\n'));
+            if (!feof (in) && !s_eol) {
+                s = _tcschr (s, _T('\0'));
+                /* It should be s + size_to_get - 1 but this is safer */
+                continue;
+            }
+
+            /* If it is a comment line then discard it and go around again */
+            if (line [0] == _T('#')) {
+                s = line;
+                continue;
+            }
+
+            /* Remove any line feed.  Leave s_eol on the \0 */
+            if (s_eol) {
+                *s_eol = _T('\0');
+                if (s_eol > line && *(s_eol-1) == _T('\r'))
+                    *--s_eol = _T('\0');
+            } else {
+                s_eol = _tcschr (s, _T('\0'));
+            }
+            /* If there is a concatenating \\ then go around again */
+            if (s_eol > line && *(s_eol-1) == _T('\\')) {
+                int c;
+                s = s_eol-1;
+                /* The following error protection could be made more self-
+                 * correcting but I thought it not worth trying.
+                 */
+
+                if ((c = _fgettc(in)) == _TEOF || c != _T(' ') ||
+                    (c = _fgettc(in)) == _TEOF || c != _T(' '))
+                    _tprintf(_T("ERROR - invalid continuation.\n"));
+                continue;
+            }
+            break; /* That is the full virtual line */
+        }
+        command(line);
+    }
+    command(NULL);
+    HeapFree(GetProcessHeap(), 0, line);
+}
+
+/******************************************************************************
+ * This funtion is the main entry point to the registerDLL action.  It
+ * receives the currently read line, then loads and registers the requested DLLs
+ */
+void doRegisterDLL(LPTSTR stdInput)
+{
+    HMODULE theLib = 0;
+    UINT retVal = 0;
+
+    /* Check for valid input */
+    if (stdInput == NULL) return;
+
+    /* Load and register the library, then free it */
+    theLib = LoadLibrary(stdInput);
+    if (theLib) {
+        FARPROC lpfnDLLRegProc = GetProcAddress(theLib, "DllRegisterServer");
+        if (lpfnDLLRegProc) {
+            retVal = (*lpfnDLLRegProc)();
+        } else {
+            _tprintf(_T("Couldn't find DllRegisterServer proc in '%s'.\n"), stdInput);
+        }
+        if (retVal != S_OK) {
+            _tprintf(_T("Couldn't find DllRegisterServer proc in '%s'.\n"), stdInput);
+        }
+        FreeLibrary(theLib);
+    } else {
+        _tprintf(_T("Could not load DLL '%s'.\n"), stdInput);
+    }
+}
+
+/******************************************************************************
+ * This funtion is the main entry point to the unregisterDLL action.  It
+ * receives the currently read line, then loads and unregisters the requested DLLs
+ */
+void doUnregisterDLL(LPTSTR stdInput)
+{
+    HMODULE theLib = 0;
+    UINT retVal = 0;
+
+    /* Check for valid input */
+    if (stdInput == NULL) return;
+
+    /* Load and unregister the library, then free it */
+    theLib = LoadLibrary(stdInput);
+    if (theLib) {
+        FARPROC lpfnDLLRegProc = GetProcAddress(theLib, "DllUnregisterServer");
+        if (lpfnDLLRegProc) {
+            retVal = (*lpfnDLLRegProc)();
+        } else {
+            _tprintf(_T("Couldn't find DllUnregisterServer proc in '%s'.\n"), stdInput);
+        }
+        if (retVal != S_OK) {
+            _tprintf(_T("DLLUnregisterServer error 0x%x in '%s'.\n"), retVal, stdInput);
+        }
+        FreeLibrary(theLib);
+    } else {
+        _tprintf(_T("Could not load DLL '%s'.\n"), stdInput);
+    }
+}
+
+/****************************************************************************
+ * REGPROC_print_error
+ *
+ * Print the message for GetLastError
+ */
+
+void REGPROC_print_error(VOID)
+{
+    LPVOID lpMsgBuf;
+    DWORD error_code;
+    int status;
+
+    error_code = GetLastError ();
+    status = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+                           NULL, error_code, 0, (LPTSTR) &lpMsgBuf, 0, NULL);
+    if (!status) {
+        _tprintf(_T("Cannot display message for error %ld, status %ld\n"), error_code, GetLastError());
+    } else {
+        _tprintf(_T("REGPROC_print_error() - "));
+        puts(lpMsgBuf);
+        LocalFree((HLOCAL)lpMsgBuf);
+    }
+    //exit(1);
+}
+
+/******************************************************************************
+ * Checks whether the buffer has enough room for the string or required size.
+ * Resizes the buffer if necessary.
+ *
+ * Parameters:
+ * buffer - pointer to a buffer for string
+ * len - current length of the buffer in characters.
+ * required_len - length of the string to place to the buffer in characters.
+ *   The length does not include the terminating null character.
+ */
+void REGPROC_resize_char_buffer(TCHAR **buffer, DWORD *len, DWORD required_len)
+{
+    required_len++;
+    if (required_len > *len) {
+        *len = required_len;
+        *buffer = HeapReAlloc(GetProcessHeap(), 0, *buffer, *len * sizeof(**buffer));
+        CHECK_ENOUGH_MEMORY(*buffer);
+    }
+}
+
+/******************************************************************************
+ * Prints string str to file
+ */
+void REGPROC_export_string(FILE *file, TCHAR *str)
+{
+    size_t len = _tcslen(str);
+    size_t i;
+
+    /* escaping characters */
+    for (i = 0; i < len; i++) {
+        TCHAR c = str[i];
+        switch (c) {
+        //case _T('\\'): _fputts(_T("\\\\"), file); break;
+        case _T('\"'): _fputts(_T("\\\""), file); break;
+        case _T('\n'): _fputts(_T("\\\n"), file); break;
+        default:       _fputtc(c, file);          break;
+        }
+    }
+}
+
+/******************************************************************************
+ * Writes contents of the registry key to the specified file stream.
+ *
+ * Parameters:
+ * file - writable file stream to export registry branch to.
+ * key - registry branch to export.
+ * reg_key_name_buf - name of the key with registry class.
+ *      Is resized if necessary.
+ * reg_key_name_len - length of the buffer for the registry class in characters.
+ * val_name_buf - buffer for storing value name.
+ *      Is resized if necessary.
+ * val_name_len - length of the buffer for storing value names in characters.
+ * val_buf - buffer for storing values while extracting.
+ *      Is resized if necessary.
+ * val_size - size of the buffer for storing values in bytes.
+ */
+void export_hkey(FILE *file, HKEY key,
+                 TCHAR **reg_key_name_buf, DWORD *reg_key_name_len,
+                 TCHAR **val_name_buf, DWORD *val_name_len,
+                 BYTE **val_buf, DWORD *val_size)
+{
+    DWORD max_sub_key_len;
+    DWORD max_val_name_len;
+    DWORD max_val_size;
+    DWORD curr_len;
+    DWORD i;
+    BOOL more_data;
+    LONG ret;
+
+    /* get size information and resize the buffers if necessary */
+    if (RegQueryInfoKey(key, NULL, NULL, NULL, NULL, &max_sub_key_len, NULL,
+                        NULL, &max_val_name_len, &max_val_size, NULL, NULL) != ERROR_SUCCESS) {
+        REGPROC_print_error();
+    }
+    curr_len = _tcslen(*reg_key_name_buf);
+    REGPROC_resize_char_buffer(reg_key_name_buf, reg_key_name_len, max_sub_key_len + curr_len + 1);
+    REGPROC_resize_char_buffer(val_name_buf, val_name_len, max_val_name_len);
+    if (max_val_size > *val_size) {
+        *val_size = max_val_size;
+        *val_buf = HeapReAlloc(GetProcessHeap(), 0, *val_buf, *val_size * sizeof(TCHAR));
+        CHECK_ENOUGH_MEMORY(val_buf);
+    }
+    /* output data for the current key */
+    _fputts(_T("\n["), file);
+    _fputts(*reg_key_name_buf, file);
+    _fputts(_T("]\n"), file);
+    /* print all the values */
+    i = 0;
+    more_data = TRUE;
+    while (more_data) {
+        DWORD value_type;
+        DWORD val_name_len1 = *val_name_len;
+        DWORD val_size1 = *val_size;
+        ret = RegEnumValue(key, i, *val_name_buf, &val_name_len1, NULL, &value_type, *val_buf, &val_size1);
+        if (ret != ERROR_SUCCESS) {
+            more_data = FALSE;
+            if (ret != ERROR_NO_MORE_ITEMS) {
+                REGPROC_print_error();
+            }
+        } else {
+            i++;
+            if ((*val_name_buf)[0]) {
+                _fputts(_T("\""), file);
+                REGPROC_export_string(file, *val_name_buf);
+                _fputts(_T("\"="), file);
+            } else {
+                _fputts(_T("@="), file);
+            }
+            switch (value_type) {
+            case REG_EXPAND_SZ:
+                _fputts(_T("expand:"), file);
+            case REG_SZ:
+                _fputts(_T("\""), file);
+                REGPROC_export_string(file, *val_buf);
+                _fputts(_T("\"\n"), file);
+                break;
+            case REG_DWORD:
+                _ftprintf(file, _T("dword:%08lx\n"), *((DWORD *)*val_buf));
+                break;
+            default:
+/*
+                _tprintf(_T("warning - unsupported registry format '%ld', ") \
+                         _T("treating as binary\n"), value_type);
+                _tprintf(_T("key name: \"%s\"\n"), *reg_key_name_buf);
+                _tprintf(_T("value name:\"%s\"\n\n"), *val_name_buf);
+ */
+                /* falls through */
+            case REG_MULTI_SZ:
+                /* falls through */
+            case REG_BINARY:
+            {
+                DWORD i1;
+                TCHAR *hex_prefix;
+                TCHAR buf[20];
+                int cur_pos;
+
+                if (value_type == REG_BINARY) {
+                    hex_prefix = _T("hex:");
+                } else {
+                    hex_prefix = buf;
+                    _stprintf(buf, _T("hex(%ld):"), value_type);
+                }
+                /* position of where the next character will be printed */
+                /* NOTE: yes, _tcslen("hex:") is used even for hex(x): */
+                cur_pos = _tcslen(_T("\"\"=")) + _tcslen(_T("hex:")) +
+                    _tcslen(*val_name_buf);
+                _fputts(hex_prefix, file);
+                for (i1 = 0; i1 < val_size1; i1++) {
+                    _ftprintf(file, _T("%02x"), (unsigned int)(*val_buf)[i1]);
+                    if (i1 + 1 < val_size1) {
+                        _fputts(_T(","), file);
+                    }
+                    cur_pos += 3;
+                    /* wrap the line */
+                    if (cur_pos > REG_FILE_HEX_LINE_LEN) {
+                        _fputts(_T("\\\n  "), file);
+                        cur_pos = 2;
+                    }
+                }
+                _fputts(_T("\n"), file);
+                break;
+            }
+            }
+        }
+    }
+    i = 0;
+    more_data = TRUE;
+    (*reg_key_name_buf)[curr_len] = _T('\\');
+    while (more_data) {
+        DWORD buf_len = *reg_key_name_len - curr_len;
+        ret = RegEnumKeyEx(key, i, *reg_key_name_buf + curr_len + 1, &buf_len, NULL, NULL, NULL, NULL);
+        if (ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA) {
+            more_data = FALSE;
+            if (ret != ERROR_NO_MORE_ITEMS) {
+                REGPROC_print_error();
+            }
+        } else {
+            HKEY subkey;
+
+            i++;
+            if (RegOpenKey(key, *reg_key_name_buf + curr_len + 1, &subkey) == ERROR_SUCCESS) {
+                export_hkey(file, subkey, reg_key_name_buf, reg_key_name_len, val_name_buf, val_name_len, val_buf, val_size);
+                RegCloseKey(subkey);
+            } else {
+                REGPROC_print_error();
+            }
+        }
+    }
+    (*reg_key_name_buf)[curr_len] = _T('\0');
+}
+/*
+#define REG_NONE                    ( 0 )   // No value type
+#define REG_SZ                      ( 1 )   // Unicode nul terminated string
+#define REG_EXPAND_SZ               ( 2 )   // Unicode nul terminated string
+                                            // (with environment variable references)
+#define REG_BINARY                  ( 3 )   // Free form binary
+#define REG_DWORD                   ( 4 )   // 32-bit number
+#define REG_DWORD_LITTLE_ENDIAN     ( 4 )   // 32-bit number (same as REG_DWORD)
+#define REG_DWORD_BIG_ENDIAN        ( 5 )   // 32-bit number
+#define REG_LINK                    ( 6 )   // Symbolic Link (unicode)
+#define REG_MULTI_SZ                ( 7 )   // Multiple Unicode strings
+#define REG_RESOURCE_LIST           ( 8 )   // Resource list in the resource map
+#define REG_FULL_RESOURCE_DESCRIPTOR ( 9 )  // Resource list in the hardware description
+#define REG_RESOURCE_REQUIREMENTS_LIST ( 10 )
+
+ */
+/******************************************************************************
+ * Open file for export.
+ */
+FILE *REGPROC_open_export_file(TCHAR *file_name)
+{
+//_CRTIMP FILE * __cdecl _wfopen(const wchar_t *, const wchar_t *);
+
+//FILE*        fopen (const char* szFileName, const char* szMode);
+//FILE*        _wfopen(const wchar_t *file, const wchar_t *mode);
+
+    FILE *file = _tfopen(file_name, _T("w"));
+    if (!file) {
+        perror("");
+        _tprintf(_T("REGPROC_open_export_file(%s) - Can't open file.\n"), file_name);
+        //exit(1);
+        return NULL;
+    }
+    _fputts(_T("REGEDIT4\n"), file);
+    return file;
+}
+
+/******************************************************************************
+ * Writes contents of the registry key to the specified file stream.
+ *
+ * Parameters:
+ * file_name - name of a file to export registry branch to.
+ * reg_key_name - registry branch to export. The whole registry is exported if
+ *      reg_key_name is NULL or contains an empty string.
+ */
+BOOL export_registry_key(TCHAR* file_name, TCHAR* reg_key_name)
+{
+    HKEY reg_key_class;
+
+    TCHAR *reg_key_name_buf;
+    TCHAR *val_name_buf;
+    BYTE *val_buf;
+    DWORD reg_key_name_len = KEY_MAX_LEN;
+    DWORD val_name_len = KEY_MAX_LEN;
+    DWORD val_size = REG_VAL_BUF_SIZE;
+    FILE *file = NULL;
+
+    //_tprintf(_T("export_registry_key(%s, %s)\n"), reg_key_name, file_name);
+
+    reg_key_name_buf = HeapAlloc(GetProcessHeap(), 0, reg_key_name_len * sizeof(*reg_key_name_buf));
+    val_name_buf = HeapAlloc(GetProcessHeap(), 0, val_name_len * sizeof(*val_name_buf));
+    val_buf = HeapAlloc(GetProcessHeap(), 0, val_size);
+    CHECK_ENOUGH_MEMORY(reg_key_name_buf && val_name_buf && val_buf);
+
+    if (reg_key_name && reg_key_name[0]) {
+        TCHAR *branch_name;
+        HKEY key;
+
+        REGPROC_resize_char_buffer(&reg_key_name_buf, &reg_key_name_len,
+                                   _tcslen(reg_key_name));
+        _tcscpy(reg_key_name_buf, reg_key_name);
+
+        /* open the specified key */
+        reg_key_class = getRegClass(reg_key_name);
+        if (reg_key_class == (HKEY)ERROR_INVALID_PARAMETER) {
+            _tprintf(_T("Incorrect registry class specification in '%s\n"), reg_key_name);
+            //exit(1);
+            return FALSE;
+        }
+        branch_name = getRegKeyName(reg_key_name);
+        CHECK_ENOUGH_MEMORY(branch_name);
+        if (!branch_name[0]) {
+            /* no branch - registry class is specified */
+            file = REGPROC_open_export_file(file_name);
+            export_hkey(file, reg_key_class,
+                        &reg_key_name_buf, &reg_key_name_len,
+                        &val_name_buf, &val_name_len,
+                        &val_buf, &val_size);
+        } else if (RegOpenKey(reg_key_class, branch_name, &key) == ERROR_SUCCESS) {
+            file = REGPROC_open_export_file(file_name);
+            export_hkey(file, key,
+                        &reg_key_name_buf, &reg_key_name_len,
+                        &val_name_buf, &val_name_len,
+                        &val_buf, &val_size);
+            RegCloseKey(key);
+        } else {
+            _tprintf(_T("Can't export. Registry key '%s does not exist!\n"), reg_key_name);
+            REGPROC_print_error();
+        }
+        HeapFree(GetProcessHeap(), 0, branch_name);
+    } else {
+        int i;
+
+        /* export all registry classes */
+        file = REGPROC_open_export_file(file_name);
+        for (i = 0; i < REG_CLASS_NUMBER; i++) {
+            /* do not export HKEY_CLASSES_ROOT */
+            if (reg_class_keys[i] != HKEY_CLASSES_ROOT &&
+                reg_class_keys[i] != HKEY_CURRENT_USER &&
+                reg_class_keys[i] != HKEY_CURRENT_CONFIG) {
+                _tcscpy(reg_key_name_buf, reg_class_names[i]);
+                export_hkey(file, reg_class_keys[i],
+                            &reg_key_name_buf, &reg_key_name_len,
+                            &val_name_buf, &val_name_len,
+                            &val_buf, &val_size);
+            }
+        }
+    }
+    if (file) {
+        fclose(file);
+    }
+//    HeapFree(GetProcessHeap(), 0, reg_key_name);
+    HeapFree(GetProcessHeap(), 0, val_buf);
+    HeapFree(GetProcessHeap(), 0, val_name_buf);
+    HeapFree(GetProcessHeap(), 0, reg_key_name_buf);
+    return TRUE;
+}
+
+/******************************************************************************
+ * Reads contents of the specified file into the registry.
+ */
+BOOL import_registry_file(LPTSTR filename)
+{
+    FILE* reg_file = _tfopen(filename, _T("r"));
+
+    if (reg_file) {
+        processRegLines(reg_file, doSetValue);
+        return TRUE;
+    }
+    return FALSE;
+}
+
+/******************************************************************************
+ * Recursive function which removes the registry key with all subkeys.
+ */
+BOOL delete_branch(HKEY key, TCHAR** reg_key_name_buf, DWORD* reg_key_name_len)
+{
+    HKEY branch_key;
+    DWORD max_sub_key_len;
+    DWORD subkeys;
+    DWORD curr_len;
+    LONG ret;
+    long int i;
+
+    if (RegOpenKey(key, *reg_key_name_buf, &branch_key) != ERROR_SUCCESS) {
+        REGPROC_print_error();
+        return FALSE;
+    }
+
+    /* get size information and resize the buffers if necessary */
+    if (RegQueryInfoKey(branch_key, NULL, NULL, NULL, &subkeys, &max_sub_key_len,
+                        NULL, NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) {
+        REGPROC_print_error();
+        RegCloseKey(branch_key);
+        return FALSE;
+    }
+    curr_len = _tcslen(*reg_key_name_buf);
+    REGPROC_resize_char_buffer(reg_key_name_buf, reg_key_name_len, max_sub_key_len + curr_len + 1);
+
+    (*reg_key_name_buf)[curr_len] = '\\';
+    for (i = subkeys - 1; i >= 0; i--) {
+        DWORD buf_len = *reg_key_name_len - curr_len;
+        ret = RegEnumKeyEx(branch_key, i, *reg_key_name_buf + curr_len + 1, &buf_len, NULL, NULL, NULL, NULL);
+        if (ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA && ret != ERROR_NO_MORE_ITEMS) {
+            REGPROC_print_error();
+            RegCloseKey(branch_key);
+            return FALSE;
+        } else {
+            delete_branch(key, reg_key_name_buf, reg_key_name_len);
+        }
+    }
+    (*reg_key_name_buf)[curr_len] = '\0';
+    RegCloseKey(branch_key);
+    RegDeleteKey(key, *reg_key_name_buf);
+    return TRUE;
+}
+
+/******************************************************************************
+ * Removes the registry key with all subkeys. Parses full key name.
+ *
+ * Parameters:
+ * reg_key_name - full name of registry branch to delete. Ignored if is NULL,
+ *      empty, points to register key class, does not exist.
+ */
+void delete_registry_key(TCHAR* reg_key_name)
+{
+    TCHAR* branch_name;
+    DWORD branch_name_len;
+    HKEY reg_key_class;
+    HKEY branch_key;
+
+    if (!reg_key_name || !reg_key_name[0]) {
+        return;
+    }
+    /* open the specified key */
+    reg_key_class = getRegClass(reg_key_name);
+    if (reg_key_class == (HKEY)ERROR_INVALID_PARAMETER) {
+        _tprintf(_T("Incorrect registry class specification in '%s'\n"), reg_key_name);
+        //exit(1);
+        return;
+    }
+    branch_name = getRegKeyName(reg_key_name);
+    CHECK_ENOUGH_MEMORY(branch_name);
+    branch_name_len = _tcslen(branch_name);
+    if (!branch_name[0]) {
+        _tprintf(_T("Can't delete registry class '%s'\n"), reg_key_name);
+        //exit(1);
+        return;
+    }
+    if (RegOpenKey(reg_key_class, branch_name, &branch_key) == ERROR_SUCCESS) {
+        /* check whether the key exists */
+        RegCloseKey(branch_key);
+        delete_branch(reg_key_class, &branch_name, &branch_name_len);
+    }
+    HeapFree(GetProcessHeap(), 0, branch_name);
+}
+
diff --git a/rosapps/tests/regdump/regproc.h b/rosapps/tests/regdump/regproc.h
new file mode 100644 (file)
index 0000000..70215a1
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright 1999 Sylvain St-Germain
+ * Copyright 2002 Andriy Palamarchuk
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/******************************************************************************
+ * Defines and consts
+ */
+#define KEY_MAX_LEN             1024
+
+/* Return values */
+#define SUCCESS               0
+#define KEY_VALUE_ALREADY_SET 2
+
+typedef void (*CommandAPI)(LPTSTR lpsLine);
+
+void doSetValue(LPTSTR lpsLine);
+void doDeleteValue(LPTSTR lpsLine);
+void doCreateKey(LPTSTR lpsLine);
+void doDeleteKey(LPTSTR lpsLine);
+void doQueryValue(LPTSTR lpsLine);
+void doRegisterDLL(LPTSTR lpsLine);
+void doUnregisterDLL(LPTSTR lpsLine);
+
+BOOL export_registry_key(TCHAR* file_name, TCHAR* reg_key_name);
+BOOL import_registry_file(LPTSTR filename);
+void delete_registry_key(TCHAR* reg_key_name);
+
+void processRegLines(FILE* in, CommandAPI command);
+
+/*
+ * Generic prototypes
+ */
+#ifdef _UNICODE
+#define get_file_name get_file_nameW
+#else
+#define get_file_name get_file_nameA
+#endif
+
+char*   getToken(char** str, const char* delims);
+void    get_file_nameA(CHAR** command_line, CHAR* filename, int max_filename);
+void    get_file_nameW(CHAR** command_line, WCHAR* filename, int max_filename);
+DWORD   convertHexToDWord(TCHAR* str, BYTE* buf);
+DWORD   convertHexCSVToHex(TCHAR* str, BYTE* buf, ULONG bufLen);
+LPTSTR  convertHexToHexCSV(BYTE* buf, ULONG len);
+LPTSTR  convertHexToDWORDStr(BYTE* buf, ULONG len);
+LPTSTR  getRegKeyName(LPTSTR lpLine);
+HKEY    getRegClass(LPTSTR lpLine);
+DWORD   getDataType(LPTSTR* lpValue, DWORD* parse_type);
+LPTSTR  getArg(LPTSTR arg);
+HRESULT openKey(LPTSTR stdInput);
+void    closeKey(VOID);
+
+/*
+ * api setValue prototypes
+ */
+void    processSetValue(LPTSTR cmdline);
+HRESULT setValue(LPTSTR val_name, LPTSTR val_data);
+
+/*
+ * api queryValue prototypes
+ */
+void    processQueryValue(LPTSTR cmdline);
+
+#ifdef __GNUC__
+#ifdef WIN32_REGDBG
+//typedef UINT_PTR SIZE_T, *PSIZE_T;
+//#define _MAX_PATH   260 /* max. length of full pathname */
+#endif /*WIN32_REGDBG*/
+
+#ifdef UNICODE
+#define _tfopen     _wfopen
+#else
+#define _tfopen     fopen
+#endif
+
+#endif /*__GNUC__*/
+
+LPVOID RegHeapAlloc(
+  HANDLE hHeap,   // handle to private heap block
+  DWORD dwFlags,  // heap allocation control
+  SIZE_T dwBytes  // number of bytes to allocate
+);
+
+LPVOID RegHeapReAlloc(
+  HANDLE hHeap,   // handle to heap block
+  DWORD dwFlags,  // heap reallocation options
+  LPVOID lpMem,   // pointer to memory to reallocate
+  SIZE_T dwBytes  // number of bytes to reallocate
+);
+
+BOOL RegHeapFree(
+  HANDLE hHeap,  // handle to heap
+  DWORD dwFlags, // heap free options
+  LPVOID lpMem   // pointer to memory
+);
diff --git a/rosapps/tests/shm/.cvsignore b/rosapps/tests/shm/.cvsignore
new file mode 100644 (file)
index 0000000..060f7fa
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.a
+*.exe
+*.coff
+*.sym
+*.map
\ No newline at end of file
diff --git a/rosapps/tests/shm/makefile b/rosapps/tests/shm/makefile
new file mode 100644 (file)
index 0000000..a9e4d96
--- /dev/null
@@ -0,0 +1,54 @@
+#
+#
+#
+PATH_TO_TOP = ../../../reactos
+
+include $(PATH_TO_TOP)/config
+include $(PATH_TO_TOP)/rules.mak
+
+SRV_OBJECTS= shmsrv.o
+CLT_OBJECTS= shmclt.o
+
+PROGS= shmsrv.exe shmclt.exe
+
+CFLAGS = $(STD_CFLAGS)
+
+LIBS = $(SDK_PATH_LIB)/kernel32.a \
+  $(SDK_PATH_LIB)/ntdll.a
+
+all: $(PROGS)
+
+.phony: all
+
+implib:
+
+clean:
+       - $(RM) *.o *.exe *.sym
+
+.phony: implib clean
+
+ifneq ($(BOOTCD_INSTALL),)
+
+install: $(PROGS:%=$(INSTALL_DIR)/%)
+
+$(PROGS:%=$(INSTALL_DIR)/%): $(INSTALL_DIR)/%: %
+       $(CP) $* $(INSTALL_DIR)/$*
+
+else # BOOTCD_INSTALL
+
+install: $(PROGS:%=$(INSTALL_DIR)/bin/%)
+
+$(PROGS:%=$(INSTALL_DIR)/bin/%): $(INSTALL_DIR)/bin/%: %
+       $(CP) $* $(INSTALL_DIR)/bin/$*
+
+endif # BOOTCD_INSTALL
+
+shmsrv.exe: $(SRV_OBJECTS) $(LIBS)
+       $(CC) $(SRV_OBJECTS) $(LIBS) -o shmsrv.exe
+       $(NM) --numeric-sort shmsrv.exe > shmsrv.sym
+
+shmclt.exe: $(CLT_OBJECTS) $(LIBS)
+       $(CC) $(CLT_OBJECTS) $(LIBS) -o shmclt.exe
+       $(NM) --numeric-sort shmsrv.exe > shmclt.sym
+
+# EOF
diff --git a/rosapps/tests/shm/shmclt.c b/rosapps/tests/shm/shmclt.c
new file mode 100644 (file)
index 0000000..4b1f5da
--- /dev/null
@@ -0,0 +1,61 @@
+#include <ddk/ntddk.h>
+#include <windows.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+
+HANDLE OutputHandle;
+HANDLE InputHandle;
+
+void debug_printf(char* fmt, ...)
+{
+   va_list args;
+   char buffer[255];
+
+   va_start(args,fmt);
+   vsprintf(buffer,fmt,args);
+   WriteConsoleA(OutputHandle, buffer, strlen(buffer), NULL, NULL);
+   va_end(args);
+}
+
+
+int
+main(int argc, char* argv[])
+{
+   HANDLE Section;
+   PVOID BaseAddress;
+   char buffer[256];
+   
+   printf("Shm test server\n");
+   
+   Section = OpenFileMappingW (
+//             PAGE_EXECUTE_READWRITE, invalid parameter
+               FILE_MAP_WRITE,
+               FALSE,
+               L"TestSection"
+               );
+   if (Section == NULL)
+     {
+       printf("Failed to open section (err=%d)", GetLastError());
+       return 1;
+     }
+   
+   BaseAddress = MapViewOfFile(Section,
+                              FILE_MAP_ALL_ACCESS,
+                              0,
+                              0,
+                              8192);
+   if (BaseAddress == NULL)
+     {
+       printf("Failed to map section (err=%d)\n", GetLastError());
+       return 1;
+     }
+   printf("BaseAddress %x\n", (UINT) BaseAddress);
+   printf("Copying from section\n");
+   strcpy(buffer, BaseAddress);
+   printf("Copyed <%s>\n", buffer);
+   
+//   for(;;);
+       return 0;
+}
+
diff --git a/rosapps/tests/shm/shmsrv.c b/rosapps/tests/shm/shmsrv.c
new file mode 100644 (file)
index 0000000..427686c
--- /dev/null
@@ -0,0 +1,53 @@
+/* $Id: shmsrv.c,v 1.1 2004/10/21 04:59:01 sedwards Exp $
+ *
+ * FILE  : reactos/apps/shm/shmsrv.c
+ * AUTHOR: David Welch
+ */
+#include <ddk/ntddk.h>
+#include <windows.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+
+int main(int argc, char* argv[])
+{
+   HANDLE Section;
+   PVOID BaseAddress;
+   
+   printf("Shm test server\n");
+   
+   Section = CreateFileMappingW (
+                       (HANDLE) 0xFFFFFFFF,
+                       NULL,
+                       PAGE_READWRITE, 
+                       0,
+                       8192,
+                       L"TestSection"
+                       );
+   if (Section == NULL)
+     {
+       printf("Failed to create section (err=%d)", GetLastError());
+       return 1;
+     }
+   
+   printf("Mapping view of section\n");
+   BaseAddress = MapViewOfFile(Section,
+                              FILE_MAP_ALL_ACCESS,
+                              0,
+                              0,
+                              8192);
+   printf("BaseAddress %x\n", (UINT) BaseAddress);
+   if (BaseAddress == NULL)
+     {
+       printf("Failed to map section\n");
+     }
+   
+   printf("Copying to section\n");
+   printf("Copying %s\n", GetCommandLineA());
+   strcpy(BaseAddress, GetCommandLineA());
+   
+   Sleep(INFINITE);
+
+   return 0;
+}
+