ReactOS 0.4.16-dev-338-g34e76ad
eventsource.c File Reference
#include "eventlog.h"
#include <debug.h>
Include dependency graph for eventsource.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID InitEventSourceList (VOID)
 
static VOID DumpEventSourceList (VOID)
 
static BOOL AddNewEventSource (PLOGFILE pLogFile, PWSTR lpSourceName)
 
BOOL LoadEventSources (HKEY hKey, PLOGFILE pLogFile)
 
PEVENTSOURCE GetEventSourceByName (LPCWSTR Name)
 

Variables

static LIST_ENTRY EventSourceListHead
 
static CRITICAL_SECTION EventSourceListCs
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file eventsource.c.

Function Documentation

◆ AddNewEventSource()

static BOOL AddNewEventSource ( PLOGFILE  pLogFile,
PWSTR  lpSourceName 
)
static

Definition at line 57 of file eventsource.c.

59{
61
63 FIELD_OFFSET(EVENTSOURCE, szName[wcslen(lpSourceName) + 1]));
64 if (lpEventSource != NULL)
65 {
66 wcscpy(lpEventSource->szName, lpSourceName);
67 lpEventSource->LogFile = pLogFile;
68
69 DPRINT("Insert event source: %S\n", lpEventSource->szName);
70
73 &lpEventSource->EventSourceListEntry);
75 }
76
77 return (lpEventSource != NULL);
78}
static LPWSTR lpEventSource
Definition: log.c:14
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define InsertTailList(ListHead, Entry)
static LIST_ENTRY EventSourceListHead
Definition: eventsource.c:16
static CRITICAL_SECTION EventSourceListCs
Definition: eventsource.c:17
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static const WCHAR szName[]
Definition: powrprof.c:45
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define DPRINT
Definition: sndvol32.h:73
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

Referenced by LoadEventSources().

◆ DumpEventSourceList()

static VOID DumpEventSourceList ( VOID  )
static

Definition at line 30 of file eventsource.c.

31{
32 PLIST_ENTRY CurrentEntry;
33 PEVENTSOURCE EventSource;
34
35 DPRINT("DumpEventSourceList()\n");
37
38 CurrentEntry = EventSourceListHead.Flink;
39 while (CurrentEntry != &EventSourceListHead)
40 {
41 EventSource = CONTAINING_RECORD(CurrentEntry,
43 EventSourceListEntry);
44
45 DPRINT("EventSource->szName: %S\n", EventSource->szName);
46
47 CurrentEntry = CurrentEntry->Flink;
48 }
49
51
52 DPRINT("Done\n");
53}
WCHAR szName[1]
Definition: eventlog.h:48
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by LoadEventSources().

◆ GetEventSourceByName()

PEVENTSOURCE GetEventSourceByName ( LPCWSTR  Name)

Definition at line 202 of file eventsource.c.

203{
204 PLIST_ENTRY CurrentEntry;
206
207 DPRINT("GetEventSourceByName(%S)\n", Name);
209
210 CurrentEntry = EventSourceListHead.Flink;
211 while (CurrentEntry != &EventSourceListHead)
212 {
213 Item = CONTAINING_RECORD(CurrentEntry,
215 EventSourceListEntry);
216
217 DPRINT("Item->szName: %S\n", Item->szName);
218// if ((*(Item->szName) != 0) && !_wcsicmp(Item->szName, Name))
219 if (_wcsicmp(Item->szName, Name) == 0)
220 {
221 DPRINT("Found it\n");
222 Result = Item;
223 break;
224 }
225
226 CurrentEntry = CurrentEntry->Flink;
227 }
228
230
231 DPRINT("Done (Result: %p)\n", Result);
232
233 return Result;
234}
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by ElfCreateEventLogHandle(), and wmain().

◆ InitEventSourceList()

VOID InitEventSourceList ( VOID  )

Definition at line 22 of file eventsource.c.

23{
26}
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751

Referenced by wmain().

◆ LoadEventSources()

BOOL LoadEventSources ( HKEY  hKey,
PLOGFILE  pLogFile 
)

Definition at line 82 of file eventsource.c.

