[CSRSRV]
[reactos.git] / win32ss / user / consrv / handle.c
index 6ab3f9a..339dbb3 100644 (file)
@@ -73,7 +73,6 @@ ConSrvCloseHandleEntry(PCONSOLE_IO_HANDLE Entry)
                           WaitAll,
                           NULL,
                           (PVOID)Entry);
-
             if (!IsListEmpty(&InputBuffer->ReadWaitQueue))
             {
                 CsrDereferenceWait(&InputBuffer->ReadWaitQueue);
@@ -130,11 +129,11 @@ ConSrvInitHandlesTable(IN OUT PCONSOLE_PROCESS_DATA ProcessData,
 
     /* Insert the Input handle */
     Status = ConSrvInsertObject(ProcessData,
-                                  &InputHandle,
-                                  &ProcessData->Console->InputBuffer.Header,
-                                  GENERIC_READ | GENERIC_WRITE,
-                                  TRUE,
-                                  FILE_SHARE_READ | FILE_SHARE_WRITE);
+                                &InputHandle,
+                                &ProcessData->Console->InputBuffer.Header,
+                                GENERIC_READ | GENERIC_WRITE,
+                                TRUE,
+                                FILE_SHARE_READ | FILE_SHARE_WRITE);
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("Failed to insert the input handle\n");
@@ -145,11 +144,11 @@ ConSrvInitHandlesTable(IN OUT PCONSOLE_PROCESS_DATA ProcessData,
 
     /* Insert the Output handle */
     Status = ConSrvInsertObject(ProcessData,
-                                  &OutputHandle,
-                                  &ProcessData->Console->ActiveBuffer->Header,
-                                  GENERIC_READ | GENERIC_WRITE,
-                                  TRUE,
-                                  FILE_SHARE_READ | FILE_SHARE_WRITE);
+                                &OutputHandle,
+                                &ProcessData->Console->ActiveBuffer->Header,
+                                GENERIC_READ | GENERIC_WRITE,
+                                TRUE,
+                                FILE_SHARE_READ | FILE_SHARE_WRITE);
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("Failed to insert the output handle\n");
@@ -160,11 +159,11 @@ ConSrvInitHandlesTable(IN OUT PCONSOLE_PROCESS_DATA ProcessData,
 
     /* Insert the Error handle */
     Status = ConSrvInsertObject(ProcessData,
-                                  &ErrorHandle,
-                                  &ProcessData->Console->ActiveBuffer->Header,
-                                  GENERIC_READ | GENERIC_WRITE,
-                                  TRUE,
-                                  FILE_SHARE_READ | FILE_SHARE_WRITE);
+                                &ErrorHandle,
+                                &ProcessData->Console->ActiveBuffer->Header,
+                                GENERIC_READ | GENERIC_WRITE,
+                                TRUE,
+                                FILE_SHARE_READ | FILE_SHARE_WRITE);
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("Failed to insert the error handle\n");
@@ -374,7 +373,7 @@ ConSrvGetObject(PCONSOLE_PROCESS_DATA ProcessData,
          (HandleEntry->Access & Access) == 0 ||
          (Type != 0 && ObjectEntry->Type != Type) )
     {
-        DPRINT1("CsrGetObject returning invalid handle (%x) of type %lu with access %lu\n", Handle, Type, Access);
+        DPRINT1("ConSrvGetObject returning invalid handle (%x) of type %lu with access %lu\n", Handle, Type, Access);
         RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
         return STATUS_INVALID_HANDLE;
     }
@@ -402,16 +401,16 @@ ConSrvReleaseObject(Object_t *Object,
 NTSTATUS
 FASTCALL
 ConSrvAllocateConsole(PCONSOLE_PROCESS_DATA ProcessData,
+                      LPCWSTR AppPath,
                       PHANDLE pInputHandle,
                       PHANDLE pOutputHandle,
                       PHANDLE pErrorHandle,
-                      int ShowCmd,
-                      PCSR_PROCESS CsrProcess)
+                      PCONSOLE_START_INFO ConsoleStartInfo)
 {
     NTSTATUS Status = STATUS_SUCCESS;
 
-    /* Initialize a new Console owned by the Console Leader Process */
-    Status = ConSrvInitConsole(&ProcessData->Console, ShowCmd, CsrProcess);
+    /* Initialize a new Console owned by this process */
+    Status = ConSrvInitConsole(&ProcessData->Console, AppPath, ConsoleStartInfo, ProcessData->Process);
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("Console initialization failed\n");
@@ -524,9 +523,17 @@ ConSrvRemoveConsole(PCONSOLE_PROCESS_DATA ProcessData)
     {
         DPRINT1("ConSrvRemoveConsole - Console->ReferenceCount = %lu - We are going to decrement it !\n", Console->ReferenceCount);
         ProcessData->Console = NULL;
+
         EnterCriticalSection(&Console->Lock);
         DPRINT1("ConSrvRemoveConsole - Locking OK\n");
+
+        /* Remove ourselves from the console's list of processes */
         RemoveEntryList(&ProcessData->ConsoleLink);
+
+        /* Update the console leader process */
+        // SetConsoleWndConsoleLeaderCID(Console);
+
+        /* Release the console */
         ConSrvReleaseConsole(Console, TRUE);
         //CloseHandle(ProcessData->ConsoleEvent);
         //ProcessData->ConsoleEvent = NULL;
@@ -591,17 +598,10 @@ ConSrvNewProcess(PCSR_PROCESS SourceProcess,
 
     PCONSOLE_PROCESS_DATA SourceProcessData, TargetProcessData;
 
-    DPRINT1("ConSrvNewProcess\n");
-    DPRINT1("SourceProcess = 0x%p ; TargetProcess = 0x%p\n", SourceProcess, TargetProcess);
-
     /* An empty target process is invalid */
-    if (!TargetProcess)
-        return STATUS_INVALID_PARAMETER;
-
-    DPRINT1("ConSrvNewProcess - OK\n");
+    if (!TargetProcess) return STATUS_INVALID_PARAMETER;
 
     TargetProcessData = ConsoleGetPerProcessData(TargetProcess);
-    DPRINT1("TargetProcessData = 0x%p\n", TargetProcessData);
 
     /**** HACK !!!! ****/ RtlZeroMemory(TargetProcessData, sizeof(*TargetProcessData));
 
@@ -615,15 +615,12 @@ ConSrvNewProcess(PCSR_PROCESS SourceProcess,
     TargetProcessData->HandleTableSize = 0;
     TargetProcessData->HandleTable = NULL;
 
-    /**** HACK !!!! ****/ RtlZeroMemory(&TargetProcessData->HandleTableLock, sizeof(RTL_CRITICAL_SECTION));
     RtlInitializeCriticalSection(&TargetProcessData->HandleTableLock);
 
     /* Do nothing if the source process is NULL */
-    if (!SourceProcess)
-        return STATUS_SUCCESS;
+    if (!SourceProcess) return STATUS_SUCCESS;
 
     SourceProcessData = ConsoleGetPerProcessData(SourceProcess);
-    DPRINT1("SourceProcessData = 0x%p\n", SourceProcessData);
 
     /*
      * If both of the processes (parent and new child) are console applications,
@@ -640,10 +637,6 @@ ConSrvNewProcess(PCSR_PROCESS SourceProcess,
         /* Temporary save the parent's console */
         TargetProcessData->ParentConsole = SourceProcessData->Console;
     }
-    else
-    {
-        DPRINT1("ConSrvNewProcess - We don't inherit a handle table : SourceProcessData->Console = 0x%p ; TargetProcess->Flags = %lu\n", SourceProcessData->Console, TargetProcess->Flags);
-    }
 
     return STATUS_SUCCESS;
 }
@@ -662,8 +655,6 @@ ConSrvConnect(IN PCSR_PROCESS CsrProcess,
     PCONSOLE_CONNECTION_INFO ConnectInfo = (PCONSOLE_CONNECTION_INFO)ConnectionInfo;
     PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrProcess);
 
-    DPRINT1("ConSrvConnect\n");
-
     if ( ConnectionInfo       == NULL ||
          ConnectionInfoLength == NULL ||
         *ConnectionInfoLength != sizeof(CONSOLE_CONNECTION_INFO) )
@@ -675,7 +666,6 @@ ConSrvConnect(IN PCSR_PROCESS CsrProcess,
     /* If we don't need a console, then get out of here */
     if (!ConnectInfo->ConsoleNeeded || !ProcessData->ConsoleApp) // In fact, it is for GUI apps.
     {
-        DPRINT("ConSrvConnect - No console needed\n");
         return STATUS_SUCCESS;
     }
 
@@ -699,11 +689,11 @@ ConSrvConnect(IN PCSR_PROCESS CsrProcess,
 
         /* Initialize a new Console owned by the Console Leader Process */
         Status = ConSrvAllocateConsole(ProcessData,
+                                       ConnectInfo->AppPath,
                                        &ConnectInfo->InputHandle,
                                        &ConnectInfo->OutputHandle,
                                        &ConnectInfo->ErrorHandle,
-                                       ConnectInfo->ShowCmd,
-                                       CsrProcess);
+                                       &ConnectInfo->ConsoleStartInfo);
         if (!NT_SUCCESS(Status))
         {
             DPRINT1("Console allocation failed\n");
@@ -734,15 +724,17 @@ ConSrvConnect(IN PCSR_PROCESS CsrProcess,
     /* Input Wait Handle */
     ConnectInfo->InputWaitHandle = ProcessData->ConsoleEvent;
 
+    /* Set the Property Dialog Handler */
+    ProcessData->PropDispatcher = ConnectInfo->PropDispatcher;
+
     /* Set the Ctrl Dispatcher */
     ProcessData->CtrlDispatcher = ConnectInfo->CtrlDispatcher;
-    DPRINT("CONSRV: CtrlDispatcher address: %x\n", ProcessData->CtrlDispatcher);
 
     return STATUS_SUCCESS;
 }
 
 VOID
-WINAPI
+NTAPI
 ConSrvDisconnect(PCSR_PROCESS Process)
 {
     PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(Process);
@@ -787,7 +779,7 @@ CSR_API(SrvVerifyConsoleIoHandle)
         Index >= ProcessData->HandleTableSize ||
         ProcessData->HandleTable[Index].Object == NULL)
     {
-        DPRINT("CsrVerifyObject failed\n");
+        DPRINT("SrvVerifyConsoleIoHandle failed\n");
         Status = STATUS_INVALID_HANDLE;
     }
 
@@ -834,11 +826,11 @@ CSR_API(SrvDuplicateHandle)
     }
 
     ApiMessage->Status = ConSrvInsertObject(ProcessData,
-                                              &DuplicateHandleRequest->ConsoleHandle, // Use the new handle value!
-                                              Entry->Object,
-                                              DesiredAccess,
-                                              DuplicateHandleRequest->Inheritable,
-                                              Entry->ShareMode);
+                                            &DuplicateHandleRequest->ConsoleHandle, // Use the new handle value!
+                                            Entry->Object,
+                                            DesiredAccess,
+                                            DuplicateHandleRequest->Inheritable,
+                                            Entry->ShareMode);
     if (NT_SUCCESS(ApiMessage->Status) &&
         DuplicateHandleRequest->Options & DUPLICATE_CLOSE_SOURCE)
     {
@@ -849,16 +841,4 @@ CSR_API(SrvDuplicateHandle)
     return ApiMessage->Status;
 }
 
-/**
-CSR_API(CsrGetInputWaitHandle)
-{
-    PCSRSS_GET_INPUT_WAIT_HANDLE GetConsoleInputWaitHandle = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetConsoleInputWaitHandle;
-
-    GetConsoleInputWaitHandle->InputWaitHandle =
-        ConsoleGetPerProcessData(CsrGetClientThread()->Process)->ConsoleEvent;
-
-    return STATUS_SUCCESS;
-}
-**/
-
 /* EOF */