mshtml: Added partial IHTMLDocument2::put_designMode implementation.
[wine] / dlls / wer / main.c
1 /*
2  * Copyright 2010 Louis Lenders
3  * Copyright 2010 Detlef Riekenberg
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include "config.h"
21
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winreg.h"
27 #include "werapi.h"
28 #include "wine/list.h"
29 #include "wine/unicode.h"
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(wer);
33
34 typedef struct {
35     struct list entry;
36     WER_REPORT_INFORMATION info;
37     WER_REPORT_TYPE reporttype;
38     WCHAR eventtype[1];
39 } report_t;
40
41
42 static CRITICAL_SECTION report_table_cs;
43 static CRITICAL_SECTION_DEBUG report_table_cs_debug =
44 {
45     0, 0, &report_table_cs,
46     { &report_table_cs_debug.ProcessLocksList, &report_table_cs_debug.ProcessLocksList },
47       0, 0, { (DWORD_PTR)(__FILE__ ": report_table_cs") }
48 };
49 static CRITICAL_SECTION report_table_cs = { &report_table_cs_debug, -1, 0, 0, 0, 0 };
50
51 static struct list report_table = LIST_INIT(report_table);
52
53 static WCHAR regpath_exclude[] = {'S','o','f','t','w','a','r','e','\\',
54                                   'M','i','c','r','o','s','o','f','t','\\',
55                                   'W','i','n','d','o','w','s',' ','E','r','r','o','r',' ','R','e','p','o','r','t','i','n','g','\\',
56                                   'E','x','c','l','u','d','e','d','A','p','p','l','i','c','a','t','i','o','n','s',0};
57
58 /***********************************************************************
59  * Memory allocation helper
60  */
61
62 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
63 {
64     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
65 }
66
67 static inline BOOL heap_free(void *mem)
68 {
69     return HeapFree(GetProcessHeap(), 0, mem);
70 }
71
72 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
73 {
74     TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
75
76     switch (fdwReason)
77     {
78         case DLL_WINE_PREATTACH:
79             return FALSE;    /* prefer native version */
80         case DLL_PROCESS_ATTACH:
81             DisableThreadLibraryCalls(hinstDLL);
82             break;
83     }
84
85     return TRUE;
86 }
87
88 /***********************************************************************
89  * WerAddExcludedApplication (wer.@)
90  *
91  * Add an application to the user specific or the system wide exclusion list
92  *
93  * PARAMS
94  *  exeName  [i] The application name
95  *  allUsers [i] for all users (TRUE) or for the current user (FALSE)
96  *
97  * RETURNS
98  *  Success: S_OK
99  *  Failure: A HRESULT error code
100  *
101  */
102 HRESULT WINAPI WerAddExcludedApplication(PCWSTR exeName, BOOL allUsers)
103 {
104     HKEY hkey;
105     DWORD value = 1;
106     LPWSTR bs;
107
108     TRACE("(%s, %d)\n",debugstr_w(exeName), allUsers);
109     if (!exeName || !exeName[0])
110         return E_INVALIDARG;
111
112     bs = strrchrW(exeName, '\\');
113     if (bs) {
114         bs++;   /* skip the backslash */
115         if (!bs[0]) {
116             return E_INVALIDARG;
117         }
118     } else
119         bs = (LPWSTR) exeName;
120
121     if (!RegCreateKeyW(allUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, regpath_exclude, &hkey)) {
122         RegSetValueExW(hkey, bs, 0, REG_DWORD, (LPBYTE)&value, sizeof(DWORD));
123         RegCloseKey(hkey);
124         return S_OK;
125     }
126     return E_ACCESSDENIED;
127 }
128
129 /***********************************************************************
130  * WerRemoveExcludedApplication (wer.@)
131  *
132  * remove an application from the exclusion list
133  *
134  * PARAMS
135  *  exeName  [i] The application name
136  *  allUsers [i] for all users (TRUE) or for the current user (FALSE)
137  *
138  * RETURNS
139  *  Success: S_OK
140  *  Failure: A HRESULT error code
141  *
142  */
143 HRESULT WINAPI WerRemoveExcludedApplication(PCWSTR exeName, BOOL allUsers)
144 {
145     HKEY hkey;
146     LPWSTR bs;
147     LONG lres;
148
149     TRACE("(%s, %d)\n",debugstr_w(exeName), allUsers);
150     if (!exeName || !exeName[0])
151         return E_INVALIDARG;
152
153     bs = strrchrW(exeName, '\\');
154     if (bs) {
155         bs++;   /* skip the backslash */
156         if (!bs[0]) {
157             return E_INVALIDARG;
158         }
159     } else
160         bs = (LPWSTR) exeName;
161
162     if (!RegCreateKeyW(allUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, regpath_exclude, &hkey)) {
163         lres = RegDeleteValueW(hkey, bs);
164         RegCloseKey(hkey);
165         return lres ? __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND) : S_OK;
166     }
167     return E_ACCESSDENIED;
168 }
169
170 /***********************************************************************
171  * WerReportAddDump (wer.@)
172  *
173  * Add a dump of dumpType to hReportHandle.
174  *
175  * PARAMS
176  *  hReportHandle      [i] error reporting handle to add the dump
177  *  hProcess           [i] handle to the regarding process
178  *  hThread            [o] handle to the regarding thread
179  *  dumpType           [i] type of the dump
180  *  pExceptionParam    [o] pointer to a WER_EXCEPTION_INFORMATION
181  *  pDumpCustomOptions [o] pointer to a WER_DUMP_CUSTOM_OPTIONS
182  *  dwFlags            [i] flag to control the heap dump
183  *
184  * RETURNS
185  *  Success: S_OK
186  *  Failure: A HRESULT error code
187  *
188  */
189 HRESULT WINAPI WerReportAddDump(HREPORT hReportHandle, HANDLE hProcess, HANDLE hThread,
190                                 WER_DUMP_TYPE dumpType, PWER_EXCEPTION_INFORMATION pExceptionParam,
191                                 PWER_DUMP_CUSTOM_OPTIONS pDumpCustomOptions, DWORD dwFlags)
192 {
193     FIXME("(%p, %p, %p, %d, %p, %p, %u) :stub\n", hReportHandle, hProcess, hThread, dumpType,
194           pExceptionParam, pDumpCustomOptions, dwFlags);
195
196     return E_NOTIMPL;
197 }
198
199 /***********************************************************************
200  * WerReportAddFile (wer.@)
201  *
202  * Add File to a error report handle.
203  *
204  * PARAMS
205  *  hreport [i] error reporting handle to add the file
206  *  path    [i] path to the file to add
207  *  type    [i] type of the file to add
208  *  flags   [i] flags for the file
209  *
210  * RETURNS
211  *  Success: S_OK
212  *  Failure: A HRESULT error code
213  *
214  */
215 HRESULT WINAPI WerReportAddFile(HREPORT hreport, PCWSTR path, WER_FILE_TYPE type, DWORD flags)
216 {
217     FIXME("(%p, %s, %d, 0x%x) :stub\n", hreport, debugstr_w(path), type, flags);
218
219     return S_OK;
220 }
221
222 /***********************************************************************
223  * WerReportCloseHandle (wer.@)
224  *
225  * Close an error reporting handle and free associated resources
226  *
227  * PARAMS
228  *  hreport [i] error reporting handle to close
229  *
230  * RETURNS
231  *  Success: S_OK
232  *  Failure: A HRESULT error code
233  *
234  */
235 HRESULT WINAPI WerReportCloseHandle(HREPORT hreport)
236 {
237     report_t * report = (report_t *) hreport;
238     report_t * cursor;
239     BOOL found = FALSE;
240
241     TRACE("(%p)\n", hreport);
242     EnterCriticalSection(&report_table_cs);
243     if (report) {
244         LIST_FOR_EACH_ENTRY(cursor, &report_table, report_t, entry)
245         {
246             if (cursor == report) {
247                 found = TRUE;
248                 list_remove(&report->entry);
249                 break;
250             }
251         }
252     }
253     LeaveCriticalSection(&report_table_cs);
254     if (!found)
255         return E_INVALIDARG;
256
257     heap_free(report);
258
259     return S_OK;
260 }
261
262 /***********************************************************************
263  * WerReportCreate (wer.@)
264  *
265  * Create an error report in memory and return a related HANDLE
266  *
267  * PARAMS
268  *  eventtype  [i] a name for the event type
269  *  reporttype [i] what type of report should be created
270  *  reportinfo [i] NULL or a ptr to a struct with some detailed information
271  *  phandle    [o] ptr, where the resulting handle should be saved
272  *
273  * RETURNS
274  *  Success: S_OK
275  *  Failure: A HRESULT error code
276  *
277  * NOTES
278  *  The event type must be registered at microsoft. Predefined types are
279  *  "APPCRASH" as the default on Windows, "Crash32" and "Crash64"
280  *
281  */
282 HRESULT WINAPI WerReportCreate(PCWSTR eventtype, WER_REPORT_TYPE reporttype, PWER_REPORT_INFORMATION reportinfo, HREPORT *phandle)
283 {
284     report_t *report;
285
286     TRACE("(%s, %d, %p, %p)\n", debugstr_w(eventtype), reporttype, reportinfo, phandle);
287     if (reportinfo) {
288         TRACE(".wzFriendlyEventName: %s\n", debugstr_w(reportinfo->wzFriendlyEventName));
289         TRACE(".wzApplicationName: %s\n", debugstr_w(reportinfo->wzApplicationName));
290     }
291
292     if (phandle)  *phandle = NULL;
293     if (!eventtype || !eventtype[0] || !phandle) {
294         return E_INVALIDARG;
295     }
296
297     report = heap_alloc_zero(FIELD_OFFSET(report_t, eventtype[lstrlenW(eventtype) + 1]));
298     if (!report)
299         return __HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
300
301     lstrcpyW(report->eventtype, eventtype);
302     report->reporttype = reporttype;
303
304     if (reportinfo) {
305         report->info = *reportinfo;
306     } else {
307         FIXME("build report information from scratch for %p\n", report);
308     }
309
310     EnterCriticalSection(&report_table_cs);
311     list_add_head(&report_table, &report->entry);
312     LeaveCriticalSection(&report_table_cs);
313
314     *phandle = report;
315     TRACE("=> %p\n", report);
316     return S_OK;
317 }
318
319 /***********************************************************************
320  * WerReportSetParameter (wer.@)
321  *
322  * Set one of 10 parameter / value pairs for a report handle
323  *
324  * PARAMS
325  *  hreport [i] error reporting handle to add the parameter
326  *  id      [i] parameter to set (WER_P0 up to WER_P9)
327  *  name    [i] optional name of the parameter
328  *  value   [i] value of the parameter
329  *
330  * RETURNS
331  *  Success: S_OK
332  *  Failure: A HRESULT error code
333  *
334  */
335 HRESULT WINAPI WerReportSetParameter(HREPORT hreport, DWORD id, PCWSTR name, PCWSTR value)
336 {
337     FIXME("(%p, %d, %s, %s) :stub\n", hreport, id, debugstr_w(name), debugstr_w(value));
338
339     return S_OK;
340 }
341
342 /***********************************************************************
343  * WerReportSubmit (wer.@)
344  *
345  * Ask the user for permission and send the error report
346  * then kill or restart the application, when requested
347  *
348  * PARAMS
349  *  hreport [i] error reporting handle to send
350  *  consent [i] current transmit permission
351  *  flags   [i] flag to select dialog, transmission snd restart options
352  *  presult [o] ptr, where the transmission result should be saved
353  *
354  * RETURNS
355  *  Success: S_OK
356  *  Failure: A HRESULT error code
357  *
358  */
359 HRESULT WINAPI WerReportSubmit(HREPORT hreport, WER_CONSENT consent, DWORD flags, PWER_SUBMIT_RESULT presult)
360 {
361     FIXME("(%p, %d, 0x%x, %p) :stub\n", hreport, consent, flags, presult);
362
363     if(!presult)
364         return E_INVALIDARG;
365
366     *presult = WerDisabled;
367     return S_OK;
368 }
369
370 /***********************************************************************
371  * WerReportSetUIOption (wer.@)
372  */
373 HRESULT WINAPI WerReportSetUIOption(HREPORT hreport, WER_REPORT_UI uitype, PCWSTR value)
374 {
375     FIXME("(%p, %d, %s) :stub\n", hreport, uitype, debugstr_w(value));
376     return E_NOTIMPL;
377 }