ReactOS  0.4.14-dev-1034-g1e60116
history.c File Reference
#include "consrv.h"
#include "popup.h"
#include <debug.h>
Include dependency graph for history.c:

Go to the source code of this file.

Classes

struct  _HISTORY_BUFFER
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _HISTORY_BUFFER HISTORY_BUFFER
 
typedef struct _HISTORY_BUFFERPHISTORY_BUFFER
 

Functions

BOOLEAN ConvertInputAnsiToUnicode (PCONSRV_CONSOLE Console, PVOID Source, USHORT SourceLength, PWCHAR *Target, PUSHORT TargetLength)
 
BOOLEAN ConvertInputUnicodeToAnsi (PCONSRV_CONSOLE Console, PVOID Source, USHORT SourceLength, PCHAR Target, USHORT TargetLength)
 
static PHISTORY_BUFFER HistoryCurrentBuffer (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
 
static PHISTORY_BUFFER HistoryFindBuffer (PCONSRV_CONSOLE Console, PVOID ExeName, USHORT ExeLength, BOOLEAN UnicodeExe)
 
static VOID HistoryDeleteBuffer (PHISTORY_BUFFER Hist)
 
VOID HistoryAddEntry (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, PUNICODE_STRING Entry)
 
VOID HistoryGetCurrentEntry (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, PUNICODE_STRING Entry)
 
BOOL HistoryRecallHistory (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, INT Offset, PUNICODE_STRING Entry)
 
BOOL HistoryFindEntryByPrefix (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName, PUNICODE_STRING Prefix, PUNICODE_STRING Entry)
 
PPOPUP_WINDOW HistoryDisplayCurrentHistory (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
 
VOID HistoryDeleteCurrentBuffer (PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
 
VOID HistoryDeleteBuffers (PCONSRV_CONSOLE Console)
 
 CSR_API (SrvGetConsoleCommandHistory)
 
 CSR_API (SrvGetConsoleCommandHistoryLength)
 
 CSR_API (SrvExpungeConsoleCommandHistory)
 
 CSR_API (SrvSetConsoleNumberOfCommands)
 
 CSR_API (SrvGetConsoleHistory)
 
 CSR_API (SrvSetConsoleHistory)
 
 CSR_API (SrvSetConsoleCommandHistoryMode)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file history.c.

Typedef Documentation

◆ HISTORY_BUFFER

◆ PHISTORY_BUFFER

Function Documentation

◆ ConvertInputAnsiToUnicode()

BOOLEAN ConvertInputAnsiToUnicode ( PCONSRV_CONSOLE  Console,
PVOID  Source,
USHORT  SourceLength,
PWCHAR Target,
PUSHORT  TargetLength 
)

Definition at line 37 of file alias.c.

43 {
44  ASSERT(Source && Target && TargetLength);
45 
46  /* Use the console input CP for the conversion */
47  *TargetLength = MultiByteToWideChar(Console->InputCodePage, 0,
48  Source, SourceLength,
49  NULL, 0);
50  *Target = ConsoleAllocHeap(0, *TargetLength * sizeof(WCHAR));
51  if (*Target == NULL) return FALSE;
52 
53  MultiByteToWideChar(Console->InputCodePage, 0,
54  Source, SourceLength,
55  *Target, *TargetLength);
56 
57  /* The returned Length was in number of WCHARs, convert it in bytes */
58  *TargetLength *= sizeof(WCHAR);
59 
60  return TRUE;
61 }
#define TRUE
Definition: types.h:120
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1068
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define MultiByteToWideChar
Definition: compat.h:100
CConsole Console
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167

Referenced by HistoryFindBuffer().

◆ ConvertInputUnicodeToAnsi()

BOOLEAN ConvertInputUnicodeToAnsi ( PCONSRV_CONSOLE  Console,
PVOID  Source,
USHORT  SourceLength,
PCHAR  Target,
USHORT  TargetLength 
)

Definition at line 64 of file alias.c.

70 {
71  ASSERT(Source && Target && TargetLength);
72 
73  /*
74  * From MSDN:
75  * "The lpMultiByteStr and lpWideCharStr pointers must not be the same.
76  * If they are the same, the function fails, and GetLastError returns
77  * ERROR_INVALID_PARAMETER."
78  */
80 
81  /* Use the console input CP for the conversion */
82  // *TargetLength = WideCharToMultiByte(Console->InputCodePage, 0,
83  // Source, SourceLength,
84  // NULL, 0, NULL, NULL);
85  // *Target = ConsoleAllocHeap(0, *TargetLength * sizeof(WCHAR));
86  // if (*Target == NULL) return FALSE;
87 
88  WideCharToMultiByte(Console->InputCodePage, 0,
89  Source, SourceLength,
90  /* * */Target, /* * */TargetLength,
91  NULL, NULL);
92 
93  // /* The returned Length was in number of WCHARs, convert it in bytes */
94  // *TargetLength *= sizeof(WCHAR);
95 
96  return TRUE;
97 }
#define TRUE
Definition: types.h:120
#define WideCharToMultiByte
Definition: compat.h:101
uint32_t ULONG_PTR
Definition: typedefs.h:64
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1068
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CConsole Console
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167

Referenced by CSR_API().

◆ CSR_API() [1/7]

CSR_API ( SrvGetConsoleCommandHistory  )

Definition at line 330 of file history.c.

331 {
333  PCONSOLE_GETCOMMANDHISTORY GetCommandHistoryRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCommandHistoryRequest;
335  ULONG BytesWritten = 0;
336  PHISTORY_BUFFER Hist;
337 
338  DPRINT1("SrvGetConsoleCommandHistory entered\n");
339 
340  if ( !CsrValidateMessageBuffer(ApiMessage,
341  (PVOID*)&GetCommandHistoryRequest->History,
342  GetCommandHistoryRequest->HistoryLength,
343  sizeof(BYTE)) ||
344  !CsrValidateMessageBuffer(ApiMessage,
345  (PVOID*)&GetCommandHistoryRequest->ExeName,
346  GetCommandHistoryRequest->ExeLength,
347  sizeof(BYTE)) )
348  {
350  }
351 
353  &Console, TRUE);
354  if (!NT_SUCCESS(Status)) return Status;
355 
356  Hist = HistoryFindBuffer(Console,
357  GetCommandHistoryRequest->ExeName,
358  GetCommandHistoryRequest->ExeLength,
359  GetCommandHistoryRequest->Unicode2);
360  if (Hist)
361  {
362  ULONG i;
363 
364  LPSTR TargetBufferA;
365  LPWSTR TargetBufferW;
366  ULONG BufferSize = GetCommandHistoryRequest->HistoryLength;
367 
368  ULONG Offset = 0;
369  ULONG SourceLength;
370 
371  if (GetCommandHistoryRequest->Unicode)
372  {
373  TargetBufferW = GetCommandHistoryRequest->History;
374  BufferSize /= sizeof(WCHAR);
375  }
376  else
377  {
378  TargetBufferA = GetCommandHistoryRequest->History;
379  }
380 
381  for (i = 0; i < Hist->NumEntries; i++)
382  {
383  SourceLength = Hist->Entries[i].Length / sizeof(WCHAR);
384  if (Offset + SourceLength + 1 > BufferSize)
385  {
387  break;
388  }
389 
390  if (GetCommandHistoryRequest->Unicode)
391  {
392  RtlCopyMemory(&TargetBufferW[Offset], Hist->Entries[i].Buffer, SourceLength * sizeof(WCHAR));
393  Offset += SourceLength;
394  TargetBufferW[Offset++] = L'\0';
395  }
396  else
397  {
399  Hist->Entries[i].Buffer, SourceLength * sizeof(WCHAR),
400  &TargetBufferA[Offset], SourceLength);
401  Offset += SourceLength;
402  TargetBufferA[Offset++] = '\0';
403  }
404  }
405 
406  if (GetCommandHistoryRequest->Unicode)
407  BytesWritten = Offset * sizeof(WCHAR);
408  else
410  }
411 
412  // GetCommandHistoryRequest->HistoryLength = TargetBuffer - (PBYTE)GetCommandHistoryRequest->History;
413  GetCommandHistoryRequest->HistoryLength = BytesWritten;
414 
416  return Status;
417 }
NTSTATUS ConSrvGetConsole(IN PCONSOLE_PROCESS_DATA ProcessData, OUT PCONSRV_CONSOLE *Console, IN BOOLEAN LockConsole)
Definition: console.c:271
#define CsrGetClientThread()
Definition: csrsrv.h:77
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
static PHISTORY_BUFFER HistoryFindBuffer(PCONSRV_CONSOLE Console, PVOID ExeName, USHORT ExeLength, BOOLEAN UnicodeExe)
Definition: history.c:79
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
ULONG NumEntries
Definition: history.c:22
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1315
#define PCONSRV_CONSOLE
Definition: conio.h:27
char * LPSTR
Definition: xmlstorage.h:182
VOID ConSrvReleaseConsole(IN PCONSRV_CONSOLE Console, IN BOOLEAN IsConsoleLocked)
Definition: console.c:296
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
PUNICODE_STRING Entries
Definition: history.c:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ConsoleGetPerProcessData(Process)
Definition: consrv.h:37
#define BufferSize
Definition: classpnp.h:419
static const WCHAR L[]
Definition: oid.c:1250
unsigned char BYTE
Definition: mem.h:68
BOOLEAN ConvertInputUnicodeToAnsi(PCONSRV_CONSOLE Console, PVOID Source, USHORT SourceLength, PCHAR Target, USHORT TargetLength)
Definition: alias.c:64
Status
Definition: gdiplustypes.h:24
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
CConsole Console
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ CSR_API() [2/7]

CSR_API ( SrvGetConsoleCommandHistoryLength  )

Definition at line 420 of file history.c.

421 {
423  PCONSOLE_GETCOMMANDHISTORYLENGTH GetCommandHistoryLengthRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCommandHistoryLengthRequest;
425  PHISTORY_BUFFER Hist;
426  ULONG Length = 0;
427 
428  if (!CsrValidateMessageBuffer(ApiMessage,
429  (PVOID*)&GetCommandHistoryLengthRequest->ExeName,
430  GetCommandHistoryLengthRequest->ExeLength,
431  sizeof(BYTE)))
432  {
434  }
435 
437  &Console, TRUE);
438  if (!NT_SUCCESS(Status)) return Status;
439 
440  Hist = HistoryFindBuffer(Console,
441  GetCommandHistoryLengthRequest->ExeName,
442  GetCommandHistoryLengthRequest->ExeLength,
443  GetCommandHistoryLengthRequest->Unicode2);
444  if (Hist)
445  {
446  ULONG i;
447  for (i = 0; i < Hist->NumEntries; i++)
448  Length += Hist->Entries[i].Length + sizeof(WCHAR); // Each entry is returned NULL-terminated
449  }
450  /*
451  * Quick and dirty way of getting the number of bytes of the
452  * corresponding ANSI string from the one in UNICODE.
453  */
454  if (!GetCommandHistoryLengthRequest->Unicode)
455  Length /= sizeof(WCHAR);
456 
457  GetCommandHistoryLengthRequest->HistoryLength = Length;
458 
460  return Status;
461 }
NTSTATUS ConSrvGetConsole(IN PCONSOLE_PROCESS_DATA ProcessData, OUT PCONSRV_CONSOLE *Console, IN BOOLEAN LockConsole)
Definition: console.c:271
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define TRUE
Definition: types.h:120
static PHISTORY_BUFFER HistoryFindBuffer(PCONSRV_CONSOLE Console, PVOID ExeName, USHORT ExeLength, BOOLEAN UnicodeExe)
Definition: history.c:79
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
ULONG NumEntries
Definition: history.c:22
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1315
#define PCONSRV_CONSOLE
Definition: conio.h:27
VOID ConSrvReleaseConsole(IN PCONSRV_CONSOLE Console, IN BOOLEAN IsConsoleLocked)
Definition: console.c:296
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PUNICODE_STRING Entries
Definition: history.c:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ConsoleGetPerProcessData(Process)
Definition: consrv.h:37
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned char BYTE
Definition: mem.h:68
Status
Definition: gdiplustypes.h:24
CConsole Console
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1

