ReactOS  0.4.12-dev-18-gf469aca
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.

Referenced by LoadEventSources().

59 {
61 
62  lpEventSource = HeapAlloc(GetProcessHeap(), 0,
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 }
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define InsertTailList(ListHead, Entry)
static LPWSTR lpEventSource
Definition: log.c:14
LIST_ENTRY EventSourceListEntry
Definition: eventlog.h:46
PLOGFILE LogFile
Definition: eventlog.h:47
WCHAR szName[1]
Definition: eventlog.h:48
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
static CRITICAL_SECTION EventSourceListCs
Definition: eventsource.c:17
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
static const WCHAR szName[]
Definition: msipriv.h:1194
static LIST_ENTRY EventSourceListHead
Definition: eventsource.c:16
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

◆ DumpEventSourceList()

static VOID DumpEventSourceList ( VOID  )
static

Definition at line 30 of file eventsource.c.

Referenced by LoadEventSources().

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 }
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
WCHAR szName[1]
Definition: eventlog.h:48
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static CRITICAL_SECTION EventSourceListCs
Definition: eventsource.c:17
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
static LIST_ENTRY EventSourceListHead
Definition: eventsource.c:16
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

◆ GetEventSourceByName()

PEVENTSOURCE GetEventSourceByName ( LPCWSTR  Name)

Definition at line 202 of file eventsource.c.

Referenced by ElfCreateEventLogHandle(), and wmain().

203 {
204  PLIST_ENTRY CurrentEntry;
205  PEVENTSOURCE Item, Result = NULL;
206 
207  DPRINT("GetEventSourceByName(%S)\n", Name);
209 
210  CurrentEntry = EventSourceListHead.Flink;
211  while (CurrentEntry != &EventSourceListHead)
212  {
213  Item = CONTAINING_RECORD(CurrentEntry,
214  EVENTSOURCE,
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 }
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
WCHAR szName[1]
Definition: eventlog.h:48
smooth NULL
Definition: ftsmooth.c:416
_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:426
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static CRITICAL_SECTION EventSourceListCs
Definition: eventsource.c:17
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
static LIST_ENTRY EventSourceListHead
Definition: eventsource.c:16
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

◆ InitEventSourceList()

VOID InitEventSourceList ( VOID  )

Definition at line 22 of file eventsource.c.

Referenced by wmain().

23 {
26 }
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
static CRITICAL_SECTION EventSourceListCs
Definition: eventsource.c:17
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static LIST_ENTRY EventSourceListHead
Definition: eventsource.c:16

◆ LoadEventSources()

BOOL LoadEventSources ( HKEY  hKey,
PLOGFILE  pLogFile 
)

Definition at line 82 of file eventsource.c.

Referenced by LoadLogFiles().

84 {
85  BOOL Success;
86  DWORD dwNumSubKeys, dwMaxSubKeyLength;
87  DWORD dwEventSourceNameLength, MaxValueLen;
88  DWORD dwIndex;
89  PWSTR Buf = NULL, SourceList = NULL, Source = NULL;
90  size_t cchRemaining = 0;
91  LONG Result;
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;
127  Source = SourceList;
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 */
179  Result = RegSetValueExW(hKey,
180  L"Sources",
181  0,
182  REG_MULTI_SZ,
183  (LPBYTE)SourceList,
184  (MaxValueLen - cchRemaining + 1) * sizeof(WCHAR));
185  if (Result != ERROR_SUCCESS)
186  {
187  DPRINT1("RegSetValueExW failed: %lu\n", Result);
188  }
189 
190  if (SourceList)
191  HeapFree(GetProcessHeap(), 0, SourceList);
192 
193  HeapFree(GetProcessHeap(), 0, Buf);
194 
196 
197  return TRUE;
198 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
static VOID DumpEventSourceList(VOID)
Definition: eventsource.c:30
_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
uint16_t * PWSTR
Definition: typedefs.h:54
unsigned char * LPBYTE
Definition: typedefs.h:52
long LONG
Definition: pedump.c:60
#define REG_MULTI_SZ
Definition: nt_native.h:1501
smooth NULL
Definition: ftsmooth.c:416
_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:426
void DPRINT(...)
Definition: polytest.cpp:61
static BOOL AddNewEventSource(PLOGFILE pLogFile, PWSTR lpSourceName)
Definition: eventsource.c:57
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:4917
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
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:3704
static const WCHAR L[]
Definition: oid.c:1087
WCHAR * LogName
Definition: eventlog.h:38
STRSAFEAPI StringCchCopyExW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags)
Definition: strsafe.h:184
#define DPRINT1
Definition: precomp.h:8
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3149
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:2541
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Variable Documentation

◆ EventSourceListCs

CRITICAL_SECTION EventSourceListCs
static

Definition at line 17 of file eventsource.c.

◆ EventSourceListHead

LIST_ENTRY EventSourceListHead
static

Definition at line 16 of file eventsource.c.