Author: tretiakov Date: Fri Jun 30 18:53:24 2006 New Revision: 22712
URL: http://svn.reactos.org/svn/reactos?rev=22712&view=rev Log: Read configuration from registry
Modified: trunk/reactos/base/services/eventlog/eventlog.c trunk/reactos/base/services/eventlog/eventlog.h trunk/reactos/base/services/eventlog/file.c trunk/reactos/base/services/eventlog/logport.c
Modified: trunk/reactos/base/services/eventlog/eventlog.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/even... ============================================================================== --- trunk/reactos/base/services/eventlog/eventlog.c (original) +++ trunk/reactos/base/services/eventlog/eventlog.c Fri Jun 30 18:53:24 2006 @@ -7,25 +7,25 @@ * Copyright 2005 Saveliy Tretiakov */
+/* INCLUDES *****************************************************************/
#include "eventlog.h"
+/* GLOBALS ******************************************************************/ + VOID CALLBACK ServiceMain(DWORD argc, LPTSTR *argv); - SERVICE_TABLE_ENTRY ServiceTable[2] = { {L"EventLog", (LPSERVICE_MAIN_FUNCTION)ServiceMain}, {NULL, NULL} };
-/* GLOBAL VARIABLES */ HANDLE MyHeap = NULL; -PLOGFILE SystemLog = NULL; -PLOGFILE ApplicationLog = NULL; -PLOGFILE SecurityLog = NULL; BOOL onLiveCD = FALSE; // On livecd events will go to debug output only - extern CRITICAL_SECTION LogListCs; +extern PLOGFILE LogListHead; + +/* FUNCTIONS ****************************************************************/
VOID CALLBACK ServiceMain(DWORD argc, LPTSTR *argv) { @@ -56,23 +56,146 @@ #endif }
- -int main(int argc, char *argv[]) +BOOL LoadLogFile(HKEY hKey, WCHAR *LogName) +{ + DWORD MaxValueLen, ValueLen, Type, ExpandedLen; + WCHAR *Buf = NULL, *Expanded = NULL; + LONG Result; + BOOL ret = FALSE; + PLOGFILE pLogf; + + DPRINT("LoadLogFile: %S\n", LogName); + + RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, &MaxValueLen, NULL, NULL); + + Buf = HeapAlloc(MyHeap, 0, MaxValueLen); + + if(!Buf) + { + DPRINT1("Can't allocate heap!\n"); + return FALSE; + } + + ValueLen = MaxValueLen; + + Result = RegQueryValueEx(hKey, L"File", + NULL, + &Type, + (LPBYTE)Buf, + &ValueLen); + + if(Result != ERROR_SUCCESS) + { + DPRINT1("RegQueryValueEx failed: %d\n", GetLastError()); + goto cleanup; + } + if(Type != REG_EXPAND_SZ && Type != REG_SZ) + { + DPRINT1("%S\File - value of wrong type %x.\n", LogName, Type); + goto cleanup; + } + + ExpandedLen = ExpandEnvironmentStrings(Buf, NULL, 0); + Expanded = HeapAlloc(MyHeap, 0, ExpandedLen*sizeof(WCHAR)); + + if(!Expanded) + { + DPRINT1("Can't allocate heap!\n"); + goto cleanup; + } + + ExpandEnvironmentStrings(Buf, Expanded, ExpandedLen); + + DPRINT("%S -> %S\n", Buf, Expanded); + + pLogf = LogfCreate(LogName, Expanded); + + if(pLogf == NULL) + { + DPRINT1("Failed to create %S!\n", Expanded); + goto cleanup; + } + + ret = TRUE; + +cleanup: + HeapFree(MyHeap, 0, Buf); + if(Expanded) HeapFree(MyHeap, 0, Expanded); + return ret; +} + +BOOL LoadLogFiles(HKEY eventlogKey) +{ + LONG result; + DWORD MaxLognameLen, LognameLen; + WCHAR *Buf = NULL; + BOOL ret = FALSE; + INT i; + + RegQueryInfoKey(eventlogKey, NULL, NULL, NULL, NULL, &MaxLognameLen, + NULL, NULL, NULL, NULL, NULL, NULL); + + MaxLognameLen++; + + Buf = HeapAlloc(MyHeap, 0, MaxLognameLen*sizeof(WCHAR)); + + if(!Buf) + { + DPRINT1("Error: can't allocate heap!\n"); + return ret; + } + + i = 0; + LognameLen=MaxLognameLen; + + while(RegEnumKeyEx(eventlogKey, i, Buf, &LognameLen, NULL, NULL, + NULL, NULL) == ERROR_SUCCESS) + { + HKEY SubKey; + DPRINT("%S\n", Buf); + + result = RegOpenKeyEx(eventlogKey, Buf, 0, KEY_ALL_ACCESS, &SubKey); + if(result != ERROR_SUCCESS) + { + DPRINT1("Failed to open %S key.\n", Buf); + goto cleanup; + } + + if(!LoadLogFile(SubKey, Buf)) + DPRINT1("Failed to load %S\n", Buf); + else DPRINT("Loaded %S\n", Buf); + + RegCloseKey(SubKey); + LognameLen=MaxLognameLen; + i++; + } + + ret = TRUE; + +cleanup: + HeapFree(MyHeap, 0, Buf); + return ret; +} + +INT main() { WCHAR LogPath[MAX_PATH]; + PLOGFILE pLogf; + INT RetCode = 0; + LONG result; + HKEY elogKey; + + InitializeCriticalSection(&LogListCs); + MyHeap = HeapCreate(0, 1024*256, 0);
if(MyHeap==NULL) { - DbgPrint("EventLog: FATAL ERROR, can't create heap.\n"); - return 1; - } - - InitializeCriticalSection(&LogListCs); - - /* - This will be fixed in near future - */ + DPRINT1("FATAL ERROR, can't create heap.\n"); + RetCode = 1; + goto bye_bye; + } GetWindowsDirectory(LogPath, MAX_PATH); if(GetDriveType(LogPath) == DRIVE_CDROM) @@ -82,38 +205,34 @@ } else { - lstrcat(LogPath, L"\system32\config\SysEvent.evt"); - - SystemLog = LogfCreate(L"System", LogPath); - - if(SystemLog == NULL) + result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + L"SYSTEM\CurrentControlSet\Services\EventLog", + 0, + KEY_ALL_ACCESS, + &elogKey); + + if(result != ERROR_SUCCESS) { - DbgPrint("EventLog: FATAL ERROR, can't create %S\n", LogPath); - HeapDestroy(MyHeap); - return 1; + DPRINT1("Fatal error: can't open eventlog registry key.\n"); + RetCode = 1; + goto bye_bye; } - - GetWindowsDirectory(LogPath, MAX_PATH); - lstrcat(LogPath, L"\system32\config\AppEvent.evt"); - - ApplicationLog = LogfCreate(L"Application", LogPath); - - if(ApplicationLog == NULL) - { - DbgPrint("EventLog: FATAL ERROR, can't create %S\n", LogPath); - HeapDestroy(MyHeap); - return 1; - } + + LoadLogFiles(elogKey); }
StartServiceCtrlDispatcher(ServiceTable);
- - LogfClose(SystemLog); +bye_bye: DeleteCriticalSection(&LogListCs); - HeapDestroy(MyHeap); - - return 0; + + // Close all log files. + for(pLogf = LogListHead; pLogf; pLogf = ((PLOGFILE)pLogf)->Next) + LogfClose(pLogf); + + if(MyHeap) HeapDestroy(MyHeap); + + return RetCode; }
VOID EventTimeToSystemTime(DWORD EventTime, @@ -238,6 +357,3 @@
DPRINT("Length2=%d\n", *(PDWORD)(((PBYTE)pRec)+pRec->Length-4)); } - - -
Modified: trunk/reactos/base/services/eventlog/eventlog.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/even... ============================================================================== --- trunk/reactos/base/services/eventlog/eventlog.h (original) +++ trunk/reactos/base/services/eventlog/eventlog.h Fri Jun 30 18:53:24 2006 @@ -11,6 +11,7 @@ #define __EVENTLOG_H__
#define WIN32_NO_STATUS + #include <windows.h> #include <lpctypes.h> #include <lpcfuncs.h>
Modified: trunk/reactos/base/services/eventlog/file.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/file... ============================================================================== --- trunk/reactos/base/services/eventlog/file.c (original) +++ trunk/reactos/base/services/eventlog/file.c Fri Jun 30 18:53:24 2006 @@ -300,7 +300,7 @@ EnterCriticalSection(&LogListCs);
for(Item = LogListHead; Item; Item = (PLOGFILE)Item->Next) - if(Item->LogName && lstrcmpW(Item->LogName, Name)==0) + if(Item->LogName && lstrcmpi(Item->LogName, Name)==0) { Ret = Item; break; @@ -319,7 +319,7 @@ EnterCriticalSection(&LogListCs);
for(Item = LogListHead; Item; i++, Item = (PLOGFILE)Item->Next) - if(Item->LogName && lstrcmpW(Item->LogName, Name)==0) + if(Item->LogName && lstrcmpi(Item->LogName, Name)==0) { ret = i; break;
Modified: trunk/reactos/base/services/eventlog/logport.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/logp... ============================================================================== --- trunk/reactos/base/services/eventlog/logport.c (original) +++ trunk/reactos/base/services/eventlog/logport.c Fri Jun 30 18:53:24 2006 @@ -15,7 +15,6 @@
HANDLE ConnectPortHandle = NULL; HANDLE MessagePortHandle = NULL; -extern PLOGFILE SystemLog; extern HANDLE MyHeap; extern BOOL onLiveCD;
@@ -125,10 +124,10 @@ NTSTATUS Status; PLOGFILE SystemLog = NULL;
- DPRINT1("ProcessPortMessage() called\n"); - - Status = STATUS_SUCCESS; - + DPRINT("ProcessPortMessage() called\n"); + + SystemLog = LogfListItemByName(L"System"); + while(TRUE) { Status = NtReplyWaitReceivePort( @@ -217,4 +216,3 @@ } return Status; } -