◆ CSR_API() [3/7]

CSR_API ( SrvExpungeConsoleCommandHistory  )

Definition at line 464 of file history.c.

465 {
467  PCONSOLE_EXPUNGECOMMANDHISTORY ExpungeCommandHistoryRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ExpungeCommandHistoryRequest;
469  PHISTORY_BUFFER Hist;
470 
471  if (!CsrValidateMessageBuffer(ApiMessage,
472  (PVOID*)&ExpungeCommandHistoryRequest->ExeName,
473  ExpungeCommandHistoryRequest->ExeLength,
474  sizeof(BYTE)))
475  {
477  }
478 
480  &Console, TRUE);
481  if (!NT_SUCCESS(Status)) return Status;
482 
483  Hist = HistoryFindBuffer(Console,
484  ExpungeCommandHistoryRequest->ExeName,
485  ExpungeCommandHistoryRequest->ExeLength,
486  ExpungeCommandHistoryRequest->Unicode2);
487  HistoryDeleteBuffer(Hist);
488 
490  return Status;
491 }
NTSTATUS ConSrvGetConsole(IN PCONSOLE_PROCESS_DATA ProcessData, OUT PCONSRV_CONSOLE *Console, IN BOOLEAN LockConsole)
Definition: console.c:271
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define TRUE
Definition: types.h:120
static PHISTORY_BUFFER HistoryFindBuffer(PCONSRV_CONSOLE Console, PVOID ExeName, USHORT ExeLength, BOOLEAN UnicodeExe)
Definition: history.c:79
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1315
#define PCONSRV_CONSOLE
Definition: conio.h:27
VOID ConSrvReleaseConsole(IN PCONSRV_CONSOLE Console, IN BOOLEAN IsConsoleLocked)
Definition: console.c:296
static VOID HistoryDeleteBuffer(PHISTORY_BUFFER Hist)
Definition: history.c:128
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ConsoleGetPerProcessData(Process)
Definition: consrv.h:37
unsigned char BYTE
Definition: mem.h:68
Status
Definition: gdiplustypes.h:24
CConsole Console
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

