Provide minimal API documentation in advapi/eventlog.c to silence some
[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 #include "wmistr.h"
31 #include "evntrace.h"
32
33 #include "wine/debug.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
36 WINE_DECLARE_DEBUG_CHANNEL(eventlog);
37
38 /******************************************************************************
39  * BackupEventLogA [ADVAPI32.@]
40  *
41  * Saves the event log to a backup file.
42  *
43  * PARAMS
44  *  hEventLog        [I] Handle to event log to backup.
45  *  lpBackupFileName [I] Name of the backup file.
46  *
47  * RETURNS
48  *  Success: nonzero. File lpBackupFileName will contain the contents of
49  *           hEvenLog.
50  *  Failure: zero.
51  */
52 BOOL WINAPI BackupEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
53 {
54         FIXME("(%p,%s) stub\n", hEventLog, debugstr_a(lpBackupFileName));
55         return TRUE;
56 }
57
58 /******************************************************************************
59  * BackupEventLogW [ADVAPI32.@]
60  *
61  * see BackupEventLogA
62  */
63 BOOL WINAPI BackupEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
64 {
65         FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
66         return TRUE;
67 }
68
69 /******************************************************************************
70  * ClearEventLogA [ADVAPI32.@]
71  *
72  * Clears the event log and/or saves the log to a backup file.
73  *
74  * PARAMS
75  *  hEvenLog         [I] Handle to event log to clear.
76  *  lpBackupFileName [I] Name of the backup file.
77  *
78  * RETURNS
79  *  Success: nonzero. if lpBackupFileName != NULL, lpBackupFileName will 
80  *           contain the contents of hEvenLog and the log will be cleared.
81  *  Failure: zero. Fails if the event log is empty or if lpBackupFileName
82  *           exists.
83  */
84 BOOL WINAPI ClearEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
85 {
86         FIXME("(%p,%s) stub\n", hEventLog, debugstr_a(lpBackupFileName));
87         return TRUE;
88 }
89
90 /******************************************************************************
91  * ClearEventLogW [ADVAPI32.@]
92  *
93  * see ClearEventLogA
94  */
95 BOOL WINAPI ClearEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
96 {
97         FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
98         return TRUE;
99 }
100
101 /******************************************************************************
102  * CloseEventLog [ADVAPI32.@]
103  *
104  * Closes a read handle to the event log.
105  *
106  * PARAMS
107  *  hEventLog [I/O] Handle of the event log to close.
108  *
109  * RETURNS
110  *  Success: nonzero
111  *  Failure: zero
112  */
113 BOOL WINAPI CloseEventLog( HANDLE hEventLog )
114 {
115         FIXME("(%p) stub\n", hEventLog);
116         return TRUE;
117 }
118
119 /******************************************************************************
120  * DeregisterEventSource [ADVAPI32.@]
121  * 
122  * Closes a write handle to an event log
123  *
124  * PARAMS
125  *  hEventLog [I/O] Handle of the event log.
126  *
127  * RETURNS
128  *  Success: nonzero
129  *  Failure: zero
130  */
131 BOOL WINAPI DeregisterEventSource( HANDLE hEventLog )
132 {
133     FIXME("(%p) stub\n", hEventLog);
134     return TRUE;
135 }
136
137 /******************************************************************************
138  * GetNumberOfEventLogRecords [ADVAPI32.@]
139  *
140  * Retrieves the number of records in an event log.
141  *
142  * PARAMS
143  *  hEventLog       [I] Handle to an open event log.
144  *  NumberOfRecords [O] Number of records in the log.
145  *
146  * RETURNS
147  *  Success: nonzero. NumberOfRecords will contain the number of records in
148  *           the log.
149  *  Failure: zero
150  */
151 BOOL WINAPI GetNumberOfEventLogRecords( HANDLE hEventLog, PDWORD NumberOfRecords )
152 {
153     FIXME("(%p,%p) stub\n", hEventLog, NumberOfRecords);
154
155     if (!NumberOfRecords) return FALSE;
156     *NumberOfRecords = 0;
157
158     return TRUE;
159 }
160
161 /******************************************************************************
162  * GetOldestEventLogRecord [ADVAPI32.@]
163  *
164  * Retrieves the absolute record number of the oldest record in an even log.
165  *
166  * PARAMS
167  *  hEventLog    [I] Handle to an open event log.
168  *  OldestRecord [O] Absolute record number of the oldest record.
169  *
170  * RETURNS
171  *  Success: nonzero. OldestRecord contains the record number of the oldest
172  *           record in the log.
173  *  Failure: zero 
174  */
175 BOOL WINAPI GetOldestEventLogRecord( HANDLE hEventLog, PDWORD OldestRecord )
176 {
177     FIXME("(%p,%p) stub\n", hEventLog, OldestRecord);
178
179     if (!OldestRecord) return FALSE;
180     *OldestRecord = 0;
181
182     return TRUE;
183 }
184
185 /******************************************************************************
186  * NotifyChangeEventLog [ADVAPI32.@]
187  *
188  * Enables an application to receive notification when an event is written
189  * to an event log.
190  *
191  * PARAMS
192  *  hEventLog [I] Handle to an event log.
193  *  hEvent    [I] Handle to a manual-reset event object.
194  *
195  * RETURNS
196  *  Success: nonzero
197  *  Failure: zero
198  */
199 BOOL WINAPI NotifyChangeEventLog( HANDLE hEventLog, HANDLE hEvent )
200 {
201         FIXME("(%p,%p) stub\n", hEventLog, hEvent);
202         return TRUE;
203 }
204
205 /******************************************************************************
206  * OpenBackupEventLogA [ADVAPI32.@]
207  *
208  * Opens a handle to a backup event log.
209  *
210  * PARAMS
211  *  lpUNCServerName [I] Universal Naming Convention name of the server on which
212  *                      this will be performed.
213  *  lpFileName      [I] Specifies the name of the backup file.
214  *
215  * RETURNS
216  *  Success: Handle to the backup event log.
217  *  Failure: NULL
218  */
219 HANDLE WINAPI OpenBackupEventLogA( LPCSTR lpUNCServerName, LPCSTR lpFileName )
220 {
221         FIXME("(%s,%s) stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpFileName));
222         return (HANDLE)0xcafe4242;
223 }
224
225 /******************************************************************************
226  * OpenBackupEventLogW [ADVAPI32.@]
227  *
228  * see OpenBackupEventLogA
229  */
230 HANDLE WINAPI OpenBackupEventLogW( LPCWSTR lpUNCServerName, LPCWSTR lpFileName )
231 {
232         FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
233         return (HANDLE)0xcafe4242;
234 }
235
236 /******************************************************************************
237  * OpenEventLogA [ADVAPI32.@]
238  *
239  * Opens a handle to the specified event log.
240  *
241  * PARAMS
242  *  lpUNCServerName [I] UNC name of the server on which the event log is
243  *                      opened.
244  *  lpSourceName    [I] Name of the log.
245  *
246  * RETURNS
247  *  Success: Handle to an event log.
248  *  Failure: NULL
249  */
250 HANDLE WINAPI OpenEventLogA( LPCSTR uncname, LPCSTR source )
251 {
252         FIXME("(%s,%s) stub\n", debugstr_a(uncname), debugstr_a(source));
253         return (HANDLE)0xcafe4242;
254 }
255
256 /******************************************************************************
257  * OpenEventLogW [ADVAPI32.@]
258  *
259  * see OpenEventLogA
260  */
261 HANDLE WINAPI OpenEventLogW( LPCWSTR uncname, LPCWSTR source )
262 {
263         FIXME("(%s,%s) stub\n", debugstr_w(uncname), debugstr_w(source));
264         return (HANDLE)0xcafe4242;
265 }
266
267 /******************************************************************************
268  * ReadEventLogA [ADVAPI32.@]
269  *
270  * Reads a whole number of entries from an event log.
271  *
272  * PARAMS
273  *  hEventLog                [I] Handle of the event log to read.
274  *  dwReadFlags              [I] see MSDN doc.
275  *  dwRecordOffset           [I] Log-entry record number to start at.
276  *  lpBuffer                 [O] Buffer for the data read.
277  *  nNumberOfBytesToRead     [I] Size of lpBuffer.
278  *  pnBytesRead              [O] Receives number of bytes read.
279  *  pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
280  *                               next log entry.
281  *
282  * RETURNS
283  *  Success: nonzero
284  *  Failure: zero
285  */
286 BOOL WINAPI ReadEventLogA( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
287     LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
288 {
289     FIXME("(%p,0x%08lx,0x%08lx,%p,0x%08lx,%p,%p) stub\n", hEventLog, dwReadFlags,
290           dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
291     return FALSE;
292 }
293
294 /******************************************************************************
295  * ReadEventLogW [ADVAPI32.@]
296  *
297  * see ReadEventLogA
298  */
299 BOOL WINAPI ReadEventLogW( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
300     LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
301 {
302     FIXME("(%p,0x%08lx,0x%08lx,%p,0x%08lx,%p,%p) stub\n", hEventLog, dwReadFlags,
303           dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
304     return FALSE;
305 }
306
307 /******************************************************************************
308  * RegisterEventSourceA [ADVAPI32.@]
309  *
310  * Returns a registered handle to an event log.
311  *
312  * PARAMS
313  *  lpUNCServerName [I] UNC name of the source server.
314  *  lpSourceName    [I] Specifies the name of the event source to retrieve.
315  *
316  * RETURNS
317  *  Success: Handle to the event log.
318  *  Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
319  *           Security event log.
320  */
321 HANDLE WINAPI RegisterEventSourceA( LPCSTR lpUNCServerName, LPCSTR lpSourceName )
322 {
323     UNICODE_STRING lpUNCServerNameW;
324     UNICODE_STRING lpSourceNameW;
325     HANDLE ret;
326
327     FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpSourceName));
328
329     RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW, lpUNCServerName);
330     RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW, lpSourceName);
331     ret = RegisterEventSourceW(lpUNCServerNameW.Buffer,lpSourceNameW.Buffer);
332     RtlFreeUnicodeString (&lpUNCServerNameW);
333     RtlFreeUnicodeString (&lpSourceNameW);
334     return ret;
335 }
336
337 /******************************************************************************
338  * RegisterEventSourceW [ADVAPI32.@]
339  *
340  * see RegisterEventSourceA
341  */
342 HANDLE WINAPI RegisterEventSourceW( LPCWSTR lpUNCServerName, LPCWSTR lpSourceName )
343 {
344     FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
345     return (HANDLE)0xcafe4242;
346 }
347
348 /******************************************************************************
349  * ReportEventA [ADVAPI32.@]
350  *
351  * Writes an entry at the end of an event log.
352  *
353  * PARAMS
354  *  hEventLog   [I] Handle of an event log.
355  *  wType       [I] See MSDN doc.
356  *  wCategory   [I] Event category.
357  *  dwEventID   [I] Event identifier.
358  *  lpUserSid   [I] Current user's security identifier.
359  *  wNumStrings [I] Number of insert strings in lpStrings.
360  *  dwDataSize  [I] Size of event-specific raw data to write.
361  *  lpStrings   [I] Buffer containing an array of string to be merged.
362  *  lpRawData   [I] Buffer containing the binary data.
363  *
364  * RETURNS
365  *  Success: nonzero. Entry was written to the log.
366  *  Failure: zero.
367  *
368  * NOTES
369  *  The ReportEvent function adds the time, the entry's length, and the
370  *  offsets before storing the entry in the log. If lpUserSid != NULL, the
371  *  username is also logged.
372  */
373 BOOL WINAPI ReportEventA ( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
374     PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR *lpStrings, LPVOID lpRawData)
375 {
376     LPCWSTR *wideStrArray;
377     UNICODE_STRING str;
378     int i;
379     BOOL ret;
380
381     FIXME("(%p,0x%04x,0x%04x,0x%08lx,%p,0x%04x,0x%08lx,%p,%p): stub\n", hEventLog,
382           wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
383
384     if (wNumStrings == 0) return TRUE;
385     if (!lpStrings) return TRUE;
386
387     wideStrArray = HeapAlloc(GetProcessHeap(), 0, sizeof(LPCWSTR) * wNumStrings);
388     for (i = 0; i < wNumStrings; i++)
389     {
390         RtlCreateUnicodeStringFromAsciiz(&str, lpStrings[i]);
391         wideStrArray[i] = str.Buffer;
392     }
393     ret = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid,
394                        wNumStrings, dwDataSize, wideStrArray, lpRawData);
395     for (i = 0; i < wNumStrings; i++)
396     {
397         HeapFree( GetProcessHeap(), 0, (LPSTR)wideStrArray[i] );
398     }
399     HeapFree(GetProcessHeap(), 0, wideStrArray);
400     return ret;
401 }
402
403 /******************************************************************************
404  * ReportEventW [ADVAPI32.@]
405  *
406  * see ReportEventA
407  */
408 BOOL WINAPI ReportEventW( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
409     PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCWSTR *lpStrings, LPVOID lpRawData )
410 {
411     int i;
412
413     FIXME("(%p,0x%04x,0x%04x,0x%08lx,%p,0x%04x,0x%08lx,%p,%p): stub\n", hEventLog,
414           wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
415
416     /* partial stub */
417
418     if (wNumStrings == 0) return TRUE;
419     if (!lpStrings) return TRUE;
420
421     for (i = 0; i < wNumStrings; i++)
422     {
423         switch (wType)
424         {
425         case EVENTLOG_SUCCESS:
426             TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
427             break;
428         case EVENTLOG_ERROR_TYPE:
429             ERR_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
430             break;
431         case EVENTLOG_WARNING_TYPE:
432             WARN_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
433             break;
434         default:
435             TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
436             break;
437         }
438     }
439     return TRUE;
440 }
441
442 /******************************************************************************
443  * RegisterTraceGuidsW [ADVAPI32.@]
444  *
445  */
446 ULONG WINAPI RegisterTraceGuidsW( WMIDPREQUEST RequestAddress,
447                 PVOID RequestContext, LPCGUID ControlGuid, ULONG GuidCount,
448                 PTRACE_GUID_REGISTRATION TraceGuidReg, LPCWSTR MofImagePath,
449                 LPCWSTR MofResourceName, PTRACEHANDLE RegistrationHandle )
450 {
451     FIXME("%p %p %p %lu %p %s %s %p\n", RequestAddress, RequestContext,
452           ControlGuid, GuidCount, TraceGuidReg, debugstr_w(MofImagePath),
453           debugstr_w(MofResourceName), RegistrationHandle);
454     return ERROR_CALL_NOT_IMPLEMENTED;
455 }
456
457 /******************************************************************************
458  * RegisterTraceGuidsA [ADVAPI32.@]
459  *
460  */
461 ULONG WINAPI RegisterTraceGuidsA( WMIDPREQUEST RequestAddress,
462                 PVOID RequestContext, LPCGUID ControlGuid, ULONG GuidCount,
463                 PTRACE_GUID_REGISTRATION TraceGuidReg, LPCSTR MofImagePath,
464                 LPCSTR MofResourceName, PTRACEHANDLE RegistrationHandle )
465 {
466     FIXME("%p %p %p %lu %p %s %s %p\n", RequestAddress, RequestContext,
467           ControlGuid, GuidCount, TraceGuidReg, debugstr_a(MofImagePath),
468           debugstr_a(MofResourceName), RegistrationHandle);
469     return ERROR_CALL_NOT_IMPLEMENTED;
470 }