ReactOS 0.4.15-dev-7924-g5949c20
history.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/client/console/history.c
5 * PURPOSE: Win32 Console Client history functions
6 * PROGRAMMERS: Jeffrey Morlan
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include <k32.h>
12
13#define NDEBUG
14#include <debug.h>
15
16
17/* PRIVATE FUNCTIONS **********************************************************/
18
19#if 0
20/* Get the size needed to copy a string to a capture buffer, including alignment */
21static ULONG
22IntStringSize(LPCVOID String,
23 BOOL Unicode)
24{
25 ULONG Size = (Unicode ? wcslen(String) : strlen(String)) * sizeof(WCHAR);
26 return (Size + 3) & ~3;
27}
28#endif
29
30static VOID
32{
33 CONSOLE_API_MESSAGE ApiMessage;
34 PCONSOLE_EXPUNGECOMMANDHISTORY ExpungeCommandHistoryRequest = &ApiMessage.Data.ExpungeCommandHistoryRequest;
35 PCSR_CAPTURE_BUFFER CaptureBuffer;
36
37 USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
38
39 if (lpExeName == NULL || NumChars == 0)
40 {
42 return;
43 }
44
45 ExpungeCommandHistoryRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
46 ExpungeCommandHistoryRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
47 ExpungeCommandHistoryRequest->Unicode =
48 ExpungeCommandHistoryRequest->Unicode2 = bUnicode;
49
50 // CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
51 CaptureBuffer = CsrAllocateCaptureBuffer(1, ExpungeCommandHistoryRequest->ExeLength);
52 if (!CaptureBuffer)
53 {
54 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
56 return;
57 }
58
59 CsrCaptureMessageBuffer(CaptureBuffer,
61 ExpungeCommandHistoryRequest->ExeLength,
62 (PVOID)&ExpungeCommandHistoryRequest->ExeName);
63
65 CaptureBuffer,
67 sizeof(*ExpungeCommandHistoryRequest));
68
69 CsrFreeCaptureBuffer(CaptureBuffer);
70
71 if (!NT_SUCCESS(ApiMessage.Status))
72 BaseSetLastNTError(ApiMessage.Status);
73}
74
75
76static DWORD
78{
79 CONSOLE_API_MESSAGE ApiMessage;
80 PCONSOLE_GETCOMMANDHISTORY GetCommandHistoryRequest = &ApiMessage.Data.GetCommandHistoryRequest;
81 PCSR_CAPTURE_BUFFER CaptureBuffer;
82
83 USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
84
85 if (lpExeName == NULL || NumChars == 0)
86 {
88 return 0;
89 }
90
91 GetCommandHistoryRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
92 GetCommandHistoryRequest->HistoryLength = cbHistory;
93 GetCommandHistoryRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
94 GetCommandHistoryRequest->Unicode =
95 GetCommandHistoryRequest->Unicode2 = bUnicode;
96
97 // CaptureBuffer = CsrAllocateCaptureBuffer(2, IntStringSize(lpExeName, bUnicode) +
98 // HistoryLength);
99 CaptureBuffer = CsrAllocateCaptureBuffer(2, GetCommandHistoryRequest->ExeLength +
100 GetCommandHistoryRequest->HistoryLength);
101 if (!CaptureBuffer)
102 {
103 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
105 return 0;
106 }
107
108 CsrCaptureMessageBuffer(CaptureBuffer,
110 GetCommandHistoryRequest->ExeLength,
111 (PVOID)&GetCommandHistoryRequest->ExeName);
112
113 CsrAllocateMessagePointer(CaptureBuffer, GetCommandHistoryRequest->HistoryLength,
114 (PVOID*)&GetCommandHistoryRequest->History);
115
117 CaptureBuffer,
119 sizeof(*GetCommandHistoryRequest));
120 if (!NT_SUCCESS(ApiMessage.Status))
121 {
122 CsrFreeCaptureBuffer(CaptureBuffer);
123 BaseSetLastNTError(ApiMessage.Status);
124 return 0;
125 }
126
127 RtlCopyMemory(lpHistory,
128 GetCommandHistoryRequest->History,
129 GetCommandHistoryRequest->HistoryLength);
130
131 CsrFreeCaptureBuffer(CaptureBuffer);
132
133 return GetCommandHistoryRequest->HistoryLength;
134}
135
136
137static DWORD
139{
140 CONSOLE_API_MESSAGE ApiMessage;
141 PCONSOLE_GETCOMMANDHISTORYLENGTH GetCommandHistoryLengthRequest = &ApiMessage.Data.GetCommandHistoryLengthRequest;
142 PCSR_CAPTURE_BUFFER CaptureBuffer;
143
144 USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
145
146 if (lpExeName == NULL || NumChars == 0)
147 {
149 return 0;
150 }
151
152 GetCommandHistoryLengthRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
153 GetCommandHistoryLengthRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
154 GetCommandHistoryLengthRequest->Unicode =
155 GetCommandHistoryLengthRequest->Unicode2 = bUnicode;
156
157 // CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
158 CaptureBuffer = CsrAllocateCaptureBuffer(1, GetCommandHistoryLengthRequest->ExeLength);
159 if (!CaptureBuffer)
160 {
161 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
163 return 0;
164 }
165
166 CsrCaptureMessageBuffer(CaptureBuffer,
168 GetCommandHistoryLengthRequest->ExeLength,
169 (PVOID)&GetCommandHistoryLengthRequest->ExeName);
170
172 CaptureBuffer,
174 sizeof(*GetCommandHistoryLengthRequest));
175
176 CsrFreeCaptureBuffer(CaptureBuffer);
177
178 if (!NT_SUCCESS(ApiMessage.Status))
179 {
180 BaseSetLastNTError(ApiMessage.Status);
181 return 0;
182 }
183
184 return GetCommandHistoryLengthRequest->HistoryLength;
185}
186
187
188static BOOL
191 BOOLEAN bUnicode)
192{
193 CONSOLE_API_MESSAGE ApiMessage;
194 PCONSOLE_SETHISTORYNUMBERCOMMANDS SetHistoryNumberCommandsRequest = &ApiMessage.Data.SetHistoryNumberCommandsRequest;
195 PCSR_CAPTURE_BUFFER CaptureBuffer;
196
197 USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
198
199 if (lpExeName == NULL || NumChars == 0)
200 {
202 return FALSE;
203 }
204
205 SetHistoryNumberCommandsRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
206 SetHistoryNumberCommandsRequest->NumCommands = dwNumCommands;
207 SetHistoryNumberCommandsRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
208 SetHistoryNumberCommandsRequest->Unicode =
209 SetHistoryNumberCommandsRequest->Unicode2 = bUnicode;
210
211 // CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
212 CaptureBuffer = CsrAllocateCaptureBuffer(1, SetHistoryNumberCommandsRequest->ExeLength);
213 if (!CaptureBuffer)
214 {
215 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
217 return FALSE;
218 }
219
220 CsrCaptureMessageBuffer(CaptureBuffer,
222 SetHistoryNumberCommandsRequest->ExeLength,
223 (PVOID)&SetHistoryNumberCommandsRequest->ExeName);
224
226 CaptureBuffer,
228 sizeof(*SetHistoryNumberCommandsRequest));
229
230 CsrFreeCaptureBuffer(CaptureBuffer);
231
232 if (!NT_SUCCESS(ApiMessage.Status))
233 {
234 BaseSetLastNTError(ApiMessage.Status);
235 return FALSE;
236 }
237
238 return TRUE;
239}
240
241
242/* FUNCTIONS ******************************************************************/
243
244/*
245 * @implemented (Undocumented)
246 */
247VOID
248WINAPI
251{
253}
254
255
256/*
257 * @implemented (Undocumented)
258 */
259VOID
260WINAPI
263{
265}
266
267
268/*
269 * @implemented (Undocumented)
270 */
271DWORD
272WINAPI
275 IN DWORD cbHistory,
277{
278 return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, TRUE);
279}
280
281
282/*
283 * @implemented (Undocumented)
284 */
285DWORD
286WINAPI
289 IN DWORD cbHistory,
291{
292 return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, FALSE);
293}
294
295
296/*
297 * @implemented (Undocumented)
298 */
299DWORD
300WINAPI
303{
305}
306
307
308/*
309 * @implemented (Undocumented)
310 */
311DWORD
312WINAPI
315{
317}
318
319
320/*
321 * @implemented (Undocumented)
322 */
323BOOL
324WINAPI
328{
329 return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, TRUE);
330}
331
332
333/*
334 * @implemented (Undocumented)
335 */
336BOOL
337WINAPI
341{
342 return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, FALSE);
343}
344
345
346/*
347 * @implemented
348 */
349BOOL
350WINAPI
353{
354 CONSOLE_API_MESSAGE ApiMessage;
355 PCONSOLE_SETHISTORYMODE SetHistoryModeRequest = &ApiMessage.Data.SetHistoryModeRequest;
356
357 SetHistoryModeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
358 SetHistoryModeRequest->Mode = dwMode;
359
361 NULL,
363 sizeof(*SetHistoryModeRequest));
364 if (!NT_SUCCESS(ApiMessage.Status))
365 {
366 BaseSetLastNTError(ApiMessage.Status);
367 return FALSE;
368 }
369
370 return TRUE;
371}
372
373/* EOF */
#define NtCurrentPeb()
Definition: FLS.c:22
unsigned char BOOLEAN
#define DECLSPEC_HOTPATCH
Definition: _mingw.h:243
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define DPRINT1
Definition: precomp.h:8
@ ConsolepGetCommandHistoryLength
Definition: conmsg.h:81
@ ConsolepSetNumberOfCommands
Definition: conmsg.h:80
@ ConsolepSetCommandHistoryMode
Definition: conmsg.h:83
@ ConsolepGetCommandHistory
Definition: conmsg.h:82
@ ConsolepExpungeCommandHistory
Definition: conmsg.h:79
#define CONSRV_SERVERDLL_INDEX
Definition: conmsg.h:15
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
static DWORD IntGetConsoleCommandHistoryLength(LPCVOID lpExeName, BOOL bUnicode)
Definition: history.c:138
DWORD WINAPI DECLSPEC_HOTPATCH GetConsoleCommandHistoryLengthW(IN LPCWSTR lpExeName)
Definition: history.c:302
VOID WINAPI DECLSPEC_HOTPATCH ExpungeConsoleCommandHistoryW(IN LPCWSTR lpExeName)
Definition: history.c:250
DWORD WINAPI DECLSPEC_HOTPATCH GetConsoleCommandHistoryW(OUT LPWSTR lpHistory, IN DWORD cbHistory, IN LPCWSTR lpExeName)
Definition: history.c:274
static VOID IntExpungeConsoleCommandHistory(LPCVOID lpExeName, BOOLEAN bUnicode)
Definition: history.c:31
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleNumberOfCommandsW(IN DWORD dwNumCommands, IN LPCWSTR lpExeName)
Definition: history.c:326
static DWORD IntGetConsoleCommandHistory(LPVOID lpHistory, DWORD cbHistory, LPCVOID lpExeName, BOOLEAN bUnicode)
Definition: history.c:77
VOID WINAPI DECLSPEC_HOTPATCH ExpungeConsoleCommandHistoryA(IN LPCSTR lpExeName)
Definition: history.c:262
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleNumberOfCommandsA(IN DWORD dwNumCommands, IN LPCSTR lpExeName)
Definition: history.c:339
static BOOL IntSetConsoleNumberOfCommands(DWORD dwNumCommands, LPCVOID lpExeName, BOOLEAN bUnicode)
Definition: history.c:189
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleCommandHistoryMode(IN DWORD dwMode)
Definition: history.c:352
DWORD WINAPI DECLSPEC_HOTPATCH GetConsoleCommandHistoryA(OUT LPSTR lpHistory, IN DWORD cbHistory, IN LPCSTR lpExeName)
Definition: history.c:288
DWORD WINAPI DECLSPEC_HOTPATCH GetConsoleCommandHistoryLengthA(IN LPCSTR lpExeName)
Definition: history.c:314
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static DWORD LPSTR lpExeName
Definition: process.c:72
unsigned short USHORT
Definition: pedump.c:61
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
PCSR_CAPTURE_BUFFER NTAPI CsrAllocateCaptureBuffer(_In_ ULONG ArgumentCount, _In_ ULONG BufferSize)
Definition: capture.c:87
ULONG NTAPI CsrAllocateMessagePointer(_Inout_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_ ULONG MessageLength, _Out_ PVOID *CapturedData)
Definition: capture.c:152
VOID NTAPI CsrFreeCaptureBuffer(_In_ _Frees_ptr_ PCSR_CAPTURE_BUFFER CaptureBuffer)
Definition: capture.c:210
VOID NTAPI CsrCaptureMessageBuffer(_Inout_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_opt_ PVOID MessageBuffer, _In_ ULONG MessageLength, _Out_ PVOID *CapturedData)
Definition: capture.c:189
NTSTATUS NTAPI CsrClientCallServer(_Inout_ PCSR_API_MESSAGE ApiMessage, _Inout_opt_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_ CSR_API_NUMBER ApiNumber, _In_ ULONG DataLength)
Definition: connect.c:366
CONSOLE_SETHISTORYNUMBERCOMMANDS SetHistoryNumberCommandsRequest
Definition: conmsg.h:1010
CONSOLE_GETCOMMANDHISTORYLENGTH GetCommandHistoryLengthRequest
Definition: conmsg.h:1007
NTSTATUS Status
Definition: conmsg.h:919
CONSOLE_GETCOMMANDHISTORY GetCommandHistoryRequest
Definition: conmsg.h:1006
CONSOLE_EXPUNGECOMMANDHISTORY ExpungeCommandHistoryRequest
Definition: conmsg.h:1008
union _CONSOLE_API_MESSAGE::@3540 Data
CONSOLE_SETHISTORYMODE SetHistoryModeRequest
Definition: conmsg.h:1011
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
CONST void * LPCVOID
Definition: windef.h:191
#define WINAPI
Definition: msvc.h:6
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
char CHAR
Definition: xmlstorage.h:175