◆ CSR_API() [4/7]

CSR_API ( SrvSetConsoleNumberOfCommands  )

Definition at line 494 of file history.c.

495 {
497  PCONSOLE_SETHISTORYNUMBERCOMMANDS SetHistoryNumberCommandsRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetHistoryNumberCommandsRequest;
499  PHISTORY_BUFFER Hist;
500 
501  if (!CsrValidateMessageBuffer(ApiMessage,
502  (PVOID*)&SetHistoryNumberCommandsRequest->ExeName,
503  SetHistoryNumberCommandsRequest->ExeLength,
504  sizeof(BYTE)))
505  {
507  }
508 
510  &Console, TRUE);
511  if (!NT_SUCCESS(Status)) return Status;
512 
513  Hist = HistoryFindBuffer(Console,
514  SetHistoryNumberCommandsRequest->ExeName,
515  SetHistoryNumberCommandsRequest->ExeLength,
516  SetHistoryNumberCommandsRequest->Unicode2);
517  if (Hist)
518  {
519  ULONG MaxEntries = SetHistoryNumberCommandsRequest->NumCommands;
520  PUNICODE_STRING OldEntryList = Hist->Entries;
521  PUNICODE_STRING NewEntryList = ConsoleAllocHeap(0, MaxEntries * sizeof(UNICODE_STRING));
522  if (!NewEntryList)
523  {
525  }
526  else
527  {
528  /* If necessary, shrink by removing oldest entries */
529  for (; Hist->NumEntries > MaxEntries; Hist->NumEntries--)
530  {
531  RtlFreeUnicodeString(Hist->Entries++);
532  Hist->Position += (Hist->Position == 0);
533  }
534 
535  Hist->MaxEntries = MaxEntries;
536  Hist->Entries = memcpy(NewEntryList, Hist->Entries,
537  Hist->NumEntries * sizeof(UNICODE_STRING));
538  ConsoleFreeHeap(OldEntryList);
539  }
540  }
541 
543  return Status;
544 }
NTSTATUS ConSrvGetConsole(IN PCONSOLE_PROCESS_DATA ProcessData, OUT PCONSRV_CONSOLE *Console, IN BOOLEAN LockConsole)
Definition: console.c:271
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define TRUE
Definition: types.h:120
static PHISTORY_BUFFER HistoryFindBuffer(PCONSRV_CONSOLE Console, PVOID ExeName, USHORT ExeLength, BOOLEAN UnicodeExe)
Definition: history.c:79
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
ULONG NumEntries
Definition: history.c:22
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1315
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
#define PCONSRV_CONSOLE
Definition: conio.h:27
VOID ConSrvReleaseConsole(IN PCONSRV_CONSOLE Console, IN BOOLEAN IsConsoleLocked)
Definition: console.c:296
ULONG MaxEntries
Definition: history.c:21
PUNICODE_STRING Entries
Definition: history.c:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ConsoleGetPerProcessData(Process)
Definition: consrv.h:37
ULONG Position
Definition: history.c:20
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
Status
Definition: gdiplustypes.h:24
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
CConsole Console
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1

