Author: gedmurphy Date: Tue Nov 6 23:36:31 2007 New Revision: 30226
URL: http://svn.reactos.org/svn/reactos?rev=30226&view=rev Log: - fix various bugs in the .rdp parser - add code to allow querying of key value pairs
Added: trunk/reactos/base/applications/mstsc/todo.h (with props) Modified: trunk/reactos/base/applications/mstsc/connectdialog.c trunk/reactos/base/applications/mstsc/mstsc_vc8_auto.vcproj trunk/reactos/base/applications/mstsc/rdpfile.c trunk/reactos/base/applications/mstsc/resource.h trunk/reactos/base/applications/mstsc/win32.c
Modified: trunk/reactos/base/applications/mstsc/connectdialog.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mstsc/con... ============================================================================== --- trunk/reactos/base/applications/mstsc/connectdialog.c (original) +++ trunk/reactos/base/applications/mstsc/connectdialog.c Tue Nov 6 23:36:31 2007 @@ -22,7 +22,9 @@ #include <commctrl.h> #include <stdio.h> #include <tchar.h> +#include <todo.h> #include "resource.h" +
#define MAX_KEY_NAME 255
@@ -62,6 +64,7 @@
typedef struct _INFO { + PRDPSETTINGS pRdpSettings; PDISPLAY_DEVICE_ENTRY DisplayDeviceList; PDISPLAY_DEVICE_ENTRY CurrentDisplayDevice; HWND hSelf; @@ -206,11 +209,11 @@ }
pInfo->hConn = LoadImage(hInst, - MAKEINTRESOURCE(IDI_CONN), - IMAGE_ICON, - 32, - 32, - LR_DEFAULTCOLOR); + MAKEINTRESOURCE(IDI_CONN), + IMAGE_ICON, + 32, + 32, + LR_DEFAULTCOLOR); if (pInfo->hConn) { SendDlgItemMessage(pInfo->hGeneralPage, @@ -221,6 +224,10 @@ }
FillServerAddesssCombo(pInfo); + + /* add address */ + //GetStringFromSettings(pInfo->pRdpSettings, L"full address"); + }
@@ -239,6 +246,18 @@ pInfo->hGeneralPage = hDlg; GeneralOnInit(pInfo); return TRUE; + + case WM_COMMAND: + { + switch(LOWORD(wParam)) + { + case IDC_SAVE: + + break; + } + + break; + }
case WM_CLOSE: { @@ -789,7 +808,7 @@ BOOL bRet = FALSE;
pInfo = HeapAlloc(GetProcessHeap(), - 0, + HEAP_ZERO_MEMORY, sizeof(INFO)); if (pInfo) { @@ -797,12 +816,17 @@ GWLP_USERDATA, (LONG_PTR)pInfo);
- pInfo->hHeader = LoadImage(hInst, - MAKEINTRESOURCE(IDB_HEADER), - IMAGE_BITMAP, - 0, - 0, - LR_DEFAULTCOLOR); + /* read the default .rdp file */ + pInfo->pRdpSettings = LoadRdpSettingsFromFile(NULL); + if (!pInfo->pRdpSettings) + return FALSE; + + pInfo->hHeader = (HBITMAP)LoadImage(hInst, + MAKEINTRESOURCE(IDB_HEADER), + IMAGE_BITMAP, + 0, + 0, + LR_DEFAULTCOLOR); if (pInfo->hHeader) { GetObject(pInfo->hHeader, sizeof(BITMAP), &pInfo->headerbitmap); @@ -840,8 +864,6 @@ }
OnTabWndSelChange(pInfo); - - bRet = TRUE; } }
@@ -888,7 +910,6 @@ switch(LOWORD(wParam)) {
- break; }
break; @@ -943,9 +964,25 @@ case WM_CLOSE: { if (pInfo) + { + if (pInfo->pRdpSettings) + { + if (pInfo->pRdpSettings->pSettings) + { + HeapFree(GetProcessHeap(), + 0, + pInfo->pRdpSettings->pSettings); + } + + HeapFree(GetProcessHeap(), + 0, + pInfo->pRdpSettings); + } + HeapFree(GetProcessHeap(), 0, pInfo); + }
EndDialog(hDlg, 0); }
Modified: trunk/reactos/base/applications/mstsc/mstsc_vc8_auto.vcproj URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mstsc/mst... ============================================================================== --- trunk/reactos/base/applications/mstsc/mstsc_vc8_auto.vcproj (original) +++ trunk/reactos/base/applications/mstsc/mstsc_vc8_auto.vcproj Tue Nov 6 23:36:31 2007 @@ -633,6 +633,10 @@ Name="Header Files" Filter="h;hpp;hxx;hm;inl" > + <File + RelativePath=".\todo.h" + > + </File> </Filter> <Filter Name="Resource Files"
Modified: trunk/reactos/base/applications/mstsc/rdpfile.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mstsc/rdp... ============================================================================== --- trunk/reactos/base/applications/mstsc/rdpfile.c (original) +++ trunk/reactos/base/applications/mstsc/rdpfile.c Tue Nov 6 23:36:31 2007 @@ -1,22 +1,9 @@ #include <windows.h> -#include <commctrl.h> #include <stdio.h> #include <tchar.h> #include <shlobj.h> +#include <todo.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] = @@ -30,6 +17,61 @@ };
+ +INT +GetIntegerFromSettings(PRDPSETTINGS pRdpSettings, + LPWSTR lpKey) +{ + INT Value = -1; + + if (pRdpSettings) + { + INT i; + + for (i = 0; i < pRdpSettings->NumSettings; i++) + { + if (wcscmp(pRdpSettings->pSettings[i].Key, lpKey) == 0) + { + if (pRdpSettings->pSettings[i].Type == L'i') + { + Value = pRdpSettings->pSettings[i].Value.i; + break; + } + } + } + } + + return Value; +} + + +LPWSTR +GetStringFromSettings(PRDPSETTINGS pRdpSettings, + LPWSTR lpKey) +{ + LPWSTR lpValue = NULL; + + if (pRdpSettings) + { + INT i; + + for (i = 0; i < pRdpSettings->NumSettings; i++) + { + if (wcscmp(pRdpSettings->pSettings[i].Key, lpKey) == 0) + { + if (pRdpSettings->pSettings[i].Type == L's') + { + lpValue = pRdpSettings->pSettings[i].Value.s; + break; + } + } + } + } + + return lpValue; +} + + static BOOL WriteRdpFile(HANDLE hFile, PSETTINGS pSettings) @@ -38,15 +80,15 @@ }
-static PSETTINGS -ParseSettings(LPWSTR lpBuffer) -{ - PSETTINGS pSettings; +static VOID +ParseSettings(PRDPSETTINGS pRdpSettings, + LPWSTR lpBuffer) +{ LPWSTR lpStr = lpBuffer; WCHAR lpKey[MAXKEY]; WCHAR lpValue[MAXVALUE]; INT NumSettings = 0; - INT s; + INT s, structsize;
if (lpStr) { @@ -60,17 +102,19 @@ lpStr = lpBuffer;
if (NumSettings == 0) - return NULL; + return;
/* move past unicode byte order */ if (lpStr[0] == 0xFEFF || lpStr[0] == 0xFFFE) lpStr += 1;
- pSettings = HeapAlloc(GetProcessHeap(), - 0, - sizeof(SETTINGS) * NumSettings); - if (pSettings) - { + pRdpSettings->pSettings = HeapAlloc(GetProcessHeap(), + 0, + sizeof(SETTINGS) * NumSettings); + if (pRdpSettings->pSettings) + { + pRdpSettings->NumSettings = NumSettings; + for (s = 0; s < NumSettings; s++) { INT i = 0, k, temp; @@ -86,12 +130,12 @@ { if (wcscmp(lpSettings[k], lpKey) == 0) { - wcscpy(pSettings[s].Key, lpKey); + wcscpy(pRdpSettings->pSettings[s].Key, lpKey);
/* get the type */ lpStr++; if (*lpStr == L'i' || *lpStr == L's') - pSettings[s].Type = *lpStr; + pRdpSettings->pSettings[s].Type = *lpStr;
lpStr += 2;
@@ -103,18 +147,16 @@ } lpValue[i] = 0;
- if (pSettings[s].Type == L'i') + if (pRdpSettings->pSettings[s].Type == L'i') { - pSettings[s].Value.i = _wtoi(lpValue); - pSettings[s].Value.s[0] = 0; + pRdpSettings->pSettings[s].Value.i = _wtoi(lpValue); } - else if (pSettings[s].Type == L's') + else if (pRdpSettings->pSettings[s].Type == L's') { - pSettings[s].Value.i = 0; - wcscpy(pSettings[s].Value.s, lpValue); + wcscpy(pRdpSettings->pSettings[s].Value.s, lpValue); } else - pSettings[s].Type = 0; + pRdpSettings->pSettings[s].Type = 0; } }
@@ -127,9 +169,8 @@ } } } - - return pSettings; -} +} +
static LPWSTR ReadRdpFile(HANDLE hFile) @@ -171,6 +212,7 @@
return lpBuffer; } +
static HANDLE OpenRdpFile(LPWSTR path, BOOL bWrite) @@ -200,10 +242,10 @@ }
-PSETTINGS +PRDPSETTINGS LoadRdpSettingsFromFile(LPWSTR lpFile) { - PSETTINGS pSettings = NULL; + PRDPSETTINGS pRdpSettings; WCHAR pszPath[MAX_PATH]; HANDLE hFile;
@@ -224,6 +266,7 @@ { wcscat(pszPath, L"\Default.rdp"); lpFile = pszPath; + CoTaskMemFree(lpidl); } } } @@ -232,22 +275,28 @@ { LPWSTR lpBuffer = NULL;
- hFile = OpenRdpFile(lpFile, FALSE); - if (hFile) - { - lpBuffer = ReadRdpFile(hFile); - if (lpBuffer) - { - pSettings = ParseSettings(lpBuffer); - - HeapFree(GetProcessHeap(), - 0, - lpBuffer); - } - - CloseRdpFile(hFile); - } - } - - return pSettings; -} + pRdpSettings = HeapAlloc(GetProcessHeap(), + 0, + sizeof(RDPSETTINGS)); + if (pRdpSettings) + { + hFile = OpenRdpFile(lpFile, FALSE); + if (hFile) + { + lpBuffer = ReadRdpFile(hFile); + if (lpBuffer) + { + ParseSettings(pRdpSettings, lpBuffer); + + HeapFree(GetProcessHeap(), + 0, + lpBuffer); + } + + CloseRdpFile(hFile); + } + } + } + + return pRdpSettings; +}
Modified: trunk/reactos/base/applications/mstsc/resource.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mstsc/res... ============================================================================== --- trunk/reactos/base/applications/mstsc/resource.h (original) +++ trunk/reactos/base/applications/mstsc/resource.h Tue Nov 6 23:36:31 2007 @@ -16,11 +16,10 @@ #define IDC_CONNICON 1017 #define IDC_REMICON 1018 #define IDC_COLORSICON 1019 +#define IDC_COLORIMAGE 1020
-#define IDB_HEADER 1016 -#define IDB_SPECT 1017 - -#define IDC_COLORIMAGE 1018 +#define IDB_HEADER 1100 +#define IDB_SPECT 1101
#define IDI_LOGON 2000 #define IDI_CONN 2001
Added: trunk/reactos/base/applications/mstsc/todo.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mstsc/tod... ============================================================================== --- trunk/reactos/base/applications/mstsc/todo.h (added) +++ trunk/reactos/base/applications/mstsc/todo.h Tue Nov 6 23:36:31 2007 @@ -1,0 +1,23 @@ +#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; + +typedef struct _RDPSETTINGS +{ + PSETTINGS pSettings; + INT NumSettings; +} RDPSETTINGS, *PRDPSETTINGS; + + +PRDPSETTINGS LoadRdpSettingsFromFile(LPWSTR lpFile); +INT GetIntegerFromSettings(PRDPSETTINGS pSettings, LPWSTR lpValue); +LPWSTR GetStringFromSettings(PRDPSETTINGS pSettings, LPWSTR lpValue);
Propchange: trunk/reactos/base/applications/mstsc/todo.h ------------------------------------------------------------------------------ svn:eol-style = native
Modified: trunk/reactos/base/applications/mstsc/win32.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mstsc/win... ============================================================================== --- trunk/reactos/base/applications/mstsc/win32.c (original) +++ trunk/reactos/base/applications/mstsc/win32.c Tue Nov 6 23:36:31 2007 @@ -1338,14 +1338,14 @@
WSAStartup(MAKEWORD(2, 0), &d);
- if (mi_process_cl(lpCmdLine)) - { + //if (mi_process_cl(lpCmdLine)) + //{ if (OpenRDPConnectDialog(hInstance)) { ui_main(); ret = 0; } - } + //} else mi_show_params();