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
9 /* INCLUDES *******************************************************************/
17 /* PRIVATE FUNCTIONS **********************************************************/
20 /* Get the size needed to copy a string to a capture buffer, including alignment */
22 IntStringSize(LPCVOID String
,
25 ULONG Size
= (Unicode
? wcslen(String
) : strlen(String
)) * sizeof(WCHAR
);
26 return (Size
+ 3) & ~3;
31 IntExpungeConsoleCommandHistory(LPCVOID lpExeName
, BOOLEAN bUnicode
)
33 CONSOLE_API_MESSAGE ApiMessage
;
34 PCONSOLE_EXPUNGECOMMANDHISTORY ExpungeCommandHistoryRequest
= &ApiMessage
.Data
.ExpungeCommandHistoryRequest
;
35 PCSR_CAPTURE_BUFFER CaptureBuffer
;
37 USHORT NumChars
= (USHORT
)(lpExeName
? (bUnicode
? wcslen(lpExeName
) : strlen(lpExeName
)) : 0);
39 if (lpExeName
== NULL
|| NumChars
== 0)
41 SetLastError(ERROR_INVALID_PARAMETER
);
45 ExpungeCommandHistoryRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
46 ExpungeCommandHistoryRequest
->ExeLength
= NumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
47 ExpungeCommandHistoryRequest
->Unicode
=
48 ExpungeCommandHistoryRequest
->Unicode2
= bUnicode
;
50 // CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
51 CaptureBuffer
= CsrAllocateCaptureBuffer(1, ExpungeCommandHistoryRequest
->ExeLength
);
54 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
55 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
59 CsrCaptureMessageBuffer(CaptureBuffer
,
61 ExpungeCommandHistoryRequest
->ExeLength
,
62 (PVOID
)&ExpungeCommandHistoryRequest
->ExeName
);
64 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
66 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepExpungeCommandHistory
),
67 sizeof(*ExpungeCommandHistoryRequest
));
69 CsrFreeCaptureBuffer(CaptureBuffer
);
71 if (!NT_SUCCESS(ApiMessage
.Status
))
72 BaseSetLastNTError(ApiMessage
.Status
);
77 IntGetConsoleCommandHistory(LPVOID lpHistory
, DWORD cbHistory
, LPCVOID lpExeName
, BOOLEAN bUnicode
)
79 CONSOLE_API_MESSAGE ApiMessage
;
80 PCONSOLE_GETCOMMANDHISTORY GetCommandHistoryRequest
= &ApiMessage
.Data
.GetCommandHistoryRequest
;
81 PCSR_CAPTURE_BUFFER CaptureBuffer
;
83 USHORT NumChars
= (USHORT
)(lpExeName
? (bUnicode
? wcslen(lpExeName
) : strlen(lpExeName
)) : 0);
85 if (lpExeName
== NULL
|| NumChars
== 0)
87 SetLastError(ERROR_INVALID_PARAMETER
);
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
;
97 // CaptureBuffer = CsrAllocateCaptureBuffer(2, IntStringSize(lpExeName, bUnicode) +
99 CaptureBuffer
= CsrAllocateCaptureBuffer(2, GetCommandHistoryRequest
->ExeLength
+
100 GetCommandHistoryRequest
->HistoryLength
);
103 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
104 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
108 CsrCaptureMessageBuffer(CaptureBuffer
,
110 GetCommandHistoryRequest
->ExeLength
,
111 (PVOID
)&GetCommandHistoryRequest
->ExeName
);
113 CsrAllocateMessagePointer(CaptureBuffer
, GetCommandHistoryRequest
->HistoryLength
,
114 (PVOID
*)&GetCommandHistoryRequest
->History
);
116 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
118 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCommandHistory
),
119 sizeof(*GetCommandHistoryRequest
));
120 if (!NT_SUCCESS(ApiMessage
.Status
))
122 CsrFreeCaptureBuffer(CaptureBuffer
);
123 BaseSetLastNTError(ApiMessage
.Status
);
127 RtlCopyMemory(lpHistory
,
128 GetCommandHistoryRequest
->History
,
129 GetCommandHistoryRequest
->HistoryLength
);
131 CsrFreeCaptureBuffer(CaptureBuffer
);
133 return GetCommandHistoryRequest
->HistoryLength
;
138 IntGetConsoleCommandHistoryLength(LPCVOID lpExeName
, BOOL bUnicode
)
140 CONSOLE_API_MESSAGE ApiMessage
;
141 PCONSOLE_GETCOMMANDHISTORYLENGTH GetCommandHistoryLengthRequest
= &ApiMessage
.Data
.GetCommandHistoryLengthRequest
;
142 PCSR_CAPTURE_BUFFER CaptureBuffer
;
144 USHORT NumChars
= (USHORT
)(lpExeName
? (bUnicode
? wcslen(lpExeName
) : strlen(lpExeName
)) : 0);
146 if (lpExeName
== NULL
|| NumChars
== 0)
148 SetLastError(ERROR_INVALID_PARAMETER
);
152 GetCommandHistoryLengthRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
153 GetCommandHistoryLengthRequest
->ExeLength
= NumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
154 GetCommandHistoryLengthRequest
->Unicode
=
155 GetCommandHistoryLengthRequest
->Unicode2
= bUnicode
;
157 // CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
158 CaptureBuffer
= CsrAllocateCaptureBuffer(1, GetCommandHistoryLengthRequest
->ExeLength
);
161 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
162 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
166 CsrCaptureMessageBuffer(CaptureBuffer
,
168 GetCommandHistoryLengthRequest
->ExeLength
,
169 (PVOID
)&GetCommandHistoryLengthRequest
->ExeName
);
171 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
173 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCommandHistoryLength
),
174 sizeof(*GetCommandHistoryLengthRequest
));
176 CsrFreeCaptureBuffer(CaptureBuffer
);
178 if (!NT_SUCCESS(ApiMessage
.Status
))
180 BaseSetLastNTError(ApiMessage
.Status
);
184 return GetCommandHistoryLengthRequest
->HistoryLength
;
189 IntSetConsoleNumberOfCommands(DWORD dwNumCommands
,
193 CONSOLE_API_MESSAGE ApiMessage
;
194 PCONSOLE_SETHISTORYNUMBERCOMMANDS SetHistoryNumberCommandsRequest
= &ApiMessage
.Data
.SetHistoryNumberCommandsRequest
;
195 PCSR_CAPTURE_BUFFER CaptureBuffer
;
197 USHORT NumChars
= (USHORT
)(lpExeName
? (bUnicode
? wcslen(lpExeName
) : strlen(lpExeName
)) : 0);
199 if (lpExeName
== NULL
|| NumChars
== 0)
201 SetLastError(ERROR_INVALID_PARAMETER
);
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
;
211 // CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
212 CaptureBuffer
= CsrAllocateCaptureBuffer(1, SetHistoryNumberCommandsRequest
->ExeLength
);
215 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
216 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
220 CsrCaptureMessageBuffer(CaptureBuffer
,
222 SetHistoryNumberCommandsRequest
->ExeLength
,
223 (PVOID
)&SetHistoryNumberCommandsRequest
->ExeName
);
225 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
227 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetNumberOfCommands
),
228 sizeof(*SetHistoryNumberCommandsRequest
));
230 CsrFreeCaptureBuffer(CaptureBuffer
);
232 if (!NT_SUCCESS(ApiMessage
.Status
))
234 BaseSetLastNTError(ApiMessage
.Status
);
242 /* FUNCTIONS ******************************************************************/
245 * @implemented (Undocumented)
250 ExpungeConsoleCommandHistoryW(LPCWSTR lpExeName
)
252 IntExpungeConsoleCommandHistory(lpExeName
, TRUE
);
257 * @implemented (Undocumented)
262 ExpungeConsoleCommandHistoryA(LPCSTR lpExeName
)
264 IntExpungeConsoleCommandHistory(lpExeName
, FALSE
);
269 * @implemented (Undocumented)
274 GetConsoleCommandHistoryW(LPWSTR lpHistory
,
278 return IntGetConsoleCommandHistory(lpHistory
, cbHistory
, lpExeName
, TRUE
);
283 * @implemented (Undocumented)
288 GetConsoleCommandHistoryA(LPSTR lpHistory
,
292 return IntGetConsoleCommandHistory(lpHistory
, cbHistory
, lpExeName
, FALSE
);
297 * @implemented (Undocumented)
302 GetConsoleCommandHistoryLengthW(LPCWSTR lpExeName
)
304 return IntGetConsoleCommandHistoryLength(lpExeName
, TRUE
);
309 * @implemented (Undocumented)
314 GetConsoleCommandHistoryLengthA(LPCSTR lpExeName
)
316 return IntGetConsoleCommandHistoryLength(lpExeName
, FALSE
);
321 * @implemented (Undocumented)
326 SetConsoleNumberOfCommandsW(DWORD dwNumCommands
,
329 return IntSetConsoleNumberOfCommands(dwNumCommands
, lpExeName
, TRUE
);
334 * @implemented (Undocumented)
339 SetConsoleNumberOfCommandsA(DWORD dwNumCommands
,
342 return IntSetConsoleNumberOfCommands(dwNumCommands
, lpExeName
, FALSE
);
352 SetConsoleCommandHistoryMode(IN DWORD dwMode
)
354 CONSOLE_API_MESSAGE ApiMessage
;
355 PCONSOLE_SETHISTORYMODE SetHistoryModeRequest
= &ApiMessage
.Data
.SetHistoryModeRequest
;
357 SetHistoryModeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
358 SetHistoryModeRequest
->Mode
= dwMode
;
360 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
362 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetCommandHistoryMode
),
363 sizeof(*SetHistoryModeRequest
));
364 if (!NT_SUCCESS(ApiMessage
.Status
))
366 BaseSetLastNTError(ApiMessage
.Status
);