◆ CSR_API() [5/7]

CSR_API ( SrvGetConsoleHistory  )

Definition at line 547 of file history.c.

548 {
549 #if 0 // Vista+
550  PCONSOLE_GETSETHISTORYINFO HistoryInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HistoryInfoRequest;
553  &Console, TRUE);
554  if (NT_SUCCESS(Status))
555  {
556  HistoryInfoRequest->HistoryBufferSize = Console->HistoryBufferSize;
557  HistoryInfoRequest->NumberOfHistoryBuffers = Console->NumberOfHistoryBuffers;
558  HistoryInfoRequest->dwFlags = (Console->HistoryNoDup ? HISTORY_NO_DUP_FLAG : 0);
560  }
561  return Status;
562 #else
563  DPRINT1("%s not yet implemented\n", __FUNCTION__);
564  return STATUS_NOT_IMPLEMENTED;
565 #endif
566 }
NTSTATUS ConSrvGetConsole(IN PCONSOLE_PROCESS_DATA ProcessData, OUT PCONSRV_CONSOLE *Console, IN BOOLEAN LockConsole)
Definition: console.c:271
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define TRUE
Definition: types.h:120
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
LONG NTSTATUS
Definition: precomp.h:26
#define PCONSRV_CONSOLE
Definition: conio.h:27
VOID ConSrvReleaseConsole(IN PCONSRV_CONSOLE Console, IN BOOLEAN IsConsoleLocked)
Definition: console.c:296
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ConsoleGetPerProcessData(Process)
Definition: consrv.h:37
Status
Definition: gdiplustypes.h:24
#define HISTORY_NO_DUP_FLAG
Definition: wincon.h:113
CConsole Console
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define __FUNCTION__
Definition: types.h:112

