2 * PROJECT: ReactOS kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/services/eventlog/eventsource.c
5 * PURPOSE: Event logging service
6 * COPYRIGHT: Copyright 2011 Eric Kohl
9 /* INCLUDES *****************************************************************/
13 static LIST_ENTRY EventSourceListHead
;
14 static CRITICAL_SECTION EventSourceListCs
;
16 /* FUNCTIONS ****************************************************************/
19 InitEventSourceList(VOID
)
21 InitializeCriticalSection(&EventSourceListCs
);
22 InitializeListHead(&EventSourceListHead
);
27 DumpEventSourceList(VOID
)
29 PLIST_ENTRY CurrentEntry
;
30 PEVENTSOURCE EventSource
;
32 DPRINT("DumpEventSourceList()\n");
33 EnterCriticalSection(&EventSourceListCs
);
35 CurrentEntry
= EventSourceListHead
.Flink
;
36 while (CurrentEntry
!= &EventSourceListHead
)
38 EventSource
= CONTAINING_RECORD(CurrentEntry
,
40 EventSourceListEntry
);
42 DPRINT("EventSource->szName: %S\n", EventSource
->szName
);
44 CurrentEntry
= CurrentEntry
->Flink
;
47 LeaveCriticalSection(&EventSourceListCs
);
54 LoadEventSources(HKEY hKey
,
57 PEVENTSOURCE lpEventSource
;
58 DWORD dwMaxSubKeyLength
;
59 DWORD dwEventSourceNameLength
;
63 DPRINT("LoadEventSources\n");
65 RegQueryInfoKeyW(hKey
, NULL
, NULL
, NULL
, NULL
, &dwMaxSubKeyLength
, NULL
,
66 NULL
, NULL
, NULL
, NULL
, NULL
);
68 DPRINT("dwMaxSubKeyLength: %lu\n", dwMaxSubKeyLength
);
72 Buf
= HeapAlloc(MyHeap
, 0, dwMaxSubKeyLength
* sizeof(WCHAR
));
75 DPRINT1("Error: can't allocate heap!\n");
79 dwEventSourceNameLength
= dwMaxSubKeyLength
;
82 while (RegEnumKeyExW(hKey
,
85 &dwEventSourceNameLength
,
86 NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
88 DPRINT("Event Source: %S\n", Buf
);
90 lpEventSource
= HeapAlloc(MyHeap
, 0, sizeof(EVENTSOURCE
) + wcslen(Buf
) * sizeof(WCHAR
));
91 if (lpEventSource
!= NULL
)
93 wcscpy(lpEventSource
->szName
, Buf
);
94 lpEventSource
->LogFile
= pLogFile
;
96 DPRINT("Insert event source: %S\n", lpEventSource
->szName
);
99 EnterCriticalSection(&EventSourceListCs
);
100 InsertTailList(&EventSourceListHead
,
101 &lpEventSource
->EventSourceListEntry
);
102 LeaveCriticalSection(&EventSourceListCs
);
105 dwEventSourceNameLength
= dwMaxSubKeyLength
;
109 HeapFree(MyHeap
, 0, Buf
);
111 DumpEventSourceList();
118 GetEventSourceByName(LPCWSTR Name
)
120 PLIST_ENTRY CurrentEntry
;
121 PEVENTSOURCE Result
= NULL
;
123 DPRINT("GetEventSourceByName(%S)\n", Name
);
124 EnterCriticalSection(&EventSourceListCs
);
126 CurrentEntry
= EventSourceListHead
.Flink
;
127 while (CurrentEntry
!= &EventSourceListHead
)
129 PEVENTSOURCE Item
= CONTAINING_RECORD(CurrentEntry
,
131 EventSourceListEntry
);
133 DPRINT("Item->szName: %S\n", Item
->szName
);
134 // if ((*(Item->szName) != 0) && !_wcsicmp(Item->szName, Name))
135 if (_wcsicmp(Item
->szName
, Name
) == 0)
137 DPRINT("Found it\n");
142 CurrentEntry
= CurrentEntry
->Flink
;
145 LeaveCriticalSection(&EventSourceListCs
);
147 DPRINT("Done (Result: %p)\n", Result
);