84{
86 DWORD dwNumSubKeys, dwMaxSubKeyLength;
87 DWORD dwEventSourceNameLength, MaxValueLen;
88 DWORD dwIndex;
89 PWSTR Buf = NULL, SourceList = NULL, Source = NULL;
90 size_t cchRemaining = 0;
92
93 DPRINT("LoadEventSources\n");
94
95 Result = RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &dwNumSubKeys, &dwMaxSubKeyLength,
96 NULL, NULL, NULL, NULL, NULL, NULL);
97 if (Result != ERROR_SUCCESS)
98 {
99 DPRINT1("RegQueryInfoKeyW failed: %lu\n", Result);
100 return FALSE;
101 }
102
103 dwMaxSubKeyLength++;
104
105 Buf = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLength * sizeof(WCHAR));
106 if (!Buf)
107 {
108 DPRINT1("Error: cannot allocate heap!\n");
109 return FALSE;
110 }
111
112 /*
113 * Allocate a buffer for storing the names of the sources as a REG_MULTI_SZ
114 * in the registry. Also add the event log as its own source.
115 * Add a final NULL-terminator.
116 */
117 MaxValueLen = dwNumSubKeys * dwMaxSubKeyLength + wcslen(pLogFile->LogName) + 2;
118 SourceList = HeapAlloc(GetProcessHeap(), 0, MaxValueLen * sizeof(WCHAR));
119 if (!SourceList)
120 {
121 DPRINT1("Error: cannot allocate heap!\n");
122 /* It is not dramatic if we cannot create it */
123 }
124 else
125 {
126 cchRemaining = MaxValueLen;
128 }
129
130 /*
131 * Enumerate all the subkeys of the event log key, that constitute
132 * all the possible event sources for this event log. At this point,
133 * skip the possible existing source having the same name as the
134 * event log, it will be added later on.
135 */
136 dwEventSourceNameLength = dwMaxSubKeyLength;
137 dwIndex = 0;
138 while (RegEnumKeyExW(hKey,
139 dwIndex,
140 Buf,
141 &dwEventSourceNameLength,
143 {
144 if (_wcsicmp(pLogFile->LogName, Buf) != 0)
145 {
146 DPRINT("Event Source: %S\n", Buf);
147 Success = AddNewEventSource(pLogFile, Buf);
148 if (Success && (Source != NULL))
149 {
150 /* Append the event source name and an extra NULL-terminator */
151 StringCchCopyExW(Source, cchRemaining, Buf, &Source, &cchRemaining, 0);
152 if (cchRemaining > 0)
153 {
154 *++Source = L'\0';
155 cchRemaining--;
156 }
157 }
158 }
159
160 dwEventSourceNameLength = dwMaxSubKeyLength;
161 dwIndex++;
162 }
163
164 /* Finally, allow the event log itself to be its own source */
165 DPRINT("Event Source: %S\n", pLogFile->LogName);
166 Success = AddNewEventSource(pLogFile, pLogFile->LogName);
167 if (Success && (Source != NULL))
168 {
169 /* Append the event source name and an extra NULL-terminator */
170 StringCchCopyExW(Source, cchRemaining, pLogFile->LogName, &Source, &cchRemaining, 0);
171 if (cchRemaining > 0)
172 {
173 *++Source = L'\0';
174 cchRemaining--;
175 }
176 }
177
178 /* Save the list of sources in the registry */
180 L"Sources",
181 0,
184 (MaxValueLen - cchRemaining + 1) * sizeof(WCHAR));
185 if (Result != ERROR_SUCCESS)
186 {
187 DPRINT1("RegSetValueExW failed: %lu\n", Result);
188 }
189
190 if (SourceList)
192
193 HeapFree(GetProcessHeap(), 0, Buf);
194
196
197 return TRUE;
198}
#define DPRINT1
Definition: precomp.h:8
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2504
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3662
#define HeapFree(x, y, z)
Definition: compat.h:735
@ Success
Definition: eventcreate.c:712
static VOID DumpEventSourceList(VOID)
Definition: eventsource.c:30
static BOOL AddNewEventSource(PLOGFILE pLogFile, PWSTR lpSourceName)
Definition: eventsource.c:57
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
#define REG_MULTI_SZ
Definition: nt_native.h:1501
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
STRSAFEAPI StringCchCopyExW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags)
Definition: strsafe.h:184
WCHAR * LogName
Definition: eventlog.h:38
uint16_t * PWSTR
Definition: typedefs.h:56
unsigned char * LPBYTE
Definition: typedefs.h:53
_In_ IN_ADDR _In_ IN_ADDR _Out_ MULTICAST_MODE_TYPE _Inout_ ULONG _Out_writes_ SourceCount IN_ADDR * SourceList
Definition: ws2tcpip.h:622
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by LoadLogFiles().

Variable Documentation

◆ EventSourceListCs

CRITICAL_SECTION EventSourceListCs
static

◆ EventSourceListHead

LIST_ENTRY EventSourceListHead
static