◆ CSR_API() [6/7]

CSR_API ( SrvSetConsoleHistory  )

Definition at line 569 of file history.c.

570 {
571 #if 0 // Vista+
572  PCONSOLE_GETSETHISTORYINFO HistoryInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HistoryInfoRequest;
575  &Console, TRUE);
576  if (NT_SUCCESS(Status))
577  {
578  Console->HistoryBufferSize = HistoryInfoRequest->HistoryBufferSize;
579  Console->NumberOfHistoryBuffers = HistoryInfoRequest->NumberOfHistoryBuffers;
580  Console->HistoryNoDup = !!(HistoryInfoRequest->dwFlags & HISTORY_NO_DUP_FLAG);
582  }
583  return Status;
584 #else
585  DPRINT1("%s not yet implemented\n", __FUNCTION__);
586  return STATUS_NOT_IMPLEMENTED;
587 #endif
588 }
NTSTATUS ConSrvGetConsole(IN PCONSOLE_PROCESS_DATA ProcessData, OUT PCONSRV_CONSOLE *Console, IN BOOLEAN LockConsole)
Definition: console.c:271
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define TRUE
Definition: types.h:120
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
LONG NTSTATUS
Definition: precomp.h:26
#define PCONSRV_CONSOLE
Definition: conio.h:27
VOID ConSrvReleaseConsole(IN PCONSRV_CONSOLE Console, IN BOOLEAN IsConsoleLocked)
Definition: console.c:296
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ConsoleGetPerProcessData(Process)
Definition: consrv.h:37
Status
Definition: gdiplustypes.h:24
#define HISTORY_NO_DUP_FLAG
Definition: wincon.h:113
CConsole Console
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define __FUNCTION__
Definition: types.h:112

◆ CSR_API() [7/7]

CSR_API ( SrvSetConsoleCommandHistoryMode  )

Definition at line 591 of file history.c.

592 {
594  PCONSOLE_SETHISTORYMODE SetHistoryModeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetHistoryModeRequest;
596 
597  DPRINT("SrvSetConsoleCommandHistoryMode(Mode = %d) is not yet implemented\n",
598  SetHistoryModeRequest->Mode);
599 
601  &Console, TRUE);
602  if (!NT_SUCCESS(Status)) return Status;
603 
604  Console->InsertMode = !!(SetHistoryModeRequest->Mode & CONSOLE_OVERSTRIKE);
605 
607  return STATUS_SUCCESS;
608 }
NTSTATUS ConSrvGetConsole(IN PCONSOLE_PROCESS_DATA ProcessData, OUT PCONSRV_CONSOLE *Console, IN BOOLEAN LockConsole)
Definition: console.c:271
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define TRUE
Definition: types.h:120
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
LONG NTSTATUS
Definition: precomp.h:26
#define PCONSRV_CONSOLE
Definition: conio.h:27
VOID ConSrvReleaseConsole(IN PCONSRV_CONSOLE Console, IN BOOLEAN IsConsoleLocked)
Definition: console.c:296
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ConsoleGetPerProcessData(Process)
Definition: consrv.h:37
#define CONSOLE_OVERSTRIKE
Definition: wincon.h:115
Status
Definition: gdiplustypes.h:24
CConsole Console
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ HistoryAddEntry()

VOID HistoryAddEntry ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName,
PUNICODE_STRING  Entry 
)

Definition at line 141 of file history.c.

144 {
145  // UNICODE_STRING NewEntry;
147 
148  if (!Hist) return;
149 
150  // NewEntry.Length = NewEntry.MaximumLength = Console->LineSize * sizeof(WCHAR);
151  // NewEntry.Buffer = Console->LineBuffer;
152 
153  /* Don't add blank or duplicate entries */
154  if (Entry->Length == 0 || Hist->MaxEntries == 0 ||
155  (Hist->NumEntries > 0 &&
156  RtlEqualUnicodeString(&Hist->Entries[Hist->NumEntries - 1], Entry, FALSE)))
157  {
158  return;
159  }
160 
161  if (Console->HistoryNoDup)
162  {
163  INT i;
164 
165  /* Check if this line has been entered before */
166  for (i = Hist->NumEntries - 1; i >= 0; i--)
167  {
168  if (RtlEqualUnicodeString(&Hist->Entries[i], Entry, FALSE))
169  {
170  UNICODE_STRING NewEntry;
171 
172  /* Just rotate the list to bring this entry to the end */
173  NewEntry = Hist->Entries[i];
174  memmove(&Hist->Entries[i], &Hist->Entries[i + 1],
175  (Hist->NumEntries - (i + 1)) * sizeof(UNICODE_STRING));
176  Hist->Entries[Hist->NumEntries - 1] = NewEntry;
177  Hist->Position = Hist->NumEntries - 1;
178  return;
179  }
180  }
181  }
182 
183  if (Hist->NumEntries == Hist->MaxEntries)
184  {
185  /* List is full, remove oldest entry */
186  RtlFreeUnicodeString(&Hist->Entries[0]);
187  memmove(&Hist->Entries[0], &Hist->Entries[1],
188  --Hist->NumEntries * sizeof(UNICODE_STRING));
189  }
190 
192  Hist->NumEntries++;
193  Hist->Position = Hist->NumEntries - 1;
194 }
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
ULONG NumEntries
Definition: history.c:22
int32_t INT
Definition: typedefs.h:57
ULONG MaxEntries
Definition: history.c:21
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PUNICODE_STRING Entries
Definition: history.c:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI NTSTATUS WINAPI RtlDuplicateUnicodeString(int, const UNICODE_STRING *, UNICODE_STRING *)
ULONG Position
Definition: history.c:20
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
CConsole Console
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
static PHISTORY_BUFFER HistoryCurrentBuffer(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
Definition: history.c:47
base of all file and directory entries
Definition: entries.h:82

Referenced by LineInputKeyDown().

◆ HistoryCurrentBuffer()

static PHISTORY_BUFFER HistoryCurrentBuffer ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName 
)
static

