Author: hbelusca Date: Thu May 8 18:08:07 2014 New Revision: 63194
URL: http://svn.reactos.org/svn/reactos?rev=63194&view=rev Log: [KERNEL32][CONSRV] Make kernel32 / winsrv console CSR structures Win2k3-compliant. The aim is to be able to put our kernel32.dll or winsrv.dll on win2k3, and vice-versa.
- Fix almost all the alias APIs and the history APIs. Unicode versions is OK, ANSI ones need correct fixes in server-side (see CORE-7931 for more details). - Half-plement SetConsoleCommandHistoryMode (client-side OK, server-side unimplemented).
Part 4/X
CORE-7931
Modified: branches/condrv_restructure/dll/win32/kernel32/client/console/alias.c branches/condrv_restructure/dll/win32/kernel32/client/console/console.c branches/condrv_restructure/dll/win32/kernel32/client/console/history.c branches/condrv_restructure/include/reactos/subsys/win/conmsg.h branches/condrv_restructure/win32ss/user/winsrv/consrv/alias.c branches/condrv_restructure/win32ss/user/winsrv/consrv/lineinput.c
Modified: branches/condrv_restructure/dll/win32/kernel32/client/console/alias.c URL: http://svn.reactos.org/svn/reactos/branches/condrv_restructure/dll/win32/ker... ============================================================================== --- branches/condrv_restructure/dll/win32/kernel32/client/console/alias.c [iso-8859-1] (original) +++ branches/condrv_restructure/dll/win32/kernel32/client/console/alias.c [iso-8859-1] Thu May 8 18:08:07 2014 @@ -387,30 +387,24 @@ }
-/* - * @implemented - */ -DWORD -WINAPI -GetConsoleAliasesLengthW(LPWSTR lpExeName) -{ - NTSTATUS Status; +static DWORD +IntGetConsoleAliasesLength(LPVOID lpExeName, DWORD dwNumChars, BOOLEAN bUnicode) +{ CONSOLE_API_MESSAGE ApiMessage; PCONSOLE_GETALLALIASESLENGTH GetAllAliasesLengthRequest = &ApiMessage.Data.GetAllAliasesLengthRequest; PCSR_CAPTURE_BUFFER CaptureBuffer;
- DPRINT("GetConsoleAliasesLengthW entered\n"); - - if (lpExeName == NULL) + if (lpExeName == NULL || dwNumChars == 0) { SetLastError(ERROR_INVALID_PARAMETER); return 0; }
- GetAllAliasesLengthRequest->ExeLength = (wcslen(lpExeName) + 1) * sizeof(WCHAR); - GetAllAliasesLengthRequest->Length = 0; - - /* Allocate a Capture Buffer */ + GetAllAliasesLengthRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle; + GetAllAliasesLengthRequest->ExeLength = dwNumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR)); + GetAllAliasesLengthRequest->Unicode = + GetAllAliasesLengthRequest->Unicode2 = bUnicode; + CaptureBuffer = CsrAllocateCaptureBuffer(1, GetAllAliasesLengthRequest->ExeLength); if (!CaptureBuffer) { @@ -419,22 +413,21 @@ return 0; }
- /* Capture the exe name */ CsrCaptureMessageBuffer(CaptureBuffer, (PVOID)lpExeName, GetAllAliasesLengthRequest->ExeLength, (PVOID)&GetAllAliasesLengthRequest->ExeName);
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, - CaptureBuffer, - CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasesLength), - sizeof(CONSOLE_GETALLALIASESLENGTH)); + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + CaptureBuffer, + CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasesLength), + sizeof(*GetAllAliasesLengthRequest));
CsrFreeCaptureBuffer(CaptureBuffer);
- if (!NT_SUCCESS(Status)) - { - BaseSetLastNTError(Status); + if (!NT_SUCCESS(ApiMessage.Status)) + { + BaseSetLastNTError(ApiMessage.Status); return 0; }
@@ -447,42 +440,48 @@ */ DWORD WINAPI +GetConsoleAliasesLengthW(LPWSTR lpExeName) +{ + if (lpExeName == NULL) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + return IntGetConsoleAliasesLength(lpExeName, wcslen(lpExeName), TRUE); +} + + +/* + * @implemented + */ +DWORD +WINAPI GetConsoleAliasesLengthA(LPSTR lpExeName) { - DWORD dwRetVal = 0; - LPWSTR lpExeNameW = NULL; - - if (lpExeName) - BasepAnsiStringToHeapUnicodeString(lpExeName, (LPWSTR*)&lpExeNameW); - - dwRetVal = GetConsoleAliasesLengthW(lpExeNameW); - if (dwRetVal) - dwRetVal /= sizeof(WCHAR); - - /* Clean up */ - if (lpExeNameW) - RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpExeNameW); - - return dwRetVal; -} - - -/* - * @implemented - */ -DWORD -WINAPI -GetConsoleAliasExesW(LPWSTR lpExeNameBuffer, - DWORD ExeNameBufferLength) -{ - NTSTATUS Status; + if (lpExeName == NULL) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + return IntGetConsoleAliasesLength(lpExeName, strlen(lpExeName), FALSE); +} + + +static DWORD +IntGetConsoleAliasExes(PVOID lpExeNameBuffer, + DWORD ExeNameBufferLength, + BOOLEAN bUnicode) +{ CONSOLE_API_MESSAGE ApiMessage; PCONSOLE_GETALIASESEXES GetAliasesExesRequest = &ApiMessage.Data.GetAliasesExesRequest; PCSR_CAPTURE_BUFFER CaptureBuffer;
- DPRINT("GetConsoleAliasExesW entered\n"); - - /* Allocate a Capture Buffer */ + GetAliasesExesRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle; + GetAliasesExesRequest->Length = ExeNameBufferLength; + GetAliasesExesRequest->Unicode = bUnicode; + CaptureBuffer = CsrAllocateCaptureBuffer(1, ExeNameBufferLength); if (!CaptureBuffer) { @@ -491,33 +490,39 @@ return 0; }
- GetAliasesExesRequest->Length = ExeNameBufferLength; - - /* Allocate space for the exe name buffer */ CsrAllocateMessagePointer(CaptureBuffer, ExeNameBufferLength, (PVOID*)&GetAliasesExesRequest->ExeNames);
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, - CaptureBuffer, - CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasExes), - sizeof(CONSOLE_GETALIASESEXES)); - if (!NT_SUCCESS(Status)) + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + CaptureBuffer, + CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasExes), + sizeof(*GetAliasesExesRequest)); + if (!NT_SUCCESS(ApiMessage.Status)) { CsrFreeCaptureBuffer(CaptureBuffer); - BaseSetLastNTError(Status); - return 0; - } - - /* Copy the returned target string into the user buffer */ + BaseSetLastNTError(ApiMessage.Status); + return 0; + } + memcpy(lpExeNameBuffer, GetAliasesExesRequest->ExeNames, GetAliasesExesRequest->Length);
- /* Release the capture buffer and exit */ CsrFreeCaptureBuffer(CaptureBuffer);
return GetAliasesExesRequest->Length; +} + +/* + * @implemented + */ +DWORD +WINAPI +GetConsoleAliasExesW(LPWSTR lpExeNameBuffer, + DWORD ExeNameBufferLength) +{ + return IntGetConsoleAliasExes(lpExeNameBuffer, ExeNameBufferLength, TRUE); }
@@ -529,46 +534,26 @@ GetConsoleAliasExesA(LPSTR lpExeNameBuffer, DWORD ExeNameBufferLength) { - LPWSTR lpwExeNameBuffer; - DWORD dwResult; - - DPRINT("GetConsoleAliasExesA entered\n"); - - lpwExeNameBuffer = HeapAlloc(GetProcessHeap(), 0, ExeNameBufferLength * sizeof(WCHAR)); - - dwResult = GetConsoleAliasExesW(lpwExeNameBuffer, ExeNameBufferLength * sizeof(WCHAR)); - - if (dwResult) - dwResult = WideCharToMultiByte(CP_ACP, 0, lpwExeNameBuffer, dwResult / sizeof(WCHAR), lpExeNameBuffer, ExeNameBufferLength, NULL, NULL); - - HeapFree(GetProcessHeap(), 0, lpwExeNameBuffer); - return dwResult; -} - - -/* - * @implemented - */ -DWORD -WINAPI -GetConsoleAliasExesLengthW(VOID) -{ - NTSTATUS Status; + return IntGetConsoleAliasExes(lpExeNameBuffer, ExeNameBufferLength, FALSE); +} + + +static DWORD +IntGetConsoleAliasExesLength(BOOLEAN bUnicode) +{ CONSOLE_API_MESSAGE ApiMessage; PCONSOLE_GETALIASESEXESLENGTH GetAliasesExesLengthRequest = &ApiMessage.Data.GetAliasesExesLengthRequest;
- DPRINT("GetConsoleAliasExesLengthW entered\n"); - - GetAliasesExesLengthRequest->Length = 0; - - Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, - NULL, - CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasExesLength), - sizeof(CONSOLE_GETALIASESEXESLENGTH)); - - if (!NT_SUCCESS(Status)) - { - BaseSetLastNTError(Status); + GetAliasesExesLengthRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle; + GetAliasesExesLengthRequest->Unicode = bUnicode; + + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + NULL, + CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasExesLength), + sizeof(*GetAliasesExesLengthRequest)); + if (!NT_SUCCESS(ApiMessage.Status)) + { + BaseSetLastNTError(ApiMessage.Status); return 0; }
@@ -581,18 +566,20 @@ */ DWORD WINAPI +GetConsoleAliasExesLengthW(VOID) +{ + return IntGetConsoleAliasExesLength(TRUE); +} + + +/* + * @implemented + */ +DWORD +WINAPI GetConsoleAliasExesLengthA(VOID) { - DWORD dwLength; - - DPRINT("GetConsoleAliasExesLengthA entered\n"); - - dwLength = GetConsoleAliasExesLengthW(); - - if (dwLength) - dwLength /= sizeof(WCHAR); - - return dwLength; + return IntGetConsoleAliasExesLength(FALSE); }
/* EOF */
Modified: branches/condrv_restructure/dll/win32/kernel32/client/console/console.c URL: http://svn.reactos.org/svn/reactos/branches/condrv_restructure/dll/win32/ker... ============================================================================== --- branches/condrv_restructure/dll/win32/kernel32/client/console/console.c [iso-8859-1] (original) +++ branches/condrv_restructure/dll/win32/kernel32/client/console/console.c [iso-8859-1] Thu May 8 18:08:07 2014 @@ -1496,18 +1496,17 @@ static BOOL IntScrollConsoleScreenBuffer(HANDLE hConsoleOutput, - const SMALL_RECT *lpScrollRectangle, - const SMALL_RECT *lpClipRectangle, + CONST SMALL_RECT* lpScrollRectangle, + CONST SMALL_RECT* lpClipRectangle, COORD dwDestinationOrigin, - const CHAR_INFO *lpFill, + CONST CHAR_INFO* lpFill, BOOL bUnicode) { - NTSTATUS Status; CONSOLE_API_MESSAGE ApiMessage; PCONSOLE_SCROLLSCREENBUFFER ScrollScreenBufferRequest = &ApiMessage.Data.ScrollScreenBufferRequest;
- ScrollScreenBufferRequest->OutputHandle = hConsoleOutput; - ScrollScreenBufferRequest->Unicode = bUnicode; + ScrollScreenBufferRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle; + ScrollScreenBufferRequest->OutputHandle = hConsoleOutput; ScrollScreenBufferRequest->ScrollRectangle = *lpScrollRectangle;
if (lpClipRectangle != NULL) @@ -1521,16 +1520,16 @@ }
ScrollScreenBufferRequest->DestinationOrigin = dwDestinationOrigin; - ScrollScreenBufferRequest->Fill = *lpFill; - - Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, - NULL, - CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepScrollScreenBuffer), - sizeof(CONSOLE_SCROLLSCREENBUFFER)); - - if (!NT_SUCCESS(Status)) - { - BaseSetLastNTError(Status); + ScrollScreenBufferRequest->Fill = *lpFill; + ScrollScreenBufferRequest->Unicode = bUnicode; + + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + NULL, + CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepScrollScreenBuffer), + sizeof(*ScrollScreenBufferRequest)); + if (!NT_SUCCESS(ApiMessage.Status)) + { + BaseSetLastNTError(ApiMessage.Status); return FALSE; }
@@ -1546,16 +1545,16 @@ BOOL WINAPI ScrollConsoleScreenBufferA(HANDLE hConsoleOutput, - CONST SMALL_RECT *lpScrollRectangle, - CONST SMALL_RECT *lpClipRectangle, + CONST SMALL_RECT* lpScrollRectangle, + CONST SMALL_RECT* lpClipRectangle, COORD dwDestinationOrigin, - CONST CHAR_INFO *lpFill) + CONST CHAR_INFO* lpFill) { return IntScrollConsoleScreenBuffer(hConsoleOutput, - (PSMALL_RECT)lpScrollRectangle, - (PSMALL_RECT)lpClipRectangle, + lpScrollRectangle, + lpClipRectangle, dwDestinationOrigin, - (PCHAR_INFO)lpFill, + lpFill, FALSE); }
Modified: branches/condrv_restructure/dll/win32/kernel32/client/console/history.c URL: http://svn.reactos.org/svn/reactos/branches/condrv_restructure/dll/win32/ker... ============================================================================== --- branches/condrv_restructure/dll/win32/kernel32/client/console/history.c [iso-8859-1] (original) +++ branches/condrv_restructure/dll/win32/kernel32/client/console/history.c [iso-8859-1] Thu May 8 18:08:07 2014 @@ -16,13 +16,14 @@
/* PRIVATE FUNCTIONS **********************************************************/
+#if 0 /* Get the size needed to copy a string to a capture buffer, including alignment */ static ULONG IntStringSize(LPCVOID String, BOOL Unicode) { ULONG Size = (Unicode ? wcslen(String) : strlen(String)) * sizeof(WCHAR); - return (Size + 3) & -4; + return (Size + 3) & ~3; }
@@ -48,67 +49,77 @@ } RequestString->Length = RequestString->MaximumLength = (USHORT)Size; } - - -static BOOL -IntExpungeConsoleCommandHistory(LPCVOID lpExeName, BOOL bUnicode) -{ - NTSTATUS Status; +#endif + +static VOID +IntExpungeConsoleCommandHistory(LPCVOID lpExeName, DWORD dwNumChars, BOOLEAN bUnicode) +{ CONSOLE_API_MESSAGE ApiMessage; PCONSOLE_EXPUNGECOMMANDHISTORY ExpungeCommandHistoryRequest = &ApiMessage.Data.ExpungeCommandHistoryRequest; PCSR_CAPTURE_BUFFER CaptureBuffer;
- if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName)) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - - CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode)); + if (lpExeName == NULL || dwNumChars == 0) + { + SetLastError(ERROR_INVALID_PARAMETER); + return; + } + + ExpungeCommandHistoryRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle; + ExpungeCommandHistoryRequest->ExeLength = dwNumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR)); + ExpungeCommandHistoryRequest->Unicode = + ExpungeCommandHistoryRequest->Unicode2 = bUnicode; + + // CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode)); + CaptureBuffer = CsrAllocateCaptureBuffer(1, ExpungeCommandHistoryRequest->ExeLength); if (!CaptureBuffer) { DPRINT1("CsrAllocateCaptureBuffer failed!\n"); SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return FALSE; - } - - IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, - &ExpungeCommandHistoryRequest->ExeName); - - Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, - CaptureBuffer, - CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepExpungeCommandHistory), - sizeof(CONSOLE_EXPUNGECOMMANDHISTORY)); + return; + } + + // IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, + // &ExpungeCommandHistoryRequest->ExeName); + CsrCaptureMessageBuffer(CaptureBuffer, + (PVOID)lpExeName, + ExpungeCommandHistoryRequest->ExeLength, + (PVOID)&ExpungeCommandHistoryRequest->ExeName); + + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + CaptureBuffer, + CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepExpungeCommandHistory), + sizeof(*ExpungeCommandHistoryRequest));
CsrFreeCaptureBuffer(CaptureBuffer);
- if (!NT_SUCCESS(Status)) - { - BaseSetLastNTError(Status); - return FALSE; - } - - return TRUE; + if (!NT_SUCCESS(ApiMessage.Status)) + BaseSetLastNTError(ApiMessage.Status); }
static DWORD -IntGetConsoleCommandHistory(LPVOID lpHistory, DWORD cbHistory, LPCVOID lpExeName, BOOL bUnicode) -{ - NTSTATUS Status; +IntGetConsoleCommandHistory(LPVOID lpHistory, DWORD cbHistory, LPCVOID lpExeName, DWORD dwNumChars, BOOLEAN bUnicode) +{ CONSOLE_API_MESSAGE ApiMessage; PCONSOLE_GETCOMMANDHISTORY GetCommandHistoryRequest = &ApiMessage.Data.GetCommandHistoryRequest; PCSR_CAPTURE_BUFFER CaptureBuffer; - DWORD HistoryLength = cbHistory * (bUnicode ? 1 : sizeof(WCHAR)); - - if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName)) - { - SetLastError(ERROR_INVALID_PARAMETER); - return 0; - } - - CaptureBuffer = CsrAllocateCaptureBuffer(2, IntStringSize(lpExeName, bUnicode) + - HistoryLength); + + if (lpExeName == NULL || dwNumChars == 0) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + GetCommandHistoryRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle; + GetCommandHistoryRequest->HistoryLength = cbHistory; + GetCommandHistoryRequest->ExeLength = dwNumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR)); + GetCommandHistoryRequest->Unicode = + GetCommandHistoryRequest->Unicode2 = bUnicode; + + // CaptureBuffer = CsrAllocateCaptureBuffer(2, IntStringSize(lpExeName, bUnicode) + + // HistoryLength); + CaptureBuffer = CsrAllocateCaptureBuffer(2, GetCommandHistoryRequest->ExeLength + + GetCommandHistoryRequest->HistoryLength); if (!CaptureBuffer) { DPRINT1("CsrAllocateCaptureBuffer failed!\n"); @@ -116,60 +127,58 @@ return 0; }
- IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, - &GetCommandHistoryRequest->ExeName); - GetCommandHistoryRequest->Length = HistoryLength; - CsrAllocateMessagePointer(CaptureBuffer, HistoryLength, + // IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, + // &GetCommandHistoryRequest->ExeName); + CsrCaptureMessageBuffer(CaptureBuffer, + (PVOID)lpExeName, + GetCommandHistoryRequest->ExeLength, + (PVOID)&GetCommandHistoryRequest->ExeName); + + // CsrAllocateMessagePointer(CaptureBuffer, HistoryLength, + CsrAllocateMessagePointer(CaptureBuffer, GetCommandHistoryRequest->HistoryLength, (PVOID*)&GetCommandHistoryRequest->History);
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, - CaptureBuffer, - CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCommandHistory), - sizeof(CONSOLE_GETCOMMANDHISTORY)); - if (!NT_SUCCESS(Status)) + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + CaptureBuffer, + CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCommandHistory), + sizeof(*GetCommandHistoryRequest)); + if (!NT_SUCCESS(ApiMessage.Status)) { CsrFreeCaptureBuffer(CaptureBuffer); - BaseSetLastNTError(Status); - return 0; - } - - if (bUnicode) - { - memcpy(lpHistory, - GetCommandHistoryRequest->History, - GetCommandHistoryRequest->Length); - } - else - { - WideCharToMultiByte(CP_ACP, 0, - GetCommandHistoryRequest->History, - GetCommandHistoryRequest->Length / sizeof(WCHAR), - lpHistory, - cbHistory, - NULL, NULL); - } + BaseSetLastNTError(ApiMessage.Status); + return 0; + } + + memcpy(lpHistory, + GetCommandHistoryRequest->History, + GetCommandHistoryRequest->HistoryLength);
CsrFreeCaptureBuffer(CaptureBuffer);
- return GetCommandHistoryRequest->Length; + return GetCommandHistoryRequest->HistoryLength; }
static DWORD -IntGetConsoleCommandHistoryLength(LPCVOID lpExeName, BOOL bUnicode) -{ - NTSTATUS Status; +IntGetConsoleCommandHistoryLength(LPCVOID lpExeName, DWORD dwNumChars, BOOL bUnicode) +{ CONSOLE_API_MESSAGE ApiMessage; PCONSOLE_GETCOMMANDHISTORYLENGTH GetCommandHistoryLengthRequest = &ApiMessage.Data.GetCommandHistoryLengthRequest; PCSR_CAPTURE_BUFFER CaptureBuffer;
- if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName)) - { - SetLastError(ERROR_INVALID_PARAMETER); - return 0; - } - - CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode)); + if (lpExeName == NULL || dwNumChars == 0) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + GetCommandHistoryLengthRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle; + GetCommandHistoryLengthRequest->ExeLength = dwNumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR)); + GetCommandHistoryLengthRequest->Unicode = + GetCommandHistoryLengthRequest->Unicode2 = bUnicode; + + // CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode)); + CaptureBuffer = CsrAllocateCaptureBuffer(1, GetCommandHistoryLengthRequest->ExeLength); if (!CaptureBuffer) { DPRINT1("CsrAllocateCaptureBuffer failed!\n"); @@ -177,43 +186,54 @@ return 0; }
- IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, - &GetCommandHistoryLengthRequest->ExeName); - - Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, - CaptureBuffer, - CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCommandHistoryLength), - sizeof(CONSOLE_GETCOMMANDHISTORYLENGTH)); + // IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, + // &GetCommandHistoryLengthRequest->ExeName); + CsrCaptureMessageBuffer(CaptureBuffer, + (PVOID)lpExeName, + GetCommandHistoryLengthRequest->ExeLength, + (PVOID)&GetCommandHistoryLengthRequest->ExeName); + + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + CaptureBuffer, + CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCommandHistoryLength), + sizeof(*GetCommandHistoryLengthRequest));
CsrFreeCaptureBuffer(CaptureBuffer);
- if (!NT_SUCCESS(Status)) - { - BaseSetLastNTError(Status); - return 0; - } - - return GetCommandHistoryLengthRequest->Length; + if (!NT_SUCCESS(ApiMessage.Status)) + { + BaseSetLastNTError(ApiMessage.Status); + return 0; + } + + return GetCommandHistoryLengthRequest->HistoryLength; }
static BOOL IntSetConsoleNumberOfCommands(DWORD dwNumCommands, LPCVOID lpExeName, - BOOL bUnicode) -{ - NTSTATUS Status; + DWORD dwNumChars, + BOOLEAN bUnicode) +{ CONSOLE_API_MESSAGE ApiMessage; PCONSOLE_SETHISTORYNUMBERCOMMANDS SetHistoryNumberCommandsRequest = &ApiMessage.Data.SetHistoryNumberCommandsRequest; PCSR_CAPTURE_BUFFER CaptureBuffer;
- if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName)) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - - CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode)); + if (lpExeName == NULL || dwNumChars == 0) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + SetHistoryNumberCommandsRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle; + SetHistoryNumberCommandsRequest->NumCommands = dwNumCommands; + SetHistoryNumberCommandsRequest->ExeLength = dwNumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR)); + SetHistoryNumberCommandsRequest->Unicode = + SetHistoryNumberCommandsRequest->Unicode2 = bUnicode; + + // CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode)); + CaptureBuffer = CsrAllocateCaptureBuffer(1, SetHistoryNumberCommandsRequest->ExeLength); if (!CaptureBuffer) { DPRINT1("CsrAllocateCaptureBuffer failed!\n"); @@ -221,20 +241,23 @@ return FALSE; }
- IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, - &SetHistoryNumberCommandsRequest->ExeName); - SetHistoryNumberCommandsRequest->NumCommands = dwNumCommands; - - Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, - CaptureBuffer, - CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetNumberOfCommands), - sizeof(CONSOLE_SETHISTORYNUMBERCOMMANDS)); + // IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, + // &SetHistoryNumberCommandsRequest->ExeName); + CsrCaptureMessageBuffer(CaptureBuffer, + (PVOID)lpExeName, + SetHistoryNumberCommandsRequest->ExeLength, + (PVOID)&SetHistoryNumberCommandsRequest->ExeName); + + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + CaptureBuffer, + CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetNumberOfCommands), + sizeof(*SetHistoryNumberCommandsRequest));
CsrFreeCaptureBuffer(CaptureBuffer);
- if (!NT_SUCCESS(Status)) - { - BaseSetLastNTError(Status); + if (!NT_SUCCESS(ApiMessage.Status)) + { + BaseSetLastNTError(ApiMessage.Status); return FALSE; }
@@ -247,22 +270,34 @@ /* * @implemented (Undocumented) */ -BOOL +VOID WINAPI ExpungeConsoleCommandHistoryW(LPCWSTR lpExeName) { - return IntExpungeConsoleCommandHistory(lpExeName, TRUE); -} - - -/* - * @implemented (Undocumented) - */ -BOOL + if (lpExeName == NULL) + { + SetLastError(ERROR_INVALID_PARAMETER); + return; + } + + IntExpungeConsoleCommandHistory(lpExeName, wcslen(lpExeName), TRUE); +} + + +/* + * @implemented (Undocumented) + */ +VOID WINAPI ExpungeConsoleCommandHistoryA(LPCSTR lpExeName) { - return IntExpungeConsoleCommandHistory(lpExeName, FALSE); + if (lpExeName == NULL) + { + SetLastError(ERROR_INVALID_PARAMETER); + return; + } + + IntExpungeConsoleCommandHistory(lpExeName, strlen(lpExeName), FALSE); }
@@ -275,7 +310,13 @@ DWORD cbHistory, LPCWSTR lpExeName) { - return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, TRUE); + if (lpExeName == NULL) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, wcslen(lpExeName), TRUE); }
@@ -288,7 +329,13 @@ DWORD cbHistory, LPCSTR lpExeName) { - return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, FALSE); + if (lpExeName == NULL) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, strlen(lpExeName), FALSE); }
@@ -299,7 +346,13 @@ WINAPI GetConsoleCommandHistoryLengthW(LPCWSTR lpExeName) { - return IntGetConsoleCommandHistoryLength(lpExeName, TRUE); + if (lpExeName == NULL) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + return IntGetConsoleCommandHistoryLength(lpExeName, wcslen(lpExeName), TRUE); }
@@ -310,7 +363,13 @@ WINAPI GetConsoleCommandHistoryLengthA(LPCSTR lpExeName) { - return IntGetConsoleCommandHistoryLength(lpExeName, FALSE) / sizeof(WCHAR); + if (lpExeName == NULL) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + return IntGetConsoleCommandHistoryLength(lpExeName, strlen(lpExeName), FALSE); }
@@ -320,33 +379,60 @@ BOOL WINAPI SetConsoleNumberOfCommandsW(DWORD dwNumCommands, + LPCWSTR lpExeName) +{ + if (lpExeName == NULL) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, wcslen(lpExeName), TRUE); +} + + +/* + * @implemented (Undocumented) + */ +BOOL +WINAPI +SetConsoleNumberOfCommandsA(DWORD dwNumCommands, LPCSTR lpExeName) { - return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, TRUE); -} - - -/* - * @implemented (Undocumented) + if (lpExeName == NULL) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, strlen(lpExeName), FALSE); +} + + +/* + * @implemented */ BOOL WINAPI -SetConsoleNumberOfCommandsA(DWORD dwNumCommands, - LPCWSTR lpExeName) -{ - return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, FALSE); -} - - -/* - * @unimplemented - */ -BOOL -WINAPI SetConsoleCommandHistoryMode(IN DWORD dwMode) { - STUB; - return FALSE; + CONSOLE_API_MESSAGE ApiMessage; + PCONSOLE_SETHISTORYMODE SetHistoryModeRequest = &ApiMessage.Data.SetHistoryModeRequest; + + SetHistoryModeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle; + SetHistoryModeRequest->Mode = dwMode; + + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + NULL, + CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCommandHistoryMode), + sizeof(*SetHistoryModeRequest)); + if (!NT_SUCCESS(ApiMessage.Status)) + { + BaseSetLastNTError(ApiMessage.Status); + return FALSE; + } + + return TRUE; }
/* EOF */
Modified: branches/condrv_restructure/include/reactos/subsys/win/conmsg.h URL: http://svn.reactos.org/svn/reactos/branches/condrv_restructure/include/react... ============================================================================== --- branches/condrv_restructure/include/reactos/subsys/win/conmsg.h [iso-8859-1] (original) +++ branches/condrv_restructure/include/reactos/subsys/win/conmsg.h [iso-8859-1] Thu May 8 18:08:07 2014 @@ -701,20 +701,35 @@
typedef struct { - UNICODE_STRING ExeName; - PWCHAR History; - DWORD Length; + HANDLE ConsoleHandle; + ULONG HistoryLength; + PVOID History; + // UNICODE_STRING ExeName; + USHORT ExeLength; + PVOID ExeName; + BOOLEAN Unicode; + BOOLEAN Unicode2; } CONSOLE_GETCOMMANDHISTORY, *PCONSOLE_GETCOMMANDHISTORY;
typedef struct { - UNICODE_STRING ExeName; - DWORD Length; + HANDLE ConsoleHandle; + ULONG HistoryLength; + // UNICODE_STRING ExeName; + USHORT ExeLength; + PVOID ExeName; + BOOLEAN Unicode; + BOOLEAN Unicode2; } CONSOLE_GETCOMMANDHISTORYLENGTH, *PCONSOLE_GETCOMMANDHISTORYLENGTH;
typedef struct { - UNICODE_STRING ExeName; + HANDLE ConsoleHandle; + // UNICODE_STRING ExeName; + USHORT ExeLength; + PVOID ExeName; + BOOLEAN Unicode; + BOOLEAN Unicode2; } CONSOLE_EXPUNGECOMMANDHISTORY, *PCONSOLE_EXPUNGECOMMANDHISTORY;
typedef struct @@ -726,8 +741,13 @@
typedef struct { - UNICODE_STRING ExeName; - DWORD NumCommands; + HANDLE ConsoleHandle; + ULONG NumCommands; + // UNICODE_STRING ExeName; + USHORT ExeLength; + PVOID ExeName; + BOOLEAN Unicode; + BOOLEAN Unicode2; } CONSOLE_SETHISTORYNUMBERCOMMANDS, *PCONSOLE_SETHISTORYNUMBERCOMMANDS;
typedef struct
Modified: branches/condrv_restructure/win32ss/user/winsrv/consrv/alias.c URL: http://svn.reactos.org/svn/reactos/branches/condrv_restructure/win32ss/user/... ============================================================================== --- branches/condrv_restructure/win32ss/user/winsrv/consrv/alias.c [iso-8859-1] (original) +++ branches/condrv_restructure/win32ss/user/winsrv/consrv/alias.c [iso-8859-1] Thu May 8 18:08:07 2014 @@ -483,6 +483,7 @@
CSR_API(SrvGetConsoleAliasesLength) { + NTSTATUS Status; PCONSOLE_GETALLALIASESLENGTH GetAllAliasesLengthRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAllAliasesLengthRequest; PCONSOLE Console; PALIAS_HEADER Header; @@ -496,28 +497,34 @@ return STATUS_INVALID_PARAMETER; }
- if (GetAllAliasesLengthRequest->ExeName == NULL) - { - return STATUS_INVALID_PARAMETER; - } - - ApiMessage->Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE); - if (!NT_SUCCESS(ApiMessage->Status)) - { - return ApiMessage->Status; - } + Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE); + if (!NT_SUCCESS(Status)) return Status; + + // FIXME!! Convert GetAllAliasesLengthRequest->ExeName into UNICODE if Unicode2 is FALSE + // and make use of GetAllAliasesLengthRequest->ExeLength
Header = IntFindAliasHeader(Console->Aliases, GetAllAliasesLengthRequest->ExeName); - if (!Header) - { - ConSrvReleaseConsole(Console, TRUE); - return STATUS_INVALID_PARAMETER; - } - - Length = IntGetAllConsoleAliasesLength(Header); - GetAllAliasesLengthRequest->Length = Length; + if (Header) + { + Length = IntGetAllConsoleAliasesLength(Header); + GetAllAliasesLengthRequest->Length = Length; + + /* + * Quick and dirty way of getting the number of bytes of the + * corresponding ANSI string from the one in UNICODE. + */ + if (!GetAllAliasesLengthRequest->Unicode) + GetAllAliasesLengthRequest->Length /= sizeof(WCHAR); + + Status = STATUS_SUCCESS; + } + else + { + Status = STATUS_INVALID_PARAMETER; + } + ConSrvReleaseConsole(Console, TRUE); - return STATUS_SUCCESS; + return Status; }
CSR_API(SrvGetConsoleAliasExes) @@ -530,7 +537,7 @@ DPRINT("SrvGetConsoleAliasExes entered\n");
if (!CsrValidateMessageBuffer(ApiMessage, - (PVOID)&GetAliasesExesRequest->ExeNames, + (PVOID*)&GetAliasesExesRequest->ExeNames, GetAliasesExesRequest->Length, sizeof(BYTE))) { @@ -568,17 +575,24 @@
CSR_API(SrvGetConsoleAliasExesLength) { + NTSTATUS Status; PCONSOLE_GETALIASESEXESLENGTH GetAliasesExesLengthRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAliasesExesLengthRequest; PCONSOLE Console; - DPRINT("SrvGetConsoleAliasExesLength entered\n"); - - ApiMessage->Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE); - if (NT_SUCCESS(ApiMessage->Status)) - { - GetAliasesExesLengthRequest->Length = IntGetConsoleAliasesExesLength(Console->Aliases); - ConSrvReleaseConsole(Console, TRUE); - } - return ApiMessage->Status; + + Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE); + if (!NT_SUCCESS(Status)) return Status; + + GetAliasesExesLengthRequest->Length = IntGetConsoleAliasesExesLength(Console->Aliases); + + /* + * Quick and dirty way of getting the number of bytes of the + * corresponding ANSI string from the one in UNICODE. + */ + if (!GetAliasesExesLengthRequest->Unicode) + GetAliasesExesLengthRequest->Length /= sizeof(WCHAR); + + ConSrvReleaseConsole(Console, TRUE); + return Status; }
/* EOF */
Modified: branches/condrv_restructure/win32ss/user/winsrv/consrv/lineinput.c URL: http://svn.reactos.org/svn/reactos/branches/condrv_restructure/win32ss/user/... ============================================================================== --- branches/condrv_restructure/win32ss/user/winsrv/consrv/lineinput.c [iso-8859-1] (original) +++ branches/condrv_restructure/win32ss/user/winsrv/consrv/lineinput.c [iso-8859-1] Thu May 8 18:08:07 2014 @@ -455,158 +455,193 @@
CSR_API(SrvGetConsoleCommandHistory) { + NTSTATUS Status; PCONSOLE_GETCOMMANDHISTORY GetCommandHistoryRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCommandHistoryRequest; - PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process); PCONSOLE Console; - NTSTATUS Status; PHISTORY_BUFFER Hist; + UNICODE_STRING ExeName; PBYTE Buffer = (PBYTE)GetCommandHistoryRequest->History; - ULONG BufferSize = GetCommandHistoryRequest->Length; + ULONG BufferSize = GetCommandHistoryRequest->HistoryLength; UINT i;
if ( !CsrValidateMessageBuffer(ApiMessage, (PVOID*)&GetCommandHistoryRequest->History, - GetCommandHistoryRequest->Length, + GetCommandHistoryRequest->HistoryLength, sizeof(BYTE)) || !CsrValidateMessageBuffer(ApiMessage, - (PVOID*)&GetCommandHistoryRequest->ExeName.Buffer, - GetCommandHistoryRequest->ExeName.Length, + (PVOID*)&GetCommandHistoryRequest->ExeName, + GetCommandHistoryRequest->ExeLength, sizeof(BYTE)) ) { return STATUS_INVALID_PARAMETER; }
- Status = ConSrvGetConsole(ProcessData, &Console, TRUE); - if (NT_SUCCESS(Status)) - { - Hist = HistoryFindBuffer(Console, &GetCommandHistoryRequest->ExeName); - if (Hist) - { - for (i = 0; i < Hist->NumEntries; i++) + Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE); + if (!NT_SUCCESS(Status)) return Status; + + // FIXME: convert to UNICODE if Unicode(2) == FALSE + ExeName.Length = ExeName.MaximumLength = GetCommandHistoryRequest->ExeLength; + ExeName.Buffer = GetCommandHistoryRequest->ExeName; + + Hist = HistoryFindBuffer(Console, &ExeName); + if (Hist) + { + for (i = 0; i < Hist->NumEntries; i++) + { + if (BufferSize < (Hist->Entries[i].Length + sizeof(WCHAR))) { - if (BufferSize < (Hist->Entries[i].Length + sizeof(WCHAR))) - { - Status = STATUS_BUFFER_OVERFLOW; - break; - } - memcpy(Buffer, Hist->Entries[i].Buffer, Hist->Entries[i].Length); - Buffer += Hist->Entries[i].Length; - *(PWCHAR)Buffer = L'\0'; - Buffer += sizeof(WCHAR); + Status = STATUS_BUFFER_OVERFLOW; + break; } - } - GetCommandHistoryRequest->Length = Buffer - (PBYTE)GetCommandHistoryRequest->History; - ConSrvReleaseConsole(Console, TRUE); - } + // FIXME: convert to UNICODE if Unicode == FALSE + memcpy(Buffer, Hist->Entries[i].Buffer, Hist->Entries[i].Length); + Buffer += Hist->Entries[i].Length; + *(PWCHAR)Buffer = L'\0'; + Buffer += sizeof(WCHAR); + + // { + // WideCharToMultiByte(CP_ACP, 0, + // GetCommandHistoryRequest->History, + // GetCommandHistoryRequest->HistoryLength / sizeof(WCHAR), + // lpHistory, + // cbHistory, + // NULL, NULL); + // } + + } + } + // FIXME: convert to UNICODE if Unicode == FALSE + GetCommandHistoryRequest->HistoryLength = Buffer - (PBYTE)GetCommandHistoryRequest->History; + + ConSrvReleaseConsole(Console, TRUE); return Status; }
CSR_API(SrvGetConsoleCommandHistoryLength) { + NTSTATUS Status; PCONSOLE_GETCOMMANDHISTORYLENGTH GetCommandHistoryLengthRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCommandHistoryLengthRequest; - PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process); PCONSOLE Console; - NTSTATUS Status; PHISTORY_BUFFER Hist; + UNICODE_STRING ExeName; ULONG Length = 0; UINT i;
if (!CsrValidateMessageBuffer(ApiMessage, - (PVOID*)&GetCommandHistoryLengthRequest->ExeName.Buffer, - GetCommandHistoryLengthRequest->ExeName.Length, + (PVOID*)&GetCommandHistoryLengthRequest->ExeName, + GetCommandHistoryLengthRequest->ExeLength, sizeof(BYTE))) { return STATUS_INVALID_PARAMETER; }
- Status = ConSrvGetConsole(ProcessData, &Console, TRUE); - if (NT_SUCCESS(Status)) - { - Hist = HistoryFindBuffer(Console, &GetCommandHistoryLengthRequest->ExeName); - if (Hist) - { - for (i = 0; i < Hist->NumEntries; i++) - Length += Hist->Entries[i].Length + sizeof(WCHAR); - } - GetCommandHistoryLengthRequest->Length = Length; - ConSrvReleaseConsole(Console, TRUE); - } + Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE); + if (!NT_SUCCESS(Status)) return Status; + + // FIXME: convert to UNICODE if Unicode(2) == FALSE + ExeName.Length = ExeName.MaximumLength = GetCommandHistoryLengthRequest->ExeLength; + ExeName.Buffer = GetCommandHistoryLengthRequest->ExeName; + + Hist = HistoryFindBuffer(Console, &ExeName); + if (Hist) + { + for (i = 0; i < Hist->NumEntries; i++) + Length += Hist->Entries[i].Length + sizeof(WCHAR); + } + GetCommandHistoryLengthRequest->HistoryLength = Length; + + /* + * Quick and dirty way of getting the number of bytes of the + * corresponding ANSI string from the one in UNICODE. + */ + if (!GetCommandHistoryLengthRequest->Unicode) + GetCommandHistoryLengthRequest->HistoryLength /= sizeof(WCHAR); + + ConSrvReleaseConsole(Console, TRUE); return Status; }
CSR_API(SrvExpungeConsoleCommandHistory) { + NTSTATUS Status; PCONSOLE_EXPUNGECOMMANDHISTORY ExpungeCommandHistoryRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ExpungeCommandHistoryRequest; - PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process); PCONSOLE Console; PHISTORY_BUFFER Hist; + UNICODE_STRING ExeName; + + if (!CsrValidateMessageBuffer(ApiMessage, + (PVOID*)&ExpungeCommandHistoryRequest->ExeName, + ExpungeCommandHistoryRequest->ExeLength, + sizeof(BYTE))) + { + return STATUS_INVALID_PARAMETER; + } + + Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE); + if (!NT_SUCCESS(Status)) return Status; + + // FIXME: convert to UNICODE if Unicode(2) == FALSE + ExeName.Length = ExeName.MaximumLength = ExpungeCommandHistoryRequest->ExeLength; + ExeName.Buffer = ExpungeCommandHistoryRequest->ExeName; + + Hist = HistoryFindBuffer(Console, &ExeName); + HistoryDeleteBuffer(Hist); + + ConSrvReleaseConsole(Console, TRUE); + return Status; +} + +CSR_API(SrvSetConsoleNumberOfCommands) +{ NTSTATUS Status; - - if (!CsrValidateMessageBuffer(ApiMessage, - (PVOID*)&ExpungeCommandHistoryRequest->ExeName.Buffer, - ExpungeCommandHistoryRequest->ExeName.Length, - sizeof(BYTE))) - { - return STATUS_INVALID_PARAMETER; - } - - Status = ConSrvGetConsole(ProcessData, &Console, TRUE); - if (NT_SUCCESS(Status)) - { - Hist = HistoryFindBuffer(Console, &ExpungeCommandHistoryRequest->ExeName); - HistoryDeleteBuffer(Hist); - ConSrvReleaseConsole(Console, TRUE); - } - return Status; -} - -CSR_API(SrvSetConsoleNumberOfCommands) -{ PCONSOLE_SETHISTORYNUMBERCOMMANDS SetHistoryNumberCommandsRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetHistoryNumberCommandsRequest; - PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process); PCONSOLE Console; PHISTORY_BUFFER Hist; - NTSTATUS Status; UINT MaxEntries = SetHistoryNumberCommandsRequest->NumCommands; + UNICODE_STRING ExeName; PUNICODE_STRING OldEntryList, NewEntryList;
if (!CsrValidateMessageBuffer(ApiMessage, - (PVOID*)&SetHistoryNumberCommandsRequest->ExeName.Buffer, - SetHistoryNumberCommandsRequest->ExeName.Length, + (PVOID*)&SetHistoryNumberCommandsRequest->ExeName, + SetHistoryNumberCommandsRequest->ExeLength, sizeof(BYTE))) { return STATUS_INVALID_PARAMETER; }
- Status = ConSrvGetConsole(ProcessData, &Console, TRUE); - if (NT_SUCCESS(Status)) - { - Hist = HistoryFindBuffer(Console, &SetHistoryNumberCommandsRequest->ExeName); - if (Hist) - { - OldEntryList = Hist->Entries; - NewEntryList = ConsoleAllocHeap(0, MaxEntries * sizeof(UNICODE_STRING)); - if (!NewEntryList) + Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE); + if (!NT_SUCCESS(Status)) return Status; + + // FIXME: convert to UNICODE if Unicode(2) == FALSE + ExeName.Length = ExeName.MaximumLength = SetHistoryNumberCommandsRequest->ExeLength; + ExeName.Buffer = SetHistoryNumberCommandsRequest->ExeName; + + Hist = HistoryFindBuffer(Console, &ExeName); + if (Hist) + { + OldEntryList = Hist->Entries; + NewEntryList = ConsoleAllocHeap(0, MaxEntries * sizeof(UNICODE_STRING)); + if (!NewEntryList) + { + Status = STATUS_NO_MEMORY; + } + else + { + /* If necessary, shrink by removing oldest entries */ + for (; Hist->NumEntries > MaxEntries; Hist->NumEntries--) { - Status = STATUS_NO_MEMORY; + RtlFreeUnicodeString(Hist->Entries++); + Hist->Position += (Hist->Position == 0); } - else - { - /* If necessary, shrink by removing oldest entries */ - for (; Hist->NumEntries > MaxEntries; Hist->NumEntries--) - { - RtlFreeUnicodeString(Hist->Entries++); - Hist->Position += (Hist->Position == 0); - } - - Hist->MaxEntries = MaxEntries; - Hist->Entries = memcpy(NewEntryList, Hist->Entries, - Hist->NumEntries * sizeof(UNICODE_STRING)); - ConsoleFreeHeap(OldEntryList); - } - } - ConSrvReleaseConsole(Console, TRUE); - } + + Hist->MaxEntries = MaxEntries; + Hist->Entries = memcpy(NewEntryList, Hist->Entries, + Hist->NumEntries * sizeof(UNICODE_STRING)); + ConsoleFreeHeap(OldEntryList); + } + } + + ConSrvReleaseConsole(Console, TRUE); return Status; }
@@ -642,8 +677,21 @@
CSR_API(SrvSetConsoleCommandHistoryMode) { - DPRINT1("%s not yet implemented\n", __FUNCTION__); - return STATUS_NOT_IMPLEMENTED; + NTSTATUS Status; + PCONSOLE_SETHISTORYMODE SetHistoryModeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetHistoryModeRequest; + PCONSOLE Console; + + DPRINT1("SrvSetConsoleCommandHistoryMode(Mode = %d) is not yet implemented\n", + SetHistoryModeRequest->Mode); + + Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE); + if (!NT_SUCCESS(Status)) return Status; + + /* This API is not yet implemented */ + Status = STATUS_NOT_IMPLEMENTED; + + ConSrvReleaseConsole(Console, TRUE); + return Status; }
/* EOF */