c9a7cf89474fa7305ef7cb6712899054e32bf5e4
[reactos.git] / reactos / base / services / eventlog / eventlog.h
1 /*
2 * PROJECT: ReactOS kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: services/eventlog/eventlog.h
5 * PURPOSE: Event logging service
6 * COPYRIGHT: Copyright 2005 Saveliy Tretiakov
7 */
8
9 #ifndef __EVENTLOG_H__
10 #define __EVENTLOG_H__
11
12 #define NDEBUG
13 #define WIN32_NO_STATUS
14
15 #include <windows.h>
16 #include <lpctypes.h>
17 #include <lpcfuncs.h>
18 #include <rtlfuncs.h>
19 #include <obfuncs.h>
20 #include <iotypes.h>
21 #include <debug.h>
22 #include "eventlogrpc_s.h"
23
24 typedef struct _IO_ERROR_LPC
25 {
26 PORT_MESSAGE Header;
27 IO_ERROR_LOG_MESSAGE Message;
28 } IO_ERROR_LPC, *PIO_ERROR_LPC;
29
30 #define MAJORVER 1
31 #define MINORVER 1
32
33 /*
34 * Our file format will be compatible with NT's
35 */
36 #define LOGFILE_SIGNATURE 0x654c664c
37
38 /*
39 * Flags used in logfile header
40 */
41 #define ELF_LOGFILE_HEADER_DIRTY 1
42 #define ELF_LOGFILE_HEADER_WRAP 2
43 #define ELF_LOGGFILE_LOGFULL_WRITTEN 4
44 #define ELF_LOGFILE_ARCHIVE_SET 8
45
46 /* FIXME: MSDN reads that the following two structs are in winnt.h. Are they? */
47 typedef struct _EVENTLOGHEADER
48 {
49 ULONG HeaderSize;
50 ULONG Signature;
51 ULONG MajorVersion;
52 ULONG MinorVersion;
53 ULONG StartOffset;
54 ULONG EndOffset;
55 ULONG CurrentRecordNumber;
56 ULONG OldestRecordNumber;
57 ULONG MaxSize;
58 ULONG Flags;
59 ULONG Retention;
60 ULONG EndHeaderSize;
61 } EVENTLOGHEADER, *PEVENTLOGHEADER;
62
63 typedef struct _EVENTLOGEOF
64 {
65 ULONG RecordSizeBeginning;
66 ULONG Ones;
67 ULONG Twos;
68 ULONG Threes;
69 ULONG Fours;
70 ULONG BeginRecord;
71 ULONG EndRecord;
72 ULONG CurrentRecordNumber;
73 ULONG OldestRecordNumber;
74 ULONG RecordSizeEnd;
75 } EVENTLOGEOF, *PEVENTLOGEOF;
76
77 typedef struct _EVENT_OFFSET_INFO
78 {
79 ULONG EventNumber;
80 ULONG EventOffset;
81 } EVENT_OFFSET_INFO, *PEVENT_OFFSET_INFO;
82
83 typedef struct _LOGFILE
84 {
85 HANDLE hFile;
86 EVENTLOGHEADER Header;
87 WCHAR *LogName;
88 WCHAR *FileName;
89 CRITICAL_SECTION cs;
90 PEVENT_OFFSET_INFO OffsetInfo;
91 ULONG OffsetInfoSize;
92 ULONG OffsetInfoNext;
93 LIST_ENTRY ListEntry;
94 } LOGFILE, *PLOGFILE;
95
96 typedef struct _EVENTSOURCE
97 {
98 LIST_ENTRY EventSourceListEntry;
99 PLOGFILE LogFile;
100 WCHAR szName[1];
101 } EVENTSOURCE, *PEVENTSOURCE;
102
103 typedef struct _LOGHANDLE
104 {
105 LIST_ENTRY LogHandleListEntry;
106 PEVENTSOURCE EventSource;
107 PLOGFILE LogFile;
108 ULONG CurrentRecord;
109 WCHAR szName[1];
110 } LOGHANDLE, *PLOGHANDLE;
111
112 /* file.c */
113 VOID LogfListInitialize(VOID);
114
115 PLOGFILE LogfListHead(VOID);
116
117 INT LogfListItemCount(VOID);
118
119 PLOGFILE LogfListItemByIndex(INT Index);
120
121 PLOGFILE LogfListItemByName(WCHAR * Name);
122
123 INT LogfListItemIndexByName(WCHAR * Name);
124
125 VOID LogfListAddItem(PLOGFILE Item);
126
127 VOID LogfListRemoveItem(PLOGFILE Item);
128
129 DWORD LogfReadEvent(PLOGFILE LogFile,
130 DWORD Flags,
131 DWORD * RecordNumber,
132 DWORD BufSize,
133 PBYTE Buffer,
134 DWORD * BytesRead,
135 DWORD * BytesNeeded);
136
137 BOOL LogfWriteData(PLOGFILE LogFile,
138 DWORD BufSize,
139 PBYTE Buffer);
140
141 PLOGFILE LogfCreate(WCHAR * LogName,
142 WCHAR * FileName);
143
144 VOID LogfClose(PLOGFILE LogFile);
145
146 VOID LogfCloseAll(VOID);
147
148 BOOL LogfInitializeNew(PLOGFILE LogFile);
149
150 BOOL LogfInitializeExisting(PLOGFILE LogFile);
151
152 DWORD LogfGetOldestRecord(PLOGFILE LogFile);
153
154 DWORD LogfGetCurrentRecord(PLOGFILE LogFile);
155
156 ULONG LogfOffsetByNumber(PLOGFILE LogFile,
157 DWORD RecordNumber);
158
159 BOOL LogfAddOffsetInformation(PLOGFILE LogFile,
160 ULONG ulNumber,
161 ULONG ulOffset);
162
163 BOOL LogfDeleteOffsetInformation(PLOGFILE LogFile,
164 ULONG ulNumber);
165
166 PBYTE LogfAllocAndBuildNewRecord(LPDWORD lpRecSize,
167 DWORD dwRecordNumber,
168 WORD wType,
169 WORD wCategory,
170 DWORD dwEventId,
171 LPCWSTR SourceName,
172 LPCWSTR ComputerName,
173 DWORD dwSidLength,
174 PSID lpUserSid,
175 WORD wNumStrings,
176 WCHAR * lpStrings,
177 DWORD dwDataSize,
178 LPVOID lpRawData);
179
180 /* eventlog.c */
181 extern HANDLE MyHeap;
182
183 VOID PRINT_HEADER(PEVENTLOGHEADER header);
184
185 VOID PRINT_RECORD(PEVENTLOGRECORD pRec);
186
187 VOID EventTimeToSystemTime(DWORD EventTime,
188 SYSTEMTIME * SystemTime);
189
190 VOID SystemTimeToEventTime(SYSTEMTIME * pSystemTime,
191 DWORD * pEventTime);
192
193 /* eventsource.c */
194 VOID InitEventSourceList(VOID);
195
196 BOOL
197 LoadEventSources(HKEY hKey,
198 PLOGFILE pLogFile);
199
200 PEVENTSOURCE
201 GetEventSourceByName(LPCWSTR Name);
202
203
204 /* logport.c */
205 NTSTATUS WINAPI PortThreadRoutine(PVOID Param);
206
207 NTSTATUS InitLogPort(VOID);
208
209 NTSTATUS ProcessPortMessage(VOID);
210
211 /* rpc.c */
212 DWORD WINAPI RpcThreadRoutine(LPVOID lpParameter);
213
214 static __inline void LogfFreeRecord(LPVOID Rec)
215 {
216 HeapFree(MyHeap, 0, Rec);
217 }
218
219 #endif /* __EVENTLOG_H__ */