Definition at line 47 of file history.c.

49 {
50  PLIST_ENTRY Entry = Console->HistoryBuffers.Flink;
51  PHISTORY_BUFFER Hist;
52 
53  for (; Entry != &Console->HistoryBuffers; Entry = Entry->Flink)
54  {
55  Hist = CONTAINING_RECORD(Entry, HISTORY_BUFFER, ListEntry);
56  if (RtlEqualUnicodeString(ExeName, &Hist->ExeName, FALSE))
57  return Hist;
58  }
59 
60  /* Couldn't find the buffer, create a new one */
61  Hist = ConsoleAllocHeap(0, sizeof(HISTORY_BUFFER) + ExeName->Length);
62  if (!Hist) return NULL;
63  Hist->MaxEntries = Console->HistoryBufferSize;
64  Hist->NumEntries = 0;
65  Hist->Entries = ConsoleAllocHeap(0, Hist->MaxEntries * sizeof(UNICODE_STRING));
66  if (!Hist->Entries)
67  {
68  ConsoleFreeHeap(Hist);
69  return NULL;
70  }
71  Hist->ExeName.Length = Hist->ExeName.MaximumLength = ExeName->Length;
72  Hist->ExeName.Buffer = (PWCHAR)(Hist + 1);
73  memcpy(Hist->ExeName.Buffer, ExeName->Buffer, ExeName->Length);
74  InsertHeadList(&Console->HistoryBuffers, &Hist->ListEntry);
75  return Hist;
76 }
UNICODE_STRING ExeName
Definition: history.c:23
USHORT MaximumLength
Definition: env_spec_w32.h:370
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
ULONG NumEntries
Definition: history.c:22
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
uint16_t * PWCHAR
Definition: typedefs.h:55
ULONG MaxEntries
Definition: history.c:21
smooth NULL
Definition: ftsmooth.c:416
LIST_ENTRY ListEntry
Definition: history.c:19
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
PUNICODE_STRING Entries
Definition: history.c:24
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: typedefs.h:118
CConsole Console
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
base of all file and directory entries
Definition: entries.h:82

Referenced by HistoryAddEntry(), HistoryDeleteCurrentBuffer(), HistoryDisplayCurrentHistory(), HistoryFindEntryByPrefix(), HistoryGetCurrentEntry(), and HistoryRecallHistory().

◆ HistoryDeleteBuffer()

static VOID HistoryDeleteBuffer ( PHISTORY_BUFFER  Hist)
static

Definition at line 128 of file history.c.

129 {
130  if (!Hist) return;
131 
132  while (Hist->NumEntries != 0)
133  RtlFreeUnicodeString(&Hist->Entries[--Hist->NumEntries]);
134 
135  ConsoleFreeHeap(Hist->Entries);
136  RemoveEntryList(&Hist->ListEntry);
137  ConsoleFreeHeap(Hist);
138 }
ULONG NumEntries
Definition: history.c:22
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
LIST_ENTRY ListEntry
Definition: history.c:19
PUNICODE_STRING Entries
Definition: history.c:24
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15

Referenced by CSR_API(), HistoryDeleteBuffers(), and HistoryDeleteCurrentBuffer().

◆ HistoryDeleteBuffers()

VOID HistoryDeleteBuffers ( PCONSRV_CONSOLE  Console)

Definition at line 313 of file history.c.

