[CMAKE]
[reactos.git] / base / services / eventlog / rpc.c
index d399d1e..cf85575 100644 (file)
@@ -11,7 +11,7 @@
 
 #include "eventlog.h"
 
-LIST_ENTRY EventSourceListHead;
+LIST_ENTRY LogHandleListHead;
 
 /* FUNCTIONS ****************************************************************/
 
@@ -19,7 +19,7 @@ DWORD WINAPI RpcThreadRoutine(LPVOID lpParameter)
 {
     RPC_STATUS Status;
 
-    InitializeListHead(&EventSourceListHead);
+    InitializeListHead(&LogHandleListHead);
 
     Status = RpcServerUseProtseqEpW(L"ncacn_np", 20, L"\\pipe\\EventLog", NULL);
     if (Status != RPC_S_OK)
@@ -44,21 +44,24 @@ DWORD WINAPI RpcThreadRoutine(LPVOID lpParameter)
     return 0;
 }
 
-PEVENTSOURCE ElfCreateEventLogHandle(LPCWSTR Name, BOOL Create)
+PLOGHANDLE ElfCreateEventLogHandle(LPCWSTR Name, BOOL Create)
 {
-    PEVENTSOURCE lpEventSource;
+    PLOGHANDLE lpLogHandle;
     PLOGFILE currentLogFile = NULL;
     INT i, LogsActive;
+    PEVENTSOURCE pEventSource;
 
-    lpEventSource = HeapAlloc(GetProcessHeap(), 0, sizeof(EVENTSOURCE)
+    DPRINT("ElfCreateEventLogHandle(Name: %S)\n", Name);
+
+    lpLogHandle = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGHANDLE)
                                   + ((wcslen(Name) + 1) * sizeof(WCHAR)));
-    if (!lpEventSource)
+    if (!lpLogHandle)
     {
         DPRINT1("Failed to allocate Heap!\n");
         return NULL;
     }
 
-    wcscpy(lpEventSource->szName, Name);
+    wcscpy(lpLogHandle->szName, Name);
 
     /* Get the number of Log Files the EventLog service found */
     LogsActive = LogfListItemCount();
@@ -70,59 +73,77 @@ PEVENTSOURCE ElfCreateEventLogHandle(LPCWSTR Name, BOOL Create)
 
     /* If Creating, default to the Application Log in case we fail, as documented on MSDN */
     if (Create == TRUE)
-        lpEventSource->LogFile = LogfListItemByName(L"Application");
-    else
-        lpEventSource->LogFile = NULL;
+    {
+        pEventSource = GetEventSourceByName(Name);
+        DPRINT("EventSource: %p\n", pEventSource);
+        if (pEventSource)
+        {
+            DPRINT("EventSource LogFile: %p\n", pEventSource->LogFile);
+            lpLogHandle->LogFile = pEventSource->LogFile;
+        }
+        else
+        {
+            DPRINT("EventSource LogFile: Application log file\n");
+            lpLogHandle->LogFile = LogfListItemByName(L"Application");
+        }
 
-    for (i = 1; i <= LogsActive; i++)
+        DPRINT("LogHandle LogFile: %p\n", lpLogHandle->LogFile);
+    }
+    else
     {
-        currentLogFile = LogfListItemByIndex(i);
+        lpLogHandle->LogFile = NULL;
 
-        if (_wcsicmp(Name, currentLogFile->LogName) == 0)
+        for (i = 1; i <= LogsActive; i++)
         {
-            lpEventSource->LogFile = LogfListItemByIndex(i);
-            lpEventSource->CurrentRecord = LogfGetOldestRecord(lpEventSource->LogFile);
-            break;
+            currentLogFile = LogfListItemByIndex(i);
+
+            if (_wcsicmp(Name, currentLogFile->LogName) == 0)
+            {
+                lpLogHandle->LogFile = LogfListItemByIndex(i);
+                lpLogHandle->CurrentRecord = LogfGetOldestRecord(lpLogHandle->LogFile);
+                break;
+            }
         }
     }
 
-    if (!lpEventSource->LogFile)
+    if (!lpLogHandle->LogFile)
         goto Cleanup;
 
