[ros-diffs] [gedmurphy] 30220: add the start of functionality to read and write standard Microsoft .rdp files

gedmurphy at svn.reactos.org gedmurphy at svn.reactos.org
Tue Nov 6 14:53:34 CET 2007


Author: gedmurphy
Date: Tue Nov  6 16:53:34 2007
New Revision: 30220

URL: http://svn.reactos.org/svn/reactos?rev=30220&view=rev
Log:
add the start of functionality to read and write standard Microsoft .rdp files

Added:
    trunk/reactos/base/applications/mstsc/rdpfile.c   (with props)
Modified:
    trunk/reactos/base/applications/mstsc/mstsc_vc8_auto.vcproj

Modified: trunk/reactos/base/applications/mstsc/mstsc_vc8_auto.vcproj
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mstsc/mstsc_vc8_auto.vcproj?rev=30220&r1=30219&r2=30220&view=diff
==============================================================================
--- trunk/reactos/base/applications/mstsc/mstsc_vc8_auto.vcproj (original)
+++ trunk/reactos/base/applications/mstsc/mstsc_vc8_auto.vcproj Tue Nov  6 16:53:34 2007
@@ -605,6 +605,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\rdpfile.c"
+				>
+			</File>
+			<File
 				RelativePath=".\secure.c"
 				>
 			</File>

Added: trunk/reactos/base/applications/mstsc/rdpfile.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mstsc/rdpfile.c?rev=30220&view=auto
==============================================================================
--- trunk/reactos/base/applications/mstsc/rdpfile.c (added)
+++ trunk/reactos/base/applications/mstsc/rdpfile.c Tue Nov  6 16:53:34 2007
@@ -1,0 +1,194 @@
+#include <windows.h>
+#include <commctrl.h>
+#include <stdio.h>
+#include <tchar.h>
+#include "resource.h"
+
+#define MAXKEY 256
+#define MAXVALUE 256
+
+typedef struct _Settings
+{
+    WCHAR Key[MAXKEY];
+    WCHAR Type; // holds 'i' or 's'
+    union {
+        INT i;
+        WCHAR s[MAXVALUE];
+    } Value;
+} SETTINGS, *PSETTINGS;
+
+#define NUM_SETTINGS 6
+LPWSTR lpSettings[NUM_SETTINGS] = 
+{
+    L"screen mode id",
+    L"desktopwidth",
+    L"desktopheight",
+    L"session bpp",
+    L"full address",
+    L"compression",
+};
+
+
+static BOOL
+WriteRdpFile(HANDLE hFile,
+             PSETTINGS pSettings)
+{
+
+}
+
+
+static PSETTINGS
+ParseSettings(LPWSTR lpBuffer)
+{
+    PSETTINGS pSettings;
+    LPWSTR lpStr = lpBuffer;
+    WCHAR lpKey[MAXKEY];
+    WCHAR lpValue[MAXVALUE];
+    INT NumSettings = 0;
+    INT s;
+
+    if (lpBuffer)
+    {
+        /* get number of settings */
+        while (*lpStr)
+        {
+            if (*lpStr == L'\n')
+                NumSettings++;
+            lpStr++;
+        }
+        lpStr = lpBuffer;
+
+        if (!NumSettings)
+            return NULL;
+
+        pSettings = HeapAlloc(GetProcessHeap(),
+                              0,
+                              sizeof(SETTINGS) * NumSettings);
+        if (pSettings)
+        {
+            for (s = 0; s < NumSettings; s++)
+            {
+                INT i = 0, k, temp;
+
+                /* get a key */
+                while (*lpStr != L':')
+                {
+                    lpKey[i++] = *lpStr++;
+                }
+                lpKey[i] = 0;
+
+                for (k = 0; k < NUM_SETTINGS; k++)
+                {
+                    if (wcscmp(lpSettings[k], lpKey) == 0)
+                    {
+                        wcscpy(pSettings[s].Key, lpKey);
+
+                        /* get the type */
+                        lpStr++;
+                        if (*lpStr == L'i' || *lpStr == L's')
+                            pSettings[s].Type = *lpStr;
+
+                        lpStr += 2;
+
+                        /* get a value */
+                        i = 0;
+                        while (*lpStr != L'\r')
+                        {
+                            lpValue[i++] = *lpStr++;
+                        }
+                        lpValue[i] = 0;
+
+                        if (pSettings[s].Type == L'i')
+                        {
+                            pSettings[s].Value.i = _wtoi(lpValue);
+                        }
+                        else if (pSettings[s].Type == L's')
+                        {
+                            wcscpy(pSettings[s].Value.s, lpValue);
+                        }
+                        else
+                            pSettings[s].Type = 0;
+                    }
+                }
+
+                // move onto next setting
+                while (*lpStr != L'\n')
+                {
+                    lpStr++;
+                }
+                lpStr++;
+            }
+        }
+    }
+
+    return pSettings;
+}
+
+static LPWSTR
+ReadRdpFile(HANDLE hFile)
+{
+    LPWSTR lpBuffer;
+    DWORD BytesToRead, BytesRead;
+    BOOL bRes;
+
+    if (hFile)
+    {
+        BytesToRead = GetFileSize(hFile, NULL);
+        if (BytesToRead)
+        {
+            lpBuffer = HeapAlloc(GetProcessHeap(),
+                                 0,
+                                 BytesToRead + 1);
+            if (lpBuffer)
+            {
+                bRes = ReadFile(hFile,
+                                lpBuffer,
+                                BytesToRead,
+                                &BytesRead,
+                                NULL);
+                if (bRes)
+                {
+                    lpBuffer[BytesRead / 2] = 0;
+                    lpBuffer += 1;
+                }
+                else
+                {
+                    HeapFree(GetProcessHeap(),
+                             0,
+                             lpBuffer);
+
+                    lpBuffer = NULL;
+                }
+            }
+        }
+    }
+
+    return lpBuffer;
+}
+
+static HANDLE
+OpenRdpFile(LPTSTR path, BOOL bWrite)
+{
+    HANDLE hFile;
+
+    if (path)
+    {
+        hFile = CreateFile(path,
+                           bWrite ? GENERIC_WRITE : GENERIC_READ,
+                           0,
+                           NULL,
+                           bWrite ? CREATE_ALWAYS : OPEN_EXISTING,
+                           FILE_ATTRIBUTE_NORMAL,
+                           NULL);
+    }
+
+    return hFile;
+}
+
+
+static VOID
+CloseRdpFile(HANDLE hFile)
+{
+    if (hFile)
+        CloseHandle(hFile);
+}

Propchange: trunk/reactos/base/applications/mstsc/rdpfile.c
------------------------------------------------------------------------------
    svn:eol-style = native




More information about the Ros-diffs mailing list