314 {
315  PLIST_ENTRY CurrentEntry;
316  PHISTORY_BUFFER HistoryBuffer;
317 
318  while (!IsListEmpty(&Console->HistoryBuffers))
319  {
320  CurrentEntry = RemoveHeadList(&Console->HistoryBuffers);
321  HistoryBuffer = CONTAINING_RECORD(CurrentEntry, HISTORY_BUFFER, ListEntry);
322  HistoryDeleteBuffer(HistoryBuffer);
323  }
324 }
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static VOID HistoryDeleteBuffer(PHISTORY_BUFFER Hist)
Definition: history.c:128
Definition: typedefs.h:118
CConsole Console

Referenced by ConDrvDeleteConsole(), and ConSrvDeleteConsole().

◆ HistoryDeleteCurrentBuffer()

VOID HistoryDeleteCurrentBuffer ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName 
)

Definition at line 306 of file history.c.

308 {
310 }
static VOID HistoryDeleteBuffer(PHISTORY_BUFFER Hist)
Definition: history.c:128
CConsole Console
static PHISTORY_BUFFER HistoryCurrentBuffer(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
Definition: history.c:47

Referenced by LineInputKeyDown().

◆ HistoryDisplayCurrentHistory()

PPOPUP_WINDOW HistoryDisplayCurrentHistory ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName 
)

Definition at line 271 of file history.c.

273 {
274  PCONSOLE_SCREEN_BUFFER ActiveBuffer;
276 
277  SHORT xLeft, yTop;
278  SHORT Width, Height;
279 
281 
282  if (!Hist) return NULL;
283  if (Hist->NumEntries == 0) return NULL;
284 
285  if (GetType(Console->ActiveBuffer) != TEXTMODE_BUFFER) return NULL;
286  ActiveBuffer = Console->ActiveBuffer;
287 
288  Width = 40;
289  Height = 10;
290 
291  /* Center the popup window on the screen */
292  xLeft = ActiveBuffer->ViewOrigin.X + (ActiveBuffer->ViewSize.X - Width ) / 2;
293  yTop = ActiveBuffer->ViewOrigin.Y + (ActiveBuffer->ViewSize.Y - Height) / 2;
294 
295  /* Create the popup */
296  Popup = CreatePopupWindow(Console, ActiveBuffer,
297  xLeft, yTop, Width, Height);
298  if (Popup == NULL) return NULL;
299 
300  Popup->PopupInputRoutine = NULL;
301 
302  return Popup;
303 }
ULONG NumEntries
Definition: history.c:22
#define TEXTMODE_BUFFER
Definition: pccons.c:21
short SHORT
Definition: pedump.c:59
smooth NULL
Definition: ftsmooth.c:416
ULONG X
Definition: bl.h:1340
INT GetType(BOOL bLocal, LPOSVERSIONINFOEX osvi, LPSERVER_INFO_102 pBuf102)
Definition: gettype.c:129
Definition: console.h:35
CConsole Console
ULONG Y
Definition: bl.h:1341
static PHISTORY_BUFFER HistoryCurrentBuffer(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
Definition: history.c:47

Referenced by LineInputKeyDown().

◆ HistoryFindBuffer()

static PHISTORY_BUFFER HistoryFindBuffer ( PCONSRV_CONSOLE  Console,
PVOID  ExeName,
USHORT  ExeLength,
BOOLEAN  UnicodeExe 
)
static

Definition at line 79 of file history.c.

83 {
84  UNICODE_STRING ExeNameU;
85 
87  PHISTORY_BUFFER Hist = NULL;
88 
89  if (ExeName == NULL) return NULL;
90 
91  if (UnicodeExe)
92  {
93  ExeNameU.Buffer = ExeName;
94  /* Length is in bytes */
95  ExeNameU.MaximumLength = ExeLength;
96  }
97  else
98  {
100  ExeName, ExeLength,
101  &ExeNameU.Buffer, &ExeNameU.MaximumLength))
102  {
103  return NULL;
104  }
105  }
106  ExeNameU.Length = ExeNameU.MaximumLength;
107 
108  Entry = Console->HistoryBuffers.Flink;
109  while (Entry != &Console->HistoryBuffers)
110  {
111  Hist = CONTAINING_RECORD(Entry, HISTORY_BUFFER, ListEntry);
112 
113  /* For the history APIs, the caller is allowed to give only part of the name */
114  if (RtlPrefixUnicodeString(&ExeNameU, &Hist->ExeName, TRUE))
115  {
116  if (!UnicodeExe) ConsoleFreeHeap(ExeNameU.Buffer);
117  return Hist;
118  }
119 
120  Entry = Entry->Flink;
121  }
122 
123  if (!UnicodeExe) ConsoleFreeHeap(ExeNameU.Buffer);
124  return NULL;
125 }
#define TRUE
Definition: types.h:120
UNICODE_STRING ExeName
Definition: history.c:23
struct _Entry Entry
Definition: kefuncs.h:627
USHORT MaximumLength
Definition: env_spec_w32.h:370
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
BOOLEAN ConvertInputAnsiToUnicode(PCONSRV_CONSOLE Console, PVOID Source, USHORT SourceLength, PWCHAR *Target, PUSHORT TargetLength)
Definition: alias.c:37
Definition: typedefs.h:118
NTSYSAPI BOOLEAN NTAPI RtlPrefixUnicodeString(IN PUNICODE_STRING String1, IN PUNICODE_STRING String2, IN BOOLEAN CaseInSensitive)
CConsole Console
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
base of all file and directory entries
Definition: entries.h:82

