Author: ekohl
Date: Sat Apr 30 22:33:53 2011
New Revision: 51513

URL: http://svn.reactos.org/svn/reactos?rev=51513&view=rev
Log:
[EVENTLOG]
Implement an event source list and use it to find the event log file for a 
given event source when an event was reported.

Added:
    trunk/reactos/base/services/eventlog/eventsource.c   (with props)
Modified:
    trunk/reactos/base/services/eventlog/eventlog.c
    trunk/reactos/base/services/eventlog/eventlog.h
    trunk/reactos/base/services/eventlog/eventlog.rbuild
    trunk/reactos/base/services/eventlog/rpc.c

Modified: trunk/reactos/base/services/eventlog/eventlog.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/eventlog.c?rev=51513&r1=51512&r2=51513&view=diff
==============================================================================
--- trunk/reactos/base/services/eventlog/eventlog.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/eventlog.c [iso-8859-1] Sat Apr 30 
22:33:53 2011
@@ -174,12 +174,11 @@
 }
 
 
-BOOL LoadLogFile(HKEY hKey, WCHAR * LogName)
+PLOGFILE LoadLogFile(HKEY hKey, WCHAR * LogName)
 {
     DWORD MaxValueLen, ValueLen, Type, ExpandedLen;
     WCHAR *Buf = NULL, *Expanded = NULL;
     LONG Result;
-    BOOL ret = TRUE;
     PLOGFILE pLogf;
 
     DPRINT("LoadLogFile: %S\n", LogName);
@@ -188,11 +187,10 @@
                     NULL, NULL, &MaxValueLen, NULL, NULL);
 
     Buf = HeapAlloc(MyHeap, 0, MaxValueLen);
-
     if (!Buf)
     {
         DPRINT1("Can't allocate heap!\n");
-        return FALSE;
+        return NULL;
     }
 
     ValueLen = MaxValueLen;
@@ -203,29 +201,27 @@
                              &Type,
                              (LPBYTE) Buf,
                              &ValueLen);
-
     if (Result != ERROR_SUCCESS)
     {
         DPRINT1("RegQueryValueEx failed: %d\n", GetLastError());
         HeapFree(MyHeap, 0, Buf);
-        return FALSE;
+        return NULL;
     }
 
     if (Type != REG_EXPAND_SZ && Type != REG_SZ)
     {
         DPRINT1("%S\\File - value of wrong type %x.\n", LogName, Type);
         HeapFree(MyHeap, 0, Buf);
-        return FALSE;
+        return NULL;
     }
 
     ExpandedLen = ExpandEnvironmentStrings(Buf, NULL, 0);
     Expanded = HeapAlloc(MyHeap, 0, ExpandedLen * sizeof(WCHAR));
-
     if (!Expanded)
     {
         DPRINT1("Can't allocate heap!\n");
         HeapFree(MyHeap, 0, Buf);
-        return FALSE;
+        return NULL;
     }
 
     ExpandEnvironmentStrings(Buf, Expanded, ExpandedLen);
@@ -237,12 +233,11 @@
     if (pLogf == NULL)
     {
         DPRINT1("Failed to create %S!\n", Expanded);
-        ret = FALSE;
     }
 
     HeapFree(MyHeap, 0, Buf);
     HeapFree(MyHeap, 0, Expanded);
-    return ret;
+    return pLogf;
 }
 
 BOOL LoadLogFiles(HKEY eventlogKey)
@@ -251,6 +246,7 @@
     DWORD MaxLognameLen, LognameLen;
     WCHAR *Buf = NULL;
     INT i;
+    PLOGFILE pLogFile;
 
     RegQueryInfoKey(eventlogKey,
                     NULL, NULL, NULL, NULL,
@@ -288,10 +284,16 @@
             return FALSE;
         }
 
-        if (!LoadLogFile(SubKey, Buf))
+        pLogFile = LoadLogFile(SubKey, Buf);
+        if (pLogFile != NULL)
+        {
+            DPRINT("Loaded %S\n", Buf);
+            LoadEventSources(SubKey, pLogFile);
+        }
+        else
+        {
             DPRINT1("Failed to load %S\n", Buf);
-        else
-            DPRINT("Loaded %S\n", Buf);
+        }
 
         RegCloseKey(SubKey);
         LognameLen = MaxLognameLen;
@@ -310,6 +312,7 @@
     HKEY elogKey;
 
     LogfListInitialize();
+    InitEventSourceList();
 
     MyHeap = HeapCreate(0, 1024 * 256, 0);
 

