2012-11-15 17:09:51 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* FILE: dll/win32/kernel32/client/console/history.c
|
|
|
|
* PURPOSE: Win32 Console Client history functions
|
|
|
|
* PROGRAMMERS: Jeffrey Morlan
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
|
|
|
#include <k32.h>
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
|
|
|
|
2012-11-15 22:34:44 +00:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Copy a string to a capture buffer */
|
|
|
|
static VOID
|
|
|
|
IntCaptureMessageString(PCSR_CAPTURE_BUFFER CaptureBuffer,
|
|
|
|
LPCVOID String,
|
|
|
|
BOOL Unicode,
|
|
|
|
PUNICODE_STRING RequestString)
|
|
|
|
{
|
|
|
|
ULONG Size;
|
|
|
|
if (Unicode)
|
|
|
|
{
|
|
|
|
Size = wcslen(String) * sizeof(WCHAR);
|
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer, (PVOID)String, Size, (PVOID *)&RequestString->Buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Size = strlen(String);
|
|
|
|
CsrAllocateMessagePointer(CaptureBuffer, Size * sizeof(WCHAR), (PVOID *)&RequestString->Buffer);
|
|
|
|
Size = MultiByteToWideChar(CP_ACP, 0, String, Size, RequestString->Buffer, Size * sizeof(WCHAR))
|
|
|
|
* sizeof(WCHAR);
|
|
|
|
}
|
2013-05-29 00:29:07 +00:00
|
|
|
RequestString->Length = RequestString->MaximumLength = (USHORT)Size;
|
2012-11-15 22:34:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-15 17:09:51 +00:00
|
|
|
static BOOL
|
|
|
|
IntExpungeConsoleCommandHistory(LPCVOID lpExeName, BOOL bUnicode)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2012-11-15 22:34:44 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_EXPUNGECOMMANDHISTORY ExpungeCommandHistoryRequest = &ApiMessage.Data.ExpungeCommandHistoryRequest;
|
2012-11-15 22:34:44 +00:00
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2012-11-15 17:09:51 +00:00
|
|
|
|
|
|
|
if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
|
|
|
|
if (!CaptureBuffer)
|
|
|
|
{
|
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
|
2013-01-05 23:10:12 +00:00
|
|
|
&ExpungeCommandHistoryRequest->ExeName);
|
2012-11-15 17:09:51 +00:00
|
|
|
|
2012-11-15 22:34:44 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-11-15 17:09:51 +00:00
|
|
|
CaptureBuffer,
|
2012-11-15 22:34:44 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepExpungeCommandHistory),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_EXPUNGECOMMANDHISTORY));
|
2012-11-15 17:09:51 +00:00
|
|
|
|
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2012-11-15 17:09:51 +00:00
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static DWORD
|
|
|
|
IntGetConsoleCommandHistory(LPVOID lpHistory, DWORD cbHistory, LPCVOID lpExeName, BOOL bUnicode)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2012-11-15 22:34:44 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_GETCOMMANDHISTORY GetCommandHistoryRequest = &ApiMessage.Data.GetCommandHistoryRequest;
|
2012-11-15 22:34:44 +00:00
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2012-11-15 17:09:51 +00:00
|
|
|
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 (!CaptureBuffer)
|
|
|
|
{
|
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
|
2013-01-05 23:10:12 +00:00
|
|
|
&GetCommandHistoryRequest->ExeName);
|
|
|
|
GetCommandHistoryRequest->Length = HistoryLength;
|
2012-11-15 17:09:51 +00:00
|
|
|
CsrAllocateMessagePointer(CaptureBuffer, HistoryLength,
|
2013-01-05 23:10:12 +00:00
|
|
|
(PVOID*)&GetCommandHistoryRequest->History);
|
2012-11-15 17:09:51 +00:00
|
|
|
|
2012-11-15 22:34:44 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-11-15 17:09:51 +00:00
|
|
|
CaptureBuffer,
|
2012-11-15 22:34:44 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCommandHistory),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETCOMMANDHISTORY));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2012-11-15 17:09:51 +00:00
|
|
|
{
|
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bUnicode)
|
|
|
|
{
|
|
|
|
memcpy(lpHistory,
|
2013-01-05 23:10:12 +00:00
|
|
|
GetCommandHistoryRequest->History,
|
|
|
|
GetCommandHistoryRequest->Length);
|
2012-11-15 17:09:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WideCharToMultiByte(CP_ACP, 0,
|
2013-01-05 23:10:12 +00:00
|
|
|
GetCommandHistoryRequest->History,
|
|
|
|
GetCommandHistoryRequest->Length / sizeof(WCHAR),
|
2012-11-15 17:09:51 +00:00
|
|
|
lpHistory,
|
|
|
|
cbHistory,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
2012-11-15 22:34:44 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
return GetCommandHistoryRequest->Length;
|
2012-11-15 17:09:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static DWORD
|
|
|
|
IntGetConsoleCommandHistoryLength(LPCVOID lpExeName, BOOL bUnicode)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2012-11-15 22:34:44 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_GETCOMMANDHISTORYLENGTH GetCommandHistoryLengthRequest = &ApiMessage.Data.GetCommandHistoryLengthRequest;
|
2012-11-15 22:34:44 +00:00
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2012-11-15 17:09:51 +00:00
|
|
|
|
|
|
|
if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
|
|
|
|
if (!CaptureBuffer)
|
|
|
|
{
|
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
|
2013-01-05 23:10:12 +00:00
|
|
|
&GetCommandHistoryLengthRequest->ExeName);
|
2012-11-15 17:09:51 +00:00
|
|
|
|
2012-11-15 22:34:44 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-11-15 17:09:51 +00:00
|
|
|
CaptureBuffer,
|
2012-11-15 22:34:44 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCommandHistoryLength),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETCOMMANDHISTORYLENGTH));
|
2012-11-15 17:09:51 +00:00
|
|
|
|
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2012-11-15 17:09:51 +00:00
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
return GetCommandHistoryLengthRequest->Length;
|
2012-11-15 17:09:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL
|
|
|
|
IntSetConsoleNumberOfCommands(DWORD dwNumCommands,
|
|
|
|
LPCVOID lpExeName,
|
|
|
|
BOOL bUnicode)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2012-11-15 22:34:44 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_SETHISTORYNUMBERCOMMANDS SetHistoryNumberCommandsRequest = &ApiMessage.Data.SetHistoryNumberCommandsRequest;
|
2012-11-15 22:34:44 +00:00
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2012-11-15 17:09:51 +00:00
|
|
|
|
|
|
|
if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
|
|
|
|
if (!CaptureBuffer)
|
|
|
|
{
|
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
|
2013-01-05 23:10:12 +00:00
|
|
|
&SetHistoryNumberCommandsRequest->ExeName);
|
|
|
|
SetHistoryNumberCommandsRequest->NumCommands = dwNumCommands;
|
2012-11-15 17:09:51 +00:00
|
|
|
|
2012-11-15 22:34:44 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-11-15 17:09:51 +00:00
|
|
|
CaptureBuffer,
|
2012-11-15 22:34:44 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetNumberOfCommands),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_SETHISTORYNUMBERCOMMANDS));
|
2012-11-15 17:09:51 +00:00
|
|
|
|
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2012-11-15 17:09:51 +00:00
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented (Undocumented)
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
ExpungeConsoleCommandHistoryW(LPCWSTR lpExeName)
|
|
|
|
{
|
|
|
|
return IntExpungeConsoleCommandHistory(lpExeName, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented (Undocumented)
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
ExpungeConsoleCommandHistoryA(LPCSTR lpExeName)
|
|
|
|
{
|
|
|
|
return IntExpungeConsoleCommandHistory(lpExeName, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented (Undocumented)
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
GetConsoleCommandHistoryW(LPWSTR lpHistory,
|
|
|
|
DWORD cbHistory,
|
|
|
|
LPCWSTR lpExeName)
|
|
|
|
{
|
|
|
|
return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented (Undocumented)
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
GetConsoleCommandHistoryA(LPSTR lpHistory,
|
|
|
|
DWORD cbHistory,
|
|
|
|
LPCSTR lpExeName)
|
|
|
|
{
|
|
|
|
return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented (Undocumented)
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
GetConsoleCommandHistoryLengthW(LPCWSTR lpExeName)
|
|
|
|
{
|
|
|
|
return IntGetConsoleCommandHistoryLength(lpExeName, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented (Undocumented)
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
GetConsoleCommandHistoryLengthA(LPCSTR lpExeName)
|
|
|
|
{
|
|
|
|
return IntGetConsoleCommandHistoryLength(lpExeName, FALSE) / sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented (Undocumented)
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
SetConsoleNumberOfCommandsW(DWORD dwNumCommands,
|
|
|
|
LPCSTR lpExeName)
|
|
|
|
{
|
|
|
|
return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented (Undocumented)
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
SetConsoleNumberOfCommandsA(DWORD dwNumCommands,
|
|
|
|
LPCWSTR lpExeName)
|
|
|
|
{
|
|
|
|
return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
SetConsoleCommandHistoryMode(IN DWORD dwMode)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|