Referenced by CSR_API().

◆ HistoryFindEntryByPrefix()

BOOL HistoryFindEntryByPrefix ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName,
PUNICODE_STRING  Prefix,
PUNICODE_STRING  Entry 
)

Definition at line 229 of file history.c.

233 {
234  INT HistPos;
235 
236  /* Search for history entries starting with input. */
238  if (!Hist || Hist->NumEntries == 0) return FALSE;
239 
240  /*
241  * Like Up/F5, on first time start from current (usually last) entry,
242  * but on subsequent times start at previous entry.
243  */
244  if (Console->LineUpPressed)
245  Hist->Position = (Hist->Position ? Hist->Position : Hist->NumEntries) - 1;
246  Console->LineUpPressed = TRUE;
247 
248  // Entry.Length = Console->LinePos * sizeof(WCHAR); // == Pos * sizeof(WCHAR)
249  // Entry.Buffer = Console->LineBuffer;
250 
251  /*
252  * Keep going backwards, even wrapping around to the end,
253  * until we get back to starting point.
254  */
255  HistPos = Hist->Position;
256  do
257  {
258  if (RtlPrefixUnicodeString(Prefix, &Hist->Entries[HistPos], FALSE))
259  {
260  Hist->Position = HistPos;
261  *Entry = Hist->Entries[HistPos];
262  return TRUE;
263  }
264  if (--HistPos < 0) HistPos += Hist->NumEntries;
265  } while (HistPos != Hist->Position);
266 
267  return FALSE;
268 }
#define TRUE
Definition: types.h:120
_In_ __drv_aliasesMem PSTRING Prefix
Definition: rtlfuncs.h:1631
ULONG NumEntries
Definition: history.c:22
int32_t INT
Definition: typedefs.h:57
PUNICODE_STRING Entries
Definition: history.c:24
ULONG Position
Definition: history.c:20
NTSYSAPI BOOLEAN NTAPI RtlPrefixUnicodeString(IN PUNICODE_STRING String1, IN PUNICODE_STRING String2, IN BOOLEAN CaseInSensitive)
CConsole Console
static PHISTORY_BUFFER HistoryCurrentBuffer(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
Definition: history.c:47
base of all file and directory entries
Definition: entries.h:82

Referenced by LineInputKeyDown().

◆ HistoryGetCurrentEntry()

VOID HistoryGetCurrentEntry ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName,
PUNICODE_STRING  Entry 
)

Definition at line 197 of file history.c.

200 {
202 
203  if (!Hist || Hist->NumEntries == 0)
204  Entry->Length = 0;
205  else
206  *Entry = Hist->Entries[Hist->Position];
207 }
ULONG NumEntries
Definition: history.c:22
PUNICODE_STRING Entries
Definition: history.c:24
ULONG Position
Definition: history.c:20
CConsole Console
static PHISTORY_BUFFER HistoryCurrentBuffer(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
Definition: history.c:47
base of all file and directory entries
Definition: entries.h:82

Referenced by LineInputKeyDown().

◆ HistoryRecallHistory()

BOOL HistoryRecallHistory ( PCONSRV_CONSOLE  Console,
PUNICODE_STRING  ExeName,
INT  Offset,
PUNICODE_STRING  Entry 
)

Definition at line 210 of file history.c.

214 {
216  ULONG Position = 0;
217 
218  if (!Hist || Hist->NumEntries == 0) return FALSE;
219 
220  Position = Hist->Position + Offset;
221  Position = min(max(Position, 0), Hist->NumEntries - 1);
222  Hist->Position = Position;
223 
224  *Entry = Hist->Entries[Hist->Position];
225  return TRUE;
226 }
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
ULONG NumEntries
Definition: history.c:22
static COORD Position
Definition: mouse.c:34
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
PUNICODE_STRING Entries
Definition: history.c:24
ULONG Position
Definition: history.c:20
#define min(a, b)
Definition: monoChain.cc:55
CConsole Console
unsigned int ULONG
Definition: retypes.h:1
static PHISTORY_BUFFER HistoryCurrentBuffer(PCONSRV_CONSOLE Console, PUNICODE_STRING ExeName)
Definition: history.c:47
base of all file and directory entries
Definition: entries.h:82

Referenced by LineInputRecallHistory().