Modified: trunk/reactos/base/services/eventlog/eventlog.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/eventlog.h?rev=51513&r1=51512&r2=51513&view=diff
==============================================================================
--- trunk/reactos/base/services/eventlog/eventlog.h [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/eventlog.h [iso-8859-1] Sat Apr 30 
22:33:53 2011
@@ -93,19 +93,17 @@
     LIST_ENTRY ListEntry;
 } LOGFILE, *PLOGFILE;
 
-#if 0
 typedef struct _EVENTSOURCE
 {
     LIST_ENTRY EventSourceListEntry;
     PLOGFILE LogFile;
-    ULONG CurrentRecord;
     WCHAR szName[1];
 } EVENTSOURCE, *PEVENTSOURCE;
-#endif
 
 typedef struct _LOGHANDLE
 {
     LIST_ENTRY LogHandleListEntry;
+    PEVENTSOURCE EventSource;
     PLOGFILE LogFile;
     ULONG CurrentRecord;
     WCHAR szName[1];
@@ -192,6 +190,17 @@
 VOID SystemTimeToEventTime(SYSTEMTIME * pSystemTime,
                            DWORD * pEventTime);
 
+/* eventsource.c */
+VOID InitEventSourceList(VOID);
+
+BOOL
+LoadEventSources(HKEY hKey,
+                 PLOGFILE pLogFile);
+
+PEVENTSOURCE
+GetEventSourceByName(LPCWSTR Name);
+
+
 /* logport.c */
 NTSTATUS WINAPI PortThreadRoutine(PVOID Param);
 

Modified: trunk/reactos/base/services/eventlog/eventlog.rbuild
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/eventlog.rbuild?rev=51513&r1=51512&r2=51513&view=diff
==============================================================================
--- trunk/reactos/base/services/eventlog/eventlog.rbuild [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/eventlog.rbuild [iso-8859-1] Sat Apr 
30 22:33:53 2011
@@ -9,6 +9,7 @@
        <library>rpcrt4</library>
        <library>pseh</library>
        <file>eventlog.c</file>
+       <file>eventsource.c</file>
        <file>logport.c</file>
        <file>eventlog.rc</file>
        <file>rpc.c</file>

Added: trunk/reactos/base/services/eventlog/eventsource.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/eventsource.c?rev=51513&view=auto
==============================================================================
--- trunk/reactos/base/services/eventlog/eventsource.c (added)
+++ trunk/reactos/base/services/eventlog/eventsource.c [iso-8859-1] Sat Apr 30 
22:33:53 2011
@@ -1,0 +1,150 @@
+/*
+ * PROJECT:          ReactOS kernel
+ * LICENSE:          GPL - See COPYING in the top level directory
+ * FILE:             base/services/eventlog/eventsource.c
+ * PURPOSE:          Event logging service
+ * COPYRIGHT:        Copyright 2011 Eric Kohl
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include "eventlog.h"
+
+static LIST_ENTRY EventSourceListHead;
+static CRITICAL_SECTION EventSourceListCs;
+
+/* FUNCTIONS ****************************************************************/
+
+VOID
+InitEventSourceList(VOID)
+{
+    InitializeCriticalSection(&EventSourceListCs);
+    InitializeListHead(&EventSourceListHead);
+}
+
+
+static VOID
+DumpEventSourceList(VOID)
+{
+    PLIST_ENTRY CurrentEntry;
+    PEVENTSOURCE EventSource;
+
+    DPRINT("DumpEventSourceList()\n");
+    EnterCriticalSection(&EventSourceListCs);
+
+    CurrentEntry = EventSourceListHead.Flink;
+    while (CurrentEntry != &EventSourceListHead)
+    {
+        EventSource = CONTAINING_RECORD(CurrentEntry,
+                                        EVENTSOURCE,
+                                        EventSourceListEntry);
+
+        DPRINT("EventSource->szName: %S\n", EventSource->szName);
+
+        CurrentEntry = CurrentEntry->Flink;
+    }
+
+    LeaveCriticalSection(&EventSourceListCs);
+
+    DPRINT("Done\n");
+}
+
+
+BOOL
+LoadEventSources(HKEY hKey,
+                 PLOGFILE pLogFile)
+{
+    PEVENTSOURCE lpEventSource;
+    DWORD dwMaxSubKeyLength;
+    DWORD dwEventSourceNameLength;
+    DWORD dwIndex;
+    WCHAR *Buf = NULL;
+
+    DPRINT("LoadEventSources\n");
+
+    RegQueryInfoKeyW(hKey, NULL, NULL, NULL, NULL, &dwMaxSubKeyLength, NULL,
+                     NULL, NULL, NULL, NULL, NULL);
+
+    DPRINT("dwMaxSubKeyLength: %lu\n", dwMaxSubKeyLength);
+
+    dwMaxSubKeyLength++;
+
+    Buf = HeapAlloc(MyHeap, 0, dwMaxSubKeyLength * sizeof(WCHAR));
+    if (!Buf)
+    {
+        DPRINT1("Error: can't allocate heap!\n");
+        return FALSE;
+    }
+
+    dwEventSourceNameLength = dwMaxSubKeyLength;
+
+    dwIndex = 0;
+    while (RegEnumKeyExW(hKey,
+                         dwIndex,
+                         Buf,
+                         &dwEventSourceNameLength,
+                         NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
+    {
+        DPRINT("Event Source: %S\n", Buf);
+
+        lpEventSource = HeapAlloc(MyHeap, 0, sizeof(EVENTSOURCE) + wcslen(Buf) 
* sizeof(WCHAR));
+        if (lpEventSource != NULL)
+        {
+            wcscpy(lpEventSource->szName, Buf);
+            lpEventSource->LogFile = pLogFile;
+
+            DPRINT("Insert event source: %S\n", lpEventSource->szName);
+
+
+            EnterCriticalSection(&EventSourceListCs);
+            InsertTailList(&EventSourceListHead,
+                           &lpEventSource->EventSourceListEntry);
+            LeaveCriticalSection(&EventSourceListCs);
+        }
+
+        dwEventSourceNameLength = dwMaxSubKeyLength;
+        dwIndex++;
+    }
+
+    HeapFree(MyHeap, 0, Buf);
+
+    DumpEventSourceList();
+
+    return TRUE;
+}
+
+
+PEVENTSOURCE
+GetEventSourceByName(LPCWSTR Name)
+{
+    PLIST_ENTRY CurrentEntry;
+    PEVENTSOURCE Result = NULL;
+
+    DPRINT("GetEventSourceByName(%S)\n", Name);
+    EnterCriticalSection(&EventSourceListCs);
+
+    CurrentEntry = EventSourceListHead.Flink;
+    while (CurrentEntry != &EventSourceListHead)
+    {
+        PEVENTSOURCE Item = CONTAINING_RECORD(CurrentEntry,
+                                              EVENTSOURCE,
+                                              EventSourceListEntry);
+
+        DPRINT("Item->szName: %S\n", Item->szName);
+//        if ((*(Item->szName) != 0) && !_wcsicmp(Item->szName, Name))
+        if (_wcsicmp(Item->szName, Name) == 0)
+        {
+            DPRINT("Found it\n");
+            Result = Item;
+            break;
+        }
+
+        CurrentEntry = CurrentEntry->Flink;
+    }
+
+    LeaveCriticalSection(&EventSourceListCs);
+
+    DPRINT("Done (Result: %p)\n", Result);
+
+    return Result;
+}

Propchange: trunk/reactos/base/services/eventlog/eventsource.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/reactos/base/services/eventlog/eventsource.c
------------------------------------------------------------------------------
    svn:keywords = author date id revision

Modified: trunk/reactos/base/services/eventlog/rpc.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/rpc.c?rev=51513&r1=51512&r2=51513&view=diff
==============================================================================
--- trunk/reactos/base/services/eventlog/rpc.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/rpc.c [iso-8859-1] Sat Apr 30 22:33:53 
2011
@@ -49,6 +49,9 @@
     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)));
@@ -70,19 +73,36 @@
 
     /* If Creating, default to the Application Log in case we fail, as 
documented on MSDN */
     if (Create == TRUE)
-        lpLogHandle->LogFile = LogfListItemByName(L"Application");
+    {
+        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");
+        }
+
+        DPRINT("LogHandle LogFile: %p\n", lpLogHandle->LogFile);
+    }
     else
+    {
         lpLogHandle->LogFile = NULL;
 
-    for (i = 1; i <= LogsActive; i++)
-    {
-        currentLogFile = LogfListItemByIndex(i);
-
-        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;
+            }
         }
     }
 
@@ -267,12 +287,16 @@
     DWORD MinorVersion,
     IELF_HANDLE *LogHandle)
 {
+    DPRINT1("ElfrRegisterEventSourceW()\n");
+
     if ((MajorVersion != 1) || (MinorVersion != 1))
         return STATUS_INVALID_PARAMETER;
 
     /* RegModuleName must be an empty string */
     if (RegModuleName->Length > 0)
         return STATUS_INVALID_PARAMETER;
+
+    DPRINT1("ModuleName: %S\n", ModuleName->Buffer);
 
     /*FIXME: UNCServerName must specify the server or empty for local */
 


Reply via email to