[EVENTLOG]

Rename the EVENTSOURCE struct to LOGHANDLE because it is currently used like a handle object. The EVENTSOURCE struct will be added again in one of the next commits.

svn path=/trunk/; revision=49055
This commit is contained in:
Eric Kohl 2010-10-08 18:48:54 +00:00
parent 3dea59438f
commit 8618ae85de
2 changed files with 57 additions and 46 deletions

View file

@ -93,6 +93,7 @@ typedef struct _LOGFILE
LIST_ENTRY ListEntry; LIST_ENTRY ListEntry;
} LOGFILE, *PLOGFILE; } LOGFILE, *PLOGFILE;
#if 0
typedef struct _EVENTSOURCE typedef struct _EVENTSOURCE
{ {
LIST_ENTRY EventSourceListEntry; LIST_ENTRY EventSourceListEntry;
@ -100,6 +101,15 @@ typedef struct _EVENTSOURCE
ULONG CurrentRecord; ULONG CurrentRecord;
WCHAR szName[1]; WCHAR szName[1];
} EVENTSOURCE, *PEVENTSOURCE; } EVENTSOURCE, *PEVENTSOURCE;
#endif
typedef struct _LOGHANDLE
{
LIST_ENTRY LogHandleListEntry;
PLOGFILE LogFile;
ULONG CurrentRecord;
WCHAR szName[1];
} LOGHANDLE, *PLOGHANDLE;
/* file.c */ /* file.c */
VOID LogfListInitialize(VOID); VOID LogfListInitialize(VOID);

View file