-    /* Append service record */
-    InsertTailList(&EventSourceListHead, &lpEventSource->EventSourceListEntry);
+    /* Append log handle */
+    InsertTailList(&LogHandleListHead, &lpLogHandle->LogHandleListEntry);
 
-    return lpEventSource;
+    return lpLogHandle;
 
 Cleanup:
-    HeapFree(GetProcessHeap(), 0, lpEventSource);
+    HeapFree(GetProcessHeap(), 0, lpLogHandle);
 
     return NULL;
 }
 
-PEVENTSOURCE ElfGetEventLogSourceEntryByHandle(IELF_HANDLE EventLogHandle)
+PLOGHANDLE ElfGetLogHandleEntryByHandle(IELF_HANDLE EventLogHandle)
 {
-    PEVENTSOURCE CurrentEventSource;
+    PLOGHANDLE lpLogHandle;
 
-    if (IsListEmpty(&EventSourceListHead))
+    if (IsListEmpty(&LogHandleListHead))
     {
         return NULL;
     }
-    CurrentEventSource = CONTAINING_RECORD((PEVENTSOURCE)EventLogHandle, EVENTSOURCE, EventSourceListEntry);
 
-    return CurrentEventSource;
+    lpLogHandle = CONTAINING_RECORD((PLOGHANDLE)EventLogHandle, LOGHANDLE, LogHandleListEntry);
+
+    return lpLogHandle;
 }
 
 BOOL ElfDeleteEventLogHandle(IELF_HANDLE EventLogHandle)
 {
-    PEVENTSOURCE lpEventSource = (PEVENTSOURCE)EventLogHandle;
-    if (!ElfGetEventLogSourceEntryByHandle(lpEventSource))
+    PLOGHANDLE lpLogHandle = (PLOGHANDLE)EventLogHandle;
+    if (!ElfGetLogHandleEntryByHandle(lpLogHandle))
     {
         return FALSE;
     }
 
-    RemoveEntryList(&lpEventSource->EventSourceListEntry);
-    HeapFree(GetProcessHeap(),0,lpEventSource);
+    RemoveEntryList(&lpLogHandle->LogHandleListEntry);
+    HeapFree(GetProcessHeap(),0,lpLogHandle);
 
     return TRUE;
 }
@@ -177,15 +198,15 @@ NTSTATUS ElfrNumberOfRecords(
     IELF_HANDLE LogHandle,
     DWORD *NumberOfRecords)
 {
-    PEVENTSOURCE lpEventSource;
+    PLOGHANDLE lpLogHandle;
 
-    lpEventSource = ElfGetEventLogSourceEntryByHandle(LogHandle);
-    if (!lpEventSource)
+    lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
+    if (!lpLogHandle)
     {
         return STATUS_INVALID_HANDLE;
     }
 
-    *NumberOfRecords = lpEventSource->LogFile->Header.CurrentRecordNumber;
+    *NumberOfRecords = lpLogHandle->LogFile->Header.CurrentRecordNumber;
 
     return STATUS_SUCCESS;
 }
@@ -196,10 +217,10 @@ NTSTATUS ElfrOldestRecord(
     IELF_HANDLE LogHandle,
     DWORD *OldestRecordNumber)
 {
-    PEVENTSOURCE lpEventSource;
+    PLOGHANDLE lpLogHandle;
 
-    lpEventSource = ElfGetEventLogSourceEntryByHandle(LogHandle);
-    if (!lpEventSource)
+    lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
+    if (!lpLogHandle)
     {
         return STATUS_INVALID_HANDLE;
     }
@@ -210,7 +231,7 @@ NTSTATUS ElfrOldestRecord(
     }
 
     *OldestRecordNumber = 0;
-    *OldestRecordNumber = LogfGetOldestRecord(lpEventSource->LogFile);
+    *OldestRecordNumber = LogfGetOldestRecord(lpLogHandle->LogFile);
     return STATUS_SUCCESS;
 }
 
