* Sync with recent trunk (r52637).
[reactos.git] / base / services / eventlog / rpc.c
index d0efdad..0f1a8ac 100644 (file)
@@ -49,6 +49,9 @@ PLOGHANDLE ElfCreateEventLogHandle(LPCWSTR Name, BOOL Create)
     PLOGHANDLE lpLogHandle;
     PLOGFILE currentLogFile = NULL;
     INT i, LogsActive;
     PLOGHANDLE lpLogHandle;
     PLOGFILE currentLogFile = NULL;
     INT i, LogsActive;
+    PEVENTSOURCE pEventSource;
+
+    DPRINT("ElfCreateEventLogHandle(Name: %S)\n", Name);
 
     lpLogHandle = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGHANDLE)
                                   + ((wcslen(Name) + 1) * sizeof(WCHAR)));
 
     lpLogHandle = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGHANDLE)
                                   + ((wcslen(Name) + 1) * sizeof(WCHAR)));
@@ -70,19 +73,36 @@ PLOGHANDLE ElfCreateEventLogHandle(LPCWSTR Name, BOOL Create)
 
     /* If Creating, default to the Application Log in case we fail, as documented on MSDN */
     if (Create == TRUE)
 
     /* If Creating, default to the Application Log in case we fail, as documented on MSDN */
     if (Create == TRUE)
-        lpLogHandle->LogFile = LogfListItemByName(L"Application");
-    else
-        lpLogHandle->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++)
         {
         {
-            lpLogHandle->LogFile = LogfListItemByIndex(i);
-            lpLogHandle->CurrentRecord = LogfGetOldestRecord(lpLogHandle->LogFile);
-            break;
+            currentLogFile = LogfListItemByIndex(i);
+
+            if (_wcsicmp(Name, currentLogFile->LogName) == 0)
+            {
+                lpLogHandle->LogFile = LogfListItemByIndex(i);
+                lpLogHandle->CurrentRecord = LogfGetOldestRecord(lpLogHandle->LogFile);
+                break;
+            }
         }
     }
 
         }
     }
 
@@ -179,6 +199,7 @@ NTSTATUS ElfrNumberOfRecords(
     DWORD *NumberOfRecords)
 {
     PLOGHANDLE lpLogHandle;
     DWORD *NumberOfRecords)
 {
     PLOGHANDLE lpLogHandle;
+    PLOGFILE lpLogFile;
 
     lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
     if (!lpLogHandle)
 
     lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
     if (!lpLogHandle)
@@ -186,7 +207,13 @@ NTSTATUS ElfrNumberOfRecords(
         return STATUS_INVALID_HANDLE;
     }
 
         return STATUS_INVALID_HANDLE;
     }
 
-    *NumberOfRecords = lpLogHandle->LogFile->Header.CurrentRecordNumber;
+    lpLogFile = lpLogHandle->LogFile;
+
+    if (lpLogFile->Header.OldestRecordNumber == 0)
+        *NumberOfRecords = 0;
+    else
+        *NumberOfRecords = lpLogFile->Header.CurrentRecordNumber -
+                           lpLogFile->Header.OldestRecordNumber;
 
     return STATUS_SUCCESS;
 }
 
     return STATUS_SUCCESS;
 }
@@ -267,6 +294,8 @@ NTSTATUS ElfrRegisterEventSourceW(
     DWORD MinorVersion,
     IELF_HANDLE *LogHandle)
 {
     DWORD MinorVersion,
     IELF_HANDLE *LogHandle)
 {
+    DPRINT1("ElfrRegisterEventSourceW()\n");
+
     if ((MajorVersion != 1) || (MinorVersion != 1))
         return STATUS_INVALID_PARAMETER;
 
     if ((MajorVersion != 1) || (MinorVersion != 1))
         return STATUS_INVALID_PARAMETER;
 
@@ -274,6 +303,8 @@ NTSTATUS ElfrRegisterEventSourceW(
     if (RegModuleName->Length > 0)
         return STATUS_INVALID_PARAMETER;
 
     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 */
     /*FIXME: UNCServerName must specify the server or empty for local */
 
     /*FIXME: Must verify that caller has write access */