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 *****************************************************************/
16 static LIST_ENTRY EventSourceListHead
;
17 static CRITICAL_SECTION EventSourceListCs
;
19 /* FUNCTIONS ****************************************************************/
22 InitEventSourceList(VOID
)
24 InitializeCriticalSection(&EventSourceListCs
);
25 InitializeListHead(&EventSourceListHead
);
30 DumpEventSourceList(VOID
)
32 PLIST_ENTRY CurrentEntry
;
33 PEVENTSOURCE EventSource
;
35 DPRINT("DumpEventSourceList()\n");
36 EnterCriticalSection(&EventSourceListCs
);
38 CurrentEntry
= EventSourceListHead
.Flink
;
39 while (CurrentEntry
!= &EventSourceListHead
)
41 EventSource
= CONTAINING_RECORD(CurrentEntry
,
43 EventSourceListEntry
);
45 DPRINT("EventSource->szName: %S\n", EventSource
->szName
);
47 CurrentEntry
= CurrentEntry
->Flink
;
50 LeaveCriticalSection(&EventSourceListCs
);
57 LoadEventSources(HKEY hKey
,
60 PEVENTSOURCE lpEventSource
;
61 DWORD dwMaxSubKeyLength
;
62 DWORD dwEventSourceNameLength
;
66 DPRINT("LoadEventSources\n");
68 RegQueryInfoKeyW(hKey
, NULL
, NULL
, NULL
, NULL
, &dwMaxSubKeyLength
, NULL
,
69 NULL
, NULL
, NULL
, NULL
, NULL
);
71 DPRINT("dwMaxSubKeyLength: %lu\n", dwMaxSubKeyLength
);
75 Buf
= HeapAlloc(MyHeap
, 0, dwMaxSubKeyLength
* sizeof(WCHAR
));
78 DPRINT1("Error: can't allocate heap!\n");
82 dwEventSourceNameLength
= dwMaxSubKeyLength
;
85 while (RegEnumKeyExW(hKey
,
88 &dwEventSourceNameLength
,
89 NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
91 DPRINT("Event Source: %S\n", Buf
);
93 lpEventSource
= HeapAlloc(MyHeap
, 0, sizeof(EVENTSOURCE
) + wcslen(Buf
) * sizeof(WCHAR
));
94 if (lpEventSource
!= NULL
)
96 wcscpy(lpEventSource
->szName
, Buf
);
97 lpEventSource
->LogFile
= pLogFile
;
99 DPRINT("Insert event source: %S\n", lpEventSource
->szName
);
102 EnterCriticalSection(&EventSourceListCs
);
103 InsertTailList(&EventSourceListHead
,
104 &lpEventSource
->EventSourceListEntry
);
105 LeaveCriticalSection(&EventSourceListCs
);
108 dwEventSourceNameLength
= dwMaxSubKeyLength
;
112 HeapFree(MyHeap
, 0, Buf
);
114 DumpEventSourceList();
121 GetEventSourceByName(LPCWSTR Name
)
123 PLIST_ENTRY CurrentEntry
;
124 PEVENTSOURCE Result
= NULL
;
126 DPRINT("GetEventSourceByName(%S)\n", Name
);
127 EnterCriticalSection(&EventSourceListCs
);
129 CurrentEntry
= EventSourceListHead
.Flink
;
130 while (CurrentEntry
!= &EventSourceListHead
)
132 PEVENTSOURCE Item
= CONTAINING_RECORD(CurrentEntry
,
134 EventSourceListEntry
);
136 DPRINT("Item->szName: %S\n", Item
->szName
);
137 // if ((*(Item->szName) != 0) && !_wcsicmp(Item->szName, Name))
138 if (_wcsicmp(Item
->szName
, Name
) == 0)
140 DPRINT("Found it\n");
145 CurrentEntry
= CurrentEntry
->Flink
;
148 LeaveCriticalSection(&EventSourceListCs
);
150 DPRINT("Done (Result: %p)\n", Result
);