Handle wParam in WM_PAINT properly: if non-null, it is the hdc we are
[wine] / dlls / advapi32 / eventlog.c
1 /*
2  * Win32 advapi functions
3  *
4  * Copyright 1995 Sven Verdoolaege
5  * Copyright 1998 Juergen Schmied
6  * Copyright 2003 Mike Hearn
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "winreg.h"
29 #include "winternl.h"
30
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
34 WINE_DECLARE_DEBUG_CHANNEL(eventlog);
35
36 /******************************************************************************
37  * BackupEventLogA [ADVAPI32.@]
38  *
39  * Saves the event log to a backup file.
40  *
41  * PARAMS
42  *  hEventLog        [I] Handle to event log to backup.
43  *  lpBackupFileName [I] Name of the backup file.
44  *
45  * RETURNS
46  *  Success: nonzero. File lpBackupFileName will contain the contents of
47  *           hEvenLog.
48  *  Failure: zero.
49  */
50 BOOL WINAPI BackupEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
51 {
52         FIXME("(%p,%s) stub\n", hEventLog, debugstr_a(lpBackupFileName));
53         return TRUE;
54 }
55
56 /******************************************************************************
57  * BackupEventLogW [ADVAPI32.@]
58  *
59  * see BackupEventLogA
60  */
61 BOOL WINAPI BackupEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
62 {
63         FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
64         return TRUE;
65 }
66
67 /******************************************************************************
68  * ClearEventLogA [ADVAPI32.@]
69  *
70  * Clears the event log and/or saves the log to a backup file.
71  *
72  * PARAMS
73  *  hEvenLog         [I] Handle to event log to clear.
74  *  lpBackupFileName [I] Name of the backup file.
75  *
76  * RETURNS
77  *  Success: nonzero. if lpBackupFileName != NULL, lpBackupFileName will 
78  *           contain the contents of hEvenLog and the log will be cleared.
79  *  Failure: zero. Fails if the event log is empty or if lpBackupFileName
80  *           exists.
81  */
82 BOOL WINAPI ClearEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
83 {
84         FIXME("(%p,%s) stub\n", hEventLog, debugstr_a(lpBackupFileName));
85         return TRUE;
86 }
87
88 /******************************************************************************
89  * ClearEventLogW [ADVAPI32.@]
90  *
91  * see ClearEventLogA
92  */
93 BOOL WINAPI ClearEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
94 {
95         FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
96         return TRUE;
97 }
98
99 /******************************************************************************
100  * CloseEventLog [ADVAPI32.@]
101  *
102  * Closes a read handle to the event log.
103  *
104  * PARAMS
105  *  hEventLog [I/O] Handle of the event log to close.
106  *
107  * RETURNS
108  *  Success: nonzero
109  *  Failure: zero
110  */
111 BOOL WINAPI CloseEventLog( HANDLE hEventLog )
112 {
113         FIXME("(%p) stub\n", hEventLog);
114         return TRUE;
115 }
116
117 /******************************************************************************
118  * DeregisterEventSource [ADVAPI32.@]
119  * 
120  * Closes a write handle to an event log
121  *
122  * PARAMS
123  *  hEventLog [I/O] Handle of the event log.
124  *
125  * RETURNS
126  *  Success: nonzero
127  *  Failure: zero
128  */
129 BOOL WINAPI DeregisterEventSource( HANDLE hEventLog )
130 {
131     FIXME("(%p) stub\n", hEventLog);
132     return TRUE;
133 }
134
135 /******************************************************************************
136  * GetNumberOfEventLogRecords [ADVAPI32.@]
137  *
138  * Retrieves the number of records in an event log.
139  *
140  * PARAMS
141  *  hEventLog       [I] Handle to an open event log.
142  *  NumberOfRecords [O] Number of records in the log.
143  *
144  * RETURNS
145  *  Success: nonzero. NumberOfRecords will contain the number of records in
146  *           the log.
147  *  Failure: zero
148  */
149 BOOL WINAPI GetNumberOfEventLogRecords( HANDLE hEventLog, PDWORD NumberOfRecords )
150 {
151     FIXME("(%p,%p) stub\n", hEventLog, NumberOfRecords);
152
153     if (!NumberOfRecords) return FALSE;
154     *NumberOfRecords = 0;
155
156     return TRUE;
157 }
158
159 /******************************************************************************
160  * GetOldestEventLogRecord [ADVAPI32.@]
161  *
162  * Retrieves the absolute record number of the oldest record in an even log.
163  *
164  * PARAMS
165  *  hEventLog    [I] Handle to an open event log.
166  *  OldestRecord [O] Absolute record number of the oldest record.
167  *
168  * RETURNS
169  *  Success: nonzero. OldestRecord contains the record number of the oldest
170  *           record in the log.
171  *  Failure: zero 
172  */
173 BOOL WINAPI GetOldestEventLogRecord( HANDLE hEventLog, PDWORD OldestRecord )
174 {
175     FIXME("(%p,%p) stub\n", hEventLog, OldestRecord);
176
177     if (!OldestRecord) return FALSE;
178     *OldestRecord = 0;
179
180     return TRUE;
181 }
182
183 /******************************************************************************
184  * NotifyChangeEventLog [ADVAPI32.@]
185  *
186  * Enables an application to receive notification when an event is written
187  * to an event log.
188  *
189  * PARAMS
190  *  hEventLog [I] Handle to an event log.
191  *  hEvent    [I] Handle to a manual-reset event object.
192  *
193  * RETURNS
194  *  Success: nonzero
195  *  Failure: zero
196  */
197 BOOL WINAPI NotifyChangeEventLog( HANDLE hEventLog, HANDLE hEvent )
198 {
199         FIXME("(%p,%p) stub\n", hEventLog, hEvent);
200         return TRUE;
201 }
202
203 /******************************************************************************
204  * OpenBackupEventLogA [ADVAPI32.@]
205  *
206  * Opens a handle to a backup event log.
207  *
208  * PARAMS
209  *  lpUNCServerName [I] Universal Naming Convention name of the server on which
210  *                      this will be performed.
211  *  lpFileName      [I] Specifies the name of the backup file.
212  *
213  * RETURNS
214  *  Success: Handle to the backup event log.
215  *  Failure: NULL
216  */
217 HANDLE WINAPI OpenBackupEventLogA( LPCSTR lpUNCServerName, LPCSTR lpFileName )
218 {
219         FIXME("(%s,%s) stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpFileName));
220         return (HANDLE)0xcafe4242;
221 }
222
223 /******************************************************************************
224  * OpenBackupEventLogW [ADVAPI32.@]
225  *
226  * see OpenBackupEventLogA
227  */
228 HANDLE WINAPI OpenBackupEventLogW( LPCWSTR lpUNCServerName, LPCWSTR lpFileName )
229 {
230         FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
231         return (HANDLE)0xcafe4242;
232 }
233
234 /******************************************************************************
235  * OpenEventLogA [ADVAPI32.@]
236  *
237  * Opens a handle to the specified event log.
238  *
239  * PARAMS
240  *  lpUNCServerName [I] UNC name of the server on which the event log is
241  *                      opened.
242  *  lpSourceName    [I] Name of the log.
243  *
244  * RETURNS
245  *  Success: Handle to an event log.
246  *  Failure: NULL
247  */
248 HANDLE WINAPI OpenEventLogA( LPCSTR uncname, LPCSTR source )
249 {
250         FIXME("(%s,%s) stub\n", debugstr_a(uncname), debugstr_a(source));
251         return (HANDLE)0xcafe4242;
252 }
253
254 /******************************************************************************
255  * OpenEventLogW [ADVAPI32.@]
256  *
257  * see OpenEventLogA
258  */
259 HANDLE WINAPI OpenEventLogW( LPCWSTR uncname, LPCWSTR source )
260 {
261         FIXME("(%s,%s) stub\n", debugstr_w(uncname), debugstr_w(source));
262         return (HANDLE)0xcafe4242;
263 }
264
265 /******************************************************************************
266  * ReadEventLogA [ADVAPI32.@]
267  *
268  * Reads a whole number of entries from an event log.
269  *
270  * PARAMS
271  *  hEventLog                [I] Handle of the event log to read.
272  *  dwReadFlags              [I] see MSDN doc.
273  *  dwRecordOffset           [I] Log-entry record number to start at.
274  *  lpBuffer                 [O] Buffer for the data read.
275  *  nNumberOfBytesToRead     [I] Size of lpBuffer.
276  *  pnBytesRead              [O] Receives number of bytes read.
277  *  pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
278  *                               next log entry.
279  *
280  * RETURNS
281  *  Success: nonzero
282  *  Failure: zero
283  */
284 BOOL WINAPI ReadEventLogA( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
285     LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
286 {
287     FIXME("(%p,0x%08lx,0x%08lx,%p,0x%08lx,%p,%p) stub\n", hEventLog, dwReadFlags,
288           dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
289     return FALSE;
290 }
291
292 /******************************************************************************
293  * ReadEventLogW [ADVAPI32.@]
294  *
295  * see ReadEventLogA
296  */
297 BOOL WINAPI ReadEventLogW( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
298     LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
299 {
300     FIXME("(%p,0x%08lx,0x%08lx,%p,0x%08lx,%p,%p) stub\n", hEventLog, dwReadFlags,
301           dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
302     return FALSE;
303 }
304
305 /******************************************************************************
306  * RegisterEventSourceA [ADVAPI32.@]
307  *
308  * Returns a registered handle to an event log.
309  *
310  * PARAMS
311  *  lpUNCServerName [I] UNC name of the source server.
312  *  lpSourceName    [I] Specifies the name of the event source to retrieve.
313  *
314  * RETURNS
315  *  Success: Handle to the event log.
316  *  Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
317  *           Security event log.
318  */
319 HANDLE WINAPI RegisterEventSourceA( LPCSTR lpUNCServerName, LPCSTR lpSourceName )
320 {
321     UNICODE_STRING lpUNCServerNameW;
322     UNICODE_STRING lpSourceNameW;
323     HANDLE ret;
324
325     FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpSourceName));
326
327     RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW, lpUNCServerName);
328     RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW, lpSourceName);
329     ret = RegisterEventSourceW(lpUNCServerNameW.Buffer,lpSourceNameW.Buffer);
330     RtlFreeUnicodeString (&lpUNCServerNameW);
331     RtlFreeUnicodeString (&lpSourceNameW);
332     return ret;
333 }
334
335 /******************************************************************************
336  * RegisterEventSourceW [ADVAPI32.@]
337  *
338  * see RegisterEventSourceA
339  */
340 HANDLE WINAPI RegisterEventSourceW( LPCWSTR lpUNCServerName, LPCWSTR lpSourceName )
341 {
342     FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
343     return (HANDLE)0xcafe4242;
344 }
345
346 /******************************************************************************
347  * ReportEventA [ADVAPI32.@]
348  *
349  * Writes an entry at the end of an event log.
350  *
351  * PARAMS
352  *  hEventLog   [I] Handle of an event log.
353  *  wType       [I] See MSDN doc.
354  *  wCategory   [I] Event category.
355  *  dwEventID   [I] Event identifier.
356  *  lpUserSid   [I] Current user's security identifier.
357  *  wNumStrings [I] Number of insert strings in lpStrings.
358  *  dwDataSize  [I] Size of event-specific raw data to write.
359  *  lpStrings   [I] Buffer containing an array of string to be merged.
360  *  lpRawData   [I] Buffer containing the binary data.
361  *
362  * RETURNS
363  *  Success: nonzero. Entry was written to the log.
364  *  Failure: zero.
365  *
366  * NOTES
367  *  The ReportEvent function adds the time, the entry's length, and the
368  *  offsets before storing the entry in the log. If lpUserSid != NULL, the
369  *  username is also logged.
370  */
371 BOOL WINAPI ReportEventA ( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
372     PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR *lpStrings, LPVOID lpRawData)
373 {
374     LPCWSTR *wideStrArray;
375     UNICODE_STRING str;
376     int i;
377     BOOL ret;
378
379     FIXME("(%p,0x%04x,0x%04x,0x%08lx,%p,0x%04x,0x%08lx,%p,%p): stub\n", hEventLog,
380           wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
381
382     if (wNumStrings == 0) return TRUE;
383     if (!lpStrings) return TRUE;
384
385     wideStrArray = HeapAlloc(GetProcessHeap(), 0, sizeof(LPCWSTR) * wNumStrings);
386     for (i = 0; i < wNumStrings; i++)
387     {
388         RtlCreateUnicodeStringFromAsciiz(&str, lpStrings[i]);
389         wideStrArray[i] = str.Buffer;
390     }
391     ret = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid,
392                        wNumStrings, dwDataSize, wideStrArray, lpRawData);
393     for (i = 0; i < wNumStrings; i++)
394     {
395         HeapFree( GetProcessHeap(), 0, (LPSTR)wideStrArray[i] );
396     }
397     HeapFree(GetProcessHeap(), 0, wideStrArray);
398     return ret;
399 }
400
401 /******************************************************************************
402  * ReportEventW [ADVAPI32.@]
403  *
404  * see ReportEventA
405  */
406 BOOL WINAPI ReportEventW( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
407     PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCWSTR *lpStrings, LPVOID lpRawData )
408 {
409     int i;
410
411     FIXME("(%p,0x%04x,0x%04x,0x%08lx,%p,0x%04x,0x%08lx,%p,%p): stub\n", hEventLog,
412           wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
413
414     /* partial stub */
415
416     if (wNumStrings == 0) return TRUE;
417     if (!lpStrings) return TRUE;
418
419     for (i = 0; i < wNumStrings; i++)
420     {
421         switch (wType)
422         {
423         case EVENTLOG_SUCCESS:
424             TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
425             break;
426         case EVENTLOG_ERROR_TYPE:
427             ERR_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
428             break;
429         case EVENTLOG_WARNING_TYPE:
430             WARN_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
431             break;
432         default:
433             TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
434             break;
435         }
436     }
437     return TRUE;
438 }