@@ -266,6 +287,8 @@ NTSTATUS ElfrRegisterEventSourceW(
     DWORD MinorVersion,
     IELF_HANDLE *LogHandle)
 {
+    DPRINT1("ElfrRegisterEventSourceW()\n");
+
     if ((MajorVersion != 1) || (MinorVersion != 1))
         return STATUS_INVALID_PARAMETER;
 
@@ -273,6 +296,8 @@ NTSTATUS ElfrRegisterEventSourceW(
     if (RegModuleName->Length > 0)
         return STATUS_INVALID_PARAMETER;
 
+    DPRINT1("ModuleName: %S\n", ModuleName->Buffer);
+
     /*FIXME: UNCServerName must specify the server or empty for local */
 
     /*FIXME: Must verify that caller has write access */
@@ -306,12 +331,12 @@ NTSTATUS ElfrReadELW(
     DWORD *NumberOfBytesRead,
     DWORD *MinNumberOfBytesNeeded)
 {
-    PEVENTSOURCE lpEventSource;
+    PLOGHANDLE lpLogHandle;
     DWORD dwError;
     DWORD RecordNumber;
 
-    lpEventSource = ElfGetEventLogSourceEntryByHandle(LogHandle);
-    if (!lpEventSource)
+    lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
+    if (!lpLogHandle)
     {
         return STATUS_INVALID_HANDLE;
     }
@@ -322,20 +347,20 @@ NTSTATUS ElfrReadELW(
     /* If sequential read, retrieve the CurrentRecord from this log handle */
     if (ReadFlags & EVENTLOG_SEQUENTIAL_READ)
     {
-        RecordNumber = lpEventSource->CurrentRecord;
+        RecordNumber = lpLogHandle->CurrentRecord;
     }
     else
     {
         RecordNumber = RecordOffset;
     }
 
-    dwError = LogfReadEvent(lpEventSource->LogFile, ReadFlags, &RecordNumber,
+    dwError = LogfReadEvent(lpLogHandle->LogFile, ReadFlags, &RecordNumber,
                             NumberOfBytesToRead, Buffer, NumberOfBytesRead, MinNumberOfBytesNeeded);
 
     /* Update the handles CurrentRecord if success*/
     if (dwError == ERROR_SUCCESS)
     {
-        lpEventSource->CurrentRecord = RecordNumber;
+        lpLogHandle->CurrentRecord = RecordNumber;
     }
 
     return I_RpcMapWin32Status(dwError);
@@ -361,7 +386,7 @@ NTSTATUS ElfrReportEventW(
 {
     USHORT i;
     PBYTE LogBuffer;
-    PEVENTSOURCE lpEventSource;
+    PLOGHANDLE lpLogHandle;
     DWORD lastRec;
     DWORD recSize;
     DWORD dwStringsSize = 0;
@@ -369,8 +394,8 @@ NTSTATUS ElfrReportEventW(
     WCHAR *lpStrings;
     int pos = 0;
 
-    lpEventSource = ElfGetEventLogSourceEntryByHandle(LogHandle);
-    if (!lpEventSource)
+    lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
+    if (!lpLogHandle)
     {
         return STATUS_INVALID_HANDLE;
     }
@@ -381,7 +406,7 @@ NTSTATUS ElfrReportEventW(
         return STATUS_INVALID_PARAMETER;
     }
 
-    lastRec = LogfGetCurrentRecord(lpEventSource->LogFile);
+    lastRec = LogfGetCurrentRecord(lpLogHandle->LogFile);
 
     for (i = 0; i < NumStrings; i++)
     {
@@ -428,7 +453,7 @@ NTSTATUS ElfrReportEventW(
                                            EventType,
                                            EventCategory,
                                            EventID,
-                                           lpEventSource->szName,
+                                           lpLogHandle->szName,
                                            ComputerName->Buffer,
                                            sizeof(UserSID),
                                            &UserSID,
@@ -437,10 +462,10 @@ NTSTATUS ElfrReportEventW(
                                            DataSize,
                                            Data);
 
-    dwError = LogfWriteData(lpEventSource->LogFile, recSize, LogBuffer);
+    dwError = LogfWriteData(lpLogHandle->LogFile, recSize, LogBuffer);
     if (!dwError)
     {
-        DPRINT1("ERROR WRITING TO EventLog %S\n",lpEventSource->LogFile->FileName);
+        DPRINT1("ERROR WRITING TO EventLog %S\n", lpLogHandle->LogFile->FileName);
     }
 
     LogfFreeRecord(LogBuffer);