@ -11,7 +11,7 @@
#include "eventlog.h" #include "eventlog.h"
LIST_ENTRY EventSourceListHead; LIST_ENTRY LogHandleListHead;
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
@ -19,7 +19,7 @@ DWORD WINAPI RpcThreadRoutine(LPVOID lpParameter)
{ {
RPC_STATUS Status; RPC_STATUS Status;
InitializeListHead(&EventSourceListHead); InitializeListHead(&LogHandleListHead);
Status = RpcServerUseProtseqEpW(L"ncacn_np", 20, L"\\pipe\\EventLog", NULL); Status = RpcServerUseProtseqEpW(L"ncacn_np", 20, L"\\pipe\\EventLog", NULL);
if (Status != RPC_S_OK) if (Status != RPC_S_OK)
@ -44,21 +44,21 @@ DWORD WINAPI RpcThreadRoutine(LPVOID lpParameter)
return 0; return 0;
} }
PEVENTSOURCE ElfCreateEventLogHandle(LPCWSTR Name, BOOL Create) PLOGHANDLE ElfCreateEventLogHandle(LPCWSTR Name, BOOL Create)
{ {
PEVENTSOURCE lpEventSource; PLOGHANDLE lpLogHandle;
PLOGFILE currentLogFile = NULL; PLOGFILE currentLogFile = NULL;
INT i, LogsActive; INT i, LogsActive;
lpEventSource = HeapAlloc(GetProcessHeap(), 0, sizeof(EVENTSOURCE) lpLogHandle = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGHANDLE)
+ ((wcslen(Name) + 1) * sizeof(WCHAR))); + ((wcslen(Name) + 1) * sizeof(WCHAR)));
if (!lpEventSource) if (!lpLogHandle)
{ {
DPRINT1("Failed to allocate Heap!\n"); DPRINT1("Failed to allocate Heap!\n");
return NULL; return NULL;
} }
wcscpy(lpEventSource->szName, Name); wcscpy(lpLogHandle->szName, Name);
/* Get the number of Log Files the EventLog service found */ /* Get the number of Log Files the EventLog service found */
LogsActive = LogfListItemCount(); LogsActive = LogfListItemCount();
@ -70,9 +70,9 @@ PEVENTSOURCE ElfCreateEventLogHandle(LPCWSTR Name, BOOL Create)
/* If Creating, default to the Application Log in case we fail, as documented on MSDN */ /* If Creating, default to the Application Log in case we fail, as documented on MSDN */
if (Create == TRUE) if (Create == TRUE)
lpEventSource->LogFile = LogfListItemByName(L"Application"); lpLogHandle->LogFile = LogfListItemByName(L"Application");
else else
lpEventSource->LogFile = NULL; lpLogHandle->LogFile = NULL;
for (i = 1; i <= LogsActive; i++) for (i = 1; i <= LogsActive; i++)
{ {
@ -80,49 +80,50 @@ PEVENTSOURCE ElfCreateEventLogHandle(LPCWSTR Name, BOOL Create)
if (_wcsicmp(Name, currentLogFile->LogName) == 0) if (_wcsicmp(Name, currentLogFile->LogName) == 0)
{ {
lpEventSource->LogFile = LogfListItemByIndex(i); lpLogHandle->LogFile = LogfListItemByIndex(i);
lpEventSource->CurrentRecord = LogfGetOldestRecord(lpEventSource->LogFile); lpLogHandle->CurrentRecord = LogfGetOldestRecord(lpLogHandle->LogFile);
break; break;
} }
} }
if (!lpEventSource->LogFile) if (!lpLogHandle->LogFile)
goto Cleanup; goto Cleanup;
/* Append service record */ /* Append log handle */
InsertTailList(&EventSourceListHead, &lpEventSource->EventSourceListEntry); InsertTailList(&LogHandleListHead, &lpLogHandle->LogHandleListEntry);
return lpEventSource; return lpLogHandle;
Cleanup: Cleanup:
HeapFree(GetProcessHeap(), 0, lpEventSource); HeapFree(GetProcessHeap(), 0, lpLogHandle);
return NULL; return NULL;
} }
PEVENTSOURCE ElfGetEventLogSourceEntryByHandle(IELF_HANDLE EventLogHandle) PLOGHANDLE ElfGetLogHandleEntryByHandle(IELF_HANDLE EventLogHandle)
{ {
PEVENTSOURCE CurrentEventSource; PLOGHANDLE lpLogHandle;
if (IsListEmpty(&EventSourceListHead)) if (IsListEmpty(&LogHandleListHead))
{ {
return NULL; return NULL;
} }
CurrentEventSource = CONTAINING_RECORD((PEVENTSOURCE)EventLogHandle, EVENTSOURCE, EventSourceListEntry);
return CurrentEventSource; lpLogHandle = CONTAINING_RECORD((PLOGHANDLE)EventLogHandle, LOGHANDLE, LogHandleListEntry);
return lpLogHandle;
} }
BOOL ElfDeleteEventLogHandle(IELF_HANDLE EventLogHandle) BOOL ElfDeleteEventLogHandle(IELF_HANDLE EventLogHandle)
{ {
PEVENTSOURCE lpEventSource = (PEVENTSOURCE)EventLogHandle; PLOGHANDLE lpLogHandle = (PLOGHANDLE)EventLogHandle;
if (!ElfGetEventLogSourceEntryByHandle(lpEventSource)) if (!ElfGetLogHandleEntryByHandle(lpLogHandle))
{ {
return FALSE; return FALSE;
} }
RemoveEntryList(&lpEventSource->EventSourceListEntry); RemoveEntryList(&lpLogHandle->LogHandleListEntry);
HeapFree(GetProcessHeap(),0,lpEventSource); HeapFree(GetProcessHeap(),0,lpLogHandle);
return TRUE; return TRUE;
} }
@ -177,15 +178,15 @@ NTSTATUS ElfrNumberOfRecords(
IELF_HANDLE LogHandle, IELF_HANDLE LogHandle,
DWORD *NumberOfRecords) DWORD *NumberOfRecords)
{ {
PEVENTSOURCE lpEventSource; PLOGHANDLE lpLogHandle;
lpEventSource = ElfGetEventLogSourceEntryByHandle(LogHandle); lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!lpEventSource) if (!lpLogHandle)
{ {
return STATUS_INVALID_HANDLE; return STATUS_INVALID_HANDLE;
} }
*NumberOfRecords = lpEventSource->LogFile->Header.CurrentRecordNumber; *NumberOfRecords = lpLogHandle->LogFile->Header.CurrentRecordNumber;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -196,10 +197,10 @@ NTSTATUS ElfrOldestRecord(
IELF_HANDLE LogHandle, IELF_HANDLE LogHandle,
DWORD *OldestRecordNumber) DWORD *OldestRecordNumber)
{ {
PEVENTSOURCE lpEventSource; PLOGHANDLE lpLogHandle;
lpEventSource = ElfGetEventLogSourceEntryByHandle(LogHandle); lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!lpEventSource) if (!lpLogHandle)
{ {
return STATUS_INVALID_HANDLE; return STATUS_INVALID_HANDLE;
} }
@ -210,7 +211,7 @@ NTSTATUS ElfrOldestRecord(
} }
*OldestRecordNumber = 0; *OldestRecordNumber = 0;
*OldestRecordNumber = LogfGetOldestRecord(lpEventSource->LogFile); *OldestRecordNumber = LogfGetOldestRecord(lpLogHandle->LogFile);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -306,12 +307,12 @@ NTSTATUS ElfrReadELW(
DWORD *NumberOfBytesRead, DWORD *NumberOfBytesRead,
DWORD *MinNumberOfBytesNeeded) DWORD *MinNumberOfBytesNeeded)
{ {
PEVENTSOURCE lpEventSource; PLOGHANDLE lpLogHandle;
DWORD dwError; DWORD dwError;
DWORD RecordNumber; DWORD RecordNumber;
lpEventSource = ElfGetEventLogSourceEntryByHandle(LogHandle); lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!lpEventSource) if (!lpLogHandle)
{ {
return STATUS_INVALID_HANDLE; return STATUS_INVALID_HANDLE;
} }
@ -322,20 +323,20 @@ NTSTATUS ElfrReadELW(
/* If sequential read, retrieve the CurrentRecord from this log handle */ /* If sequential read, retrieve the CurrentRecord from this log handle */
if (ReadFlags & EVENTLOG_SEQUENTIAL_READ) if (ReadFlags & EVENTLOG_SEQUENTIAL_READ)
{ {
RecordNumber = lpEventSource->CurrentRecord; RecordNumber = lpLogHandle->CurrentRecord;
} }
else else
{ {
RecordNumber = RecordOffset; RecordNumber = RecordOffset;
} }
dwError = LogfReadEvent(lpEventSource->LogFile, ReadFlags, &RecordNumber, dwError = LogfReadEvent(lpLogHandle->LogFile, ReadFlags, &RecordNumber,
NumberOfBytesToRead, Buffer, NumberOfBytesRead, MinNumberOfBytesNeeded); NumberOfBytesToRead, Buffer, NumberOfBytesRead, MinNumberOfBytesNeeded);
/* Update the handles CurrentRecord if success*/ /* Update the handles CurrentRecord if success*/
if (dwError == ERROR_SUCCESS) if (dwError == ERROR_SUCCESS)
{ {
lpEventSource->CurrentRecord = RecordNumber; lpLogHandle->CurrentRecord = RecordNumber;
} }
return I_RpcMapWin32Status(dwError); return I_RpcMapWin32Status(dwError);
@ -361,7 +362,7 @@ NTSTATUS ElfrReportEventW(
{ {
USHORT i; USHORT i;
PBYTE LogBuffer; PBYTE LogBuffer;
PEVENTSOURCE lpEventSource; PLOGHANDLE lpLogHandle;
DWORD lastRec; DWORD lastRec;
DWORD recSize; DWORD recSize;
DWORD dwStringsSize = 0; DWORD dwStringsSize = 0;
@ -369,8 +370,8 @@ NTSTATUS ElfrReportEventW(
WCHAR *lpStrings; WCHAR *lpStrings;
int pos = 0; int pos = 0;
lpEventSource = ElfGetEventLogSourceEntryByHandle(LogHandle); lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!lpEventSource) if (!lpLogHandle)
{ {
return STATUS_INVALID_HANDLE; return STATUS_INVALID_HANDLE;
} }
@ -381,7 +382,7 @@ NTSTATUS ElfrReportEventW(
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
lastRec = LogfGetCurrentRecord(lpEventSource->LogFile); lastRec = LogfGetCurrentRecord(lpLogHandle->LogFile);
for (i = 0; i < NumStrings; i++) for (i = 0; i < NumStrings; i++)
{ {
@ -428,7 +429,7 @@ NTSTATUS ElfrReportEventW(
EventType, EventType,
EventCategory, EventCategory,
EventID, EventID,
lpEventSource->szName, lpLogHandle->szName,
ComputerName->Buffer, ComputerName->Buffer,
sizeof(UserSID), sizeof(UserSID),
&UserSID, &UserSID,
@ -437,10 +438,10 @@ NTSTATUS ElfrReportEventW(
DataSize, DataSize,
Data); Data);
dwError = LogfWriteData(lpEventSource->LogFile, recSize, LogBuffer); dwError = LogfWriteData(lpLogHandle->LogFile, recSize, LogBuffer);
if (!dwError) if (!dwError)
{ {
DPRINT1("ERROR WRITING TO EventLog %S\n",lpEventSource->LogFile->FileName); DPRINT1("ERROR WRITING TO EventLog %S\n", lpLogHandle->LogFile->FileName);
} }
LogfFreeRecord(LogBuffer); LogfFreeRecord(LogBuffer);