[CONSRV]
[reactos.git] / win32ss / user / consrv / lineinput.c
index 075b365..536ce77 100644 (file)
@@ -14,7 +14,7 @@
 #define NDEBUG
 #include <debug.h>
 
-typedef struct tagHISTORY_BUFFER
+typedef struct _HISTORY_BUFFER
 {
     LIST_ENTRY ListEntry;
     UINT Position;
@@ -27,7 +27,7 @@ typedef struct tagHISTORY_BUFFER
 /* FUNCTIONS *****************************************************************/
 
 static PHISTORY_BUFFER
-HistoryCurrentBuffer(PCSRSS_CONSOLE Console)
+HistoryCurrentBuffer(PCONSOLE Console)
 {
     /* TODO: use actual EXE name sent from process that called ReadConsole */
     UNICODE_STRING ExeName = { 14, 14, L"cmd.exe" };
@@ -61,7 +61,7 @@ HistoryCurrentBuffer(PCSRSS_CONSOLE Console)
 }
 
 static VOID
-HistoryAddEntry(PCSRSS_CONSOLE Console)
+HistoryAddEntry(PCONSOLE Console)
 {
     UNICODE_STRING NewEntry;
     PHISTORY_BUFFER Hist;
@@ -113,7 +113,7 @@ HistoryAddEntry(PCSRSS_CONSOLE Console)
 }
 
 static VOID
-HistoryGetCurrentEntry(PCSRSS_CONSOLE Console, PUNICODE_STRING Entry)
+HistoryGetCurrentEntry(PCONSOLE Console, PUNICODE_STRING Entry)
 {
     PHISTORY_BUFFER Hist;
     if (!(Hist = HistoryCurrentBuffer(Console)) || Hist->NumEntries == 0)
@@ -123,7 +123,7 @@ HistoryGetCurrentEntry(PCSRSS_CONSOLE Console, PUNICODE_STRING Entry)
 }
 
 static PHISTORY_BUFFER
-HistoryFindBuffer(PCSRSS_CONSOLE Console, PUNICODE_STRING ExeName)
+HistoryFindBuffer(PCONSOLE Console, PUNICODE_STRING ExeName)
 {
     PLIST_ENTRY Entry = Console->HistoryBuffers.Flink;
     while (Entry != &Console->HistoryBuffers)
@@ -151,40 +151,32 @@ HistoryDeleteBuffer(PHISTORY_BUFFER Hist)
 
 CSR_API(SrvGetConsoleCommandHistoryLength)
 {
-    PCSRSS_GET_COMMAND_HISTORY_LENGTH GetCommandHistoryLength = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCommandHistoryLength;
+    PCONSOLE_GETCOMMANDHISTORYLENGTH GetCommandHistoryLengthRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCommandHistoryLengthRequest;
     PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
-    PCSRSS_CONSOLE Console;
+    PCONSOLE Console;
     NTSTATUS Status;
     PHISTORY_BUFFER Hist;
     ULONG Length = 0;
     INT i;
 
     if (!CsrValidateMessageBuffer(ApiMessage,
-                                  (PVOID*)&GetCommandHistoryLength->ExeName.Buffer,
-                                  GetCommandHistoryLength->ExeName.Length,
+                                  (PVOID*)&GetCommandHistoryLengthRequest->ExeName.Buffer,
+                                  GetCommandHistoryLengthRequest->ExeName.Length,
                                   sizeof(BYTE)))
     {
         return STATUS_INVALID_PARAMETER;
     }
-/*
-    if (!Win32CsrValidateBuffer(ProcessData->Process,
-                                GetCommandHistoryLength->ExeName.Buffer,
-                                GetCommandHistoryLength->ExeName.Length, 1))
-    {
-        return STATUS_ACCESS_VIOLATION;
-    }
-*/
 
     Status = ConioConsoleFromProcessData(ProcessData, &Console);
     if (NT_SUCCESS(Status))
     {
-        Hist = HistoryFindBuffer(Console, &GetCommandHistoryLength->ExeName);
+        Hist = HistoryFindBuffer(Console, &GetCommandHistoryLengthRequest->ExeName);
         if (Hist)
         {
             for (i = 0; i < Hist->NumEntries; i++)
                 Length += Hist->Entries[i].Length + sizeof(WCHAR);
         }
-        GetCommandHistoryLength->Length = Length;
+        GetCommandHistoryLengthRequest->Length = Length;
         ConioUnlockConsole(Console);
     }
     return Status;
@@ -192,40 +184,31 @@ CSR_API(SrvGetConsoleCommandHistoryLength)
 
 CSR_API(SrvGetConsoleCommandHistory)
 {
-    PCSRSS_GET_COMMAND_HISTORY GetCommandHistory = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCommandHistory;
+    PCONSOLE_GETCOMMANDHISTORY GetCommandHistoryRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCommandHistoryRequest;
     PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
-    PCSRSS_CONSOLE Console;
+    PCONSOLE Console;
     NTSTATUS Status;
     PHISTORY_BUFFER Hist;
-    PBYTE Buffer = (PBYTE)GetCommandHistory->History;
-    ULONG BufferSize = GetCommandHistory->Length;
+    PBYTE Buffer = (PBYTE)GetCommandHistoryRequest->History;
+    ULONG BufferSize = GetCommandHistoryRequest->Length;
     INT i;
 
     if ( !CsrValidateMessageBuffer(ApiMessage,
-                                   (PVOID*)&GetCommandHistory->History,
-                                   GetCommandHistory->Length,
+                                   (PVOID*)&GetCommandHistoryRequest->History,
+                                   GetCommandHistoryRequest->Length,
                                    sizeof(BYTE))                    ||
          !CsrValidateMessageBuffer(ApiMessage,
-                                   (PVOID*)&GetCommandHistory->ExeName.Buffer,
-                                   GetCommandHistory->ExeName.Length,
+                                   (PVOID*)&GetCommandHistoryRequest->ExeName.Buffer,
+                                   GetCommandHistoryRequest->ExeName.Length,
                                    sizeof(BYTE)) )
     {
         return STATUS_INVALID_PARAMETER;
     }
-/*
-    if (!Win32CsrValidateBuffer(ProcessData->Process, Buffer, BufferSize, 1) ||
-        !Win32CsrValidateBuffer(ProcessData->Process,
-                                GetCommandHistory->ExeName.Buffer,
-                                GetCommandHistory->ExeName.Length, 1))
-    {
-        return STATUS_ACCESS_VIOLATION;
-    }
-*/
 
     Status = ConioConsoleFromProcessData(ProcessData, &Console);
     if (NT_SUCCESS(Status))
     {
-        Hist = HistoryFindBuffer(Console, &GetCommandHistory->ExeName);
+        Hist = HistoryFindBuffer(Console, &GetCommandHistoryRequest->ExeName);
         if (Hist)
         {
             for (i = 0; i < Hist->NumEntries; i++)
@@ -241,7 +224,7 @@ CSR_API(SrvGetConsoleCommandHistory)
                 Buffer += sizeof(WCHAR);
             }
         }
-        GetCommandHistory->Length = Buffer - (PBYTE)GetCommandHistory->History;
+        GetCommandHistoryRequest->Length = Buffer - (PBYTE)GetCommandHistoryRequest->History;
         ConioUnlockConsole(Console);
     }
     return Status;
@@ -249,32 +232,24 @@ CSR_API(SrvGetConsoleCommandHistory)
 
 CSR_API(SrvExpungeConsoleCommandHistory)
 {
-    PCSRSS_EXPUNGE_COMMAND_HISTORY ExpungeCommandHistory = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ExpungeCommandHistory;
+    PCONSOLE_EXPUNGECOMMANDHISTORY ExpungeCommandHistoryRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ExpungeCommandHistoryRequest;
     PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
-    PCSRSS_CONSOLE Console;
+    PCONSOLE Console;
     PHISTORY_BUFFER Hist;
     NTSTATUS Status;
 
     if (!CsrValidateMessageBuffer(ApiMessage,
-                                  (PVOID*)&ExpungeCommandHistory->ExeName.Buffer,
-                                  ExpungeCommandHistory->ExeName.Length,
+                                  (PVOID*)&ExpungeCommandHistoryRequest->ExeName.Buffer,
+                                  ExpungeCommandHistoryRequest->ExeName.Length,
                                   sizeof(BYTE)))
     {
         return STATUS_INVALID_PARAMETER;
     }
-/*
-    if (!Win32CsrValidateBuffer(ProcessData->Process,
-                                ExpungeCommandHistory->ExeName.Buffer,
-                                ExpungeCommandHistory->ExeName.Length, 1))
-    {
-        return STATUS_ACCESS_VIOLATION;
-    }
-*/
 
     Status = ConioConsoleFromProcessData(ProcessData, &Console);
     if (NT_SUCCESS(Status))
     {
-        Hist = HistoryFindBuffer(Console, &ExpungeCommandHistory->ExeName);
+        Hist = HistoryFindBuffer(Console, &ExpungeCommandHistoryRequest->ExeName);
         HistoryDeleteBuffer(Hist);
         ConioUnlockConsole(Console);
     }
@@ -283,34 +258,26 @@ CSR_API(SrvExpungeConsoleCommandHistory)
 
 CSR_API(SrvSetConsoleNumberOfCommands)
 {
-    PCSRSS_SET_HISTORY_NUMBER_COMMANDS SetHistoryNumberCommands = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetHistoryNumberCommands;
+    PCONSOLE_SETHISTORYNUMBERCOMMANDS SetHistoryNumberCommandsRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetHistoryNumberCommandsRequest;
     PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
-    PCSRSS_CONSOLE Console;
+    PCONSOLE Console;
     PHISTORY_BUFFER Hist;
     NTSTATUS Status;
-    UINT MaxEntries = SetHistoryNumberCommands->NumCommands;
+    UINT MaxEntries = SetHistoryNumberCommandsRequest->NumCommands;
     PUNICODE_STRING OldEntryList, NewEntryList;
 
     if (!CsrValidateMessageBuffer(ApiMessage,
-                                  (PVOID*)&SetHistoryNumberCommands->ExeName.Buffer,
-                                  SetHistoryNumberCommands->ExeName.Length,
+                                  (PVOID*)&SetHistoryNumberCommandsRequest->ExeName.Buffer,
+                                  SetHistoryNumberCommandsRequest->ExeName.Length,
                                   sizeof(BYTE)))
     {
         return STATUS_INVALID_PARAMETER;
     }
-/*
-    if (!Win32CsrValidateBuffer(ProcessData->Process,
-                                SetHistoryNumberCommands->ExeName.Buffer,
-                                SetHistoryNumberCommands->ExeName.Length, 1))
-    {
-        return STATUS_ACCESS_VIOLATION;
-    }
-*/
 
     Status = ConioConsoleFromProcessData(ProcessData, &Console);
     if (NT_SUCCESS(Status))
     {
-        Hist = HistoryFindBuffer(Console, &SetHistoryNumberCommands->ExeName);
+        Hist = HistoryFindBuffer(Console, &SetHistoryNumberCommandsRequest->ExeName);
         if (Hist)
         {
             OldEntryList = Hist->Entries;
@@ -342,8 +309,8 @@ CSR_API(SrvSetConsoleNumberOfCommands)
 
 CSR_API(SrvGetConsoleHistory)
 {
-    PCSRSS_HISTORY_INFO HistoryInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HistoryInfoRequest;
-    PCSRSS_CONSOLE Console;
+    PCONSOLE_GETSETHISTORYINFO HistoryInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HistoryInfoRequest;
+    PCONSOLE Console;
     NTSTATUS Status = ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console);
     if (NT_SUCCESS(Status))
     {
@@ -357,8 +324,8 @@ CSR_API(SrvGetConsoleHistory)
 
 CSR_API(SrvSetConsoleHistory)
 {
-    PCSRSS_HISTORY_INFO HistoryInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HistoryInfoRequest;
-    PCSRSS_CONSOLE Console;
+    PCONSOLE_GETSETHISTORYINFO HistoryInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HistoryInfoRequest;
+    PCONSOLE Console;
     NTSTATUS Status = ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console);
     if (NT_SUCCESS(Status))
     {
@@ -371,11 +338,11 @@ CSR_API(SrvSetConsoleHistory)
 }
 
 static VOID
-LineInputSetPos(PCSRSS_CONSOLE Console, UINT Pos)
+LineInputSetPos(PCONSOLE Console, UINT Pos)
 {
     if (Pos != Console->LinePos && Console->Mode & ENABLE_ECHO_INPUT)
     {
-        PCSRSS_SCREEN_BUFFER Buffer = Console->ActiveBuffer;
+        PCONSOLE_SCREEN_BUFFER Buffer = Console->ActiveBuffer;
         UINT OldCursorX = Buffer->CurrentX;
         UINT OldCursorY = Buffer->CurrentY;
         INT XY = OldCursorY * Buffer->MaxX + OldCursorX;
@@ -395,7 +362,7 @@ LineInputSetPos(PCSRSS_CONSOLE Console, UINT Pos)
 }
 
 static VOID
-LineInputEdit(PCSRSS_CONSOLE Console, UINT NumToDelete, UINT NumToInsert, WCHAR *Insertion)
+LineInputEdit(PCONSOLE Console, UINT NumToDelete, UINT NumToInsert, WCHAR *Insertion)
 {
     UINT Pos = Console->LinePos;
     UINT NewSize = Console->LineSize - NumToDelete + NumToInsert;
@@ -432,7 +399,7 @@ LineInputEdit(PCSRSS_CONSOLE Console, UINT NumToDelete, UINT NumToInsert, WCHAR
 }
 
 static VOID
-LineInputRecallHistory(PCSRSS_CONSOLE Console, INT Offset)
+LineInputRecallHistory(PCONSOLE Console, INT Offset)
 {
     PHISTORY_BUFFER Hist;
 
@@ -451,7 +418,7 @@ LineInputRecallHistory(PCSRSS_CONSOLE Console, INT Offset)
 }
 
 VOID FASTCALL
-LineInputKeyDown(PCSRSS_CONSOLE Console, KEY_EVENT_RECORD *KeyEvent)
+LineInputKeyDown(PCONSOLE Console, KEY_EVENT_RECORD *KeyEvent)
 {
     UINT Pos = Console->LinePos;
     PHISTORY_BUFFER Hist;